shared-bus icon indicating copy to clipboard operation
shared-bus copied to clipboard

Esp32 with I2C using BusManagerStd for threads

Open enelson1001 opened this issue 2 years ago • 1 comments

I got lost on your example for using shared-bus with threads.

My cargo.toml file in [dependencies]

shared-bus = {git = "https://github.com/Rahix/shared-bus.git", version = "0.2.3", features = ["eh-alpha", "std"]}

My main.rs

    let peripherals = Peripherals::take().unwrap();
    let pins = peripherals.pins;

    // Create i2c interface on I2C0 with bus speed of 400kHz
    let i2c0 = peripherals.i2c0;
    let scl = pins.gpio22;
    let sda = pins.gpio21;
    let i2c_config = <i2c::config::MasterConfig as Default>::default().baudrate(400.kHz().into());
    let i2c_bus_0 =
        i2c::Master::<i2c::I2C0, _, _>::new(i2c0, i2c::MasterPins { sda, scl }, i2c_config)
            .unwrap();

    // Create a shared-bus for the I2C devices
    let i2c_bus_manager: &'static _ = shared_bus::new_std!(i2c_bus_0).unwrap();  <-------- ERROR IS HERE

My error

expected 1 argument, found 0
unexpected end of macro invocation
missing tokens in macro arguments

1. Sorry I am new to rust, what needs to be done to get rid of the error. 2. I tried xtensa feature but that failed with " cannot find macro llvm_asm in this scope"

enelson1001 avatar Jun 12 '22 22:06 enelson1001

Well the problem is you are not calling the macro correctly. Check the documentation for new_std!(), you need to state the type signature explicitly as well. The usual pattern would be something like:

type SclPin = [[[TYPE OF pins.gpio22]]];
type SdaPin = [[[TYPE OF pins.gpio21]]];
type I2cBus = i2c::Master<i2c::I2C0, SdaPin, SclPin>;

...

let i2c_bus_manager = shared_bus::new_std!(I2cBus = i2c_bus_0).unwrap();

Rahix avatar Jun 13 '22 09:06 Rahix