# HG changeset patch # User John Tsiombikas # Date 1508243133 -10800 # Node ID a4fd9c5a665547e2d20cd7eab05b9a61b1d91696 # Parent 3228a731d4db6c084501f8b53c926ac503ce55aa first working version diff -r 3228a731d4db -r a4fd9c5a6655 Makefile --- a/Makefile Sat Oct 14 07:23:47 2017 +0300 +++ b/Makefile Tue Oct 17 15:25:33 2017 +0300 @@ -10,7 +10,7 @@ CC = avr-gcc OBJCOPY = avr-objcopy -CFLAGS = -Os -pedantic -Wall -mmcu=$(mcu_gcc) -DXTAL=14745600 +CFLAGS = -Os -pedantic -Wall -mmcu=$(mcu_gcc) -DF_CPU=14745600 LDFLAGS = -Wl,-Map,$(bin).map -mmcu=$(mcu_gcc) -lprintf_min .PHONY: all diff -r 3228a731d4db -r a4fd9c5a6655 src/amigakb.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/amigakb.c Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include "amigakb.h" +#include "defs.h" +#include "timer.h" + +#define TIMEOUT_MSEC 143 + +static void resync(void); + +void amikb_sendkey(unsigned char keycode, int press) +{ + int i; + static unsigned char prev_keycode = 0xff; + + /* keycode bit transfer order: 6 5 4 3 2 1 0 7 (7 is pressed flag) */ + keycode = (keycode << 1) | (~press & 1); + if(keycode == prev_keycode) return; + prev_keycode = keycode; + + /* make sure we don't pulse the lines while grabbing control + * by first reinstating the pullups before changing direction + */ + PORTD |= ACLK_BIT | ADATA_BIT; + DDRD |= ACLK_BIT | ADATA_BIT; + + /* pulse the data line and wait for about 100us */ + PORTD &= ~ADATA_BIT; + _delay_us(20); + PORTD |= ADATA_BIT; + _delay_us(100); + + for(i=0; i<8; i++) { + /* data line is inverted */ + if(keycode & 0x80) { + PORTD &= ~ADATA_BIT; + } else { + PORTD |= ADATA_BIT; + } + keycode <<= 1; + _delay_us(20); + /* pulse the clock */ + cli(); + PORTD &= ~ACLK_BIT; + EIFR |= (1 << INTF1); + sei(); + _delay_us(20); + PORTD |= ACLK_BIT; + _delay_us(20); + } + + /* similarly tristate first, then drop the pullups */ + DDRD &= ~(ACLK_BIT | ADATA_BIT); + PORTD &= ~(ACLK_BIT | ADATA_BIT); + + /* wait for ack */ + reset_timer(); + while(PIND & ADATA_BIT) { + if(get_msec() >= TIMEOUT_MSEC) { + resync(); + break; + } + } +} + +void amikb_reset(void) +{ + cli(); + PORTD &= ~ARST_BIT; + DDRD |= ARST_BIT; + _delay_ms(10); + PORTD |= ARST_BIT; + DDRD &= ~ARST_BIT; + sei(); +} + +static void resync(void) +{ + PORTD |= ACLK_BIT | ADATA_BIT; + printf("lost sync\r\n"); + + for(;;) { + cli(); + DDRD |= ACLK_BIT | ADATA_BIT; + + PORTD &= ~ACLK_BIT; + EIFR |= (1 << INTF1); /* clear interrupt raised by the previous line */ + sei(); + _delay_us(20); + PORTD |= ACLK_BIT; + + DDRD &= ~(ACLK_BIT | ADATA_BIT); + + reset_timer(); + while(get_msec() < TIMEOUT_MSEC) { + if(!(PIND & ADATA_BIT)) { + return; + } + } + } +} + +static void handle_cmd(unsigned char cmd) +{ + printf("amikbd got cmd: %x\r\n", (unsigned int)cmd); +} + +ISR(INT1_vect) +{ + static unsigned char value; + static int nbits; + + value <<= 1; + if(PIND & ADATA_BIT) { + value |= 1; + } + if(++nbits >= 8) { + handle_cmd(value); + nbits = 0; + value = 0; + } +} diff -r 3228a731d4db -r a4fd9c5a6655 src/amigakb.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/amigakb.h Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,7 @@ +#ifndef AMIGAKB_H_ +#define AMIGAKB_H_ + +void amikb_sendkey(unsigned char keycode, int press); +void amikb_reset(void); + +#endif /* AMIGAKB_H_ */ diff -r 3228a731d4db -r a4fd9c5a6655 src/defs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/defs.h Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,29 @@ +#ifndef DEFS_H_ +#define DEFS_H_ + +#include + +/* pin assignments: + * D2 PS/2 clock (INT0) + * D3 amikbd clock (INT1) + * D4 PS/2 data + * D5 amikbd data + * D6 amiga reset + * D7 amiga drvled in + */ + +#define PCLK 2 +#define ACLK 3 +#define PDATA 4 +#define ADATA 5 +#define ARST 6 +#define ADRVLED 7 + +#define PCLK_BIT (1 << PCLK) +#define ACLK_BIT (1 << ACLK) +#define PDATA_BIT (1 << PDATA) +#define ADATA_BIT (1 << ADATA) +#define ARST_BIT (1 << ARST) +#define ADRVLED_BIT (1 << ADRVLED) + +#endif /* DEFS_H_ */ diff -r 3228a731d4db -r a4fd9c5a6655 src/main.c --- a/src/main.c Sat Oct 14 07:23:47 2017 +0300 +++ b/src/main.c Tue Oct 17 15:25:33 2017 +0300 @@ -1,64 +1,50 @@ -#define F_CPU XTAL #include #include #include #include #include -#include #include "serial.h" #include "scantbl.h" - -/* pin assignments: - * B0 PS/2 data - * D2 PS/2 clock (INT0) - * B1 KBD data - * D3 KBD clock (INT1) - */ - -#define BIT_DATA 1 -#define BIT_CLK 2 - -#define PS2LOW(bit) do { DDRB |= (bit); PORTB &= ~(bit); } while(0) -#define PS2HIGH(bit) do { DDRB |= (bit); PORTB |= (bit); } while(0) -#define PS2REL(bit) do { DDRB &= ~(bit); PORTB &= ~(bit); } while(0) - -void ps2write(unsigned char c); -unsigned char ps2read(void); -int ps2pending(void); - -#define BUF_SZ 16 -#define BUF_IDX_MASK (BUF_SZ - 1) -#define NEXT_IDX(x) (((x) + 1) & BUF_IDX_MASK) -static volatile unsigned char keybuf[BUF_SZ]; -static volatile unsigned char key_rd, key_wr; - -static volatile int sending; +#include "ps2kbd.h" +#include "amigakb.h" +#include "defs.h" +#include "timer.h" enum { KF_BRK = 1, KF_EXT = 2, KF_EXT1 = 4, + + KF_CTRL = 16, + KF_LAMIGA = 32, + KF_RAMIGA = 64 }; +#define KF_TRANSIENT 0x0f +#define KF_STICKY 0xf0 int main(void) { unsigned int keyflags = 0; - int keycode; + unsigned char keycode; + int press; - DDRB = 0; + /* disable all pullups globally */ + MCUCR |= 1 << PUD; + DDRD = 0; - PORTB = 0; PORTD = 0; EIMSK = 0; /* mask external interrupts */ EICRA = (1 << ISC11) | (1 << ISC01); /* falling edge interrupts */ + init_timer(); + /* initialize the UART and enable interrupts */ init_serial(9600); sei(); printf("PS/2 keyboard controller - John Tsiombikas \r\n"); - EIMSK = (1 << INT0); /* enable ps/2 clock interrupt */ + EIMSK = (1 << INT0) | (1 << INT1); /* enable ps/2 clock interrupt */ for(;;) { unsigned char c = ps2read(); @@ -76,7 +62,9 @@ break; default: - keycode = 0; + press = !(keyflags & KF_BRK); + + keycode = 0xff; if(keyflags & KF_EXT) { printf("ext "); if(c < KEYMAP_EXT_SIZE) { @@ -90,94 +78,48 @@ } } - if(keycode >= 256) { - /*printf("%s: %s (scancode: %x)\r\n", keyflags & KF_BRK ? "release" : "press", skeystr[keycode - 256], (unsigned int)c);*/ - printf("%s: key %xh (scancode: %x)\r\n", keyflags & KF_BRK ? "release" : "press", keycode, (unsigned int)c); - } else if(isprint(keycode)) { - printf("%s: %c (scancode: %x)\r\n", keyflags & KF_BRK ? "release" : "press", (char)keycode, (unsigned int)c); - } else if(keycode > 0) { - printf("%s: key %xh (scancode: %x)\r\n", keyflags & KF_BRK ? "release" : "press", keycode, (unsigned int)c); + switch(keycode) { + case AMIKEY_CTRL: + if(press) + keyflags |= KF_CTRL; + else + keyflags &= ~KF_CTRL; + break; + + case AMIKEY_LAMI: + if(press) + keyflags |= KF_LAMIGA; + else + keyflags &= ~KF_LAMIGA; + break; + + case AMIKEY_RAMI: + if(press) + keyflags |= KF_RAMIGA; + else + keyflags &= ~KF_RAMIGA; + break; + + default: + break; + } + + if((keyflags & (KF_CTRL | KF_RAMIGA | KF_LAMIGA)) == (KF_CTRL | KF_RAMIGA | KF_LAMIGA)) { + printf("CTRL - AMIGA - AMIGA!\r\n"); + amikb_reset(); + } + + printf("scancode %x -> ", (unsigned int)c); + if(keycode != 0xff) { + amikb_sendkey(keycode, ~keyflags & KF_BRK); + printf("[%s] amiga key %xh\r\n", press ? "press" : "release", keycode); } else { - printf("%s: %x\r\n", keyflags & KF_BRK ? "release" : "press", (unsigned int)c); + printf("[%s] no translation\r\n", press ? "press" : "release"); } - keyflags = 0; + keyflags &= ~KF_TRANSIENT; } } return 0; } -void ps2write(unsigned char c) -{ - int i; - unsigned short out = (unsigned short)c | ((unsigned short)(parity_even_bit(c) & 1) << 8); - /* pull clock low for >60us */ - PS2LOW(BIT_CLK); - _delay_us(60); - - /* then pull data low and release clock */ - PS2LOW(BIT_DATA); - PS2REL(BIT_CLK); - - for(i=0; i<9; i++) { - while(PINB & BIT_CLK); /* wait for kbd to drive the clock low */ - PORTB |= out & 1; - out >>= 1; - while(!(PINB & BIT_CLK)); /* wait for kbd to drive the clock high */ - } - - PS2REL(BIT_DATA); - /* wait for ack */ - while(PINB & BIT_DATA); - while(!(PINB & BIT_DATA)); -} - -unsigned char ps2read(void) -{ - unsigned char key; - - while(key_rd == key_wr) { - } - - cli(); - key = keybuf[key_rd]; - key_rd = NEXT_IDX(key_rd); - sei(); - - return key; -} - -int ps2pending(void) -{ - return key_rd != key_wr; -} - -ISR(INT0_vect) -{ - static unsigned char value, valp, parity; - static int nbits; - - if(sending) { - } else { - if(nbits > 0 && nbits < 9) { - value >>= 1; - if(PINB & 1) { - value |= 0x80; - parity ^= 1; - } - }/* else if(nbits == 9) { - valp = PINB & 1; - }*/ - if(++nbits >= 11) { - nbits = 0; - - /* check parity */ - /*if((parity & 1) == (valp & 1)) {}*/ - keybuf[key_wr] = (unsigned char)value; - key_wr = NEXT_IDX(key_wr); - - value = 0; - parity = 0; - } - } -} diff -r 3228a731d4db -r a4fd9c5a6655 src/ps2kbd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ps2kbd.c Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,92 @@ +#include +#include +#include +#include "ps2kbd.h" +#include "defs.h" + +#define BUF_SZ 16 +#define BUF_IDX_MASK (BUF_SZ - 1) +#define NEXT_IDX(x) (((x) + 1) & BUF_IDX_MASK) +static volatile unsigned char keybuf[BUF_SZ]; +static volatile unsigned char key_rd, key_wr; + +static volatile int sending; + +void ps2write(unsigned char c) +{ +#if 0 + int i; + unsigned short out = (unsigned short)c | ((unsigned short)(parity_even_bit(c) & 1) << 8); + + /* pull clock low for >60us */ + PS2LOW(BIT_CLK); + _delay_us(60); + + /* then pull data low and release clock */ + PS2LOW(BIT_DATA); + PS2REL(BIT_CLK); + + for(i=0; i<9; i++) { + while(PINB & BIT_CLK); /* wait for kbd to drive the clock low */ + PORTB |= out & 1; + out >>= 1; + while(!(PINB & BIT_CLK)); /* wait for kbd to drive the clock high */ + } + + PS2REL(BIT_DATA); + /* wait for ack */ + while(PINB & BIT_DATA); + while(!(PINB & BIT_DATA)); +#endif +} + +unsigned char ps2read(void) +{ + unsigned char key; + + while(key_rd == key_wr) { + } + + cli(); + key = keybuf[key_rd]; + key_rd = NEXT_IDX(key_rd); + sei(); + + return key; +} + +int ps2pending(void) +{ + return key_rd != key_wr; +} + +ISR(INT0_vect) +{ + static unsigned char value, parity; + /*static unsigned char valp;*/ + static int nbits; + + if(sending) { + } else { + if(nbits > 0 && nbits < 9) { + value >>= 1; + if(PIND & PDATA_BIT) { + value |= 0x80; + parity ^= 1; + } + }/* else if(nbits == 9) { + valp = (PIND >> PDATA) & 1; + }*/ + if(++nbits >= 11) { + nbits = 0; + + /* check parity */ + /*if((parity & 1) == (valp & 1)) {}*/ + keybuf[key_wr] = (unsigned char)value; + key_wr = NEXT_IDX(key_wr); + + value = 0; + parity = 0; + } + } +} diff -r 3228a731d4db -r a4fd9c5a6655 src/ps2kbd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ps2kbd.h Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,8 @@ +#ifndef PS2KBD_H_ +#define PS2KBD_H_ + +void ps2write(unsigned char c); +unsigned char ps2read(void); +int ps2pending(void); + +#endif /* PS2KBD_H_ */ diff -r 3228a731d4db -r a4fd9c5a6655 src/scantbl.h --- a/src/scantbl.h Sat Oct 14 07:23:47 2017 +0300 +++ b/src/scantbl.h Tue Oct 17 15:25:33 2017 +0300 @@ -1,6 +1,7 @@ #ifndef SCANTBL_H_ #define SCANTBL_H_ +/* enum { KEY_ESC = 27, @@ -29,35 +30,21 @@ KEY_APPS, KEY_ACPI_POWER, KEY_ACPI_SLEEP, KEY_ACPI_WAKEUP }; - - -static const char *skeystr[] = { - "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", - "SysRq", "Break", "Scroll Lock", "Caps Lock", "Num Lock", - "L Shift", "R Shift", "L Ctrl", "R Ctrl", "L Alt", "R Alt", "L Win", "R Win", "Menu", - "Insert", "Delete", "Home", "End", "Page Up", "Page Down", "Left", "Right", "Up", "Down", - "Keypad 0", "Keypad 1", "Keypad 2", "Keypad 3", "Keypad 4", "Keypad 5", "Keypad 6", - "Keypad 7", "Keypad 8", "Keypad 9", "Keypad /", "Keypad *", "Keypad -", "Keypad +", - "Keypad .", "Keypad Enter", - "WWW Search", "WWW Fav", "WWW Refresh", "WWW Stop", "WWW Fwd", "WWW Back", "WWW Home", - "Prev", "Next", "Play", "Stop", "Volume Up", "Volume Down", "Mute", "Calculator", - "My Computer", "Email", "Select Media", "Apps", - "Power", "Sleep", "Wakeup", -}; - +*/ #define KEYMAP_NORMAL_SIZE (sizeof keymap_normal / sizeof *keymap_normal) +#if 0 static int keymap_normal[] = { 0, KEY_F9, 0, KEY_F5, KEY_F3, KEY_F1, KEY_F2, KEY_F12, /* 00 - 07 */ 0, KEY_F10, KEY_F8, KEY_F6, KEY_F4, '\t', '`', 0, /* 08 - 0f */ - 0, KEY_LALT, KEY_LSHIFT, 0, KEY_LCTRL, 'q', '1', 0, /* 10 - 17 */ - 0, 0, 'z', 's', 'a', 'w', '2', 0, /* 18 - 1f */ - 0, 'c', 'x', 'd', 'e', '4', '3', 0, /* 20 - 27 */ - 0, ' ', 'v', 'f', 't', 'r', '5', 0, /* 28 - 2f */ - 0, 'n', 'b', 'h', 'g', 'y', '6', 0, /* 30 - 37 */ - 0, 0, 'm', 'j', 'u', '7', '8', 0, /* 38 - 3f */ - 0, ',', 'k', 'i', 'o', '0', '9', 0, /* 40 - 47 */ - 0, '.', '/', 'l', ';', 'p', '-', 0, /* 48 - 4f */ + 0, KEY_LALT, KEY_LSHIFT, 0, KEY_LCTRL, 'Q', '1', 0, /* 10 - 17 */ + 0, 0, 'Z', 'S', 'A', 'W', '2', 0, /* 18 - 1f */ + 0, 'C', 'X', 'D', 'E', '4', '3', 0, /* 20 - 27 */ + 0, ' ', 'V', 'F', 'T', 'R', '5', 0, /* 28 - 2f */ + 0, 'N', 'B', 'H', 'G', 'Y', '6', 0, /* 30 - 37 */ + 0, 0, 'M', 'J', 'U', '7', '8', 0, /* 38 - 3f */ + 0, ',', 'K', 'I', 'O', '0', '9', 0, /* 40 - 47 */ + 0, '.', '/', 'L', ';', 'P', '-', 0, /* 48 - 4f */ 0, 0, '\'', 0, '[', '=', 0, 0, /* 50 - 57 */ KEY_CAPSLK, KEY_RSHIFT, '\n', ']', 0, '\\', 0, 0, /* 58 - 5f */ 0, 0, 0, 0, 0, 0, '\b', 0, /* 60 - 67 */ @@ -66,8 +53,35 @@ KEY_F11, KEY_KP_PLUS, KEY_KP_3, KEY_KP_MINUS, KEY_KP_MUL, KEY_KP_9, KEY_SCRLK, 0,/* 78 - 7f */ 0, 0, 0, KEY_F7 /* 80 - 83 */ }; +#endif + +/* converts a normal (non-extended) PS/2 scancode to an amiga rawkey value + * caps lock -> control + * ctrl -> amiga + * F12 -> help + */ +static unsigned char keymap_normal[] = { + 0xff, 0x58, 0xff, 0x54, 0x52, 0x50, 0x51, 0x5f, /* 00 - 07: - f9 - f5 f3 f1 f2 f12 */ + 0xff, 0x59, 0x57, 0x55, 0x53, 0x42, 0x00, 0xff, /* 08 - 0f: - f10 f8 f6 f4 tab ` - */ + 0xff, 0x64, 0x60, 0xff, 0x66, 0x10, 0x01, 0xff, /* 10 - 17: - lalt lshift - lctrl(lamiga) Q 1 - */ + 0xff, 0xff, 0x31, 0x21, 0x20, 0x11, 0x02, 0xff, /* 18 - 1f: - - Z S A W 2 - */ + 0xff, 0x33, 0x32, 0x22, 0x12, 0x04, 0x03, 0xff, /* 20 - 27: - C X D E 4 3 - */ + 0xff, 0x40, 0x34, 0x23, 0x14, 0x13, 0x05, 0xff, /* 28 - 2f: - space V F T R 5 - */ + 0xff, 0x36, 0x35, 0x25, 0x24, 0x15, 0x06, 0xff, /* 30 - 37: - N B H G Y 6 - */ + 0xff, 0xff, 0x37, 0x26, 0x16, 0x07, 0x08, 0xff, /* 38 - 3f: - - M J U 7 8 - */ + 0xff, 0x38, 0x27, 0x17, 0x18, 0x0a, 0x09, 0xff, /* 40 - 47: - , K I O 0 9 - */ + 0xff, 0x39, 0x3a, 0x28, 0x29, 0x19, 0x0b, 0xff, /* 48 - 4f: - . / L ; P minus - */ + 0xff, 0xff, 0x2a, 0xff, 0x1a, 0x0c, 0xff, 0xff, /* 50 - 57: - - \ - [ = - - */ + 0x63, 0x61, 0x44, 0x1b, 0xff, 0x0d, 0xff, 0xff, /* 58 - 5f: caps rshift enter ] - \ - - */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x41, 0xff, /* 60 - 67: - - - - - - backsp - */ + 0xff, 0x1d, 0xff, 0x2d, 0x3d, 0xff, 0xff, 0xff, /* 68 - 6f: - KP1 - KP4 KP7 - - - */ + 0x0f, 0x3c, 0x1e, 0x2e, 0x2f, 0x3e, 0x45, 0x5a, /* 70 - 77: KP0 KP. KP2 KP5 KP6 KP8 esc numlk */ + 0xff, 0x5e, 0x1f, 0x4a, 0x5d, 0x3f, 0x5b, 0xff, /* 78 - 7f: f11 KP+ KP3 KP- KP* KP9 scrlk - */ + 0xff, 0xff, 0xff, 0x56 /* 80 - 83: - - - f7 */ +}; #define KEYMAP_EXT_SIZE (sizeof keymap_ext / sizeof *keymap_ext) +#if 0 static int keymap_ext[] = { 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 07 */ 0, 0, 0, 0, 0, 0, 0, 0, /* 08 - 0f */ @@ -77,11 +91,39 @@ KEY_MM_STOP, 0, 0, KEY_MM_CALC, 0, 0, 0, KEY_APPS, /* 28 - 2f */ KEY_MM_WWW_FWD, 0, KEY_MM_VOLUP, 0, KEY_MM_PLAY, 0, 0, KEY_ACPI_POWER, /* 30 - 37 */ KEY_MM_WWW_BACK, 0, KEY_MM_WWW_HOME, KEY_MM_STOP, 0, 0, 0, KEY_ACPI_SLEEP, /* 38 - 3f */ - KEY_MM_MYCOMP, 0, 0, 0, KEY_MM_EMAIL, 0, KEY_KP_DIV, 0, /* 40 - 47 */ - 0, KEY_MM_NEXT, 0, 0, KEY_MM_SELECT, 0, 0, 0, /* 48 - 4f */ - 0, 0, KEY_ACPI_WAKEUP, 0, 0, KEY_END, 0, KEY_LEFT, /* 50 - 57 */ - KEY_HOME, 0, 0, 0, KEY_INS, KEY_DEL, KEY_DOWN, 0, /* 58 - 5f */ - KEY_RIGHT, KEY_UP, 0, 0, 0, 0, KEY_DOWN, 0, /* 60 - 67 */ + KEY_MM_MYCOMP, 0, 0, 0, 0, 0, 0, 0, /* 40 - 47 */ + KEY_MM_EMAIL, 0, KEY_KP_DIV, 0, 0, KEY_MM_NEXT, 0, 0, /* 48 - 4f */ + KEY_MM_SELECT, 0, 0, 0, 0, 0, 0, 0, /* 50 - 57 */ + 0, 0, KEY_KP_ENTER, 0, 0, 0, KEY_ACPI_WAKEUP, 0, /* 58 - 5f */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 67 */ + 0, KEY_END, 0, KEY_LEFT, KEY_HOME, 0, 0, 0, /* 68 - 6f */ + KEY_INS, KEY_DEL, KEY_DOWN, 0, KEY_RIGHT, KEY_UP, 0, 0, /* 70 - 77 */ + 0, 0, KEY_PGDOWN, 0, 0, KEY_PGUP, 0, 0, /* 78 - 7f */ +}; +#endif + +static unsigned char keymap_ext[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 00 - 07: - - - - - - - - */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 08 - 0f: - - - - - - - - */ + 0xff, 0x65, 0xff, 0xff, 0x67, 0xff, 0xff, 0xff, /* 10 - 17: - ralt - - rctrl(ramiga) - - - */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x66, /* 18 - 1f: - - - - - - - lwin(lamiga) */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x67, /* 20 - 27: - - - - - - - rwin(ramiga) */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 28 - 2f */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 30 - 37 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 38 - 3f */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 40 - 47 */ + 0xff, 0xff, 0x5c, 0xff, 0xff, 0xff, 0xff, 0xff, /* 48 - 4f: - - KP/ - - - - - */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 50 - 57 */ + 0xff, 0xff, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, /* 58 - 5f: - - KP_enter - - - - - */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 60 - 67 */ + 0xff, 0x1d, 0xff, 0x4f, 0x3d, 0xff, 0xff, 0xff, /* 68 - 6f: - end - left home - - - */ + 0x0f, 0x46, 0x4d, 0xff, 0x4e, 0x4c, 0xff, 0xff, /* 70 - 77: ins del down - right up - - */ + 0xff, 0xff, 0x1f, 0xff, 0xff, 0x3f, 0xff, 0xff /* 78 - 7f: - - pgdown - - pgup - - */ }; +/* some useful keycodes */ +#define AMIKEY_CTRL 0x63 +#define AMIKEY_LAMI 0x66 +#define AMIKEY_RAMI 0x67 + #endif /* SCANTBL_H_ */ diff -r 3228a731d4db -r a4fd9c5a6655 src/serial.c --- a/src/serial.c Sat Oct 14 07:23:47 2017 +0300 +++ b/src/serial.c Tue Oct 17 15:25:33 2017 +0300 @@ -1,11 +1,11 @@ +#ifndef F_CPU #ifdef XTAL -#define F_CLK XTAL #define F_CPU XTAL #else #warning "compiled for 1mhz internal rc osc. serial comms won't work" -#define F_CLK 1000000 #define F_CPU 1000000 #endif +#endif #include #include @@ -30,7 +30,7 @@ void init_serial(long baud) { - unsigned int ubrr_val = F_CLK / 16 / baud - 1; + unsigned int ubrr_val = F_CPU / 16 / baud - 1; power_usart0_enable(); diff -r 3228a731d4db -r a4fd9c5a6655 src/timer.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer.c Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,35 @@ +#include +#include +#include +#include "timer.h" + +#define PRESCL_256 4 +/* 256 ticks per interrupt, 256 clock divisor */ +#define TICKS_PER_SEC (F_CPU / 256 / 256) + +static volatile unsigned long ticks; + +void init_timer(void) +{ + power_timer0_enable(); + + TCCR0A = 0; + TCCR0B = PRESCL_256; + + TIMSK0 |= (1 << TOIE0); /* enable ovf intr. */ +} + +void reset_timer(void) +{ + ticks = 0; +} + +unsigned long get_msec(void) +{ + return 1000 * ticks / TICKS_PER_SEC; +} + +ISR(TIMER0_OVF_vect) +{ + ++ticks; +} diff -r 3228a731d4db -r a4fd9c5a6655 src/timer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer.h Tue Oct 17 15:25:33 2017 +0300 @@ -0,0 +1,8 @@ +#ifndef TIMER_H_ +#define TIMER_H_ + +void init_timer(void); +void reset_timer(void); +unsigned long get_msec(void); + +#endif /* TIMER_H_ */