Skip to content

Commit

Permalink
yubideck v3 firmware support
Browse files Browse the repository at this point in the history
  • Loading branch information
4yn committed Nov 17, 2022
1 parent 828f480 commit 3bd7ee8
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Software adapter for various Chunithm slider controllers with a built-in Brokeni

## Changelog

- v0.5.0
- Support for Yubideck 3.0 firmware
- v0.4.3
- Make Yubideck USB reports more flexible when reading data
- v0.4.2
Expand Down
5 changes: 5 additions & 0 deletions src-slider_io/src/device/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub enum HardwareSpec {
TasollerTwo,
Yuancon,
Yubideck,
YubideckThree,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -53,6 +54,10 @@ impl DeviceMode {
spec: HardwareSpec::Yubideck,
disable_air: v["disableAirStrings"].as_bool()?,
},
"yubideck-three" => DeviceMode::Hardware {
spec: HardwareSpec::YubideckThree,
disable_air: v["disableAirStrings"].as_bool()?,
},
"diva" => DeviceMode::DivaSlider {
port: v["divaSerialPort"].as_str()?.to_string(),
brightness: u8::try_from(v["divaBrightness"].as_i64()?).ok()?,
Expand Down
88 changes: 82 additions & 6 deletions src-slider_io/src/device/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
use super::config::HardwareSpec;

type HidReadCallback = fn(&Buffer, &mut SliderInput) -> ();
type HidLedCallback = fn(&mut Buffer, &SliderLights) -> ();
type HidLedCallback = fn(&mut Buffer, &mut Buffer, &SliderLights) -> ();

enum WriteType {
Bulk,
Expand All @@ -41,6 +41,7 @@ pub struct HidJob {
led_write_type: WriteType,
led_callback: HidLedCallback,
led_buf: Buffer,
led_buf_two: Buffer,

handle: Option<DeviceHandle<GlobalContext>>,
}
Expand Down Expand Up @@ -70,6 +71,7 @@ impl HidJob {
led_write_type: led_type,
led_callback,
led_buf: Buffer::new(),
led_buf_two: Buffer::new(),
handle: None,
}
}
Expand Down Expand Up @@ -102,7 +104,7 @@ impl HidJob {
input.extra[0..2].copy_from_slice(&bits[26..28]);
},
WriteType::Bulk,
|buf, lights| {
|buf, _, lights| {
buf.len = 240;
buf.data[0] = 'B' as u8;
buf.data[1] = 'L' as u8;
Expand Down Expand Up @@ -139,7 +141,7 @@ impl HidJob {
input.extra[0..2].copy_from_slice(&bits[6..8]);
},
WriteType::Bulk,
|buf, lights| {
|buf, _, lights| {
buf.len = 240;
buf.data[0] = 'B' as u8;
buf.data[1] = 'L' as u8;
Expand Down Expand Up @@ -190,7 +192,7 @@ impl HidJob {
}
},
WriteType::Interrupt,
|buf, lights| {
|buf, _, lights| {
buf.len = 31 * 2;
for (buf_chunk, state_chunk) in buf
.data
Expand Down Expand Up @@ -225,7 +227,7 @@ impl HidJob {
}
},
WriteType::Interrupt,
|buf, lights| {
|buf, _, lights| {
buf.len = 62;

let lights_nibbles: Vec<u8> = lights
Expand All @@ -252,6 +254,56 @@ impl HidJob {
}
},
),
HardwareSpec::YubideckThree => Self::new(
state.clone(),
0x1973,
0x2001,
0x81, // Need to confirm
0x02, // Need to confirm
*disable_air,
|buf, input| {
if buf.len != 45 && buf.len != 46 {
return;
}

input.ground.copy_from_slice(&buf.data[2..34]);
input.flip_vert();
for i in 0..6 {
input.air[i ^ 1] = (buf.data[0] >> i) & 1;
}
for i in 0..3 {
input.extra[2 - i] = (buf.data[1] >> i) & 1;
}
},
WriteType::Interrupt,
|buf, buf_two, lights| {
buf.len = 61;
buf.data[0] = 0;
buf_two.len = 61;
buf_two.data[0] = 1;

for (buf_chunk, state_chunk) in buf.data[1..61]
.chunks_mut(3)
.zip(lights.ground.chunks(3).skip(11).take(20).rev())
{
buf_chunk[0] = state_chunk[0];
buf_chunk[1] = state_chunk[1];
buf_chunk[2] = state_chunk[2];
}

for (buf_chunk, state_chunk) in buf_two.data[1..34]
.chunks_mut(3)
.zip(lights.ground.chunks(3).take(11).rev())
{
buf_chunk[0] = state_chunk[0];
buf_chunk[1] = state_chunk[1];
buf_chunk[2] = state_chunk[2];
}

buf_two.data[34..37].copy_from_slice(&lights.air_left[3..6]);
buf_two.data[37..40].copy_from_slice(&lights.air_right[3..6]);
},
),
}
}

Expand Down Expand Up @@ -327,7 +379,11 @@ impl ThreadJob for HidJob {
{
let mut lights_handle = self.state.lights.lock();
if lights_handle.dirty {
(self.led_callback)(&mut self.led_buf, lights_handle.deref());
(self.led_callback)(
&mut self.led_buf,
&mut self.led_buf_two,
lights_handle.deref(),
);
lights_handle.dirty = false;
}
}
Expand All @@ -349,6 +405,26 @@ impl ThreadJob for HidJob {
self.led_buf.len = 0;
}
}

if self.led_buf_two.len != 0 {
let res = (match self.led_write_type {
WriteType::Bulk => {
handle.write_bulk(self.led_endpoint, self.led_buf_two.slice(), TIMEOUT)
}
WriteType::Interrupt => {
handle.write_interrupt(self.led_endpoint, &self.led_buf_two.slice(), TIMEOUT)
}
})
.map_err(|e| {
// debug!("Device write error {}", e);
e
})
.unwrap_or(0);
if res == self.led_buf_two.len + 1 {
// work = true;
self.led_buf_two.len = 0;
}
}
}

work
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slidershim"
version = "0.4.3"
version = "0.5.0"
description = "slidershim"
authors = ["4yn"]
license = ""
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
___| (_) __| | ___ _ __ ___| |__ (_)_ __ ___
/ __| | |/ _` |/ _ \ '__/ __| '_ \| | '_ ` _ \
\__ \ | | (_| | __/ | \__ \ | | | | | | | | |
|___/_|_|\__,_|\___|_| |___/_| |_|_|_| |_| |_| v0.4.3
|___/_|_|\__,_|\___|_| |___/_| |_|_|_| |_| |_| v0.5.0
===============================================

https://github.com/4yn/slidershim

# Changelog

- v0.5.0
- Support for Yubideck 3.0 firmware
- v0.4.3
- Make Yubideck USB reports more flexible when reading data
- v0.4.2
Expand Down
8 changes: 5 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "slidershim",
"version": "0.4.3"
"version": "0.5.0"
},
"build": {
"distDir": "../public",
Expand All @@ -21,7 +21,9 @@
"icons/icon.icns",
"icons/icon.ico"
],
"resources": ["./README.txt"],
"resources": [
"./README.txt"
],
"externalBin": [],
"copyright": "© 4yn 2022",
"category": "DeveloperTool",
Expand Down Expand Up @@ -74,4 +76,4 @@
"iconAsTemplate": true
}
}
}
}
3 changes: 2 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
<option value="tasoller-one">GAMO2 Tasoller, 1.0 HID Firmware</option>
<option value="tasoller-two">GAMO2 Tasoller, 2.0 HID Firmware</option>
<option value="yuancon">Yuancon Laverita, HID Firmware</option>
<option value="yubideck">大四 / Yubideck, HID Firmware</option>
<option value="yubideck">大四 / Yubideck, HID Firmware 1.0</option>
<option value="yubideck-three">大四 / Yubideck, HID Firmware 3.0</option>
<option value="diva">Slider over Serial</option>
<option value="brokenithm">Brokenithm</option>
<option value="brokenithm-led">Brokenithm + Led</option>
Expand Down

0 comments on commit 3bd7ee8

Please sign in to comment.