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


Ignore:
Timestamp:
Jul 23, 2014, 11:19:14 PM (10 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
39e523d
Parents:
071dc14
Message:

Make XTK work (sort of).

  • Switch to atmega48P. No need for an atmega8 here.
  • Fix the XT keyboard protocol generation. It's fairly simple once understood.
  • Fix (mostly) the scancode conversion table

Things are rather glitchy, still. Since the XT protocol is not time critical at
all, this points to either:

  • Problems in the PS/2 scanning code
  • Errors in the scancode map

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

File:
1 edited

Legend:

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

    r071dc14 rc2c5ac9  
    77#include "../../../libs/ps2_keyboard/ps2_keyboard.h"
    88
    9 static uint8_t key;
     9static volatile uint8_t key;
    1010
    11 const uint8_t pcw[128] PROGMEM = {
     11const uint8_t at2xt[128] PROGMEM = {
    1212// 0   1   2   3    4    5    6    7    8    9    A    B    C    D    E    F
    13 '?' ,0x20,'?' ,0xA0,0x00,0x02,'?' ,0x12,'?' ,0x03,0xA4,'?' ,'?' ,0x84,0x26,'?', // 0
    14 '?' ,0xA7,0x26,'?' ,0xA1,0x83,0x80,'?' ,'?' ,'?' ,0x87,0x74,0x85,0x73,0x81,'?', // 1
    15 '?' ,0x76,0x77,0x75,0x72,0x70,0x71,'?' ,'?' ,0x57,0x67,0x65,0x63,0x62,0x61,'?', // 2
    16 '?' ,0x56,0x66,0x54,0x64,0x53,0x60,'?' ,'?' ,'?' ,0x46,0x55,0x52,0x51,0x50,'?', // 3
    17 '?' ,',' ,0x45,0x43,0x42,0x40,0x41,'?' ,'?' ,0x37,0x23,0x44,0x35,0x33,0x31,'?', // 4
    18 '?' ,'?' ,'?' ,0x11,0x32,0x30,'?' ,'?' ,0x86,0x25,0x22,0x21,0x36,0x34,'?' ,'?', // 5
    19 '?' ,'?' ,'?' ,'?' ,'?' ,'?' ,0x97,'?' ,'?' ,0x17,'?' ,0x15,0x24,'?' ,'?' ,'?', // 6
    20 0x01,0xA6,0x07,0x16,0x05,0x14,0x82,0xA5,0x13,0x27,0x06,0xA3,0xA2,0x04,0x10,'?'  // 7
     13'?' ,0x43,'?' ,0x3F,0x3D,0x3B,0x3C,0x58,0x64,0x44,0x42,0x40,0x3E,0x0F,0x29,'?', // 0
     140x65,0x38,0x2A,0x70,0x1D,0x10,0x02,'?' ,0x66,0x71,0x2C,0x1F,0x1E,0x11,0x03,0x5B, // 1
     150x67,0x2E,0x2D,0x20,0x12,0x05,0x04,0x5C,0x68,0x39,0x2F,0x21,0x14,0x13,0x06,0x5D, // 2
     160x69,0x31,0x30,0x23,0x22,0x15,0x07,0x5E,0x6A,0x72,0x32,0x24,0x16,0x08,0x09,0x5F, // 3
     170x6B,0x33,0x25,0x17,0x18,0x0B,0x0A,0x6C,'?' ,0x34,0x35,0x26,0x27,0x19,0x0C,'?', // 4
     180x6D,0x73,0x28,0x74,0x1A,0x0D,'?' ,'?' ,0x3A,0x36,0x1C,0x1B,0x75,0x2B,0x63,0x76, // 5
     19'?' ,0x56,0x77,'?' ,0x79,'?' ,0x0E,0x7B,'?' ,0x4F,0x7D,0x4B,0x47,0x7E,'?' ,0x6F, // 6
     200x52,0x53,0x50,0x4C,0x4D,0x48,0x01,0x45,0x57,0x4E,0x51,0x4A,0x37,0x49,0x46,'?'  // 7
    2121};
    2222
     23// 83 > 41 (F7)
     24// 84 > 54 (SysRq)
    2325
    2426void callback()
     
    2729        key_code = read_char(); // TODO this function is blocking. Can it disturb main?
    2830
    29         key = 0 /*pgm_read_byte(&(pcw[key_code]))*/;
     31        key = pgm_read_byte(&(at2xt[key_code]));
    3032        if(release)
    3133                key |= 0x80;
     
    3436
    3537int main() {
    36         key = 0xFF;
     38        key = 0xAA;
    3739        init_keyboard(); // PS/2 KBD handler
    3840
     
    4446        DDRD |= (1<<PD6);
    4547
    46         static const int PCLK = 2;
    47         static const int PDAT = 4;
     48        static const int PCLK = (1<<PB1);
     49        static const int PDAT = (1<<PB2);
    4850
    4951        uint8_t k;
    5052        while(1) {
    51 #if 0
    52                 while ((PINB & 2) == 0)
     53                while ((PINB & (PDAT|PCLK)) != (PDAT|PCLK))
    5354                        ; // Wait for PC to be ready to receive data
    54 #endif
    5555
    56 PORTD ^= (1<<PD6);
    5756                while(key == 0xFF)
    5857                        ; // Wait for data to send
    5958
    60                 k = k+1; /*key;*/ // local copy so we can receive another code from PS/2
     59                PORTD ^= (1<<PD6);
     60
     61                k = key; // local copy so we can receive another code from PS/2
    6162                // before we're done sending this one.
    6263                key = 0xFF;
    6364
    6465                // SEND START BIT
     66                DDRB &= ~PDAT; // DAT HI
     67                _delay_us(50);
    6568                DDRB |= PCLK; // CLK LOW
    66                 _delay_us(23);
    67                 DDRB &= ~PDAT; // DAT HI
    68                 _delay_us(9);
     69                _delay_us(50);
     70                DDRB &= ~PCLK; // CLK HI
    6971
    7072                for(int i = 0; i < 8; i++)
    7173                {
    72                         DDRB &= ~PCLK; // CLK HI
    73                         _delay_us(66);
    74                         DDRB |= PCLK; // CLK LOW
    75                         _delay_us(23);
    7674                        if (k & 1)
    7775                                DDRB &= ~PDAT;
     
    7977                                DDRB |= PDAT;
    8078
    81                         _delay_us(9);
     79                        _delay_us(50);
     80                        DDRB |= PCLK; // CLK LOW
     81                        _delay_us(50);
     82                        DDRB &= ~PCLK; // CLK HI
    8283
    8384                        k >>= 1;
    8485                }
    8586
    86                 DDRB &= ~PCLK; // CLK HI
    87                 _delay_us(66);
     87                DDRB &= ~PDAT; // DAT HI
    8888
     89                _delay_us(100);
    8990        }
    9091
Note: See TracChangeset for help on using the changeset viewer.