expression

Distinguish I2C address from wire address byte

For ordinary seven-bit I2C addressing, the wire address byte includes the direction bit. The embedded-hal I2c API accepts the unshifted address; the controller constructs the wire address. This pure model computes the wire byte for a hypothetical nonreserved address range and is not an address scanner. Expected host stdout (not executed): write: 64, read: 65 Common mistake: Passing an already shifted address to the seven-bit HAL API.

Formal Syntax & Structure

rust syntaxrust
address << 1 | read_bit

Working Example

Example Snippetrust
#![no_std]pub fn wire_address(addr: u8, read: bool) -> Option<u8> {    if !(0x08..=0x77).contains(&addr) { return None; }    Some((addr << 1) | u8::from(read))}
Rust Reference