Sfoglia il codice sorgente

Rename USB drivers base class

main
PaulStoffregen 7 anni fa
parent
commit
a45a462931
2 ha cambiato i file con 19 aggiunte e 14 eliminazioni
  1. +14
    -9
      USBHost.h
  2. +5
    -5
      enumeration.cpp

+ 14
- 9
USBHost.h Vedi File

/************************************************/ /************************************************/


class USBHost; class USBHost;
class USBHostDriver;
class USBDriver;
typedef struct Device_struct Device_t; typedef struct Device_struct Device_t;
typedef struct Pipe_struct Pipe_t; typedef struct Pipe_struct Pipe_t;
typedef struct Transfer_struct Transfer_t; typedef struct Transfer_struct Transfer_t;
Pipe_t *control_pipe; Pipe_t *control_pipe;
Device_t *next; Device_t *next;
setup_t setup; // TODO: move this to static in enumeration.cpp setup_t setup; // TODO: move this to static in enumeration.cpp
USBHostDriver *drivers;
USBDriver *drivers;
uint8_t speed; // 0=12, 1=1.5, 2=480 Mbit/sec uint8_t speed; // 0=12, 1=1.5, 2=480 Mbit/sec
uint8_t address; uint8_t address;
uint8_t hub_address; uint8_t hub_address;
static bool new_Transfer(Pipe_t *pipe, void *buffer, uint32_t len); static bool new_Transfer(Pipe_t *pipe, void *buffer, uint32_t len);
static Device_t * new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port); static Device_t * new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port);
static void enumeration(const Transfer_t *transfer); static void enumeration(const Transfer_t *transfer);
static void driver_ready_for_device(USBHostDriver *driver);
static void driver_ready_for_device(USBDriver *driver);
private: private:
static void isr(); static void isr();
static void claim_drivers(Device_t *dev); static void claim_drivers(Device_t *dev);
s.word1 = bmRequestType | (bRequest << 8) | (wValue << 16); s.word1 = bmRequestType | (bRequest << 8) | (wValue << 16);
s.word2 = wIndex | (wLength << 16); s.word2 = wIndex | (wLength << 16);
} }

}; };




/************************************************/ /************************************************/
/* USB Device Drivers */
/* USB Device Driver Common Base Class */
/************************************************/ /************************************************/


class USBHostDriver : public USBHost {
// All USB device drivers inherit from this base class.
class USBDriver : public USBHost {
protected: protected:
USBHostDriver() : next(NULL), device(NULL) {}
USBDriver() : next(NULL), device(NULL) {}
// Check if a driver wishes to claim a device or interface or group // Check if a driver wishes to claim a device or interface or group
// of interfaces within a device. When this function returns true, // of interfaces within a device. When this function returns true,
// the driver is considered bound or loaded for that device. When // the driver is considered bound or loaded for that device. When
// (not bound to any device) drivers are linked from // (not bound to any device) drivers are linked from
// available_drivers is enumeration.cpp. When bound to a device, // available_drivers is 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.
USBHostDriver *next;
USBDriver *next;
// When not bound to any device, this must be NULL. // When not bound to any device, this must be NULL.
Device_t *device; Device_t *device;
friend class USBHost; friend class USBHost;
// query string: manufacturer, product, serial number // query string: manufacturer, product, serial number
}; };


class USBHub : public USBHostDriver {

/************************************************/
/* USB Device Drivers */
/************************************************/

class USBHub : public USBDriver {
public: public:
USBHub(); USBHub();
protected: protected:

+ 5
- 5
enumeration.cpp Vedi File

#include "USBHost.h" #include "USBHost.h"




static USBHostDriver *available_drivers = NULL;
static USBDriver *available_drivers = NULL;
static uint8_t enumbuf[256] __attribute__ ((aligned(16))); static uint8_t enumbuf[256] __attribute__ ((aligned(16)));










void USBHost::driver_ready_for_device(USBHostDriver *driver)
void USBHost::driver_ready_for_device(USBDriver *driver)
{ {
driver->next = NULL; driver->next = NULL;
if (available_drivers == NULL) { if (available_drivers == NULL) {
available_drivers = driver; available_drivers = driver;
} else { } else {
// append to end of list // append to end of list
USBHostDriver *last = available_drivers;
USBDriver *last = available_drivers;
while (last->next) last = last->next; while (last->next) last = last->next;
last->next = driver; last->next = driver;
} }
return; return;
case 15: // control transfers for other stuff? case 15: // control transfers for other stuff?
// TODO: handle other standard control: set/clear feature, etc // TODO: handle other standard control: set/clear feature, etc
for (USBHostDriver *d = dev->drivers; d != NULL; d = d->next) {
for (USBDriver *d = dev->drivers; d != NULL; d = d->next) {
if (d->control(transfer)) { if (d->control(transfer)) {
// this driver processed the control transfer reply // this driver processed the control transfer reply
return; return;


void USBHost::claim_drivers(Device_t *dev) void USBHost::claim_drivers(Device_t *dev)
{ {
USBHostDriver *driver, *prev=NULL;
USBDriver *driver, *prev=NULL;


// first check if any driver wishes to claim the entire device // first check if any driver wishes to claim the entire device
for (driver=available_drivers; driver != NULL; driver = driver->next) { for (driver=available_drivers; driver != NULL; driver = driver->next) {

Loading…
Annulla
Salva