[][src]Struct lpc81x_hal::spi::SPI0

pub struct SPI0<MODE, SCLK, MOSI, MISO, SSEL> where
    MODE: Mode,
    SCLK: PinAssignment,
    MOSI: PinAssignment,
    MISO: PinAssignment,
    SSEL: PinAssignment
{ /* fields omitted */ }

Represents the SPI peripheral.

Each SPI peripheral starts in an inactive state, not connected to any pins. To use it, call either activate_as_host or activate_as_device to activate the peripheral and assign it an external pin for the SCLK signal.

Once activated, call either with_data_pins, with_mosi, or with_miso to assign further external pins for the MOSI and MISO signals, as required.

An activated SPI peripheral in host mode implements the embedded-hal SPI traits, so you can pass it directly to a device driver that expects any of these traits.

Methods

impl SPI0<Inactive, Unassigned, Unassigned, Unassigned, Unassigned>[src]

pub fn activate_as_host<SCLK: UnassignedPin>(
    self,
    sclk: SCLK,
    cfg: Config
) -> SPI0<Host, Assigned<SCLK>, Unassigned, Unassigned, Unassigned>
[src]

Consumes the inactive SPI bus and returns it with host mode enabled, using the given pin for SCLK.

pub fn activate_as_device<SCLK: InputPin>(
    self,
    sclk: SCLK,
    cfg: Config
) -> SPI0<Device, Assigned<SCLK>, Unassigned, Unassigned, Unassigned>
[src]

Consumes the inactive SPI bus and returns it with device mode enabled, using the given pin for SCLK.

impl<SCLK: PinAssignment, MOSI: PinAssignment, MISO: PinAssignment, SSEL: PinAssignment> SPI0<Host, SCLK, MOSI, MISO, SSEL>[src]

pub fn set_clock_divider(&mut self, div: u32)[src]

impl<MODE: Active, SCLK: PinAssignment, SSEL: PinAssignment> SPI0<MODE, SCLK, Unassigned, Unassigned, SSEL>[src]

pub fn with_data_pins<MOSI: UnassignedPin, MISO: UnassignedPin>(
    self,
    mosi: MOSI,
    miso: MISO
) -> SPI0<MODE, SCLK, Assigned<MOSI>, Assigned<MISO>, SSEL>
[src]

Assigns pins to both the MOSI and MISO signals at once.

This is just a convenience shortcut for .with_mosi(mosi).with_miso(miso).

impl<MODE: Active, SCLK: PinAssignment, MISO: PinAssignment, SSEL: PinAssignment> SPI0<MODE, SCLK, Unassigned, MISO, SSEL>[src]

pub fn with_mosi<MOSI: UnassignedPin>(
    self,
    mosi: MOSI
) -> SPI0<MODE, SCLK, Assigned<MOSI>, MISO, SSEL>
[src]

Assigns an unassigned external pin to the MOSI signal.

impl<MODE: Active, SCLK: PinAssignment, MOSI: PinAssignment, SSEL: PinAssignment> SPI0<MODE, SCLK, MOSI, Unassigned, SSEL>[src]

pub fn with_miso<MISO: UnassignedPin>(
    self,
    miso: MISO
) -> SPI0<MODE, SCLK, MOSI, Assigned<MISO>, SSEL>
[src]

Assigns an unassigned external pin to the MISO signal.

impl<MODE: Active, SCLK: PinAssignment, MOSI: PinAssignment, MISO: PinAssignment> SPI0<MODE, SCLK, MOSI, MISO, Unassigned>[src]

pub fn with_ssel<SSEL: UnassignedPin>(
    self,
    ssel: SSEL,
    polarity: Polarity
) -> SPI0<MODE, SCLK, MOSI, MISO, Assigned<SSEL>>
[src]

Assigns an unassigned external pin to the SSEL signal.

impl<MODE: Active, SCLK: PinAssignment, MOSI: Pin, MISO: Pin, SSEL: PinAssignment> SPI0<MODE, SCLK, Assigned<MOSI>, Assigned<MISO>, SSEL>[src]

pub fn release_data_pins(
    self
) -> (SPI0<MODE, SCLK, Unassigned, Unassigned, SSEL>, MOSI, MISO)
[src]

Consumes the SPI object and returns a new object with the MOSI and MISO pins detached.

Along with that new object, the former MOSI and MISO pins are also returned in unassigned mode, ready to be assigned to another function.

impl<MODE: Active, SCLK: PinAssignment, MOSI: Pin, MISO: PinAssignment, SSEL: PinAssignment> SPI0<MODE, SCLK, Assigned<MOSI>, MISO, SSEL>[src]

pub fn release_mosi(self) -> (SPI0<MODE, SCLK, Unassigned, MISO, SSEL>, MOSI)[src]

Consumes the SPI object and returns a new object with the MOSI pin detached.

Along with that new object, the former MOSI pin is also returned in unassigned mode, ready to be assigned to another function.

impl<MODE: Active, SCLK: PinAssignment, MOSI: PinAssignment, MISO: Pin, SSEL: PinAssignment> SPI0<MODE, SCLK, MOSI, Assigned<MISO>, SSEL>[src]

pub fn release_miso(self) -> (SPI0<MODE, SCLK, MOSI, Unassigned, SSEL>, MISO)[src]

Consumes the SPI object and returns a new object with the MISO pin detached.

Along with that new object, the former MISO pin is also returned in unassigned mode, ready to be assigned to another function.

impl<MODE: Active, SCLK: PinAssignment, MOSI: PinAssignment, MISO: PinAssignment, SSEL: Pin> SPI0<MODE, SCLK, MOSI, MISO, Assigned<SSEL>>[src]

pub fn release_ssel(self) -> (SPI0<MODE, SCLK, MOSI, MISO, Unassigned>, SSEL)[src]

Consumes the SPI object and returns a new object with the SSEL pin detached.

Along with that new object, the former SSEL pin is also returned in unassigned mode, ready to be assigned to another function.

impl<MODE: Active, SCLK: Pin> SPI0<MODE, Assigned<SCLK>, Unassigned, Unassigned, Unassigned>[src]

pub fn deactivate(
    self
) -> (SPI0<Inactive, Unassigned, Unassigned, Unassigned, Unassigned>, SCLK)
[src]

Consumes the active SPI bus and returns it deactivated, along with the now-unused pin that was used for SCK.

This method can be called only when any assigned MOSI, MISO, and SSEL pins have already been released. For example:

let (spi, mosi, miso) = spi.release_data_pins();
// (for this example, assume the object never had SSEL active)
let (spi, sclk) = spi.deactivate();

Trait Implementations

impl<MODE, SCLK, MOSI, MISO, SSEL> !Sync for SPI0<MODE, SCLK, MOSI, MISO, SSEL>[src]

An SPI peripheral object represents access to a single system peripheral, so it's not safe to share it across multiple threads without some external concurrency control mechanisms.

impl<W, SCLK, MOSI, MISO, SSEL> Default<W> for SPI0<Host, SCLK, MOSI, MISO, SSEL> where
    W: Word,
    SCLK: PinAssignment,
    MOSI: PinAssignment,
    MISO: PinAssignment,
    SSEL: PinAssignment
[src]

impl<W, SCLK, MOSI, MISO, SSEL> Default<W> for SPI0<Host, SCLK, MOSI, MISO, SSEL> where
    W: Word,
    SCLK: PinAssignment,
    MOSI: PinAssignment,
    MISO: PinAssignment,
    SSEL: PinAssignment
[src]

impl<W, SCLK, MOSI, MISO, SSEL> Default<W> for SPI0<Host, SCLK, MOSI, MISO, SSEL> where
    W: Word,
    SCLK: PinAssignment,
    MOSI: PinAssignment,
    MISO: PinAssignment,
    SSEL: PinAssignment
[src]

impl<W, SCLK, MOSI, MISO, SSEL> FullDuplex<W> for SPI0<Host, SCLK, MOSI, MISO, SSEL> where
    W: Word,
    SCLK: PinAssignment,
    MOSI: PinAssignment,
    MISO: PinAssignment,
    SSEL: PinAssignment
[src]

type Error = !

An enumeration of SPI errors

fn send(&mut self, word: W) -> Result<(), Error<!>>[src]

Sends a word (from 1 to 16 bits) over the SPI interface.

The embedded-hal contract calls for chip select to be managed separately by calling code, so send does not automatically assert and unassert the SSEL signal to delimit the transaction. When using this trait implementation, implement chip select as a generic digital output pin instead, because that is what embedded-hal device drivers expect.

fn read(&mut self) -> Result<W, Error<!>>[src]

Reads the word returned from the device after a send.

Calling read once for every send is mandatory in order to leave the SPI bus in a correct state for subsequent transfers.

Auto Trait Implementations

impl<MODE, SCLK, MOSI, MISO, SSEL> Send for SPI0<MODE, SCLK, MOSI, MISO, SSEL> where
    MISO: Send,
    MODE: Send,
    MOSI: Send,
    SCLK: Send,
    SSEL: Send

impl<MODE, SCLK, MOSI, MISO, SSEL> Unpin for SPI0<MODE, SCLK, MOSI, MISO, SSEL> where
    MISO: Unpin,
    MODE: Unpin,
    MOSI: Unpin,
    SCLK: Unpin,
    SSEL: Unpin

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<W, S> Transfer<W> for S where
    S: Default<W>,
    W: Clone
[src]

type Error = <S as FullDuplex<W>>::Error

Error type

impl<W, S> Write<W> for S where
    S: Default<W>,
    W: Clone
[src]

type Error = <S as FullDuplex<W>>::Error

Error type

impl<W, S> WriteIter<W> for S where
    S: Default<W>,
    W: Clone
[src]

type Error = <S as FullDuplex<W>>::Error

Error type