diff --git a/atusb/fw/board.h b/atusb/fw/board.h index 9f16e5a..09ec915 100644 --- a/atusb/fw/board.h +++ b/atusb/fw/board.h @@ -73,6 +73,7 @@ #define HAS_BOARD_SERNUM extern uint8_t board_sernum[42]; +extern uint8_t irq_serial; void reset_rf(void); diff --git a/atusb/fw/board_app.c b/atusb/fw/board_app.c index 80eed69..22b93c3 100644 --- a/atusb/fw/board_app.c +++ b/atusb/fw/board_app.c @@ -150,13 +150,15 @@ static void done(void *user) } +uint8_t irq_serial; + + ISR(INT0_vect) { - static uint8_t buf; - if (eps[1].state == EP_IDLE) { led(1); - usb_send(&eps[1], &buf, 1, done, NULL); + irq_serial++; + usb_send(&eps[1], &irq_serial, 1, done, NULL); } } diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c index 83ab075..c1be341 100644 --- a/atusb/fw/ep0.c +++ b/atusb/fw/ep0.c @@ -217,6 +217,16 @@ static int my_setup(const struct setup_request *setup) else do_buf_write(NULL); return 1; + case ATUSB_FROM_DEV(ATUSB_SPI_WRITE2_SYNC): + spi_begin(); + spi_send(setup->wValue); + spi_send(setup->wIndex); + spi_end(); + buf[0] = irq_serial; + if (setup->wLength) + usb_send(&eps[0], buf, 1, NULL, NULL); + return 1; + case ATUSB_FROM_DEV(ATUSB_SPI_READ1): case ATUSB_FROM_DEV(ATUSB_SPI_READ2): spi_begin(); diff --git a/atusb/fw/include/atusb/ep0.h b/atusb/fw/include/atusb/ep0.h index 391b114..55bc222 100644 --- a/atusb/fw/include/atusb/ep0.h +++ b/atusb/fw/include/atusb/ep0.h @@ -39,6 +39,7 @@ * host-> ATUSB_SPI_WRITE byte0 byte1 #bytes * ->host ATUSB_SPI_READ1 byte0 - #bytes * ->host ATUSB_SPI_READ2 byte0 byte1 #bytes + * ->host ATUSB_SPI_WRITE2_SYNC byte0 bute1 0/1 */ /* @@ -91,6 +92,7 @@ enum atspi_requests { ATUSB_SPI_WRITE = 0x30, /* SPI group */ ATUSB_SPI_READ1, ATUSB_SPI_READ2, + ATUSB_SPI_WRITE2_SYNC, };