Changeset ea32107 in avrstuff
- Timestamp:
- Jul 31, 2014, 10:13:43 PM (10 years ago)
- Branches:
- main
- Children:
- 87ab18e
- Parents:
- c7cc629
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kbd/common.mk
rc7cc629 rea32107 7 7 LIBS=../../../libs 8 8 9 CFLAGS=-DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -mmcu=$(MCU) -Os 10 11 # default target 12 all: $(MCU).hex 13 9 14 # Generic rules 10 15 %.hex: %.bin 11 16 $(OBJCOPY) -j .text -j .data -O ihex $^ $@ 12 17 18 $(MCU): 19 mkdir -p $(MCU) 20 21 flash: $(MCU).hex 22 $(AVRDUDE) -c usbasp -p $(MCU) -Uflash:w:$^ 23 13 24 clean: 14 25 rm *.bin *.o *.hex -
kbd/ps2toserial/code/Makefile
rc7cc629 rea32107 1 # Board settings 2 3 # K4KUSB 1 4 MCU=attiny2313 5 F_CPU=12000000 2 6 3 all: $(MCU).hex 7 # Generic settings 8 BAUD=9600 9 4 10 5 11 include ../../common.mk 6 7 $(MCU):8 mkdir -p $(MCU)9 12 10 13 $(MCU).bin: $(MCU)/keyboard.o $(MCU)/usart.o $(MCU)/main.o … … 12 15 13 16 $(MCU)/main.o: main.c $(LIBS)/usart/usart.h $(LIBS)/ps2_keyboard/ps2_keyboard.h $(MCU) 14 $(CC) -c $< -Os -o $@ -mmcu=$(MCU) -Os17 $(CC) $(CFLAGS) -c $< -o $@ 15 18 16 19 $(MCU)/usart.o: $(LIBS)/usart/usart.c $(LIBS)/usart/usart.h $(MCU) 17 $(CC) -c $< -o $@ -mmcu=$(MCU) -Os20 $(CC) $(CFLAGS) -c $< -o $@ 18 21 19 22 $(MCU)/keyboard.o: $(LIBS)/ps2_keyboard/ps2_keyboard.c $(LIBS)/ps2_keyboard/ps2_keyboard.h $(LIBS)/ps2_keyboard/keymap.h $(MCU) 20 $(CC) -c $< -mmcu=$(MCU) -Os-o $@23 $(CC) $(CFLAGS) -c $< -o $@ -
kbd/xtk/code/main.c
rc7cc629 rea32107 1 #define F_CPU 16000000UL2 3 1 #include <avr/io.h> 4 2 #include <avr/pgmspace.h> … … 39 37 init_keyboard(); // PS/2 KBD handler 40 38 41 // PCW init - configure pins directions42 PORTB = 0;43 DDRB = 0; // PB2 and PB1 as inputs (floating)44 39 45 //debug LED - output 46 DDRD |= (1<<PD6); 47 40 #ifdef __AVR_ATtiny2313__ 41 #define PORTXT PORTD 42 #define DDRXT DDRD 43 #define PINXT PIND 44 static const int PCLK = (1<<PD0); 45 static const int PDAT = (1<<PD1); 46 #else 47 #define PORTXT PORTB 48 #define DDRXT DDRB 49 #define PINXT PINB 48 50 static const int PCLK = (1<<PB1); 49 51 static const int PDAT = (1<<PB2); 52 #endif 53 54 static const int delay = 25; 55 56 // XT init - configure pins directions 57 PORTXT &= ~(PCLK | PDAT); 58 DDRXT &= ~(PCLK | PDAT); // both pins as inputs (floating) 59 60 DDRB |= (1<<PB2); // LED 50 61 51 62 uint8_t k; 52 63 while(1) { 53 while ((PINB & (PDAT|PCLK)) != (PDAT|PCLK)) 64 PORTB ^= (1<<PB2); // LED 65 66 while ((PINXT & (PDAT|PCLK)) != (PDAT|PCLK)) 54 67 ; // Wait for PC to be ready to receive data 55 68 56 69 while(key == 0xFF) 57 70 ; // Wait for data to send 58 59 PORTD ^= (1<<PD6);60 71 61 72 k = key; // local copy so we can receive another code from PS/2 … … 64 75 65 76 // SEND START BIT 66 DDR B&= ~PDAT; // DAT HI67 _delay_us( 50);68 DDR B|= PCLK; // CLK LOW69 _delay_us( 50);70 DDR B&= ~PCLK; // CLK HI77 DDRXT &= ~PDAT; // DAT HI 78 _delay_us(delay); 79 DDRXT |= PCLK; // CLK LOW 80 _delay_us(delay); 81 DDRXT &= ~PCLK; // CLK HI 71 82 72 83 for(int i = 0; i < 8; i++) 73 84 { 74 85 if (k & 1) 75 DDR B&= ~PDAT;86 DDRXT &= ~PDAT; 76 87 else 77 DDR B|= PDAT;88 DDRXT |= PDAT; 78 89 79 _delay_us( 50);80 DDR B|= PCLK; // CLK LOW81 _delay_us( 50);82 DDR B&= ~PCLK; // CLK HI90 _delay_us(delay); 91 DDRXT |= PCLK; // CLK LOW 92 _delay_us(delay); 93 DDRXT &= ~PCLK; // CLK HI 83 94 84 95 k >>= 1; 85 96 } 86 97 87 DDR B&= ~PDAT; // DAT HI98 DDRXT &= ~PDAT; // DAT HI 88 99 89 _delay_us( 100);100 _delay_us(delay * 2); 90 101 } 91 102 -
libs/ps2_keyboard/ps2_keyboard.c
rc7cc629 rea32107 21 21 #define PS2_PORT PIND 22 22 #define PS2_CLK PD3 /* Also INT1 */ 23 24 #ifdef __AVR_ATtiny2313__ 25 // K4KUSB modified board 26 #define PS2_DATA PD5 27 #else 28 // ENSSAT IR modified board 23 29 #define PS2_DATA PD4 30 #endif 24 31 25 32 static volatile uint8_t kbd_data; … … 107 114 108 115 //make PS2_CLK input pin 109 DDRD &= ~( 1<<PS2_CLK);116 DDRD &= ~((1<<PS2_CLK) | (1<<PS2_DATA)); 110 117 //turn on pullup resistor 111 118 PS2_PORT |= (1<<PS2_CLK);
Note:
See TracChangeset
for help on using the changeset viewer.