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); } }

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbdc.h Source File

usbdc.h

00001 /* usbdc.h */
00002 /* USB device controller */
00003 /* Copyright (c) Phil Wright 2008 */
00004 
00005 #ifndef USBDC_H
00006 #define USBDC_H
00007 
00008 /* Endpoints */
00009 #define EP0OUT  (0) /* Control */
00010 #define EP0IN   (1) /* Control */
00011 #define EP1OUT  (2) /* Interrupt */
00012 #define EP1IN   (3) /* Interrupt */
00013 #define EP2OUT  (4) /* Bulk */
00014 #define EP2IN   (5) /* Bulk */
00015 
00016 #include "mbed.h"
00017 
00018 class usbdc : public Base 
00019 {
00020 public:
00021     usbdc();
00022     void connect(void);
00023     void disconnect(void);
00024 protected:
00025     void setAddress(unsigned char address);
00026     void realiseEndpoint(unsigned char endpoint, unsigned long maxPacket);
00027     void enableEndpointEvent(unsigned char endpoint);
00028     void disableEndpointEvent(unsigned char endpoint);
00029     void stallEndpoint(unsigned char endpoint);
00030     void unstallEndpoint(unsigned char endpoint);
00031     bool getEndpointStallState(unsigned char endpoint);
00032     void configureDevice(void);
00033     void unconfigureDevice(void);
00034     unsigned long endpointRead(unsigned char endpoint, unsigned char *buffer);
00035     void endpointWrite(unsigned char endpoint, unsigned char *buffer, unsigned long size);
00036     void enableEvents(void);
00037     void disableEvents(void);    
00038     virtual void deviceEventReset(void);
00039     virtual void deviceEventFrame(void); 
00040     virtual void endpointEventEP0Setup(void);
00041     virtual void endpointEventEP0In(void);
00042     virtual void endpointEventEP0Out(void);
00043     virtual void endpointEventEP1In(void);
00044     virtual void endpointEventEP1Out(void);    
00045     virtual void endpointEventEP2In(void);
00046     virtual void endpointEventEP2Out(void);        
00047 private:
00048     void SIECommand(unsigned long command);
00049     void SIEWriteData(unsigned char data);
00050     unsigned char SIEReadData(unsigned long command);
00051     void setDeviceStatus(unsigned char status);
00052     void setEndpointStatus(unsigned char endpoint, unsigned char status);    
00053     unsigned char getDeviceStatus(void);
00054     unsigned char selectEndpoint(unsigned char endpoint);
00055     unsigned char selectEndpointClearInterrupt(unsigned char endpoint);
00056     unsigned char clearBuffer(void);
00057     void validateBuffer(void);
00058     void usbisr(void);
00059     unsigned long endpointStallState;
00060     static void _usbisr(void);
00061     static usbdc *instance;
00062 };
00063 
00064 
00065 #endif