kernel::hil::spi::cs

Trait IntoChipSelect

Source
pub trait IntoChipSelect<T, POLARITY> {
    // Required method
    fn into_cs(self) -> T;
}
Expand description

A type that can be converted to the appropriate type for SpiMaster::ChipSelect for a particular POLARITY.

Instantiating a driver for any SPI peripheral should require a type that implements IntoChipSelect. That enforces that whatever object is used as the chip select can support the correct polarity for the particular SPI peripheral. This is mostly commonly handled by the component for the peripheral, which requires an object with type IntoChipSelect and then converts the object to the SpiMaster::ChipSelect type.

§Examples:

Some SPI host controllers only support active low or active high chip select pins. Such a controller might provide a unit implementation of this trait only for the ActiveLow marker.

use kernel::hil::spi::cs::*;

#[derive(Copy, Clone)]
enum PeripheralSelect {
    Peripheral0,
    Peripheral1,
}

impl IntoChipSelect<PeripheralSelect, ActiveLow> for PeripheralSelect {
    fn into_cs(self) -> Self { self }
}

Many other controllers can handle both active low and active high chip select pins, in which case, they should implement both the ActiveLow and ActiveHigh variants, for example, using the ChipSelectPolar wrapper struct (which implements both).

Required Methods§

Source

fn into_cs(self) -> T

Implementations on Foreign Types§

Source§

impl<'a, P: Output, A: ChipSelectActivePolarity> IntoChipSelect<ChipSelectPolar<'a, P>, A> for &'a P

Source§

fn into_cs(self) -> ChipSelectPolar<'a, P>

Implementors§