adding deinit() stub for usbh/hcd class driver

add TUSB_VERSION_BUILD, also add TUSB_VERSION_NUMBER
This commit is contained in:
hathach 2024-03-22 11:42:33 +07:00
parent 08b09926a4
commit 74bd264758
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
13 changed files with 76 additions and 19 deletions

View File

@ -637,6 +637,10 @@ void cdch_init(void) {
}
}
bool cdch_deinit(void) {
return true;
}
void cdch_close(uint8_t daddr) {
for (uint8_t idx = 0; idx < CFG_TUH_CDC; idx++) {
cdch_interface_t* p_cdc = &cdch_data[idx];

View File

@ -193,6 +193,7 @@ TU_ATTR_WEAK extern void tuh_cdc_tx_complete_cb(uint8_t idx);
// Internal Class Driver API
//--------------------------------------------------------------------+
void cdch_init (void);
bool cdch_deinit (void);
bool cdch_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
bool cdch_set_config (uint8_t dev_addr, uint8_t itf_num);
bool cdch_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);

View File

@ -376,6 +376,10 @@ void hidh_init(void) {
tu_memclr(_hidh_itf, sizeof(_hidh_itf));
}
bool hidh_deinit(void) {
return true;
}
bool hidh_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
(void) result;

View File

@ -164,6 +164,7 @@ TU_ATTR_WEAK void tuh_hid_set_protocol_complete_cb(uint8_t dev_addr, uint8_t idx
// Internal Class Driver API
//--------------------------------------------------------------------+
void hidh_init(void);
bool hidh_deinit(void);
bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const* desc_itf, uint16_t max_len);
bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num);
bool hidh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);

View File

@ -288,6 +288,11 @@ void msch_init(void) {
tu_memclr(_msch_itf, sizeof(_msch_itf));
}
bool msch_deinit(void) {
return true;
}
void msch_close(uint8_t dev_addr) {
TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX,);
msch_interface_t* p_msc = get_itf(dev_addr);

View File

@ -114,6 +114,7 @@ TU_ATTR_WEAK void tuh_msc_umount_cb(uint8_t dev_addr);
//--------------------------------------------------------------------+
void msch_init (void);
bool msch_deinit (void);
bool msch_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
bool msch_set_config (uint8_t dev_addr, uint8_t itf_num);
void msch_close (uint8_t dev_addr);

View File

@ -130,6 +130,9 @@ bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) TU_AT
// Initialize controller to host mode
bool hcd_init(uint8_t rhport);
// De-initialize controller
bool hcd_deinit(uint8_t rhport);
// Interrupt Handler
void hcd_int_handler(uint8_t rhport, bool in_isr);

View File

@ -182,11 +182,14 @@ bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp,
//--------------------------------------------------------------------+
// CLASS-USBH API (don't require to verify parameters)
//--------------------------------------------------------------------+
void hub_init(void)
{
void hub_init(void) {
tu_memclr(hub_data, sizeof(hub_data));
}
bool hub_deinit(void) {
return true;
}
bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
{
(void) rhport;

View File

@ -205,6 +205,7 @@ static inline bool hub_port_clear_reset_change(uint8_t hub_addr, uint8_t hub_por
// Internal Class Driver API
//--------------------------------------------------------------------+
void hub_init (void);
bool hub_deinit (void);
bool hub_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
bool hub_set_config (uint8_t dev_addr, uint8_t itf_num);
bool hub_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);

View File

@ -45,8 +45,13 @@
#endif
//--------------------------------------------------------------------+
// Callback weak stubs (called if application does not provide)
// Weak stubs: invoked if no strong implementation is available
//--------------------------------------------------------------------+
TU_ATTR_WEAK bool hcd_deinit(uint8_t rhport) {
(void) rhport;
return false;
}
TU_ATTR_WEAK void tuh_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
(void) rhport;
(void) eventid;
@ -119,16 +124,17 @@ typedef struct {
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
#if CFG_TUSB_DEBUG >= CFG_TUH_LOG_LEVEL
#define DRIVER_NAME(_name) .name = _name,
#define DRIVER_NAME(_name) _name
#else
#define DRIVER_NAME(_name)
#define DRIVER_NAME(_name) NULL
#endif
static usbh_class_driver_t const usbh_class_drivers[] = {
#if CFG_TUH_CDC
{
DRIVER_NAME("CDC")
.name = DRIVER_NAME("CDC"),
.init = cdch_init,
.deinit = cdch_deinit,
.open = cdch_open,
.set_config = cdch_set_config,
.xfer_cb = cdch_xfer_cb,
@ -138,8 +144,9 @@ static usbh_class_driver_t const usbh_class_drivers[] = {
#if CFG_TUH_MSC
{
DRIVER_NAME("MSC")
.name = DRIVER_NAME("MSC"),
.init = msch_init,
.deinit = msch_deinit,
.open = msch_open,
.set_config = msch_set_config,
.xfer_cb = msch_xfer_cb,
@ -149,8 +156,9 @@ static usbh_class_driver_t const usbh_class_drivers[] = {
#if CFG_TUH_HID
{
DRIVER_NAME("HID")
.name = DRIVER_NAME("HID"),
.init = hidh_init,
.deinit = hidh_deinit,
.open = hidh_open,
.set_config = hidh_set_config,
.xfer_cb = hidh_xfer_cb,
@ -160,8 +168,9 @@ static usbh_class_driver_t const usbh_class_drivers[] = {
#if CFG_TUH_HUB
{
DRIVER_NAME("HUB")
.name = DRIVER_NAME("HUB"),
.init = hub_init,
.deinit = hub_deinit,
.open = hub_open,
.set_config = hub_set_config,
.xfer_cb = hub_xfer_cb,
@ -171,9 +180,11 @@ static usbh_class_driver_t const usbh_class_drivers[] = {
#if CFG_TUH_VENDOR
{
DRIVER_NAME("VENDOR")
.name = DRIVER_NAME("VENDOR"),
.init = cush_init,
.open = cush_open_subtask,
.deinit = cush_deinit,
.open = cush_open,
.set_config = cush_set_config,
.xfer_cb = cush_isr,
.close = cush_close
}
@ -338,11 +349,11 @@ bool tuh_inited(void) {
return _usbh_controller != TUSB_INDEX_INVALID_8;
}
bool tuh_init(uint8_t controller_id) {
bool tuh_init(uint8_t rhport) {
// skip if already initialized
if ( tuh_inited() ) return true;
TU_LOG_USBH("USBH init on controller %u\r\n", controller_id);
TU_LOG_USBH("USBH init on controller %u\r\n", rhport);
TU_LOG_INT_USBH(sizeof(usbh_device_t));
TU_LOG_INT_USBH(sizeof(hcd_event_t));
TU_LOG_INT_USBH(sizeof(_ctrl_xfer));
@ -383,10 +394,26 @@ bool tuh_init(uint8_t controller_id) {
}
}
_usbh_controller = controller_id;;
_usbh_controller = rhport;;
TU_ASSERT(hcd_init(controller_id));
hcd_int_enable(controller_id);
TU_ASSERT(hcd_init(rhport));
hcd_int_enable(rhport);
return true;
}
bool tuh_deinit(uint8_t rhport) {
if (!tuh_rhport_is_active(rhport)) return true;
hcd_int_disable(rhport);
hcd_deinit(rhport);
_usbh_controller = TUSB_INDEX_INVALID_8;
// no other controller is active, deinit the stack
if (!tuh_inited()) {
}
return true;
}

View File

@ -109,7 +109,11 @@ bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param);
// Init host stack
bool tuh_init(uint8_t rhport);
// Deinit host stack on rhport
bool tuh_deinit(uint8_t rhport);
// Check if host stack is already initialized with any roothub ports
// To check if an rhport is initialized, use tuh_rhport_is_active()
bool tuh_inited(void);
// Task function should be called in main/rtos loop, extended version of tuh_task()

View File

@ -50,11 +50,9 @@ enum {
//--------------------------------------------------------------------+
typedef struct {
#if CFG_TUSB_DEBUG >= CFG_TUH_LOG_LEVEL
char const* name;
#endif
void (* const init )(void);
bool (* const deinit )(void);
bool (* const open )(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
bool (* const set_config )(uint8_t dev_addr, uint8_t itf_num);
bool (* const xfer_cb )(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);

View File

@ -29,9 +29,14 @@
#include "common/tusb_compiler.h"
// Version is release as major.minor.revision eg 1.0.0. though there could be notable APIs before a new release.
// For notable API changes within a release, we increase the build number.
#define TUSB_VERSION_MAJOR 0
#define TUSB_VERSION_MINOR 16
#define TUSB_VERSION_REVISION 0
#define TUSB_VERSION_BUILD 1
#define TUSB_VERSION_NUMBER (TUSB_VERSION_MAJOR << 24 | TUSB_VERSION_MINOR << 16 | TUSB_VERSION_REVISION << 8 | TUSB_VERSION_BUILD)
#define TUSB_VERSION_STRING TU_STRING(TUSB_VERSION_MAJOR) "." TU_STRING(TUSB_VERSION_MINOR) "." TU_STRING(TUSB_VERSION_REVISION)
//--------------------------------------------------------------------+