Skip to content

Commit 0223656

Browse files
committed
Create separate library for reset interface
1 parent e14bb98 commit 0223656

File tree

4 files changed

+120
-91
lines changed

4 files changed

+120
-91
lines changed

src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,74 +26,4 @@
2626
// regular flash boot
2727
#define RESET_REQUEST_FLASH 0x02
2828

29-
// These defines are only used on device
30-
#if PICO_ON_DEVICE
31-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=pico_stdio_usb
32-
33-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=pico_stdio_usb
34-
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW
35-
#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0
36-
#endif
37-
38-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb
39-
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
40-
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0
41-
#endif
42-
43-
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE.
44-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb
45-
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK
46-
#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u
47-
#endif
48-
49-
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb
50-
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
51-
#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE
52-
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1
53-
#else
54-
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0
55-
#endif
56-
#endif
57-
58-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_stdio_usb
59-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
60-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1
61-
#endif
62-
63-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_stdio_usb
64-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
65-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1
66-
#endif
67-
68-
// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_stdio_usb
69-
#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS
70-
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100
71-
#endif
72-
73-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1 when using default USB descriptors, 0 otherwise, group=pico_stdio_usb
74-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
75-
#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
76-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1
77-
#else
78-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0
79-
#endif
80-
#endif
81-
82-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included the USB interface number for the reset interface, type=int, default=2 when using default USB descriptors, undefined otherwise, group=pico_stdio_usb
83-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF
84-
#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
85-
#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2
86-
#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
87-
#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors
88-
#endif
89-
#endif
90-
91-
// Interface descriptor
92-
#define TUD_RPI_RESET_DESC_LEN 9
93-
#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \
94-
/* Interface */\
95-
TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx
96-
97-
#endif // PICO_ON_DEVICE
98-
9929
#endif

src/rp2_common/pico_stdio_usb/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
if (TARGET tinyusb_device_unmarked)
2+
pico_add_library(pico_stdio_usb_reset_interface)
3+
4+
target_include_directories(pico_stdio_usb_reset_interface_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
5+
6+
target_sources(pico_stdio_usb_reset_interface INTERFACE
7+
${CMAKE_CURRENT_LIST_DIR}/reset_interface.c
8+
)
9+
10+
pico_mirrored_target_link_libraries(pico_stdio_usb_reset_interface INTERFACE
11+
pico_usb_reset_interface
12+
)
13+
target_link_libraries(pico_stdio_usb_reset_interface INTERFACE
14+
tinyusb_device_unmarked
15+
)
16+
217
pico_add_library(pico_stdio_usb)
318

419
target_include_directories(pico_stdio_usb_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
520

621
target_sources(pico_stdio_usb INTERFACE
7-
${CMAKE_CURRENT_LIST_DIR}/reset_interface.c
822
${CMAKE_CURRENT_LIST_DIR}/stdio_usb.c
923
${CMAKE_CURRENT_LIST_DIR}/stdio_usb_descriptors.c
1024
)
@@ -13,7 +27,7 @@ if (TARGET tinyusb_device_unmarked)
1327
pico_stdio
1428
pico_time
1529
pico_unique_id
16-
pico_usb_reset_interface
30+
pico_stdio_usb_reset_interface
1731
)
1832
target_link_libraries(pico_stdio_usb INTERFACE
1933
tinyusb_device_unmarked

src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,101 @@
1010
// definitions have been moved here
1111
#include "pico/usb_reset_interface.h"
1212

13+
#if PICO_ON_DEVICE
14+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=pico_stdio_usb
15+
16+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=pico_stdio_usb
17+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW
18+
#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0
19+
#endif
20+
21+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb
22+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
23+
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0
24+
#endif
25+
26+
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE.
27+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb
28+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK
29+
#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u
30+
#endif
31+
32+
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb
33+
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
34+
#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE
35+
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1
36+
#else
37+
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0
38+
#endif
39+
#endif
40+
41+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1, group=pico_stdio_usb
42+
#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB
43+
#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB 1
44+
#endif
45+
46+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_stdio_usb
47+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
48+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1
49+
#endif
50+
51+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_stdio_usb
52+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
53+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1
54+
#endif
55+
56+
// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_stdio_usb
57+
#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS
58+
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100
59+
#endif
60+
61+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1 when using default USB descriptors, 0 otherwise, group=pico_stdio_usb
62+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
63+
#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
64+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1
65+
#else
66+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0
67+
#endif
68+
#endif
69+
70+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included the USB interface number for the reset interface, type=int, default=2 when using default USB descriptors, undefined otherwise, group=pico_stdio_usb
71+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF
72+
#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
73+
#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2
74+
#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
75+
#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors
76+
#endif
77+
#endif
78+
79+
// Interface descriptor
80+
#define TUD_RPI_RESET_DESC_LEN 9
81+
#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \
82+
/* Interface */\
83+
TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx
84+
85+
86+
#include "stdint.h"
87+
#include "device/usbd_pvt.h"
88+
89+
void resetd_init(void);
90+
void resetd_reset(uint8_t __unused rhport);
91+
uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
92+
bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request);
93+
bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes);
94+
95+
static usbd_class_driver_t const _resetd_driver =
96+
{
97+
#if CFG_TUSB_DEBUG >= 2
98+
.name = "RESET",
99+
#endif
100+
.init = resetd_init,
101+
.reset = resetd_reset,
102+
.open = resetd_open,
103+
.control_xfer_cb = resetd_control_xfer_cb,
104+
.xfer_cb = resetd_xfer_cb,
105+
.sof = NULL
106+
};
107+
108+
#endif
109+
13110
#endif

src/rp2_common/pico_stdio_usb/reset_interface.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
1818
#include "hardware/watchdog.h"
19-
#include "device/usbd_pvt.h"
2019

2120
static uint8_t itf_num;
2221

@@ -89,14 +88,14 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
8988
}
9089
#endif
9190

92-
static void resetd_init(void) {
91+
void resetd_init(void) {
9392
}
9493

95-
static void resetd_reset(uint8_t __unused rhport) {
94+
void resetd_reset(uint8_t __unused rhport) {
9695
itf_num = 0;
9796
}
9897

99-
static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
98+
uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
10099
TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass &&
101100
RESET_INTERFACE_SUBCLASS == itf_desc->bInterfaceSubClass &&
102101
RESET_INTERFACE_PROTOCOL == itf_desc->bInterfaceProtocol, 0);
@@ -109,7 +108,7 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const
109108
}
110109

111110
// Support for parameterized reset via vendor interface control request
112-
static bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) {
111+
bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) {
113112
// nothing to do with DATA & ACK stage
114113
if (stage != CONTROL_STAGE_SETUP) return true;
115114

@@ -146,29 +145,18 @@ static bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_
146145
return false;
147146
}
148147

149-
static bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) {
148+
bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) {
150149
return true;
151150
}
152151

153-
static usbd_class_driver_t const _resetd_driver =
154-
{
155-
#if CFG_TUSB_DEBUG >= 2
156-
.name = "RESET",
157-
#endif
158-
.init = resetd_init,
159-
.reset = resetd_reset,
160-
.open = resetd_open,
161-
.control_xfer_cb = resetd_control_xfer_cb,
162-
.xfer_cb = resetd_xfer_cb,
163-
.sof = NULL
164-
};
165-
152+
#if PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB
166153
// Implement callback to add our custom driver
167154
usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) {
168155
*driver_count = 1;
169156
return &_resetd_driver;
170157
}
171158
#endif
159+
#endif
172160

173161
#if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE
174162
// Support for default BOOTSEL reset by changing baud rate

0 commit comments

Comments
 (0)