Ver código fonte

Minor device driver API simplifications

main
PaulStoffregen 8 anos atrás
pai
commit
ce2fafd18c
2 arquivos alterados com 24 adições e 15 exclusões
  1. +15
    -10
      USBHost.h
  2. +9
    -5
      hub.cpp

+ 15
- 10
USBHost.h Ver arquivo

// 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) {
return false;
}
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors);

// 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) {
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. // 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
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);

+ 9
- 5
hub.cpp Ver arquivo

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];
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;
} }
update_status(); update_status();
} }
return true;
} }


void USBHub::callback(const Transfer_t *transfer) void USBHub::callback(const Transfer_t *transfer)
} }
} }


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

Carregando…
Cancelar
Salvar