#ifndef AD7606_H #define AD7606_H #include #include // 可按需修改为你的实际接线。若 OS 引脚已硬连到 GND/3V3,可将其保持为 -1(不配置)。 namespace ad7606 { // 数据/控制引脚 static const int PIN_AD_MISO = 8; // DOUTA -> ESP32 MISO static const int PIN_AD_CS = 39; // CS_N static const int PIN_AD_CONVST = 13; // CONVST(CO-A/CO-B 共用) static const int PIN_AD_RESET = 40; // RESET static const int PIN_AD_BUSY = 38; // BUSY // 可选:过采样和模式引脚(-1 表示不配置/已硬件固定) static const int PIN_AD_OS0 = -1; static const int PIN_AD_OS1 = -1; static const int PIN_AD_OS2 = -1; static const int PIN_AD_SER = -1; // SER=1 串行模式(若已焊 3.3V,可 -1) static const int PIN_AD_STBY = -1; // STBY=1 正常工作(若已焊 3.3V,可 -1) // 量程:用于将 16-bit 原码转换为电压(缺省 ±10V) static constexpr float AD_FS_VOLTS = 5.0f; // 根据硬件 RANGE 引脚实际设置改成 5.0/2.5 等 // 初始化(与 TFT 共用 SPI:外部需已调用 SPI.begin 并指定 MISO=SENSOR_DOUT) void init(); // 触发并读取 8 路原始数据(阻塞等待 BUSY 变低) void readAll(int16_t* data8); // 读取 CH0 原始码 inline int16_t readCH0() { int16_t tmp[8]; readAll(tmp); return tmp[0]; } // 原码转电压,范围 ±AD_FS_VOLTS inline float codeToVolts(int16_t code) { return (static_cast(code) / 32768.0f) * AD_FS_VOLTS; } } // namespace ad7606 #endif