USBDevice stack

Dependents:   erg USBSerial_HelloWorld Slingshot SuperScanner ... more

Committer:
samux
Date:
Wed May 30 18:28:11 2012 +0000
Revision:
0:140cdf8e2d60

        

Who changed what in which revision?

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