Files
ESPC3-wireless/app/drivers/sertrf/sertrf.h

139 lines
3.0 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.

#pragma once
#include "device.h"
#include "../led_strip/led_strip.h"
#include "key.h"
#include "protocol/p_protocol.h"
#include "protocol/resend_protl.h"
#include "protocol/stmisp.h"
#include "ota_u.h"
#include "tool.h"
#include "ring_buffer.h"
#include "../../config/app_config.h"
#define FC_ADDRESS "0x08000000"
#define DATA_HANDLE_BUFFER_SIZE 4096
typedef enum
{
DATA_HANDLE_IDLE = 0,
DATA_HANDLE_OTA_DATA,
DATA_HANDLE_OTA_DATA_END,
DATA_HANDLE_ISP_DATA,
DATA_HANDLE_ISP_DATA_END
}data_handle_e;
typedef enum
{
SERTRF_ERROR_NONE = 0,
SERTRF_ERROR_OTA_INIT = 10, // ota初始化失败
SERTRF_ERROR_OTA_DATA, // ota数据传输异常
SERTRF_ERROR_OTA_END, // ota 结束异常
SERTRF_ERROR_FC_ISP_UART_TYPE = 30, // 飞控ISP 无法识别其协议
SERTRF_ERROR_FC_ISP_UART_DATA, // 飞控ISP 无法收到其数据
SERTRF_ERROR_FC_ISP_SYNC, // 飞控ISP 无法与ISP建立连接需判断BOOT键是否有效
}sertrf_error_code_e;
typedef struct __attribute__((packed))
{
data_handle_e task_state;
uint16_t sertrf_error_code;
}sertrf_mode_status_t;
typedef struct
{
device_t device;
// 任务
os_thread_t embedded_thread; //处理飞控接收
os_thread_t pc_thread; //处理app接收
os_thread_t task_thread; //处理其他任务
os_thread_t app_thread; //处理app任务
os_thread_t data_handle_thread; //数据处理任务
sertrf_mode_status_t mode_status;
// ota
ota_u_t otau;
//自定义协议
resend_device_t resend_device;
SemaphoreHandle_t resend_read_mutex;
//STMISP协议
stmisp_device_t stmisp_device;
// 环形buff
RingBuffer data_handle_buffer;
uint32_t fc_address;
// efuse MAC 地址
uint8_t efuse_mac[6];
uint8_t efuse_mac_encrypt[6];
// 记录错误信息
protocol_status_e fc_protocol_status; //飞控连接端的协议状态
}sertrf_t;
typedef struct __attribute__((packed))
{
char ble_name[32];
char wifi_ap_ssid[32];
char wifi_ap_password[32];
char wifi_sta_ssid[32];
char wifi_sta_password[32];
uint8_t efuse_mac_encrypt[6];
}sertrf_stauct_t;
/**
* @brief 模块初始化
*/
void sertrf_init(void);
/**
* @brief 模块启动
*/
void sertrf_start(void);
/**
* @brief 模块停止
*/
void sertrf_stop(void);
/**
* @brief 射频模块开关
*/
void sertrf_rf_switch(uint8_t on);
/**
* @brief 模块数据查看
*/
void sertrf_status(void);
/**
* @brief embedded thread
*/
void embedded_thread(void* arg);
/**
* @brief pc thread
*/
void pc_thread(void* arg);
/**
* @brief app thread
*/
void app_thread(void* arg);
/**
* @brief task thread
*/
void task_thread(void* arg);
/**
* @brief data handle thread
*/
void data_handle_thread(void* arg);
/**
* @brief 根据连接状态显示不同的颜色
*
* @param connect 连接状态
*/
void pc_link_rgb_color(device_t* device);