Changeset 8e1fb41 in avrstuff for kbd/xtk/code/main.c
- Timestamp:
- Jul 23, 2014, 7:31:42 PM (10 years ago)
- Branches:
- main
- Children:
- 4fbae10
- Parents:
- 9e3cc04
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kbd/xtk/code/main.c
r9e3cc04 r8e1fb41 5 5 #include <util/delay.h> 6 6 7 #include "../../ libs/ps2_keyboard/ps2_keyboard.h"7 #include "../../../libs/ps2_keyboard/ps2_keyboard.h" 8 8 9 uint8_t keys[16];9 static uint8_t key; 10 10 11 11 const uint8_t pcw[128] PROGMEM = { … … 25 25 { 26 26 uint8_t key_code = 0; 27 key_code = read_char(); // TODO this is blocking function27 key_code = read_char(); // TODO this function is blocking. Can it disturb main? 28 28 29 uint8_t decode = pgm_read_byte(&(pcw[key_code]));29 key = 0 /*pgm_read_byte(&(pcw[key_code]))*/; 30 30 if(release) 31 keys[decode >> 4] &= ~(1 << (decode & 0xF)); 32 else 33 keys[decode >> 4] |= 1 << (decode & 0xF); 31 key |= 0x80; 34 32 } 35 33 36 34 37 35 int main() { 38 init_keyboard(); 36 key = 0xFF; 37 init_keyboard(); // PS/2 KBD handler 39 38 40 41 42 DDRB = 0x6; // PB1 and PB2 as outputs 39 // PCW init - configure pins directions 40 PORTB = 0; 41 DDRB = 0; // PB2 and PB1 as inputs (floating) 43 42 44 45 43 //debug LED - output 44 DDRD |= (1<<PD6); 46 45 46 static const int PCLK = 2; 47 static const int PDAT = 4; 47 48 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); 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 62 55 63 // Address 64 for(int j = 4; --j >= 0;) 56 PORTD ^= (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++) 65 71 { 66 if(idx & (1<<j)) 67 PORTB = 4; 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; 68 78 else 69 PORTB = 0;79 DDRB |= PDAT; 70 80 71 // Clock 72 _delay_us(6); 73 PORTB |= 2; 74 _delay_us(12); 75 PORTB = 0; 76 _delay_us(21); 81 _delay_us(9); 82 83 k >>= 1; 77 84 } 78 85 79 // One "empty" clock cycle80 _delay_us( 21 + 33);86 DDRB &= ~PCLK; // CLK HI 87 _delay_us(66); 81 88 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 } 89 90 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; 91 return 0; 101 92 } 102 93
Note:
See TracChangeset
for help on using the changeset viewer.