In development. It changes without notice.
Topic
I2C Bus
The board's internal I2C bus, and reading and writing the registers of a chip on it.
kleidos::
- See also
- GPIO & Buses
Files | |
| file | src/ |
| The memo of a chip probe, counting only what the chip said while its bus was up. | |
| file | src/ |
| Thin RAII helper for register access to an internal-bus I2C device. | |
| file | src/ |
| Selector and register I/O for the internal (on-board) I2C bus. | |
Classes | |
| class | kleidos:: |
| A chip probe's memo, gated on the bus being up. More about kleidos:: | |
| class | kleidos:: |
| RAII view of a single device on the internal I2C bus. More about kleidos:: | |
| struct | kleidos:: |
| Internal I2C pin map of this board. More about kleidos:: | |
Functions | |
| Pins | kleidos:: |
| Get this board's internal I2C pin map. | |
| bool | kleidos:: |
| Whether this board declares an internal I2C bus (its SDA, SCL and port all set in its configuration). | |
| bool | kleidos:: |
| Whether the internal bus exists right now (a beginPlatform that took, and no teardown since). | |
| bool | kleidos:: |
| Start (or restart) the bus with the platform facade. | |
| bool | kleidos:: |
| Read bytes from a register of an I2C device. | |
| bool | kleidos:: |
| Write bytes to a register of an I2C device. | |
| bool | kleidos:: |
| Clock one device of the bus at a rate of its own. | |
Variables | |
| constexpr uint32_t | kleidos:: |
| Default bus clock (100 kHz). | |
| constexpr uint32_t | kleidos:: |
| constexpr size_t | kleidos:: |
Function Documentation
beginPlatform() #
Start (or restart) the bus with the platform facade.
- Parameters
-
Name Direction Meaning frequencyHz in Bus clock in Hz. timeoutMs in Per-transfer timeout in milliseconds.
- Return values
-
Value Meaning true if the bus started. false on driver install or configuration failure.
configured() #
Whether this board declares an internal I2C bus (its SDA, SCL and port all set in its configuration).
- Return values
-
Value Meaning true The board's configuration gives the bus pins and a controller port. false It leaves any of them at -1, so beginPlatform has nothing to start (the LILYGO T-Deck's I2C devices are not on such a bus).
pins() #
Get this board's internal I2C pin map.
- Returns
- Struct containing sda, scl and port for this board.
readRegister() #
Read bytes from a register of an I2C device.
- Parameters
-
Name Direction Meaning address in Device I2C address (7-bit). reg in Register address to read from. data out Buffer receiving the read bytes. length in Number of bytes to read. frequencyHz in Bus clock in Hz. timeoutMs in Per-transfer timeout in milliseconds.
- Return values
-
Value Meaning true if the transfer completed without error. false on NACK, bus error, or timeout.
ready() #
Whether the internal bus exists right now (a beginPlatform that took, and no teardown since).
A chip that does not answer while this is false has said nothing about itself: the bus it would answer on is not there yet, or no longer (bus::
- Return values
-
Value Meaning true The bus is up and transfers can reach its devices. false It has not been started this boot, or was torn down.
setDeviceFrequency() #
Clock one device of the bus at a rate of its own.
The frequencyHz the register calls take is not applied per call: every device runs at the rate beginPlatform gave the bus until its driver asks for another here (bus::). The other devices keep their rate.
- Parameters
-
Name Direction Meaning address in Device I2C address (7-bit). frequencyHz in Its bus clock in Hz.
- Return values
-
Value Meaning true The device is clocked at frequencyHzfrom its next transfer.false The platform facade refused the rate (no device at addresson a started bus, or a rate it cannot set).
writeRegister() #
Write bytes to a register of an I2C device.
- Parameters
-
Name Direction Meaning address in Device I2C address (7-bit). reg in Register address to write to. data in Data bytes to write. length in Number of bytes to write. The whole write is one transaction, so a long one must fit timeoutMsat the device's bus clock.frequencyHz in Bus clock in Hz. timeoutMs in Per-transfer timeout in milliseconds.
- Return values
-
Value Meaning true if the transfer completed without error. false on NACK, bus error, or timeout.
Variable Documentation
kCopiedRegisterWriteBytes #
Longest payload writeRegister copies behind the register address into one stack buffer. A longer one goes out uncopied, as the second buffer of the same transaction.
kDefaultTimeoutMs #
Default per-transfer timeout.