Skip to content

Commit

Permalink
Xbox One Multiplayer Fix & Auth Bug Fix (OpenStickCommunity#1264)
Browse files Browse the repository at this point in the history
* Testing Xbox One randomization for serial ID

* Moving USB host start to before we run in gp2040. Added a 0.1s sleep to slowing down the CPU, fixes issues with tinyusb sync'ing

* Missed this, important to not start it twice

* Moving the order so tinyusb host boots up first?

* Reverted usb host start to core1

* This might be the issue, the variable is undefined when gp2040 input driver runs a process() and xbone has not been opened yet.

* We have to send descriptor on LED request for player 2

* Moved from enums.js to enums.ts
  • Loading branch information
arntsonl authored Feb 17, 2025
1 parent 03fc5cc commit f01feca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ env.ini
.devcontainer
*Dockerfile
*docker-compose.yml
/www/src_gen/enums.js
www/src_gen/enums.ts
4 changes: 3 additions & 1 deletion headers/drivers/xbone/XBOneDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ static const uint8_t * xbone_get_string_descriptor(int index) {
// Generate a serial number from the pico's unique ID
pico_unique_board_id_t id;
pico_get_unique_board_id(&id);
memcpy(uniqueSerial, (uint8_t*)&id, PICO_UNIQUE_BOARD_ID_SIZE_BYTES);
for(int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++) {
uniqueSerial[i] = 'A' + (id.id[i]%25); // some alphanumeric from 'A' to 'Z'
}
return uniqueSerial;
} else if ( index == 4 ) { // security method used
return xboxSecurityMethod;
Expand Down
14 changes: 12 additions & 2 deletions src/drivers/xbone/XBOneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ typedef enum {
WAIT_DESCRIPTOR_REQUEST,
SEND_DESCRIPTOR,
SETUP_AUTH,
AUTH_DONE
AUTH_DONE,
NOT_READY
} XboxOneDriverState;

static XboxOneDriverState xboneDriverState;
static XboxOneDriverState xboneDriverState = NOT_READY;

static uint8_t xb1_guide_on[] = { 0x01, 0x5b };
static uint8_t xb1_guide_off[] = { 0x00, 0x5b };
Expand Down Expand Up @@ -282,6 +283,14 @@ bool xbone_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result,
// Set all player LEDs to on
report_led_mode = incomingXGIP->getData()[1]; // 1 - turn LEDs on
report_led_brightness = incomingXGIP->getData()[2]; // 2 - brightness (ignored for now)

// Send our descriptor if descriptor is waiting (Player 2)
if ( xboneDriverState == XboxOneDriverState::WAIT_DESCRIPTOR_REQUEST ) {
outgoingXGIP->reset(); // reset if anything was in there
outgoingXGIP->setAttributes(GIP_DEVICE_DESCRIPTOR, incomingXGIP->getSequence(), 1, 1, 0);
outgoingXGIP->setData(xboxOneDescriptor, sizeof(xboxOneDescriptor));
xboneDriverState = XboxOneDriverState::SEND_DESCRIPTOR;
}
} else if ( command == GIP_CMD_RUMBLE ) {
// TO-DO
} else if ( command == GIP_AUTH || command == GIP_FINAL_AUTH) {
Expand Down Expand Up @@ -668,6 +677,7 @@ void XBOneDriver::update() {
}
break;
case AUTH_DONE:
case NOT_READY:
default:
break;
};
Expand Down
4 changes: 2 additions & 2 deletions src/gp2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ void GP2040::run() {
Gamepad * processedGamepad = Storage::getInstance().GetProcessedGamepad();
bool configMode = Storage::getInstance().GetConfigMode();
GamepadState prevState;

// Start the TinyUSB Device functionality
tud_init(TUD_OPT_RHPORT);

while (1) { // LOOP
this->getReinitGamepad(gamepad);

Expand Down

0 comments on commit f01feca

Please sign in to comment.