Dependencies:   ChaNFSSD mbed ChaNFS

Committer:
okini3939
Date:
Thu Nov 10 03:20:42 2011 +0000
Revision:
1:efbcfbae4747
Parent:
0:02c293160df3

        

Who changed what in which revision?

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