namespace: ashet.io.i2c
Documentation
Functions and types related to the I²C bus.
Types
System Calls
syscall enumerate(in list: ?[]io.i2c.BusID, out count: usize)syscall query_metadata(in id: io.i2c.BusID, in name_buf: ?[]u8, out name_len: usize)Queries information about the given serial port id.
syscall open(in id: io.i2c.BusID, out bus: io.i2c.Bus)
Asynchronous Operations
async_call Execute(in bus: io.i2c.Bus, in sequence: []io.i2c.Operation, out count: usize)Performs a sequence of I²C operations on the bus without interruption.
This function allows to ping devices, read or write data from/to the devices.
The operations are performed first-to-last without interruption. If an operation fails, the sequence will be aborted.
Lore:
This function was introduced instead of separate read and write functions, as it's sometimes necessary for certain I²C ICs (like EEPROMs) to have "atomic" read-after-write operations.
As both a singular read and a singular write can be expressed as a batch of one operation, this is the only available function on the I²C bus.
**Example:** Typical I²C EEPROMs have an internally maintained "memory cursor" which is advanced for every read operation. All write operations will update the cursor also for read operations.
This means that in an OS context, where scheduling can interrupt our process, performing a split "update cursor" write operation and "read data" read operation can be interrupted by another process also scheduling writes in between. This means that after we've set up our memory cursor to the desired address another process would change that before we read and we'll read data from the wrong memory location.
To prevent such a situation, this batch interface was introduced.