Skip to main content

Bulk

Struct Bulk 

Source
pub struct Bulk { /* private fields */ }
Expand description

SPI transfers gathered into one order to the bridge.

Each transfer is an entry: who it is for, how long it is, and the raw frame the chip sees, target byte first, exactly as spi builds it. The bridge answers with every entry echoed and the bytes the chip clocked back in place of the frame, which is what Replies walks.

Implementations§

Source§

impl Bulk

Source

pub const fn new() -> Bulk

An empty order.

§Returns

Room for BULK_CHUNK bytes of entries.

Source

pub fn transfer(&mut self, target: u8, frame: &[u8]) -> Result<u8, BridgeError>

Adds a transfer.

§Arguments
§Returns

The entry’s identifier, which is its position, so the reply can be matched.

§Errors

BridgeError::TooMany when the order is full, by entries or by bytes.

§Examples
use pamoja_radios::sx1302::bridge::{Bulk, TARGET_CONCENTRATOR};
use pamoja_radios::sx1302::spi;

let mut bulk = Bulk::new();
let frame = spi::write(spi::TARGET_CONCENTRATOR, 0x5b00, 0x01);
bulk.transfer(TARGET_CONCENTRATOR, &frame).unwrap();

// Identifier, kind, target, the frame's length, then the frame itself.
assert_eq!(&bulk.as_bytes()[..5], &[0, 0x01, 0, 0, 4]);
assert_eq!(&bulk.as_bytes()[5..], &frame);
Source

pub fn modify( &mut self, address: u16, offset: u8, width: u8, value: u8, ) -> Result<u8, BridgeError>

Adds a change to some bits of one concentrator register, done on the bridge.

The bridge reads the register, replaces the field, and writes it back, which saves the host a round trip on a register it shares with something else.

§Arguments
  • address - the register.
  • offset - which bit the field starts at.
  • width - how many bits it spans.
  • value - what to put there, right aligned.
§Returns

The entry’s identifier.

§Errors

BridgeError::TooMany when the order is full.

§Examples
use pamoja_radios::sx1302::bridge::Bulk;

let mut bulk = Bulk::new();
bulk.modify(0x5b21, 4, 2, 0b11).unwrap();

// A two bit field at bit four is the mask 0x30, and the value moves up to meet it.
assert_eq!(bulk.as_bytes(), &[0, 0x02, 0x5b, 0x21, 0x30, 0x30]);
Source

pub fn as_bytes(&self) -> &[u8] ⓘ

The entries, as the order carries them.

§Returns

The bytes that follow the header.

Source

pub const fn entries(&self) -> u8

How many entries are in the order.

§Returns

The count.

Source

pub const fn is_empty(&self) -> bool

Whether the order holds nothing yet.

§Returns

Whether there are no entries.

Source

pub const fn header(&self, id: u8) -> Header

The header this order goes out under.

§Arguments
  • id - the message identifier to use.
§Returns

The header.

Source

pub fn clear(&mut self)

Starts over.

Trait Implementations§

Source§

impl Clone for Bulk

Source§

fn clone(&self) -> Bulk

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bulk

Source§

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

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

impl Default for Bulk

Source§

fn default() -> Bulk

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Bulk

§

impl RefUnwindSafe for Bulk

§

impl Send for Bulk

§

impl Sync for Bulk

§

impl Unpin for Bulk

§

impl UnsafeUnpin for Bulk

§

impl UnwindSafe for Bulk

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.