summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-03-27 23:58:24 +0700
committerhathach <[email protected]>2019-03-27 23:58:24 +0700
commit8fb9fbb0b19de3422645e65fbd422c86cb548c62 (patch)
tree0fe97b0fb5f78737d6e34b605732cf8b904c044e /src
parentc09d754654eb7846f3b53cbe58da517076c97494 (diff)
add tud_mounted() check in tud_cdc_connected()
mark device as disconnected immed with DCD_EVENT_UNPLUGGED
Diffstat (limited to 'src')
-rw-r--r--src/class/cdc/cdc_device.c2
-rw-r--r--src/class/cdc/cdc_device.h1
-rw-r--r--src/device/usbd.c8
3 files changed, 7 insertions, 4 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index 2ac8d471c..7b8f1bf72 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -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 TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
+ return tud_mounted() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
}
uint8_t tud_cdc_n_get_line_state (uint8_t itf)
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h
index 468edef45..d9a200dd4 100644
--- a/src/class/cdc/cdc_device.h
+++ b/src/class/cdc/cdc_device.h
@@ -97,7 +97,6 @@ ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_li
//--------------------------------------------------------------------+
// INTERNAL USBD-CLASS DRIVER API
-
//--------------------------------------------------------------------+
void cdcd_init (void);
bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length);
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 604f35bc5..58c0d3c4d 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -40,7 +40,7 @@
// Device Data
//--------------------------------------------------------------------+
typedef struct {
- uint8_t config_num;
+ volatile uint8_t config_num;
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
@@ -332,7 +332,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
break;
case TUSB_REQ_GET_CONFIGURATION:
- data_buf = &_usbd_dev.config_num;
+ data_buf = (uint8_t*) &_usbd_dev.config_num;
data_len = 1;
break;
@@ -543,7 +543,11 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
switch (event->event_id)
{
case DCD_EVENT_BUS_RESET:
+ osal_queue_send(_usbd_q, event, in_isr);
+ break;
+
case DCD_EVENT_UNPLUGGED:
+ _usbd_dev.config_num = 0; // mark disconnected
osal_queue_send(_usbd_q, event, in_isr);
break;