|
|
|
|
|
|
|
|
Serial.println(); |
|
|
Serial.println(); |
|
|
Serial.println("Ring Doorbell"); |
|
|
Serial.println("Ring Doorbell"); |
|
|
USBHS_USBCMD |= USBHS_USBCMD_IAA; |
|
|
USBHS_USBCMD |= USBHS_USBCMD_IAA; |
|
|
|
|
|
if (rootdev) print(rootdev->control_pipe); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void loop() |
|
|
void loop() |
|
|
|
|
|
|
|
|
Serial.println(" end recovery"); |
|
|
Serial.println(" end recovery"); |
|
|
|
|
|
|
|
|
// HCSPARAMS TTCTRL page 1671 |
|
|
// HCSPARAMS TTCTRL page 1671 |
|
|
rootdev = new_Device((USBHS_PORTSC1 >> 26) & 3, 0, 0); |
|
|
|
|
|
|
|
|
uint32_t speed = (USBHS_PORTSC1 >> 26) & 3; |
|
|
|
|
|
rootdev = new_Device(speed, 0, 0); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dev = allocate_Device(); |
|
|
dev = allocate_Device(); |
|
|
if (!dev) return NULL; |
|
|
if (!dev) return NULL; |
|
|
dev->speed = speed; |
|
|
dev->speed = speed; |
|
|
dev->address = 1; // TODO: dynamic assign address |
|
|
|
|
|
|
|
|
dev->address = 0; |
|
|
dev->hub_address = hub_addr; |
|
|
dev->hub_address = hub_addr; |
|
|
dev->hub_port = hub_port; |
|
|
dev->hub_port = hub_port; |
|
|
dev->control_pipe = new_Pipe(dev, 0, 0, 0, 8); |
|
|
dev->control_pipe = new_Pipe(dev, 0, 0, 0, 8); |
|
|
|
|
|
|
|
|
dev->setup.wIndex = 0x0000; |
|
|
dev->setup.wIndex = 0x0000; |
|
|
dev->setup.wLength = 0; |
|
|
dev->setup.wLength = 0; |
|
|
Transfer_t *transfer = new_Transfer(dev->control_pipe, buffer, 8); |
|
|
Transfer_t *transfer = new_Transfer(dev->control_pipe, buffer, 8); |
|
|
|
|
|
//print(dev->control_pipe); |
|
|
if (transfer) queue_Transfer(transfer); |
|
|
if (transfer) queue_Transfer(transfer); |
|
|
|
|
|
|
|
|
return dev; |
|
|
return dev; |
|
|
|
|
|
|
|
|
Serial.println("new_Pipe"); |
|
|
Serial.println("new_Pipe"); |
|
|
pipe = allocate_Pipe(); |
|
|
pipe = allocate_Pipe(); |
|
|
if (!pipe) return NULL; |
|
|
if (!pipe) return NULL; |
|
|
|
|
|
pipe->device = dev; |
|
|
pipe->qh.current = 0; |
|
|
pipe->qh.current = 0; |
|
|
pipe->qh.next = 1; |
|
|
pipe->qh.next = 1; |
|
|
pipe->qh.alt_next = 1; |
|
|
pipe->qh.alt_next = 1; |
|
|
|
|
|
|
|
|
transfer->qtd.next = (uint32_t)status; |
|
|
transfer->qtd.next = (uint32_t)status; |
|
|
status_direction = 1; // always IN, USB 2.0 page 226 |
|
|
status_direction = 1; // always IN, USB 2.0 page 226 |
|
|
} |
|
|
} |
|
|
init_qTD(transfer, &(pipe->device->setup), 8, 2, 0, false); |
|
|
|
|
|
|
|
|
Serial.print("setup address "); |
|
|
|
|
|
Serial.println((uint32_t)&pipe->device->setup, HEX); |
|
|
|
|
|
init_qTD(transfer, &pipe->device->setup, 8, 2, 0, false); |
|
|
init_qTD(status, NULL, 0, status_direction, 1, true); |
|
|
init_qTD(status, NULL, 0, status_direction, 1, true); |
|
|
status->pipe = pipe; |
|
|
status->pipe = pipe; |
|
|
status->qtd.next = 1; |
|
|
status->qtd.next = 1; |
|
|
|
|
|
|
|
|
void queue_Transfer(Transfer_t *transfer) |
|
|
void queue_Transfer(Transfer_t *transfer) |
|
|
{ |
|
|
{ |
|
|
Serial.println("queue_Transfer"); |
|
|
Serial.println("queue_Transfer"); |
|
|
volatile Pipe_t *pipe = transfer->pipe; |
|
|
|
|
|
|
|
|
Pipe_t *pipe = transfer->pipe; |
|
|
|
|
|
|
|
|
if (!pipe->active) { |
|
|
if (!pipe->active) { |
|
|
if (pipe->type == 0 || pipe->type == 2) { |
|
|
if (pipe->type == 0 || pipe->type == 2) { |
|
|
// control or bulk: add to async queue |
|
|
// control or bulk: add to async queue |
|
|
pipe->qh.next = (uint32_t)transfer; |
|
|
pipe->qh.next = (uint32_t)transfer; |
|
|
volatile Pipe_t *list = (Pipe_t *)USBHS_ASYNCLISTADDR; |
|
|
|
|
|
|
|
|
Pipe_t *list = (Pipe_t *)USBHS_ASYNCLISTADDR; |
|
|
if (list == NULL) { |
|
|
if (list == NULL) { |
|
|
Serial.println(" first in async list, with qTD"); |
|
|
Serial.println(" first in async list, with qTD"); |
|
|
pipe->qh.capabilities[0] |= 0x8000; // H bit |
|
|
pipe->qh.capabilities[0] |= 0x8000; // H bit |
|
|
pipe->qh.horizontal_link = (uint32_t)(&(pipe->qh)) | 2; // 2=QH |
|
|
pipe->qh.horizontal_link = (uint32_t)(&(pipe->qh)) | 2; // 2=QH |
|
|
USBHS_ASYNCLISTADDR = (uint32_t)pipe; |
|
|
USBHS_ASYNCLISTADDR = (uint32_t)pipe; |
|
|
|
|
|
print(pipe); |
|
|
Serial.println(USBHS_USBSTS & USBHS_USBSTS_AS, HEX); |
|
|
Serial.println(USBHS_USBSTS & USBHS_USBSTS_AS, HEX); |
|
|
Serial.println(USBHS_USBCMD & USBHS_USBCMD_ASE, HEX); |
|
|
Serial.println(USBHS_USBCMD & USBHS_USBCMD_ASE, HEX); |
|
|
//USBHS_USBCMD |= USBHS_USBCMD_IAA; |
|
|
//USBHS_USBCMD |= USBHS_USBCMD_IAA; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print(const Transfer_t *transfer) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!((uint32_t)transfer & 0xFFFFFFE0)) return; |
|
|
|
|
|
Serial.print("Transfer @ "); |
|
|
|
|
|
Serial.println(((uint32_t)transfer & 0xFFFFFFE0), HEX); |
|
|
|
|
|
Serial.print(" next: "); |
|
|
|
|
|
Serial.println(transfer->qtd.next, HEX); |
|
|
|
|
|
Serial.print(" anext: "); |
|
|
|
|
|
Serial.println(transfer->qtd.alt_next, HEX); |
|
|
|
|
|
Serial.print(" token: "); |
|
|
|
|
|
Serial.println(transfer->qtd.token, HEX); |
|
|
|
|
|
Serial.print(" bufs: "); |
|
|
|
|
|
for (int i=0; i < 5; i++) { |
|
|
|
|
|
Serial.print(transfer->qtd.buffer[i], HEX); |
|
|
|
|
|
if (i < 4) Serial.print(','); |
|
|
|
|
|
} |
|
|
|
|
|
Serial.println(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void print(const Pipe_t *pipe) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!((uint32_t)pipe & 0xFFFFFFE0)) return; |
|
|
|
|
|
Serial.print("Pipe "); |
|
|
|
|
|
if (pipe->type == 0) Serial.print("control"); |
|
|
|
|
|
else if (pipe->type == 1) Serial.print("isochronous"); |
|
|
|
|
|
else if (pipe->type == 2) Serial.print("bulk"); |
|
|
|
|
|
else if (pipe->type == 3) Serial.print("interrupt"); |
|
|
|
|
|
Serial.print(pipe->direction ? " IN" : " OUT"); |
|
|
|
|
|
Serial.print(" @ "); |
|
|
|
|
|
Serial.println((uint32_t)pipe, HEX); |
|
|
|
|
|
Serial.print(" horiz link: "); |
|
|
|
|
|
Serial.println(pipe->qh.horizontal_link, HEX); |
|
|
|
|
|
Serial.print(" capabilities: "); |
|
|
|
|
|
Serial.print(pipe->qh.capabilities[0], HEX); |
|
|
|
|
|
Serial.print(','); |
|
|
|
|
|
Serial.println(pipe->qh.capabilities[1], HEX); |
|
|
|
|
|
Serial.println(" overlay:"); |
|
|
|
|
|
Serial.print(" cur: "); |
|
|
|
|
|
Serial.println(pipe->qh.current, HEX); |
|
|
|
|
|
Serial.print(" next: "); |
|
|
|
|
|
Serial.println(pipe->qh.next, HEX); |
|
|
|
|
|
Serial.print(" anext: "); |
|
|
|
|
|
Serial.println(pipe->qh.alt_next, HEX); |
|
|
|
|
|
Serial.print(" token: "); |
|
|
|
|
|
Serial.println(pipe->qh.token, HEX); |
|
|
|
|
|
Serial.print(" bufs: "); |
|
|
|
|
|
for (int i=0; i < 5; i++) { |
|
|
|
|
|
Serial.print(pipe->qh.buffer[i], HEX); |
|
|
|
|
|
if (i < 4) Serial.print(','); |
|
|
|
|
|
} |
|
|
|
|
|
Serial.println(); |
|
|
|
|
|
const Transfer_t *t = (Transfer_t *)pipe->qh.next; |
|
|
|
|
|
while (((uint32_t)t & 0xFFFFFFE0)) { |
|
|
|
|
|
print(t); |
|
|
|
|
|
t = (Transfer_t *)t->qtd.next; |
|
|
|
|
|
} |
|
|
|
|
|
//Serial.print(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print(const char *s) |
|
|
void print(const char *s) |
|
|
{ |
|
|
{ |