summaryrefslogtreecommitdiffstats
path: root/app/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/keyboard.c')
-rw-r--r--app/keyboard.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/app/keyboard.c b/app/keyboard.c
new file mode 100644
index 0000000..e9046a3
--- /dev/null
+++ b/app/keyboard.c
@@ -0,0 +1,140 @@
+#include "project.h"
+
+#if 0
+static const uint8_t keyboard_report_descriptor[] = {
+ 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
+ 0x09, 0x01, /* USAGE (Keyboard */
+ 0xa1, 0x01, /* COLLECTION (Application) */
+ 0x05, 0x07, /* USAGE_PAGE (Key Codes) */
+ 0x19, 0xe0, /* USAGE_MINIMUM (Control Left) */
+ 0x29, 0xe7, /* USAGE_MAXIMUM (GUI Right) */
+ 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, 0x01, /* INPUT (Cnst,Ary,Abs) */
+ 0x95, 0x05, /* REPORT_COUNT (5) */
+ 0x75, 0x01, /* REPORT_SIZE (1) */
+#if 0
+ 0x05, 0x08, /* USAGE_PAGE (LEDs) */
+ 0x19, 0x01, /* USAGE_MINIMUM (NumLock) */
+ 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */
+ 0x ? ?, 0x02, /* OUTPUT (Data,Var,Abs) */
+ 0x95, 0x01, /* REPORT_COUNT (1) */
+ 0x75, 0x03, /* REPORT_SIZE (3) */
+ 0x ? ?, 0x01, /* OUTPUT (Cnst,Ary,Abs) */
+ 0x95, 0x06, /* REPORT_COUNT (6) */
+ 0x75, 0x03, /* REPORT_SIZE (8) */
+ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
+ 0x25, 0xff, 0x00, /*LOGICAL_MAXIMUM (255) */
+#endif
+ 0x05, 0x07, /* USAGE_PAGE (Key Codes) */
+ 0x19, 0x00, /* USAGE_MINIMUM (?) */
+ 0x29, 0x98, /* USAGE_MAXIMUM (LANG 9) */
+ 0xc0 /* END_COLLECTION */
+};
+#endif
+
+static const uint8_t keyboard_report_descriptor[] = {
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
+ 0x09, 0x06, /* Usage (Keyboard) */
+ 0xA1, 0x01, /* Collection (Application) */
+ 0x05, 0x07, /* Usage page (Key Codes) */
+ 0x19, 0xE0, /* Usage minimum (224) */
+ 0x29, 0xE7, /* Usage maximum (231) */
+ 0x15, 0x00, /* Logical minimum (0) */
+ 0x25, 0x01, /* Logical maximum (1) */
+ 0x75, 0x01, /* Report size (1) */
+ 0x95, 0x08, /* Report count (8) */
+ 0x81, 0x02, /* Input (data, variable, absolute) */
+ 0x95, 0x01, /* Report count (1) */
+ 0x75, 0x08, /* Report size (8) */
+ 0x81, 0x01, /* Input (constant) */
+ 0x95, 0x06, /* Report count (6) */
+ 0x75, 0x08, /* Report size (8) */
+ 0x15, 0x00, /* Logical minimum (0) */
+ 0x25, 0x65, /* Logical maximum (101) */
+ 0x05, 0x07, /* Usage page (key codes) */
+ 0x19, 0x00, /* Usage minimum (0) */
+ 0x2A, 0xff, 0x00, /* Usage maximum (255) */
+// 0x29, 0x65, /* Usage maximum (101) */
+// 0x2A, 0xff, 0x03, /* Usage maximum (1023) */
+ 0x81, 0x00, /* Input (data, array) */
+ 0xC0 /* End Collection */
+};
+
+
+static const struct
+{
+ struct usb_hid_descriptor hid_descriptor;
+ struct
+ {
+ uint8_t bReportDescriptorType;
+ uint16_t wDescriptorLength;
+ } __attribute__ ((packed)) hid_report;
+} __attribute__ ((packed)) keyboard_function =
+{
+ .hid_descriptor =
+ {
+ .bLength = sizeof (keyboard_function),.bDescriptorType =
+ USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,}
+ ,.hid_report =
+ {
+ .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength =
+ sizeof (keyboard_report_descriptor),}
+,};
+
+const struct usb_endpoint_descriptor keyboard_endpoint = {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x81,
+ .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
+ .wMaxPacketSize = 8,
+ .bInterval = 0x20,
+};
+
+const struct usb_interface_descriptor keyboard_iface = {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 0,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 1,
+ .bInterfaceClass = USB_CLASS_HID,
+ .bInterfaceSubClass = 1, /* boot */
+ .bInterfaceProtocol = 1, /* keyboard */
+ .iInterface = 0,
+
+ .endpoint = &keyboard_endpoint,
+
+ .extra = &keyboard_function,
+ .extralen = sizeof (keyboard_function),
+};
+
+
+void
+keyboard_get_descriptor (uint8_t ** buf, uint16_t * len)
+{
+
+ /* Handle the HID report descriptor. */
+ *buf = (uint8_t *) keyboard_report_descriptor;
+ *len = sizeof (keyboard_report_descriptor);
+}
+
+void
+keyboard_test (void)
+{
+ static int c = 0;
+ uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+
+ buf[0] = (c >> 1) & 7;
+
+ buf[2] = (c & 1) ? 12 : 0;
+
+ c++;
+
+ usbd_ep_write_packet (usbd_dev, 0x81, buf, 8);
+}