Handle control requests for Dualshock 3

This commit is contained in:
Marc Riera Irigoyen 2023-05-22 18:30:11 +02:00
parent c6013f2b74
commit 1f84543091
2 changed files with 47 additions and 3 deletions

View file

@ -177,7 +177,13 @@ pub fn handle_ctrl_transfer(model: ControllerModel, data: &[u8]) {
None => (),
}
}
else if data[1] == 9 {
else {
match model {
ControllerModel::SLPH00051 => {
slph00051::handle_ctrl_transfer(data);
}
_ => ()
}
}
}

View file

@ -2,7 +2,7 @@ use std::fs::File;
use std::io::{Write};
use bitflags::bitflags;
use crate::controller::physical::ControllerState;
use crate::controller::emulated::{DeviceDescriptor, ENDPOINT1};
use crate::controller::emulated::{DeviceDescriptor, ENDPOINT0, ENDPOINT1};
pub const DESCRIPTORS: [u8; 80] = [0x01, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x09, 0x04, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00,
@ -98,6 +98,16 @@ pub const HID_REPORT_DESCRIPTOR: [u8; 148] = [
0xC0, // End Collection
];
const F2_REPORT: [u8; 64] = [0xF2, 0xFF, 0xFF, 0x0, 0x0, 0x6, 0xF5, 0x48, 0xE2, 0x49, 0x0, 0x3, 0x50, 0x81, 0xD8, 0x1,
0x8A, 0x13, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x2, 0x2, 0x2, 0x2, 0x0, 0x0, 0x0, 0x4,
0x4, 0x4, 0x4, 0x0, 0x0, 0x4, 0x0, 0x1, 0x2, 0x7, 0x0, 0x17, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0];
const F5_REPORT: [u8; 64] = [0x1, 0x0, 0x0, 0x23, 0x6, 0x7C, 0xB9, 0xB, 0xE2, 0x49, 0x0, 0x3, 0x50, 0x81, 0xD8, 0x1,
0x8A, 0x13, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x2, 0x2, 0x2, 0x2, 0x0, 0x0, 0x0, 0x4,
0x4, 0x4, 0x4, 0x0, 0x0, 0x4, 0x0, 0x1, 0x2, 0x7, 0x0, 0x17, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0];
bitflags! {
struct Buttons1: u8 {
const NONE = 0;
@ -188,11 +198,39 @@ pub fn update_gadget(state: &mut ControllerState) {
if state.button_start { buttons1.insert(Buttons1::START) }
if state.button_select { buttons1.insert(Buttons1::SELECT) }
let btn_up = if buttons1.contains(Buttons1::UP) {0xFF} else {0x0};
let btn_right = if buttons1.contains(Buttons1::RIGHT) {0xFF} else {0x0};
let btn_down = if buttons1.contains(Buttons1::DOWN) {0xFF} else {0x0};
let btn_left = if buttons1.contains(Buttons1::LEFT) {0xFF} else {0x0};
let btn_l2 = if buttons2.contains(Buttons2::L2) {0xFF} else {0x0};
let btn_r2 = if buttons2.contains(Buttons2::R2) {0xFF} else {0x0};
let btn_l1 = if buttons2.contains(Buttons2::L1) {0xFF} else {0x0};
let btn_r1 = if buttons2.contains(Buttons2::R1) {0xFF} else {0x0};
let btn_triangle = if buttons2.contains(Buttons2::TRIANGLE) {0xFF} else {0x0};
let btn_circle = if buttons2.contains(Buttons2::CIRCLE) {0xFF} else {0x0};
let btn_cross = if buttons2.contains(Buttons2::CROSS) {0xFF} else {0x0};
let btn_square = if buttons2.contains(Buttons2::SQUARE) {0xFF} else {0x0};
// Assemble data and send it to gadget
let data = [0x1, 0x0, buttons1.bits, buttons2.bits, 0x0, 0x0, 0x80, 0x80, 0x80, 0x80,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, btn_up, btn_right, btn_down, btn_left, btn_l2, btn_r2, btn_l1, btn_r1, btn_triangle, btn_circle, btn_cross, btn_square, 0x0, 0x0, 0x0,
0x3, 0xEF, 0x14, 0x0, 0x0, 0x0, 0x0, 0x23, 0x1A, 0x77, 0x1, 0x81, 0x1, 0xFE, 0x1, 0xFE, 0x1, 0xFE, 0x1, 0xFE];
if let Ok(mut file) = File::create(ENDPOINT1) {
file.write(&data).ok();
}
}
pub fn handle_ctrl_transfer(data: &[u8]) {
if data[1] == 1 && data[2] == 0xF2 {
// Init 1
if let Ok(mut file) = File::create(ENDPOINT0) {
file.write(&F2_REPORT).unwrap();
}
}
else if data[1] == 1 && data[2] == 0xF5 {
// Init 2
if let Ok(mut file) = File::create(ENDPOINT0) {
file.write(&F5_REPORT).unwrap();
}
}
}