refactor(vd960Loop): 算法回退到 DLD154V4B,四通道适配

- 用 DLD154V4B vd1_task/per_channel 替换 vds_task 复杂算法
- 移除 FUNCTION_B/二次判断/快速变化/多重确认等增强特性
- 保留平坦性离开算法 (CN200910309382),每通道独立状态
- 灵敏度表改为 DLD154V4B 4级: {216,108,36,10} / {108,72,18,9}
- 清理废弃类型: FltHistoryManager, Loop_ACS_Info, StageRangeConfig 等
- 首次添加 vd960DBN 完整源码
This commit is contained in:
wangfq
2026-06-25 16:21:57 +08:00
parent 6fd4e564e3
commit 95808f9f25
966 changed files with 406958 additions and 84 deletions
+82
View File
@@ -0,0 +1,82 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : HAL.h
* Author : WCH
* Version : V1.0
* Date : 2016/05/05
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#ifndef __HAL_H
#define __HAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "config.h"
#include "RTC.h"
#include "SLEEP.h"
#include "KEY.h"
#include "LED.h"
/* hal task Event */
#define LED_BLINK_EVENT 0x0001
#define HAL_KEY_EVENT 0x0002
#define HAL_REG_INIT_EVENT 0x2000
#define HAL_TEST_EVENT 0x4000
/*********************************************************************
* GLOBAL VARIABLES
*/
extern tmosTaskID halTaskID;
/*********************************************************************
* GLOBAL FUNCTIONS
*/
/**
* @brief Hardware initialization
*/
extern void HAL_Init(void);
/**
* @brief HAL processing
*
* @param task_id - The TMOS assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*/
extern tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events);
/**
* @brief Initialization of the BLE library
*/
extern void WCHBLE_Init(void);
/**
* @brief Get the internal temperature sampling value.
* If the ADC interrupt sampling is used,
* the interrupt is temporarily shielded in this function.
*
* @return Internal temperature sampling value.
*/
extern uint16_t HAL_GetInterTempValue(void);
/**
* @brief Internal 32K calibration
*/
extern void Lib_Calibration_LSI(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+112
View File
@@ -0,0 +1,112 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : KEY.h
* Author : WCH
* Version : V1.0
* Date : 2016/04/12
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#ifndef __KEY_H
#define __KEY_H
#ifdef __cplusplus
extern "C" {
#endif
/**************************************************************************************************
* MACROS
**************************************************************************************************/
#define HAL_KEY_POLLING_VALUE 100
/* Switches (keys) */
#define HAL_KEY_SW_1 0x01 // key1
#define HAL_KEY_SW_2 0x02 // key2
#define HAL_KEY_SW_3 0x04 // key3
#define HAL_KEY_SW_4 0x08 // key4
/* Key definition */
/* 1 - KEY */
#define KEY1_PCENR (RCC_APB2Periph_GPIOB)
#define KEY2_PCENR ()
#define KEY3_PCENR ()
#define KEY4_PCENR ()
#define KEY1_GPIO (GPIOB)
#define KEY2_GPIO ()
#define KEY3_GPIO ()
#define KEY4_GPIO ()
#define KEY1_BV BV(13)
#define KEY2_BV ()
#define KEY3_BV ()
#define KEY4_BV ()
#define KEY1_IN (GPIO_ReadInputDataBit(KEY1_GPIO, KEY1_BV)==0)
#define KEY2_IN ()
#define KEY3_IN ()
#define KEY4_IN ()
#define HAL_PUSH_BUTTON1() (KEY1_IN) //Add custom button
#define HAL_PUSH_BUTTON2() (0)
#define HAL_PUSH_BUTTON3() (0)
#define HAL_PUSH_BUTTON4() (0)
/**************************************************************************************************
* TYPEDEFS
**************************************************************************************************/
typedef void (*halKeyCBack_t)(uint8_t keys);
typedef struct
{
uint8_t keys; // keys
} keyChange_t;
/**************************************************************************************************
* GLOBAL VARIABLES
**************************************************************************************************/
/*********************************************************************
* FUNCTIONS
*/
/**
* @brief Initialize the Key Service
*/
void HAL_KeyInit(void);
/**
* @brief This is for internal used by hal_driver
*/
void HAL_KeyPoll(void);
/**
* @brief Configure the Key serivce
*
* @param cback - pointer to the CallBack function
*/
void HalKeyConfig(const halKeyCBack_t cback);
/**
* @brief Read the Key callback
*/
void HalKeyCallback(uint8_t keys);
/**
* @brief Read the Key status
*/
uint8_t HalKeyRead(void);
/**************************************************************************************************
**************************************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+133
View File
@@ -0,0 +1,133 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : LED.h
* Author : WCH
* Version : V1.0
* Date : 2016/04/12
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#ifndef __LED_H
#define __LED_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************************************************************
* CONSTANTS
*/
/* LEDS - The LED number is the same as the bit position */
#define HAL_LED_1 0x01
#define HAL_LED_2 0x02
#define HAL_LED_3 0x04
#define HAL_LED_4 0x08
#define HAL_LED_ALL (HAL_LED_1 | HAL_LED_2 | HAL_LED_3 | HAL_LED_4)
/* Modes */
#define HAL_LED_MODE_OFF 0x00
#define HAL_LED_MODE_ON 0x01
#define HAL_LED_MODE_BLINK 0x02
#define HAL_LED_MODE_FLASH 0x04
#define HAL_LED_MODE_TOGGLE 0x08
/* Defaults */
#define HAL_LED_DEFAULT_MAX_LEDS 4
#define HAL_LED_DEFAULT_DUTY_CYCLE 5
#define HAL_LED_DEFAULT_FLASH_COUNT 50
#define HAL_LED_DEFAULT_FLASH_TIME 1000
/*********************************************************************
* TYPEDEFS
*/
/* Connect an LED to monitor the progress of the demo program, the low-level LED is on */
/* 1 - LED */
#define LED1_PCENR (RCC_APB2Periph_GPIOB)
#define LED2_PCENR
#define LED3_PCENR
#define LED1_GPIO (GPIOB)
#define LED2_GPIO
#define LED3_GPIO
#define LED1_BV BV(15)
#define LED2_BV
#define LED3_BV
#define HAL_TURN_OFF_LED1() (GPIO_WriteBit(LED1_GPIO, LED1_BV, Bit_SET))
#define HAL_TURN_OFF_LED2()
#define HAL_TURN_OFF_LED3()
#define HAL_TURN_OFF_LED4()
#define HAL_TURN_ON_LED1() (GPIO_WriteBit(LED1_GPIO, LED1_BV, Bit_RESET))
#define HAL_TURN_ON_LED2()
#define HAL_TURN_ON_LED3()
#define HAL_TURN_ON_LED4()
#define HAL_STATE_LED1() 0
#define HAL_STATE_LED2() 0
#define HAL_STATE_LED3() 0
#define HAL_STATE_LED4() 0
/*********************************************************************
* GLOBAL VARIABLES
*/
/**
* @brief Initialize LED Service.
*/
void HAL_LedInit(void);
/**
* @brief update time LED Service.
*/
void HalLedUpdate(void);
/**
* @brief Turn ON/OFF/TOGGLE given LEDs
*
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
* @param mode - BLINK, FLASH, TOGGLE, ON, OFF
*/
extern uint8_t HalLedSet(uint8_t led, uint8_t mode);
/**
* @brief Blink the leds
*
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
* @param numBlinks - number of blinks
* @param percent - the percentage in each period where the led will be on
* @param period - length of each cycle in milliseconds
*/
extern void HalLedBlink(uint8_t leds, uint8_t cnt, uint8_t duty, uint16_t time);
/**
* @brief Put LEDs in sleep state - store current values
*/
extern void HalLedEnterSleep(void);
/**
* @brief Retore LEDs from sleep state
*/
extern void HalLedExitSleep(void);
/**
* @brief Return LED state
*/
extern uint8_t HalLedGetState(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+40
View File
@@ -0,0 +1,40 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : RTC.h
* Author : WCH
* Version : V1.0
* Date : 2016/04/12
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#ifndef __RTC_H
#define __RTC_H
#ifdef __cplusplus
extern "C" {
#endif
extern volatile uint32_t RTCTigFlag;
/**
* @brief Initialize time Service.
*/
void HAL_TimeInit(void);
/**
* @brief Configure RTC trigger time
*
* @param time - Trigger time.
*/
extern void RTC_SetTignTime(uint32_t time);
#ifdef __cplusplus
}
#endif
#endif
+50
View File
@@ -0,0 +1,50 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : SLEEP.h
* Author : WCH
* Version : V1.0
* Date : 2018/11/12
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#ifndef __SLEEP_H
#define __SLEEP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************************************************************
* GLOBAL VARIABLES
*/
/*********************************************************************
* FUNCTIONS
*/
/**
* @brief Configure sleep Wake-up source - RTC wake up, trigger mode
*/
extern void HAL_SleepInit(void);
/**
* @brief Start sleep
*
* @param time - Wake-up time (RTC absolute value)
*
* @return state.
*/
extern uint32_t BLE_LowPower(uint32_t time);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+137
View File
@@ -0,0 +1,137 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CONFIG.h
* Author : WCH
* Version : V1.2
* Date : 2022/01/18
* Description : Configuration description and default value,
* it is recommended to modify the current value in the
* pre-processing of the engineering configuration
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#ifndef __CONFIG_H
#define __CONFIG_H
#define ID_CH32V208 0x0208
#define CHIP_ID ID_CH32V208
#ifdef WCHBLE_ROM
#include "WCHBLE_ROM.H"
#else
#include "wchble.H"
#endif
#include "ch32v20x.h"
/*********************************************************************
【MAC】
BLE_MAC - 是否自定义蓝牙Mac地址 ( 默认:FALSE - 使用芯片Mac地址 ),需要在main.c修改Mac地址定义
【SLEEP】
HAL_SLEEP - 是否开启睡眠功能 ( 默认:FALSE )
WAKE_UP_MAX_TIME_US - 提前唤醒时间,即系统时钟稳定所需要时间
暂停模式 - 45
空闲模式 - 5
【TEMPERATION】
TEM_SAMPLE - 是否打开根据温度变化校准的功能,单次校准耗时小于10ms( 默认:TRUE )
【CALIBRATION】
BLE_CALIBRATION_ENABLE - 是否打开定时校准的功能,单次校准耗时小于10ms( 默认:TRUE )
BLE_CALIBRATION_PERIOD - 定时校准的周期,单位ms( 默认:120000 )
【SNV】
BLE_SNV - 是否开启SNV功能,用于储存绑定信息( 默认:TRUE )
BLE_SNV_ADDR - SNV信息保存地址,使用data flash最后( 默认:0x77E00 )
BLE_SNV_NUM - SNV信息存储扇区数量等于可存储的绑定数量( 默认:3 )
- 如果配置了SNVNum参数,则需要对应修改Lib_Write_Flash函数内擦除的flash大小,大小为SNVBlock*SNVNum
【RTC】
CLK_OSC32K - RTC时钟选择,如包含主机角色必须使用外部32K( 0 外部(32768Hz),默认:1:内部(32000Hz)2:内部(32768Hz) )
【MEMORY】
BLE_MEMHEAP_SIZE - 蓝牙协议栈使用的RAM大小,不小于6K ( 默认:(1024*6) )
【DATA】
BLE_BUFF_MAX_LEN - 单个连接最大包长度( 默认:27 (ATT_MTU=23),取值范围[27~251] )
BLE_BUFF_NUM - 控制器缓存的包数量( 默认:5 )
BLE_TX_NUM_EVENT - 单个连接事件最多可以发多少个数据包( 默认:1 )
BLE_TX_POWER - 发射功率( 默认:LL_TX_POWEER_0_DBM (0dBm) )
【MULTICONN】
PERIPHERAL_MAX_CONNECTION - 最多可同时做多少从机角色( 默认:1 )
CENTRAL_MAX_CONNECTION - 最多可同时做多少主机角色( 默认:3 )
**********************************************************************/
/*********************************************************************
* 默认配置值
*/
#ifndef BLE_MAC
#define BLE_MAC FALSE
#endif
#ifndef HAL_SLEEP
#define HAL_SLEEP FALSE
#endif
#ifndef WAKE_UP_MAX_TIME_US
#define WAKE_UP_MAX_TIME_US 2400
#endif
#ifndef HAL_KEY
#define HAL_KEY FALSE
#endif
#ifndef HAL_LED
#define HAL_LED FALSE
#endif
#ifndef TEM_SAMPLE
#define TEM_SAMPLE TRUE
#endif
#ifndef BLE_CALIBRATION_ENABLE
#define BLE_CALIBRATION_ENABLE TRUE
#endif
#ifndef BLE_CALIBRATION_PERIOD
#define BLE_CALIBRATION_PERIOD 120000
#endif
#ifndef BLE_SNV
#define BLE_SNV TRUE
#endif
#ifndef BLE_SNV_ADDR
#define BLE_SNV_ADDR 0x08077C00
#endif
#ifndef BLE_SNV_NUM
#define BLE_SNV_NUM 3
#endif
#ifndef CLK_OSC32K
#define CLK_OSC32K 1 // 该项请勿在此修改,必须在工程配置里的预处理中修改,如包含主机角色必须使用外部32K
#endif
#ifndef BLE_MEMHEAP_SIZE
#define BLE_MEMHEAP_SIZE (1024*7)
#endif
#ifndef BLE_BUFF_MAX_LEN
#define BLE_BUFF_MAX_LEN 100 //27
#endif
#ifndef BLE_BUFF_NUM
#define BLE_BUFF_NUM 5
#endif
#ifndef BLE_TX_NUM_EVENT
#define BLE_TX_NUM_EVENT 1
#endif
#ifndef BLE_TX_POWER
#define BLE_TX_POWER LL_TX_POWEER_7_DBM //LL_TX_POWEER_7_DBM //LL_TX_POWEER_0_DBM
#endif
#ifndef PERIPHERAL_MAX_CONNECTION
#define PERIPHERAL_MAX_CONNECTION 1
#endif
#ifndef CENTRAL_MAX_CONNECTION
#define CENTRAL_MAX_CONNECTION 3
#endif
extern uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
extern const uint8_t MacAddr[6];
#endif