Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wii extension controller support #228

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ src/addons/ps4mode.cpp
src/addons/reverse.cpp
src/addons/turbo.cpp
src/addons/slider_socd.cpp
src/addons/wiiext.cpp
src/gamepad/GamepadDebouncer.cpp
src/gamepad/GamepadDescriptors.cpp
)
Expand All @@ -147,6 +148,7 @@ OneBitDisplay
ArduinoJson
rndis
hardware_adc
WiiExtension
pico_mbedtls
TinyUSB_Gamepad
)
Expand Down
Binary file added docs/assets/images/gpc-add-ons-wii-extensions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions docs/web-configurator.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,37 @@ Enabling this add-on will allow you to use GP2040-CE on a PS4 with an 8 minute t
* `Serial Number (16 Bytes in Hex Ascii)` - Choose your serial number file.
* `Signature (256 Bytes in Binary)` - Choose your signature file.

### Wii Extensions

![GP2040 Configurator - Wii Extensions](assets/images/gpc-add-ons-wii-extensions.png)

* `I2C SDA Pin` - The GPIO pin used for Wii Extension SDA.
* `I2C SCL Pin` - The GPIO pin used for Wii Extension SCL.
* `I2C Block` - The block of I2C to use (i2c0 or i2c1).
* `I2C Speed` - Sets the speed of I2C communication. Common values are `100000` for standard, or `400000` for fast.

Supported Extension Controllers and their mapping is as follows:

| GP2040-CE | Nunchuck | Classic | Guitar Hero Guitar |
|-----------|----------|--------------|--------------------|
| B1 | C | B | Green |
| B2 | Z | A | Red |
| B3 | | Y | Blue |
| B4 | | X | Yellow |
| L1 | | L | |
| L2 | | ZL | |
| R1 | | R | |
| R2 | | ZR | |
| S1 | | Select | |
| S2 | | Start | |
| A1 | | Home | |
| D-Pad | | D-Pad | Strum Up/Down |
| Analog | Left | Left & Right | Left |

Classic Controller support includes Classic, Classic Pro, and NES/SNES Mini Controllers.

Original Classic Controller L & R triggers are analog sensitive, where Pro triggers are not.

## Data Backup and Restoration

![GP2040-CE Configurator - Add-Ons Backup and Restore](assets/images/gpc-backup-and-restore.png)
Expand Down
85 changes: 85 additions & 0 deletions headers/addons/wiiext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef _WIIExtensionAddon_H
#define _WIIExtensionAddon_H

#include <string>
#include <stdint.h>
#include <hardware/i2c.h>
#include "BoardConfig.h"
#include "gpaddon.h"
#include "gamepad.h"
#include "storagemanager.h"
#include "WiiExtension.h"

// WiiExtension Module Name
#define WiiExtensionName "WiiExtension"

#ifndef WII_EXTENSION_ENABLED
#define WII_EXTENSION_ENABLED 1
#endif

#ifndef WII_EXTENSION_I2C_ADDR
#define WII_EXTENSION_I2C_ADDR 0x52
#endif

#ifndef WII_EXTENSION_I2C_SDA_PIN
#define WII_EXTENSION_I2C_SDA_PIN 16
#endif

#ifndef WII_EXTENSION_I2C_SCL_PIN
#define WII_EXTENSION_I2C_SCL_PIN 17
#endif

#ifndef WII_EXTENSION_I2C_BLOCK
#define WII_EXTENSION_I2C_BLOCK i2c0
#endif

#ifndef WII_EXTENSION_I2C_SPEED
#define WII_EXTENSION_I2C_SPEED 400000
#endif

class WiiExtensionInput : public GPAddon {
public:
virtual bool available();
virtual void setup(); // WiiExtension Setup
virtual void process(); // WiiExtension Process
virtual void preprocess() {}
virtual std::string name() { return WiiExtensionName; }
private:
WiiExtension * wii;
uint32_t uIntervalMS;
uint32_t nextTimer;

bool buttonC = false;
bool buttonZ = false;

bool buttonA = false;
bool buttonB = false;
bool buttonX = false;
bool buttonY = false;
bool buttonL = false;
bool buttonZL = false;
bool buttonR = false;
bool buttonZR = false;

bool buttonSelect = false;
bool buttonStart = false;
bool buttonHome = false;

bool dpadUp = false;
bool dpadDown = false;
bool dpadLeft = false;
bool dpadRight = false;

uint16_t triggerLeft = 0;
uint16_t triggerRight = 0;
uint16_t whammyBar = 0;

uint16_t leftX = 0;
uint16_t leftY = 0;
uint16_t rightX = 0;
uint16_t rightY = 0;

uint16_t map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);
};

#endif // _WIIExtensionAddon_H
5 changes: 5 additions & 0 deletions headers/storagemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ struct AddonOptions {
SOCDMode sliderSOCDModeOne;
SOCDMode sliderSOCDModeTwo;
SOCDMode sliderSOCDModeDefault;
uint8_t wiiExtensionSDAPin;
uint8_t wiiExtensionSCLPin;
int wiiExtensionBlock;
uint32_t wiiExtensionSpeed;
uint8_t AnalogInputEnabled;
uint8_t BoardLedAddonEnabled;
uint8_t BootselButtonAddonEnabled;
Expand All @@ -156,6 +160,7 @@ struct AddonOptions {
uint8_t ReverseInputEnabled;
uint8_t TurboInputEnabled;
uint8_t SliderSOCDInputEnabled;
uint8_t WiiExtensionAddonEnabled;
uint32_t checksum;
};

Expand Down
3 changes: 2 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ add_subdirectory(NeoPico)
add_subdirectory(OneBitDisplay)
add_subdirectory(PlayerLEDs)
add_subdirectory(rndis)
add_subdirectory(TinyUSB_Gamepad)
add_subdirectory(TinyUSB_Gamepad)
add_subdirectory(WiiExtension)
6 changes: 6 additions & 0 deletions lib/WiiExtension/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_library(WiiExtension WiiExtension.cpp)
target_link_libraries(WiiExtension PUBLIC BitBang_I2C)
target_include_directories(WiiExtension INTERFACE .)
target_include_directories(WiiExtension PUBLIC
BitBang_I2C
)
6 changes: 6 additions & 0 deletions lib/WiiExtension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# WiiExtension
# Ported to BitBangI2C
#
# Written by:
# Mike Parks
# <[email protected]>
Loading