Skip to content

Commit

Permalink
native/platform: flash error led using morse subsystem to indicate no…
Browse files Browse the repository at this point in the history
… USB host present.
  • Loading branch information
krogozinski authored and dragonmux committed Sep 15, 2023
1 parent 8d7d064 commit 3eabf98
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/platforms/common/stm32/timing_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "general.h"
#include "platform.h"
#include "morse.h"
#include "usb.h"

#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/nvic.h>
Expand All @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/platforms/common/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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;
}
6 changes: 6 additions & 0 deletions src/platforms/common/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 3eabf98

Please sign in to comment.