|
1 | 1 | use super::*;
|
2 | 2 |
|
| 3 | +pub const SETTINGS_SIZE: usize = 10; |
| 4 | +static mut NVM_REF: Option<&mut AtomicStorage<[u8; SETTINGS_SIZE]>> = None; |
| 5 | +static mut SWITCH_ARRAY: [nbgl_contentSwitch_t; SETTINGS_SIZE] = |
| 6 | + [unsafe { const_zero!(nbgl_contentSwitch_t) }; SETTINGS_SIZE]; |
| 7 | + |
3 | 8 | /// Callback triggered by the NBGL API when a setting switch is toggled.
|
4 | 9 | unsafe extern "C" fn settings_callback(token: c_int, _index: u8, _page: c_int) {
|
5 | 10 | let idx = token - FIRST_USER_TOKEN as i32;
|
@@ -47,7 +52,9 @@ pub struct NbglHomeAndSettings {
|
47 | 52 | icon: nbgl_icon_details_t,
|
48 | 53 | }
|
49 | 54 |
|
50 |
| -impl SyncNBGL for NbglHomeAndSettings {} |
| 55 | +unsafe extern "C" fn quit_callback() { |
| 56 | + exit_app(0); |
| 57 | +} |
51 | 58 |
|
52 | 59 | impl<'a> NbglHomeAndSettings {
|
53 | 60 | pub fn new() -> NbglHomeAndSettings {
|
@@ -111,83 +118,62 @@ impl<'a> NbglHomeAndSettings {
|
111 | 118 | }
|
112 | 119 | }
|
113 | 120 |
|
114 |
| - pub fn show<T: TryFrom<ApduHeader>>(&mut self) -> Event<T> |
115 |
| - where |
116 |
| - Reply: From<<T as TryFrom<ApduHeader>>::Error>, |
117 |
| - { |
| 121 | + pub fn show(&mut self) { |
118 | 122 | unsafe {
|
119 |
| - loop { |
120 |
| - self.info_contents_ptr = self |
121 |
| - .info_contents |
122 |
| - .iter() |
123 |
| - .map(|s| s.as_ptr()) |
124 |
| - .collect::<Vec<_>>(); |
125 |
| - |
126 |
| - self.info_list = nbgl_contentInfoList_t { |
127 |
| - infoTypes: INFO_FIELDS.as_ptr() as *const *const c_char, |
128 |
| - infoContents: self.info_contents_ptr[..].as_ptr() as *const *const c_char, |
129 |
| - nbInfos: INFO_FIELDS.len() as u8, |
130 |
| - }; |
131 |
| - |
132 |
| - for (i, setting) in self.setting_contents.iter().enumerate() { |
133 |
| - SWITCH_ARRAY[i].text = setting[0].as_ptr(); |
134 |
| - SWITCH_ARRAY[i].subText = setting[1].as_ptr(); |
135 |
| - let state = if let Some(data) = NVM_REF.as_mut() { |
136 |
| - data.get_ref()[i] |
137 |
| - } else { |
138 |
| - OFF_STATE |
139 |
| - }; |
140 |
| - SWITCH_ARRAY[i].initState = state; |
141 |
| - SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8; |
142 |
| - SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8; |
143 |
| - } |
144 |
| - |
145 |
| - self.content = nbgl_content_t { |
146 |
| - content: nbgl_content_u { |
147 |
| - switchesList: nbgl_pageSwitchesList_s { |
148 |
| - switches: &SWITCH_ARRAY as *const nbgl_contentSwitch_t, |
149 |
| - nbSwitches: self.nb_settings, |
150 |
| - }, |
151 |
| - }, |
152 |
| - contentActionCallback: Some(settings_callback), |
153 |
| - type_: SWITCHES_LIST, |
| 123 | + self.info_contents_ptr = self |
| 124 | + .info_contents |
| 125 | + .iter() |
| 126 | + .map(|s| s.as_ptr()) |
| 127 | + .collect::<Vec<_>>(); |
| 128 | + |
| 129 | + self.info_list = nbgl_contentInfoList_t { |
| 130 | + infoTypes: INFO_FIELDS.as_ptr() as *const *const c_char, |
| 131 | + infoContents: self.info_contents_ptr[..].as_ptr() as *const *const c_char, |
| 132 | + nbInfos: INFO_FIELDS.len() as u8, |
| 133 | + }; |
| 134 | + |
| 135 | + for (i, setting) in self.setting_contents.iter().enumerate() { |
| 136 | + SWITCH_ARRAY[i].text = setting[0].as_ptr(); |
| 137 | + SWITCH_ARRAY[i].subText = setting[1].as_ptr(); |
| 138 | + let state = if let Some(data) = NVM_REF.as_mut() { |
| 139 | + data.get_ref()[i] |
| 140 | + } else { |
| 141 | + OFF_STATE |
154 | 142 | };
|
| 143 | + SWITCH_ARRAY[i].initState = state; |
| 144 | + SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8; |
| 145 | + SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8; |
| 146 | + } |
155 | 147 |
|
156 |
| - self.generic_contents = nbgl_genericContents_t { |
157 |
| - callbackCallNeeded: false, |
158 |
| - __bindgen_anon_1: nbgl_genericContents_t__bindgen_ty_1 { |
159 |
| - contentsList: &self.content as *const nbgl_content_t, |
| 148 | + self.content = nbgl_content_t { |
| 149 | + content: nbgl_content_u { |
| 150 | + switchesList: nbgl_pageSwitchesList_s { |
| 151 | + switches: &SWITCH_ARRAY as *const nbgl_contentSwitch_t, |
| 152 | + nbSwitches: self.nb_settings, |
160 | 153 | },
|
161 |
| - nbContents: if self.nb_settings > 0 { 1 } else { 0 }, |
162 |
| - }; |
163 |
| - |
164 |
| - self.ux_sync_init(); |
165 |
| - nbgl_useCaseHomeAndSettings( |
166 |
| - self.app_name.as_ptr() as *const c_char, |
167 |
| - &self.icon as *const nbgl_icon_details_t, |
168 |
| - core::ptr::null(), |
169 |
| - INIT_HOME_PAGE as u8, |
170 |
| - &self.generic_contents as *const nbgl_genericContents_t, |
171 |
| - &self.info_list as *const nbgl_contentInfoList_t, |
172 |
| - core::ptr::null(), |
173 |
| - Some(quit_callback), |
174 |
| - ); |
175 |
| - match self.ux_sync_wait(true) { |
176 |
| - SyncNbgl::UxSyncRetApduReceived => { |
177 |
| - if let Some(comm) = COMM_REF.as_mut() { |
178 |
| - if let Some(value) = comm.check_event() { |
179 |
| - return value; |
180 |
| - } |
181 |
| - } |
182 |
| - } |
183 |
| - SyncNbgl::UxSyncRetQuitted => { |
184 |
| - exit_app(0); |
185 |
| - } |
186 |
| - _ => { |
187 |
| - panic!("Unexpected return value from ux_sync_homeAndSettings"); |
188 |
| - } |
189 |
| - } |
190 |
| - } |
| 154 | + }, |
| 155 | + contentActionCallback: Some(settings_callback), |
| 156 | + type_: SWITCHES_LIST, |
| 157 | + }; |
| 158 | + |
| 159 | + self.generic_contents = nbgl_genericContents_t { |
| 160 | + callbackCallNeeded: false, |
| 161 | + __bindgen_anon_1: nbgl_genericContents_t__bindgen_ty_1 { |
| 162 | + contentsList: &self.content as *const nbgl_content_t, |
| 163 | + }, |
| 164 | + nbContents: if self.nb_settings > 0 { 1 } else { 0 }, |
| 165 | + }; |
| 166 | + |
| 167 | + nbgl_useCaseHomeAndSettings( |
| 168 | + self.app_name.as_ptr() as *const c_char, |
| 169 | + &self.icon as *const nbgl_icon_details_t, |
| 170 | + core::ptr::null(), |
| 171 | + INIT_HOME_PAGE as u8, |
| 172 | + &self.generic_contents as *const nbgl_genericContents_t, |
| 173 | + &self.info_list as *const nbgl_contentInfoList_t, |
| 174 | + core::ptr::null(), |
| 175 | + Some(quit_callback), |
| 176 | + ); |
191 | 177 | }
|
192 | 178 | }
|
193 | 179 | }
|
0 commit comments