Skip to content

Commit

Permalink
change usbd_init() return to bool for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Dec 5, 2018
1 parent 3dc0653 commit d887829
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,22 @@ bool tud_mounted(void)
//--------------------------------------------------------------------+
// USBD Task
//--------------------------------------------------------------------+
tusb_error_t usbd_init (void)
bool usbd_init (void)
{
// Init device queue & task
_usbd_q = osal_queue_create(&_usbd_qdef);
TU_VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
TU_ASSERT(_usbd_q != NULL);

osal_task_create(&_usbd_task_def);

// Init class drivers
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();

// Init device controller driver
dcd_init(TUD_OPT_RHPORT);
TU_ASSERT(dcd_init(TUD_OPT_RHPORT));
dcd_int_enable(TUD_OPT_RHPORT);

return TUSB_ERROR_NONE;
return true;
}

static void usbd_reset(uint8_t rhport)
Expand Down
4 changes: 2 additions & 2 deletions src/device/usbd_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ extern tud_desc_set_t const* usbd_desc_set;
//--------------------------------------------------------------------+
// INTERNAL API for stack management
//--------------------------------------------------------------------+
tusb_error_t usbd_init (void);
void usbd_task (void* param);
bool usbd_init (void);
void usbd_task (void* param);


// Carry out Data and Status stage of control transfer
Expand Down
3 changes: 0 additions & 3 deletions src/host/usbh.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,11 @@ ATTR_WEAK void tuh_device_mount_failed_cb(tusb_error_t error, tusb_desc_devic
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_


void usbh_enumeration_task(void* param);
tusb_error_t usbh_init(void);

tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest,
uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data);


#endif

#ifdef __cplusplus
Expand Down
8 changes: 4 additions & 4 deletions src/tusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@

static bool _initialized = false;

tusb_error_t tusb_init(void)
bool tusb_init(void)
{
// skip if already initialized
if (_initialized) return TUSB_ERROR_NONE;
if (_initialized) return true;

#if MODE_HOST_SUPPORTED
TU_ASSERT_ERR( usbh_init() ); // host stack init
TU_VERIFY( usbh_init() == TUSB_ERROR_NONE ); // init host stack
#endif

#if TUSB_OPT_DEVICE_ENABLED
TU_ASSERT_ERR ( usbd_init() ); // device stack init
TU_VERIFY ( usbd_init() ); // init device stack
#endif

_initialized = true;
Expand Down
10 changes: 4 additions & 6 deletions src/tusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,14 @@
/** \ingroup group_application_api
* @{ */

/** \brief Initialize the usb stack
* \return Error Code of the \ref TUSB_ERROR enum
* \note Function will initialize the stack according to configuration in the configure file (tusb_config.h)
*/
tusb_error_t tusb_init(void);
// Initialize device/host stack according to tusb_config.h
// return true if success
bool tusb_init(void);

#if CFG_TUSB_OS == OPT_OS_NONE
/** \brief Run all tinyusb's internal tasks (e.g host task, device task).
* \note This function is only required when using no RTOS (\ref CFG_TUSB_OS == OPT_OS_NONE). All the stack functions
* & callback are invoked within this function, so it should be called periodically within the mainloop
* & callback are invoked within this function. This should be called periodically within the mainloop
*
@code
int main(void)
Expand Down

0 comments on commit d887829

Please sign in to comment.