Changeset de0f65f in avrstuff


Ignore:
Timestamp:
Nov 21, 2010, 4:38:41 PM (13 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
df91872
Parents:
86824a6
Message:

Final working version.

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

Location:
starkadroid/code
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • starkadroid/code/main.c

    r86824a6 rde0f65f  
    1717#define PORTOUT PORTC
    1818
    19 static uint8_t reportBuffer[6];
     19static uint8_t reportBuffer[5];
     20static uint8_t buttons[6];
    2021static uint8_t idleRate;
    2122
    2223void main() {
    23         bool which = false;
    24         uint8_t idleCounter = 0;
    25 
    2624        wdt_enable(WDTO_2S);
    2725
     
    3432        PORTOUT = 255; // Enable pull up
    3533                // We put all pins as input then output a 0 in only one at a time.
    36                 // All the other pins are high-Z to avoid short circuits when many buttons are pressed.
     34                // All the other pins are high-Z to avoid short circuits when many
     35                // buttons are pressed.
    3736        DDRIN = 0; // Keyboard matrix in
    3837        PORTIN = 255; // Enable pull up
     
    4140    TCCR0 = 4;          // timer 0 prescaler: 256
    4241
     42        reportBuffer[0] = 0;
     43        doReport = false;
     44
    4345        while(1) {
    4446                wdt_reset();
    4547                usbPoll();
    4648
    47                 doReport = false;
    48                 for(char i = 0; i != 6; i++) {
     49                for(int i = 0; i != 6; i++) {
    4950                        DDROUT = 1<<i;
    5051                        PORTOUT = ~(1<<i);
    51                         if (reportBuffer[i] != ((~PININ)&0x3F))
     52                        _delay_us(63);
     53                        if (buttons[i] != ((~PININ)&0x3F))
     54                        {
    5255                                doReport = true;
    53                         reportBuffer[i] = (~PININ)&0x3F;
     56                                buttons[i] = (~PININ)&0x3F;
     57                        }
    5458                }
    5559                DDROUT = 0;
    5660                PORTOUT = 255;
     61
     62                // Copy lines 1 to 3 to the same lines in the report
     63                for(int i=1; i != 4; i++) {
     64                        reportBuffer[i] = buttons[i];
     65                }
     66
     67                // Dispatch line 0 to report 1,2,3 (2 buttons each)
     68                reportBuffer[1] |= (buttons[0] << 4)&0xC0;
     69                reportBuffer[2] |= (buttons[0] << 2)&0xC0;
     70                reportBuffer[3] |= (buttons[0])&0xC0;
     71
     72                // Copy part line 6
     73                reportBuffer[4] = buttons[5]; // 2 btns left here
     74                //reportBuffer[0] = buttons[4]; // this line is unused anyway, report as
     75                                                                          // axis
    5776
    5877                if (doReport && usbInterruptIsReady()) {
     
    7089char PROGMEM usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {
    7190        0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    72     0x09, 0x05,                    // USAGE (Game Pad)
     91    0x09, 0x04,                    // USAGE (Joystick)
    7392    0xa1, 0x01,                    // COLLECTION (Application)
    74     0xa1, 0x00,                    //   COLLECTION (Physical)
     93    0xa1, 0x02,                    //   COLLECTION (Logical)
     94
     95    0x75, 0x04,                    //     REPORT_SIZE (8)
     96    0x95, 0x02,                    //     REPORT_COUNT (2)
     97    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
     98    0x25, 0x0F,                    //     LOGICAL_MAXIMUM (15)
     99    0x35, 0x00,                    //     PHYS_MINIMUM (0)
     100    0x45, 0x0F,                    //     PHYS_MAXIMUM (15)
     101    0x09, 0x30,                    //     USAGE (X)
     102    0x09, 0x31,                    //     USAGE (Y)
     103    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
     104
     105    0x75, 0x01,                    //     REPORT_SIZE (1)
     106    0x95, 0x20,                    //     REPORT_COUNT (32)
     107    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
     108    0x45, 0x01,                    //     PHYSMAX (1)
    75109    0x05, 0x09,                    //     USAGE_PAGE (Button)
    76110    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
    77     0x29, 0x30,                    //     USAGE_MAXIMUM (Button 40)
    78     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    79     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
    80     0x95, 0x30,                    //     REPORT_COUNT (40)
    81     0x75, 0x01,                    //     REPORT_SIZE (1)
     111    0x29, 0x20,                    //     USAGE_MAXIMUM (Button 32)
    82112    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    83113    0xc0,                          //   END_COLLECTION
  • starkadroid/code/starkadroid.hex

    r86824a6 rde0f65f  
    1 :1000000062C059C17BC07AC079C078C077C076C061
     1:1000000062C052C17BC07AC079C078C077C076C068
    22:1000100075C074C073C072C071C070C06FC06EC054
    33:100020006DC06CC06BC005010904A101A10275047B
     
    1212:1000B000000103000000092101010001222C0007BA
    1313:1000C00005810308001411241FBECFE5D4E0DEBF74
    14 :1000D000CDBF10E0A0E6B0E0ECE6F7E002C005908E
     14:1000D000CDBF10E0A0E6B0E0EEE5F7E002C005908D
    1515:1000E0000D92A436B107D9F710E0A4E6B0E001C044
    16 :1000F0001D92A83AB107E1F741D036C381CFFC0188
     16:1000F0001D92A83AB107E1F741D02FC381CFFC018F
    1717:1001000085E690E090938D0080938C0080818076CE
    1818:10011000803271F58181813011F485E00895893054
     
    2222:100150008381882369F41092600008958B3041F404
    2323:1001600080E690E090938D0080938C0081E008956C
    24 :1001700080E008951092640081E00895DF92EF928C
    25 :10018000FF920F931F93CF93DF932FE088E190E0CE
    26 :100190000FB6F894A89581BD0FBE21BDADD178945E
    27 :1001A00014BA8FEF85BB17BA88BB84E083BF109267
    28 :1001B000650000E0F1E0EF2EF12CCCEFD0E0DD2483
    29 :1001C000DA9401C0012FA895A4D1EAE6F0E0102F3F
    30 :1001D00040E050E0C701042E02C0880F991F0A9426
    31 :1001E000E2F784BB809585BBCE010197F1F786B31A
    32 :1001F000208130E090E0809590958F739070281763
    33 :10020000390729F086B380958F73808311E04F5FA3
    34 :100210005F4F319646305105E9F614BAD5BA509180
    35 :100220006B0060916C0070916D0040916A00242F0A
    36 :1002300030E0C901E4E0880F991FEA95E1F7807C7E
    37 :10024000852B80936600220F331F220F331F207CE3
    38 :10025000262B20936700407C472B409368008091B9
    39 :100260006F0080936900002309F4ACCF112309F0DB
    40 :10027000A9CF80917D0084FFA5CF85E690E065E061
    41 :1002800051D2A0CFA82FB92F80E090E041E050EAF2
    42 :10029000609530E009C02D9182279795879510F0E1
    43 :1002A00084279527305EC8F36F5FA8F30895EADFCF
    44 :1002B0008D939D930895CF93CFB7CF93DF93C3953D
    45 :1002C000859BE9F7859B0BC0859B09C0859B07C073
    46 :1002D000859B05C0859B03C0859B01C08BC06F9328
    47 :1002E000C0918B00DD27CE56DF4F2F9365E5859BB0
    48 :1002F00003C02F916F91E6CF0F931F934F9320E090
    49 :1003000040E15F9300B3047205FB27F93F9350E08F
    50 :100310003BE039C0147240642F77012F5F5F1EC02D
    51 :10032000406810B314722F7752501FC0406400B35E
    52 :100330002F770472D1F15F5F00C023C0406210B319
    53 :100340002F77147291F15F5F00C025C004721027EF
    54 :10035000515012F45D5F0000115027952C3F10B3EF
    55 :10036000C8F614720127015027952C3FC8F6422782
    56 :10037000499300B3047210274F73115027952C3FF7
    57 :10038000A8F64695469510B3147279F001270150EE
    58 :1003900027952C3F98F66B5A60F3315000B3B0F6B6
    59 :1003A00000C010E41ABF002719C03B503195C31B91
    60 :1003B000D04010E41ABF0881033C09F10B34F9F076
    61 :1003C000209189001981110F1213EDCF4A81441F2A
    62 :1003D000093651F10D3211F0013E29F700939000DA
    63 :1003E0003F915F914F911F910F912F916F91CAB7DC
    64 :1003F000C6FD65CFDF91CF91CFBFCF9118952091EA
    65 :100400009000222369F310918E00112391F534306E
    66 :1004100092F130938E0020938A0010918B003BE084
    67 :10042000311B30938B0027C000918E0001300CF5FA
    68 :100430000AE54F7049F43091610034FD1DC000930E
    69 :100440006100C2E7D0E01CC030917D0034FD14C0D3
    70 :1004500000937D00CEE7D0E013C0052710E000C078
    71 :10046000000002BB1AC0052710E0221F1DC010E0CB
    72 :1004700021C04AE502C032ED432FC4E1D0E032E0B2
    73 :1004800011B31462959A02B311BB54E220E865E3FC
    74 :1004900020FF052702BB279517951C3FF0F66695B0
    75 :1004A000B8F7B1F720FF052702BB279517951C3F2A
    76 :1004B000D0F62795179517FF052700001C3F02BBB4
    77 :1004C000B0F629913A9519F70B7D10918F00110F15
    78 :1004D000C651D04002BB11F01093890010E41ABF3E
    79 :1004E000006211B31B7D402F4B7D54E05A95F1F70C
    80 :1004F00002BB11BB42BB74CF85B7836085BF8BB78E
    81 :1005000080648BBF8BE480937E008AE580937D00BE
    82 :1005100008951F93CF93DF9390918E00935097FD92
    83 :10052000A6C020918B0080918A008D3209F09DC079
    84 :10053000983009F09AC0CCE0D0E0C21BD109CE5669
    85 :10054000DF4F83EC809372008AE580936100109204
    86 :1005500071008881807621F0CE01D1DD282F7CC00A
    87 :100560009A8110927B008981882321F410927C006B
    88 :1005700022E06CC0853019F490938F0066C08630FD
    89 :1005800009F04FC08B81813041F482E990E0909373
    90 :100590008D0080938C0022E140C0823041F484EAD7
    91 :1005A00090E090938D0080938C0022E236C08330DF
    92 :1005B000F9F48A81882341F482E590E090938D00DC
    93 :1005C00080938C0024E029C0813041F486E590E0DE
    94 :1005D00090938D0080938C0024E21FC08230E1F460
    95 :1005E0008AE790E090938D0080938C0028E115C0FD
    96 :1005F000813241F486EB90E090938D0080938C00E3
    97 :1006000029E00BC0823241F486E290E090938D00A5
    98 :1006100080938C002CE201C020E080E48093710084
    99 :100620001BC0883021F421E081E990E011C08930BD
    100 :1006300019F49093910009C08A3011F421E006C0AA
    101 :100640008B3019F48BE480937E0020E08BE790E000
    102 :1006500090938D0080938C008F81882321F48E816C
    103 :10066000821708F4282F2093620010928E00809148
    104 :10067000610084FF49C0809162008F3F09F444C04B
    105 :10068000182F893008F018E0811B80936200809158
    106 :10069000720098E8892780937200112341F120911C
    107 :1006A0008C0030918D008091710086FF0DC0A3E712
    108 :1006B000B0E080E090E0F901E80FF91FE491ED93DC
    109 :1006C00001961817C1F708C0912FD901E3E7F0E0B0
    110 :1006D0008D9181939150E1F71150812F90E01F5F30
    111 :1006E0000196820F931F90938D0080938C0083E777
    112 :1006F00090E0612FDCDD612F6C5F6C3019F08FEFC3
    113 :10070000809362006093610094E180B3847231F45D
    114 :100710009150D9F710928F0010928900DF91CF91FC
    115 :100720001F9108951F93DC01162F80917D0084FF97
    116 :1007300007C080917E0098E8892780937E0003C0DF
    117 :100740008AE580937D00912FEFE7F0E08D91819312
    118 :1007500091501916DCF38FE790E0612FA8DD1C5F44
    119 :0C07600010937D001F910895F894FFCFC6
    120 :04076C00015AFF002F
     24:1001700080E008951092640081E00895EF92FF926C
     25:100180000F931F93CF93DF932FE088E190E00FB69A
     26:10019000F894A89581BD0FBE21BDA7D1789414BA5B
     27:1001A0008FEF85BB17BA88BB84E083BF10926500D0
     28:1001B00010E0F1E0EF2EF12CCCEFD0E00FEFA8959E
     29:1001C000A1D1EAE6F0E040E050E0C701042E02C011
     30:1001D000880F991F0A94E2F784BB809585BBCE01F6
     31:1001E0000197F1F786B3208130E090E080959095FB
     32:1001F0008F7390702817390729F086B380958F7315
     33:10020000808311E04F5F5F4F319646305105E9F62C
     34:1002100014BA05BB50916B0060916C0070916D0039
     35:1002200040916A00242F30E0C901E4E0880F991F53
     36:10023000EA95E1F7807C852B80936600220F331FBF
     37:10024000220F331F207C262B20936700407C472BF6
     38:100250004093680080916F0080936900112309F436
     39:10026000AECF80917D0084FFAACF85E690E065E067
     40:1002700052D210E0A4CFA82FB92F80E090E041E047
     41:1002800050EA609530E009C02D91822797958795B7
     42:1002900010F084279527305EC8F36F5FA8F30895A8
     43:1002A000EADF8D939D930895CF93CFB7CF93DF93DC
     44:1002B000C395859BE9F7859B0BC0859B09C0859BF2
     45:1002C00007C0859B05C0859B03C0859B01C08BC073
     46:1002D0006F93C0918B00DD27CE56DF4F2F9365E5DE
     47:1002E000859B03C02F916F91E6CF0F931F934F9380
     48:1002F00020E040E15F9300B3047205FB27F93F93D0
     49:1003000050E03BE039C0147240642F77012F5F5FEB
     50:100310001EC0406810B314722F7752501FC0406443
     51:1003200000B32F770472D1F15F5F00C023C0406239
     52:1003300010B32F77147291F15F5F00C025C0047273
     53:100340001027515012F45D5F0000115027952C3F8B
     54:1003500010B3C8F614720127015027952C3FC8F638
     55:100360004227499300B3047210274F731150279509
     56:100370002C3FA8F64695469510B3147279F00127E4
     57:10038000015027952C3F98F66B5A60F3315000B31B
     58:10039000B0F600C010E41ABF002719C03B503195D9
     59:1003A000C31BD04010E41ABF0881033C09F10B3491
     60:1003B000F9F0209189001981110F1213EDCF4A81B4
     61:1003C000441F093651F10D3211F0013E29F7009317
     62:1003D00090003F915F914F911F910F912F916F91DD
     63:1003E000CAB7C6FD65CFDF91CF91CFBFCF9118952A
     64:1003F00020919000222369F310918E00112391F532
     65:10040000343092F130938E0020938A0010918B004B
     66:100410003BE0311B30938B0027C000918E000130F0
     67:100420000CF50AE54F7049F43091610034FD1DC0B0
     68:1004300000936100C2E7D0E01CC030917D0034FD24
     69:1004400014C000937D00CEE7D0E013C0052710E074
     70:1004500000C0000002BB1AC0052710E0221F1DC00B
     71:1004600010E021C04AE502C032ED432FC4E1D0E0E4
     72:1004700032E011B31462959A02B311BB54E220E842
     73:1004800065E320FF052702BB279517951C3FF0F673
     74:100490006695B8F7B1F720FF052702BB279517959A
     75:1004A0001C3FD0F62795179517FF052700001C3F26
     76:1004B00002BBB0F629913A9519F70B7D10918F0088
     77:1004C000110FC651D04002BB11F01093890010E407
     78:1004D0001ABF006211B31B7D402F4B7D54E05A952B
     79:1004E000F1F702BB11BB42BB74CF85B7836085BFF8
     80:1004F0008BB780648BBF8BE480937E008AE580930A
     81:100500007D0008951F93CF93DF9390918E009350B9
     82:1005100097FDA6C020918B0080918A008D3209F052
     83:100520009DC0983009F09AC0CCE0D0E0C21BD10940
     84:10053000CE56DF4F83EC809372008AE58093610092
     85:10054000109271008881807621F0CE01D8DD282FAD
     86:100550007CC09A8110927B008981882321F41092BB
     87:100560007C0022E06CC0853019F490938F0066C047
     88:10057000863009F04FC08B81813041F482E990E0F0
     89:1005800090938D0080938C0022E140C0823041F432
     90:1005900084EA90E090938D0080938C0022E236C034
     91:1005A0008330F9F48A81882341F482E590E09093C6
     92:1005B0008D0080938C0024E029C0813041F486E5D1
     93:1005C00090E090938D0080938C0024E21FC08230D5
     94:1005D000E1F48AE790E090938D0080938C0028E10D
     95:1005E00015C0813241F486EB90E090938D008093AA
     96:1005F0008C0029E00BC0823241F486E290E09093B7
     97:100600008D0080938C002CE201C020E080E4809378
     98:1006100071001BC0883021F421E081E990E011C015
     99:10062000893019F49093910009C08A3011F421E0C7
     100:1006300006C08B3019F48BE480937E0020E08BE7BA
     101:1006400090E090938D0080938C008F81882321F41B
     102:100650008E81821708F4282F2093620010928E005A
     103:100660008091610084FF49C0809162008F3F09F44E
     104:1006700044C0182F893008F018E0811B8093620075
     105:100680008091720098E8892780937200112341F1CC
     106:1006900020918C0030918D008091710086FF0DC0FB
     107:1006A000A3E7B0E080E090E0F901E80FF91FE491E2
     108:1006B000ED9301961817C1F708C0912FD901E3E710
     109:1006C000F0E08D9181939150E1F71150812F90E0EE
     110:1006D0001F5F0196820F931F90938D0080938C0073
     111:1006E00083E790E0612FDCDD612F6C5F6C3019F0E7
     112:1006F0008FEF809362006093610094E180B3847215
     113:1007000031F49150D9F710928F0010928900DF9147
     114:10071000CF911F9108951F93DC01162F80917D00CA
     115:1007200084FF07C080917E0098E8892780937E002F
     116:1007300003C08AE580937D00912FEFE7F0E08D9173
     117:10074000819391501916DCF38FE790E0612FA8DDBB
     118:0E0750001C5F10937D001F910895F894FFCF59
     119:04075E00015AFF003D
    121120:00000001FF
Note: See TracChangeset for help on using the changeset viewer.