A Rust crate providing I2C slave mode driver implementation for ESP32 family of processors using esp-hal 1.0.0-rc.0.
Note: This crate uses esp-hal 1.0.0-rc.0. The examples are templates and need to be adjusted for your specific chip and esp-hal API. See
MIGRATION.md
for details.
- I2C slave mode support for ESP32 family processors
- Configurable slave address (7-bit and 10-bit)
- Interrupt-driven operation
- Read/Write buffer management
- Support for multiple ESP32 variants (ESP32, ESP32-C3, ESP32-C6, ESP32-S2, ESP32-S3, etc.)
- ESP32
- ESP32-C2
- ESP32-C3
- ESP32-C6
- ESP32-H2
- ESP32-S2
- ESP32-S3
Add this to your Cargo.toml
:
[dependencies]
esp32-i2c-slave = "0.1"
Enable the feature for your specific chip:
[dependencies]
esp32-i2c-slave = { version = "0.1", features = ["esp32c3"] }
use esp32_i2c_slave::{I2cSlave, I2cSlaveConfig};
// Note: Actual initialization depends on your chip and esp-hal version
// See examples/ directory for templates
fn main() -> ! {
let peripherals = esp_hal::init(Default::default());
// Initialize your GPIO pins (chip-specific)
// let sda = ...;
// let scl = ...;
// Configure I2C slave
let config = I2cSlaveConfig::default()
.with_slave_address(0x55)
.with_timeout(50000);
let mut i2c_slave = I2cSlave::new(
peripherals.I2C0,
sda, // Your SDA pin
scl, // Your SCL pin
config,
);
loop {
// Handle I2C slave operations
let mut buffer = [0u8; 128];
let count = i2c_slave.read_bytes(&mut buffer);
if count > 0 {
// Process received data
println!("Received: {:?}", &buffer[..count]);
}
// Write data to send buffer
i2c_slave.write_bytes(&[0x01, 0x02, 0x03]);
}
}
For ESP32-C3 (RISC-V):
cargo build --release --features esp32c3
For Xtensa chips (ESP32, ESP32-S2, ESP32-S3), see XTENSA.md
for setup instructions.
- Quick Start: See
QUICKSTART.md
- Building: See
BUILDING.md
- Xtensa Setup: See
XTENSA.md
- Migration Guide: See
MIGRATION.md
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.