mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-29 01:20:19 +00:00
Merge remote-tracking branch 'upstream/master' into uac2
Conflicts: src/device/usbd.c src/device/usbd.h src/portable/st/synopsys/dcd_synopsys.c
This commit is contained in:
commit
6309364722
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@ -41,10 +41,12 @@ jobs:
|
|||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: /tmp/dl/
|
path: /tmp/dl/
|
||||||
# Increment serial number at end when updating downloads
|
# Increment gcc version number at end when updating downloads
|
||||||
key: msp430-${{ runner.os }}-0
|
key: msp430-${{ runner.os }}-9.2.0.50
|
||||||
|
|
||||||
- name: Install Toolchains
|
- name: Install Toolchains
|
||||||
|
env:
|
||||||
|
MSP430GCC_URL: http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2
|
||||||
run: |
|
run: |
|
||||||
# ARM & RISC-V GCC from xpack
|
# ARM & RISC-V GCC from xpack
|
||||||
npm install --global xpm
|
npm install --global xpm
|
||||||
@ -55,7 +57,7 @@ jobs:
|
|||||||
|
|
||||||
# TI MSP430 GCC
|
# TI MSP430 GCC
|
||||||
mkdir -p /tmp/dl/
|
mkdir -p /tmp/dl/
|
||||||
[ -f "/tmp/dl/msp430-gcc.tar.bz2" ] || wget --progress=dot:mega http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/8_3_0_0/exports/msp430-gcc-8.3.0.16_linux64.tar.bz2 -O /tmp/dl/msp430-gcc.tar.bz2
|
[ -f "/tmp/dl/msp430-gcc.tar.bz2" ] || wget --progress=dot:mega $MSP430GCC_URL -O /tmp/dl/msp430-gcc.tar.bz2
|
||||||
tar -C $HOME -xaf /tmp/dl/msp430-gcc.tar.bz2
|
tar -C $HOME -xaf /tmp/dl/msp430-gcc.tar.bz2
|
||||||
echo "::add-path::`echo $HOME/msp430-gcc-*_linux64/bin`"
|
echo "::add-path::`echo $HOME/msp430-gcc-*_linux64/bin`"
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ All of the code for the low-level device API is in `src/portable/<vendor>/<chip
|
|||||||
##### dcd_init
|
##### dcd_init
|
||||||
|
|
||||||
Initializes the USB peripheral for device mode and enables it.
|
Initializes the USB peripheral for device mode and enables it.
|
||||||
This function should leave an internal D+/D- pull-up in its default power-on state. `dcd_connect` will be called by the USBD core following `dcd_init`.
|
This function should enable internal D+/D- pull-up for enumeration.
|
||||||
|
|
||||||
##### dcd_int_enable / dcd_int_disable
|
##### dcd_int_enable / dcd_int_disable
|
||||||
|
|
||||||
|
@ -6,9 +6,6 @@ CFLAGS += \
|
|||||||
-DTCP_WND=2*TCP_MSS \
|
-DTCP_WND=2*TCP_MSS \
|
||||||
-DHTTPD_USE_CUSTOM_FSDATA=0
|
-DHTTPD_USE_CUSTOM_FSDATA=0
|
||||||
|
|
||||||
# TODO rndis_reports.c and net_device cause cast algin warnings
|
|
||||||
CFLAGS += -Wno-error=cast-align
|
|
||||||
|
|
||||||
INC += \
|
INC += \
|
||||||
src \
|
src \
|
||||||
$(TOP)/hw \
|
$(TOP)/hw \
|
||||||
|
2
lib/lwip
2
lib/lwip
@ -1 +1 @@
|
|||||||
Subproject commit 0192fe773ec28e11f66ec76f4e827fbb58b7e257
|
Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10
|
@ -74,7 +74,7 @@ static const uint32_t OIDSupportedList[] =
|
|||||||
#define OID_LIST_LENGTH TU_ARRAY_SIZE(OIDSupportedList)
|
#define OID_LIST_LENGTH TU_ARRAY_SIZE(OIDSupportedList)
|
||||||
#define ENC_BUF_SIZE (OID_LIST_LENGTH * 4 + 32)
|
#define ENC_BUF_SIZE (OID_LIST_LENGTH * 4 + 32)
|
||||||
|
|
||||||
static uint8_t *encapsulated_buffer;
|
static void *encapsulated_buffer;
|
||||||
|
|
||||||
static void rndis_report(void)
|
static void rndis_report(void)
|
||||||
{
|
{
|
||||||
@ -152,7 +152,7 @@ static void rndis_query(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INFBUF ((uint32_t *)((uint8_t *)&(m->RequestId) + m->InformationBufferOffset))
|
#define INFBUF ((uint8_t *)&(m->RequestId) + m->InformationBufferOffset)
|
||||||
|
|
||||||
static void rndis_handle_config_parm(const char *data, int keyoffset, int valoffset, int keylen, int vallen)
|
static void rndis_handle_config_parm(const char *data, int keyoffset, int valoffset, int keylen, int vallen)
|
||||||
{
|
{
|
||||||
@ -191,14 +191,14 @@ static void rndis_handle_set_msg(void)
|
|||||||
char *ptr = (char *)m;
|
char *ptr = (char *)m;
|
||||||
ptr += sizeof(rndis_generic_msg_t);
|
ptr += sizeof(rndis_generic_msg_t);
|
||||||
ptr += m->InformationBufferOffset;
|
ptr += m->InformationBufferOffset;
|
||||||
p = (rndis_config_parameter_t *)ptr;
|
p = (rndis_config_parameter_t *) ((void*) ptr);
|
||||||
rndis_handle_config_parm(ptr, p->ParameterNameOffset, p->ParameterValueOffset, p->ParameterNameLength, p->ParameterValueLength);
|
rndis_handle_config_parm(ptr, p->ParameterNameOffset, p->ParameterValueOffset, p->ParameterNameLength, p->ParameterValueLength);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Mandatory general OIDs */
|
/* Mandatory general OIDs */
|
||||||
case OID_GEN_CURRENT_PACKET_FILTER:
|
case OID_GEN_CURRENT_PACKET_FILTER:
|
||||||
oid_packet_filter = *INFBUF;
|
memcpy(&oid_packet_filter, INFBUF, 4);
|
||||||
if (oid_packet_filter)
|
if (oid_packet_filter)
|
||||||
{
|
{
|
||||||
rndis_packetFilter(oid_packet_filter);
|
rndis_packetFilter(oid_packet_filter);
|
||||||
@ -239,7 +239,7 @@ void rndis_class_set_handler(uint8_t *data, int size)
|
|||||||
encapsulated_buffer = data;
|
encapsulated_buffer = data;
|
||||||
(void)size;
|
(void)size;
|
||||||
|
|
||||||
switch (((rndis_generic_msg_t *)data)->MessageType)
|
switch (((rndis_generic_msg_t *)encapsulated_buffer)->MessageType)
|
||||||
{
|
{
|
||||||
case REMOTE_NDIS_INITIALIZE_MSG:
|
case REMOTE_NDIS_INITIALIZE_MSG:
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,7 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
|
|||||||
desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
|
desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
|
||||||
|
|
||||||
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
|
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
|
||||||
TU_ASSERT(dcd_edpt_open(rhport, desc_ep), 0);
|
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
|
||||||
_btd_itf.ep_ev = desc_ep->bEndpointAddress;
|
_btd_itf.ep_ev = desc_ep->bEndpointAddress;
|
||||||
|
|
||||||
// Open endpoint pair
|
// Open endpoint pair
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "common/tusb_common.h"
|
#include "common/tusb_common.h"
|
||||||
#include "msc_device.h"
|
#include "msc_device.h"
|
||||||
#include "device/usbd_pvt.h"
|
#include "device/usbd_pvt.h"
|
||||||
|
#include "device/dcd.h" // for faking dcd_event_xfer_complete
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF
|
// MACRO CONSTANT TYPEDEF
|
||||||
@ -105,7 +106,7 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#if CFG_TUSB_DEBUG >= 2
|
#if CFG_TUSB_DEBUG >= 2
|
||||||
|
|
||||||
static lookup_entry_t const _msc_scsi_cmd_lookup[] =
|
static tu_lookup_entry_t const _msc_scsi_cmd_lookup[] =
|
||||||
{
|
{
|
||||||
{ .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" },
|
{ .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" },
|
||||||
{ .key = SCSI_CMD_INQUIRY , .data = "Inquiry" },
|
{ .key = SCSI_CMD_INQUIRY , .data = "Inquiry" },
|
||||||
@ -120,7 +121,7 @@ static lookup_entry_t const _msc_scsi_cmd_lookup[] =
|
|||||||
{ .key = SCSI_CMD_WRITE_10 , .data = "Write10" }
|
{ .key = SCSI_CMD_WRITE_10 , .data = "Write10" }
|
||||||
};
|
};
|
||||||
|
|
||||||
static lookup_table_t const _msc_scsi_cmd_table =
|
static tu_lookup_table_t const _msc_scsi_cmd_table =
|
||||||
{
|
{
|
||||||
.count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup),
|
.count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup),
|
||||||
.items = _msc_scsi_cmd_lookup
|
.items = _msc_scsi_cmd_lookup
|
||||||
@ -418,7 +419,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
|||||||
TU_ASSERT( event == XFER_RESULT_SUCCESS &&
|
TU_ASSERT( event == XFER_RESULT_SUCCESS &&
|
||||||
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
|
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
|
||||||
|
|
||||||
TU_LOG2(" SCSI Command: %s\r\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
|
TU_LOG2(" SCSI Command: %s\r\n", tu_lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
|
||||||
// TU_LOG2_MEM(p_cbw, xferred_bytes, 2);
|
// TU_LOG2_MEM(p_cbw, xferred_bytes, 2);
|
||||||
|
|
||||||
p_csw->signature = MSC_CSW_SIGNATURE;
|
p_csw->signature = MSC_CSW_SIGNATURE;
|
||||||
|
@ -326,7 +326,7 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
|||||||
{
|
{
|
||||||
if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
|
if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
|
||||||
{
|
{
|
||||||
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)notify.rndis_buf;
|
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *) ((void*) notify.rndis_buf);
|
||||||
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
|
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
|
||||||
TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
|
TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
|
||||||
tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
|
tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
|
||||||
@ -356,7 +356,7 @@ static void handle_incoming_packet(uint32_t len)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
|
rndis_data_packet_t *r = (rndis_data_packet_t *) ((void*) pnt);
|
||||||
if (len >= sizeof(rndis_data_packet_t))
|
if (len >= sizeof(rndis_data_packet_t))
|
||||||
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
|
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
|
||||||
if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
|
if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
|
||||||
@ -450,7 +450,7 @@ void tud_network_xmit(struct pbuf *p)
|
|||||||
|
|
||||||
if (!_netd_itf.ecm_mode)
|
if (!_netd_itf.ecm_mode)
|
||||||
{
|
{
|
||||||
rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
|
rndis_data_packet_t *hdr = (rndis_data_packet_t *) ((void*) transmitted);
|
||||||
memset(hdr, 0, sizeof(rndis_data_packet_t));
|
memset(hdr, 0, sizeof(rndis_data_packet_t));
|
||||||
hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
|
hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
|
||||||
hdr->MessageLength = len;
|
hdr->MessageLength = len;
|
||||||
|
@ -80,7 +80,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "usbtmc.h"
|
#include "usbtmc.h"
|
||||||
#include "usbtmc_device.h"
|
#include "usbtmc_device.h"
|
||||||
#include "device/dcd.h"
|
|
||||||
#include "device/usbd.h"
|
#include "device/usbd.h"
|
||||||
#include "osal/osal.h"
|
#include "osal/osal.h"
|
||||||
|
|
||||||
|
@ -251,16 +251,16 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize)
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
char const * data;
|
const char* data;
|
||||||
}lookup_entry_t;
|
} tu_lookup_entry_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t count;
|
uint16_t count;
|
||||||
lookup_entry_t const* items;
|
tu_lookup_entry_t const* items;
|
||||||
} lookup_table_t;
|
} tu_lookup_table_t;
|
||||||
|
|
||||||
static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t key)
|
static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key)
|
||||||
{
|
{
|
||||||
for(uint16_t i=0; i<p_table->count; i++)
|
for(uint16_t i=0; i<p_table->count; i++)
|
||||||
{
|
{
|
||||||
|
@ -82,21 +82,7 @@ enum { DRVID_INVALID = 0xFFu };
|
|||||||
#define DRIVER_NAME(_name)
|
#define DRIVER_NAME(_name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct
|
// Built-in class drivers
|
||||||
{
|
|
||||||
#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;
|
|
||||||
|
|
||||||
static usbd_class_driver_t const _usbd_driver[] =
|
static usbd_class_driver_t const _usbd_driver[] =
|
||||||
{
|
{
|
||||||
#if CFG_TUD_CDC
|
#if CFG_TUD_CDC
|
||||||
@ -230,7 +216,30 @@ static usbd_class_driver_t const _usbd_driver[] =
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SIZE(_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;
|
||||||
|
|
||||||
|
// virtually joins built-in and application drivers together.
|
||||||
|
// Application is positioned first to allow overwriting built-in ones.
|
||||||
|
static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
|
||||||
|
{
|
||||||
|
// Application drivers
|
||||||
|
if ( usbd_app_driver_get_cb )
|
||||||
|
{
|
||||||
|
if ( drvid < _app_driver_count ) return &_app_driver[drvid];
|
||||||
|
drvid -= _app_driver_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Built-in drivers
|
||||||
|
if (drvid < BUILTIN_DRIVER_COUNT) return &_usbd_driver[drvid];
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// DCD Event
|
// DCD Event
|
||||||
@ -249,6 +258,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
|
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
|
||||||
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
|
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||||
|
|
||||||
|
// from usbd_control.c
|
||||||
void usbd_control_reset(void);
|
void usbd_control_reset(void);
|
||||||
void usbd_control_set_request(tusb_control_request_t const *request);
|
void usbd_control_set_request(tusb_control_request_t const *request);
|
||||||
void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) );
|
void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) );
|
||||||
@ -256,7 +266,7 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event,
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Debugging
|
// Debug
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#if CFG_TUSB_DEBUG >= 2
|
#if CFG_TUSB_DEBUG >= 2
|
||||||
static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
|
static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
|
||||||
@ -292,11 +302,12 @@ static char const* const _tusb_std_request_str[] =
|
|||||||
// for usbd_control to print the name of control complete driver
|
// for usbd_control to print the name of control complete driver
|
||||||
void usbd_driver_print_control_complete_name(bool (*control_complete) (uint8_t, tusb_control_request_t const * ))
|
void usbd_driver_print_control_complete_name(bool (*control_complete) (uint8_t, tusb_control_request_t const * ))
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (_usbd_driver[i].control_complete == control_complete )
|
usbd_class_driver_t const * driver = get_driver(i);
|
||||||
|
if ( driver->control_complete == control_complete )
|
||||||
{
|
{
|
||||||
TU_LOG2(" %s control complete\r\n", _usbd_driver[i].name);
|
TU_LOG2(" %s control complete\r\n", driver->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,6 +341,20 @@ bool tud_remote_wakeup(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tud_disconnect(void)
|
||||||
|
{
|
||||||
|
TU_VERIFY(dcd_disconnect);
|
||||||
|
dcd_disconnect(TUD_OPT_RHPORT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tud_connect(void)
|
||||||
|
{
|
||||||
|
TU_VERIFY(dcd_connect);
|
||||||
|
dcd_connect(TUD_OPT_RHPORT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USBD Task
|
// USBD Task
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -343,16 +368,22 @@ bool tud_init (void)
|
|||||||
_usbd_q = osal_queue_create(&_usbd_qdef);
|
_usbd_q = osal_queue_create(&_usbd_qdef);
|
||||||
TU_ASSERT(_usbd_q != NULL);
|
TU_ASSERT(_usbd_q != NULL);
|
||||||
|
|
||||||
// Init class drivers
|
// Get application driver if available
|
||||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
if ( usbd_app_driver_get_cb )
|
||||||
{
|
{
|
||||||
TU_LOG2("%s init\r\n", _usbd_driver[i].name);
|
_app_driver = usbd_app_driver_get_cb(&_app_driver_count);
|
||||||
_usbd_driver[i].init();
|
}
|
||||||
|
|
||||||
|
// Init class drivers
|
||||||
|
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
|
||||||
|
{
|
||||||
|
usbd_class_driver_t const * driver = get_driver(i);
|
||||||
|
TU_LOG2("%s init\r\n", driver->name);
|
||||||
|
driver->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init device controller driver
|
// Init device controller driver
|
||||||
dcd_init(TUD_OPT_RHPORT);
|
dcd_init(TUD_OPT_RHPORT);
|
||||||
tud_connect();
|
|
||||||
dcd_int_enable(TUD_OPT_RHPORT);
|
dcd_int_enable(TUD_OPT_RHPORT);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -367,9 +398,9 @@ static void usbd_reset(uint8_t rhport)
|
|||||||
|
|
||||||
usbd_control_reset();
|
usbd_control_reset();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
for ( uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++ )
|
||||||
{
|
{
|
||||||
if ( _usbd_driver[i].reset ) _usbd_driver[i].reset( rhport );
|
get_driver(i)->reset(rhport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,11 +498,11 @@ void tud_task (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t const drv_id = _usbd_dev.ep2drv[epnum][ep_dir];
|
usbd_class_driver_t const * driver = get_driver( _usbd_dev.ep2drv[epnum][ep_dir] );
|
||||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,);
|
TU_ASSERT(driver, );
|
||||||
|
|
||||||
TU_LOG2(" %s xfer callback\r\n", _usbd_driver[drv_id].name);
|
TU_LOG2(" %s xfer callback\r\n", driver->name);
|
||||||
_usbd_driver[drv_id].xfer_cb(event.rhport, ep_addr, (xfer_result_t)event.xfer_complete.result, event.xfer_complete.len);
|
driver->xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -488,12 +519,10 @@ void tud_task (void)
|
|||||||
|
|
||||||
case DCD_EVENT_SOF:
|
case DCD_EVENT_SOF:
|
||||||
TU_LOG2("\r\n");
|
TU_LOG2("\r\n");
|
||||||
for ( uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++ )
|
for ( uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++ )
|
||||||
{
|
{
|
||||||
if ( _usbd_driver[i].sof )
|
usbd_class_driver_t const * driver = get_driver(i);
|
||||||
{
|
if ( driver->sof ) driver->sof(event.rhport);
|
||||||
_usbd_driver[i].sof(event.rhport);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -514,11 +543,11 @@ void tud_task (void)
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
// Helper to invoke class driver control request handler
|
// Helper to invoke class driver control request handler
|
||||||
static bool invoke_class_control(uint8_t rhport, uint8_t drvid, tusb_control_request_t const * request)
|
static bool invoke_class_control(uint8_t rhport, usbd_class_driver_t const * driver, tusb_control_request_t const * request)
|
||||||
{
|
{
|
||||||
usbd_control_set_complete_callback(_usbd_driver[drvid].control_complete);
|
usbd_control_set_complete_callback(driver->control_complete);
|
||||||
TU_LOG2(" %s control request\r\n", _usbd_driver[drvid].name);
|
TU_LOG2(" %s control request\r\n", driver->name);
|
||||||
return _usbd_driver[drvid].control_request(rhport, request);
|
return driver->control_request(rhport, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This handles the actual request and its response.
|
// This handles the actual request and its response.
|
||||||
@ -555,12 +584,11 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||||
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
||||||
|
|
||||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
|
||||||
TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
|
TU_VERIFY(driver);
|
||||||
|
|
||||||
// forward to class driver: "non-STD request to Interface"
|
// forward to class driver: "non-STD request to Interface"
|
||||||
TU_VERIFY(invoke_class_control(rhport, drvid, p_request));
|
return invoke_class_control(rhport, driver, p_request);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if ( TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type )
|
if ( TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type )
|
||||||
{
|
{
|
||||||
@ -593,7 +621,6 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
uint8_t const cfg_num = (uint8_t) p_request->wValue;
|
uint8_t const cfg_num = (uint8_t) p_request->wValue;
|
||||||
|
|
||||||
if ( !_usbd_dev.cfg_num && cfg_num ) TU_ASSERT( process_set_config(rhport, cfg_num) );
|
if ( !_usbd_dev.cfg_num && cfg_num ) TU_ASSERT( process_set_config(rhport, cfg_num) );
|
||||||
|
|
||||||
_usbd_dev.cfg_num = cfg_num;
|
_usbd_dev.cfg_num = cfg_num;
|
||||||
|
|
||||||
tud_control_status(rhport, p_request);
|
tud_control_status(rhport, p_request);
|
||||||
@ -643,12 +670,12 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||||
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
||||||
|
|
||||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
|
||||||
TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
|
TU_VERIFY(driver);
|
||||||
|
|
||||||
// all requests to Interface (STD or Class) is forwarded to class driver.
|
// all requests to Interface (STD or Class) is forwarded to class driver.
|
||||||
// notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
|
// notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
|
||||||
if ( !invoke_class_control(rhport, drvid, p_request) )
|
if ( !invoke_class_control(rhport, driver, p_request) )
|
||||||
{
|
{
|
||||||
// For GET_INTERFACE, it is mandatory to respond even if the class
|
// For GET_INTERFACE, it is mandatory to respond even if the class
|
||||||
// driver doesn't use alternate settings.
|
// driver doesn't use alternate settings.
|
||||||
@ -670,8 +697,6 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
|
|
||||||
TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
|
TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
|
||||||
|
|
||||||
uint8_t const drvid = _usbd_dev.ep2drv[ep_num][ep_dir];
|
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
// Handle STD request to endpoint
|
// Handle STD request to endpoint
|
||||||
@ -690,18 +715,12 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TUSB_REQ_CLEAR_FEATURE:
|
case TUSB_REQ_CLEAR_FEATURE:
|
||||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) usbd_edpt_clear_stall(rhport, ep_addr);
|
||||||
{
|
|
||||||
usbd_edpt_clear_stall(rhport, ep_addr);
|
|
||||||
}
|
|
||||||
tud_control_status(rhport, p_request);
|
tud_control_status(rhport, p_request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TUSB_REQ_SET_FEATURE:
|
case TUSB_REQ_SET_FEATURE:
|
||||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) usbd_edpt_stall(rhport, ep_addr);
|
||||||
{
|
|
||||||
usbd_edpt_stall(rhport, ep_addr);
|
|
||||||
}
|
|
||||||
tud_control_status(rhport, p_request);
|
tud_control_status(rhport, p_request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -710,16 +729,17 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drvid < 0xFF) {
|
usbd_class_driver_t const * driver = get_driver(_usbd_dev.ep2drv[ep_num][ep_dir]);
|
||||||
TU_ASSERT(drvid < USBD_CLASS_DRIVER_COUNT);
|
|
||||||
|
|
||||||
|
if (driver)
|
||||||
|
{
|
||||||
// Some classes such as USBTMC needs to clear/re-init its buffer when receiving CLEAR_FEATURE request
|
// Some classes such as USBTMC needs to clear/re-init its buffer when receiving CLEAR_FEATURE request
|
||||||
// We will forward all request targeted endpoint to class drivers after
|
// We will forward all request targeted endpoint to class drivers after
|
||||||
// - For class-type requests: driver is fully responsible to reply to host
|
// - For class-type requests: driver is fully responsible to reply to host
|
||||||
// - For std-type requests : driver init/re-init internal variable/buffer only, and
|
// - For std-type requests : driver init/re-init internal variable/buffer only, and
|
||||||
// must not call tud_control_status(), driver's return value will have no effect.
|
// must not call tud_control_status(), driver's return value will have no effect.
|
||||||
// EP state has already affected (stalled/cleared)
|
// EP state has already affected (stalled/cleared)
|
||||||
if ( invoke_class_control(rhport, drvid, p_request) ) ret = true;
|
if ( invoke_class_control(rhport, driver, p_request) ) ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type )
|
if ( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type )
|
||||||
@ -774,13 +794,10 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
|||||||
uint16_t const remaining_len = desc_end-p_desc;
|
uint16_t const remaining_len = desc_end-p_desc;
|
||||||
|
|
||||||
uint8_t drv_id;
|
uint8_t drv_id;
|
||||||
uint16_t drv_len;
|
for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++)
|
||||||
|
|
||||||
for (drv_id = 0; drv_id < USBD_CLASS_DRIVER_COUNT; drv_id++)
|
|
||||||
{
|
{
|
||||||
usbd_class_driver_t const *driver = &_usbd_driver[drv_id];
|
usbd_class_driver_t const *driver = get_driver(drv_id);
|
||||||
|
uint16_t const drv_len = driver->open(rhport, desc_itf, remaining_len);
|
||||||
drv_len = driver->open(rhport, desc_itf, remaining_len);
|
|
||||||
|
|
||||||
if ( drv_len > 0 )
|
if ( drv_len > 0 )
|
||||||
{
|
{
|
||||||
@ -788,7 +805,7 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
|||||||
TU_ASSERT( sizeof(tusb_desc_interface_t) <= drv_len && drv_len <= remaining_len);
|
TU_ASSERT( sizeof(tusb_desc_interface_t) <= drv_len && drv_len <= remaining_len);
|
||||||
|
|
||||||
// Interface number must not be used already
|
// Interface number must not be used already
|
||||||
TU_ASSERT( DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] );
|
TU_ASSERT(DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber]);
|
||||||
|
|
||||||
TU_LOG2(" %s opened\r\n", driver->name);
|
TU_LOG2(" %s opened\r\n", driver->name);
|
||||||
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
|
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
|
||||||
@ -806,16 +823,16 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, drv_len, drv_id); // TODO refactor
|
||||||
|
|
||||||
|
p_desc += drv_len; // next interface
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failed if cannot find supported driver
|
// Failed if cannot find supported driver
|
||||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT);
|
TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
|
||||||
|
|
||||||
mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, drv_len, drv_id); // TODO refactor
|
|
||||||
|
|
||||||
p_desc += drv_len; // next interface
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke callback
|
// invoke callback
|
||||||
|
@ -35,7 +35,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common/tusb_common.h"
|
#include "common/tusb_common.h"
|
||||||
#include "dcd.h"
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Application API
|
// Application API
|
||||||
@ -53,6 +52,7 @@ void tud_task (void);
|
|||||||
bool tud_task_event_ready(void);
|
bool tud_task_event_ready(void);
|
||||||
|
|
||||||
// Interrupt handler, name alias to DCD
|
// Interrupt handler, name alias to DCD
|
||||||
|
extern void dcd_int_handler(uint8_t rhport);
|
||||||
#define tud_int_handler dcd_int_handler
|
#define tud_int_handler dcd_int_handler
|
||||||
|
|
||||||
// Get current bus speed
|
// Get current bus speed
|
||||||
@ -75,21 +75,11 @@ bool tud_remote_wakeup(void);
|
|||||||
|
|
||||||
// Enable pull-up resistor on D+ D-
|
// Enable pull-up resistor on D+ D-
|
||||||
// Return false on unsupported MCUs
|
// Return false on unsupported MCUs
|
||||||
static inline bool tud_disconnect(void)
|
bool tud_disconnect(void);
|
||||||
{
|
|
||||||
TU_VERIFY(dcd_disconnect);
|
|
||||||
dcd_disconnect(TUD_OPT_RHPORT);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable pull-up resistor on D+ D-
|
// Disable pull-up resistor on D+ D-
|
||||||
// Return false on unsupported MCUs
|
// Return false on unsupported MCUs
|
||||||
static inline bool tud_connect(void)
|
bool tud_connect(void);
|
||||||
{
|
|
||||||
TU_VERIFY(dcd_connect);
|
|
||||||
dcd_connect(TUD_OPT_RHPORT);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carry out Data and Status stage of control transfer
|
// Carry out Data and Status stage of control transfer
|
||||||
// - If len = 0, it is equivalent to sending status only
|
// - If len = 0, it is equivalent to sending status only
|
||||||
|
@ -33,6 +33,30 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Class Drivers
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Invoked when initializing device stack to get additional class drivers.
|
||||||
|
// Can optionally implemented by application to extend/overwrite class driver support.
|
||||||
|
// Note: The drivers array must be accessible at all time when stack is active
|
||||||
|
usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) TU_ATTR_WEAK;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USBD Endpoint API
|
// USBD Endpoint API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -555,10 +555,10 @@ static void handle_ep0_nak(void)
|
|||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
void dcd_init(uint8_t rhport)
|
void dcd_init(uint8_t rhport)
|
||||||
{
|
{
|
||||||
(void)rhport;
|
|
||||||
|
|
||||||
USB->USB_MCTRL_REG = USB_USB_MCTRL_REG_USBEN_Msk;
|
USB->USB_MCTRL_REG = USB_USB_MCTRL_REG_USBEN_Msk;
|
||||||
tusb_vbus_changed((CRG_TOP->ANA_STATUS_REG & CRG_TOP_ANA_STATUS_REG_VBUS_AVAILABLE_Msk) != 0);
|
tusb_vbus_changed((CRG_TOP->ANA_STATUS_REG & CRG_TOP_ANA_STATUS_REG_VBUS_AVAILABLE_Msk) != 0);
|
||||||
|
|
||||||
|
dcd_connect(rhport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dcd_int_enable(uint8_t rhport)
|
void dcd_int_enable(uint8_t rhport)
|
||||||
|
@ -54,6 +54,9 @@
|
|||||||
// FIFO size in bytes
|
// FIFO size in bytes
|
||||||
#define EP_FIFO_SIZE 1024
|
#define EP_FIFO_SIZE 1024
|
||||||
|
|
||||||
|
// Max number of IN EP FIFOs
|
||||||
|
#define EP_FIFO_NUM 5
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint16_t total_len;
|
uint16_t total_len;
|
||||||
@ -71,6 +74,16 @@ static uint32_t _setup_packet[2];
|
|||||||
#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
|
#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
|
||||||
static xfer_ctl_t xfer_status[EP_MAX][2];
|
static xfer_ctl_t xfer_status[EP_MAX][2];
|
||||||
|
|
||||||
|
// Keep count of how many FIFOs are in use
|
||||||
|
static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
|
||||||
|
|
||||||
|
// Will either return an unused FIFO number, or 0 if all are used.
|
||||||
|
static uint8_t get_free_fifo(void)
|
||||||
|
{
|
||||||
|
if (_allocated_fifos < EP_FIFO_NUM) return _allocated_fifos++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Setup the control endpoint 0.
|
// Setup the control endpoint 0.
|
||||||
static void bus_reset(void)
|
static void bus_reset(void)
|
||||||
{
|
{
|
||||||
@ -152,8 +165,6 @@ static void enum_done_processing(void)
|
|||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
void dcd_init(uint8_t rhport)
|
void dcd_init(uint8_t rhport)
|
||||||
{
|
{
|
||||||
(void)rhport;
|
|
||||||
|
|
||||||
ESP_LOGV(TAG, "DCD init - Start");
|
ESP_LOGV(TAG, "DCD init - Start");
|
||||||
|
|
||||||
// A. Disconnect
|
// A. Disconnect
|
||||||
@ -191,6 +202,8 @@ void dcd_init(uint8_t rhport)
|
|||||||
USB_ENUMDONEMSK_M |
|
USB_ENUMDONEMSK_M |
|
||||||
USB_RESETDETMSK_M |
|
USB_RESETDETMSK_M |
|
||||||
USB_DISCONNINTMSK_M; // host most only
|
USB_DISCONNINTMSK_M; // host most only
|
||||||
|
|
||||||
|
dcd_connect(rhport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
|
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
|
||||||
@ -271,8 +284,12 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
|
|||||||
// - Offset: GRXFSIZ + 16 + Size*(epnum-1)
|
// - Offset: GRXFSIZ + 16 + Size*(epnum-1)
|
||||||
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
|
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
|
||||||
|
|
||||||
|
uint8_t fifo_num = get_free_fifo();
|
||||||
|
TU_ASSERT(fifo_num != 0);
|
||||||
|
|
||||||
|
in_ep[epnum].diepctl &= ~(USB_D_TXFNUM1_M | USB_D_EPTYPE1_M | USB_DI_SETD0PID1 | USB_D_MPS1_M);
|
||||||
in_ep[epnum].diepctl |= USB_D_USBACTEP1_M |
|
in_ep[epnum].diepctl |= USB_D_USBACTEP1_M |
|
||||||
epnum << USB_D_TXFNUM1_S |
|
fifo_num << USB_D_TXFNUM1_S |
|
||||||
desc_edpt->bmAttributes.xfer << USB_D_EPTYPE1_S |
|
desc_edpt->bmAttributes.xfer << USB_D_EPTYPE1_S |
|
||||||
(desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? (1 << USB_DI_SETD0PID1_S) : 0) |
|
(desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? (1 << USB_DI_SETD0PID1_S) : 0) |
|
||||||
desc_edpt->wMaxPacketSize.size << 0;
|
desc_edpt->wMaxPacketSize.size << 0;
|
||||||
@ -282,8 +299,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
|
|||||||
// Both TXFD and TXSA are in unit of 32-bit words.
|
// Both TXFD and TXSA are in unit of 32-bit words.
|
||||||
// IN FIFO 0 was configured during enumeration, hence the "+ 16".
|
// IN FIFO 0 was configured during enumeration, hence the "+ 16".
|
||||||
uint16_t const allocated_size = (USB0.grxfsiz & 0x0000ffff) + 16;
|
uint16_t const allocated_size = (USB0.grxfsiz & 0x0000ffff) + 16;
|
||||||
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_MAX-1);
|
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_FIFO_NUM-1);
|
||||||
uint32_t const fifo_offset = allocated_size + fifo_size*(epnum-1);
|
uint32_t const fifo_offset = allocated_size + fifo_size*(fifo_num-1);
|
||||||
|
|
||||||
// DIEPTXF starts at FIFO #1.
|
// DIEPTXF starts at FIFO #1.
|
||||||
USB0.dieptxf[epnum - 1] = (fifo_size << USB_NPTXFDEP_S) | fifo_offset;
|
USB0.dieptxf[epnum - 1] = (fifo_size << USB_NPTXFDEP_S) | fifo_offset;
|
||||||
@ -361,7 +378,8 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flush the FIFO, and wait until we have confirmed it cleared.
|
// Flush the FIFO, and wait until we have confirmed it cleared.
|
||||||
USB0.grstctl |= ((epnum - 1) << USB_TXFNUM_S);
|
uint8_t const fifo_num = ((in_ep[epnum].diepctl >> USB_D_TXFNUM1_S) & USB_D_TXFNUM1_V);
|
||||||
|
USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
|
||||||
USB0.grstctl |= USB_TXFFLSH_M;
|
USB0.grstctl |= USB_TXFFLSH_M;
|
||||||
while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
|
while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
|
||||||
} else {
|
} else {
|
||||||
@ -660,6 +678,8 @@ static void _dcd_int_handler(void* arg)
|
|||||||
// start of reset
|
// start of reset
|
||||||
ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset");
|
ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset");
|
||||||
USB0.gintsts = USB_USBRST_M;
|
USB0.gintsts = USB_USBRST_M;
|
||||||
|
// FIFOs will be reassigned when the endpoints are reopen
|
||||||
|
_allocated_fifos = 1;
|
||||||
bus_reset();
|
bus_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,9 +154,8 @@ static void bus_reset(void)
|
|||||||
// Initialize controller to device mode
|
// Initialize controller to device mode
|
||||||
void dcd_init (uint8_t rhport)
|
void dcd_init (uint8_t rhport)
|
||||||
{
|
{
|
||||||
(void) rhport;
|
|
||||||
|
|
||||||
tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
|
tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
|
||||||
|
dcd_connect(rhport);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable device interrupt
|
// Enable device interrupt
|
||||||
|
@ -271,6 +271,10 @@ void dcd_disconnect(uint8_t rhport)
|
|||||||
{
|
{
|
||||||
(void) rhport;
|
(void) rhport;
|
||||||
NRF_USBD->USBPULLUP = 0;
|
NRF_USBD->USBPULLUP = 0;
|
||||||
|
|
||||||
|
// Disable Pull-up does not trigger Power USB Removed, in fact it have no
|
||||||
|
// impact on the USB Power status at all -> need to submit unplugged event to the stack.
|
||||||
|
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect by enabling internal pull-up resistor on D+/D-
|
// connect by enabling internal pull-up resistor on D+/D-
|
||||||
@ -693,6 +697,8 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
|||||||
switch ( event )
|
switch ( event )
|
||||||
{
|
{
|
||||||
case USB_EVT_DETECTED:
|
case USB_EVT_DETECTED:
|
||||||
|
TU_LOG2("Power USB Detect\r\n");
|
||||||
|
|
||||||
if ( !NRF_USBD->ENABLE )
|
if ( !NRF_USBD->ENABLE )
|
||||||
{
|
{
|
||||||
/* Prepare for READY event receiving */
|
/* Prepare for READY event receiving */
|
||||||
@ -743,6 +749,12 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_EVT_READY:
|
case USB_EVT_READY:
|
||||||
|
TU_LOG2("Power USB Ready\r\n");
|
||||||
|
|
||||||
|
// Skip if pull-up is enabled and HCLK is already running.
|
||||||
|
// Application probably call this more than necessary.
|
||||||
|
if ( NRF_USBD->USBPULLUP && hfclk_running() ) break;
|
||||||
|
|
||||||
/* Waiting for USBD peripheral enabled */
|
/* Waiting for USBD peripheral enabled */
|
||||||
while ( !(USBD_EVENTCAUSE_READY_Msk & NRF_USBD->EVENTCAUSE) ) { }
|
while ( !(USBD_EVENTCAUSE_READY_Msk & NRF_USBD->EVENTCAUSE) ) { }
|
||||||
|
|
||||||
@ -810,6 +822,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_EVT_REMOVED:
|
case USB_EVT_REMOVED:
|
||||||
|
TU_LOG2("Power USB Removed\r\n");
|
||||||
if ( NRF_USBD->ENABLE )
|
if ( NRF_USBD->ENABLE )
|
||||||
{
|
{
|
||||||
// Abort all transfers
|
// Abort all transfers
|
||||||
@ -829,7 +842,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
|||||||
|
|
||||||
hfclk_disable();
|
hfclk_disable();
|
||||||
|
|
||||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
|
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -181,6 +181,8 @@ void dcd_init(uint8_t rhport)
|
|||||||
LPC_USB->UDCAH = (uint32_t) _dcd.udca;
|
LPC_USB->UDCAH = (uint32_t) _dcd.udca;
|
||||||
LPC_USB->DMAIntEn = (DMA_INT_END_OF_XFER_MASK /*| DMA_INT_NEW_DD_REQUEST_MASK*/ | DMA_INT_ERROR_MASK);
|
LPC_USB->DMAIntEn = (DMA_INT_END_OF_XFER_MASK /*| DMA_INT_NEW_DD_REQUEST_MASK*/ | DMA_INT_ERROR_MASK);
|
||||||
|
|
||||||
|
dcd_connect(rhport);
|
||||||
|
|
||||||
// Clear pending IRQ
|
// Clear pending IRQ
|
||||||
NVIC_ClearPendingIRQ(USB_IRQn);
|
NVIC_ClearPendingIRQ(USB_IRQn);
|
||||||
}
|
}
|
||||||
|
@ -346,6 +346,7 @@ void dcd_init(uint8_t rhport)
|
|||||||
dcd_reg->USBINTR = INTR_USB | INTR_ERROR | INTR_PORT_CHANGE | INTR_RESET | INTR_SUSPEND /*| INTR_SOF*/;
|
dcd_reg->USBINTR = INTR_USB | INTR_ERROR | INTR_PORT_CHANGE | INTR_RESET | INTR_SUSPEND /*| INTR_SOF*/;
|
||||||
|
|
||||||
dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
|
dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
|
||||||
|
dcd_reg->USBCMD |= USBCMD_RUN_STOP; // Connect
|
||||||
}
|
}
|
||||||
|
|
||||||
void dcd_int_enable(uint8_t rhport)
|
void dcd_int_enable(uint8_t rhport)
|
||||||
|
@ -205,7 +205,6 @@ static inline void reg16_clear_bits(__IO uint16_t *reg, uint16_t mask) {
|
|||||||
|
|
||||||
void dcd_init (uint8_t rhport)
|
void dcd_init (uint8_t rhport)
|
||||||
{
|
{
|
||||||
(void)rhport;
|
|
||||||
/* Clocks should already be enabled */
|
/* Clocks should already be enabled */
|
||||||
/* Use __HAL_RCC_USB_CLK_ENABLE(); to enable the clocks before calling this function */
|
/* Use __HAL_RCC_USB_CLK_ENABLE(); to enable the clocks before calling this function */
|
||||||
|
|
||||||
@ -244,7 +243,8 @@ void dcd_init (uint8_t rhport)
|
|||||||
USB->CNTR |= USB_CNTR_RESETM | (USE_SOF ? USB_CNTR_SOFM : 0) | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
|
USB->CNTR |= USB_CNTR_RESETM | (USE_SOF ? USB_CNTR_SOFM : 0) | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
|
||||||
dcd_handle_bus_reset();
|
dcd_handle_bus_reset();
|
||||||
|
|
||||||
// Data-line pull-up is left disconnected.
|
// Enable pull-up if supported
|
||||||
|
if ( dcd_connect ) dcd_connect(rhport);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.
|
// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.
|
||||||
|
@ -305,6 +305,7 @@ static void set_EP0_max_pkt_size()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set turn-around timeout according to link speed
|
// Set turn-around timeout according to link speed
|
||||||
|
extern uint32_t SystemCoreClock;
|
||||||
static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
|
static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
|
||||||
{
|
{
|
||||||
usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
|
usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
|
||||||
@ -317,7 +318,6 @@ static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Turnaround timeout depends on the MCU clock
|
// Turnaround timeout depends on the MCU clock
|
||||||
extern uint32_t SystemCoreClock;
|
|
||||||
uint32_t turnaround;
|
uint32_t turnaround;
|
||||||
|
|
||||||
if ( SystemCoreClock >= 32000000U )
|
if ( SystemCoreClock >= 32000000U )
|
||||||
@ -439,6 +439,13 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
|
|||||||
((total_bytes << USB_OTG_DIEPTSIZ_XFRSIZ_Pos) & USB_OTG_DIEPTSIZ_XFRSIZ_Msk);
|
((total_bytes << USB_OTG_DIEPTSIZ_XFRSIZ_Pos) & USB_OTG_DIEPTSIZ_XFRSIZ_Msk);
|
||||||
|
|
||||||
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_EPENA | USB_OTG_DIEPCTL_CNAK;
|
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_EPENA | USB_OTG_DIEPCTL_CNAK;
|
||||||
|
// For ISO endpoint set correct odd/even bit for next frame.
|
||||||
|
if ((in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPTYP) == USB_OTG_DIEPCTL_EPTYP_0)
|
||||||
|
{
|
||||||
|
// Take odd/even bit from frame counter.
|
||||||
|
uint32_t const odd_frame_now = (dev->DSTS & (1u << USB_OTG_DSTS_FNSOF_Pos));
|
||||||
|
in_ep[epnum].DIEPCTL |= (odd_frame_now ? USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Msk : USB_OTG_DIEPCTL_SODDFRM_Msk);
|
||||||
|
}
|
||||||
// Enable fifo empty interrupt only if there are something to put in the fifo.
|
// Enable fifo empty interrupt only if there are something to put in the fifo.
|
||||||
if(total_bytes != 0) {
|
if(total_bytes != 0) {
|
||||||
dev->DIEPEMPMSK |= (1 << epnum);
|
dev->DIEPEMPMSK |= (1 << epnum);
|
||||||
@ -527,6 +534,8 @@ void dcd_init (uint8_t rhport)
|
|||||||
|
|
||||||
// Enable global interrupt
|
// Enable global interrupt
|
||||||
usb_otg->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
|
usb_otg->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
|
||||||
|
|
||||||
|
dcd_connect(rhport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dcd_int_enable (uint8_t rhport)
|
void dcd_int_enable (uint8_t rhport)
|
||||||
@ -588,13 +597,13 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
|||||||
|
|
||||||
TU_ASSERT(epnum < EP_MAX);
|
TU_ASSERT(epnum < EP_MAX);
|
||||||
|
|
||||||
if (desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS)
|
if (desc_edpt->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
|
||||||
{
|
{
|
||||||
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 512 : 64));
|
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 1024 : 1023));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 1024 : 1023));
|
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 512 : 64));
|
||||||
}
|
}
|
||||||
|
|
||||||
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
|
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
|
||||||
@ -771,7 +780,7 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flush the FIFO, and wait until we have confirmed it cleared.
|
// Flush the FIFO, and wait until we have confirmed it cleared.
|
||||||
usb_otg->GRSTCTL |= ((epnum - 1) << USB_OTG_GRSTCTL_TXFNUM_Pos);
|
usb_otg->GRSTCTL |= (epnum << USB_OTG_GRSTCTL_TXFNUM_Pos);
|
||||||
usb_otg->GRSTCTL |= USB_OTG_GRSTCTL_TXFFLSH;
|
usb_otg->GRSTCTL |= USB_OTG_GRSTCTL_TXFFLSH;
|
||||||
while((usb_otg->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH_Msk) != 0);
|
while((usb_otg->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH_Msk) != 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,8 +70,7 @@ typedef enum
|
|||||||
SIZXY = 7
|
SIZXY = 7
|
||||||
} ep_regs_index_t;
|
} ep_regs_index_t;
|
||||||
|
|
||||||
#define EP_REGS(epnum, dir) &USBOEPCNF_1 + 64*dir + 8*(epnum - 1)
|
#define EP_REGS(epnum, dir) ((ep_regs_t) ((uintptr_t)&USBOEPCNF_1 + 64*dir + 8*(epnum - 1)))
|
||||||
|
|
||||||
|
|
||||||
static void bus_reset(void)
|
static void bus_reset(void)
|
||||||
{
|
{
|
||||||
@ -134,6 +133,9 @@ void dcd_init (uint8_t rhport)
|
|||||||
// Enable reset and wait for it before continuing.
|
// Enable reset and wait for it before continuing.
|
||||||
USBIE |= RSTRIE;
|
USBIE |= RSTRIE;
|
||||||
|
|
||||||
|
// Enable pullup.
|
||||||
|
USBCNF |= PUR_EN;
|
||||||
|
|
||||||
USBKEYPID = 0;
|
USBKEYPID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,6 @@ void setUp(void)
|
|||||||
if ( !tusb_inited() )
|
if ( !tusb_inited() )
|
||||||
{
|
{
|
||||||
dcd_init_Expect(rhport);
|
dcd_init_Expect(rhport);
|
||||||
dcd_connect_Expect(rhport);
|
|
||||||
tusb_init();
|
tusb_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,6 @@ void setUp(void)
|
|||||||
{
|
{
|
||||||
mscd_init_Expect();
|
mscd_init_Expect();
|
||||||
dcd_init_Expect(rhport);
|
dcd_init_Expect(rhport);
|
||||||
dcd_connect_Expect(rhport);
|
|
||||||
tusb_init();
|
tusb_init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user