Skip to content

Commit

Permalink
Add new init_comm function to initialize COMM_REF global.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed May 23, 2024
1 parent ab74eb1 commit d23eeaa
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ impl<'a> Into<nbgl_icon_details_t> for &NbglGlyph<'a> {
}
}

/// Initialize the global COMM_REF variable with the provided Comm instance.
/// This function should be called from the main function of the application.
/// The COMM_REF variable is used by the NBGL API to detect touch events and
/// APDU reception.
pub fn init_comm(comm: &mut Comm) {
unsafe {
COMM_REF = Some(transmute(comm));
}
}

/// IO function used in the synchronous NBGL C library to process
/// events (touch, buttons, etc.) or detect if an APDU was received.
/// It returns true if an APDU was received, false otherwise.
Expand Down Expand Up @@ -179,10 +189,7 @@ pub struct NbglHomeAndSettings<'a> {
}

impl<'a> NbglHomeAndSettings<'a> {
pub fn new(comm: &mut Comm) -> NbglHomeAndSettings<'a> {
unsafe {
COMM_REF = Some(transmute(comm));
}
pub fn new() -> NbglHomeAndSettings<'a> {
NbglHomeAndSettings {
app_name: "Rust App\0".as_ptr() as *const c_char,
icon: core::ptr::null(),
Expand Down

0 comments on commit d23eeaa

Please sign in to comment.