atomvm_gleam/i2c
Typed wrappers for AtomVM 0.7 i2c.
Upstream:
libs/avm_esp32/src/i2c.erl
(same export names on RP2/STM32 under avm_rp2 / avm_stm32).
Two write styles
Register write — write_bytes/4 (and read_bytes/4) are one-shot
transactions: they address a device, send a register/pointer byte, then
write or read a payload. Do not wrap them in
begin_transmission / end_transmission.
Transmission framing — begin_transmission → write_byte /
write_transmission_bytes → end_transmission builds a multi-byte write
by hand (useful when the first byte is not a simple register pointer, or
when streaming several bytes in one stop-bit-framed message).
write_bytes_to is the one-shot address+payload write without a register
byte (upstream i2c:write_bytes/3); also not framed.
Types
Bus open options. clock_speed_hz is required on AtomVM.
See i2c:open/1.
pub type Config {
Config(scl: Int, sda: Int, clock_speed_hz: Int)
}
Constructors
-
Config(scl: Int, sda: Int, clock_speed_hz: Int)
Values
pub fn begin_transmission(
bus: Bus,
address: Int,
) -> Result(Nil, Error)
Begin a framed write to address.
Follow with one or more write_byte / write_transmission_bytes calls,
then end_transmission. Not used with register write_bytes / read_bytes.
pub fn end_transmission(bus: Bus) -> Result(Nil, Error)
End a framed write started with begin_transmission.
pub fn read_bytes(
bus: Bus,
address: Int,
register: Int,
count: Int,
) -> Result(BitArray, Error)
Read count bytes from address at register (pointer byte).
One-shot; do not wrap in begin_transmission / end_transmission.
See i2c:read_bytes/4.
pub fn write_byte(bus: Bus, byte: Int) -> Result(Nil, Error)
Queue one byte inside an open transmission (begin_transmission …
end_transmission).
See i2c:write_byte/2.
pub fn write_bytes(
bus: Bus,
address: Int,
register: Int,
data: BitArray,
) -> Result(Nil, Error)
Write data to address at register (pointer byte).
One-shot register write (upstream i2c:write_bytes/4). Do not wrap in
begin_transmission / end_transmission; use those helpers when you need
a custom framed payload instead.
See i2c:write_bytes/4.
pub fn write_bytes_to(
bus: Bus,
address: Int,
data: BitArray,
) -> Result(Nil, Error)
Write data to address (no register pointer byte).
Upstream i2c:write_bytes/3. One-shot; do not wrap in transmission helpers.
See i2c:write_bytes/3.
pub fn write_transmission_bytes(
bus: Bus,
data: BitArray,
) -> Result(Nil, Error)
Queue a byte sequence inside an open transmission.
Upstream i2c:write_bytes/2.
See i2c:write_bytes/2.