pamoja_gpio/error.rs
1//! The error type for on-board bus addressing and pin logic.
2
3/// What can go wrong forming an I2C address frame.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum GpioError {
6 /// An address is outside its range: a 7-bit address above `0x7F`, or a 10-bit address
7 /// above `0x3FF`.
8 AddressOutOfRange,
9 /// The caller's output buffer is too small to hold the address frame. A 7-bit address
10 /// needs one byte and a 10-bit address two;
11 /// [`Address::frame_len`](crate::i2c::Address::frame_len) gives the exact count.
12 BufferTooSmall,
13}
14
15impl core::fmt::Display for GpioError {
16 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
17 match self {
18 GpioError::AddressOutOfRange => f.write_str("I2C address is out of range"),
19 GpioError::BufferTooSmall => {
20 f.write_str("output buffer is too small for the I2C address frame")
21 }
22 }
23 }
24}
25
26// `core::error::Error` rather than `std::error::Error`, so a caller on a
27// microcontroller gets the same trait a caller on a gateway does.
28impl core::error::Error for GpioError {}