/* 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) 2022 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 "stm32f0xx_hal.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 */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/**
 * Though PWM frequency and and ADC trigger rate can be adjusted in the STM32CubeIDE, the settings will be overwritten with manually written code in main.c.
 *
 * In STM32CubeIDE the PWM frequency can be found in TIM1 -> Parameter Settings -> Counter Period.
 * Because of center aligned mode, this value can be calculated this way (example for 10 kHz):
 * fTimer / desired PWM frequency / 2 = 48e6 / 10e3 / 2 = 2400.
 *
 * The ADC trigger rate can be controlled by the TIM8 repetition counter (RCR). This timer causes an Update Event (UEV) on every over- and underflow.
 * In center aligned mode, the timer counts in up- and down count mode and therefore causes an UEV twice per period.
 * To get 1 ADC trigger per period, the RCR has to be set to 1.
 * To get 1 ADC trigger on every 2nd period, the RCR has to be set to 3.
 */
/*------------------------------------------------------------------------*/
/* PWM Frequencies */
/*------------------------------------------------------------------------*/
#define PWM_FREQUENCY	(float)10e3             /**< PWM frequency of power stage [Hz] */
#define CONTROL_TASK_FREQUENCY_DIVIDER	1       /**< Ratio between sample frequency and PWM frequency */

#define CPU_CLK			(float)48e6
#define PWM_PERIOD		((uint16)(CPU_CLK/PWM_FREQUENCY/(float)2))

/* USER CODE END EM */

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

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

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define LD4_Pin GPIO_PIN_8
#define LD4_GPIO_Port GPIOC
#define LD3_Pin GPIO_PIN_9
#define LD3_GPIO_Port GPIOC
#define SWDIO_Pin GPIO_PIN_13
#define SWDIO_GPIO_Port GPIOA
#define SWCLK_Pin GPIO_PIN_14
#define SWCLK_GPIO_Port GPIOA

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
