Files
433_STM32/Driver_RF433/Inc/rf433_hal.h

218 lines
6.4 KiB
C
Raw Normal View History

/**
******************************************************************************
* @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__ */