diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 0e6c21e..e1e99c2 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -165,8 +165,37 @@ void Error_Handler(void); #define TOF_R_XSHUT_Pin GPIO_PIN_10 #define TOF_R_XSHUT_GPIO_Port GPIOA -#endif +/* **** PCB BOARD RM2 **** */ +/* **** NO LONG USED ANYMORE FOR TEST ONLY */ +#ifdef RM2 +/* TOF-1 */ +/* | U3, PB-3 XSHUT | */ +/* INT PIN PB-5 | */ + +#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 + +#define TOF_INT_EXTI_PIN TOF_C_INT_Pin +#define TOF_INT_EXTI_PORT TOF_C_INT_GPIO_Port + +/* | TOF-2 | */ +/* U4, PA-9 XSHUT | */ +/* NT PIN PB-5 | */ +#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 //RM2 + +#endif // defined(VL53LX)||defined(VL53L0) #ifdef STM32WLE5xx #define I2C2_SCL_PIN GPIO_PIN_12 diff --git a/Core/Inc/utilities_def.h b/Core/Inc/utilities_def.h index 4e28fcc..3f355e1 100644 --- a/Core/Inc/utilities_def.h +++ b/Core/Inc/utilities_def.h @@ -87,7 +87,7 @@ typedef enum CFG_SEQ_Task_YunhornSTSEventP2, /* MOTION */ CFG_SEQ_Task_YunhornSTSEventP3, /* LAMP BAR LED */ #endif -#ifdef STS_R1 +#if defined(STS_R1)||defined(STS_R1D)||defined(STS_R5)||defined(STS_R2) CFG_SEQ_Task_YunhornSTSEventP4, /* TOF RANGE */ #endif #ifdef STS_P2 diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index b7a3bd2..7f58d4d 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -101,6 +101,14 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(TOF_C_XSHUT_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pins : TOF_L_XSHUT_Pin */ + GPIO_InitStruct.Pin = TOF_L_XSHUT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(TOF_L_XSHUT_GPIO_Port, &GPIO_InitStruct); + + HAL_NVIC_SetPriority(TOF_C_INT_EXTI_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn); diff --git a/Core/Src/stm32_lpm_if.c b/Core/Src/stm32_lpm_if.c index d5f862f..0e6a462 100644 --- a/Core/Src/stm32_lpm_if.c +++ b/Core/Src/stm32_lpm_if.c @@ -23,7 +23,7 @@ #include "stm32_lpm.h" #include "stm32_lpm_if.h" #include "usart_if.h" - +#include "i2c.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index 0c4a24a..d10854e 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -312,7 +312,12 @@ void EXTI9_5_IRQHandler(void) /* USER CODE BEGIN EXTI9_5_IRQn 0 */ /* USER CODE END EXTI9_5_IRQn 0 */ +#ifndef RM2 HAL_GPIO_EXTI_IRQHandler(BUT3_Pin); +#elif defined(RM2) + HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); +#endif + /* USER CODE BEGIN EXTI9_5_IRQn 1 */ /* USER CODE END EXTI9_5_IRQn 1 */ diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 22c19fa..81d71ef 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -49,6 +49,8 @@ extern volatile uint8_t sts_ac_code[20]; 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; +volatile uint8_t sts_data_buf[LORAWAN_APP_DATA_BUFFER_MAX_SIZE]={0x0}; +volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; /* USER CODE END EV */ @@ -663,6 +665,31 @@ static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params) } /* USER CODE END OnRxData_1 */ } +void STS_SENSOR_Upload_AppData_Message(LmHandlerAppData_t stsAppdata) +{ + uint32_t nextTxIn =0; + LmHandlerErrorStatus_t status; + + if (LmHandlerIsBusy() == false) + { + + status = LmHandlerSend(&stsAppdata, LmHandlerParams.IsTxConfirmed, false); + if (LORAMAC_HANDLER_SUCCESS == status) + { + APP_LOG(TS_ON, VLEVEL_H, "SEND REQUEST\r\n"); + } + else if (LORAMAC_HANDLER_DUTYCYCLE_RESTRICTED == status) + { + nextTxIn = LmHandlerGetDutyCycleWaitTime(); + if (nextTxIn > 0) + { + APP_LOG(TS_ON, VLEVEL_H, "Next Tx in : ~%d second(s)\r\n", (nextTxIn / 1000)); + } + } + + } + +} void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8_t *appDataBuffer) { @@ -708,7 +735,7 @@ static void SendTxData(void) #ifdef STS_P2 sts_people_count_sensor_data_t sts_p2_sensor_data={0x0}; #endif -#ifdef STS_R1 +#if defined(STS_R1)||defined(STS_R1D)||defined(STS_R2)||defined(STS_R5) sts_tof_range_data_t sts_rr_sensor_data={0x0,0x0,0x0}; #endif @@ -717,6 +744,7 @@ static void SendTxData(void) #ifdef CAYENNE_LPP uint8_t channel = 0; #else + uint16_t pressure = 0; int16_t temperature = 0; uint16_t humidity = 0; @@ -724,6 +752,7 @@ static void SendTxData(void) int32_t latitude = 0; int32_t longitude = 0; uint16_t altitudeGps = 0; + #endif /* CAYENNE_LPP */ EnvSensors_Read(&sensor_data); @@ -733,7 +762,16 @@ static void SendTxData(void) #ifdef VL53L0 STS_YunhornSTSEventP4_Process(); STS_RR_Sensor_Read(&sts_rr_sensor_data); +#ifdef STS_R1 AppData.Port = YUNHORN_STS_R1_LORA_APP_DATA_PORT; /* STS-R1 Data Port */ +#elif defined(STS_R1D) + AppData.Port = YUNHORN_STS_R1D_LORA_APP_DATA_PORT; /* STS-R1D Data Port */ +#elif defined(STS_R2) + AppData.Port = YUNHORN_STS_R2_LORA_APP_DATA_PORT; /* STS-R2 Data Port */ +#elif defined(STS_R5) + AppData.Port = YUNHORN_STS_R5_LORA_APP_DATA_PORT; /* STS-R5 Data Port */ +#endif + #endif AppData.Buffer[i++] = AppLedStateOn; @@ -811,9 +849,7 @@ static void SendTxData(void) AppData.Buffer[i++] = 2; AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm & 0xFF); -#endif - -#ifdef STS_R1D +#else ifdef STS_R1D AppData.Buffer[i++] = 4; AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm & 0xFF); @@ -826,11 +862,6 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm & 0xFF); #endif -#if defined(STS_R1D) - AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_2_distance_mm >>8 & 0xFF); - AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_2_distance_mm & 0xFF); -#endif - #if defined(STS_R5_EXT) AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm & 0xFF); @@ -1287,10 +1318,14 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context) uint8_t appHeartBeatDataPort, appHeartBeatBufferSize, appHeartBeatDataBuffer[32]; #ifdef STS_P2 appHeartBeatDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT; -#endif -#ifdef STS_R1 +#elif defined(STS_R1) appHeartBeatDataPort = YUNHORN_STS_R1_LORA_APP_HTBT_PORT; +#elif defined(STS_R1D) + appHeartBeatDataPort = YUNHORN_STS_R1D_LORA_APP_HTBT_PORT; +#elif defined(STS_R5) + appHeartBeatDataPort = YUNHORN_STS_R5_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 diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index 035cf0b..b4652aa 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -134,6 +134,7 @@