Merge branch 'master' into stm32f4

This commit is contained in:
hathach
2019-03-05 05:45:42 -08:00
committed by GitHub
35 changed files with 9036 additions and 212 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ typedef struct
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC] = { { 0 } };
//--------------------------------------------------------------------+
// APPLICATION API
+1 -1
View File
@@ -91,7 +91,7 @@ typedef struct
hidd_interface_t* itf;
} hidd_report_t ;
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[ITF_COUNT];
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[ITF_COUNT] = { { 0 } };
#if CFG_TUD_HID_KEYBOARD
+3 -1
View File
@@ -284,8 +284,10 @@ typedef struct ATTR_PACKED
{
uint8_t data_len;
uint8_t medium_type;
bool write_protected : 1;
uint8_t reserved : 7;
bool write_protected : 1;
uint8_t block_descriptor_len;
} scsi_mode_sense6_resp_t;
+33 -13
View File
@@ -83,7 +83,7 @@ typedef struct {
uint8_t add_sense_qualifier;
}mscd_interface_t;
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf;
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf = { 0 };
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _mscd_buf[CFG_TUD_MSC_BUFSIZE];
//--------------------------------------------------------------------+
@@ -265,14 +265,20 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf
.is_removable = 1,
.version = 2,
.response_data_format = 2,
.vendor_id = "Adafruit",
.product_id = "Feather52840",
.product_rev = "1.0"
// vendor_id, product_id, product_rev is space padded string
.vendor_id = "",
.product_id = "",
.product_rev = "",
};
strncpy((char*) inquiry_rsp.vendor_id , CFG_TUD_MSC_VENDOR , sizeof(inquiry_rsp.vendor_id));
strncpy((char*) inquiry_rsp.product_id , CFG_TUD_MSC_PRODUCT , sizeof(inquiry_rsp.product_id));
strncpy((char*) inquiry_rsp.product_rev, CFG_TUD_MSC_PRODUCT_REV, sizeof(inquiry_rsp.product_rev));
memset(inquiry_rsp.vendor_id, ' ', sizeof(inquiry_rsp.vendor_id));
memcpy(inquiry_rsp.vendor_id, CFG_TUD_MSC_VENDOR, tu_min32(strlen(CFG_TUD_MSC_VENDOR), sizeof(inquiry_rsp.vendor_id)));
memset(inquiry_rsp.product_id, ' ', sizeof(inquiry_rsp.product_id));
memcpy(inquiry_rsp.product_id, CFG_TUD_MSC_PRODUCT, tu_min32(strlen(CFG_TUD_MSC_PRODUCT), sizeof(inquiry_rsp.product_id)));
memset(inquiry_rsp.product_rev, ' ', sizeof(inquiry_rsp.product_rev));
memcpy(inquiry_rsp.product_rev, CFG_TUD_MSC_PRODUCT_REV, tu_min32(strlen(CFG_TUD_MSC_PRODUCT_REV), sizeof(inquiry_rsp.product_rev)));
ret = sizeof(inquiry_rsp);
memcpy(buffer, &inquiry_rsp, ret);
@@ -525,6 +531,12 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
}
else
{
// Move to default CMD stage when sending status
p_msc->stage = MSC_STAGE_CMD;
// Send SCSI Status
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
// Invoke complete callback if defined
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
{
@@ -539,12 +551,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
if ( tud_msc_scsi_complete_cb ) tud_msc_scsi_complete_cb(p_cbw->lun, p_cbw->command);
}
// Move to default CMD stage after sending status
p_msc->stage = MSC_STAGE_CMD;
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
//------------- Queue the next CBW -------------//
// Queue for the next CBW
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
}
}
@@ -594,6 +601,19 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
{
msc_cbw_t const * p_cbw = &p_msc->cbw;
bool writable = true;
if (tud_msc_is_writable_cb) {
writable = tud_msc_is_writable_cb(p_cbw->lun);
}
if (!writable) {
msc_csw_t* p_csw = &p_msc->csw;
p_csw->data_residue = p_cbw->total_bytes;
p_csw->status = MSC_CSW_STATUS_FAILED;
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_DATA_PROTECT, 0x27, 0x00); // Sense = Write protected
dcd_edpt_stall(rhport, p_msc->ep_out);
return;
}
// remaining bytes capped at class buffer
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
+4 -1
View File
@@ -61,7 +61,7 @@ typedef struct {
}usbd_device_t;
static usbd_device_t _usbd_dev;
static usbd_device_t _usbd_dev = { 0 };
// Auto descriptor is enabled, descriptor set point to auto generated one
#if CFG_TUD_DESC_AUTO
@@ -240,6 +240,9 @@ static void usbd_reset(uint8_t rhport)
*/
void tud_task (void)
{
// Skip if stack is not initialized
if ( !tusb_inited() ) return;
// Loop until there is no more events in the queue
while (1)
{
+3
View File
@@ -620,6 +620,9 @@ bool enum_task(hcd_event_t* event)
*/
void tuh_task(void)
{
// Skip if stack is not initialized
if ( !tusb_inited() ) return;
// Loop until there is no more events in the queue
while (1)
{
+1 -1
View File
@@ -296,7 +296,7 @@ void maybe_transfer_complete(void) {
uint32_t epintflag = ep->EPINTFLAG.reg;
uint16_t total_transfer_size;
uint16_t total_transfer_size = 0;
// Handle IN completions
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
+3 -13
View File
@@ -49,25 +49,16 @@
#ifdef SOFTDEVICE_PRESENT
#include "nrf_sdm.h"
#include "nrf_soc.h"
// TODO fully move to nrfx
enum {
NRFX_POWER_USB_EVT_DETECTED, /**< USB power detected on the connector (plugged in). */
NRFX_POWER_USB_EVT_REMOVED, /**< USB power removed from the connector. */
NRFX_POWER_USB_EVT_READY /**< USB power regulator ready. */
};
#else
#include "nrfx_power.h"
#endif
#include "nrfx_power.h"
#include "tusb_hal.h"
#include "device/dcd.h"
/*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/
#define USB_NVIC_PRIO 7
void tusb_hal_nrf_power_event(uint32_t event);
/*------------------------------------------------------------------*/
@@ -239,8 +230,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk |
USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk;
// Enable interrupt, Priorities 0,1,4,5 (nRF52) are reserved for SoftDevice
NVIC_SetPriority(USBD_IRQn, USB_NVIC_PRIO);
// Enable interrupt, priorities should be set by application
NVIC_ClearPendingIRQ(USBD_IRQn);
NVIC_EnableIRQ(USBD_IRQn);
+5
View File
@@ -68,6 +68,11 @@ bool tusb_init(void)
return TUSB_ERROR_NONE;
}
bool tusb_inited(void)
{
return _initialized;
}
/*------------------------------------------------------------------*/
/* Debug
*------------------------------------------------------------------*/
+3
View File
@@ -108,6 +108,9 @@
// Initialize device/host stack
bool tusb_init(void);
// Check if stack is initialized
bool tusb_inited(void);
// TODO
// bool tusb_teardown(void);