-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fd65d4
commit 874e632
Showing
7 changed files
with
976 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,247 @@ | ||
use packed_struct::{prelude::*, types::SizedInteger, PackedStruct}; | ||
use packed_struct::prelude::*; | ||
|
||
use super::driver::*; | ||
|
||
pub trait PackedInputDataReport: PackedStruct + Copy + Clone + PartialEq | ||
{ | ||
fn new() -> Self; | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum PackedInputDataReport { | ||
Usb(USBPackedInputDataReport), | ||
Bluetooth(BluetoothPackedInputDataReport), | ||
} | ||
|
||
fn set_frame_number(&mut self, num: u8); | ||
} | ||
impl PackedInputDataReport { | ||
pub fn set_frame_number(&mut self, num: u8) { | ||
match self { | ||
PackedInputDataReport::Usb(_) => (), | ||
PackedInputDataReport::Bluetooth(_) => (), | ||
} | ||
} | ||
} | ||
|
||
// https://github.com/nondebug/dualsense | ||
#[derive(PackedStruct, Debug, Copy, Clone, PartialEq)] | ||
#[packed_struct(bit_numbering = "msb0", size_bytes = "64")] | ||
pub struct USBPackedInputDataReport { | ||
// byte 0 | ||
#[packed_field(bytes = "0")] | ||
pub input_report: u8, | ||
pub report_id: u8, // Report ID (always 0x01) | ||
|
||
// byte 1-7 | ||
#[packed_field(bytes = "1")] | ||
pub joystick_l_x: u8, | ||
pub joystick_l_x: u8, // left stick X axis | ||
#[packed_field(bytes = "2")] | ||
pub joystick_l_y: u8, | ||
pub joystick_l_y: u8, // left stick Y axis | ||
#[packed_field(bytes = "3")] | ||
pub joystick_r_x: u8, | ||
pub joystick_r_x: u8, // right stick X axis | ||
#[packed_field(bytes = "4")] | ||
pub joystick_r_y: u8, | ||
pub joystick_r_y: u8, // right stick Y axis | ||
#[packed_field(bytes = "5")] | ||
pub l2_trigger: u8, // L2 trigger axis | ||
#[packed_field(bytes = "6")] | ||
pub r2_trigger: u8, // R2 trigger axis | ||
#[packed_field(bytes = "7")] | ||
pub _vendor_defined_0: u8, // Vendor defined | ||
|
||
// byte 8 | ||
#[packed_field(bits = "64")] | ||
pub down: bool, // Directional buttons | ||
#[packed_field(bits = "65")] | ||
pub left: bool, | ||
#[packed_field(bits = "66")] | ||
pub right: bool, | ||
#[packed_field(bits = "67")] | ||
pub up: bool, | ||
#[packed_field(bits = "68")] | ||
pub square: bool, // Button cluster, x, ◯, □, ∆ | ||
#[packed_field(bits = "69")] | ||
pub cross: bool, | ||
#[packed_field(bits = "70")] | ||
pub circle: bool, | ||
#[packed_field(bits = "71")] | ||
pub triangle: bool, | ||
|
||
// byte 9 | ||
#[packed_field(bits = "72")] | ||
pub l1: bool, // Triggers | ||
#[packed_field(bits = "73")] | ||
pub r1: bool, | ||
#[packed_field(bits = "74")] | ||
pub l2: bool, | ||
#[packed_field(bits = "75")] | ||
pub r2: bool, | ||
#[packed_field(bits = "76")] | ||
pub create: bool, // Create button ⚟ | ||
#[packed_field(bits = "77")] | ||
pub options: bool, // Options button ☰ | ||
#[packed_field(bits = "78")] | ||
pub l3: bool, | ||
#[packed_field(bits = "79")] | ||
pub r3: bool, | ||
|
||
// byte 10 | ||
#[packed_field(bits = "80")] | ||
pub ps: bool, // PS button | ||
#[packed_field(bits = "81")] | ||
pub touchpad: bool, // Touchpad button | ||
#[packed_field(bits = "82")] | ||
pub mute: bool, // Mute button 🔇 | ||
#[packed_field(bits = "83..=95")] | ||
pub _vendor_defined_1: [u8; 13], | ||
|
||
// byte 12-64 | ||
#[packed_field(bytes = "12..=64")] | ||
pub _vendor_defined_2: [u8; 52], | ||
} | ||
|
||
impl PackedInputDataReport for USBPackedInputDataReport { | ||
impl USBPackedInputDataReport { | ||
/// Return a new empty input data report | ||
fn new() -> Self { | ||
pub fn new() -> Self { | ||
Self { | ||
input_report: INPUT_REPORT_USB, | ||
joystick_l_x : 127, | ||
joystick_l_y : 127, | ||
joystick_r_x : 127, | ||
joystick_r_y : 127, | ||
report_id: INPUT_REPORT_USB, | ||
joystick_l_x: 127, | ||
joystick_l_y: 127, | ||
joystick_r_x: 127, | ||
joystick_r_y: 127, | ||
l2_trigger: 0, | ||
r2_trigger: 0, | ||
_vendor_defined_0: 0, | ||
down: false, | ||
left: false, | ||
right: false, | ||
up: false, | ||
square: false, | ||
cross: false, | ||
circle: false, | ||
triangle: false, | ||
l1: false, | ||
r1: false, | ||
l2: false, | ||
r2: false, | ||
create: false, | ||
options: false, | ||
l3: false, | ||
r3: false, | ||
ps: false, | ||
touchpad: false, | ||
mute: false, | ||
_vendor_defined_1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | ||
_vendor_defined_2: [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
], | ||
} | ||
} | ||
} | ||
|
||
impl Default for USBPackedInputDataReport { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
fn set_frame_number(&mut self, num: u8) { | ||
#[derive(PackedStruct, Debug, Copy, Clone, PartialEq)] | ||
#[packed_struct(bit_numbering = "msb0", size_bytes = "10")] | ||
pub struct BluetoothPackedInputDataReport { | ||
// byte 0 | ||
#[packed_field(bytes = "0")] | ||
pub report_id: u8, // Report ID (always 0x01) | ||
|
||
// byte 1-4 | ||
#[packed_field(bytes = "1")] | ||
pub joystick_l_x: u8, // left stick X axis | ||
#[packed_field(bytes = "2")] | ||
pub joystick_l_y: u8, // left stick Y axis | ||
#[packed_field(bytes = "3")] | ||
pub joystick_r_x: u8, // right stick X axis | ||
#[packed_field(bytes = "4")] | ||
pub joystick_r_y: u8, // right stick Y axis | ||
|
||
// byte 5 | ||
#[packed_field(bits = "40")] | ||
pub down: bool, // Directional buttons | ||
#[packed_field(bits = "41")] | ||
pub left: bool, | ||
#[packed_field(bits = "42")] | ||
pub right: bool, | ||
#[packed_field(bits = "43")] | ||
pub up: bool, | ||
#[packed_field(bits = "44")] | ||
pub square: bool, // Button cluster, x, ◯, □, ∆ | ||
#[packed_field(bits = "45")] | ||
pub cross: bool, | ||
#[packed_field(bits = "46")] | ||
pub circle: bool, | ||
#[packed_field(bits = "47")] | ||
pub triangle: bool, | ||
|
||
// byte 6 | ||
#[packed_field(bits = "48")] | ||
pub l1: bool, // Triggers | ||
#[packed_field(bits = "49")] | ||
pub r1: bool, | ||
#[packed_field(bits = "50")] | ||
pub l2: bool, | ||
#[packed_field(bits = "51")] | ||
pub r2: bool, | ||
#[packed_field(bits = "52")] | ||
pub create: bool, // Create button ⚟ | ||
#[packed_field(bits = "53")] | ||
pub options: bool, // Options button ☰ | ||
#[packed_field(bits = "54")] | ||
pub l3: bool, | ||
#[packed_field(bits = "55")] | ||
pub r3: bool, | ||
|
||
// byte 7 | ||
#[packed_field(bits = "56")] | ||
pub ps: bool, // PS button | ||
#[packed_field(bits = "57")] | ||
pub touchpad: bool, // Touchpad button | ||
#[packed_field(bits = "58..=63")] | ||
pub _vendor_defined_0: [u8; 6], | ||
|
||
// byte 8-9 | ||
#[packed_field(bytes = "8")] | ||
pub l2_trigger: u8, // L2 trigger axis | ||
#[packed_field(bytes = "9")] | ||
pub r2_trigger: u8, // R2 trigger axis | ||
} | ||
|
||
impl BluetoothPackedInputDataReport { | ||
/// Return a new empty input data report | ||
pub fn new() -> Self { | ||
Self { | ||
report_id: INPUT_REPORT_BT, | ||
joystick_l_x: 127, | ||
joystick_l_y: 127, | ||
joystick_r_x: 127, | ||
joystick_r_y: 127, | ||
l2_trigger: 0, | ||
r2_trigger: 0, | ||
_vendor_defined_0: [0, 0, 0, 0, 0, 0], | ||
down: false, | ||
left: false, | ||
right: false, | ||
up: false, | ||
square: false, | ||
cross: false, | ||
circle: false, | ||
triangle: false, | ||
l1: false, | ||
r1: false, | ||
l2: false, | ||
r2: false, | ||
create: false, | ||
options: false, | ||
l3: false, | ||
r3: false, | ||
ps: false, | ||
touchpad: false, | ||
} | ||
} | ||
} | ||
|
||
impl Default for USBPackedInputDataReport { | ||
impl Default for BluetoothPackedInputDataReport { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod bmi_imu; | ||
pub mod dualsense; | ||
pub mod lego; | ||
pub mod steam_deck; | ||
pub mod dualsense; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.