summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2015-06-06 16:00:52 +0100
committerroot <root@lamia.panaceas.james.local>2015-06-06 16:00:52 +0100
commit808e3dc9de1fb26eed6efcfe5665f0a66c239970 (patch)
treeb71ef5c7af6a735198472e305c055667b2373fd7 /app
parent98cba32ca9d62f6e4b7e735d177dba699b8d0698 (diff)
downloadtims_keyboard-808e3dc9de1fb26eed6efcfe5665f0a66c239970.tar.gz
tims_keyboard-808e3dc9de1fb26eed6efcfe5665f0a66c239970.tar.bz2
tims_keyboard-808e3dc9de1fb26eed6efcfe5665f0a66c239970.zip
fish
Diffstat (limited to 'app')
-rw-r--r--app/Makefile2
-rw-r--r--app/at_scancodes.h126
-rw-r--r--app/atkbd.c602
-rw-r--r--app/project.h2
-rw-r--r--app/prototypes.h9
-rw-r--r--app/scancode.c10
-rw-r--r--app/tims_keyboard.c6
7 files changed, 532 insertions, 225 deletions
diff --git a/app/Makefile b/app/Makefile
index 39d9779..a5e4d88 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -24,7 +24,7 @@ PROG=tims_keyboard
V=1
default: ${PROG}.elf
-CSRCS=tims_keyboard.c dfu.c keyboard.c usb.c consumer.c atkbd.c ring.c usart.c stdio.c ticker.c
+CSRCS=tims_keyboard.c dfu.c keyboard.c usb.c consumer.c atkbd.c ring.c usart.c stdio.c ticker.c scancode.c
BINARY = ${PROG}
diff --git a/app/at_scancodes.h b/app/at_scancodes.h
new file mode 100644
index 0000000..9af7bcc
--- /dev/null
+++ b/app/at_scancodes.h
@@ -0,0 +1,126 @@
+#ifndef _AT_SCANCODES_H_
+#define _AT_SCANCODES_H_
+
+#define AT_BS_EMUL0 0x0100
+#define AT_BS_EMUL1 0x0200
+#define AT_BS_FSHIFT_ON 0x0000
+#define AT_BS_FSHIFT_OFF 0x0000
+#define AT_BS_FCTRL_ON 0x0000
+
+#define AT_SC_GRAVE 0x0E
+#define AT_SC_1 0x16
+#define AT_SC_2 0x1E
+#define AT_SC_3 0x26
+#define AT_SC_4 0x25
+#define AT_SC_5 0x2E
+#define AT_SC_6 0x36
+#define AT_SC_7 0x3D
+#define AT_SC_8 0x3E
+#define AT_SC_9 0x46
+#define AT_SC_0 0x45
+#define AT_SC_MINUS 0x4E
+#define AT_SC_EQUAL 0x55
+#define AT_SC_BACKSPACE 0x66
+#define AT_SC_TAB 0x0D
+#define AT_SC_Q 0x15
+#define AT_SC_W 0x1D
+#define AT_SC_E 0x24
+#define AT_SC_R 0x2D
+#define AT_SC_T 0x2C
+#define AT_SC_Y 0x35
+#define AT_SC_U 0x3C
+#define AT_SC_I 0x43
+#define AT_SC_O 0x44
+#define AT_SC_P 0x4D
+#define AT_SC_LEFTBRACE 0x54
+#define AT_SC_RIGHTBRACE 0x5B
+#define AT_SC_BACKSLASH 0x5D
+#define AT_SC_CAPSLOCK 0x58
+#define AT_SC_A 0x1C
+#define AT_SC_S 0x1B
+#define AT_SC_D 0x23
+#define AT_SC_F 0x2B
+#define AT_SC_G 0x34
+#define AT_SC_H 0x33
+#define AT_SC_J 0x3B
+#define AT_SC_K 0x42
+#define AT_SC_L 0x4B
+#define AT_SC_SEMICOLON 0x4C
+#define AT_SC_APOSTROPHE 0x52
+#define AT_SC_ENTER 0x5A
+#define AT_SC_LEFTSHIFT 0x12
+#define AT_SC_Z 0x1A
+#define AT_SC_X 0x22
+#define AT_SC_C 0x21
+#define AT_SC_V 0x2A
+#define AT_SC_B 0x32
+#define AT_SC_N 0x31
+#define AT_SC_M 0x3A
+#define AT_SC_COMMA 0x41
+#define AT_SC_DOT 0x49
+#define AT_SC_SLASH 0x4A
+#define AT_SC_RIGHTSHIFT 0x59
+#define AT_SC_LEFTCTRL 0x14
+#define AT_SC_LEFTALT 0x11
+#define AT_SC_SPACE 0x29
+#define AT_SC_RIGHTALT (AT_BS_EMUL0 | 0x11)
+#define AT_SC_RIGHTCTRL (AT_BS_EMUL0 | 0x14)
+#define AT_SC_INSERT (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x70)
+#define AT_SC_DELETE (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x71)
+#define AT_SC_LEFT (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x79)
+#define AT_SC_HOME (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x6C)
+#define AT_SC_END (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x69)
+#define AT_SC_UP (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x75)
+#define AT_SC_DOWN (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x72)
+#define AT_SC_PAGEUP (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x7D)
+#define AT_SC_PAGEDOWN (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x7A)
+#define AT_SC_RIGHT (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x74)
+#define AT_SC_NUMLOCK 0x77
+#define AT_SC_KP7 (AT_SC_FSHIFT_ON | 0x6C)
+#define AT_SC_KP4 (AT_SC_FSHIFT_ON | 0x6B)
+#define AT_SC_KP1 (AT_SC_FSHIFT_ON | 0x69)
+#define AT_SC_KPSLASH (AT_SC_FSHIFT_OFF | AT_BS_EMUL0 | 0x4A)
+#define AT_SC_KP8 (AT_SC_FSHIFT_ON | 0x75)
+#define AT_SC_KP5 (AT_SC_FSHIFT_ON | 0x73)
+#define AT_SC_KP2 (AT_SC_FSHIFT_ON | 0x72)
+#define AT_SC_KP0 (AT_SC_FSHIFT_ON | 0x70)
+#define AT_SC_KPASTERISK 0x7C
+#define AT_SC_KP9 (AT_SC_FSHIFT_ON | 0x7D)
+#define AT_SC_KP6 (AT_SC_FSHIFT_ON | 0x74)
+#define AT_SC_KP3 (AT_SC_FSHIFT_ON | 0x7A)
+#define AT_SC_KPDOT (AT_SC_FSHIFT_ON | 0x71)
+#define AT_SC_KPMINUS 0x7B
+#define AT_SC_KPPLUS 0x79
+#define AT_SC_KPENTER (AT_SC_FSHIFT_OFF | 0x5A)
+#define AT_SC_ESC 0x76
+#define AT_SC_F1 0x05
+#define AT_SC_F2 0x06
+#define AT_SC_F3 0x04
+#define AT_SC_F4 0x0C
+#define AT_SC_F5 0x03
+#define AT_SC_F6 0x0B
+#define AT_SC_F7 0x83
+#define AT_SC_F8 0x0A
+#define AT_SC_F9 0x01
+#define AT_SC_F10 0x09
+#define AT_SC_F11 0x78
+#define AT_SC_F12 0x07
+#define AT_SC_SYSRQ (AT_BS_FSHIFT_ON | AT_BS_EMUL0 | 0x7C)
+#define AT_SC_SCROLLLOCK 0x7E
+#define AT_SC_PAUSE (AT_BS_FCTRL_ON | AT_BS_EMUL0 | 0x7E)
+#define AT_SC_LEFTMETA (AT_BS_EMUL0 | 0x1F)
+#define AT_SC_RIGHTMETA (AT_BS_EMUL0 | 0x27)
+#define AT_SC_MENU (AT_BS_EMUL0 | 0x2F)
+#define AT_SC_POWER (AT_BS_EMUL0 | 0x37)
+#define AT_SC_SLEEP (AT_BS_EMUL0 | 0x3F)
+#define AT_SC_WAKEUP (AT_BS_EMUL0 | 0x5E)
+#define AT_SC_DBE_KATAKANA 0x13
+#define AT_SC_DBE_SBCSCHAR 0x62
+#define AT_SC_CONVERT 0x64
+#define AT_SC_NONCONVERT 0x67
+
+#define AT_SC_EMUL0 0xE0
+#define AT_SC_EMUL1 0xE1
+
+
+#endif
diff --git a/app/atkbd.c b/app/atkbd.c
index 0dfc9c8..63482a6 100644
--- a/app/atkbd.c
+++ b/app/atkbd.c
@@ -1,5 +1,6 @@
#include "project.h"
+
#define KBCLK (1UL << 0)
#define KBCLK_PORT GPIOA
#define KBCLK_IRQ NVIC_EXTI0_IRQ
@@ -9,26 +10,35 @@
/*Cope with lost sync */
/*If we've had no bits for this long, it's definately the start of a new word, 72MHz units */
-#define RESYNC_GAP (7200000) /* 100ms */
-
-#define ATKBD_TIMEOUT 1000 /*how long to wait for the keyboard to respond to a command in ms */
-
-
-typedef enum {
- STATE_START=0,
- STATE_BIT0,
- STATE_BIT1,
- STATE_BIT2,
- STATE_BIT3,
- STATE_BIT4,
- STATE_BIT5,
- STATE_BIT6,
- STATE_BIT7,
- STATE_PARITY,
- STATE_STOP,
+#define RESYNC_GAP (7200000) /* 100ms */
+
+#define ATKBD_TIMEOUT 1000 /*how long to wait for the keyboard to respond to a command in ms */
+
+#define ATKBD_CLOCK_SEIZE_DELAY 200 /* how many us from pulling clock low to pulling data low, when we xmit */
+#define ATKBD_BIT_DELAY 10 /* how many us we allow from the KBD to pull clock back up */
+
+
+typedef enum
+{
+ STATE_START = 0,
+ STATE_BIT0,
+ STATE_BIT1,
+ STATE_BIT2,
+ STATE_BIT3,
+ STATE_BIT4,
+ STATE_BIT5,
+ STATE_BIT6,
+ STATE_BIT7,
+ STATE_PARITY,
+ STATE_STOP,
} atkbd_state;
+#define LED_CAPS 0x01
+#define LED_NUMLOCK 0x02
+#define LED_SCROLLOCK 0x04
+
+
#define ATKBD_CMD_SETLEDS 0xed
#define ATKBD_CMD_GSCANSET 0xf0
#define ATKBD_CMD_SSCANSET 0xf0
@@ -38,12 +48,13 @@ typedef enum {
#define ATKBD_CMD_RESET_DIS 0xf5
#define ATKBD_CMD_RESET_DEF 0xf6
#define ATKBD_CMD_SETALL_MB 0xf8
-#define ATKBD_CMD_SETALL_MBR 0xfa
+#define ATKBD_CMD_SETALL_MBR 0xfa
#define ATKBD_CMD_RESET_BAT 0xff
#define ATKBD_CMD_RESEND 0xfe
#define ATKBD_CMD_EX_ENABLE 0xea
#define ATKBD_CMD_EX_SETLEDS 0xeb
#define ATKBD_CMD_OK_GETID 0xe8
+#define ATKBD_CMD_ECHO 0xee
#define ATKBD_RET_ECHO 0xee
#define ATKBD_RET_ACK 0xfa
@@ -65,261 +76,412 @@ static int atkbd_nack;
static int atkbd_bat;
static int atkbd_echo;
-
-
-static uint32_t cycle_diff(uint32_t a,uint32_t b)
+static void
+atkbd_mask_irq (void)
{
-return b-a;
+ nvic_disable_irq (KBCLK_IRQ);
}
-
-static void atkbd_dispatch(int emul,int key,int updown)
+static void
+atkbd_unmask_flush_irq (void)
{
-
-printf("KEY> %x %x %x\r\n",emul,key,updown);
-
-
+ exti_reset_request (KBCLK);
+ nvic_enable_irq (KBCLK_IRQ);
}
-static void atkbd_data_dispatch(uint8_t byte)
-{
-static int release;
-static int emul;
-
-printf("ATKBD < 0x%02x\r\n",byte);
-
-switch (byte) {
-case ATKBD_RET_ACK:
- atkbd_ack++;
- break;
-case ATKBD_RET_NAK:
- atkbd_nack++;
- break;
-case ATKBD_RET_BAT:
- atkbd_bat++;
- break;
-case ATKBD_RET_ECHO:
- atkbd_echo++;
- break;
-case ATKBD_RET_ERR:
-case ATKBD_KEY_UNKNOWN:
-case ATKBD_RET_HANJA: /*Don't handle japanese or korean for the moment*/
-case ATKBD_RET_HANGEUL: /*Don't handle japanese or korean for the moment*/
- /*All these need no action */
- break;
-case ATKBD_RET_EMUL0:
- emul=1;
- break;
-case ATKBD_RET_EMUL1:
- emul=2;
- break;
-case ATKBD_RET_RELEASE:
- release=1;
- break;
-default:
- atkbd_dispatch(emul,byte,release);
- emul=0;
- release=0;
-}
-
-}
-void exti0_isr(void)
+static uint32_t
+cycle_diff (uint32_t a, uint32_t b)
{
- static uint32_t last_interrupt=0;
- static atkbd_state state=STATE_START;
- static uint8_t atkbd_byte;
- static int parity;
-
- uint32_t now,diff;
- int d;
-
- d=!!GET(KBDAT);
-
- exti_reset_request(KBCLK);
-
- now=dwt_read_cycle_counter();
- diff=cycle_diff(last_interrupt,now);
- last_interrupt=now;
-
-
- if (diff>RESYNC_GAP) state=STATE_START;
-
-
- switch (state) {
- case STATE_START:
- atkbd_byte=0;
- parity=0;
- if (!d) state++;
- break;
- case STATE_BIT0:
- case STATE_BIT1:
- case STATE_BIT2:
- case STATE_BIT3:
- case STATE_BIT4:
- case STATE_BIT5:
- case STATE_BIT6:
- case STATE_BIT7:
- atkbd_byte|=d<<(state-STATE_BIT0);
- /* fall through*/
- case STATE_PARITY:
- parity ^= d;
- state++;
- break;
- case STATE_STOP:
- if (d && parity) atkbd_data_dispatch(atkbd_byte);
- state=STATE_START;
- break;
- }
+ return b - a;
}
-void atkbd_set(int clk,int dat)
-{
-if (clk) {
- MAP_INPUT_PU(KBCLK);
-} else {
- CLEAR(KBCLK);
- MAP_OUTPUT_PP(KBCLK);
-}
-
-if (dat) {
- MAP_INPUT_PU(KBDAT);
-} else {
- CLEAR(KBDAT);
- MAP_OUTPUT_PP(KBDAT);
-}
+static void
+atkbd_dispatch (int key, int updown)
+{
+/* the logic here is batshit, consult scancode.doc in the DOCS dir */
+ static int fake_ctrl, pause_down;
+
+ switch (key)
+ {
+ case AT_SC_LEFTCTRL | AT_BS_EMUL1:
+ fake_ctrl = updown;
+ break;
+ }
+
+
+ if (key == 0x84)
+ key = AT_SC_SYSRQ;
+ if (key == 0x77)
+ {
+ /*Grr broken MS state machine in docs */
+ if ((!updown) && (pause_down))
+ {
+ key = AT_SC_PAUSE;
+ pause_down = 0;
+ }
+
+ if (fake_ctrl && updown)
+ {
+ key = AT_SC_PAUSE;
+ pause_down = 1;
+ }
+ }
+
+
+/* Filter fakes */
+ switch (key)
+ {
+ case AT_SC_LEFTCTRL | AT_BS_EMUL1:
+ case AT_SC_LEFTSHIFT | AT_BS_EMUL0:
+ case AT_SC_RIGHTSHIFT | AT_BS_EMUL0:
+ break;
+ default:
+ scancode_dispatch (key, updown);
+ }
}
-
-int atkbd_send(uint8_t d)
+static void
+atkbd_data_dispatch (uint8_t byte)
{
-uint32_t then=ticks;
-int parity=1;
-uint32_t c;
+ static int release;
+ static int emul;
+
+// printf ("ATKBD < 0x%02x\r\n", byte);
+
+ switch (byte)
+ {
+ case ATKBD_RET_ACK:
+ atkbd_ack++;
+ break;
+ case ATKBD_RET_NAK:
+ atkbd_nack++;
+ break;
+ case ATKBD_RET_BAT:
+ atkbd_bat++;
+ break;
+ case ATKBD_RET_ECHO:
+ atkbd_echo++;
+ break;
+ case ATKBD_RET_ERR:
+ case ATKBD_KEY_UNKNOWN:
+ /*All these need no action */
+ break;
+ case AT_SC_EMUL0:
+ emul = AT_BS_EMUL0;
+ break;
+ case AT_SC_EMUL1:
+ emul = AT_BS_EMUL1;
+ break;
+ case ATKBD_RET_RELEASE:
+ release = 1;
+ break;
+ default:
+ atkbd_dispatch (emul | byte, !release);
+ emul = 0;
+ release = 0;
+ }
-
-nvic_disable_irq(KBCLK_IRQ);
-
-#define PS2_CLOCK_SEIZE_DELAY 200
-#define PS2_BIT_DELAY 10
-
-atkbd_set(0,1);
-delay_us(PS2_CLOCK_SEIZE_DELAY);
-atkbd_set(0,0);
-delay_us(PS2_BIT_DELAY);
-atkbd_set(1,0);
-delay_us(PS2_BIT_DELAY);
-
-for (c=1;c<0x100;c<<=1) {
-while (GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-atkbd_set(1,c&d);
-parity^=!!(c&d);
-while (!GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
}
-while (GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-atkbd_set(1,parity);
-while (!GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-while (GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-while (!GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-atkbd_set(1,1);
-while (GET(KBDAT)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-while (GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
+void
+exti0_isr (void)
+{
+ static uint32_t last_interrupt = 0;
+ static atkbd_state state = STATE_START;
+ static uint8_t atkbd_byte;
+ static int parity;
+
+ uint32_t now, diff;
+ int d;
+
+ d = ! !GET (KBDAT);
+
+ exti_reset_request (KBCLK);
+
+ now = dwt_read_cycle_counter ();
+ diff = cycle_diff (last_interrupt, now);
+ last_interrupt = now;
+
+
+ if (diff > RESYNC_GAP)
+ state = STATE_START;
+
+
+ switch (state)
+ {
+ case STATE_START:
+ atkbd_byte = 0;
+ parity = 0;
+ if (!d)
+ state++;
+ break;
+ case STATE_BIT0:
+ case STATE_BIT1:
+ case STATE_BIT2:
+ case STATE_BIT3:
+ case STATE_BIT4:
+ case STATE_BIT5:
+ case STATE_BIT6:
+ case STATE_BIT7:
+ atkbd_byte |= d << (state - STATE_BIT0);
+ /* fall through */
+ case STATE_PARITY:
+ parity ^= d;
+ state++;
+ break;
+ case STATE_STOP:
+ if (d && parity)
+ atkbd_data_dispatch (atkbd_byte);
+ state = STATE_START;
+ break;
+ }
+}
-while (!GET(KBDAT)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-while (!GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
+void
+atkbd_set (int clk, int dat)
+{
+ if (clk)
+ {
+ MAP_INPUT_PU (KBCLK);
+ }
+ else
+ {
+ CLEAR (KBCLK);
+ MAP_OUTPUT_PP (KBCLK);
+ }
+
+
+ if (dat)
+ {
+ MAP_INPUT_PU (KBDAT);
+ }
+ else
+ {
+ CLEAR (KBDAT);
+ MAP_OUTPUT_PP (KBDAT);
+ }
-exti_reset_request(KBCLK);
-nvic_enable_irq(KBCLK_IRQ);
+}
-printf("ATKBD > 0x%02x\r\n",d);
-return 0;
+int
+atkbd_send (uint8_t d)
+{
+ uint32_t then = ticks;
+ int parity = 1;
+ uint32_t c;
+
+ atkbd_mask_irq ();
+
+ atkbd_set (0, 1);
+ delay_us (ATKBD_CLOCK_SEIZE_DELAY);
+ atkbd_set (0, 0);
+ delay_us (ATKBD_BIT_DELAY);
+ atkbd_set (1, 0);
+ delay_us (ATKBD_BIT_DELAY);
+
+
+ /* 8 data bits */
+ for (c = 1; c < 0x100; c <<= 1)
+ {
+ while (GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ atkbd_set (1, c & d);
+ parity ^= ! !(c & d);
+ while (!GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ }
+
+ /* A parity bit */
+ while (GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ atkbd_set (1, parity);
+ while (!GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+
+ /* two stop bits */
+ while (GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ atkbd_set (1, 1);
+ while (!GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+
+ while (GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ atkbd_set (1, 1);
+ while (!GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+
+ while (!GET (KBDAT))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ while (!GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+
+ atkbd_unmask_flush_irq ();
+
+// printf ("ATKBD > 0x%02x\r\n", d);
+
+ return 0;
err:
-atkbd_set(1,1);
-while (!GET(KBDAT)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-while (!GET(KBCLK)) if (timed_out(then,ATKBD_TIMEOUT)) goto err;
-
-exti_reset_request(KBCLK);
-nvic_enable_irq(KBCLK_IRQ);
-
-printf("ATKBD >! 0x%02x\r\n",d);
-return -1;
+ atkbd_set (1, 1);
+ while (!GET (KBDAT))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+ while (!GET (KBCLK))
+ if (timed_out (then, ATKBD_TIMEOUT))
+ goto err;
+
+ atkbd_unmask_flush_irq ();
+
+// printf ("ATKBD >! 0x%02x\r\n", d);
+ return -1;
}
-static int atkbd_reset(void)
+static int
+atkbd_reset (void)
{
-uint32_t then=ticks;
-atkbd_bat=0;
-atkbd_send(ATKBD_CMD_RESET_BAT);
-while (!atkbd_bat) if (timed_out(then,ATKBD_TIMEOUT)) return -1;
-
-then=ticks;
-atkbd_ack=0;
-atkbd_send(ATKBD_CMD_SETALL_MBR);
-while (!atkbd_ack) if (timed_out(then,ATKBD_TIMEOUT)) return -1;
-
-
-return 0;
+ uint32_t then = ticks;
+ atkbd_bat = 0;
+ atkbd_send (ATKBD_CMD_RESET_BAT);
+ while (!atkbd_bat)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (ATKBD_CMD_SETALL_MBR);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+
+ return 0;
}
-int atkbd_request_echo(void)
+int
+atkbd_request_echo (void)
{
-uint32_t then=ticks;
-atkbd_ack=0;
-atkbd_send(ATKBD_CMD_ECHO);
-while (!atkbd_echo) if (timed_out(then,ATKBD_TIMEOUT)) return -1;
-
-return 0;
+ uint32_t then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (ATKBD_CMD_ECHO);
+ while (!atkbd_echo)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ return 0;
}
-int atkbd_set_leds(uint8_t leds)
+int
+atkbd_set_leds (uint8_t leds)
{
-uint32_t then=ticks;
-atkbd_ack=0;
-atkbd_send(ATKBD_CMD_SETLEDS);
-while (!atkbd_ack) if (timed_out(then,ATKBD_TIMEOUT)) return -1;
+ uint32_t then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (ATKBD_CMD_SETLEDS);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (leds);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ return 0;
+}
-then=ticks;
-atkbd_ack=0;
-atkbd_send(leds);
-while (!atkbd_ack) if (timed_out(then,ATKBD_TIMEOUT)) return -1;
-return 0;
+int
+atkbd_set_scanset (uint8_t scanset)
+{
+ uint32_t then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (ATKBD_CMD_SSCANSET);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (scanset);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ return 0;
}
+int
+atkbd_set_mb (void)
+{
+ uint32_t then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (ATKBD_CMD_SETALL_MB);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ return 0;
+}
-void atkbd_init(void)
+int
+atkbd_set_mbr (void)
{
-atkbd_set(1,1);
-delay_ms(200);
+ uint32_t then = ticks;
+ atkbd_ack = 0;
+ atkbd_send (ATKBD_CMD_SETALL_MBR);
+ while (!atkbd_ack)
+ if (timed_out (then, ATKBD_TIMEOUT))
+ return -1;
+
+ return 0;
+}
-nvic_enable_irq(NVIC_EXTI0_IRQ);
+void
+atkbd_init (void)
+{
+ atkbd_set (1, 1);
+ delay_ms (200);
-exti_select_source(KBCLK, KBCLK_PORT);
-exti_set_trigger(KBCLK, EXTI_TRIGGER_FALLING);
-exti_enable_request(KBCLK);
+ nvic_enable_irq (NVIC_EXTI0_IRQ);
-exti_reset_request(KBCLK);
-nvic_enable_irq(KBCLK_IRQ);
+ exti_select_source (KBCLK, KBCLK_PORT);
+ exti_set_trigger (KBCLK, EXTI_TRIGGER_FALLING);
+ exti_enable_request (KBCLK);
-atkbd_reset();
-atkbd_request_echo();
-atkbd_set_leds(0x07);
+ exti_reset_request (KBCLK);
+ nvic_enable_irq (KBCLK_IRQ);
-}
+ atkbd_reset ();
+ atkbd_request_echo ();
+ atkbd_set_mbr ();
+ atkbd_set_scanset (2);
+ atkbd_set_leds (LED_CAPS);
+}
diff --git a/app/project.h b/app/project.h
index 24ca271..5885046 100644
--- a/app/project.h
+++ b/app/project.h
@@ -19,6 +19,8 @@
#include "ring.h"
#include "pins.h"
+#include "at_scancodes.h"
+
#include "id.h"
diff --git a/app/prototypes.h b/app/prototypes.h
index 52b504f..ed15fd1 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -21,10 +21,15 @@ extern void usb_run(void);
extern const struct usb_endpoint_descriptor consumer_endpoint;
extern const struct usb_interface_descriptor consumer_iface;
extern void consumer_get_descriptor(uint8_t **buf, uint16_t *len);
-/* ps2.c */
+/* atkbd.c */
extern void exti0_isr(void);
extern void atkbd_set(int clk, int dat);
extern int atkbd_send(uint8_t d);
+extern int atkbd_request_echo(void);
+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_init(void);
/* ring.c */
extern void ring_init(volatile ring_t *r, uint8_t *buf, size_t len);
@@ -55,3 +60,5 @@ extern void sys_tick_handler(void);
extern void delay_ms(uint32_t d);
extern int timed_out(uint32_t then, unsigned int ms);
extern void ticker_init(void);
+/* scancode.c */
+extern void scancode_dispatch(int key, int updown);
diff --git a/app/scancode.c b/app/scancode.c
new file mode 100644
index 0000000..a44c8b3
--- /dev/null
+++ b/app/scancode.c
@@ -0,0 +1,10 @@
+
+#include "project.h"
+
+
+void scancode_dispatch(int key,int updown)
+{
+
+printf("Key %4x ud %d\r\n",key,updown);
+}
+
diff --git a/app/tims_keyboard.c b/app/tims_keyboard.c
index e6a4aae..ec1ce59 100644
--- a/app/tims_keyboard.c
+++ b/app/tims_keyboard.c
@@ -21,10 +21,10 @@ main (void)
rcc_periph_clock_enable (RCC_USART1);
dwt_enable_cycle_counter();
- /*Change interrupt priorities so that USART trumps everything else */
+ /*Change interrupt priorities so that USART trumps Timer trumps ATKBD */
nvic_set_priority(NVIC_USART1_IRQ, 0x40);
- nvic_set_priority(NVIC_EXTI0_IRQ, 0xff);
- nvic_set_priority(NVIC_SYSTICK_IRQ, 0xff);
+ nvic_set_priority(NVIC_SYSTICK_IRQ, 0x80);
+ nvic_set_priority(NVIC_EXTI0_IRQ, 0xc0);
usart_init();