Changeset c2c5ac9 in avrstuff for kbd/xtk/code/main.c
- Timestamp:
- Jul 23, 2014, 11:19:14 PM (10 years ago)
- Branches:
- main
- Children:
- 39e523d
- Parents:
- 071dc14
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kbd/xtk/code/main.c
r071dc14 rc2c5ac9 7 7 #include "../../../libs/ps2_keyboard/ps2_keyboard.h" 8 8 9 static uint8_t key;9 static volatile uint8_t key; 10 10 11 const uint8_t pcw[128] PROGMEM = {11 const uint8_t at2xt[128] PROGMEM = { 12 12 // 0 1 2 3 4 5 6 7 8 9 A B C D E F 13 '?' ,0x 20,'?' ,0xA0,0x00,0x02,'?' ,0x12,'?' ,0x03,0xA4,'?' ,'?' ,0x84,0x26,'?', // 014 '?' ,0xA7,0x26,'?' ,0xA1,0x83,0x80,'?' ,'?' ,'?' ,0x87,0x74,0x85,0x73,0x81,'?', // 115 '?' ,0x76,0x77,0x75,0x72,0x70,0x71,'?' ,'?' ,0x57,0x67,0x65,0x63,0x62,0x61,'?', // 216 '?' ,0x56,0x66,0x54,0x64,0x53,0x60,'?' ,'?' ,'?' ,0x46,0x55,0x52,0x51,0x50,'?', // 317 '?' ,',' ,0x45,0x43,0x42,0x40,0x41,'?' ,'?' ,0x37,0x23,0x44,0x35,0x33,0x31,'?', // 418 '?' ,'?' ,'?' ,0x11,0x32,0x30,'?' ,'?' ,0x86,0x25,0x22,0x21,0x36,0x34,'?' ,'?', // 519 '?' , '?' ,'?' ,'?' ,'?' ,'?' ,0x97,'?' ,'?' ,0x17,'?' ,0x15,0x24,'?' ,'?' ,'?', // 620 0x 01,0xA6,0x07,0x16,0x05,0x14,0x82,0xA5,0x13,0x27,0x06,0xA3,0xA2,0x04,0x10,'?' // 713 '?' ,0x43,'?' ,0x3F,0x3D,0x3B,0x3C,0x58,0x64,0x44,0x42,0x40,0x3E,0x0F,0x29,'?', // 0 14 0x65,0x38,0x2A,0x70,0x1D,0x10,0x02,'?' ,0x66,0x71,0x2C,0x1F,0x1E,0x11,0x03,0x5B, // 1 15 0x67,0x2E,0x2D,0x20,0x12,0x05,0x04,0x5C,0x68,0x39,0x2F,0x21,0x14,0x13,0x06,0x5D, // 2 16 0x69,0x31,0x30,0x23,0x22,0x15,0x07,0x5E,0x6A,0x72,0x32,0x24,0x16,0x08,0x09,0x5F, // 3 17 0x6B,0x33,0x25,0x17,0x18,0x0B,0x0A,0x6C,'?' ,0x34,0x35,0x26,0x27,0x19,0x0C,'?', // 4 18 0x6D,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 20 0x52,0x53,0x50,0x4C,0x4D,0x48,0x01,0x45,0x57,0x4E,0x51,0x4A,0x37,0x49,0x46,'?' // 7 21 21 }; 22 22 23 // 83 > 41 (F7) 24 // 84 > 54 (SysRq) 23 25 24 26 void callback() … … 27 29 key_code = read_char(); // TODO this function is blocking. Can it disturb main? 28 30 29 key = 0 /*pgm_read_byte(&(pcw[key_code]))*/;31 key = pgm_read_byte(&(at2xt[key_code])); 30 32 if(release) 31 33 key |= 0x80; … … 34 36 35 37 int main() { 36 key = 0x FF;38 key = 0xAA; 37 39 init_keyboard(); // PS/2 KBD handler 38 40 … … 44 46 DDRD |= (1<<PD6); 45 47 46 static const int PCLK = 2;47 static const int PDAT = 4;48 static const int PCLK = (1<<PB1); 49 static const int PDAT = (1<<PB2); 48 50 49 51 uint8_t k; 50 52 while(1) { 51 #if 0 52 while ((PINB & 2) == 0) 53 while ((PINB & (PDAT|PCLK)) != (PDAT|PCLK)) 53 54 ; // Wait for PC to be ready to receive data 54 #endif55 55 56 PORTD ^= (1<<PD6);57 56 while(key == 0xFF) 58 57 ; // Wait for data to send 59 58 60 k = k+1; /*key;*/ // local copy so we can receive another code from PS/2 59 PORTD ^= (1<<PD6); 60 61 k = key; // local copy so we can receive another code from PS/2 61 62 // before we're done sending this one. 62 63 key = 0xFF; 63 64 64 65 // SEND START BIT 66 DDRB &= ~PDAT; // DAT HI 67 _delay_us(50); 65 68 DDRB |= PCLK; // CLK LOW 66 _delay_us(23); 67 DDRB &= ~PDAT; // DAT HI 68 _delay_us(9); 69 _delay_us(50); 70 DDRB &= ~PCLK; // CLK HI 69 71 70 72 for(int i = 0; i < 8; i++) 71 73 { 72 DDRB &= ~PCLK; // CLK HI73 _delay_us(66);74 DDRB |= PCLK; // CLK LOW75 _delay_us(23);76 74 if (k & 1) 77 75 DDRB &= ~PDAT; … … 79 77 DDRB |= PDAT; 80 78 81 _delay_us(9); 79 _delay_us(50); 80 DDRB |= PCLK; // CLK LOW 81 _delay_us(50); 82 DDRB &= ~PCLK; // CLK HI 82 83 83 84 k >>= 1; 84 85 } 85 86 86 DDRB &= ~PCLK; // CLK HI 87 _delay_us(66); 87 DDRB &= ~PDAT; // DAT HI 88 88 89 _delay_us(100); 89 90 } 90 91
Note:
See TracChangeset
for help on using the changeset viewer.