USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Tue Mar 28 11:00:57 2017 +0200
Branch:
master
Revision:
4:50ec00aa4515
Parent:
1:2a3ae13b45ef
update for 5.4.2

Who changed what in which revision?

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