summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2015-06-07 02:35:01 +0100
committerroot <root@lamia.panaceas.james.local>2015-06-07 02:35:01 +0100
commitcdea4f5da56c6158beccc801f0a4efa045cf46cb (patch)
tree456a1677aff4cd0f08a9461d72659ec20b4e0c8b
parent7fa21387755e96ea0403ff4213af8a053811b81d (diff)
downloadtims_keyboard-cdea4f5da56c6158beccc801f0a4efa045cf46cb.tar.gz
tims_keyboard-cdea4f5da56c6158beccc801f0a4efa045cf46cb.tar.bz2
tims_keyboard-cdea4f5da56c6158beccc801f0a4efa045cf46cb.zip
tidy up makefiles and fix init delay
-rw-r--r--Makefile.rules1
-rw-r--r--app/Makefile2
-rw-r--r--app/atkbd.c31
-rw-r--r--app/keyboard.c3
-rw-r--r--app/project.h4
-rw-r--r--app/prototypes.h2
-rw-r--r--app/ticker.c2
-rw-r--r--app/tims_keyboard.c22
-rw-r--r--app/usb.c8
9 files changed, 58 insertions, 17 deletions
diff --git a/Makefile.rules b/Makefile.rules
index 3b92c42..a193f2c 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -257,4 +257,5 @@ $(LIB_DIR)/lib$(LIBNAME).a: $(OPENCM3_DIR)/build.stamp
$(OPENCM3_DIR)/build.stamp:
${MAKE} -C ${OPENCM3_DIR}
+ touch $@
diff --git a/app/Makefile b/app/Makefile
index 4761d45..7c378cf 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -32,7 +32,7 @@ OBJS = ${CSRCS:%.c=%.o}
include ../Makefile.include
-CFLAGS+=-Wno-redundant-decls -Wno-unused-parameter
+CFLAGS+=-Wno-redundant-decls -Wno-unused-parameter #-DDEBUG
DID=$(shell printf '\#include "id.h"\nID_PRODUCT' | ${CC} -I.. -E - | grep -v ^\# )
diff --git a/app/atkbd.c b/app/atkbd.c
index 9091636..1ba599a 100644
--- a/app/atkbd.c
+++ b/app/atkbd.c
@@ -67,6 +67,8 @@ typedef enum
+static int ready;
+static uint8_t saved_leds;
static int atkbd_ack;
static int atkbd_nack;
@@ -396,7 +398,14 @@ atkbd_request_echo (void)
int
atkbd_set_leds (uint8_t leds)
{
- uint32_t then = ticks;
+ uint32_t then;
+
+ saved_leds = leds;
+
+ if (!ready)
+ return 0;
+
+ then = ticks;
atkbd_ack = 0;
atkbd_send (ATKBD_CMD_SETLEDS);
while (!atkbd_ack)
@@ -462,10 +471,22 @@ atkbd_set_mbr (void)
void
+atkbd_start (void)
+{
+
+ atkbd_reset ();
+ atkbd_request_echo ();
+ atkbd_set_mbr ();
+ atkbd_set_scanset (2);
+ atkbd_set_leds (saved_leds);
+
+ ready++;
+}
+
+void
atkbd_init (void)
{
atkbd_set (1, 1);
- delay_ms (200);
nvic_enable_irq (NVIC_EXTI0_IRQ);
@@ -478,11 +499,5 @@ atkbd_init (void)
nvic_enable_irq (KBCLK_IRQ);
- atkbd_reset ();
- atkbd_request_echo ();
- atkbd_set_mbr ();
- atkbd_set_scanset (2);
- atkbd_set_leds (0);
-
}
diff --git a/app/keyboard.c b/app/keyboard.c
index cecbd58..d06f555 100644
--- a/app/keyboard.c
+++ b/app/keyboard.c
@@ -124,7 +124,8 @@ keyboard_send (uint8_t modifiers, uint8_t * key_list)
/*Last byte is the power wakeup stuff that we don't yet support */
uint8_t buf[KEYBOARD_EP_TXN_SIZE] =
{ modifiers, 0, key_list[0], key_list[1], key_list[2], key_list[3],
-key_list[4], key_list[5], 0 };
+ key_list[4], key_list[5], 0
+ };
usbd_ep_write_packet (usbd_dev, KEYBOARD_EP, buf, sizeof (buf));
}
diff --git a/app/project.h b/app/project.h
index 3271bb8..87363f9 100644
--- a/app/project.h
+++ b/app/project.h
@@ -29,7 +29,9 @@
#define KEYBOARD_EP_TXN_SIZE 0x9
#define CONSUMER_EP 0x82
-#define CONSUMER_EP_TXN_SIZE 0x9
+#define CONSUMER_EP_TXN_SIZE 0x2
+
+#define AT_KBD_INIT_TIME 200
diff --git a/app/prototypes.h b/app/prototypes.h
index 4349f48..8849f83 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -17,6 +17,7 @@ extern const struct usb_config_descriptor config;
extern usbd_device *usbd_dev;
extern void usb_set_config(usbd_device *usbd_dev, uint16_t wValue);
extern void usb_init(void);
+extern void usb_poll(void);
extern void usb_run(void);
/* consumer.c */
extern const struct usb_endpoint_descriptor consumer_endpoint;
@@ -32,6 +33,7 @@ extern int atkbd_set_leds(uint8_t leds);
extern int atkbd_set_scanset(uint8_t scanset);
extern int atkbd_set_mb(void);
extern int atkbd_set_mbr(void);
+extern void atkbd_start(void);
extern void atkbd_init(void);
/* ring.c */
extern void ring_init(volatile ring_t *r, uint8_t *buf, size_t len);
diff --git a/app/ticker.c b/app/ticker.c
index 37884a6..e3ff474 100644
--- a/app/ticker.c
+++ b/app/ticker.c
@@ -3,7 +3,7 @@
static volatile uint32_t delay_ms_count;
volatile uint32_t ticks;
-static uint32_t scale = 10;
+static uint32_t scale = 7;
void
delay_us (uint32_t d)
diff --git a/app/tims_keyboard.c b/app/tims_keyboard.c
index c3c947b..4897c4d 100644
--- a/app/tims_keyboard.c
+++ b/app/tims_keyboard.c
@@ -27,19 +27,33 @@ main (void)
nvic_set_priority (NVIC_EXTI0_IRQ, 0xc0);
usart_init ();
-
ticker_init ();
#ifdef DEBUG
- printf ("Hello world!\r\n");
+ printf ("USART and ticker started\r\n");
+#endif
+
+ usb_init ();
+
+#ifdef DEBUG
+ printf ("USB started\r\n");
#endif
atkbd_init ();
- usb_init ();
+#ifdef DEBUG
+ printf ("ATKBD i/f started\r\n");
+#endif
+ while (ticks < AT_KBD_INIT_TIME)
+ usb_poll ();
- usb_run ();
+ atkbd_start ();
+#ifdef DEBUG
+ printf ("Keyboard started\r\n");
+#endif
+
+ usb_run ();
return 0;
}
diff --git a/app/usb.c b/app/usb.c
index 767ad69..83dc620 100644
--- a/app/usb.c
+++ b/app/usb.c
@@ -142,8 +142,14 @@ usb_init (void)
}
void
+usb_poll (void)
+{
+ usbd_poll (usbd_dev);
+}
+
+void
usb_run (void)
{
- while (1)
+ for (;;)
usbd_poll (usbd_dev);
}