Changeset de0f65f in avrstuff for starkadroid/code/main.c
- Timestamp:
- Nov 21, 2010, 4:38:41 PM (13 years ago)
- Branches:
- main
- Children:
- df91872
- Parents:
- 86824a6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
starkadroid/code/main.c
r86824a6 rde0f65f 17 17 #define PORTOUT PORTC 18 18 19 static uint8_t reportBuffer[6]; 19 static uint8_t reportBuffer[5]; 20 static uint8_t buttons[6]; 20 21 static uint8_t idleRate; 21 22 22 23 void main() { 23 bool which = false;24 uint8_t idleCounter = 0;25 26 24 wdt_enable(WDTO_2S); 27 25 … … 34 32 PORTOUT = 255; // Enable pull up 35 33 // 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. 37 36 DDRIN = 0; // Keyboard matrix in 38 37 PORTIN = 255; // Enable pull up … … 41 40 TCCR0 = 4; // timer 0 prescaler: 256 42 41 42 reportBuffer[0] = 0; 43 doReport = false; 44 43 45 while(1) { 44 46 wdt_reset(); 45 47 usbPoll(); 46 48 47 doReport = false; 48 for(char i = 0; i != 6; i++) { 49 for(int i = 0; i != 6; i++) { 49 50 DDROUT = 1<<i; 50 51 PORTOUT = ~(1<<i); 51 if (reportBuffer[i] != ((~PININ)&0x3F)) 52 _delay_us(63); 53 if (buttons[i] != ((~PININ)&0x3F)) 54 { 52 55 doReport = true; 53 reportBuffer[i] = (~PININ)&0x3F; 56 buttons[i] = (~PININ)&0x3F; 57 } 54 58 } 55 59 DDROUT = 0; 56 60 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 57 76 58 77 if (doReport && usbInterruptIsReady()) { … … 70 89 char PROGMEM usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { 71 90 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 72 0x09, 0x0 5, // USAGE (Game Pad)91 0x09, 0x04, // USAGE (Joystick) 73 92 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) 75 109 0x05, 0x09, // USAGE_PAGE (Button) 76 110 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) 82 112 0x81, 0x02, // INPUT (Data,Var,Abs) 83 113 0xc0, // END_COLLECTION
Note:
See TracChangeset
for help on using the changeset viewer.