Skip to content

Commit

Permalink
Merge pull request #187 from LedgerHQ/y333/stax_support_sound
Browse files Browse the repository at this point in the history
Implement io_seproxyhal_play_tune to enable PIEZO_SOUND on Stax/Flex
  • Loading branch information
yogh333 authored Sep 20, 2024
2 parents 2574df9 + 2f9c8d5 commit f6faf62
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_device_sdk"
version = "1.15.5"
version = "1.15.6"
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
edition = "2021"
license.workspace = true
Expand Down
52 changes: 27 additions & 25 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,33 +278,35 @@ pub enum TuneIndex {
TapNext,
}

impl TryFrom<u8> for TuneIndex {
type Error = ();
fn try_from(index: u8) -> Result<TuneIndex, ()> {
Ok(match index {
TUNE_RESERVED => TuneIndex::Reserved,
TUNE_BOOT => TuneIndex::Boot,
TUNE_CHARGING => TuneIndex::Charging,
TUNE_LEDGER_MOMENT => TuneIndex::LedgerMoment,
TUNE_ERROR => TuneIndex::Error,
TUNE_NEUTRAL => TuneIndex::Neutral,
TUNE_LOCK => TuneIndex::Lock,
TUNE_SUCCESS => TuneIndex::Success,
TUNE_LOOK_AT_ME => TuneIndex::LookAtMe,
TUNE_TAP_CASUAL => TuneIndex::TapCasual,
TUNE_TAP_NEXT => TuneIndex::TapNext,
_ => return Err(()),
})
}
}

// this is a mock that does nothing yet, but should become a direct translation
// of the C original. This was done to avoid compiling `os_io_seproxyhal.c` which
// includes many other things
// Direct translation of the C original. This was done to
// avoid compiling `os_io_seproxyhal.c` which includes many other things
#[no_mangle]
extern "C" fn io_seproxyhal_play_tune(tune_index: u8) {
let index = TuneIndex::try_from(tune_index);
if index.is_err() {
let mut buffer = [0u8; 4];
let mut spi_buffer = [0u8; 128];

if tune_index >= NB_TUNES {
return;
}

let sound_setting =
unsafe { os_setting_get(OS_SETTING_PIEZO_SOUND.into(), core::ptr::null_mut(), 0) };

if ((sound_setting & 2) == 2) && (tune_index < TUNE_TAP_CASUAL) {
return;
}

if ((sound_setting & 1) == 1) && (tune_index >= TUNE_TAP_CASUAL) {
return;
}

if seph::is_status_sent() {
seph::seph_recv(&mut spi_buffer, 0);
}

buffer[0] = SEPROXYHAL_TAG_PLAY_TUNE as u8;
buffer[1] = 0;
buffer[2] = 1;
buffer[3] = tune_index;
seph::seph_send(&buffer);
}

0 comments on commit f6faf62

Please sign in to comment.