190 lines
5.4 KiB
C
Executable File
190 lines
5.4 KiB
C
Executable File
/*
|
|
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
// #include "driver/usb_serial_jtag.h"
|
|
#include "sdkconfig.h"
|
|
#include "esp_log.h"
|
|
#include "esp_check.h"
|
|
#include "freertos/queue.h"
|
|
#include "driver/uart.h"
|
|
#include "freertos/event_groups.h"
|
|
#include "esp_system.h"
|
|
#include "esp_wifi.h"
|
|
#include "esp_event.h"
|
|
#include "nvs_flash.h"
|
|
|
|
#include "lwip/err.h"
|
|
#include "lwip/sockets.h"
|
|
#include "lwip/sys.h"
|
|
#include <lwip/netdb.h>
|
|
|
|
#include "esp32_port.h"
|
|
#include "esp_loader.h"
|
|
#include "flasher_common.h"
|
|
#include "driver/uart.h"
|
|
#include "driver/gpio.h"
|
|
|
|
#include "wifi_task.h"
|
|
#include "spiffs.h"
|
|
|
|
#include "bsp_flash.h"
|
|
#include "stream.h"
|
|
#include "esp_efuse.h"
|
|
#include "public.h"
|
|
#include "esp_flash.h"
|
|
#include "esp_lcd_st7735.h"
|
|
|
|
#include "i2c_port.h"
|
|
|
|
static const char *TAG = "main";
|
|
|
|
|
|
uint8_t* load_html2Ram(wifi_html_t html)
|
|
{
|
|
uint8_t* buff;
|
|
if(html.html_data != NULL) {
|
|
return html.html_data;
|
|
}else{
|
|
buff = malloc(html.html_size + 10);
|
|
Read_ESPFlash(0x41,html.html_addr,&buff[0],html.html_size);
|
|
// ESP_LOGI(TAG,"html:%s",buff);
|
|
return buff;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
extern uint8_t* home_html_data;
|
|
stream_data_t wifi_interface_data;
|
|
stream_data_t uart_interface_data;
|
|
Device_info_t off_line_tool;
|
|
|
|
extern void axp_init(void);
|
|
extern void axp_info();
|
|
extern void axp_config();
|
|
extern void axp_irq_init();
|
|
|
|
void app_main(void)
|
|
{
|
|
|
|
esp_err_t err = nvs_flash_init();
|
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_ERROR_CHECK(nvs_flash_erase()); // 擦除 NVS 分区
|
|
err = nvs_flash_init(); // 重新初始化
|
|
}
|
|
ESP_ERROR_CHECK(err);
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
xTaskCreate(&Gui_Task, "Gui_Task", 1024*20, NULL, 12, NULL);
|
|
init_spiffs();
|
|
list_files_in_spiffs("/spiffs",off_line_tool.directory, 10);
|
|
ESP_LOGI(TAG, "Found file: %s, size: %ld bytes", off_line_tool.directory[0].name, off_line_tool.directory[0].size);
|
|
ESP_LOGI(TAG, "Found file: %s, size: %ld bytes", off_line_tool.directory[1].name, off_line_tool.directory[1].size);
|
|
ESPFlash_Init();
|
|
stream_init(&uart_interface_data,1024*50);
|
|
|
|
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
|
gpio_config_t config = {
|
|
.mode = GPIO_MODE_OUTPUT,
|
|
.pin_bit_mask = 1ULL << 8 | 1ULL << 7,
|
|
.pull_up_en = 1
|
|
};
|
|
gpio_config(&config);
|
|
gpio_set_level(8,0);
|
|
// gpio_set_level(18,1);
|
|
// gpio_config_t input_config = {
|
|
// .mode = GPIO_MODE_INPUT,
|
|
// .pin_bit_mask = 1ULL << 9 | 1ULL << 2,
|
|
// .pull_up_en = 1
|
|
// };
|
|
// gpio_config(&input_config);
|
|
// button_init_all();
|
|
ESP_ERROR_CHECK(i2c_master_init());
|
|
|
|
axp_init();
|
|
|
|
axp_info();
|
|
|
|
// axp_irq_init();
|
|
|
|
axp_config();
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32C3
|
|
usb_serial2Uart(NULL);
|
|
#endif
|
|
xTaskCreate(&Read_CMD_task, "Read_CMD_task", 1024*20, NULL, 14, NULL);
|
|
xTaskCreate(&usb_serial_task,"usb_serial_task",1024*10,NULL,22,NULL);
|
|
// xTaskCreate(&Flasher_tool_task, "Flasher_tool_task", 1024*20, NULL, 10, NULL);
|
|
#if 0
|
|
home_html.html_data = load_html2Ram(home_html);
|
|
wifi_config_html.html_data = load_html2Ram(wifi_config_html);
|
|
upload_ota_html.html_data = load_html2Ram(upload_ota_html);
|
|
// favicon_ico.html_data = load_html2Ram(favicon_ico);
|
|
// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
|
// ESP_LOGI(TAG,"def_name:%s",Sys_wifi_config.def_AP_Name);
|
|
ESP_LOGI(TAG,"sizeof--Sys_wifi_config:%d",sizeof(wifi_Save_info_t));
|
|
Read_ESPFlash(0x40,0,&Sys_wifi_config,sizeof(wifi_Save_info_t));
|
|
ESP_LOGI(TAG,"wifi_ssid:%s",Sys_wifi_config.wifi_ssid);
|
|
ESP_LOGI(TAG,"wifi_password:%s",Sys_wifi_config.wifi_password);
|
|
if(Sys_wifi_config.wifi_mode != 0x55)
|
|
{
|
|
wifi_init_softap();
|
|
}else{
|
|
wifi_init_station();
|
|
}
|
|
#endif
|
|
|
|
|
|
esp_flash_t *chip = esp_flash_default_chip;
|
|
esp_err_t ret = esp_flash_read_id(chip, &off_line_tool.flash_id);
|
|
if (ret == ESP_OK) {
|
|
ESP_LOGI("FLASH", "Flash ID: 0x%lX", off_line_tool.flash_id);
|
|
} else {
|
|
ESP_LOGE("FLASH", "Failed to read flash ID, error=0x%x", ret);
|
|
}
|
|
|
|
|
|
uint8_t mac_wifi[6];
|
|
uint8_t mac_bt[6];
|
|
|
|
// 获取 Wi-Fi MAC 地址
|
|
esp_efuse_mac_get_default(mac_wifi);
|
|
ESP_LOGI("MAC Address", "Wi-Fi MAC: %02x:%02x:%02x:%02x:%02x:%02x",
|
|
mac_wifi[0], mac_wifi[1], mac_wifi[2], mac_wifi[3], mac_wifi[4], mac_wifi[5]);
|
|
|
|
memcpy(&off_line_tool.Device_MAC_WIFI[0],&mac_wifi[0],6);
|
|
|
|
sprintf((char*)&off_line_tool.Device_SN[0],"1234567890");
|
|
// 获取蓝牙 MAC 地址
|
|
// esp_bt_dev_get_address(mac_bt);
|
|
// ESP_LOGI("MAC Address", "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x",
|
|
// mac_bt[0], mac_bt[1], mac_bt[2], mac_bt[3], mac_bt[4], mac_bt[5]);
|
|
|
|
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
|
// start_web_server();
|
|
// xTaskCreate(tcp_server_task, "tcp_server", 4096, (void*)AF_INET, 5, NULL);
|
|
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
|
|
|
while (1)
|
|
{
|
|
// if(gpio_get_level(GPIO_NUM_9) == 0 || gpio_get_level(GPIO_NUM_2) == 0)
|
|
// {
|
|
// ESP_LOGI(TAG,"BOOT Down");
|
|
// }
|
|
// ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
|
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
|
}
|
|
|
|
}
|
|
|