update tinyusb

This commit is contained in:
hathach committed 2018-08-29 15:38:55 +07:00
1 parent 2b1f24524e
commit e5d69d7b9a
5 files changed
+60 -58

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ feather52832.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 -Os
#**********************************************
# Feather nRF52840 Board
#**********************************************
feather52840.name=Adafruit Bluefruit nRF52840 Feather
feather52840.name=Adafruit Bluefruit nRF52840 Feather Express
# DFU Mode with CDC only
feather52840.vid.0=0x239A
@@ -73,8 +73,8 @@ typedef struct
uint8_t tx_ff_buf[CFG_TUD_CDC_TX_BUFSIZE];
// Endpoint Transfer buffer
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_CDC_EPSIZE];
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_CDC_EPSIZE];
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_CDC_EPSIZE];
}cdcd_interface_t;
@@ -90,7 +90,7 @@ CFG_TUSB_ATTR_USBRAM static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
//--------------------------------------------------------------------+
bool tud_cdc_n_connected(uint8_t itf)
{
// DTR (bit 0) active isconsidered as connected
// DTR (bit 0) active is considered as connected
return BIT_TEST_(_cdcd_itf[itf].line_state, 0);
}
@@ -159,11 +159,12 @@ bool tud_cdc_n_write_flush (uint8_t itf)
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
TU_VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
if ( count ) TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epout_buf, count) );
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE);
if ( count )
{
TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
}
return true;
}
@@ -264,7 +265,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface
}
// Prepare for incoming data
TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER);
TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER);
return TUSB_ERROR_NONE;
}
@@ -293,16 +294,15 @@ tusb_error_t cdcd_control_request_st(uint8_t rhport, tusb_control_request_t cons
}
else if (CDC_REQUEST_SET_CONTROL_LINE_STATE == p_request->bRequest )
{
dcd_control_status(rhport, p_request->bmRequestType_bit.direction); // ACK control request
// CDC PSTN v1.2 section 6.3.12
// Bit 0: Indicates if DTE is present or not.
// This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready)
// Bit 1: Carrier control for half-duplex modems.
// This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send)
p_cdc->line_state = (uint8_t) p_request->wValue;
dcd_control_status(rhport, p_request->bmRequestType_bit.direction); // ACK control request
// Invoke callback
if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, BIT_TEST_(p_request->wValue, 0), BIT_TEST_(p_request->wValue, 1));
}
@@ -327,10 +327,10 @@ tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
for(uint32_t i=0; i<xferred_bytes; i++)
{
tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epin_buf[i]);
tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epout_buf[i]);
// Check for wanted char and invoke callback if needed
if ( tud_cdc_rx_wanted_cb && ( wanted != -1 ) && ( wanted == p_cdc->epin_buf[i] ) )
if ( tud_cdc_rx_wanted_cb && ( wanted != -1 ) && ( wanted == p_cdc->epout_buf[i] ) )
{
tud_cdc_rx_wanted_cb(itf, wanted);
}
@@ -340,7 +340,7 @@ tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
// prepare for next
TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER );
TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER );
}
// nothing to do with in and notif endpoint
+37 -33
View File
@@ -265,45 +265,49 @@ static tusb_error_t usbd_main_st(void)
OSAL_SUBTASK_BEGIN
tusb_error_t err;
err = TUSB_ERROR_NONE;
memclr_(&event, sizeof(usbd_task_event_t));
osal_queue_receive(_usbd_q, &event, OSAL_TIMEOUT_WAIT_FOREVER, &err);
if ( USBD_EVT_SETUP_RECEIVED == event.event_id )
// Loop until there is no more events in the queue
while (1)
{
STASK_INVOKE( proc_control_request_st(event.rhport, &event.setup_received), err );
}
else if (USBD_EVT_XFER_DONE == event.event_id)
{
// Invoke the class callback associated with the endpoint address
uint8_t const ep_addr = event.xfer_done.ep_addr;
uint8_t const drv_id = _usbd_dev.ep2drv[ edpt_dir(ep_addr) ][ edpt_number(ep_addr) ];
tusb_error_t err;
err = TUSB_ERROR_NONE;
if (drv_id < USBD_CLASS_DRIVER_COUNT)
memclr_(&event, sizeof(usbd_task_event_t));
osal_queue_receive(_usbd_q, &event, OSAL_TIMEOUT_WAIT_FOREVER, &err);
if ( USBD_EVT_SETUP_RECEIVED == event.event_id )
{
usbd_class_drivers[drv_id].xfer_cb( event.rhport, ep_addr, (tusb_event_t) event.xfer_done.result, event.xfer_done.xferred_byte);
STASK_INVOKE( proc_control_request_st(event.rhport, &event.setup_received), err );
}
}
else if (USBD_EVT_SOF == event.event_id)
{
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
else if (USBD_EVT_XFER_DONE == event.event_id)
{
if ( usbd_class_drivers[i].sof )
// Invoke the class callback associated with the endpoint address
uint8_t const ep_addr = event.xfer_done.ep_addr;
uint8_t const drv_id = _usbd_dev.ep2drv[ edpt_dir(ep_addr) ][ edpt_number(ep_addr) ];
if (drv_id < USBD_CLASS_DRIVER_COUNT)
{
usbd_class_drivers[i].sof( event.rhport );
usbd_class_drivers[drv_id].xfer_cb( event.rhport, ep_addr, (tusb_event_t) event.xfer_done.result, event.xfer_done.xferred_byte);
}
}
}
else if ( USBD_EVT_FUNC_CALL == event.event_id )
{
if ( event.func_call.func ) event.func_call.func(event.func_call.param);
}
else
{
STASK_ASSERT(false);
else if (USBD_EVT_SOF == event.event_id)
{
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
{
if ( usbd_class_drivers[i].sof )
{
usbd_class_drivers[i].sof( event.rhport );
}
}
}
else if ( USBD_EVT_FUNC_CALL == event.event_id )
{
if ( event.func_call.func ) event.func_call.func(event.func_call.param);
}
else
{
STASK_ASSERT(false);
}
}
OSAL_SUBTASK_END
@@ -601,8 +605,8 @@ void dcd_setup_received(uint8_t rhport, uint8_t const* p_request)
{
usbd_task_event_t task_event =
{
.rhport = rhport,
.event_id = USBD_EVT_SETUP_RECEIVED,
.rhport = rhport,
.event_id = USBD_EVT_SETUP_RECEIVED,
};
memcpy(&task_event.setup_received, p_request, sizeof(tusb_control_request_t));
+1 -1
View File
@@ -83,7 +83,7 @@ extern tud_desc_set_t tud_desc_set;
bool tud_mounted(void);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK
// APPLICATION CALLBACK (WEAK is optional)
//--------------------------------------------------------------------+
/** Callback invoked when device is mounted (configured) */
@@ -60,7 +60,8 @@ enum
MAX_PACKET_SIZE = 64,
// Mask of all END event (IN & OUT) for all endpoints. ENDEPIN0-7, ENDEPOUT0-7, ENDISOIN, ENDISOOUT
EDPT_END_ALL_MASK = 0x1FFBFCUL
EDPT_END_ALL_MASK = (0xff << USBD_INTEN_ENDEPIN0_Pos) | (0xff << USBD_INTEN_ENDEPOUT0_Pos) |
USBD_INTENCLR_ENDISOIN_Msk | USBD_INTEN_ENDISOOUT_Msk
};
/*------------------------------------------------------------------*/
@@ -85,7 +86,7 @@ typedef struct
{
uint8_t* buffer;
uint16_t total_len;
uint16_t actual_len;
volatile uint16_t actual_len;
uint8_t dir;
}control;
@@ -215,9 +216,9 @@ bool dcd_control_xfer (uint8_t rhport, uint8_t dir, uint8_t * buffer, uint16_t l
xact_control_start();
}else
{
// Status Phase
NRF_USBD->TASKS_EP0STATUS = 1;
__ISB(); __DSB();
// Status Phase also require Easy DMA has to be free as well !!!!
edpt_dma_start(&NRF_USBD->TASKS_EP0STATUS);
edpt_dma_end();
}
return true;
@@ -401,7 +402,7 @@ void USBD_IRQHandler(void)
volatile uint32_t* regevt = &NRF_USBD->EVENTS_USBRESET;
for(int i=0; i<32; i++)
for(int i=0; i<USBD_INTEN_EPDATA_Pos+1; i++)
{
if ( BIT_TEST_(inten, i) && regevt[i] )
{
@@ -417,7 +418,6 @@ void USBD_IRQHandler(void)
if ( int_status & USBD_INTEN_USBRESET_Msk )
{
bus_reset();
dcd_bus_event(0, USBD_BUS_EVENT_RESET);
}
@@ -558,8 +558,6 @@ void USBD_IRQHandler(void)
{
dcd_bus_event(0, USBD_BUS_EVENT_SOF);
}
}
#endif