
/* 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 */

  /* USER CODE END Includes */

  /* Exported types ------------------------------------------------------------*/
  /* USER CODE BEGIN ET */

  /* USER CODE END ET */

  /* Exported constants --------------------------------------------------------*/
  /* USER CODE BEGIN EC */
  extern SPI_HandleTypeDef hspi1;
  extern TIM_HandleTypeDef htim2; // using Timer 2 for RPM counting via PIP signal
/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
#define RPMTIMER 2 // define the timer
#define AUXILIARY_HIGH {};
#define AUXILIARY_LOW triggerSAW();
  // scale for filtered RPM samples
  static const float Scale = 1.0;
  /* USER CODE END EM */

  void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

  /* Exported functions prototypes ---------------------------------------------*/
  void Error_Handler(void);

  // code required to use libPlx/commsLib.h
  // this is called when it is time to format data for sending from this
  // processor rather than just forwarding data.
  extern void libPLXcallbackSendUserData();

  /* USER CODE BEGIN EFP */
  void triggerSAW(); // Generate a SAW pulse

  // trigger watchdog
  void watchdogWrite();

/* USER CODE END EF`P */

/* Private defines -----------------------------------------------------------*/
#define SAW_DELAY 5
#define PIP_Pin GPIO_PIN_0
#define PIP_GPIO_Port GPIOA
#define SPI1_NSS_Pin GPIO_PIN_4
#define SPI1_NSS_GPIO_Port GPIOA
#define SPI1_RESET_Pin GPIO_PIN_6
#define SPI1_RESET_GPIO_Port GPIOA
#define SPI1_CD_Pin GPIO_PIN_0
#define SPI1_CD_GPIO_Port GPIOB
#define PUSHBUTTON_Pin GPIO_PIN_12
#define PUSHBUTTON_GPIO_Port GPIOB
#define SAW_Pin GPIO_PIN_8
#define SAW_GPIO_Port GPIOA
#define dualSpark_Pin GPIO_PIN_9
#define dualSpark_GPIO_Port GPIOA
  /* USER CODE BEGIN Private defines */

  /* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
