Skip to content

Commit

Permalink
Add #[non_exhaustive] and derive BuilderLite where necessary in I…
Browse files Browse the repository at this point in the history
…2C module
  • Loading branch information
jessebraham committed Nov 26, 2024
1 parent be923da commit 5958deb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const MAX_ITERATIONS: u32 = 1_000_000;
/// I2C-specific transmission errors
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
/// The transmission exceeded the FIFO size.
ExceedingFifo,
Expand All @@ -107,14 +108,15 @@ pub enum Error {
/// I2C-specific configuration errors
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum ConfigError {}

#[derive(PartialEq)]
// This enum is used to keep track of the last/next operation that was/will be
// performed in an embedded-hal(-async) I2c::transaction. It is used to
// determine whether a START condition should be issued at the start of the
// current operation and whether a read needs an ack or a nack for the final
// byte.
#[derive(PartialEq)]
enum OpKind {
Write,
Read,
Expand Down Expand Up @@ -218,6 +220,7 @@ enum Ack {
Ack = 0,
Nack = 1,
}

impl From<u32> for Ack {
fn from(ack: u32) -> Self {
match ack {
Expand All @@ -227,15 +230,17 @@ impl From<u32> for Ack {
}
}
}

impl From<Ack> for u32 {
fn from(ack: Ack) -> u32 {
ack as u32
}
}

/// I2C driver configuration
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, procmacros::BuilderLite)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub struct Config {
/// The I2C clock frequency.
pub frequency: HertzU32,
Expand Down

0 comments on commit 5958deb

Please sign in to comment.