Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement embedded-hal 1.0 traits #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ edition = "2021"
targets = [ "thumbv7m-none-eabi", "thumbv7em-none-eabihf" ]

[dependencies]
embedded-hal = "^ 0.2"
display-interface = "^ 0.4"
embedded-hal = "^ 1.0"
display-interface = "^ 0.5"
embedded-graphics-core = { version = "^ 0.4", optional = true }

[dev-dependencies]
cortex-m = "^ 0.7"
cortex-m-rt = "^ 0.7"
embedded-graphics = "^ 0.8"
panic-semihosting = "^ 0.6"
display-interface-i2c = "^ 0.4"
display-interface-spi = "^ 0.4"
display-interface-i2c = "^ 0.5"
display-interface-spi = "^ 0.5"

[dev-dependencies.stm32f1xx-hal]
version = "^ 0.10"
Expand Down
30 changes: 24 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
//! ```

use core::marker::PhantomData;
use hal::{self, digital::v2::OutputPin};
use hal::{self, digital::{ErrorKind, ErrorType, OutputPin}};

use crate::{
displayrotation::DisplayRotation,
Expand Down Expand Up @@ -117,20 +117,38 @@ impl<PinE> NoOutputPin<PinE> {
}
}

impl<PinE> OutputPin for NoOutputPin<PinE> {
type Error = PinE;
fn set_low(&mut self) -> Result<(), PinE> {
#[derive(Debug, Clone, Copy)]
/// Implement error type for NoOutputPin, required by OutputPin trait in embedded-hal 1.0
pub enum Error {
/// This isn't a pin, so you can't change it's outputs
NotAPin
}

/// Required trait by embedded-hal 1.0
impl hal::digital::Error for Error {
/// Needs to return
fn kind(&self) -> ErrorKind {
ErrorKind::Other
}
}

impl ErrorType for NoOutputPin {
type Error = Error;
}

impl OutputPin for NoOutputPin {
fn set_low(&mut self) -> Result<(), Error> {
Ok(())
}
fn set_high(&mut self) -> Result<(), PinE> {
fn set_high(&mut self) -> Result<(), Error> {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::NoOutputPin;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;

enum SomeError {}

Expand Down
4 changes: 2 additions & 2 deletions src/mode/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! ```

use display_interface::{DisplayError, WriteOnlyDataCommand};
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};
use hal::{delay::DelayNs, digital::OutputPin};

use crate::{
displayrotation::DisplayRotation,
Expand Down Expand Up @@ -72,7 +72,7 @@ where
) -> Result<(), PinE>
where
RST: OutputPin<Error = PinE>,
DELAY: DelayMs<u8>,
DELAY: DelayNs,
{
rst.set_high()?;
delay.delay_ms(10);
Expand Down