source: avrstuff/kbd/xtk/code/main.c@ c2c5ac9

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

Make XTK work (sort of).

  • Switch to atmega48P. No need for an atmega8 here.
  • Fix the XT keyboard protocol generation. It's fairly simple once understood.
  • Fix (mostly) the scancode conversion table

Things are rather glitchy, still. Since the XT protocol is not time critical at
all, this points to either:

  • Problems in the PS/2 scanning code
  • Errors in the scancode map

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

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