mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
drivers/si1133: migrate to ztimer
This commit is contained in:
parent
54d62f1303
commit
393c78b8e2
@ -10,4 +10,4 @@ config MODULE_SI1133
|
|||||||
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 ZTIMER_USEC
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
USEMODULE += xtimer
|
USEMODULE += ztimer_usec
|
||||||
FEATURES_REQUIRED += periph_i2c
|
FEATURES_REQUIRED += periph_i2c
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "timex.h"
|
||||||
|
#include "ztimer.h"
|
||||||
|
|
||||||
#include "periph/i2c.h"
|
#include "periph/i2c.h"
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command)
|
|||||||
|
|
||||||
if (command == SI1133_CMD_FORCE) {
|
if (command == SI1133_CMD_FORCE) {
|
||||||
/* Wait for the expected force acquisition time. */
|
/* Wait for the expected force acquisition time. */
|
||||||
xtimer_usleep(_si1133_force_time_us(dev));
|
ztimer_sleep(ZTIMER_USEC, _si1133_force_time_us(dev));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == SI1133_CMD_RESET_SW) {
|
if (command == SI1133_CMD_RESET_SW) {
|
||||||
@ -94,7 +95,7 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command)
|
|||||||
dev->cmd_counter = 0x0f;
|
dev->cmd_counter = 0x0f;
|
||||||
/* Reset command puts the device in "Initialization Mode" which requires
|
/* Reset command puts the device in "Initialization Mode" which requires
|
||||||
* us to wait until the device is ready. */
|
* us to wait until the device is ready. */
|
||||||
xtimer_msleep(SI1133_STARTUP_TIME_MS);
|
ztimer_sleep(ZTIMER_USEC, SI1133_STARTUP_TIME_MS * US_PER_MS);
|
||||||
}
|
}
|
||||||
else if (command == SI1133_CMD_RESET_CMD_CTR) {
|
else if (command == SI1133_CMD_RESET_CMD_CTR) {
|
||||||
/* The reset cmd_counter command, well, resets it to 0. */
|
/* The reset cmd_counter command, well, resets it to 0. */
|
||||||
@ -106,7 +107,7 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t new_cmd_ctr;
|
uint8_t new_cmd_ctr;
|
||||||
xtimer_ticks32_t start_time;
|
ztimer_now_t start_time;
|
||||||
bool retry = false;
|
bool retry = false;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = i2c_read_reg(dev->i2c_dev, dev->address, SI1133_REG_RESPONSE0,
|
ret = i2c_read_reg(dev->i2c_dev, dev->address, SI1133_REG_RESPONSE0,
|
||||||
@ -142,22 +143,21 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command)
|
|||||||
}
|
}
|
||||||
/* The command didn't yet finish in this case so it should be in running
|
/* The command didn't yet finish in this case so it should be in running
|
||||||
* state and we need to retry the loop with a timeout. This avoids
|
* state and we need to retry the loop with a timeout. This avoids
|
||||||
* calling xtimer for commands that are immediate. */
|
* calling ztimer for commands that are immediate. */
|
||||||
if (retry) {
|
if (retry) {
|
||||||
if (xtimer_usec_from_ticks(xtimer_diff(xtimer_now(), start_time))
|
if (ztimer_now(ZTIMER_USEC) - start_time > SI1133_COMMAND_TIMEOUT_USEC) {
|
||||||
> SI1133_COMMAND_TIMEOUT_USEC) {
|
|
||||||
DEBUG("[si1133] Command 0x%.2x timeout.\n", (unsigned)command);
|
DEBUG("[si1133] Command 0x%.2x timeout.\n", (unsigned)command);
|
||||||
return SI1133_ERR_LOGIC;
|
return SI1133_ERR_LOGIC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
retry = true;
|
retry = true;
|
||||||
start_time = xtimer_now();
|
start_time = ztimer_now(ZTIMER_USEC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (retry) {
|
if (retry) {
|
||||||
DEBUG("[si1133] Command overtime: %" PRIu32 " us.\n",
|
DEBUG("[si1133] Command overtime: %" PRIu32 " us.\n",
|
||||||
xtimer_usec_from_ticks(xtimer_diff(xtimer_now(), start_time)));
|
ztimer_now(ZTIMER_USEC) - start_time);
|
||||||
}
|
}
|
||||||
return SI1133_OK;
|
return SI1133_OK;
|
||||||
}
|
}
|
||||||
@ -320,7 +320,7 @@ si1133_ret_code_t si1133_init(si1133_t *dev, const si1133_params_t *params)
|
|||||||
/* After leaving "Off Mode" the SI1133 enters an "Initialization Mode" for
|
/* After leaving "Off Mode" the SI1133 enters an "Initialization Mode" for
|
||||||
* a period of time in which it can't be reached over I2C. After this time
|
* a period of time in which it can't be reached over I2C. After this time
|
||||||
* the device will be in Standby Mode. */
|
* the device will be in Standby Mode. */
|
||||||
xtimer_msleep(SI1133_STARTUP_TIME_MS);
|
ztimer_sleep(ZTIMER_USEC, SI1133_STARTUP_TIME_MS * US_PER_MS);
|
||||||
|
|
||||||
i2c_acquire(params->i2c_dev);
|
i2c_acquire(params->i2c_dev);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user