|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
-
-
- #include <Arduino.h>
- #include "USBHost.h"
-
- USBHub::USBHub()
- {
-
- driver_ready_for_device(this);
- }
-
- bool USBHub::claim(Device_t *dev, int type, const uint8_t *descriptors)
- {
-
- if (type != 0) return false;
-
- Serial.print("USBHub claim_device this=");
- Serial.println((uint32_t)this, HEX);
-
-
- if (dev->bDeviceClass != 9 || dev->bDeviceSubClass != 0) return false;
-
- if (dev->bDeviceProtocol > 2) return false;
-
- if (descriptors[9] != 7 || descriptors[10] != 5) return false;
-
- if ((descriptors[11] & 0xF0) != 0x80) return false;
-
- if (descriptors[12] != 3) return false;
-
- endpoint = descriptors[11] & 0x0F;
- if (endpoint == 0) return false;
-
- uint32_t maxsize = descriptors[13] | (descriptors[14] << 8);
- if (maxsize == 0) return false;
- if (maxsize > 1) return false;
-
- Serial.println(descriptors[9]);
- Serial.println(descriptors[10]);
- Serial.println(descriptors[11], HEX);
- Serial.println(maxsize);
-
-
-
-
- Serial.print("bDeviceClass = ");
- Serial.println(dev->bDeviceClass);
- Serial.print("bDeviceSubClass = ");
- Serial.println(dev->bDeviceSubClass);
- Serial.print("bDeviceProtocol = ");
- Serial.println(dev->bDeviceProtocol);
-
- changepipe = NULL;
- changebits = 0;
- state = 0;
-
- mk_setup(setup, 0xA0, 6, 0x2900, 0, sizeof(hub_desc));
- queue_Control_Transfer(dev, &setup, hub_desc, this);
-
- return true;
- }
-
- void USBHub::poweron(uint32_t port)
- {
- mk_setup(setup, 0x23, 3, 8, port, 0);
- queue_Control_Transfer(device, &setup, NULL, this);
- }
-
- bool USBHub::control(const Transfer_t *transfer)
- {
- Serial.println("USBHub control callback");
- print_hexbytes(transfer->buffer, transfer->length);
-
- if (state == 0) {
-
- if (transfer->buffer != hub_desc) return false;
-
- if (hub_desc[0] == 9 && hub_desc[1] == 0x29) {
- numports = hub_desc[2];
- characteristics = hub_desc[3];
- powertime = hub_desc[5];
-
-
- Serial.print("Hub has ");
- Serial.print(numports);
- Serial.println(" ports");
- state = 1;
- poweron(1);
- }
- } else if (state < numports) {
-
- poweron(++state);
- } else if (state == numports) {
- Serial.println("power turned on to all ports");
-
- changepipe = new_Pipe(device, 3, endpoint, 1, 1);
- state = 255;
- } else if (state == 255) {
-
- }
- return true;
- }
-
-
-
-
-
|