std1.0.0-beta-7 SafeC docs

std :: hal::i2c

Struct std::I2cBus

#include <std/hal/i2c.h> source

generic<C: I2cChip> struct I2cBus {
    &volatile unsigned int base;
    unsigned int speed;
    C chip;
}

Fields

§&volatile unsigned int basesource

MMIO base address

§unsigned int speedsource

bus speed in Hz

§C chipsource

Methods

§static struct I2cBus<C> new( &volatile unsigned int base, unsigned int speed, unsigned int clock_hz, )source · definition

Initialize an I2C master at base for speed Hz, from a clock_hz peripheral clock (STM32: the APB1 clock; ignored by I2cGeneric). The chip type comes from the target.

§int write(unsigned char addr, []const unsigned char data)source · definition

Write data to the 7-bit address addr. Returns I2C_OK on success.

§int read(unsigned char addr, []unsigned char data)source · definition

Read data.len bytes into data from device at addr. Returns I2C_OK on success.

§int write_read(unsigned char addr, []const unsigned char wr, []unsigned char rd)source · definition

Write, then read (e.g. a register address, then its value). Returns I2C_OK on success.

§int probe(unsigned char addr)source · definition

Probe: address the device with no data. Returns 1 if it acknowledges.