基本示波

This commit is contained in:
2025-11-15 12:57:16 +08:00
parent 9529ecd0d5
commit 042af6036e
7 changed files with 211 additions and 586 deletions
+47
View File
@@ -0,0 +1,47 @@
#ifndef AD7606_H
#define AD7606_H
#include <Arduino.h>
#include <SPI.h>
// 可按需修改为你的实际接线。若 OS 引脚已硬连到 GND/3V3,可将其保持为 -1(不配置)。
namespace ad7606 {
// 数据/控制引脚
static const int PIN_AD_MISO = 8; // DOUTA -> ESP32 MISO
static const int PIN_AD_CS = 12; // CS_N
static const int PIN_AD_CONVST = 13; // CONVST(CO-A/CO-B 共用)
static const int PIN_AD_RESET = 5; // RESET
static const int PIN_AD_BUSY = 14; // 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<float>(code) / 32768.0f) * AD_FS_VOLTS;
}
} // namespace ad7606
#endif
-55
View File
@@ -1,55 +0,0 @@
#ifndef GAME_H
#define GAME_H
#include <Arduino.h>
#include "ui.h" // for DisplayList and colors
namespace esp32 {
namespace game {
using namespace esp32::ui;
// 棋盘尺寸(经典 10x20)
static const int COLS = 10;
static const int ROWS = 20;
enum class State : uint8_t { Playing = 0, GameOver = 1 };
struct Piece {
uint8_t type; // 0..6
int8_t x; // 左上角/参考点
int8_t y;
// 仅使用一个朝向(简化:不提供旋转)
int8_t blocks[4][2]; // 4 个方块偏移
uint16_t color;
};
struct Tetris {
uint8_t board[ROWS][COLS]; // 0=空,其它=颜色索引或标记
uint16_t colors[8]; // 颜色表(index->RGB565)
Piece current;
uint32_t lastDropMs = 0;
uint32_t dropInterval = 700; // ms
State state = State::Playing;
uint32_t score = 0;
uint32_t rng = 1;
};
void init(Tetris& g);
void reset(Tetris& g);
void update(Tetris& g, uint32_t nowMs);
// 输入
void moveLeft(Tetris& g);
void moveRight(Tetris& g);
void hardDrop(Tetris& g);
// UI 构建
void buildScene(const Tetris& g, DisplayList& out,
int16_t screenW, int16_t screenH,
int16_t cell, int16_t originX, int16_t originY);
} // namespace game
} // namespace esp32
#endif // GAME_H
-30
View File
@@ -1,30 +0,0 @@
#ifndef TIMER_H
#define TIMER_H
#include <Arduino.h>
#include "ui.h"
namespace esp32 {
namespace timer {
struct ClockState {
uint32_t startMs = 0; // 起始时间
uint32_t elapsedMs = 0; // 当前经过时间
static const int MAX_LAPS = 12;
uint16_t lapCount = 0;
float lapAngles[MAX_LAPS]; // 存储圈记录的角度(秒针位置)
uint32_t lapMs[MAX_LAPS]; // 每次记录的时间戳 (ms)
bool running = true;
};
void init(ClockState& s);
void reset(ClockState& s);
void update(ClockState& s, uint32_t nowMs);
void addLap(ClockState& s);
void buildScene(const ClockState& s, esp32::ui::DisplayList& out,
int16_t screenW, int16_t screenH);
} // namespace timer
} // namespace esp32
#endif // TIMER_H