USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Fri Nov 11 15:22:53 2011 +0000
Revision:
2:27a7e7f8d399
we have 2MB with the sdcard!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 2:27a7e7f8d399 1 /* USBHID.h */
samux 2:27a7e7f8d399 2 /* Human Interface Device (HID) class */
samux 2:27a7e7f8d399 3 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
samux 2:27a7e7f8d399 4
samux 2:27a7e7f8d399 5 #ifndef USB_HID_H
samux 2:27a7e7f8d399 6 #define USB_HID_H
samux 2:27a7e7f8d399 7
samux 2:27a7e7f8d399 8 /* These headers are included for child class. */
samux 2:27a7e7f8d399 9 #include "USBEndpoints.h"
samux 2:27a7e7f8d399 10 #include "USBDescriptor.h"
samux 2:27a7e7f8d399 11 #include "USBDevice_Types.h"
samux 2:27a7e7f8d399 12
samux 2:27a7e7f8d399 13 #include "USBHID_Types.h"
samux 2:27a7e7f8d399 14 #include "USBDevice.h"
samux 2:27a7e7f8d399 15
samux 2:27a7e7f8d399 16
samux 2:27a7e7f8d399 17 /**
samux 2:27a7e7f8d399 18 * USBHID example
samux 2:27a7e7f8d399 19 * @code
samux 2:27a7e7f8d399 20 * #include "mbed.h"
samux 2:27a7e7f8d399 21 * #include "USBHID.h"
samux 2:27a7e7f8d399 22 *
samux 2:27a7e7f8d399 23 * USBHID hid;
samux 2:27a7e7f8d399 24 * HID_REPORT recv;
samux 2:27a7e7f8d399 25 * BusOut leds(LED1,LED2,LED3,LED4);
samux 2:27a7e7f8d399 26 *
samux 2:27a7e7f8d399 27 * int main(void) {
samux 2:27a7e7f8d399 28 * while (1) {
samux 2:27a7e7f8d399 29 * hid.read(&recv);
samux 2:27a7e7f8d399 30 * leds = recv.data[0];
samux 2:27a7e7f8d399 31 * }
samux 2:27a7e7f8d399 32 * }
samux 2:27a7e7f8d399 33 * @endcode
samux 2:27a7e7f8d399 34 */
samux 2:27a7e7f8d399 35
samux 2:27a7e7f8d399 36 class USBHID: public USBDevice {
samux 2:27a7e7f8d399 37 public:
samux 2:27a7e7f8d399 38
samux 2:27a7e7f8d399 39 /**
samux 2:27a7e7f8d399 40 * Constructor
samux 2:27a7e7f8d399 41 *
samux 2:27a7e7f8d399 42 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
samux 2:27a7e7f8d399 43 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
samux 2:27a7e7f8d399 44 * @param vendor_id Your vendor_id
samux 2:27a7e7f8d399 45 * @param product_id Your product_id
samux 2:27a7e7f8d399 46 * @param product_release Your preoduct_release
samux 2:27a7e7f8d399 47 */
samux 2:27a7e7f8d399 48 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);
samux 2:27a7e7f8d399 49
samux 2:27a7e7f8d399 50
samux 2:27a7e7f8d399 51 /**
samux 2:27a7e7f8d399 52 * Send a Report
samux 2:27a7e7f8d399 53 *
samux 2:27a7e7f8d399 54 * @param report Report which will be sent (a report is defined by all data and the length)
samux 2:27a7e7f8d399 55 * @returns true if successful
samux 2:27a7e7f8d399 56 */
samux 2:27a7e7f8d399 57 bool send(HID_REPORT *report);
samux 2:27a7e7f8d399 58
samux 2:27a7e7f8d399 59 /**
samux 2:27a7e7f8d399 60 * Read a report: blocking
samux 2:27a7e7f8d399 61 *
samux 2:27a7e7f8d399 62 * @param report pointer to the report to fill
samux 2:27a7e7f8d399 63 * @returns true if successful
samux 2:27a7e7f8d399 64 */
samux 2:27a7e7f8d399 65 bool read(HID_REPORT * report);
samux 2:27a7e7f8d399 66
samux 2:27a7e7f8d399 67 /**
samux 2:27a7e7f8d399 68 * Read a report: non blocking
samux 2:27a7e7f8d399 69 *
samux 2:27a7e7f8d399 70 * @param report pointer to the report to fill
samux 2:27a7e7f8d399 71 * @returns true if successful
samux 2:27a7e7f8d399 72 */
samux 2:27a7e7f8d399 73 bool readNB(HID_REPORT * report);
samux 2:27a7e7f8d399 74
samux 2:27a7e7f8d399 75 protected:
samux 2:27a7e7f8d399 76 uint16_t reportLength;
samux 2:27a7e7f8d399 77
samux 2:27a7e7f8d399 78 /*
samux 2:27a7e7f8d399 79 * Get the Report descriptor
samux 2:27a7e7f8d399 80 *
samux 2:27a7e7f8d399 81 * @returns pointer to the report descriptor
samux 2:27a7e7f8d399 82 */
samux 2:27a7e7f8d399 83 virtual uint8_t * reportDesc();
samux 2:27a7e7f8d399 84
samux 2:27a7e7f8d399 85 /*
samux 2:27a7e7f8d399 86 * Get the length of the report descriptor
samux 2:27a7e7f8d399 87 *
samux 2:27a7e7f8d399 88 * @returns the length of the report descriptor
samux 2:27a7e7f8d399 89 */
samux 2:27a7e7f8d399 90 virtual uint16_t reportDescLength();
samux 2:27a7e7f8d399 91
samux 2:27a7e7f8d399 92 /*
samux 2:27a7e7f8d399 93 * Get string product descriptor
samux 2:27a7e7f8d399 94 *
samux 2:27a7e7f8d399 95 * @returns pointer to the string product descriptor
samux 2:27a7e7f8d399 96 */
samux 2:27a7e7f8d399 97 virtual uint8_t * stringIproductDesc();
samux 2:27a7e7f8d399 98
samux 2:27a7e7f8d399 99 /*
samux 2:27a7e7f8d399 100 * Get string interface descriptor
samux 2:27a7e7f8d399 101 *
samux 2:27a7e7f8d399 102 * @returns pointer to the string interface descriptor
samux 2:27a7e7f8d399 103 */
samux 2:27a7e7f8d399 104 virtual uint8_t * stringIinterfaceDesc();
samux 2:27a7e7f8d399 105
samux 2:27a7e7f8d399 106 /*
samux 2:27a7e7f8d399 107 * Get configuration descriptor
samux 2:27a7e7f8d399 108 *
samux 2:27a7e7f8d399 109 * @returns pointer to the configuration descriptor
samux 2:27a7e7f8d399 110 */
samux 2:27a7e7f8d399 111 virtual uint8_t * configurationDesc();
samux 2:27a7e7f8d399 112
samux 2:27a7e7f8d399 113
samux 2:27a7e7f8d399 114 /*
samux 2:27a7e7f8d399 115 * HID Report received by SET_REPORT request. Warning: Called in ISR context
samux 2:27a7e7f8d399 116 * First byte of data will be the report ID
samux 2:27a7e7f8d399 117 *
samux 2:27a7e7f8d399 118 * @param report Data and length received
samux 2:27a7e7f8d399 119 */
samux 2:27a7e7f8d399 120 virtual void HID_callbackSetReport(HID_REPORT *report){};
samux 2:27a7e7f8d399 121
samux 2:27a7e7f8d399 122
samux 2:27a7e7f8d399 123 /*
samux 2:27a7e7f8d399 124 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
samux 2:27a7e7f8d399 125 * This is used to handle extensions to standard requests
samux 2:27a7e7f8d399 126 * and class specific requests
samux 2:27a7e7f8d399 127 *
samux 2:27a7e7f8d399 128 * @returns true if class handles this request
samux 2:27a7e7f8d399 129 */
samux 2:27a7e7f8d399 130 virtual bool USBCallback_request();
samux 2:27a7e7f8d399 131
samux 2:27a7e7f8d399 132 /*
samux 2:27a7e7f8d399 133 * Called by USBDevice on Endpoint0 request completion
samux 2:27a7e7f8d399 134 * if the 'notify' flag has been set to true. Warning: Called in ISR context
samux 2:27a7e7f8d399 135 *
samux 2:27a7e7f8d399 136 * In this case it is used to indicate that a HID report has
samux 2:27a7e7f8d399 137 * been received from the host on endpoint 0
samux 2:27a7e7f8d399 138 */
samux 2:27a7e7f8d399 139 virtual void USBCallback_requestCompleted();
samux 2:27a7e7f8d399 140
samux 2:27a7e7f8d399 141 /*
samux 2:27a7e7f8d399 142 * Called by USBDevice layer. Set configuration of the device.
samux 2:27a7e7f8d399 143 * For instance, you can add all endpoints that you need on this function.
samux 2:27a7e7f8d399 144 *
samux 2:27a7e7f8d399 145 * @param configuration Number of the configuration
samux 2:27a7e7f8d399 146 * @returns true if class handles this request
samux 2:27a7e7f8d399 147 */
samux 2:27a7e7f8d399 148 virtual bool USBCallback_setConfiguration(uint8_t configuration);
samux 2:27a7e7f8d399 149
samux 2:27a7e7f8d399 150 private:
samux 2:27a7e7f8d399 151 HID_REPORT outputReport;
samux 2:27a7e7f8d399 152 uint8_t output_length;
samux 2:27a7e7f8d399 153 uint8_t input_length;
samux 2:27a7e7f8d399 154 };
samux 2:27a7e7f8d399 155
samux 2:27a7e7f8d399 156 #endif