diff --git a/Core/Inc/main.h b/Core/Inc/main.h index c8bf8fc..2ec7385 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -111,8 +111,9 @@ void Error_Handler(void); #define PME_OFF HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET ) #define PME_TOGGLE HAL_GPIO_TogglePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin) +#if (defined(TOF_1)||defined(TOF_2)||defined(STS_R1)||defined(STS_R5)||defined(STS_R1D)) #define VL53L0 -#ifndef VL53L0 +#elif defined(STS_P2) #define VL53LX 1 #endif @@ -210,6 +211,24 @@ void Error_Handler(void); #define I2C2_FAST_PLUS_1M 0x00000000 #endif + +#if defined(STS_R4) +/* IF_SOAP_IN, MEMS_IF_3, PA10 */ +#define SOAP_STATUS_Pin GPIO_PIN_10 +#define SOAP_STATUS_GPIO_Port GPIOA + +#ifdef RM2 +#define SOAP_SWITCH_Pin GPIO_PIN_3 // 2024-04-08 WAS GPIO_PIN_3 +#define SOAP_SWITCH_GPIO_Port GPIOB +#elif defined(STS_R4) +/* IF_SENSOR_ON_OFF, MEMS_IF_1, PB3 */ +#define SOAP_SWITCH_Pin GPIO_PIN_5 // 2024-04-08 WAS GPIO_PIN_3 +#define SOAP_SWITCH_GPIO_Port GPIOB +#endif + +#define SOAP_DATA HAL_GPIO_ReadPin(SOAP_STATUS_GPIO_Port,SOAP_STATUS_Pin) +#endif + /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index 7f58d4d..6b70c38 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -113,6 +113,29 @@ void MX_GPIO_Init(void) HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn); #endif + +/* ============== SOAP LEVEL DETECTION ========================= */ + +#if defined(STS_R4) + + HAL_GPIO_WritePin(SOAP_SWITCH_GPIO_Port, SOAP_SWITCH_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pins : PAPin PAPin */ + GPIO_InitStruct.Pin = SOAP_STATUS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(SOAP_STATUS_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = SOAP_SWITCH_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(SOAP_SWITCH_GPIO_Port, &GPIO_InitStruct); + +#endif +/* ============== SOAP LEVEL DETECTION ========================= */ + /* EXTI interrupt init*/ HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI0_IRQn); diff --git a/Core/Src/stm32_lpm_if.c b/Core/Src/stm32_lpm_if.c index 0e6a462..5523477 100644 --- a/Core/Src/stm32_lpm_if.c +++ b/Core/Src/stm32_lpm_if.c @@ -24,6 +24,7 @@ #include "stm32_lpm_if.h" #include "usart_if.h" #include "i2c.h" +#include "gpio.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -120,6 +121,7 @@ void PWR_ExitStopMode(void) SRAM ctrls, DMAx, DMAMux, AES, RNG, HSEM */ /* Resume not retained USARTx and DMA */ + MX_GPIO_Init(); MX_I2C2_Init(); MX_DMA_Init(); vcom_Resume(); diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index d10854e..64715f8 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -60,10 +60,10 @@ extern SUBGHZ_HandleTypeDef hsubghz; extern DMA_HandleTypeDef hdma_usart2_tx; extern UART_HandleTypeDef huart2; /* USER CODE BEGIN EV */ -#if defined(VL53LX)||defined(VL53L0) +//#if defined(VL53LX)||defined(VL53L0) extern DMA_HandleTypeDef hdma_i2c2_rx; extern DMA_HandleTypeDef hdma_i2c2_tx; -#endif +//#endif /* USER CODE END EV */ /******************************************************************************/ @@ -250,7 +250,7 @@ void EXTI3_IRQHandler(void) /* USER CODE BEGIN EXTI3_IRQn 0 */ /* USER CODE END EXTI3_IRQn 0 */ -#ifdef STM32WLE5xx +#if defined(VL53LX)||defined(VL53L0) HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); #endif /* USER CODE BEGIN EXTI3_IRQn 1 */ @@ -314,7 +314,7 @@ void EXTI9_5_IRQHandler(void) /* USER CODE END EXTI9_5_IRQn 0 */ #ifndef RM2 HAL_GPIO_EXTI_IRQHandler(BUT3_Pin); -#elif defined(RM2) +#elif defined(RM2)&&(defined(VL53L0)||defined(VL53LX)) HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); #endif diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 51b1d45..8fec7a1 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -516,6 +516,10 @@ void LoRaWAN_Init(void) #endif +#ifdef STS_R4 + UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP6), UTIL_SEQ_RFU, STS_YunhornSTSEventP6_Process); +#endif + #ifdef VL53L0 UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), UTIL_SEQ_RFU, STS_YunhornSTSEventP4_Process); #endif @@ -523,6 +527,7 @@ void LoRaWAN_Init(void) UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, 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); @@ -543,16 +548,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); } break; +#ifndef STS_R4 case BUT2_Pin: UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0); break; +#endif case BUT3_Pin: UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStoreContextEvent), CFG_SEQ_Prio_0); break; +#if (defined(VL53L0)||defined(VL53LX)) case TOF_INT_EXTI_PIN: ToF_EventDetected = 1; break; - +#endif default: break; } @@ -738,6 +746,8 @@ static void SendTxData(void) sts_people_count_sensor_data_t sts_p2_sensor_data={0x0}; #elif defined(STS_R1)||defined(STS_R1D)||defined(STS_R2)||defined(STS_R5) sts_tof_range_data_t sts_rr_sensor_data={0x0,0x0,0x0}; +#elif defined(STS_R4) + sts_r_sensor_data_t sts_r4_sensor_data={0}; #endif if (LmHandlerIsBusy() == false) @@ -757,6 +767,11 @@ static void SendTxData(void) #endif /* CAYENNE_LPP */ EnvSensors_Read(&sensor_data); +#ifdef STS_R4 + //UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP6), CFG_SEQ_Prio_0); + //STS_YunhornSTSEventP6_Process(); + STS_R4_sensor_read(&sts_r4_sensor_data); +#endif #ifdef VL53LX STS_people_count_sensor_Read(&sts_p2_sensor_data); @@ -777,7 +792,12 @@ static void SendTxData(void) #endif //VL53L0 - AppData.Buffer[i++] = AppLedStateOn; +#ifdef STS_R4 + AppData.Port = YUNHORN_STS_R4_LORA_APP_DATA_PORT; /* STS-R4 Data Port */ +#endif + + + AppData.Buffer[i++] = (uint8_t) (AppLedStateOn|0x80); // for first byte, cannot be 0x0 AppData.Buffer[i++] = (uint8_t) sts_mtmcode1; AppData.Buffer[i++] = (uint8_t) sts_mtmcode2; AppData.Buffer[i++] = (uint8_t) sts_hardware_ver; @@ -899,10 +919,15 @@ static void SendTxData(void) #endif // VL53L1X #endif //STS_P2 + +/* STS-R4 SOAP LEVEL SENSOR */ +#ifdef STS_R4 + AppData.Buffer[i++] = 2; + AppData.Buffer[i++] = (uint8_t)(sts_r4_sensor_data.measure_tech & 0xFF); + AppData.Buffer[i++] = (uint8_t)(sts_r4_sensor_data.on_off_event & 0xFF); +#endif //STS_R4 AppData.BufferSize = i; - - if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET)) { UTIL_TIMER_Stop(&JoinLedTimer); @@ -939,6 +964,9 @@ static void OnTxTimerEvent(void *context) /* USER CODE BEGIN OnTxTimerEvent_1 */ /* USER CODE END OnTxTimerEvent_1 */ + + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP6), CFG_SEQ_Prio_0); + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); /*Wait for next tx slot*/ @@ -1320,7 +1348,7 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context) // UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0); UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer); - uint8_t appHeartBeatDataPort, appHeartBeatBufferSize, appHeartBeatDataBuffer[32]; + uint8_t appHeartBeatDataPort=2, appHeartBeatBufferSize=2, appHeartBeatDataBuffer[32]={0x0}; if ((rfac_timer <(STS_BURN_IN_RFAC+3))&&(sts_cfg_nvm.ac[0]==0x0)&&(sts_cfg_nvm.ac[19]==0x0)) { @@ -1346,12 +1374,14 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context) appHeartBeatDataPort = YUNHORN_STS_R1D_LORA_APP_HTBT_PORT; #elif defined(STS_R5) appHeartBeatDataPort = YUNHORN_STS_R5_LORA_APP_HTBT_PORT; +#elif defined(STS_R4) + appHeartBeatDataPort = YUNHORN_STS_R4_LORA_APP_HTBT_PORT; #endif appHeartBeatBufferSize = 2; appHeartBeatDataBuffer[0]=(uint8_t)(0x80|AppLedStateOn); appHeartBeatDataBuffer[1]=(uint8_t)(SYS_GetBatteryLevel()/100); //TODO XXX change to battery level in mV - + //APP_LOG(TS_OFF, VLEVEL_M, "\n\n HEART-BEAT TIMER = %d\n\n", rfac_timer); STS_SENSOR_Upload_Message(appHeartBeatDataPort, appHeartBeatBufferSize, (uint8_t*)appHeartBeatDataBuffer); #endif @@ -1385,7 +1415,7 @@ void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); /* USER CODE BEGIN OnYunhornSTSHeartBeatPeriodicityChanged_2 */ - APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 ); + APP_LOG(TS_OFF, VLEVEL_M,"* STS HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 ); /* USER CODE END OnYunhornSTSHeartBeatPeriodicityChanged_2 */ } @@ -1400,3 +1430,24 @@ static void OnYunhornSTSWakeUpScanTimerEvent(void *context) } +/** + * @brief Yunhorn STS Tx Periodicity Change function + * @param duration of periodicty in ms (1/1000 sec) + */ +void OnYunhornSTSTxPeriodicityChanged(uint32_t periodicity) +{ + /* USER CODE BEGIN OnYunhornSTSTxPeriodicityChanged */ + + /* USER CODE END OnYunhornSTSTxPeriodicityChanged */ + + /* Update timer OnYunhornSTSTxPeriodicityChanged */ + + UTIL_TIMER_Stop(&TxTimer); + TxPeriodicity = periodicity; + UTIL_TIMER_SetPeriod(&TxTimer, TxPeriodicity); + UTIL_TIMER_Start(&TxTimer); + + /* USER CODE BEGIN OnYunhornSTSTxPeriodicityChanged */ + APP_LOG(TS_OFF, VLEVEL_M,"* STS TxPeriodicity = %u (sec)\r\n", TxPeriodicity/1000 ); + /* USER CODE END OnYunhornSTSTxPeriodicityChanged */ +} diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index f826144..27a9d57 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -133,10 +133,7 @@