Changeset 8e1fb41 in avrstuff for kbd/xtk/code/main.c


Ignore:
Timestamp:
Jul 23, 2014, 7:31:42 PM (10 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
4fbae10
Parents:
9e3cc04
Message:

Start modifying PCW code for XT.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kbd/xtk/code/main.c

    r9e3cc04 r8e1fb41  
    55#include <util/delay.h>
    66
    7 #include "../../libs/ps2_keyboard/ps2_keyboard.h"
     7#include "../../../libs/ps2_keyboard/ps2_keyboard.h"
    88
    9 uint8_t keys[16];
     9static uint8_t key;
    1010
    1111const uint8_t pcw[128] PROGMEM = {
     
    2525{
    2626        uint8_t key_code = 0;
    27         key_code = read_char(); // TODO this is blocking function
     27        key_code = read_char(); // TODO this function is blocking. Can it disturb main?
    2828
    29         uint8_t decode = pgm_read_byte(&(pcw[key_code]));
     29        key = 0 /*pgm_read_byte(&(pcw[key_code]))*/;
    3030        if(release)
    31                 keys[decode >> 4] &= ~(1 << (decode & 0xF));
    32         else
    33                 keys[decode >> 4] |= 1 << (decode & 0xF);
     31                key |= 0x80;
    3432}
    3533
    3634
    3735int main() {
    38   init_keyboard();
     36        key = 0xFF;
     37        init_keyboard(); // PS/2 KBD handler
    3938
    40   // PCW init - configure pins directions
    41   PORTB = 0;
    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)
    4342
    44   //debug LED - output
    45   DDRD |= (1<<PD6);
     43        //debug LED - output
     44        DDRD |= (1<<PD6);
    4645
     46        static const int PCLK = 2;
     47        static const int PDAT = 4;
    4748
    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
    6255
    63                 // Address
    64                 for(int j = 4; --j >= 0;)
     56PORTD ^= (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++)
    6571                {
    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;
    6878                        else
    69                                 PORTB = 0;
     79                                DDRB |= PDAT;
    7080
    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;
    7784                }
    7885
    79                 // One "empty" clock cycle
    80                 _delay_us(21 + 33);
     86                DDRB &= ~PCLK; // CLK HI
     87                _delay_us(66);
    8188
    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        }
    8990
    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;
    10192}
    10293
Note: See TracChangeset for help on using the changeset viewer.