mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 06:40:45 +00:00
refractor usbd-dcd callback, add bus event isr
This commit is contained in:
parent
d94efa60d6
commit
6887e5e642
@ -117,10 +117,10 @@ void tusbd_cdc_xfer_isr(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id
|
||||
|
||||
OSAL_TASK_FUNCTION( cdcd_serial_app_task ) (void* p_task_para)
|
||||
{
|
||||
tusb_error_t error;
|
||||
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
tusb_error_t error;
|
||||
|
||||
osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
||||
|
||||
if ( tusbd_cdc_is_configured(0) )
|
||||
|
@ -46,6 +46,8 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
OSAL_TASK_DEF(keyboardd_app_task, 128, KEYBOARDD_APP_TASK_PRIO);
|
||||
|
||||
ATTR_USB_MIN_ALIGNMENT hid_keyboard_report_t keyboard_report TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -62,11 +64,13 @@ void tusbd_hid_keyboard_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred
|
||||
|
||||
void keyboardd_app_init(void)
|
||||
{
|
||||
|
||||
ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(keyboardd_app_task) ), VOID_RETURN);
|
||||
}
|
||||
|
||||
OSAL_TASK_FUNCTION( keyboardd_app_task ) (void* p_task_para)
|
||||
{
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
if (tusbd_is_configured(0))
|
||||
{
|
||||
static uint32_t count =0;
|
||||
@ -79,6 +83,10 @@ OSAL_TASK_FUNCTION( keyboardd_app_task ) (void* p_task_para)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osal_task_delay(1000);
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -50,6 +50,8 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
OSAL_TASK_DEF(moused_app_task, 128, MOUSED_APP_TASK_PRIO);
|
||||
|
||||
ATTR_USB_MIN_ALIGNMENT hid_mouse_report_t mouse_report TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -62,11 +64,13 @@ void tusbd_hid_mouse_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred_by
|
||||
|
||||
void moused_app_init(void)
|
||||
{
|
||||
|
||||
ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(moused_app_task) ), VOID_RETURN);
|
||||
}
|
||||
|
||||
OSAL_TASK_FUNCTION( moused_app_task ) (void* p_task_para)
|
||||
{
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
if (tusbd_is_configured(0))
|
||||
{
|
||||
static uint32_t count =0;
|
||||
@ -79,6 +83,10 @@ OSAL_TASK_FUNCTION( moused_app_task ) (void* p_task_para)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osal_task_delay(1000);
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -81,17 +81,16 @@
|
||||
#define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor, remove
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD 0
|
||||
#define TUSB_CFG_DEVICE_HID_MOUSE 0
|
||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD 1
|
||||
#define TUSB_CFG_DEVICE_HID_MOUSE 1
|
||||
#define TUSB_CFG_DEVICE_HID_GENERIC 0
|
||||
#define TUSB_CFG_DEVICE_MSC 1
|
||||
#define TUSB_CFG_DEVICE_CDC 0
|
||||
#define TUSB_CFG_DEVICE_CDC 1
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// COMMON CONFIGURATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUSB_CFG_DEBUG 3
|
||||
|
||||
#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build
|
||||
|
@ -194,7 +194,7 @@ tusb_error_t cdcd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void cdcd_bus_reset(uint8_t coreid)
|
||||
void cdcd_close(uint8_t coreid)
|
||||
{
|
||||
// no need to close opened pipe, dcd bus reset will put controller's endpoints to default state
|
||||
memclr_(&cdcd_data[coreid], sizeof(cdcd_data_t));
|
||||
|
@ -63,11 +63,13 @@ bool tusbd_cdc_is_busy(uint8_t coreid, cdc_pipeid_t pipeid) ATTR_PURE ATTR_WARN
|
||||
tusb_error_t tusbd_cdc_send(uint8_t coreid, void * p_data, uint32_t length, bool is_notify);
|
||||
tusb_error_t tusbd_cdc_receive(uint8_t coreid, void * p_buffer, uint32_t length, bool is_notify);
|
||||
|
||||
//------------- Callback -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbd_cdc_mounted_cb(uint8_t coreid);
|
||||
void tusbd_cdc_unmounted_cb(uint8_t coreid);
|
||||
void tusbd_cdc_xfer_isr(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes);
|
||||
void tusbd_cdc_line_coding_changed_cb(uint8_t coreid, cdc_line_coding_t* p_line_coding);
|
||||
//void tusbd_cdc_line_coding_changed_cb(uint8_t coreid, cdc_line_coding_t* p_line_coding);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS DRIVER API
|
||||
@ -76,9 +78,9 @@ void tusbd_cdc_line_coding_changed_cb(uint8_t coreid, cdc_line_coding_t* p_line_
|
||||
|
||||
void cdcd_init(void);
|
||||
tusb_error_t cdcd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
void cdcd_bus_reset(uint8_t coreid);
|
||||
tusb_error_t cdcd_control_request(uint8_t coreid, tusb_control_request_t const * p_request);
|
||||
void cdcd_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void cdcd_close(uint8_t coreid);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -124,7 +124,7 @@ void hidd_init(void)
|
||||
// TODO not implemented yet
|
||||
}
|
||||
|
||||
void hidd_bus_reset(uint8_t coreid)
|
||||
void hidd_close(uint8_t coreid)
|
||||
{
|
||||
// TODO not implemented yet
|
||||
}
|
||||
@ -148,6 +148,8 @@ tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const *
|
||||
uint8_t const desc_type = u16_high_u8(p_request->wValue);
|
||||
uint8_t const desc_index = u16_low_u8 (p_request->wValue);
|
||||
|
||||
(void) desc_index;
|
||||
|
||||
ASSERT ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT,
|
||||
TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT);
|
||||
|
||||
@ -170,6 +172,9 @@ tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const *
|
||||
hid_request_report_type_t report_type = u16_high_u8(p_request->wValue);
|
||||
uint8_t report_id = u16_low_u8(p_request->wValue);
|
||||
|
||||
(void) report_id;
|
||||
(void) report_type;
|
||||
|
||||
dcd_pipe_control_xfer(coreid, TUSB_DIR_HOST_TO_DEV, &set_report, p_request->wLength);
|
||||
}
|
||||
break;
|
||||
|
@ -49,13 +49,21 @@
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD Application API
|
||||
// KEYBOARD APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
/** \defgroup Keyboard_Device Device
|
||||
* @{ */
|
||||
|
||||
/** \brief Check if the interface is configured and ready to use
|
||||
* \param[in] coreid USB Controller ID
|
||||
* \retval true if the interface is configured
|
||||
* \retval false if the interface is not configured (e.g device is not attached)
|
||||
* \note This function should be call frequently or before any xfer attempt to check if device is still attached
|
||||
*/
|
||||
bool tusbd_hid_keyboard_is_configured(uint8_t coreid);
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] coreid USB Controller ID
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
|
||||
@ -77,7 +85,9 @@ bool tusbd_hid_keyboard_is_busy(uint8_t coreid);
|
||||
*/
|
||||
tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_report);
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* \param[in] coreid USB Controller ID
|
||||
* \param[in] event an value from \ref tusb_event_t
|
||||
@ -88,6 +98,8 @@ tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const
|
||||
* \note Application should schedule the next report by calling \ref tusbh_hid_keyboard_get_report within this callback
|
||||
*/
|
||||
void tusbd_hid_keyboard_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void tusbd_hid_keyboard_mounted_cb(uint8_t coreid);
|
||||
void tusbd_hid_keyboard_unmounted_cb(uint8_t coreid);
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
@ -100,6 +112,14 @@ void tusbd_hid_keyboard_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred
|
||||
/** \defgroup Mouse_Device Device
|
||||
* @{ */
|
||||
|
||||
/** \brief Check if the interface is configured and ready to use
|
||||
* \param[in] coreid USB Controller ID
|
||||
* \retval true if the interface is configured
|
||||
* \retval false if the interface is not configured (e.g device is not attached)
|
||||
* \note This function should be call frequently or before any xfer attempt to check if device is still attached
|
||||
*/
|
||||
bool tusbd_hid_mouse_is_configured(uint8_t coreid);
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] coreid USB Controller ID
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
|
||||
@ -121,7 +141,12 @@ bool tusbd_hid_mouse_is_busy(uint8_t coreid);
|
||||
*/
|
||||
tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_report);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbd_hid_mouse_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void tusbd_hid_mouse_mounted_cb(uint8_t coreid);
|
||||
void tusbd_hid_mouse_unmounted_cb(uint8_t coreid);
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
@ -134,10 +159,10 @@ void tusbd_hid_mouse_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred_by
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
void hidd_init(void);
|
||||
void hidd_bus_reset(uint8_t coreid);
|
||||
tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const * p_request);
|
||||
void hidd_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void hidd_close(uint8_t coreid);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -75,7 +75,7 @@ void mscd_init(void)
|
||||
// TODO not implemented
|
||||
}
|
||||
|
||||
void mscd_bus_reset(uint8_t coreid)
|
||||
void mscd_close(uint8_t coreid)
|
||||
{
|
||||
// TODO not implemented yet
|
||||
}
|
||||
|
@ -50,6 +50,20 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \brief Check if the interface is configured and ready to use
|
||||
* \param[in] coreid USB Controller ID
|
||||
* \retval true if the interface is configured
|
||||
* \retval false if the interface is not configured (e.g device is not attached)
|
||||
* \note This function should be call frequently or before any xfer attempt to check if device is still attached
|
||||
*/
|
||||
bool tusbd_msc_is_configured(uint8_t coreid);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbd_msc_mounted_cb(uint8_t coreid);
|
||||
void tusbd_msc_unmounted_cb(uint8_t coreid);
|
||||
|
||||
// p_length [in,out] allocated/maximum length, application update with actual length
|
||||
msc_csw_status_t tusbd_msc_scsi_received_isr (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void ** pp_buffer, uint16_t* p_length);
|
||||
|
||||
@ -62,10 +76,10 @@ tusb_error_t tusbh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buf
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
void mscd_init(void);
|
||||
void mscd_bus_reset(uint8_t coreid);
|
||||
tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t mscd_control_request(uint8_t coreid, tusb_control_request_t const * p_request);
|
||||
void mscd_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void mscd_close(uint8_t coreid);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -73,42 +73,6 @@ STATIC_ dcd_data_t dcd_data TUSB_CFG_ATTR_USBRAM;
|
||||
static void bus_reset(void);
|
||||
static tusb_error_t pipe_control_read(void * buffer, uint16_t length);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SIE Command
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void sie_cmd_code (sie_cmdphase_t phase, uint8_t code_data) ATTR_ALWAYS_INLINE;
|
||||
static inline void sie_cmd_code (sie_cmdphase_t phase, uint8_t code_data)
|
||||
{
|
||||
LPC_USB->USBDevIntClr = (DEV_INT_COMMAND_CODE_EMPTY_MASK | DEV_INT_COMMAND_DATA_FULL_MASK);
|
||||
LPC_USB->USBCmdCode = (phase << 8) | (code_data << 16);
|
||||
|
||||
uint32_t const wait_flag = (phase == SIE_CMDPHASE_READ) ? DEV_INT_COMMAND_DATA_FULL_MASK : DEV_INT_COMMAND_CODE_EMPTY_MASK;
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & wait_flag) == 0); // TODO blocking forever potential
|
||||
#endif
|
||||
LPC_USB->USBDevIntClr = wait_flag;
|
||||
}
|
||||
|
||||
static inline void sie_write (uint8_t cmd_code, uint8_t data_len, uint8_t data) ATTR_ALWAYS_INLINE;
|
||||
static inline void sie_write (uint8_t cmd_code, uint8_t data_len, uint8_t data)
|
||||
{
|
||||
sie_cmd_code(SIE_CMDPHASE_COMMAND, cmd_code);
|
||||
|
||||
if (data_len)
|
||||
{
|
||||
sie_cmd_code(SIE_CMDPHASE_WRITE, data);
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t sie_read (uint8_t cmd_code, uint8_t data_len) ATTR_ALWAYS_INLINE;
|
||||
static inline uint32_t sie_read (uint8_t cmd_code, uint8_t data_len)
|
||||
{
|
||||
// TODO multiple read
|
||||
sie_cmd_code(SIE_CMDPHASE_COMMAND , cmd_code);
|
||||
sie_cmd_code(SIE_CMDPHASE_READ , cmd_code);
|
||||
return LPC_USB->USBCmdData;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PIPE HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
@ -239,22 +203,29 @@ void endpoint_control_isr(void)
|
||||
|
||||
void dcd_isr(uint8_t coreid)
|
||||
{
|
||||
(void) coreid;
|
||||
uint32_t const device_int_status = LPC_USB->USBDevIntSt & LPC_USB->USBDevIntEn;
|
||||
LPC_USB->USBDevIntClr = device_int_status;// Acknowledge handled interrupt
|
||||
|
||||
//------------- usb bus event -------------//
|
||||
if (device_int_status & DEV_INT_DEVICE_STATUS_MASK)
|
||||
{
|
||||
uint32_t const dev_status_reg = sie_read(SIE_CMDCODE_DEVICE_STATUS, 1);
|
||||
uint8_t const dev_status_reg = sie_read(SIE_CMDCODE_DEVICE_STATUS, 1);
|
||||
if (dev_status_reg & SIE_DEV_STATUS_RESET_MASK)
|
||||
{
|
||||
bus_reset();
|
||||
usbd_bus_reset(coreid);
|
||||
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_RESET);
|
||||
}
|
||||
|
||||
// TODO invoke some callbacks
|
||||
if (dev_status_reg & SIE_DEV_STATUS_CONNECT_CHANGE_MASK) { }
|
||||
if (dev_status_reg & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK) { }
|
||||
if ( (dev_status_reg & SIE_DEV_STATUS_CONNECT_CHANGE_MASK) && !(dev_status_reg & SIE_DEV_STATUS_CONNECT_STATUS_MASK))
|
||||
{ // device is disconnected, require using VBUS (P1_30)
|
||||
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_UNPLUGGED);
|
||||
}
|
||||
|
||||
if ( (dev_status_reg & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK) && (dev_status_reg & SIE_DEV_STATUS_SUSPEND_MASK) )
|
||||
{
|
||||
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_SUSPENDED);
|
||||
}
|
||||
}
|
||||
|
||||
//------------- Control Endpoint (Slave Mode) -------------//
|
||||
@ -323,16 +294,19 @@ void dcd_isr(uint8_t coreid)
|
||||
//--------------------------------------------------------------------+
|
||||
void dcd_controller_connect(uint8_t coreid)
|
||||
{
|
||||
(void) coreid;
|
||||
sie_write(SIE_CMDCODE_DEVICE_STATUS, 1, 1);
|
||||
}
|
||||
|
||||
void dcd_controller_set_address(uint8_t coreid, uint8_t dev_addr)
|
||||
{
|
||||
(void) coreid;
|
||||
sie_write(SIE_CMDCODE_SET_ADDRESS, 1, 0x80 | dev_addr); // 7th bit is : device_enable
|
||||
}
|
||||
|
||||
void dcd_controller_set_configuration(uint8_t coreid)
|
||||
{
|
||||
(void) coreid;
|
||||
sie_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1);
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ enum {
|
||||
|
||||
//------------- SIE Device Status (get/set from SIE_CMDCODE_DEVICE_STATUS) -------------//
|
||||
enum {
|
||||
SIE_DEV_STATUS_CONNECT_MASK = BIT_(0),
|
||||
SIE_DEV_STATUS_CONNECT_STATUS_MASK = BIT_(0),
|
||||
SIE_DEV_STATUS_CONNECT_CHANGE_MASK = BIT_(1),
|
||||
SIE_DEV_STATUS_SUSPEND_MASK = BIT_(2),
|
||||
SIE_DEV_STATUS_SUSPEND_CHANGE_MASK = BIT_(3),
|
||||
@ -196,6 +196,42 @@ enum {
|
||||
DD_STATUS_SYSTEM_ERROR
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SIE Command
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void sie_cmd_code (sie_cmdphase_t phase, uint8_t code_data) ATTR_ALWAYS_INLINE;
|
||||
static inline void sie_cmd_code (sie_cmdphase_t phase, uint8_t code_data)
|
||||
{
|
||||
LPC_USB->USBDevIntClr = (DEV_INT_COMMAND_CODE_EMPTY_MASK | DEV_INT_COMMAND_DATA_FULL_MASK);
|
||||
LPC_USB->USBCmdCode = (phase << 8) | (code_data << 16);
|
||||
|
||||
uint32_t const wait_flag = (phase == SIE_CMDPHASE_READ) ? DEV_INT_COMMAND_DATA_FULL_MASK : DEV_INT_COMMAND_CODE_EMPTY_MASK;
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & wait_flag) == 0); // TODO blocking forever potential
|
||||
#endif
|
||||
LPC_USB->USBDevIntClr = wait_flag;
|
||||
}
|
||||
|
||||
static inline void sie_write (uint8_t cmd_code, uint8_t data_len, uint8_t data) ATTR_ALWAYS_INLINE;
|
||||
static inline void sie_write (uint8_t cmd_code, uint8_t data_len, uint8_t data)
|
||||
{
|
||||
sie_cmd_code(SIE_CMDPHASE_COMMAND, cmd_code);
|
||||
|
||||
if (data_len)
|
||||
{
|
||||
sie_cmd_code(SIE_CMDPHASE_WRITE, data);
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t sie_read (uint8_t cmd_code, uint8_t data_len) ATTR_ALWAYS_INLINE;
|
||||
static inline uint32_t sie_read (uint8_t cmd_code, uint8_t data_len)
|
||||
{
|
||||
// TODO multiple read
|
||||
sie_cmd_code(SIE_CMDPHASE_COMMAND , cmd_code);
|
||||
sie_cmd_code(SIE_CMDPHASE_READ , cmd_code);
|
||||
return LPC_USB->USBCmdData;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -71,7 +71,7 @@ static usbd_class_driver_t const usbd_class_drivers[TUSB_CLASS_MAPPED_INDEX_STAR
|
||||
.open = hidd_open,
|
||||
.control_request = hidd_control_request,
|
||||
.isr = hidd_isr,
|
||||
.bus_reset = hidd_bus_reset
|
||||
.close = hidd_close
|
||||
},
|
||||
#endif
|
||||
|
||||
@ -82,7 +82,7 @@ static usbd_class_driver_t const usbd_class_drivers[TUSB_CLASS_MAPPED_INDEX_STAR
|
||||
.open = mscd_open,
|
||||
.control_request = mscd_control_request,
|
||||
.isr = mscd_isr,
|
||||
.bus_reset = mscd_bus_reset
|
||||
.close = mscd_close
|
||||
},
|
||||
#endif
|
||||
|
||||
@ -93,7 +93,7 @@ static usbd_class_driver_t const usbd_class_drivers[TUSB_CLASS_MAPPED_INDEX_STAR
|
||||
.open = cdcd_open,
|
||||
.control_request = cdcd_control_request,
|
||||
.isr = cdcd_isr,
|
||||
.bus_reset = cdcd_bus_reset
|
||||
.close = cdcd_close
|
||||
},
|
||||
#endif
|
||||
|
||||
@ -251,19 +251,6 @@ OSAL_TASK_FUNCTION(usbd_task) (void* p_task_para)
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
||||
void usbd_bus_reset(uint32_t coreid)
|
||||
{
|
||||
memclr_(&usbd_devices[coreid], sizeof(usbd_device_info_t));
|
||||
|
||||
for (tusb_std_class_code_t class_code = TUSB_CLASS_AUDIO; class_code <= TUSB_CLASS_AUDIO_VIDEO; class_code++)
|
||||
{
|
||||
if ( usbd_class_drivers[class_code].bus_reset )
|
||||
{
|
||||
usbd_class_drivers[class_code].bus_reset( coreid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tusb_error_t usbd_init (void)
|
||||
{
|
||||
ASSERT_STATUS ( dcd_init() );
|
||||
@ -368,8 +355,29 @@ tusb_error_t get_descriptor_subtask(uint8_t coreid, tusb_control_request_t * p_r
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Callback API
|
||||
// USBD-DCD Callback API
|
||||
//--------------------------------------------------------------------+
|
||||
void usbd_dcd_bus_event_isr(uint8_t coreid, usbd_bus_event_type_t bus_event)
|
||||
{
|
||||
switch(bus_event)
|
||||
{
|
||||
case USBD_BUS_EVENT_RESET :
|
||||
case USBD_BUS_EVENT_UNPLUGGED :
|
||||
memclr_(&usbd_devices[coreid], sizeof(usbd_device_info_t));
|
||||
for (tusb_std_class_code_t class_code = TUSB_CLASS_AUDIO; class_code <= TUSB_CLASS_AUDIO_VIDEO; class_code++)
|
||||
{
|
||||
if ( usbd_class_drivers[class_code].close ) usbd_class_drivers[class_code].close( coreid );
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_BUS_EVENT_SUSPENDED:
|
||||
usbd_devices[coreid].state = TUSB_DEVICE_STATE_SUSPENDED;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request)
|
||||
{
|
||||
usbd_devices[coreid].control_request = (*p_request);
|
||||
|
@ -72,7 +72,7 @@ typedef struct {
|
||||
tusb_error_t (* const open)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
|
||||
tusb_error_t (* const control_request) (uint8_t, tusb_control_request_t const *);
|
||||
void (* const isr) (endpoint_handle_t, tusb_event_t, uint32_t);
|
||||
void (* const bus_reset) (uint8_t);
|
||||
void (* const close) (uint8_t);
|
||||
} usbd_class_driver_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -55,24 +55,31 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USBD_MAX_INTERFACE 16 // TODO refractor later
|
||||
#define USBD_MAX_ENDPOINT 32 // TODO refractor later
|
||||
enum {
|
||||
USBD_INTERFACE_NUM_MAX = 16 // USB specs specify up to 16 endpoints per device
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
USBD_BUS_EVENT_RESET = 1,
|
||||
USBD_BUS_EVENT_UNPLUGGED,
|
||||
USBD_BUS_EVENT_SUSPENDED
|
||||
}usbd_bus_event_type_t;
|
||||
|
||||
typedef struct {
|
||||
volatile uint8_t state;
|
||||
uint8_t is_waiting_control_xfer; // set if task is waiting for control xfer to complete to proceed
|
||||
tusb_control_request_t control_request;
|
||||
uint8_t interface2class[USBD_MAX_INTERFACE]; // determine interface number belongs to which class
|
||||
uint8_t interface2class[USBD_INTERFACE_NUM_MAX]; // determine interface number belongs to which class
|
||||
}usbd_device_info_t;
|
||||
|
||||
extern usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
|
||||
//--------------------------------------------------------------------+
|
||||
// callback from DCD ISR
|
||||
//--------------------------------------------------------------------+
|
||||
void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void usbd_bus_reset(uint32_t coreid);
|
||||
void usbd_dcd_bus_event_isr(uint8_t coreid, usbd_bus_event_type_t bus_event);
|
||||
void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request);
|
||||
void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user