218 lines
6.4 KiB
C
218 lines
6.4 KiB
C
/**
|
||
******************************************************************************
|
||
* @file rf433_hal.h
|
||
* @brief RF433硬件抽象层接口
|
||
* @note 基于原e32_hal.c重构,保持与原版设备兼容
|
||
******************************************************************************
|
||
*/
|
||
|
||
#ifndef __RF433_HAL_H__
|
||
#define __RF433_HAL_H__
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
|
||
/* ============================================================================
|
||
* HAL配置宏
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief 是否使用AUX引脚检测忙状态
|
||
* @note 1: 使用AUX引脚(推荐)
|
||
* 0: 使用延时(不推荐)
|
||
*/
|
||
#ifndef RF433_USE_GPIO_AUX
|
||
#define RF433_USE_GPIO_AUX 1
|
||
#endif
|
||
|
||
/**
|
||
* @brief AUX引脚忙等待超时时间(ms)
|
||
*/
|
||
#ifndef RF433_AUX_TIMEOUT
|
||
#define RF433_AUX_TIMEOUT 100
|
||
#endif
|
||
|
||
/* ============================================================================
|
||
* 错误码定义
|
||
* ============================================================================ */
|
||
|
||
typedef enum
|
||
{
|
||
RF433_HAL_OK = 0, // 成功
|
||
RF433_HAL_ERROR = -1, // 通用错误
|
||
RF433_HAL_ERROR_TIMEOUT = -2, // 超时
|
||
RF433_HAL_ERROR_INVALID_PARAM = -3, // 无效参数
|
||
RF433_HAL_ERROR_BUSY = -4, // 模块忙
|
||
} rf433_hal_error_t;
|
||
|
||
/* ============================================================================
|
||
* 工作模式枚举(与原e32_hal.h保持一致)
|
||
* ============================================================================ */
|
||
|
||
typedef enum
|
||
{
|
||
RF433_WORK_MODE_TRANSPARENT = 0x00, // 一般模式(透明传输)
|
||
RF433_WORK_MODE_WAKE_ON_RADIO_MASTER = 0x01, // WOR主模式
|
||
RF433_WORK_MODE_WAKE_ON_RADIO_SLAVE = 0x02, // WOR从模式
|
||
RF433_WORK_MODE_CONFIG_AND_SLEEP = 0x03, // 配置/睡眠模式
|
||
} rf433_work_mode_t;
|
||
|
||
/* ============================================================================
|
||
* HAL初始化函数
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief 初始化硬件抽象层
|
||
* @return RF433_HAL_OK 成功
|
||
* RF433_HAL_ERROR 失败
|
||
*/
|
||
rf433_hal_error_t rf433_hal_init(void);
|
||
|
||
/**
|
||
* @brief 反初始化硬件抽象层
|
||
* @return RF433_HAL_OK 成功
|
||
*/
|
||
rf433_hal_error_t rf433_hal_deinit(void);
|
||
|
||
/* ============================================================================
|
||
* UART通信函数
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief UART发送数据(基于原e32_hal_uart_tx)
|
||
* @param buffer 数据缓冲区
|
||
* @param length 数据长度
|
||
* @return RF433_HAL_OK 成功
|
||
* RF433_HAL_ERROR_TIMEOUT 超时
|
||
*/
|
||
rf433_hal_error_t rf433_hal_uart_tx(uint8_t *buffer, uint16_t length);
|
||
|
||
/**
|
||
* @brief UART接收数据(中断模式)
|
||
* @param data 接收到的数据
|
||
* @param length 数据长度
|
||
* @note 此函数由UART中断回调调用
|
||
*/
|
||
void rf433_hal_uart_rx_callback(uint8_t *data, uint16_t length);
|
||
|
||
/**
|
||
* @brief UART接收完成回调函数(由HAL_UART_RxCpltCallback调用)
|
||
* @retval 无
|
||
*/
|
||
void rf433_hal_uart_rxcplt_callback(void);
|
||
|
||
/* ============================================================================
|
||
* GPIO控制函数
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief 等待AUX引脚变为空闲(基于原e32_hal_aux_wait)
|
||
* @return RF433_HAL_OK 成功
|
||
* RF433_HAL_ERROR_TIMEOUT 超时
|
||
*/
|
||
rf433_hal_error_t rf433_hal_aux_wait(void);
|
||
|
||
/**
|
||
* @brief 设置工作模式(基于原e32_hal_work_mode)
|
||
* @param mode 工作模式
|
||
* @return RF433_HAL_OK 成功
|
||
* RF433_HAL_ERROR_TIMEOUT 超时
|
||
*/
|
||
rf433_hal_error_t rf433_hal_set_work_mode(rf433_work_mode_t mode);
|
||
|
||
/**
|
||
* @brief 复位模块(基于原e32_hal_reset)
|
||
* @return RF433_HAL_OK 成功
|
||
*/
|
||
rf433_hal_error_t rf433_hal_reset(void);
|
||
|
||
/* ============================================================================
|
||
* FIFO操作函数
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief 写入FIFO
|
||
* @param data 数据指针
|
||
* @param length 数据长度
|
||
* @return RF433_HAL_OK 成功
|
||
* RF433_HAL_ERROR_FULL FIFO满
|
||
*/
|
||
rf433_hal_error_t rf433_hal_fifo_write(const uint8_t *data, uint16_t length);
|
||
|
||
/**
|
||
* @brief 读取FIFO
|
||
* @param data 数据缓冲区
|
||
* @param length 期望读取长度
|
||
* @param actual_length 实际读取长度
|
||
* @return RF433_HAL_OK 成功
|
||
* RF433_HAL_ERROR_EMPTY FIFO空
|
||
*/
|
||
rf433_hal_error_t rf433_hal_fifo_read(uint8_t *data, uint16_t length, uint16_t *actual_length);
|
||
|
||
/**
|
||
* @brief 获取FIFO数据长度
|
||
* @param length 数据长度输出
|
||
* @return RF433_HAL_OK 成功
|
||
*/
|
||
rf433_hal_error_t rf433_hal_fifo_get_length(uint16_t *length);
|
||
|
||
/**
|
||
* @brief 清空FIFO
|
||
* @return RF433_HAL_OK 成功
|
||
*/
|
||
rf433_hal_error_t rf433_hal_fifo_clear(void);
|
||
|
||
/* ============================================================================
|
||
* 定时器回调函数
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief 1ms定时器回调(用于超时检测)
|
||
* @note 此函数需要在1ms定时器中断中调用
|
||
*/
|
||
void rf433_hal_1ms_callback(void);
|
||
|
||
/* ============================================================================
|
||
* 兼容函数声明(用于保持与原代码的兼容性)
|
||
* ============================================================================ */
|
||
|
||
/**
|
||
* @brief UART接收超时1ms回调(兼容原uart1_rx_timeout_1ms_callback)
|
||
* @note 此函数需要在1ms定时器中断中调用
|
||
*/
|
||
void uart1_rx_timeout_1ms_callback(void);
|
||
|
||
/**
|
||
* @brief UART等待响应(阻塞模式,兼容原uart1_wait_response_blocked)
|
||
* @param buffer 数据缓冲区
|
||
* @param length 数据长度输出
|
||
* @note 与main.h中的声明保持一致,返回void
|
||
*/
|
||
void uart1_wait_response_blocked(uint8_t *buffer, uint16_t *length);
|
||
|
||
/**
|
||
* @brief UART检查接收完成(兼容原uart1_check_rx_done)
|
||
* @param buffer 数据缓冲区
|
||
* @param length 数据长度输出(uint32_t*,与main.h中的声明保持一致)
|
||
* @return true 接收到数据
|
||
* false 无数据
|
||
*/
|
||
bool uart1_check_rx_done(uint8_t *buffer, uint32_t *length);
|
||
|
||
/**
|
||
* @brief 检查接收完成标志(用于RF433应用层)
|
||
* @return true 接收完成
|
||
* false 接收未完成
|
||
*/
|
||
bool rf433_hal_check_rx_done(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* __RF433_HAL_H__ */
|