A Composite device with USBSerial and USBKeyboard

Dependents:   USBSerialKeyboard_Example

Committer:
p3p
Date:
Sat Mar 30 12:27:31 2013 +0000
Revision:
1:9367d07d0707
Parent:
0:93ff83b03fd8
Initial Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p3p 0:93ff83b03fd8 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
p3p 0:93ff83b03fd8 2 *
p3p 0:93ff83b03fd8 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
p3p 0:93ff83b03fd8 4 * and associated documentation files (the "Software"), to deal in the Software without
p3p 0:93ff83b03fd8 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
p3p 0:93ff83b03fd8 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
p3p 0:93ff83b03fd8 7 * Software is furnished to do so, subject to the following conditions:
p3p 0:93ff83b03fd8 8 *
p3p 0:93ff83b03fd8 9 * The above copyright notice and this permission notice shall be included in all copies or
p3p 0:93ff83b03fd8 10 * substantial portions of the Software.
p3p 0:93ff83b03fd8 11 *
p3p 0:93ff83b03fd8 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
p3p 0:93ff83b03fd8 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
p3p 0:93ff83b03fd8 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
p3p 0:93ff83b03fd8 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
p3p 0:93ff83b03fd8 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
p3p 0:93ff83b03fd8 17 */
p3p 0:93ff83b03fd8 18
p3p 0:93ff83b03fd8 19 #ifndef USBCDCHID_H
p3p 0:93ff83b03fd8 20 #define USBCDCHID_H
p3p 0:93ff83b03fd8 21
p3p 0:93ff83b03fd8 22 /* These headers are included for child class. */
p3p 0:93ff83b03fd8 23 #include "USBEndpoints.h"
p3p 0:93ff83b03fd8 24 #include "USBDescriptor.h"
p3p 0:93ff83b03fd8 25 #include "USBDevice_Types.h"
p3p 0:93ff83b03fd8 26
p3p 0:93ff83b03fd8 27 #include "USBDevice.h"
p3p 0:93ff83b03fd8 28 #include "USBHID_Types.h"
p3p 0:93ff83b03fd8 29
p3p 0:93ff83b03fd8 30 #define REPORT_ID_KEYBOARD 1
p3p 0:93ff83b03fd8 31 #define REPORT_ID_VOLUME 3
p3p 0:93ff83b03fd8 32
p3p 0:93ff83b03fd8 33 #include "Keyboard_Types.h"
p3p 0:93ff83b03fd8 34
p3p 0:93ff83b03fd8 35 class USBCDCHID: public USBDevice {
p3p 0:93ff83b03fd8 36 public:
p3p 0:93ff83b03fd8 37
p3p 0:93ff83b03fd8 38 /*
p3p 0:93ff83b03fd8 39 * Constructor
p3p 0:93ff83b03fd8 40 *
p3p 0:93ff83b03fd8 41 * @param vendor_id Your vendor_id
p3p 0:93ff83b03fd8 42 * @param product_id Your product_id
p3p 0:93ff83b03fd8 43 * @param product_release Your preoduct_release
p3p 0:93ff83b03fd8 44 */
p3p 0:93ff83b03fd8 45 USBCDCHID(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
p3p 0:93ff83b03fd8 46
p3p 0:93ff83b03fd8 47 protected:
p3p 0:93ff83b03fd8 48
p3p 0:93ff83b03fd8 49 /*
p3p 0:93ff83b03fd8 50 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
p3p 0:93ff83b03fd8 51 *
p3p 0:93ff83b03fd8 52 * @returns pointer to the device descriptor
p3p 0:93ff83b03fd8 53 */
p3p 0:93ff83b03fd8 54 virtual uint8_t * deviceDesc();
p3p 0:93ff83b03fd8 55
p3p 0:93ff83b03fd8 56 /*
p3p 0:93ff83b03fd8 57 * Get string product descriptor
p3p 0:93ff83b03fd8 58 *
p3p 0:93ff83b03fd8 59 * @returns pointer to the string product descriptor
p3p 0:93ff83b03fd8 60 */
p3p 0:93ff83b03fd8 61 virtual uint8_t * stringIproductDesc();
p3p 0:93ff83b03fd8 62
p3p 0:93ff83b03fd8 63 /*
p3p 0:93ff83b03fd8 64 * Get string interface descriptor
p3p 0:93ff83b03fd8 65 *
p3p 0:93ff83b03fd8 66 * @returns pointer to the string interface descriptor
p3p 0:93ff83b03fd8 67 */
p3p 0:93ff83b03fd8 68 virtual uint8_t * stringIinterfaceDesc();
p3p 0:93ff83b03fd8 69
p3p 0:93ff83b03fd8 70 /*
p3p 0:93ff83b03fd8 71 * Get configuration descriptor
p3p 0:93ff83b03fd8 72 *
p3p 0:93ff83b03fd8 73 * @returns pointer to the configuration descriptor
p3p 0:93ff83b03fd8 74 */
p3p 0:93ff83b03fd8 75 virtual uint8_t * configurationDesc();
p3p 0:93ff83b03fd8 76
p3p 0:93ff83b03fd8 77 /*
p3p 0:93ff83b03fd8 78 * Send a buffer
p3p 0:93ff83b03fd8 79 *
p3p 0:93ff83b03fd8 80 * @param endpoint endpoint which will be sent the buffer
p3p 0:93ff83b03fd8 81 * @param buffer buffer to be sent
p3p 0:93ff83b03fd8 82 * @param size length of the buffer
p3p 0:93ff83b03fd8 83 * @returns true if successful
p3p 0:93ff83b03fd8 84 */
p3p 0:93ff83b03fd8 85 bool send(uint8_t * buffer, uint32_t size);
p3p 0:93ff83b03fd8 86
p3p 0:93ff83b03fd8 87 /*
p3p 0:93ff83b03fd8 88 * Read a buffer from a certain endpoint. Warning: blocking
p3p 0:93ff83b03fd8 89 *
p3p 0:93ff83b03fd8 90 * @param endpoint endpoint to read
p3p 0:93ff83b03fd8 91 * @param buffer buffer where will be stored bytes
p3p 0:93ff83b03fd8 92 * @param size the number of bytes read will be stored in *size
p3p 0:93ff83b03fd8 93 * @param maxSize the maximum length that can be read
p3p 0:93ff83b03fd8 94 * @returns true if successful
p3p 0:93ff83b03fd8 95 */
p3p 0:93ff83b03fd8 96 bool readEP(uint8_t * buffer, uint32_t * size);
p3p 0:93ff83b03fd8 97
p3p 0:93ff83b03fd8 98 /*
p3p 0:93ff83b03fd8 99 * Read a buffer from a certain endpoint. Warning: non blocking
p3p 0:93ff83b03fd8 100 *
p3p 0:93ff83b03fd8 101 * @param endpoint endpoint to read
p3p 0:93ff83b03fd8 102 * @param buffer buffer where will be stored bytes
p3p 0:93ff83b03fd8 103 * @param size the number of bytes read will be stored in *size
p3p 0:93ff83b03fd8 104 * @param maxSize the maximum length that can be read
p3p 0:93ff83b03fd8 105 * @returns true if successful
p3p 0:93ff83b03fd8 106 */
p3p 0:93ff83b03fd8 107 bool readEP_NB(uint8_t * buffer, uint32_t * size);
p3p 0:93ff83b03fd8 108
p3p 0:93ff83b03fd8 109 virtual uint8_t * reportDesc();
p3p 0:93ff83b03fd8 110 uint16_t reportLength;
p3p 0:93ff83b03fd8 111 virtual uint16_t reportDescLength() {
p3p 0:93ff83b03fd8 112 reportDesc();
p3p 0:93ff83b03fd8 113 return reportLength;
p3p 0:93ff83b03fd8 114 }
p3p 0:93ff83b03fd8 115
p3p 0:93ff83b03fd8 116 protected:
p3p 0:93ff83b03fd8 117 virtual bool USBCallback_request();
p3p 0:93ff83b03fd8 118 virtual bool USBCallback_setConfiguration(uint8_t configuration);
p3p 0:93ff83b03fd8 119 volatile bool terminal_connected;
p3p 0:93ff83b03fd8 120
p3p 0:93ff83b03fd8 121 HID_REPORT outputReport;
p3p 0:93ff83b03fd8 122 uint8_t output_length;
p3p 0:93ff83b03fd8 123 uint8_t input_length;
p3p 0:93ff83b03fd8 124
p3p 0:93ff83b03fd8 125 };
p3p 0:93ff83b03fd8 126
p3p 0:93ff83b03fd8 127 #endif