From a61ccf61cb0641c5ff1c25a4cdfd5406fb3b02fc Mon Sep 17 00:00:00 2001 From: Rahix Date: Sat, 2 Nov 2024 06:25:30 +0100 Subject: [PATCH] Add i2c display integration Just show placeholder text for a start. --- Cargo.lock | 250 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 ++ src/display.rs | 0 src/main.rs | 28 ++++++ 4 files changed, 284 insertions(+) create mode 100644 src/display.rs diff --git a/Cargo.lock b/Cargo.lock index 6adb319..7adfbb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" @@ -84,12 +90,62 @@ dependencies = [ "wyz", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "colorchoice" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[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", + "nb", +] + [[package]] name = "env_filter" version = "0.1.0" @@ -119,12 +175,42 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "hd44780-driver" +version = "0.4.0" +source = "git+https://github.com/JohnDoneth/hd44780-driver?rev=99152ccfe2263e70c480f7d1f417181b00423d37#99152ccfe2263e70c480f7d1f417181b00423d37" +dependencies = [ + "embedded-hal", +] + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "i2cdev" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01f563561b53e2def844167c92984da13779a53ca409e948a03400633cb8228" +dependencies = [ + "bitflags 2.5.0", + "byteorder", + "libc", + "nix 0.26.4", +] + +[[package]] +name = "io-kit-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b" +dependencies = [ + "core-foundation-sys", + "mach2", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -137,12 +223,36 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linux-embedded-hal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d566b726e1b6810f66c6f1c769889248439c27f06a59df2881a735454cfa02" +dependencies = [ + "cast", + "embedded-hal", + "embedded-hal-nb", + "i2cdev", + "nb", + "nix 0.27.1", + "serialport", +] + [[package]] name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "managed" version = "0.8.0" @@ -155,6 +265,43 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + +[[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "libc", +] + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + [[package]] name = "process-image" version = "0.2.0" @@ -174,6 +321,15 @@ dependencies = [ "rs485", ] +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + [[package]] name = "radium" version = "0.7.0" @@ -219,6 +375,41 @@ dependencies = [ "libc", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serialport" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7331eefcaafaa382c0df95bcd84068f0b3e3c215c300750dde2316e9b8806ed5" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "core-foundation", + "core-foundation-sys", + "io-kit-sys", + "mach2", + "nix 0.26.4", + "scopeguard", + "unescaper", + "winapi", +] + +[[package]] +name = "syn" +version = "2.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89275301d38033efb81a6e60e3497e734dfcc62571f2854bf4b16690398824c" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tap" version = "1.0.1" @@ -230,17 +421,76 @@ name = "test-jig-software" version = "0.1.0" dependencies = [ "env_logger", + "hd44780-driver", + "linux-embedded-hal", "log", "process-image", "profirust", ] +[[package]] +name = "thiserror" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d171f59dbaa811dbbb1aee1e73db92ec2b122911a48e1390dfe327a821ddede" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b08be0f17bd307950653ce45db00cd31200d82b624b36e181337d9c7d92765b5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unescaper" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" +dependencies = [ + "thiserror", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + [[package]] name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 67d5d9f..c83cc96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] env_logger = "0.11.3" +linux-embedded-hal = { version = "0.4.0", default-features = false, features = ["i2c"] } log = "0.4.21" process-image = "0.2.0" @@ -14,3 +15,8 @@ git = "https://github.com/rahix/profirust.git" rev = "6274541806f2b5fb8cfdffb641ca8fa452806c81" default-features = false features = ["phy-linux", "std"] + +[dependencies.hd44780] +package = "hd44780-driver" +git = "https://github.com/JohnDoneth/hd44780-driver" +rev = "99152ccfe2263e70c480f7d1f417181b00423d37" diff --git a/src/display.rs b/src/display.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index f193403..4f9080a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,6 +105,34 @@ fn main() { .format_timestamp_micros() .init(); + let mut i2c = linux_embedded_hal::I2cdev::new("/dev/i2c-1").unwrap(); + let mut delay = linux_embedded_hal::Delay; + let mut display_options = + hd44780::setup::DisplayOptionsI2C::new(hd44780::memory_map::MemoryMap2004::new()) + .with_i2c_bus(i2c, 0x27); + let mut display = loop { + match hd44780::HD44780::new(display_options, &mut delay) { + Err((options_back, error)) => { + log::warn!("Failed setting up display: {:?}", error); + display_options = options_back; + } + Ok(display) => break display, + } + }; + + display.clear(&mut delay).unwrap(); + display.reset(&mut delay).unwrap(); + display.set_display_mode(hd44780::DisplayMode { + cursor_visibility: hd44780::Cursor::Invisible, + cursor_blink: hd44780::CursorBlink::Off, + display: hd44780::Display::On, + }, &mut delay).unwrap(); + + display.set_cursor_xy((0, 0), &mut delay).unwrap(); + display.write_str(&format!("{:^20}", "torque tester"), &mut delay).unwrap(); + display.set_cursor_xy((0, 2), &mut delay).unwrap(); + display.write_str(&format!("{:^20}", "W. in P."), &mut delay).unwrap(); + let mut dp_master = dp::DpMaster::new(vec![]); // Options generated by `gsdtool` using "B751_P39.GSD"