initial commit

This commit is contained in:
Viv Lim 2022-08-26 20:30:00 -07:00
commit cedc2cd854
8 changed files with 260 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

60
Cargo.lock generated Normal file
View File

@ -0,0 +1,60 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "hidraw"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4493a7a098442b8090b814fdfa429596a592c3c61a20e88b658b37e8afab28e2"
dependencies = [
"hidraw-sys",
]
[[package]]
name = "hidraw-sys"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed025ec58e36ba4ef82d3daff8972a5cd60538e0cf96fbb8cdb96a9d06582cf0"
dependencies = [
"ioctl-macro",
"rustc_version",
]
[[package]]
name = "ioctl-macro"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a69813de0be04779a757d18246a463092be1f89a623ee81a2cc337e3b0729248"
dependencies = [
"rustc_version",
]
[[package]]
name = "libc"
version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711"
[[package]]
name = "steamdeck-keyb"
version = "0.1.0"
dependencies = [
"hidraw",
"libc",
]

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "steamdeck-keyb"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
#input = "0.7.1"
libc = "0.2"
hidraw = "0.0.1"

59
flake.lock Normal file
View File

@ -0,0 +1,59 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1661538846,
"narHash": "sha256-DNXCkkpDWk9Hj9FjdhBLPakg3lTWDqcuqDLTZYB/r8Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5d52b4e4fba11066959751366e410b97dcadc055",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-22.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-mozilla": {
"locked": {
"lastModified": 1657214286,
"narHash": "sha256-rO/4oymKXU09wG2bcTt4uthPCp1XsBZjxuCJo3yVXNs=",
"owner": "mozilla",
"repo": "nixpkgs-mozilla",
"rev": "0508a66e28a5792fdfb126bbf4dec1029c2509e0",
"type": "github"
},
"original": {
"owner": "mozilla",
"repo": "nixpkgs-mozilla",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"nixpkgs-mozilla": "nixpkgs-mozilla",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

42
flake.nix Normal file
View File

@ -0,0 +1,42 @@
{
inputs = {
nixpkgs = { url = "github:NixOS/nixpkgs/release-22.05"; };
utils.url = "github:numtide/flake-utils";
nixpkgs-mozilla = { url = "github:mozilla/nixpkgs-mozilla"; };
};
outputs = { self, nixpkgs, utils, nixpkgs-mozilla }:
utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import nixpkgs-mozilla) ];
};
toolchain = (pkgs.rustChannelOf {
# sadly, https://github.com/mozilla/nixpkgs-mozilla/issues/287
date = "2022-08-07";
channel = "nightly";
sha256 = "sha256-cXABXvQuh4dXNLtFMvRuB7YBi9LXRerA0u/u/TUm4rQ=";
}).rust.override {
extensions = [
"rust-src"
"rust-analyzer-preview"
"clippy-preview"
"rustfmt-preview"
];
};
baseBuildInputs = [ toolchain pkgs.glibc ];
in {
devShell = with pkgs;
mkShell {
nativeBuildInputs = baseBuildInputs ++ [ udev pkg-config glibc binutils ];
shellHook = ''
'';
};
});
}

44
notes.md Normal file
View File

@ -0,0 +1,44 @@
https://steamdecklinux.wiki/wiki/Main_Page
https://patchwork.kernel.org/project/linux-input/patch/20180416122703.22306-2-rodrigorivascosta@gmail.com/
https://github.com/torvalds/linux/blob/master/drivers/hid/hid-steam.c
look at steam_raw_event
https://github.com/rodrigorc/inputmap.git
https://github.com/rodrigorc/inputmap/blob/master/STEAM.md
(root@steamdeck /)# cat usr/lib/udev/rules.d/70-steam-jupiter-input.rules
# USB devices
SUBSYSTEM=="usb", TAG+="uaccess"
# HID devices over hidraw
KERNEL=="hidraw*", TAG+="uaccess"
# Steam Controller udev write access
KERNEL=="uinput", SUBSYSTEM=="misc", TAG+="uaccess", OPTIONS+="static_node=uinput"
(root@steamdeck /)#
--
steamdeck in steamctrl on  master [?] via C v11.3.0-gcc via ❄️ impure (shell)
sudo src/steamctrl --device /dev/hidraw3 get_serial
FWAA207022
the report descriptor run through https://eleccelerator.com/usbdescreqparser/
0x06, 0xFF, 0xFF, // Usage Page (Vendor Defined 0xFFFF)
0x09, 0x01, // Usage (0x01)
0xA1, 0x01, // Collection (Application)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x40, // Report Count (64)
0x09, 0x01, // Usage (0x01)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x01, // Usage (0x01)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x09, 0x01, // Usage (0x01)
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
// 29 bytes

7
shell.nix Normal file
View File

@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).shellNix

36
src/main.rs Normal file
View File

@ -0,0 +1,36 @@
use std::fs::OpenOptions;
use std::os::unix::prelude::*;
use std::path::Path;
use hidraw::{
get_physical_address, get_raw_info, get_raw_name, get_raw_unique, get_report_descriptor,
Result, *,
};
const O_NONBLOCK: i32 = 2048;
fn print_info<P: AsRef<Path>>(path: P) -> Result<()> {
let mut file = OpenOptions::new()
.custom_flags(O_NONBLOCK)
.read(true)
.open(path)?;
println!("{:?}", get_physical_address(&mut file)?);
println!("{:?}", get_raw_info(&mut file)?);
println!("{:?}", get_raw_name(&mut file)?);
println!("{:?}", get_raw_unique(&mut file)?);
let desc = get_report_descriptor(&mut file)?;
for b in desc {
print!("{:02x}", b);
}
//println!("{:?}", get_output_report(&mut file,)?);
Ok(())
}
fn main() {
if let Err(error) = print_info(format!("/dev/hidraw{}", 3)) {
eprintln!("{}", error);
}
}