diff options
| author | hathach <[email protected]> | 2021-05-02 01:46:22 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-05-18 12:58:24 +0700 |
| commit | 2666e1efec20d78f8f74c23cdbb7977737b8d956 (patch) | |
| tree | 6ab8a02da835daf4065260513992c9ac342fa64a /src/device | |
| parent | 68fa17e17ca900ec2800c55c9345a2a0fed3fca9 (diff) | |
add tuh_inited() and tud_inited()
Diffstat (limited to 'src/device')
| -rw-r--r-- | src/device/usbd.c | 19 | ||||
| -rw-r--r-- | src/device/usbd.h | 3 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index 2853b619b..fe18b21b3 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -44,6 +44,10 @@ //--------------------------------------------------------------------+ // Device Data //--------------------------------------------------------------------+ + +// Invalid driver ID in itf2drv[] ep2drv[][] mapping +enum { DRVID_INVALID = 0xFFu }; + typedef struct { struct TU_ATTR_PACKED @@ -76,9 +80,6 @@ typedef struct static usbd_device_t _usbd_dev; -// Invalid driver ID in itf2drv[] ep2drv[][] mapping -enum { DRVID_INVALID = 0xFFu }; - //--------------------------------------------------------------------+ // Class Driver //--------------------------------------------------------------------+ @@ -241,6 +242,8 @@ static inline usbd_class_driver_t const * get_driver(uint8_t drvid) // DCD Event //--------------------------------------------------------------------+ +static bool _initialized = false; + // Event queue // OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr) OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t); @@ -368,8 +371,16 @@ bool tud_connect(void) //--------------------------------------------------------------------+ // USBD Task //--------------------------------------------------------------------+ +bool tud_inited(void) +{ + return _initialized; +} + bool tud_init (void) { + // skip if already initialized + if (_initialized) return _initialized; + TU_LOG2("USBD init\r\n"); tu_varclr(&_usbd_dev); @@ -402,6 +413,8 @@ bool tud_init (void) dcd_init(TUD_OPT_RHPORT); dcd_int_enable(TUD_OPT_RHPORT); + _initialized = true; + return true; } diff --git a/src/device/usbd.h b/src/device/usbd.h index 7c50a6db0..10fbe0bf1 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -43,6 +43,9 @@ extern "C" { // Init device stack bool tud_init (void); +// Check if device stack is already initialized +bool tud_inited(void); + // Task function should be called in main/rtos loop void tud_task (void); |
