usb device

Committer:
ppo
Date:
Sat May 14 17:24:10 2022 +0000
Revision:
0:c1e89c49eae5
commit

Who changed what in which revision?

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