USB keyboard code for atmega8.
Discussion in "AVR Discussion Forum" started by Nestor_avr Aug 18, 2013.
Sat Apr 05 2014, 07:14 am
You can take the code the part that recognizes the DOS and put in the code that I use?
Mon Apr 07 2014, 11:26 am
You can compare the source files of your project and the other project to see what needs to be changed. I do not have enough time to look into this. I can simply give you pointers.
Mon Apr 07 2014, 04:11 pm
I've done comparisons and aicionei parts of a code on the other more was lost, why is one of the codes matrix and the other is not.
Mon Apr 07 2014, 06:39 pm
Just check the configuration of USB and their respective handlers (if there). all you need to see is the IBM keyboard project implements boot protocol (see usbconfig.h) is there any handler that is added for handling this special function. If yes just replicate that part of code in your project. I will also look into them as soon as I get time.
Mon Apr 07 2014, 06:50 pm
I still have little knowledge and I am not able to, I'll post the 2 codes for you to see.
Source 2 codes: https://www.dropbox.com/s/9tnfrm0rsi7d5je/source%20codes.rar
Source 2 codes: https://www.dropbox.com/s/9tnfrm0rsi7d5je/source%20codes.rar
[ Edited Mon Apr 07 2014, 06:51 pm ]
Tue Apr 08 2014, 03:40 pm
First difference
usbconfig.h:
In main.c:
Try to make these changes and see if something works for you. Let me know the results.
usbconfig.h:
#define USB_CFG_INTERFACE_CLASS 0x03 /* HID class */ #define USB_CFG_INTERFACE_SUBCLASS 0x01 /* Boot-device subclass */ #define USB_CFG_INTERFACE_PROTOCOL 0x01 /* Keyboard protocol */ #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 63 /* total length of report descriptor */
In main.c:
/* USB report descriptor (length is defined in usbconfig.h) This has been changed to conform to the USB keyboard boot protocol */ char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] PROGMEM = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x06, // USAGE (Keyboard) 0xa1, 0x01, // COLLECTION (Application) 0x05, 0x07, // USAGE_PAGE (Keyboard) 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x95, 0x01, // REPORT_COUNT (1) 0x75, 0x08, // REPORT_SIZE (8) 0x81, 0x03, // INPUT (Cnst,Var,Abs) 0x95, 0x05, // REPORT_COUNT (5) 0x75, 0x01, // REPORT_SIZE (1) 0x05, 0x08, // USAGE_PAGE (LEDs) 0x19, 0x01, // USAGE_MINIMUM (Num Lock) 0x29, 0x05, // USAGE_MAXIMUM (Kana) 0x91, 0x02, // OUTPUT (Data,Var,Abs) 0x95, 0x01, // REPORT_COUNT (1) 0x75, 0x03, // REPORT_SIZE (3) 0x91, 0x03, // OUTPUT (Cnst,Var,Abs) 0x95, 0x06, // REPORT_COUNT (6) 0x75, 0x08, // REPORT_SIZE (8) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x65, // LOGICAL_MAXIMUM (101) 0x05, 0x07, // USAGE_PAGE (Keyboard) 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) 0x81, 0x00, // INPUT (Data,Ary,Abs) 0xc0 // END_COLLECTION };
Try to make these changes and see if something works for you. Let me know the results.
Tue Apr 08 2014, 08:14 pm
When muted # defineUSB_CFG_INTERFACE_PROTOCOL 0x01 or # define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 63 compiles more does not work
When I change const char PROGMEM usbHidReportDescriptor [35] to char usbHidReportDescriptor [USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] I get this error:
Changes that could make and still works on windows:
In Usbconfig.h
In main.c
Added other lines:
source changed working on windows: https://www.dropbox.com/s/pepgixcty1j5rsq/modified%20source.rar
When I change const char PROGMEM usbHidReportDescriptor [35] to char usbHidReportDescriptor [USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] I get this error:
../main.c:109: error: conflicting types for 'usbDescriptorHidReport' ../usbdrv.h:477: error: previous declaration of 'usbDescriptorHidReport' was here ../main.c:128: warning: excess elements in array initializer ../main.c:128: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:129: warning: excess elements in array initializer ../main.c:129: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:129: warning: excess elements in array initializer ../main.c:129: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:130: warning: excess elements in array initializer ../main.c:130: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:130: warning: excess elements in array initializer ../main.c:130: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:131: warning: excess elements in array initializer ../main.c:131: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:131: warning: excess elements in array initializer ../main.c:131: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:132: warning: excess elements in array initializer ../main.c:132: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:132: warning: excess elements in array initializer ../main.c:132: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:133: warning: excess elements in array initializer ../main.c:133: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:133: warning: excess elements in array initializer ../main.c:133: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:134: warning: excess elements in array initializer ../main.c:134: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:134: warning: excess elements in array initializer ../main.c:134: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:135: warning: excess elements in array initializer ../main.c:135: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:135: warning: excess elements in array initializer ../main.c:135: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:136: warning: excess elements in array initializer ../main.c:136: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:136: warning: excess elements in array initializer ../main.c:136: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:137: warning: excess elements in array initializer ../main.c:137: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:137: warning: excess elements in array initializer ../main.c:137: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:138: warning: excess elements in array initializer ../main.c:138: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:138: warning: excess elements in array initializer ../main.c:138: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:139: warning: excess elements in array initializer ../main.c:139: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:139: warning: excess elements in array initializer ../main.c:139: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:140: warning: excess elements in array initializer ../main.c:140: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:140: warning: excess elements in array initializer ../main.c:140: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:141: warning: excess elements in array initializer ../main.c:141: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:141: warning: excess elements in array initializer ../main.c:141: warning: (near initialization for 'usbDescriptorHidReport') ../main.c:143: warning: excess elements in array initializer ../main.c:143: warning: (near initialization for 'usbDescriptorHidReport') make: *** [main.o] Error 1 Build failed with 2 errors and 56 warnings...
Changes that could make and still works on windows:
In Usbconfig.h
# define USB_CFG_INTERFACE_CLASS 0x03 / * HID class * / # define USB_CFG_INTERFACE_SUBCLASS 0x01 / * only changed here * / # define USB_CFG_INTERFACE_PROTOCOL 0 / * the protocol * / # define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 35 / * Total length of report descriptor * /
In main.c
static uchar reportBuffer[2]; /* buffer for HID reports */ static uchar idleRate; /* in 4 ms units */ static uchar protocolVer=1; /* 0 is the boot protocol, 1 is report protocol - I added this line */
Added other lines:
uchar usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (void *)data; usbMsgPtr = reportBuffer; if((rq-> bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ if(rq-> bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */ /* we only have one report type, so don't look at wValue */ buildReport(keyPressed()); return sizeof(reportBuffer); }else if(rq-> bRequest == USBRQ_HID_GET_IDLE){ usbMsgPtr = &idleRate; return 1; }else if(rq-> bRequest == USBRQ_HID_SET_IDLE){ idleRate = rq-> wValue.bytes[1]; }else if(rq-> bRequest == USBRQ_HID_GET_PROTOCOL) { if (rq-> wValue.bytes[1] < 1) { protocolVer = rq-> wValue.bytes[1]; } }else if(rq-> bRequest == USBRQ_HID_SET_PROTOCOL) { usbMsgPtr = &protocolVer; return 1; } } return 0; }
source changed working on windows: https://www.dropbox.com/s/pepgixcty1j5rsq/modified%20source.rar
[ Edited Tue Apr 08 2014, 08:36 pm ]
Wed Apr 09 2014, 03:29 pm
did you remove the previous declaration of the USB descriptor HID report? from error it looks like its defined twice. Also the IBM keyboard project uses older version of V-USB whereas HID key uses a newer version. Keep that in mind before doing any modifications.
Wed Apr 09 2014, 04:17 pm
IBM keyboard project uses older version of V-USB whereas HID key uses a newer version. Keep that in mind before doing any modifications.Ajay Bhargav
So it can not work hidkeys the bios and in the dos?
Powered by e107 Forum System