Files
FilmForge/Inc/board_config.h
T

166 lines
7.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H
#ifndef CFG_DISABLE
#define CFG_DISABLE 0
#endif
#ifndef CFG_ENABLE
#define CFG_ENABLE 1
#endif
#define PROTOCOL_BOARD_TYPE 0x01 /**< 板卡类型标识 */
#include "version.h"
/* GD32_FLASH_SIZE_KB(512/1024/2048)由 CMake 按 GD32_FLASH_CAPACITY 注入,
切换容量:cmake --preset Debug -DGD32_FLASH_CAPACITY=xG */
/* >>>>>>>>>>>>>>>>>>>>[IIC TYPE DEFINE]<<<<<<<<<<<<<<<<<<<< */
#define SOFTWARE_IIC CFG_DISABLE // CFG_DISABLE: Hardware IIC; CFG_ENABLE: Software IIC
/* TODO: I2C 驱动尚未从 GD32E23x 工程移植,先保证工程可编译(见 AGENTS.md 进度清单) */
/* >>>>>>>>>>>>>>>>>>>>[DEBUG MODE]<<<<<<<<<<<<<<<<<<<< */
#define DEBUG_MODE CFG_ENABLE // CFG_DISABLE: Release Mode; CFG_ENABLE: Debug Mode(发布/量产前改回 CFG_DISABLE)
/* >>>>>>>>>>>>>>>>>>>>[COMMAND DEBUG]<<<<<<<<<<<<<<<<<<<< */
#define COM_DEBUG CFG_DISABLE // CFG_DISABLE: Command debug off; CFG_ENABLE: Command debug on
/* 命令协议框架已移植(Src/command.c,数据口 RS485),业务命令待定义 */
/* >>>>>>>>>>>>>>>>>>>>[DEBUG ASSERTIONS DEFINE]<<<<<<<<<<<<<<<<<<<< */
#define DEBUG_VERBOSE CFG_DISABLE // CFG_DISABLE: Verbose debug off; CFG_ENABLE: Verbose debug on
/* >>>>>>>>>>>>>>>>>>>>[SEGGER RTT DETECTION]<<<<<<<<<<<<<<<<<<<< */
#define SEGGER_RTT_DETECTION CFG_ENABLE // CFG_DISABLE: SEGGER RTT off; CFG_ENABLE: SEGGER RTT on
#if SEGGER_RTT_DETECTION == CFG_ENABLE
#include "SEGGER_RTT.h"
#define RTT_printf(ch, ...) SEGGER_RTT_printf(ch, __VA_ARGS__)
#define RTT_WriteString(ch, s) SEGGER_RTT_WriteString(ch, s)
#define RTT_PutChar(ch, c) SEGGER_RTT_PutChar(ch, c)
#else
#define RTT_printf(ch, ...)
#define RTT_WriteString(ch, s)
#define RTT_PutChar(ch, c)
#endif
/* >>>>>>>>>>>>>>>>>>>>[RS485 MODE]<<<<<<<<<<<<<<<<<<<< */
#define RS485_MODE CFG_ENABLE // CFG_DISABLE: RS485 off; CFG_ENABLE: RS485 on
/* GD32F4xx USART 无硬件 RS485 DE 驱动(E23x 特有),DE 引脚由 GPIO 手动控制 */
#if RS485_MODE == CFG_ENABLE
/* 数据口 RS485:USART0(PA9 TX / PA10 RX,AF7),DE 引脚 PA8(GPIO 手动切换收发) */
#define RS485_RCU RCU_USART0
#define RS485_PHY USART0
#define RS485_IRQ USART0_IRQn
#define RS485_GPIO_RCU RCU_GPIOA
#define RS485_GPIO_PORT GPIOA
#define RS485_TX_PIN GPIO_PIN_9
#define RS485_RX_PIN GPIO_PIN_10
#define RS485_BAUDRATE 115200U
#define RS485_DE_RCU RCU_GPIOA
#define RS485_DE_PORT GPIOA
#define RS485_DE_PIN GPIO_PIN_8
#endif
/* >>>>>>>>>>>>>>>>>>>>[NTC TEMPERATURE]<<<<<<<<<<<<<<<<<<<< */
#define NTC_MODE CFG_ENABLE // CFG_DISABLE: NTC off; CFG_ENABLE: NTC on
#if NTC_MODE == CFG_ENABLE
/* 10K NTC 测温:PC5(ADC0_IN15),硬件 10K 上拉,NTC 接 GND 侧 */
#define NTC_ADC_RCU RCU_ADC0
#define NTC_GPIO_RCU RCU_GPIOC
#define NTC_GPIO_PORT GPIOC
#define NTC_GPIO_PIN GPIO_PIN_5
#define NTC_ADC ADC0
#define NTC_ADC_CHANNEL ADC_CHANNEL_15
#define NTC_SAMPLETIME ADC_SAMPLETIME_480 /* 长采样时间(高阻 NTC 分压源) */
#define NTC_SAMPLE_COUNT 16U /* 单次测温的采样次数 */
#define NTC_TRIM_COUNT 2U /* 修剪均值:每端去掉的最大/最小样本数(抗毛刺) */
#define NTC_VREF 3.3f /* ADC 参考电压 V */
#define NTC_ADC_MAX 4095.0f /* 12bit ADC 满量程 */
#define NTC_R_PULL 10000.0f /* 上拉电阻(硬件) */
#define NTC_R25 10000.0f /* NTC 标称阻值 @25C */
#define NTC_T25 298.15f /* 标称温度 K */
#define NTC_B_VALUE 3950 /* B 值:3950 或 3435,按实测确认后修改 */
#endif
/******************************************************************************/
/* 调试串口:USART1(PA2 TX / PA3 RX,AF7),纯串口,非 RS485。
注意 GD32F4xx 外设编号比 STM32 整体小 1:PA2/PA3 是 USART1(=STM32 的 USART2),
PA9/PA10 才是 USART0(=STM32 的 USART1) */
#define UART_RCU RCU_USART1
#define UART_PHY USART1
#define UART_IRQ USART1_IRQn
#define UART_GPIO_RCU RCU_GPIOA
#define UART_GPIO_PORT GPIOA
#define UART_TX_PIN GPIO_PIN_2
#define UART_RX_PIN GPIO_PIN_3
#define UART_BAUDRATE 115200U
/* USART中断处理函数声明(USART0 的处理在 rs485.c,USART1 的处理在 uart.c) */
void rs485_irq_handler(void);
void usart1_irq_handler(void);
/******************************************************************************/
/* I2C0: PB6 SCL / PB7 SDA, AF4 */
#define RCU_GPIO_I2C RCU_GPIOB
#define RCU_I2C RCU_I2C0
#define I2C_SCL_PORT GPIOB
#define I2C_SCL_PIN GPIO_PIN_6
#define I2C_SDA_PORT GPIOB
#define I2C_SDA_PIN GPIO_PIN_7
#define I2C_GPIO_AF GPIO_AF_4
/******************************************************************************/
/* LED: PA15(demo 板实测引脚,低电平点亮按原理图确认) */
#define LED_RCU RCU_GPIOA
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_15
/******************************************************************************/
/* 加热控制参数(M3 开关 / M4 目标温度设定) */
#define HEATER_TEMP_MIN 0U /* 目标温度下限(整数摄氏度) */
#define HEATER_TEMP_MAX 200U /* 目标温度上限(整数摄氏度) */
/******************************************************************************/
/* >>>>>>>>>>>>>>>>>>>>[POWER HOLD(PMOS 自锁保持脚)]<<<<<<<<<<<<<<<<<<<< */
/* PA11:上电保持脚——main 入口即初始化为推挽输出高(先于一切外设初始化),
维持 PMOS 导通;复位期间由外部电路(按键/上拉)保持。 */
#define PWR_HOLD_RCU RCU_GPIOA
#define PWR_HOLD_PORT GPIOA
#define PWR_HOLD_PIN GPIO_PIN_11
/* >>>>>>>>>>>>>>>>>>>>[HEATER OUTPUT(加热驱动 PB12=HEAT_EN)]<<<<<<<<<<<<<<<<<<<< */
/* PB12:高 = 加热开,低 = 关(2N7002K 电平转换 → VBE2412 PMOS → 24V 加热回路)。
开关频率限制:慢 PWM 周期 1s、占空比 10% 步进——脉宽恒 >=100ms,开关频率恒 1Hz。 */
#define HEATER_EN_RCU RCU_GPIOB
#define HEATER_EN_PORT GPIOB
#define HEATER_EN_PIN GPIO_PIN_12
#define HEATER_PWM_PERIOD_MS 1000U /* PWM 载波周期(1s,恒 1Hz 开关频率) */
#define HEATER_PWM_STEP_PCT 10U /* 占空比步进(每档脉宽 = 100ms) */
#define HEATER_PID_PERIOD_MS 500U /* PID 计算周期 */
#define HEATER_PID_KP 8.0f /* PID 参数:初值,需上板实测整定 */
#define HEATER_PID_KI 0.05f
#define HEATER_PID_KD 0.0f /* NTC 噪声对微分放大,先禁用 */
#define HEATER_OVERTEMP_C 150.0f /* 过温强制关断阈值(滞回保护) */
#define HEATER_OVERTEMP_HYST 5.0f /* 过温恢复滞回 */
/******************************************************************************/
#define DEBUG_UART USART1
#endif //BOARD_CONFIG_H