Merge pull request #7702 from dhalbert/tinyusb-update

update tinyusb to latest
This commit is contained in:
Scott Shawcroft 2023-03-14 09:59:45 -07:00 committed by GitHub
commit 141a43cdce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 34 deletions

@ -1 +1 @@
Subproject commit 73896a3b71c525a3ee4cefa7e35ce3b3a93786ef
Subproject commit ea8ecea59aa60a1028cce16b0f15bb33918b11af

View File

@ -18,6 +18,8 @@
#define PICO_NO_HARDWARE (0)
#define PICO_ON_DEVICE (1)
#define PICO_PRINTF_ALWAYS_INCLUDED (1)
#define PICO_RP2040_USB_DEVICE_ENUMERATION_FIX (1)
#define PICO_RP2040_USB_DEVICE_UFRAME_FIX (1)
#define PICO_STDIO_IGNORE_NESTED_STDOUT (0)
#define PICO_USE_CRT_PRINTF (0)
#define PICO_USE_OPTIMISTIC_SBRK (0)

View File

@ -39,15 +39,8 @@ STATIC void _usb_irq_wrapper(void) {
}
void post_usb_init(void) {
irq_set_enabled(USBCTRL_IRQ, false);
irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ);
if (usb_handler) {
irq_remove_handler(USBCTRL_IRQ, usb_handler);
}
irq_set_exclusive_handler(USBCTRL_IRQ, _usb_irq_wrapper);
irq_set_enabled(USBCTRL_IRQ, true);
irq_add_shared_handler(USBCTRL_IRQ, _usb_irq_wrapper,
PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY);
// There is a small window where the USB interrupt may be handled by the
// pico-sdk instead of CircuitPython. If that is the case, then we'll have

View File

@ -215,7 +215,7 @@ ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0)
endif
ifneq ($(CIRCUITPY_USB),0)
SRC_C += lib/tinyusb/src/portable/st/synopsys/dcd_synopsys.c
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c
endif
SRC_S = \

View File

@ -61,12 +61,9 @@ uint16_t common_hal_usb_core_device_get_idProduct(usb_core_device_obj_t *self) {
}
STATIC xfer_result_t _get_string_result;
STATIC bool _transfer_done_cb(uint8_t daddr, tusb_control_request_t const *request, xfer_result_t result) {
// Store the result so we stop waiting for the transfer. We don't need the other data for now.
(void)daddr;
(void)request;
_get_string_result = result;
return true;
STATIC void _transfer_done_cb(tuh_xfer_t *xfer) {
// Store the result so we stop waiting for the transfer.
_get_string_result = xfer->result;
}
STATIC void _wait_for_callback(void) {
@ -89,7 +86,7 @@ STATIC mp_obj_t _get_string(const uint16_t *temp_buf) {
mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *self) {
_get_string_result = 0xff;
uint16_t temp_buf[127];
if (!tuh_descriptor_string_serial_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) {
if (!tuh_descriptor_get_serial_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) {
return mp_const_none;
}
_wait_for_callback();
@ -99,7 +96,7 @@ mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *sel
mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) {
_get_string_result = 0xff;
uint16_t temp_buf[127];
if (!tuh_descriptor_string_product_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) {
if (!tuh_descriptor_get_product_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) {
return mp_const_none;
}
_wait_for_callback();
@ -109,7 +106,7 @@ mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) {
mp_obj_t common_hal_usb_core_device_get_manufacturer(usb_core_device_obj_t *self) {
_get_string_result = 0xff;
uint16_t temp_buf[127];
if (!tuh_descriptor_string_manufacturer_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) {
if (!tuh_descriptor_get_manufacturer_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) {
return mp_const_none;
}
_wait_for_callback();
@ -125,11 +122,8 @@ mp_obj_t common_hal_usb_core_device_read(usb_core_device_obj_t *self, mp_int_t e
}
xfer_result_t control_result;
STATIC bool _control_complete_cb(uint8_t dev_addr, tusb_control_request_t const *request, xfer_result_t result) {
(void)dev_addr;
(void)request;
control_result = result;
return true;
STATIC void _control_complete_cb(tuh_xfer_t *xfer) {
control_result = xfer->result;
}
mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
@ -145,11 +139,17 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
.wIndex = wIndex,
.wLength = len
};
tuh_xfer_t xfer = {
.daddr = self->device_number,
.ep_addr = 0,
.setup = &request,
.buffer = buffer,
.complete_cb = _control_complete_cb,
};
control_result = XFER_RESULT_STALLED;
bool result = tuh_control_xfer(self->device_number,
&request,
buffer,
_control_complete_cb);
bool result = tuh_control_xfer(&xfer);
if (!result) {
mp_raise_usb_core_USBError(NULL);
}

View File

@ -225,13 +225,17 @@ void usb_background_schedule(void) {
}
void usb_irq_handler(int instance) {
#if CFG_TUSB_MCU != OPT_MCU_RP2040
// For rp2040, IRQ handler is already installed and invoked automatically
if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) {
tud_int_handler(instance);
} else if (instance == CIRCUITPY_USB_HOST_INSTANCE) {
#if CIRCUITPY_USB_HOST
tuh_int_handler(instance);
#endif
}
#if CIRCUITPY_USB_HOST
else if (instance == CIRCUITPY_USB_HOST_INSTANCE) {
tuh_int_handler(instance);
}
#endif
#endif
usb_background_schedule();
}

View File

@ -163,7 +163,6 @@ ifeq ($(CIRCUITPY_USB),1)
SRC_SUPERVISOR += \
lib/tinyusb/src/host/hub.c \
lib/tinyusb/src/host/usbh.c \
lib/tinyusb/src/host/usbh_control.c \
endif
endif