Skip to content

turgu1/slave

Repository files navigation

ESP32 I2C Slave Driver

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.

Features

  • 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.)

Supported Chips

  • ESP32
  • ESP32-C2
  • ESP32-C3
  • ESP32-C6
  • ESP32-H2
  • ESP32-S2
  • ESP32-S3

Usage

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"] }

Example

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]);
    }
}

Building

Quick Start

For ESP32-C3 (RISC-V):

cargo build --release --features esp32c3

For Xtensa chips (ESP32, ESP32-S2, ESP32-S3), see XTENSA.md for setup instructions.

Documentation

  • Quick Start: See QUICKSTART.md
  • Building: See BUILDING.md
  • Xtensa Setup: See XTENSA.md
  • Migration Guide: See MIGRATION.md

License

Licensed under either of:

at your option.

Contribution

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.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages