mirror of
https://github.com/gdsports/USBHost_t36
synced 2025-01-08 20:28:37 -05:00
Trim hud driver memory usage
This commit is contained in:
parent
ba0e6f495b
commit
05582c91a0
16
USBHost.h
16
USBHost.h
@ -341,13 +341,14 @@ protected:
|
|||||||
void new_port_status(uint32_t port, uint32_t status);
|
void new_port_status(uint32_t port, uint32_t status);
|
||||||
void start_debounce_timer(uint32_t port);
|
void start_debounce_timer(uint32_t port);
|
||||||
void stop_debounce_timer(uint32_t port);
|
void stop_debounce_timer(uint32_t port);
|
||||||
|
|
||||||
USBDriverTimer debouncetimer;
|
USBDriverTimer debouncetimer;
|
||||||
USBDriverTimer mytimer;
|
//USBDriverTimer mytimer;
|
||||||
USBDriverTimer othertimer;
|
USBDriverTimer resettimer;
|
||||||
USBDriverTimer mytimers[MAXPORTS];
|
setup_t setup;
|
||||||
uint32_t debounce_in_use;
|
Pipe_t *changepipe;
|
||||||
setup_t setup[MAXPORTS+1];
|
uint32_t changebits;
|
||||||
uint32_t statusbits[MAXPORTS+1];
|
uint32_t statusbits;
|
||||||
uint8_t hub_desc[16];
|
uint8_t hub_desc[16];
|
||||||
uint8_t endpoint;
|
uint8_t endpoint;
|
||||||
uint8_t interval;
|
uint8_t interval;
|
||||||
@ -363,8 +364,7 @@ protected:
|
|||||||
portbitmask_t send_pending_clearstatus_overcurrent;
|
portbitmask_t send_pending_clearstatus_overcurrent;
|
||||||
portbitmask_t send_pending_clearstatus_reset;
|
portbitmask_t send_pending_clearstatus_reset;
|
||||||
portbitmask_t send_pending_setreset;
|
portbitmask_t send_pending_setreset;
|
||||||
Pipe_t *changepipe;
|
portbitmask_t debounce_in_use;
|
||||||
uint32_t changebits;
|
|
||||||
uint8_t portstate[MAXPORTS];
|
uint8_t portstate[MAXPORTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
52
hub.cpp
52
hub.cpp
@ -24,7 +24,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "USBHost.h"
|
#include "USBHost.h"
|
||||||
|
|
||||||
USBHub::USBHub() : debouncetimer(this), /* mytimer(this), */ othertimer(this)
|
USBHub::USBHub() : debouncetimer(this), /* mytimer(this), */ resettimer(this)
|
||||||
{
|
{
|
||||||
// TODO: free Device_t, Pipe_t & Transfer_t we will need
|
// TODO: free Device_t, Pipe_t & Transfer_t we will need
|
||||||
driver_ready_for_device(this);
|
driver_ready_for_device(this);
|
||||||
@ -39,16 +39,12 @@ bool USBHub::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t
|
|||||||
println("USBHub claim_device this=", (uint32_t)this, HEX);
|
println("USBHub claim_device this=", (uint32_t)this, HEX);
|
||||||
|
|
||||||
// timer testing TODO: remove this later
|
// timer testing TODO: remove this later
|
||||||
mytimer.init(this);
|
//mytimer.init(this);
|
||||||
mytimer.pointer = (void *)"This is mytimer";
|
//mytimer.pointer = (void *)"This is mytimer";
|
||||||
//mytimer.start(99129);
|
//mytimer.start(99129);
|
||||||
othertimer.pointer = (void *)"Hello, I'm othertimer";
|
resettimer.pointer = (void *)"Hello, I'm resettimer";
|
||||||
//othertimer.start(12345);
|
//resettimer.start(12345);
|
||||||
debouncetimer.pointer = (void *)"Debounce Timer";
|
debouncetimer.pointer = (void *)"Debounce Timer";
|
||||||
for (int i=0; i < 7; i++) {
|
|
||||||
mytimers[i].init(this);
|
|
||||||
//mytimers[i].start((i + 1) * 10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for HUB type
|
// check for HUB type
|
||||||
if (dev->bDeviceClass != 9 || dev->bDeviceSubClass != 0) return false;
|
if (dev->bDeviceClass != 9 || dev->bDeviceSubClass != 0) return false;
|
||||||
@ -87,8 +83,8 @@ bool USBHub::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t
|
|||||||
sending_control_transfer = 0;
|
sending_control_transfer = 0;
|
||||||
memset(portstate, 0, sizeof(portstate));
|
memset(portstate, 0, sizeof(portstate));
|
||||||
|
|
||||||
mk_setup(setup[0], 0xA0, 6, 0x2900, 0, sizeof(hub_desc));
|
mk_setup(setup, 0xA0, 6, 0x2900, 0, sizeof(hub_desc));
|
||||||
queue_Control_Transfer(dev, &setup[0], hub_desc, this);
|
queue_Control_Transfer(dev, &setup, hub_desc, this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -105,8 +101,8 @@ void USBHub::send_poweron(uint32_t port)
|
|||||||
{
|
{
|
||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 3, 8, port, 0);
|
mk_setup(setup, 0x23, 3, 8, port, 0);
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_poweron &= ~(1 << port);
|
send_pending_poweron &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_poweron |= (1 << port);
|
send_pending_poweron |= (1 << port);
|
||||||
@ -118,8 +114,8 @@ void USBHub::send_getstatus(uint32_t port)
|
|||||||
if (port > numports) return;
|
if (port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
println("getstatus, port = ", port);
|
println("getstatus, port = ", port);
|
||||||
mk_setup(setup[port], ((port > 0) ? 0xA3 : 0xA0), 0, 0, port, 4);
|
mk_setup(setup, ((port > 0) ? 0xA3 : 0xA0), 0, 0, port, 4);
|
||||||
queue_Control_Transfer(device, &setup[port], &statusbits[port], this);
|
queue_Control_Transfer(device, &setup, &statusbits, this);
|
||||||
send_pending_getstatus &= ~(1 << port);
|
send_pending_getstatus &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_getstatus |= (1 << port);
|
send_pending_getstatus |= (1 << port);
|
||||||
@ -130,8 +126,8 @@ void USBHub::send_clearstatus_connect(uint32_t port)
|
|||||||
{
|
{
|
||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 1, 16, port, 0); // 16=C_PORT_CONNECTION
|
mk_setup(setup, 0x23, 1, 16, port, 0); // 16=C_PORT_CONNECTION
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_clearstatus_connect &= ~(1 << port);
|
send_pending_clearstatus_connect &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_clearstatus_connect |= (1 << port);
|
send_pending_clearstatus_connect |= (1 << port);
|
||||||
@ -142,8 +138,8 @@ void USBHub::send_clearstatus_enable(uint32_t port)
|
|||||||
{
|
{
|
||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 1, 17, port, 0); // 17=C_PORT_ENABLE
|
mk_setup(setup, 0x23, 1, 17, port, 0); // 17=C_PORT_ENABLE
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_clearstatus_enable &= ~(1 << port);
|
send_pending_clearstatus_enable &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_clearstatus_enable |= (1 << port);
|
send_pending_clearstatus_enable |= (1 << port);
|
||||||
@ -154,8 +150,8 @@ void USBHub::send_clearstatus_suspend(uint32_t port)
|
|||||||
{
|
{
|
||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 1, 18, port, 0); // 18=C_PORT_SUSPEND
|
mk_setup(setup, 0x23, 1, 18, port, 0); // 18=C_PORT_SUSPEND
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_clearstatus_suspend &= ~(1 << port);
|
send_pending_clearstatus_suspend &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_clearstatus_suspend |= (1 << port);
|
send_pending_clearstatus_suspend |= (1 << port);
|
||||||
@ -166,8 +162,8 @@ void USBHub::send_clearstatus_overcurrent(uint32_t port)
|
|||||||
{
|
{
|
||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 1, 19, port, 0); // 19=C_PORT_OVER_CURRENT
|
mk_setup(setup, 0x23, 1, 19, port, 0); // 19=C_PORT_OVER_CURRENT
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_clearstatus_overcurrent &= ~(1 << port);
|
send_pending_clearstatus_overcurrent &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_clearstatus_overcurrent |= (1 << port);
|
send_pending_clearstatus_overcurrent |= (1 << port);
|
||||||
@ -178,8 +174,8 @@ void USBHub::send_clearstatus_reset(uint32_t port)
|
|||||||
{
|
{
|
||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 1, 20, port, 0); // 20=C_PORT_RESET
|
mk_setup(setup, 0x23, 1, 20, port, 0); // 20=C_PORT_RESET
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_clearstatus_reset &= ~(1 << port);
|
send_pending_clearstatus_reset &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_clearstatus_reset |= (1 << port);
|
send_pending_clearstatus_reset |= (1 << port);
|
||||||
@ -191,8 +187,8 @@ void USBHub::send_setreset(uint32_t port)
|
|||||||
if (port == 0 || port > numports) return;
|
if (port == 0 || port > numports) return;
|
||||||
println("send_setreset");
|
println("send_setreset");
|
||||||
if (can_send_control_now()) {
|
if (can_send_control_now()) {
|
||||||
mk_setup(setup[port], 0x23, 3, 4, port, 0); // set feature PORT_RESET
|
mk_setup(setup, 0x23, 3, 4, port, 0); // set feature PORT_RESET
|
||||||
queue_Control_Transfer(device, &setup[port], NULL, this);
|
queue_Control_Transfer(device, &setup, NULL, this);
|
||||||
send_pending_setreset &= ~(1 << port);
|
send_pending_setreset &= ~(1 << port);
|
||||||
} else {
|
} else {
|
||||||
send_pending_setreset |= (1 << port);
|
send_pending_setreset |= (1 << port);
|
||||||
@ -242,7 +238,7 @@ void USBHub::control(const Transfer_t *transfer)
|
|||||||
println("New Port Status");
|
println("New Port Status");
|
||||||
if (transfer->length == 4) {
|
if (transfer->length == 4) {
|
||||||
uint32_t status = *(uint32_t *)(transfer->buffer);
|
uint32_t status = *(uint32_t *)(transfer->buffer);
|
||||||
if (status != statusbits[port]) println("ERROR: status not same");
|
if (status != statusbits) println("ERROR: status not same");
|
||||||
new_port_status(port, status);
|
new_port_status(port, status);
|
||||||
}
|
}
|
||||||
//if (changebits & (1 << port)) {
|
//if (changebits & (1 << port)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user