Skip to content

Commit 0937f0c

Browse files
committed
Keep backward compatibility with show() API
1 parent 471a2ba commit 0937f0c

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

ledger_device_sdk/src/nbgl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::io::{ApduHeader, Comm};
1+
use crate::io::{ApduHeader, Comm, Event, Reply};
22
use crate::nvm::*;
33
use const_zero::const_zero;
44
extern crate alloc;

ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ unsafe extern "C" fn quit_callback() {
5656
exit_app(0);
5757
}
5858

59+
impl SyncNBGL for NbglHomeAndSettings {}
60+
61+
unsafe extern "C" fn quit_cb() {
62+
exit_app(0);
63+
}
64+
5965
impl<'a> NbglHomeAndSettings {
6066
pub fn new() -> NbglHomeAndSettings {
6167
NbglHomeAndSettings {
@@ -118,7 +124,87 @@ impl<'a> NbglHomeAndSettings {
118124
}
119125
}
120126

121-
pub fn show(&mut self) {
127+
pub fn show<T: TryFrom<ApduHeader>>(&mut self) -> Event<T>
128+
where
129+
Reply: From<<T as TryFrom<ApduHeader>>::Error>,
130+
{
131+
unsafe {
132+
loop {
133+
self.info_contents_ptr = self
134+
.info_contents
135+
.iter()
136+
.map(|s| s.as_ptr())
137+
.collect::<Vec<_>>();
138+
139+
self.info_list = nbgl_contentInfoList_t {
140+
infoTypes: INFO_FIELDS.as_ptr() as *const *const c_char,
141+
infoContents: self.info_contents_ptr[..].as_ptr() as *const *const c_char,
142+
nbInfos: INFO_FIELDS.len() as u8,
143+
};
144+
145+
for (i, setting) in self.setting_contents.iter().enumerate() {
146+
SWITCH_ARRAY[i].text = setting[0].as_ptr();
147+
SWITCH_ARRAY[i].subText = setting[1].as_ptr();
148+
let state = if let Some(data) = NVM_REF.as_mut() {
149+
data.get_ref()[i]
150+
} else {
151+
OFF_STATE
152+
};
153+
SWITCH_ARRAY[i].initState = state;
154+
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
155+
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
156+
}
157+
158+
self.content = nbgl_content_t {
159+
content: nbgl_content_u {
160+
switchesList: nbgl_pageSwitchesList_s {
161+
switches: &SWITCH_ARRAY as *const nbgl_contentSwitch_t,
162+
nbSwitches: self.nb_settings,
163+
},
164+
},
165+
contentActionCallback: Some(settings_callback),
166+
type_: SWITCHES_LIST,
167+
};
168+
169+
self.generic_contents = nbgl_genericContents_t {
170+
callbackCallNeeded: false,
171+
__bindgen_anon_1: nbgl_genericContents_t__bindgen_ty_1 {
172+
contentsList: &self.content as *const nbgl_content_t,
173+
},
174+
nbContents: if self.nb_settings > 0 { 1 } else { 0 },
175+
};
176+
177+
self.ux_sync_init();
178+
nbgl_useCaseHomeAndSettings(
179+
self.app_name.as_ptr() as *const c_char,
180+
&self.icon as *const nbgl_icon_details_t,
181+
core::ptr::null(),
182+
INIT_HOME_PAGE as u8,
183+
&self.generic_contents as *const nbgl_genericContents_t,
184+
&self.info_list as *const nbgl_contentInfoList_t,
185+
core::ptr::null(),
186+
Some(quit_callback),
187+
);
188+
match self.ux_sync_wait(true) {
189+
SyncNbgl::UxSyncRetApduReceived => {
190+
if let Some(comm) = COMM_REF.as_mut() {
191+
if let Some(value) = comm.check_event() {
192+
return value;
193+
}
194+
}
195+
}
196+
SyncNbgl::UxSyncRetQuitted => {
197+
exit_app(0);
198+
}
199+
_ => {
200+
panic!("Unexpected return value from ux_sync_homeAndSettings");
201+
}
202+
}
203+
}
204+
}
205+
}
206+
207+
pub fn display(&mut self) {
122208
unsafe {
123209
self.info_contents_ptr = self
124210
.info_contents
@@ -172,7 +258,7 @@ impl<'a> NbglHomeAndSettings {
172258
&self.generic_contents as *const nbgl_genericContents_t,
173259
&self.info_list as *const nbgl_contentInfoList_t,
174260
core::ptr::null(),
175-
Some(quit_callback),
261+
Some(quit_cb),
176262
);
177263
}
178264
}

0 commit comments

Comments
 (0)