fix(usb): Add support for HighSpeed USB
This commit adds support for HighSpeed USB as present on ESP32-P4
This commit is contained in:
parent
157b4c8643
commit
341dc18079
8 changed files with 29 additions and 10 deletions
|
|
@ -31,7 +31,7 @@ USBCDC *devices[MAX_USB_CDC_DEVICES] = {NULL, NULL};
|
|||
static uint16_t load_cdc_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC");
|
||||
uint8_t descriptor[TUD_CDC_DESC_LEN] = {// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(*itf, str_index, 0x85, 64, 0x03, 0x84, 64)
|
||||
TUD_CDC_DESCRIPTOR(*itf, str_index, 0x85, CFG_TUD_ENDOINT_SIZE, 0x03, 0x84, CFG_TUD_ENDOINT_SIZE)
|
||||
};
|
||||
*itf += 2;
|
||||
memcpy(dst, descriptor, TUD_CDC_DESC_LEN);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ extern "C" uint16_t tusb_msc_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
|||
uint8_t ep_num = tinyusb_get_free_duplex_endpoint();
|
||||
TU_VERIFY(ep_num != 0);
|
||||
uint8_t descriptor[TUD_MSC_DESC_LEN] = {// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), 64)
|
||||
TUD_MSC_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), CFG_TUD_ENDOINT_SIZE)
|
||||
};
|
||||
*itf += 1;
|
||||
memcpy(dst, descriptor, TUD_MSC_DESC_LEN);
|
||||
|
|
|
|||
|
|
@ -131,7 +131,11 @@ esp_err_t init_usb_hal(bool external_phy) {
|
|||
.controller = USB_PHY_CTRL_OTG,
|
||||
.target = USB_PHY_TARGET_INT,
|
||||
.otg_mode = USB_OTG_MODE_DEVICE,
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
.otg_speed = USB_PHY_SPEED_HIGH,
|
||||
#else
|
||||
.otg_speed = USB_PHY_SPEED_FULL,
|
||||
#endif
|
||||
.ext_io_conf = NULL,
|
||||
.otg_io_conf = NULL,
|
||||
};
|
||||
|
|
@ -169,7 +173,11 @@ void deinit_usb_hal() {
|
|||
|
||||
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) {
|
||||
init_usb_hal(config->external_phy);
|
||||
if (!tusb_init()) {
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
if (!tud_init(1)) {
|
||||
#else
|
||||
if (!tud_init(0)) {
|
||||
#endif
|
||||
log_e("Can't initialize the TinyUSB stack.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ extern "C" {
|
|||
#define USB_ESPRESSIF_VID 0x303A
|
||||
#define USB_STRING_DESCRIPTOR_ARRAY_SIZE 10
|
||||
|
||||
#ifndef CFG_TUD_ENDOINT_SIZE
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
#define CFG_TUD_ENDOINT_SIZE 512
|
||||
#else
|
||||
#define CFG_TUD_ENDOINT_SIZE 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint16_t vid;
|
||||
uint16_t pid;
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ extern "C" uint16_t tusb_hid_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
|||
uint8_t descriptor[TUD_HID_INOUT_DESC_LEN] = {
|
||||
// HID Input & Output descriptor
|
||||
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
|
||||
TUD_HID_INOUT_DESCRIPTOR(*itf, str_index, tinyusb_interface_protocol, tinyusb_hid_device_descriptor_len, ep_out, (uint8_t)(0x80 | ep_in), 64, 1)
|
||||
TUD_HID_INOUT_DESCRIPTOR(*itf, str_index, tinyusb_interface_protocol, tinyusb_hid_device_descriptor_len, ep_out, (uint8_t)(0x80 | ep_in), CFG_TUD_ENDOINT_SIZE, 1)
|
||||
};
|
||||
*itf += 1;
|
||||
memcpy(dst, descriptor, TUD_HID_INOUT_DESC_LEN);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
|||
uint8_t ep_out = tinyusb_get_free_out_endpoint();
|
||||
TU_VERIFY(ep_out != 0);
|
||||
uint8_t descriptor[TUD_MIDI_DESC_LEN] = {
|
||||
TUD_MIDI_DESCRIPTOR(*itf, str_index, ep_out, (uint8_t)(0x80 | ep_in), 64),
|
||||
TUD_MIDI_DESCRIPTOR(*itf, str_index, ep_out, (uint8_t)(0x80 | ep_in), CFG_TUD_ENDOINT_SIZE),
|
||||
};
|
||||
*itf += 2;
|
||||
memcpy(dst, descriptor, TUD_MIDI_DESC_LEN);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, i
|
|||
|
||||
static USBVendor *_Vendor = NULL;
|
||||
static QueueHandle_t rx_queue = NULL;
|
||||
static uint8_t USB_VENDOR_ENDPOINT_SIZE = 64;
|
||||
static uint16_t USB_VENDOR_ENDPOINT_SIZE = CFG_TUD_ENDOINT_SIZE;
|
||||
|
||||
uint16_t tusb_vendor_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB Vendor");
|
||||
|
|
@ -68,10 +68,13 @@ extern "C" bool tinyusb_vendor_control_request_cb(uint8_t rhport, uint8_t stage,
|
|||
return false;
|
||||
}
|
||||
|
||||
USBVendor::USBVendor(uint8_t endpoint_size) : itf(0), cb(NULL) {
|
||||
USBVendor::USBVendor(uint16_t endpoint_size) : itf(0), cb(NULL) {
|
||||
if (!_Vendor) {
|
||||
_Vendor = this;
|
||||
if (endpoint_size <= 64) {
|
||||
if (endpoint_size == 0) {
|
||||
endpoint_size = CFG_TUD_ENDOINT_SIZE;
|
||||
}
|
||||
if (endpoint_size <= CFG_TUD_ENDOINT_SIZE) {
|
||||
USB_VENDOR_ENDPOINT_SIZE = endpoint_size;
|
||||
}
|
||||
tinyusb_enable_interface(USB_INTERFACE_VENDOR, TUD_VENDOR_DESC_LEN, tusb_vendor_load_descriptor);
|
||||
|
|
@ -97,7 +100,7 @@ size_t USBVendor::setRxBufferSize(size_t rx_queue_len) {
|
|||
}
|
||||
|
||||
void USBVendor::begin() {
|
||||
setRxBufferSize(256); //default if not preset
|
||||
setRxBufferSize(512); //default if not preset
|
||||
}
|
||||
|
||||
void USBVendor::end() {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ private:
|
|||
arduino_usb_vendor_control_request_handler_t cb;
|
||||
|
||||
public:
|
||||
USBVendor(uint8_t endpoint_size = 64);
|
||||
USBVendor(uint16_t endpoint_size = 0);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
size_t setRxBufferSize(size_t);
|
||||
|
|
|
|||
Loading…
Reference in a new issue