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