mirror of https://github.com/ARMmbed/mbed-os.git
usbhost: USBHost::fileControlBuf() handle alignment and endianness
Based on great feedback from Martin Kojtal on my previous commit, I
have modified my USBHost::fileControlBuf() change to be more portable.
ddb3fbe826 (commitcomment-3988044)
The code now fills in the setupPacket byte array a byte at a time,
using bit shifts to extract lower and upper bytes from the 16-bit
values so that the code should work on big endian or little endian
machines. I also removed the 2-byte alignment attribute from the
setupPacket array as it is no longer required.
pull/67/head
parent
c0d7c3fb39
commit
2056ad025e
|
@ -1153,14 +1153,12 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
|
||||||
|
|
||||||
void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len)
|
void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len)
|
||||||
{
|
{
|
||||||
#ifdef __BIG_ENDIAN
|
|
||||||
#error "Must implement BE to LE conv here"
|
|
||||||
#endif
|
|
||||||
setupPacket[0] = requestType;
|
setupPacket[0] = requestType;
|
||||||
setupPacket[1] = request;
|
setupPacket[1] = request;
|
||||||
//We are in LE so it's fine
|
setupPacket[2] = (uint8_t) value;
|
||||||
uint16_t* setupPacketHalfWords = (uint16_t*)setupPacket;
|
setupPacket[3] = (uint8_t) (value >> 8);
|
||||||
setupPacketHalfWords[1] = value;
|
setupPacket[4] = (uint8_t) index;
|
||||||
setupPacketHalfWords[2] = index;
|
setupPacket[5] = (uint8_t) (index >> 8);
|
||||||
setupPacketHalfWords[3] = (uint32_t) len;
|
setupPacket[6] = (uint8_t) len;
|
||||||
|
setupPacket[7] = (uint8_t) (len >> 8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// to store a setup packet
|
// to store a setup packet
|
||||||
__attribute__((aligned(2))) uint8_t setupPacket[8];
|
uint8_t setupPacket[8];
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t event_id;
|
uint8_t event_id;
|
||||||
|
|
Loading…
Reference in New Issue