fix laverita v2 support

This commit is contained in:
beerpsi
2025-07-25 08:40:44 +07:00
parent f14f3e2950
commit 6091c72776
4 changed files with 31 additions and 48 deletions
+2
View File
@@ -0,0 +1,2 @@
[build]
target = "x86_64-pc-windows-msvc"
+2 -1
View File
@@ -1,2 +1,3 @@
/target
/dist
/dist
.xwin-cache
Regular → Executable
+12 -4
View File
@@ -3,14 +3,22 @@
mkdir -p dist/chusan
mkdir -p dist/chuni
PLATFORM="$(uname -s)"
if [ "${PLATFORM:0:5}" != "MINGW" ]; then
CARGO="cargo xwin"
else
CARGO="cargo"
fi
for backend in tasoller_v1 tasoller_v2 laverita_v2 laverita_v3 tasoller_plus
do
cargo build --target i686-pc-windows-msvc --release --features chusan,$backend
cargo build --target x86_64-pc-windows-msvc --release --features chusan,$backend
$CARGO build --target i686-pc-windows-msvc --release --features chusan,$backend
$CARGO build --target x86_64-pc-windows-msvc --release --features chusan,$backend
cp target/i686-pc-windows-msvc/release/chuniio_rs.dll dist/chusan/chuniio_${backend}_x86.dll
cp target/x86_64-pc-windows-msvc/release/chuniio_rs.dll dist/chusan/chuniio_${backend}_x64.dll
cargo build --target i686-pc-windows-msvc --release --features $backend
$CARGO build --target i686-pc-windows-msvc --release --features $backend
cp target/i686-pc-windows-msvc/release/chuniio_rs.dll dist/chuni/chuniio_${backend}.dll
done
+15 -43
View File
@@ -1,25 +1,6 @@
//! # Yuancon Laverita v2
//! (does anyone still use this?)
//!
//! Notes: I'm getting conflicting information on the protocol.
//! CrazyRedMachine is claiming that there is [a leading byte][1], while 4yn's
//! [slidershim][2] as well as their earlier [Yuancon HID test script][3] is
//! claiming the opposite. This implementation is based on CrazyRedMachine,
//! since the chuniio open-sourced by ZhouSensor himself seems to agree.
//!
//!
//! ```c
//! struct outputdata_gaosan
//! {
//! unsigned char Address;
//! unsigned char Touch[62];
//! }OutputDataGaosan;
//! ```
//!
//! [1]: https://github.com/CrazyRedMachine/yuancon_laverita_v2-docs/blob/main/pcb_protocol/hid_reports.txt
//! [2]: https://github.com/4yn/slidershim/blob/main/src-slider_io/src/device/hid.rs#L174-L207
//! [3]: https://gist.github.com/4yn/53a6b6b681e40fd5658bf5b7f9fe9c15
//!
//! USB device: 1973:2001
//!
//! USB interface: 0
@@ -27,19 +8,17 @@
//! ## Protocol information
//!
//! ### IN Interrupt (0x81)
//! - Content length: 35 bytes
//! - Byte 0: ReportID 0x00
//! - Byte 1: Air sensors, from lowest to highest bit {2, 1, 4, 3, 6, 5}
//! - Byte 2:
//! - Content length: 34 bytes
//! - Byte 0: Air sensors, from lowest to highest bit {2, 1, 4, 3, 6, 5}
//! - Byte 1:
//! - Bit 0: Test
//! - Bit 1: Service
//! - Bit 2: Coin
//! - Bytes 3..35: Slider pressure (bottom -> top, then left -> right)
//! - Bytes 2..34: Slider pressure (bottom -> top, then left -> right)
//!
//! ### OUT Interrupt (0x02)
//! - Content length: 63 bytes
//! - Byte 0: ReportID 0x00
//! - Byte 1..63: Slider LED data (right -> left)
//! - Content length: 62 bytes
//! - Byte 0..62: Slider LED data (right -> left)
//! - Each LED is controlled by 2 bytes: GGGG GRRR (second byte) | RRRB BBBB (first byte)
#[cfg(any(chuni, chusanapp))]
@@ -47,8 +26,8 @@ use anyhow::Result;
#[cfg(any(chuni, chusanapp))]
use rusb::{DeviceHandle, UsbContext};
use crate::TIMEOUT;
use super::ReadType;
use crate::TIMEOUT;
pub const DEVICE_VID: u16 = 0x1973;
pub const DEVICE_PID: u16 = 0x2001;
@@ -60,7 +39,6 @@ pub const OUTPUT_MEMORY_SIZE: usize = std::mem::size_of::<LaveritaV2Output>();
#[repr(C)]
struct LaveritaV2Input {
pub report_id: u8,
pub ir: u8,
pub buttons: u8,
pub slider_pressure: [u8; 32],
@@ -68,7 +46,6 @@ struct LaveritaV2Input {
#[repr(C)]
struct LaveritaV2Output {
pub report_id: u8,
pub slider_led: [u8; 62],
}
@@ -111,7 +88,7 @@ pub fn is_coin_button_pressed(input: &[u8]) -> bool {
/// and going from top to bottom, right to left.
///
/// ```ignore
/// ^^ Towards screen ^^
/// ^^ Towards screen ^^
/// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
/// 30 | 28 | 26 | 24 | 22 | 20 | 18 | 16 | 14 | 12 | 10 | 8 | 6 | 4 | 2 | 0 |
/// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
@@ -135,13 +112,7 @@ pub fn read_pressure_data(input: &[u8]) -> [u8; 32] {
/// (e.g. set magic bytes).
#[cfg(any(chuni, chusanapp))]
#[inline(always)]
pub fn init_output_buffer(output: &mut [u8]) {
let output = output.as_mut_ptr() as *mut LaveritaV2Output;
unsafe {
(*output).report_id = 0;
}
}
pub fn init_output_buffer(_output: &mut [u8]) {}
/// Update the RGB lighting on the slider. A slice `rgb` is provided, alternating
/// between 16 touch pad pixels and 15 divider pixels, going from right to left.
@@ -155,16 +126,17 @@ pub fn set_slider_leds<T: UsbContext>(
unsafe {
let output = output.as_mut_ptr() as *mut LaveritaV2Output;
for (buf_chunk, state_chunk) in (*output).slider_led
for (buf_chunk, state_chunk) in (*output)
.slider_led
.chunks_mut(2)
.take(31)
.zip(brg.chunks(3))
.zip(brg.chunks(3))
{
buf_chunk[0] = (state_chunk[0] << 3 & 0xE0) | (state_chunk[2] >> 3);
buf_chunk[1] = (state_chunk[1] & 0xF8) | (state_chunk[0] >> 5);
buf_chunk[0] = (state_chunk[1] << 3 & 0xE0) | (state_chunk[0] >> 3);
buf_chunk[1] = (state_chunk[2] & 0xF8) | (state_chunk[1] >> 5);
}
}
device.write_interrupt(0x02, output, TIMEOUT)?;
Ok(())