Skip to content

Commit e226641

Browse files
committed
Enable NBGL build for all Nano* devices
1 parent f0a2b82 commit e226641

File tree

12 files changed

+77
-13
lines changed

12 files changed

+77
-13
lines changed

ledger_device_sdk/src/io.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ impl Comm {
372372
match seph::Events::from(tag) {
373373
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
374374
seph::Events::ButtonPush => {
375+
#[cfg(feature = "nbgl")]
376+
unsafe {
377+
ux_process_button_event(spi_buffer.as_mut_ptr());
378+
}
375379
let button_info = spi_buffer[3] >> 1;
376380
if let Some(btn_evt) = get_button_event(&mut self.buttons, button_info) {
377381
return Some(Event::Button(btn_evt));

ledger_device_sdk/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub mod seph;
2222

2323
pub mod testing;
2424

25-
#[cfg(any(target_os = "stax", target_os = "flex"))]
25+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nbgl"))]
2626
pub mod nbgl;
27-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
27+
#[cfg(not(any(target_os = "stax", target_os = "flex", feature = "nbgl")))]
2828
pub mod ui;
2929

3030
pub mod uxapp;

ledger_device_sdk/src/nbgl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use ledger_secure_sdk_sys::*;
1010

1111
pub mod nbgl_address_review;
1212
pub mod nbgl_choice;
13+
#[cfg(any(target_os = "stax", target_os = "flex"))]
1314
pub mod nbgl_generic_review;
1415
pub mod nbgl_home_and_settings;
1516
pub mod nbgl_review;
@@ -20,6 +21,7 @@ pub mod nbgl_streaming_review;
2021

2122
pub use nbgl_address_review::*;
2223
pub use nbgl_choice::*;
24+
#[cfg(any(target_os = "stax", target_os = "flex"))]
2325
pub use nbgl_generic_review::*;
2426
pub use nbgl_home_and_settings::*;
2527
pub use nbgl_review::*;
@@ -105,6 +107,7 @@ unsafe extern "C" fn quit_callback() {
105107
G_ENDED = true;
106108
}
107109

110+
#[cfg(any(target_os = "stax", target_os = "flex"))]
108111
unsafe extern "C" fn rejected_callback() {
109112
G_RET = SyncNbgl::UxSyncRetRejected.into();
110113
G_ENDED = true;
@@ -274,6 +277,7 @@ pub enum TuneIndex {
274277
// Direct translation of the C original. This was done to
275278
// avoid compiling `os_io_seproxyhal.c` which includes many other things
276279
#[no_mangle]
280+
#[cfg(any(target_os = "stax", target_os = "flex"))]
277281
extern "C" fn io_seproxyhal_play_tune(tune_index: u8) {
278282
let mut buffer = [0u8; 4];
279283
let mut spi_buffer = [0u8; 128];

ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ impl<'a> NbglHomeAndSettings {
173173
};
174174
SWITCH_ARRAY[i].initState = state;
175175
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
176-
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
176+
#[cfg(any(target_os = "stax", target_os = "flex"))]
177+
{
178+
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
179+
}
177180
}
178181

179182
self.content = nbgl_content_t {
@@ -257,7 +260,10 @@ impl<'a> NbglHomeAndSettings {
257260
};
258261
SWITCH_ARRAY[i].initState = state;
259262
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
260-
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
263+
#[cfg(any(target_os = "stax", target_os = "flex"))]
264+
{
265+
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
266+
}
261267
}
262268

263269
self.content = nbgl_content_t {

ledger_secure_sdk_sys/build.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl SDKBuilder<'_> {
223223
v.push((String::from("NBGL_USE_CASE"), None));
224224
} else {
225225
println!("cargo:warning=BAGL is built");
226+
println!("cargo:rustc-env=C_SDK_GRAPHICS={}", "bagl");
226227
v.push((String::from("HAVE_BAGL"), None));
227228
}
228229
v
@@ -245,6 +246,7 @@ impl SDKBuilder<'_> {
245246
v.push((String::from("NBGL_USE_CASE"), None));
246247
} else {
247248
println!("cargo:warning=BAGL is built");
249+
println!("cargo:rustc-env=C_SDK_GRAPHICS={}", "bagl");
248250
v.push((String::from("HAVE_BAGL"), None));
249251
}
250252
v
@@ -394,7 +396,7 @@ impl SDKBuilder<'_> {
394396
pub fn build_c_sdk(&self) -> Result<(), SDKBuildError> {
395397
// Generate glyphs
396398
if self.device.name != DeviceName::NanoS {
397-
generate_glyphs(&self.device.c_sdk, &self.device.glyphs_folders);
399+
generate_glyphs(&self.device);
398400
}
399401

400402
let mut command = cc::Build::new();
@@ -669,6 +671,8 @@ fn configure_lib_ble(command: &mut cc::Build, c_sdk: &Path) {
669671
}
670672

671673
fn configure_lib_nbgl(command: &mut cc::Build, c_sdk: &Path) {
674+
println!("cargo:rustc-env=C_SDK_GRAPHICS={}", "nbgl");
675+
672676
let glyphs_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("glyphs");
673677
command
674678
.include(c_sdk.join("lib_nbgl/include/"))
@@ -864,8 +868,8 @@ fn clone_sdk(devicename: &DeviceName) -> PathBuf {
864868
c_sdk
865869
}
866870

867-
pub fn generate_glyphs(c_sdk: &PathBuf, glyphs_folders: &[PathBuf]) {
868-
let icon2glyph = c_sdk.join("lib_nbgl/tools/icon2glyph.py");
871+
fn generate_glyphs(device: &Device) {
872+
let icon2glyph = device.c_sdk.join("lib_nbgl/tools/icon2glyph.py");
869873

870874
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
871875
let dest_path = out_path.join("glyphs");
@@ -879,7 +883,11 @@ pub fn generate_glyphs(c_sdk: &PathBuf, glyphs_folders: &[PathBuf]) {
879883
.arg("--glyphcfile")
880884
.arg(dest_path.join("glyphs.c").as_os_str());
881885

882-
for folder in glyphs_folders.iter() {
886+
if device.name == DeviceName::NanoSPlus || device.name == DeviceName::NanoX {
887+
cmd.arg("--reverse");
888+
}
889+
890+
for folder in device.glyphs_folders.iter() {
883891
for file in std::fs::read_dir(folder).unwrap() {
884892
let path = file.unwrap().path();
885893
let path_str = path.to_str().unwrap().to_string();

ledger_secure_sdk_sys/csdk_flex.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@
5757
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5858
// Misc
5959
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60-
#define HAVE_LOCAL_APDU_BUFFER
60+
#define HAVE_LOCAL_APDU_BUFFER
61+
62+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63+
// DEBUG C SDK
64+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65+
//#define HAVE_PRINTF
66+
//#define PRINTF mcu_usb_printf

ledger_secure_sdk_sys/csdk_nanos2.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@
4747
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4848
// Misc
4949
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50-
#define HAVE_LOCAL_APDU_BUFFER
50+
#define HAVE_LOCAL_APDU_BUFFER
51+
52+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53+
// DEBUG C SDK
54+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55+
//#define HAVE_PRINTF
56+
//#define PRINTF mcu_usb_printf

ledger_secure_sdk_sys/csdk_nanox.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@
5454
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5555
#define HAVE_LOCAL_APDU_BUFFER
5656
#define HAVE_SEPROXYHAL_MCU
57-
#define HAVE_MCU_PROTECT
57+
#define HAVE_MCU_PROTECT
58+
59+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60+
// DEBUG C SDK
61+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62+
//#define HAVE_PRINTF
63+
//#define PRINTF mcu_usb_printf

ledger_secure_sdk_sys/csdk_stax.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,10 @@
5555
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5656
// Misc
5757
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58-
#define HAVE_LOCAL_APDU_BUFFER
58+
#define HAVE_LOCAL_APDU_BUFFER
59+
60+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61+
// DEBUG C SDK
62+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63+
//#define HAVE_PRINTF
64+
//#define PRINTF mcu_usb_printf

ledger_secure_sdk_sys/link.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ SECTIONS
141141
ledger.rust_sdk_name (INFO): { KEEP(*(ledger.rust_sdk_name)) }
142142
ledger.sdk_name (INFO): { KEEP(*(ledger.sdk_name)) }
143143
ledger.sdk_hash (INFO): { KEEP(*(ledger.sdk_hash)) }
144+
ledger.sdk_graphics (INFO): { KEEP(*(ledger.sdk_graphics)) }
144145
}
145146

146147
PROVIDE(_nvram = ABSOLUTE(_nvram_start));

0 commit comments

Comments
 (0)