adding tuh_cdc_mount_cb/tuh_cdc_umount_cb

start adding cdc_app.c to example
This commit is contained in:
hathach
2022-12-14 16:52:28 +07:00
parent 159aa599be
commit 4f03695084
6 changed files with 81 additions and 16 deletions

View File

@@ -239,6 +239,8 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
bool cdch_set_config(uint8_t dev_addr, uint8_t itf_num)
{
(void) dev_addr; (void) itf_num;
if (tuh_cdc_mount_cb) tuh_cdc_mount_cb(dev_addr);
return true;
}
@@ -254,6 +256,16 @@ void cdch_close(uint8_t dev_addr)
TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
cdch_data_t * p_cdc = get_itf(dev_addr);
// Invoke application callback
if (tuh_cdc_umount_cb)
{
if (p_cdc->ep_out || p_cdc->ep_in || p_cdc->ep_notif)
{
tuh_cdc_umount_cb(dev_addr);
}
}
tu_memclr(p_cdc, sizeof(cdch_data_t));
}

View File

@@ -34,13 +34,18 @@
#endif
//--------------------------------------------------------------------+
// CDC APPLICATION PUBLIC API
// Application API
//--------------------------------------------------------------------+
/** \ingroup ClassDriver_CDC Communication Device Class (CDC)
* \addtogroup CDC_Serial Serial
* @{
* \defgroup CDC_Serial_Host Host
* @{ */
//------------- Application Callback -------------//
// Invoked when a device with CDC interface is mounted
TU_ATTR_WEAK void tuh_cdc_mount_cb(uint8_t dev_addr);
// Invoked when a device with CDC interface is unmounted
TU_ATTR_WEAK void tuh_cdc_umount_cb(uint8_t dev_addr);
bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_xfer_cb_t complete_cb);