library

Dependents:   USB_CDC_MSD_Hello

Committer:
sherckuith
Date:
Fri Aug 24 02:01:51 2012 +0000
Revision:
0:d5bb9a9c3e24
[mbed] converted /USB_CDC_MSD_Hello/USBDevice

Who changed what in which revision?

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