mirror of https://github.com/ARMmbed/mbed-os.git
USBHost : fix indentation USBHost.cpp
parent
27877bd4e8
commit
41f12260b1
|
@ -46,7 +46,8 @@ USBHost * USBHost::instHost = NULL;
|
|||
* - when the usb_thread receives the event, it:
|
||||
* - call the callback attached to the endpoint where the td is attached
|
||||
*/
|
||||
void USBHost::usb_process() {
|
||||
void USBHost::usb_process()
|
||||
{
|
||||
|
||||
bool controlListState;
|
||||
bool bulkListState;
|
||||
|
@ -79,8 +80,7 @@ void USBHost::usb_process() {
|
|||
too_many_hub = false;
|
||||
buf[4] = 0;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Lock lock(this);
|
||||
|
||||
for (i = 0; i < MAX_DEVICE_CONNECTED; i++) {
|
||||
|
@ -104,10 +104,11 @@ void USBHost::usb_process() {
|
|||
controlEndpointAllocated = true;
|
||||
}
|
||||
|
||||
#if MAX_HUB_NB
|
||||
if (usb_msg->hub_parent)
|
||||
#if MAX_HUB_NB
|
||||
if (usb_msg->hub_parent) {
|
||||
devices[i].setHubParent((USBHostHub *)(usb_msg->hub_parent));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
for (j = 0; j < timeout_set_addr; j++) {
|
||||
|
||||
|
@ -154,7 +155,7 @@ void USBHost::usb_process() {
|
|||
|
||||
USB_INFO("New device connected: %p [hub: %d - port: %d]", &devices[i], usb_msg->hub, usb_msg->port);
|
||||
|
||||
#if MAX_HUB_NB
|
||||
#if MAX_HUB_NB
|
||||
if (buf[4] == HUB_CLASS) {
|
||||
for (k = 0; k < MAX_HUB_NB; k++) {
|
||||
if (hub_in_use[k] == false) {
|
||||
|
@ -165,10 +166,11 @@ void USBHost::usb_process() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (hub_in_use[k] == true)
|
||||
if (hub_in_use[k] == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (k == MAX_HUB_NB) {
|
||||
USB_ERR("Too many hubs connected!!\r\n");
|
||||
|
@ -176,9 +178,10 @@ void USBHost::usb_process() {
|
|||
}
|
||||
}
|
||||
|
||||
if (usb_msg->hub_parent)
|
||||
if (usb_msg->hub_parent) {
|
||||
((USBHostHub *)(usb_msg->hub_parent))->deviceConnected(&devices[i]);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((i < MAX_DEVICE_CONNECTED) && !too_many_hub) {
|
||||
deviceInUse[i] = true;
|
||||
|
@ -191,8 +194,7 @@ void USBHost::usb_process() {
|
|||
// a device has been disconnected
|
||||
case DEVICE_DISCONNECTED_EVENT:
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Lock lock(this);
|
||||
|
||||
controlListState = disableList(CONTROL_ENDPOINT);
|
||||
|
@ -204,9 +206,15 @@ void USBHost::usb_process() {
|
|||
freeDevice((USBDeviceConnected*)&devices[idx]);
|
||||
}
|
||||
|
||||
if (controlListState) enableList(CONTROL_ENDPOINT);
|
||||
if (bulkListState) enableList(BULK_ENDPOINT);
|
||||
if (interruptListState) enableList(INTERRUPT_ENDPOINT);
|
||||
if (controlListState) {
|
||||
enableList(CONTROL_ENDPOINT);
|
||||
}
|
||||
if (bulkListState) {
|
||||
enableList(BULK_ENDPOINT);
|
||||
}
|
||||
if (interruptListState) {
|
||||
enableList(INTERRUPT_ENDPOINT);
|
||||
}
|
||||
|
||||
} while(0);
|
||||
|
||||
|
@ -224,8 +232,9 @@ void USBHost::usb_process() {
|
|||
if (ep->getDir() == IN) {
|
||||
buf_transfer = ep->getBufStart();
|
||||
printf("READ SUCCESS [%d bytes transferred - td: 0x%08X] on ep: [%p - addr: %02X]: ", ep->getLengthTransferred(), usb_msg->td_addr, ep, ep->getAddress());
|
||||
for (int i = 0; i < ep->getLengthTransferred(); i++)
|
||||
for (int i = 0; i < ep->getLengthTransferred(); i++) {
|
||||
printf("%02X ", buf_transfer[i]);
|
||||
}
|
||||
printf("\r\n\r\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -266,9 +275,10 @@ USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK)
|
|||
devices[i].setAddress(i + 1);
|
||||
deviceReset[i] = false;
|
||||
deviceInited[i] = false;
|
||||
for (uint8_t j = 0; j < MAX_INTF; j++)
|
||||
for (uint8_t j = 0; j < MAX_INTF; j++) {
|
||||
deviceAttachedDriver[i][j] = false;
|
||||
}
|
||||
}
|
||||
|
||||
#if MAX_HUB_NB
|
||||
for (uint8_t i = 0; i < MAX_HUB_NB; i++) {
|
||||
|
@ -294,8 +304,9 @@ void USBHost::transferCompleted(volatile uint32_t addr)
|
|||
{
|
||||
uint8_t state;
|
||||
|
||||
if(addr == 0)
|
||||
if(addr == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
volatile HCTD* tdList = NULL;
|
||||
|
||||
|
@ -315,20 +326,23 @@ void USBHost::transferCompleted(volatile uint32_t addr)
|
|||
|
||||
#ifdef USBHOST_OTHER
|
||||
state = ((HCTD *)td)->state;
|
||||
if (state == USB_TYPE_IDLE)
|
||||
if (state == USB_TYPE_IDLE) {
|
||||
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
|
||||
}
|
||||
|
||||
#else
|
||||
if (((HCTD *)td)->control >> 28) {
|
||||
state = ((HCTD *)td)->control >> 28;
|
||||
} else {
|
||||
if (td->currBufPtr)
|
||||
if (td->currBufPtr) {
|
||||
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
|
||||
}
|
||||
state = 16 /*USB_TYPE_IDLE*/;
|
||||
}
|
||||
#endif
|
||||
if (state == USB_TYPE_IDLE)
|
||||
if (state == USB_TYPE_IDLE) {
|
||||
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
|
||||
}
|
||||
|
||||
ep->unqueueTransfer(td);
|
||||
|
||||
|
@ -365,9 +379,10 @@ USBHost * USBHost::getHostInst()
|
|||
// be sure that the new device connected is not already connected...
|
||||
int idx = findDevice(hub, port, hub_parent);
|
||||
if (idx != -1) {
|
||||
if (deviceInited[idx])
|
||||
if (deviceInited[idx]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
message_t * usb_msg = mail_usb_event.alloc();
|
||||
usb_msg->event_id = DEVICE_CONNECTED_EVENT;
|
||||
|
@ -387,8 +402,9 @@ USBHost * USBHost::getHostInst()
|
|||
// be sure that the device disconnected is connected...
|
||||
int idx = findDevice(hub, port, hub_parent);
|
||||
if (idx != -1) {
|
||||
if (!deviceInUse[idx])
|
||||
if (!deviceInUse[idx]) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -422,8 +438,9 @@ void USBHost::freeDevice(USBDeviceConnected * dev)
|
|||
}
|
||||
|
||||
// notify hub parent that this device has been disconnected
|
||||
if (dev->getHubParent())
|
||||
if (dev->getHubParent()) {
|
||||
dev->getHubParent()->deviceDisconnected(dev);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -667,8 +684,9 @@ int USBHost::findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent)
|
|||
for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) {
|
||||
if (devices[i].getHub() == hub && devices[i].getPort() == port) {
|
||||
if (hub_parent != NULL) {
|
||||
if (hub_parent == devices[i].getHubParent())
|
||||
if (hub_parent == devices[i].getHubParent()) {
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
|
@ -774,8 +792,9 @@ USB_TYPE USBHost::getDeviceDescriptor(USBDeviceConnected * dev, uint8_t * buf, u
|
|||
GET_DESCRIPTOR,
|
||||
(DEVICE_DESCRIPTOR << 8) | (0),
|
||||
0, buf, MIN(DEVICE_DESCRIPTOR_LENGTH, max_len_buf));
|
||||
if (len_dev_descr)
|
||||
if (len_dev_descr) {
|
||||
*len_dev_descr = MIN(DEVICE_DESCRIPTOR_LENGTH, max_len_buf);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
@ -799,8 +818,9 @@ USB_TYPE USBHost::getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t *
|
|||
total_conf_descr_length = buf[2] | (buf[3] << 8);
|
||||
total_conf_descr_length = MIN(max_len_buf, total_conf_descr_length);
|
||||
|
||||
if (len_conf_descr)
|
||||
if (len_conf_descr) {
|
||||
*len_conf_descr = total_conf_descr_length;
|
||||
}
|
||||
|
||||
USB_DBG("TOTAL_LENGTH: %d \t NUM_INTERF: %d", total_conf_descr_length, buf[4]);
|
||||
|
||||
|
@ -812,7 +832,8 @@ USB_TYPE USBHost::getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t *
|
|||
}
|
||||
|
||||
|
||||
USB_TYPE USBHost::setAddress(USBDeviceConnected * dev, uint8_t address) {
|
||||
USB_TYPE USBHost::setAddress(USBDeviceConnected * dev, uint8_t address)
|
||||
{
|
||||
return controlWrite( dev,
|
||||
USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE,
|
||||
SET_ADDRESS,
|
||||
|
@ -830,15 +851,18 @@ USB_TYPE USBHost::setConfiguration(USBDeviceConnected * dev, uint8_t conf)
|
|||
0, NULL, 0);
|
||||
}
|
||||
|
||||
uint8_t USBHost::numberDriverAttached(USBDeviceConnected * dev) {
|
||||
uint8_t USBHost::numberDriverAttached(USBDeviceConnected * dev)
|
||||
{
|
||||
int index = findDevice(dev);
|
||||
uint8_t cnt = 0;
|
||||
if (index == -1)
|
||||
if (index == -1) {
|
||||
return 0;
|
||||
}
|
||||
for (uint8_t i = 0; i < MAX_INTF; i++) {
|
||||
if (deviceAttachedDriver[index][i])
|
||||
if (deviceAttachedDriver[index][i]) {
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
@ -848,8 +872,7 @@ USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerato
|
|||
uint16_t total_conf_descr_length = 0;
|
||||
USB_TYPE res;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Lock lock(this);
|
||||
|
||||
// don't enumerate a device which all interfaces are registered to a specific driver
|
||||
|
@ -891,12 +914,13 @@ USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerato
|
|||
return res;
|
||||
}
|
||||
|
||||
#if (DEBUG > 3)
|
||||
#if (DEBUG > 3)
|
||||
USB_DBG("CONFIGURATION DESCRIPTOR:\r\n");
|
||||
for (int i = 0; i < total_conf_descr_length; i++)
|
||||
for (int i = 0; i < total_conf_descr_length; i++) {
|
||||
printf("%02X ", data[i]);
|
||||
}
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Parse the configuration descriptor
|
||||
parseConfDescr(dev, data, total_conf_descr_length, pEnumerator);
|
||||
|
@ -1016,7 +1040,8 @@ USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint
|
|||
return generalTransfer(dev, ep, buf, len, blocking, INTERRUPT_ENDPOINT, false);
|
||||
}
|
||||
|
||||
USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking, ENDPOINT_TYPE type, bool write) {
|
||||
USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking, ENDPOINT_TYPE type, bool write)
|
||||
{
|
||||
|
||||
#if DEBUG_TRANSFER
|
||||
const char * type_str = (type == BULK_ENDPOINT) ? "BULK" : ((type == INTERRUPT_ENDPOINT) ? "INTERRUPT" : "ISOCHRONOUS");
|
||||
|
@ -1056,8 +1081,9 @@ USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, ui
|
|||
#if DEBUG_TRANSFER
|
||||
if (write) {
|
||||
USB_DBG_TRANSFER("%s WRITE buffer", type_str);
|
||||
for (int i = 0; i < ep->getLengthTransferred(); i++)
|
||||
for (int i = 0; i < ep->getLengthTransferred(); i++) {
|
||||
printf("%02X ", buf[i]);
|
||||
}
|
||||
printf("\r\n\r\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -1082,11 +1108,13 @@ USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, ui
|
|||
}
|
||||
|
||||
|
||||
USB_TYPE USBHost::controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) {
|
||||
USB_TYPE USBHost::controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len)
|
||||
{
|
||||
return controlTransfer(dev, requestType, request, value, index, buf, len, false);
|
||||
}
|
||||
|
||||
USB_TYPE USBHost::controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) {
|
||||
USB_TYPE USBHost::controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len)
|
||||
{
|
||||
return controlTransfer(dev, requestType, request, value, index, buf, len, true);
|
||||
}
|
||||
|
||||
|
@ -1112,15 +1140,18 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
|
|||
|
||||
#if DEBUG_TRANSFER
|
||||
USB_DBG_TRANSFER("SETUP PACKET: ");
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
printf("%01X ", setupPacket[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
#endif
|
||||
|
||||
control->setNextToken(TD_SETUP);
|
||||
res = addTransfer(control, (uint8_t*)setupPacket, 8);
|
||||
|
||||
if (res == USB_TYPE_PROCESSING) control->ep_queue.get();
|
||||
if (res == USB_TYPE_PROCESSING) {
|
||||
control->ep_queue.get();
|
||||
}
|
||||
res = control->getState();
|
||||
|
||||
USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString());
|
||||
|
@ -1134,20 +1165,24 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
|
|||
control->setNextToken(token);
|
||||
res = addTransfer(control, (uint8_t *)buf, length_transfer);
|
||||
|
||||
if (res == USB_TYPE_PROCESSING) control->ep_queue.get();
|
||||
if (res == USB_TYPE_PROCESSING) {
|
||||
control->ep_queue.get();
|
||||
}
|
||||
res = control->getState();
|
||||
|
||||
#if DEBUG_TRANSFER
|
||||
USB_DBG_TRANSFER("CONTROL %s stage %s", (write) ? "WRITE" : "READ", control->getStateString());
|
||||
if (write) {
|
||||
USB_DBG_TRANSFER("CONTROL WRITE buffer");
|
||||
for (int i = 0; i < control->getLengthTransferred(); i++)
|
||||
for (int i = 0; i < control->getLengthTransferred(); i++) {
|
||||
printf("%02X ", buf[i]);
|
||||
}
|
||||
printf("\r\n\r\n");
|
||||
} else {
|
||||
USB_DBG_TRANSFER("CONTROL READ SUCCESS [%d bytes transferred]", control->getLengthTransferred());
|
||||
for (int i = 0; i < control->getLengthTransferred(); i++)
|
||||
for (int i = 0; i < control->getLengthTransferred(); i++) {
|
||||
printf("%02X ", buf[i]);
|
||||
}
|
||||
printf("\r\n\r\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -1161,13 +1196,16 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
|
|||
control->setNextToken(token);
|
||||
res = addTransfer(control, NULL, 0);
|
||||
|
||||
if (res == USB_TYPE_PROCESSING) control->ep_queue.get();
|
||||
if (res == USB_TYPE_PROCESSING) {
|
||||
control->ep_queue.get();
|
||||
}
|
||||
res = control->getState();
|
||||
|
||||
USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString());
|
||||
|
||||
if (res != USB_TYPE_IDLE)
|
||||
if (res != USB_TYPE_IDLE) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return USB_TYPE_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue