Clean up request type helpers

This commit is contained in:
Diego Ismirlian 2017-06-06 10:21:00 -03:00
parent e1357dab69
commit 9349f74004
8 changed files with 102 additions and 120 deletions

View File

@ -141,18 +141,17 @@ typedef PACKED_STRUCT {
#define USBH_REQ_SET_INTERFACE 0x0B #define USBH_REQ_SET_INTERFACE 0x0B
#define USBH_REQ_SYNCH_FRAME 0x0C #define USBH_REQ_SYNCH_FRAME 0x0C
#define USBH_REQTYPE_DIR_IN 0x80
#define USBH_REQTYPE_DIR_OUT 0x00
#define USBH_REQTYPE_IN 0x80 #define USBH_REQTYPE_TYPE_STANDARD 0x00
#define USBH_REQTYPE_OUT 0x00 #define USBH_REQTYPE_TYPE_CLASS 0x20
#define USBH_REQTYPE_TYPE_VENDOR 0x40
#define USBH_REQTYPE_STANDARD 0x00 #define USBH_REQTYPE_RECIP_DEVICE 0x00
#define USBH_REQTYPE_CLASS 0x20 #define USBH_REQTYPE_RECIP_INTERFACE 0x01
#define USBH_REQTYPE_VENDOR 0x40 #define USBH_REQTYPE_RECIP_ENDPOINT 0x02
#define USBH_REQTYPE_RECIP_OTHER 0x03
#define USBH_REQTYPE_DEVICE 0x00
#define USBH_REQTYPE_INTERFACE 0x01
#define USBH_REQTYPE_ENDPOINT 0x02
#define USBH_REQTYPE_OTHER 0x03
#endif #endif

View File

@ -106,7 +106,7 @@ static inline usbh_urbstatus_t usbhhubControlRequest(USBHDriver *host,
static inline usbh_urbstatus_t usbhhubClearFeaturePort(usbh_port_t *port, uint8_t feature) { static inline usbh_urbstatus_t usbhhubClearFeaturePort(usbh_port_t *port, uint8_t feature) {
return usbhhubControlRequest(port->device.host, return usbhhubControlRequest(port->device.host,
USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_OTHER, USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
USBH_REQ_CLEAR_FEATURE, USBH_REQ_CLEAR_FEATURE,
feature, feature,
port->number, port->number,
@ -116,7 +116,7 @@ static inline usbh_urbstatus_t usbhhubClearFeaturePort(usbh_port_t *port, uint8_
static inline usbh_urbstatus_t usbhhubClearFeatureHub(USBHDriver *host, uint8_t feature) { static inline usbh_urbstatus_t usbhhubClearFeatureHub(USBHDriver *host, uint8_t feature) {
return usbhhubControlRequest(host, return usbhhubControlRequest(host,
USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_DEVICE, USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE,
USBH_REQ_CLEAR_FEATURE, USBH_REQ_CLEAR_FEATURE,
feature, feature,
0, 0,
@ -126,7 +126,7 @@ static inline usbh_urbstatus_t usbhhubClearFeatureHub(USBHDriver *host, uint8_t
static inline usbh_urbstatus_t usbhhubSetFeaturePort(usbh_port_t *port, uint8_t feature) { static inline usbh_urbstatus_t usbhhubSetFeaturePort(usbh_port_t *port, uint8_t feature) {
return usbhhubControlRequest(port->device.host, return usbhhubControlRequest(port->device.host,
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_REQ_SET_FEATURE,
feature, feature,
port->number, port->number,

View File

@ -55,29 +55,17 @@ bool _usbh_urb_abortI(usbh_urb_t *urb, usbh_urbstatus_t status);
void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status); void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status);
#define USBH_CLASSIN(type, req, value, index) \ #define USBH_REQTYPE_CLASSIN(type) \
(USBH_REQTYPE_IN | type | USBH_REQTYPE_CLASS), \ (USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_CLASS)
req, \
value, \
index
#define USBH_CLASSOUT(type, req, value, index) \ #define USBH_REQTYPE_CLASSOUT(type) \
(USBH_REQTYPE_OUT | type | USBH_REQTYPE_CLASS), \ (USBH_REQTYPE_DIR_OUT | type | USBH_REQTYPE_TYPE_CLASS)
req, \
value, \
index
#define USBH_STANDARDIN(type, req, value, index) \ #define USBH_REQTYPE_STANDARDIN(type) \
(USBH_REQTYPE_IN | type | USBH_REQTYPE_STANDARD), \ (USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_STANDARD)
req, \
value, \
index
#define USBH_STANDARDOUT(type, req, value, index) \ #define USBH_REQTYPE_STANDARDOUT(type) \
(USBH_REQTYPE_OUT | type | USBH_REQTYPE_STANDARD), \ (USBH_REQTYPE_DIR_OUT | type | USBH_REQTYPE_TYPE_STANDARD)
req, \
value, \
index
#define USBH_PID_DATA0 0 #define USBH_PID_DATA0 0
@ -88,19 +76,19 @@ void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status);
/* GetBusState and SetHubDescriptor are optional, omitted */ /* GetBusState and SetHubDescriptor are optional, omitted */
#define ClearHubFeature (((USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_DEVICE) << 8) \ #define ClearHubFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
| USBH_REQ_CLEAR_FEATURE) | USBH_REQ_CLEAR_FEATURE)
#define SetHubFeature (((USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_DEVICE) << 8) \ #define SetHubFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
| USBH_REQ_SET_FEATURE) | USBH_REQ_SET_FEATURE)
#define ClearPortFeature (((USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_OTHER) << 8) \ #define ClearPortFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
| USBH_REQ_CLEAR_FEATURE) | USBH_REQ_CLEAR_FEATURE)
#define SetPortFeature (((USBH_REQTYPE_OUT | USBH_REQTYPE_CLASS | USBH_REQTYPE_OTHER) << 8) \ #define SetPortFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
| USBH_REQ_SET_FEATURE) | USBH_REQ_SET_FEATURE)
#define GetHubDescriptor (((USBH_REQTYPE_IN | USBH_REQTYPE_CLASS | USBH_REQTYPE_DEVICE) << 8) \ #define GetHubDescriptor (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
| USBH_REQ_GET_DESCRIPTOR) | USBH_REQ_GET_DESCRIPTOR)
#define GetHubStatus (((USBH_REQTYPE_IN | USBH_REQTYPE_CLASS | USBH_REQTYPE_DEVICE) << 8) \ #define GetHubStatus (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
| USBH_REQ_GET_STATUS) | USBH_REQ_GET_STATUS)
#define GetPortStatus (((USBH_REQTYPE_IN | USBH_REQTYPE_CLASS | USBH_REQTYPE_OTHER) << 8) \ #define GetPortStatus (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
| USBH_REQ_GET_STATUS) | USBH_REQ_GET_STATUS)

View File

@ -201,8 +201,9 @@ bool usbhEPReset(usbh_ep_t *ep) {
osalDbgAssert(ep->type != USBH_EPTYPE_CTRL, "don't need to reset control endpoint"); osalDbgAssert(ep->type != USBH_EPTYPE_CTRL, "don't need to reset control endpoint");
usbh_urbstatus_t ret = usbhControlRequest(ep->device, usbh_urbstatus_t ret = usbhControlRequest(ep->device,
USBH_STANDARDOUT(USBH_REQTYPE_ENDPOINT, USBH_REQ_CLEAR_FEATURE, 0, ep->address | (ep->in ? 0x80 : 0x00)), USBH_REQTYPE_STANDARDOUT(USBH_REQTYPE_RECIP_ENDPOINT),
0, 0); USBH_REQ_CLEAR_FEATURE,
0, ep->address | (ep->in ? 0x80 : 0x00), 0, 0);
/* TODO: GET_STATUS to see if endpoint is still halted */ /* TODO: GET_STATUS to see if endpoint is still halted */
osalSysLock(); osalSysLock();
@ -460,27 +461,19 @@ usbh_urbstatus_t usbhControlRequest(usbh_device_t *dev,
/* Standard request helpers. */ /* 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, bool usbhStdReqGetDeviceDescriptor(usbh_device_t *dev,
uint16_t wLength, uint16_t wLength,
uint8_t *buf) { uint8_t *buf) {
usbh_device_descriptor_t *desc; 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; desc = (usbh_device_descriptor_t *)buf;
if ((ret != USBH_URBSTATUS_OK) if ((ret != USBH_URBSTATUS_OK)
|| (desc->bLength != USBH_DT_DEVICE_SIZE) || (desc->bLength != USBH_DT_DEVICE_SIZE)
|| (desc->bDescriptorType != USBH_DT_DEVICE)) { || (desc->bDescriptorType != USBH_DT_DEVICE)) {
@ -493,8 +486,15 @@ bool usbhStdReqGetConfigurationDescriptor(usbh_device_t *dev,
uint8_t index, uint8_t index,
uint16_t wLength, uint16_t wLength,
uint8_t *buf) { 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; usbh_config_descriptor_t *const desc = (usbh_config_descriptor_t *)buf;
if ((ret != USBH_URBSTATUS_OK) if ((ret != USBH_URBSTATUS_OK)
|| (desc->bLength < USBH_DT_CONFIG_SIZE) || (desc->bLength < USBH_DT_CONFIG_SIZE)
|| (desc->bDescriptorType != USBH_DT_CONFIG)) { || (desc->bDescriptorType != USBH_DT_CONFIG)) {
@ -511,7 +511,13 @@ bool usbhStdReqGetStringDescriptor(usbh_device_t *dev,
osalDbgAssert(wLength >= USBH_DT_STRING_SIZE, "wrong size"); osalDbgAssert(wLength >= USBH_DT_STRING_SIZE, "wrong size");
usbh_string_descriptor_t *desc = (usbh_string_descriptor_t *)buf; 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) if ((ret != USBH_URBSTATUS_OK)
|| (desc->bLength < USBH_DT_STRING_SIZE) || (desc->bLength < USBH_DT_STRING_SIZE)
|| (desc->bDescriptorType != USBH_DT_STRING)) { || (desc->bDescriptorType != USBH_DT_STRING)) {
@ -520,25 +526,17 @@ bool usbhStdReqGetStringDescriptor(usbh_device_t *dev,
return HAL_SUCCESS; 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, bool usbhStdReqSetInterface(usbh_device_t *dev,
uint8_t bInterfaceNumber, uint8_t bInterfaceNumber,
uint8_t bAlternateSetting) { 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) if (ret != USBH_URBSTATUS_OK)
return HAL_FAILED; return HAL_FAILED;
@ -551,7 +549,13 @@ bool usbhStdReqGetInterface(usbh_device_t *dev,
USBH_DEFINE_BUFFER(uint8_t alt); 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) if (ret != USBH_URBSTATUS_OK)
return HAL_FAILED; 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) { static bool _device_setaddress(usbh_device_t *dev, uint8_t address) {
usbh_urbstatus_t ret = usbhControlRequest(dev, 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,
0); 0);
if (ret != USBH_URBSTATUS_OK) 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) { static bool _device_set_configuration(usbh_device_t *dev, uint8_t configuration) {
usbh_urbstatus_t ret = usbhControlRequest(dev, usbh_urbstatus_t ret = usbhControlRequest(dev,
USBH_SETDEVICECONFIGURATION(configuration), USBH_REQTYPE_STANDARDOUT(USBH_REQTYPE_RECIP_DEVICE),
0, USBH_REQ_SET_CONFIGURATION,
0); configuration,
0, 0, 0);
if (ret != USBH_URBSTATUS_OK) if (ret != USBH_URBSTATUS_OK)
return HAL_FAILED; return HAL_FAILED;
return HAL_SUCCESS; return HAL_SUCCESS;
@ -894,7 +889,7 @@ static void _port_reset(usbh_port_t *port) {
#if HAL_USBH_USE_HUB #if HAL_USBH_USE_HUB
port->hub, port->hub,
#endif #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_REQ_SET_FEATURE,
USBH_PORT_FEAT_RESET, USBH_PORT_FEAT_RESET,
port->number, port->number,
@ -908,7 +903,7 @@ static void _port_update_status(usbh_port_t *port) {
#if HAL_USBH_USE_HUB #if HAL_USBH_USE_HUB
port->hub, port->hub,
#endif #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, USBH_REQ_GET_STATUS,
0, 0,
port->number, port->number,

View File

@ -594,7 +594,7 @@ static bool _get_protocol(usbh_device_t *dev, uint16_t *protocol) {
USBH_DEFINE_BUFFER(uint16_t proto); USBH_DEFINE_BUFFER(uint16_t proto);
usbh_urbstatus_t ret = usbhControlRequest(dev, 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, AOA_ACCESSORY_GET_PROTOCOL,
0, 0,
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) { static bool _accessory_start(usbh_device_t *dev) {
usbh_urbstatus_t ret = usbhControlRequest(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, AOA_ACCESSORY_START,
0, 0,
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) { static bool _set_audio_mode(usbh_device_t *dev, uint16_t mode) {
usbh_urbstatus_t ret = usbhControlRequest(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_SET_AUDIO_MODE, AOA_SET_AUDIO_MODE,
mode, mode,
0, 0,
@ -645,7 +645,7 @@ static bool _send_string(usbh_device_t *dev, uint8_t index, const char *string)
string = nullstr; string = nullstr;
usbh_urbstatus_t ret = usbhControlRequest(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_SEND_STRING, AOA_ACCESSORY_SEND_STRING,
0, 0,
index, index,

View File

@ -316,11 +316,11 @@ static usbh_urbstatus_t _ftdi_port_control(USBHFTDIPortDriver *ftdipp,
uint8_t *buff) { uint8_t *buff) {
static const uint8_t bmRequestType[] = { static const uint8_t bmRequestType[] = {
USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //0 FTDI_COMMAND_RESET USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //0 FTDI_COMMAND_RESET
USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //1 FTDI_COMMAND_MODEMCTRL USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //1 FTDI_COMMAND_MODEMCTRL
USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //2 FTDI_COMMAND_SETFLOW USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_DEVICE, //2 FTDI_COMMAND_SETFLOW
USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE, //3 FTDI_COMMAND_SETBAUD USBH_REQTYPE_TYPE_VENDOR | USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_RECIP_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, //4 FTDI_COMMAND_SETDATA
}; };
osalDbgCheck(bRequest < sizeof_array(bmRequestType)); 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); wIndex = (wIndex << 8) | (ftdipp->ifnum + 1);
USBH_DEFINE_BUFFER(const usbh_control_request_t req) = { 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, FTDI_COMMAND_SETBAUD,
wValue, wValue,
wIndex, wIndex,

View File

@ -262,9 +262,8 @@ usbh_urbstatus_t usbhhidGetReport(USBHHIDDriver *hidp,
osalDbgCheck(hidp); osalDbgCheck(hidp);
osalDbgAssert((uint8_t)report_type <= USBHHID_REPORTTYPE_FEATURE, "wrong report type"); osalDbgAssert((uint8_t)report_type <= USBHHID_REPORTTYPE_FEATURE, "wrong report type");
return usbhControlRequest(hidp->dev, return usbhControlRequest(hidp->dev,
USBH_CLASSIN(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_GET_REPORT, USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_GET_REPORT,
((uint8_t)report_type << 8) | report_id, hidp->ifnum), ((uint8_t)report_type << 8) | report_id, hidp->ifnum, len, data);
len, data);
} }
usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp, usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp,
@ -273,38 +272,37 @@ usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp,
osalDbgCheck(hidp); osalDbgCheck(hidp);
osalDbgAssert((uint8_t)report_type <= USBHHID_REPORTTYPE_FEATURE, "wrong report type"); osalDbgAssert((uint8_t)report_type <= USBHHID_REPORTTYPE_FEATURE, "wrong report type");
return usbhControlRequest(hidp->dev, return usbhControlRequest(hidp->dev,
USBH_CLASSOUT(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_SET_REPORT, USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_SET_REPORT,
((uint8_t)report_type << 8) | report_id, hidp->ifnum), ((uint8_t)report_type << 8) | report_id, hidp->ifnum, len, (void *)data);
len, (void *)data);
} }
usbh_urbstatus_t usbhhidGetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t *duration) { usbh_urbstatus_t usbhhidGetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t *duration) {
osalDbgCheck(hidp); osalDbgCheck(hidp);
return usbhControlRequest(hidp->dev, return usbhControlRequest(hidp->dev,
USBH_CLASSIN(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_GET_IDLE, report_id, hidp->ifnum), USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_GET_IDLE,
1, duration); report_id, hidp->ifnum, 1, duration);
} }
usbh_urbstatus_t usbhhidSetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t duration) { usbh_urbstatus_t usbhhidSetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t duration) {
osalDbgCheck(hidp); osalDbgCheck(hidp);
return usbhControlRequest(hidp->dev, return usbhControlRequest(hidp->dev,
USBH_CLASSOUT(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_SET_IDLE, USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_SET_IDLE,
(duration << 8) | report_id, hidp->ifnum), 0, NULL); (duration << 8) | report_id, hidp->ifnum, 0, NULL);
} }
usbh_urbstatus_t usbhhidGetProtocol(USBHHIDDriver *hidp, uint8_t *protocol) { usbh_urbstatus_t usbhhidGetProtocol(USBHHIDDriver *hidp, uint8_t *protocol) {
osalDbgCheck(hidp); osalDbgCheck(hidp);
return usbhControlRequest(hidp->dev, return usbhControlRequest(hidp->dev,
USBH_CLASSIN(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_GET_PROTOCOL, 0, hidp->ifnum), USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_GET_PROTOCOL,
1, protocol); 0, hidp->ifnum, 1, protocol);
} }
usbh_urbstatus_t usbhhidSetProtocol(USBHHIDDriver *hidp, uint8_t protocol) { usbh_urbstatus_t usbhhidSetProtocol(USBHHIDDriver *hidp, uint8_t protocol) {
osalDbgCheck(hidp); osalDbgCheck(hidp);
osalDbgAssert(protocol <= 1, "invalid protocol"); osalDbgAssert(protocol <= 1, "invalid protocol");
return usbhControlRequest(hidp->dev, return usbhControlRequest(hidp->dev,
USBH_CLASSOUT(USBH_REQTYPE_INTERFACE, USBH_HID_REQ_SET_PROTOCOL, USBH_REQTYPE_CLASSOUT(USBH_REQTYPE_RECIP_INTERFACE), USBH_HID_REQ_SET_PROTOCOL,
protocol, hidp->ifnum), 0, NULL); protocol, hidp->ifnum, 0, NULL);
} }
void usbhhidObjectInit(USBHHIDDriver *hidp) { void usbhhidObjectInit(USBHHIDDriver *hidp) {

View File

@ -158,8 +158,8 @@ alloc_ok:
uinfo("Reading Max LUN:"); uinfo("Reading Max LUN:");
USBH_DEFINE_BUFFER(uint8_t buff[4]); USBH_DEFINE_BUFFER(uint8_t buff[4]);
stat = usbhControlRequest(dev, stat = usbhControlRequest(dev,
USBH_CLASSIN(USBH_REQTYPE_INTERFACE, MSD_GET_MAX_LUN, 0, msdp->ifnum), USBH_REQTYPE_CLASSIN(USBH_REQTYPE_RECIP_INTERFACE),
1, buff); MSD_GET_MAX_LUN, 0, msdp->ifnum, 1, buff);
if (stat == USBH_URBSTATUS_OK) { if (stat == USBH_URBSTATUS_OK) {
msdp->max_lun = buff[0] + 1; msdp->max_lun = buff[0] + 1;
uinfof("\tmax_lun = %d", msdp->max_lun); uinfof("\tmax_lun = %d", msdp->max_lun);
@ -290,7 +290,9 @@ typedef enum {
static bool _msd_bot_reset(USBHMassStorageDriver *msdp) { static bool _msd_bot_reset(USBHMassStorageDriver *msdp) {
usbh_urbstatus_t res; 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) { if (res != USBH_URBSTATUS_OK) {
return FALSE; return FALSE;
} }