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
impl Bulk
Sourcepub fn transfer(&mut self, target: u8, frame: &[u8]) -> Result<u8, BridgeError>
pub fn transfer(&mut self, target: u8, frame: &[u8]) -> Result<u8, BridgeError>
Adds a transfer.
§Arguments
target-TARGET_CONCENTRATORorTARGET_LISTENER.frame- the raw frame, target byte first, as the chip sees it. For a read it includes the dummy byte and room for the answer, asspi::readbuilds it.
§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);Sourcepub fn modify(
&mut self,
address: u16,
offset: u8,
width: u8,
value: u8,
) -> Result<u8, BridgeError>
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]);