|
16 | 16 | #define APP_BUTTON (GPIO_NUM_0) // Use BOOT signal by default |
17 | 17 | static const char *TAG = "example"; |
18 | 18 |
|
| 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 | + |
19 | 24 | /************* TinyUSB descriptors ****************/ |
20 | 25 |
|
21 | 26 | #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) |
152 | 157 | } |
153 | 158 | } |
154 | 159 |
|
| 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 | + |
155 | 178 | void app_main(void) |
156 | 179 | { |
157 | 180 | // Initialize button that will trigger HID reports |
@@ -182,7 +205,17 @@ void app_main(void) |
182 | 205 | if (tud_mounted()) { |
183 | 206 | static bool send_hid_data = true; |
184 | 207 | 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 | + } |
186 | 219 | } |
187 | 220 | send_hid_data = !gpio_get_level(APP_BUTTON); |
188 | 221 | } |
|
0 commit comments