decouple pico-sdk from device drivers

This commit is contained in:
wiredopposite
2024-12-31 21:13:58 -07:00
parent de3f25d183
commit c4ebea1d01
11 changed files with 25 additions and 50 deletions

View File

@@ -7,7 +7,7 @@
"PICO_SDK_PATH": "C:/Programming/pico-sdk"
},
"cmake.configureArgs": [
"-DOGXM_BOARD=W_ESP32",
"-DOGXM_BOARD=PI_PICO2",
"-DMAX_GAMEPADS=1"
],
"files.associations": {

View File

@@ -184,6 +184,11 @@ void reboot()
while(1);
}
uint32_t ms_since_boot()
{
return to_ms_since_boot(get_absolute_time());
}
void init_board()
{
if (inited_)

View File

@@ -13,6 +13,8 @@ namespace board_api
bool uart_bridge_mode();
void reset_esp32();
void enter_esp32_prog_mode();
uint32_t ms_since_boot();
}
#endif // _OGXM_BOARD_API_H_

View File

@@ -33,7 +33,7 @@ namespace DInput
static constexpr uint8_t START = 0x02;
static constexpr uint8_t L3 = 0x04;
static constexpr uint8_t R3 = 0x08;
static constexpr uint8_t PS = 0x10;
static constexpr uint8_t SYS = 0x10;
static constexpr uint8_t TP = 0x20;
};

View File

@@ -3,7 +3,7 @@
#include <stdint.h>
#include <cstring>
#include <pico/rand.h>
#include <random>
#include "tusb.h"
@@ -75,7 +75,7 @@ namespace PS3
namespace Buttons2
{
static constexpr uint8_t PS = 0x01;
static constexpr uint8_t SYS = 0x01;
static constexpr uint8_t TP = 0x02;
};
@@ -203,13 +203,18 @@ namespace PS3
{
std::memset(this, 0, sizeof(BTInfo));
std::memcpy(device_address, DEFAULT_BT_INFO_HEADER, sizeof(DEFAULT_BT_INFO_HEADER));
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<uint8_t> dist(0, 0xFF);
for (uint8_t addr = 0; addr < 3; addr++)
{
device_address[4 + addr] = static_cast<uint8_t>(get_rand_32() % 0xff);
device_address[4 + addr] = dist(gen);
}
for (uint8_t addr = 0; addr < 6; addr++)
{
host_address[1 + addr] = static_cast<uint8_t>(get_rand_32() % 0xff);
host_address[1 + addr] = dist(gen);
}
}
};

View File

@@ -447,42 +447,6 @@ namespace XboxOG
static constexpr uint16_t DRIVER_LEN = 9+7+9;
// enum xboxog_xremote_xid_interface
// {
// ITF_NUM_XID_XREMOTE = 0,
// ITF_NUM_XID_XREMOTE_ROM,
// XID_REMOTE_ITF_NUM_TOTAL
// };
// #define TUD_XID_XREMOTE_DESC_LEN (9+7+9)
// #define TUD_XID_XREMOTE_DESCRIPTOR(_itfnum, _epin) \
// /* Interface 0 (HID DATA)*/\
// 9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, XID_REMOTE_INTERFACE_CLASS, XID_REMOTE_INTERFACE_SUBCLASS, 0x00, 0x00,\
// /* Endpoint In */\
// 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(8), 16, \
// /* Interface 1 (ROM DATA)*/\
// 9, TUSB_DESC_INTERFACE, _itfnum + 1, 0, 0, XID_XREMOTE_ROM_CLASS, 0x00, 0x00, 0x00
// #define XID_REMOTE_CONFIG_TOTAL_LEN \
// (TUD_CONFIG_DESC_LEN) + \
// (TUD_XID_XREMOTE_DESC_LEN)
// static const uint8_t CONFIGURATION_DESCRIPTORS[] =
// {
// // Config number, interface count, string index, total length, attribute, power in mA
// TUD_CONFIG_DESCRIPTOR( 1,
// XID_REMOTE_ITF_NUM_TOTAL,
// 0,
// XID_REMOTE_CONFIG_TOTAL_LEN,
// TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
// 500),
// TUD_XID_XREMOTE_DESCRIPTOR( ITF_NUM_XID_XREMOTE,
// 0x80 | (ITF_NUM_XID_XREMOTE + 1)),
// };
static const uint8_t DEVICE_DESCRIPTORS[] =
{
0x12, // bLength

View File

@@ -92,7 +92,7 @@ void DInputDevice::process(const uint8_t idx, Gamepad& gamepad)
if (gp_in.buttons & Gamepad::BUTTON_R3) in_report.buttons[1] |= DInput::Buttons1::R3;
if (gp_in.buttons & Gamepad::BUTTON_BACK) in_report.buttons[1] |= DInput::Buttons1::SELECT;
if (gp_in.buttons & Gamepad::BUTTON_START) in_report.buttons[1] |= DInput::Buttons1::START;
if (gp_in.buttons & Gamepad::BUTTON_SYS) in_report.buttons[1] |= DInput::Buttons1::PS;
if (gp_in.buttons & Gamepad::BUTTON_SYS) in_report.buttons[1] |= DInput::Buttons1::SYS;
if (gp_in.buttons & Gamepad::BUTTON_MISC) in_report.buttons[1] |= DInput::Buttons1::TP;
if (gamepad.analog_enabled())

View File

@@ -65,7 +65,7 @@ void PS3Device::process(const uint8_t idx, Gamepad& gamepad)
if (gp_in.buttons & Gamepad::BUTTON_START) report_in_.buttons[0] |= PS3::Buttons0::START;
if (gp_in.buttons & Gamepad::BUTTON_L3) report_in_.buttons[0] |= PS3::Buttons0::L3;
if (gp_in.buttons & Gamepad::BUTTON_R3) report_in_.buttons[0] |= PS3::Buttons0::R3;
if (gp_in.buttons & Gamepad::BUTTON_SYS) report_in_.buttons[2] |= PS3::Buttons2::PS;
if (gp_in.buttons & Gamepad::BUTTON_SYS) report_in_.buttons[2] |= PS3::Buttons2::SYS;
if (gp_in.buttons & Gamepad::BUTTON_MISC) report_in_.buttons[2] |= PS3::Buttons2::TP;
if (gp_in.trigger_l) report_in_.buttons[1] |= PS3::Buttons1::L2;

View File

@@ -1,7 +1,6 @@
#include <cstring>
#include <vector>
#include "pico/stdlib.h"
#include "Board/board_api.h"
#include "USBDevice/DeviceDriver/XboxOG/tud_xid/tud_xid.h"
#include "USBDevice/DeviceDriver/XboxOG/XboxOG_XR.h"
@@ -21,7 +20,7 @@ void XboxOGXRDevice::process(const uint8_t idx, Gamepad& gamepad)
return;
}
uint32_t time_elapsed = to_ms_since_boot(get_absolute_time()) - ms_timer_;
uint32_t time_elapsed = board_api::ms_since_boot() - ms_timer_;
uint8_t index = tud_xid::get_index_by_type(0, tud_xid::Type::XREMOTE);
if (index == 0xFF || !gamepad.new_pad_in() || time_elapsed < 64)
@@ -72,7 +71,7 @@ void XboxOGXRDevice::process(const uint8_t idx, Gamepad& gamepad)
if (tud_xid::send_report_ready(index) &&
tud_xid::send_report(index, reinterpret_cast<uint8_t*>(&in_report_), sizeof(XboxOG::XR::InReport)))
{
ms_timer_ = to_ms_since_boot(get_absolute_time());
ms_timer_ = board_api::ms_since_boot();
}
}

View File

@@ -62,7 +62,7 @@ void DInputHost::process_report(Gamepad& gamepad, uint8_t address, uint8_t insta
if (in_report->buttons[1] & DInput::Buttons1::R3) gp_in.buttons |= gamepad.MAP_BUTTON_R3;
if (in_report->buttons[1] & DInput::Buttons1::SELECT) gp_in.buttons |= gamepad.MAP_BUTTON_BACK;
if (in_report->buttons[1] & DInput::Buttons1::START) gp_in.buttons |= gamepad.MAP_BUTTON_START;
if (in_report->buttons[1] & DInput::Buttons1::PS) gp_in.buttons |= gamepad.MAP_BUTTON_SYS;
if (in_report->buttons[1] & DInput::Buttons1::SYS) gp_in.buttons |= gamepad.MAP_BUTTON_SYS;
if (in_report->buttons[1] & DInput::Buttons1::TP) gp_in.buttons |= gamepad.MAP_BUTTON_MISC;
if (gamepad.analog_enabled())

View File

@@ -121,7 +121,7 @@ void PS3Host::process_report(Gamepad& gamepad, uint8_t address, uint8_t instance
if (in_report->buttons[1] & PS3::Buttons1::CIRCLE) gp_in.buttons |= gamepad.MAP_BUTTON_B;
if (in_report->buttons[1] & PS3::Buttons1::CROSS) gp_in.buttons |= gamepad.MAP_BUTTON_A;
if (in_report->buttons[1] & PS3::Buttons1::SQUARE) gp_in.buttons |= gamepad.MAP_BUTTON_X;
if (in_report->buttons[2] & PS3::Buttons2::PS) gp_in.buttons |= gamepad.MAP_BUTTON_SYS;
if (in_report->buttons[2] & PS3::Buttons2::SYS) gp_in.buttons |= gamepad.MAP_BUTTON_SYS;
if (gamepad.analog_enabled())
{