From c19a78765ad004bc5179a8e98b4f077f281a6bfd Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Thu, 9 Dec 2021 12:52:37 +0100 Subject: [PATCH] drivers/pir: migrate to ztimer64 --- drivers/pir/Kconfig | 2 +- drivers/pir/Makefile.dep | 2 +- drivers/pir/pir.c | 8 ++++---- tests/driver_pir/Makefile.ci | 1 + tests/driver_pir/main.c | 5 +++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/pir/Kconfig b/drivers/pir/Kconfig index fd43da5e80..d676cdff66 100644 --- a/drivers/pir/Kconfig +++ b/drivers/pir/Kconfig @@ -12,7 +12,7 @@ config MODULE_PIR depends on TEST_KCONFIG select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ - select MODULE_XTIMER + select ZTIMER64_USEC config HAVE_PIR bool diff --git a/drivers/pir/Makefile.dep b/drivers/pir/Makefile.dep index 46a195a15d..add2d6c03c 100644 --- a/drivers/pir/Makefile.dep +++ b/drivers/pir/Makefile.dep @@ -1,3 +1,3 @@ FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio_irq -USEMODULE += xtimer +USEMODULE += ztimer64_usec diff --git a/drivers/pir/pir.c b/drivers/pir/pir.c index b46bd26bc8..d12c9c4463 100644 --- a/drivers/pir/pir.c +++ b/drivers/pir/pir.c @@ -24,7 +24,7 @@ #include "irq.h" #include "thread.h" #include "msg.h" -#include "xtimer.h" +#include "ztimer64.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -50,7 +50,7 @@ int pir_init(pir_t *dev, const pir_params_t *params) dev->active = false; dev->accum_active_time = 0; dev->start_active_time = 0; - dev->last_read_time = xtimer_now_usec64(); + dev->last_read_time = ztimer64_now(ZTIMER64_USEC); gpio_mode_t gpio_mode; if (dev->p.active_high) { @@ -74,7 +74,7 @@ pir_event_t pir_get_status(const pir_t *dev) int pir_get_occupancy(pir_t *dev, int16_t *occup) { int irq_state = irq_disable(); - uint64_t now = xtimer_now_usec64(); + uint64_t now = ztimer64_now(ZTIMER64_USEC); uint64_t total_time = now - dev->last_read_time; if (total_time == 0) { irq_restore(irq_state); @@ -145,7 +145,7 @@ static void pir_callback(void *arg) DEBUG("pir_callback: %p\n", arg); pir_t *dev = (pir_t*) arg; bool pin_now = gpio_read(dev->p.gpio); - uint64_t now = xtimer_now_usec64(); + uint64_t now = ztimer64_now(ZTIMER64_USEC); /* We were busy counting */ if (dev->active) { diff --git a/tests/driver_pir/Makefile.ci b/tests/driver_pir/Makefile.ci index 419215ecfd..d5368f025e 100644 --- a/tests/driver_pir/Makefile.ci +++ b/tests/driver_pir/Makefile.ci @@ -7,5 +7,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega328p-xplained-mini \ nucleo-f031k6 \ nucleo-l011k4 \ + samd10-xmini \ stm32f030f4-demo \ # diff --git a/tests/driver_pir/main.c b/tests/driver_pir/main.c index 63736db54d..53ef6b21b9 100644 --- a/tests/driver_pir/main.c +++ b/tests/driver_pir/main.c @@ -23,7 +23,8 @@ #include #include "thread.h" -#include "xtimer.h" +#include "timex.h" +#include "ztimer.h" #include "pir.h" #include "pir_params.h" @@ -76,7 +77,7 @@ int main(void) while (1) { printf("Status: %s\n", pir_get_status(&dev) == PIR_STATUS_INACTIVE ? "inactive" : "active"); - xtimer_usleep(1000 * 1000); + ztimer_sleep(ZTIMER_USEC, 1 * US_PER_SEC); } #else thread_create(