From eddda61c598452ff2981b4f08d23258f448b3d0d Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Sep 2016 14:32:16 +0100 Subject: fish --- app/consumer.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/consumer.c diff --git a/app/consumer.c b/app/consumer.c new file mode 100644 index 0000000..a73853b --- /dev/null +++ b/app/consumer.c @@ -0,0 +1,92 @@ +#include "project.h" + + +static const uint8_t consumer_report_descriptor[] = { + 0x05, 0x0c, /* Usage Page (Consumer Devices) */ + 0x09, 0x01, /* Usage (Consumer Control) */ + 0xA1, 0x01, /* Collection (Application) */ + 0x15, 0x00, /* Logical minimum (0) */ + 0x25, 0x01, /* Logical maximum (1) */ + 0x75, 0x01, /* Report size (1) */ + 0x95, 0x10, /* Report count (16) */ + + 0x09, 0xb5, /* USAGE (Scan Next Track) */ + 0x09, 0xb6, /* USAGE (Scan Prev Track) */ + 0x09, 0xb7, /* USAGE (Stop) */ + 0x09, 0xcd, /* USAGE (Play/Pause) */ + + 0x09, 0xe2, /* USAGE (Mute) */ + 0x09, 0xe9, /* USAGE (Volume up) */ + 0x09, 0xea, /* USAGE (Volume down) */ + 0x0a, 0x21, 0x02, /* USAGE (www search) */ + + 0x0a, 0x23, 0x02, /* USAGE (www home) */ + 0x0a, 0x24, 0x02, /* USAGE (www back) */ + 0x0a, 0x25, 0x02, /* USAGE (www forward) */ + 0x0a, 0x26, 0x02, /* USAGE (www stop) */ + + 0x0a, 0x27, 0x02, /* USAGE (www refresh) */ + 0x0a, 0x2a, 0x02, /* USAGE (www favourites) */ + 0x0a, 0x8a, 0x01, /* USAGE (Mail) */ + 0x0a, 0x92, 0x01, /* USAGE (Calculator) */ + + 0x81, 0x62, /* Input (data, variable, relative, preferreed) */ + 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)) consumer_function = +{ + .hid_descriptor = + { + .bLength = sizeof (consumer_function),.bDescriptorType = + USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,} + ,.hid_report = + { + .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength = + sizeof (consumer_report_descriptor),} +,}; + +const struct usb_endpoint_descriptor consumer_endpoint = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x82, + .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, + .wMaxPacketSize = 2, + .bInterval = 0x1 //0x20, +}; + +const struct usb_interface_descriptor consumer_iface = { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 1, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_CLASS_HID, + .bInterfaceSubClass = 1, /* boot */ + .bInterfaceProtocol = 1, /* consumer */ + .iInterface = 6, + + .endpoint = &consumer_endpoint, + + .extra = &consumer_function, + .extralen = sizeof (consumer_function), +}; + + +void +consumer_get_descriptor (uint8_t ** buf, uint16_t * len) +{ + + /* Handle the HID report descriptor. */ + *buf = (uint8_t *) consumer_report_descriptor; + *len = sizeof (consumer_report_descriptor); +} -- cgit v1.2.3