B. H. / Mbed 2 deprecated trolololol

Dependencies:   mbed

Revision:
0:505207de8566
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice/USBHID/.svn/text-base/RawHID.cpp.svn-base	Tue Nov 29 21:26:20 2011 +0000
@@ -0,0 +1,130 @@
+/* USBKeyboard.c */
+/* USB device example: Standard keyboard */
+/* Copyright (c) 2011 ARM Limited. All rights reserved. */
+
+#include "stdint.h"
+
+#include "RawHID.h"
+
+/*
+ *  Descriptors
+ */
+
+#define RAWHID_USAGE_PAGE    0xFFAB    // recommended: 0xFF00 to 0xFFFF
+#define RAWHID_USAGE        0x0200    // recommended: 0x0100 to 0xFFFF
+
+uint8_t * RawHID::ReportDesc() {
+    static uint8_t reportDescriptor[] = {
+        0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
+        0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
+        0xA1, 0x01,                // Collection 0x01
+        0x75, 0x08,                // report size = 8 bits
+        0x15, 0x00,                // logical minimum = 0
+        0x26, 0xFF, 0x00,            // logical maximum = 255
+        0x95, 64,            // report count
+        0x09, 0x01,                // usage
+        0x81, 0x02,                // Input (array)
+        0x95, 64,            // report count
+        0x09, 0x02,                // usage
+        0x91, 0x02,                // Output (array)
+        0xC0                    // end collection
+
+    };
+    reportLength = sizeof(reportDescriptor);
+    return reportDescriptor;
+}
+
+
+#define DEFAULT_CONFIGURATION (1)
+#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
+                               + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
+                               + (1 * HID_DESCRIPTOR_LENGTH) \
+                               + (2 * ENDPOINT_DESCRIPTOR_LENGTH))
+
+uint8_t * RawHID::ConfigurationDesc() {
+    static uint8_t configurationDescriptor[] = {
+        CONFIGURATION_DESCRIPTOR_LENGTH,/* bLength */
+        CONFIGURATION_DESCRIPTOR,       /* bDescriptorType */
+        LSB(TOTAL_DESCRIPTOR_LENGTH),   /* wTotalLength (LSB) */
+        MSB(TOTAL_DESCRIPTOR_LENGTH),   /* wTotalLength (MSB) */
+        0x01,                           /* bNumInterfaces */
+        DEFAULT_CONFIGURATION,          /* bConfigurationValue */
+        0x00,                           /* iConfiguration */
+        C_RESERVED | C_SELF_POWERED,    /* bmAttributes */
+        C_POWER(0),                     /* bMaxPower */
+
+        INTERFACE_DESCRIPTOR_LENGTH,    /* bLength */
+        INTERFACE_DESCRIPTOR,           /* bDescriptorType */
+        0x00,                           /* bInterfaceNumber */
+        0x00,                           /* bAlternateSetting */
+        0x02,                           /* bNumEndpoints */
+        HID_CLASS,                      /* bInterfaceClass */
+        HID_SUBCLASS_NONE,              /* bInterfaceSubClass */
+        HID_PROTOCOL_NONE,              /* bInterfaceProtocol */
+        0x00,                           /* iInterface */
+
+        HID_DESCRIPTOR_LENGTH,          /* bLength */
+        HID_DESCRIPTOR,                 /* bDescriptorType */
+        LSB(HID_VERSION_1_11),          /* bcdHID (LSB) */
+        MSB(HID_VERSION_1_11),          /* bcdHID (MSB) */
+        0x00,                           /* bCountryCode */
+        0x01,                           /* bNumDescriptors */
+        REPORT_DESCRIPTOR,              /* bDescriptorType */
+        LSB(this->ReportDescLength()),    /* wDescriptorLength (LSB) */
+        MSB(this->ReportDescLength()),    /* wDescriptorLength (MSB) */
+
+        ENDPOINT_DESCRIPTOR_LENGTH,     /* bLength */
+        ENDPOINT_DESCRIPTOR,            /* bDescriptorType */
+        PHY_TO_DESC(EPINT_IN),          /* bEndpointAddress */
+        E_INTERRUPT,                    /* bmAttributes */
+        LSB(MAX_PACKET_SIZE_EPINT),     /* wMaxPacketSize (LSB) */
+        MSB(MAX_PACKET_SIZE_EPINT),     /* wMaxPacketSize (MSB) */
+        10,                             /* bInterval (milliseconds) */
+        
+        ENDPOINT_DESCRIPTOR_LENGTH,     /* bLength */
+        ENDPOINT_DESCRIPTOR,            /* bDescriptorType */
+        PHY_TO_DESC(EPINT_OUT),          /* bEndpointAddress */
+        E_INTERRUPT,                    /* bmAttributes */
+        LSB(MAX_PACKET_SIZE_EPINT),     /* wMaxPacketSize (LSB) */
+        MSB(MAX_PACKET_SIZE_EPINT),     /* wMaxPacketSize (MSB) */
+        10,                             /* bInterval (milliseconds) */
+    };
+    return configurationDescriptor;
+}
+
+bool RawHID::send(uint8_t * buf, uint8_t length)
+{
+    HID_REPORT report;
+    for(int i = 0; i < length; i++)
+        report.data[i] = buf[i];
+    for(int i = length; i < MAX_PACKET_SIZE_EPINT; i++) 
+        report.data[i] = 0;
+    report.length = MAX_PACKET_SIZE_EPINT;
+    return USBHID_send(EPINT_IN, &report);
+    
+}
+
+bool RawHID::USBCallback_setConfiguration(uint8_t configuration) {
+    /* Called in ISR context */
+
+    /* Set configuration. Return false if the */
+    /* configuration is not supported. */
+    if (configuration != DEFAULT_CONFIGURATION) {
+        return false;
+    }
+
+    /* Configure endpoints > 0 */
+    USBDevice_addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
+    USBDevice_addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
+    return true;
+}
+
+bool RawHID::recv(HID_REPORT& report)
+{
+    return USBHID_read(EPINT_OUT, &report);
+}
+
+bool RawHID::recvNB(HID_REPORT& report)
+{
+    return USBHID_readNB(EPINT_OUT, &report);
+}