Skip to content

Commit

Permalink
migration...
Browse files Browse the repository at this point in the history
  • Loading branch information
AdinAck committed Jan 13, 2025
1 parent d0a011f commit 645254c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
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
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<CHANNEL, PERIPHERAL, DIR, BUF, TXFRT>
where
CHANNEL: Channel,
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

0 comments on commit 645254c

Please sign in to comment.