add USB interface as a setting for controller implementations

This commit is contained in:
beerpsi
2025-03-21 16:34:52 +07:00
parent 79cdee8e6a
commit 28fcd47be1
8 changed files with 38 additions and 32 deletions
+7 -7
View File
@@ -7,16 +7,16 @@ segatools.ini
```ini
[chuniio]
;; For Chunithm NEW or newer
path32=chuniio_xxx_chusan.dll
path64=chuniio_xxx_amdaemon.dll
path32=chuniio_xxx_x86.dll
path64=chuniio_xxx_x64.dll
;; For CHUNITHM PARADISE and older
path=chuniio_xxx.dll
[io3]
test=0x31
service=0x32
coin=0x33
test=0x70
service=0x71
coin=0x72
```
## Build instructions
@@ -24,7 +24,7 @@ Currently supported backends are:
- `tasoller_v1`
- `tasoller_v2`
- `laverita_v2`
- `laverita_v3`
- `laverita_v3` (contributed by [sr1canskhsia](https://gitea.tendokyu.moe/sr1canskhsia))
```shell
CONTROLLER="tasoller_v1" # replace with your preferred controller backend
@@ -38,4 +38,4 @@ cp target/x86_64-pc-windows-msvc/release/chuniio_rs.dll chuniio_${CONTROLLER}_am
# For CHUNITHM (SDBT)
cargo build --target i686-pc-windows-msvc --release --features $CONTROLLER
cp target/i686-pc-windows-msvc/release/chuniio_rs.dll chuniio_$CONTROLLER.dll
```
```
+1
View File
@@ -7,6 +7,7 @@ use super::ReadType;
pub const DEVICE_VID: u16 = 0x0000;
pub const DEVICE_PID: u16 = 0x0000;
pub const DEVICE_INTERFACE: u8 = 0;
pub const READ_TYPE: ReadType = ReadType::Interrupt;
pub const READ_ENDPOINT: u8 = 0x00;
pub const INPUT_MEMORY_SIZE: usize = 1;
+1
View File
@@ -51,6 +51,7 @@ use super::ReadType;
pub const DEVICE_VID: u16 = 0x1973;
pub const DEVICE_PID: u16 = 0x2001;
pub const DEVICE_INTERFACE: u8 = 0;
pub const READ_TYPE: ReadType = ReadType::Interrupt;
pub const READ_ENDPOINT: u8 = 0x81;
pub const INPUT_MEMORY_SIZE: usize = 35;
+7 -7
View File
@@ -35,6 +35,7 @@ use super::ReadType;
pub const DEVICE_VID: u16 = 0x0518;
pub const DEVICE_PID: u16 = 0x2022;
pub const DEVICE_INTERFACE: u8 = 3;
pub const READ_TYPE: ReadType = ReadType::Interrupt;
pub const READ_ENDPOINT: u8 = 0x83;
pub const INPUT_MEMORY_SIZE: usize = 34;
@@ -91,12 +92,8 @@ pub fn is_coin_button_pressed(_input: &[u8]) -> bool {
pub fn read_pressure_data(input: &[u8]) -> [u8; 32] {
let mut pressure = [0u8; 32];
for i in (0..32).step_by(2) {
pressure[i] = input[32 - i];
}
for i in (1..32).step_by(2) {
pressure[i] = input[34 - i];
for (i, p) in input[2..34].iter().enumerate() {
pressure[if i % 2 == 0 { 30 - i } else { 32 - i }] = *p;
}
pressure
@@ -129,7 +126,10 @@ pub fn set_slider_leds<T: UsbContext>(
output_chunk[2] = brg_chunk[0]; // B
}
for (output_chunk, brg_chunk) in output[62..95].chunks_mut(3).zip(brg.chunks(3).skip(20).take(11)) {
for (output_chunk, brg_chunk) in output[62..95]
.chunks_mut(3)
.zip(brg.chunks(3).skip(20).take(11))
{
output_chunk[0] = brg_chunk[1]; // R
output_chunk[1] = brg_chunk[2]; // G
output_chunk[2] = brg_chunk[0]; // B
+2 -1
View File
@@ -32,6 +32,7 @@ use crate::TIMEOUT;
pub const DEVICE_VID: u16 = 0x0E8F;
pub const DEVICE_PID: u16 = 0x1231;
pub const DEVICE_INTERFACE: u8 = 0;
pub const READ_TYPE: ReadType = ReadType::Interrupt;
pub const READ_ENDPOINT: u8 = 0x84;
pub const INPUT_MEMORY_SIZE: usize = 36;
@@ -146,7 +147,7 @@ pub fn set_led_colors<T: UsbContext>(
rgb: &[u8],
) -> Result<()> {
if board > 1 {
return Ok(())
return Ok(());
}
let output_start = if board == 0 { 0x60 } else { 0x69 };
+1
View File
@@ -46,6 +46,7 @@ use crate::TIMEOUT;
pub const DEVICE_VID: u16 = 0x1CCF;
pub const DEVICE_PID: u16 = 0x2333;
pub const DEVICE_INTERFACE: u8 = 0;
pub const READ_TYPE: ReadType = ReadType::Interrupt;
pub const READ_ENDPOINT: u8 = 0x84;
pub const INPUT_MEMORY_SIZE: usize = 11;
+1
View File
@@ -31,6 +31,7 @@ use crate::TIMEOUT;
pub const DEVICE_VID: u16 = 0x1CCF;
pub const DEVICE_PID: u16 = 0x2333;
pub const DEVICE_INTERFACE: u8 = 0;
pub const READ_TYPE: ReadType = ReadType::Interrupt;
pub const READ_ENDPOINT: u8 = 0x84;
pub const INPUT_MEMORY_SIZE: usize = 36;
+18 -17
View File
@@ -24,7 +24,14 @@ use winapi::{
minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
winerror::{E_FAIL, S_OK},
},
um::{winbase::SetThreadExecutionState, winnt::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH, ES_CONTINUOUS, ES_DISPLAY_REQUIRED, ES_SYSTEM_REQUIRED, HRESULT}},
um::{
winbase::SetThreadExecutionState,
winnt::{
DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH, ES_CONTINUOUS, ES_DISPLAY_REQUIRED,
ES_SYSTEM_REQUIRED, HRESULT,
},
winuser::{VK_F1, VK_F2, VK_F3},
},
};
use crate::log::init_logger;
@@ -88,19 +95,19 @@ cfg_if::cfg_if! {
test_key: GetPrivateProfileIntA(
io3.as_ptr(),
test.as_ptr(),
0x31,
VK_F1,
cfg_file.as_ptr(),
),
service_key: GetPrivateProfileIntA(
io3.as_ptr(),
service.as_ptr(),
0x32,
VK_F2,
cfg_file.as_ptr(),
),
coin_key: GetPrivateProfileIntA(
io3.as_ptr(),
coin.as_ptr(),
0x33,
VK_F3,
cfg_file.as_ptr(),
),
}
@@ -120,11 +127,13 @@ extern "system" fn DllMain(_dll_module: HINSTANCE, call_reason: DWORD, _reserved
match call_reason {
DLL_PROCESS_ATTACH => {
init_logger();
unsafe { SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED); }
}
DLL_PROCESS_DETACH => {
unsafe { SetThreadExecutionState(ES_CONTINUOUS); }
unsafe {
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
}
}
DLL_PROCESS_DETACH => unsafe {
SetThreadExecutionState(ES_CONTINUOUS);
},
_ => {}
}
@@ -361,15 +370,7 @@ fn device_init() -> Result<()> {
};
device.set_active_configuration(1)?;
// A bit janky but Laverita v3 seems to require interface 3
cfg_if::cfg_if! {
if #[cfg(feature = "laverita_v3")] {
device.claim_interface(3)?;
} else {
device.claim_interface(0)?;
}
}
device.claim_interface(con_impl::DEVICE_INTERFACE)?;
let mut global_device = DEVICE.write();
*global_device = Some(device);