-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from andrewdavidmackenzie/pigg-4
Virtual GPIO Config and State
- Loading branch information
Showing
10 changed files
with
492 additions
and
53 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::gpio::{GPIOConfig, GPIOState}; | ||
|
||
#[cfg_attr(feature="pico", path="pico.rs")] | ||
#[cfg_attr(feature="pi", path="pi.rs")] | ||
#[cfg_attr(not(any(feature="pico", feature="pi")), path="none.rs")] | ||
mod implementation; | ||
|
||
pub fn get() -> impl Hardware { | ||
implementation::get() | ||
} | ||
|
||
// TODO placeholder until I figure out what this trait needs to implement | ||
pub trait Hardware { | ||
fn apply_config(&mut self, config: &GPIOConfig); | ||
fn get_state(&self) -> GPIOState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Implementation of GPIO for hosts that don't have GPIO (Linux, macOS, etc.) | ||
|
||
use super::Hardware; | ||
use crate::gpio::{GPIOState, GPIOConfig}; | ||
|
||
pub struct NoneHW; | ||
|
||
pub fn get() -> impl Hardware { | ||
NoneHW {} | ||
} | ||
|
||
impl Hardware for NoneHW { | ||
fn apply_config(&mut self, _config: &GPIOConfig) { | ||
println!("GPIO Config has been applied to fake hardware"); | ||
} | ||
|
||
fn get_state(&self) -> GPIOState { | ||
GPIOState { | ||
pin_state: [None; 40] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// Implementation of GPIO for raspberry pi - uses rrpal | ||
#[cfg(feature = "rppal")] | ||
#[allow(unused_imports)] // just checking builds work for now... | ||
use rppal::gpio::{InputPin, Level, Trigger}; | ||
|
||
use super::Hardware; | ||
use crate::gpio::{GPIOState, GPIOConfig}; | ||
|
||
pub struct PiHW; | ||
|
||
pub fn get() -> impl Hardware { | ||
PiHW {} | ||
} | ||
|
||
impl Hardware for PiHW { | ||
fn apply_config(&mut self, _config: &GPIOConfig) { | ||
println!("GPIO Config has been applied to Pi hardware"); | ||
} | ||
|
||
fn get_state(&self) -> GPIOState { | ||
GPIOState { | ||
pin_state: [None; 40] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// Implementation of GPIO for pi pico targets | ||
#[cfg(feature = "rppal")] | ||
use rppal::gpio::{InputPin, Level, Trigger}; | ||
|
||
use super::Hardware; | ||
use crate::gpio::{GPIOState, GPIOConfig}; | ||
|
||
pub struct PicoHW; | ||
|
||
pub fn get() -> impl Hardware { | ||
PicoHW {} | ||
} | ||
|
||
impl Hardware for PicoHW { | ||
fn apply_config(&mut self, _config: &GPIOConfig) { | ||
println!("GPIO Config has been applied to Pico hardware"); | ||
} | ||
|
||
fn get_state(&self) -> GPIOState { | ||
GPIOState { | ||
pin_state: [None; 40] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
mod gpio; | ||
mod hw; | ||
|
||
// Use Hardware via trait | ||
use hw::Hardware; | ||
|
||
fn main() { | ||
let config = gpio::GPIOConfig::new(); | ||
println!("Pin configs: {:?}", config); | ||
println!("Pin1 Config is: {:?}", config.pins[1]); | ||
|
||
let state = gpio::GPIOState::get(&config); | ||
|
||
println!("Oink: {:?}", state); | ||
let mut hw = hw::get(); | ||
hw.apply_config(&config); | ||
println!("Oink: {:?}", hw.get_state()); | ||
} |