Skip to content

Commit

Permalink
OutputPort<u8> impl
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Mar 5, 2022
1 parent 6ce0714 commit f8a442f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ sdio-host = { version = "0.6.0", optional = true }
embedded-dma = "0.2.0"
bare-metal = { version = "1" }
void = { default-features = false, version = "1.0.2" }
embedded-hal = { features = ["unproven"], version = "0.2.7" }
embedded-hal = { git = "https://github.com/burrbull/embedded-hal", branch = "outport", features = ["unproven"] }
display-interface = { version = "0.4.1", optional = true }
fugit = "0.3.5"
fugit-timer = "0.1.3"
rtic-monotonic = { version = "1.0", optional = true }
bitflags = "1.3.2"
embedded-storage = "0.2"
hd44780-driver = "0.4.0"

[dependencies.time]
version = "0.3"
Expand Down Expand Up @@ -80,6 +79,7 @@ display-interface-spi = "0.4"
ist7920 = "0.1.0"
smart-leds = "0.3.0"
ws2812-spi = { version = "0.4.0", features = [] }
hd44780-driver = { git = "https://github.com/burrbull/hd44780-driver", branch = "outport" }

[dev-dependencies.time]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/hd44780.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() -> ! {
let d6 = gpiob.pb4.into_push_pull_output();
let d7 = gpiob.pb3.into_push_pull_output();

let mut lcd = HD44780::new_4bit(rs, en, d4, d5, d6, d7, &mut delay).unwrap();
let mut lcd = HD44780::new_4bit_port(rs, en, (d4, d5, d6, d7).outport(), &mut delay).unwrap();
lcd.reset(&mut delay).unwrap();
lcd.clear(&mut delay).unwrap();
lcd.set_display_mode(
Expand Down
25 changes: 17 additions & 8 deletions src/gpio/outport.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::*;
use embedded_hal::digital::v2::OutputPort;

pub trait OutPort {
type Target;
fn outport(self) -> Self::Target;
}

macro_rules! out_port {
( $name:ident => ( $($i:literal),+ ), ( $($N:ident),+ ), ( $($d:ident),* )) => {
( $name:ident => $n:literal, ( $($i:literal),+ ), ( $($N:ident),+ ), ( $($d:ident),* )) => {
pub struct $name<const P: char $(, const $N: u8)+> {
$(pub $d: Pin<P, $N, Output<PushPull>>,)+
}
Expand Down Expand Up @@ -40,13 +41,21 @@ macro_rules! out_port {
}
}
}

impl<const P: char $(, const $N: u8)+> OutputPort<$n, u8> for $name<P $(, $N)+> {
type Error = core::convert::Infallible;
fn write(&mut self, data: u8) -> Result<(), Self::Error> {
self.write_u8(data);
Ok(())
}
}
}
}

out_port!(OutPort2 => (0, 1), (N0, N1), (d0, d1));
out_port!(OutPort3 => (0, 1, 2), (N0, N1, N2), (d0, d1, d2));
out_port!(OutPort4 => (0, 1, 2, 3), (N0, N1, N2, N3), (d0, d1, d2, d3));
out_port!(OutPort5 => (0, 1, 2, 3, 4), (N0, N1, N2, N3, N4), (d0, d1, d2, d3, d4));
out_port!(OutPort6 => (0, 1, 2, 3, 4, 5), (N0, N1, N2, N3, N4, N5), (d0, d1, d2, d3, d4, d5));
out_port!(OutPort7 => (0, 1, 2, 3, 4, 5, 6), (N0, N1, N2, N3, N4, N5, N6), (d0, d1, d2, d3, d4, d5, d6));
out_port!(OutPort8 => (0, 1, 2, 3, 4, 5, 6, 7), (N0, N1, N2, N3, N4, N5, N6, N7), (d0, d1, d2, d3, d4, d5, d6, d7));
out_port!(OutPort2 => 2, (0, 1), (N0, N1), (d0, d1));
out_port!(OutPort3 => 3, (0, 1, 2), (N0, N1, N2), (d0, d1, d2));
out_port!(OutPort4 => 4, (0, 1, 2, 3), (N0, N1, N2, N3), (d0, d1, d2, d3));
out_port!(OutPort5 => 5, (0, 1, 2, 3, 4), (N0, N1, N2, N3, N4), (d0, d1, d2, d3, d4));
out_port!(OutPort6 => 6, (0, 1, 2, 3, 4, 5), (N0, N1, N2, N3, N4, N5), (d0, d1, d2, d3, d4, d5));
out_port!(OutPort7 => 7, (0, 1, 2, 3, 4, 5, 6), (N0, N1, N2, N3, N4, N5, N6), (d0, d1, d2, d3, d4, d5, d6));
out_port!(OutPort8 => 8, (0, 1, 2, 3, 4, 5, 6, 7), (N0, N1, N2, N3, N4, N5, N6, N7), (d0, d1, d2, d3, d4, d5, d6, d7));

0 comments on commit f8a442f

Please sign in to comment.