Changeset de0f65f in avrstuff for starkadroid/code/main.c


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.