-
|
I imagine it should be possible to use both of these in the same project relatively easily since they're both official components, but I'm stumped. TSL2591 uses i2cdev to handle i2c communications internally, while esp_lcd uses the i2c drivers directly. if I initialize i2c with i2cdev_init() I get an error when using i2c_new_master_bus(), and vice versa if I initialize them in the opposite order. I can't just use one initialization, because i2cdev throws an error if I initialize via the drivers, and if I initialize via i2cdev I have no way to get the master bus handle to pass into my esp_lcd initialization. I think I must be missing something here, since I would imagine these components should work together just fine, but as far as i can tell at the moment I would need to rewrite how one of the components works to get them to coexist. How can I use both of these components together? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
|
tl;dr The answer is: you cannot.
We can rewrite |
Beta Was this translation helpful? Give feedback.
-
|
@quinkq any advice from your side? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @trombik, @jChereck I definetly agree that one should expect for esp-idf-lib and ESP-IDF I2C components to be working together. I've tried to devise a quick fix for you, however I really can't spare any time this week to test it properly: Add to i2cdev.h: Add to i2cdev.c: Usage: In theory this should unify I2C ecosystem where allowing mixing any esp-idf-lib sensor with any ESP-IDF component, so both TSL2591 and esp_lcd should work on the same I2C bus with proper thread synchronization. @trombik I might try adding PR in some near future once i get some spare time and proper testing setup. |
Beta Was this translation helpful? Give feedback.
tl;dr The answer is: you cannot.
i2cdev.hdoes NOT simply provide short-hand functions or thin wrappers of underlyingesp-idffunctions. It handles resource management and, most importantly, thread-safe operations with locking because the olderi2c.hfromesp-idfdoes not guarantee thread-safety. The neweri2c_master.hintroduced buses, devices and thread-safe functions, which is quite similar to whati2cdev.hhas been providing. Because two implementations do the same thing, you cannot mix them up.We can rewrite
i2cdev.hso that the drivers andi2c_master.hcan co-exist but it will break olderesp-idfversions. In addition,esp8266does not, and probably will not, havei2c_master.h.