summaryrefslogtreecommitdiffstats
path: root/usb/endpt0.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2017-03-28 21:53:36 +0100
committerTomasz Kramkowski <tk@the-tk.com>2017-03-28 21:53:36 +0100
commit440cd59182a962b7f987d990db6d43a6026877ba (patch)
treec3efbbf25c69406b32ce04f8c504a6faf4062231 /usb/endpt0.c
parent003974902952dedc56e9060c4db4b2b1ff63f283 (diff)
downloadfmk-440cd59182a962b7f987d990db6d43a6026877ba.tar.gz
fmk-440cd59182a962b7f987d990db6d43a6026877ba.tar.xz
fmk-440cd59182a962b7f987d990db6d43a6026877ba.zip
hid mouse pointer jiggler
Diffstat (limited to 'usb/endpt0.c')
-rw-r--r--usb/endpt0.c59
1 files changed, 26 insertions, 33 deletions
diff --git a/usb/endpt0.c b/usb/endpt0.c
index 485e464..c4c3360 100644
--- a/usb/endpt0.c
+++ b/usb/endpt0.c
@@ -7,10 +7,9 @@
#include <reg/gpio.h>
-#include "../uart/uart.h"
-
#include "bdt.h"
#include "endpt0.h"
+#include "endpt1.h"
#include "descriptors.h"
@@ -21,7 +20,7 @@ static bool tx_data01;
static volatile unsigned int nextaddr;
-static const void *tx_data;
+static void *tx_data;
static size_t tx_size;
struct tok_setup {
@@ -49,12 +48,12 @@ static void read_setup(struct tok_setup *setup, const void *_data)
/* puttx: place data in the current buffer descriptor */
static bool puttx(void *data, size_t size)
{
- if (GET_BIT(BDT_ENDPT(0, BDT_TX, tx_odd).desc, BD_OWN))
+ if (GET_BIT(usb_bdt[0][BDT_TX][tx_odd].desc, BD_OWN))
return false;
/* TODO: Just stop bothering with const */
- BDT_ENDPT(0, BDT_TX, tx_odd).addr = data;
- BDT_ENDPT(0, BDT_TX, tx_odd).desc = USB0_BD_INIT(size, tx_data01);
+ usb_bdt[0][BDT_TX][tx_odd].addr = data;
+ usb_bdt[0][BDT_TX][tx_odd].desc = USB0_BD_INIT(size, tx_data01);
tx_odd = !tx_odd;
tx_data01 = !tx_data01;
@@ -102,17 +101,17 @@ void usb_endpt0_disable(void)
/* usb_endpt0_enable: Enable and reset endpoint 0 */
void usb_endpt0_enable(void)
{
- BDT_ENDPT(0, BDT_RX, BDT_EVEN).addr = buf[0];
- BDT_ENDPT(0, BDT_RX, BDT_EVEN).desc = USB0_BD_INIT(sizeof buf[0], 0);
+ usb_bdt[0][BDT_RX][BDT_EVEN].addr = buf[0];
+ usb_bdt[0][BDT_RX][BDT_EVEN].desc = USB0_BD_INIT(sizeof buf[0], 0);
- BDT_ENDPT(0, BDT_RX, BDT_ODD).addr = buf[1];
- BDT_ENDPT(0, BDT_RX, BDT_ODD).desc = USB0_BD_INIT(sizeof buf[1], 0);
+ usb_bdt[0][BDT_RX][BDT_ODD].addr = buf[1];
+ usb_bdt[0][BDT_RX][BDT_ODD].desc = USB0_BD_INIT(sizeof buf[1], 0);
- BDT_ENDPT(0, BDT_TX, BDT_EVEN).addr = NULL;
- BDT_ENDPT(0, BDT_TX, BDT_EVEN).desc = 0;
+ usb_bdt[0][BDT_TX][BDT_EVEN].addr = NULL;
+ usb_bdt[0][BDT_TX][BDT_EVEN].desc = 0;
- BDT_ENDPT(0, BDT_TX, BDT_ODD).addr = NULL;
- BDT_ENDPT(0, BDT_TX, BDT_ODD).desc = 0;
+ usb_bdt[0][BDT_TX][BDT_ODD].addr = NULL;
+ usb_bdt[0][BDT_TX][BDT_ODD].desc = 0;
USB0_ENDPT(0) = BV(ENDPT_EPRXEN) | BV(ENDPT_EPTXEN) | BV(ENDPT_EPHSHK);
nextaddr = 0;
@@ -134,39 +133,38 @@ static void tok_setup(struct tok_setup *setup)
{
switch (setup->reqtyp << 8 | setup->req) {
case 0x0005: /* SET ADDRESS */
- uart_printf(" SET ADDRESS (%u)\n", (unsigned)setup->value);
nextaddr = setup->value;
puttx(NULL, 0);
break;
case 0x0009: /* SET CONFIGURATION */
- uart_puts(" SET CONFIGURATION");
+ usb_endpt1_enable();
+ puttx(NULL, 0);
+ break;
+ case 0x210a: /* SET IDLE */
puttx(NULL, 0);
break;
+ case 0x8106: /* GET INTERFACE */
case 0x8006: /* GET DESCRIPTOR */
- uart_printf(" GET DESCRIPTOR (0x%x)", (unsigned)setup->value);
switch (setup->value) {
case 0x0100: /* DEVICE */
- uart_puts(" DEVICE");
quetx(ds_dev, trunc(ARRLEN(ds_dev), setup->length));
return;
case 0x0200: /* CONFIGURATION */
- uart_puts(" CONFIGURATION");
quetx(ds_conf, trunc(ARRLEN(ds_conf), setup->length));
return;
case 0x0300: /* STRING 0 */
- uart_puts(" STRING 0");
quetx(ds_lang, trunc(ARRLEN(ds_lang), setup->length));
return;
case 0x0301: /* STRING 1 */
- uart_puts(" STRING 1");
quetx(ds_str1, trunc(ARRLEN(ds_str1), setup->length));
return;
+ case 0x2200:
+ quetx(ds_hidrep, trunc(ARRLEN(ds_hidrep), setup->length));
+ return;
}
/* fall through */
default:
/* We received an unexpected SETUP so we STALL the endpoint */
- printf("Unexpected SETUP: RT: 0x%x R: 0x%x V: 0x%x\n",
- setup->reqtyp, setup->req, setup->value);
SET_BIT(USB0_ENDPT(0), ENDPT_EPSTALL);
break;
}
@@ -174,31 +172,27 @@ static void tok_setup(struct tok_setup *setup)
void usb_endpt0_token(uint8_t state)
{
- struct usb0_bd *bd;
+ volatile struct usb0_bd *bd;
struct tok_setup setup;
- bd = &BDT_ENDPT(0, GET_BIT(state, STAT_TX), GET_BIT(state, STAT_ODD));
+ bd = &usb_bdt[0][GET_BIT(state, STAT_TX)][GET_BIT(state, STAT_ODD)];
switch (GET_BITS(bd->desc, BD_TOK_PID)) {
case BD_TOK_PID_OUT:
- uart_puts(" PID_OUT");
bd->desc = USB0_BD_INIT(sizeof buf[0], 1);
break;
case BD_TOK_PID_IN:
- uart_puts(" PID_IN");
- uart_printf(" pushtx: %d\n", (int)pushtx());
if (nextaddr) {
USB0_ADDR = nextaddr;
nextaddr = 0;
}
break;
case BD_TOK_PID_SETUP:
- uart_puts(" PID_SETUP");
read_setup(&setup, bd->addr);
bd->desc = USB0_BD_INIT(sizeof buf[0], 1);
- BDT_ENDPT(0, BDT_TX, BDT_EVEN).desc = 0;
- BDT_ENDPT(0, BDT_TX, BDT_ODD).desc = 0;
+ usb_bdt[0][BDT_TX][BDT_EVEN].desc = 0;
+ usb_bdt[0][BDT_TX][BDT_ODD].desc = 0;
tx_data = NULL;
tx_data01 = 1;
@@ -206,8 +200,7 @@ void usb_endpt0_token(uint8_t state)
tok_setup(&setup);
/* SETUP sets CTL_TXSUSPENDTOKENBUSY to suspend TX */
- uart_printf("Clearing USB0_CTL, was: 0x%x", (unsigned)USB0_CTL);
- USB0_CTL = 0;
+ USB0_CTL = BV(CTL_USBENSOFEN);
break;
}