You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.7 KiB
60 lines
2.7 KiB
|
|
#include <avr/io.h>
|
|
#include <avr/pgmspace.h>
|
|
#include "usbdrv.h"
|
|
#include "usb_key_codes.h"
|
|
|
|
extern void buildReport(uint8_t mod,uint8_t key);
|
|
extern uint8_t reportBuffer[2];
|
|
|
|
uint8_t idleRate;
|
|
|
|
uint8_t usbFunctionSetup(uint8_t 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(0x00, 0x00);
|
|
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{
|
|
/* no vendor specific requests implemented */
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* We use a simplifed keyboard report descriptor which does not support the
|
|
* boot protocol. We don't allow setting status LEDs and we only allow one
|
|
* simultaneous key press (except modifiers). We can therefore use short
|
|
* 2 byte input reports.
|
|
* The report descriptor has been created with usb.org's "HID Descriptor Tool"
|
|
* which can be downloaded from http://www.usb.org/developers/hidpage/.
|
|
* Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
|
|
* for the second INPUT item.
|
|
*/
|
|
const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
|
|
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)
|
|
0x25, 0x65, // LOGICAL_MAXIMUM (101)
|
|
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
|
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
|
|
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
|
0xc0 // END_COLLECTION
|
|
};
|
|
|