diff options
author | Tomasz Moń <desowin@gmail.com> | 2021-06-27 12:20:56 +0200 |
---|---|---|
committer | Tomasz Moń <desowin@gmail.com> | 2021-06-27 12:20:56 +0200 |
commit | a4ab6364236b4453e93b12ecba1e9f389f6edd2f (patch) | |
tree | ac2420cdd3004ebd7215b6d57c1805fc314d819f /firmware/target | |
parent | ead4bc07695765d0ad5d5a92793e74aaa40be410 (diff) |
Sansa Connect: More reliable AVR communication
AVR requires bigger delays between retries. Read state instead of
version for synchronization purposes as it shifts more bytes.
Change-Id: Ib7fa980496d3bc7744a086b45e1865861ef58b88
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c index 056ba7b56a..a72faea7be 100644 --- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c +++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c @@ -52,8 +52,8 @@ #define dbgprintf(...) #endif -#define AVR_DELAY_US 100 -#define AVR_MAX_RETRIES 3 +#define AVR_DELAY_US 200 +#define AVR_MAX_RETRIES 10 #define CMD_SYNC 0xAA #define CMD_CLOSE 0xCC @@ -428,17 +428,29 @@ static bool avr_run_command(uint8_t opcode, uint8_t *data, size_t data_length) return success; } +static bool avr_hid_get_state(void) +{ + uint8_t state[8]; + if (avr_run_command(CMD_STATE, state, sizeof(state))) + { + avr_battery_status = state[6]; + avr_battery_level = state[7]; + parse_button_state(state); + return true; + } + return false; +} static bool avr_hid_sync(void) { - uint8_t data; int retry; for (retry = 0; retry < AVR_MAX_RETRIES; retry++) { - if (avr_run_command(CMD_VER, &data, sizeof(data))) + if (avr_hid_get_state()) { return true; } + mdelay(100); } /* TODO: Program HID as it appears to be not programmed. * To do so, unfortunately, AVR firmware would have to be written @@ -509,17 +521,6 @@ bool charging_state(void) return (avr_battery_status & BATTERY_STATUS_CHARGING) != 0; } -static void avr_hid_get_state(void) -{ - uint8_t state[8]; - if (avr_execute_command(CMD_STATE, state, sizeof(state))) - { - avr_battery_status = state[6]; - avr_battery_level = state[7]; - parse_button_state(state); - } -} - static uint32_t avr_hid_get_monotime(void) { uint8_t tmp[4]; |