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 /* usbhid.h */
innocopter 0:237d5ef643e9 2 /* USB HID class device */
innocopter 0:237d5ef643e9 3 /* Copyright (c) Phil Wright 2008 */
innocopter 0:237d5ef643e9 4
innocopter 0:237d5ef643e9 5 /* modified by Shinichiro Oba <http://mbed.org/users/bricklife/> */
innocopter 0:237d5ef643e9 6
innocopter 0:237d5ef643e9 7 #ifndef USBHID_H
innocopter 0:237d5ef643e9 8 #define USBHID_H
innocopter 0:237d5ef643e9 9
innocopter 0:237d5ef643e9 10 #include "usbdevice.h"
innocopter 0:237d5ef643e9 11
innocopter 0:237d5ef643e9 12 /* Mouse buttons */
innocopter 0:237d5ef643e9 13 #define MOUSE_L (1<<0)
innocopter 0:237d5ef643e9 14 #define MOUSE_M (1<<1)
innocopter 0:237d5ef643e9 15 #define MOUSE_R (1<<2)
innocopter 0:237d5ef643e9 16
innocopter 0:237d5ef643e9 17 class usbhid : public usbdevice
innocopter 0:237d5ef643e9 18 {
innocopter 0:237d5ef643e9 19 public:
innocopter 0:237d5ef643e9 20 usbhid();
innocopter 0:237d5ef643e9 21 bool keyboard(char c);
innocopter 0:237d5ef643e9 22 bool keyboard(char *string);
innocopter 0:237d5ef643e9 23 bool mouse(signed char x, signed char y, unsigned char buttons=0, signed char wheel=0);
innocopter 0:237d5ef643e9 24 protected:
innocopter 0:237d5ef643e9 25 virtual bool requestSetConfiguration();
innocopter 0:237d5ef643e9 26 virtual void endpointEventEP1In(void);
innocopter 0:237d5ef643e9 27 virtual void deviceEventReset(void);
innocopter 0:237d5ef643e9 28 virtual bool requestGetDescriptor(void);
innocopter 0:237d5ef643e9 29 virtual bool requestSetup(void);
innocopter 0:237d5ef643e9 30 private:
innocopter 0:237d5ef643e9 31 bool sendInputReport(unsigned char id, unsigned char *data, unsigned char size);
innocopter 0:237d5ef643e9 32 };
innocopter 0:237d5ef643e9 33
innocopter 0:237d5ef643e9 34
innocopter 0:237d5ef643e9 35 //
innocopter 0:237d5ef643e9 36 // USBJoystick
innocopter 0:237d5ef643e9 37 //
innocopter 0:237d5ef643e9 38
innocopter 0:237d5ef643e9 39 #define JOYSTICK_UP (1<<0)
innocopter 0:237d5ef643e9 40 #define JOYSTICK_DOWN (1<<1)
innocopter 0:237d5ef643e9 41 #define JOYSTICK_LEFT (1<<2)
innocopter 0:237d5ef643e9 42 #define JOYSTICK_RIGHT (1<<3)
innocopter 0:237d5ef643e9 43
innocopter 0:237d5ef643e9 44 class USBJoystick : public usbhid
innocopter 0:237d5ef643e9 45 {
innocopter 0:237d5ef643e9 46 public:
innocopter 0:237d5ef643e9 47 USBJoystick();
innocopter 0:237d5ef643e9 48 bool joystick(unsigned char stick, unsigned short buttons=0, signed char x=0, signed char y=0, signed char z=0, signed char rz=0);
innocopter 0:237d5ef643e9 49 protected:
innocopter 0:237d5ef643e9 50 virtual bool requestGetDescriptor(void);
innocopter 0:237d5ef643e9 51 virtual bool requestSetup(void);
innocopter 0:237d5ef643e9 52 private:
innocopter 0:237d5ef643e9 53 bool sendInputReport(unsigned char *data, unsigned char size);
innocopter 0:237d5ef643e9 54 };
innocopter 0:237d5ef643e9 55
innocopter 0:237d5ef643e9 56 #endif