source: avrstuff/kbd/pcwk/code/main.c@ a3eb2c6

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

Move all the keyboard stuff to a subdirectory.

git-svn-id: svn://pulkomandy.tk/avrstuff@94 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
9uint8_t keys[16];
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 is blocking function
28
29 uint8_t decode = pgm_read_byte(&(pcw[key_code]));
30 if(release)
31 keys[decode >> 4] &= ~(1 << (decode & 0xF));
32 else
33 keys[decode >> 4] |= 1 << (decode & 0xF);
34}
35
36
37int main() {
38 init_keyboard();
39
40 // PCW init - configure pins directions
41 PORTB = 0;
42 DDRB = 0x6; // PB1 and PB2 as outputs
43
44 //debug LED - output
45 DDRD |= (1<<PD6);
46
47
48 while(1) {
49 for(int idx = -1; idx < 16; idx++)
50 {
51 // send data to PCW
52
53 // Start pulse
54 PORTB = 4;
55 _delay_us(6);
56 PORTB = 0;
57 _delay_us(6);
58 PORTB = 4;
59 _delay_us(6);
60 PORTB = 0;
61 _delay_us(6);
62
63 // Address
64 for(int j = 4; --j >= 0;)
65 {
66 if(idx & (1<<j))
67 PORTB = 4;
68 else
69 PORTB = 0;
70
71 // Clock
72 _delay_us(6);
73 PORTB |= 2;
74 _delay_us(12);
75 PORTB = 0;
76 _delay_us(21);
77 }
78
79 // One "empty" clock cycle
80 _delay_us(21 + 33);
81
82 // Data
83 for(int j = 8; --j >= 0;)
84 {
85 if (keys[idx & 0xF] & (1 << j))
86 PORTB = 4;
87 else
88 PORTB = 0;
89
90 // Clock
91 _delay_us(6);
92 PORTB |= 2;
93 _delay_us(12);
94 PORTB = 0;
95 _delay_us(21);
96 }
97 }
98 }
99
100 return 0;
101}
102
Note: See TracBrowser for help on using the repository browser.