Skip to content

Commit

Permalink
Add 2 new examples : nbgl_review, nbgl_address
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed May 23, 2024
1 parent d23eeaa commit d690db9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
30 changes: 30 additions & 0 deletions ledger_device_sdk/examples/nbgl_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![no_std]
#![no_main]

// Force boot section to be embedded in
use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{init_comm, NbglAddressConfirm, NbglGlyph};
use ledger_secure_sdk_sys::*;

#[no_mangle]
extern "C" fn sample_main() {
unsafe {
nbgl_refreshReset();
}

let mut comm = Comm::new();
// Initialize reference to Comm instance for NBGL
// API calls.
init_comm(&mut comm);

let addr_hex = "0x1234567890ABCDEF1234567890ABCDEF12345678";

// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph =
NbglGlyph::from_include(include_gif!("examples/crab_64x64.gif", NBGL));
// Display the address confirmation screen.
NbglAddressConfirm::new().glyph(&FERRIS).show(addr_hex);
}
7 changes: 5 additions & 2 deletions ledger_device_sdk/examples/nbgl_home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{NbglGlyph, NbglHomeAndSettings};
use ledger_device_sdk::nbgl::{init_comm, NbglGlyph, NbglHomeAndSettings};
use ledger_device_sdk::nvm::*;
use ledger_device_sdk::NVMData;
use ledger_secure_sdk_sys::*;
Expand Down Expand Up @@ -40,14 +40,17 @@ extern "C" fn sample_main() {
NVMData::new(AtomicStorage::new(&[0u8; 10]));

let mut comm = Comm::new();
// Initialize reference to Comm instance for NBGL
// API calls.
init_comm(&mut comm);

// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph =
NbglGlyph::from_include(include_gif!("examples/crab_64x64.gif", NBGL));

let settings_strings = [["Switch title", "Switch subtitle"]];
// Display the home screen.
NbglHomeAndSettings::new(&mut comm)
NbglHomeAndSettings::new()
.glyph(&FERRIS)
.settings(unsafe { DATA.get_mut() }, &settings_strings)
.infos(
Expand Down
52 changes: 52 additions & 0 deletions ledger_device_sdk/examples/nbgl_review.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#![no_std]
#![no_main]

// Force boot section to be embedded in
use ledger_device_sdk as _;

use include_gif::include_gif;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::{init_comm, Field, NbglGlyph, NbglReview};
use ledger_secure_sdk_sys::*;

#[no_mangle]
extern "C" fn sample_main() {
unsafe {
nbgl_refreshReset();
}

let mut comm = Comm::new();
// Initialize reference to Comm instance for NBGL
// API calls.
init_comm(&mut comm);

let my_fields = [
Field {
name: "Amount",
value: "111 CRAB",
},
Field {
name: "Destination",
value: "0x1234567890ABCDEF1234567890ABCDEF12345678",
},
Field {
name: "Memo",
value: "This is a test transaction.",
},
];

// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph =
NbglGlyph::from_include(include_gif!("examples/crab_64x64.gif", NBGL));
// Create NBGL review. Maximum number of fields and string buffer length can be customised
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
let mut review: NbglReview = NbglReview::new()
.titles(
"Please review transaction",
"To send CRAB",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS);

review.show(&my_fields);
}

0 comments on commit d690db9

Please sign in to comment.