diff --git a/BIN b/BIN new file mode 100644 index 0000000..e152748 Binary files /dev/null and b/BIN differ diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 4abdacf..d3a0266 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -64,8 +64,7 @@ void Error_Handler(void); #define LED1_Pin GPIO_PIN_15 #define LED1_GPIO_Port GPIOB #endif -#define LED2_Pin GPIO_PIN_9 -#define LED2_GPIO_Port GPIOB + #define BUT1_Pin GPIO_PIN_0 #define BUT1_GPIO_Port GPIOA #define BUT1_EXTI_IRQn EXTI0_IRQn @@ -100,6 +99,7 @@ void Error_Handler(void); #define BUT2_GPIO_Port GPIOA #define BUT2_EXTI_IRQn EXTI1_IRQn + #ifdef STS_O5 // STS_O5 GPIO PORT PIN DEFINATION SINGLE BOARD /* --------------------------------------------------*/ @@ -120,17 +120,44 @@ void Error_Handler(void); #define HALL2_STATE HAL_GPIO_ReadPin(HALL2_GPIO_Port, HALL2_Pin) #endif +// GREEN LED #define LED1_Pin GPIO_PIN_2 #define LED1_GPIO_Port GPIOB + +// RED LED +#define LED2_Pin GPIO_PIN_7 +#define LED2_GPIO_Port GPIOB + #endif #define BUT1_State HAL_GPIO_ReadPin(BUT1_GPIO_Port, BUT1_Pin) #define BUT2_State HAL_GPIO_ReadPin(BUT2_GPIO_Port, BUT2_Pin) +// GREEN LED #define LED1_ON HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET ) #define LED1_OFF HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET) + +// RED LED +#define LED2_ON HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET ) +#define LED2_OFF HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET) + +#define LED_GREEN_ON LED1_ON +#define LED_GREEN_OFF LED1_OFF + +#define LED_RED_ON LED2_ON +#define LED_RED_OFF LED2_OFF + #define LED1_STATE HAL_GPIO_ReadPin(LED1_GPIO_Port, LED1_Pin) #define LED1_TOGGLE HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin) +// for PIR sensor +#ifdef STS_T6 +#define PIR_Pin GPIO_PIN_6 +#define PIR_GPIO_Port GPIOB +#define PIR_EXTI_IRQn EXTI9_5_IRQn +#define PIR_STATE HAL_GPIO_ReadPin(PIR_GPIO_Port, PIR_Pin) + +#endif + #ifndef L8 #define MEMS_POWER_Pin GPIO_PIN_4 // PMU_ENABLE #define MEMS_POWER_GPIO_Port GPIOB // PMU_ENABLE @@ -323,6 +350,28 @@ void Error_Handler(void); #endif +#if defined(O1L) +/* + * STM32WL55, STM32WLE5 Clock=48Mhz 48,000,000/800khz = 60 + */ +#define STS_LAMP_BAR_PWM_TIM_PERIOD (240 - 1) +#define STS_LAMP_BAR_HTIM htim1 +#define STS_LAMP_BAR_LED_NUM (60) //60 for 46CM length LED strip + +#define WSDATA_PORT_PIN_PA8 +//#define WSDATA_PORT_PIN_PA9 + +#ifdef WSDATA_PORT_PIN_PA8 +#define STS_LAMP_BAR_TIM_CHANNEL TIM_CHANNEL_1 +#define STS_LAMP_BAR_WSDATA_PIN GPIO_PIN_8 +#define STS_LAMP_BAR_WSDATA_PORT GPIOA +#elif defined(WSDATA_PORT_PIN_PA9) +#define STS_LAMP_BAR_TIM_CHANNEL TIM_CHANNEL_2 +#define STS_LAMP_BAR_WSDATA_PIN GPIO_PIN_9 +#define STS_LAMP_BAR_WSDATA_PORT GPIOA +#endif +#endif + /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/Core/Inc/stm32wlxx_hal_conf.h b/Core/Inc/stm32wlxx_hal_conf.h index bae70e9..660926c 100644 --- a/Core/Inc/stm32wlxx_hal_conf.h +++ b/Core/Inc/stm32wlxx_hal_conf.h @@ -54,7 +54,7 @@ /*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */ #define HAL_SUBGHZ_MODULE_ENABLED -/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ diff --git a/Core/Inc/sts_lamp_bar.h b/Core/Inc/sts_lamp_bar.h new file mode 100644 index 0000000..b93ab66 --- /dev/null +++ b/Core/Inc/sts_lamp_bar.h @@ -0,0 +1,125 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : sts_lamp_bar.h + * @brief : Header for sts_lamp_bar.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * + * 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 __STS_LAMP_BAR_H +#define __STS_LAMP_BAR_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "main.h" + +#define DEFAULT_SATURATION 50 // 0 - 100 S:Saturation, 0~100 +#define DEFAULT_BRIGHTNESS 50 // 0 - 100 V:Value of lightness, 0~100 +#define DEFAULT_LUMINANCE_LEVEL (30) +#define STS_Status_Door_Close (0) //Normal Close NC:Open **2024-07-15 changed +#define STS_Status_Door_Open (1) //Normal Close NC:Close **2024-07-15 changed +#define STS_Status_SOS_Pushdown (0) //Normal Open NO:Open +#define STS_Status_SOS_Release (1) //Normal Open NO:Close +#define STS_Status_Alarm_Mute_Pushdown (0) //Normal Open NO:Open +#define STS_Status_Alarm_Mute_Release (1) //Normal Open NO:Close# +#define STS_Status_Alarm_Reset_Pushdown (0) //Normal Open NO:Open +#define STS_Status_Alarm_Reset_Release (1) //Normal Open NO:Close# + +enum sts_lamp_color { + STS_DARK = 0, //灭:0, Code 0x00 + STS_GREEN, //绿:1 0 1 0 code 0x01 0b0000 0001 + STS_RED, //红:2 1 0 0 code 0x02 0b0000 0010 + STS_BLUE, //蓝:3 0 0 1 code 0x03 0b0000 0011 + STS_YELLOW, //黄:4 1 1 0 code 0x04 0b0000 0100 + STS_PINK, //紫:5 1 0 1 code 0x05 0b0000 0101 + STS_CYAN, //青:6 0 1 1 code 0x06 0b0000 0110 + STS_WHITE, //白:7 1 1 1 code 0x07 0b0000 0111 + STS_COLOR_MAX, //8: MAX NUM OF COLORS 0x08 0b0000 1000 + + STS_GREEN_DARK=0x10, //0b0001 0000 GREEN DARK + STS_RED_DARK=0x20, //0b0010 0000, + STS_RED_GREEN=0x21, + STS_RED_BLUE=0x23, //0b0010 0011 RED BLUE FLASH + STS_BLUE_DARK=0x30, //0b0011 0000 BLUE DARK + STS_BLUE_GREEN=0x31, + + STS_GREENDARK=0x41, // GREEN FLASH 'A' + STS_REDDARK=0x42, // RED FLASH 'B' + STS_REDBLUE=0x43, // RED/BLUE FLASH 'C' + STS_BLUEDARK=0x44, // BLUE FLASH 'D' + STS_REDGREEN=0x45, // RED/GREEN FLASH 'E' + STS_BLUEGREEN=0x46 // BLUE/GREEN FLASH 'F' +}; + +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 DUAL_MODE + FALL DETECTION + STS_REMOTE_REED_RSS_MODE, // 6 REMOTE REED SWITCH + RSS MODE 2023-05-04 + STS_DUAL_RSS_MODE, // 7 RSS_1 + RSS_2 IN TWO UNITS + STS_TOF_RSS_MODE, // 8 TOF + RSS MODE + STS_TOF_DISTANCE_MODE, // 9 TOF DISTANCE O6T + STS_TOF_PRESENCE_MODE, // A TOF PRESENCE OCCUPANCY + STS_TOF_IN_OUT_MODE, // B TOF IN OUT COUNT + STS_FALL_DETECTION_MODE, // C FALL DETECTION + + STS_OTHER_MODE // ? OTHER MODE +}; +#if defined(STS_O7)||defined(STS_O6) +#define STS_Reed_Hall_State HALL1_STATE +#define STS_Emergency_Button_State HALL2_STATE +#else +#define STS_Reed_Hall_State HAL_GPIO_ReadPin(BUT1_GPIO_Port, BUT1_Pin) +#endif +//void STS_Lamp_Bar_All(uint8_t lamp_color, uint8_t luminance_level); +void STS_Lamp_Bar_Set_Color(uint8_t red, uint8_t green, uint8_t blue ); +void STS_Lamp_Bar_Set_RGB(uint8_t red, uint8_t green, uint8_t blue); +void STS_Lamp_Bar_Set_RGB_Color(uint8_t red, uint8_t green, uint8_t blue); +void STS_Lamp_Bar_Init(void); +void STS_Lamp_Bar_Full_Color_Gradient(void); +void STS_WS2812B_Refresh(void); +void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx); +void STS_Reed_Hall_Working(void); +void STS_Lamp_Bar_Self_Test_Simple(void); +void STS_Lamp_Bar_Self_Test(void); +void STS_Lamp_Bar_Set_Dark(void); +void sts_rgb_unit_test(void); +void STS_Reed_Hall_Presence_Detection(void); + +void STS_RSS_Smart_Presence_Detection(void); +void STS_RSS_Smart_Presence(void); + +void STS_Combined_Status_Processing(void); + +// Before Join LoRa-WAN Network +void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t luminance_level); +// Occupancy Status, Set Color to STS_RED +// Vacant Status, Set Color to STS_GREEN +void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t luminance_level); +void STS_Lamp_Bar_Refresh(void); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _STS_LAMP_BAR_H */ + diff --git a/Core/Inc/sys_conf.h b/Core/Inc/sys_conf.h index f10502a..241072d 100644 --- a/Core/Inc/sys_conf.h +++ b/Core/Inc/sys_conf.h @@ -47,12 +47,12 @@ extern "C" { /** * @brief Verbose level for all trace logs */ -#define VERBOSE_LEVEL VLEVEL_M +#define VERBOSE_LEVEL VLEVEL_OFF /** * @brief Enable trace logs */ -#define APP_LOG_ENABLED 1 +#define APP_LOG_ENABLED 0 /** * @brief Activate monitoring (probes) of some internal RF signals for debug purpose @@ -75,7 +75,7 @@ extern "C" { * @brief Enable/Disable MCU Debugger pins (dbg serial wires) * @note by HW serial wires are ON by default, need to put them OFF to save power */ -#define DEBUGGER_ENABLED 1 +#define DEBUGGER_ENABLED 0 /** * @brief Disable Low Power mode diff --git a/Core/Inc/tim.h b/Core/Inc/tim.h new file mode 100644 index 0000000..efd1057 --- /dev/null +++ b/Core/Inc/tim.h @@ -0,0 +1,51 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @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 __TIM_H__ +#define __TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ +extern TIM_HandleTypeDef htim1; +/* USER CODE END Private defines */ + + +/* USER CODE BEGIN Prototypes */ +void MX_TIM1_Init(void); +void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIM_H__ */ + diff --git a/Core/Inc/utilities_def.h b/Core/Inc/utilities_def.h index 22653b4..35411f6 100644 --- a/Core/Inc/utilities_def.h +++ b/Core/Inc/utilities_def.h @@ -87,6 +87,8 @@ typedef enum #endif #if defined(STS_O6) CFG_SEQ_Task_YunhornSTSEventP2, /* MOTION */ +#endif +#if (defined(STS_T6)||defined(STS_O6)||defined(STS_O7)) CFG_SEQ_Task_YunhornSTSEventP3, /* LAMP BAR LED */ #endif #if defined(STS_R1)||defined(STS_R1D)||defined(STS_R5)||defined(STS_R2) diff --git a/Core/Src/dma.c b/Core/Src/dma.c index cffe8a6..d04f763 100644 --- a/Core/Src/dma.c +++ b/Core/Src/dma.c @@ -45,8 +45,13 @@ void MX_DMA_Init(void) /* DMA interrupt init */ + /* TIM1_CH1 */ + /* DMA1_Channel1_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); + // I2C2 -#if 0 +#if 1 #if defined(VL53LX)||defined(VL53L0) /* DMA1_Channel3_IRQn interrupt configuration */ /* I2C2 RX */ @@ -77,8 +82,8 @@ void MX_DMA_Init(void) HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); /* DMA1_Channel7_IRQn interrupt configuration */ - //HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0); - //HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); + HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); // HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 2, 0); // HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index 0bdc85f..1a04042 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -56,6 +56,11 @@ void MX_GPIO_Init(void) HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET); #endif + +#if defined(STS_T6)||defined(STS_P2) + HAL_GPIO_WritePin(TOF_C_XSHUT_GPIO_Port, TOF_C_XSHUT_Pin, GPIO_PIN_SET); +#endif + #ifdef STS_P2 HAL_GPIO_WritePin(TOF_C_XSHUT_GPIO_Port, TOF_C_XSHUT_Pin, GPIO_PIN_SET); #endif @@ -85,6 +90,15 @@ void MX_GPIO_Init(void) HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); #endif +#ifdef STS_T6 + GPIO_InitStruct.Pin = PIR_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; //GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(PIR_GPIO_Port, &GPIO_InitStruct); + +#endif + #if defined(STM32WL55xx) /*Configure GPIO pins : PBPin PBPin */ GPIO_InitStruct.Pin = PROB2_Pin|PROB1_Pin; @@ -150,7 +164,7 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(TOF_L_XSHUT_GPIO_Port, &GPIO_InitStruct); -#endif + HAL_NVIC_SetPriority(TOF_C_INT_EXTI_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn); @@ -200,17 +214,19 @@ void MX_GPIO_Init(void) /* ============== SOAP LEVEL DETECTION ========================= */ /* EXTI interrupt init*/ - HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI0_IRQn); - HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI1_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI1_IRQn); + HAL_NVIC_SetPriority(TOF_C_INT_EXTI_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn); + + HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); - HAL_NVIC_SetPriority(TOF_C_INT_EXTI_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn); // HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); // HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); diff --git a/Core/Src/main.c b/Core/Src/main.c index 28a417a..fb97bb7 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -27,10 +27,12 @@ #include "dma.h" #include "usart.h" #include "sys_app.h" +#include "tim.h" #ifdef STS_P2 #include "app_tof.h" #include "app_tof_peoplecount.h" #elif defined(STS_T6) +#include "app_tof_peoplecount.h" #include "app_tof.h" #elif defined(L8) #include "app_tof.h" @@ -112,13 +114,20 @@ int main(void) { MX_I2C2_Init(); MX_DMA_Init(); +#if defined(STS_T6) + MX_TIM1_Init(); +#endif MX_LoRaWAN_Init(); } /* USER CODE BEGIN 2 */ - //MX_USART2_UART_Init(); + //MX_USART2_UART_Init(); +#ifdef STS_P2 STS_TOF_VL53LX_PeopleCounting_Process_Init(); + #elif defined(STS_T6) + STS_TOF_VL53LX_PresenceDetection_Process_Init(); +#endif /* USER CODE END 2 */ diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index a07d0f9..ece34a8 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -66,6 +66,9 @@ extern DMA_HandleTypeDef hdma_i2c2_tx; extern DMA_HandleTypeDef hdma_usart2_tx; extern DMA_HandleTypeDef hdma_usart2_rx; +extern DMA_HandleTypeDef hdma_tim1_ch2; +extern DMA_HandleTypeDef hdma_tim1_ch1; + /* USER CODE END EV */ /******************************************************************************/ @@ -281,6 +284,24 @@ void EXTI4_IRQHandler(void) /* USER CODE END EXTI1_IRQn 1 */ } + +/** + * @brief This function handles DMA1 Channel 1 Interrupt. + */ +void DMA1_Channel1_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */ + + /* USER CODE END DMA1_Channel1_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_tim1_ch1); + + //HAL_DMA_IRQHandler(&hdma_tim1_ch2); + + /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */ + + /* USER CODE END DMA1_Channel1_IRQn 1 */ +} + /* SPI1 */ /** * @brief This function handles DMA1 Channel 2 Interrupt. @@ -386,7 +407,9 @@ void EXTI9_5_IRQHandler(void) #elif defined(RM2)&&(defined(VL53L0)||defined(VL53LX)) HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); #endif - +#ifdef STS_T6 + HAL_GPIO_EXTI_IRQHandler(PIR_Pin); +#endif /* USER CODE BEGIN EXTI9_5_IRQn 1 */ /* USER CODE END EXTI9_5_IRQn 1 */ diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c new file mode 100644 index 0000000..26b1794 --- /dev/null +++ b/Core/Src/sts_lamp_bar.c @@ -0,0 +1,285 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file yunhorn_sts_lamp_bar.c * + * @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 */ +#include "main.h" +#include "dma.h" +#include "tim.h" +#include "string.h" +#include "sys_app.h" +#include "stm32_systime.h" +#include "sts_lamp_bar.h" + +#include "yunhorn_sts_sensors.h" + +#define ONE_PULSE (40) //36 +#define ZERO_PULSE (20) + +#define LED_DATA_LEN 24 +#define WS2812B_DATA_LEN (LED_DATA_LEN * (STS_LAMP_BAR_LED_NUM)) +#define RESET_PULSE (24) //(80) TO FIX DARK_COLOR AND SM2 + + +typedef struct ws2812b_e { + //uint16_t head[3]; + uint16_t GRB[WS2812B_DATA_LEN]; + uint16_t tail; +} WS2812B_FrameTypeDef; + +volatile WS2812B_FrameTypeDef rgb_buf = { +// .head[0] = 0, +// .head[1] = 0, +// .head[2] = 0, + .tail = 0 +}; + +uint8_t color_rgb[8][3] = { //STS_COLOR R G B MAPPING TABLE + {0,0,0},{0,1,0},{1,0,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,1,1} +}; +extern volatile uint8_t sts_service_mask; +extern volatile uint8_t sts_work_mode; +volatile uint8_t sts_reed_hall_ext_int = 0; +volatile uint8_t sts_status_color = STS_GREEN; +volatile uint8_t sts_color_occupy_vacant = (STS_RED<<4)|(STS_DARK&0x0f); +volatile uint8_t sts_lamp_bar_color = STS_RED; //puColor +volatile uint8_t sts_lamp_bar_flashing_color = STS_RED_DARK; //0x23; RED_BLUE; +volatile uint8_t sts_cloud_netcolor = STS_GREEN; //netColor +extern volatile uint8_t sts_occupancy_status; + +extern volatile uint8_t sts_reed_hall_result, sts_emergency_button_pushed; // inital 0 = close +volatile uint8_t sts_hall1_read=STS_Status_Door_Open,sts_hall2_read=STS_Status_SOS_Release; // Above hall1_read == reed_hall_result, hall2_read == emergency_button +volatile uint8_t sts_hall3_read=STS_Status_Alarm_Mute_Release,sts_hall4_read=STS_Status_Alarm_Reset_Release; +extern volatile uint8_t sts_reed_hall_1_result, sts_reed_hall_2_result; +extern volatile uint8_t sts_tof_result_changed_flag; + + + +extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag; +extern volatile uint8_t sts_rss_result; +extern volatile uint8_t sts_rss_2nd_result; //2nd RSS sensor status +extern volatile uint8_t sts_tof_result; + + +volatile uint8_t last_lamp_bar_color=STS_RED; +extern volatile uint8_t sts_presence_fall_detection; +extern volatile uint8_t sts_fall_rising_detected_result; +extern volatile float sts_presence_rss_distance; +extern volatile uint8_t sensor_data_ready; +extern SysTime_t mems_event_time; +extern volatile uint32_t event_start_time, event_stop_time; +extern volatile uint32_t event_door_lock_start_time, event_door_lock_stop_time; +volatile uint8_t luminance_level = DEFAULT_LUMINANCE_LEVEL; + + +void STS_Lamp_Bar_Set_Dark(void) +{ + for (uint8_t i=0; i< STS_LAMP_BAR_LED_NUM; i++) + { + STS_WS2812B_Set_RGB(0x00,0x00,0x00,i); + + } + STS_WS2812B_Refresh(); +} + +void STS_WS2812B_Refresh(void) +{ + + HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)&rgb_buf, (WS2812B_DATA_LEN+RESET_PULSE)); + //HAL_TIM_PWM_Start_IT(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL); +} + +void STS_Lamp_Bar_Init(void) +{ + if (sts_service_mask == STS_SERVICE_MASK_L0) + { + STS_Lamp_Bar_Set_STS_RGB_Color(STS_GREEN, luminance_level); + + HAL_Delay(200); + STS_Lamp_Bar_Set_STS_RGB_Color(STS_RED, luminance_level); + + HAL_Delay(200); + STS_Lamp_Bar_Set_STS_RGB_Color(STS_BLUE, luminance_level); + + HAL_Delay(200); + } +} + +//marquee scoller +void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t lum_level) +{ + STS_Lamp_Bar_Set_Dark(); + + for(uint8_t i = 0; iInstance==TIM1) + { + /* USER CODE BEGIN TIM1_MspInit 0 */ + + /* USER CODE END TIM1_MspInit 0 */ + /* TIM1 clock enable */ + __HAL_RCC_TIM1_CLK_ENABLE(); + + /* TIM1 DMA Init */ + /* TIM1_CH1 Init */ + hdma_tim1_ch1.Instance = DMA1_Channel1; + + hdma_tim1_ch1.Init.Request = DMA_REQUEST_TIM1_CH1; + hdma_tim1_ch1.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma_tim1_ch1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_tim1_ch1.Init.MemInc = DMA_MINC_ENABLE; + hdma_tim1_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_tim1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; //DMA_MDATAALIGN_HALFWORD; //DMA_MDATAALIGN_HALFWORD; + hdma_tim1_ch1.Init.Mode = DMA_CIRCULAR; + hdma_tim1_ch1.Init.Priority = DMA_PRIORITY_HIGH; //was HIGH + + if (HAL_DMA_Init(&hdma_tim1_ch1) != HAL_OK) + { + Error_Handler(); + } +#ifdef STM32WL55xx + if (HAL_DMA_ConfigChannelAttributes(&hdma_tim1_ch1, DMA_CHANNEL_NPRIV) != HAL_OK) + { + Error_Handler(); + } +#endif + __HAL_LINKDMA(tim_baseHandle,hdma[TIM_DMA_ID_CC1],hdma_tim1_ch1); + + /* USER CODE BEGIN TIM1_MspInit 1 */ + + /* USER CODE END TIM1_MspInit 1 */ + } + +} +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(timHandle->Instance==TIM1) + { + /* USER CODE BEGIN TIM1_MspPostInit 0 */ + + /* USER CODE END TIM1_MspPostInit 0 */ + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**TIM1 GPIO Configuration + PA8 ------> TIM1_CH1 + */ + GPIO_InitStruct.Pin = GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; //GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN TIM1_MspPostInit 1 */ + + /* USER CODE END TIM1_MspPostInit 1 */ + } + +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM1) + { + /* USER CODE BEGIN TIM1_MspDeInit 0 */ + + /* USER CODE END TIM1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM1_CLK_DISABLE(); + + /* TIM1 DMA DeInit */ + HAL_DMA_DeInit(tim_baseHandle->hdma[TIM_DMA_ID_CC1]); + /* USER CODE BEGIN TIM1_MspDeInit 1 */ + + /* USER CODE END TIM1_MspDeInit 1 */ + } + +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 29a8855..0275f76 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -41,7 +41,7 @@ void MX_USART2_UART_Init(void) /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; -#if defined(L8)||defined(STS_P2) +#if defined(L8)||defined(STS_P2)||defined(STS_T6) huart2.Init.BaudRate = 460800; #else huart2.Init.BaudRate = 115200; diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index aeb475a..6871cd6 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -40,15 +40,21 @@ #include "app_tof_peoplecount.h" #include "yunhorn_sts_prd_conf.h" #include "yunhorn_sts_sensors.h" +#if defined(STS_O6)||defined(STS_T6)||defined(O1L) +#include "sts_lamp_bar.h" +#endif /* USER CODE END Includes */ /* External variables ---------------------------------------------------------*/ /* USER CODE BEGIN EV */ uint8_t outbuf[128]={0x0}; extern volatile uint8_t sts_ac_code[20], sts_service_mask; +extern volatile uint8_t sts_work_mode, sts_cloud_netcolor, sts_lamp_bar_color, sts_status_color, luminance_level; +volatile static bool r_b=true; extern volatile sts_cfg_nvm_t sts_cfg_nvm; extern volatile uint32_t rfac_timer; extern volatile uint32_t STS_TOFScanPeriod_msec, STS_TxPeriod_sec, STS_HeartBeatTimerPeriod_sec; +extern volatile uint8_t sts_pir_state; volatile uint8_t sts_data_buf[LORAWAN_APP_DATA_BUFFER_MAX_SIZE]={0x0}; //volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; #ifdef STS_M1 @@ -365,7 +371,12 @@ static UTIL_TIMER_Object_t YunhornSTSHeartBeatTimer; /** * @brief Timer to handle the application Lamp Bar LED Timer refresh */ -static UTIL_TIMER_Object_t YunhornSTSLampBarColorTimer; +static UTIL_TIMER_Object_t STSLampBarColorTimer; + +/** + * @brief Timer to handle the application Duration check Timer + */ +static UTIL_TIMER_Object_t STSDurationCheckTimer; /** * @brief Tx Timer period @@ -462,6 +473,8 @@ void LoRaWAN_Init(void) UTIL_TIMER_Create(&TxLedTimer, LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnTxTimerLedEvent, NULL); UTIL_TIMER_Create(&RxLedTimer, LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnRxTimerLedEvent, NULL); UTIL_TIMER_Create(&JoinLedTimer, LED_PERIOD_TIME, UTIL_TIMER_PERIODIC, OnJoinTimerLedEvent, NULL); + UTIL_TIMER_Create(&STSLampBarColorTimer, LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSLampBarColorTimerEvent, NULL); + UTIL_TIMER_Create(&STSDurationCheckTimer, 20*LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSDurationCheckTimerEvent, NULL); if (FLASH_IF_Init(NULL) != FLASH_IF_OK) { @@ -522,6 +535,9 @@ void LoRaWAN_Init(void) #endif +#if defined(STS_T6)||defined(STS_O6) + UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP3), UTIL_SEQ_RFU, STS_YunhornSTSEventP3_Process); +#endif #if defined(STS_P2)||defined(STS_T6)||defined(L8) @@ -537,15 +553,21 @@ void LoRaWAN_Init(void) UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), UTIL_SEQ_RFU, STS_YunhornSTSEventP4_Process); #endif -#if defined(STS_P2)||defined(STS_T6)||defined(L8) - //UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL); +#if defined(STS_T6)||defined(L8) + UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL); + //UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)STS_TOF_VL53LX_PresenceDetection_Process_Start, NULL); + UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); + + UTIL_TIMER_Start(&STSLampBarColorTimer); + +#elif defined(STS_P2) UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)STS_TOF_VL53LX_PeopleCounting_Process_Start, NULL); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); #endif - //UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, 1000*STS_HeartBeatTimerPeriod_sec, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL); -// UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, 1000*STS_HeartBeatTimerPeriod_sec, UTIL_TIMER_ONESHOT, OnYunhornSTSHeartBeatTimerEvent, NULL); - //UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); + // UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, 1000*STS_HeartBeatTimerPeriod_sec, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL); + // UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, 1000*STS_HeartBeatTimerPeriod_sec, UTIL_TIMER_ONESHOT, OnYunhornSTSHeartBeatTimerEvent, NULL); + // UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); /* USER CODE END LoRaWAN_Init_Last */ } @@ -631,6 +653,16 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStoreContextEvent), CFG_SEQ_Prio_0); break; #endif +#ifdef STS_T6 + case PIR_Pin: + sts_pir_state= PIR_STATE; + // HAL_Delay(50); + __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); + // APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotion Detection result=%d \r\n", sts_pir_state); + // UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + + break; +#endif #if (defined(VL53L0)||defined(VL53LX)||defined(L8)) case TOF_INT_EXTI_PIN: ToF_EventDetected = 1; @@ -1031,8 +1063,11 @@ static void SendTxData(void) #endif //STS_P2 #if defined(STS_T6) - AppData.Buffer[i++] = 1; + AppData.Buffer[i++] = 4; AppData.Buffer[i++] = (uint8_t)((sts_t6_sensor_data.tof_range_presence_state & 0xFF)); + AppData.Buffer[i++] = (uint8_t)((sts_t6_sensor_data.pir_motion_sensor_state & 0xFF)); + AppData.Buffer[i++] = (uint8_t)((sts_t6_sensor_data.lamp_bar_color & 0xFF)); + AppData.Buffer[i++] = (uint8_t)((sts_t6_sensor_data.tof_presence_distance_dm & 0xFF)); #endif //STS_T6 @@ -1096,7 +1131,7 @@ static void OnTxTimerEvent(void *context) /* USER CODE BEGIN OnTxTimerEvent_1 */ /* USER CODE END OnTxTimerEvent_1 */ - UTIL_TIMER_Stop(&TxTimer); + #ifdef STS_R4 UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP6), CFG_SEQ_Prio_0); #elif defined(STS_M1) @@ -1104,7 +1139,7 @@ static void OnTxTimerEvent(void *context) #elif (defined(STS_R1D)||defined(STS_R5)||defined(STS_R1)) APP_LOG(TS_OFF, VLEVEL_H, "\nSET TASK P4\r\n"); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), CFG_SEQ_Prio_0); -#elif (defined(STS_P2)) +#elif (defined(STS_P2)||defined(STS_T6)) UTIL_TIMER_Stop(&YunhornSTSWakeUpScanTimer); @@ -1114,7 +1149,7 @@ static void OnTxTimerEvent(void *context) UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); -#if (defined(STS_P2)) +#if (defined(STS_P2)||defined(STS_T6)) UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); #endif @@ -1457,10 +1492,24 @@ static void OnRestoreContextRequest(void *nvm, uint32_t nvm_size) */ static void OnYunhornSTSLampBarColorTimerEvent(void *context) { -#ifdef STS_O6 - UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP3), CFG_SEQ_Prio_0); + uint8_t high4=(sts_lamp_bar_color>>4)&0x0f, low4=sts_lamp_bar_color&0x0f; +#if defined(STS_O6)||defined(STS_T6) //||defined(O1L) + //UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP3), CFG_SEQ_Prio_0); - UTIL_TIMER_Start(&YunhornSTSLampBarColorTimer); + UTIL_TIMER_Stop(&STSLampBarColorTimer); + + if (high4==0) + { + STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, luminance_level); + + } else + { + STS_Lamp_Bar_Set_STS_RGB_Color(r_b?high4:low4, luminance_level); + r_b = !r_b; + } + + + UTIL_TIMER_Start(&STSLampBarColorTimer); #endif } @@ -1479,15 +1528,13 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) * @brief Yunhorn STS Occupancy RSS WakeUP timer callback function * @param context ptr of STS RSS WakeUp context */ - +#ifdef STS_O6 static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) { -#ifdef STS_O6 -#endif } - +#endif /** * @brief Yunhorn STS Heart beat timer callback function * @param context ptr of context @@ -1580,9 +1627,10 @@ void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) static void OnYunhornSTSWakeUpScanTimerEvent(void *context) { #if defined(STS_P2)||defined(STS_T6)||defined(L8) + // UTIL_TIMER_Stop(&YunhornSTSWakeUpScanTimer); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), CFG_SEQ_Prio_0); - //UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); + // UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); #endif } diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index 6b533d7..d79866c 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -99,7 +99,11 @@ +<<<<<<< HEAD +======= + +>>>>>>> 735cf8c2aa1be8a1a9f9a07734d4c77574425bd4 @@ -136,7 +140,7 @@