Skip to content

Commit 521b2f8

Browse files
projectgusdpgeorge
authored andcommitted
shared/tinyusb: Remove USBD_RHPORT constant.
TinyUSB defines TUD_OPT_RHPORT which is the same thing, make shorter definition RHPORT in the two files which use it. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 83131c1 commit 521b2f8

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

extmod/machine_usb_device.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#define HAS_BUILTIN_DRIVERS (MICROPY_HW_USB_CDC || MICROPY_HW_USB_MSC)
4444

45+
#define RHPORT TUD_OPT_RHPORT
46+
4547
const mp_obj_type_t machine_usb_device_type;
4648

4749
static mp_obj_t usb_device_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@@ -111,11 +113,11 @@ static mp_obj_t usb_device_submit_xfer(mp_obj_t self, mp_obj_t ep, mp_obj_t buff
111113
mp_raise_ValueError(MP_ERROR_TEXT("ep"));
112114
}
113115

114-
if (!usbd_edpt_claim(USBD_RHPORT, ep_addr)) {
116+
if (!usbd_edpt_claim(RHPORT, ep_addr)) {
115117
mp_raise_OSError(MP_EBUSY);
116118
}
117119

118-
result = usbd_edpt_xfer(USBD_RHPORT, ep_addr, buf_info.buf, buf_info.len);
120+
result = usbd_edpt_xfer(RHPORT, ep_addr, buf_info.buf, buf_info.len);
119121

120122
if (result) {
121123
// Store the buffer object until the transfer completes
@@ -168,14 +170,14 @@ static mp_obj_t usb_device_stall(size_t n_args, const mp_obj_t *args) {
168170

169171
usb_device_check_active(self);
170172

171-
mp_obj_t res = mp_obj_new_bool(usbd_edpt_stalled(USBD_RHPORT, epnum));
173+
mp_obj_t res = mp_obj_new_bool(usbd_edpt_stalled(RHPORT, epnum));
172174

173175
if (n_args == 3) { // Set stall state
174176
mp_obj_t stall = args[2];
175177
if (mp_obj_is_true(stall)) {
176-
usbd_edpt_stall(USBD_RHPORT, epnum);
178+
usbd_edpt_stall(RHPORT, epnum);
177179
} else {
178-
usbd_edpt_clear_stall(USBD_RHPORT, epnum);
180+
usbd_edpt_clear_stall(RHPORT, epnum);
179181
}
180182
}
181183

shared/tinyusb/mp_usbd_runtime.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "device/usbd_pvt.h"
4545
#endif
4646

47+
#define RHPORT TUD_OPT_RHPORT
48+
4749
static bool in_usbd_task; // Flags if mp_usbd_task() is currently running
4850

4951
// Some top-level functions that manage global TinyUSB USBD state, not the
@@ -233,7 +235,7 @@ static uint16_t _runtime_dev_claim_itfs(tusb_desc_interface_t const *itf_desc, u
233235
} else if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT) {
234236
// Open any endpoints that we come across
235237
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT) {
236-
bool r = usbd_edpt_open(USBD_RHPORT, (const void *)p_desc);
238+
bool r = usbd_edpt_open(RHPORT, (const void *)p_desc);
237239
if (!r) {
238240
mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENODEV));
239241
usbd_pend_exception(exc);
@@ -322,7 +324,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
322324

323325
// Check if callback returned any data to submit
324326
if (mp_get_buffer(cb_res, &buf_info, dir == TUSB_DIR_IN ? MP_BUFFER_READ : MP_BUFFER_RW)) {
325-
result = tud_control_xfer(USBD_RHPORT,
327+
result = tud_control_xfer(RHPORT,
326328
request,
327329
buf_info.buf,
328330
buf_info.len);
@@ -468,7 +470,7 @@ static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd) {
468470
for (int epnum = 0; epnum < CFG_TUD_ENDPPOINT_MAX; epnum++) {
469471
for (int dir = 0; dir < 2; dir++) {
470472
if (usbd->xfer_data[epnum][dir] != mp_const_none) {
471-
usbd_edpt_stall(USBD_RHPORT, tu_edpt_addr(epnum, dir));
473+
usbd_edpt_stall(RHPORT, tu_edpt_addr(epnum, dir));
472474
usbd->xfer_data[epnum][dir] = mp_const_none;
473475
}
474476
}
@@ -479,7 +481,7 @@ static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd) {
479481
// Ensure no pending static CDC writes, as these can cause TinyUSB to crash
480482
tud_cdc_write_clear();
481483
// Prevent cdc write flush from initiating any new transfers while disconnecting
482-
usbd_edpt_stall(USBD_RHPORT, USBD_CDC_EP_IN);
484+
usbd_edpt_stall(RHPORT, USBD_CDC_EP_IN);
483485
#endif
484486

485487
bool was_connected = tud_connected();

shared/tinyusb/tusb_config.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#ifndef CFG_TUD_CDC_TX_BUFSIZE
8484
#define CFG_TUD_CDC_TX_BUFSIZE ((CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED) ? 512 : 256)
8585
#endif
86-
#endif
86+
#endif // CFG_TUD_CDC
8787

8888
// MSC Configuration
8989
#if CFG_TUD_MSC
@@ -92,9 +92,7 @@
9292
#endif
9393
// Set MSC EP buffer size to FatFS block size to avoid partial read/writes (offset arg).
9494
#define CFG_TUD_MSC_BUFSIZE (MICROPY_FATFS_MAX_SS)
95-
#endif
96-
97-
#define USBD_RHPORT (0) // Currently only one port is supported
95+
#endif // CFG_TUD_MSC
9896

9997
// Define built-in interface, string and endpoint numbering based on the above config
10098

0 commit comments

Comments
 (0)