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