文件
phonerail/firmware/components/phonerail_hal/include/hal_pwm.h
T
zhou yang和Claude Opus 5 cac6ce47ce 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
2026-09-06 18:33:26 +08:00

29 行
714 B
C

/* PWM 输出。本项目只有风扇一路(计划 A16 的闭环),留 4 个通道够用。
占空比单位是**千分比**(0~1000),不是硬件码值 ——
应用层不该知道 LEDC 配了几位分辨率。 */
#ifndef HAL_PWM_H
#define HAL_PWM_H
#include <stdint.h>
#include "hal_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HAL_PWM_CH_MAX 4
hal_err_t hal_pwm_config(int ch, int pin, uint32_t freq_hz);
hal_err_t hal_pwm_set_permille(int ch, uint16_t permille);
/* 回读的是**固件设过的值**,不是量出来的波形。风扇实际转不转看 TACH。 */
hal_err_t hal_pwm_get_permille(int ch, uint16_t *permille);
#ifdef __cplusplus
}
#endif
#endif /* HAL_PWM_H */