/*
 * esp8266.h
 *
 *  Created on: 2025Äê10ÔÂ18ÈÕ
 *      Author: LHYe200
 */

#ifndef CODE_ESP8266_H_
#define CODE_ESP8266_H_

#include "zf_common_typedef.h"

#define ESP8266_IO0             P20_9
#define ESP8266_IO2             P20_8
#define ESP8266_IO15            P20_7
#define ESP8266_RST             P20_3
#define ESP8266_EN              P20_6

#define ESP8266_UART_CHANNEL    UART_2
#define ESP8266_UART_BAUDRATE   115200
#define ESP8266_UART_TX_PIN     UART2_TX_P33_9
#define ESP8266_UART_RX_PIN     UART2_RX_P33_8

#define ESP8266_WIFI_SSID          "601_IoT_WIFI"
#define ESP8266_WIFI_PASSWORD      "wuhcw64667_jsj"
#define ESP8266_WIFI_TARGET_IP     "192.168.1.111"
#define ESP8266_WIFI_TARGET_PORT   1347

#define ESP8266_CONFIG_SEND_PIN     ESP8266_IO0


typedef enum{
    ESP8266_Mode_Invalid = 0,
    ESP8266_Mode_Per_Config,
    ESP8266_Mode_Config,
    ESP8266_Mode_Working,
}esp8266_mode_enum;

typedef struct{
    uint8 ssid[64];
    uint8 password[128];
    uint8 target_ip[20];
    uint16 target_port;
    uint8 config_str[254];
}esp8266_config_t;

typedef struct{
    uint8 ip[16];
    uint8 mac[18];
}esp8266_status_t;

// extern uint8 esp8266_download_passthrough;

void ESP8266_Init(void);
void ESP8266_Uart_Callback(void);
void ESP8266_send_data(uint8 *data, uint32 len);
void ESP8266_Set_Config(uint8 *ssid, uint8 *password, uint8 *target_ip, uint16 target_port);
void ESP8266_Into_Change_Config_Mode(uint8 on);
// void ESP8266_Auto_Download_Uart_Hook(void);
// void ESP8266_Uart_Callback(void);
// void ESP8266_Main_Loop_Change_Mode(void);

// void ESP8266_send_ack_packet(void);

// void ESP8266_Init2(void);
// void ESP8266_send_sync_packet(void);

#endif /* CODE_ESP8266_H_ */
