Skip to content

Commit f6faf62

Browse files
authored
Merge pull request #187 from LedgerHQ/y333/stax_support_sound
Implement io_seproxyhal_play_tune to enable PIEZO_SOUND on Stax/Flex
2 parents 2574df9 + 2f9c8d5 commit f6faf62

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ledger_device_sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_device_sdk"
3-
version = "1.15.5"
3+
version = "1.15.6"
44
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
55
edition = "2021"
66
license.workspace = true

ledger_device_sdk/src/nbgl.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -278,33 +278,35 @@ pub enum TuneIndex {
278278
TapNext,
279279
}
280280

281-
impl TryFrom<u8> for TuneIndex {
282-
type Error = ();
283-
fn try_from(index: u8) -> Result<TuneIndex, ()> {
284-
Ok(match index {
285-
TUNE_RESERVED => TuneIndex::Reserved,
286-
TUNE_BOOT => TuneIndex::Boot,
287-
TUNE_CHARGING => TuneIndex::Charging,
288-
TUNE_LEDGER_MOMENT => TuneIndex::LedgerMoment,
289-
TUNE_ERROR => TuneIndex::Error,
290-
TUNE_NEUTRAL => TuneIndex::Neutral,
291-
TUNE_LOCK => TuneIndex::Lock,
292-
TUNE_SUCCESS => TuneIndex::Success,
293-
TUNE_LOOK_AT_ME => TuneIndex::LookAtMe,
294-
TUNE_TAP_CASUAL => TuneIndex::TapCasual,
295-
TUNE_TAP_NEXT => TuneIndex::TapNext,
296-
_ => return Err(()),
297-
})
298-
}
299-
}
300-
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
281+
// Direct translation of the C original. This was done to
282+
// avoid compiling `os_io_seproxyhal.c` which includes many other things
304283
#[no_mangle]
305284
extern "C" fn io_seproxyhal_play_tune(tune_index: u8) {
306-
let index = TuneIndex::try_from(tune_index);
307-
if index.is_err() {
285+
let mut buffer = [0u8; 4];
286+
let mut spi_buffer = [0u8; 128];
287+
288+
if tune_index >= NB_TUNES {
289+
return;
290+
}
291+
292+
let sound_setting =
293+
unsafe { os_setting_get(OS_SETTING_PIEZO_SOUND.into(), core::ptr::null_mut(), 0) };
294+
295+
if ((sound_setting & 2) == 2) && (tune_index < TUNE_TAP_CASUAL) {
296+
return;
297+
}
298+
299+
if ((sound_setting & 1) == 1) && (tune_index >= TUNE_TAP_CASUAL) {
308300
return;
309301
}
302+
303+
if seph::is_status_sent() {
304+
seph::seph_recv(&mut spi_buffer, 0);
305+
}
306+
307+
buffer[0] = SEPROXYHAL_TAG_PLAY_TUNE as u8;
308+
buffer[1] = 0;
309+
buffer[2] = 1;
310+
buffer[3] = tune_index;
311+
seph::seph_send(&buffer);
310312
}

0 commit comments

Comments
 (0)