source: avrstuff/kbd/xtk/code/main.c@ 87ab18e

main
Last change on this file since 87ab18e was 87ab18e, checked in by Adrien Destugues <pulkomandy@…>, 10 years ago

Drop hacked "shift" handling from libps2.

  • It's up to clients to do that if they wish so (useful if you're converting

to ASCII, for example, but not for a regular keyboard adapter)

Improve callback system to handle release events.

  • The callback would only be called for pressed keys, not for releases, leading

to weird results. Things work much better now in XTK.

  • Also ignore the E0 byte for extended keys in XTK. This avoids apps going

crazy as the Turbo XT BIOS doesn't handle it right.

git-svn-id: svn://pulkomandy.tk/avrstuff@114 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#include <avr/io.h>
2#include <avr/pgmspace.h>
3#include <util/delay.h>
4
5#include "../../../libs/ps2_keyboard/ps2_keyboard.h"
6
7static volatile uint8_t key;
8
9const uint8_t at2xt[128] PROGMEM = {
10// 0 1 2 3 4 5 6 7 8 9 A B C D E F
11'?' ,0x43,'?' ,0x3F,0x3D,0x3B,0x3C,0x58,0x64,0x44,0x42,0x40,0x3E,0x0F,0x29,'?', // 0
120x65,0x38,0x2A,0x70,0x1D,0x10,0x02,'?' ,0x66,0x71,0x2C,0x1F,0x1E,0x11,0x03,0x5B, // 1
130x67,0x2E,0x2D,0x20,0x12,0x05,0x04,0x5C,0x68,0x39,0x2F,0x21,0x14,0x13,0x06,0x5D, // 2
140x69,0x31,0x30,0x23,0x22,0x15,0x07,0x5E,0x6A,0x72,0x32,0x24,0x16,0x08,0x09,0x5F, // 3
150x6B,0x33,0x25,0x17,0x18,0x0B,0x0A,0x6C,'?' ,0x34,0x35,0x26,0x27,0x19,0x0C,'?', // 4
160x6D,0x73,0x28,0x74,0x1A,0x0D,'?' ,'?' ,0x3A,0x36,0x1C,0x1B,0x75,0x2B,0x63,0x76, // 5
17'?' ,0x56,0x77,'?' ,0x79,'?' ,0x0E,0x7B,'?' ,0x4F,0x7D,0x4B,0x47,0x7E,'?' ,0x6F, // 6
180x52,0x53,0x50,0x4C,0x4D,0x48,0x01,0x45,0x57,0x4E,0x51,0x4A,0x37,0x49,0x46,'?' // 7
19};
20
21// 83 > 41 (F7)
22// 84 > 54 (SysRq)
23
24void callback()
25{
26 // Ignore all keys above 0x80, and importantly ignore 0xE0 from extended keys.
27 if (kbd_data < 0x80) {
28 key = pgm_read_byte(&(at2xt[kbd_data]));
29 if(release)
30 key |= 0x80;
31 }
32}
33
34
35int main() {
36 key = 0xAA;
37 init_keyboard(); // PS/2 KBD handler
38
39
40#ifdef __AVR_ATtiny2313__
41#define PORTXT PORTD
42#define DDRXT DDRD
43#define PINXT PIND
44 static const int PCLK = (1<<PD0);
45 static const int PDAT = (1<<PD1);
46#else
47#define PORTXT PORTB
48#define DDRXT DDRB
49#define PINXT PINB
50 static const int PCLK = (1<<PB1);
51 static const int PDAT = (1<<PB2);
52#endif
53
54 static const int delay = 12;
55
56 // XT init - configure pins directions
57 PORTXT &= ~(PCLK | PDAT);
58 DDRXT &= ~(PCLK | PDAT); // both pins as inputs (floating)
59
60 uint8_t k;
61 while(1) {
62 while ((PINXT & (PDAT|PCLK)) != (PDAT|PCLK))
63 ; // Wait for PC to be ready to receive data
64
65 while(key == 0xFF)
66 ; // Wait for data to send
67
68 k = key; // local copy so we can receive another code from PS/2
69 // before we're done sending this one.
70 key = 0xFF;
71
72 // SEND START BIT
73 DDRXT &= ~PDAT; // DAT HI
74 _delay_us(delay);
75 DDRXT |= PCLK; // CLK LOW
76 _delay_us(delay);
77 DDRXT &= ~PCLK; // CLK HI
78
79 for(int i = 0; i < 8; i++)
80 {
81 if (k & 1)
82 DDRXT &= ~PDAT;
83 else
84 DDRXT |= PDAT;
85
86 _delay_us(delay);
87 DDRXT |= PCLK; // CLK LOW
88 _delay_us(delay);
89 DDRXT &= ~PCLK; // CLK HI
90
91 k >>= 1;
92 }
93
94 DDRXT &= ~PDAT; // DAT HI
95
96 _delay_us(delay * 2);
97 }
98
99 return 0;
100}
101
Note: See TracBrowser for help on using the repository browser.