Struct serpente::sercom::v2::spi::Config

source ·
pub struct Config<P, M = Master, Z = EightBit>where
    P: ValidPads,
    M: OpMode,
    Z: Size,{ /* private fields */ }
Expand description

A configurable SPI peripheral in its disabled state

See the module-level documentation for more details on declaring and instantiating Pads types.

Implementations§

source§

impl<P> Config<P, Master, EightBit>where P: ValidPads,

source

pub fn new( apb_clk_ctrl: &PM, sercom: <P as PadSet>::Sercom, pads: P, freq: impl Into<Hertz> ) -> Config<P, Master, EightBit>

Create a new Config in the default configuration

This function will enable the corresponding APB clock, reset the Sercom peripheral, and return a Config in the default configuration. The default OpMode is Master, while the default Size is an EightBit CharSize for SAMD11 and SAMD21 chips or a Length of U1 for SAMx5x chips. Note that Config takes ownership of both the PAC Sercom struct as well as the Pads.

Users must configure GCLK manually. The freq parameter represents the GCLK frequency for this Sercom instance.

source§

impl<P, M, Z> Config<P, M, Z>where P: ValidPads, M: OpMode, Z: Size,

source

pub unsafe fn sercom(&self) -> &<P as PadSet>::Sercom

Obtain a reference to the PAC SERCOM struct

Directly accessing the SERCOM could break the invariants of the type-level tracking in this module, so it is unsafe.

source

pub fn reset(self) -> Config<P, Master, EightBit>

Trigger the Sercom’s SWRST and return a Config in the default configuration.

source

pub fn free(self) -> (<P as PadSet>::Sercom, P)

Consume the Config, reset the peripheral, and return the Sercom and Pads

source

pub fn op_mode<M2>(self) -> Config<P, M2, Z>where M2: OpMode,

Change the OpMode

source

pub fn char_size<C2>(self) -> Config<P, M, C2>where C2: CharSize,

Change the CharSize using the builder pattern

source

pub fn get_cpol(&self) -> Polarity

Get the clock polarity

source

pub fn set_cpol(&mut self, cpol: Polarity)

Set the clock polarity

source

pub fn cpol(self, cpol: Polarity) -> Config<P, M, Z>

Set the clock polarity using the builder pattern

source

pub fn get_cpha(&self) -> Phase

Get the clock phase

source

pub fn set_cpha(&mut self, cpha: Phase)

Set the clock phase

source

pub fn cpha(self, cpha: Phase) -> Config<P, M, Z>

Set the clock phase using the builder pattern

source

pub fn get_spi_mode(&self) -> Mode

Get the SPI mode (clock polarity & phase)

source

pub fn set_spi_mode(&mut self, mode: Mode)

Set the SPI mode (clock polarity & phase)

source

pub fn spi_mode(self, mode: Mode) -> Config<P, M, Z>

Set the SPI mode (clock polarity & phase) using the builder pattern

source

pub fn get_bit_order(&self) -> BitOrder

Get the bit order of transmission (MSB/LSB first)

This only affects the order of bits within each byte. Bytes are always transferred in little endian order from the 32-bit DATA register.

source

pub fn set_bit_order(&mut self, order: BitOrder)

Set the bit order of transmission (MSB/LSB first) using the builder pattern

This only affects the order of bits within each byte. Bytes are always transferred in little endian order from the 32-bit DATA register.

source

pub fn bit_order(self, order: BitOrder) -> Config<P, M, Z>

Set the bit order of transmission (MSB/LSB first) using the builder pattern

This only affects the order of bits within each byte. Bytes are always transferred in little endian order from the 32-bit DATA register.

source

pub fn get_baud(&mut self) -> Hertz

Get the baud rate

The returned baud rate may not exactly match what was set.

source

pub fn set_baud(&mut self, baud: impl Into<Hertz>)

Set the baud rate

This function will calculate the best BAUD register setting based on the stored GCLK frequency and desired baud rate. The maximum baud rate is half the GCLK frequency. The minimum baud rate is the GCLK frequency / 512. Values outside this range will saturate at the extremes.

source

pub fn baud(self, baud: impl Into<Hertz>) -> Config<P, M, Z>

Set the baud rate using the builder API

This function will calculate the best BAUD register setting based on the stored GCLK frequency and desired baud rate. The maximum baud rate is half the GCLK frequency. The minimum baud rate is the GCLK frequency / 512. Values outside this range will saturate at the extremes.

source

pub fn get_ibon(&self) -> bool

Read the enabled state of the immediate buffer overflow notification

If set to true, an Error::Overflow will be issued as soon as an overflow occurs. Otherwise, it will not be issued until its place within the data stream.

source

pub fn set_ibon(&mut self, enabled: bool)

Enable or disable the immediate buffer overflow notification

If set to true, an Error::Overflow will be issued as soon as an overflow occurs. Otherwise, it will not be issued until its place within the data stream.

source

pub fn ibon(self, enabled: bool) -> Config<P, M, Z>

Enable or disable the immediate buffer overflow notification using the builder API

If set to true, an Error::Overflow will be issued as soon as an overflow occurs. Otherwise, it will not be issued until its place within the data stream.

source

pub fn get_run_in_standby(&self) -> bool

Read the enable state of run in standby mode

source

pub fn set_run_in_standby(&mut self, enabled: bool)

Enable or disable run in standby mode

source

pub fn run_in_standby(self, enabled: bool) -> Config<P, M, Z>

Enable or disable run in standby mode using the builder API

source

pub fn enable(self) -> Spi<Config<P, M, Z>, <P as ValidPads>::Capability>where Config<P, M, Z>: ValidConfig,

Enable the SPI peripheral

SPI transactions are not possible until the peripheral is enabled. This function is limited to ValidConfigs.

Trait Implementations§

source§

impl<P, M, Z> AnyConfig for Config<P, M, Z>where P: ValidPads, M: OpMode, Z: Size,

§

type Sercom = <P as PadSet>::Sercom

§

type Pads = P

§

type Capability = <P as ValidPads>::Capability

§

type OpMode = M

§

type Size = Z

§

type Word = <Z as CharSize>::Word

source§

impl<P, M, Z> AsMut<Config<P, M, Z>> for Config<P, M, Z>where P: ValidPads, M: OpMode, Z: Size,

source§

fn as_mut(&mut self) -> &mut Config<P, M, Z>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<C, A> AsRef<Config<<C as AnyConfig>::Pads, <C as AnyConfig>::OpMode, <C as AnyConfig>::Size>> for Spi<C, A>where C: ValidConfig, A: Capability,

Get a shared reference to the underlying Config struct

This can be used to call the various get_* functions on Config

source§

fn as_ref( &self ) -> &Config<<C as AnyConfig>::Pads, <C as AnyConfig>::OpMode, <C as AnyConfig>::Size>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<P, M, Z> AsRef<Config<P, M, Z>> for Config<P, M, Z>where P: ValidPads, M: OpMode, Z: Size,

source§

fn as_ref(&self) -> &Config<P, M, Z>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<P, Z> ValidConfig for Config<P, Master, Z>where P: ValidPads<SS = NoneT>, Z: Size,

source§

impl<P, Z> ValidConfig for Config<P, MasterHWSS, Z>where P: ValidPads, Z: Size, <P as PadSet>::SS: SomePad,

source§

impl<P, Z> ValidConfig for Config<P, Slave, Z>where P: ValidPads, Z: Size, <P as PadSet>::SS: SomePad,

Auto Trait Implementations§

§

impl<P, M, Z> RefUnwindSafe for Config<P, M, Z>where M: RefUnwindSafe, P: RefUnwindSafe, Z: RefUnwindSafe, <P as PadSet>::Sercom: RefUnwindSafe,

§

impl<P, M, Z> Send for Config<P, M, Z>where M: Send, P: Send, Z: Send, <P as PadSet>::Sercom: Send,

§

impl<P, M, Z> Sync for Config<P, M, Z>where M: Sync, P: Sync, Z: Sync,

§

impl<P, M, Z> Unpin for Config<P, M, Z>where M: Unpin, P: Unpin, Z: Unpin, <P as PadSet>::Sercom: Unpin,

§

impl<P, M, Z> UnwindSafe for Config<P, M, Z>where M: UnwindSafe, P: UnwindSafe, Z: UnwindSafe, <P as PadSet>::Sercom: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Is for Twhere T: Sealed + AsRef<T> + AsMut<T>,

§

type Type = T

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.