summaryrefslogtreecommitdiffstats
path: root/usb/endpt1.c
diff options
context:
space:
mode:
Diffstat (limited to 'usb/endpt1.c')
-rw-r--r--usb/endpt1.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/usb/endpt1.c b/usb/endpt1.c
index ca954fc..4358221 100644
--- a/usb/endpt1.c
+++ b/usb/endpt1.c
@@ -1,4 +1,5 @@
#include <reg/usbotg.h>
+#include <stddef.h>
#include <stdint.h>
#include "../uart/uart.h"
@@ -8,33 +9,45 @@
#define MAX_PACKET 64
-static unsigned char buf[2][MAX_PACKET];
+static unsigned char report[4][4] = {
+ { 0x00, 0x01, 0x00, 0x00, },
+ { 0x00, 0x00, 0x01, 0x00, },
+ { 0x00, 0xff, 0x00, 0x00, },
+ { 0x00, 0x00, 0xff, 0x00, },
+};
+static int nextrep;
void usb_endpt1_enable(void)
{
+ nextrep = 0;
+
+ usb_bdt[1][BDT_TX][BDT_EVEN].addr = &report[0];
+ usb_bdt[1][BDT_TX][BDT_EVEN].desc = USB0_BD_INIT(4, nextrep % 2);
+ nextrep++;
+
+ usb_bdt[1][BDT_TX][BDT_ODD].addr = &report[1];
+ usb_bdt[1][BDT_TX][BDT_ODD].desc = USB0_BD_INIT(4, nextrep % 2);
+ nextrep++;
+
+ USB0_ENDPT(1) = BV(ENDPT_EPTXEN) | BV(ENDPT_EPHSHK);
}
void usb_endpt1_disable(void)
{
+ USB0_ENDPT(1) = 0;
}
void usb_endpt1_token(uint8_t state)
{
- struct usb0_bd *bd;
+ volatile struct usb0_bd *bd;
- uart_puts(" endpt1 token");
-
- bd = &BDT_ENDPT(1, GET_BIT(state, STAT_TX), GET_BIT(state, STAT_ODD));
+ bd = &usb_bdt[1][GET_BIT(state, STAT_TX)][GET_BIT(state, STAT_ODD)];
switch (GET_BITS(bd->desc, BD_TOK_PID)) {
- case BD_TOK_PID_OUT:
- bd->desc = USB0_BD_INIT(sizeof buf[0], 1);
- /* should never happen */
- break;
case BD_TOK_PID_IN:
- /*pushtx();*/
+ bd->addr = &report[nextrep];
+ bd->desc = USB0_BD_INIT(4, nextrep % 2);
+ nextrep = (nextrep + 1) % 4;
break;
}
-
- /*USB0_CTL = BV(CTL_USBENSOFEN);*/
}