A copy of the mbed USBDevice with USBSerial library

Dependents:   STM32L0_LoRa Smartage STM32L0_LoRa Turtle_RadioShuttle

Committer:
Helmut Tschemernjak
Date:
Sun Feb 24 14:52:33 2019 +0100
Revision:
8:961423d1da74
Parent:
0:a3ea811f80f2
Added sleep manager support to avoids sleeps while a USB CDC
connection is active

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:a3ea811f80f2 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Helmut64 0:a3ea811f80f2 2 *
Helmut64 0:a3ea811f80f2 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Helmut64 0:a3ea811f80f2 4 * and associated documentation files (the "Software"), to deal in the Software without
Helmut64 0:a3ea811f80f2 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Helmut64 0:a3ea811f80f2 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Helmut64 0:a3ea811f80f2 7 * Software is furnished to do so, subject to the following conditions:
Helmut64 0:a3ea811f80f2 8 *
Helmut64 0:a3ea811f80f2 9 * The above copyright notice and this permission notice shall be included in all copies or
Helmut64 0:a3ea811f80f2 10 * substantial portions of the Software.
Helmut64 0:a3ea811f80f2 11 *
Helmut64 0:a3ea811f80f2 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Helmut64 0:a3ea811f80f2 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Helmut64 0:a3ea811f80f2 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Helmut64 0:a3ea811f80f2 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Helmut64 0:a3ea811f80f2 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Helmut64 0:a3ea811f80f2 17 */
Helmut64 0:a3ea811f80f2 18
Helmut64 0:a3ea811f80f2 19 #ifndef USBDEVICE_TYPES_H
Helmut64 0:a3ea811f80f2 20 #define USBDEVICE_TYPES_H
Helmut64 0:a3ea811f80f2 21
Helmut64 0:a3ea811f80f2 22 /* Standard requests */
Helmut64 0:a3ea811f80f2 23 #define GET_STATUS (0)
Helmut64 0:a3ea811f80f2 24 #define CLEAR_FEATURE (1)
Helmut64 0:a3ea811f80f2 25 #define SET_FEATURE (3)
Helmut64 0:a3ea811f80f2 26 #define SET_ADDRESS (5)
Helmut64 0:a3ea811f80f2 27 #define GET_DESCRIPTOR (6)
Helmut64 0:a3ea811f80f2 28 #define SET_DESCRIPTOR (7)
Helmut64 0:a3ea811f80f2 29 #define GET_CONFIGURATION (8)
Helmut64 0:a3ea811f80f2 30 #define SET_CONFIGURATION (9)
Helmut64 0:a3ea811f80f2 31 #define GET_INTERFACE (10)
Helmut64 0:a3ea811f80f2 32 #define SET_INTERFACE (11)
Helmut64 0:a3ea811f80f2 33
Helmut64 0:a3ea811f80f2 34 /* bmRequestType.dataTransferDirection */
Helmut64 0:a3ea811f80f2 35 #define HOST_TO_DEVICE (0)
Helmut64 0:a3ea811f80f2 36 #define DEVICE_TO_HOST (1)
Helmut64 0:a3ea811f80f2 37
Helmut64 0:a3ea811f80f2 38 /* bmRequestType.Type*/
Helmut64 0:a3ea811f80f2 39 #define STANDARD_TYPE (0)
Helmut64 0:a3ea811f80f2 40 #define CLASS_TYPE (1)
Helmut64 0:a3ea811f80f2 41 #define VENDOR_TYPE (2)
Helmut64 0:a3ea811f80f2 42 #define RESERVED_TYPE (3)
Helmut64 0:a3ea811f80f2 43
Helmut64 0:a3ea811f80f2 44 /* bmRequestType.Recipient */
Helmut64 0:a3ea811f80f2 45 #define DEVICE_RECIPIENT (0)
Helmut64 0:a3ea811f80f2 46 #define INTERFACE_RECIPIENT (1)
Helmut64 0:a3ea811f80f2 47 #define ENDPOINT_RECIPIENT (2)
Helmut64 0:a3ea811f80f2 48 #define OTHER_RECIPIENT (3)
Helmut64 0:a3ea811f80f2 49
Helmut64 0:a3ea811f80f2 50 /* Descriptors */
Helmut64 0:a3ea811f80f2 51 #define DESCRIPTOR_TYPE(wValue) (wValue >> 8)
Helmut64 0:a3ea811f80f2 52 #define DESCRIPTOR_INDEX(wValue) (wValue & 0xff)
Helmut64 0:a3ea811f80f2 53
Helmut64 0:a3ea811f80f2 54 typedef struct {
Helmut64 0:a3ea811f80f2 55 struct {
Helmut64 0:a3ea811f80f2 56 uint8_t dataTransferDirection;
Helmut64 0:a3ea811f80f2 57 uint8_t Type;
Helmut64 0:a3ea811f80f2 58 uint8_t Recipient;
Helmut64 0:a3ea811f80f2 59 } bmRequestType;
Helmut64 0:a3ea811f80f2 60 uint8_t bRequest;
Helmut64 0:a3ea811f80f2 61 uint16_t wValue;
Helmut64 0:a3ea811f80f2 62 uint16_t wIndex;
Helmut64 0:a3ea811f80f2 63 uint16_t wLength;
Helmut64 0:a3ea811f80f2 64 } SETUP_PACKET;
Helmut64 0:a3ea811f80f2 65
Helmut64 0:a3ea811f80f2 66 typedef struct {
Helmut64 0:a3ea811f80f2 67 SETUP_PACKET setup;
Helmut64 0:a3ea811f80f2 68 uint8_t *ptr;
Helmut64 0:a3ea811f80f2 69 uint32_t remaining;
Helmut64 0:a3ea811f80f2 70 uint8_t direction;
Helmut64 0:a3ea811f80f2 71 bool zlp;
Helmut64 0:a3ea811f80f2 72 bool notify;
Helmut64 0:a3ea811f80f2 73 } CONTROL_TRANSFER;
Helmut64 0:a3ea811f80f2 74
Helmut64 0:a3ea811f80f2 75 typedef enum {ATTACHED, POWERED, DEFAULT, ADDRESS, CONFIGURED} DEVICE_STATE;
Helmut64 0:a3ea811f80f2 76
Helmut64 0:a3ea811f80f2 77 typedef struct {
Helmut64 0:a3ea811f80f2 78 volatile DEVICE_STATE state;
Helmut64 0:a3ea811f80f2 79 uint8_t configuration;
Helmut64 0:a3ea811f80f2 80 bool suspended;
Helmut64 0:a3ea811f80f2 81 } USB_DEVICE;
Helmut64 0:a3ea811f80f2 82
Helmut64 0:a3ea811f80f2 83 #endif