Module rtc

Source
Available on crate feature unstable only.
Expand description

§RTC I2C driver

§Overview

This is the host driver for the RTC_I2C peripheral which is primarily for the ULP.

The RTC I2C peripheral always expects a slave sub-register address to be provided when reading or writing. This could make the RTC I2C peripheral incompatible with certain I2C devices or sensors which do not need any sub-register to be programmed. It also means a embedded_hal::i2c::I2c implementation cannot be provided.

§Configuration

The driver can be configured using the Config struct. To create a configuration, you can use the Config::default() method, and then modify the individual settings as needed, by calling with_* methods on the Config struct.

use core::time::Duration;

use esp_hal::i2c::rtc::Config;

let config = Config::default().with_timeout(Duration::from_micros(100));

You will then need to pass the configuration to I2c::new, and you can also change the configuration later by calling I2c::apply_config.

You will also need to specify the SDA and SCL pins when you create the driver instance.

use esp_hal::i2c::rtc::I2c;
// You need to configure the driver during initialization:
let mut i2c = I2c::new(
    peripherals.RTC_I2C,
    config,
    peripherals.GPIO3,
    peripherals.GPIO2,
)?;

// You can change the configuration later:
let new_config = config.with_timeout(Duration::from_micros(150));
i2c.apply_config(&new_config)?;

§Usage

// `u8` is automatically converted to `I2cAddress::SevenBit`. The device
// address does not contain the `R/W` bit!
const DEVICE_ADDR: u8 = 0x77;
const DEVICE_REG: u8 = 0x01;
let write_buffer = [0xAA];
let mut read_buffer = [0u8; 22];

i2c.write(DEVICE_ADDR, DEVICE_REG, &write_buffer)?;
i2c.read(DEVICE_ADDR, DEVICE_REG, &mut read_buffer)?;

Structs§

Config
I2C driver configuration
I2c
I2C (RTC) driver
Timing
I2C timings

Enums§

ConfigError
I2C-specific configuration errors
Error
I2C-specific transmission errors

Traits§

Scl
Trait representing the RTC_I2C SCL pin.
Sda
Trait representing the RTC_I2C SDA pin.