|
5 | 5 | */ |
6 | 6 | #include "tusb.h" |
7 | 7 |
|
8 | | -#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE |
9 | 8 | #include "pico/bootrom.h" |
| 9 | + |
| 10 | +#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && !(PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) |
| 11 | +#warning PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. |
| 12 | +#endif |
| 13 | + |
| 14 | +#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE |
10 | 15 | #include "pico/stdio_usb/reset_interface.h" |
11 | 16 | #include "hardware/watchdog.h" |
12 | 17 | #include "device/usbd_pvt.h" |
@@ -35,22 +40,31 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const |
35 | 40 | // Support for parameterized reset via vendor interface control request |
36 | 41 | static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_request_t const *request) { |
37 | 42 | if (request->wIndex == itf_num) { |
| 43 | + |
38 | 44 | #if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL |
39 | 45 | if (request->bRequest == RESET_REQUEST_BOOTSEL) { |
40 | | - uint gpio_mask = 0; |
| 46 | +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED |
| 47 | + uint gpio_mask = 1u << PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED; |
| 48 | +#else |
| 49 | + uint gpio_mask = 0u; |
| 50 | +#endif |
| 51 | +#if !PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED |
41 | 52 | if (request->wValue & 0x100) { |
42 | 53 | gpio_mask = 1u << (request->wValue >> 9u); |
43 | 54 | } |
44 | | - reset_usb_boot(gpio_mask, request->wValue & 0x7f); |
| 55 | +#endif |
| 56 | + reset_usb_boot(gpio_mask, (request->wValue & 0x7f) | PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK); |
45 | 57 | // does not return, otherwise we'd return true |
46 | 58 | } |
47 | 59 | #endif |
| 60 | + |
48 | 61 | #if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT |
49 | 62 | if (request->bRequest == RESET_REQUEST_FLASH) { |
50 | 63 | watchdog_reboot(0, SRAM_END, PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS); |
51 | 64 | return true; |
52 | 65 | } |
53 | 66 | #endif |
| 67 | + |
54 | 68 | } |
55 | 69 | return false; |
56 | 70 | } |
@@ -88,7 +102,12 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { |
88 | 102 | // Support for default BOOTSEL reset by changing baud rate |
89 | 103 | void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding) { |
90 | 104 | if (p_line_coding->bit_rate == PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE) { |
91 | | - reset_usb_boot(0, 0); |
| 105 | +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED |
| 106 | + const uint gpio_mask = 1u << PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED; |
| 107 | +#else |
| 108 | + const uint gpio_mask = 0u; |
| 109 | +#endif |
| 110 | + reset_usb_boot(gpio_mask, PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK); |
92 | 111 | } |
93 | 112 | } |
94 | 113 | #endif |
|
0 commit comments