Emulation of LocalFileSystem with virtual COM.

Dependencies:   USBDevice

Dependents:   KL46Z-lpc81isp lpcterm2

#include "USBLocalFileSystem.h"

int main() {
    USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)

    while(1) {
        usb_local->lock(true);
        usb_local->remount();
        char filename[32];
        if (usb_local->find(filename, sizeof(filename), "*.TXT")) {
            FILE* fp = fopen(filename, "r");
            if (fp) {
                int c;
                while((c = fgetc(fp)) != EOF) {
                    usb_local->putc(c);
                }
                fclose(fp);
            }
        }    
        usb_local->lock(false);

        wait_ms(1000*5);
    }
}



Sample application:

Import programKL46Z-lpc81isp

ISP example program.

Import programlpcterm2

semihost server example program

Committer:
va009039
Date:
Sat Jun 21 22:39:59 2014 +0000
Revision:
6:528036abfb02
Parent:
0:39eb4d5b97df
add LPC11U68

Who changed what in which revision?

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