add tuh_mount_cb/tuh_umount_cb

This commit is contained in:
hathach
2018-12-10 19:25:57 +07:00
parent 9c4c797502
commit 4e7596ca9c
7 changed files with 26 additions and 39 deletions

View File

@@ -71,7 +71,7 @@ static host_class_driver_t const usbh_class_drivers[] =
{
.class_code = TUSB_CLASS_CDC,
.init = cdch_init,
.open_subtask = cdch_open_subtask,
.open_subtask = cdch_open,
.isr = cdch_isr,
.close = cdch_close
},
@@ -218,10 +218,6 @@ bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8
if ( XFER_RESULT_STALLED == dev->control.pipe_status ) return false;
if ( XFER_RESULT_FAILED == dev->control.pipe_status ) return false;
// STASK_ASSERT_HDLR(TUSB_ERROR_NONE == error &&
// XFER_RESULT_SUCCESS == dev->control.pipe_status,
// tuh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
return true;
}
@@ -336,6 +332,9 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_
(hub_port == 0 || dev->hub_port == hub_port) &&
dev->state != TUSB_DEVICE_STATE_UNPLUG)
{
// Invoke callback before close driver
if (tuh_umount_cb) tuh_umount_cb(dev_addr);
// TODO Hub multiple level
// Close class driver
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].close(dev_addr);
@@ -624,7 +623,7 @@ bool enum_task(hcd_event_t* event)
}
}
tuh_device_mount_succeed_cb(new_addr);
if (tuh_mount_cb) tuh_mount_cb(new_addr);
return true;
}

View File

@@ -90,8 +90,12 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr)
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WARN_UNUSED_RESULT;
ATTR_WEAK void tuh_device_mount_succeed_cb (uint8_t dev_addr);
ATTR_WEAK void tuh_device_mount_failed_cb(tusb_error_t error, tusb_desc_device_t const *p_desc_device); // TODO refractor remove desc_device
/** Callback invoked when device is mounted (configured) */
ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr);
/** Callback invoked when device is unmounted (bus reset/unplugged) */
ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
//--------------------------------------------------------------------+
// CLASS-USBH & INTERNAL API