From cdea4f5da56c6158beccc801f0a4efa045cf46cb Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Jun 2015 02:35:01 +0100 Subject: tidy up makefiles and fix init delay --- app/Makefile | 2 +- app/atkbd.c | 31 +++++++++++++++++++++++-------- app/keyboard.c | 3 ++- app/project.h | 4 +++- app/prototypes.h | 2 ++ app/ticker.c | 2 +- app/tims_keyboard.c | 22 ++++++++++++++++++---- app/usb.c | 8 +++++++- 8 files changed, 57 insertions(+), 17 deletions(-) (limited to 'app') 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) @@ -461,11 +470,23 @@ 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 @@ -141,9 +141,15 @@ usb_init (void) } +void +usb_poll (void) +{ + usbd_poll (usbd_dev); +} + void usb_run (void) { - while (1) + for (;;) usbd_poll (usbd_dev); } -- cgit v1.2.3