Added ToF interrupt, switch to SLEEP mode while sampling.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-07-07 23:25:56 +08:00
parent b7fd756262
commit c470f137b5
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
2 changed files with 31 additions and 4 deletions

@ -1 +1 @@
Subproject commit 23ff8ae04f14cacffabcac75c98f6dff32c7c5d3
Subproject commit 11283beab731b14b8812dade573fa7509e7c3e23

View File

@ -22,6 +22,7 @@
#include "app_ranging_impl.h"
#include "app_sensors_impl.h"
extern void SystemClock_Config_MSI2MHz(void);
extern void SystemClock_Config(void);
static app_sensors_impl_t s_dht_impl = {
@ -81,6 +82,8 @@ static VL53L1_Dev_t s_ranging = {
.OpsData = &s_ranging_impl,
};
static volatile bool s_ranging_irq;
int main(void) {
/* HAL */
HAL_Init();
@ -140,7 +143,7 @@ int main(void) {
VL53L1_StaticInit(&s_ranging);
VL53L1_SetDistanceMode(&s_ranging, VL53L1_DISTANCEMODE_MEDIUM);
VL53L1_SetMeasurementTimingBudgetMicroSeconds(&s_ranging, 50000);
VL53L1_SetInterMeasurementPeriodMilliSeconds(&s_ranging, 500);
VL53L1_SetInterMeasurementPeriodMilliSeconds(&s_ranging, 1000);
VL53L1_StartMeasurement(&s_ranging);
if (HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK) {
@ -155,8 +158,24 @@ int main(void) {
int16_t imu_temp;
uint16_t vbat;
s_ranging_irq = false;
for (;;) {
HAL_Delay(1000);
HAL_SuspendTick();
SystemClock_Config_MSI2MHz();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
SystemClock_Config();
HAL_ResumeTick();
if (s_ranging_irq) {
s_ranging_irq = false;
} else {
continue;
}
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
@ -195,6 +214,8 @@ int main(void) {
dht_result.temperature, dht_result.humidity, dht_result.pressure / 100.0f, als_result.ch0_value / 48.0,
als_result.ch1_value / 48.0, (imu_temp / 256.0) + 25.0, ranging_result.RangeMilliMeter,
(vbat * VDD_VALUE / 4096.0));
fflush(stdout);
}
dead_loop:
@ -204,5 +225,11 @@ dead_loop:
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
/* -- */
switch (GPIO_Pin) {
case TOF_GPIO_Pin:
s_ranging_irq = true;
break;
default:
break;
}
}