From 38c2ea57aa66e69b09e8c52e7403c16aa523e355 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 10 Dec 2021 14:02:07 +0100 Subject: [PATCH] drivers/pn532: migrate to ztimer --- drivers/pn532/Kconfig | 2 ++ drivers/pn532/Makefile.dep | 3 +++ drivers/pn532/pn532.c | 10 +++++----- tests/driver_pn532/Makefile | 3 ++- tests/driver_pn532/Makefile.ci | 3 +++ tests/driver_pn532/app.config.test | 3 ++- tests/driver_pn532/main.c | 6 +++--- 7 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 tests/driver_pn532/Makefile.ci diff --git a/drivers/pn532/Kconfig b/drivers/pn532/Kconfig index ab53f61eb5..45314ca0be 100644 --- a/drivers/pn532/Kconfig +++ b/drivers/pn532/Kconfig @@ -26,6 +26,8 @@ config MODULE_PN532 bool select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ + select MODULE_ZTIMER + select MODULE_ZTIMER_MSEC endmenu # PN532 NFC reader diff --git a/drivers/pn532/Makefile.dep b/drivers/pn532/Makefile.dep index f96df031c5..ce36e39e3f 100644 --- a/drivers/pn532/Makefile.dep +++ b/drivers/pn532/Makefile.dep @@ -1,2 +1,5 @@ FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio_irq + +USEMODULE += ztimer +USEMODULE += ztimer_msec diff --git a/drivers/pn532/pn532.c b/drivers/pn532/pn532.c index 2e25c7667f..508bbf3a9c 100644 --- a/drivers/pn532/pn532.c +++ b/drivers/pn532/pn532.c @@ -22,7 +22,7 @@ #include "assert.h" #include "kernel_defines.h" -#include "xtimer.h" +#include "ztimer.h" #include "mutex.h" #include "pn532.h" #include "periph/gpio.h" @@ -63,8 +63,8 @@ /* Constants and magic numbers */ #define MIFARE_CLASSIC_BLOCK_SIZE (16) -#define RESET_TOGGLE_SLEEP (400000) -#define RESET_BACKOFF (10000) +#define RESET_TOGGLE_SLEEP_MS (400) +#define RESET_BACKOFF_MS (10) #define HOST_TO_PN532 (0xD4) #define PN532_TO_HOST (0xD5) #define SPI_DATA_WRITE (0x80) @@ -104,9 +104,9 @@ void pn532_reset(const pn532_t *dev) DEBUG("pn532: reset\n"); gpio_clear(dev->conf->reset); - xtimer_usleep(RESET_TOGGLE_SLEEP); + ztimer_sleep(ZTIMER_MSEC, RESET_TOGGLE_SLEEP_MS); gpio_set(dev->conf->reset); - xtimer_usleep(RESET_BACKOFF); + ztimer_sleep(ZTIMER_MSEC, RESET_BACKOFF_MS); } int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode) diff --git a/tests/driver_pn532/Makefile b/tests/driver_pn532/Makefile index db0a924155..74f0bcd17c 100644 --- a/tests/driver_pn532/Makefile +++ b/tests/driver_pn532/Makefile @@ -1,6 +1,7 @@ include ../Makefile.tests_common -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_msec # select if you want to build the SPI or the I2C version of the driver: USEMODULE += pn532_i2c diff --git a/tests/driver_pn532/Makefile.ci b/tests/driver_pn532/Makefile.ci new file mode 100644 index 0000000000..b9ff275375 --- /dev/null +++ b/tests/driver_pn532/Makefile.ci @@ -0,0 +1,3 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-l011k4 \ + # diff --git a/tests/driver_pn532/app.config.test b/tests/driver_pn532/app.config.test index b31e14958f..8aa03c7b53 100644 --- a/tests/driver_pn532/app.config.test +++ b/tests/driver_pn532/app.config.test @@ -5,4 +5,5 @@ CONFIG_MODULE_PN532_I2C=y # CONFIG_MODULE_PN532_SPI=y -CONFIG_MODULE_XTIMER=y +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_MSEC=y diff --git a/tests/driver_pn532/main.c b/tests/driver_pn532/main.c index 1d1c92adc3..4cb60b7afb 100644 --- a/tests/driver_pn532/main.c +++ b/tests/driver_pn532/main.c @@ -22,7 +22,7 @@ #include "pn532.h" #include "pn532_params.h" -#include "xtimer.h" +#include "ztimer.h" #define LOG_LEVEL LOG_INFO #include "log.h" @@ -53,7 +53,7 @@ int main(void) LOG_INFO("init error %d\n", ret); } - xtimer_usleep(200000); + ztimer_sleep(ZTIMER_MSEC, 200); LOG_INFO("awake\n"); uint32_t fwver; @@ -65,7 +65,7 @@ int main(void) while (1) { /* Delay not to be always polling the interface */ - xtimer_usleep(250000UL); + ztimer_sleep(ZTIMER_MSEC, 250); ret = pn532_get_passive_iso14443a(&pn532, &card, 0x50); if (ret < 0) {