Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Mon Feb 15 23:03:55 2016 +0000
Revision:
68:edfecf67a931
Parent:
52:63f0a9b45f0c
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.

Who changed what in which revision?

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