Files
zhengxinandCursor 851e347cf5 初始提交卡包 USB 工程
纳入固件源码、屏幕组件、nand_xfer 工具和文档。忽略本机构建产物、sdkconfig,以及含本机路径的依赖锁。

Co-authored-by: Cursor <[email protected]>
2026-10-13 21:54:50 +08:00

109 lines
2.6 KiB
C
Raw Permalink 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.
#ifndef OTA_UPGRADE_H
#define OTA_UPGRADE_H
#include "esp_err.h"
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_app_format.h"
#include "esp_http_client.h"
#include "esp_partition.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
#include "errno.h"
#include "esp_wifi.h"
#define BUFFSIZE (1024*4)
#define OTA_TASK_STACK_SIZE 1024*24//1024*24
#define OTA_TASK_PRIORITY 5
/**
* @brief OTA升级状态回调函数类型
* @param status 升级状态
* @param progress 升级进度(0-100)
* @param message 状态信息
*/
typedef void (*ota_status_callback_t)(const char* status, int progress, const char* message);
// 提取信息管理
typedef struct
{
char filename[64];
uint32_t original_size;
uint32_t extracted_size;
uint32_t timestamp;
uint32_t crc;
bool compressed;
bool verified;
} extraction_info_t;
// OTA升级状态结构体
typedef struct
{
TaskHandle_t task_handle;
ota_status_callback_t status_callback;
SemaphoreHandle_t mutex; //互斥信号量
bool is_running;
int progress;
bool cancel_requested;
} ota_upgrade_context_t;
esp_err_t http_json_download_flash(char* filename, const char* firmware_url);
void trigger_ota_upgrade(char* url);
void check_ota_progress(void);
/**
* @brief 初始化OTA升级模块
* @return esp_err_t ESP_OK表示成功
*/
esp_err_t ota_upgrade_init(void);
/**
* @brief 设置OTA升级状态回调函数
* @param callback 回调函数指针
*/
void ota_upgrade_set_callback(ota_status_callback_t callback);
/**
* @brief 开始OTA升级(非阻塞方式,在新任务中运行)
* @param firmware_url 固件下载URL
* @return esp_err_t ESP_OK表示任务创建成功
*/
esp_err_t ota_upgrade_start(const char* firmware_url);
/**
* @brief 开始OTA升级(阻塞方式,在当前任务中运行)
* @param firmware_url 固件下载URL
* @return esp_err_t 升级结果
*/
esp_err_t ota_upgrade_start_blocking(const char* firmware_url);
/**
* @brief 获取当前升级进度
* @return int 进度百分比(0-100),-1表示未在升级
*/
int ota_upgrade_get_progress(void);
/**
* @brief 检查是否正在升级
* @return true 正在升级
* @return false 未在升级
*/
bool ota_upgrade_is_running(void);
/**
* @brief 取消OTA升级
* @return esp_err_t ESP_OK表示取消成功
*/
esp_err_t ota_upgrade_cancel(void);
#endif // OTA_UPGRADE_H