mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
working on suspend and resume
change dcd_init signature
This commit is contained in:
parent
0bdd4bd550
commit
1c2beba85c
@ -127,6 +127,7 @@ void usb_hid_task(void)
|
||||
if ( board_millis() < start_ms + interval_ms) return; // not enough time
|
||||
start_ms += interval_ms;
|
||||
|
||||
#if 1
|
||||
uint32_t const btn = board_buttons();
|
||||
|
||||
/*------------- Keyboard -------------*/
|
||||
@ -160,18 +161,29 @@ void usb_hid_task(void)
|
||||
if ( btn & 0x04 ) tud_hid_mouse_move( 0 , -DELTA); // up
|
||||
if ( btn & 0x08 ) tud_hid_mouse_move( 0 , DELTA); // down
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
|
||||
{
|
||||
// TODO not Implemented
|
||||
(void) report_id;
|
||||
(void) report_type;
|
||||
(void) buffer;
|
||||
(void) reqlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
|
||||
{
|
||||
// TODO not Implemented
|
||||
(void) report_id;
|
||||
(void) report_type;
|
||||
(void) buffer;
|
||||
(void) bufsize;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -38,7 +38,6 @@
|
||||
#define CFG_TUD_CDC_EPSIZE 64
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -103,6 +103,13 @@ typedef enum
|
||||
TUSB_REQ_SYNCH_FRAME ///< 12
|
||||
}tusb_request_code_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_REQ_FEATURE_EDPT_HALT = 0,
|
||||
TUSB_REQ_FEATURE_REMOTE_WAKEUP = 1,
|
||||
TUSB_REQ_FEATURE_TEST_MODE = 2
|
||||
}tusb_request_feature_selector_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_REQ_TYPE_STANDARD = 0,
|
||||
|
@ -80,7 +80,9 @@ TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Device API
|
||||
*------------------------------------------------------------------*/
|
||||
bool dcd_init (uint8_t rhport);
|
||||
|
||||
// Initialize controller to device mode
|
||||
void dcd_init (uint8_t rhport);
|
||||
|
||||
// Enable device interrupt
|
||||
void dcd_int_enable (uint8_t rhport);
|
||||
@ -91,9 +93,12 @@ void dcd_int_disable(uint8_t rhport);
|
||||
// Receive Set Address request, mcu port must also include status IN response
|
||||
void dcd_set_address(uint8_t rhport, uint8_t dev_addr);
|
||||
|
||||
// Receive Set Config request
|
||||
// Receive Set Configure request
|
||||
void dcd_set_config (uint8_t rhport, uint8_t config_num);
|
||||
|
||||
// Wake up host
|
||||
void dcd_remote_wakeup(uint8_t rhport);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Endpoint API
|
||||
* - open : Configure endpoint's registers
|
||||
|
@ -40,12 +40,13 @@
|
||||
// Device Data
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
volatile uint8_t config_num; // 0 is non-configure ~ disconnect
|
||||
volatile uint8_t config_num; // 0 is non-configured ~ disconnect
|
||||
bool remote_wakeup_en;
|
||||
|
||||
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
|
||||
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
|
||||
|
||||
uint8_t ep_busy_mask[2]; // bit mask for busy endpoint
|
||||
// uint8_t ep_busy_mask[2]; // bit mask for busy endpoint
|
||||
uint8_t ep_stall_mask[2]; // bit mask for stalled endpoint
|
||||
}usbd_device_t;
|
||||
|
||||
@ -186,7 +187,7 @@ bool usbd_init (void)
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();
|
||||
|
||||
// Init device controller driver
|
||||
TU_ASSERT(dcd_init(TUD_OPT_RHPORT));
|
||||
dcd_init(TUD_OPT_RHPORT);
|
||||
dcd_int_enable(TUD_OPT_RHPORT);
|
||||
|
||||
return true;
|
||||
@ -352,6 +353,20 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
if ( data_buf == NULL || data_len == 0 ) return false;
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue )
|
||||
{
|
||||
// Host enable remote wake up before suspending especially HID device
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue )
|
||||
{
|
||||
// Host disable remote wake up after resuming
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
TU_BREAKPOINT();
|
||||
return false;
|
||||
@ -386,15 +401,19 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
// only endpoint feature is halted/stalled
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
dcd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
usbd_control_status(rhport, p_request);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
// only endpoint feature is halted/stalled
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
usbd_control_status(rhport, p_request);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -556,11 +575,8 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SUSPEND:
|
||||
// TODO support suspended
|
||||
break;
|
||||
|
||||
case DCD_EVENT_RESUME:
|
||||
// TODO support resume
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
|
@ -60,7 +60,6 @@ typedef struct {
|
||||
|
||||
}tud_desc_set_t;
|
||||
|
||||
|
||||
// Must be defined by application
|
||||
extern tud_desc_set_t tud_desc_set;
|
||||
|
||||
@ -70,6 +69,8 @@ extern tud_desc_set_t tud_desc_set;
|
||||
bool tud_mounted(void);
|
||||
void tud_task (void);
|
||||
|
||||
bool tud_remote_wakeup(void);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK (WEAK is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
@ -77,10 +78,14 @@ void tud_task (void);
|
||||
// Callback invoked when device is mounted (configured)
|
||||
ATTR_WEAK void tud_mount_cb(void);
|
||||
|
||||
// Callback invoked when device is unmounted (bus reset/unplugged)
|
||||
// Callback invoked when device is unmounted
|
||||
ATTR_WEAK void tud_umount_cb(void);
|
||||
|
||||
//void tud_device_suspended_cb(void);
|
||||
// Callback invoked when device is suspended
|
||||
ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
|
||||
|
||||
// Callback invoked when device is resumed
|
||||
ATTR_WEAK void tud_resume_cb(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ static void bus_reset(void) {
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Controller API
|
||||
*------------------------------------------------------------------*/
|
||||
bool dcd_init (uint8_t rhport)
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@ -80,8 +80,6 @@ bool dcd_init (uint8_t rhport)
|
||||
while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {}
|
||||
|
||||
USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF | USB_DEVICE_INTENSET_EORST;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -57,7 +57,7 @@ static void bus_reset(void) {
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Controller API
|
||||
*------------------------------------------------------------------*/
|
||||
bool dcd_init (uint8_t rhport)
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@ -79,8 +79,6 @@ bool dcd_init (uint8_t rhport)
|
||||
USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE | USB_CTRLA_RUNSTDBY;
|
||||
while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {}
|
||||
USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF | USB_DEVICE_INTENSET_EORST;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -177,10 +177,9 @@ static void xact_in_prepare(uint8_t epnum)
|
||||
//--------------------------------------------------------------------+
|
||||
// Controller API
|
||||
//--------------------------------------------------------------------+
|
||||
bool dcd_init (uint8_t rhport)
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -153,7 +153,7 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
|
||||
LPC_USB->DEVCMDSTAT |= dev_addr;
|
||||
}
|
||||
|
||||
bool dcd_init(uint8_t rhport)
|
||||
void dcd_init(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@ -166,8 +166,6 @@ bool dcd_init(uint8_t rhport)
|
||||
CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
|
||||
|
||||
NVIC_EnableIRQ(USB0_IRQn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -166,7 +166,7 @@ static void bus_reset(void)
|
||||
tu_memclr(&_dcd, sizeof(dcd_data_t));
|
||||
}
|
||||
|
||||
bool dcd_init(uint8_t rhport)
|
||||
void dcd_init(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@ -186,8 +186,6 @@ bool dcd_init(uint8_t rhport)
|
||||
// USB IRQ priority should be set by application previously
|
||||
NVIC_ClearPendingIRQ(USB_IRQn);
|
||||
NVIC_EnableIRQ(USB_IRQn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -121,7 +121,7 @@ static void bus_reset(uint8_t rhport)
|
||||
p_dcd->qhd[0].int_on_setup = 1; // OUT only
|
||||
}
|
||||
|
||||
bool dcd_init(uint8_t rhport)
|
||||
void dcd_init(uint8_t rhport)
|
||||
{
|
||||
LPC_USBHS_T* const lpc_usb = LPC_USB[rhport];
|
||||
dcd_data_t* p_dcd = dcd_data_ptr[rhport];
|
||||
@ -134,8 +134,6 @@ bool dcd_init(uint8_t rhport)
|
||||
|
||||
lpc_usb->USBCMD_D &= ~0x00FF0000; // Interrupt Threshold Interval = 0
|
||||
lpc_usb->USBCMD_D |= TU_BIT(0); // connect
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -35,10 +35,8 @@
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
bool dcd_init (uint8_t rhport)
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Enable device interrupt
|
||||
|
@ -128,7 +128,7 @@ static void end_of_reset(void) {
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Controller API
|
||||
*------------------------------------------------------------------*/
|
||||
bool dcd_init (uint8_t rhport)
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@ -161,8 +161,6 @@ bool dcd_init (uint8_t rhport)
|
||||
|
||||
// Enable pullup, enable peripheral.
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN | USB_OTG_GCCFG_PWRDWN;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_int_enable (uint8_t rhport)
|
||||
|
Loading…
x
Reference in New Issue
Block a user