/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file: main.h															   *
  * @author  Yunhorn (r) Technology Limited Application Team	               *
  * @brief   Yunhorn (r) SmarToilets (r) Product configuration file.		   *
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 Yunhorn Technology Limited.
  * Copyright (c) 2023 Shenzhen Yunhorn Technology Co., Ltd.
  * 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 "stm32wlxx_hal.h"
#include "yunhorn_sts_prd_conf.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 */

/* USER CODE END EM */

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

/* USER CODE BEGIN EFP */
void MX_I2C2_Init(void);
void MX_DMA_Init(void);
void MX_TOF_Init(void);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define RTC_N_PREDIV_S 10
#define RTC_PREDIV_S ((1<<RTC_N_PREDIV_S)-1)
#define RTC_PREDIV_A ((1<<(15-RTC_N_PREDIV_S))-1)

#if	defined(STM32WL55xx)
#define LED1_Pin GPIO_PIN_15
#define LED1_GPIO_Port GPIOB
#define LED2_Pin GPIO_PIN_9
#define LED2_GPIO_Port GPIOB
#define LED3_Pin GPIO_PIN_11
#define LED3_GPIO_Port GPIOB
#define BSP_BUTTON_EXTI_IRQn EXTI0_IRQn
#define PROB2_Pin GPIO_PIN_13
#define PROB2_GPIO_Port GPIOB
#define PROB1_Pin GPIO_PIN_12
#define PROB1_GPIO_Port GPIOB
#endif

#if defined(STM32WLE5xx)
#define LED1_Pin GPIO_PIN_2
#define LED1_GPIO_Port GPIOB
#define LED_ON	HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET )
#define LED_OFF	HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET )
#define BSP_BUTTON_EXTI_IRQn EXTI0_IRQn

#define LED2_Pin LED1_Pin
#define LED2_GPIO_Port LED1_GPIO_Port
#define LED3_Pin LED1_Pin
#define LED3_GPIO_Port LED1_GPIO_Port
#endif

#define BUT1_Pin GPIO_PIN_0
#define BUT1_GPIO_Port GPIOA
#define BUT1_EXTI_IRQn EXTI0_IRQn

#define BUT2_Pin GPIO_PIN_1
#define BUT2_GPIO_Port GPIOA
#define BUT2_EXTI_IRQn EXTI1_IRQn

#if	defined(STM32WL55xx)
#define BUT3_Pin GPIO_PIN_6
#define BUT3_GPIO_Port GPIOC
#define BUT3_EXTI_IRQn EXTI9_5_IRQn
#endif

#define USARTx_RX_Pin GPIO_PIN_3
#define USARTx_RX_GPIO_Port GPIOA
#define USARTx_TX_Pin GPIO_PIN_2
#define USARTx_TX_GPIO_Port GPIOA

#define MEMS_POWER_Pin							GPIO_PIN_4				// PMU_ENABLE
#define MEMS_POWER_GPIO_Port 					GPIOB					// PMU_ENABLE

#define MEMS_RESET_Pin							GPIO_PIN_4
#define MEMS_RESET_GPIO_Port 					GPIOB

#define TOF250_I2C_ADDR        	(0x52<<1)

#if	defined(STM32WLE5xx) || defined(STM32WL55xx)
#define	I2C2_SCL_PIN	GPIO_PIN_12
#define	I2C2_SDA_PIN	GPIO_PIN_11
#define	I2C2_SCL_PORT	GPIOA
#define	I2C2_SDA_PORT	GPIOA
#endif

/* USER CODE BEGIN Private defines */


/*  -------------------- | --------------------	*/
/*  |                    |            		  |	*/
/*  | TOF-2              |	       TOF-1      | */
/*  -------------------- | ------------------ |	*/
/*     U4, PA-9          |    U3, PB-3        |	*/


/*    TOF_1, U3      RIGHT CORNER, PB-3         */

#if	defined(TOF_1)&& defined(STM32WLE5xx)
#define TOF_C_INT_Pin GPIO_PIN_5
#define TOF_C_INT_GPIO_Port GPIOB
#define TOF_C_INT_EXTI_IRQn EXTI9_5_IRQn
#define TOF_C_XSHUT_Pin GPIO_PIN_3
#define TOF_C_XSHUT_GPIO_Port GPIOB
#endif

// Common Shared Int Pin and Port for VL53L0X
#if	defined(TOF_1)||defined(TOF_2)||defined(TOF_3)
#define TOF_INT_EXTI_PIN	GPIO_PIN_5		//TOF_C_INT_Pin
#define TOF_INT_EXTI_PORT	GPIOB			//TOF_C_INT_GPIO_Port
#endif

/*    TOF_2,                     */
#if	defined(TOF_2) && defined(STM32WL55xx)
#define TOF_L_INT_Pin GPIO_PIN_7
#define TOF_L_INT_GPIO_Port GPIOC
#define TOF_L_INT_EXTI_IRQn EXTI9_5_IRQn
#define TOF_L_XSHUT_Pin GPIO_PIN_10
#define TOF_L_XSHUT_GPIO_Port GPIOB
#endif


/*    TOF_2, U4      LEFT   CORNER, PA-9       */
#if	defined(TOF_1) && defined(STM32WLE5xx)
#define TOF_L_INT_Pin GPIO_PIN_5
#define TOF_L_INT_GPIO_Port GPIOB
#define TOF_L_INT_EXTI_IRQn EXTI9_5_IRQn
#define TOF_L_XSHUT_Pin GPIO_PIN_9
#define TOF_L_XSHUT_GPIO_Port GPIOA
#endif


/*    TOF_3                    */
#if	defined(STM32WL55xx)&& defined(TOF_3)
#define TOF_R_INT_Pin GPIO_PIN_10
#define TOF_R_INT_GPIO_Port GPIOA
#define TOF_R_INT_EXTI_IRQn EXTI15_10_IRQn
#define TOF_R_XSHUT_Pin GPIO_PIN_5
#define TOF_R_XSHUT_GPIO_Port GPIOB
#endif


/*    TOF_3                    */
#if	defined(STM32WLE5xx)&& defined(TOF_3)
#define TOF_R_INT_Pin GPIO_PIN_5
#define TOF_R_INT_GPIO_Port GPIOB
#define TOF_R_INT_EXTI_IRQn EXTI9_5_IRQn
#define TOF_R_XSHUT_Pin GPIO_PIN_10
#define TOF_R_XSHUT_GPIO_Port GPIOA
#endif

#if defined(SOAP_LEVEL)
/* IF_SOAP_IN, MEMS_IF_3, PA10  */
#define SOAP_STATUS_Pin				GPIO_PIN_10
#define SOAP_STATUS_GPIO_Port		GPIOA

/* IF_SENSOR_ON_OFF, MEMS_IF_1, PB3   */
#define SOAP_SWITCH_Pin				GPIO_PIN_3
#define SOAP_SWITCH_GPIO_Port		GPIOB

#define SOAP_DATA		HAL_GPIO_ReadPin(SOAP_STATUS_GPIO_Port,SOAP_STATUS_Pin)
#endif

#define	STS_SERVICE_MASK_L0		(0)		// Service normal , no mask off
#define	STS_SERVICE_MASK_L1		(1)		// service mask level 1, sensing data upload in silence mode, node appearance silence (no LED, No display, no sound, no vibration)
#define	STS_SERVICE_MASK_L2		(2)		// service mask level 2, NO sensing data upload (event or periodicity)
#define	STS_SERVICE_MASK_L3		(3)		// service mask level 3, NO responsing to cloud control command, or config change/responding, EXCEPT STS_SERVICE_MASK_ON_OFF cmd
//#define	STS_SERVICE_MASK_L4		(1<<4)		// service mask level 4, level 3 + node states heart-beat(predefined long periodicity off), EXCEPT STS_SERVICE_MASK_ON_OFF cmd

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
