Merge branch 'master' into portability
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@@ -167,6 +167,12 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
// This API never calls with control endpoints, since it is auto cleared when receiving setup packet
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// Allocate packet buffer used by ISO endpoints
|
||||
// Some MCU need manual packet buffer allocation, we allocation largest size to avoid clustering
|
||||
TU_ATTR_WEAK bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size);
|
||||
|
||||
// Configure and enable an ISO endpoint according to descriptor
|
||||
TU_ATTR_WEAK bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
|
||||
//--------------------------------------------------------------------+
|
||||
// Event API (implemented by stack)
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -193,7 +199,7 @@ TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_reset (uint8_t rhport, t
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr)
|
||||
{
|
||||
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SETUP_RECEIVED };
|
||||
memcpy(&event.setup_received, setup, 8);
|
||||
memcpy(&event.setup_received, setup, sizeof(tusb_control_request_t));
|
||||
|
||||
dcd_event_handler(&event, in_isr);
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@
|
||||
// USBD Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Debug level of USBD
|
||||
#define USBD_DBG 2
|
||||
|
||||
#ifndef CFG_TUD_TASK_QUEUE_SZ
|
||||
#define CFG_TUD_TASK_QUEUE_SZ 16
|
||||
#endif
|
||||
|
||||
// Debug level of USBD
|
||||
#define USBD_DBG 2
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Data
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -76,7 +76,7 @@ typedef struct
|
||||
|
||||
}usbd_device_t;
|
||||
|
||||
static usbd_device_t _usbd_dev;
|
||||
tu_static usbd_device_t _usbd_dev;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver
|
||||
@@ -88,7 +88,7 @@ static usbd_device_t _usbd_dev;
|
||||
#endif
|
||||
|
||||
// Built-in class drivers
|
||||
static usbd_class_driver_t const _usbd_driver[] =
|
||||
tu_static usbd_class_driver_t const _usbd_driver[] =
|
||||
{
|
||||
#if CFG_TUD_CDC
|
||||
{
|
||||
@@ -238,8 +238,8 @@ static usbd_class_driver_t const _usbd_driver[] =
|
||||
enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
|
||||
|
||||
// Additional class drivers implemented by application
|
||||
static usbd_class_driver_t const * _app_driver = NULL;
|
||||
static uint8_t _app_driver_count = 0;
|
||||
tu_static usbd_class_driver_t const * _app_driver = NULL;
|
||||
tu_static uint8_t _app_driver_count = 0;
|
||||
|
||||
// virtually joins built-in and application drivers together.
|
||||
// Application is positioned first to allow overwriting built-in ones.
|
||||
@@ -265,17 +265,19 @@ static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
enum { RHPORT_INVALID = 0xFFu };
|
||||
static uint8_t _usbd_rhport = RHPORT_INVALID;
|
||||
tu_static uint8_t _usbd_rhport = RHPORT_INVALID;
|
||||
|
||||
// Event queue
|
||||
// usbd_int_set() is used as mutex in OS NONE config
|
||||
OSAL_QUEUE_DEF(usbd_int_set, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
|
||||
static osal_queue_t _usbd_q;
|
||||
tu_static osal_queue_t _usbd_q;
|
||||
|
||||
// Mutex for claiming endpoint, only needed when using with preempted RTOS
|
||||
#if CFG_TUSB_OS != OPT_OS_NONE
|
||||
static osal_mutex_def_t _ubsd_mutexdef;
|
||||
static osal_mutex_t _usbd_mutex;
|
||||
// Mutex for claiming endpoint
|
||||
#if OSAL_MUTEX_REQUIRED
|
||||
tu_static osal_mutex_def_t _ubsd_mutexdef;
|
||||
tu_static osal_mutex_t _usbd_mutex;
|
||||
#else
|
||||
#define _usbd_mutex NULL
|
||||
#endif
|
||||
|
||||
|
||||
@@ -297,7 +299,7 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event,
|
||||
// Debug
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
|
||||
tu_static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
|
||||
{
|
||||
"Invalid" ,
|
||||
"Bus Reset" ,
|
||||
@@ -386,10 +388,12 @@ bool tud_init (uint8_t rhport)
|
||||
|
||||
TU_LOG(USBD_DBG, "USBD init on controller %u\r\n", rhport);
|
||||
TU_LOG_INT(USBD_DBG, sizeof(usbd_device_t));
|
||||
TU_LOG_INT(USBD_DBG, sizeof(tu_fifo_t));
|
||||
TU_LOG_INT(USBD_DBG, sizeof(tu_edpt_stream_t));
|
||||
|
||||
tu_varclr(&_usbd_dev);
|
||||
|
||||
#if CFG_TUSB_OS != OPT_OS_NONE
|
||||
#if OSAL_MUTEX_REQUIRED
|
||||
// Init device mutex
|
||||
_usbd_mutex = osal_mutex_create(&_ubsd_mutexdef);
|
||||
TU_ASSERT(_usbd_mutex);
|
||||
@@ -504,7 +508,7 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr)
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
TU_LOG_VAR(USBD_DBG, &event.setup_received);
|
||||
TU_LOG_PTR(USBD_DBG, &event.setup_received);
|
||||
TU_LOG(USBD_DBG, "\r\n");
|
||||
|
||||
// Mark as connected after receiving 1st setup packet.
|
||||
@@ -1209,11 +1213,7 @@ bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
tu_edpt_state_t* ep_state = &_usbd_dev.ep_status[epnum][dir];
|
||||
|
||||
#if TUSB_OPT_MUTEX
|
||||
return tu_edpt_claim(ep_state, _usbd_mutex);
|
||||
#else
|
||||
return tu_edpt_claim(ep_state, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr)
|
||||
@@ -1224,11 +1224,7 @@ bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
tu_edpt_state_t* ep_state = &_usbd_dev.ep_status[epnum][dir];
|
||||
|
||||
#if TUSB_OPT_MUTEX
|
||||
return tu_edpt_release(ep_state, _usbd_mutex);
|
||||
#else
|
||||
return tu_edpt_release(ep_state, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
|
||||
@@ -1386,4 +1382,31 @@ void usbd_sof_enable(uint8_t rhport, bool en)
|
||||
dcd_sof_enable(rhport, en);
|
||||
}
|
||||
|
||||
bool usbd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size)
|
||||
{
|
||||
rhport = _usbd_rhport;
|
||||
|
||||
TU_ASSERT(dcd_edpt_iso_alloc);
|
||||
TU_ASSERT(tu_edpt_number(ep_addr) < CFG_TUD_ENDPPOINT_MAX);
|
||||
|
||||
return dcd_edpt_iso_alloc(rhport, ep_addr, largest_packet_size);
|
||||
}
|
||||
|
||||
bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep)
|
||||
{
|
||||
rhport = _usbd_rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(desc_ep->bEndpointAddress);
|
||||
uint8_t const dir = tu_edpt_dir(desc_ep->bEndpointAddress);
|
||||
|
||||
TU_ASSERT(dcd_edpt_iso_activate);
|
||||
TU_ASSERT(epnum < CFG_TUD_ENDPPOINT_MAX);
|
||||
TU_ASSERT(tu_edpt_validate(desc_ep, (tusb_speed_t) _usbd_dev.speed));
|
||||
|
||||
_usbd_dev.ep_status[epnum][dir].stalled = false;
|
||||
_usbd_dev.ep_status[epnum][dir].busy = false;
|
||||
_usbd_dev.ep_status[epnum][dir].claimed = false;
|
||||
return dcd_edpt_iso_activate(rhport, desc_ep);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -293,7 +293,7 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* MIDI Streaming (MS) Interface */\
|
||||
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum) + 1), 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, 0,\
|
||||
/* MS Header */\
|
||||
7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(7 + (_numcables) * TUD_MIDI_DESC_JACK_LEN)
|
||||
7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(7 + (_numcables) * TUD_MIDI_DESC_JACK_LEN + 2 * TUD_MIDI_DESC_EP_LEN(_numcables))
|
||||
|
||||
#define TUD_MIDI_JACKID_IN_EMB(_cablenum) \
|
||||
(uint8_t)(((_cablenum) - 1) * 4 + 1)
|
||||
@@ -308,15 +308,17 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
(uint8_t)(((_cablenum) - 1) * 4 + 4)
|
||||
|
||||
#define TUD_MIDI_DESC_JACK_LEN (6 + 6 + 9 + 9)
|
||||
#define TUD_MIDI_DESC_JACK(_cablenum) \
|
||||
#define TUD_MIDI_DESC_JACK_DESC(_cablenum, _stridx) \
|
||||
/* MS In Jack (Embedded) */\
|
||||
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_IN_EMB(_cablenum), 0,\
|
||||
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_IN_EMB(_cablenum), _stridx,\
|
||||
/* MS In Jack (External) */\
|
||||
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_IN_EXT(_cablenum), 0,\
|
||||
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_IN_EXT(_cablenum), _stridx,\
|
||||
/* MS Out Jack (Embedded), connected to In Jack External */\
|
||||
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_OUT_EMB(_cablenum), 1, TUD_MIDI_JACKID_IN_EXT(_cablenum), 1, 0,\
|
||||
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_OUT_EMB(_cablenum), 1, TUD_MIDI_JACKID_IN_EXT(_cablenum), 1, _stridx,\
|
||||
/* MS Out Jack (External), connected to In Jack Embedded */\
|
||||
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_OUT_EXT(_cablenum), 1, TUD_MIDI_JACKID_IN_EMB(_cablenum), 1, 0
|
||||
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_OUT_EXT(_cablenum), 1, TUD_MIDI_JACKID_IN_EMB(_cablenum), 1, _stridx
|
||||
|
||||
#define TUD_MIDI_DESC_JACK(_cablenum) TUD_MIDI_DESC_JACK_DESC(_cablenum, 0)
|
||||
|
||||
#define TUD_MIDI_DESC_EP_LEN(_numcables) (9 + 4 + (_numcables))
|
||||
#define TUD_MIDI_DESC_EP(_epout, _epsize, _numcables) \
|
||||
@@ -333,7 +335,7 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
// - 1 Embedded Jack out connected to 1 External Jack In
|
||||
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
|
||||
TUD_MIDI_DESC_HEAD(_itfnum, _stridx, 1),\
|
||||
TUD_MIDI_DESC_JACK(1),\
|
||||
TUD_MIDI_DESC_JACK_DESC(1, 0),\
|
||||
TUD_MIDI_DESC_EP(_epout, _epsize, 1),\
|
||||
TUD_MIDI_JACKID_IN_EMB(1),\
|
||||
TUD_MIDI_DESC_EP(_epin, _epsize, 1),\
|
||||
@@ -602,7 +604,7 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* optional interrupt endpoint */ \
|
||||
// _int_pollingInterval : for LS/FS, expressed in frames (1ms each). 16 may be a good number?
|
||||
#define TUD_USBTMC_INT_DESCRIPTOR(_ep_interrupt, _ep_interrupt_size, _int_pollingInterval ) \
|
||||
7, TUSB_DESC_ENDPOINT, _ep_interrupt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_interrupt_size), 0x16
|
||||
7, TUSB_DESC_ENDPOINT, _ep_interrupt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_interrupt_size), _int_pollingInterval
|
||||
|
||||
#define TUD_USBTMC_INT_DESCRIPTOR_LEN (7u)
|
||||
|
||||
@@ -647,7 +649,7 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
#define TUD_DFU_DESC_LEN(_alt_count) (9 + (_alt_count) * 9)
|
||||
|
||||
// Interface number, Alternate count, starting string index, attributes, detach timeout, transfer size
|
||||
// Note: Alternate count must be numberic or macro, string index is increased by one for each Alt interface
|
||||
// Note: Alternate count must be numeric or macro, string index is increased by one for each Alt interface
|
||||
#define TUD_DFU_DESCRIPTOR(_itfnum, _alt_count, _stridx, _attr, _timeout, _xfer_size) \
|
||||
TU_XSTRCAT(_TUD_DFU_ALT_,_alt_count)(_itfnum, 0, _stridx), \
|
||||
/* Function */ \
|
||||
|
||||
@@ -53,10 +53,10 @@ typedef struct
|
||||
usbd_control_xfer_cb_t complete_cb;
|
||||
} usbd_control_xfer_t;
|
||||
|
||||
static usbd_control_xfer_t _ctrl_xfer;
|
||||
tu_static usbd_control_xfer_t _ctrl_xfer;
|
||||
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN
|
||||
static uint8_t _usbd_ctrl_buf[CFG_TUD_ENDPOINT0_SIZE];
|
||||
tu_static uint8_t _usbd_ctrl_buf[CFG_TUD_ENDPOINT0_SIZE];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
@@ -93,7 +93,9 @@ static bool _data_stage_xact(uint8_t rhport)
|
||||
if ( _ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_IN )
|
||||
{
|
||||
ep_addr = EDPT_CTRL_IN;
|
||||
if ( xact_len ) memcpy(_usbd_ctrl_buf, _ctrl_xfer.buffer, xact_len);
|
||||
if ( xact_len ) {
|
||||
TU_VERIFY(0 == tu_memcpy_s(_usbd_ctrl_buf, CFG_TUD_ENDPOINT0_SIZE, _ctrl_xfer.buffer, xact_len));
|
||||
}
|
||||
}
|
||||
|
||||
return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_buf : NULL, xact_len);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@@ -96,6 +96,12 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
// Check if endpoint is stalled
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// Allocate packet buffer used by ISO endpoints
|
||||
bool usbd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size);
|
||||
|
||||
// Configure and enable an ISO endpoint according to descriptor
|
||||
bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
|
||||
|
||||
// Check if endpoint is ready (not busy and not stalled)
|
||||
TU_ATTR_ALWAYS_INLINE static inline
|
||||
bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr)
|
||||
|
||||
Reference in New Issue
Block a user