Files
JBao_Sprayer_FW/apps/usr_app/app_pump.c
T
2026-09-09 15:03:50 +08:00

91 lines
2.2 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.
/******************************************************************************
* @file app_pump.c
* @brief 水泵双脚成对控制:PC2 供 5V + PA6 导通,同开同关
* @author cyWu <1917507415@qq.com>
* @date 2026.09.09
* @version V1.0.0
* @history
* - V1.0.0, 2026.09.09, cyWu, P0 首次发布
*
* @note 禁止只开一只脚;上电两脚默认低、绝不自动开泵。本模块不保存"开",
* 是否开由上层 app_spray 作业引擎决定(规格书 7.2app_pump_set 只
* 由 app_spray 调用)。泵无过零/继电器,请求态==实际态。
******************************************************************************/
#include "system/includes.h"
#include "app_pump.h"
#include "bsp_hw.h"
#include "board_pin.h"
#define LOG_TAG_CONST APP
#define LOG_TAG "[APP_PUMP]"
#define LOG_INFO_ENABLE
#include "debug.h"
/** 模块状态:on 只被 app_spray 在 20ms 节拍里改写 */
typedef struct {
uint8_t initialized;
volatile uint8_t on; /**< 1=泵转(两脚都已导通),0=泵停 */
} PumpCtx_t;
static PumpCtx_t s_pump;
/**
* @brief 初始化泵模块(GPIO 成对低已在 bsp_hw_init 完成)
* @return APP_PUMP_OK=成功
*/
AppPump_Ret_t app_pump_init(void)
{
if (s_pump.initialized) {
return APP_PUMP_OK;
}
#if BOARD_PUMP_ENABLE
bsp_pump_set(0); /* 兜底:两脚都低 */
s_pump.on = 0;
s_pump.initialized = 1;
#else
log_info("pump disabled\n");
#endif
return APP_PUMP_OK;
}
/**
* @brief 成对切泵:on=1 两脚同时高,on=0 两脚同时低
* @param on 1=开,0=关
* @return 无
*/
void app_pump_set(uint8_t on)
{
#if BOARD_PUMP_ENABLE
if (!s_pump.initialized) {
return;
}
bsp_pump_set(on ? 1 : 0);
s_pump.on = on ? 1 : 0;
#else
(void)on;
#endif
}
/**
* @brief 读泵当前态(请求态即实际态)
* @return 1=泵转,0=泵停
*/
uint8_t app_pump_get(void)
{
#if BOARD_PUMP_ENABLE
return s_pump.on;
#else
return 0;
#endif
}
/**
* @brief 查询模块是否已初始化
* @return APP_PUMP_OK=已初始化,APP_PUMP_ERR_NOT_INIT=未初始化
*/
AppPump_Ret_t app_pump_get_status(void)
{
return s_pump.initialized ? APP_PUMP_OK : APP_PUMP_ERR_NOT_INIT;
}