Skip to main content

with_field

Function with_field 

Source
pub const fn with_field(byte: u8, offset: u8, width: u8, value: u8) -> u8
Expand description

Puts a value into the bits a register holds, leaving the rest of the byte alone.

A register narrower than a byte shares that byte with its neighbors, so writing one means reading the byte, replacing those bits, and writing it back. This is the middle step.

§Arguments

  • byte - the byte as it reads now.
  • offset - which bit the field starts at.
  • width - how many bits it spans.
  • value - what to put there.

§Returns

The byte to write back.

§Examples

use pamoja_radios::sx1302::spi::with_field;

// Setting the host programming bit leaves the clock enable beside it untouched.
assert_eq!(with_field(0b0001_0000, 1, 1, 1), 0b0001_0010);