Sensor reporting over USB CDC

Dependencies:   MAG3110 MMA8451Q SLCD- TSI USBDevice mbed

Committer:
wue
Date:
Wed Apr 16 12:20:12 2014 +0000
Revision:
0:7b58cdacf811
Sensor reporting over USB CDC

Who changed what in which revision?

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