Skip to content

Commit

Permalink
Add defmt::Format to error enums (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored Sep 14, 2023
1 parent a0e5737 commit 976549f
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Implement enabling/disabling BLE clock on ESP32-C6 (#784)
- Async support for RMT (#787)
- Implement `defmt::Format` for more types (#786)

### Changed

Expand Down
8 changes: 4 additions & 4 deletions esp-hal-common/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub mod pdma;
const CHUNK_SIZE: usize = 4092;

/// DMA Errors
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaError {
InvalidAlignment,
Expand All @@ -96,7 +96,7 @@ pub enum DmaError {

/// DMA Priorities
#[cfg(gdma)]
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaPriority {
Priority0 = 0,
Expand All @@ -114,15 +114,15 @@ pub enum DmaPriority {
/// DMA Priorities
/// The values need to match the TRM
#[cfg(pdma)]
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaPriority {
Priority0 = 0,
}

/// DMA capable peripherals
/// The values need to match the TRM
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaPeripheral {
Spi2 = 0,
Expand Down
13 changes: 8 additions & 5 deletions esp-hal-common/src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ pub struct Hmac<'d> {
}

/// HMAC interface error
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// It means the purpose of the selected block does not match the
/// configured key purpose and the calculation will not proceed.
KeyPurposeMismatch,
}

/// The peripheral can be configured to deliver its output directrly to the
/// user. It can also deliver to other periperals.
#[derive(Clone, Copy, Debug)]
/// The peripheral can be configured to deliver its output directly to the
/// user. It can also deliver to other peripherals.
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum HmacPurpose {
/// HMAC is used to re-enable JTAG after soft-disabling it.
ToJtag = 6,
Expand All @@ -73,7 +75,8 @@ pub enum HmacPurpose {
ToDsOrJtag = 5,
}

#[derive(Clone, Copy, Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum KeyId {
Key0 = 0,
Key1 = 1,
Expand Down
3 changes: 2 additions & 1 deletion esp-hal-common/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ cfg_if::cfg_if! {
}

/// I2C-specific transmission errors
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
ExceedingFifo,
AckCheckFailed,
Expand Down
9 changes: 8 additions & 1 deletion esp-hal-common/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ impl AcceptedWord for i16 {}
impl AcceptedWord for i32 {}

/// I2S Error
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
Unknown,
DmaError(DmaError),
Expand All @@ -119,13 +120,17 @@ impl From<DmaError> for Error {
}

/// Supported standards.
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Standard {
Philips,
// Tdm,
// Pdm,
}

/// Supported data formats
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg(not(any(esp32, esp32s2)))]
pub enum DataFormat {
Data32Channel32,
Expand All @@ -138,6 +143,8 @@ pub enum DataFormat {
}

/// Supported data formats
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg(any(esp32, esp32s2))]
pub enum DataFormat {
Data32Channel32,
Expand Down
10 changes: 7 additions & 3 deletions esp-hal-common/src/ledc/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use crate::{
};

/// Fade parameter sub-errors
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FadeError {
/// Start duty % out of range
StartDuty,
Expand All @@ -37,7 +38,8 @@ pub enum FadeError {
}

/// Channel errors
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// Invalid duty % value
Duty,
Expand All @@ -51,6 +53,7 @@ pub enum Error {

/// Channel number
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Number {
Channel0,
Channel1,
Expand All @@ -68,7 +71,8 @@ pub enum Number {
pub mod config {
use crate::ledc::timer::{TimerIFace, TimerSpeed};

#[derive(Copy, Clone)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PinConfig {
PushPull,
OpenDrain,
Expand Down
7 changes: 6 additions & 1 deletion esp-hal-common/src/ledc/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::{clock::Clocks, peripherals::ledc};
const LEDC_TIMER_DIV_NUM_MAX: u64 = 0x3FFFF;

/// Timer errors
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// Invalid Divisor
Divisor,
Expand All @@ -28,20 +29,23 @@ pub enum Error {
#[cfg(esp32)]
/// Clock source for HS Timers
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum HSClockSource {
APBClk,
// TODO RefTick,
}

/// Clock source for LS Timers
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LSClockSource {
APBClk,
// TODO SLOWClk
}

/// Timer number
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Number {
Timer0,
Timer1,
Expand All @@ -55,6 +59,7 @@ pub mod config {

/// Number of bits reserved for duty cycle adjustment
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Duty {
Duty1Bit = 1,
Duty2Bit,
Expand Down
1 change: 1 addition & 0 deletions esp-hal-common/src/mcpwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl<'a> PeripheralClockConfig<'a> {
/// Target frequency could not be set.
/// Check how the frequency is calculated in the corresponding method docs.
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FrequencyError;

/// A MCPWM peripheral
Expand Down
14 changes: 10 additions & 4 deletions esp-hal-common/src/parl_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ use crate::{
const MAX_DMA_SIZE: usize = 32736;

/// Parallel IO errors
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// General DMA error
DmaError(DmaError),
Expand All @@ -122,6 +123,7 @@ impl From<DmaError> for Error {

/// Parallel IO sample edge
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum SampleEdge {
/// Positive edge
Normal = 0,
Expand All @@ -130,7 +132,8 @@ pub enum SampleEdge {
}

/// Parallel IO bit packing order
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BitPackOrder {
/// Bit pack order: MSB
Msb = 0,
Expand All @@ -140,7 +143,8 @@ pub enum BitPackOrder {

#[cfg(esp32c6)]
/// Enable Mode
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum EnableMode {
/// Enable at high level
HighLevel,
Expand Down Expand Up @@ -219,7 +223,8 @@ impl EnableMode {

#[cfg(esp32h2)]
/// Enable Mode
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum EnableMode {
/// Enable at high level
HighLevel,
Expand Down Expand Up @@ -272,6 +277,7 @@ impl EnableMode {

/// Generation of GDMA SUC EOF
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum EofMode {
/// Generate GDMA SUC EOF by data byte length
ByteLen,
Expand Down
8 changes: 6 additions & 2 deletions esp-hal-common/src/pcnt/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub enum Number {
}

/// Unit errors
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// Invalid filter threshold value
InvalidFilterThresh,
Expand All @@ -43,7 +44,8 @@ pub enum Error {
}

/// the current status of the counter.
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ZeroMode {
/// pulse counter decreases from positive to 0.
#[default]
Expand All @@ -70,6 +72,7 @@ impl From<u8> for ZeroMode {

// Events
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Events {
pub low_limit: bool,
pub high_limit: bool,
Expand All @@ -80,6 +83,7 @@ pub struct Events {

/// Unit configuration
#[derive(Copy, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Config {
pub low_limit: i16,
pub high_limit: i16,
Expand Down
6 changes: 5 additions & 1 deletion esp-hal-common/src/rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ use crate::{
system::PeripheralClockControl,
};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
UnreachableTargetFrequency,
Overflow,
Expand All @@ -106,6 +107,7 @@ pub enum Error {
///
/// Allows for the assignment of two levels and their lengths
#[derive(Clone, Copy, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PulseCode {
/// Logical output level in the first pulse code interval
pub level1: bool,
Expand Down Expand Up @@ -159,6 +161,7 @@ impl From<PulseCode> for u32 {

/// Channel configuration for TX channels
#[derive(Debug, Copy, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct TxChannelConfig {
/// Channel's clock divider
pub clk_divider: u8,
Expand All @@ -178,6 +181,7 @@ pub struct TxChannelConfig {

/// Channel configuration for RX channels
#[derive(Debug, Copy, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct RxChannelConfig {
/// Channel's clock divider
pub clk_divider: u8,
Expand Down
3 changes: 2 additions & 1 deletion esp-hal-common/src/rtc_cntl/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl TimerWakeupSource {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
NotRtcPin,
TooManyWakeupSources,
Expand Down
3 changes: 2 additions & 1 deletion esp-hal-common/src/soc/esp32/cpu_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ impl<'a> Drop for AppCoreGuard<'a> {
}
}

#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
CoreAlreadyRunning,
}
Expand Down
3 changes: 2 additions & 1 deletion esp-hal-common/src/soc/esp32s3/cpu_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ impl<'a> Drop for AppCoreGuard<'a> {
}
}

#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
CoreAlreadyRunning,
}
Expand Down
9 changes: 6 additions & 3 deletions esp-hal-common/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const EMPTY_WRITE_PAD: u8 = 0x00u8;
#[allow(unused)]
const MAX_DMA_SIZE: usize = 32736;

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
DmaError(DmaError),
MaxDmaTransferSizeExceeded,
Expand All @@ -95,7 +96,8 @@ impl embedded_hal_1::spi::Error for Error {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum SpiMode {
Mode0,
Mode1,
Expand All @@ -112,7 +114,8 @@ pub trait IsHalfDuplex: DuplexMode {}
/// Single = 1 bit, 2 wires
/// Dual = 2 bit, 2 wires
/// Quad = 4 bit, 4 wires
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum SpiDataMode {
Single,
Dual,
Expand Down
Loading

0 comments on commit 976549f

Please sign in to comment.