Base station firmware

Committer:
Perijah
Date:
Tue May 24 13:16:55 2016 +0000
Revision:
0:ecc3925d3f8c
Base station firmware

Who changed what in which revision?

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