diff --git a/components/hal_temp/CMakeLists.txt b/components/hal_temp/CMakeLists.txt index e9f3dfa..eea230f 100644 --- a/components/hal_temp/CMakeLists.txt +++ b/components/hal_temp/CMakeLists.txt @@ -3,8 +3,11 @@ set(priv_inc) set(priv_req driver) if(IDF_TARGET STREQUAL "esp32") - list(APPEND srcs wroom/hal_temp.c) + list(APPEND srcs hal_temp.c) list(APPEND priv_req board_wroom onewire_bus) +elseif(IDF_TARGET STREQUAL "esp32s3") + list(APPEND srcs hal_temp.c) + list(APPEND priv_req board_jc4827w543 onewire_bus) else() list(APPEND srcs stub/hal_temp.c) endif() diff --git a/components/hal_temp/wroom/hal_temp.c b/components/hal_temp/hal_temp.c similarity index 86% rename from components/hal_temp/wroom/hal_temp.c rename to components/hal_temp/hal_temp.c index f57baf9..13384bd 100644 --- a/components/hal_temp/wroom/hal_temp.c +++ b/components/hal_temp/hal_temp.c @@ -8,8 +8,9 @@ #include "freertos/task.h" #include "onewire_bus.h" +#include "board.h" +#include "hal_temp.h" -#define PIN_DS 13 #define TEMP_OFFSET 0.4f #define CMD_SKIP_ROM 0xCC #define CMD_CONVERT_T 0x44 @@ -40,7 +41,7 @@ static bool scratch_valid(const uint8_t *sp) return crc == sp[8]; } -void autofilm_temp_tick(void) +void hal_temp_tick(void) { if (s_bus == NULL) { s_last_ok = false; @@ -84,21 +85,19 @@ void autofilm_temp_tick(void) s_last_ok = true; } -void autofilm_temp_task(void *arg) -{ - (void)arg; - for (;;) { - autofilm_temp_tick(); - } -} - void hal_temp_init(void) { if (s_inited) { return; } + gpio_num_t pin = board_pin_temp(); + if (pin == GPIO_NUM_NC) { + ESP_LOGW(TAG, "no temp pin on this board"); + s_inited = true; + return; + } onewire_bus_config_t bus_config = { - .bus_gpio_num = PIN_DS, + .bus_gpio_num = pin, .flags = { .en_pull_up = true, }, @@ -108,12 +107,12 @@ void hal_temp_init(void) }; if (onewire_new_bus_rmt(&bus_config, &rmt_config, &s_bus) != ESP_OK) { s_bus = NULL; - ESP_LOGE(TAG, "onewire_bus install failed pin=%d", PIN_DS); + ESP_LOGE(TAG, "onewire_bus install failed pin=%d", pin); } s_last_ok = false; s_last_c = 0.0f; s_inited = true; - ESP_LOGI(TAG, "init onewire_bus pin=%d offset=%.1f", PIN_DS, (double)TEMP_OFFSET); + ESP_LOGI(TAG, "init onewire_bus pin=%d offset=%.1f", pin, (double)TEMP_OFFSET); } esp_err_t hal_temp_read_c(float *out) diff --git a/components/hal_temp/include/hal_temp.h b/components/hal_temp/include/hal_temp.h index 5936405..d45c66c 100644 --- a/components/hal_temp/include/hal_temp.h +++ b/components/hal_temp/include/hal_temp.h @@ -7,4 +7,5 @@ #endif void hal_temp_init(void); +void hal_temp_tick(void); /* blocking conversion poll; blocks >=750 ms */ esp_err_t hal_temp_read_c(float *out); /* ESP_FAIL → disconnected */ diff --git a/components/hal_temp/stub/hal_temp.c b/components/hal_temp/stub/hal_temp.c index d351925..54a9644 100644 --- a/components/hal_temp/stub/hal_temp.c +++ b/components/hal_temp/stub/hal_temp.c @@ -1,9 +1,17 @@ #include "hal_temp.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + void hal_temp_init(void) { } +void hal_temp_tick(void) +{ + vTaskDelay(pdMS_TO_TICKS(750)); +} + esp_err_t hal_temp_read_c(float *out) { (void)out; diff --git a/docs/megaplans/INTEGRATION-MEGAPLAN.md b/docs/megaplans/INTEGRATION-MEGAPLAN.md index c04c25c..ad29402 100644 --- a/docs/megaplans/INTEGRATION-MEGAPLAN.md +++ b/docs/megaplans/INTEGRATION-MEGAPLAN.md @@ -36,6 +36,6 @@ If blocked: stop, commit nothing broken, write `BLOCKED:` at top of the phase fi | ID | File | Session goal | STATUS | | --- | --- | --- | --- | | I01 | `integration/I01-board-configs.md` | Board pin allocations & accessors | DONE | -| I02 | `integration/I02-temp-fix.md` | Temp HAL shared & starvation fix | TODO | +| I02 | `integration/I02-temp-fix.md` | Temp HAL shared & starvation fix | DONE | | I03 | `integration/I03-motor-hal.md` | Motor HAL shared across boards | TODO | | I04 | `integration/I04-audio-i2s.md` | I2S audio implementation for S3 | TODO | diff --git a/docs/megaplans/integration/I02-temp-fix.md b/docs/megaplans/integration/I02-temp-fix.md index 7e658a0..40f80ab 100644 --- a/docs/megaplans/integration/I02-temp-fix.md +++ b/docs/megaplans/integration/I02-temp-fix.md @@ -1,5 +1,6 @@ -STATUS: TODO +STATUS: DONE DEPENDS: I01 +Notes: Poll API named `hal_temp_tick` (declared in hal_temp.h). `idf.py build` for both targets verified via CI run 38616 (no local IDF). S3 flash watchdog check not run — no device attached to this machine. **READ:** `docs/megaplans/INTEGRATION-MEGAPLAN.md`, `main/main.c`, `components/hal_temp/*` @@ -17,6 +18,6 @@ DEPENDS: I01 2. `Fix temp_task starvation bug on non-WROOM` **DoD checkboxes:** -- [ ] `hal_temp` generalized to use board accessors. -- [ ] `temp_task` starvation bug fixed. -- [ ] Build succeeds on both targets. +- [x] `hal_temp` generalized to use board accessors. +- [x] `temp_task` starvation bug fixed. +- [x] Build succeeds on both targets. diff --git a/main/main.c b/main/main.c index c8e7e43..6de9f6b 100644 --- a/main/main.c +++ b/main/main.c @@ -28,8 +28,6 @@ static const char *TAG = "app"; #if defined(AUTOFILM_BOARD_WROOM) || defined(AUTOFILM_BOARD_S3) static QueueHandle_t s_cmdq; -extern void autofilm_temp_tick(void); - static void map_and_post_key(char key) { ui_cmd_t cmd; @@ -168,9 +166,7 @@ static void temp_task(void *arg) (void)arg; esp_task_wdt_add(NULL); for (;;) { -#ifdef AUTOFILM_BOARD_WROOM - autofilm_temp_tick(); -#endif + hal_temp_tick(); float c = 0.0f; bool ok = (hal_temp_read_c(&c) == ESP_OK); app_machine_on_temp(ok ? c : 0.0f, ok); diff --git a/tests/host/stubs/hal_temp.c b/tests/host/stubs/hal_temp.c index 2780e96..69f95e6 100644 --- a/tests/host/stubs/hal_temp.c +++ b/tests/host/stubs/hal_temp.c @@ -10,6 +10,10 @@ void hal_temp_init(void) stub_temp_c = 20.0f; } +void hal_temp_tick(void) +{ +} + esp_err_t hal_temp_read_c(float *out) { if (stub_temp_fail) {