Changeset 5649b6c in avrstuff for starkadroid/code/main.c
- Timestamp:
- Nov 14, 2010, 12:01:03 PM (13 years ago)
- Branches:
- main
- Children:
- 8f4b118
- Parents:
- 98713b5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
starkadroid/code/main.c
r98713b5 r5649b6c 10 10 #include "usbdrv/usbdrv.h" 11 11 12 static uint8_t reportBuffer[5]; 12 #define DDRIN DDRB 13 #define PORTIN PORTB 14 #define PININ PINB 15 16 #define DDROUT DDRC 17 #define PORTOUT PORTC 18 19 static uint8_t reportBuffer[6]; 13 20 static uint8_t idleRate; 14 21 15 22 void main() { 23 bool which = false; 16 24 uint8_t idleCounter = 0; 17 25 … … 23 31 bool doReport; 24 32 25 DDR B= 0; // Keyboard matrix out26 PORT B= 255; // Enable pull up33 DDROUT = 0; // Keyboard matrix out 34 PORTOUT = 255; // Enable pull up 27 35 // We put all pins as input then output a 0 in only one at a time. 28 36 // All the other pins are high-Z to avoid short circuits when many buttons are pressed. 29 DDR C= 0; // Keyboard matrix in30 PORT C= 255; // Enable pull up37 DDRIN = 0; // Keyboard matrix in 38 PORTIN = 255; // Enable pull up 31 39 32 40 // configure timer 0 for a rate of 16M/(256 * 256) = ~244Hz 33 41 TCCR0 = 4; // timer 0 prescaler: 256 34 42 35 43 while(1) { 36 44 wdt_reset(); … … 38 46 39 47 doReport = false; 40 for(int i=0; i < 5; i++) { 41 DDRB = ~(1<<i); 42 PORTB = ~(1<<i); 43 reportBuffer[i] = (~PINC)&0x3F; 48 for(char i = 0; i != 6; i++) { 49 DDROUT = 1<<i; 50 PORTOUT = ~(1<<i); 51 if (reportBuffer[i] != ((~PININ)&0x3F)) 52 doReport = true; 53 reportBuffer[i] = (~PININ)&0x3F; 44 54 } 55 DDROUT = 0; 56 PORTOUT = 255; 45 57 46 DDRB = ~(1<<5); 47 PORTB = ~(1<<5); 48 reportBuffer[0] |= (~PINC)<<6 & 0xC0; 49 reportBuffer[1] |= (~PINC)<<4 & 0xC0; 50 reportBuffer[2] |= (~PINC)<<2 & 0xC0; 51 // reportBuffer[3] |= (~PINC)<<0 & 0xC0; // These are not existing pins... 52 53 DDRB = 255; 54 PORTB = 255; 55 56 if (usbInterruptIsReady()) { 58 if (doReport && usbInterruptIsReady()) { 57 59 usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); 58 // LEDOFF;59 60 doReport = false; 60 }61 62 if (TIFR & (1 << TOV0)) {63 TIFR = (1 << TOV0); // reset flag64 65 if(++idleCounter > 4){ // yes, but not yet66 idleCounter -= 5; // 22ms in units of 4ms67 } else { // yes, it is time now68 idleCounter = idleRate;69 if (usbInterruptIsReady()) {70 usbSetInterrupt(reportBuffer, sizeof(reportBuffer));71 }72 }73 61 } 74 62 } … … 81 69 82 70 char PROGMEM usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { 83 71 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 84 72 0x09, 0x05, // USAGE (Game Pad) 85 73 0xa1, 0x01, // COLLECTION (Application) 86 0x09, 0x01, // USAGE (Pointer)87 74 0xa1, 0x00, // COLLECTION (Physical) 88 0x09, 0x30, // USAGE (X) 89 0x09, 0x31, // USAGE (Y) 90 0x15, 0xff, // LOGICAL_MINIMUM (-1) 75 0x05, 0x09, // USAGE_PAGE (Button) 76 0x19, 0x01, // USAGE_MINIMUM (Button 1) 77 0x29, 0x30, // USAGE_MAXIMUM (Button 40) 78 0x15, 0x00, // LOGICAL_MINIMUM (0) 91 79 0x25, 0x01, // LOGICAL_MAXIMUM (1) 92 0x 75, 0x02, // REPORT_SIZE (2)93 0x 95, 0x02, // REPORT_COUNT (2)80 0x95, 0x30, // REPORT_COUNT (40) 81 0x75, 0x01, // REPORT_SIZE (1) 94 82 0x81, 0x02, // INPUT (Data,Var,Abs) 95 83 0xc0, // END_COLLECTION 96 0x05, 0x09, // USAGE_PAGE (Button)97 0x19, 0x01, // USAGE_MINIMUM (Button 1)98 0x29, 0x24, // USAGE_MAXIMUM (Button 36)99 0x15, 0x00, // LOGICAL_MINIMUM (0)100 0x25, 0x01, // LOGICAL_MAXIMUM (1)101 0x75, 0x01, // REPORT_SIZE (1)102 0x95, 0x24, // REPORT_COUNT (36)103 0x81, 0x02, // INPUT (Data,Var,Abs)104 84 0xc0 // END_COLLECTION 105 85 };
Note:
See TracChangeset
for help on using the changeset viewer.