pub struct Config<P, M = Master, Z = DefaultSize>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
sourceimpl<P: ValidPads> Config<P>
impl<P: ValidPads> Config<P>
sourcepub fn new(
apb_clk_ctrl: &APB_CLK_CTRL,
sercom: P::Sercom,
pads: P,
freq: impl Into<Hertz>
) -> Self
pub fn new(
apb_clk_ctrl: &APB_CLK_CTRL,
sercom: P::Sercom,
pads: P,
freq: impl Into<Hertz>
) -> Self
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.
sourceimpl<P, M, Z> Config<P, M, Z>where
P: ValidPads,
M: OpMode,
Z: Size,
impl<P, M, Z> Config<P, M, Z>where
P: ValidPads,
M: OpMode,
Z: Size,
sourcepub unsafe fn sercom(&self) -> &P::Sercom
pub unsafe fn sercom(&self) -> &P::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.
sourcepub fn char_size<C2: CharSize>(self) -> Config<P, M, C2>
pub fn char_size<C2: CharSize>(self) -> Config<P, M, C2>
Change the CharSize
using the builder pattern
sourcepub fn get_spi_mode(&self) -> Mode
pub fn get_spi_mode(&self) -> Mode
Get the SPI mode (clock polarity & phase)
sourcepub fn set_spi_mode(&mut self, mode: Mode)
pub fn set_spi_mode(&mut self, mode: Mode)
Set the SPI mode (clock polarity & phase)
sourcepub fn spi_mode(self, mode: Mode) -> Self
pub fn spi_mode(self, mode: Mode) -> Self
Set the SPI mode (clock polarity & phase) using the builder pattern
sourcepub fn get_bit_order(&self) -> BitOrder
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.
sourcepub fn set_bit_order(&mut self, order: BitOrder)
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.
sourcepub fn bit_order(self, order: BitOrder) -> Self
pub fn bit_order(self, order: BitOrder) -> Self
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.
sourcepub fn get_baud(&mut self) -> Hertz
pub fn get_baud(&mut self) -> Hertz
Get the baud rate
The returned baud rate may not exactly match what was set.
sourcepub fn set_baud(&mut self, baud: impl Into<Hertz>)
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.
sourcepub fn baud(self, baud: impl Into<Hertz>) -> Self
pub fn baud(self, baud: impl Into<Hertz>) -> Self
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.
sourcepub fn get_ibon(&self) -> bool
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.
sourcepub fn set_ibon(&mut self, enabled: bool)
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.
sourcepub fn ibon(self, enabled: bool) -> Self
pub fn ibon(self, enabled: bool) -> Self
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.
sourcepub fn get_run_in_standby(&self) -> bool
pub fn get_run_in_standby(&self) -> bool
Read the enable state of run in standby mode
sourcepub fn set_run_in_standby(&mut self, enabled: bool)
pub fn set_run_in_standby(&mut self, enabled: bool)
Enable or disable run in standby mode
sourcepub fn run_in_standby(self, enabled: bool) -> Self
pub fn run_in_standby(self, enabled: bool) -> Self
Enable or disable run in standby mode using the builder API
sourcepub fn enable(self) -> Spi<Self, P::Capability>where
Self: ValidConfig,
pub fn enable(self) -> Spi<Self, P::Capability>where
Self: ValidConfig,
Enable the SPI peripheral
SPI transactions are not possible until the peripheral is enabled.
This function is limited to ValidConfig
s.
Trait Implementations
sourceimpl<P, M, Z> AsMut<Config<P, M, Z>> for Config<P, M, Z>where
P: ValidPads,
M: OpMode,
Z: Size,
impl<P, M, Z> AsMut<Config<P, M, Z>> for Config<P, M, Z>where
P: ValidPads,
M: OpMode,
Z: Size,
sourceimpl<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,
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