test

Dependencies:   mbed

Fork of USBMouse by Simon Ford

Committer:
USER10
Date:
Fri Jan 19 01:42:11 2018 +0000
Revision:
2:554ad697ebbb
Parent:
1:eb68149218fd
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 1:eb68149218fd 1 /* usbdevice.h */
simon 1:eb68149218fd 2 /* Generic USB device */
simon 1:eb68149218fd 3 /* Copyright (c) Phil Wright 2008 */
simon 1:eb68149218fd 4
simon 1:eb68149218fd 5 #ifndef USBDEVICE_H
simon 1:eb68149218fd 6 #define USBDEVICE_H
simon 1:eb68149218fd 7
simon 1:eb68149218fd 8 #include "usbdc.h"
simon 1:eb68149218fd 9
simon 1:eb68149218fd 10 /* Endpoint packet sizes */
simon 1:eb68149218fd 11 #define MAX_PACKET_SIZE_EP0 (64)
simon 1:eb68149218fd 12
simon 1:eb68149218fd 13 /* bmRequestType.dataTransferDirection */
simon 1:eb68149218fd 14 #define HOST_TO_DEVICE (0)
simon 1:eb68149218fd 15 #define DEVICE_TO_HOST (1)
simon 1:eb68149218fd 16
simon 1:eb68149218fd 17 /* bmRequestType.Type*/
simon 1:eb68149218fd 18 #define STANDARD_TYPE (0)
simon 1:eb68149218fd 19 #define CLASS_TYPE (1)
simon 1:eb68149218fd 20 #define VENDOR_TYPE (2)
simon 1:eb68149218fd 21 #define RESERVED_TYPE (3)
simon 1:eb68149218fd 22
simon 1:eb68149218fd 23 /* bmRequestType.Recipient */
simon 1:eb68149218fd 24 #define DEVICE_RECIPIENT (0)
simon 1:eb68149218fd 25 #define INTERFACE_RECIPIENT (1)
simon 1:eb68149218fd 26 #define ENDPOINT_RECIPIENT (2)
simon 1:eb68149218fd 27 #define OTHER_RECIPIENT (3)
simon 1:eb68149218fd 28
simon 1:eb68149218fd 29 /* Descriptors */
simon 1:eb68149218fd 30 #define DESCRIPTOR_TYPE(wValue) (wValue >> 8)
simon 1:eb68149218fd 31 #define DESCRIPTOR_INDEX(wValue) (wValue & 0xf)
simon 1:eb68149218fd 32
simon 1:eb68149218fd 33 /* Descriptor type */
simon 1:eb68149218fd 34 #define DEVICE_DESCRIPTOR (1)
simon 1:eb68149218fd 35 #define CONFIGURATION_DESCRIPTOR (2)
simon 1:eb68149218fd 36 #define STRING_DESCRIPTOR (3)
simon 1:eb68149218fd 37 #define INTERFACE_DESCRIPTOR (4)
simon 1:eb68149218fd 38 #define ENDPOINT_DESCRIPTOR (5)
simon 1:eb68149218fd 39
simon 1:eb68149218fd 40 typedef struct {
simon 1:eb68149218fd 41 struct {
simon 1:eb68149218fd 42 unsigned char dataTransferDirection;
simon 1:eb68149218fd 43 unsigned char Type;
simon 1:eb68149218fd 44 unsigned char Recipient;
simon 1:eb68149218fd 45 } bmRequestType;
simon 1:eb68149218fd 46 unsigned char bRequest;
simon 1:eb68149218fd 47 unsigned short wValue;
simon 1:eb68149218fd 48 unsigned short wIndex;
simon 1:eb68149218fd 49 unsigned short wLength;
simon 1:eb68149218fd 50 } SETUP_PACKET;
simon 1:eb68149218fd 51
simon 1:eb68149218fd 52 typedef struct {
simon 1:eb68149218fd 53 SETUP_PACKET setup;
simon 1:eb68149218fd 54 unsigned char *ptr;
simon 1:eb68149218fd 55 unsigned long remaining;
simon 1:eb68149218fd 56 unsigned char direction;
simon 1:eb68149218fd 57 bool zlp;
simon 1:eb68149218fd 58 } CONTROL_TRANSFER;
simon 1:eb68149218fd 59
simon 1:eb68149218fd 60 typedef enum {ATTACHED, POWERED, DEFAULT, ADDRESS, CONFIGURED} DEVICE_STATE;
simon 1:eb68149218fd 61
simon 1:eb68149218fd 62 typedef struct {
simon 1:eb68149218fd 63 DEVICE_STATE state;
simon 1:eb68149218fd 64 unsigned char configuration;
simon 1:eb68149218fd 65 bool suspended;
simon 1:eb68149218fd 66 } USB_DEVICE;
simon 1:eb68149218fd 67
simon 1:eb68149218fd 68 class usbdevice : public usbdc
simon 1:eb68149218fd 69 {
simon 1:eb68149218fd 70 public:
simon 1:eb68149218fd 71 usbdevice();
simon 1:eb68149218fd 72 protected:
simon 1:eb68149218fd 73 virtual void endpointEventEP0Setup(void);
simon 1:eb68149218fd 74 virtual void endpointEventEP0In(void);
simon 1:eb68149218fd 75 virtual void endpointEventEP0Out(void);
simon 1:eb68149218fd 76 virtual bool requestSetup(void);
simon 1:eb68149218fd 77 virtual bool requestOut(void);
simon 1:eb68149218fd 78 virtual void deviceEventReset(void);
simon 1:eb68149218fd 79 virtual bool requestGetDescriptor(void);
simon 1:eb68149218fd 80 bool requestSetAddress(void);
simon 1:eb68149218fd 81 virtual bool requestSetConfiguration(void);
simon 1:eb68149218fd 82 virtual bool requestGetConfiguration(void);
simon 1:eb68149218fd 83 bool requestGetStatus(void);
simon 1:eb68149218fd 84 virtual bool requestSetInterface(void);
simon 1:eb68149218fd 85 virtual bool requestGetInterface(void);
simon 1:eb68149218fd 86 bool requestSetFeature(void);
simon 1:eb68149218fd 87 bool requestClearFeature(void);
simon 1:eb68149218fd 88 CONTROL_TRANSFER transfer;
simon 1:eb68149218fd 89 USB_DEVICE device;
simon 1:eb68149218fd 90 private:
simon 1:eb68149218fd 91 bool controlIn(void);
simon 1:eb68149218fd 92 bool controlOut(void);
simon 1:eb68149218fd 93 bool controlSetup(void);
simon 1:eb68149218fd 94 void decodeSetupPacket(unsigned char *data, SETUP_PACKET *packet);
simon 1:eb68149218fd 95 };
simon 1:eb68149218fd 96
simon 1:eb68149218fd 97 #endif