Merge pull request #17315 from aabadie/pr/drivers/ztimer

drivers: migrate some drivers to ztimer
This commit is contained in:
Alexandre Abadie 2021-12-09 09:49:47 +01:00 committed by GitHub
commit 5c99f951cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 84 additions and 56 deletions

View File

@ -12,7 +12,9 @@ menuconfig MODULE_CCS811
depends on TEST_KCONFIG depends on TEST_KCONFIG
select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO
select MODULE_PERIPH_I2C select MODULE_PERIPH_I2C
select MODULE_XTIMER select MODULE_ZTIMER
select MODULE_ZTIMER_USEC
select MODULE_ZTIMER_PERIPH_TIMER
config MODULE_CCS811_FULL config MODULE_CCS811_FULL
bool "Full functionalities" bool "Full functionalities"

View File

@ -1,6 +1,7 @@
FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_i2c FEATURES_REQUIRED += periph_i2c
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_usec
ifneq (,$(filter ccs811_full,$(USEMODULE))) ifneq (,$(filter ccs811_full,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_gpio_irq

View File

@ -19,7 +19,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "log.h" #include "log.h"
#include "xtimer.h" #include "ztimer.h"
#include "ccs811_regs.h" #include "ccs811_regs.h"
#include "ccs811.h" #include "ccs811.h"
@ -82,11 +82,11 @@ int ccs811_init(ccs811_t *dev, const ccs811_params_t *params)
/* enable low active reset signal */ /* enable low active reset signal */
gpio_clear(dev->params.reset_pin); gpio_clear(dev->params.reset_pin);
/* t_RESET (reset impuls) has to be at least 20 us, we wait 1 ms */ /* t_RESET (reset impuls) has to be at least 20 us, we wait 1 ms */
xtimer_usleep(1000); ztimer_sleep(ZTIMER_USEC, 1000);
/* disable low active reset signal */ /* disable low active reset signal */
gpio_set(dev->params.reset_pin); gpio_set(dev->params.reset_pin);
/* t_START after reset is 1 ms, we wait 1 further ms */ /* t_START after reset is 1 ms, we wait 1 further ms */
xtimer_usleep(1000); ztimer_sleep(ZTIMER_USEC, 1000);
} }
if (gpio_is_valid(dev->params.wake_pin) && if (gpio_is_valid(dev->params.wake_pin) &&
@ -112,7 +112,7 @@ int ccs811_init(ccs811_t *dev, const ccs811_params_t *params)
uint8_t status; uint8_t status;
/* wait 100 ms after the reset */ /* wait 100 ms after the reset */
xtimer_usleep(100000); ztimer_sleep(ZTIMER_USEC, 100000);
/* get the status to check whether sensor is in bootloader mode */ /* get the status to check whether sensor is in bootloader mode */
if (_reg_read(dev, CCS811_REG_STATUS, &status, 1) != CCS811_OK) { if (_reg_read(dev, CCS811_REG_STATUS, &status, 1) != CCS811_OK) {
@ -139,7 +139,7 @@ int ccs811_init(ccs811_t *dev, const ccs811_params_t *params)
} }
/* wait 100 ms after starting the app */ /* wait 100 ms after starting the app */
xtimer_usleep(100000); ztimer_sleep(ZTIMER_USEC, 100000);
/* get the status to check whether sensor switched to application mode */ /* get the status to check whether sensor switched to application mode */
if (_reg_read(dev, CCS811_REG_STATUS, &status, 1) != CCS811_OK) { if (_reg_read(dev, CCS811_REG_STATUS, &status, 1) != CCS811_OK) {
@ -482,7 +482,7 @@ static int _reg_read(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t l
/* wake the sensor with low active WAKE signal */ /* wake the sensor with low active WAKE signal */
gpio_clear(dev->params.wake_pin); gpio_clear(dev->params.wake_pin);
/* t_WAKE is 50 us */ /* t_WAKE is 50 us */
xtimer_usleep(50); ztimer_sleep(ZTIMER_USEC, 50);
} }
#endif #endif
@ -494,7 +494,7 @@ static int _reg_read(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t l
/* let the sensor enter to sleep mode */ /* let the sensor enter to sleep mode */
gpio_set(dev->params.wake_pin); gpio_set(dev->params.wake_pin);
/* minimum t_DWAKE is 20 us */ /* minimum t_DWAKE is 20 us */
xtimer_usleep(20); ztimer_sleep(ZTIMER_USEC, 20);
} }
#endif #endif
@ -540,7 +540,7 @@ static int _reg_write(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t
/* wake the sensor with low active WAKE signal */ /* wake the sensor with low active WAKE signal */
gpio_clear(dev->params.wake_pin); gpio_clear(dev->params.wake_pin);
/* t_WAKE is 50 us */ /* t_WAKE is 50 us */
xtimer_usleep(50); ztimer_sleep(ZTIMER_USEC, 50);
} }
#endif #endif
@ -557,7 +557,7 @@ static int _reg_write(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t
/* let the sensor enter to sleep mode */ /* let the sensor enter to sleep mode */
gpio_set(dev->params.wake_pin); gpio_set(dev->params.wake_pin);
/* minimum t_DWAKE is 20 us */ /* minimum t_DWAKE is 20 us */
xtimer_usleep(20); ztimer_sleep(ZTIMER_USEC, 20);
} }
#endif #endif

View File

@ -10,4 +10,5 @@ config MODULE_LSM6DSL
depends on HAS_PERIPH_I2C depends on HAS_PERIPH_I2C
depends on TEST_KCONFIG depends on TEST_KCONFIG
select MODULE_PERIPH_I2C select MODULE_PERIPH_I2C
select MODULE_XTIMER select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC

View File

@ -1,2 +1,3 @@
FEATURES_REQUIRED += periph_i2c FEATURES_REQUIRED += periph_i2c
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec

View File

@ -22,8 +22,6 @@
#ifndef LSM6DSL_INTERNAL_H #ifndef LSM6DSL_INTERNAL_H
#define LSM6DSL_INTERNAL_H #define LSM6DSL_INTERNAL_H
#include "xtimer.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -159,9 +157,9 @@ extern "C" {
#define LSM6DSL_TEMP_OFFSET (0x1900) #define LSM6DSL_TEMP_OFFSET (0x1900)
/** /**
* @brief Reboot wait interval in us (15ms) * @brief Reboot wait interval in ms (15ms)
*/ */
#define LSM6DSL_BOOT_WAIT (15 * US_PER_MS) #define LSM6DSL_BOOT_WAIT_MS (15)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -22,7 +22,7 @@
#include <assert.h> #include <assert.h>
#include "xtimer.h" #include "ztimer.h"
#include "lsm6dsl.h" #include "lsm6dsl.h"
#include "lsm6dsl_internal.h" #include "lsm6dsl_internal.h"
@ -62,7 +62,7 @@ int lsm6dsl_init(lsm6dsl_t *dev, const lsm6dsl_params_t *params)
/* Reboot */ /* Reboot */
i2c_write_reg(BUS, ADDR, LSM6DSL_REG_CTRL3_C, LSM6DSL_CTRL3_C_BOOT, 0); i2c_write_reg(BUS, ADDR, LSM6DSL_REG_CTRL3_C, LSM6DSL_CTRL3_C_BOOT, 0);
xtimer_usleep(LSM6DSL_BOOT_WAIT); ztimer_sleep(ZTIMER_MSEC, LSM6DSL_BOOT_WAIT_MS);
if (i2c_read_reg(BUS, ADDR, LSM6DSL_REG_WHO_AM_I, &tmp, 0) < 0) { if (i2c_read_reg(BUS, ADDR, LSM6DSL_REG_WHO_AM_I, &tmp, 0) < 0) {
i2c_release(BUS); i2c_release(BUS);

View File

@ -31,6 +31,7 @@ config MODULE_SI114X
bool bool
depends on HAS_PERIPH_I2C depends on HAS_PERIPH_I2C
select MODULE_PERIPH_I2C select MODULE_PERIPH_I2C
select MODULE_XTIMER select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC
endif # TEST_KCONFIG endif # TEST_KCONFIG

View File

@ -1,2 +1,3 @@
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
FEATURES_REQUIRED += periph_i2c FEATURES_REQUIRED += periph_i2c

View File

@ -161,8 +161,8 @@ extern "C" {
#define SI1145_ID (0x45) #define SI1145_ID (0x45)
#define SI1146_ID (0x46) #define SI1146_ID (0x46)
#define SI1147_ID (0x47) #define SI1147_ID (0x47)
#define SI114X_STARTUP_TIME (25000UL) /* 25ms */ #define SI114X_STARTUP_TIME_MS (25UL) /**< startup time (25ms) */
#define SI114X_WAIT_10MS (10000UL) /* 10ms */ #define SI114X_WAIT_10MS (10UL) /* 10ms */
#define SI114X_INIT_VALUE (0x17) #define SI114X_INIT_VALUE (0x17)
#define SI114X_UCOEF0_DEFAULT (0x29) #define SI114X_UCOEF0_DEFAULT (0x29)
#define SI114X_UCOEF1_DEFAULT (0x89) #define SI114X_UCOEF1_DEFAULT (0x89)

View File

@ -24,7 +24,7 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include "xtimer.h" #include "ztimer.h"
#include "periph/i2c.h" #include "periph/i2c.h"
@ -50,7 +50,7 @@ int8_t si114x_init(si114x_t *dev, const si114x_params_t *params)
dev->params = *params; dev->params = *params;
/* wait before sensor is ready */ /* wait before sensor is ready */
xtimer_usleep(SI114X_STARTUP_TIME); ztimer_sleep(ZTIMER_MSEC, SI114X_STARTUP_TIME_MS);
/* acquire exclusive access */ /* acquire exclusive access */
i2c_acquire(DEV_I2C); i2c_acquire(DEV_I2C);
@ -178,12 +178,12 @@ void _reset(si114x_t *dev)
/* perform RESET command */ /* perform RESET command */
i2c_write_reg(DEV_I2C, SI114X_ADDR, i2c_write_reg(DEV_I2C, SI114X_ADDR,
SI114X_REG_COMMAND, SI114X_RESET, 0); SI114X_REG_COMMAND, SI114X_RESET, 0);
xtimer_usleep(SI114X_WAIT_10MS); ztimer_sleep(ZTIMER_MSEC, SI114X_WAIT_10MS);
/* write HW_KEY for proper operation */ /* write HW_KEY for proper operation */
i2c_write_reg(DEV_I2C, SI114X_ADDR, i2c_write_reg(DEV_I2C, SI114X_ADDR,
SI114X_REG_HW_KEY, SI114X_INIT_VALUE, 0); SI114X_REG_HW_KEY, SI114X_INIT_VALUE, 0);
xtimer_usleep(SI114X_WAIT_10MS); ztimer_sleep(ZTIMER_MSEC, SI114X_WAIT_10MS);
} }
void _initialize(si114x_t *dev) void _initialize(si114x_t *dev)

View File

@ -9,9 +9,12 @@ config MODULE_STMPE811
bool bool
depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO
depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_GPIO_IRQ
depends on HAS_PERIPH_I2C
depends on TEST_KCONFIG
select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO
select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_GPIO_IRQ
select MODULE_XTIMER select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC
depends on TEST_KCONFIG depends on TEST_KCONFIG
choice choice

View File

@ -8,4 +8,5 @@ ifneq (,$(filter stmpe811_i2c,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c FEATURES_REQUIRED += periph_i2c
endif endif
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec

View File

@ -20,7 +20,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "xtimer.h" #include "ztimer.h"
#if IS_USED(MODULE_STMPE811_SPI) #if IS_USED(MODULE_STMPE811_SPI)
#include "periph/spi.h" #include "periph/spi.h"
#else #else
@ -135,13 +135,13 @@ static int _soft_reset(const stmpe811_t *dev)
DEBUG("[stmpe811] soft reset: cannot write soft reset bit to SYS_CTRL1 register\n"); DEBUG("[stmpe811] soft reset: cannot write soft reset bit to SYS_CTRL1 register\n");
return -EPROTO; return -EPROTO;
} }
xtimer_msleep(10); ztimer_sleep(ZTIMER_MSEC, 10);
if (_write_reg(dev, STMPE811_SYS_CTRL1, 0) < 0) { if (_write_reg(dev, STMPE811_SYS_CTRL1, 0) < 0) {
DEBUG("[stmpe811] soft reset: cannot clear SYS_CTRL1 register\n"); DEBUG("[stmpe811] soft reset: cannot clear SYS_CTRL1 register\n");
return -EPROTO; return -EPROTO;
} }
xtimer_msleep(2); ztimer_sleep(ZTIMER_MSEC, 2);
return 0; return 0;
} }

View File

@ -10,4 +10,5 @@ config MODULE_TSL2561
depends on HAS_PERIPH_I2C depends on HAS_PERIPH_I2C
depends on TEST_KCONFIG depends on TEST_KCONFIG
select MODULE_PERIPH_I2C select MODULE_PERIPH_I2C
select MODULE_XTIMER select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC

View File

@ -1,2 +1,3 @@
FEATURES_REQUIRED += periph_i2c FEATURES_REQUIRED += periph_i2c
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec

View File

@ -25,7 +25,7 @@
#include "tsl2561.h" #include "tsl2561.h"
#include "tsl2561_internals.h" #include "tsl2561_internals.h"
#include "periph/i2c.h" #include "periph/i2c.h"
#include "xtimer.h" #include "ztimer.h"
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
@ -220,16 +220,16 @@ static void _read_data(const tsl2561_t *dev, uint16_t *full, uint16_t *ir)
/* Wait integration time in ms for ADC to complete */ /* Wait integration time in ms for ADC to complete */
switch (DEV_INTEGRATION) { switch (DEV_INTEGRATION) {
case TSL2561_INTEGRATIONTIME_13MS: case TSL2561_INTEGRATIONTIME_13MS: /* 13700us */
xtimer_usleep(13700); ztimer_sleep(ZTIMER_MSEC, 14);
break; break;
case TSL2561_INTEGRATIONTIME_101MS: case TSL2561_INTEGRATIONTIME_101MS:
xtimer_usleep(101000); ztimer_sleep(ZTIMER_MSEC, 101);
break; break;
default: /* TSL2561_INTEGRATIONTIME_402MS */ default: /* TSL2561_INTEGRATIONTIME_402MS */
xtimer_usleep(402000); ztimer_sleep(ZTIMER_MSEC, 402);
break; break;
} }

View File

@ -2,4 +2,7 @@ include ../Makefile.tests_common
USEMODULE += ccs811 USEMODULE += ccs811
USEMODULE += ztimer
USEMODULE += ztimer_usec
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -1,3 +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_CCS811=y CONFIG_MODULE_CCS811=y
CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_USEC=y

View File

@ -27,7 +27,7 @@
#include <string.h> #include <string.h>
#include "thread.h" #include "thread.h"
#include "xtimer.h" #include "ztimer.h"
#include "ccs811.h" #include "ccs811.h"
#include "ccs811_params.h" #include "ccs811_params.h"
@ -54,7 +54,7 @@ int main(void)
/* wait and check for for new data every 10 ms */ /* wait and check for for new data every 10 ms */
while (ccs811_data_ready (&sensor) != CCS811_OK) { while (ccs811_data_ready (&sensor) != CCS811_OK) {
xtimer_usleep(10000); ztimer_sleep(ZTIMER_USEC, 10000);
} }
/* read the data and print them on success */ /* read the data and print them on success */

View File

@ -35,7 +35,6 @@
#include <string.h> #include <string.h>
#include "thread.h" #include "thread.h"
#include "xtimer.h"
#include "ccs811.h" #include "ccs811.h"
#include "ccs811_params.h" #include "ccs811_params.h"

View File

@ -1,6 +1,7 @@
include ../Makefile.tests_common include ../Makefile.tests_common
USEMODULE += lsm6dsl USEMODULE += lsm6dsl
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

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_LSM6DSL=y CONFIG_MODULE_LSM6DSL=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y

View File

@ -22,11 +22,11 @@
#include <stdio.h> #include <stdio.h>
#include "xtimer.h" #include "ztimer.h"
#include "lsm6dsl.h" #include "lsm6dsl.h"
#include "lsm6dsl_params.h" #include "lsm6dsl_params.h"
#define SLEEP_USEC (500UL * US_PER_MS) #define SLEEP_MSEC (500UL)
int main(void) int main(void)
{ {
@ -55,7 +55,7 @@ int main(void)
} }
puts("[SUCCESS]\n"); puts("[SUCCESS]\n");
xtimer_sleep(1); ztimer_sleep(ZTIMER_MSEC, 1 * 1000);
puts("Powering up LSM6DSL sensor..."); puts("Powering up LSM6DSL sensor...");
if (lsm6dsl_acc_power_up(&dev) != LSM6DSL_OK) { if (lsm6dsl_acc_power_up(&dev) != LSM6DSL_OK) {
@ -95,7 +95,7 @@ int main(void)
} }
puts(""); puts("");
xtimer_usleep(SLEEP_USEC); ztimer_sleep(ZTIMER_MSEC, SLEEP_MSEC);
} }
return 0; return 0;

View File

@ -1,5 +1,8 @@
include ../Makefile.tests_common include ../Makefile.tests_common
USEMODULE += ztimer
USEMODULE += ztimer_msec
# This test should also work with Si1146 and Si1147 variants. # This test should also work with Si1146 and Si1147 variants.
USEMODULE += si1145 USEMODULE += si1145

View File

@ -1,5 +1,8 @@
# 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_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y
# This test should also work with Si1146 and Si1147 variants. # This test should also work with Si1146 and Si1147 variants.
CONFIG_MODULE_SI1145=y CONFIG_MODULE_SI1145=y

View File

@ -25,7 +25,8 @@
#include "si114x.h" #include "si114x.h"
#include "si114x_params.h" #include "si114x_params.h"
#include "xtimer.h" #include "timex.h"
#include "ztimer.h"
#include "board.h" #include "board.h"
static si114x_t dev; static si114x_t dev;
@ -63,7 +64,7 @@ int main(void)
si114x_read_response(&dev)); si114x_read_response(&dev));
/* 2 seconds delay between measures */ /* 2 seconds delay between measures */
xtimer_sleep(2); ztimer_sleep(ZTIMER_MSEC, 2 * MS_PER_SEC);
} }
return 0; return 0;

View File

@ -0,0 +1,3 @@
BOARD_INSUFFICIENT_MEMORY := \
nucleo-l011k4 \
#

View File

@ -1,6 +1,7 @@
include ../Makefile.tests_common include ../Makefile.tests_common
USEMODULE += tsl2561 USEMODULE += tsl2561
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

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_TSL2561=y CONFIG_MODULE_TSL2561=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y

View File

@ -21,14 +21,13 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include "xtimer.h" #include "timex.h"
#include "ztimer.h"
#include "board.h" #include "board.h"
#include "tsl2561.h" #include "tsl2561.h"
#include "tsl2561_params.h" #include "tsl2561_params.h"
#define SLEEP_1S (1 * 1000 * 1000u) /* 1 second delay between printf */
int main(void) int main(void)
{ {
puts("TSL2561 test application\n"); puts("TSL2561 test application\n");
@ -58,7 +57,7 @@ int main(void)
"\n+-------------------------------------+\n", "\n+-------------------------------------+\n",
(int)tsl2561_read_illuminance(&dev)); (int)tsl2561_read_illuminance(&dev));
xtimer_usleep(SLEEP_1S); ztimer_sleep(ZTIMER_MSEC, MS_PER_SEC); /* 1s delay */
} }
return 0; return 0;