diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c index 95f112f..bb36ad8 100644 --- a/atusb/fw/ep0.c +++ b/atusb/fw/ep0.c @@ -58,11 +58,12 @@ static void do_buf_write(void *user) static int my_setup(const struct setup_request *setup) { + uint16_t req = setup->bmRequestType | setup->bRequest << 8; unsigned tmp; uint8_t i; uint64_t tmp64; - switch (setup->bmRequestType | setup->bRequest << 8) { + switch (req) { case ATUSB_FROM_DEV(ATUSB_ID): debug("ATUSB_ID\n"); 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); 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: error("Unrecognized SETUP: 0x%02x 0x%02x ...\n", setup->bmRequestType, setup->bRequest); diff --git a/atusb/fw/include/atusb/ep0.h b/atusb/fw/include/atusb/ep0.h index 00746e1..4775c3c 100644 --- a/atusb/fw/include/atusb/ep0.h +++ b/atusb/fw/include/atusb/ep0.h @@ -34,6 +34,10 @@ * ->host ATUSB_BUF_READ - - #bytes * host-> ATUSB_SRAM_WRITE - 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_SRAM_WRITE, ATUSB_SRAM_READ, + ATUSB_SPI_WRITE = 0x30, /* SPI group */ + ATUSB_SPI_READ1, + ATUSB_SPI_READ2, };