USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Tue Dec 06 12:07:12 2011 +0000
Revision:
14:757226626acb
protection enabled when usb cable plugged. filesystem has no access when plugged

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 14:757226626acb 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
samux 14:757226626acb 2 *
samux 14:757226626acb 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 14:757226626acb 4 * and associated documentation files (the "Software"), to deal in the Software without
samux 14:757226626acb 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
samux 14:757226626acb 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
samux 14:757226626acb 7 * Software is furnished to do so, subject to the following conditions:
samux 14:757226626acb 8 *
samux 14:757226626acb 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 14:757226626acb 10 * substantial portions of the Software.
samux 14:757226626acb 11 *
samux 14:757226626acb 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 14:757226626acb 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 14:757226626acb 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 14:757226626acb 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 14:757226626acb 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 14:757226626acb 17 */
samux 14:757226626acb 18
samux 14:757226626acb 19 #include "stdint.h"
samux 14:757226626acb 20 #include "USBSerial.h"
samux 14:757226626acb 21 #include "USBBusInterface.h"
samux 14:757226626acb 22
samux 14:757226626acb 23
samux 14:757226626acb 24 int USBSerial::_putc(int c) {
samux 14:757226626acb 25 send((uint8_t *)&c, 1);
samux 14:757226626acb 26 return 1;
samux 14:757226626acb 27 }
samux 14:757226626acb 28
samux 14:757226626acb 29 int USBSerial::_getc() {
samux 14:757226626acb 30 uint8_t c;
samux 14:757226626acb 31 while (buf.isEmpty());
samux 14:757226626acb 32 buf.dequeue(&c);
samux 14:757226626acb 33 return c;
samux 14:757226626acb 34 }
samux 14:757226626acb 35
samux 14:757226626acb 36
samux 14:757226626acb 37 bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) {
samux 14:757226626acb 38 if(size > MAX_PACKET_SIZE_EPBULK) {
samux 14:757226626acb 39 return false;
samux 14:757226626acb 40 }
samux 14:757226626acb 41 if(!send(buf, size)) {
samux 14:757226626acb 42 return false;
samux 14:757226626acb 43 }
samux 14:757226626acb 44 return true;
samux 14:757226626acb 45 }
samux 14:757226626acb 46
samux 14:757226626acb 47
samux 14:757226626acb 48
samux 14:757226626acb 49 bool USBSerial::EP2_OUT_callback() {
samux 14:757226626acb 50 uint8_t c[65];
samux 14:757226626acb 51 uint16_t size = 0;
samux 14:757226626acb 52
samux 14:757226626acb 53 //we read the packet received and put it on the circular buffer
samux 14:757226626acb 54 readEP(c, &size);
samux 14:757226626acb 55 for (int i = 0; i < size; i++) {
samux 14:757226626acb 56 buf.queue(c[i]);
samux 14:757226626acb 57 }
samux 14:757226626acb 58
samux 14:757226626acb 59 //call a potential handler
samux 14:757226626acb 60 rx.call();
samux 14:757226626acb 61
samux 14:757226626acb 62 // We reactivate the endpoint to receive next characters
samux 14:757226626acb 63 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
samux 14:757226626acb 64 return true;
samux 14:757226626acb 65 }
samux 14:757226626acb 66
samux 14:757226626acb 67 uint8_t USBSerial::available() {
samux 14:757226626acb 68 return buf.available();
samux 14:757226626acb 69 }
samux 14:757226626acb 70