Module i2c

Module i2c 

Source
Expand description

Raw I2C bus access: CMD_I2C_TRANSFER, CMD_I2C_SCAN, their common reply CMD_I2C_RESULT, and the two tables that describe what a host may address (PROP_I2C_BUSES, PROP_I2C_DEVICES).

A transfer is one bus transaction with the semantics of embedded-hal 1.0’s I2c::transaction: a START, the address, the operations in order with a repeated START on each change of direction and no restart between consecutive operations of the same direction, and one STOP at the end. The wire form is

BUS (UINT8) | ADDR (UINT8) | OP | OP | ...
OP = KIND (UINT8: 0 write, 1 read) | LEN (PUI) | [LEN data octets, write only]

This module validates structure and the protocol’s own rules (a 7-bit address, a known kind, no empty operations, at least one operation). The per-bus limits a device advertises—how much data and how many operations one transfer may carry—are the device’s to enforce, since only it knows which bus is meant.

Structs§

BusInfo
One PROP_I2C_BUSES item.
DeviceInfo
One PROP_I2C_DEVICES item.
Ops
The operations of a transfer, decoded one at a time from their wire form. Yields an error and then ends when the list is malformed, so a device validates the whole list before touching the bus.
ScanRequest
A CMD_I2C_SCAN request with an absent range resolved to the default.
TransferRequest
A CMD_I2C_TRANSFER request whose structure has been validated.
TransferShape
What a transfer amounts to, summed over its operations.

Enums§

I2cError
Why a request could not be honored, before any bus was touched.
Op
One operation of a transfer.
OpKind
The direction of one operation.

Constants§

ADDRESS_MAX
Largest 7-bit address.
NAME_MAX_LEN
Longest bus or device name this crate encodes.
RESULT_OVERHEAD
Octets a CMD_I2C_RESULT frame occupies beyond its payload: the header and the command identifier.
SCAN_DEFAULT_FIRST
First address a scan probes when the request names no range: the addresses below are reserved (general call, START byte, CBUS, and the high-speed master codes).
SCAN_DEFAULT_LAST
Last address a scan probes when the request names no range: the addresses above are reserved for 10-bit addressing and future use.

Functions§

buses
Decode a whole PROP_I2C_BUSES value.
devices
Decode a whole PROP_I2C_DEVICES value.
encode_result
Encode a CMD_I2C_RESULT frame carrying data: the octets a transfer read, or the addresses a scan found.
encode_scan
Encode a CMD_I2C_SCAN frame; range is None for the default.
encode_transfer
Encode a CMD_I2C_TRANSFER frame.