Changeset ea32107 in avrstuff


Ignore:
Timestamp:
Jul 31, 2014, 10:13:43 PM (10 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
87ab18e
Parents:
c7cc629
Message:

kbd: working XTK on ATtiny2313

  • Move more stuff to common.mk and handle multicpu support
  • Fix some pins mixups to get things working

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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kbd/common.mk

    rc7cc629 rea32107  
    77LIBS=../../../libs
    88
     9CFLAGS=-DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -mmcu=$(MCU) -Os
     10
     11# default target
     12all: $(MCU).hex
     13
    914# Generic rules
    1015%.hex: %.bin
    1116        $(OBJCOPY) -j .text -j .data -O ihex $^ $@
    1217
     18$(MCU):
     19        mkdir -p $(MCU)
     20
     21flash: $(MCU).hex
     22        $(AVRDUDE) -c usbasp -p $(MCU) -Uflash:w:$^
     23
    1324clean:
    1425        rm *.bin *.o *.hex
  • kbd/ps2toserial/code/Makefile

    rc7cc629 rea32107  
     1# Board settings
     2
     3# K4KUSB
    14MCU=attiny2313
     5F_CPU=12000000
    26
    3 all: $(MCU).hex
     7# Generic settings
     8BAUD=9600
     9
    410
    511include ../../common.mk
    6 
    7 $(MCU):
    8         mkdir -p $(MCU)
    912
    1013$(MCU).bin: $(MCU)/keyboard.o $(MCU)/usart.o $(MCU)/main.o
     
    1215
    1316$(MCU)/main.o: main.c $(LIBS)/usart/usart.h $(LIBS)/ps2_keyboard/ps2_keyboard.h $(MCU)
    14         $(CC) -c $< -Os -o $@ -mmcu=$(MCU) -Os
     17        $(CC) $(CFLAGS) -c $< -o $@
    1518
    1619$(MCU)/usart.o: $(LIBS)/usart/usart.c $(LIBS)/usart/usart.h $(MCU)
    17         $(CC) -c $< -o $@ -mmcu=$(MCU) -Os
     20        $(CC) $(CFLAGS) -c $< -o $@
    1821
    1922$(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 16000000UL
    2 
    31#include <avr/io.h>
    42#include <avr/pgmspace.h>
     
    3937        init_keyboard(); // PS/2 KBD handler
    4038
    41         // PCW init - configure pins directions
    42         PORTB = 0;
    43         DDRB = 0; // PB2 and PB1 as inputs (floating)
    4439
    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
    4850        static const int PCLK = (1<<PB1);
    4951        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
    5061
    5162        uint8_t k;
    5263        while(1) {
    53                 while ((PINB & (PDAT|PCLK)) != (PDAT|PCLK))
     64                PORTB ^= (1<<PB2); // LED
     65
     66                while ((PINXT & (PDAT|PCLK)) != (PDAT|PCLK))
    5467                        ; // Wait for PC to be ready to receive data
    5568
    5669                while(key == 0xFF)
    5770                        ; // Wait for data to send
    58 
    59                 PORTD ^= (1<<PD6);
    6071
    6172                k = key; // local copy so we can receive another code from PS/2
     
    6475
    6576                // SEND START BIT
    66                 DDRB &= ~PDAT; // DAT HI
    67                 _delay_us(50);
    68                 DDRB |= PCLK; // CLK LOW
    69                 _delay_us(50);
    70                 DDRB &= ~PCLK; // CLK HI
     77                DDRXT &= ~PDAT; // DAT HI
     78                _delay_us(delay);
     79                DDRXT |= PCLK; // CLK LOW
     80                _delay_us(delay);
     81                DDRXT &= ~PCLK; // CLK HI
    7182
    7283                for(int i = 0; i < 8; i++)
    7384                {
    7485                        if (k & 1)
    75                                 DDRB &= ~PDAT;
     86                                DDRXT &= ~PDAT;
    7687                        else
    77                                 DDRB |= PDAT;
     88                                DDRXT |= PDAT;
    7889
    79                         _delay_us(50);
    80                         DDRB |= PCLK; // CLK LOW
    81                         _delay_us(50);
    82                         DDRB &= ~PCLK; // CLK HI
     90                        _delay_us(delay);
     91                        DDRXT |= PCLK; // CLK LOW
     92                        _delay_us(delay);
     93                        DDRXT &= ~PCLK; // CLK HI
    8394
    8495                        k >>= 1;
    8596                }
    8697
    87                 DDRB &= ~PDAT; // DAT HI
     98                DDRXT &= ~PDAT; // DAT HI
    8899
    89                 _delay_us(100);
     100                _delay_us(delay * 2);
    90101        }
    91102
  • libs/ps2_keyboard/ps2_keyboard.c

    rc7cc629 rea32107  
    2121#define PS2_PORT PIND
    2222#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
    2329#define PS2_DATA PD4
     30#endif
    2431
    2532static volatile uint8_t kbd_data;
     
    107114
    108115  //make PS2_CLK input pin
    109   DDRD &= ~(1<<PS2_CLK);
     116  DDRD &= ~((1<<PS2_CLK) | (1<<PS2_DATA));
    110117  //turn on pullup resistor
    111118  PS2_PORT |= (1<<PS2_CLK);
Note: See TracChangeset for help on using the changeset viewer.