USB-toetsenbord
De HID-verslag "descriptor" is gewijzigd om aan te geven dat het gebruik een toetsenbord is. Deze descriptor is iets ingewikkelder. We sturen 8 bytes aan gegevens, de eerste byte is een byte van de modifier met bits vlaggen voor de shift, CTRL, ALT en andere speciale toetsen. De 2de byte is nutteloos. De laatste 6 bytes bevatten toetscodes (geen ASCII) van toetsen worden ingedrukt.
De C gegevens struct eruit:
static struct keyboard_report_t { uint8_t modifier; // bit flags for shift, ctrl, and alt, and other stuff uint8_t reserved; // useless for now uint8_t key[6]; // HID keycodes } keyboard_report;
De HID-verslag "descriptor" ziet eruit als
PROGMEM char usbHidReportDescriptor[63] = { // make sure the size matches USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH in usbconfig.h 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 };
Deze descriptor is een soort van "gestandaardiseerde" zodat het werkt zonder een besturingssysteem. "usbconfig.h" bevat enkele wijzigingen in de subklasse van de interface en het protocol inschakelen "boot protocol" zodat het werkt zonder een besturingssysteem (bijvoorbeeld wanneer u in de BIOS menu's bent).
Een V-USB functie genaamd "usbFunctionWrite" wordt ook gemaakt voor het afhandelen van de situatie wanneer de computer wil vertellen van het toetsenbord aan of uitschakelen status-LED's, zoals de CAPS LOCK, NUM LOCK of SCROLL LOCK. De functie is geschreven, maar het doet eigenlijk niets.
// data from the computer is handled here // this is actually going to be stuff like NUM LOCK, CAPS LOCK, and SCROLL LOCK LED data unsigned char usbFunctionWrite(unsigned char *data, unsigned char len) { // ignore this data return len; }
De functie "usbFunctionSetup" is een beetje langer om wat meer dingen zoals het wijzigen van het huidige protocol, en roepen "usbFunctionWrite".
Enkele andere kleine wijzigingen werden gemaakt in "usbconfig.h", voornamelijk de leverancier en product-id's zijn gewijzigd. De lengte van de HID verslag "descriptor" is ook aangepast aan de grootte van de matrix.