Skip to content

I2cBusModule

Source: I2cBusModule.h

I2cBusModule

class I2cBusModule
src/core/system/I2cBusModule.h:33

Inherits: MoonModule

The board's I2C bus: its two pins, opened once and shared by every device on it, with the standard detect scan.

A device on the bus, such as AudioService's codec, names only its own address; the wires are stated here, once per board. A fixed System module, wired by code.

I2cBusModule card

Public Methods

virtual inline void defineControls() override : Declare the two bus pins, the scan button and the result readout.

virtual inline bool affectsPrepare(const char * name) const override : A pin change moves the bus, which the build sweep does through prepare.

virtual inline void prepare() override : Open the bus on the set pins, or close it while either is unset.

virtual inline void release() override : Close the bus this instance opened, the devices on it first.

virtual inline void onControlChanged(const char * controlName) override : Run a scan when the button is pressed.

More info

One bus, many devices

Two drivers each opening a bus on the same port collide the moment both are active, so the bus is opened here and the devices attach to it. Moving it to other pins releases what is attached first, and each device attaches again on its own. A scan names each answering address by the module driving it, as 0x18 Audio (ES8311); a claimed address that stays silent reads no answer.

The pins

They default to unused, so a board without an I2C device claims no GPIO. A board with a bus sets them from its catalog entry; on one whose bus pins drive something else, such as LED outputs, they stay unset.

Prior art: the scan mirrors MoonLight's, and the probe range follows Linux i2c-tools.