Joystick enabled version of USBHID -library. Has full Playstation 3 functionality including button pressures and a working home-button implementation, while maintaining full PC/MAC/linux -compatibility. basic operation of the lib: #include "mbed.h" #include "usbhid.h" USBJoystick joystick; int main() { while(1) { char dpad = 0xf; /*only the rightmost 4 bits matter*/ short button = 0xff; /*only the rightmost 13 bits matter*/ /*buttons are square, cross, circle, triangle, l1, r1, l2, r2, l3, r3, home.*/ char stick1x = 0; char stick1y = 0; char stick2x = 0; char stick2y = 0; joystick.joystick(dpad, buttons, stick1x, stick1y, stick2x, stick2y); wait_ms(5); } }

Committer:
innocopter
Date:
Fri May 11 13:35:59 2012 +0000
Revision:
0:237d5ef643e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
innocopter 0:237d5ef643e9 1 /* usbdc.h */
innocopter 0:237d5ef643e9 2 /* USB device controller */
innocopter 0:237d5ef643e9 3 /* Copyright (c) Phil Wright 2008 */
innocopter 0:237d5ef643e9 4
innocopter 0:237d5ef643e9 5 #ifndef USBDC_H
innocopter 0:237d5ef643e9 6 #define USBDC_H
innocopter 0:237d5ef643e9 7
innocopter 0:237d5ef643e9 8 /* Endpoints */
innocopter 0:237d5ef643e9 9 #define EP0OUT (0) /* Control */
innocopter 0:237d5ef643e9 10 #define EP0IN (1) /* Control */
innocopter 0:237d5ef643e9 11 #define EP1OUT (2) /* Interrupt */
innocopter 0:237d5ef643e9 12 #define EP1IN (3) /* Interrupt */
innocopter 0:237d5ef643e9 13 #define EP2OUT (4) /* Bulk */
innocopter 0:237d5ef643e9 14 #define EP2IN (5) /* Bulk */
innocopter 0:237d5ef643e9 15
innocopter 0:237d5ef643e9 16 #include "mbed.h"
innocopter 0:237d5ef643e9 17
innocopter 0:237d5ef643e9 18 class usbdc : public Base
innocopter 0:237d5ef643e9 19 {
innocopter 0:237d5ef643e9 20 public:
innocopter 0:237d5ef643e9 21 usbdc();
innocopter 0:237d5ef643e9 22 void connect(void);
innocopter 0:237d5ef643e9 23 void disconnect(void);
innocopter 0:237d5ef643e9 24 protected:
innocopter 0:237d5ef643e9 25 void setAddress(unsigned char address);
innocopter 0:237d5ef643e9 26 void realiseEndpoint(unsigned char endpoint, unsigned long maxPacket);
innocopter 0:237d5ef643e9 27 void enableEndpointEvent(unsigned char endpoint);
innocopter 0:237d5ef643e9 28 void disableEndpointEvent(unsigned char endpoint);
innocopter 0:237d5ef643e9 29 void stallEndpoint(unsigned char endpoint);
innocopter 0:237d5ef643e9 30 void unstallEndpoint(unsigned char endpoint);
innocopter 0:237d5ef643e9 31 bool getEndpointStallState(unsigned char endpoint);
innocopter 0:237d5ef643e9 32 void configureDevice(void);
innocopter 0:237d5ef643e9 33 void unconfigureDevice(void);
innocopter 0:237d5ef643e9 34 unsigned long endpointRead(unsigned char endpoint, unsigned char *buffer);
innocopter 0:237d5ef643e9 35 void endpointWrite(unsigned char endpoint, unsigned char *buffer, unsigned long size);
innocopter 0:237d5ef643e9 36 void enableEvents(void);
innocopter 0:237d5ef643e9 37 void disableEvents(void);
innocopter 0:237d5ef643e9 38 virtual void deviceEventReset(void);
innocopter 0:237d5ef643e9 39 virtual void deviceEventFrame(void);
innocopter 0:237d5ef643e9 40 virtual void endpointEventEP0Setup(void);
innocopter 0:237d5ef643e9 41 virtual void endpointEventEP0In(void);
innocopter 0:237d5ef643e9 42 virtual void endpointEventEP0Out(void);
innocopter 0:237d5ef643e9 43 virtual void endpointEventEP1In(void);
innocopter 0:237d5ef643e9 44 virtual void endpointEventEP1Out(void);
innocopter 0:237d5ef643e9 45 virtual void endpointEventEP2In(void);
innocopter 0:237d5ef643e9 46 virtual void endpointEventEP2Out(void);
innocopter 0:237d5ef643e9 47 private:
innocopter 0:237d5ef643e9 48 void SIECommand(unsigned long command);
innocopter 0:237d5ef643e9 49 void SIEWriteData(unsigned char data);
innocopter 0:237d5ef643e9 50 unsigned char SIEReadData(unsigned long command);
innocopter 0:237d5ef643e9 51 void setDeviceStatus(unsigned char status);
innocopter 0:237d5ef643e9 52 void setEndpointStatus(unsigned char endpoint, unsigned char status);
innocopter 0:237d5ef643e9 53 unsigned char getDeviceStatus(void);
innocopter 0:237d5ef643e9 54 unsigned char selectEndpoint(unsigned char endpoint);
innocopter 0:237d5ef643e9 55 unsigned char selectEndpointClearInterrupt(unsigned char endpoint);
innocopter 0:237d5ef643e9 56 unsigned char clearBuffer(void);
innocopter 0:237d5ef643e9 57 void validateBuffer(void);
innocopter 0:237d5ef643e9 58 void usbisr(void);
innocopter 0:237d5ef643e9 59 unsigned long endpointStallState;
innocopter 0:237d5ef643e9 60 static void _usbisr(void);
innocopter 0:237d5ef643e9 61 static usbdc *instance;
innocopter 0:237d5ef643e9 62 };
innocopter 0:237d5ef643e9 63
innocopter 0:237d5ef643e9 64
innocopter 0:237d5ef643e9 65 #endif