Changeset c2c5ac9 in avrstuff


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

Location:
kbd/xtk/code
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kbd/xtk/code/Makefile

    r071dc14 rc2c5ac9  
    22OBJCOPY := $(shell { which avr-objcopy || which avr-objcopy-x86; } 2>/dev/null)
    33AVRDUDE := $(shell { which avrdude || which avrdude-x86; } 2>/dev/null)
     4
     5MCU=atmega48p
    46
    57keyboard.hex: keyboard.bin
     
    79
    810keyboard.bin: keyboard.o main.o
    9         $(CC) $^ -o $@ -mmcu=atmega8 -Os
     11        $(CC) $^ -o $@ -mmcu=$(MCU) -Os
    1012
    1113main.o: main.c ../../../libs/ps2_keyboard/ps2_keyboard.h
    12         $(CC) -std=c99 -c $< -mmcu=atmega8 -Os -o $@ -mmcu=atmega8 -Os
     14        $(CC) -std=c99 -c $< -mmcu=$(MCU) -Os -o $@ -Os
    1315
    1416keyboard.o: ../../../libs/ps2_keyboard/ps2_keyboard.c ../../../libs/ps2_keyboard/ps2_keyboard.h ../../../libs/ps2_keyboard/keymap.h
    15         $(CC) -DCALLBACK="callback();" -c $< -mmcu=atmega8 -Os -o $@
     17        $(CC) -DCALLBACK="callback();" -c $< -mmcu=$(MCU) -Os -o $@
     18
     19clean:
     20        rm *.o *.bin *.hex
    1621
    1722flash: keyboard.hex
    18         $(AVRDUDE) -c usbasp -p atmega8 -Uflash:w:$^
     23        $(AVRDUDE) -c usbasp -p $(MCU) -Uflash:w:$^
  • kbd/xtk/code/keyboard.hex

    r071dc14 rc2c5ac9  
    1 :1000000092C0A1C0A1C09FC09EC09DC09CC09BC00B
    2 :100010009AC099C098C097C096C095C094C093C02C
    3 :1000200092C091C090C03F3F3F3F3F3F3F3F3F3F67
    4 :100030003F3F3F3F3F3F3F3F3F3F3F71313F3F3FAC
    5 :100040007A736177323F3F6378646534333F3F2092
    6 :1000500076667472353F3F6E62686779363F3F3F20
    7 :100060006D6A7537383F3F3F6B696F30393F3F3FAF
    8 :100070003F6C3F703F3F3F3F3F3F3F3F3F3F3F3F32
    9 :100080003F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F80
     1:1000000099C0A8C0A8C0A6C0A5C0A4C0A3C0A2C0D3
     2:10001000A1C0A0C09FC09EC09DC09CC09BC09AC0F4
     3:1000200099C098C097C096C095C094C093C092C024
     4:1000300091C090C03F3F3F3F3F3F3F3F3F3F3F3F2B
     5:100040003F3F3F3F3F3F3F3F3F71313F3F3F7A732D
     6:100050006177323F3F6378646534333F3F20766693
     7:100060007472353F3F6E62686779363F3F3F6D6A15
     8:100070007537383F3F3F6B696F30393F3F3F3F6CCB
     9:100080003F703F3F3F3F3F3F3F3F3F3F3F3F3F3F4F
    1010:100090003F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F70
    11 :1000A0003F3F3F3F3F3F3F203FA000023F123F0303
    12 :1000B000A43F3F84263F3FA7263FA183803F3F3F89
    13 :1000C00087748573813F3F7677757270713F3F57B4
    14 :1000D00067656362613F3F5666546453603F3F3FCC
    15 :1000E00046555251503F3F2C45434240413F3F37D8
    16 :1000F00023443533313F3F3F3F1132303F3F862568
    17 :10010000222136343F3F3F3F3F3F3F3F973F3F171E
    18 :100110003F15243F3F3F01A60716051482A513276C
    19 :1001200006A3A204103F11241FBECFE5D4E0DEBF1A
    20 :10013000CDBF10E0A0E6B0E001C01D92A736B10728
    21 :10014000E1F7A5D0E3C05CCF1F920F920FB60F92DC
    22 :1001500011242F933F934F935F936F937F938F93CC
    23 :100160009F93AF93BF93EF93FF9383994EC080917A
    24 :100170006200811108C0849926C081E080936200EA
    25 :100180001092610027C020916100283090F4849B78
    26 :100190000CC03091640081E090E0022E01C0880F15
    27 :1001A0000A94EAF7382B309364002F5F20936100A4
    28 :1001B0002CC0283021F489E08093610026C0109281
    29 :1001C00062001092610080916400803F31F481E010
    30 :1001D000809366001092640018C090916400809132
    31 :1001E0006600923149F4811104C081E0809360007F
    32 :1001F0000CC01092600002C0882319F010926600B3
    33 :1002000004C081E08093630037D0FF91EF91BF91EC
    34 :10021000AF919F918F917F916F915F914F913F919E
    35 :100220002F910F900FBE0F901F901895E82FF0E0C0
    36 :10023000EA5DFF4F84919091600091118052089582
    37 :10024000809163008823E1F3109263008091640041
    38 :1002500008951092620010926400109261008B98D1
    39 :10026000839A85B7886085BF85B78B7F85BF8BB73D
    40 :1002700080688BBF78940895E3DF109265008091C9
    41 :100280006600882319F080E88093650008958FEF59
    42 :1002900080936500DEDF18BA17BA8E9A20E43FEF2C
    43 :1002A00082B3822782BB809165008F3F09F4FFCF24
    44 :1002B000CF5F30936500B99A4AE74A95F1F700C0DD
    45 :1002C000BA9880E38A95F1F788E090E0B998E7E082
    46 :1002D000F1E03197F1F700C00000B99AFAE7FA951A
    47 :1002E000F1F700C0C0FF02C0BA9801C0BA9A40E35B
    48 :1002F0004A95F1F7C6950197009741F7B99887E0BD
    49 :1003000091E00197F1F700C00000CACFF894FFCF49
     11:1000A0003F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F60
     12:1000B0003F3F3F3F3F433F3F3D3B3C58644442400E
     13:1000C0003E0F293F65382A701D10023F66712C1FB4
     14:1000D0001E11035B672E2D201205045C68392F2149
     15:1000E0001413065D693130232215075E6A723224CB
     16:1000F0001608095F6B332517180B0A6C3F34352639
     17:1001000027190C3F6D7328741A0D3F3F3A361C1B9C
     18:10011000752B63763F56773F793F0E7B3F4F7D4B84
     19:10012000477E3F6F5253504C4D480145574E514A00
     20:100130003749463F11241FBECFEFD2E0DEBFCDBF0F
     21:1001400021E0A0E0B1E001C01D92A730B207E1F7C5
     22:10015000AAD0F1C055CF1F920F920FB60F92112463
     23:100160002F933F934F935F936F937F938F939F93BF
     24:10017000AF93BF93EF93FF934B994EC080910201D1
     25:10018000811108C04C9926C081E080930201109231
     26:10019000010127C020910101283090F44C9B0CC034
     27:1001A0003091040181E090E0022E01C0880F0A9492
     28:1001B000EAF7382B309304012F5F209301012CC004
     29:1001C000283021F489E08093010126C010920201B9
     30:1001D0001092010180910401803F31F481E080930D
     31:1001E00006011092040118C090910401809106014B
     32:1001F000923149F4811104C081E0809300010CC068
     33:100200001092000102C0882319F01092060104C068
     34:1002100081E08093030135D0FF91EF91BF91AF91C1
     35:100220009F918F917F916F915F914F913F912F910E
     36:100230000F900FBE0F901F901895E82FF0E0EC5C28
     37:10024000FF4F849190910001911180520895809107
     38:1002500003018823E1F310920301809104010895C2
     39:1002600010920201109204011092010153984B9ACE
     40:1002700085B7886085BF85B78B7F85BFE99A7894FD
     41:100280000895E5DFE82FF0E0EC54FF4FE491E093B0
     42:10029000050180910601882329F08091050180687D
     43:1002A0008093050108958AEA80930501D9DF15B886
     44:1002B00014B8569A30E44FEF83B186708630E1F778
     45:1002C000809105018F3FE1F38BB183278BB920919A
     46:1002D000050140930501229887EC90E00197F1F722
     47:1002E00000C00000219AE7ECF0E03197F1F700C080
     48:1002F0000000219888E090E020FF02C0229801C011
     49:10030000229AE7ECF0E03197F1F700C00000219A63
     50:10031000E7ECF0E03197F1F700C000002198269556
     51:100320000197009749F722988FE891E00197F1F73C
     52:0A03300000C00000C1CFF894FFCF19
    5053:00000001FF
  • 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.