From eb56592992930c5e45218b872bae87f603e0f6de Mon Sep 17 00:00:00 2001 From: Kamil Rogozinski Date: Wed, 30 Aug 2023 22:24:29 +0800 Subject: [PATCH] native/platform: flash error led using morse subsystem to indicate no USB host present. --- src/platforms/common/stm32/timing_stm32.c | 14 ++++++++++++++ src/platforms/common/usb.c | 20 ++++++++++++++++++++ src/platforms/common/usb.h | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/src/platforms/common/stm32/timing_stm32.c b/src/platforms/common/stm32/timing_stm32.c index 0f6edf53d4e..9a94364bc76 100644 --- a/src/platforms/common/stm32/timing_stm32.c +++ b/src/platforms/common/stm32/timing_stm32.c @@ -21,6 +21,7 @@ #include "general.h" #include "platform.h" #include "morse.h" +#include "usb.h" #include #include @@ -44,6 +45,18 @@ static uint8_t monitor_ticks = 0; #define ADC_VREFINT_MIN 1404U #endif +static void usb_config_morse_msg_update(void) +{ + if (usb_config_is_updated()) { + if (usb_config == 0) + morse("NO USB HOST.", true); + else + morse(NULL, false); + + usb_config_clear_updated(); + } +} + void platform_timing_init(void) { /* Setup heartbeat timer */ @@ -71,6 +84,7 @@ void sys_tick_handler(void) if (morse_tick >= MORSECNT) { if (running_status) gpio_toggle(LED_PORT, LED_IDLE_RUN); + usb_config_morse_msg_update(); SET_ERROR_STATE(morse_update()); morse_tick = 0; } else diff --git a/src/platforms/common/usb.c b/src/platforms/common/usb.c index 882d7b88fb5..7baa04d8cf4 100644 --- a/src/platforms/common/usb.c +++ b/src/platforms/common/usb.c @@ -40,6 +40,15 @@ static uint8_t usbd_control_buffer[512]; * to fit your EP0 transactions. */ +static bool usb_config_updated = true; + +static void usb_config_set_updated(usbd_device *const dev, const uint16_t value) +{ + (void)dev; + (void)value; + usb_config_updated = true; +} + void blackmagic_usb_init(void) { read_serial_number(); @@ -51,6 +60,7 @@ void blackmagic_usb_init(void) microsoft_os_register_descriptor_sets(usbdev, microsoft_os_descriptor_sets, DESCRIPTOR_SETS); usbd_register_set_config_callback(usbdev, usb_serial_set_config); usbd_register_set_config_callback(usbdev, dfu_set_config); + usbd_register_set_config_callback(usbdev, usb_config_set_updated); nvic_set_priority(USB_IRQ, IRQ_PRI_USB); nvic_enable_irq(USB_IRQ); @@ -65,3 +75,13 @@ void USB_ISR(void) { usbd_poll(usbdev); } + +bool usb_config_is_updated(void) +{ + return usb_config_updated; +} + +void usb_config_clear_updated(void) +{ + usb_config_updated = false; +} diff --git a/src/platforms/common/usb.h b/src/platforms/common/usb.h index 4693829ef6d..336d075b2f3 100644 --- a/src/platforms/common/usb.h +++ b/src/platforms/common/usb.h @@ -58,4 +58,10 @@ void blackmagic_usb_init(void); /* Returns current usb configuration, or 0 if not configured. */ uint16_t usb_get_config(void); +/* Returns true if usb config has been updated. */ +bool usb_config_is_updated(void); + +/* Clears usb config updated flag. */ +void usb_config_clear_updated(void); + #endif /* PLATFORMS_COMMON_USB_H */