BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:55:34 2018 +0000
Revision:
2:798925c9e4a8
Parent:
1:9c5af431a1f1
bluetooth

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gustavatmel 1:9c5af431a1f1 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
gustavatmel 1:9c5af431a1f1 2 *
gustavatmel 1:9c5af431a1f1 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
gustavatmel 1:9c5af431a1f1 4 * and associated documentation files (the "Software"), to deal in the Software without
gustavatmel 1:9c5af431a1f1 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
gustavatmel 1:9c5af431a1f1 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
gustavatmel 1:9c5af431a1f1 7 * Software is furnished to do so, subject to the following conditions:
gustavatmel 1:9c5af431a1f1 8 *
gustavatmel 1:9c5af431a1f1 9 * The above copyright notice and this permission notice shall be included in all copies or
gustavatmel 1:9c5af431a1f1 10 * substantial portions of the Software.
gustavatmel 1:9c5af431a1f1 11 *
gustavatmel 1:9c5af431a1f1 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
gustavatmel 1:9c5af431a1f1 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
gustavatmel 1:9c5af431a1f1 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
gustavatmel 1:9c5af431a1f1 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gustavatmel 1:9c5af431a1f1 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gustavatmel 1:9c5af431a1f1 17 */
gustavatmel 1:9c5af431a1f1 18
gustavatmel 1:9c5af431a1f1 19 #ifndef USB_HID_H
gustavatmel 1:9c5af431a1f1 20 #define USB_HID_H
gustavatmel 1:9c5af431a1f1 21
gustavatmel 1:9c5af431a1f1 22 /* These headers are included for child class. */
gustavatmel 1:9c5af431a1f1 23 #include "USBEndpoints.h"
gustavatmel 1:9c5af431a1f1 24 #include "USBDescriptor.h"
gustavatmel 1:9c5af431a1f1 25 #include "USBDevice_Types.h"
gustavatmel 1:9c5af431a1f1 26
gustavatmel 1:9c5af431a1f1 27 #include "USBHID_Types.h"
gustavatmel 1:9c5af431a1f1 28 #include "USBDevice.h"
gustavatmel 1:9c5af431a1f1 29
gustavatmel 1:9c5af431a1f1 30
gustavatmel 1:9c5af431a1f1 31 /**
gustavatmel 1:9c5af431a1f1 32 * USBHID example
gustavatmel 1:9c5af431a1f1 33 * @code
gustavatmel 1:9c5af431a1f1 34 * #include "mbed.h"
gustavatmel 1:9c5af431a1f1 35 * #include "USBHID.h"
gustavatmel 1:9c5af431a1f1 36 *
gustavatmel 1:9c5af431a1f1 37 * USBHID hid;
gustavatmel 1:9c5af431a1f1 38 * HID_REPORT recv;
gustavatmel 1:9c5af431a1f1 39 * BusOut leds(LED1,LED2,LED3,LED4);
gustavatmel 1:9c5af431a1f1 40 *
gustavatmel 1:9c5af431a1f1 41 * int main(void) {
gustavatmel 1:9c5af431a1f1 42 * while (1) {
gustavatmel 1:9c5af431a1f1 43 * hid.read(&recv);
gustavatmel 1:9c5af431a1f1 44 * leds = recv.data[0];
gustavatmel 1:9c5af431a1f1 45 * }
gustavatmel 1:9c5af431a1f1 46 * }
gustavatmel 1:9c5af431a1f1 47 * @endcode
gustavatmel 1:9c5af431a1f1 48 */
gustavatmel 1:9c5af431a1f1 49
gustavatmel 1:9c5af431a1f1 50 class USBHID: public USBDevice {
gustavatmel 1:9c5af431a1f1 51 public:
gustavatmel 1:9c5af431a1f1 52
gustavatmel 1:9c5af431a1f1 53 /**
gustavatmel 1:9c5af431a1f1 54 * Constructor
gustavatmel 1:9c5af431a1f1 55 *
gustavatmel 1:9c5af431a1f1 56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
gustavatmel 1:9c5af431a1f1 57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
gustavatmel 1:9c5af431a1f1 58 * @param vendor_id Your vendor_id
gustavatmel 1:9c5af431a1f1 59 * @param product_id Your product_id
gustavatmel 1:9c5af431a1f1 60 * @param product_release Your preoduct_release
gustavatmel 1:9c5af431a1f1 61 * @param connect Connect the device
gustavatmel 1:9c5af431a1f1 62 */
gustavatmel 1:9c5af431a1f1 63 USBHID(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
gustavatmel 1:9c5af431a1f1 64
gustavatmel 1:9c5af431a1f1 65
gustavatmel 1:9c5af431a1f1 66 /**
gustavatmel 1:9c5af431a1f1 67 * Send a Report. warning: blocking
gustavatmel 1:9c5af431a1f1 68 *
gustavatmel 1:9c5af431a1f1 69 * @param report Report which will be sent (a report is defined by all data and the length)
gustavatmel 1:9c5af431a1f1 70 * @returns true if successful
gustavatmel 1:9c5af431a1f1 71 */
gustavatmel 1:9c5af431a1f1 72 bool send(HID_REPORT *report);
gustavatmel 1:9c5af431a1f1 73
gustavatmel 1:9c5af431a1f1 74
gustavatmel 1:9c5af431a1f1 75 /**
gustavatmel 1:9c5af431a1f1 76 * Send a Report. warning: non blocking
gustavatmel 1:9c5af431a1f1 77 *
gustavatmel 1:9c5af431a1f1 78 * @param report Report which will be sent (a report is defined by all data and the length)
gustavatmel 1:9c5af431a1f1 79 * @returns true if successful
gustavatmel 1:9c5af431a1f1 80 */
gustavatmel 1:9c5af431a1f1 81 bool sendNB(HID_REPORT *report);
gustavatmel 1:9c5af431a1f1 82
gustavatmel 1:9c5af431a1f1 83 /**
gustavatmel 1:9c5af431a1f1 84 * Read a report: blocking
gustavatmel 1:9c5af431a1f1 85 *
gustavatmel 1:9c5af431a1f1 86 * @param report pointer to the report to fill
gustavatmel 1:9c5af431a1f1 87 * @returns true if successful
gustavatmel 1:9c5af431a1f1 88 */
gustavatmel 1:9c5af431a1f1 89 bool read(HID_REPORT * report);
gustavatmel 1:9c5af431a1f1 90
gustavatmel 1:9c5af431a1f1 91 /**
gustavatmel 1:9c5af431a1f1 92 * Read a report: non blocking
gustavatmel 1:9c5af431a1f1 93 *
gustavatmel 1:9c5af431a1f1 94 * @param report pointer to the report to fill
gustavatmel 1:9c5af431a1f1 95 * @returns true if successful
gustavatmel 1:9c5af431a1f1 96 */
gustavatmel 1:9c5af431a1f1 97 bool readNB(HID_REPORT * report);
gustavatmel 1:9c5af431a1f1 98
gustavatmel 1:9c5af431a1f1 99 protected:
gustavatmel 1:9c5af431a1f1 100 uint16_t reportLength;
gustavatmel 1:9c5af431a1f1 101 uint8_t reportDescriptor[27];
gustavatmel 1:9c5af431a1f1 102
gustavatmel 1:9c5af431a1f1 103 /*
gustavatmel 1:9c5af431a1f1 104 * Get the Report descriptor
gustavatmel 1:9c5af431a1f1 105 *
gustavatmel 1:9c5af431a1f1 106 * @returns pointer to the report descriptor
gustavatmel 1:9c5af431a1f1 107 */
gustavatmel 1:9c5af431a1f1 108 virtual const uint8_t * reportDesc();
gustavatmel 1:9c5af431a1f1 109
gustavatmel 1:9c5af431a1f1 110 /*
gustavatmel 1:9c5af431a1f1 111 * Get the length of the report descriptor
gustavatmel 1:9c5af431a1f1 112 *
gustavatmel 1:9c5af431a1f1 113 * @returns the length of the report descriptor
gustavatmel 1:9c5af431a1f1 114 */
gustavatmel 1:9c5af431a1f1 115 virtual uint16_t reportDescLength();
gustavatmel 1:9c5af431a1f1 116
gustavatmel 1:9c5af431a1f1 117 /*
gustavatmel 1:9c5af431a1f1 118 * Get string product descriptor
gustavatmel 1:9c5af431a1f1 119 *
gustavatmel 1:9c5af431a1f1 120 * @returns pointer to the string product descriptor
gustavatmel 1:9c5af431a1f1 121 */
gustavatmel 1:9c5af431a1f1 122 virtual const uint8_t * stringIproductDesc();
gustavatmel 1:9c5af431a1f1 123
gustavatmel 1:9c5af431a1f1 124 /*
gustavatmel 1:9c5af431a1f1 125 * Get string interface descriptor
gustavatmel 1:9c5af431a1f1 126 *
gustavatmel 1:9c5af431a1f1 127 * @returns pointer to the string interface descriptor
gustavatmel 1:9c5af431a1f1 128 */
gustavatmel 1:9c5af431a1f1 129 virtual const uint8_t * stringIinterfaceDesc();
gustavatmel 1:9c5af431a1f1 130
gustavatmel 1:9c5af431a1f1 131 /*
gustavatmel 1:9c5af431a1f1 132 * Get configuration descriptor
gustavatmel 1:9c5af431a1f1 133 *
gustavatmel 1:9c5af431a1f1 134 * @returns pointer to the configuration descriptor
gustavatmel 1:9c5af431a1f1 135 */
gustavatmel 1:9c5af431a1f1 136 virtual const uint8_t * configurationDesc();
gustavatmel 1:9c5af431a1f1 137
gustavatmel 1:9c5af431a1f1 138
gustavatmel 1:9c5af431a1f1 139 /*
gustavatmel 1:9c5af431a1f1 140 * HID Report received by SET_REPORT request. Warning: Called in ISR context
gustavatmel 1:9c5af431a1f1 141 * First byte of data will be the report ID
gustavatmel 1:9c5af431a1f1 142 *
gustavatmel 1:9c5af431a1f1 143 * @param report Data and length received
gustavatmel 1:9c5af431a1f1 144 */
gustavatmel 1:9c5af431a1f1 145 virtual void HID_callbackSetReport(HID_REPORT *report){};
gustavatmel 1:9c5af431a1f1 146
gustavatmel 1:9c5af431a1f1 147
gustavatmel 1:9c5af431a1f1 148 /*
gustavatmel 1:9c5af431a1f1 149 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
gustavatmel 1:9c5af431a1f1 150 * This is used to handle extensions to standard requests
gustavatmel 1:9c5af431a1f1 151 * and class specific requests
gustavatmel 1:9c5af431a1f1 152 *
gustavatmel 1:9c5af431a1f1 153 * @returns true if class handles this request
gustavatmel 1:9c5af431a1f1 154 */
gustavatmel 1:9c5af431a1f1 155 virtual bool USBCallback_request();
gustavatmel 1:9c5af431a1f1 156
gustavatmel 1:9c5af431a1f1 157
gustavatmel 1:9c5af431a1f1 158 /*
gustavatmel 1:9c5af431a1f1 159 * Called by USBDevice layer. Set configuration of the device.
gustavatmel 1:9c5af431a1f1 160 * For instance, you can add all endpoints that you need on this function.
gustavatmel 1:9c5af431a1f1 161 *
gustavatmel 1:9c5af431a1f1 162 * @param configuration Number of the configuration
gustavatmel 1:9c5af431a1f1 163 * @returns true if class handles this request
gustavatmel 1:9c5af431a1f1 164 */
gustavatmel 1:9c5af431a1f1 165 virtual bool USBCallback_setConfiguration(uint8_t configuration);
gustavatmel 1:9c5af431a1f1 166
gustavatmel 1:9c5af431a1f1 167 private:
gustavatmel 1:9c5af431a1f1 168 uint8_t configurationDescriptor[41];
gustavatmel 1:9c5af431a1f1 169 HID_REPORT outputReport;
gustavatmel 1:9c5af431a1f1 170 uint8_t output_length;
gustavatmel 1:9c5af431a1f1 171 uint8_t input_length;
gustavatmel 1:9c5af431a1f1 172 };
gustavatmel 1:9c5af431a1f1 173
gustavatmel 1:9c5af431a1f1 174 #endif