mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
add tud_mount_cb, tud_umount_cb
remove device class/interface callback
This commit is contained in:
parent
0afa0ce4cc
commit
2580b4c6a7
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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; i<HIDD_NUMBER_OF_SUBCLASS; i++)
|
||||
{
|
||||
interface_clear(hidd_class_driver[i].p_interface);
|
||||
if ( hidd_class_driver[i].unmounted_cb ) hidd_class_driver[i].unmounted_cb(coreid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +288,6 @@ tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
|
||||
p_hid->report_length = p_desc_hid->wReportLength;
|
||||
|
||||
ASSERT_PTR(p_hid->p_report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
p_driver->mounted_cb(coreid);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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) );
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user