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

#ifdef STS_R1												/* STS R1 for single roll					*/
#define 			YUNHORN_STS_R1_ENABLED	1U
#elif	defined(STS_R1D)									/* STS R1D for double roll					*/
#define				YUNHORN_STS_R1D_ENABLED	1U
#elif	defined(STS_R2)										/* STS R2 for tissue paper					*/
#define				YUNHORN_STS_R2_ENABLED	1U
#elif	defined(STS_R5)										/* STS_R5 for waste bin						*/
#define				YUNHORN_STS_R5_ENABLED	1U
#elif	defined(STS_P2)										/* STS_P2 for people count in-out			*/
#define				YUNHORN_STS_P2_ENABLED	1U
#elif 	defined(STS_O6T)									/* STS_O6T for occupancy sensor via ToF		*/
#define				YUNHORN_STS_O6T_ENABLED	1U
#elif 	defined(STS_T6)									/* STS_O6T for occupancy sensor via ToF		*/
#define				YUNHORN_STS_T6_ENABLED	1U
#elif 	defined(STS_R4)									/* STS_O6T for occupancy sensor via ToF		*/
#define				YUNHORN_STS_R4_ENABLED	1U
#elif 	defined(L8)
#define				YUNHORN_STS_L8_ENABLED	1U
#endif
/*
#define		PRD_O0			0x0000
#define		PRD_O1			0x0001
#define		PRD_O2			0x0002
#define		PRD_O3			0x0004
#define		PRD_O4			0x0008
#define		PRD_O5			0x0010
#define		PRD_O6			0x0020
#define		PRD_O7			0x0040
#define		PRD_O8			0x0080
#define		PRD_09			0x0100
#define		PRD_10			0x0200
#define		PRD_11			0x0400
#define		PRD_12			0x0800
#define		PRD_13			0x1000
#define		PRD_14			0x2000
#define		PRD_15			0x4000
#define		PRD_16			0x8000
 */

/* ########################## Product Selection ##############################
 * @brief This is the list of Yunhorn STS products to be used in ALL product config
 */
#define YUNHORN_STS_USER_APP_CTRL_PORT				2U
#define YUNHORN_STS_USER_APP_CTRL_REPLY_PORT		1U

#define sts_hardware_ver							1U
#define sts_version									1U

#ifdef  YUNHORN_STS_R1_ENABLED
#define YUNHORN_STS_R1_LORA_APP_DATA_PORT         	57U
#define YUNHORN_STS_R1_LORA_APP_HTBT_PORT         	58U
#define sts_mtmcode1							  	0U
#define sts_mtmcode2							  	57U

#endif

#ifdef  YUNHORN_STS_R1D_ENABLED
#define YUNHORN_STS_R1D_LORA_APP_DATA_PORT         	57U
#define YUNHORN_STS_R1D_LORA_APP_HTBT_PORT         	58U
#define	YUNHORN_STS_PRD_STRING						"STS_R1D"
#define sts_mtmcode1								0U
#define sts_mtmcode2								57U
#define sts_senddataport						(YUNHORN_STS_R1D_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_R1D_LORA_APP_HTBT_PORT)
#endif

#ifdef  YUNHORN_STS_R2_ENABLED
#define YUNHORN_STS_R2_LORA_APP_DATA_PORT         	52U
#define YUNHORN_STS_R2_LORA_APP_HTBT_PORT         	53U
#define sts_mtmcode1								0U
#define sts_mtmcode2								52U

#endif

#ifdef  YUNHORN_STS_R3_ENABLED
#define YUNHORN_STS_R3_LORA_APP_DATA_PORT         	7U
#define YUNHORN_STS_R3_LORA_APP_HTBT_PORT         	8U
#define sts_mtmcode1								0U
#define sts_mtmcode2								7U
#endif

#ifdef  YUNHORN_STS_R4_ENABLED
#define YUNHORN_STS_R4_LORA_APP_DATA_PORT         	7U
#define YUNHORN_STS_R4_LORA_APP_HTBT_PORT         	8U
#define	YUNHORN_STS_PRD_STRING						"STS_R4"
#define sts_mtmcode1								0U
#define sts_mtmcode2								8U

#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
#define	YUNHORN_STS_PRD_STRING						"STS_R5"
#define sts_mtmcode1								0U
#define sts_mtmcode2								11U
#define sts_senddataport						(YUNHORN_STS_R5_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_R5_LORA_APP_HTBT_PORT)
#endif

#ifdef  STS_P2
#define YUNHORN_STS_P2_LORA_APP_DATA_PORT         	106U
#define YUNHORN_STS_P2_LORA_APP_HTBT_PORT         	107U
#define	YUNHORN_STS_PRD_STRING						"STS_P2"
#define sts_mtmcode1								0U
#define sts_mtmcode2								106U

#endif

#ifdef  STS_T6
#define YUNHORN_STS_T6_LORA_APP_DATA_PORT         	14U
#define YUNHORN_STS_T6_LORA_APP_HTBT_PORT         	15U
#define	YUNHORN_STS_PRD_STRING						"STS_T6"
#define sts_mtmcode1								0U
#define sts_mtmcode2								14U

#endif

#ifdef  L8
#define YUNHORN_STS_L8_LORA_APP_DATA_PORT         	16U
#define YUNHORN_STS_L8_LORA_APP_HTBT_PORT         	17U
#define	YUNHORN_STS_PRD_STRING						"STS_L8"
#define sts_mtmcode1								0U
#define sts_mtmcode2								16U
#define sts_senddataport						(YUNHORN_STS_L8_LORA_APP_DATA_PORT)
#define sts_sendhtbtport						(YUNHORN_STS_L8_LORA_APP_HTBT_PORT)
#endif

#ifdef	STS_M1
#define YUNHORN_STS_M1_LORA_APP_DATA_PORT         	6U
#define YUNHORN_STS_M1_LORA_APP_HTBT_PORT         	6U
#define	YUNHORN_STS_PRD_STRING						"STS_M1"
#define sts_mtmcode1								0U
#define sts_mtmcode2								6U

#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 sts_senddataport						(YUNHORN_STS_T6_LORA_APP_DATA_PORT)
//#define sts_sendhtbtport						(YUNHORN_STS_T6_LORA_APP_HTBT_PORT)
#define sts_appctrlport							(YUNHORN_STS_USER_APP_CTRL_PORT)
#define sts_appctrl_reply_port					(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT)

 /*		General Settings							*/
#define MajorVer									24U
#define MinorVer									10U
#define SubMinorVer 								15U
#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							20U
#define	STS_CFG_CMD_SIZE							30U
#define STS_CFG_CMD_SHORT_LEN						8U
#define STS_MODE_COLOR_CMD_LEN						5U

#if	defined(STS_USE_TOF_VL53L0X)||defined(STS_USE_TOF_VL53L1X)		// RETIRED TODO
#define I2C_TIMING_TOF250			0x20303E5D
#define I2C_TIMING 					0x20303E5D						//DEFAULT FOR I2C TOF

/* FOR STM32WLE5CCU6 UFQFPN48  PA12 PA11					*/
#define I2C2_STANDARD_100K			0x00000E14
#define I2C2_FAST_400K				0x00000004
#define I2C2_FAST_PLUS_1M			0x00000000
#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_UNI_MODE,  				// 5	RSS + REEDSWITCH +PIR + TOF	2023-09-24
	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_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


#define MOTION_SENSOR_TIM_HANDLE		htim2
#define MOTION_SENSOR_I2C_HANDLE 		hi2c1


#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__ */
