Просмотр исходного кода

implement & document all the device class _mounted_cb & _unmounted_cb callbacks

hathach 12 лет назад
Родитель
Сommit
6682720b2a

+ 19 - 11
demos/device/src/cdc_device_app.c

@@ -58,30 +58,27 @@ OSAL_SEM_DEF(cdcd_semaphore);
 
 
 static osal_semaphore_handle_t sem_hdl;
 static osal_semaphore_handle_t sem_hdl;
 
 
-TUSB_CFG_ATTR_USBRAM static uint8_t serial_rx_buffer[CDCD_APP_BUFFER_SIZE];
-TUSB_CFG_ATTR_USBRAM static uint8_t serial_tx_buffer[CDCD_APP_BUFFER_SIZE];
-
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // INTERNAL OBJECT & FUNCTION DECLARATION
 // INTERNAL OBJECT & FUNCTION DECLARATION
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
+TUSB_CFG_ATTR_USBRAM static uint8_t serial_rx_buffer[CDCD_APP_BUFFER_SIZE];
+TUSB_CFG_ATTR_USBRAM static uint8_t serial_tx_buffer[CDCD_APP_BUFFER_SIZE];
+
 FIFO_DEF(fifo_serial, CDCD_APP_BUFFER_SIZE, uint8_t, true);
 FIFO_DEF(fifo_serial, CDCD_APP_BUFFER_SIZE, uint8_t, true);
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
-// IMPLEMENTATION
+// tinyusb Callbacks
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
-void cdcd_serial_app_init(void)
+void tusbd_cdc_mounted_cb(uint8_t coreid)
 {
 {
-  sem_hdl = osal_semaphore_create( OSAL_SEM_REF(cdcd_semaphore) );
-  ASSERT_PTR( sem_hdl, VOID_RETURN);
+  osal_semaphore_reset(sem_hdl);
 
 
-  ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(cdcd_serial_app_task) ), VOID_RETURN);
+  tusbd_cdc_receive(coreid, serial_rx_buffer, CDCD_APP_BUFFER_SIZE, true);
 }
 }
 
 
-void tusbd_cdc_mounted_cb(uint8_t coreid)
+void tusbd_cdc_unmounted_cb(uint8_t coreid)
 {
 {
-  osal_semaphore_reset(sem_hdl);
 
 
-  tusbd_cdc_receive(coreid, serial_rx_buffer, CDCD_APP_BUFFER_SIZE, true);
 }
 }
 
 
 void tusbd_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
 void tusbd_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
@@ -116,6 +113,17 @@ void tusbd_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id,
   }
   }
 }
 }
 
 
+//--------------------------------------------------------------------+
+// APPLICATION CODE
+//--------------------------------------------------------------------+
+void cdcd_serial_app_init(void)
+{
+  sem_hdl = osal_semaphore_create( OSAL_SEM_REF(cdcd_semaphore) );
+  ASSERT_PTR( sem_hdl, VOID_RETURN);
+
+  ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(cdcd_serial_app_task) ), VOID_RETURN);
+}
+
 OSAL_TASK_FUNCTION( cdcd_serial_app_task , p_task_para)
 OSAL_TASK_FUNCTION( cdcd_serial_app_task , p_task_para)
 {
 {
   OSAL_TASK_LOOP_BEGIN
   OSAL_TASK_LOOP_BEGIN

+ 4 - 2
demos/device/src/mouse_device_app.c

@@ -1,4 +1,4 @@
-/**************************************************************************/
+  /**************************************************************************/
 /*!
 /*!
     @file     mouse_device_app.c
     @file     mouse_device_app.c
     @author   hathach (tinyusb.org)
     @author   hathach (tinyusb.org)
@@ -42,6 +42,7 @@
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // INCLUDE
 // INCLUDE
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
+#include "app_os_prio.h"
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // MACRO CONSTANT TYPEDEF
 // MACRO CONSTANT TYPEDEF
@@ -50,7 +51,7 @@
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // INTERNAL OBJECT & FUNCTION DECLARATION
 // INTERNAL OBJECT & FUNCTION DECLARATION
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
-OSAL_TASK_DEF(mouse_device_app_task, 128, MOUSED_APP_TASK_PRIO);
+OSAL_TASK_DEF(mouse_device_app_task, 128, MOUSE_APP_TASK_PRIO);
 
 
 TUSB_CFG_ATTR_USBRAM hid_mouse_report_t mouse_report;
 TUSB_CFG_ATTR_USBRAM hid_mouse_report_t mouse_report;
 
 
@@ -90,6 +91,7 @@ void tusbd_hid_mouse_set_report_cb(uint8_t coreid, hid_request_report_type_t rep
 {
 {
   // mouse demo does not support set report --> do nothing
   // mouse demo does not support set report --> do nothing
 }
 }
+
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // APPLICATION CODE
 // APPLICATION CODE
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+

+ 10 - 0
demos/device/src/msc_device_app.c

@@ -93,6 +93,16 @@ static scsi_mode_parameters_t const msc_dev_mode_para =
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // tinyusb callback (ISR context)
 // tinyusb callback (ISR context)
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
+void tusbd_msc_mounted_cb(uint8_t coreid)
+{
+
+}
+
+void tusbd_msc_unmounted_cb(uint8_t coreid)
+{
+
+}
+
 msc_csw_status_t tusbd_msc_scsi_cb (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void const ** pp_buffer, uint16_t* p_length)
 msc_csw_status_t tusbd_msc_scsi_cb (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void const ** pp_buffer, uint16_t* p_length)
 {
 {
   // read10 & write10 has their own callback and MUST not be handled here
   // read10 & write10 has their own callback and MUST not be handled here

+ 2 - 2
demos/device/src/tusb_config.h

@@ -59,10 +59,10 @@
 
 
 //------------- CLASS -------------//
 //------------- CLASS -------------//
 #define TUSB_CFG_DEVICE_HID_KEYBOARD            1
 #define TUSB_CFG_DEVICE_HID_KEYBOARD            1
-#define TUSB_CFG_DEVICE_HID_MOUSE               0
+#define TUSB_CFG_DEVICE_HID_MOUSE               1
 #define TUSB_CFG_DEVICE_HID_GENERIC             0 // not supported yet
 #define TUSB_CFG_DEVICE_HID_GENERIC             0 // not supported yet
 #define TUSB_CFG_DEVICE_MSC                     1
 #define TUSB_CFG_DEVICE_MSC                     1
-#define TUSB_CFG_DEVICE_CDC                     0
+#define TUSB_CFG_DEVICE_CDC                     1
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // COMMON CONFIGURATION
 // COMMON CONFIGURATION

+ 2 - 0
tinyusb/class/cdc_device.c

@@ -180,6 +180,8 @@ void cdcd_close(uint8_t coreid)
 {
 {
   // no need to close opened pipe, dcd bus reset will put controller's endpoints to default state
   // 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));
   memclr_(&cdcd_data[coreid], sizeof(cdcd_data_t));
+
+  tusbd_cdc_unmounted_cb(coreid);
 }
 }
 
 
 tusb_error_t cdcd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request)
 tusb_error_t cdcd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request)

+ 9 - 0
tinyusb/class/cdc_device.h

@@ -98,7 +98,16 @@ tusb_error_t tusbd_cdc_receive(uint8_t coreid, void * p_buffer, uint32_t length,
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // APPLICATION CALLBACK API
 // 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 tusbd_cdc_mounted_cb(uint8_t coreid);
 void tusbd_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 tusbd_cdc_unmounted_cb(uint8_t coreid);
 void tusbd_cdc_unmounted_cb(uint8_t coreid);
 
 
 /** \brief      Callback function that is invoked when an completion (error or success) of an USB transfer previously submitted
 /** \brief      Callback function that is invoked when an completion (error or success) of an USB transfer previously submitted

+ 19 - 1
tinyusb/class/hid_device.h

@@ -80,7 +80,17 @@ tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // APPLICATION CALLBACK API
 // 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 tusbd_hid_keyboard_mounted_cb(uint8_t coreid);
 void tusbd_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 tusbd_hid_keyboard_unmounted_cb(uint8_t coreid);
 void tusbd_hid_keyboard_unmounted_cb(uint8_t coreid);
 
 
 /** \brief      Callback function that is invoked when an transferring event occurred
 /** \brief      Callback function that is invoked when an transferring event occurred
@@ -155,8 +165,16 @@ tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_re
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // APPLICATION CALLBACK API
 // 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 tusbd_hid_mouse_mounted_cb(uint8_t coreid);
 void tusbd_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 tusbd_hid_mouse_unmounted_cb(uint8_t coreid);
 void tusbd_hid_mouse_unmounted_cb(uint8_t coreid);
 
 
 /** \brief      Callback function that is invoked when an transferring event occurred
 /** \brief      Callback function that is invoked when an transferring event occurred

+ 3 - 0
tinyusb/class/msc_device.c

@@ -82,6 +82,7 @@ void mscd_init(void)
 void mscd_close(uint8_t coreid)
 void mscd_close(uint8_t coreid)
 {
 {
   memclr_(&mscd_data, sizeof(mscd_interface_t));
   memclr_(&mscd_data, sizeof(mscd_interface_t));
+  tusbd_msc_unmounted_cb(coreid);
 }
 }
 
 
 tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
 tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
@@ -111,6 +112,8 @@ 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);
   (*p_length) += sizeof(tusb_descriptor_interface_t) + 2*sizeof(tusb_descriptor_endpoint_t);
 
 
+  tusbd_msc_mounted_cb(coreid);
+
   //------------- Queue Endpoint OUT for Command Block Wrapper -------------//
   //------------- 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) );
   ASSERT_STATUS( dcd_pipe_xfer(p_msc->edpt_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) );
 
 

+ 10 - 2
tinyusb/class/msc_device.h

@@ -50,7 +50,7 @@
 /** \addtogroup ClassDriver_MSC
 /** \addtogroup ClassDriver_MSC
  *  @{
  *  @{
  * \defgroup MSC_Device Device
  * \defgroup MSC_Device Device
-  *  @{ */
+ *  @{ */
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // APPLICATION API
 // APPLICATION API
@@ -59,9 +59,17 @@
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // APPLICATION CALLBACK API
 // 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 tusbd_msc_mounted_cb(uint8_t coreid);
 void tusbd_msc_mounted_cb(uint8_t coreid);
-void tusbd_msc_unmounted_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 tusbd_msc_unmounted_cb(uint8_t coreid);
 
 
 /** \brief 			Callback that is invoked when tinyusb stack received \ref SCSI_CMD_READ_10 command from host
 /** \brief 			Callback that is invoked when tinyusb stack received \ref SCSI_CMD_READ_10 command from host
  * \param[in]		coreid	    USB Controller ID
  * \param[in]		coreid	    USB Controller ID