v0.1.6: Add support for FTD2XX

This commit is contained in:
Kyan Wanschers 2024-12-20 18:57:23 +01:00
parent 91617b81f6
commit 31035b9c92
4 changed files with 150 additions and 21 deletions

126
Cargo.lock generated
View file

@ -7,11 +7,9 @@ name = "ELApse"
version = "0.1.5"
dependencies = [
"clap",
"ftdi-embedded-hal",
"image",
"piston",
"piston2d-graphics 0.45.0",
"piston_window",
"rand",
"unreal_asset",
"url",
]
@ -541,6 +539,32 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "embedded-hal"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
dependencies = [
"nb 0.1.3",
"void",
]
[[package]]
name = "embedded-hal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
[[package]]
name = "embedded-hal-nb"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
dependencies = [
"embedded-hal 1.0.0",
"nb 1.1.0",
]
[[package]]
name = "enum_dispatch"
version = "0.3.13"
@ -633,6 +657,29 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "ftdi-embedded-hal"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e328c2738c104e2649586bda4baabf376825db50014eb0d41bee74fb6064deb"
dependencies = [
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
"embedded-hal-nb",
"ftdi-mpsse",
"libftd2xx",
"nb 1.1.0",
]
[[package]]
name = "ftdi-mpsse"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7cfcda69930a8d2fdcdd7ffb9234fe4c79a8c73934ed4904327d77bfb5078a"
dependencies = [
"static_assertions",
]
[[package]]
name = "funty"
version = "2.0.0"
@ -976,6 +1023,28 @@ version = "0.2.158"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
[[package]]
name = "libftd2xx"
version = "0.32.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f20d68b3138aaabb97edc3db8ed8f418d60f8abd2a7d8220d562906fb38ff08e"
dependencies = [
"ftdi-mpsse",
"libftd2xx-ffi",
"log",
"paste",
"static_assertions",
]
[[package]]
name = "libftd2xx-ffi"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40bed7f53ea45282e0e4f1361d1a8094e62abe0ccfd9a6dbf7e3db932b2789ce"
dependencies = [
"cfg-if",
]
[[package]]
name = "libfuzzer-sys"
version = "0.4.7"
@ -1119,6 +1188,21 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fce7b49e1e6d8aa67232ef1c4c936c0af58756eb2db6f65c40bacb39035e7f42"
[[package]]
name = "nb"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
dependencies = [
"nb 1.1.0",
]
[[package]]
name = "nb"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
[[package]]
name = "ndk"
version = "0.7.0"
@ -1433,7 +1517,7 @@ dependencies = [
"gfx",
"piston-gfx_texture",
"piston-shaders_graphics2d",
"piston2d-graphics 0.44.0",
"piston2d-graphics",
"shader_version",
]
@ -1452,19 +1536,6 @@ dependencies = [
"vecmath",
]
[[package]]
name = "piston2d-graphics"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efa81d40c7b656d270fdbfeef8c531cc04493a001937f5a7d0c5cdb3db2b1469"
dependencies = [
"interpolation",
"piston-texture",
"piston-viewport",
"read_color",
"vecmath",
]
[[package]]
name = "piston_window"
version = "0.132.0"
@ -1476,7 +1547,7 @@ dependencies = [
"piston",
"piston-texture",
"piston2d-gfx_graphics",
"piston2d-graphics 0.44.0",
"piston2d-graphics",
"pistoncore-glutin_window",
"shader_version",
]
@ -1954,6 +2025,12 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strict-num"
version = "0.1.1"
@ -2220,6 +2297,13 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "usbintled"
version = "0.1.0"
dependencies = [
"ELApse",
]
[[package]]
name = "utf8parse"
version = "0.2.2"
@ -2264,6 +2348,12 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"

View file

@ -9,19 +9,23 @@ readme = "README.md"
[dependencies]
clap = { version = "4.5.17", features = ["derive"] }
ftdi-embedded-hal = { version = "0.22.0", features = ["libftd2xx"] }
image = "0.25.2"
piston = "1.0.0"
piston2d-graphics = "0.45.0"
piston_window = "0.132.0"
rand = "0.8.5"
unreal_asset = "0.1.16"
url = "2.5.2"
[profile.dev]
opt-level = 3
# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
lto = "thin"
[workspace]
members = ["usbintled"]
# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)

View file

@ -48,6 +48,7 @@ fn main() {
}
match args.output.as_str() {
"piston" => output::piston(rx),
"ftd2xx" => output::ft2dxx(rx),
_ => {
match Url::parse(&args.output) {
Ok(o) => {

View file

@ -4,6 +4,9 @@ use piston_window::*;
use piston_window::graphics::math::Scalar;
use std::{net::UdpSocket, sync::mpsc::Receiver, time::Duration};
use ftdi_embedded_hal::eh0::prelude::_embedded_hal_blocking_spi_Write;
use ftdi_embedded_hal::{self as hal, libftd2xx};
use crate::utils::{compare, offset};
pub fn piston(rx: Receiver<Vec<[f32; 4]>>) {
@ -50,8 +53,39 @@ pub fn realtimeudp(rx: Receiver<Vec<[f32; 4]>>, addr: String) {
}
}
pub fn ft2dxx(rx: Receiver<Vec<[f32; 4]>>) {
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
println!("Connected to FT232H");
let hal = hal::FtHal::init_freq(device, 3_000_000).unwrap();
let mut spi = hal.spi().unwrap();
// led stuff
loop {
let leds = rx.recv().unwrap();
let mut fdata: Vec<u8> = Vec::new();
for led in leds {
let sled = [led[1],led[0],led[2]]; //Shift colors (be gone when I make a color struct)
for i in 0..3 {
let mut data = (sled[i].clone()*255.0) as u8;
let patterns = [0b1000_1000, 0b1000_1110, 0b11101000, 0b11101110];
for _ in 0..4 {
let bits = (data & 0b1100_0000) >> 6;
fdata.push(patterns[bits as usize]);
data <<= 2;
}
}
}
let _ = spi.write(&fdata);
// for _ in 0..140 {
// spi.write(std::array::from_ref(&0)).unwrap();
// }
}
}
#[derive(clap::ValueEnum, Clone, Debug)]
pub enum Output {
piston,
realtimeudp,
ft2dxx,
}