SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

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