Changeset ea32107 in avrstuff for kbd/xtk/code/main.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.