Lucas Lim / Mbed 2 deprecated HSP_Temperature_Barometer_CS3237

Dependencies:   mbed

Committer:
lucaslwl
Date:
Mon Aug 26 08:11:41 2019 +0000
Revision:
22:5c07298d3383
add library folder

Who changed what in which revision?

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