A fully-Android-compatible two joysticks USB driver for LPC1768. The joysticks have 1 hat, 6 buttons, and there are 1P, 2P buttons.

Dependencies:   mbed

Fork of app-board-Joystick by Chris Styles

Committer:
Alberto_Wino
Date:
Fri Dec 16 18:17:42 2016 +0000
Revision:
1:76c47d2ba442
Child:
3:f1a8ec4659f8
Import for dual joystick support, suitable for an arcade machine.; Based on code from Phil Wright.

Who changed what in which revision?

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