/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "string.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
extern uint8_t receive_buffer[30];  // 定义接收缓存，这里假设最多可以接收100个字节
extern uint8_t flag ;

extern uint16_t Adc2_CalibrationValue ;
extern uint16_t Adc3_CalibrationValue ;

extern uint8_t gpioaStatus ;
extern uint8_t gpiobStatus ;

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */
uint16_t read_flash_16(uint32_t flash_address);
void read_new_address_from_flash(uint32_t flash_address);
void erase_flash(uint32_t ADDR_FLASH);
void write_flash_address(uint8_t* rx_buffer);
void write_flash_PbStatus(uint8_t* rx_buffer);
void write_flash_autoAdc(uint32_t ADDR_FLASH);
void CoverADC(uint32_t ADDR);
void write_flash_Baudrate(uint8_t* rx_buffer);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/

/* USER CODE BEGIN Private defines */
#define FILTER_LENGTH 10
#define DEBOUNCE_COUNT 10
#define Modbus 1
#define ADDR_FLASH_PAGE_61   ((uint32_t)0x0800A000)  // Flash扇区61的起始地址      address
#define ADDR_FLASH_PAGE_62   ((uint32_t)0x0800C000)  // Flash扇区62的起始地址      PbStatus
#define ADDR_FLASH_PAGE_63   ((uint32_t)0x0800E000)  // Flash扇区63的起始地址      Baudrate
#define ADDR_FLASH_PAGE_64   ((uint32_t)0x0800EC00)  // Flash扇区64的起始地址      Adc2_Calibration    4-20mA
#define ADDR_FLASH_PAGE_65   ((uint32_t)0x0800F000)  // Flash扇区65的起始地址      Adc3_Calibration    4-20mA
#define ADDR_FLASH_PAGE_66   ((uint32_t)0x0800FC00)  // Flash扇区66的起始地址      

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
