1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-22 13:54:59 +02:00

atusb/fw/: new mechanism for SPI commands (more general than reg/buf requests)

- ep0.c (setup_request): store combined request code in "req", for
  later reuse
- include/ep0.h (ATUSB_SPI_WRITE, ATUSB_SPI_READ1, ATUSB_SPI_READ2),
  ep0.c (setup_request): new requests that translate easily into
  general SPI operations
This commit is contained in:
Werner Almesberger 2011-06-19 15:37:40 -03:00
parent 13f031be25
commit 9a0184cacb
2 changed files with 33 additions and 1 deletions

View File

@ -58,11 +58,12 @@ static void do_buf_write(void *user)
static int my_setup(const struct setup_request *setup) static int my_setup(const struct setup_request *setup)
{ {
uint16_t req = setup->bmRequestType | setup->bRequest << 8;
unsigned tmp; unsigned tmp;
uint8_t i; uint8_t i;
uint64_t tmp64; uint64_t tmp64;
switch (setup->bmRequestType | setup->bRequest << 8) { switch (req) {
case ATUSB_FROM_DEV(ATUSB_ID): case ATUSB_FROM_DEV(ATUSB_ID):
debug("ATUSB_ID\n"); debug("ATUSB_ID\n");
if (setup->wLength > 3) if (setup->wLength > 3)
@ -201,6 +202,30 @@ static int my_setup(const struct setup_request *setup)
usb_send(&eps[0], buf, setup->wLength, NULL, NULL); usb_send(&eps[0], buf, setup->wLength, NULL, NULL);
return 1; return 1;
case ATUSB_TO_DEV(ATUSB_SPI_WRITE):
size = setup->wLength+2;
if (size > sizeof(buf))
return 0;
buf[0] = setup->wValue;
buf[1] = setup->wIndex;
if (setup->wLength)
usb_recv(&eps[0], buf+2, setup->wLength,
do_buf_write, NULL);
else
do_buf_write(NULL);
return 1;
case ATUSB_FROM_DEV(ATUSB_SPI_READ1):
case ATUSB_FROM_DEV(ATUSB_SPI_READ2):
spi_begin();
spi_send(setup->wValue);
if (req == ATUSB_SPI_READ2)
spi_send(setup->wIndex);
for (i = 0; i != setup->wLength; i++)
buf[i] = spi_recv();
spi_end();
usb_send(&eps[0], buf, setup->wLength, NULL, NULL);
return 1;
default: default:
error("Unrecognized SETUP: 0x%02x 0x%02x ...\n", error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
setup->bmRequestType, setup->bRequest); setup->bmRequestType, setup->bRequest);

View File

@ -34,6 +34,10 @@
* ->host ATUSB_BUF_READ - - #bytes * ->host ATUSB_BUF_READ - - #bytes
* host-> ATUSB_SRAM_WRITE - addr #bytes * host-> ATUSB_SRAM_WRITE - addr #bytes
* ->host ATUSB_SRAM_READ - addr #bytes * ->host ATUSB_SRAM_READ - addr #bytes
*
* host-> ATUSB_SPI_WRITE byte0 byte1 #bytes
* ->host ATUSB_SPI_READ1 byte0 - #bytes
* ->host ATUSB_SPI_READ2 byte0 byte1 #bytes
*/ */
/* /*
@ -82,6 +86,9 @@ enum atspi_requests {
ATUSB_BUF_READ, ATUSB_BUF_READ,
ATUSB_SRAM_WRITE, ATUSB_SRAM_WRITE,
ATUSB_SRAM_READ, ATUSB_SRAM_READ,
ATUSB_SPI_WRITE = 0x30, /* SPI group */
ATUSB_SPI_READ1,
ATUSB_SPI_READ2,
}; };