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

GP2040-CE Input Driver system rehaul #830

Merged
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
29 changes: 26 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,36 @@ src/main.cpp
src/gp2040.cpp
src/gp2040aux.cpp
src/gamepad.cpp
src/gamepad/GamepadDebouncer.cpp
src/gamepad/GamepadState.cpp
src/addonmanager.cpp
src/configmanager.cpp
src/drivers/shared/xinput_host.cpp
src/drivers/shared/xgip_protocol.cpp
src/drivers/astro/AstroDriver.cpp
src/drivers/egret/EgretDriver.cpp
src/drivers/hid/HIDDriver.cpp
src/drivers/keyboard/KeyboardDriver.cpp
src/drivers/mdmini/MDMiniDriver.cpp
src/drivers/neogeo/NeoGeoDriver.cpp
src/drivers/net/NetDriver.cpp
src/drivers/pcengine/PCEngineDriver.cpp
src/drivers/ps4/PS4Driver.cpp
src/drivers/psclassic/PSClassicDriver.cpp
src/drivers/switch/SwitchDriver.cpp
src/drivers/xbone/XBOneDriver.cpp
src/drivers/xboxog/xid/xid_driver.c
src/drivers/xboxog/xid/xid_gamepad.c
src/drivers/xboxog/xid/xid_remote.c
src/drivers/xboxog/xid/xid_steelbattalion.c
src/drivers/xboxog/xid/xid.c
src/drivers/xboxog/XboxOriginalDriver.cpp
src/drivers/xinput/XInputDriver.cpp
src/drivermanager.cpp
src/peripheralmanager.cpp
src/storagemanager.cpp
src/system.cpp
src/usbdriver.cpp
src/usbhostmanager.cpp
src/config_legacy.cpp
src/config_utils.cpp
Expand All @@ -173,8 +198,6 @@ src/addons/wiiext.cpp
src/addons/input_macro.cpp
src/addons/snes_input.cpp
src/addons/inputhistory.cpp
src/gamepad/GamepadDebouncer.cpp
src/gamepad/GamepadDescriptors.cpp
src/addons/tilt.cpp
src/addons/xbonepassthrough.cpp
${PROTO_OUTPUT_DIR}/enums.pb.c
Expand Down Expand Up @@ -205,14 +228,14 @@ PicoPeripherals
WiiExtension
SNESpad
pico_mbedtls
TinyUSB_Gamepad
nanopb
)

target_include_directories(${PROJECT_NAME} PUBLIC
headers
headers/addons
headers/configs
headers/drivers
headers/gamepad
configs/${GP2040_BOARDCONFIG}
${PROTO_OUTPUT_DIR}
Expand Down
1 change: 1 addition & 0 deletions headers/addons/keyboard_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "usbaddon.h"
#include "gamepad.h"
#include "class/hid/hid.h"

#ifndef KEYBOARD_HOST_ENABLED
#define KEYBOARD_HOST_ENABLED 0
Expand Down
3 changes: 1 addition & 2 deletions headers/addons/pspassthrough.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define _PSPassthrough_H

#include "usbaddon.h"

#include "ps4_driver.h"
#include "drivers/shared/ps4data.h"

#ifndef PSPASSTHROUGH_ENABLED
#define PSPASSTHROUGH_ENABLED 0
Expand Down
2 changes: 1 addition & 1 deletion headers/addons/xbonepassthrough.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "usbaddon.h"

#include "xgip_protocol.h"
#include "drivers/shared/xgip_protocol.h"

#ifndef XBONEPASSTHROUGH_ENABLED
#define XBONEPASSTHROUGH_ENABLED 0
Expand Down
24 changes: 24 additions & 0 deletions headers/drivermanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _DRIVERMANAGER_H
#define _DRIVERMANAGER_H

#include "enums.pb.h"
#include "gpdriver.h"

class GPDriver;

class DriverManager {
public:
DriverManager(DriverManager const&) = delete;
void operator=(DriverManager const&) = delete;
static DriverManager& getInstance() {// Thread-safe storage ensures cross-thread talk
static DriverManager instance; // Guaranteed to be destroyed. // Instantiated on first use.
return instance;
}
GPDriver * getDriver() { return driver; }
void setup(InputMode);
private:
DriverManager() {}
GPDriver * driver;
};

#endif
30 changes: 30 additions & 0 deletions headers/drivers/astro/AstroDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _ASTRO_DRIVER_H_
#define _ASTRO_DRIVER_H_

#include "gpdriver.h"
#include "drivers/astro/AstroDescriptors.h"

class AstroDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
AstroReport astroReport;
};

#endif // _ASTRO_DRIVER_H_
30 changes: 30 additions & 0 deletions headers/drivers/egret/EgretDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _EGRET_DRIVER_H_
#define _EGRET_DRIVER_H_

#include "gpdriver.h"
#include "drivers/egret/EgretDescriptors.h"

class EgretDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
EgretReport egretReport;
};

#endif // _EGRET_DRIVER_H_
30 changes: 30 additions & 0 deletions headers/drivers/hid/HIDDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _HID_DRIVER_H_
#define _HID_DRIVER_H_

#include "gpdriver.h"
#include "drivers/hid/HIDDescriptors.h"

class HIDDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
HIDReport hidReport;
};

#endif // _HID_DRIVER_H_
35 changes: 35 additions & 0 deletions headers/drivers/keyboard/KeyboardDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _KEYBOARD_DRIVER_H_
#define _KEYBOARD_DRIVER_H_

#include "gpdriver.h"
#include "drivers/keyboard/KeyboardDescriptors.h"

class KeyboardDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
void releaseAllKeys(void);
void pressKey(uint8_t code);
uint8_t getModifier(uint8_t code);
uint8_t getMultimedia(uint8_t code);
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
uint16_t last_report_size;
KeyboardReport keyboardReport;
};

#endif // _KEYBOARD_DRIVER_H_
30 changes: 30 additions & 0 deletions headers/drivers/mdmini/MDMiniDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _MDMINI_DRIVER_H_
#define _MDMINI_DRIVER_H_

#include "gpdriver.h"
#include "drivers/mdmini/MDMiniDescriptors.h"

class MDMiniDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
MDMiniReport mdminiReport;
};

#endif // _MDMINI_DRIVER_H_
30 changes: 30 additions & 0 deletions headers/drivers/neogeo/NeoGeoDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _NEOGEO_DRIVER_H_
#define _NEOGEO_DRIVER_H_

#include "gpdriver.h"
#include "drivers/neogeo/NeoGeoDescriptors.h"

class NeoGeoDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
NeogeoReport neogeoReport;
};

#endif // _NEOGEO_DRIVER_H_
27 changes: 27 additions & 0 deletions headers/drivers/net/NetDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _NET_DRIVER_H_
#define _NET_DRIVER_H_

#include "gpdriver.h"

class NetDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
};

#endif // _NET_DRIVER_H_
30 changes: 30 additions & 0 deletions headers/drivers/pcengine/PCEngineDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Copyright (c) 2024 OpenStickCommunity (gp2040-ce.info)
*/

#ifndef _PCENGINE_DRIVER_H_
#define _PCENGINE_DRIVER_H_

#include "gpdriver.h"
#include "drivers/pcengine/PCEngineDescriptors.h"

class PCEngineDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
virtual void set_report(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize);
virtual bool vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
virtual const uint16_t * get_descriptor_string_cb(uint8_t index, uint16_t langid);
virtual const uint8_t * get_descriptor_device_cb();
virtual const uint8_t * get_hid_descriptor_report_cb(uint8_t itf) ;
virtual const uint8_t * get_descriptor_configuration_cb(uint8_t index);
virtual const uint8_t * get_descriptor_device_qualifier_cb();
virtual uint16_t GetJoystickMidValue();
private:
uint8_t last_report[CFG_TUD_ENDPOINT0_SIZE] = { };
PCEngineReport pcengineReport;
};

#endif // _PCENGINE_DRIVER_H_
Loading
Loading