feat(radio): OS compatibility layer (#5840)

This commit is contained in:
Raphael Coeffic
2025-05-03 19:07:49 +10:00
committed by GitHub
parent c996612b0a
commit ab2a19e153
92 changed files with 1740 additions and 896 deletions
@@ -22,6 +22,7 @@
#include "hal/gpio.h"
#include "hal/audio_driver.h"
#include "os/sleep.h"
#include "stm32_gpio.h"
#include "stm32_timer.h"
#include "stm32_dma.h"
@@ -162,7 +163,7 @@ void audioUnmute()
if (get_mute_pin()) {
// ..un-mute
set_mute_pin(false);
RTOS_WAIT_MS(AUDIO_UNMUTE_DELAY);
sleep_ms(AUDIO_UNMUTE_DELAY);
}
// reset the mute delay
audioQueue.lastAudioPlayTime = 0;
@@ -6,6 +6,8 @@ AddHWGenTarget(${HW_DESC_JSON} hal_keys hal_keys.inc)
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
${CMAKE_CURRENT_BINARY_DIR}/hal_keys.inc
${RADIO_SRC_DIR}/os/time_nortos.cpp
${RADIO_SRC_DIR}/os/sleep_nortos.cpp
${RADIO_SRC_DIR}/keys.cpp
${RADIO_SRC_DIR}/strhelpers.cpp
${RADIO_SRC_DIR}/stamp.cpp
@@ -135,6 +135,11 @@ void bootloaderInitApp()
boardBLInit();
}
#if defined(FIRMWARE_FORMAT_UF2)
// make linker happy
void per5ms() {}
#endif
int main()
#else // SIMU
void bootloaderInitApp() {}
@@ -2,9 +2,11 @@
#include "boot.h"
#include "hal/usb_driver.h"
#include "os/time.h"
#include "lcd.h"
extern volatile uint8_t tenms;
#define FRAME_INTERVAL_MS 20
void bootloaderDFU()
{
@@ -13,8 +15,11 @@ void bootloaderDFU()
bootloaderDrawDFUScreen();
uint32_t next_frame = time_get_ms();
for (;;) {
if (tenms) {
if (time_get_ms() - next_frame >= FRAME_INTERVAL_MS) {
next_frame += FRAME_INTERVAL_MS;
if (!usbPlugged()) break;
bootloaderDrawDFUScreen();
lcdRefresh();
@@ -3,9 +3,12 @@
#include "hal/usb_driver.h"
#include "hal/rotary_encoder.h"
#include "os/time.h"
#include "lcd.h"
#define FRAME_INTERVAL_MS 20
#if defined(SPI_FLASH)
#define MAIN_MENU_LEN 3
#else
@@ -17,16 +20,8 @@
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
#endif
volatile tmr10ms_t g_tmr10ms;
volatile uint8_t tenms = 1;
void per5ms() {} // make linker happy
void per10ms()
void pollInputs()
{
tenms |= 1u; // 10 mS has passed
g_tmr10ms++;
keysPollingCycle();
// TODO: use rotaryEncoderPollingCycle() instead
@@ -42,6 +37,13 @@ void per10ms()
#endif
}
// poll inputs every 10ms
void per5ms()
{
static uint32_t cnt = 0;
if (++cnt & 1) { pollInputs(); }
}
FlashCheckRes valid;
int menuFlashFile(uint32_t index, event_t event)
@@ -74,10 +76,12 @@ void bootloaderMenu()
sdInit();
uint32_t next_frame = time_get_ms();
for (;;) {
if (tenms) {
tenms = 0;
if (time_get_ms() - next_frame >= FRAME_INTERVAL_MS) {
next_frame += FRAME_INTERVAL_MS;
if (state != ST_USB && state != ST_FLASHING
&& state != ST_FLASH_DONE && state != ST_RADIO_MENU) {
@@ -3,6 +3,7 @@
#include "hal/usb_driver.h"
#include "hal/storage.h"
#include "hal/fatfs_diskio.h"
#include "os/time.h"
#include "thirdparty/FatFs/diskio.h"
#include "drivers/uf2_ghostfat.h"
@@ -10,19 +11,10 @@
#include "board.h"
#include "lcd.h"
#define FRAME_INTERVAL_MS 20
extern uf2_fat_write_state_t _uf2_write_state;
volatile tmr10ms_t g_tmr10ms;
volatile uint8_t tenms = 1;
void per5ms() {} // make linker happy
void per10ms()
{
tenms |= 1u; // 10 mS has passed
g_tmr10ms++;
}
void bootloaderUF2()
{
BootloaderState state = ST_START;
@@ -31,10 +23,12 @@ void bootloaderUF2()
storageInit();
disk_initialize(0);
uint32_t next_frame = time_get_ms();
for (;;) {
if (tenms) {
tenms = 0;
if (time_get_ms() - next_frame >= FRAME_INTERVAL_MS) {
next_frame += FRAME_INTERVAL_MS;
if (state != ST_USB && state != ST_FLASHING && state != ST_FLASH_DONE) {
if (usbPlugged()) {
@@ -137,7 +137,7 @@ void rotaryEncoderCheck()
rotenc_t diff = (value - last_value);
if (diff != 0) {
uint32_t now = RTOS_GET_MS();
uint32_t now = timersGetMsTick();
uint32_t dt = now - last_tick;
// pre-compute accumulated dt (dx/dt is done later in LVGL driver)
rotencDt += dt;
@@ -100,8 +100,6 @@ static inline void _interrupt_1ms()
watchdogTimeout -= 1;
WDG_RESET(); // Retrigger hardware watchdog
}
per10ms();
}
}
@@ -21,6 +21,7 @@
#include "vs1053b.h"
#include "os/sleep.h"
#include "stm32_hal_ll.h"
#include "stm32_gpio_driver.h"
#include "stm32_gpio.h"
@@ -327,7 +328,7 @@ static void vs1053b_unmute()
if (_is_muted) {
// ..un-mute
_set_mute_pin(false);
RTOS_WAIT_MS(_instance->unmute_delay_ms);
sleep_ms(_instance->unmute_delay_ms);
}
// reset the mute delay
_last_play_ts = 0;