Struct rppal::spi::Segment

source ·
#[repr(C)]
pub struct Segment<'a, 'b> { /* private fields */ }
Expand description

Part of a multi-segment transfer.

Segments are transferred using the Spi::transfer_segments method.

Construct a new Segment for a simultaneous (full-duplex) read/write transfer using new. For read operations without any outgoing data, use with_read. For write operations where any incoming data should be discarded, use with_write.

Implementations§

source§

impl<'a, 'b> Segment<'a, 'b>

source

pub fn new(read_buffer: &'a mut [u8], write_buffer: &'b [u8]) -> Segment<'a, 'b>

Constructs a new Segment with the default settings, and configures it for a simultaneous (full-duplex) read/write transfer.

For Segments that only require either a read or write operation, call with_read or with_write instead of new.

Spi::transfer_segments will only transfer as many bytes as the shortest of the two buffers contains.

By default, all customizable settings are set to 0, which means it uses the same values as set for Spi.

source

pub fn with_read(buffer: &mut [u8]) -> Segment<'_, '_>

Constructs a new Segment with the default settings, and configures it for a read operation.

Incoming data from the slave device is written to buffer. The total number of bytes read depends on the length of buffer. A zero-value byte is sent for every byte read.

By default, all customizable settings are set to 0, which means it uses the same values as set for Spi.

source

pub fn with_write(buffer: &[u8]) -> Segment<'_, '_>

Constructs a new Segment with the default settings, and configures it for a write operation.

Outgoing data from buffer is sent to the slave device. Any incoming data is discarded.

By default, all customizable settings are set to 0, which means it uses the same values as set for Spi.

source

pub fn with_settings( read_buffer: Option<&'a mut [u8]>, write_buffer: Option<&'b [u8]>, clock_speed: u32, delay: u16, bits_per_word: u8, ss_change: bool ) -> Segment<'a, 'b>

Constructs a new Segment with the specified settings.

These settings override the values set for Spi, and are only used for this specific segment.

If read_buffer is set to None, any incoming data is discarded.

If write_buffer is set to None, a zero-value byte is sent for every byte read.

If both read_buffer and write_buffer are specified, Spi::transfer_segments will only transfer as many bytes as the shortest of the two buffers contains.

clock_speed sets a custom clock speed in hertz (Hz).

delay sets a delay in microseconds (µs).

bits_per_word sets the number of bits per word. The Raspberry Pi currently only supports 8 bits per word.

ss_change changes how Slave Select behaves in between two segments (toggle SS), or after the final segment (keep SS active).

source

pub fn len(&self) -> usize

Returns the number of bytes that will be transferred.

If both a read buffer and write buffer are supplied, Spi::transfer_segments only transfers as many bytes as the shortest of the two buffers contains.

source

pub fn is_empty(&self) -> bool

Returns true if this segment won’t transfer any bytes.

source

pub fn clock_speed(&self) -> u32

Gets the custom clock speed in hertz (Hz) for this segment.

source

pub fn set_clock_speed(&mut self, clock_speed: u32)

Sets a custom clock speed in hertz (Hz) for this segment.

The SPI driver will automatically select the closest valid frequency.

By default, clock_speed is set to 0, which means it will use the same value as configured for Spi.

source

pub fn delay(&self) -> u16

Gets the delay in microseconds (µs) for this segment.

source

pub fn set_delay(&mut self, delay: u16)

Sets a delay in microseconds (µs) for this segment.

set_delay adds a delay at the end of this segment, before the (optional) Slave Select change.

By default, delay is set to 0.

source

pub fn bits_per_word(&self) -> u8

Gets the number of bits per word for this segment.

source

pub fn set_bits_per_word(&mut self, bits_per_word: u8)

Sets the number of bits per word for this segment.

The Raspberry Pi currently only supports 8 bit words.

By default, bits_per_word is set to 0, which means it will use the same value as configured for Spi.

source

pub fn ss_change(&self) -> bool

Gets the state of Slave Select change for this segment.

source

pub fn set_ss_change(&mut self, ss_change: bool)

Changes Slave Select’s behavior for this segment.

If ss_change is set to true, and this is not the last segment of the transfer, the Slave Select line will briefly change to inactive between this segment and the next. If this is the last segment, setting ss_change to true will keep Slave Select active after the transfer ends.

By default, ss_change is set to false.

Trait Implementations§

source§

impl<'a, 'b> Clone for Segment<'a, 'b>

source§

fn clone(&self) -> Segment<'a, 'b>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, 'b> Debug for Segment<'a, 'b>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, 'b> PartialEq<Segment<'a, 'b>> for Segment<'a, 'b>

source§

fn eq(&self, other: &Segment<'a, 'b>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> Copy for Segment<'a, 'b>

source§

impl<'a, 'b> Eq for Segment<'a, 'b>

source§

impl<'a, 'b> StructuralEq for Segment<'a, 'b>

source§

impl<'a, 'b> StructuralPartialEq for Segment<'a, 'b>

Auto Trait Implementations§

§

impl<'a, 'b> RefUnwindSafe for Segment<'a, 'b>

§

impl<'a, 'b> Send for Segment<'a, 'b>

§

impl<'a, 'b> Sync for Segment<'a, 'b>

§

impl<'a, 'b> Unpin for Segment<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for Segment<'a, 'b>

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.