From 583af33148173be41808ea6d6f2557ef1bab9860 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Sun, 22 Mar 2026 20:25:15 +0100 Subject: [PATCH 1/7] drivers/sgp30: use event_timeout, to avoid long ISR code block --- drivers/include/sgp30.h | 9 ++++++++- drivers/sgp30/Makefile.dep | 4 ++++ drivers/sgp30/sgp30.c | 10 +++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/include/sgp30.h b/drivers/include/sgp30.h index ce4609b7d952..3f98d3784792 100644 --- a/drivers/include/sgp30.h +++ b/drivers/include/sgp30.h @@ -48,6 +48,12 @@ #include "periph/i2c.h" #include "ztimer.h" +#ifdef MODULE_SGP30_STRICT +#include "event/thread.h" +#include "event/callback.h" +#include "event/timeout.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -87,7 +93,8 @@ typedef struct { sgp30_params_t params; /**< parameters of the sensor device */ #ifdef MODULE_SGP30_STRICT bool ready; /**< if initialization phase is over*/ - ztimer_t _timer; /**< timer */ + event_callback_t _event; /**< event callback */ + event_timeout_t _timeout; /**< event timeout */ sgp30_data_t _data; /**< internal current data */ #endif } sgp30_t; diff --git a/drivers/sgp30/Makefile.dep b/drivers/sgp30/Makefile.dep index 4661682e3066..1bf35a6b90f5 100644 --- a/drivers/sgp30/Makefile.dep +++ b/drivers/sgp30/Makefile.dep @@ -4,3 +4,7 @@ USEMODULE += ztimer_usec FEATURES_REQUIRED += periph_i2c DEFAULT_MODULE += sgp30_strict + +USEMODULE += event_timeout +USEMODULE += event_callback +USEMODULE += event_thread diff --git a/drivers/sgp30/sgp30.c b/drivers/sgp30/sgp30.c index b325fd33d8ab..6aa30b2572d2 100644 --- a/drivers/sgp30/sgp30.c +++ b/drivers/sgp30/sgp30.c @@ -158,7 +158,7 @@ static void _read_cb(void *arg) } _read_measurements(dev, &dev->_data); dev->_data.timestamp = ztimer_now(ZTIMER_USEC); - ztimer_set(ZTIMER_USEC, &dev->_timer, SGP30_RECOMMENDED_SAMPLING_PERIOD); + event_timeout_set(&dev->_timeout, SGP30_RECOMMENDED_SAMPLING_PERIOD); } #endif @@ -169,7 +169,7 @@ int sgp30_start_air_quality(sgp30_t *dev) #ifdef MODULE_SGP30_STRICT if (ret == 0) { - ztimer_set(ZTIMER_USEC, &dev->_timer, SGP30_AIR_QUALITY_INIT_DELAY_US); + event_timeout_set(&dev->_timeout, SGP30_AIR_QUALITY_INIT_DELAY_US); } #endif return ret ? -EPROTO : 0; @@ -181,8 +181,8 @@ int sgp30_init(sgp30_t *dev, const sgp30_params_t *params) dev->params = *params; #ifdef MODULE_SGP30_STRICT dev->ready = false; - dev->_timer.callback = _read_cb; - dev->_timer.arg = dev; + event_callback_init(&dev->_event, _read_cb, dev); + event_timeout_init(&dev->_timeout, EVENT_PRIO_LOWEST, (event_t *)&dev->_event); #endif /* delay while powering up */ @@ -226,7 +226,7 @@ int sgp30_reset(sgp30_t *dev) int ret = _rx_tx_data(dev, SGP30_CMD_SOFT_RESET, NULL, 0, SGP30_DELAY_SOFT_RESET, false); #ifdef MODULE_SGP30_STRICT if (ret == 0) { - ztimer_remove(ZTIMER_USEC, &dev->_timer); + event_timeout_clear(&dev->_timeout); dev->ready = false; } #endif From 46b8dd78cfc36ceb22a085195fb79a9fed1bf8c5 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 24 Mar 2026 19:46:28 +0100 Subject: [PATCH 2/7] drivers/sgp30: format with uncrustify --- drivers/include/sgp30.h | 26 ++++++++++++------------- drivers/sgp30/include/sgp30_constants.h | 10 +++++----- drivers/sgp30/include/sgp30_params.h | 20 +++++++++++-------- drivers/sgp30/sgp30.c | 6 +++--- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/drivers/include/sgp30.h b/drivers/include/sgp30.h index 3f98d3784792..9ccfba33f983 100644 --- a/drivers/include/sgp30.h +++ b/drivers/include/sgp30.h @@ -49,9 +49,9 @@ #include "ztimer.h" #ifdef MODULE_SGP30_STRICT -#include "event/thread.h" -#include "event/callback.h" -#include "event/timeout.h" +# include "event/thread.h" +# include "event/callback.h" +# include "event/timeout.h" #endif #ifdef __cplusplus @@ -62,9 +62,9 @@ extern "C" { * @brief Set of measured values */ typedef struct { - uint16_t tvoc; /**< The last measurement of the IAQ-calculated Total + uint16_t tvoc; /**< The last measurement of the IAQ-calculated Total Volatile Organic Compounds in ppb. */ - uint16_t eco2; /**< The last measurement of the IAQ-calculated + uint16_t eco2; /**< The last measurement of the IAQ-calculated equivalent CO2 in ppm */ #ifdef MODULE_SGP30_STRICT uint32_t timestamp; /**< Timestamp of last measured value */ @@ -75,27 +75,27 @@ typedef struct { * @brief Set of measured raw values */ typedef struct { - uint16_t raw_h2; /**< raw H2 signal, only for testing purposes */ - uint16_t raw_ethanol; /**< raw Ethanol signal, only for testing purposes */ + uint16_t raw_h2; /**< raw H2 signal, only for testing purposes */ + uint16_t raw_ethanol; /**< raw Ethanol signal, only for testing purposes */ } sgp30_raw_data_t; /** * @brief Device initialization parameters */ typedef struct { - i2c_t i2c_dev; /**< I2C dev the sensor is connected to */ + i2c_t i2c_dev; /**< I2C dev the sensor is connected to */ } sgp30_params_t; /** * @brief Device descriptor for the driver */ typedef struct { - sgp30_params_t params; /**< parameters of the sensor device */ + sgp30_params_t params; /**< parameters of the sensor device */ #ifdef MODULE_SGP30_STRICT - bool ready; /**< if initialization phase is over*/ - event_callback_t _event; /**< event callback */ - event_timeout_t _timeout; /**< event timeout */ - sgp30_data_t _data; /**< internal current data */ + bool ready; /**< if initialization phase is over*/ + event_callback_t _event; /**< event callback */ + event_timeout_t _timeout; /**< event timeout */ + sgp30_data_t _data; /**< internal current data */ #endif } sgp30_t; diff --git a/drivers/sgp30/include/sgp30_constants.h b/drivers/sgp30/include/sgp30_constants.h index 55d39b5854ad..fe57f5cd7083 100644 --- a/drivers/sgp30/include/sgp30_constants.h +++ b/drivers/sgp30/include/sgp30_constants.h @@ -27,27 +27,27 @@ extern "C" { /** * @brief SGP30 I2C address, only one is defined */ -#define SGP30_I2C_ADDRESS (0x58) +#define SGP30_I2C_ADDRESS (0x58) /** * @brief Minimum required feature set version for this driver */ -#define SGP30_REQUIRED_FEATURE_SET (0x0020) +#define SGP30_REQUIRED_FEATURE_SET (0x0020) /** * @brief Length of serial id */ -#define SGP30_SERIAL_ID_LEN (6U) +#define SGP30_SERIAL_ID_LEN (6U) /** * @brief Initialization time */ -#define SGP30_AIR_QUALITY_INIT_DELAY_US (15 * US_PER_SEC) +#define SGP30_AIR_QUALITY_INIT_DELAY_US (15 * US_PER_SEC) /** * @brief Sampling for dynamic baseline compensation algorithm */ -#define SGP30_RECOMMENDED_SAMPLING_PERIOD (1 * US_PER_SEC) +#define SGP30_RECOMMENDED_SAMPLING_PERIOD (1 * US_PER_SEC) #ifdef __cplusplus } diff --git a/drivers/sgp30/include/sgp30_params.h b/drivers/sgp30/include/sgp30_params.h index cdfd0a62101c..966b3c05a881 100644 --- a/drivers/sgp30/include/sgp30_params.h +++ b/drivers/sgp30/include/sgp30_params.h @@ -32,34 +32,38 @@ extern "C" { * @{ */ #ifndef SGP30_PARAM_I2C_DEV -#define SGP30_PARAM_I2C_DEV (I2C_DEV(0)) +# define SGP30_PARAM_I2C_DEV (I2C_DEV(0)) #endif #ifndef SGP30_PARAMS -#define SGP30_PARAMS { .i2c_dev = SGP30_PARAM_I2C_DEV } +# define SGP30_PARAMS \ + { \ + .i2c_dev = SGP30_PARAM_I2C_DEV \ + } #endif #ifndef SGP30_SAUL_INFO -#define SGP30_SAUL_INFO { .name = "sgp30" } +# define SGP30_SAUL_INFO \ + { \ + .name = "sgp30" \ + } #endif /**@}*/ /** * @brief SGP30 configuration */ -static const sgp30_params_t sgp30_params[] = -{ +static const sgp30_params_t sgp30_params[] = { SGP30_PARAMS }; /** * @brief Define the number of configured sensors */ -#define SGP30_NUM ARRAY_SIZE(sgp30_params) +#define SGP30_NUM ARRAY_SIZE(sgp30_params) /** * @brief Additional meta information to keep in the SAUL registry */ -static const saul_reg_info_t sgp30_saul_info[] = -{ +static const saul_reg_info_t sgp30_saul_info[] = { SGP30_SAUL_INFO }; diff --git a/drivers/sgp30/sgp30.c b/drivers/sgp30/sgp30.c index 6aa30b2572d2..887274d014af 100644 --- a/drivers/sgp30/sgp30.c +++ b/drivers/sgp30/sgp30.c @@ -211,7 +211,7 @@ int sgp30_init(sgp30_t *dev, const sgp30_params_t *params) DEBUG_PUTS("\n"); } - /* start air quality measurement */ + /* start air quality measurement */ if (sgp30_start_air_quality(dev)) { DEBUG_PUTS("[sgp30]: could not start air quality measurements "); return -1; @@ -235,7 +235,7 @@ int sgp30_reset(sgp30_t *dev) int sgp30_read_serial_number(sgp30_t *dev, uint8_t *buf, size_t len) { - (void) len; + (void)len; assert(dev && buf && (len == SGP30_SERIAL_ID_LEN)); uint8_t frame[9]; if (_rx_tx_data(dev, SGP30_CMD_READ_SERIAL, (uint8_t *)frame, sizeof(frame), @@ -244,7 +244,7 @@ int sgp30_read_serial_number(sgp30_t *dev, uint8_t *buf, size_t len) return -EPROTO; } /* the serial id is in big endian format */ - uint16_t tmp[SGP30_SERIAL_ID_LEN/2]; + uint16_t tmp[SGP30_SERIAL_ID_LEN / 2]; if (_get_uint16_and_check_crc(&frame[0], &tmp[2]) || _get_uint16_and_check_crc(&frame[3], &tmp[1]) || _get_uint16_and_check_crc(&frame[6], &tmp[0])) { From d75d3f7157ccccd6b665eaa490b36fc848bdff91 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 24 Mar 2026 19:46:52 +0100 Subject: [PATCH 3/7] fixup! drivers/sgp30: use event_timeout, to avoid long ISR code block --- drivers/sgp30/sgp30.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/sgp30/sgp30.c b/drivers/sgp30/sgp30.c index 887274d014af..d8ae3ddf839f 100644 --- a/drivers/sgp30/sgp30.c +++ b/drivers/sgp30/sgp30.c @@ -182,7 +182,7 @@ int sgp30_init(sgp30_t *dev, const sgp30_params_t *params) #ifdef MODULE_SGP30_STRICT dev->ready = false; event_callback_init(&dev->_event, _read_cb, dev); - event_timeout_init(&dev->_timeout, EVENT_PRIO_LOWEST, (event_t *)&dev->_event); + event_timeout_init(&dev->_timeout, EVENT_PRIO_MEDIUM, (event_t *)&dev->_event); #endif /* delay while powering up */ From a516421446ea7c86688d5290985a4058957378b2 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Sat, 28 Mar 2026 08:06:59 +0100 Subject: [PATCH 4/7] fixup! fixup! drivers/sgp30: use event_timeout, to avoid long ISR code block --- drivers/include/sgp30.h | 8 ++++++++ drivers/sgp30/sgp30.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/include/sgp30.h b/drivers/include/sgp30.h index 9ccfba33f983..7a97ae21025d 100644 --- a/drivers/include/sgp30.h +++ b/drivers/include/sgp30.h @@ -58,6 +58,14 @@ extern "C" { #endif + +/** + * @brief The event queue if 'sgp30_strict' is used + */ +#ifndef SGP30_STRICT_EVENT_THREAD_QUEUE +#define SGP30_STRICT_EVENT_THREAD_QUEUE EVENT_PRIO_MEDIUM +#endif + /** * @brief Set of measured values */ diff --git a/drivers/sgp30/sgp30.c b/drivers/sgp30/sgp30.c index d8ae3ddf839f..f0c313a82682 100644 --- a/drivers/sgp30/sgp30.c +++ b/drivers/sgp30/sgp30.c @@ -182,7 +182,8 @@ int sgp30_init(sgp30_t *dev, const sgp30_params_t *params) #ifdef MODULE_SGP30_STRICT dev->ready = false; event_callback_init(&dev->_event, _read_cb, dev); - event_timeout_init(&dev->_timeout, EVENT_PRIO_MEDIUM, (event_t *)&dev->_event); + event_timeout_init(&dev->_timeout, SGP30_STRICT_EVENT_THREAD_QUEUE, (event_t *)&dev->_event); +#error #endif /* delay while powering up */ From 5489038f158d4e1d7f0567865782e137fd7a3899 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 20 Apr 2026 20:50:21 +0200 Subject: [PATCH 5/7] fixup! fixup! fixup! drivers/sgp30: use event_timeout, to avoid long ISR code block --- drivers/sgp30/sgp30.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/sgp30/sgp30.c b/drivers/sgp30/sgp30.c index f0c313a82682..295aacd6a8b4 100644 --- a/drivers/sgp30/sgp30.c +++ b/drivers/sgp30/sgp30.c @@ -183,7 +183,6 @@ int sgp30_init(sgp30_t *dev, const sgp30_params_t *params) dev->ready = false; event_callback_init(&dev->_event, _read_cb, dev); event_timeout_init(&dev->_timeout, SGP30_STRICT_EVENT_THREAD_QUEUE, (event_t *)&dev->_event); -#error #endif /* delay while powering up */ From 38f403c1dccc759cf86a576775568197ad888985 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 20 Apr 2026 20:57:04 +0200 Subject: [PATCH 6/7] fixup! fixup! fixup! fixup! drivers/sgp30: use event_timeout, to avoid long ISR code block --- drivers/include/sgp30.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/include/sgp30.h b/drivers/include/sgp30.h index 7a97ae21025d..bf4cf0428003 100644 --- a/drivers/include/sgp30.h +++ b/drivers/include/sgp30.h @@ -58,12 +58,11 @@ extern "C" { #endif - /** * @brief The event queue if 'sgp30_strict' is used */ -#ifndef SGP30_STRICT_EVENT_THREAD_QUEUE -#define SGP30_STRICT_EVENT_THREAD_QUEUE EVENT_PRIO_MEDIUM +#ifndef CONFIG_SGP30_STRICT_EVENT_THREAD_QUEUE +#define CONFIG_SGP30_STRICT_EVENT_THREAD_QUEUE EVENT_PRIO_MEDIUM #endif /** From 61ced53a8515f3954b0b649eb181e657f06fae10 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 20 Apr 2026 21:00:26 +0200 Subject: [PATCH 7/7] fixup! fixup! fixup! fixup! fixup! drivers/sgp30: use event_timeout, to avoid long ISR code block --- drivers/include/sgp30.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/include/sgp30.h b/drivers/include/sgp30.h index bf4cf0428003..af946dbed599 100644 --- a/drivers/include/sgp30.h +++ b/drivers/include/sgp30.h @@ -62,7 +62,7 @@ extern "C" { * @brief The event queue if 'sgp30_strict' is used */ #ifndef CONFIG_SGP30_STRICT_EVENT_THREAD_QUEUE -#define CONFIG_SGP30_STRICT_EVENT_THREAD_QUEUE EVENT_PRIO_MEDIUM +# define CONFIG_SGP30_STRICT_EVENT_THREAD_QUEUE EVENT_PRIO_MEDIUM #endif /**