summaryrefslogtreecommitdiff
path: root/class
diff options
context:
space:
mode:
authorsakimisu <[email protected]>2022-11-26 23:52:58 +0800
committersakimisu <[email protected]>2022-11-26 23:52:58 +0800
commit512de54d335807b98a6c80076dcff5dad015e7ae (patch)
tree21cd423a6f9ac07f4a4f4150f4118e39a3af136e /class
parent69e240355d411919912983093bc09d47e84f1909 (diff)
add host class run and stop callback
Diffstat (limited to 'class')
-rw-r--r--class/cdc/usbh_cdc_acm.c12
-rw-r--r--class/cdc/usbh_cdc_acm.h3
-rw-r--r--class/hid/usbh_hid.c14
-rw-r--r--class/hid/usbh_hid.h3
-rw-r--r--class/msc/usbh_msc.c12
-rw-r--r--class/msc/usbh_msc.h3
-rw-r--r--class/vendor/usbh_air724.c55
-rw-r--r--class/video/usbh_video.c14
-rw-r--r--class/video/usbh_video.h3
-rw-r--r--class/wireless/usbh_rndis.c50
-rw-r--r--class/wireless/usbh_rndis.h18
11 files changed, 161 insertions, 26 deletions
diff --git a/class/cdc/usbh_cdc_acm.c b/class/cdc/usbh_cdc_acm.c
index 77300a9c..54f1e2e5 100644
--- a/class/cdc/usbh_cdc_acm.c
+++ b/class/cdc/usbh_cdc_acm.c
@@ -146,6 +146,7 @@ static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register CDC ACM Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_cdc_acm_run(cdc_acm_class);
return ret;
}
@@ -166,6 +167,7 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
usbh_pipe_free(cdc_acm_class->bulkout);
}
+ usbh_cdc_acm_stop(cdc_acm_class);
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
usb_free(cdc_acm_class);
@@ -176,6 +178,16 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret;
}
+__WEAK void usbh_cdc_acm_run(struct usbh_cdc_acm *cdc_acm_class)
+{
+
+}
+
+__WEAK void usbh_cdc_acm_stop(struct usbh_cdc_acm *cdc_acm_class)
+{
+
+}
+
const struct usbh_class_driver cdc_acm_class_driver = {
.driver_name = "cdc_acm",
.connect = usbh_cdc_acm_connect,
diff --git a/class/cdc/usbh_cdc_acm.h b/class/cdc/usbh_cdc_acm.h
index eda1ea93..3ffa64d0 100644
--- a/class/cdc/usbh_cdc_acm.h
+++ b/class/cdc/usbh_cdc_acm.h
@@ -32,6 +32,9 @@ int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts);
+void usbh_cdc_acm_run(struct usbh_cdc_acm *cdc_acm_class);
+void usbh_cdc_acm_stop(struct usbh_cdc_acm *cdc_acm_class);
+
#ifdef __cplusplus
}
#endif
diff --git a/class/hid/usbh_hid.c b/class/hid/usbh_hid.c
index 1ad95f1f..d6a252ec 100644
--- a/class/hid/usbh_hid.c
+++ b/class/hid/usbh_hid.c
@@ -148,7 +148,8 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register HID Class:%s\r\n", hport->config.intf[intf].devname);
- return 0;
+ usbh_hid_run(hid_class);
+ return ret;
}
int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
@@ -168,6 +169,7 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
usbh_pipe_free(hid_class->intout);
}
+ usbh_hid_stop(hid_class);
memset(hid_class, 0, sizeof(struct usbh_hid));
usb_free(hid_class);
@@ -178,6 +180,16 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret;
}
+__WEAK void usbh_hid_run(struct usbh_hid *hid_class)
+{
+
+}
+
+__WEAK void usbh_hid_stop(struct usbh_hid *hid_class)
+{
+
+}
+
const struct usbh_class_driver hid_class_driver = {
.driver_name = "hid",
.connect = usbh_hid_connect,
diff --git a/class/hid/usbh_hid.h b/class/hid/usbh_hid.h
index 74e8b408..9faf2023 100644
--- a/class/hid/usbh_hid.h
+++ b/class/hid/usbh_hid.h
@@ -25,6 +25,9 @@ extern "C" {
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration);
int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer);
+void usbh_hid_run(struct usbh_hid *hid_class);
+void usbh_hid_stop(struct usbh_hid *hid_class);
+
#ifdef __cplusplus
}
#endif
diff --git a/class/msc/usbh_msc.c b/class/msc/usbh_msc.c
index 550b0c25..5c644322 100644
--- a/class/msc/usbh_msc.c
+++ b/class/msc/usbh_msc.c
@@ -371,6 +371,7 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register MSC Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_msc_run(msc_class);
return ret;
}
@@ -391,6 +392,7 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
usbh_pipe_free(msc_class->bulkout);
}
+ usbh_msc_stop(msc_class);
memset(msc_class, 0, sizeof(struct usbh_msc));
usb_free(msc_class);
@@ -401,6 +403,16 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret;
}
+__WEAK void usbh_msc_run(struct usbh_msc *msc_class)
+{
+
+}
+
+__WEAK void usbh_msc_stop(struct usbh_msc *msc_class)
+{
+
+}
+
const struct usbh_class_driver msc_class_driver = {
.driver_name = "msc",
.connect = usbh_msc_connect,
diff --git a/class/msc/usbh_msc.h b/class/msc/usbh_msc.h
index 5a61de7d..aa489a1d 100644
--- a/class/msc/usbh_msc.h
+++ b/class/msc/usbh_msc.h
@@ -25,6 +25,9 @@ struct usbh_msc {
int usbh_msc_scsi_write10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors);
int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors);
+void usbh_msc_run(struct usbh_msc *msc_class);
+void usbh_msc_stop(struct usbh_msc *msc_class);
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/class/vendor/usbh_air724.c b/class/vendor/usbh_air724.c
index 72ffcab3..04de5646 100644
--- a/class/vendor/usbh_air724.c
+++ b/class/vendor/usbh_air724.c
@@ -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;
}
diff --git a/class/video/usbh_video.c b/class/video/usbh_video.c
index e6952ca2..3fb73585 100644
--- a/class/video/usbh_video.c
+++ b/class/video/usbh_video.c
@@ -382,7 +382,8 @@ static int usbh_video_ctrl_intf_connect(struct usbh_hubport *hport, uint8_t intf
inityuyv2rgb_table();
USB_LOG_INFO("Register Video Class:%s\r\n", hport->config.intf[intf].devname);
- return 0;
+ usbh_video_run(video_class);
+ return ret;
}
static int usbh_video_ctrl_intf_disconnect(struct usbh_hubport *hport, uint8_t intf)
@@ -402,6 +403,7 @@ static int usbh_video_ctrl_intf_disconnect(struct usbh_hubport *hport, uint8_t i
usbh_pipe_free(video_class->isoout);
}
+ usbh_video_stop(video_class);
memset(video_class, 0, sizeof(struct usbh_video));
usb_free(video_class);
@@ -541,6 +543,16 @@ void usbh_videostreaming_parse_yuyv2rgb565(struct usbh_urb *urb, struct usbh_vid
}
}
+__WEAK void usbh_video_run(struct usbh_video *video_class)
+{
+
+}
+
+__WEAK void usbh_video_stop(struct usbh_video *video_class)
+{
+
+}
+
const struct usbh_class_driver video_class_ctrl_intf_driver = {
.driver_name = "video",
.connect = usbh_video_ctrl_intf_connect,
diff --git a/class/video/usbh_video.h b/class/video/usbh_video.h
index 4cc0933a..bbf8d9fb 100644
--- a/class/video/usbh_video.h
+++ b/class/video/usbh_video.h
@@ -65,6 +65,9 @@ void usbh_video_list_info(struct usbh_video *video_class);
void usbh_videostreaming_parse_mjpeg(struct usbh_urb *urb, struct usbh_videostreaming *stream);
void usbh_videostreaming_parse_yuyv2rgb565(struct usbh_urb *urb, struct usbh_videostreaming *stream);
+void usbh_video_run(struct usbh_video *video_class);
+void usbh_video_stop(struct usbh_video *video_class);
+
#ifdef __cplusplus
}
#endif
diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c
index 515b6456..80f737ee 100644
--- a/class/wireless/usbh_rndis.c
+++ b/class/wireless/usbh_rndis.c
@@ -158,6 +158,34 @@ static int usbh_rndis_set_msg_transfer(struct usbh_rndis *rndis_class, uint32_t
return ret;
}
+int usbh_rndis_bulk_out_transfer(struct usbh_rndis *rndis_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
+{
+ int ret;
+ struct usbh_urb *urb = &rndis_class->bulkout_urb;
+ memset(urb, 0, sizeof(struct usbh_urb));
+
+ usbh_bulk_urb_fill(urb, rndis_class->bulkout, buffer, buflen, timeout, NULL, NULL);
+ ret = usbh_submit_urb(urb);
+ if (ret == 0) {
+ ret = urb->actual_length;
+ }
+ return ret;
+}
+
+int usbh_rndis_bulk_in_transfer(struct usbh_rndis *rndis_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout)
+{
+ int ret;
+ struct usbh_urb *urb = &rndis_class->bulkin_urb;
+ memset(urb, 0, sizeof(struct usbh_urb));
+
+ usbh_bulk_urb_fill(urb, rndis_class->bulkin, buffer, buflen, timeout, NULL, NULL);
+ ret = usbh_submit_urb(urb);
+ if (ret == 0) {
+ ret = urb->actual_length;
+ }
+ return ret;
+}
+
int usbh_rndis_keepalive(struct usbh_rndis *rndis_class)
{
struct usb_setup_packet *setup = &rndis_class->hport->setup;
@@ -285,12 +313,19 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
if (ret < 0) {
goto query_errorout;
}
+
+ memcpy(&rndis_class->link_speed, data, 4);
break;
case OID_GEN_MEDIA_CONNECT_STATUS:
ret = usbh_rndis_query_msg_transfer(rndis_class, OID_GEN_MEDIA_CONNECT_STATUS, 4, data, &data_len);
if (ret < 0) {
goto query_errorout;
}
+ if (NDIS_MEDIA_STATE_CONNECTED == data[0]) {
+ rndis_class->link_status = true;
+ } else {
+ rndis_class->link_status = false;
+ }
break;
case OID_802_3_MAXIMUM_LIST_SIZE:
ret = usbh_rndis_query_msg_transfer(rndis_class, OID_802_3_MAXIMUM_LIST_SIZE, 4, data, &data_len);
@@ -303,6 +338,10 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
if (ret < 0) {
goto query_errorout;
}
+
+ for (uint8_t j = 0; j < 6; j++) {
+ rndis_class->mac[j] = data[j];
+ }
break;
case OID_802_3_PERMANENT_ADDRESS:
ret = usbh_rndis_query_msg_transfer(rndis_class, OID_802_3_PERMANENT_ADDRESS, 6, data, &data_len);
@@ -334,6 +373,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
USB_LOG_INFO("Register RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_rndis_run(rndis_class);
return ret;
query_errorout:
USB_LOG_ERR("rndis query iod:%08x error\r\n", oid);
@@ -354,6 +394,8 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
if (rndis_class->bulkout) {
usbh_pipe_free(rndis_class->bulkout);
}
+
+ usbh_rndis_stop(rndis_class);
memset(rndis_class, 0, sizeof(struct usbh_rndis));
usb_free(rndis_class);
@@ -364,6 +406,14 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret;
}
+__WEAK void usbh_rndis_run(struct usbh_rndis *rndis_class)
+{
+}
+
+__WEAK void usbh_rndis_stop(struct usbh_rndis *rndis_class)
+{
+}
+
static const struct usbh_class_driver rndis_class_driver = {
.driver_name = "rndis",
.connect = usbh_rndis_connect,
diff --git a/class/wireless/usbh_rndis.h b/class/wireless/usbh_rndis.h
index 88562c64..b9610b32 100644
--- a/class/wireless/usbh_rndis.h
+++ b/class/wireless/usbh_rndis.h
@@ -14,11 +14,15 @@ struct usbh_rndis {
uint8_t ctrl_intf; /* Control interface number */
uint8_t data_intf; /* Data interface number */
- usbh_pipe_t bulkin; /* Bulk IN endpoint */
- usbh_pipe_t bulkout; /* Bulk OUT endpoint */
- usbh_pipe_t intin; /* Notify endpoint */
-
+ usbh_pipe_t bulkin; /* Bulk IN endpoint */
+ usbh_pipe_t bulkout; /* Bulk OUT endpoint */
+ usbh_pipe_t intin; /* Notify endpoint */
+ struct usbh_urb bulkin_urb; /* Bulk IN urb */
+ struct usbh_urb bulkout_urb; /* Bulk OUT urb */
uint32_t request_id;
+
+ uint32_t link_speed;
+ bool link_status;
uint8_t mac[6];
};
@@ -26,8 +30,14 @@ struct usbh_rndis {
extern "C" {
#endif
+int usbh_rndis_bulk_out_transfer(struct usbh_rndis *rndis_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
+int usbh_rndis_bulk_in_transfer(struct usbh_rndis *rndis_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
+
int usbh_rndis_keepalive(struct usbh_rndis *rndis_class);
+void usbh_rndis_run(struct usbh_rndis *rndis_class);
+void usbh_rndis_stop(struct usbh_rndis *rndis_class);
+
#ifdef __cplusplus
}
#endif