add host class run and stop callback

This commit is contained in:
sakimisu
2022-11-26 23:52:58 +08:00
parent 69e240355d
commit 512de54d33
11 changed files with 161 additions and 26 deletions

View File

@@ -7,15 +7,29 @@
#define DEV_FORMAT "/dev/air724"
static uint32_t g_devinuse = 0;
struct usbh_cdc_custom_air724 {
struct usbh_hubport *hport;
usbh_pipe_t bulkin; /* Bulk IN endpoint */
usbh_pipe_t bulkout; /* Bulk OUT endpoint */
usbh_pipe_t bulkin; /* Bulk IN endpoint */
usbh_pipe_t bulkout; /* Bulk OUT endpoint */
struct usbh_urb bulkin_urb; /* Bulk IN urb */
struct usbh_urb bulkout_urb; /* Bulk OUT urb */
};
static inline int usbh_air724_bulk_out_transfer(struct usbh_cdc_custom_air724 *cdc_custom_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
{
int ret;
struct usbh_urb *urb = &cdc_custom_class->bulkout_urb;
memset(urb, 0, sizeof(struct usbh_urb));
usbh_bulk_urb_fill(urb, cdc_custom_class->bulkout, buffer, buflen, timeout, NULL, NULL);
ret = usbh_submit_urb(urb);
if (ret == 0) {
ret = urb->actual_length;
}
return ret;
}
int usbh_air724_connect(struct usbh_hubport *hport, uint8_t intf)
{
struct usbh_endpoint_cfg ep_cfg = { 0 };
@@ -50,22 +64,23 @@ int usbh_air724_connect(struct usbh_hubport *hport, uint8_t intf)
}
USB_LOG_INFO("Register air724 Class:%s\r\n", hport->config.intf[intf].devname);
// uint8_t cdc_buffer[32] = {0X41,0X54,0x0d,0x0a};
// ret = usbh_ep_bulk_transfer(cdc_custom_class->bulkout, cdc_buffer, 4, 3000);
// if (ret < 0) {
// USB_LOG_ERR("bulk out error,ret:%d\r\n", ret);
// } else {
// USB_LOG_RAW("send over:%d\r\n", ret);
// }
// ret = usbh_ep_bulk_transfer(cdc_custom_class->bulkin, cdc_buffer, 10, 3000);
// if (ret < 0) {
// USB_LOG_ERR("bulk in error,ret:%d\r\n", ret);
// } else {
// USB_LOG_RAW("recv over:%d\r\n", ret);
// for (size_t i = 0; i < ret; i++) {
// USB_LOG_RAW("0x%02x ", cdc_buffer[i]);
// }
// }
uint8_t cdc_buffer[32] = { 0x41, 0x54, 0x0d, 0x0a };
ret = usbh_air724_bulk_out_transfer(cdc_custom_class->bulkout, cdc_buffer, 4, 3000);
if (ret < 0) {
USB_LOG_ERR("bulk out error,ret:%d\r\n", ret);
} else {
USB_LOG_RAW("send over:%d\r\n", ret);
}
ret = usbh_air724_bulk_out_transfer(cdc_custom_class->bulkin, cdc_buffer, 10, 3000);
if (ret < 0) {
USB_LOG_ERR("bulk in error,ret:%d\r\n", ret);
} else {
USB_LOG_RAW("recv over:%d\r\n", ret);
for (size_t i = 0; i < ret; i++) {
USB_LOG_RAW("0x%02x ", cdc_buffer[i]);
}
}
return ret;
}