source: avrstuff/kbd/xtk/code/main.c@ 8e1fb41

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

Start modifying PCW code for XT.

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

  • Property mode set to 100644
File size: 2.2 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 uint8_t key;
10
11const uint8_t pcw[128] PROGMEM = {
12// 0 1 2 3 4 5 6 7 8 9 A B C D E F
13'?' ,0x20,'?' ,0xA0,0x00,0x02,'?' ,0x12,'?' ,0x03,0xA4,'?' ,'?' ,0x84,0x26,'?', // 0
14'?' ,0xA7,0x26,'?' ,0xA1,0x83,0x80,'?' ,'?' ,'?' ,0x87,0x74,0x85,0x73,0x81,'?', // 1
15'?' ,0x76,0x77,0x75,0x72,0x70,0x71,'?' ,'?' ,0x57,0x67,0x65,0x63,0x62,0x61,'?', // 2
16'?' ,0x56,0x66,0x54,0x64,0x53,0x60,'?' ,'?' ,'?' ,0x46,0x55,0x52,0x51,0x50,'?', // 3
17'?' ,',' ,0x45,0x43,0x42,0x40,0x41,'?' ,'?' ,0x37,0x23,0x44,0x35,0x33,0x31,'?', // 4
18'?' ,'?' ,'?' ,0x11,0x32,0x30,'?' ,'?' ,0x86,0x25,0x22,0x21,0x36,0x34,'?' ,'?', // 5
19'?' ,'?' ,'?' ,'?' ,'?' ,'?' ,0x97,'?' ,'?' ,0x17,'?' ,0x15,0x24,'?' ,'?' ,'?', // 6
200x01,0xA6,0x07,0x16,0x05,0x14,0x82,0xA5,0x13,0x27,0x06,0xA3,0xA2,0x04,0x10,'?' // 7
21};
22
23
24void callback()
25{
26 uint8_t key_code = 0;
27 key_code = read_char(); // TODO this function is blocking. Can it disturb main?
28
29 key = 0 /*pgm_read_byte(&(pcw[key_code]))*/;
30 if(release)
31 key |= 0x80;
32}
33
34
35int main() {
36 key = 0xFF;
37 init_keyboard(); // PS/2 KBD handler
38
39 // PCW init - configure pins directions
40 PORTB = 0;
41 DDRB = 0; // PB2 and PB1 as inputs (floating)
42
43 //debug LED - output
44 DDRD |= (1<<PD6);
45
46 static const int PCLK = 2;
47 static const int PDAT = 4;
48
49 uint8_t k;
50 while(1) {
51#if 0
52 while ((PINB & 2) == 0)
53 ; // Wait for PC to be ready to receive data
54#endif
55
56PORTD ^= (1<<PD6);
57 while(key == 0xFF)
58 ; // Wait for data to send
59
60 k = k+1; /*key;*/ // local copy so we can receive another code from PS/2
61 // before we're done sending this one.
62 key = 0xFF;
63
64 // SEND START BIT
65 DDRB |= PCLK; // CLK LOW
66 _delay_us(23);
67 DDRB &= ~PDAT; // DAT HI
68 _delay_us(9);
69
70 for(int i = 0; i < 8; i++)
71 {
72 DDRB &= ~PCLK; // CLK HI
73 _delay_us(66);
74 DDRB |= PCLK; // CLK LOW
75 _delay_us(23);
76 if (k & 1)
77 DDRB &= ~PDAT;
78 else
79 DDRB |= PDAT;
80
81 _delay_us(9);
82
83 k >>= 1;
84 }
85
86 DDRB &= ~PCLK; // CLK HI
87 _delay_us(66);
88
89 }
90
91 return 0;
92}
93
Note: See TracBrowser for help on using the repository browser.