max4146x_comp

Dependencies:   MAX14690

Committer:
sdivarci
Date:
Sun Oct 25 20:10:02 2020 +0000
Revision:
0:0061165683ee
sdivarci

Who changed what in which revision?

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