Skip to content

Commit 167b5e3

Browse files
authored
Merge pull request #21804 from krzysztof-cabaj/drivers-ds18-move-to-ztimer
drivers/ds18: move to ztimer
2 parents ac3cd3f + 56660dd commit 167b5e3

File tree

8 files changed

+45
-47
lines changed

8 files changed

+45
-47
lines changed

drivers/ds18/Makefile.dep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
USEMODULE += xtimer
1+
USEMODULE += ztimer_usec
22
FEATURES_REQUIRED += periph_gpio

drivers/ds18/ds18.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/*
2-
* Copyright (C) 2017 Frits Kuipers
3-
* 2018 HAW Hamburg
4-
*
5-
* This file is subject to the terms and conditions of the GNU Lesser
6-
* General Public License v2.1. See the file LICENSE in the top level
7-
* directory for more details.
2+
* SPDX-FileCopyrightText: 2017 Frits Kuipers
3+
* SPDX-FileCopyrightText: 2018 HAW Hamburg
4+
* SPDX-License-Identifier: LGPL-2.1-only
85
*/
96

107
/**
@@ -25,7 +22,7 @@
2522

2623
#include "log.h"
2724
#include "periph/gpio.h"
28-
#include "xtimer.h"
25+
#include "ztimer.h"
2926

3027
#define ENABLE_DEBUG 0
3128
#include "debug.h"
@@ -54,9 +51,9 @@ static void ds18_write_bit(const ds18_t *dev, uint8_t bit)
5451
}
5552

5653
/* Wait for slot to end */
57-
xtimer_usleep(DS18_DELAY_SLOT);
54+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_SLOT);
5855
ds18_release(dev);
59-
xtimer_usleep(1);
56+
ztimer_sleep(ZTIMER_USEC, 1);
6057
}
6158

6259
static int ds18_read_bit(const ds18_t *dev, uint8_t *bit)
@@ -66,17 +63,17 @@ static int ds18_read_bit(const ds18_t *dev, uint8_t *bit)
6663
ds18_release(dev);
6764

6865
#if defined(MODULE_DS18_OPTIMIZED)
69-
xtimer_usleep(DS18_SAMPLE_TIME);
66+
ztimer_sleep(ZTIMER_USEC, DS18_SAMPLE_TIME);
7067
*bit = gpio_read(dev->params.pin);
71-
xtimer_usleep(DS18_DELAY_R_RECOVER);
68+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_R_RECOVER);
7269
return DS18_OK;
7370
#else
7471
uint32_t start, measurement = 0;
7572

7673
/* Measure time low of device pin, timeout after slot time*/
77-
start = xtimer_now_usec();
74+
start = ztimer_now(ZTIMER_USEC);
7875
while (!gpio_read(dev->params.pin) && measurement < DS18_DELAY_SLOT) {
79-
measurement = xtimer_now_usec() - start;
76+
measurement = ztimer_now(ZTIMER_USEC) - start;
8077
}
8178

8279
/* If there was a timeout return error */
@@ -88,7 +85,7 @@ static int ds18_read_bit(const ds18_t *dev, uint8_t *bit)
8885
*bit = measurement < DS18_SAMPLE_TIME;
8986

9087
/* Wait for slot to end */
91-
xtimer_usleep(DS18_DELAY_SLOT - measurement);
88+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_SLOT - measurement);
9289

9390
return DS18_OK;
9491
#endif
@@ -124,17 +121,17 @@ static int ds18_reset(const ds18_t *dev)
124121

125122
/* Line low and sleep the reset delay */
126123
ds18_low(dev);
127-
xtimer_usleep(DS18_DELAY_RESET);
124+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_RESET);
128125

129126
/* Release and wait for the presence response */
130127
ds18_release(dev);
131-
xtimer_usleep(DS18_DELAY_PRESENCE);
128+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_PRESENCE);
132129

133130
/* Check device presence */
134131
res = gpio_read(dev->params.pin);
135132

136133
/* Sleep for reset delay */
137-
xtimer_usleep(DS18_DELAY_RESET);
134+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_RESET);
138135

139136
return res;
140137
}
@@ -199,7 +196,7 @@ int ds18_get_temperature(const ds18_t *dev, int16_t *temperature)
199196
}
200197

201198
DEBUG("[DS18] Wait for convert T\n");
202-
xtimer_usleep(DS18_DELAY_CONVERT);
199+
ztimer_sleep(ZTIMER_USEC, DS18_DELAY_CONVERT);
203200

204201
return ds18_read(dev, temperature);
205202
}

drivers/ds18/ds18_internal.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/*
2-
* Copyright (C) 2017 Frits Kuipers
3-
* 2018 HAW Hamburg
4-
*
5-
* This file is subject to the terms and conditions of the GNU Lesser
6-
* General Public License v2.1. See the file LICENSE in the top level
7-
* directory for more details.
2+
* SPDX-FileCopyrightText: 2017 Frits Kuipers
3+
* SPDX-FileCopyrightText: 2018 HAW Hamburg
4+
* SPDX-License-Identifier: LGPL-2.1-only
85
*/
96

107
#pragma once
118

9+
#include "time_units.h"
10+
1211
/**
1312
* @ingroup drivers_ds18
1413
* @{

drivers/ds18/ds18_saul.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/*
2-
* Copyright (C) 2017 Frits Kuipers
3-
* 2018 HAW Hamburg
4-
*
5-
* This file is subject to the terms and conditions of the GNU Lesser
6-
* General Public License v2.1. See the file LICENSE in the top level
7-
* directory for more details.
2+
* SPDX-FileCopyrightText: 2017 Frits Kuipers
3+
* SPDX-FileCopyrightText: 2018 HAW Hamburg
4+
* SPDX-License-Identifier: LGPL-2.1-only
85
*/
96

107
/**

tests/drivers/ds18/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ include ../Makefile.drivers_common
33
BOARD_WHITELIST := sensebox_samd21 samr21-xpro nucleo-l152re nucleo-l432kc nucleo-l073rz b-l072z-lrwan arduino-nano
44

55
USEMODULE += ds18
6-
USEMODULE += xtimer
6+
USEMODULE += ztimer_sec
77
USEMODULE += printf_float
8-
# Use the module if you have an accurate sleep with xtimer (~3us)
8+
# Use the module if you have an accurate sleep with ztimer (~3us)
99
#USEMODULE += ds18_optimized
1010

1111
include $(RIOTBASE)/Makefile.include

tests/drivers/ds18/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## About
2+
3+
This is a test application for the Maxim
4+
[DS18B20](https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf)
5+
1-Wire temperature sensor.
6+
7+
## Usage
8+
9+
The application will initialize the DS18B20 sensor, read
10+
the temperature and print the measurement to STDOUT every two seconds.
11+
12+
The default GPIO pin is (0,0), which equates for example to PA0 for STM32s.
13+
If you connected sensor to other pin you should set `DS18_PARAM_PIN` accordingly.
14+
Guide showing how to change default driver configuration is provided by
15+
[link](https://guide.riot-os.org/advanced_tutorials/device_drivers/#default-device-configuration) .

tests/drivers/ds18/Readme.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/drivers/ds18/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/*
2-
* Copyright (C) 2018 HAW Hamburg
3-
*
4-
* This file is subject to the terms and conditions of the GNU Lesser
5-
* General Public License v2.1. See the file LICENSE in the top level
6-
* directory for more details.
2+
* SPDX-FileCopyrightText: 2018 HAW Hamburg
3+
* SPDX-License-Identifier: LGPL-2.1-only
74
*/
85

96
/**
@@ -24,7 +21,7 @@
2421
#include "board.h"
2522
#include "ds18.h"
2623
#include "ds18_params.h"
27-
#include "xtimer.h"
24+
#include "ztimer.h"
2825

2926
#define SAMPLING_PERIOD 2
3027

@@ -63,7 +60,7 @@ int main(void)
6360
puts("[Error] Could not read temperature");
6461
}
6562

66-
xtimer_sleep(SAMPLING_PERIOD);
63+
ztimer_sleep(ZTIMER_SEC, SAMPLING_PERIOD);
6764
}
6865

6966
return 0;

0 commit comments

Comments
 (0)