ram version see usbmsd_sd.cpp ram ok fs CANNOT be installed - too small use for illustrative purpose only

Dependencies:   USBDevice USBMSD_SD mbed

Fork of USBMSD_SD_HelloWorld_Mbed by Samuel Mokrani

Committer:
samux
Date:
Wed Nov 16 17:17:42 2011 +0000
Revision:
11:a26e7b7a1221
GOOD COMMIT: msd and hid work even on MAC...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 11:a26e7b7a1221 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
samux 11:a26e7b7a1221 2 *
samux 11:a26e7b7a1221 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 11:a26e7b7a1221 4 * and associated documentation files (the "Software"), to deal in the Software without
samux 11:a26e7b7a1221 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
samux 11:a26e7b7a1221 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
samux 11:a26e7b7a1221 7 * Software is furnished to do so, subject to the following conditions:
samux 11:a26e7b7a1221 8 *
samux 11:a26e7b7a1221 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 11:a26e7b7a1221 10 * substantial portions of the Software.
samux 11:a26e7b7a1221 11 *
samux 11:a26e7b7a1221 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 11:a26e7b7a1221 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 11:a26e7b7a1221 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 11:a26e7b7a1221 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 11:a26e7b7a1221 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 11:a26e7b7a1221 17 */
samux 11:a26e7b7a1221 18
samux 11:a26e7b7a1221 19 #ifndef USBSERIAL_H
samux 11:a26e7b7a1221 20 #define USBSERIAL_H
samux 11:a26e7b7a1221 21
samux 11:a26e7b7a1221 22 #include "USBCDC.h"
samux 11:a26e7b7a1221 23 #include "Stream.h"
samux 11:a26e7b7a1221 24 #include "CBuffer.h"
samux 11:a26e7b7a1221 25
samux 11:a26e7b7a1221 26
samux 11:a26e7b7a1221 27 /**
samux 11:a26e7b7a1221 28 * USBSerial example
samux 11:a26e7b7a1221 29 *
samux 11:a26e7b7a1221 30 * @code
samux 11:a26e7b7a1221 31 * #include "mbed.h"
samux 11:a26e7b7a1221 32 * #include "USBSerial.h"
samux 11:a26e7b7a1221 33 *
samux 11:a26e7b7a1221 34 * //Virtual serial port over USB
samux 11:a26e7b7a1221 35 * USBSerial serial;
samux 11:a26e7b7a1221 36 *
samux 11:a26e7b7a1221 37 * int main(void) {
samux 11:a26e7b7a1221 38 *
samux 11:a26e7b7a1221 39 * while(1)
samux 11:a26e7b7a1221 40 * {
samux 11:a26e7b7a1221 41 * serial.printf("I am a virtual serial port\n");
samux 11:a26e7b7a1221 42 * wait(1);
samux 11:a26e7b7a1221 43 * }
samux 11:a26e7b7a1221 44 * }
samux 11:a26e7b7a1221 45 * @endcode
samux 11:a26e7b7a1221 46 */
samux 11:a26e7b7a1221 47 class USBSerial: public USBCDC, public Stream {
samux 11:a26e7b7a1221 48 public:
samux 11:a26e7b7a1221 49
samux 11:a26e7b7a1221 50 /**
samux 11:a26e7b7a1221 51 * Constructor
samux 11:a26e7b7a1221 52 *
samux 11:a26e7b7a1221 53 * @param vendor_id Your vendor_id (default: 0x1f00)
samux 11:a26e7b7a1221 54 * @param product_id Your product_id (default: 0x2012)
samux 11:a26e7b7a1221 55 * @param product_release Your preoduct_release (default: 0x0001)
samux 11:a26e7b7a1221 56 *
samux 11:a26e7b7a1221 57 */
samux 11:a26e7b7a1221 58 USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001): USBCDC(vendor_id, product_id, product_release){
samux 11:a26e7b7a1221 59 handler = false;
samux 11:a26e7b7a1221 60 proc = false;
samux 11:a26e7b7a1221 61 };
samux 11:a26e7b7a1221 62
samux 11:a26e7b7a1221 63
samux 11:a26e7b7a1221 64 /**
samux 11:a26e7b7a1221 65 * Send a character. You can use puts, printf.
samux 11:a26e7b7a1221 66 *
samux 11:a26e7b7a1221 67 * @param c character to be sent
samux 11:a26e7b7a1221 68 * @returns true if there is no error, false otherwise
samux 11:a26e7b7a1221 69 */
samux 11:a26e7b7a1221 70 virtual int _putc(int c);
samux 11:a26e7b7a1221 71
samux 11:a26e7b7a1221 72 /**
samux 11:a26e7b7a1221 73 * Read a character: blocking
samux 11:a26e7b7a1221 74 *
samux 11:a26e7b7a1221 75 * @returns character read
samux 11:a26e7b7a1221 76 */
samux 11:a26e7b7a1221 77 virtual int _getc();
samux 11:a26e7b7a1221 78
samux 11:a26e7b7a1221 79 /**
samux 11:a26e7b7a1221 80 * Check the number of bytes available.
samux 11:a26e7b7a1221 81 *
samux 11:a26e7b7a1221 82 * @returns the number of bytes available
samux 11:a26e7b7a1221 83 */
samux 11:a26e7b7a1221 84 uint8_t available();
samux 11:a26e7b7a1221 85
samux 11:a26e7b7a1221 86 /**
samux 11:a26e7b7a1221 87 * Attach a member function to call when a packet is received.
samux 11:a26e7b7a1221 88 *
samux 11:a26e7b7a1221 89 * @param tptr pointer to the object to call the member function on
samux 11:a26e7b7a1221 90 * @param mptr pointer to the member function to be called
samux 11:a26e7b7a1221 91 */
samux 11:a26e7b7a1221 92 template<typename T>
samux 11:a26e7b7a1221 93 void attach(T* tptr, void (T::*mptr)(void)) {
samux 11:a26e7b7a1221 94 if((mptr != NULL) && (tptr != NULL)) {
samux 11:a26e7b7a1221 95 proc = false;
samux 11:a26e7b7a1221 96 handler = true;
samux 11:a26e7b7a1221 97 rx.attach(tptr, mptr);
samux 11:a26e7b7a1221 98 }
samux 11:a26e7b7a1221 99 }
samux 11:a26e7b7a1221 100
samux 11:a26e7b7a1221 101 /**
samux 11:a26e7b7a1221 102 * Attach a callback for when a packet is received
samux 11:a26e7b7a1221 103 *
samux 11:a26e7b7a1221 104 * @param fptr function pointer
samux 11:a26e7b7a1221 105 */
samux 11:a26e7b7a1221 106 void attach(void (*fn)(void));
samux 11:a26e7b7a1221 107
samux 11:a26e7b7a1221 108
samux 11:a26e7b7a1221 109 protected:
samux 11:a26e7b7a1221 110 virtual bool EP2_OUT_callback();
samux 11:a26e7b7a1221 111
samux 11:a26e7b7a1221 112 private:
samux 11:a26e7b7a1221 113 FunctionPointer rx;
samux 11:a26e7b7a1221 114 CBuffer buf;
samux 11:a26e7b7a1221 115 void (*fn)(void);
samux 11:a26e7b7a1221 116 bool handler;
samux 11:a26e7b7a1221 117 bool proc;
samux 11:a26e7b7a1221 118 };
samux 11:a26e7b7a1221 119
samux 11:a26e7b7a1221 120 #endif