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