/* 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) 2025 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 "stm32g4xx_hal.h"

#include "stm32g4xx_ll_ucpd.h"
#include "stm32g4xx_ll_bus.h"
#include "stm32g4xx_ll_cortex.h"
#include "stm32g4xx_ll_rcc.h"
#include "stm32g4xx_ll_system.h"
#include "stm32g4xx_ll_utils.h"
#include "stm32g4xx_ll_pwr.h"
#include "stm32g4xx_ll_gpio.h"
#include "stm32g4xx_ll_dma.h"

#include "stm32g4xx_ll_exti.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

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

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
#define SYSTEM_BOOTLOADER_START_ADDR		  0x1FFF0000
#define GOTO_SYSTEM_BOOTLOADER_MARK			  0xACCE55ED

#define VREF								  3000.0
/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

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

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define AUX_EN_Pin GPIO_PIN_13
#define AUX_EN_GPIO_Port GPIOC
#define ADC_START_CONV_Pin GPIO_PIN_0
#define ADC_START_CONV_GPIO_Port GPIOC
#define ADC_RESET_Pin GPIO_PIN_1
#define ADC_RESET_GPIO_Port GPIOC
#define LED_FUNCTION_Pin GPIO_PIN_4
#define LED_FUNCTION_GPIO_Port GPIOA
#define ADC2_IN3_UBAT__Pin GPIO_PIN_6
#define ADC2_IN3_UBAT__GPIO_Port GPIOA
#define ADC2_IN4_UBAT__Pin GPIO_PIN_7
#define ADC2_IN4_UBAT__GPIO_Port GPIOA
#define LTC_CHARGE_CURRENT_MON_Pin GPIO_PIN_0
#define LTC_CHARGE_CURRENT_MON_GPIO_Port GPIOB
#define ADC3_IN1_SHUNT_TEMP_Pin GPIO_PIN_1
#define ADC3_IN1_SHUNT_TEMP_GPIO_Port GPIOB
#define LED_ERROR_Pin GPIO_PIN_2
#define LED_ERROR_GPIO_Port GPIOB
#define BUZZER_Pin GPIO_PIN_10
#define BUZZER_GPIO_Port GPIOB
#define OVERWRITE_DISCHARGE_CTRL_Pin GPIO_PIN_11
#define OVERWRITE_DISCHARGE_CTRL_GPIO_Port GPIOB
#define OVERWRITE_CHARGE_CTRL_Pin GPIO_PIN_12
#define OVERWRITE_CHARGE_CTRL_GPIO_Port GPIOB
#define ADC3_IN5_LTC_DISCHARGE_CURRENT_MON_Pin GPIO_PIN_13
#define ADC3_IN5_LTC_DISCHARGE_CURRENT_MON_GPIO_Port GPIOB
#define ADC4_IN4_U_SHUNT_SENSE__Pin GPIO_PIN_14
#define ADC4_IN4_U_SHUNT_SENSE__GPIO_Port GPIOB
#define ADC4_IN5_U_SHUNT_SENSE__Pin GPIO_PIN_15
#define ADC4_IN5_U_SHUNT_SENSE__GPIO_Port GPIOB
#define LVP_SENSE_Pin GPIO_PIN_8
#define LVP_SENSE_GPIO_Port GPIOA
#define OVP_SENSE_Pin GPIO_PIN_9
#define OVP_SENSE_GPIO_Port GPIOA
#define GPIO_INPUT_BTN_MODE_Pin GPIO_PIN_10
#define GPIO_INPUT_BTN_MODE_GPIO_Port GPIOA
#define ADC_DATA_READY_Pin GPIO_PIN_2
#define ADC_DATA_READY_GPIO_Port GPIOD
#define ADC_DATA_READY_EXTI_IRQn EXTI2_IRQn
#define FAULT_INT_Pin GPIO_PIN_7
#define FAULT_INT_GPIO_Port GPIOB
#define FAULT_INT_EXTI_IRQn EXTI9_5_IRQn
#define COM_POWERPRO_RES_Pin GPIO_PIN_9
#define COM_POWERPRO_RES_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */
// mögliche Kommandos für das Command Register
#define COMMAND_STORE_CONFIG								1
#define COMMAND_FULL_RESTORE								2
#define COMMAND_FACTORY_RESTORE								3
#define COMMAND_RESTORE_LAST_SAVED_VALUES					4
#define COMMAND_RESTART										6
#define COMMAND_BATTERY_CURRENT_OFFSET_CAL					7
#define COMMAND_BATTERY_CURRENT_OFFSET_COMMONMODE_CAL		8
#define COMMAND_BATTERY_CURRENT_OFFSET_TEMP_CAL				9
#define COMMAND_BATTERY_CURRENT_GAIN_CAL					10
#define COMMAND_BATTERY_CURRENT_GAIN_TEMP_SHUNT_CAL			11
//#define COMMAND_BATTERY_CURRENT_GAIN_TEMP_CHIP_CAL		12
#define COMMAND_STORE_WITH_SERIAL_NUMBER					1234
#define COMMAND_SET_RDP_LEVEL0								1010
#define COMMAND_SET_RDP_LEVEL1								1011
#define COMMAND_SET_RDP_LEVEL1_AND_BOOTSEL					1012
#define COMMAND_GOTO_SYS_BOOTLOADER							5458				// Looks like SYSB = System Bootloader

enum SOC_CALC_MODE{
  SOC_CALC_MODE_AH_RATED,
  SOC_CALC_MODE_AH_AUTO,
  SOC_CALC_MODE_WH_RATED,
  SOC_CALC_MODE_WH_AUTO,
  SOC_CALC_MODE_WH_AUTO_TEMP,
};

enum AUX_MODE{
  AUX_MODE_OFF,
  AUX_MODE_HEATER,
  AUX_MODE_SOC,
  AUX_MODE_ALARM,
};
/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
