Norbert S / Mbed 2 deprecated joykey

Dependencies:   mbed

Committer:
norberts
Date:
Sun Aug 05 17:29:07 2012 +0000
Revision:
3:13401b125368
Parent:
0:207850946233
runs with WASD + SP (minecraft)

Who changed what in which revision?

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