1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

drivers/sps30: fix unused include, migrate to ztimer

This commit is contained in:
Alexandre Abadie 2021-12-10 14:23:19 +01:00
parent e71988d22a
commit e1310e3378
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
4 changed files with 18 additions and 16 deletions

View File

@ -21,7 +21,6 @@
#include "checksum/crc8.h" #include "checksum/crc8.h"
#include "sps30.h" #include "sps30.h"
#include "xtimer.h"
#include "byteorder.h" #include "byteorder.h"
#include "kernel_defines.h" #include "kernel_defines.h"

View File

@ -1,7 +1,8 @@
include ../Makefile.tests_common include ../Makefile.tests_common
USEMODULE += sps30 USEMODULE += sps30
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
CFLAGS+=-DPARAM_SPS30_I2C=I2C_DEV\(0\) CFLAGS+=-DPARAM_SPS30_I2C=I2C_DEV\(0\)
CFLAGS+=-DI2C0_SPEED=I2C_SPEED_NORMAL CFLAGS+=-DI2C0_SPEED=I2C_SPEED_NORMAL

View File

@ -1,4 +1,5 @@
# this file enables modules defined in Kconfig. Do not use this file for # this file enables modules defined in Kconfig. Do not use this file for
# application configuration. This is only needed during migration. # application configuration. This is only needed during migration.
CONFIG_MODULE_SPS30=y CONFIG_MODULE_SPS30=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y

View File

@ -18,15 +18,16 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "xtimer.h" #include "timex.h"
#include "ztimer.h"
#include "sps30.h" #include "sps30.h"
#include "sps30_params.h" #include "sps30_params.h"
#define TEST_START_DELAY_S (2U) #define TEST_START_DELAY_MS (2 * MS_PER_SEC)
#define SENSOR_RESET_DELAY_S (10U) #define SENSOR_RESET_DELAY_MS (10 * MS_PER_SEC)
#define SENSOR_STARTUP_DELAY_S (10U) #define SENSOR_STARTUP_DELAY_MS (10 * MS_PER_SEC)
#define SENSOR_SLEEP_WAKE_DELAY_S (5U) #define SENSOR_SLEEP_WAKE_DELAY_MS (5 * MS_PER_SEC)
#define POLL_FOR_READY_S (1U) #define POLL_FOR_READY_MS (1 * MS_PER_SEC)
#define NUM_OF_MEASUREMENTS (10U) #define NUM_OF_MEASUREMENTS (10U)
#define TYPE_MC_STR "MC PM" #define TYPE_MC_STR "MC PM"
@ -62,7 +63,7 @@ int main(void)
bool error = false; bool error = false;
unsigned cnt = NUM_OF_MEASUREMENTS; unsigned cnt = NUM_OF_MEASUREMENTS;
xtimer_sleep(TEST_START_DELAY_S); ztimer_sleep(ZTIMER_MSEC, TEST_START_DELAY_MS);
puts("SPS30 test application\n"); puts("SPS30 test application\n");
@ -87,7 +88,7 @@ int main(void)
error |= _print_error("start_fan_clean", ec); error |= _print_error("start_fan_clean", ec);
/* wait long enough for the fan clean to be done and the fan to settle */ /* wait long enough for the fan clean to be done and the fan to settle */
xtimer_sleep(2 * SPS30_FAN_CLEAN_S); ztimer_sleep(ZTIMER_MSEC, 2 * SPS30_FAN_CLEAN_S);
/* read the currently set value from the sensor */ /* read the currently set value from the sensor */
ec = sps30_read_ac_interval(&dev, &ci); ec = sps30_read_ac_interval(&dev, &ci);
@ -101,23 +102,23 @@ int main(void)
ec = sps30_reset(&dev); ec = sps30_reset(&dev);
error |= _print_error("reset", ec); error |= _print_error("reset", ec);
xtimer_sleep(SENSOR_RESET_DELAY_S); ztimer_sleep(ZTIMER_MSEC, SENSOR_RESET_DELAY_MS);
/* Put the sensor in sleep */ /* Put the sensor in sleep */
ec = sps30_sleep(&dev); ec = sps30_sleep(&dev);
error |= _print_error("sleep", ec); error |= _print_error("sleep", ec);
xtimer_sleep(SENSOR_SLEEP_WAKE_DELAY_S); ztimer_sleep(ZTIMER_MSEC, SENSOR_SLEEP_WAKE_DELAY_MS);
/* Wake-up the sensor */ /* Wake-up the sensor */
ec = sps30_wakeup(&dev); ec = sps30_wakeup(&dev);
error |= _print_error("wake-up", ec); error |= _print_error("wake-up", ec);
xtimer_sleep(SENSOR_SLEEP_WAKE_DELAY_S); ztimer_sleep(ZTIMER_MSEC, SENSOR_SLEEP_WAKE_DELAY_MS);
/* start the sensor again again... */ /* start the sensor again again... */
ec = sps30_start_measurement(&dev); ec = sps30_start_measurement(&dev);
error |= _print_error("start_measurement", ec); error |= _print_error("start_measurement", ec);
xtimer_sleep(SENSOR_STARTUP_DELAY_S); ztimer_sleep(ZTIMER_MSEC, SENSOR_STARTUP_DELAY_MS);
ec = sps30_read_ac_interval(&dev, &ci); ec = sps30_read_ac_interval(&dev, &ci);
error |= _print_error("read_ac_interval", ec); error |= _print_error("read_ac_interval", ec);
@ -141,7 +142,7 @@ int main(void)
cnt--; /* if errors happen, stop after NUM_OF_MEASUREMENTS */ cnt--; /* if errors happen, stop after NUM_OF_MEASUREMENTS */
} }
/* try again after some time */ /* try again after some time */
xtimer_sleep(POLL_FOR_READY_S); ztimer_sleep(ZTIMER_MSEC, POLL_FOR_READY_MS);
continue; continue;
} }