Skip to content

Commit dc20136

Browse files
roma-jamespressif-bot
authored andcommitted
feat(tusb_hid_example): Added possibility to wakeup the Host with the button press
1 parent 2104c05 commit dc20136

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

examples/peripherals/usb/device/tusb_hid/main/tusb_hid_example_main.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#define APP_BUTTON (GPIO_NUM_0) // Use BOOT signal by default
1717
static const char *TAG = "example";
1818

19+
/* Flag to indicate if the host has suspended the USB bus */
20+
static bool suspended = false;
21+
/* Flag of possibility to Wakeup Host via Remote Wakeup feature */
22+
static bool wakeup_host = false;
23+
1924
/************* TinyUSB descriptors ****************/
2025

2126
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_HID * TUD_HID_DESC_LEN)
@@ -152,6 +157,24 @@ static void app_send_hid_demo(void)
152157
}
153158
}
154159

160+
void tud_suspend_cb(bool remote_wakeup_en)
161+
{
162+
ESP_LOGI(TAG, "USB device suspended");
163+
suspended = true;
164+
if (remote_wakeup_en) {
165+
ESP_LOGI(TAG, "Remote wakeup available, press the button to wake up the Host");
166+
wakeup_host = true;
167+
} else {
168+
ESP_LOGI(TAG, "Remote wakeup not available");
169+
}
170+
}
171+
172+
void tud_resume_cb(void)
173+
{
174+
ESP_LOGI(TAG, "USB device resumed");
175+
suspended = false;
176+
}
177+
155178
void app_main(void)
156179
{
157180
// Initialize button that will trigger HID reports
@@ -182,7 +205,17 @@ void app_main(void)
182205
if (tud_mounted()) {
183206
static bool send_hid_data = true;
184207
if (send_hid_data) {
185-
app_send_hid_demo();
208+
if (!suspended) {
209+
app_send_hid_demo();
210+
} else {
211+
if (wakeup_host) {
212+
ESP_LOGI(TAG, "Waking up the Host");
213+
tud_remote_wakeup();
214+
wakeup_host = false;
215+
} else {
216+
ESP_LOGI(TAG, "USB Host remote wakeup is not available.");
217+
}
218+
}
186219
}
187220
send_hid_data = !gpio_get_level(APP_BUTTON);
188221
}

0 commit comments

Comments
 (0)