From 2580b4c6a7e45c762e09020719af805f1be46117 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 2 Mar 2018 00:18:21 +0700 Subject: [PATCH] add tud_mount_cb, tud_umount_cb remove device class/interface callback --- demos/device/src/cdc_device_app.c | 16 ++++++------- demos/device/src/cdc_device_app.h | 13 ++++++---- demos/device/src/keyboard_device_app.c | 10 ++++---- demos/device/src/keyboard_device_app.h | 13 ++++++---- demos/device/src/main.c | 33 +++++++++++++++++++------- demos/device/src/mouse_device_app.c | 16 ++++++------- demos/device/src/mouse_device_app.h | 12 ++++++---- demos/device/src/msc_device_app.c | 8 +++---- demos/device/src/msc_device_app.h | 13 ++++++---- tinyusb/class/cdc_device.c | 4 ---- tinyusb/class/cdc_device.h | 12 ---------- tinyusb/class/hid_device.c | 8 ------- tinyusb/class/hid_device.h | 23 ------------------ tinyusb/class/msc_device.c | 3 --- tinyusb/class/msc_device.h | 11 --------- tinyusb/device/usbd.h | 9 +++++++ 16 files changed, 94 insertions(+), 110 deletions(-) diff --git a/demos/device/src/cdc_device_app.c b/demos/device/src/cdc_device_app.c index d8491d87b..b5420733d 100644 --- a/demos/device/src/cdc_device_app.c +++ b/demos/device/src/cdc_device_app.c @@ -64,14 +64,14 @@ FIFO_DEF(fifo_serial, SERIAL_BUFFER_SIZE, uint8_t, true); //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_cdc_mounted_cb(uint8_t coreid) +void cdc_serial_app_mount(uint8_t coreid) { osal_semaphore_reset(sem_hdl); tud_cdc_receive(coreid, serial_rx_buffer, SERIAL_BUFFER_SIZE, true); } -void tud_cdc_unmounted_cb(uint8_t coreid) +void cdc_serial_app_umount(uint8_t coreid) { } @@ -111,26 +111,26 @@ void tud_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, u //--------------------------------------------------------------------+ // APPLICATION CODE //--------------------------------------------------------------------+ -void cdcd_serial_app_init(void) +void cdc_serial_app_init(void) { sem_hdl = osal_semaphore_create(1, 0); ASSERT_PTR( sem_hdl, VOID_RETURN); - osal_task_create(cdcd_serial_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO); + osal_task_create(cdc_serial_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO); } -tusb_error_t cdcd_serial_subtask(void); +tusb_error_t cdc_serial_subtask(void); -void cdcd_serial_app_task(void* param) +void cdc_serial_app_task(void* param) { (void) param; OSAL_TASK_BEGIN - cdcd_serial_subtask(); + cdc_serial_subtask(); OSAL_TASK_END } -tusb_error_t cdcd_serial_subtask(void) +tusb_error_t cdc_serial_subtask(void) { OSAL_SUBTASK_BEGIN diff --git a/demos/device/src/cdc_device_app.h b/demos/device/src/cdc_device_app.h index 19941bbac..cf796c943 100644 --- a/demos/device/src/cdc_device_app.h +++ b/demos/device/src/cdc_device_app.h @@ -55,13 +55,18 @@ #if TUSB_CFG_DEVICE_CDC -void cdcd_serial_app_init(void); -void cdcd_serial_app_task(void* param); +void cdc_serial_app_init(void); +void cdc_serial_app_task(void* param); + +void cdc_serial_app_mount(uint8_t coreid); +void cdc_serial_app_umount(uint8_t coreid); #else -#define cdcd_serial_app_init() -#define cdcd_serial_app_task(x) +#define cdc_serial_app_init() +#define cdc_serial_app_task(x) +#define cdc_serial_app_mount(x) +#define cdc_serial_app_umount(x) #endif diff --git a/demos/device/src/keyboard_device_app.c b/demos/device/src/keyboard_device_app.c index 61e42f99d..946680345 100644 --- a/demos/device/src/keyboard_device_app.c +++ b/demos/device/src/keyboard_device_app.c @@ -56,12 +56,12 @@ TUSB_CFG_ATTR_USBRAM hid_keyboard_report_t keyboard_report; //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_hid_keyboard_mounted_cb(uint8_t coreid) +void keyboard_app_mount(uint8_t coreid) { } -void tud_hid_keyboard_unmounted_cb(uint8_t coreid) +void keyboard_app_umount(uint8_t coreid) { } @@ -104,14 +104,14 @@ void tud_hid_keyboard_set_report_cb(uint8_t coreid, hid_request_report_type_t re //--------------------------------------------------------------------+ // APPLICATION CODE //--------------------------------------------------------------------+ -void keyboard_device_app_init(void) +void keyboard_app_init(void) { - osal_task_create(keyboard_device_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO); + osal_task_create(keyboard_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO); } tusb_error_t keyboard_device_subtask(void); -void keyboard_device_app_task(void* param) +void keyboard_app_task(void* param) { (void) param; diff --git a/demos/device/src/keyboard_device_app.h b/demos/device/src/keyboard_device_app.h index 3eeb6b48b..bba6463af 100644 --- a/demos/device/src/keyboard_device_app.h +++ b/demos/device/src/keyboard_device_app.h @@ -55,13 +55,18 @@ #if TUSB_CFG_DEVICE_HID_KEYBOARD -void keyboard_device_app_init(void); -void keyboard_device_app_task(void* param); +void keyboard_app_init(void); +void keyboard_app_task(void* param); + +void keyboard_app_mount(uint8_t coreid); +void keyboard_app_umount(uint8_t coreid); #else -#define keyboard_device_app_init() -#define keyboard_device_app_task(x) +#define keyboard_app_init() +#define keyboard_app_task(x) +#define keyboard_app_mount(x) +#define keyboard_app_umount(x) #endif diff --git a/demos/device/src/main.c b/demos/device/src/main.c index bb26d0368..8e2020812 100644 --- a/demos/device/src/main.c +++ b/demos/device/src/main.c @@ -69,10 +69,10 @@ void os_none_start_scheduler(void) tusb_task_runner(); led_blinking_task(NULL); - msc_device_app_task(NULL); - keyboard_device_app_task(NULL); - mouse_device_app_task(NULL); - cdcd_serial_app_task(NULL); + msc_app_task(NULL); + keyboard_app_task(NULL); + mouse_app_task(NULL); + cdc_serial_app_task(NULL); } } #endif @@ -87,10 +87,10 @@ int main(void) //------------- application task init -------------// led_blinking_init(); - msc_device_app_init(); - keyboard_device_app_init(); - mouse_device_app_init(); - cdcd_serial_app_init(); + msc_app_init(); + keyboard_app_init(); + mouse_app_init(); + cdc_serial_app_init(); //------------- start OS scheduler (never return) -------------// #if TUSB_CFG_OS == TUSB_OS_FREERTOS @@ -104,6 +104,23 @@ int main(void) return 0; } +//--------------------------------------------------------------------+ +// tinyusb callbacks +//--------------------------------------------------------------------+ +void tud_mount_cb(uint8_t coreid) +{ + cdc_serial_app_mount(coreid); + keyboard_app_mount(coreid); + msc_app_mount(coreid); +} + +void tud_umount_cb(uint8_t coreid) +{ + cdc_serial_app_umount(coreid); + keyboard_app_umount(coreid); + msc_app_umount(coreid); +} + //--------------------------------------------------------------------+ // HELPER FUNCTION //--------------------------------------------------------------------+ diff --git a/demos/device/src/mouse_device_app.c b/demos/device/src/mouse_device_app.c index 56a4f51f4..91173bf3a 100644 --- a/demos/device/src/mouse_device_app.c +++ b/demos/device/src/mouse_device_app.c @@ -56,12 +56,12 @@ TUSB_CFG_ATTR_USBRAM hid_mouse_report_t mouse_report; //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tusbd_hid_mouse_mounted_cb(uint8_t coreid) +void mouse_app_mount(uint8_t coreid) { } -void tusbd_hid_mouse_unmounted_cb(uint8_t coreid) +void mouse_app_umount(uint8_t coreid) { } @@ -93,22 +93,22 @@ void tusbd_hid_mouse_set_report_cb(uint8_t coreid, hid_request_report_type_t rep //--------------------------------------------------------------------+ // APPLICATION CODE //--------------------------------------------------------------------+ -void mouse_device_app_init(void) +void mouse_app_init(void) { - osal_task_create(mouse_device_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO); + osal_task_create(mouse_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO); } -void mouse_device_subtask(void); +void mouse_app_subtask(void); -void mouse_device_app_task(void * param) +void mouse_app_task(void * param) { (void) para; OSAL_TASK_BEGIN - mouse_device_subtask(); + mouse_app_subtask(); OSAL_TASK_END } -void mouse_device_subtask(void) +void mouse_app_subtask(void) { OSAL_SUBTASK_BEGIN diff --git a/demos/device/src/mouse_device_app.h b/demos/device/src/mouse_device_app.h index 7c90b68a4..4b0964bc9 100644 --- a/demos/device/src/mouse_device_app.h +++ b/demos/device/src/mouse_device_app.h @@ -55,13 +55,17 @@ #if TUSB_CFG_DEVICE_HID_MOUSE -void mouse_device_app_init(void); -void mouse_device_app_task(void * param); +void mouse_app_init(void); +void mouse_app_task(void * param); +void mouse_app_mount(uint8_t coreid); +void mouse_app_umount(uint8_t coreid); #else -#define mouse_device_app_init() -#define mouse_device_app_task(x) +#define mouse_app_init() +#define mouse_app_task(x) +#define mouse_app_mount(x) +#define mouse_app_umount(x) #endif diff --git a/demos/device/src/msc_device_app.c b/demos/device/src/msc_device_app.c index 0ae193e4b..cf4353a1c 100644 --- a/demos/device/src/msc_device_app.c +++ b/demos/device/src/msc_device_app.c @@ -89,12 +89,12 @@ static scsi_mode_parameters_t const msc_dev_mode_para = //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_msc_mounted_cb(uint8_t coreid) +void msc_app_mount(uint8_t coreid) { } -void tud_msc_unmounted_cb(uint8_t coreid) +void msc_app_umount(uint8_t coreid) { } @@ -156,7 +156,7 @@ msc_csw_status_t tud_msc_scsi_cb (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[ //--------------------------------------------------------------------+ // APPLICATION CODE //--------------------------------------------------------------------+ -void msc_device_app_task(void* param) +void msc_app_task(void* param) { // no need to implement the task yet (void) param; @@ -165,7 +165,7 @@ void msc_device_app_task(void* param) OSAL_TASK_END } -void msc_device_app_init (void) +void msc_app_init (void) { } diff --git a/demos/device/src/msc_device_app.h b/demos/device/src/msc_device_app.h index 3ab38241e..f8b3ff93b 100644 --- a/demos/device/src/msc_device_app.h +++ b/demos/device/src/msc_device_app.h @@ -69,15 +69,20 @@ issue at github.com/hathach/tinyusb" #define MSCD_APP_RAMDISK #endif -void msc_device_app_init(void); -void msc_device_app_task(void* param); +void msc_app_init(void); +void msc_app_task(void* param); + +void msc_app_mount(uint8_t coreid); +void msc_app_umount(uint8_t coreid); extern scsi_sense_fixed_data_t mscd_sense_data; #else -#define msc_device_app_init() -#define msc_device_app_task(x) +#define msc_app_init() +#define msc_app_task(x) +#define msc_app_mount(x) +#define msc_app_umount(x) #endif diff --git a/tinyusb/class/cdc_device.c b/tinyusb/class/cdc_device.c index 455c04339..4f34c455a 100644 --- a/tinyusb/class/cdc_device.c +++ b/tinyusb/class/cdc_device.c @@ -170,8 +170,6 @@ tusb_error_t cdcd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int p_cdc->interface_number = p_interface_desc->bInterfaceNumber; - tud_cdc_mounted_cb(coreid); - return TUSB_ERROR_NONE; } @@ -179,8 +177,6 @@ void cdcd_close(uint8_t coreid) { // no need to close opened pipe, dcd bus reset will put controller's endpoints to default state memclr_(&cdcd_data[coreid], sizeof(cdcd_data_t)); - - tud_cdc_unmounted_cb(coreid); } tusb_error_t cdcd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request) diff --git a/tinyusb/class/cdc_device.h b/tinyusb/class/cdc_device.h index 757614535..1f738aa7f 100644 --- a/tinyusb/class/cdc_device.h +++ b/tinyusb/class/cdc_device.h @@ -98,18 +98,6 @@ tusb_error_t tud_cdc_receive(uint8_t coreid, void * p_buffer, uint32_t length, b //--------------------------------------------------------------------+ // APPLICATION CALLBACK API //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked when this interface is mounted (configured) by USB host - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b set-up interface-related data - */ -void tud_cdc_mounted_cb(uint8_t coreid); - -/** \brief Callback function that will be invoked when this interface is unmounted (bus reset/unplugged) - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b tear-down interface-related data - */ -void tud_cdc_unmounted_cb(uint8_t coreid); - /** \brief Callback function that is invoked when an completion (error or success) of an USB transfer previously submitted * by application (e.g \ref tusbd_cdc_send or \ref tusbd_cdc_send) with \a is_notify set to true. * \param[in] coreid USB Controller ID diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c index d06f71925..f0fe7352f 100644 --- a/tinyusb/class/hid_device.c +++ b/tinyusb/class/hid_device.c @@ -65,8 +65,6 @@ typedef struct { typedef struct { hidd_interface_t * const p_interface; - void (* const mounted_cb) (uint8_t coreid); - void (* const unmounted_cb) (uint8_t coreid); void (* const xfer_cb) (uint8_t, tusb_event_t, uint32_t); uint16_t (* const get_report_cb) (uint8_t, hid_request_report_type_t, void**, uint16_t ); void (* const set_report_cb) (uint8_t, hid_request_report_type_t, uint8_t[], uint16_t); @@ -83,8 +81,6 @@ static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] = [HID_PROTOCOL_KEYBOARD] = { .p_interface = &keyboardd_data, - .mounted_cb = tud_hid_keyboard_mounted_cb, - .unmounted_cb = tud_hid_keyboard_unmounted_cb, .xfer_cb = tud_hid_keyboard_cb, .get_report_cb = tud_hid_keyboard_get_report_cb, .set_report_cb = tud_hid_keyboard_set_report_cb @@ -95,8 +91,6 @@ static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] = [HID_PROTOCOL_MOUSE] = { .p_interface = &moused_data, - .mounted_cb = tusbd_hid_mouse_mounted_cb, - .unmounted_cb = tusbd_hid_mouse_unmounted_cb, .xfer_cb = tusbd_hid_mouse_cb, .get_report_cb = tusbd_hid_mouse_get_report_cb, .set_report_cb = tusbd_hid_mouse_set_report_cb @@ -178,7 +172,6 @@ void hidd_close(uint8_t coreid) for(uint8_t i=0; ireport_length = p_desc_hid->wReportLength; ASSERT_PTR(p_hid->p_report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED); - p_driver->mounted_cb(coreid); } break; diff --git a/tinyusb/class/hid_device.h b/tinyusb/class/hid_device.h index c909422d5..5808dc214 100644 --- a/tinyusb/class/hid_device.h +++ b/tinyusb/class/hid_device.h @@ -81,18 +81,6 @@ tusb_error_t tud_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const * // APPLICATION CALLBACK API //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked when this interface is mounted (configured) by USB host - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b set-up interface-related data - */ -void tud_hid_keyboard_mounted_cb(uint8_t coreid); - -/** \brief Callback function that will be invoked when this interface is unmounted (bus reset/unplugged) - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b tear-down interface-related data - */ -void tud_hid_keyboard_unmounted_cb(uint8_t coreid); - /** \brief Callback function that is invoked when an transferring event occurred * after invoking \ref tusbd_hid_keyboard_send * \param[in] coreid USB Controller ID @@ -165,17 +153,6 @@ tusb_error_t tud_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_repo //--------------------------------------------------------------------+ // APPLICATION CALLBACK API //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked when this interface is mounted (configured) by USB host - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b set-up interface-related data - */ -void tud_hid_mouse_mounted_cb(uint8_t coreid); - -/** \brief Callback function that will be invoked when this interface is unmounted (bus reset/unplugged) - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b tear-down interface-related data - */ -void tud_hid_mouse_unmounted_cb(uint8_t coreid); /** \brief Callback function that is invoked when an transferring event occurred * after invoking \ref tusbd_hid_mouse_send diff --git a/tinyusb/class/msc_device.c b/tinyusb/class/msc_device.c index 34d6bdcd8..8bd01f834 100644 --- a/tinyusb/class/msc_device.c +++ b/tinyusb/class/msc_device.c @@ -82,7 +82,6 @@ void mscd_init(void) void mscd_close(uint8_t coreid) { memclr_(&mscd_data, sizeof(mscd_interface_t)); - tud_msc_unmounted_cb(coreid); } tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length) @@ -112,8 +111,6 @@ tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int (*p_length) += sizeof(tusb_descriptor_interface_t) + 2*sizeof(tusb_descriptor_endpoint_t); - tud_msc_mounted_cb(coreid); - //------------- Queue Endpoint OUT for Command Block Wrapper -------------// ASSERT_STATUS( dcd_pipe_xfer(p_msc->edpt_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) ); diff --git a/tinyusb/class/msc_device.h b/tinyusb/class/msc_device.h index 91f043c10..c8cc29db8 100644 --- a/tinyusb/class/msc_device.h +++ b/tinyusb/class/msc_device.h @@ -59,17 +59,6 @@ //--------------------------------------------------------------------+ // APPLICATION CALLBACK API //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked when this interface is mounted (configured) by USB host - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b set-up interface-related data - */ -void tud_msc_mounted_cb(uint8_t coreid); - -/** \brief Callback function that will be invoked when this interface is unmounted (bus reset/unplugged) - * \param[in] coreid USB Controller ID of the interface - * \note This callback should be used by Application to \b tear-down interface-related data - */ -void tud_msc_unmounted_cb(uint8_t coreid); /** \brief Callback that is invoked when tinyusb stack received \ref SCSI_CMD_READ_10 command from host * \param[in] coreid USB Controller ID diff --git a/tinyusb/device/usbd.h b/tinyusb/device/usbd.h index 59128db84..28923dfae 100644 --- a/tinyusb/device/usbd.h +++ b/tinyusb/device/usbd.h @@ -90,7 +90,16 @@ typedef struct { bool tud_mounted(uint8_t coreid); /*------------- Callback -------------*/ +/** \brief Callback function that will be invoked device is mounted (configured) by USB host + * \param[in] coreid USB Controller ID of the interface + * \note This callback should be used by Application to \b set-up application data + */ void tud_mount_cb(uint8_t coreid); + +/** \brief Callback function that will be invoked when device is unmounted (bus reset/unplugged) + * \param[in] coreid USB Controller ID of the interface + * \note This callback should be used by Application to \b tear-down application data + */ void tud_umount_cb(uint8_t coreid); //void tud_device_suspended_cb(uint8_t coreid);