3.24_433_TX版本:项目去UI化,删除OLED/菜单/按键,TX已验证,RX待验证
删除内容: - 删除OLED显示相关代码(u8g2库、I2C接口) - 删除按键输入相关代码(key.c) - 删除菜单系统(MultMenu整个目录) - 删除USB CDC功能(USB_DEVICE目录) - 删除旧的E32演示代码(e32_demo.c/h) 保留内容: - Driver_RF433核心驱动(已封装完整) - rf433_tx_app.c(TX应用层,独立无UI依赖) - rf433_rx_app.c(RX应用层,独立无UI依赖) - GPIO LED指示功能(LED_TX/LED_RX)
This commit is contained in:
@ -12,7 +12,6 @@
|
||||
#include "main.h"
|
||||
#include "gpio.h"
|
||||
#include "usart.h"
|
||||
#include "fifo.h"
|
||||
|
||||
/* ============================================================================
|
||||
* 私有变量
|
||||
@ -22,10 +21,99 @@ static bool rf433_hal_initialized = false;
|
||||
|
||||
/* FIFO缓冲区 */
|
||||
static uint8_t rf433_fifo_buffer[1024];
|
||||
static fifo_t rf433_fifo;
|
||||
static volatile uint32_t rf433_fifo_head = 0;
|
||||
static volatile uint32_t rf433_fifo_tail = 0;
|
||||
static volatile uint32_t rf433_fifo_count = 0;
|
||||
#define RF433_FIFO_SIZE 1024
|
||||
|
||||
/* ============================================================================
|
||||
* 私有FIFO函数
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief FIFO写入数据
|
||||
*/
|
||||
static rf433_hal_error_t rf433_fifo_write(const uint8_t *data, uint16_t length)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
if (data == NULL || length == 0)
|
||||
{
|
||||
return RF433_HAL_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if (rf433_fifo_count >= RF433_FIFO_SIZE)
|
||||
{
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
rf433_fifo_buffer[rf433_fifo_head] = data[i];
|
||||
rf433_fifo_head = (rf433_fifo_head + 1) % RF433_FIFO_SIZE;
|
||||
rf433_fifo_count++;
|
||||
}
|
||||
|
||||
return RF433_HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FIFO读取数据
|
||||
*/
|
||||
static rf433_hal_error_t rf433_fifo_read(uint8_t *data, uint16_t length, uint16_t *actual_length)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
if (data == NULL || length == 0 || actual_length == NULL)
|
||||
{
|
||||
return RF433_HAL_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (rf433_fifo_count == 0)
|
||||
{
|
||||
*actual_length = 0;
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
*actual_length = 0;
|
||||
for (i = 0; i < length && rf433_fifo_count > 0; i++)
|
||||
{
|
||||
data[i] = rf433_fifo_buffer[rf433_fifo_tail];
|
||||
rf433_fifo_tail = (rf433_fifo_tail + 1) % RF433_FIFO_SIZE;
|
||||
rf433_fifo_count--;
|
||||
(*actual_length)++;
|
||||
}
|
||||
|
||||
return RF433_HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取FIFO数据长度
|
||||
*/
|
||||
static rf433_hal_error_t rf433_fifo_get_length(uint16_t *length)
|
||||
{
|
||||
if (length == NULL)
|
||||
{
|
||||
return RF433_HAL_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
*length = rf433_fifo_count;
|
||||
return RF433_HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空FIFO
|
||||
*/
|
||||
static rf433_hal_error_t rf433_fifo_clear(void)
|
||||
{
|
||||
rf433_fifo_head = 0;
|
||||
rf433_fifo_tail = 0;
|
||||
rf433_fifo_count = 0;
|
||||
return RF433_HAL_OK;
|
||||
}
|
||||
|
||||
/* UART接收相关变量 */
|
||||
static uint8_t rf433_uart_rx_tmp;
|
||||
uint8_t rf433_uart_rx_tmp;
|
||||
static volatile uint32_t rf433_uart_rx_timeout = 0;
|
||||
static volatile bool rf433_uart_rx_done = false;
|
||||
|
||||
@ -38,8 +126,6 @@ static volatile bool rf433_uart_rx_done = false;
|
||||
*/
|
||||
rf433_hal_error_t rf433_hal_init(void)
|
||||
{
|
||||
fifo_error_t ret;
|
||||
|
||||
/* 检查是否已初始化 */
|
||||
if (rf433_hal_initialized)
|
||||
{
|
||||
@ -47,11 +133,9 @@ rf433_hal_error_t rf433_hal_init(void)
|
||||
}
|
||||
|
||||
/* 初始化FIFO */
|
||||
ret = fifo_create(&rf433_fifo, rf433_fifo_buffer, sizeof(rf433_fifo_buffer));
|
||||
if (ret != FIFO_OK)
|
||||
{
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
rf433_fifo_head = 0;
|
||||
rf433_fifo_tail = 0;
|
||||
rf433_fifo_count = 0;
|
||||
|
||||
rf433_hal_initialized = true;
|
||||
return RF433_HAL_OK;
|
||||
@ -101,7 +185,7 @@ rf433_hal_error_t rf433_hal_uart_tx(uint8_t *buffer, uint16_t length)
|
||||
void rf433_hal_uart_rx_callback(uint8_t *data, uint16_t length)
|
||||
{
|
||||
/* 写入FIFO */
|
||||
fifo_write(&rf433_fifo, data, length);
|
||||
rf433_fifo_write(data, length);
|
||||
|
||||
/* 设置超时 */
|
||||
rf433_uart_rx_timeout = 10;
|
||||
@ -231,22 +315,7 @@ rf433_hal_error_t rf433_hal_reset(void)
|
||||
*/
|
||||
rf433_hal_error_t rf433_hal_fifo_write(const uint8_t *data, uint16_t length)
|
||||
{
|
||||
fifo_error_t ret;
|
||||
|
||||
/* 参数检查 */
|
||||
if (data == NULL || length == 0)
|
||||
{
|
||||
return RF433_HAL_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* 写入FIFO */
|
||||
ret = fifo_write(&rf433_fifo, (uint8_t *)data, length);
|
||||
if (ret != FIFO_OK)
|
||||
{
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
return RF433_HAL_OK;
|
||||
return rf433_fifo_write(data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,44 +323,7 @@ rf433_hal_error_t rf433_hal_fifo_write(const uint8_t *data, uint16_t length)
|
||||
*/
|
||||
rf433_hal_error_t rf433_hal_fifo_read(uint8_t *data, uint16_t length, uint16_t *actual_length)
|
||||
{
|
||||
fifo_error_t ret;
|
||||
uint32_t fifo_length;
|
||||
|
||||
/* 参数检查 */
|
||||
if (data == NULL || length == 0 || actual_length == NULL)
|
||||
{
|
||||
return RF433_HAL_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* 获取FIFO长度 */
|
||||
ret = fifo_get_length(&rf433_fifo, &fifo_length);
|
||||
if (ret != FIFO_OK)
|
||||
{
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
/* 检查是否有数据 */
|
||||
if (fifo_length == 0)
|
||||
{
|
||||
*actual_length = 0;
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
/* 读取数据 */
|
||||
if (fifo_length > length)
|
||||
{
|
||||
fifo_length = length;
|
||||
}
|
||||
|
||||
ret = fifo_read(&rf433_fifo, data, fifo_length);
|
||||
if (ret != FIFO_OK)
|
||||
{
|
||||
*actual_length = 0;
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
*actual_length = fifo_length;
|
||||
return RF433_HAL_OK;
|
||||
return rf433_fifo_read(data, length, actual_length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,24 +331,7 @@ rf433_hal_error_t rf433_hal_fifo_read(uint8_t *data, uint16_t length, uint16_t *
|
||||
*/
|
||||
rf433_hal_error_t rf433_hal_fifo_get_length(uint16_t *length)
|
||||
{
|
||||
fifo_error_t ret;
|
||||
uint32_t fifo_length;
|
||||
|
||||
/* 参数检查 */
|
||||
if (length == NULL)
|
||||
{
|
||||
return RF433_HAL_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* 获取FIFO长度 */
|
||||
ret = fifo_get_length(&rf433_fifo, &fifo_length);
|
||||
if (ret != FIFO_OK)
|
||||
{
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
*length = fifo_length;
|
||||
return RF433_HAL_OK;
|
||||
return rf433_fifo_get_length(length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,16 +339,7 @@ rf433_hal_error_t rf433_hal_fifo_get_length(uint16_t *length)
|
||||
*/
|
||||
rf433_hal_error_t rf433_hal_fifo_clear(void)
|
||||
{
|
||||
fifo_error_t ret;
|
||||
|
||||
/* 清空FIFO */
|
||||
ret = fifo_clear(&rf433_fifo);
|
||||
if (ret != FIFO_OK)
|
||||
{
|
||||
return RF433_HAL_ERROR;
|
||||
}
|
||||
|
||||
return RF433_HAL_OK;
|
||||
return rf433_fifo_clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -369,7 +375,7 @@ void rf433_hal_uart_rxcplt_callback(void)
|
||||
data = huart1.Instance->DR;
|
||||
|
||||
/* 写入FIFO */
|
||||
fifo_write(&rf433_fifo, &data, 1);
|
||||
rf433_fifo_write(&data, 1);
|
||||
|
||||
/* 设置超时 */
|
||||
rf433_uart_rx_timeout = 10;
|
||||
|
||||
Reference in New Issue
Block a user