N64 to USB HID interface

Dependencies:   mbed

Committer:
igor_m
Date:
Wed Dec 10 14:22:30 2014 +0000
Revision:
5:eb93a4f91396
Parent:
0:547c5459faa6
Initial Release

Who changed what in which revision?

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