Parcourir la source

Minor device driver API simplifications

main
PaulStoffregen il y a 7 ans
Parent
révision
ce2fafd18c
2 fichiers modifiés avec 24 ajouts et 15 suppressions
  1. +15
    -10
      USBHost.h
  2. +9
    -5
      hub.cpp

+ 15
- 10
USBHost.h Voir le fichier

@@ -191,27 +191,31 @@ protected:
// device has its vid&pid, class/subclass fields initialized
// type is 0 for device level, 1 for interface level, 2 for IAD
// descriptors points to the specific descriptor data
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors) {
return false;
}
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors);

// When an unknown (not chapter 9) control transfer completes, this
// function is called for all drivers bound to the device. Return
// true means this driver originated this control transfer, so no
// more drivers need to be offered an opportunity to process it.
virtual bool control(const Transfer_t *transfer) {
return false;
}
// This function is optional, only needed if the driver uses control
// 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.
// 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
// (not bound to any device) drivers are linked from
// available_drivers in enumeration.cpp. When bound to a device,
// drivers are linked from that Device_t drivers list.
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;

friend class USBHost;
public:
// TODO: user-level functions
@@ -230,7 +234,8 @@ public:
USBHub();
protected:
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 getstatus(uint32_t port);
void clearstatus(uint32_t port);

+ 9
- 5
hub.cpp Voir le fichier

@@ -107,14 +107,13 @@ void USBHub::clearstatus(uint32_t port)
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");
print_hexbytes(transfer->buffer, transfer->length);

if (state == 0) {
// 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
if (hub_desc[0] == 9 && hub_desc[1] == 0x29) {
numports = hub_desc[2];
@@ -147,12 +146,12 @@ bool USBHub::control(const Transfer_t *transfer)
case 0x000000A0: // get hub status
Serial.println("New Hub Status");
clearstatus(0);
return true;
return;
case 0x000000A3: // get port status
Serial.print("New Port Status, port=");
Serial.println(setup.wIndex);
clearstatus(setup.wIndex);
return true;
return;
case 0x00100120: // clear hub status
Serial.println("Hub Status Cleared");
changebits &= ~1;
@@ -165,7 +164,6 @@ bool USBHub::control(const Transfer_t *transfer)
}
update_status();
}
return true;
}

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
09 02 29 00 01 01 00 E0 32

Chargement…
Annuler
Enregistrer