aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/usbh
diff options
context:
space:
mode:
authorDiego Ismirlian <dismirlian (at) google's mail.com>2017-07-13 16:45:31 -0300
committerDiego Ismirlian <dismirlian (at) google's mail.com>2017-07-13 16:45:31 -0300
commitc044306ad058689783b1a6941a2a44d5baf738a2 (patch)
tree5ccc2a53c2e4c61450b5cad5208ca704e79fd741 /os/hal/src/usbh
parentc9cc2abf3e6854f68a87f72e73cd4eec92262317 (diff)
downloadChibiOS-Contrib-c044306ad058689783b1a6941a2a44d5baf738a2.tar.gz
ChibiOS-Contrib-c044306ad058689783b1a6941a2a44d5baf738a2.tar.bz2
ChibiOS-Contrib-c044306ad058689783b1a6941a2a44d5baf738a2.zip
USBH: Add flexibility to the enumeration process
Diffstat (limited to 'os/hal/src/usbh')
-rw-r--r--os/hal/src/usbh/hal_usbh_aoa.c14
-rw-r--r--os/hal/src/usbh/hal_usbh_ftdi.c9
-rw-r--r--os/hal/src/usbh/hal_usbh_hid.c7
-rw-r--r--os/hal/src/usbh/hal_usbh_hub.c17
-rw-r--r--os/hal/src/usbh/hal_usbh_msd.c9
-rw-r--r--os/hal/src/usbh/hal_usbh_uvc.c5
6 files changed, 26 insertions, 35 deletions
diff --git a/os/hal/src/usbh/hal_usbh_aoa.c b/os/hal/src/usbh/hal_usbh_aoa.c
index db348c0..1526aa3 100644
--- a/os/hal/src/usbh/hal_usbh_aoa.c
+++ b/os/hal/src/usbh/hal_usbh_aoa.c
@@ -133,7 +133,7 @@ static const usbh_classdriver_vmt_t class_driver_vmt = {
};
const usbh_classdriverinfo_t usbhaoaClassDriverInfo = {
- 0xff, 0xff, 0xff, "AOA", &class_driver_vmt
+ "AOA", &class_driver_vmt
};
#if defined(HAL_USBHAOA_FILTER_CALLBACK)
@@ -146,7 +146,7 @@ static usbh_baseclassdriver_t *_aoa_load(usbh_device_t *dev, const uint8_t *desc
if (dev->devDesc.idVendor != AOA_GOOGLE_VID) {
uint16_t protocol;
- static const USBHAOAConfig config = {
+ static USBHAOAConfig config = {
{
HAL_USBHAOA_DEFAULT_MANUFACTURER,
HAL_USBHAOA_DEFAULT_MODEL,
@@ -223,15 +223,9 @@ static usbh_baseclassdriver_t *_aoa_load(usbh_device_t *dev, const uint8_t *desc
return NULL;
}
- if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
- return NULL;
-
const usbh_interface_descriptor_t * const ifdesc = (const usbh_interface_descriptor_t *)descriptor;
-
- if ((ifdesc->bInterfaceClass != 0xff)
- || (ifdesc->bInterfaceSubClass != 0xff)
- || (ifdesc->bInterfaceProtocol != 0x00)
- || (ifdesc->bNumEndpoints < 2)) {
+ if ((_usbh_match_descriptor(descriptor, rem, USBH_DT_INTERFACE, 0xFF, 0xFF, 0x00) != HAL_SUCCESS)
+ || (ifdesc->bNumEndpoints < 2)) {
uerr("AOA: This IF is not the Accessory IF");
return NULL;
}
diff --git a/os/hal/src/usbh/hal_usbh_ftdi.c b/os/hal/src/usbh/hal_usbh_ftdi.c
index a01c566..edcf022 100644
--- a/os/hal/src/usbh/hal_usbh_ftdi.c
+++ b/os/hal/src/usbh/hal_usbh_ftdi.c
@@ -77,7 +77,7 @@ static const usbh_classdriver_vmt_t class_driver_vmt = {
};
const usbh_classdriverinfo_t usbhftdiClassDriverInfo = {
- 0xff, 0xff, 0xff, "FTDI", &class_driver_vmt
+ "FTDI", &class_driver_vmt
};
static USBHFTDIPortDriver *_find_port(void) {
@@ -93,10 +93,8 @@ static usbh_baseclassdriver_t *_ftdi_load(usbh_device_t *dev, const uint8_t *des
int i;
USBHFTDIDriver *ftdip;
- if (dev->devDesc.idVendor != 0x0403) {
- uerr("FTDI: Unrecognized VID");
+ if (_usbh_match_vid_pid(dev, 0x0403, -1) != HAL_SUCCESS)
return NULL;
- }
switch (dev->devDesc.idProduct) {
case 0x6001:
@@ -111,7 +109,8 @@ static usbh_baseclassdriver_t *_ftdi_load(usbh_device_t *dev, const uint8_t *des
return NULL;
}
- if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
+ if (_usbh_match_descriptor(descriptor, rem, USBH_DT_INTERFACE,
+ 0xff, 0xff, 0xff) != HAL_SUCCESS)
return NULL;
if (((const usbh_interface_descriptor_t *)descriptor)->bInterfaceNumber != 0) {
diff --git a/os/hal/src/usbh/hal_usbh_hid.c b/os/hal/src/usbh/hal_usbh_hid.c
index 5b2823f..269b1b2 100644
--- a/os/hal/src/usbh/hal_usbh_hid.c
+++ b/os/hal/src/usbh/hal_usbh_hid.c
@@ -85,14 +85,15 @@ static const usbh_classdriver_vmt_t class_driver_vmt = {
};
const usbh_classdriverinfo_t usbhhidClassDriverInfo = {
- 0x03, -1, -1, "HID", &class_driver_vmt
+ "HID", &class_driver_vmt
};
static usbh_baseclassdriver_t *_hid_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem) {
int i;
USBHHIDDriver *hidp;
- if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
+ if (_usbh_match_descriptor(descriptor, rem, USBH_DT_INTERFACE,
+ 0x03, -1, -1) != HAL_SUCCESS)
return NULL;
const usbh_interface_descriptor_t * const ifdesc = (const usbh_interface_descriptor_t *)descriptor;
@@ -183,7 +184,7 @@ deinit:
static void _hid_unload(usbh_baseclassdriver_t *drv) {
USBHHIDDriver *const hidp = (USBHHIDDriver *)drv;
-
+ (void)hidp;
}
static void _in_cb(usbh_urb_t *urb) {
diff --git a/os/hal/src/usbh/hal_usbh_hub.c b/os/hal/src/usbh/hal_usbh_hub.c
index c9bbe9b..80282ef 100644
--- a/os/hal/src/usbh/hal_usbh_hub.c
+++ b/os/hal/src/usbh/hal_usbh_hub.c
@@ -73,7 +73,7 @@ static const usbh_classdriver_vmt_t usbhhubClassDriverVMT = {
};
const usbh_classdriverinfo_t usbhhubClassDriverInfo = {
- 0x09, 0x00, -1, "HUB", &usbhhubClassDriverVMT
+ "HUB", &usbhhubClassDriverVMT
};
@@ -146,10 +146,8 @@ static usbh_baseclassdriver_t *_hub_load(usbh_device_t *dev,
USBHHubDriver *hubdp;
- if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_DEVICE))
- return NULL;
-
- if (dev->devDesc.bDeviceProtocol != 0)
+ if (_usbh_match_descriptor(descriptor, rem, USBH_DT_DEVICE,
+ 0x09, 0x00, 0x00) != HAL_SUCCESS)
return NULL;
generic_iterator_t iep, icfg;
@@ -161,12 +159,10 @@ static usbh_baseclassdriver_t *_hub_load(usbh_device_t *dev,
if_iter_init(&iif, &icfg);
if (!iif.valid)
return NULL;
- const usbh_interface_descriptor_t *const ifdesc = if_get(&iif);
- if ((ifdesc->bInterfaceClass != 0x09)
- || (ifdesc->bInterfaceSubClass != 0x00)
- || (ifdesc->bInterfaceProtocol != 0x00)) {
+
+ if (_usbh_match_descriptor(iif.curr, iif.rem, USBH_DT_INTERFACE,
+ 0x09, 0x00, 0x00) != HAL_SUCCESS)
return NULL;
- }
ep_iter_init(&iep, &iif);
if (!iep.valid)
@@ -261,6 +257,7 @@ alloc_ok:
osalOsRescheduleS();
osalSysUnlock();
+ hubdp->dev = NULL;
return (usbh_baseclassdriver_t *)hubdp;
}
diff --git a/os/hal/src/usbh/hal_usbh_msd.c b/os/hal/src/usbh/hal_usbh_msd.c
index f212516..abc58f3 100644
--- a/os/hal/src/usbh/hal_usbh_msd.c
+++ b/os/hal/src/usbh/hal_usbh_msd.c
@@ -91,7 +91,7 @@ static const usbh_classdriver_vmt_t class_driver_vmt = {
};
const usbh_classdriverinfo_t usbhmsdClassDriverInfo = {
- 0x08, 0x06, 0x50, "MSD", &class_driver_vmt
+ "MSD", &class_driver_vmt
};
#define MSD_REQ_RESET 0xFF
@@ -103,15 +103,14 @@ static usbh_baseclassdriver_t *_msd_load(usbh_device_t *dev, const uint8_t *desc
uint8_t luns;
usbh_urbstatus_t stat;
- if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
+ if (_usbh_match_descriptor(descriptor, rem, USBH_DT_INTERFACE,
+ 0x08, 0x06, 0x50) != HAL_SUCCESS)
return NULL;
const usbh_interface_descriptor_t * const ifdesc = (const usbh_interface_descriptor_t *)descriptor;
if ((ifdesc->bAlternateSetting != 0)
- || (ifdesc->bNumEndpoints < 2)
- || (ifdesc->bInterfaceSubClass != 0x06)
- || (ifdesc->bInterfaceProtocol != 0x50)) {
+ || (ifdesc->bNumEndpoints < 2)) {
return NULL;
}
diff --git a/os/hal/src/usbh/hal_usbh_uvc.c b/os/hal/src/usbh/hal_usbh_uvc.c
index 3f362a2..7777823 100644
--- a/os/hal/src/usbh/hal_usbh_uvc.c
+++ b/os/hal/src/usbh/hal_usbh_uvc.c
@@ -77,7 +77,7 @@ static const usbh_classdriver_vmt_t class_driver_vmt = {
_uvc_unload
};
const usbh_classdriverinfo_t usbhuvcClassDriverInfo = {
- 0x0e, 0x03, 0x00, "UVC", &class_driver_vmt
+ "UVC", &class_driver_vmt
};
static bool _request(USBHUVCDriver *uvcdp,
@@ -518,7 +518,8 @@ static usbh_baseclassdriver_t *_uvc_load(usbh_device_t *dev, const uint8_t *desc
USBHUVCDriver *uvcdp;
uint8_t i;
- if (descriptor[1] != USBH_DT_INTERFACE_ASSOCIATION)
+ if (_usbh_match_descriptor(descriptor, rem, USBH_DT_INTERFACE_ASSOCIATION,
+ 0x0e, 0x03, 0x00) != HAL_SUCCESS)
return NULL;
/* alloc driver */