forked from espressif/arduino-esp32
Update TinyUSB Lib
This commit is contained in:
@ -18,16 +18,17 @@
|
||||
#include "usb_descriptors.h"
|
||||
|
||||
|
||||
#if CONFIG_USB_USE_BUILTIN_DESCRIPTORS
|
||||
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
|
||||
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
||||
*
|
||||
* Auto ProductID layout's Bitmap:
|
||||
* [MSB] HID | MSC | CDC [LSB]
|
||||
*/
|
||||
#define EPNUM_MSC 0x01
|
||||
#define EPNUM_HID 0x02
|
||||
#define EPNUM_MIDI 0x04
|
||||
#define EPNUM_VENDOR 0x06
|
||||
#define EPNUM_MSC 0x02
|
||||
#define EPNUM_HID 0x03
|
||||
#define EPNUM_MIDI 0x06
|
||||
#define EPNUM_VENDOR 0x01
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -47,6 +48,10 @@ enum {
|
||||
ITF_NUM_CDC_DATA,
|
||||
# endif
|
||||
|
||||
# if CFG_TUD_DFU_RT
|
||||
ITF_NUM_DFU_RT,
|
||||
# endif
|
||||
|
||||
# if CFG_TUD_MSC
|
||||
ITF_NUM_MSC,
|
||||
# endif
|
||||
@ -68,7 +73,7 @@ enum {
|
||||
};
|
||||
|
||||
enum {
|
||||
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_MSC * TUD_MSC_DESC_LEN +
|
||||
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_DFU_RT * TUD_DFU_RT_DESC_LEN + CFG_TUD_MSC * TUD_MSC_DESC_LEN +
|
||||
CFG_TUD_HID * TUD_HID_DESC_LEN + CFG_TUD_VENDOR * TUD_VENDOR_DESC_LEN + CFG_TUD_MIDI * TUD_MIDI_DESC_LEN
|
||||
};
|
||||
|
||||
@ -81,3 +86,5 @@ void tusb_clear_descriptor(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_USB_USE_BUILTIN_DESCRIPTORS */
|
||||
|
@ -1,51 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Espressif
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "freertos/xtensa_api.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp32s2/rom/gpio.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/gpio_sig_map.h"
|
||||
#include "soc/usb_periph.h"
|
||||
#include "tusb_config.h"
|
||||
// TinyUSB
|
||||
#include "tusb_option.h"
|
||||
#include "descriptors_control.h"
|
||||
#include "device/dcd.h"
|
||||
|
||||
|
||||
#define USB_EP_DIRECTIONS 2
|
||||
#define USB_MAX_EP_NUM 16
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
uint16_t total_len;
|
||||
uint16_t queued_len;
|
||||
uint16_t max_size;
|
||||
bool short_packet;
|
||||
} xfer_ctl_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -74,14 +74,79 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
tusb_desc_device_t *descriptor;
|
||||
char **string_descriptor;
|
||||
bool external_phy;
|
||||
} tinyusb_config_t;
|
||||
|
||||
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
|
||||
// TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
|
||||
|
||||
/*
|
||||
* USB Persistence API
|
||||
* */
|
||||
typedef enum {
|
||||
REBOOT_NO_PERSIST,
|
||||
REBOOT_PERSIST,
|
||||
REBOOT_BOOTLOADER,
|
||||
REBOOT_BOOTLOADER_DFU
|
||||
} reboot_type_t;
|
||||
|
||||
/*
|
||||
* Enable Persist reboot
|
||||
*
|
||||
* Note: Persistence should be enabled when ONLY CDC and DFU are being used
|
||||
* */
|
||||
void tinyusb_persist_set_enable(bool enable);
|
||||
|
||||
/*
|
||||
* Set Persist reboot mode, if available, before calling esp_reboot();
|
||||
* */
|
||||
void tinyusb_persist_set_mode(reboot_type_t mode);
|
||||
|
||||
/*
|
||||
* TinyUSB Dynamic Driver Loading
|
||||
*
|
||||
* When enabled, usb drivers can be loaded at runtime, before calling tinyusb_driver_install()
|
||||
* */
|
||||
#if CFG_TUSB_DYNAMIC_DRIVER_LOAD
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
#define DRIVER_NAME(_name) .name = _name,
|
||||
#else
|
||||
#define DRIVER_NAME(_name)
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
char const* name;
|
||||
#endif
|
||||
|
||||
void (* init ) (void);
|
||||
void (* reset ) (uint8_t rhport);
|
||||
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
|
||||
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void (* sof ) (uint8_t rhport); /* optional */
|
||||
} usbd_class_driver_t;
|
||||
|
||||
bool usbd_device_driver_load(const usbd_class_driver_t * driver);
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
#define LOAD_DEFAULT_TUSB_DRIVER(name) \
|
||||
static usbd_class_driver_t name ## d_driver = { \
|
||||
DRIVER_NAME(TOSTRING(name)) \
|
||||
.init = name ## d_init, \
|
||||
.reset = name ## d_reset, \
|
||||
.open = name ## d_open, \
|
||||
.control_request = name ## d_control_request, \
|
||||
.control_complete = name ## d_control_complete, \
|
||||
.xfer_cb = name ## d_xfer_cb, \
|
||||
.sof = NULL \
|
||||
}; \
|
||||
TU_VERIFY (usbd_device_driver_load(&name ## d_driver));
|
||||
#endif /* CFG_TUSB_DYNAMIC_DRIVER_LOAD */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -60,6 +60,10 @@ extern "C" {
|
||||
# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
|
||||
#endif
|
||||
|
||||
//Allow loading additional drivers
|
||||
#define CFG_TUSB_DYNAMIC_DRIVER_LOAD CONFIG_USB_DYNAMIC_DRIVER_LOADING
|
||||
#define CFG_TUSB_DYNAMIC_DRIVER_MAX CONFIG_USB_DYNAMIC_DRIVER_MAX
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -93,10 +97,6 @@ extern "C" {
|
||||
# define CONFIG_USB_DFU_RT_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_NET_ENABLED
|
||||
# define CONFIG_USB_NET_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_VENDOR_ENABLED
|
||||
# define CONFIG_USB_VENDOR_ENABLED 0
|
||||
#endif
|
||||
@ -106,11 +106,11 @@ extern "C" {
|
||||
#define CFG_TUD_MSC CONFIG_USB_MSC_ENABLED
|
||||
#define CFG_TUD_HID CONFIG_USB_HID_ENABLED
|
||||
#define CFG_TUD_DFU_RT CONFIG_USB_DFU_RT_ENABLED
|
||||
#define CFG_TUD_NET CONFIG_USB_NET_ENABLED
|
||||
|
||||
#define CFG_TUD_MIDI CONFIG_USB_MIDI_ENABLED
|
||||
#define CFG_TUD_CUSTOM_CLASS CONFIG_USB_CUSTOM_CLASS_ENABLED
|
||||
|
||||
|
||||
#define CFG_TUD_VENDOR CONFIG_USB_VENDOR_ENABLED
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
|
Reference in New Issue
Block a user