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

Merge pull request #17101 from aabadie/pr/drivers/bmp180_ztimer

drivers/bmp180: migrate to ztimer
This commit is contained in:
Francisco 2021-11-04 15:25:48 +01:00 committed by GitHub
commit f08c5da7aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 19 deletions

View File

@ -10,4 +10,5 @@ config MODULE_BMP180
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 "bmp180_internals.h" #include "bmp180_internals.h"
#include "bmp180_params.h" #include "bmp180_params.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"
@ -65,7 +65,7 @@ int bmp180_init(bmp180_t *dev, const bmp180_params_t *params)
} }
/* adding delay before reading calibration values to avoid timing issues */ /* adding delay before reading calibration values to avoid timing issues */
xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS);
uint8_t buffer[22] = {0}; uint8_t buffer[22] = {0};
/* Read calibration values, using contiguous register addresses */ /* Read calibration values, using contiguous register addresses */
@ -187,7 +187,7 @@ static int _read_ut(const bmp180_t *dev, int32_t *output)
uint8_t ut[2] = {0}; uint8_t ut[2] = {0};
uint8_t control[2] = { BMP180_REGISTER_CONTROL, BMP180_TEMPERATURE_COMMAND }; uint8_t control[2] = { BMP180_REGISTER_CONTROL, BMP180_TEMPERATURE_COMMAND };
i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0); i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0);
xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS);
if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, ut, 2, 0) < 0) { if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, ut, 2, 0) < 0) {
DEBUG("[Error] Cannot read uncompensated temperature.\n"); DEBUG("[Error] Cannot read uncompensated temperature.\n");
i2c_release(DEV_I2C); i2c_release(DEV_I2C);
@ -209,19 +209,19 @@ static int _read_up(const bmp180_t *dev, int32_t *output)
i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0); i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0);
switch (OVERSAMPLING) { switch (OVERSAMPLING) {
case BMP180_ULTRALOWPOWER: case BMP180_ULTRALOWPOWER:
xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS);
break; break;
case BMP180_STANDARD: case BMP180_STANDARD:
xtimer_usleep(BMP180_STANDARD_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_STANDARD_DELAY_MS);
break; break;
case BMP180_HIGHRES: case BMP180_HIGHRES:
xtimer_usleep(BMP180_HIGHRES_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_HIGHRES_DELAY_MS);
break; break;
case BMP180_ULTRAHIGHRES: case BMP180_ULTRAHIGHRES:
xtimer_usleep(BMP180_ULTRAHIGHRES_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRAHIGHRES_DELAY_MS);
break; break;
default: default:
xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS);
break; break;
} }
if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, up, 3, 0) < 0) { if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, up, 3, 0) < 0) {

View File

@ -23,7 +23,6 @@
#include "saul.h" #include "saul.h"
#include "bmp180.h" #include "bmp180.h"
#include "xtimer.h"
static int read_temperature(const void *dev, phydat_t *res) static int read_temperature(const void *dev, phydat_t *res)
{ {

View File

@ -47,10 +47,10 @@ extern "C" {
* @name Oversampling modes delays (micros) * @name Oversampling modes delays (micros)
* @{ * @{
*/ */
#define BMP180_ULTRALOWPOWER_DELAY (5000UL) #define BMP180_ULTRALOWPOWER_DELAY_MS (5UL) /**< Ultra low power delay (ms) */
#define BMP180_STANDARD_DELAY (8000UL) #define BMP180_STANDARD_DELAY_MS (8UL) /**< Standard resolution delay (ms) */
#define BMP180_HIGHRES_DELAY (14000UL) #define BMP180_HIGHRES_DELAY_MS (14UL) /**< High resolution delay (ms) */
#define BMP180_ULTRAHIGHRES_DELAY (26000UL) #define BMP180_ULTRAHIGHRES_DELAY_MS (26UL) /**< Ultra high resolution delay (ms) */
/** @} */ /** @} */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,7 +1,8 @@
include ../Makefile.tests_common include ../Makefile.tests_common
USEMODULE += bmp180 USEMODULE += bmp180
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
# set default altitude # set default altitude
TEST_ALTITUDE ?= 158 # altitude in Polytechnique School campus TEST_ALTITUDE ?= 158 # altitude in Polytechnique School campus

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_BMP180=y CONFIG_MODULE_BMP180=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y

View File

@ -24,7 +24,8 @@
#include "bmp180.h" #include "bmp180.h"
#include "bmp180_params.h" #include "bmp180_params.h"
#include "xtimer.h" #include "timex.h"
#include "ztimer.h"
#include "board.h" #include "board.h"
int main(void) int main(void)
@ -84,7 +85,7 @@ int main(void)
(unsigned long)pressure_0 / 100, (int)(pressure_0 % 100), (unsigned long)pressure_0 / 100, (int)(pressure_0 % 100),
(int)altitude); (int)altitude);
xtimer_sleep(2); ztimer_sleep(ZTIMER_MSEC, 2 * MS_PER_SEC);
} }
return 0; return 0;