Skip to content

Commit 4d200ca

Browse files
committed
Implement io_seproxyhal_play_tune()
1 parent 2574df9 commit 4d200ca

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

ledger_device_sdk/src/nbgl.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,35 @@ impl TryFrom<u8> for TuneIndex {
298298
}
299299
}
300300

301-
// this is a mock that does nothing yet, but should become a direct translation
302-
// of the C original. This was done to avoid compiling `os_io_seproxyhal.c` which
303-
// includes many other things
301+
// Direct translation of the C original. This was done to
302+
// avoid compiling `os_io_seproxyhal.c` which includes many other things
304303
#[no_mangle]
305304
extern "C" fn io_seproxyhal_play_tune(tune_index: u8) {
306-
let index = TuneIndex::try_from(tune_index);
307-
if index.is_err() {
305+
let mut buffer = [0u8; 4];
306+
let mut spi_buffer = [0u8; 128];
307+
308+
if tune_index >= NB_TUNES {
309+
return;
310+
}
311+
312+
let sound_setting =
313+
unsafe { os_setting_get(OS_SETTING_PIEZO_SOUND.into(), core::ptr::null_mut(), 0) };
314+
315+
if ((sound_setting & 2) == 1) && (tune_index < TUNE_TAP_CASUAL) {
308316
return;
309317
}
318+
319+
if ((sound_setting & 1) == 1) && (tune_index >= TUNE_TAP_CASUAL) {
320+
return;
321+
}
322+
323+
if seph::is_status_sent() {
324+
seph::seph_recv(&mut spi_buffer, 0);
325+
}
326+
327+
buffer[0] = SEPROXYHAL_TAG_PLAY_TUNE as u8;
328+
buffer[1] = 0;
329+
buffer[2] = 1;
330+
buffer[3] = tune_index;
331+
seph::seph_send(&buffer);
310332
}

0 commit comments

Comments
 (0)