@johntalton/and-other-delights
v8.6.6
Published
A simple set of abstraction and helpers useful when working with I²C
Readme
And Other Delights
A simple set of abstraction and helpers useful when working with I²C
Contents
:book: I2CBus
This is the top level interface for I2CBus implementations. There are several concert version that conform to this, and a wide range of other abstraction that can provided capabilities around it.
- MCP221 can provide I²C interface
- The Excamera Labs I2CDriver also exposes a
I2CBus - NodeJS version based on
i2c-busI2CBusFivdi - A Virtualized Managed
I2CBusfor the TCA9548 Multiplexer - A Proxy implementation over
MessagePortin order to provide further abstraction, and a Web Service that uses it.
:book: I2CAddressedBus
An addressed wrapper for I²C bus interactions.
Providing a I2CAddressedBus interface to the device and wrapping an I2CBus.
const ab = await I2CAddressedBus.from(i2cbus, busAddress)
const buffer = await ab.readI2cBlock(command, length):book: I2CBusSoft16
Some I2CBus concret implementation do not directly support 16-bit register addresses in the readI2cBlock and writeI2cBlock methods. This wrapper bus can be used to provided that feature by directly calling i2cWrite and i2cRead directly.
This may introduce differences in the interaction and timing of specific devices or underlying implementation expectation.
const bus = /* I2CBus that may-or-may-not implement 16-bit addresses */
const bus16 = new I2CBusSoft16(bus)
// read 8 bytes from a 16-bit address 0x0402
// this will only use software version
// if not supported by the underlying `bus`
const buffer = await bus16.readI2cBlock([ 4, 2 ], 8)