feat(firmware): support configurable SEN54 and SEN66 boards

Add the pinned Sensirion SEN66 driver, central sensor and board profiles, and a separate GPIO I2C bus for SEN66 with display. Preserve the original display layout and keep NOx and CO2 in InfluxDB. Include protocol tests, hardware workflow documentation and verified deployment results without credentials.
This commit is contained in:
root
2026-11-09 21:44:04 +00:00
parent 45b05d045a
commit 69bb47dda1
27 changed files with 2634 additions and 111 deletions
@@ -11,6 +11,9 @@
#include <inttypes.h>
#include "sensirion_i2c_esp32_config.h"
#include "hardware_config.h"
#include "sensor_soft_i2c.h"
#include "esp_rom_sys.h"
static const char* TAG = "sensirion_i2c_hal";
@@ -31,6 +34,45 @@ static i2c_dev_t dev = {0};
static struct esp32_i2c_config i2c_cfg = {0};
static esp_err_t i2c_ok = ESP_OK;
#if NANOPSX_SENSOR_SOFT_I2C
static SemaphoreHandle_t soft_mutex;
static void soft_sda(void *ctx, int release) {
struct esp32_i2c_config *p = ctx;
gpio_set_level(p->sda, release);
}
static void soft_scl(void *ctx, int release) {
struct esp32_i2c_config *p = ctx;
gpio_set_level(p->scl, release);
}
static int soft_read_sda(void *ctx) {
return gpio_get_level(((struct esp32_i2c_config *)ctx)->sda);
}
static int soft_read_scl(void *ctx) {
return gpio_get_level(((struct esp32_i2c_config *)ctx)->scl);
}
static void soft_delay(void *ctx, unsigned us) {
(void)ctx;
esp_rom_delay_us(us);
}
static int8_t soft_transfer(uint8_t address, uint8_t *data, uint16_t count, bool read) {
if (!soft_mutex || !xSemaphoreTake(soft_mutex, pdMS_TO_TICKS(1000)))
return SENSIRION_I2C_HAL_ERROR;
const sensor_soft_i2c_t port = {
.context = &i2c_cfg, .sda = soft_sda, .scl = soft_scl,
.read_sda = soft_read_sda, .read_scl = soft_read_scl,
.delay_us = soft_delay,
.half_period_us = (1000000U + 2 * i2c_cfg.freq - 1) / (2 * i2c_cfg.freq),
.stretch_timeout_us = 5000,
};
int rc = sensor_soft_i2c_transfer(&port, address, data, count, read);
xSemaphoreGive(soft_mutex);
i2c_ok = rc == 0 ? ESP_OK : ESP_FAIL;
if (rc) ESP_LOGW(TAG, "GPIO I2C %s failed addr=0x%02x rc=%d",
read ? "read" : "write", address, rc);
return rc == 0 ? 0 : SENSIRION_I2C_HAL_ERROR;
}
#endif
static int8_t sensirion_map_esp_err(esp_err_t err) {
return (err == ESP_OK) ? (int8_t)NO_ERROR : SENSIRION_I2C_HAL_ERROR;
}
@@ -40,6 +82,9 @@ static int8_t sensirion_map_esp_err(esp_err_t err) {
* Optional for single-bus setups.
*/
int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx) {
#if NANOPSX_SENSOR_SOFT_I2C
return bus_idx == i2c_cfg.port ? NO_ERROR : SENSIRION_I2C_HAL_ERROR;
#endif
/*
* NOTE:
* - This only switches the I2C port number.
@@ -70,6 +115,30 @@ esp_err_t sensirion_i2c_esp32_ok(void) {
* communication.
*/
void sensirion_i2c_hal_init(void) {
#if NANOPSX_SENSOR_SOFT_I2C
if (!i2c_cfg.freq || i2c_cfg.freq > 100000 ||
!GPIO_IS_VALID_OUTPUT_GPIO(i2c_cfg.sda) || !GPIO_IS_VALID_OUTPUT_GPIO(i2c_cfg.scl) ||
i2c_cfg.sda == i2c_cfg.scl) {
i2c_ok = ESP_ERR_INVALID_ARG;
return;
}
gpio_set_level(i2c_cfg.sda, 1);
gpio_set_level(i2c_cfg.scl, 1);
gpio_config_t pins = {
.pin_bit_mask = (1ULL << i2c_cfg.sda) | (1ULL << i2c_cfg.scl),
.mode = GPIO_MODE_INPUT_OUTPUT_OD,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
i2c_ok = gpio_config(&pins);
if (i2c_ok != ESP_OK) return;
soft_mutex = xSemaphoreCreateMutex();
if (!soft_mutex) { i2c_ok = ESP_ERR_NO_MEM; return; }
ESP_LOGI(TAG, "GPIO I2C ready SDA=%d SCL=%d target=%lu Hz; touch uses hardware I2C",
i2c_cfg.sda, i2c_cfg.scl, (unsigned long)i2c_cfg.freq);
return;
#endif
memset(&dev, 0, sizeof(dev));
// Minimal sanity check
@@ -111,6 +180,12 @@ void sensirion_i2c_hal_init(void) {
* Release all resources initialized by sensirion_i2c_hal_init().
*/
void sensirion_i2c_hal_free(void) {
#if NANOPSX_SENSOR_SOFT_I2C
gpio_set_level(i2c_cfg.sda, 1);
gpio_set_level(i2c_cfg.scl, 1);
if (soft_mutex) { vSemaphoreDelete(soft_mutex); soft_mutex = NULL; }
return;
#endif
esp_err_t err = i2c_dev_delete_mutex(&dev);
if (err != ESP_OK) {
ESP_LOGW(TAG, "i2c_dev_delete_mutex failed: %s", esp_err_to_name(err));
@@ -126,6 +201,9 @@ int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
if (count > 0 && data == NULL) {
return SENSIRION_I2C_HAL_ERROR;
}
#if NANOPSX_SENSOR_SOFT_I2C
return soft_transfer(address, data, count, true);
#endif
dev.addr = address;
@@ -163,6 +241,9 @@ int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data, uint16_t co
if (count > 0 && data == NULL) {
return SENSIRION_I2C_HAL_ERROR;
}
#if NANOPSX_SENSOR_SOFT_I2C
return soft_transfer(address, (uint8_t *)data, count, false);
#endif
dev.addr = address;