USB composite device example program, drag-and-drop flash writer.

Dependencies:   SWD USBDevice mbed BaseDAP

Committer:
va009039
Date:
Sat Sep 28 03:21:14 2013 +0000
Revision:
1:ea8e179320d7
add USBMSD_Drop class. add CDC(Virtual COM) and HID(for example CMSIS-DAP), but KL25Z not work.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 1:ea8e179320d7 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
va009039 1:ea8e179320d7 2 *
va009039 1:ea8e179320d7 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
va009039 1:ea8e179320d7 4 * and associated documentation files (the "Software"), to deal in the Software without
va009039 1:ea8e179320d7 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
va009039 1:ea8e179320d7 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
va009039 1:ea8e179320d7 7 * Software is furnished to do so, subject to the following conditions:
va009039 1:ea8e179320d7 8 *
va009039 1:ea8e179320d7 9 * The above copyright notice and this permission notice shall be included in all copies or
va009039 1:ea8e179320d7 10 * substantial portions of the Software.
va009039 1:ea8e179320d7 11 *
va009039 1:ea8e179320d7 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
va009039 1:ea8e179320d7 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
va009039 1:ea8e179320d7 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
va009039 1:ea8e179320d7 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
va009039 1:ea8e179320d7 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
va009039 1:ea8e179320d7 17 */
va009039 1:ea8e179320d7 18
va009039 1:ea8e179320d7 19 #pragma once
va009039 1:ea8e179320d7 20
va009039 1:ea8e179320d7 21 /* These headers are included for child class. */
va009039 1:ea8e179320d7 22 #include "USBEndpoints.h"
va009039 1:ea8e179320d7 23 #include "USBDescriptor.h"
va009039 1:ea8e179320d7 24 #include "USBDevice_Types.h"
va009039 1:ea8e179320d7 25
va009039 1:ea8e179320d7 26 #include "USBHID_Types.h"
va009039 1:ea8e179320d7 27 #include "USBDevice.h"
va009039 1:ea8e179320d7 28
va009039 1:ea8e179320d7 29 #define HID_EPINT_IN EP4IN
va009039 1:ea8e179320d7 30 #define HID_EPINT_OUT EP4OUT
va009039 1:ea8e179320d7 31
va009039 1:ea8e179320d7 32 /** USB HID device for CMSIS-DAP
va009039 1:ea8e179320d7 33 */
va009039 1:ea8e179320d7 34 class USB_HID {
va009039 1:ea8e179320d7 35 public:
va009039 1:ea8e179320d7 36
va009039 1:ea8e179320d7 37 /**
va009039 1:ea8e179320d7 38 * Constructor
va009039 1:ea8e179320d7 39 *
va009039 1:ea8e179320d7 40 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
va009039 1:ea8e179320d7 41 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
va009039 1:ea8e179320d7 42 */
va009039 1:ea8e179320d7 43 USB_HID(USBDevice* device, uint8_t output_report_length = 64, uint8_t input_report_length = 64);
va009039 1:ea8e179320d7 44
va009039 1:ea8e179320d7 45
va009039 1:ea8e179320d7 46 /**
va009039 1:ea8e179320d7 47 * Send a Report. warning: blocking
va009039 1:ea8e179320d7 48 *
va009039 1:ea8e179320d7 49 * @param report Report which will be sent (a report is defined by all data and the length)
va009039 1:ea8e179320d7 50 * @returns true if successful
va009039 1:ea8e179320d7 51 */
va009039 1:ea8e179320d7 52 bool send(HID_REPORT *report);
va009039 1:ea8e179320d7 53
va009039 1:ea8e179320d7 54
va009039 1:ea8e179320d7 55 /**
va009039 1:ea8e179320d7 56 * Send a Report. warning: non blocking
va009039 1:ea8e179320d7 57 *
va009039 1:ea8e179320d7 58 * @param report Report which will be sent (a report is defined by all data and the length)
va009039 1:ea8e179320d7 59 * @returns true if successful
va009039 1:ea8e179320d7 60 */
va009039 1:ea8e179320d7 61 bool sendNB(HID_REPORT *report);
va009039 1:ea8e179320d7 62
va009039 1:ea8e179320d7 63 /**
va009039 1:ea8e179320d7 64 * Read a report: blocking
va009039 1:ea8e179320d7 65 *
va009039 1:ea8e179320d7 66 * @param report pointer to the report to fill
va009039 1:ea8e179320d7 67 * @returns true if successful
va009039 1:ea8e179320d7 68 */
va009039 1:ea8e179320d7 69 bool read(HID_REPORT * report);
va009039 1:ea8e179320d7 70
va009039 1:ea8e179320d7 71 /**
va009039 1:ea8e179320d7 72 * Read a report: non blocking
va009039 1:ea8e179320d7 73 *
va009039 1:ea8e179320d7 74 * @param report pointer to the report to fill
va009039 1:ea8e179320d7 75 * @returns true if successful
va009039 1:ea8e179320d7 76 */
va009039 1:ea8e179320d7 77 bool readNB(HID_REPORT * report);
va009039 1:ea8e179320d7 78
va009039 1:ea8e179320d7 79 /*
va009039 1:ea8e179320d7 80 * Get the length of the report descriptor
va009039 1:ea8e179320d7 81 *
va009039 1:ea8e179320d7 82 * @returns the length of the report descriptor
va009039 1:ea8e179320d7 83 */
va009039 1:ea8e179320d7 84 virtual uint16_t reportDescLength();
va009039 1:ea8e179320d7 85
va009039 1:ea8e179320d7 86 bool Request_callback(CONTROL_TRANSFER* transfer, uint8_t* hidDescriptor);
va009039 1:ea8e179320d7 87 protected:
va009039 1:ea8e179320d7 88 /*
va009039 1:ea8e179320d7 89 * Get the Report descriptor
va009039 1:ea8e179320d7 90 *
va009039 1:ea8e179320d7 91 * @returns pointer to the report descriptor
va009039 1:ea8e179320d7 92 */
va009039 1:ea8e179320d7 93 virtual uint8_t * reportDesc();
va009039 1:ea8e179320d7 94
va009039 1:ea8e179320d7 95 uint16_t reportLength;
va009039 1:ea8e179320d7 96
va009039 1:ea8e179320d7 97 private:
va009039 1:ea8e179320d7 98 USBDevice* _device;
va009039 1:ea8e179320d7 99 HID_REPORT outputReport;
va009039 1:ea8e179320d7 100 uint8_t output_length;
va009039 1:ea8e179320d7 101 uint8_t input_length;
va009039 1:ea8e179320d7 102 };