Browse Source

Trim hud driver memory usage

main
PaulStoffregen 7 years ago
parent
commit
05582c91a0
2 changed files with 32 additions and 36 deletions
  1. +8
    -8
      USBHost.h
  2. +24
    -28
      hub.cpp

+ 8
- 8
USBHost.h View File

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 othertimer;
USBDriverTimer mytimers[MAXPORTS];
uint32_t debounce_in_use;
setup_t setup[MAXPORTS+1];
uint32_t statusbits[MAXPORTS+1];
//USBDriverTimer mytimer;
USBDriverTimer resettimer;
setup_t setup;
Pipe_t *changepipe;
uint32_t changebits;
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;
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;
uint32_t changebits;
portbitmask_t debounce_in_use;
uint8_t portstate[MAXPORTS]; uint8_t portstate[MAXPORTS];
}; };



+ 24
- 28
hub.cpp View File

#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);
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.pointer = (void *)"This is mytimer";
//mytimer.init(this);
//mytimer.pointer = (void *)"This is mytimer";
//mytimer.start(99129); //mytimer.start(99129);
othertimer.pointer = (void *)"Hello, I'm othertimer";
//othertimer.start(12345);
resettimer.pointer = (void *)"Hello, I'm resettimer";
//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;
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));
queue_Control_Transfer(dev, &setup[0], hub_desc, this);
mk_setup(setup, 0xA0, 6, 0x2900, 0, sizeof(hub_desc));
queue_Control_Transfer(dev, &setup, hub_desc, this);


return true; return true;
} }
{ {
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);
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 3, 8, port, 0);
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);
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);
queue_Control_Transfer(device, &setup[port], &statusbits[port], this);
mk_setup(setup, ((port > 0) ? 0xA3 : 0xA0), 0, 0, port, 4);
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);
{ {
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
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 1, 16, port, 0); // 16=C_PORT_CONNECTION
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);
{ {
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
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 1, 17, port, 0); // 17=C_PORT_ENABLE
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);
{ {
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
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 1, 18, port, 0); // 18=C_PORT_SUSPEND
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);
{ {
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
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 1, 19, port, 0); // 19=C_PORT_OVER_CURRENT
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);
{ {
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
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 1, 20, port, 0); // 20=C_PORT_RESET
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);
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
queue_Control_Transfer(device, &setup[port], NULL, this);
mk_setup(setup, 0x23, 3, 4, port, 0); // set feature PORT_RESET
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);
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…
Cancel
Save