A fully-Android-compatible two joysticks USB driver for LPC1768. The joysticks have 1 hat, 6 buttons, and there are 1P, 2P buttons.
Fork of app-board-Joystick by
main.cpp@2:84ea6e2fb4b6, 2016-12-17 (annotated)
- Committer:
- Alberto_Wino
- Date:
- Sat Dec 17 13:13:59 2016 +0000
- Revision:
- 2:84ea6e2fb4b6
- Parent:
- 1:76c47d2ba442
- Child:
- 3:f1a8ec4659f8
Added 2nd-pad-as-buttons configuration.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alberto_Wino | 2:84ea6e2fb4b6 | 1 | #include "config.h" |
chris | 0:0e4db18afd77 | 2 | #include "mbed.h" |
Alberto_Wino | 1:76c47d2ba442 | 3 | #include "usbhid.h" |
Alberto_Wino | 1:76c47d2ba442 | 4 | |
Alberto_Wino | 1:76c47d2ba442 | 5 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 6 | #ifdef CONFIG_TWO_REPORTS |
Alberto_Wino | 1:76c47d2ba442 | 7 | BusIn buttonsL |
Alberto_Wino | 1:76c47d2ba442 | 8 | ( |
Alberto_Wino | 1:76c47d2ba442 | 9 | p17, p16, p15, p20, // 3 top row, bottom-left |
Alberto_Wino | 2:84ea6e2fb4b6 | 10 | p19, p18, p14 // 2 bottom right, 1p |
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 | 2:84ea6e2fb4b6 | 16 | p11, p10, p6 // 2 bottom right, 2p |
Alberto_Wino | 1:76c47d2ba442 | 17 | ); |
chris | 0:0e4db18afd77 | 18 | |
Alberto_Wino | 1:76c47d2ba442 | 19 | BusIn stickL(p21, p22, p23, p24); |
Alberto_Wino | 1:76c47d2ba442 | 20 | BusIn stickR(p28, p26, p27, p29); |
Alberto_Wino | 2:84ea6e2fb4b6 | 21 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 22 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 23 | #ifdef CONFIG_2ND_PAD_AS_BUTTONS |
Alberto_Wino | 2:84ea6e2fb4b6 | 24 | BusIn buttonsL |
Alberto_Wino | 2:84ea6e2fb4b6 | 25 | ( |
Alberto_Wino | 2:84ea6e2fb4b6 | 26 | p17, p16, p15, p20, // 3 top row, bottom-left |
Alberto_Wino | 2:84ea6e2fb4b6 | 27 | p19, p18, p14 // 2 bottom right, 1p |
Alberto_Wino | 2:84ea6e2fb4b6 | 28 | ); |
Alberto_Wino | 2:84ea6e2fb4b6 | 29 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 30 | BusIn buttonsR |
Alberto_Wino | 2:84ea6e2fb4b6 | 31 | ( |
Alberto_Wino | 2:84ea6e2fb4b6 | 32 | p9, p8, p7, p12, // 3 top row, bottom-left |
Alberto_Wino | 2:84ea6e2fb4b6 | 33 | p11, p10, p6, p28, // 2 bottom right, 2p, pad |
Alberto_Wino | 2:84ea6e2fb4b6 | 34 | p26, p27, p29 // pad, pad, pad |
Alberto_Wino | 2:84ea6e2fb4b6 | 35 | ); |
Alberto_Wino | 2:84ea6e2fb4b6 | 36 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 37 | BusIn stickL(p21, p22, p23, p24); |
Alberto_Wino | 2:84ea6e2fb4b6 | 38 | #endif |
Alberto_Wino | 1:76c47d2ba442 | 39 | |
Alberto_Wino | 1:76c47d2ba442 | 40 | USBJoystick joysticks; // left and right pads |
chris | 0:0e4db18afd77 | 41 | |
chris | 0:0e4db18afd77 | 42 | int main() |
chris | 0:0e4db18afd77 | 43 | { |
Alberto_Wino | 2:84ea6e2fb4b6 | 44 | uint8_t stickL_old = 0; |
Alberto_Wino | 2:84ea6e2fb4b6 | 45 | #ifdef CONFIG_TWO_REPORTS |
Alberto_Wino | 2:84ea6e2fb4b6 | 46 | uint8_t stickR_old = 0; |
Alberto_Wino | 2:84ea6e2fb4b6 | 47 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 48 | uint32_t buttonsL_old = 0; |
Alberto_Wino | 2:84ea6e2fb4b6 | 49 | uint32_t buttonsR_old = 0; |
Alberto_Wino | 1:76c47d2ba442 | 50 | |
Alberto_Wino | 1:76c47d2ba442 | 51 | while(1) |
Alberto_Wino | 1:76c47d2ba442 | 52 | { |
Alberto_Wino | 2:84ea6e2fb4b6 | 53 | const uint8_t stickL_new = stickL.read(); |
Alberto_Wino | 2:84ea6e2fb4b6 | 54 | #ifdef CONFIG_TWO_REPORTS |
Alberto_Wino | 2:84ea6e2fb4b6 | 55 | const uint8_t stickR_new = stickR.read(); |
Alberto_Wino | 2:84ea6e2fb4b6 | 56 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 57 | const uint32_t buttonsL_new = buttonsL.read(); |
Alberto_Wino | 2:84ea6e2fb4b6 | 58 | const uint32_t buttonsR_new = buttonsR.read(); |
Alberto_Wino | 1:76c47d2ba442 | 59 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 60 | #ifdef CONFIG_TWO_REPORTS |
Alberto_Wino | 1:76c47d2ba442 | 61 | if ((stickL_old != stickL_new) || (buttonsL_old != buttonsL_new)) |
Alberto_Wino | 1:76c47d2ba442 | 62 | { |
Alberto_Wino | 1:76c47d2ba442 | 63 | stickL_old = stickL_new; |
Alberto_Wino | 1:76c47d2ba442 | 64 | buttonsL_old = buttonsL_new; |
Alberto_Wino | 1:76c47d2ba442 | 65 | joysticks.update(1, stickL_old, buttonsL_old); |
chris | 0:0e4db18afd77 | 66 | } |
Alberto_Wino | 1:76c47d2ba442 | 67 | |
Alberto_Wino | 1:76c47d2ba442 | 68 | if ((stickR_old != stickR_new) || (buttonsR_old != buttonsR_new)) |
Alberto_Wino | 1:76c47d2ba442 | 69 | { |
Alberto_Wino | 1:76c47d2ba442 | 70 | stickR_old = stickR_new; |
Alberto_Wino | 1:76c47d2ba442 | 71 | buttonsR_old = buttonsR_new; |
Alberto_Wino | 1:76c47d2ba442 | 72 | joysticks.update(2, stickR_old, buttonsR_old); |
Alberto_Wino | 1:76c47d2ba442 | 73 | } |
Alberto_Wino | 2:84ea6e2fb4b6 | 74 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 75 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 76 | #ifdef CONFIG_2ND_PAD_AS_BUTTONS |
Alberto_Wino | 2:84ea6e2fb4b6 | 77 | if ((stickL_old != stickL_new) || (buttonsL_old != buttonsL_new) || (buttonsR_old != buttonsR_new)) |
Alberto_Wino | 2:84ea6e2fb4b6 | 78 | { |
Alberto_Wino | 2:84ea6e2fb4b6 | 79 | const uint32_t buttons = buttonsL_new | (buttonsR_new << 7); |
Alberto_Wino | 2:84ea6e2fb4b6 | 80 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 81 | stickL_old = stickL_new; |
Alberto_Wino | 2:84ea6e2fb4b6 | 82 | buttonsL_old = buttonsL_new; |
Alberto_Wino | 2:84ea6e2fb4b6 | 83 | buttonsR_old = buttonsR_new; |
Alberto_Wino | 2:84ea6e2fb4b6 | 84 | joysticks.update(0, stickL_old, buttons); |
Alberto_Wino | 2:84ea6e2fb4b6 | 85 | } |
Alberto_Wino | 2:84ea6e2fb4b6 | 86 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 87 | |
Alberto_Wino | 1:76c47d2ba442 | 88 | wait(0.016666); /* 60 Hz */ |
chris | 0:0e4db18afd77 | 89 | } |
Alberto_Wino | 1:76c47d2ba442 | 90 | } |