pub struct I2c<'d> { /* private fields */ }Available on crate feature
unstable only.Expand description
I2C (RTC) driver
§Example
use esp_hal::i2c::rtc::{Config, I2c};
let mut i2c = I2c::new(
peripherals.RTC_I2C,
Config::default(),
peripherals.GPIO1,
peripherals.GPIO2,
)?;
let mut data = [0u8; 22];
i2c.read(DEVICE_ADDR, 0xaa, &mut data)?;Implementations§
Source§impl<'d> I2c<'d>
impl<'d> I2c<'d>
Sourcepub fn new(
i2c: RTC_I2C<'d>,
config: Config,
sda: impl Sda + 'd,
scl: impl Scl + 'd,
) -> Result<Self, ConfigError>
pub fn new( i2c: RTC_I2C<'d>, config: Config, sda: impl Sda + 'd, scl: impl Scl + 'd, ) -> Result<Self, ConfigError>
Create a new I2C (RTC) instance.
§Errors
A crate::i2c::rtc::ConfigError variant will be returned if bus frequency or timeout
passed in config is invalid.
§Example
use esp_hal::i2c::rtc::{Config, I2c};
let i2c = I2c::new(
peripherals.RTC_I2C,
Config::default(),
peripherals.GPIO1,
peripherals.GPIO2,
)?;Sourcepub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
Applies a new configuration.
§Errors
A crate::i2c::rtc::ConfigError variant will be returned if bus frequency or timeout
passed in config is invalid.
§Example
use core::time::Duration;
use esp_hal::i2c::rtc::{Config, I2c};
let mut i2c = I2c::new(
peripherals.RTC_I2C,
Config::default(),
peripherals.GPIO1,
peripherals.GPIO2,
)?;
i2c.apply_config(&Config::default().with_timeout(Duration::from_micros(100)))?;Sourcepub fn write(
&mut self,
address: u8,
register: u8,
data: &[u8],
) -> Result<(), Error>
pub fn write( &mut self, address: u8, register: u8, data: &[u8], ) -> Result<(), Error>
Writes bytes to slave with given address and register.
§Example
use esp_hal::i2c::rtc::{Config, I2c};
const DEVICE_ADDR: u8 = 0x77;
let mut i2c = I2c::new(
peripherals.RTC_I2C,
Config::default(),
peripherals.GPIO1,
peripherals.GPIO2,
)?;
i2c.write(DEVICE_ADDR, 2, &[0xaa])?;Sourcepub fn read(
&mut self,
address: u8,
register: u8,
data: &mut [u8],
) -> Result<(), Error>
pub fn read( &mut self, address: u8, register: u8, data: &mut [u8], ) -> Result<(), Error>
Writes bytes to slave with given address and register.
§Example
use esp_hal::i2c::rtc::{Config, I2c};
const DEVICE_ADDR: u8 = 0x77;
let mut i2c = I2c::new(
peripherals.RTC_I2C,
Config::default(),
peripherals.GPIO1,
peripherals.GPIO2,
)?;
let mut data = [0u8; 22];
i2c.read(DEVICE_ADDR, 7, &mut data)?;