Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRACKING] Derive defmt::Format #165

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use transfer::{Transfer, TransferExt};

/// Errors.
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DMAError {
/// DMA not ready to change buffers.
NotReady,
Expand All @@ -39,6 +40,7 @@ pub enum DMAError {

/// Possible DMA's directions.
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaDirection {
/// Memory to Memory transfer.
MemoryToMemory,
Expand All @@ -50,6 +52,7 @@ pub enum DmaDirection {

/// DMA from a peripheral to a memory location.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PeripheralToMemory;

impl PeripheralToMemory {
Expand All @@ -73,6 +76,7 @@ impl Direction for PeripheralToMemory {

/// DMA from one memory location to another memory location.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MemoryToMemory<T>
where
T: Into<u32>,
Expand Down Expand Up @@ -101,6 +105,7 @@ where

/// DMA from a memory location to a peripheral.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MemoryToPeripheral;

impl MemoryToPeripheral {
Expand Down
8 changes: 8 additions & 0 deletions src/dma/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,42 @@ pub struct DmaInterrupts {
}

/// Stream 0 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream0<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 1 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream1<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 2 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream2<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 3 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream3<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 4 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream4<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 5 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream5<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 6 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream6<DMA> {
_dma: PhantomData<DMA>,
}
/// Stream 7 on DMA
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Stream7<DMA> {
_dma: PhantomData<DMA>,
}
Expand Down
3 changes: 3 additions & 0 deletions src/dma/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ use core::{
use embedded_dma::{StaticReadBuffer, StaticWriteBuffer};

/// Marker type for a transfer with a mutable source and backed by a
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MutTransfer;
/// Marker type for a transfer with a constant source and backed by a
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ConstTransfer;

/// DMA Transfer.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Transfer<STREAM, PERIPHERAL, DIR, BUF, TXFRT>
where
STREAM: Stream,
Expand Down
14 changes: 14 additions & 0 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,43 @@ pub trait GpioExt {
}

/// Input mode (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Input<MODE> {
_mode: PhantomData<MODE>,
}

/// Floating input (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Floating;

/// Pulled down input (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PullDown;

/// Pulled up input (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PullUp;

/// Open drain input or output (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct OpenDrain;

/// Analog mode (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Analog;

/// Output mode (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Output<MODE> {
_mode: PhantomData<MODE>,
}

/// Push pull output (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PushPull;

/// GPIO Pin speed selection
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Speed {
Low = 0,
Medium = 1,
Expand All @@ -54,14 +63,17 @@ pub enum Speed {
}

/// Trigger edgw
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum SignalEdge {
Rising,
Falling,
RisingFalling,
}

/// Altername Mode (type state)
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Alternate<const A: u8>;
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct AlternateOD<const A: u8>;

pub const AF0: u8 = 0;
Expand Down Expand Up @@ -267,6 +279,7 @@ macro_rules! gpio {
}

/// Partially erased pin
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct $PXx<MODE> {
i: u8,
_mode: PhantomData<MODE>,
Expand Down Expand Up @@ -338,6 +351,7 @@ macro_rules! gpio {
exti_erased!($PXx<Input<MODE>>, $Pxn);

$(
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct $PXi<MODE> {
_mode: PhantomData<MODE>,
}
Expand Down
1 change: 1 addition & 0 deletions src/serial/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl FullConfig {
}

#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct InvalidConfig;

impl Default for LowPowerConfig {
Expand Down
8 changes: 8 additions & 0 deletions src/serial/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use nb::block;
use crate::serial::config::*;
/// Serial error
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// Framing error
Framing,
Expand All @@ -28,6 +29,7 @@ pub enum Error {
}

/// Interrupt event
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Event {
/// TXFIFO reaches the threshold
TXFT = 1 << 27,
Expand Down Expand Up @@ -74,20 +76,23 @@ impl Event {
}

/// Serial receiver
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Rx<USART, Pin, Dma> {
pin: Pin,
_usart: PhantomData<USART>,
_dma: PhantomData<Dma>,
}

/// Serial transmitter
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Tx<USART, Pin, Dma> {
pin: Pin,
usart: USART,
_dma: PhantomData<Dma>,
}

/// Serial abstraction
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Serial<USART, TXPin, RXPin> {
tx: Tx<USART, TXPin, NoDMA>,
rx: Rx<USART, RXPin, NoDMA>,
Expand All @@ -99,15 +104,18 @@ pub trait TxPin<USART> {}
/// Serial RX pin
pub trait RxPin<USART> {}

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct NoTx;

impl<USART> TxPin<USART> for NoTx {}

/// Type state for Tx/Rx, indicating operation without DMA
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct NoDMA;
/// Type state for Tx/Rx, indicating configuration for DMA
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DMA;

pub trait SerialExt<USART, Config> {
Expand Down
Loading