mirror of
https://github.com/gdsports/USBHost_t36
synced 2024-11-27 19:42:15 -05:00
Minor device driver API simplifications
This commit is contained in:
parent
a6352852ed
commit
ce2fafd18c
25
USBHost.h
25
USBHost.h
@ -191,27 +191,31 @@ protected:
|
|||||||
// device has its vid&pid, class/subclass fields initialized
|
// device has its vid&pid, class/subclass fields initialized
|
||||||
// type is 0 for device level, 1 for interface level, 2 for IAD
|
// type is 0 for device level, 1 for interface level, 2 for IAD
|
||||||
// descriptors points to the specific descriptor data
|
// descriptors points to the specific descriptor data
|
||||||
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors) {
|
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// When an unknown (not chapter 9) control transfer completes, this
|
// When an unknown (not chapter 9) control transfer completes, this
|
||||||
// function is called for all drivers bound to the device. Return
|
// function is called for all drivers bound to the device. Return
|
||||||
// true means this driver originated this control transfer, so no
|
// true means this driver originated this control transfer, so no
|
||||||
// more drivers need to be offered an opportunity to process it.
|
// more drivers need to be offered an opportunity to process it.
|
||||||
virtual bool control(const Transfer_t *transfer) {
|
// This function is optional, only needed if the driver uses control
|
||||||
return false;
|
// transfers and wishes to be notified when they complete.
|
||||||
}
|
virtual void control(const Transfer_t *transfer) { }
|
||||||
|
|
||||||
// When a device disconnects from the USB, this function is called.
|
// When a device disconnects from the USB, this function is called.
|
||||||
// The driver must free all resources it has allocated.
|
// The driver must free all resources it has allocated.
|
||||||
virtual void disconnect() {
|
virtual void disconnect();
|
||||||
}
|
|
||||||
// Drivers are managed by this single-linked list. All inactive
|
// Drivers are managed by this single-linked list. All inactive
|
||||||
// (not bound to any device) drivers are linked from
|
// (not bound to any device) drivers are linked from
|
||||||
// available_drivers in enumeration.cpp. When bound to a device,
|
// available_drivers in enumeration.cpp. When bound to a device,
|
||||||
// drivers are linked from that Device_t drivers list.
|
// drivers are linked from that Device_t drivers list.
|
||||||
USBDriver *next;
|
USBDriver *next;
|
||||||
// When not bound to any device, this must be NULL.
|
|
||||||
|
// The device this object instance is bound to. In words, this
|
||||||
|
// is the specific device this driver is using. When not bound
|
||||||
|
// to any device, this must be NULL.
|
||||||
Device_t *device;
|
Device_t *device;
|
||||||
|
|
||||||
friend class USBHost;
|
friend class USBHost;
|
||||||
public:
|
public:
|
||||||
// TODO: user-level functions
|
// TODO: user-level functions
|
||||||
@ -230,7 +234,8 @@ public:
|
|||||||
USBHub();
|
USBHub();
|
||||||
protected:
|
protected:
|
||||||
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors);
|
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors);
|
||||||
virtual bool control(const Transfer_t *transfer);
|
virtual void control(const Transfer_t *transfer);
|
||||||
|
virtual void disconnect();
|
||||||
void poweron(uint32_t port);
|
void poweron(uint32_t port);
|
||||||
void getstatus(uint32_t port);
|
void getstatus(uint32_t port);
|
||||||
void clearstatus(uint32_t port);
|
void clearstatus(uint32_t port);
|
||||||
|
14
hub.cpp
14
hub.cpp
@ -107,14 +107,13 @@ void USBHub::clearstatus(uint32_t port)
|
|||||||
queue_Control_Transfer(device, &setup, NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool USBHub::control(const Transfer_t *transfer)
|
void USBHub::control(const Transfer_t *transfer)
|
||||||
{
|
{
|
||||||
Serial.println("USBHub control callback");
|
Serial.println("USBHub control callback");
|
||||||
print_hexbytes(transfer->buffer, transfer->length);
|
print_hexbytes(transfer->buffer, transfer->length);
|
||||||
|
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
// read hub descriptor to learn hub's capabilities
|
// read hub descriptor to learn hub's capabilities
|
||||||
if (transfer->buffer != hub_desc) return false;
|
|
||||||
// Hub Descriptor, USB 2.0, 11.23.2.1 page 417
|
// Hub Descriptor, USB 2.0, 11.23.2.1 page 417
|
||||||
if (hub_desc[0] == 9 && hub_desc[1] == 0x29) {
|
if (hub_desc[0] == 9 && hub_desc[1] == 0x29) {
|
||||||
numports = hub_desc[2];
|
numports = hub_desc[2];
|
||||||
@ -147,12 +146,12 @@ bool USBHub::control(const Transfer_t *transfer)
|
|||||||
case 0x000000A0: // get hub status
|
case 0x000000A0: // get hub status
|
||||||
Serial.println("New Hub Status");
|
Serial.println("New Hub Status");
|
||||||
clearstatus(0);
|
clearstatus(0);
|
||||||
return true;
|
return;
|
||||||
case 0x000000A3: // get port status
|
case 0x000000A3: // get port status
|
||||||
Serial.print("New Port Status, port=");
|
Serial.print("New Port Status, port=");
|
||||||
Serial.println(setup.wIndex);
|
Serial.println(setup.wIndex);
|
||||||
clearstatus(setup.wIndex);
|
clearstatus(setup.wIndex);
|
||||||
return true;
|
return;
|
||||||
case 0x00100120: // clear hub status
|
case 0x00100120: // clear hub status
|
||||||
Serial.println("Hub Status Cleared");
|
Serial.println("Hub Status Cleared");
|
||||||
changebits &= ~1;
|
changebits &= ~1;
|
||||||
@ -165,7 +164,6 @@ bool USBHub::control(const Transfer_t *transfer)
|
|||||||
}
|
}
|
||||||
update_status();
|
update_status();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHub::callback(const Transfer_t *transfer)
|
void USBHub::callback(const Transfer_t *transfer)
|
||||||
@ -196,6 +194,12 @@ void USBHub::update_status()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USBHub::disconnect()
|
||||||
|
{
|
||||||
|
// TODO: free resources
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
config descriptor from a Multi-TT hub
|
config descriptor from a Multi-TT hub
|
||||||
09 02 29 00 01 01 00 E0 32
|
09 02 29 00 01 01 00 E0 32
|
||||||
|
Loading…
Reference in New Issue
Block a user