diff --git a/GP2040-CE/headers/gba/GBAKey.h b/GP2040-CE/headers/gba/GBAKey.h new file mode 100644 index 0000000..14d9382 --- /dev/null +++ b/GP2040-CE/headers/gba/GBAKey.h @@ -0,0 +1,14 @@ +#pragma once + +enum GBAKey : uint32_t { + A = 1 << 0, + B = 1 << 1, + SELECT = 1 << 2, + START = 1 << 3, + RIGHT = 1 << 4, + LEFT = 1 << 5, + UP = 1 << 6, + DOWN = 1 << 7, + R = 1 << 8, + L = 1 << 9 +}; diff --git a/GP2040-CE/headers/gba/multiboot.h b/GP2040-CE/headers/gba/multiboot.h index 11f957c..df74efc 100644 --- a/GP2040-CE/headers/gba/multiboot.h +++ b/GP2040-CE/headers/gba/multiboot.h @@ -5,8 +5,7 @@ * https://github.com/akkera102/gba_03_multiboot */ -#ifndef _GBA_SPI32_H_ -#define _GBA_SPI32_H_ +#pragma once #include @@ -14,9 +13,7 @@ namespace gba { /// @return `true` if ROM is sent -/// @return `false` if GBA program is already running, and only `L` is pressed on it +/// @return `false` if GBA program is already running, and only `Start` is pressed on it bool sendGBARom(const uint8_t* romAddr, uint32_t romSize); } - -#endif \ No newline at end of file diff --git a/GP2040-CE/headers/gba/spi32.h b/GP2040-CE/headers/gba/spi32.h index 8210e71..6a7c146 100644 --- a/GP2040-CE/headers/gba/spi32.h +++ b/GP2040-CE/headers/gba/spi32.h @@ -2,8 +2,7 @@ * SPDX-License-Identifier: CC0-1.0 */ -#ifndef _GBA_SPI32_H_ -#define _GBA_SPI32_H_ +#pragma once // Pico SPI #include "hardware/spi.h" @@ -18,5 +17,3 @@ void deinitSpi32(); uint32_t spi32(uint32_t val); } - -#endif diff --git a/GP2040-CE/src/gamepad.cpp b/GP2040-CE/src/gamepad.cpp index 84ef020..634f49b 100644 --- a/GP2040-CE/src/gamepad.cpp +++ b/GP2040-CE/src/gamepad.cpp @@ -14,6 +14,7 @@ #include "CRC32.h" #include "gba/spi32.h" +#include "gba/GBAKey.h" // MUST BE DEFINED for mpgs uint32_t getMillis() { @@ -180,19 +181,6 @@ void Gamepad::read() { constexpr uint32_t GBA_SPI_ERROR = 0xFFFFFFFFu; - enum GBAKey : uint32_t { - A = 1 << 0, - B = 1 << 1, - SELECT = 1 << 2, - START = 1 << 3, - RIGHT = 1 << 4, - LEFT = 1 << 5, - UP = 1 << 6, - DOWN = 1 << 7, - R = 1 << 8, - L = 1 << 9 - }; - uint32_t received = gba::spi32(state.buttons); if (received == GBA_SPI_ERROR) { diff --git a/GP2040-CE/src/gba/multiboot.cpp b/GP2040-CE/src/gba/multiboot.cpp index 4c40ce1..921c18b 100644 --- a/GP2040-CE/src/gba/multiboot.cpp +++ b/GP2040-CE/src/gba/multiboot.cpp @@ -5,11 +5,14 @@ * https://github.com/akkera102/gba_03_multiboot */ -#include "gba/spi32.h" +#include "gba/multiboot.h" #include #include "pico/stdlib.h" +#include "gba/spi32.h" +#include "gba/GBAKey.h" + namespace gba { @@ -34,10 +37,10 @@ bool sendGBARom(const uint8_t* romAddr, const uint32_t romSize) { do { recv = gba::spi32(0x6202); sleep_ms(10); - } while ((recv >> 16) != 0x7202 && recv != (1 << 9)); + } while ((recv >> 16) != 0x7202 && recv != (GBAKey::START)); - // if GBA program is already running, and only `L` is pressed on it - if (recv == (1 << 9)) + // if GBA program is already running, and only `Start` is pressed on it + if (recv == (GBAKey::START)) return false; // ----------------------------------------------------- diff --git a/GP2040-CE/src/gp2040.cpp b/GP2040-CE/src/gp2040.cpp index 25cc08b..ca7b832 100644 --- a/GP2040-CE/src/gp2040.cpp +++ b/GP2040-CE/src/gp2040.cpp @@ -177,11 +177,13 @@ GP2040::BootAction GP2040::getBootAction() { if (gamepad->pressedF1() && gamepad->pressedUp()) { return BootAction::ENTER_USB_MODE; - } else if (gamepad->pressedS2()) { - return BootAction::ENTER_WEBCONFIG_MODE; - } else if (gamepad->pressedB3()) { // P1 + } + // else if (gamepad->pressedS2()) { + // return BootAction::ENTER_WEBCONFIG_MODE; + // } + else if (gamepad->pressedL1()) { // P1 return BootAction::SET_INPUT_MODE_HID; - } else if (gamepad->pressedB4()) { // P2 + } else if (gamepad->pressedR1()) { // P2 return BootAction::SET_INPUT_MODE_PS4; } else if (gamepad->pressedB1()) { // K1 return BootAction::SET_INPUT_MODE_SWITCH; diff --git a/README.md b/README.md index d8f2223..e7e197f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Proof-of-concept Game Boy Advance (GBA) to USB controller, which uses Raspberry [![](https://img.youtube.com/vi/JmBufgcb4Gw/hqdefault.jpg)](https://www.youtube.com/watch?v=JmBufgcb4Gw "Youtube video for gba-pico-gamepad") -# How it works +# How it's done This project is essentially a modified version of [GP2040-CE](https://github.com/OpenStickCommunity/GP2040-CE) that enables communication with the Game Boy Advance using the GBA link cable. @@ -43,16 +43,17 @@ And that's about it. 4. Plug the USB Cable to your PC.\ It will start sending the program once the GBA is ready. - * You can [hold down certain key on boot to change Input Mode.](https://gp2040-ce.info/#/usage?id=input-modes) + * You can hold down certain key on boot to change Input Mode. + + Note that the key binding is differ from the [original](https://gp2040-ce.info/#/usage?id=input-modes). + Hold `B` on boot -> Nintendo Switch + Hold `A` on boot -> XInput - + The other options cannot be pressed with keys on the GBA,\ - but no modifications are done yet to deal with that. + + Hold `L` on boot -> DirectInput/PS3 + + Hold `R` on boot -> PS4 * You can [change the D-Pad Mode anytime with certain key combination.](https://gp2040-ce.info/#/usage?id=d-pad-modes) * GP2040-CE's Web Config is disabled. 5. Enjoy your GBA as an USB gamepad. - * If you accidentally pulled out your cable, you can re-plug it and press `L` to reconnect. + * If you accidentally pulled out your cable, you can re-plug it and press `Start` to reconnect. # Build