Replace custom error type in favour of Debug constraints

This commit is contained in:
Wesley Moore 2020-03-10 20:50:19 +11:00
parent 9d8b68d78e
commit f27c2c6f68
No known key found for this signature in database
GPG key ID: BF67766C0BC2D0EE
3 changed files with 10 additions and 25 deletions

View file

@ -1,16 +0,0 @@
use core::fmt::{self, Debug};
use hal::digital::v2::OutputPin;
pub enum Error<GPIO: OutputPin> {
/// A GPIO could not be set.
Gpio(GPIO::Error),
}
impl<GPIO: OutputPin> Debug for Error<GPIO>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Gpio(_) => write!(f, "GPIO error"),
}
}
}

View file

@ -1,4 +1,4 @@
use crate::Error;
use core::fmt::Debug;
use hal;
// Section 15.2 of the HINK-E0213A07 data sheet says to hold for 10ms
@ -138,29 +138,32 @@ impl<SPI, CS, BUSY, DC, RESET> DisplayInterface for Interface<SPI, CS, BUSY, DC,
where
SPI: hal::blocking::spi::Write<u8>,
CS: hal::digital::v2::OutputPin,
CS::Error: Debug,
BUSY: hal::digital::v2::InputPin,
DC: hal::digital::v2::OutputPin,
DC::Error: Debug,
RESET: hal::digital::v2::OutputPin,
RESET::Error: Debug,
{
type Error = SPI::Error;
fn reset<D: hal::blocking::delay::DelayMs<u8>>(&mut self, delay: &mut D){
self.reset.set_low().map_err::<Error<RESET>, _>(Error::Gpio).unwrap();
fn reset<D: hal::blocking::delay::DelayMs<u8>>(&mut self, delay: &mut D) {
self.reset.set_low().unwrap();
delay.delay_ms(RESET_DELAY_MS);
self.reset.set_high().map_err::<Error<RESET>, _>(Error::Gpio).unwrap();
self.reset.set_high().unwrap();
delay.delay_ms(RESET_DELAY_MS);
}
fn send_command(&mut self, command: u8) -> Result<(), Self::Error> {
self.dc.set_low().map_err::<Error<DC>, _>(Error::Gpio).unwrap();
self.dc.set_low().unwrap();
self.write(&[command])?;
self.dc.set_high().map_err::<Error<DC>, _>(Error::Gpio).unwrap();
self.dc.set_high().unwrap();
Ok(())
}
fn send_data(&mut self, data: &[u8]) -> Result<(), Self::Error> {
self.dc.set_high().map_err::<Error<DC>, _>(Error::Gpio).unwrap();
self.dc.set_high().unwrap();
self.write(data)
}

View file

@ -47,14 +47,12 @@ mod color;
pub mod command;
pub mod config;
pub mod display;
pub mod error;
pub mod graphics;
pub mod interface;
pub use color::Color;
pub use config::Builder;
pub use display::{Dimensions, Display, Rotation};
pub use error::Error;
pub use graphics::GraphicDisplay;
pub use interface::DisplayInterface;
pub use interface::Interface;