/* 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) 2024 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 "stm32l4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#define RS485_TX_ENABLE()  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET)   // PA1拉高，RS485进入发�?�模�?
#define RS485_RX_ENABLE()  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET) // PA1拉低，RS485进入接收模式

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
#include <string.h> //memset
#include <stdio.h>	//printf
#include <stdbool.h> // bool
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include "ML307A.h"
#include "DWIN.h"
#include "FLASH.h"
#include <time.h>
#include "RTCtime.h"
#include "circle_buffer.h"
#include "WIFI.h"
#include "w25qxx.h"
/* USER CODE END ET */

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

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/**
	* @breaf 串口接收缓冲区大小
  */
#define BUFFER_SIZE 30
#define BUFFER_SIZE2 256
#define BUFFER_SIZE4G 512

/**
  * @breaf 内部flash参数定义
	* STM32L431RCT6 的Flash容量256KB，RAM容量64KB。
	* STM32L431RCT6 的内部 Flash 起始地址是 0x08000000，每页 2KB（0x800）2048个字节，共有0到127页
	* 计算第N页的起始地址 起始地址 = Flash起始地址 + 页号 × 每页大小
  */
#define FLASH_PAGE_ADDR(page) (0x08000000 + (page) * 0x800) // 每页2KB=0x800

#define FLASH_LAST_PAGE_ADDR 0x0801FC00 // STM32L431RCT6 内部Flash第127页起始地址 存阈值参数
#define FLASH_SECOND_LAST_PAGE_ADDR 0x0801F400 // STM32L431RCT6 内部Flash第126页起始地址 存终端ID和手机号
#define FLASH_THIRD_LAST_PAGE_ADDR 0x0801EC00 // STM32L431RCT6 内部Flash第125页起始地址 记录外部flash的写入地址
#define FLASH_FOURTH_LAST_PAGE_ADDR 0x0801E400 // STM32L431RCT6 内部Flash第124页起始地址 记录版本号
#define FLASH_FIFTH_LAST_PAGE_ADDR 0x0801DC00 // STM32L431RCT6 内部Flash第123页起始地址 存储WIFI名称密码
#define FLASH_SIXTH_LAST_PAGE_ADDR 0x0801D400 // STM32L431RCT6 内部Flash第122页起始地址 存储4G或WIFI模式标志位
/* USER CODE END EM */

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

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define DWIN_12V_Pin GPIO_PIN_0
#define DWIN_12V_GPIO_Port GPIOC
#define V5V_DC_EN_Pin GPIO_PIN_1
#define V5V_DC_EN_GPIO_Port GPIOC
#define V12V_EN_Pin GPIO_PIN_2
#define V12V_EN_GPIO_Port GPIOC
#define V3_8V_4G_enable_Pin GPIO_PIN_4
#define V3_8V_4G_enable_GPIO_Port GPIOC
#define RESET_4G_Pin GPIO_PIN_2
#define RESET_4G_GPIO_Port GPIOB
#define SPI2_CS_Pin GPIO_PIN_12
#define SPI2_CS_GPIO_Port GPIOB
#define CAN_RS_Pin GPIO_PIN_15
#define CAN_RS_GPIO_Port GPIOA
#define CAN_SHDT_Pin GPIO_PIN_10
#define CAN_SHDT_GPIO_Port GPIOC
#define V5V_CAN_EN_Pin GPIO_PIN_2
#define V5V_CAN_EN_GPIO_Port GPIOD
#define mcuLED_Pin GPIO_PIN_5
#define mcuLED_GPIO_Port GPIOB
#define alarm_LED_Pin GPIO_PIN_6
#define alarm_LED_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
