Implement Error for error types
This commit is contained in:
parent
420e9f098d
commit
16d8071a03
1 changed files with 7 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ use embedded_hal::{
|
||||||
digital::{InputPin, OutputPin},
|
digital::{InputPin, OutputPin},
|
||||||
spi::{Operation, SpiDevice},
|
spi::{Operation, SpiDevice},
|
||||||
};
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
const EPD_WIDTH: usize = 240;
|
const EPD_WIDTH: usize = 240;
|
||||||
const EPD_HEIGHT: usize = 320;
|
const EPD_HEIGHT: usize = 320;
|
||||||
|
|
@ -27,25 +28,31 @@ pub struct EPaperDisplay<BusyPin, ResetPin, DcPin, SpiDevice, Delay> {
|
||||||
delay: Delay,
|
delay: Delay,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
/// An error that may occur during display initialisation.
|
/// An error that may occur during display initialisation.
|
||||||
pub enum InitError<ResetError, DcError, SpiError> {
|
pub enum InitError<ResetError, DcError, SpiError> {
|
||||||
/// This variant is for any error with setting the level of the reset pin.
|
/// This variant is for any error with setting the level of the reset pin.
|
||||||
///
|
///
|
||||||
/// This variant may be uninhabited if the `ResetPin` type parameter for [EPaperDisplay] is one that
|
/// This variant may be uninhabited if the `ResetPin` type parameter for [EPaperDisplay] is one that
|
||||||
/// doesn't produce errors.
|
/// doesn't produce errors.
|
||||||
|
#[error("While initialising the display, an error occurred when toggling the reset pin: {0}")]
|
||||||
ResetError(ResetError),
|
ResetError(ResetError),
|
||||||
/// This variant is for errors when attempting to communicate with the display controller after reset.
|
/// This variant is for errors when attempting to communicate with the display controller after reset.
|
||||||
|
#[error("While initialising the display, a communication error occurred: {0}")]
|
||||||
WriteError(WriteError<DcError, SpiError>),
|
WriteError(WriteError<DcError, SpiError>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
/// An error when trying to communicate with the display controller.
|
/// An error when trying to communicate with the display controller.
|
||||||
pub enum WriteError<DcError, SpiError> {
|
pub enum WriteError<DcError, SpiError> {
|
||||||
/// This variant is for any error with setting the level of the DC (Data/Command) pin.
|
/// This variant is for any error with setting the level of the DC (Data/Command) pin.
|
||||||
///
|
///
|
||||||
/// This variant may be uninhabited if the `DcPin` type parameter for [EPaperDisplay] is one that
|
/// This variant may be uninhabited if the `DcPin` type parameter for [EPaperDisplay] is one that
|
||||||
/// doesn't produce errors.
|
/// doesn't produce errors.
|
||||||
|
#[error("Failed to set the data/command line: {0}")]
|
||||||
DcError(DcError),
|
DcError(DcError),
|
||||||
/// This variant is for errors produced by the SPI driver.
|
/// This variant is for errors produced by the SPI driver.
|
||||||
|
#[error("Failed to perform SPI operations: {0}")]
|
||||||
SpiError(SpiError),
|
SpiError(SpiError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue