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