A2:HAL 接口(i2c/gpio/pwm/time)+ sim 与 ESP 两套实现

接口在 components/phonerail_hal/include/,宿主机链 sim/、ESP32-S3 链 esp/
(IDF v5.4 新版 i2c_master / gpio / LEDC / esp_timer)。

sim 提供 A3 起要用的假板子控制面:假 I²C 器件(寄存器表 + 大端 + 指针自增)、
可注入 NAK / 器件失联、GPIO 外部驱动与写计数、虚拟时钟。

组件名不叫 hal —— ESP-IDF 自己有 components/hal(driver 依赖它),同名会盖掉。

验收:bash host/test.sh → 3 条 ctest 全过;build_idf.ps1 → 编过且零警告。

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYuExfgyYa6DzRRcUso8M8
这个提交包含在:
zhou yang
2026-09-06 18:33:26 +08:00
共同撰写人 Claude Opus 5
父节点 1b5bd159ec
当前提交 cac6ce47ce
共修改 25 个文件,包含 1174 行新增和 40 行删除
@@ -0,0 +1,25 @@
/* 时钟的 ESP-IDF 实现。 */
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "hal_time.h"
uint64_t hal_time_now_us(void) { return (uint64_t)esp_timer_get_time(); }
uint32_t hal_time_now_ms(void) { return (uint32_t)(hal_time_now_us() / 1000u); }
uint32_t hal_time_elapsed_ms(uint32_t since_ms)
{
return hal_time_now_ms() - since_ms; /* 无符号减法,49.7 天回绕自然正确 */
}
void hal_time_delay_ms(uint32_t ms)
{
if (ms == 0) {
return;
}
/* 至少睡一个 tick:pdMS_TO_TICKS(1) 在 100 Hz tick 下会算成 0,
那样就变成忙等而不是让出 CPU。 */
TickType_t ticks = pdMS_TO_TICKS(ms);
vTaskDelay(ticks != 0 ? ticks : 1);
}