Add bh1750, aht20, sgp40 drivers unified on native i2c_master API

Forked from managed_components (espressif/bh1750, espressif/aht20,
esp-idf-lib/sgp40) and rewrote aht20/sgp40 internals to use
driver/i2c_master.h directly instead of the i2c_bus and i2cdev
wrapper components, so all three sensors share one create/delete
handle pattern over a single i2c_master_bus_handle_t.
This commit is contained in:
Julien Lazarewicz
2026-07-05 23:27:50 +02:00
commit e940c767a6
19 changed files with 2441 additions and 0 deletions

47
README.md Normal file
View File

@@ -0,0 +1,47 @@
# espidf_i2c
Forked/rewritten ESP-IDF I2C sensor drivers, unified onto the native
`driver/i2c_master.h` API (ESP-IDF >= 5.3) so every sensor shares the same
handle lifecycle instead of each vendor bringing its own I2C abstraction
(`i2c_bus`, `i2cdev`, etc.).
## Common API convention
Every driver in this repo follows the same shape:
```c
typedef void *xxx_handle_t;
esp_err_t xxx_create(i2c_master_bus_handle_t bus_handle, uint8_t dev_addr, xxx_handle_t *handle_ret);
esp_err_t xxx_delete(xxx_handle_t handle);
// ... device-specific read/measure functions taking xxx_handle_t
```
Callers create one `i2c_master_bus_handle_t` via `i2c_new_master_bus()` and
pass it to each sensor's `_create()`, which internally calls
`i2c_master_bus_add_device()`. No sensor wraps the bus a second time.
## Components
- `bh1750/` — ambient light sensor. Already used the native API upstream;
relocated here unchanged.
- `aht20/` — temperature/humidity sensor. Rewritten from Espressif's
`i2c_bus` component onto `i2c_master_transmit`/`i2c_master_receive`.
- `sgp40/` — VOC index sensor. Rewritten from esp-idf-lib's `i2cdev`
component onto `i2c_master_transmit`/`i2c_master_receive`; the Sensirion
VOC algorithm files are carried over unmodified (no I2C dependency).
## Using from a project
```yaml
dependencies:
laz/bh1750:
git: https://git.jeese.fr/laz/espidf_i2c.git
path: bh1750
laz/aht20:
git: https://git.jeese.fr/laz/espidf_i2c.git
path: aht20
laz/sgp40:
git: https://git.jeese.fr/laz/espidf_i2c.git
path: sgp40
```