seperate tusb_task() to tud_task() and tuh_task()

tusb_task() still exists for backward compatible
This commit is contained in:
hathach
2018-12-13 14:51:37 +07:00
parent af1ffe4675
commit 1c49c479ca
13 changed files with 64 additions and 49 deletions

View File

@@ -340,7 +340,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
/*------------- Boot protocol only keyboard & mouse -------------*/
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, ERR_TUD_INVALID_DESCRIPTOR);
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE);
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)

View File

@@ -208,8 +208,24 @@ static void usbd_reset(uint8_t rhport)
/* USB Device Driver task
* This top level thread manages all device controller event and delegates events to class-specific drivers.
* This should be called periodically within the mainloop or rtos thread.
*
@code
int main(void)
{
application_init();
tusb_init();
while(1) // the mainloop
{
application_code();
tud_task(); // tinyusb device task
}
}
@endcode
*/
void usbd_task (void)
void tud_task (void)
{
// Loop until there is no more events in the queue
while (1)

View File

@@ -81,6 +81,7 @@ extern tud_desc_set_t tud_desc_set;
// APPLICATION API
//--------------------------------------------------------------------+
bool tud_mounted(void);
void tud_task (void);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK (WEAK is optional)

View File

@@ -52,8 +52,6 @@ extern tud_desc_set_t const* usbd_desc_set;
// INTERNAL API for stack management
//--------------------------------------------------------------------+
bool usbd_init (void);
void usbd_task (void);
// Carry out Data and Status stage of control transfer
// - If len = 0, it is equivalent to sending status only

View File

@@ -601,8 +601,24 @@ bool enum_task(hcd_event_t* event)
/* USB Host Driver task
* This top level thread manages all host controller event and delegates events to class-specific drivers.
* This should be called periodically within the mainloop or rtos thread.
*
@code
int main(void)
{
application_init();
tusb_init();
while(1) // the mainloop
{
application_code();
tuh_task(); // tinyusb host task
}
}
@endcode
*/
void usbh_task(void)
void tuh_task(void)
{
// Loop until there is no more events in the queue
while (1)

View File

@@ -78,9 +78,9 @@ typedef struct {
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
//tusb_error_t tusbh_configuration_set (uint8_t dev_addr, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT;
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT ATTR_PURE;
static inline bool tuh_device_is_configured(uint8_t dev_addr) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_PURE;
void tuh_task(void);
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr);
static inline bool tuh_device_is_configured(uint8_t dev_addr)
{
return tuh_device_get_state(dev_addr) == TUSB_DEVICE_STATE_CONFIGURED;
@@ -89,7 +89,7 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr)
//--------------------------------------------------------------------+
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WARN_UNUSED_RESULT;
ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device);
/** Callback invoked when device is mounted (configured) */
ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr);
@@ -103,7 +103,6 @@ ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
#ifdef _TINY_USB_SOURCE_FILE_
bool usbh_init(void);
void usbh_task(void);
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data);

View File

@@ -68,17 +68,6 @@ bool tusb_init(void)
return TUSB_ERROR_NONE;
}
void tusb_task(void)
{
#if TUSB_OPT_HOST_ENABLED
usbh_task();
#endif
#if TUSB_OPT_DEVICE_ENABLED
usbd_task();
#endif
}
/*------------------------------------------------------------------*/
/* Debug
*------------------------------------------------------------------*/

View File

@@ -101,32 +101,24 @@
/** \ingroup group_application_api
* @{ */
// Initialize device/host stack according to tusb_config.h
// return true if success
// Initialize device/host stack
bool tusb_init(void);
/** Run all tinyusb's internal tasks (e.g host task, device task) and invoke callback
* This should be called periodically within the mainloop.
// TODO
// bool tusb_teardown(void);
@code
int main(void)
{
your_init_code();
tusb_init();
// other config code
// backward compatible only. TODO remove later
static inline void tusb_task(void)
{
#if TUSB_OPT_HOST_ENABLED
tuh_task();
#endif
while(1) // the mainloop
{
your_application_code();
tusb_task(); // handle tinyusb event, task etc ...
}
}
@endcode
*/
void tusb_task(void);
#if TUSB_OPT_DEVICE_ENABLED
tud_task();
#endif
}
/** @} */