aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src
diff options
context:
space:
mode:
authorDiego Ismirlian <dismirlian (at) google's mail.com>2017-06-06 10:21:00 -0300
committerDiego Ismirlian <dismirlian (at) google's mail.com>2017-06-06 10:21:00 -0300
commit9349f7400432ae5a999c524b89da8a835da59b08 (patch)
treecbfdc9866114d3169475724232bc34e260d8a22d /os/hal/src
parente1357dab69fed9b5eacb40ba18978729f5844566 (diff)
downloadChibiOS-Contrib-9349f7400432ae5a999c524b89da8a835da59b08.tar.gz
ChibiOS-Contrib-9349f7400432ae5a999c524b89da8a835da59b08.tar.bz2
ChibiOS-Contrib-9349f7400432ae5a999c524b89da8a835da59b08.zip
Clean up request type helpers
Diffstat (limited to 'os/hal/src')
-rw-r--r--os/hal/src/hal_usbh.c101
-rw-r--r--os/hal/src/usbh/hal_usbh_aoa.c8
-rw-r--r--os/hal/src/usbh/hal_usbh_ftdi.c12
-rw-r--r--os/hal/src/usbh/hal_usbh_hid.c26
-rw-r--r--os/hal/src/usbh/hal_usbh_msd.c8
5 files changed, 75 insertions, 80 deletions
diff --git a/os/hal/src/hal_usbh.c b/os/hal/src/hal_usbh.c
index 11add0d..538f36e 100644
--- a/os/hal/src/hal_usbh.c
+++ b/os/hal/src/hal_usbh.c
@@ -201,8 +201,9 @@ bool usbhEPReset(usbh_ep_t *ep) {
osalDbgAssert(ep->type != USBH_EPTYPE_CTRL, "don't need to reset control endpoint");
usbh_urbstatus_t ret = usbhControlRequest(ep->device,
- USBH_STANDARDOUT(USBH_REQTYPE_ENDPOINT, USBH_REQ_CLEAR_FEATURE, 0, ep->address | (ep->in ? 0x80 : 0x00)),
- 0, 0);
+ USBH_REQTYPE_STANDARDOUT(USBH_REQTYPE_RECIP_ENDPOINT),
+ USBH_REQ_CLEAR_FEATURE,
+ 0, ep->address | (ep->in ? 0x80 : 0x00), 0, 0);
/* TODO: GET_STATUS to see if endpoint is still halted */
osalSysLock();
@@ -460,27 +461,19 @@ usbh_urbstatus_t usbhControlRequest(usbh_device_t *dev,
/* Standard request helpers. */
/*===========================================================================*/
-#define USBH_GET_DESCRIPTOR(type, value, index) \
- USBH_STANDARDIN(type, \
- USBH_REQ_GET_DESCRIPTOR, \
- value, \
- index) \
-
-#define USBH_GETDEVICEDESCRIPTOR \
- USBH_GET_DESCRIPTOR(USBH_REQTYPE_DEVICE, (USBH_DT_DEVICE << 8) | 0, 0)
-
-#define USBH_GETCONFIGURATIONDESCRIPTOR(index) \
- USBH_GET_DESCRIPTOR(USBH_REQTYPE_DEVICE, (USBH_DT_CONFIG << 8) | index, 0)
-
-#define USBH_GETSTRINGDESCRIPTOR(index, langID) \
- USBH_GET_DESCRIPTOR(USBH_REQTYPE_DEVICE, (USBH_DT_STRING << 8) | index, langID)
-
bool usbhStdReqGetDeviceDescriptor(usbh_device_t *dev,
uint16_t wLength,
uint8_t *buf) {
usbh_device_descriptor_t *desc;
- usbh_urbstatus_t ret = usbhControlRequest(dev, USBH_GETDEVICEDESCRIPTOR, wLength, buf);
+
+ usbh_urbstatus_t ret = usbhControlRequest(dev,
+ USBH_REQTYPE_STANDARDIN(USBH_REQTYPE_RECIP_DEVICE),
+ USBH_REQ_GET_DESCRIPTOR,
+ (USBH_DT_DEVICE << 8) | 0, 0,
+ wLength, buf);
+
desc = (usbh_device_descriptor_t *)buf;
+
if ((ret != USBH_URBSTATUS_OK)
|| (desc->bLength != USBH_DT_DEVICE_SIZE)
|| (desc->bDescriptorType != USBH_DT_DEVICE)) {
@@ -493,8 +486,15 @@ bool usbhStdReqGetConfigurationDescriptor(usbh_device_t *dev,
uint8_t index,
uint16_t wLength,
uint8_t *buf) {
- usbh_urbstatus_t ret = usbhControlRequest(dev, USBH_GETCONFIGURATIONDESCRIPTOR(index), wLength, buf);
+
+ usbh_urbstatus_t ret = usbhControlRequest(dev,
+ USBH_REQTYPE_STANDARDIN(USBH_REQTYPE_RECIP_DEVICE),
+ USBH_REQ_GET_DESCRIPTOR,
+ (USBH_DT_CONFIG << 8) | index, 0,
+ wLength, buf);
+
usbh_config_descriptor_t *const desc = (usbh_config_descriptor_t *)buf;
+
if ((ret != USBH_URBSTATUS_OK)
|| (desc->bLength < USBH_DT_CONFIG_SIZE)
|| (desc->bDescriptorType != USBH_DT_CONFIG)) {
@@ -511,7 +511,13 @@ bool usbhStdReqGetStringDescriptor(usbh_device_t *dev,
osalDbgAssert(wLength >= USBH_DT_STRING_SIZE, "wrong size");
usbh_string_descriptor_t *desc = (usbh_string_descriptor_t *)buf;
- usbh_urbstatus_t ret = usbhControlRequest(dev, USBH_GETSTRINGDESCRIPTOR(index, langID), wLength, buf);
+
+ usbh_urbstatus_t ret = usbhControlRequest(dev,
+ USBH_REQTYPE_STANDARDIN(USBH_REQTYPE_RECIP_DEVICE),
+ USBH_REQ_GET_DESCRIPTOR,
+ (USBH_DT_STRING << 8) | index, langID,
+ wLength, buf);
+
if ((ret != USBH_URBSTATUS_OK)
|| (desc->bLength < USBH_DT_STRING_SIZE)
|| (desc->bDescriptorType != USBH_DT_STRING)) {
@@ -520,25 +526,17 @@ bool usbhStdReqGetStringDescriptor(usbh_device_t *dev,
return HAL_SUCCESS;
}
-
-
-#define USBH_SET_INTERFACE(interface, alt) \
- USBH_STANDARDOUT(USBH_REQTYPE_INTERFACE, \
- USBH_REQ_SET_INTERFACE, \
- alt, \
- interface) \
-
-#define USBH_GET_INTERFACE(interface) \
- USBH_STANDARDIN(USBH_REQTYPE_INTERFACE, \
- USBH_REQ_GET_INTERFACE, \
- 0, \
- interface) \
-
bool usbhStdReqSetInterface(usbh_device_t *dev,
uint8_t bInterfaceNumber,
uint8_t bAlternateSetting) {
- usbh_urbstatus_t ret = usbhControlRequest(dev, USBH_SET_INTERFACE(bInterfaceNumber, bAlternateSetting), 0, NULL);
+ usbh_urbstatus_t ret = usbhControlRequest(dev,
+ USBH_REQTYPE_STANDARDOUT(USBH_REQTYPE_RECIP_INTERFACE),
+ USBH_REQ_SET_INTERFACE,
+ bAlternateSetting,
+ bInterfaceNumber,
+ 0, NULL);
+
if (ret != USBH_URBSTATUS_OK)
return HAL_FAILED;
@@ -551,7 +549,13 @@ bool usbhStdReqGetInterface(usbh_device_t *dev,
USBH_DEFINE_BUFFER(uint8_t alt);
- usbh_urbstatus_t ret = usbhControlRequest(dev, USBH_GET_INTERFACE(bInterfaceNumber), 1, &alt);
+ usbh_urbstatus_t ret = usbhControlRequest(dev,
+ USBH_REQTYPE_STANDARDIN(USBH_REQTYPE_RECIP_INTERFACE),
+ USBH_REQ_GET_INTERFACE,
+ 0,
+ bInterfaceNumber,
+ 1, &alt);
+
if (ret != USBH_URBSTATUS_OK)
return HAL_FAILED;
@@ -596,7 +600,8 @@ static void _device_initialize(usbh_device_t *dev, usbh_devspeed_t speed) {
static bool _device_setaddress(usbh_device_t *dev, uint8_t address) {
usbh_urbstatus_t ret = usbhControlRequest(dev,
- USBH_STANDARDOUT(USBH_REQTYPE_DEVICE, USBH_REQ_SET_ADDRESS, address, 0),
+ USBH_REQTYPE_STANDARDOUT(USBH_REQTYPE_RECIP_DEVICE),
+ USBH_REQ_SET_ADDRESS, address, 0,
0,
0);
if (ret != USBH_URBSTATUS_OK)
@@ -649,22 +654,12 @@ static void _device_free_full_cfgdesc(usbh_device_t *dev) {
}
}
-
-#define USBH_SET_CONFIGURATION(type, value, index) \
- USBH_STANDARDOUT(type, \
- USBH_REQ_SET_CONFIGURATION, \
- value, \
- index) \
-
-#define USBH_SETDEVICECONFIGURATION(index) \
- USBH_SET_CONFIGURATION(USBH_REQTYPE_DEVICE, index, 0)
-
-
static bool _device_set_configuration(usbh_device_t *dev, uint8_t configuration) {
usbh_urbstatus_t ret = usbhControlRequest(dev,
- USBH_SETDEVICECONFIGURATION(configuration),
- 0,
- 0);
+ USBH_REQTYPE_STANDARDOUT(USBH_REQTYPE_RECIP_DEVICE),
+ USBH_REQ_SET_CONFIGURATION,
+ configuration,
+ 0, 0, 0);
if (ret != USBH_URBSTATUS_OK)
return HAL_FAILED;
return HAL_SUCCESS;
@@ -894,7 +889,7 @@ static void _port_reset(usbh_port_t *port) {
#if HAL_USBH_USE_HUB
port->hub,
#endif
- USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_OTHER,
+ USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
USBH_REQ_SET_FEATURE,
USBH_PORT_FEAT_RESET,
port->number,
@@ -908,7 +903,7 @@ static void _port_update_status(usbh_port_t *port) {
#if HAL_USBH_USE_HUB
port->hub,
#endif
- USBH_REQTYPE_IN | USBH_REQTYPE_CLASS | USBH_REQTYPE_OTHER,
+ USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
USBH_REQ_GET_STATUS,
0,
port->number,
diff --git a/os/hal/src/usbh/hal_usbh_aoa.c b/os/hal/src/usbh/hal_usbh_aoa.c
index 2d96235..1fa49f8 100644
--- a/os/hal/src/usbh/hal_usbh_aoa.c
+++ b/os/hal/src/usbh/hal_usbh_aoa.c
@@ -594,7 +594,7 @@ static bool _get_protocol(usbh_device_t *dev, uint16_t *protocol) {
USBH_DEFINE_BUFFER(uint16_t proto);
usbh_urbstatus_t ret = usbhControlRequest(dev,
- USBH_REQTYPE_IN | USBH_REQTYPE_VENDOR | USBH_REQTYPE_DEVICE,
+ USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_RECIP_DEVICE,
AOA_ACCESSORY_GET_PROTOCOL,
0,
0,
@@ -610,7 +610,7 @@ static bool _get_protocol(usbh_device_t *dev, uint16_t *protocol) {
static bool _accessory_start(usbh_device_t *dev) {
usbh_urbstatus_t ret = usbhControlRequest(dev,
- USBH_REQTYPE_OUT | USBH_REQTYPE_VENDOR | USBH_REQTYPE_DEVICE,
+ USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_RECIP_DEVICE,
AOA_ACCESSORY_START,
0,
0,
@@ -625,7 +625,7 @@ static bool _accessory_start(usbh_device_t *dev) {
static bool _set_audio_mode(usbh_device_t *dev, uint16_t mode) {
usbh_urbstatus_t ret = usbhControlRequest(dev,
- USBH_REQTYPE_OUT | USBH_REQTYPE_VENDOR | USBH_REQTYPE_DEVICE,
+ USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_RECIP_DEVICE,
AOA_SET_AUDIO_MODE,
mode,
0,
@@ -645,7 +645,7 @@ static bool _send_string(usbh_device_t *dev, uint8_t index, const char *string)
string = nullstr;
usbh_urbstatus_t ret = usbhControlRequest(dev,
- USBH_REQTYPE_OUT | USBH_REQTYPE_VENDOR | USBH_REQTYPE_DEVICE,
+ USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_RECIP_DEVICE,
AOA_ACCESSORY_SEND_STRING,
0,
index,
diff --git a/os/hal/src/usbh/hal_usbh_ftdi.c b/os/hal/src/usbh/hal_usbh_ftdi.c
index aa6ec1a..ce96958 100644
--- a/os/hal/src/usbh/hal_usbh_ftdi.c
+++ b/os/hal/src/usbh/hal_usbh_ftdi.c
@@ -316,11 +316,11 @@ static usbh_urbstatus_t _ftdi_port_control(USBHFTDIPortDriver *ftdipp,
uint8_t *buff) {
static const uint8_t bmRequestType[] = {
- USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //0 FTDI_COMMAND_RESET
- USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //1 FTDI_COMMAND_MODEMCTRL
- USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //2 FTDI_COMMAND_SETFLOW
- USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //3 FTDI_COMMAND_SETBAUD
- USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //4 FTDI_COMMAND_SETDATA
+ USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //0 FTDI_COMMAND_RESET
+ USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //1 FTDI_COMMAND_MODEMCTRL
+ USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //2 FTDI_COMMAND_SETFLOW
+ USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //3 FTDI_COMMAND_SETBAUD
+ USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //4 FTDI_COMMAND_SETDATA
};
osalDbgCheck(bRequest < sizeof_array(bmRequestType));
@@ -390,7 +390,7 @@ static usbh_urbstatus_t _set_baudrate(USBHFTDIPortDriver *ftdipp, uint32_t baudr
wIndex = (wIndex << 8) | (ftdipp->ifnum + 1);
USBH_DEFINE_BUFFER(const usbh_control_request_t req) = {
- USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE,
+ USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE,
FTDI_COMMAND_SETBAUD,
wValue,
wIndex,
diff --git a/os/hal/src/usbh/hal_usbh_hid.c b/os/hal/src/usbh/hal_usbh_hid.c
index 9e248cb..e98dff7 100644
--- a/os/hal/src/usbh/hal_usbh_hid.c
+++ b/os/hal/src/usbh/hal_usbh_hid.c
@@ -262,9 +262,8 @@ usbh_urbstatus_t usbhhidGetReport(USBHHIDDriver *hidp,
osalDbgCheck(hidp);
osalDbgAssert((uint8_t)report_type <= USBHHID_REPORTTYPE_FEATURE, "wrong report type");
return usbhControlRequest(hidp->dev,
- USBH_CLASSIN(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_GET_REPORT,
- ((uint8_t)report_type << 8) | report_id, hidp->ifnum),
- len, data);
+ USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_GET_REPORT,
+ ((uint8_t)report_type << 8) | report_id, hidp->ifnum, len, data);
}
usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp,
@@ -273,38 +272,37 @@ usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp,
osalDbgCheck(hidp);
osalDbgAssert((uint8_t)report_type <= USBHHID_REPORTTYPE_FEATURE, "wrong report type");
return usbhControlRequest(hidp->dev,
- USBH_CLASSOUT(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_SET_REPORT,
- ((uint8_t)report_type << 8) | report_id, hidp->ifnum),
- len, (void *)data);
+ USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_SET_REPORT,
+ ((uint8_t)report_type << 8) | report_id, hidp->ifnum, len, (void *)data);
}
usbh_urbstatus_t usbhhidGetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t *duration) {
osalDbgCheck(hidp);
return usbhControlRequest(hidp->dev,
- USBH_CLASSIN(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_GET_IDLE, report_id, hidp->ifnum),
- 1, duration);
+ USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_GET_IDLE,
+ report_id, hidp->ifnum, 1, duration);
}
usbh_urbstatus_t usbhhidSetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t duration) {
osalDbgCheck(hidp);
return usbhControlRequest(hidp->dev,
- USBH_CLASSOUT(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_SET_IDLE,
- (duration << 8) | report_id, hidp->ifnum), 0, NULL);
+ USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_SET_IDLE,
+ (duration << 8) | report_id, hidp->ifnum, 0, NULL);
}
usbh_urbstatus_t usbhhidGetProtocol(USBHHIDDriver *hidp, uint8_t *protocol) {
osalDbgCheck(hidp);
return usbhControlRequest(hidp->dev,
- USBH_CLASSIN(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_GET_PROTOCOL, 0, hidp->ifnum),
- 1, protocol);
+ USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_GET_PROTOCOL,
+ 0, hidp->ifnum, 1, protocol);
}
usbh_urbstatus_t usbhhidSetProtocol(USBHHIDDriver *hidp, uint8_t protocol) {
osalDbgCheck(hidp);
osalDbgAssert(protocol <= 1, "invalid protocol");
return usbhControlRequest(hidp->dev,
- USBH_CLASSOUT(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_SET_PROTOCOL,
- protocol, hidp->ifnum), 0, NULL);
+ USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_SET_PROTOCOL,
+ protocol, hidp->ifnum, 0, NULL);
}
void usbhhidObjectInit(USBHHIDDriver *hidp) {
diff --git a/os/hal/src/usbh/hal_usbh_msd.c b/os/hal/src/usbh/hal_usbh_msd.c
index 6abc48c..121e730 100644
--- a/os/hal/src/usbh/hal_usbh_msd.c
+++ b/os/hal/src/usbh/hal_usbh_msd.c
@@ -158,8 +158,8 @@ alloc_ok:
uinfo("Reading Max LUN:");
USBH_DEFINE_BUFFER(uint8_t buff[4]);
stat = usbhControlRequest(dev,
- USBH_CLASSIN(USBH_REQTYPE_INTERFACE, MSD_GET_MAX_LUN, 0, msdp->ifnum),
- 1, buff);
+ USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE),
+ MSD_GET_MAX_LUN, 0, msdp->ifnum, 1, buff);
if (stat == USBH_URBSTATUS_OK) {
msdp->max_lun = buff[0] + 1;
uinfof("\tmax_lun = %d", msdp->max_lun);
@@ -290,7 +290,9 @@ typedef enum {
static bool _msd_bot_reset(USBHMassStorageDriver *msdp) {
usbh_urbstatus_t res;
- res = usbhControlRequest(msdp->dev, USBH_CLASSOUT(USBH_REQTYPE_CLASS, 0xFF, 0, msdp->ifnum), 0, NULL);
+ res = usbhControlRequest(msdp->dev,
+ USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE),
+ 0xFF, 0, msdp->ifnum, 0, NULL);
if (res != USBH_URBSTATUS_OK) {
return FALSE;
}