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
Parent:
0:0e4db18afd77
Child:
2:84ea6e2fb4b6
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
chris 0:0e4db18afd77 1 #include "mbed.h"
Alberto_Wino 1:76c47d2ba442 2 #include "usbhid.h"
Alberto_Wino 1:76c47d2ba442 3
Alberto_Wino 1:76c47d2ba442 4 #define IGN p5 /* ignore */
Alberto_Wino 1:76c47d2ba442 5
Alberto_Wino 1:76c47d2ba442 6 BusIn buttonsL
Alberto_Wino 1:76c47d2ba442 7 (
Alberto_Wino 1:76c47d2ba442 8 p17, p16, p15, p20, // 3 top row, bottom-left
Alberto_Wino 1:76c47d2ba442 9 p19, p18, p14, IGN, // 2 bottom right, 1p
Alberto_Wino 1:76c47d2ba442 10 IGN, IGN, IGN, IGN
Alberto_Wino 1:76c47d2ba442 11 );
chris 0:0e4db18afd77 12
Alberto_Wino 1:76c47d2ba442 13 BusIn buttonsR
Alberto_Wino 1:76c47d2ba442 14 (
Alberto_Wino 1:76c47d2ba442 15 p9, p8, p7, p12, // 3 top row, bottom-left
Alberto_Wino 1:76c47d2ba442 16 p11, p10, p6, IGN, // 2 bottom right, 2p
Alberto_Wino 1:76c47d2ba442 17 IGN, IGN, IGN, IGN
Alberto_Wino 1:76c47d2ba442 18 );
chris 0:0e4db18afd77 19
Alberto_Wino 1:76c47d2ba442 20 BusIn stickL(p21, p22, p23, p24);
Alberto_Wino 1:76c47d2ba442 21 BusIn stickR(p28, p26, p27, p29);
Alberto_Wino 1:76c47d2ba442 22
Alberto_Wino 1:76c47d2ba442 23 USBJoystick joysticks; // left and right pads
chris 0:0e4db18afd77 24
chris 0:0e4db18afd77 25 int main()
chris 0:0e4db18afd77 26 {
Alberto_Wino 1:76c47d2ba442 27 unsigned char stickL_old = 0;
Alberto_Wino 1:76c47d2ba442 28 unsigned char stickR_old = 0;
Alberto_Wino 1:76c47d2ba442 29 unsigned char buttonsL_old = 0;
Alberto_Wino 1:76c47d2ba442 30 unsigned char buttonsR_old = 0;
Alberto_Wino 1:76c47d2ba442 31
Alberto_Wino 1:76c47d2ba442 32 while(1)
Alberto_Wino 1:76c47d2ba442 33 {
Alberto_Wino 1:76c47d2ba442 34 const unsigned char stickL_new = stickL.read();
Alberto_Wino 1:76c47d2ba442 35 const unsigned char stickR_new = stickR.read();
Alberto_Wino 1:76c47d2ba442 36 const unsigned long buttonsL_new = buttonsL.read();
Alberto_Wino 1:76c47d2ba442 37 const unsigned long buttonsR_new = buttonsR.read();
Alberto_Wino 1:76c47d2ba442 38
Alberto_Wino 1:76c47d2ba442 39 if ((stickL_old != stickL_new) || (buttonsL_old != buttonsL_new))
Alberto_Wino 1:76c47d2ba442 40 {
Alberto_Wino 1:76c47d2ba442 41 stickL_old = stickL_new;
Alberto_Wino 1:76c47d2ba442 42 buttonsL_old = buttonsL_new;
Alberto_Wino 1:76c47d2ba442 43 joysticks.update(1, stickL_old, buttonsL_old);
chris 0:0e4db18afd77 44 }
Alberto_Wino 1:76c47d2ba442 45
Alberto_Wino 1:76c47d2ba442 46 if ((stickR_old != stickR_new) || (buttonsR_old != buttonsR_new))
Alberto_Wino 1:76c47d2ba442 47 {
Alberto_Wino 1:76c47d2ba442 48 stickR_old = stickR_new;
Alberto_Wino 1:76c47d2ba442 49 buttonsR_old = buttonsR_new;
Alberto_Wino 1:76c47d2ba442 50 joysticks.update(2, stickR_old, buttonsR_old);
Alberto_Wino 1:76c47d2ba442 51 }
Alberto_Wino 1:76c47d2ba442 52 wait(0.016666); /* 60 Hz */
chris 0:0e4db18afd77 53 }
Alberto_Wino 1:76c47d2ba442 54 }