Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esp32 with I2C using BusManagerStd for threads #37

Open
enelson1001 opened this issue Jun 12, 2022 · 1 comment
Open

Esp32 with I2C using BusManagerStd for threads #37

enelson1001 opened this issue Jun 12, 2022 · 1 comment
Labels
question Further information is requested

Comments

@enelson1001
Copy link

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"

@Rahix
Copy link
Owner

Rahix commented Jun 13, 2022

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 Rahix added the question Further information is requested label Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants