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 /* SWSPI, Software SPI library
va009039 0:39eb4d5b97df 2 * Copyright (c) 2012-2014, David R. Van Wagner, http://techwithdave.blogspot.com
va009039 0:39eb4d5b97df 3 *
va009039 0:39eb4d5b97df 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
va009039 0:39eb4d5b97df 5 * of this software and associated documentation files (the "Software"), to deal
va009039 0:39eb4d5b97df 6 * in the Software without restriction, including without limitation the rights
va009039 0:39eb4d5b97df 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
va009039 0:39eb4d5b97df 8 * copies of the Software, and to permit persons to whom the Software is
va009039 0:39eb4d5b97df 9 * furnished to do so, subject to the following conditions:
va009039 0:39eb4d5b97df 10 *
va009039 0:39eb4d5b97df 11 * The above copyright notice and this permission notice shall be included in
va009039 0:39eb4d5b97df 12 * all copies or substantial portions of the Software.
va009039 0:39eb4d5b97df 13 *
va009039 0:39eb4d5b97df 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
va009039 0:39eb4d5b97df 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
va009039 0:39eb4d5b97df 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
va009039 0:39eb4d5b97df 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
va009039 0:39eb4d5b97df 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
va009039 0:39eb4d5b97df 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
va009039 0:39eb4d5b97df 20 * THE SOFTWARE.
va009039 0:39eb4d5b97df 21 */
va009039 0:39eb4d5b97df 22
va009039 0:39eb4d5b97df 23 #ifndef SWSPI_H
va009039 0:39eb4d5b97df 24 #define SWSPI_H
va009039 0:39eb4d5b97df 25
va009039 0:39eb4d5b97df 26 /** A software implemented SPI that can use any digital pins
va009039 0:39eb4d5b97df 27 *
va009039 0:39eb4d5b97df 28 * Useful when don't want to share a single SPI hardware among attached devices
va009039 0:39eb4d5b97df 29 * or when pinout doesn't match exactly to the target's SPI pins
va009039 0:39eb4d5b97df 30 *
va009039 0:39eb4d5b97df 31 * @code
va009039 0:39eb4d5b97df 32 * #include "mbed.h"
va009039 0:39eb4d5b97df 33 * #include "SWSPI.h"
va009039 0:39eb4d5b97df 34 *
va009039 0:39eb4d5b97df 35 * SWSPI spi(p5, p6, p7); // mosi, miso, sclk
va009039 0:39eb4d5b97df 36 *
va009039 0:39eb4d5b97df 37 * int main()
va009039 0:39eb4d5b97df 38 * {
va009039 0:39eb4d5b97df 39 * DigitalOut cs(p8);
va009039 0:39eb4d5b97df 40 * spi.format(8, 0);
va009039 0:39eb4d5b97df 41 * spi.frequency(10000000);
va009039 0:39eb4d5b97df 42 * cs.write(0);
va009039 0:39eb4d5b97df 43 * spi.write(0x9f);
va009039 0:39eb4d5b97df 44 * int jedecid = (spi.write(0) << 16) | (spi.write(0) << 8) | spi.write(0);
va009039 0:39eb4d5b97df 45 * cs.write(1);
va009039 0:39eb4d5b97df 46 * }
va009039 0:39eb4d5b97df 47 * @endcode
va009039 0:39eb4d5b97df 48 */
va009039 0:39eb4d5b97df 49 class SWSPI
va009039 0:39eb4d5b97df 50 {
va009039 0:39eb4d5b97df 51 private:
va009039 0:39eb4d5b97df 52 uint8_t fast_write(uint8_t value);
va009039 0:39eb4d5b97df 53 DigitalOut* mosi;
va009039 0:39eb4d5b97df 54 DigitalIn* miso;
va009039 0:39eb4d5b97df 55 DigitalOut* sclk;
va009039 0:39eb4d5b97df 56 int port;
va009039 0:39eb4d5b97df 57 int bits;
va009039 0:39eb4d5b97df 58 int mode;
va009039 0:39eb4d5b97df 59 int polarity; // idle clock value
va009039 0:39eb4d5b97df 60 int phase; // 0=sample on leading (first) clock edge, 1=trailing (second)
va009039 0:39eb4d5b97df 61 int freq;
va009039 0:39eb4d5b97df 62 bool _fast;
va009039 0:39eb4d5b97df 63
va009039 0:39eb4d5b97df 64 public:
va009039 0:39eb4d5b97df 65 /** Create SWSPI object
va009039 0:39eb4d5b97df 66 *
va009039 0:39eb4d5b97df 67 * @param mosi_pin
va009039 0:39eb4d5b97df 68 * @param miso_pin
va009039 0:39eb4d5b97df 69 * @param sclk_pin
va009039 0:39eb4d5b97df 70 */
va009039 0:39eb4d5b97df 71 SWSPI(PinName mosi_pin, PinName miso_pin, PinName sclk_pin);
va009039 0:39eb4d5b97df 72
va009039 0:39eb4d5b97df 73 /** Destructor */
va009039 0:39eb4d5b97df 74 ~SWSPI();
va009039 0:39eb4d5b97df 75
va009039 0:39eb4d5b97df 76 /** Specify SPI format
va009039 0:39eb4d5b97df 77 *
va009039 0:39eb4d5b97df 78 * @param bits 8 or 16 are typical values
va009039 0:39eb4d5b97df 79 * @param mode 0, 1, 2, or 3 phase (bit1) and idle clock (bit0)
va009039 0:39eb4d5b97df 80 */
va009039 0:39eb4d5b97df 81 void format(int bits, int mode = 0);
va009039 0:39eb4d5b97df 82
va009039 0:39eb4d5b97df 83 /** Specify SPI clock frequency
va009039 0:39eb4d5b97df 84 *
va009039 0:39eb4d5b97df 85 * @param hz frequency (optional, defaults to 10000000)
va009039 0:39eb4d5b97df 86 */
va009039 0:39eb4d5b97df 87 void frequency(int hz = 10000000);
va009039 0:39eb4d5b97df 88
va009039 0:39eb4d5b97df 89 /** Write data and read result
va009039 0:39eb4d5b97df 90 *
va009039 0:39eb4d5b97df 91 * @param value data to write (see format for bit size)
va009039 0:39eb4d5b97df 92 * returns value read from device
va009039 0:39eb4d5b97df 93 */
va009039 0:39eb4d5b97df 94 int write(int value);
va009039 0:39eb4d5b97df 95 };
va009039 0:39eb4d5b97df 96
va009039 0:39eb4d5b97df 97 #endif // SWSPI_H