Slingshot Controller

Dependencies:   ADXL345 DebounceIn USBDevice mbed

Committer:
Brandon
Date:
Wed Oct 17 16:33:04 2012 +0000
Revision:
1:2721dc2acc2c
Parent:
0:cf17ea89fd09
Updated comments, added names, cleaned old code.

Who changed what in which revision?

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