#ifndef _SOFT_FLASH_
#define _SOFT_FLASH_
#include "stm32f1xx_hal.h"
#include "stdbool.h"

extern bool write_vol_information;
extern bool write_uav_information;
extern bool write_serial_information;
struct date_vol // 电压校准信息
{
    short _vol_flag;
    short cal_vol; // 0.1v
};
extern struct date_vol volinf;
extern short set_cali_voltage;
extern uint32_t set_pmu_serail;

struct pmu_serial // 电压校准信息
{
    short _flag;
    uint32_t num;
};
extern struct pmu_serial serial;

typedef enum
{
    R_Default = 0,
    R_NRST = 1,   // 引脚复位
    R_POWER = 2,  // 上电掉电复位
    R_SOFT = 3,   // 软件复位
    R_IWD = 4,    // 独立看门狗复位
    R_WWD = 5,    // 窗口看门狗复位
    R_LOPWER = 6, // 低功耗复位
} Reset;
struct uav_type // 电压校准信息
{
    short _uavtype_flag;
    short uavtype;              // 机型 用于管脚初始化
    short abnormal_outage_flag; // 异常断电标志
    short reset_reason;         // 重启原因
};
extern struct uav_type uavinf;
// bootloader flag在120kb

// 现在每个参数用了1kb，应该初始化两个结构体参数，整合到一起,PMU要改版，先不改了
// 125kb
#define FLASH_SERIAL_IFO (uint32_t)0x801F400
// 126kb
#define FLASH_VOL_IFO (uint32_t)0x801F800
// 127kb
#define FLASH_UAV_IFO (uint32_t)0x801FC00
// 128kb
#define FLSH_MAX_SIZE (uint32_t)0x801FFFF

void ReadFlashNBtye(uint32_t ReadAddress, uint8_t *pdata, uint16_t size);

HAL_StatusTypeDef WriteFlashNBtye(uint32_t ReadAddress, uint8_t *pdata, uint16_t size);

short check_flash_par_normal(short par, short min_par, short max_par, uint8_t par_or_zero);

void write_flash_function(void);
void read_flash_function(void);

void flash_read_funcktion(void);
#endif
