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@3:f1a8ec4659f8, 2016-12-17 (annotated)
- Committer:
- Alberto_Wino
- Date:
- Sat Dec 17 15:10:12 2016 +0000
- Revision:
- 3:f1a8ec4659f8
- Parent:
- 2:84ea6e2fb4b6
Added a two-interface configuration, which fully works on Android.
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 | 3:f1a8ec4659f8 | 5 | #if CONFIG_TWO_REPORTS || CONFIG_TWO_INTERFACES |
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 | 2:84ea6e2fb4b6 | 9 | p19, p18, p14 // 2 bottom right, 1p |
Alberto_Wino | 1:76c47d2ba442 | 10 | ); |
chris | 0:0e4db18afd77 | 11 | |
Alberto_Wino | 1:76c47d2ba442 | 12 | BusIn buttonsR |
Alberto_Wino | 1:76c47d2ba442 | 13 | ( |
Alberto_Wino | 1:76c47d2ba442 | 14 | p9, p8, p7, p12, // 3 top row, bottom-left |
Alberto_Wino | 2:84ea6e2fb4b6 | 15 | p11, p10, p6 // 2 bottom right, 2p |
Alberto_Wino | 1:76c47d2ba442 | 16 | ); |
chris | 0:0e4db18afd77 | 17 | |
Alberto_Wino | 1:76c47d2ba442 | 18 | BusIn stickL(p21, p22, p23, p24); |
Alberto_Wino | 1:76c47d2ba442 | 19 | BusIn stickR(p28, p26, p27, p29); |
Alberto_Wino | 2:84ea6e2fb4b6 | 20 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 21 | |
Alberto_Wino | 3:f1a8ec4659f8 | 22 | #if CONFIG_2ND_PAD_AS_BUTTONS |
Alberto_Wino | 2:84ea6e2fb4b6 | 23 | BusIn buttonsL |
Alberto_Wino | 2:84ea6e2fb4b6 | 24 | ( |
Alberto_Wino | 2:84ea6e2fb4b6 | 25 | p17, p16, p15, p20, // 3 top row, bottom-left |
Alberto_Wino | 2:84ea6e2fb4b6 | 26 | p19, p18, p14 // 2 bottom right, 1p |
Alberto_Wino | 2:84ea6e2fb4b6 | 27 | ); |
Alberto_Wino | 2:84ea6e2fb4b6 | 28 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 29 | BusIn buttonsR |
Alberto_Wino | 2:84ea6e2fb4b6 | 30 | ( |
Alberto_Wino | 2:84ea6e2fb4b6 | 31 | p9, p8, p7, p12, // 3 top row, bottom-left |
Alberto_Wino | 2:84ea6e2fb4b6 | 32 | p11, p10, p6, p28, // 2 bottom right, 2p, pad |
Alberto_Wino | 2:84ea6e2fb4b6 | 33 | p26, p27, p29 // pad, pad, pad |
Alberto_Wino | 2:84ea6e2fb4b6 | 34 | ); |
Alberto_Wino | 2:84ea6e2fb4b6 | 35 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 36 | BusIn stickL(p21, p22, p23, p24); |
Alberto_Wino | 2:84ea6e2fb4b6 | 37 | #endif |
Alberto_Wino | 1:76c47d2ba442 | 38 | |
Alberto_Wino | 1:76c47d2ba442 | 39 | USBJoystick joysticks; // left and right pads |
chris | 0:0e4db18afd77 | 40 | |
chris | 0:0e4db18afd77 | 41 | int main() |
chris | 0:0e4db18afd77 | 42 | { |
Alberto_Wino | 2:84ea6e2fb4b6 | 43 | uint8_t stickL_old = 0; |
Alberto_Wino | 3:f1a8ec4659f8 | 44 | #if CONFIG_TWO_REPORTS || CONFIG_TWO_INTERFACES |
Alberto_Wino | 2:84ea6e2fb4b6 | 45 | uint8_t stickR_old = 0; |
Alberto_Wino | 2:84ea6e2fb4b6 | 46 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 47 | uint32_t buttonsL_old = 0; |
Alberto_Wino | 2:84ea6e2fb4b6 | 48 | uint32_t buttonsR_old = 0; |
Alberto_Wino | 1:76c47d2ba442 | 49 | |
Alberto_Wino | 1:76c47d2ba442 | 50 | while(1) |
Alberto_Wino | 1:76c47d2ba442 | 51 | { |
Alberto_Wino | 2:84ea6e2fb4b6 | 52 | const uint8_t stickL_new = stickL.read(); |
Alberto_Wino | 3:f1a8ec4659f8 | 53 | #if CONFIG_TWO_REPORTS || CONFIG_TWO_INTERFACES |
Alberto_Wino | 2:84ea6e2fb4b6 | 54 | const uint8_t stickR_new = stickR.read(); |
Alberto_Wino | 2:84ea6e2fb4b6 | 55 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 56 | const uint32_t buttonsL_new = buttonsL.read(); |
Alberto_Wino | 2:84ea6e2fb4b6 | 57 | const uint32_t buttonsR_new = buttonsR.read(); |
Alberto_Wino | 1:76c47d2ba442 | 58 | |
Alberto_Wino | 3:f1a8ec4659f8 | 59 | #if CONFIG_TWO_REPORTS || CONFIG_TWO_INTERFACES |
Alberto_Wino | 1:76c47d2ba442 | 60 | if ((stickL_old != stickL_new) || (buttonsL_old != buttonsL_new)) |
Alberto_Wino | 1:76c47d2ba442 | 61 | { |
Alberto_Wino | 1:76c47d2ba442 | 62 | stickL_old = stickL_new; |
Alberto_Wino | 1:76c47d2ba442 | 63 | buttonsL_old = buttonsL_new; |
Alberto_Wino | 1:76c47d2ba442 | 64 | joysticks.update(1, stickL_old, buttonsL_old); |
chris | 0:0e4db18afd77 | 65 | } |
Alberto_Wino | 1:76c47d2ba442 | 66 | |
Alberto_Wino | 1:76c47d2ba442 | 67 | if ((stickR_old != stickR_new) || (buttonsR_old != buttonsR_new)) |
Alberto_Wino | 1:76c47d2ba442 | 68 | { |
Alberto_Wino | 1:76c47d2ba442 | 69 | stickR_old = stickR_new; |
Alberto_Wino | 1:76c47d2ba442 | 70 | buttonsR_old = buttonsR_new; |
Alberto_Wino | 1:76c47d2ba442 | 71 | joysticks.update(2, stickR_old, buttonsR_old); |
Alberto_Wino | 1:76c47d2ba442 | 72 | } |
Alberto_Wino | 2:84ea6e2fb4b6 | 73 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 74 | |
Alberto_Wino | 3:f1a8ec4659f8 | 75 | #if CONFIG_2ND_PAD_AS_BUTTONS |
Alberto_Wino | 2:84ea6e2fb4b6 | 76 | if ((stickL_old != stickL_new) || (buttonsL_old != buttonsL_new) || (buttonsR_old != buttonsR_new)) |
Alberto_Wino | 2:84ea6e2fb4b6 | 77 | { |
Alberto_Wino | 2:84ea6e2fb4b6 | 78 | const uint32_t buttons = buttonsL_new | (buttonsR_new << 7); |
Alberto_Wino | 2:84ea6e2fb4b6 | 79 | |
Alberto_Wino | 2:84ea6e2fb4b6 | 80 | stickL_old = stickL_new; |
Alberto_Wino | 2:84ea6e2fb4b6 | 81 | buttonsL_old = buttonsL_new; |
Alberto_Wino | 2:84ea6e2fb4b6 | 82 | buttonsR_old = buttonsR_new; |
Alberto_Wino | 2:84ea6e2fb4b6 | 83 | joysticks.update(0, stickL_old, buttons); |
Alberto_Wino | 2:84ea6e2fb4b6 | 84 | } |
Alberto_Wino | 2:84ea6e2fb4b6 | 85 | #endif |
Alberto_Wino | 2:84ea6e2fb4b6 | 86 | |
Alberto_Wino | 1:76c47d2ba442 | 87 | wait(0.016666); /* 60 Hz */ |
chris | 0:0e4db18afd77 | 88 | } |
Alberto_Wino | 1:76c47d2ba442 | 89 | } |