USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

USBDevice/USBSERIAL/USBSerial.cpp

Committer:
samux
Date:
2011-11-11
Revision:
2:27a7e7f8d399

File content as of revision 2:27a7e7f8d399:

// USBSerial.c
// USB device example: virtual serial port
// Copyright (c) 2011 ARM Limited. All rights reserved

#include "stdint.h"
#include "USBSerial.h"
#include "USBBusInterface.h"


int USBSerial::_putc(int c) {
    send(EPBULK_IN, (uint8_t *)&c, 1);
    return 1;
}

int USBSerial::_getc() {
    uint8_t c;
    while (buf.isEmpty());
    buf.dequeue(&c);
    return c;
}

void USBSerial::attach(void (*ptr)(void)) {
    handler = true;
    proc = true;
    fn = ptr;
}


bool USBSerial::EP2_OUT_callback() {
    uint8_t c[65];
    uint16_t size = 0;

    //we read the packet received and put it on the circular buffer
    USBCDC::read(EPBULK_OUT, c, &size, MAX_PACKET_SIZE_EPBULK);
    for (int i = 0; i < size; i++) {
        buf.queue(c[i]);
    }

    //call a potential handler
    if (handler) {
        if (proc) {
            (*fn)();
        } else {
            rx.call();
        }
    }

    // We reactivate the endpoint to receive next characters
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    return true;
}

uint8_t USBSerial::available() {
    return buf.available();
}