Skip to content

Commit

Permalink
Merge pull request #16 from andrewdavidmackenzie/pigg-15
Browse files Browse the repository at this point in the history
virtual gpio on all HW
  • Loading branch information
andrewdavidmackenzie authored May 13, 2024
2 parents 6b9a01d + 581b7bc commit 50e0afc
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 34 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ jobs:
- name: test
run: make test

- name: Upload code coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: UploadCoverage
run: |
grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info
#lcov --remove lcov.info 'target/debug/build/**' '**/errors.rs' '*tests/*' -o lcov.info
bash <(curl -s https://codecov.io/bash) -f lcov.info
rm -f lcov.info
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ readme = "README.md"
[[bin]]
name = "piggui"
path = "src/piggui.rs"
required-features = ["iced"]
required-features = ["gui"]

[[bin]]
name = "piglet"
path = "src/piglet.rs"
required-features = ["rppal"]
required-features = ["pi"]

[features]
default = []
pi = ["rppal"]
pico = [] #embassy
gui = ["iced"]

[dependencies]
# for interacting with GPIO on the Raspberry Pi
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,41 @@ release: release-build pibuild

.PHONY: piclippy
piclippy:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross clippy --release --features "rppal","iced" --tests --no-deps --target=aarch64-unknown-linux-gnu
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross clippy --release --features "pi","gui" --tests --no-deps --target=aarch64-unknown-linux-gnu

.PHONY: clippy
clippy: piclippy
cargo clippy --features "iced" --tests --no-deps
cargo clippy --features "gui" --tests --no-deps
#-- --warn clippy::pedantic -D warnings

# Enable the "iced" feature so we only build the "piggui" binary on the current host (macos, linux or raspberry pi)
# To build both binaries on a Pi directly, we will need to modify this
.PHONY: build
build:
cargo build --features "iced"
cargo build --features "gui"

.PHONY: run
run:
cargo run --features "iced"
cargo run --features "gui"

# This will build all binaries on the current host, be it macos, linux or raspberry pi - with release profile
.PHONY: release-build
release-build:
cargo build --release --features "iced"
cargo build --release --features "gui"

# I'm currently building using release profile for Pi, as not debugging natively on it. If we want to do that then
# we may need to add another make target
# For raspberry pi, build with the "rrpal" and "iced" features.
# That should build both the "piggui" and "piglet" binaries, with GUI and GPIO in "piggui" and GPIO in "piglet"
.PHONY: pibuild
pibuild:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --release --features "rppal","iced" --target=aarch64-unknown-linux-gnu
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --release --features "pi","gui" --target=aarch64-unknown-linux-gnu

# This will only test GUI tests in piggui on the local host, whatever that is
# We'd need to think how to run tests on RPi, on piggui with GUI and GPIO functionality, and piglet with GPIO functionality
.PHONY: test
test:
cargo test --features "iced"
cargo test --features "gui"

.PHONY: copy
copy: pibuild
Expand Down
15 changes: 15 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
codecov:
token: c53ff4f3-0633-441a-b737-b8ee9980ee7a

coverage:
round: up
precision: 0
status:
project:
default:
target: auto
threshold: 20%
patch:
default:
target: auto
threshold: 20%
39 changes: 27 additions & 12 deletions src/gpio/mod.rs → src/gpio.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/// When built with the "rppal" feature for interacting with GPIO - can only be built for RPi
#[cfg(feature = "rppal")]
use rppal::gpio::{InputPin, Level, Trigger};

// TODO will need to create a GPIOConfig and state that is NOT related to rrpal -
// for use in the UI when not compiled for Pi
#[cfg_attr(feature = "pi", path="gpio/pi.rs")]
#[cfg_attr(feature = "pico", path="gpio/pico.rs")]
#[cfg_attr(not(any(feature = "pico", feature = "pico")), path="gpio/none.rs")]
pub(crate) mod gpio_sys;

pub type PinLevel = bool;

// TODO do this for real
#[derive(Debug)]
#[allow(dead_code)] // TODO remove later
pub struct GPIOState {
pin_state: [Option<Level>; 40]
pin_state: [Option<PinLevel>; 40]
}

impl GPIOState {
Expand All @@ -21,21 +20,20 @@ impl GPIOState {
}

// TODO - add in here all the possible config options for GPIO
#[derive(Debug)]
#[allow(dead_code)] // TODO remove later
#[derive(Debug, PartialEq)]
pub enum PinConfig {
Input(InputPin, Option<Trigger>),
Input,
Output
}

// Pin Names
const SDA1: usize = 2;

const NO_CONFIG: Option<PinConfig> = None;

// Model the 40 pin GPIO connections - including Ground, 3.3V and 5V outputs
// If no specific config is set on a pin, it will have None
#[derive(Debug)]
#[allow(dead_code)] // TODO remove later
pub struct GPIOConfig {
pin_configs: [Option<PinConfig>; 40]
}
Expand All @@ -50,4 +48,21 @@ impl GPIOConfig {
pin_configs,
}
}
}

// TODO placeholder until I figure out what this trait needs to implement
pub trait GPIO {
fn apply_config(config: &GPIOConfig);
fn get_state() -> GPIOState;
}

#[cfg(test)]
mod test {
use crate::gpio;

#[test]
fn create_a_config() {
let config = gpio::GPIOConfig::new();
assert_eq!(config.pin_configs[0], None);
}
}
1 change: 1 addition & 0 deletions src/gpio/none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Implementation of GPIO for hosts that don't have GPIO (Linux, macOS, etc.)
3 changes: 3 additions & 0 deletions src/gpio/pi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Implementation of GPIO for raspberry pi - uses rrpal
#[cfg(feature = "rppal")]
use rppal::gpio::{InputPin, Level, Trigger};
1 change: 1 addition & 0 deletions src/gpio/pico.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// Implementation of GPIO for pi pico targets
6 changes: 0 additions & 6 deletions src/piggui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// When built with the "rppal" feature include code for interacting with GPIO
#[cfg(feature = "rppal")]
mod gpio;

// This binary will only be built with the "iced" feature enabled, by use of "required-features"
Expand All @@ -13,14 +11,10 @@ fn main() -> Result<(), iced::Error> {
..Default::default()
};

// TODO figure out how to connect config and state to the UI....
#[cfg(feature = "rppal")]
{
let config = gpio::GPIOConfig::new();
println!("Pin configs: {:?}", config);
let state = gpio::GPIOState::get(&config);
println!("OINK: {:?}", state);
}

Gpio::run(Settings {
window,
Expand Down
3 changes: 0 additions & 3 deletions src/piglet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// This binary will only be built when the "rppal" feature for interacting with GPIO is enabled
// so no need for conditional compilation here

mod gpio;

fn main() {
Expand Down

0 comments on commit 50e0afc

Please sign in to comment.