USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Fri Nov 11 15:22:53 2011 +0000
Revision:
2:27a7e7f8d399
we have 2MB with the sdcard!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 2:27a7e7f8d399 1 /* USBSerial.h */
samux 2:27a7e7f8d399 2 /* USB device example: virtual serial port */
samux 2:27a7e7f8d399 3 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
samux 2:27a7e7f8d399 4
samux 2:27a7e7f8d399 5 #ifndef USBSERIAL_H
samux 2:27a7e7f8d399 6 #define USBSERIAL_H
samux 2:27a7e7f8d399 7
samux 2:27a7e7f8d399 8 #include "USBCDC.h"
samux 2:27a7e7f8d399 9 #include "Stream.h"
samux 2:27a7e7f8d399 10 #include "CBuffer.h"
samux 2:27a7e7f8d399 11
samux 2:27a7e7f8d399 12
samux 2:27a7e7f8d399 13 /**
samux 2:27a7e7f8d399 14 * USBSerial example
samux 2:27a7e7f8d399 15 *
samux 2:27a7e7f8d399 16 * @code
samux 2:27a7e7f8d399 17 * #include "mbed.h"
samux 2:27a7e7f8d399 18 * #include "USBSerial.h"
samux 2:27a7e7f8d399 19 *
samux 2:27a7e7f8d399 20 * //Virtual serial port over USB
samux 2:27a7e7f8d399 21 * USBSerial serial;
samux 2:27a7e7f8d399 22 *
samux 2:27a7e7f8d399 23 * int main(void) {
samux 2:27a7e7f8d399 24 *
samux 2:27a7e7f8d399 25 * while(1)
samux 2:27a7e7f8d399 26 * {
samux 2:27a7e7f8d399 27 * serial.printf("I am a virtual serial port\n");
samux 2:27a7e7f8d399 28 * wait(1);
samux 2:27a7e7f8d399 29 * }
samux 2:27a7e7f8d399 30 * }
samux 2:27a7e7f8d399 31 * @endcode
samux 2:27a7e7f8d399 32 */
samux 2:27a7e7f8d399 33 class USBSerial: public USBCDC, public Stream {
samux 2:27a7e7f8d399 34 public:
samux 2:27a7e7f8d399 35
samux 2:27a7e7f8d399 36 /**
samux 2:27a7e7f8d399 37 * Constructor
samux 2:27a7e7f8d399 38 *
samux 2:27a7e7f8d399 39 * @param vendor_id Your vendor_id (default: 0x1f00)
samux 2:27a7e7f8d399 40 * @param product_id Your product_id (default: 0x2012)
samux 2:27a7e7f8d399 41 * @param product_release Your preoduct_release (default: 0x0001)
samux 2:27a7e7f8d399 42 *
samux 2:27a7e7f8d399 43 */
samux 2:27a7e7f8d399 44 USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001): USBCDC(vendor_id, product_id, product_release){
samux 2:27a7e7f8d399 45 handler = false;
samux 2:27a7e7f8d399 46 proc = false;
samux 2:27a7e7f8d399 47 };
samux 2:27a7e7f8d399 48
samux 2:27a7e7f8d399 49
samux 2:27a7e7f8d399 50 /**
samux 2:27a7e7f8d399 51 * Send a character. You can use puts, printf.
samux 2:27a7e7f8d399 52 *
samux 2:27a7e7f8d399 53 * @param c character to be sent
samux 2:27a7e7f8d399 54 * @returns true if there is no error, false otherwise
samux 2:27a7e7f8d399 55 */
samux 2:27a7e7f8d399 56 virtual int _putc(int c);
samux 2:27a7e7f8d399 57
samux 2:27a7e7f8d399 58 /**
samux 2:27a7e7f8d399 59 * Read a character: blocking
samux 2:27a7e7f8d399 60 *
samux 2:27a7e7f8d399 61 * @returns character read
samux 2:27a7e7f8d399 62 */
samux 2:27a7e7f8d399 63 virtual int _getc();
samux 2:27a7e7f8d399 64
samux 2:27a7e7f8d399 65 /**
samux 2:27a7e7f8d399 66 * Check the number of bytes available.
samux 2:27a7e7f8d399 67 *
samux 2:27a7e7f8d399 68 * @returns the number of bytes available
samux 2:27a7e7f8d399 69 */
samux 2:27a7e7f8d399 70 uint8_t available();
samux 2:27a7e7f8d399 71
samux 2:27a7e7f8d399 72 /**
samux 2:27a7e7f8d399 73 * Attach a member function to call when a packet is received.
samux 2:27a7e7f8d399 74 *
samux 2:27a7e7f8d399 75 * @param tptr pointer to the object to call the member function on
samux 2:27a7e7f8d399 76 * @param mptr pointer to the member function to be called
samux 2:27a7e7f8d399 77 */
samux 2:27a7e7f8d399 78 template<typename T>
samux 2:27a7e7f8d399 79 void attach(T* tptr, void (T::*mptr)(void)) {
samux 2:27a7e7f8d399 80 if((mptr != NULL) && (tptr != NULL)) {
samux 2:27a7e7f8d399 81 proc = false;
samux 2:27a7e7f8d399 82 handler = true;
samux 2:27a7e7f8d399 83 rx.attach(tptr, mptr);
samux 2:27a7e7f8d399 84 }
samux 2:27a7e7f8d399 85 }
samux 2:27a7e7f8d399 86
samux 2:27a7e7f8d399 87 /**
samux 2:27a7e7f8d399 88 * Attach a callback for when a packet is received
samux 2:27a7e7f8d399 89 *
samux 2:27a7e7f8d399 90 * @param fptr function pointer
samux 2:27a7e7f8d399 91 */
samux 2:27a7e7f8d399 92 void attach(void (*fn)(void));
samux 2:27a7e7f8d399 93
samux 2:27a7e7f8d399 94
samux 2:27a7e7f8d399 95 protected:
samux 2:27a7e7f8d399 96 virtual bool EP2_OUT_callback();
samux 2:27a7e7f8d399 97
samux 2:27a7e7f8d399 98 private:
samux 2:27a7e7f8d399 99 FunctionPointer rx;
samux 2:27a7e7f8d399 100 CBuffer buf;
samux 2:27a7e7f8d399 101 void (*fn)(void);
samux 2:27a7e7f8d399 102 bool handler;
samux 2:27a7e7f8d399 103 bool proc;
samux 2:27a7e7f8d399 104 };
samux 2:27a7e7f8d399 105
samux 2:27a7e7f8d399 106 #endif