Skip to content

Commit 9b1b781

Browse files
authored
Merge pull request #3627 from hathach/merge-usbd-control
Refactor USB control transfer handling into `usbd.c`
2 parents 3170fa0 + 076fd79 commit 9b1b781

19 files changed

Lines changed: 371 additions & 489 deletions

File tree

hw/bsp/nrf/boards/nrf54h20dk/board.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
set(MCU_VARIANT nrf54h20)
22

33
function(update_board TARGET)
4-
# temporarily, 54h20 has multiple sram sections
4+
# 32 KB primary RAM is too tight for memory-heavy examples (e.g. video YUY2
5+
# framebuf). TODO: route static .bss to RAM00 (512 KB) and drop this.
56
target_compile_definitions(${TARGET} PUBLIC
67
CFG_EXAMPLE_VIDEO_READONLY
78
)

hw/bsp/nrf/boards/nrf54h20dk/board.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
MCU_VARIANT = nrf54h20
22
CFLAGS += -DNRF54H20_XXAA
33

4+
# 32 KB primary RAM is too tight for memory-heavy examples (e.g. video YUY2
5+
# framebuf). Match the CMake build (board.cmake) — TODO: route static .bss to
6+
# RAM00 (512 KB) and drop this.
7+
CFLAGS += -DCFG_EXAMPLE_VIDEO_READONLY
8+
49
# enable max3421 host driver for this board
510
MAX3421_HOST = 1
611

hw/bsp/nrf/boards/nrf54lm20dk/board.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ set(MCU_VARIANT nrf54lm20a_enga)
22
set(JLINK_DEVICE NRF54LM20A_M33)
33

44
function(update_board TARGET)
5-
target_compile_definitions(${TARGET} PUBLIC
6-
CFG_EXAMPLE_VIDEO_READONLY
7-
)
5+
# No board-specific overrides needed — primary 256 KB RAM is plenty for
6+
# memory-heavy examples (video YUY2 framebuf etc.).
87
endfunction()

hw/bsp/rp2040/family.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ target_sources(tinyusb_device_base INTERFACE
9393
${TOP}/src/portable/raspberrypi/rp2040/dcd_rp2040.c
9494
${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c
9595
${TOP}/src/device/usbd.c
96-
${TOP}/src/device/usbd_control.c
9796
${TOP}/src/class/audio/audio_device.c
9897
${TOP}/src/class/cdc/cdc_device.c
9998
${TOP}/src/class/dfu/dfu_device.c

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function(tinyusb_sources_get OUTPUT_VAR)
88
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/common/tusb_fifo.c
99
# device
1010
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/device/usbd.c
11-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/device/usbd_control.c
1211
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/audio/audio_device.c
1312
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/cdc/cdc_device.c
1413
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/dfu/dfu_device.c

src/class/hid/hid_host.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,31 @@ static uint8_t _hidh_default_protocol = HID_PROTOCOL_BOOT;
7474
// Weak stubs: invoked if no strong implementation is available
7575
//--------------------------------------------------------------------+
7676
TU_ATTR_WEAK void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report_desc, uint16_t desc_len) {
77-
(void) dev_addr;
78-
(void) idx;
79-
(void) report_desc;
80-
(void) desc_len;
77+
(void) dev_addr; (void) idx; (void) report_desc; (void) desc_len;
8178
}
8279

8380
TU_ATTR_WEAK void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t idx) {
84-
(void) dev_addr;
85-
(void) idx;
81+
(void) dev_addr; (void) idx;
82+
}
83+
84+
TU_ATTR_WEAK void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t idx, const uint8_t *report, uint16_t len) {
85+
(void) dev_addr; (void) idx; (void) report; (void) len;
8686
}
8787

8888
TU_ATTR_WEAK void tuh_hid_report_sent_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report, uint16_t len) {
89-
(void) dev_addr;
90-
(void) idx;
91-
(void) report;
92-
(void) len;
89+
(void) dev_addr; (void) idx; (void) report; (void) len;
9390
}
9491

9592
TU_ATTR_WEAK void tuh_hid_get_report_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_t report_type, uint16_t len) {
96-
(void) dev_addr;
97-
(void) idx;
98-
(void) report_id;
99-
(void) report_type;
100-
(void) len;
93+
(void) dev_addr; (void) idx; (void) report_id; (void) report_type; (void) len;
10194
}
10295

10396
TU_ATTR_WEAK void tuh_hid_set_report_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_t report_type, uint16_t len) {
104-
(void) dev_addr;
105-
(void) idx;
106-
(void) report_id;
107-
(void) report_type;
108-
(void) len;
97+
(void) dev_addr; (void) idx; (void) report_id; (void) report_type; (void) len;
10998
}
11099

111100
TU_ATTR_WEAK void tuh_hid_set_protocol_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t protocol) {
112-
(void) dev_addr;
113-
(void) idx;
114-
(void) protocol;
101+
(void) dev_addr; (void) idx; (void) protocol;
115102
}
116103

117104
//--------------------------------------------------------------------+

src/class/hid/hid_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx);
140140
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, const void *report, uint16_t len);
141141

142142
//--------------------------------------------------------------------+
143-
// Callbacks (Weak is optional)
143+
// Callbacks (optional)
144144
//--------------------------------------------------------------------+
145145

146146
// Invoked when device with hid interface is mounted

src/class/printer/printer_device.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ typedef struct {
4141
uint8_t itf_num;
4242

4343
/*------------- From this point, data is not cleared by bus reset -------------*/
44-
4544
tu_edpt_stream_t rx_stream;
4645
tu_edpt_stream_t tx_stream;
4746

src/common/tusb_private.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,10 @@ extern tusb_role_t _tusb_rhport_role[TUP_USBIP_CONTROLLER_NUM];
4646
// Endpoint
4747
//--------------------------------------------------------------------+
4848

49-
enum {
50-
TU_EDPT_STATE_BUSY = 0x01,
51-
TU_EDPT_STATE_STALLED = 0x02,
52-
TU_EDPT_STATE_CLAIMED = 0x04,
53-
};
54-
55-
typedef struct TU_ATTR_PACKED {
56-
volatile uint8_t busy : 1;
57-
volatile uint8_t stalled : 1;
58-
volatile uint8_t claimed : 1;
59-
} tu_edpt_state_t;
49+
// Endpoint state bits — manipulate the bare uint8_t with these masks.
50+
#define TU_EDPT_STATE_BUSY 0x01u
51+
#define TU_EDPT_STATE_STALLED 0x02u
52+
#define TU_EDPT_STATE_CLAIMED 0x04u
6053

6154
typedef struct {
6255
uint8_t hwid; // device: rhport, host: daddr
@@ -92,10 +85,10 @@ bool tu_bind_driver_to_ep_itf(uint8_t driver_id, uint8_t ep2drv[][2], uint8_t it
9285
const uint8_t *p_desc, uint16_t desc_len);
9386

9487
// Claim an endpoint with provided mutex
95-
bool tu_edpt_claim(tu_edpt_state_t* ep_state, osal_mutex_t mutex);
88+
bool tu_edpt_claim(volatile uint8_t* ep_state, osal_mutex_t mutex);
9689

9790
// Release an endpoint with provided mutex
98-
bool tu_edpt_release(tu_edpt_state_t* ep_state, osal_mutex_t mutex);
91+
bool tu_edpt_release(volatile uint8_t* ep_state, osal_mutex_t mutex);
9992

10093
//--------------------------------------------------------------------+
10194
// Endpoint Stream

0 commit comments

Comments
 (0)