Expand description
The C ABI for the bus layer: one I2C bus that a program and every driver on it share.
A bus is the kernel’s adapter on a Linux board, a set of simulated parts, or a script of
the transfers a driver is expected to make, and the same calls work on each: a write, a
read, and a write then a read in one transaction, which is how a register is read. A
driver built on a bus, such as the BME280 in crate::sensors_driver, holds a share of
it, so the caller keeps its own handle, reads back what a simulated part holds after a
driver wrote to it, and frees its handle whenever it likes; the bus closes when the last
holder lets go.
A part and a script are built here and copied onto a bus, so the handles that built them
stay the caller’s to free. Every failed transfer returns PamojaStatus::Io with the
reason in the last error message: nothing answered at the address, the script expected
something else, or the kernel’s own words for what went wrong.
A simulated part is one of three kinds, and one handle holds any of them:
PAMOJA_I2C_PART_BYTES, registers a byte wide, as Bosch’s parts have;
PAMOJA_I2C_PART_WORDS, registers sixteen bits wide, as Texas Instruments’ parts have;
and PAMOJA_I2C_PART_COMMANDS, commands that leave replies, as Sensirion’s parts take.
A call made on the wrong kind of part is refused with PamojaStatus::InvalidArgument,
or reads as zero where the call returns a value.
Structs§
- Pamoja
I2cBus - One I2C bus, shared with every driver built on it. Opaque; release it with
pamoja_i2c_bus_free. - Pamoja
I2cPart - A part that is not there, answering from its registers or its commands. Opaque; release it
with
pamoja_i2c_part_free. - Pamoja
I2cScript - The transfers a driver is expected to make, in order, and the replies. Opaque; release it
with
pamoja_i2c_script_free.
Constants§
- PAMOJA_
I2C_ BUS_ ADAPTER - A bus kind: the kernel’s adapter, with real parts on real wires.
- PAMOJA_
I2C_ BUS_ SCRIPTED - A bus kind: a script of the transfers a driver is expected to make.
- PAMOJA_
I2C_ BUS_ SIMULATED - A bus kind: simulated parts answering from their registers.
- PAMOJA_
I2C_ FAULT_ ARBITRATION_ LOSS - A scripted failure: another controller won the bus.
- PAMOJA_
I2C_ FAULT_ BUS - A scripted failure: a bus error, such as a misplaced start or stop condition.
- PAMOJA_
I2C_ FAULT_ NO_ ACKNOWLEDGE - A scripted failure: a missing acknowledge, with no telling whether of the address or data.
- PAMOJA_
I2C_ FAULT_ NO_ ACKNOWLEDGE_ ADDRESS - A scripted failure: nothing acknowledged the address.
- PAMOJA_
I2C_ FAULT_ NO_ ACKNOWLEDGE_ DATA - A scripted failure: the part did not acknowledge a data byte.
- PAMOJA_
I2C_ FAULT_ OTHER - A scripted failure of no more particular kind.
- PAMOJA_
I2C_ FAULT_ OVERRUN - A scripted failure: data arrived faster than it was taken.
- PAMOJA_
I2C_ PART_ BYTES - A part kind: 256 registers a byte wide.
- PAMOJA_
I2C_ PART_ COMMANDS - A part kind: commands, each leaving the reply it was given for a read to take.
- PAMOJA_
I2C_ PART_ WORDS - A part kind: 256 registers sixteen bits wide, each traveling most significant byte first.
Functions§
- pamoja_
i2c_ ⚠bus_ attach - Puts a copy of a part of any kind on a simulated bus, in place of any part already at its address.
- pamoja_
i2c_ ⚠bus_ free - Releases the caller’s share of a bus. The bus closes when no driver holds it either. A null pointer is ignored.
- pamoja_
i2c_ ⚠bus_ kind - Returns what answers on a bus.
- pamoja_
i2c_ ⚠bus_ open - Opens the kernel’s I2C adapter, such as
/dev/i2c-1on a Raspberry Pi. - pamoja_
i2c_ ⚠bus_ part - Copies what a simulated part holds now, with whatever drivers have written to it.
- pamoja_
i2c_ ⚠bus_ read - Reads bytes from a part, in one transaction.
- pamoja_
i2c_ ⚠bus_ remaining - Reports how many steps a scripted bus has left.
- pamoja_
i2c_ ⚠bus_ scripted - Creates a bus that plays a script and refuses any transfer that is not its next step.
- pamoja_
i2c_ bus_ simulated - Creates a simulated bus with no parts on it yet;
pamoja_i2c_bus_attachputs them on. - pamoja_
i2c_ ⚠bus_ transfers - Returns how many transfers have been made on a bus, by the caller and every driver on it, including any that failed.
- pamoja_
i2c_ ⚠bus_ waited_ micros - Returns how long the drivers on a bus have asked to wait.
- pamoja_
i2c_ ⚠bus_ write - Writes bytes to a part, in one transaction.
- pamoja_
i2c_ ⚠bus_ write_ read - Writes bytes to a part and reads its reply in one transaction, with a repeated start between them, which is how a register is read.
- pamoja_
i2c_ command_ part_ new - Creates a part answering at one address that takes commands and has been given no replies
yet. A write sends a command and any arguments after it; a read takes the reply that
command left, once, padded with
0xFF; a read with no reply waiting is not acknowledged. - pamoja_
i2c_ ⚠part_ address - Returns the address a part answers to.
- pamoja_
i2c_ ⚠part_ answer - Gives a part that takes commands the reply one command leaves, in place of any reply given before.
- pamoja_
i2c_ ⚠part_ free - Releases a part. A null pointer is ignored.
- pamoja_
i2c_ ⚠part_ kind - Returns which kind of part a handle holds.
- pamoja_
i2c_ ⚠part_ load - Puts bytes in a part whose registers are a byte wide, from a register on. Past the last register they wrap to the first.
- pamoja_
i2c_ part_ new - Creates a part answering at one address from 256 registers a byte wide, every one reading zero.
- pamoja_
i2c_ ⚠part_ read - Reads consecutive registers of a part whose registers are a byte wide, from one register on.
- pamoja_
i2c_ ⚠part_ read_ only - Marks bits of one register of a part whose registers are sixteen bits wide as the part’s to set: a driver’s write leaves them as the part holds them, as a conversion-ready flag is.
- pamoja_
i2c_ ⚠part_ received - Copies one write a part that takes commands received: a command and any arguments after it.
- pamoja_
i2c_ ⚠part_ received_ count - Returns how many writes a part that takes commands has received.
- pamoja_
i2c_ ⚠part_ register - Reads what one register of a part whose registers are a byte wide holds.
- pamoja_
i2c_ ⚠part_ set_ word - Puts a value in one register of a part whose registers are sixteen bits wide, read-only bits included, the way the part itself would.
- pamoja_
i2c_ ⚠part_ transfers - Returns how many transfers a part has served.
- pamoja_
i2c_ ⚠part_ word - Reads what one register of a part whose registers are sixteen bits wide holds.
- pamoja_
i2c_ ⚠script_ fault - Adds a step: the next transfer to the address fails, the way a missing or busy part does.
- pamoja_
i2c_ ⚠script_ free - Releases a script. A null pointer is ignored.
- pamoja_
i2c_ ⚠script_ len - Returns how many steps a script holds.
- pamoja_
i2c_ script_ new - Creates an empty script.
- pamoja_
i2c_ ⚠script_ read - Adds a step: the driver reads from the address and receives the reply, whose length is the length it must ask for.
- pamoja_
i2c_ ⚠script_ write - Adds a step: the driver writes exactly these bytes to the address.
- pamoja_
i2c_ ⚠script_ write_ read - Adds a step: the driver writes these bytes and then reads the reply in one transaction, the shape of a register read.
- pamoja_
i2c_ word_ part_ new - Creates a part answering at one address from 256 registers sixteen bits wide, every one reading zero. A pointer byte names a register, a write of a word stores it and leaves the pointer where it was, and a read takes words from the pointer on.