summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/export/events.h12
-rw-r--r--firmware/usb.c8
-rw-r--r--uisimulator/common/sim_tasks.c7
3 files changed, 24 insertions, 3 deletions
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 @@
52#define EVENT_CLASS_RECORDING 0x1000 52#define EVENT_CLASS_RECORDING 0x1000
53#define EVENT_CLASS_LCD 0x2000 53#define EVENT_CLASS_LCD 0x2000
54#define EVENT_CLASS_VOICE 0x4000 54#define EVENT_CLASS_VOICE 0x4000
55 55#define EVENT_CLASS_SYSTEM 0x8000 /*LAST ONE */
56/** 56/**
57 * Subscribe to an event with a simple callback. The callback will be called 57 * Subscribe to an event with a simple callback. The callback will be called
58 * synchronously everytime the event fires, passing the event id and data to 58 * 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
99 */ 99 */
100void send_event(unsigned short id, void *data); 100void send_event(unsigned short id, void *data);
101 101
102/** System events **/
103enum {
104 /* USB_INSERTED
105 data = &usbmode */
106 SYS_EVENT_USB_INSERTED = (EVENT_CLASS_SYSTEM|1),
107 /* USB_EXTRACTED
108 data = NULL */
109 SYS_EVENT_USB_EXTRACTED,
110};
111
102#endif 112#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)
476 usb_state = USB_POWERED; 476 usb_state = USB_POWERED;
477 477
478 usb_stack_enable(true); 478 usb_stack_enable(true);
479 479#ifndef BOOTLOADER
480 send_event(SYS_EVENT_USB_INSERTED, &usb_mode);
481#endif
480 /* Power (charging-only) button */ 482 /* Power (charging-only) button */
481#ifdef HAVE_USB_POWER 483#ifdef HAVE_USB_POWER
482 new_usbmode = usb_mode; 484 new_usbmode = usb_mode;
@@ -547,7 +549,9 @@ static void NORETURN_ATTR usb_thread(void)
547#ifdef HAVE_USB_POWER 549#ifdef HAVE_USB_POWER
548 new_usbmode = usb_mode; 550 new_usbmode = usb_mode;
549#endif 551#endif
550 552#ifndef BOOTLOADER
553 send_event(SYS_EVENT_USB_EXTRACTED, NULL);
554#endif
551 usb_set_host_present(false); 555 usb_set_host_present(false);
552 break; 556 break;
553 /* USB_EXTRACTED: */ 557 /* 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)
145static bool is_usb_inserted; 145static bool is_usb_inserted;
146void sim_trigger_usb(bool inserted) 146void sim_trigger_usb(bool inserted)
147{ 147{
148 int usbmode = 0;
148 if (inserted) 149 if (inserted)
150 {
151 send_event(SYS_EVENT_USB_INSERTED, &usbmode);
149 queue_post(&sim_queue, SIM_USB_INSERTED, 0); 152 queue_post(&sim_queue, SIM_USB_INSERTED, 0);
153 }
150 else 154 else
155 {
156 send_event(SYS_EVENT_USB_EXTRACTED, NULL);
151 queue_post(&sim_queue, SIM_USB_EXTRACTED, 0); 157 queue_post(&sim_queue, SIM_USB_EXTRACTED, 0);
158 }
152 is_usb_inserted = inserted; 159 is_usb_inserted = inserted;
153} 160}
154 161