Naoya Hasegawa / USBDevice

Fork of USBDevice by Samuel Mokrani

Committer:
hase
Date:
Wed Nov 07 09:27:57 2012 +0000
Revision:
1:f6a91be12476
Parent:
0:140cdf8e2d60
PWM TEST NG program

Who changed what in which revision?

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