/**
  *******************************************************************************
  * @file    yunhorn_sts_prd_conf.h												*
  * @author  Yunhorn (r) Technology Limited Application Team	                *
  * @brief   Yunhorn (r) SmarToilets (r) Product configuration file.			*
  *******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 Yunhorn Technology Limited.
  * Copyright (c) 2022 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 __YUNHORN_STS_PRD_CONF_H__
#define __YUNHORN_STS_PRD_CONF_H__

#ifdef __cplusplus
 extern "C" {
#endif

/* Exported types -------------------------------------------------------------*/
/* Exported constants ---------------------------------------------------------*/

/* 
 * MCU CORE SELECTION
 */
#define  			STS_USE_STM32WLE5					1U						//STM32WLE5CCUX
//#define  			USE_STM32WL55					1U							//STM32WL55JC1X

/*
 *	MODULE SELECTION
 */
//#define 				USE_OLED_SSD1306
//#define					USE_TOF_VL53L1X
//#define				STS_USE_TOF_VL53L0X		1U
//#define				YUNHORN_STS_R1_ENABLED
#define				YUNHORN_STS_R3_ENABLED
#define				YUNHORN_STS_R4_ENABLED


 // TOF VL53LX number
//#define					USE_MEMS_ADXL345
//#define						USE_ACCONEER_A111
/* ########################## Product Selection ############################## */
/**
  * @brief This is the list of Yunhorn STS products to be used in ALL product config
  */

/**   YUNHORN SMARTOILETS OCCUPANCY PRODUCTS 									**/
/*#define YUNHORN_STS_O1_ENABLED		*/
/*#define YUNHORN_STS_O2_ENABLED		*/
/*#define YUNHORN_STS_O3_ENABLED		*/
/*#define YUNHORN_STS_O4_ENABLED		*/
/*#define YUNHORN_STS_O5_ENABLED		*/
/*#define YUNHORN_STS_O6_ENABLED		*/
/*#define YUNHORN_STS_O7_ENABLED		*/
/*#define YUNHORN_STS_O8_ENABLED		*/
/*#define YUNHORN_STS_O9_ENABLED		*/
/*#define YUNHORN_STS_O10_ENABLED		*/

 /*#define YUNHORN_STS_O6_ENABLED		*/

/**   YUNHORN SMARTOILETS ENVIRONMENT PRODUCTS  							**/
/*#define YUNHORN_STS_E1_ENABLED		*/
/*#define YUNHORN_STS_E2_ENABLED		*/
/*#define YUNHORN_STS_E3_ENABLED		*/
/*#define YUNHORN_STS_E4_ENABLED		*/
/*#define YUNHORN_STS_E5_ENABLED		*/
/*#define YUNHORN_STS_E6_ENABLED		*/


/**   YUNHORN SMARTOILETS PEOPLE COUNTING PRODUCTS						**/
/*#define YUNHORN_STS_P1_ENABLED		*/
/*#define YUNHORN_STS_P2_ENABLED		*/
/*#define YUNHORN_STS_P3_ENABLED		*/
/*#define YUNHORN_STS_P4_ENABLED		*/
/*#define YUNHORN_STS_P5_ENABLED		*/
/*#define YUNHORN_STS_P6_ENABLED		*/

/**   YUNHORN SMARTOILETS CLEANSING RESOUCES LEVEL PRODUCTS		**/
//#define YUNHORN_STS_R0_ENABLED
//#define YUNHORN_STS_R0_ENABLED
//#define YUNHORN_STS_R2_ENABLED
/*#define YUNHORN_STS_R3_ENABLED		*/
/*#define YUNHORN_STS_R4_ENABLED		*/

/*#define YUNHORN_STS_R6_ENABLED		*/
/*#define YUNHORN_STS_R7_ENABLED		*/
/*#define YUNHORN_STS_R8_ENABLED		*/


/**   YUNHORN SMARTOILETS MECHNICAL REACTURAL PRODUCTS				**/
/*#define YUNHORN_STS_M1_ENABLED		*/
/*#define YUNHORN_STS_M2_ENABLED		*/
/*#define YUNHORN_STS_M3_ENABLED		*/
/*#define YUNHORN_STS_M4_ENABLED		*/
/*#define YUNHORN_STS_M5_ENABLED		*/
/*#define YUNHORN_STS_M6_ENABLED		*/

/*#define YUNHORN_STS_M7_ENABLED		*/

/*#define YUNHORN_STS_M8_ENABLED		*/
/*#define YUNHORN_STS_M9_ENABLED		*/
//#define YUNHORN_STS_M10_ENABLED

/**   YUNHORN SMARTOILETS DIPLAY AND SMART PANEL PRODUCTS			**/
/*#define YUNHORN_STS_D1_ENABLED		*/
/*#define YUNHORN_STS_D2_ENABLED		*/
/*#define YUNHORN_STS_D3_ENABLED		*/
/*#define YUNHORN_STS_D4_ENABLED		*/
/*#define YUNHORN_STS_D5_ENABLED		*/
/*#define YUNHORN_STS_D6_ENABLED		*/
/*#define YUNHORN_STS_D7_ENABLED		*/
/*#define YUNHORN_STS_D8_ENABLED		*/



/**   YUNHORN SMARTOILETS DIGITAL SIGNAGE PRODUCTS						**/
/*#define YUNHORN_STS_F1_ENABLED		*/
/*#define YUNHORN_STS_F2_ENABLED		*/
/*#define YUNHORN_STS_F3_ENABLED		*/
/*#define YUNHORN_STS_F4_ENABLED		*/
/*#define YUNHORN_STS_F5_ENABLED		*/
/*#define YUNHORN_STS_F6_ENABLED		*/
/*#define YUNHORN_STS_F7_ENABLED		*/
/*#define YUNHORN_STS_F8_ENABLED		*/
/*#define YUNHORN_STS_F9_ENABLED		*/
/*#define YUNHORN_STS_F10_ENABLED		*/


/**   YUNHORN SMARTOILETS CONNECTIVITY AND GATEWAY PRODUCTS		**/
/*#define YUNHORN_STS_N1_ENABLED		*/
/*#define YUNHORN_STS_N2_ENABLED		*/
/*#define YUNHORN_STS_N3_ENABLED		*/
/*#define YUNHORN_STS_N4_ENABLED		*/
/*#define YUNHORN_STS_N5_ENABLED		*/
/*#define YUNHORN_STS_N6_ENABLED		*/
/*#define YUNHORN_STS_N7_ENABLED		*/
/*#define YUNHORN_STS_N8_ENABLED		*/


/** Includes ---------------------------------------------------------
 * @brief YUNHORN SMARTOILETS SENSOR
 * LORA-WAN MESSAGE UPLINK DATA PORTS AND HEARTBEAT PORTS DEFINATION
 */

//#define YUNHORN_STS_O1_LORA_APP_DATA_PORT         4U
//#define YUNHORN_STS_O1_LORA_APP_HTBT_PORT         5U
//#define YUNHORN_STS_O2_LORA_APP_DATA_PORT         4U
//#define YUNHORN_STS_O2_LORA_APP_HTBT_PORT         5U
//#define YUNHORN_STS_O3_LORA_APP_DATA_PORT         4U
//#define YUNHORN_STS_O3_LORA_APP_HTBT_PORT         5U
//#define YUNHORN_STS_O4_LORA_APP_DATA_PORT         56U
//#define YUNHORN_STS_O4_LORA_APP_HTBT_PORT         57U
#ifdef STS_O5
#define YUNHORN_STS_O5_LORA_APP_DATA_PORT         4U
#define YUNHORN_STS_O5_LORA_APP_HTBT_PORT         5U
#endif

//#define YUNHORN_STS_O6_LORA_APP_DATA_PORT         17U
//#define YUNHORN_STS_O6_LORA_APP_HTBT_PORT         18U
//#define YUNHORN_STS_O6_USER_APP_CTRL_PORT			2U
//#define YUNHORN_STS_O6_USER_APP_CTRL_REPLY_PORT	1U

//#define YUNHORN_STS_E1_LORA_APP_DATA_PORT         102U
//#define YUNHORN_STS_E1_LORA_APP_HTBT_PORT         103U
//#define YUNHORN_STS_E2_LORA_APP_DATA_PORT         101U
//#define YUNHORN_STS_E2_LORA_APP_HTBT_PORT         108U
//#define YUNHORN_STS_E3_LORA_APP_DATA_PORT         00U
//#define YUNHORN_STS_E3_LORA_APP_HTBT_PORT         00U

//#define YUNHORN_STS_E4_LORA_APP_DATA_PORT         70U
//#define YUNHORN_STS_E4_LORA_APP_HTBT_PORT         71U


#define YUNHORN_STS_USER_APP_CTRL_PORT				2U
#define YUNHORN_STS_USER_APP_CTRL_REPLY_PORT		1U

#ifdef  YUNHORN_STS_R1_ENABLED
#define YUNHORN_STS_R1_LORA_APP_DATA_PORT         57U
#define YUNHORN_STS_R1_LORA_APP_HTBT_PORT         58U
#endif

#ifdef  YUNHORN_STS_R2_ENABLED
#define YUNHORN_STS_R2_LORA_APP_DATA_PORT         57U
#define YUNHORN_STS_R2_LORA_APP_HTBT_PORT         58U
#endif
#ifdef  YUNHORN_STS_R3_ENABLED
#define YUNHORN_STS_R3_LORA_APP_DATA_PORT         7U
#define YUNHORN_STS_R3_LORA_APP_HTBT_PORT         8U
#endif
#ifdef  YUNHORN_STS_R4_ENABLED
#define YUNHORN_STS_R4_LORA_APP_DATA_PORT         7U
#define YUNHORN_STS_R4_LORA_APP_HTBT_PORT         8U
#endif

#ifdef YUNHORN_STS_R0_ENABLED
#define YUNHORN_STS_R0_LORA_APP_DATA_PORT         	10U
#define YUNHORN_STS_R0_LORA_APP_HTBT_PORT         	11U
#endif

#ifdef YUNHORN_STS_R5_ENABLED
// FOR ROCTEC R5, 2023-10-28
#define YUNHORN_STS_R5_LORA_APP_DATA_PORT         11U
#define YUNHORN_STS_R5_LORA_APP_HTBT_PORT         12U
#endif
//#define YUNHORN_STS_M1_LORA_APP_DATA_PORT         6U
//#define YUNHORN_STS_M1_LORA_APP_HTBT_PORT         6U
//#define YUNHORN_STS_M2_LORA_APP_DATA_PORT         59U
//#define YUNHORN_STS_M2_LORA_APP_HTBT_PORT         219U
//#define YUNHORN_STS_M3_LORA_APP_DATA_PORT         9U
//#define YUNHORN_STS_M3_LORA_APP_HTBT_PORT         9U
//#define YUNHORN_STS_M4_LORA_APP_DATA_PORT         12U
//#define YUNHORN_STS_M4_LORA_APP_HTBT_PORT         12U
//#define YUNHORN_STS_M5_LORA_APP_DATA_PORT         8U
//#define YUNHORN_STS_M5_LORA_APP_HTBT_PORT         8U
//#define YUNHORN_STS_M6_LORA_APP_DATA_PORT         219U
//#define YUNHORN_STS_M6_LORA_APP_HTBT_PORT         219U

//#define YUNHORN_STS_M8_LORA_APP_DATA_PORT         55U
//#define YUNHORN_STS_M8_LORA_APP_HTBT_PORT         55U
//#define YUNHORN_STS_M9_LORA_APP_DATA_PORT         16U
//#define YUNHORN_STS_M9_LORA_APP_HTBT_PORT         16U
//#define YUNHORN_STS_M10_LORA_APP_DATA_PORT        9U
//#define YUNHORN_STS_M10_LORA_APP_HTBT_PORT        9U



#define MajorVer									23U
#define MinorVer									11U
#define SubMinorVer 								18U
#define FirmwareVersion								3U
#define	YUNHORN_STS_MAX_NVM_CFG_SIZE				64U
#define YUNHORN_STS_AC_CODE_SIZE					20U

#define	STS_NVM_CFG_SIZE							32U
#define STS_CFG_PCFG_SIZE							28U
#define	STS_CFG_CMD_SIZE							30U
#define STS_CFG_CMD_SHORT_LEN						8U
#define STS_MODE_COLOR_CMD_LEN						5U


#define	STS_R0_NVM_CFG_SIZE							16U
#define	STS_R0_CFG_CMD_SIZE							12U
#define CFG_CMD_TOF_SIMPLE_SIZE						(STS_R0_CFG_CMD_SIZE)

#ifdef YUNHORN_STS_R1_ENABLED
#define sts_mtmcode1								0U
#define sts_mtmcode2								57U
#define sts_hardware_ver							1U
#define sts_version									1U
#define sts_senddataport						(YUNHORN_STS_R1_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_R1_LORA_APP_HTBT_PORT)
#endif

#ifdef YUNHORN_STS_R4_ENABLED
#define sts_mtmcode1								0U
#define sts_mtmcode2								86U
#define sts_hardware_ver							1U
#define sts_version									1U
#define sts_senddataport						(YUNHORN_STS_R4_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_R4_LORA_APP_HTBT_PORT)
#endif


#ifdef YUNHORN_STS_R5_ENABLED
#define sts_mtmcode1								0U
#define sts_mtmcode2								16U
#define sts_hardware_ver							1U
#define sts_version									1U
#define sts_senddataport						(YUNHORN_STS_R5_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_R5_LORA_APP_HTBT_PORT)
#endif

#define sts_appctrlport							(YUNHORN_STS_USER_APP_CTRL_PORT)
#define sts_appctrl_reply_port					(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT)

#ifdef STS_O5
#define YUNHORN_STS_O5_ENABLED						1U
#define sts_mtmcode1								0U
#define sts_mtmcode2								5U
#define sts_hardware_ver							1U
#define sts_version									1U
#define sts_senddataport						(YUNHORN_STS_O5_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_O5_LORA_APP_HTBT_PORT)
#endif


//#define	NVM_CFG_PARAMETER_SIZE					(STS_R0_NVM_CFG_SIZE)


#ifdef  STS_USE_TOF_VL53L0X														// RETIRED TODO
#define I2C_TIMING_TOF250			0x20303E5D
#define I2C_TIMING 					0x20303E5D						//DEFAULT FOR I2C TOF
#endif

#define STS_Status_Door_Close                (0)		//Normal Close NC:Open
#define STS_Status_Door_Open                 (1)		//Normal Close NC:Close
#define STS_Reed_Hall_State			HAL_GPIO_ReadPin(BUT1_GPIO_Port, BUT1_Pin)

enum sts_lamp_color {
	STS_DARK = 0,	//灭：0
	STS_GREEN,		//绿：1 0 1 0
	STS_RED,		//红：2 1 0 0
	STS_BLUE,		//蓝：3 0 0 1
	STS_YELLOW,		//黄：4 1 1 0
	STS_PINK,		//紫：5 1 0 1
	STS_CYAN,		//青：6 0 1 1
	STS_WHITE,		//白：7 1 1 1
	STS_RED_BLUE	//红蓝闪烁：8
};

 enum sts_oo_work_mode {
	STS_NETWORK_MODE = 0,		// 0    NETWORK MODE
	STS_WIRED_MODE,				// 1    WIRED MODE   === WATER LEAKAGE, SOAP CAPACITY SENSOR MODE
	STS_REEDSWITCH_MODE,		// 2	REED SWITCH ONLY
	STS_RSS_MODE,				// 3  	RSS ONLY
	STS_DUAL_MODE,  			// 4	RSS + REED SWITCH IN ONE UNIT
	STS_REMOTE_REED_RSS_MODE,  	// 5	REMOTE REED SWITCH + RSS MODE	2023-05-04
	STS_DUAL_RSS_MODE,			// 6    RSS_1 + RSS_2 IN TWO UNITS
	STS_TOF_RSS_MODE,			// 7	TOF + RSS MODE
	STS_TOF_DISTANCE_MODE,		// 8	TOF DISTANCE
	STS_TOF_PRESENCE_MODE,		// 9 	TOF PRESENCE OCCUPANCY
	STS_TOF_IN_OUT_MODE,		// A    TOF IN OUT COUNT
	STS_FALL_DETECTION_MODE,	// B    DUAL_MODE + FALL DETECTION

	STS_OTHER_MODE				// ?    OTHER MODE
};


#ifdef    YUNHORN_STS_O6_ENABLED
#define	STS_O6_NVM_CFG_SIZE							30U
#define	STS_O6_CFG_CMD_SIZE							30U
#define STS_O6_CFG_CMD_SHORT_LEN					8U
#define STS_MODE_COLOR_CMD_LEN						5U
#define	CFG_CMD_RSS_FULL_SIZE					(STS_O6_CFG_CMD_SIZE)
#define	CFG_CMD_RSS_SIMPLE_SIZE					(STS_O6_CFG_CMD_SHORT_LEN)
#define	CFG_CMD_MODE_COLOR_LENGTH				(STS_MODE_COLOR_CMD_LEN)
#endif

#ifdef  USE_STM32WLE5
#define	PRESENCE_SENSOR_SPI_HANDLE		hspi1
#define PRESENCE_SENSOR_TIM_HANDLE		htim2
#define PRESENCE_SENSOR_I2C_HANDLE 		hi2c2
#endif

#ifdef	USE_OLED_SSD1306
#define SSD1306_I2C_HANDLE	hi2c2
#include "ssd1306.h"
#include "ssd1306_tests.h"
#endif


#ifdef  USE_STM32WLE5
#define I2C_TIMING_STANDARD_MODE			0x2000090E  //STANDARD MODE 100Khz
#define I2C_TIMING_FAST_MODE					0x2010091A  //FAST MODE 400Khz
#define I2C_TIMING_FAST_PLUS_MODE			0x20000209  //FAST PLUS MODE 1000Khz
#endif

#ifdef  USE_STM32WL55															//DEFAULT for MEMS_ADXL345
#define I2C_TIMING_STANDARD_MODE			0x2000090E  //STANDARD MODE 100Khz
#define I2C_TIMING_FAST_MODE					0x2010091A  //FAST MODE 400Khz
#define I2C_TIMING_FAST_PLUS_MODE			0x20000209  //FAST PLUS MODE 1000Khz
#endif


#ifdef    YUNHORN_STS_E4_ENABLED
//#include "yunhorn_sts_e4_conf.h"
#define senddataport			YUNHORN_STS_E4_LORA_APP_DATA_PORT
#define sendhtbtport			YUNHORN_STS_E4_LORA_APP_HTBT_PORT
#endif /* YUNHORN_STS_E4_ENABLED */


#ifdef    YUNHORN_STS_M7_ENABLED
#define	YUNHORN_STS_M7_NVM_CFG_SIZE				3U
#define	YUNHORN_STS_M7_CFG_CMD_SIZE				9U
#define	YUNHORN_STS_MAX_NVM_CFG_SIZE			32U

#include "yunhorn_sts_motion_sensor.h"
#define YUNHORN_STS_M7_LORA_APP_DATA_PORT         20U
#define YUNHORN_STS_M7_LORA_APP_HTBT_PORT         21U
#define YUNHORN_STS_M7_USER_APP_CTRL_PORT					2U
#define YUNHORN_STS_M7_USER_APP_CTRL_REPLY_PORT		1U
#define sts_mtmcode1								0U
#define sts_mtmcode2								90U
#define sts_hardware_ver						1U
#define sts_version									1U
#define sts_senddataport						YUNHORN_STS_M7_LORA_APP_DATA_PORT
#define sts_sendhtbtport						YUNHORN_STS_M7_LORA_APP_HTBT_PORT
#define sts_appctrlport							YUNHORN_STS_M7_USER_APP_CTRL_PORT
#define sts_appctrl_reply_port			YUNHORN_STS_M7_USER_APP_CTRL_REPLY_PORT

#define	NVM_CFG_PARAMETER_SIZE			YUNHORN_STS_M7_NVM_CFG_SIZE
#define	CFG_CMD_PARAMETER_SIZE			YUNHORN_STS_M7_CFG_CMD_SIZE
#define MOTION_SENSOR_TIM_HANDLE		htim2
#define MOTION_SENSOR_I2C_HANDLE 		hi2c1
#endif /* YUNHORN_STS_M7_ENABLED */


#define    YUNHORN_STS_DUTY_CYCLE_INTERVAL_ENABLED


// YUNHORN_STS_BP (3K,6K,19K)
// BATTERY PACK STS_BPER_3K, STS_BPER_6K, STS_BPER_19K
// BATTERY PACK STS_BPCR_2K, STS_BPCR_5K, STS_BPCR_9K

#define BAT_CR2032                  ((uint32_t) 3000)
#define BAT_CR2450                  ((uint32_t) 3000)
#define BAT_CR2477                  ((uint32_t) 3000)
#define BAT_LION523450_1000MAH			((uint32_t) 4200)
#define BAT_ER34615_19000AH					((uint32_t)	3600)
#define BAT_ER26500_8500AH				((uint32_t) 3600)
#define BAT_ER14505_2P_4800MAH			((uint32_t)	3600)
#define BAT_STS_BOARD_3V3						((uint32_t)	3300)
/*
#ifndef	VDD_BAT
#define VDD_BAT                     BAT_STS_BOARD_3V3
#endif
*/
#define	STS_BURN_IN_RFAC	((uint32_t) 2)


/* STM32WL55JC READ/WRITE FLASH ADDRESS AND SIZE
 * SECTION		START ADDRESS 		SIZE
 * RAM1 			0x20000000				0x8000
 * RAM2				0x20008000				0x8000
 */

/* @note All the executable code is mapped in SRAM1 area */
#define FLASH_ROW_SIZE          			32
#define ADDR_SRAM1_FLASH_PAGE_0				((uint32_t) 0x20000000)
#define ADDR_SRAM2_FLASH_PAGE_0				((uint32_t) 0x20008000)
#define SIZE_SRAM1_FLASH_PAGE					((uint32_t) 0x8000)
#define SIZE_SRAM1_FLASH_PAGE					((uint32_t) 0x8000)

/*  STM32WLxx CM4 FLASH 
 *	DEVICE SIZE 	256K
 *  DEVICE TYPE   On-chip Flash
 *	Address range	0800 0000H - 0803 FFFFH   Size: 0x0004 0000
 */
 
#define FLASH_USER_START_ADDR   			((void *)	0x0803F800U)		// Last 2kB of flash
#define FLASH_USER_CONFIG_SIZE				((void *) 	0x000007FFU)		//0x400=1KB=1024
#define FLASH_USER_END_ADDR     			(FLASH_USER_START_ADDR + FLASH_USER_CONFIG - 1)   
/* 2KB = 2048 = 0x800 End @ of user Flash area 	*/

/**
  * @brief YUNHORN STS CONFIG NVM Flash address
  * @note last 2 sector of a 128kBytes device
  */
	
#define STS_CONFIG_NVM_BASE_ADDRESS					FLASH_USER_START_ADDR                    	
#define STS_CONFIG_NVM_CONFIG_SIZE					FLASH_USER_CONFIG_SIZE                    	
/*---------------------------------------------------------------------------*/
/*                             LoRaWAN NVM configuration                     */
/*---------------------------------------------------------------------------*/
/**
  * @brief LoRaWAN NVM Flash address
  * @note last 2 sector of a 128kBytes device
  */
// #define LORAWAN_NVM_BASE_ADDRESS                    ((uint32_t)0x0803F000UL)





#ifdef __cplusplus
}
#endif

#endif /* __YUNHORN_STS_PRD_CONF_H__ */
