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

How to use i2c interface with esp-idf-hal? #6

Open
JohnTheCoolingFan opened this issue Dec 25, 2022 · 6 comments
Open

How to use i2c interface with esp-idf-hal? #6

JohnTheCoolingFan opened this issue Dec 25, 2022 · 6 comments

Comments

@JohnTheCoolingFan
Copy link
Contributor

esp-idf-hal is implementation of embedded-hal for esp32. I cannot find any type that implements i2c::Transactional from embedded_hal. Am I missing something?

@JohnTheCoolingFan JohnTheCoolingFan changed the title How to use with esp-idf-hal? How to use i2c interface with esp-idf-hal? Dec 25, 2022
@dimpolo
Copy link
Collaborator

dimpolo commented Dec 25, 2022

Thanks for the report!

I looked around the esp-idf-hal a bit, you're not missing anything 😃.

Basically we have three options here:

The one where I do the work:

I2CDriver does have an impl of the embedded-hal v1.0.0 version of the I2c trait and that trait includes a transaction method.
We could add a eh1 feature flag I2CInterface in terms of the new trait.

I definitely want to make this happen but I won't get to this until in a couple of weeks. (I would of course welcome a PR 😉)

The one where the esp crew does the work:

You could open an issue over there asking for an implementation of Transactional (or even write a PR yourself). They have been very helpful and open to suggestions in my experience.

The one where you do the work:

You can implement Interface yourself on a wrapper type of I2CDriver.

struct I2CWrapper<'a>(I2CDriver<'a>);

impl<'a> pn532::Interface for I2CWrapper<'a> {
    ...
}

You can have a look at https://github.com/WMT-GmbH/pn532/blob/master/src/i2c.rs#L30-L60. I'll be glad to help you out if questions come up.

@JohnTheCoolingFan
Copy link
Contributor Author

Thank you for such a great reply! I'll report it to esp crew and maybe do a PR, as I think that's an error from their side.

@liebman
Copy link

liebman commented Apr 28, 2024

Will be fixed "soon-ish": esp-rs/esp-hal#1505

@dimpolo
Copy link
Collaborator

dimpolo commented Apr 28, 2024

Thanks for your work!

@LimesKey
Copy link

LimesKey commented May 4, 2024

I'm having some issues doing this fix,

    struct I2CWrapper<'a>(I2cDriver<'a>);

    impl<'a> pn532::Interface for I2CWrapper<'a> {
        type Error = ErrorKind;

        fn write(&mut self, frame: &[u8]) -> Result<(), Self::Error> {
            I2CWrapper::write(self, frame)
        }

        fn wait_ready(&mut self) -> Poll<Result<(), Self::Error>> {
            I2CWrapper::wait_ready(self)
        }

        fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> {
            I2CWrapper::read(self, buf)
        }
    }

    let mut pn532 = Pn532::new(I2CWrapper(i2cdriver), config);
    if let Err(e) = pn532.process(&Request::sam_configuration(SAMMode::Normal, false), 0, 50.ms()){

I'm getting, the method process exists for struct Pn532<I2CWrapper<'_>, Config, _>, but its trait bounds were not satisfied the following trait bounds were not satisfied: esp_idf_svc::hal::i2c::config::Config: embedded_hal::timer::CountDown, on "process".

@liebman
Copy link

liebman commented May 5, 2024

Pn532 needs to implement for embedded-hal 1.0 traits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants