mirror of
https://github.com/gdsports/USBHost_t36
synced 2024-11-24 18:12:16 -05:00
Add driver claiming at the device level
This commit is contained in:
parent
dc87eeaaf6
commit
eb807023db
12
USBHost.h
12
USBHost.h
@ -71,6 +71,8 @@ struct Device_struct {
|
|||||||
uint8_t bDeviceClass;
|
uint8_t bDeviceClass;
|
||||||
uint8_t bDeviceSubClass;
|
uint8_t bDeviceSubClass;
|
||||||
uint8_t bDeviceProtocol;
|
uint8_t bDeviceProtocol;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint8_t bMaxPower;
|
||||||
uint16_t idVendor;
|
uint16_t idVendor;
|
||||||
uint16_t idProduct;
|
uint16_t idProduct;
|
||||||
uint16_t LanguageID;
|
uint16_t LanguageID;
|
||||||
@ -139,6 +141,7 @@ protected:
|
|||||||
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);
|
||||||
private:
|
private:
|
||||||
static void isr();
|
static void isr();
|
||||||
static void init_Device_Pipe_Transfer_memory(void);
|
static void init_Device_Pipe_Transfer_memory(void);
|
||||||
@ -165,10 +168,10 @@ protected:
|
|||||||
|
|
||||||
class USBHostDriver : public USBHost {
|
class USBHostDriver : public USBHost {
|
||||||
public:
|
public:
|
||||||
virtual bool claim_device(Device_t *device) {
|
virtual bool claim_device(Device_t *device, const uint8_t *descriptors) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
virtual bool claim_interface(Device_t *device) {
|
virtual bool claim_interface(Device_t *device, const uint8_t *descriptors) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
virtual void disconnect() {
|
virtual void disconnect() {
|
||||||
@ -178,8 +181,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class USBHub : public USBHostDriver {
|
class USBHub : public USBHostDriver {
|
||||||
|
public:
|
||||||
|
USBHub(); // { driver_ready_for_device(this); }
|
||||||
|
virtual bool claim_device(Device_t *device, const uint8_t *descriptors);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
1
ehci.cpp
1
ehci.cpp
@ -38,7 +38,6 @@ static Transfer_t *periodic_followup_first=NULL;
|
|||||||
static Transfer_t *periodic_followup_last=NULL;
|
static Transfer_t *periodic_followup_last=NULL;
|
||||||
|
|
||||||
|
|
||||||
static void isr();
|
|
||||||
static void init_qTD(volatile Transfer_t *t, void *buf, uint32_t len,
|
static void init_qTD(volatile Transfer_t *t, void *buf, uint32_t len,
|
||||||
uint32_t pid, uint32_t data01, bool irq);
|
uint32_t pid, uint32_t data01, bool irq);
|
||||||
static bool followup_Transfer(Transfer_t *transfer);
|
static bool followup_Transfer(Transfer_t *transfer);
|
||||||
|
@ -25,16 +25,32 @@
|
|||||||
#include "USBHost.h"
|
#include "USBHost.h"
|
||||||
|
|
||||||
|
|
||||||
|
static USBHostDriver *available_drivers = NULL;
|
||||||
static uint8_t enumbuf[256] __attribute__ ((aligned(16)));
|
static uint8_t enumbuf[256] __attribute__ ((aligned(16)));
|
||||||
|
|
||||||
|
|
||||||
static void mk_setup(setup_t &s, uint32_t bmRequestType, uint32_t bRequest,
|
static void mk_setup(setup_t &s, uint32_t bmRequestType, uint32_t bRequest,
|
||||||
uint32_t wValue, uint32_t wIndex, uint32_t wLength);
|
uint32_t wValue, uint32_t wIndex, uint32_t wLength);
|
||||||
|
static void claim_drivers(Device_t *dev);
|
||||||
static uint32_t assign_addr(void);
|
static uint32_t assign_addr(void);
|
||||||
static void pipe_set_maxlen(Pipe_t *pipe, uint32_t maxlen);
|
static void pipe_set_maxlen(Pipe_t *pipe, uint32_t maxlen);
|
||||||
static void pipe_set_addr(Pipe_t *pipe, uint32_t addr);
|
static void pipe_set_addr(Pipe_t *pipe, uint32_t addr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void USBHost::driver_ready_for_device(USBHostDriver *driver)
|
||||||
|
{
|
||||||
|
driver->next = NULL;
|
||||||
|
if (available_drivers == NULL) {
|
||||||
|
available_drivers = driver;
|
||||||
|
} else {
|
||||||
|
// append to end of list
|
||||||
|
USBHostDriver *last = available_drivers;
|
||||||
|
while (last->next) last = last->next;
|
||||||
|
last->next = driver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new device and begin the enumeration process
|
// Create a new device and begin the enumeration process
|
||||||
//
|
//
|
||||||
Device_t * USBHost::new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port)
|
Device_t * USBHost::new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_port)
|
||||||
@ -63,6 +79,9 @@ Device_t * USBHost::new_Device(uint32_t speed, uint32_t hub_addr, uint32_t hub_p
|
|||||||
}
|
}
|
||||||
dev->control_pipe->callback_function = &enumeration;
|
dev->control_pipe->callback_function = &enumeration;
|
||||||
dev->control_pipe->direction = 1; // 1=IN
|
dev->control_pipe->direction = 1; // 1=IN
|
||||||
|
// TODO: exclusive access to enumeration process
|
||||||
|
// any new devices detected while enumerating would
|
||||||
|
// go onto a waiting list
|
||||||
mk_setup(dev->setup, 0x80, 6, 0x0100, 0, 8); // 6=GET_DESCRIPTOR
|
mk_setup(dev->setup, 0x80, 6, 0x0100, 0, 8); // 6=GET_DESCRIPTOR
|
||||||
new_Transfer(dev->control_pipe, enumbuf, 8);
|
new_Transfer(dev->control_pipe, enumbuf, 8);
|
||||||
|
|
||||||
@ -193,8 +212,10 @@ void USBHost::enumeration(const Transfer_t *transfer)
|
|||||||
dev->enum_state = 14;
|
dev->enum_state = 14;
|
||||||
return;
|
return;
|
||||||
case 14: // device is now configured
|
case 14: // device is now configured
|
||||||
// TODO: initialize drivers??
|
claim_drivers(dev);
|
||||||
dev->enum_state = 15;
|
dev->enum_state = 15;
|
||||||
|
// TODO: unlock exclusive access to enumeration process
|
||||||
|
// if any detected devices are waiting, start the first
|
||||||
return;
|
return;
|
||||||
case 15: // control transfers for other stuff??
|
case 15: // control transfers for other stuff??
|
||||||
default:
|
default:
|
||||||
@ -203,6 +224,27 @@ void USBHost::enumeration(const Transfer_t *transfer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void claim_drivers(Device_t *dev)
|
||||||
|
{
|
||||||
|
USBHostDriver *driver, *prev=NULL;
|
||||||
|
|
||||||
|
// first check if any driver wishes to claim the entire device
|
||||||
|
for (driver=available_drivers; driver != NULL; driver = driver->next) {
|
||||||
|
if (driver->claim_device(dev, enumbuf + 9)) {
|
||||||
|
if (prev) {
|
||||||
|
prev->next = driver->next;
|
||||||
|
} else {
|
||||||
|
available_drivers = driver->next;
|
||||||
|
}
|
||||||
|
driver->next = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
prev = driver;
|
||||||
|
}
|
||||||
|
// TODO: parse interfaces from config descriptor
|
||||||
|
// try claim_interface on drivers
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t assign_addr(void)
|
static uint32_t assign_addr(void)
|
||||||
{
|
{
|
||||||
return 29; // TODO: when multiple devices, assign a unique address
|
return 29; // TODO: when multiple devices, assign a unique address
|
||||||
|
53
hub.cpp
Normal file
53
hub.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* USB EHCI Host for Teensy 3.6
|
||||||
|
* Copyright 2017 Paul Stoffregen (paul@pjrc.com)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "USBHost.h"
|
||||||
|
|
||||||
|
USBHub::USBHub()
|
||||||
|
{
|
||||||
|
// TODO: free Device_t, Pipe_t & Transfer_t we will need
|
||||||
|
driver_ready_for_device(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool USBHub::claim_device(Device_t *dev, const uint8_t *descriptors)
|
||||||
|
{
|
||||||
|
Serial.print("USBHub claim_device this=");
|
||||||
|
Serial.println((uint32_t)this, HEX);
|
||||||
|
|
||||||
|
if (dev->bDeviceClass != 9 || dev->bDeviceSubClass != 0) return false;
|
||||||
|
|
||||||
|
// bDeviceProtocol = 0 is full speed
|
||||||
|
// bDeviceProtocol = 1 is high speed single TT
|
||||||
|
// bDeviceProtocol = 2 is high speed multiple TT
|
||||||
|
|
||||||
|
Serial.print("bDeviceClass = ");
|
||||||
|
Serial.println(dev->bDeviceClass);
|
||||||
|
Serial.print("bDeviceSubClass = ");
|
||||||
|
Serial.println(dev->bDeviceSubClass);
|
||||||
|
Serial.print("bDeviceProtocol = ");
|
||||||
|
Serial.println(dev->bDeviceProtocol);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,9 @@
|
|||||||
#include "USBHost.h"
|
#include "USBHost.h"
|
||||||
|
|
||||||
USBHost myusb;
|
USBHost myusb;
|
||||||
|
USBHub hub1;
|
||||||
|
USBHub hub2;
|
||||||
|
USBHub hub3;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
@ -141,14 +141,12 @@ void USBHost::print_hexbytes(const void *ptr, uint32_t len)
|
|||||||
void USBHost::print(const char *s)
|
void USBHost::print(const char *s)
|
||||||
{
|
{
|
||||||
Serial.println(s);
|
Serial.println(s);
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHost::print(const char *s, int num)
|
void USBHost::print(const char *s, int num)
|
||||||
{
|
{
|
||||||
Serial.print(s);
|
Serial.print(s);
|
||||||
Serial.println(num);
|
Serial.println(num);
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user