added tud_suspended() and tud_ready()

This commit is contained in:
hathach
2019-03-30 23:01:23 +07:00
parent f3a954e7de
commit eabfc53f38
6 changed files with 39 additions and 9 deletions

View File

@@ -99,7 +99,7 @@ static void _prep_out_transaction (uint8_t itf)
bool tud_cdc_n_connected(uint8_t itf)
{
// DTR (bit 0) active is considered as connected
return tud_mounted() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
return tud_ready() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
}
uint8_t tud_cdc_n_get_line_state (uint8_t itf)

View File

@@ -182,6 +182,11 @@ bool tud_mounted(void)
return _usbd_dev.configured;
}
bool tud_suspended(void)
{
return _usbd_dev.suspended;
}
bool tud_remote_wakeup(void)
{
// only wake up host if this feature is supported and enabled and we are suspended
@@ -627,6 +632,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
case DCD_EVENT_UNPLUGGED:
_usbd_dev.connected = 0;
_usbd_dev.configured = 0;
_usbd_dev.suspended = 0;
osal_queue_send(_usbd_q, event, in_isr);
break;

View File

@@ -66,6 +66,15 @@ void tud_task (void);
// Check if device is connected and configured
bool tud_mounted(void);
// Check if device is suspended
bool tud_suspended(void);
// Check if device is ready to transfer
static inline bool tud_ready(void)
{
return tud_mounted() && !tud_suspended();
}
// Remote wake up host, only if suspended and enabled by host
bool tud_remote_wakeup(void);
@@ -79,7 +88,8 @@ ATTR_WEAK void tud_mount_cb(void);
// Invoked when device is unmounted
ATTR_WEAK void tud_umount_cb(void);
// Invoked when usb bus is suspended, max bus current draw is 2.5 mA
// Invoked when usb bus is suspended
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
// Invoked when usb bus is resumed

View File

@@ -219,6 +219,9 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
void dcd_remote_wakeup(uint8_t rhport)
{
(void) rhport;
NRF_USBD->DPDMVALUE = USBD_DPDMVALUE_STATE_Resume;
NRF_USBD->TASKS_DPDMDRIVE = 1;
}
//--------------------------------------------------------------------+
@@ -389,6 +392,8 @@ void USBD_IRQHandler(void)
if ( evt_cause & USBD_EVENTCAUSE_SUSPEND_Msk )
{
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
}
if ( evt_cause & USBD_EVENTCAUSE_RESUME_Msk )