From 66d7958392222213f252c8164c86f0abc65ce24c Mon Sep 17 00:00:00 2001 From: Harald Kube Date: Thu, 25 Feb 2021 22:58:52 +0100 Subject: [PATCH] Add build target for RPi which will access the GPIOs if build-option --fetaure "rppal" is passed. --- .cargo/config.toml | 2 ++ Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 14 ++++++++++++-- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..6df6788 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.armv7-unknown-linux-musleabihf] +linker = "/usr/local/Cellar/arm-linux-gnueabihf-binutils/2.36.1/bin/arm-linux-gnueabihf-ld" diff --git a/Cargo.lock b/Cargo.lock index 9521a44..84da9f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,6 +617,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "embedded-hal" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa998ce59ec9765d15216393af37a58961ddcefb14c753b4816ba2191d865fcb" +dependencies = [ + "nb 0.1.3", + "void", +] + [[package]] name = "event-listener" version = "2.5.1" @@ -999,6 +1009,21 @@ dependencies = [ "serde_json", ] +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" + [[package]] name = "nb-connect" version = "1.0.3" @@ -1234,6 +1259,19 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56770675ebc04927ded3e60633437841581c285dc6236109ea25fbf3beb7b59e" +[[package]] +name = "rppal" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "137dbba1fb867daa27cda4c3cd6a11bca5bb5a1551f034cf9319b994846ddbe1" +dependencies = [ + "embedded-hal", + "lazy_static", + "libc", + "nb 0.1.3", + "void", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -1264,6 +1302,7 @@ dependencies = [ "function_name", "lazy_static", "minreq", + "rppal", "serde", "serde_derive", "tide", @@ -1732,6 +1771,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "waker-fn" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 168ee4a..7d45637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,7 @@ serde_derive = "1.0" function_name = "0.2" tide = "0.16" +rppal = { version = "0.11.3", features = ["hal"], optional = true } + lazy_static = "1.4" minreq = { version = "2.3", features = ["json-using-serde"] } diff --git a/src/main.rs b/src/main.rs index 83b05f4..f6e38f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,15 @@ #[macro_use] extern crate clap; -use async_std::task; - mod cfg_reader; mod pulse_counter; mod rest_api; +use async_std; +use async_std::task; + const APP_VERSION: &'static str = env!("CARGO_PKG_VERSION"); + const DEFAULT_CONFIG_FILE_NAME: &str = "/etc/s0_logger.cfg"; fn main() { @@ -32,6 +34,14 @@ fn main() { .unwrap_or(DEFAULT_CONFIG_FILE_NAME); println!("Read the config from file '{}'", config_file_name); + if cfg!(feature = "rppal") { + println!("Will access GPIO pins"); + } else if cfg!(feature = "hal") { + println!("Will access HAL"); + } else { + println!("Will NOT access GPIO pins"); + } + let rest_api_config = rest_api::RestApiConfig { ip_and_port: String::from("127.0.0.1:8080"), get_channels: fake_get_channels,