diff --git a/firmware/export/events.h b/firmware/export/events.h index 4591058d4f..8bdf1b55e2 100644 --- a/firmware/export/events.h +++ b/firmware/export/events.h @@ -52,7 +52,7 @@ #define EVENT_CLASS_RECORDING 0x1000 #define EVENT_CLASS_LCD 0x2000 #define EVENT_CLASS_VOICE 0x4000 - +#define EVENT_CLASS_SYSTEM 0x8000 /*LAST ONE */ /** * Subscribe to an event with a simple callback. The callback will be called * synchronously everytime the event fires, passing the event id and data to @@ -99,4 +99,14 @@ void remove_event_ex(unsigned short id, void (*handler)(unsigned short id, void */ void send_event(unsigned short id, void *data); +/** System events **/ +enum { + /* USB_INSERTED + data = &usbmode */ + SYS_EVENT_USB_INSERTED = (EVENT_CLASS_SYSTEM|1), + /* USB_EXTRACTED + data = NULL */ + SYS_EVENT_USB_EXTRACTED, +}; + #endif diff --git a/firmware/usb.c b/firmware/usb.c index b919fe468d..9d071578b5 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -476,7 +476,9 @@ static void NORETURN_ATTR usb_thread(void) usb_state = USB_POWERED; usb_stack_enable(true); - +#ifndef BOOTLOADER + send_event(SYS_EVENT_USB_INSERTED, &usb_mode); +#endif /* Power (charging-only) button */ #ifdef HAVE_USB_POWER new_usbmode = usb_mode; @@ -547,7 +549,9 @@ static void NORETURN_ATTR usb_thread(void) #ifdef HAVE_USB_POWER new_usbmode = usb_mode; #endif - +#ifndef BOOTLOADER + send_event(SYS_EVENT_USB_EXTRACTED, NULL); +#endif usb_set_host_present(false); break; /* USB_EXTRACTED: */ diff --git a/uisimulator/common/sim_tasks.c b/uisimulator/common/sim_tasks.c index c862d4d909..809b50569f 100644 --- a/uisimulator/common/sim_tasks.c +++ b/uisimulator/common/sim_tasks.c @@ -145,10 +145,17 @@ void sim_trigger_screendump(void) static bool is_usb_inserted; void sim_trigger_usb(bool inserted) { + int usbmode = 0; if (inserted) + { + send_event(SYS_EVENT_USB_INSERTED, &usbmode); queue_post(&sim_queue, SIM_USB_INSERTED, 0); + } else + { + send_event(SYS_EVENT_USB_EXTRACTED, NULL); queue_post(&sim_queue, SIM_USB_EXTRACTED, 0); + } is_usb_inserted = inserted; }