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 #ifndef CIRCBUFFER_H
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 20 #define CIRCBUFFER_H
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 21
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 22 template <class T, int Size>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 23 class CircBuffer {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 24 public:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 25 CircBuffer():write(0), read(0){}
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 26 bool isFull() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 27 return ((write + 1) % size == read);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30 bool isEmpty() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31 return (read == write);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 void queue(T k) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 if (isFull()) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 read++;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37 read %= size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39 buf[write++] = k;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 write %= size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43 uint16_t available() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44 return (write >= read) ? write - read : size - read + write;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 bool dequeue(T * c) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 bool empty = isEmpty();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49 if (!empty) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 *c = buf[read++];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 read %= size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 return(!empty);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56 private:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 volatile uint16_t write;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 volatile uint16_t read;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59 static const int size = Size+1; //a modern optimizer should be able to remove this so it uses no ram.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60 T buf[Size+1];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63 #endif