From 72e83db34ae22aa38e690b71525fb97b3f71bdc4 Mon Sep 17 00:00:00 2001 From: zhiayang <500236+zhiayang@users.noreply.github.com> Date: Tue, 16 May 2023 21:11:01 +0800 Subject: [PATCH] fix semaphore initialisation in max17048 driver Previously, we were using the semaphore before initialising it; this is now fixed. --- app/drivers/sensor/max17048/max17048.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/drivers/sensor/max17048/max17048.c b/app/drivers/sensor/max17048/max17048.c index 33a4202b..9f4bbc43 100644 --- a/app/drivers/sensor/max17048/max17048.c +++ b/app/drivers/sensor/max17048/max17048.c @@ -186,13 +186,15 @@ static int max17048_init(const struct device *dev) { return err; } + // the functions below need the semaphore, so initialise it here + k_sem_init(&drv_data->lock, 1, 1); + // bring the device out of sleep set_sleep_enabled(dev, false); // set the default rcomp value -- 0x97, as stated in the datasheet set_rcomp_value(dev, 0x97); - k_sem_init(&drv_data->lock, 1, 1); LOG_INF("device initialised at 0x%x (version %d)", config->i2c_bus.addr, ic_version); return 0;