Index: starkadroid/code/main.c
===================================================================
--- starkadroid/code/main.c	(revision 98713b530089bd178bb7d6a09d6109922f60cf36)
+++ starkadroid/code/main.c	(revision 5649b6cf680fb4193a079724f8493d55b688eac5)
@@ -10,8 +10,16 @@
 #include "usbdrv/usbdrv.h"
 
-static uint8_t reportBuffer[5]; 
+#define DDRIN DDRB
+#define PORTIN PORTB
+#define PININ PINB
+
+#define DDROUT DDRC
+#define PORTOUT PORTC
+
+static uint8_t reportBuffer[6]; 
 static uint8_t idleRate;
 
 void main() {
+	bool which = false;
 	uint8_t idleCounter = 0;
 
@@ -23,14 +31,14 @@
 	bool doReport;
 
-	DDRB = 0; // Keyboard matrix out
-	PORTB = 255; // Enable pull up
+	DDROUT = 0; // Keyboard matrix out
+	PORTOUT = 255; // Enable pull up
 		// We put all pins as input then output a 0 in only one at a time.
 		// All the other pins are high-Z to avoid short circuits when many buttons are pressed.
-	DDRC = 0; // Keyboard matrix in
-	PORTC = 255; // Enable pull up
+	DDRIN = 0; // Keyboard matrix in
+	PORTIN = 255; // Enable pull up
 
     // configure timer 0 for a rate of 16M/(256 * 256) = ~244Hz
     TCCR0 = 4;          // timer 0 prescaler: 256
-	
+
 	while(1) {
 		wdt_reset();
@@ -38,37 +46,17 @@
 
 		doReport = false;
-		for(int i=0; i < 5; i++) {
-			DDRB = ~(1<<i);
-			PORTB = ~(1<<i);
-			reportBuffer[i] = (~PINC)&0x3F;
+		for(char i = 0; i != 6; i++) {
+			DDROUT = 1<<i;
+			PORTOUT = ~(1<<i);
+			if (reportBuffer[i] != ((~PININ)&0x3F))
+				doReport = true;
+			reportBuffer[i] = (~PININ)&0x3F;
 		}
+		DDROUT = 0;
+		PORTOUT = 255;
 
-		DDRB = ~(1<<5);
-		PORTB = ~(1<<5);
-		reportBuffer[0] |= (~PINC)<<6 & 0xC0;
-		reportBuffer[1] |= (~PINC)<<4 & 0xC0;
-		reportBuffer[2] |= (~PINC)<<2 & 0xC0;
-		// reportBuffer[3] |= (~PINC)<<0 & 0xC0; // These are not existing pins...
-
-		DDRB = 255;
-		PORTB = 255;
-
-		if (usbInterruptIsReady()) {
+		if (doReport && usbInterruptIsReady()) {
 			usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
-//			LEDOFF;
 			doReport = false;
-		}
-
-		if (TIFR & (1 << TOV0)) {
-			TIFR = (1 << TOV0); // reset flag
-
-			if(++idleCounter > 4){ // yes, but not yet
-				idleCounter -= 5; // 22ms in units of 4ms
-			} else { // yes, it is time now
-				idleCounter = idleRate;
-				if (usbInterruptIsReady()) {
-					usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
-				}
-			}
 		}
 	}
@@ -81,25 +69,17 @@
 
 char PROGMEM usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {
-    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
+	0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
     0x09, 0x05,                    // USAGE (Game Pad)
     0xa1, 0x01,                    // COLLECTION (Application)
-    0x09, 0x01,                    //   USAGE (Pointer)
     0xa1, 0x00,                    //   COLLECTION (Physical)
-    0x09, 0x30,                    //     USAGE (X)
-    0x09, 0x31,                    //     USAGE (Y)
-    0x15, 0xff,                    //     LOGICAL_MINIMUM (-1)
+    0x05, 0x09,                    //     USAGE_PAGE (Button)
+    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
+    0x29, 0x30,                    //     USAGE_MAXIMUM (Button 40)
+    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
-    0x75, 0x02,                    //     REPORT_SIZE (2)
-    0x95, 0x02,                    //     REPORT_COUNT (2)
+    0x95, 0x30,                    //     REPORT_COUNT (40)
+    0x75, 0x01,                    //     REPORT_SIZE (1)
     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
     0xc0,                          //   END_COLLECTION
-    0x05, 0x09,                    //   USAGE_PAGE (Button)
-    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)
-    0x29, 0x24,                    //   USAGE_MAXIMUM (Button 36)
-    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
-    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
-    0x75, 0x01,                    //   REPORT_SIZE (1)
-    0x95, 0x24,                    //   REPORT_COUNT (36)
-    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
     0xc0                           // END_COLLECTION
 };
Index: starkadroid/code/starkadroid.hex
===================================================================
--- starkadroid/code/starkadroid.hex	(revision 98713b530089bd178bb7d6a09d6109922f60cf36)
+++ starkadroid/code/starkadroid.hex	(revision 5649b6cf680fb4193a079724f8493d55b688eac5)
@@ -1,125 +1,113 @@
-:1000000061C05AC17AC079C078C077C076C075C067
-:1000100074C073C072C071C070C06FC06EC06DC05C
-:100020006CC06BC06AC005010905A1010901A100EE
-:100030000930093115FF2501750295028102C005BD
-:10004000091901292415002501750195248102C093
-:10005000040309042403700075006C006B006F003A
-:100060006D0061006E00640079002E006100740074
-:1000700068002E00630078001803530074006100CC
-:1000800072006B006100640072006F006900640020
-:100090001201100100000008424231170001010264
-:1000A0000001090222000101008032090400000160
-:1000B00003000000092101010001222A0007058137
-:1000C0000308000A11241FBECFE5D4E0DEBFCDBF78
-:1000D00010E0A0E6B0E0E6EAF7E002C005900D927D
-:1000E000A436B107D9F710E0A4E6B0E001C01D9234
-:1000F000A23AB107E1F741D054C382CFFC0185E6B3
-:1001000090E0909387008093860080818076803293
-:1001100071F58181813011F485E00895893049F4C9
-:1001200086819781019719F581E0809364008FEFB4
-:100130000895823019F48AE690E013C08A3029F4D9
-:10014000838180936A0080E00895833031F4838155
-:10015000882369F41092600008958B3041F480E6A2
-:1001600090E0909387008093860081E0089580E07E
-:1001700008951092640081E00895EF92FF920F932A
-:100180001F93CF93DF932FE088E190E00FB6F894B0
-:10019000A89581BD0FBE21BDB0D1789417BA8FEF5D
-:1001A00088BB14BA85BB84E083BF10E0C1E0D0E017
-:1001B0005FEDF52E0FEFEE24E394A895ABD120E090
-:1001C00030E0CE01022E02C0880F991F0A94E2F798
-:1001D000809587BB88BB83B3F901EB59FF4F8095AE
-:1001E0008F7380832F5F3F4F2530310551F7F7BA6A
-:1001F000F8BA83B390E08095909546E0880F991FF8
-:100200004A95E1F720916500282B2093650083B380
-:1002100090E08095909534E0880F991F3A95E1F72A
-:10022000807C20916600822B8093660083B390E0EF
-:1002300080959095880F991F880F991F807C209139
-:100240006700822B8093670007BB08BB8091770013
-:1002500084FF04C085E690E065E081D208B600FE28
-:10026000ACCFE8BE812F8F5F853010F01450A5CF42
-:1002700010916A008091770084FF9FCF85E690E01F
-:1002800065E06DD29ACFA82FB92F80E090E041E0D1
-:1002900050EA609530E009C02D91822797958795A7
-:1002A00010F084279527305EC8F36F5FA8F3089598
-:1002B000EADF8D939D930895CF93CFB7CF93DF93CC
-:1002C000C395859BE9F7859B0BC0859B09C0859BE2
-:1002D00007C0859B05C0859B03C0859B01C08BC063
-:1002E0006F93C0918500DD27C457DF4F2F9365E5DD
-:1002F000859B03C02F916F91E6CF0F931F934F9370
-:1003000020E040E15F9300B3047205FB27F93F93BF
-:1003100050E03BE039C0147240642F77012F5F5FDB
-:100320001EC0406810B314722F7752501FC0406433
-:1003300000B32F770472D1F15F5F00C023C0406229
-:1003400010B32F77147291F15F5F00C025C0047263
-:100350001027515012F45D5F0000115027952C3F7B
-:1003600010B3C8F614720127015027952C3FC8F628
-:100370004227499300B3047210274F7311502795F9
-:100380002C3FA8F64695469510B3147279F00127D4
-:10039000015027952C3F98F66B5A60F3315000B30B
-:1003A000B0F600C010E41ABF002719C03B503195C9
-:1003B000C31BD04010E41ABF0881033C09F10B3481
-:1003C000F9F0209183001981110F1213EDCF4A81AA
-:1003D000441F093651F10D3211F0013E29F7009307
-:1003E0008A003F915F914F911F910F912F916F91D3
-:1003F000CAB7C6FD65CFDF91CF91CFBFCF9118951A
-:1004000020918A00222369F310918800112391F52D
-:10041000343092F13093880020938400109185004D
-:100420003BE0311B3093850027C0009188000130EC
-:100430000CF50AE54F7049F43091610034FD1DC0A0
-:1004400000936100CCE6D0E01CC03091770034FD11
-:1004500014C000937700C8E7D0E013C0052710E070
-:1004600000C0000002BB1AC0052710E0221F1DC0FB
-:1004700010E021C04AE502C032ED432FC4E1D0E0D4
-:1004800032E011B31462959A02B311BB54E220E832
-:1004900065E320FF052702BB279517951C3FF0F663
-:1004A0006695B8F7B1F720FF052702BB279517958A
-:1004B0001C3FD0F62795179517FF052700001C3F16
-:1004C00002BBB0F629913A9519F70B7D109189007E
-:1004D000110FC651D04002BB11F01093830010E4FD
-:1004E0001ABF006211B31B7D402F4B7D54E05A951B
-:1004F000F1F702BB11BB42BB74CF85B7836085BFE8
-:100500008BB780648BBF8BE4809378008AE58093FF
-:10051000770008951F93CF93DF9360918800635015
-:1005200067FDC2C080918500CCE0D0E0C81BD10936
-:10053000C457DF4F809184008D3209F0A3C068302A
-:1005400009F0B0C083EC80936C008AE58093610071
-:1005500010926B008881807639F0CE01CFDD282F94
-:100560008F3F09F47EC084C09A8110927500898102
-:10057000882321F41092760022E06CC0853019F4B3
-:100580009093890066C0863009F04FC08B8181301E
-:1005900041F480E990E0909387008093860022E107
-:1005A00040C0823041F482EA90E0909387008093CB
-:1005B000860022E236C08330F9F48A81882341F430
-:1005C00080E590E0909387008093860024E029C026
-:1005D000813041F484E590E0909387008093860019
-:1005E00024E21FC08230E1F488E790E09093870016
-:1005F0008093860028E115C0813241F484EB90E0BD
-:10060000909387008093860029E00BC0823241F4EA
-:1006100086E290E090938700809386002AE201C0F2
-:1006200020E080E480936B0023C0883021F421E037
-:100630008BE890E011C0893019F490938B0009C0C9
-:100640008A3011F421E006C08B3019F48BE48093DA
-:10065000780020E085E790E0909387008093860003
-:1006600007C0888187FD2E8180E880936B0006C0DB
-:100670008F81882319F48E81821708F0822F80934E
-:10068000620010C080916B0087FF0CC0CE0171DD4D
-:100690008F3F21F48EE18093610004C0882311F024
-:1006A00010926200109288008091610084FF49C01E
-:1006B000809162008F3F09F444C0182F893008F000
-:1006C00018E0811B8093620080916C0098E8892774
-:1006D00080936C00112341F12091860030918700B6
-:1006E00080916B0086FF0DC0ADE6B0E080E090E049
-:1006F000F901E80FF91FE491ED9301961817C1F77E
-:1007000008C0912FD901EDE6F0E08D9181939150D1
-:10071000E1F71150812F90E01F5F0196820F931F28
-:1007200090938700809386008DE690E0612FC0DD76
-:10073000612F6C5F6C3019F08FEF809362006093D3
-:10074000610094E180B3847231F49150D9F7109232
-:10075000890010928300DF91CF911F9108951F931C
-:10076000DC01162F8091770084FF07C0809178000C
-:1007700098E889278093780003C08AE58093770002
-:10078000912FE9E7F0E08D91819391501916DCF3F8
-:1007900089E790E0612F8CDD1C5F109377001F913B
-:0607A0000895F894FFCF5C
-:0407A600015AFF00F5
+:1000000059C017C172C071C070C06FC06EC06DC0E2
+:100010006CC06BC06AC069C068C067C066C065C09C
+:1000200064C063C062C005010905A101A100050902
+:100030001901293015002501953075018102C0C0D4
+:10004000040309042403700075006C006B006F004A
+:100050006D0061006E00640079002E006100740084
+:1000600068002E00630078001803530074006100DC
+:1000700072006B006100640072006F006900640030
+:100080001201100100000008424231170001010274
+:100090000001090222000101008032090400000170
+:1000A00003000000092101010001221A0007058157
+:1000B0000308001411241FBECFE5D4E0DEBFCDBF7E
+:1000C00010E0A0E6B0E0E8EEF6E002C005900D9288
+:1000D000A436B107D9F710E0A4E6B0E001C01D9244
+:1000E000A33AB107E1F741D0FDC28ACFFC0185E612
+:1000F00090E09093880080938700808180768032A2
+:1001000071F58181813011F486E00895893049F4D8
+:1001100086819781019719F581E0809364008FEFC4
+:100120000895823019F48BE690E013C08A3029F4E8
+:10013000838180936B0080E00895833031F4838164
+:10014000882369F41092600008958B3041F480E6B2
+:1001500090E0909388008093870081E0089580E08C
+:1001600008951092640081E008951F93CF93DF9368
+:100170002FE088E190E00FB6F894A89581BD0FBEFE
+:1001800021BD78D1789414BA8FEF85BB17BA88BB9C
+:1001900084E083BFC1E0D0E01FEFA89578D1E5E609
+:1001A000F0E060E040E050E0CE01042E02C0880F95
+:1001B000991F0A94E2F784BB809585BB86B32081A2
+:1001C00030E090E0809590958F73907028173907F4
+:1001D00009F061E086B380958F7381934F5F5F4F25
+:1001E0004630510509F714BA15BB6623B1F2809168
+:1001F000780084FFD2CF85E690E066E051D2CDCF83
+:10020000A82FB92F80E090E041E050EA609530E0FF
+:1002100009C02D9182279795879510F084279527FF
+:10022000305EC8F36F5FA8F30895EADF8D939D9366
+:100230000895CF93CFB7CF93DF93C395859BE9F70D
+:10024000859B0BC0859B09C0859B07C0859B05C00E
+:10025000859B03C0859B01C08BC06F93C0918600B6
+:10026000DD27C357DF4F2F9365E5859B03C02F9193
+:100270006F91E6CF0F931F934F9320E040E15F9380
+:1002800000B3047205FB27F93F9350E03BE039C00F
+:10029000147240642F77012F5F5F1EC0406810B357
+:1002A00014722F7752501FC0406400B32F7704722E
+:1002B000D1F15F5F00C023C0406210B32F7714728A
+:1002C00091F15F5F00C025C004721027515012F4F5
+:1002D0005D5F0000115027952C3F10B3C8F61472D3
+:1002E0000127015027952C3FC8F64227499300B3B8
+:1002F000047210274F73115027952C3FA8F646958E
+:10030000469510B3147279F00127015027952C3FC0
+:1003100098F66B5A60F3315000B3B0F600C010E4A9
+:100320001ABF002719C03B503195C31BD04010E4C1
+:100330001ABF0881033C09F10B34F9F020918400C5
+:100340001981110F1213EDCF4A81441F093651F163
+:100350000D3211F0013E29F700938B003F915F9120
+:100360004F911F910F912F916F91CAB7C6FD65CF25
+:10037000DF91CF91CFBFCF91189520918B00222391
+:1003800069F310918900112391F5343092F1309383
+:10039000890020938500109186003BE0311B30934B
+:1003A000860027C00091890001300CF50AE54F70E6
+:1003B00049F43091610034FD1DC000936100CDE629
+:1003C000D0E01CC03091780034FD14C00093780058
+:1003D000C9E7D0E013C0052710E000C0000002BB51
+:1003E0001AC0052710E0221F1DC010E021C04AE5F9
+:1003F00002C032ED432FC4E1D0E032E011B3146209
+:10040000959A02B311BB54E220E865E320FF05276B
+:1004100002BB279517951C3FF0F66695B8F7B1F724
+:1004200020FF052702BB279517951C3FD0F627957F
+:10043000179517FF052700001C3F02BBB0F6299156
+:100440003A9519F70B7D10918A00110FC651D040D3
+:1004500002BB11F01093840010E41ABF006211B3C4
+:100460001B7D402F4B7D54E05A95F1F702BB11BB29
+:1004700042BB74CF85B7836085BF8BB780648BBF69
+:100480008BE4809379008AE58093780008951F9328
+:10049000CF93DF9390918900935097FDA6C0209150
+:1004A0008600809185008D3209F09DC0983009F05A
+:1004B0009AC0CCE0D0E0C21BD109C357DF4F83EC18
+:1004C00080936D008AE58093610010926C008881B2
+:1004D000807621F0CE010ADE282F7CC09A8110920E
+:1004E00076008981882321F41092770022E06CC085
+:1004F000853019F490938A0066C0863009F04FC0A9
+:100500008B81813041F480E890E090938800809363
+:10051000870022E140C0823041F482E990E090936C
+:1005200088008093870022E236C08330F9F48A8104
+:10053000882341F480E490E09093880080938700C2
+:1005400024E029C0813041F484E490E09093880055
+:100550008093870024E21FC08230E1F488E690E0B7
+:10056000909388008093870028E115C0813241F480
+:1005700084EA90E0909388008093870029E00BC084
+:10058000823241F486E290E0909388008093870065
+:100590002AE101C020E080E480936C001BC0883019
+:1005A00021F421E08CE890E011C0893019F4909397
+:1005B0008C0009C08A3011F421E006C08B3019F498
+:1005C0008BE48093790020E086E790E090938800A8
+:1005D000809387008F81882321F48E81821708F40D
+:1005E000282F20936200109289008091610084FF7F
+:1005F00049C0809162008F3F09F444C0182F8930B0
+:1006000008F018E0811B8093620080916D0098E8EB
+:10061000892780936D00112341F12091870030914B
+:10062000880080916C0086FF0DC0AEE6B0E080E0EF
+:1006300090E0F901E80FF91FE491ED930196181786
+:10064000C1F708C0912FD901EEE6F0E08D918193BA
+:100650009150E1F71150812F90E01F5F0196820FBA
+:10066000931F90938800809387008EE690E0612F1F
+:10067000DCDD612F6C5F6C3019F08FEF80936200CE
+:100680006093610094E180B3847231F49150D9F7A2
+:1006900010928A0010928400DF91CF911F910895EB
+:1006A0001F93DC01162F8091780084FF07C0809192
+:1006B000790098E889278093790003C08AE58093C0
+:1006C0007800912FEAE7F0E08D918193915019160F
+:1006D000DCF38AE790E0612FA8DD1C5F10937800BF
+:0806E0001F910895F894FFCF6B
+:0406E800015AFF00B4
 :00000001FF
Index: starkadroid/code/usbconfig.h
===================================================================
--- starkadroid/code/usbconfig.h	(revision 98713b530089bd178bb7d6a09d6109922f60cf36)
+++ starkadroid/code/usbconfig.h	(revision 5649b6cf680fb4193a079724f8493d55b688eac5)
@@ -68,5 +68,5 @@
  * low speed devices.
  */
-#define USB_CFG_INTR_POLL_INTERVAL      10
+#define USB_CFG_INTR_POLL_INTERVAL      20
 /** Define this to 1 if the device has its own power supply. Set it to 0 if the
  * device is powered from the USB bus.
@@ -82,5 +82,5 @@
  * bytes.
  */
-#define USB_CFG_IMPLEMENT_FN_WRITE      1
+#define USB_CFG_IMPLEMENT_FN_WRITE      0
 /** Set this to 1 if you need to send control replies which are generated
  * "on the fly" when usbFunctionRead() is called. If you only want to send
@@ -165,5 +165,5 @@
  * an HID device. Otherwise don't define it or define it to 0.
  */
-#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    42
+#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    26
 
 /* ------------------- Fine Control over USB Descriptors ------------------- */
