Skip to content

Commit c530dbd

Browse files
committed
Replace commulated USB callback with individual callbacks
1 parent 7b507b8 commit c530dbd

1 file changed

Lines changed: 13 additions & 28 deletions

File tree

lib/storage/storage.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,36 +106,20 @@ static void usb_started_cb(void *const pvParameters)
106106
vTaskDelete(nullptr);
107107
}
108108

109-
static void usbEventCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
109+
static bool usbIsRunning = false;
110+
static void usbStoppedCallback(void *, esp_event_base_t, int32_t, void *)
110111
{
111-
if (event_base == ARDUINO_USB_EVENTS)
112+
if (!usbIsRunning)
112113
{
113-
arduino_usb_event_data_t *data = (arduino_usb_event_data_t *)event_data;
114-
static int32_t old_event_id = ARDUINO_USB_ANY_EVENT;
115-
if (old_event_id == event_id)
116-
return;
117-
switch (event_id)
118-
{
119-
case ARDUINO_USB_STARTED_EVENT:
120-
HWSerial.println("USB PLUGGED");
121-
xTaskCreate(usb_started_cb, "USB_Started_CB", 4096, nullptr, 5, nullptr);
122-
break;
123-
case ARDUINO_USB_STOPPED_EVENT:
124-
HWSerial.println("USB UNPLUGGED");
125-
xTaskCreate(usb_stopped_cb, "USB_Stopped_CB", 4096, nullptr, 5, nullptr);
126-
break;
127-
case ARDUINO_USB_SUSPEND_EVENT:
128-
HWSerial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en);
129-
break;
130-
case ARDUINO_USB_RESUME_EVENT:
131-
HWSerial.println("USB RESUMED");
132-
break;
133-
134-
default:
135-
break;
136-
}
137-
old_event_id = event_id;
114+
return;
138115
}
116+
usbIsRunning = false;
117+
xTaskCreate(usb_stopped_cb, "USB_Stopped_CB", 4096, nullptr, 5, nullptr);
118+
}
119+
static void usbStartedCallback(void *, esp_event_base_t, int32_t, void *)
120+
{
121+
usbIsRunning = true;
122+
xTaskCreate(usb_started_cb, "USB_Started_CB", 4096, nullptr, 5, nullptr);
139123
}
140124

141125
const esp_partition_t *check_ffat_partition(const char *label); // defined in FFat.cpp
@@ -158,7 +142,8 @@ void Storage::begin()
158142
}
159143
HWSerial.printf("Flash has a size of %u bytes\n", FFat.totalBytes());
160144

161-
USB.onEvent(usbEventCallback);
145+
USB.onEvent(ARDUINO_USB_STARTED_EVENT, usbStartedCallback);
146+
USB.onEvent(ARDUINO_USB_STOPPED_EVENT, usbStoppedCallback);
162147
MSC.vendorID("ESP32"); // max 8 chars
163148
MSC.productID("USB_MSC"); // max 16 chars
164149
MSC.productRevision("1.0"); // max 4 chars

0 commit comments

Comments
 (0)