blablabla

Dependencies:   MAG3110 MMA8451Q SLCD- TSI USBDevice mbed

Committer:
Osator
Date:
Wed Apr 16 12:20:00 2014 +0000
Revision:
0:339b7abfa147
blablabla

Who changed what in which revision?

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