From fffd6a2e076727e5e8f363b379f508d64864c84b Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 28 Feb 2018 16:33:42 +0100 Subject: [PATCH 1/2] drivers/dht: use new driver params scheme --- drivers/dht/include/dht_params.h | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/dht/include/dht_params.h b/drivers/dht/include/dht_params.h index 89cbcae66c..8cd84f6aec 100644 --- a/drivers/dht/include/dht_params.h +++ b/drivers/dht/include/dht_params.h @@ -40,10 +40,14 @@ extern "C" { #ifndef DHT_PARAM_PULL #define DHT_PARAM_PULL (GPIO_IN_PU) #endif - -#define DHT_PARAMS_DEFAULT {.pin = DHT_PARAM_PIN, \ - .type = DHT_PARAM_TYPE, \ - .in_mode = DHT_PARAM_PULL} +#ifndef DHT_PARAMS +#define DHT_PARAMS { .pin = DHT_PARAM_PIN, \ + .type = DHT_PARAM_TYPE, \ + .in_mode = DHT_PARAM_PULL } +#endif +#ifndef DHT_SAULINFO +#define DHT_SAULINFO { .name = "dht" } +#endif /**@}*/ /** @@ -51,27 +55,16 @@ extern "C" { */ static const dht_params_t dht_params[] = { -#ifdef DHT_PARAMS_BOARD - DHT_PARAMS_BOARD, -#else - DHT_PARAMS_DEFAULT, -#endif + DHT_PARAMS }; -/** - * @brief Get the number of configured DHT devices - */ -#define DHT_NUMOF (sizeof(dht_params) / sizeof(dht_params[0])) - -#ifdef MODULE_SAUL_REG /** * @brief Allocate and configure entries to the SAUL registry */ -static const saul_reg_info_t dht_saul_reg_info[] = +static const saul_reg_info_t dht_saul_info[] = { - { .name = "dht" } + DHT_SAULINFO }; -#endif #ifdef __cplusplus } From d0b34af78867a29dd9ede6fbd8b58f05fe58e782 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 28 Feb 2018 16:34:28 +0100 Subject: [PATCH 2/2] sys/auto_init: update dht auto_init --- sys/auto_init/saul/auto_init_dht.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/sys/auto_init/saul/auto_init_dht.c b/sys/auto_init/saul/auto_init_dht.c index 3d687d6d90..08175ac71a 100644 --- a/sys/auto_init/saul/auto_init_dht.c +++ b/sys/auto_init/saul/auto_init_dht.c @@ -29,29 +29,36 @@ /** * @brief Define the number of configured sensors */ -#define DHT_NUMOF (sizeof(dht_params) / sizeof(dht_params[0])) +#define DHT_NUM (sizeof(dht_params) / sizeof(dht_params[0])) /** * @brief Allocate memory for the device descriptors */ -static dht_t dht_devs[DHT_NUMOF]; +static dht_t dht_devs[DHT_NUM]; /** - * @brief Import SAUL endpoints + * @brief Memory for the SAUL registry entries + */ +static saul_reg_t saul_entries[DHT_NUM * 2]; + +/** + * @brief Define the number of saul info + */ +#define DHT_INFO_NUM (sizeof(dht_saul_info) / sizeof(dht_saul_info[0])) + +/** + * @name Import SAUL endpoints * @{ */ extern const saul_driver_t dht_temp_saul_driver; extern const saul_driver_t dht_hum_saul_driver; /** @} */ -/** - * @brief Memory for the SAUL registry entries - */ -static saul_reg_t saul_entries[DHT_NUMOF * 2]; - void auto_init_dht(void) { - for (unsigned int i = 0; i < DHT_NUMOF; i++) { + assert(DHT_INFO_NUM == DHT_NUM); + + for (unsigned int i = 0; i < DHT_NUM; i++) { LOG_DEBUG("[auto_init_saul] initializing dht #%u\n", i); if (dht_init(&dht_devs[i], &dht_params[i]) != DHT_OK) { @@ -60,10 +67,10 @@ void auto_init_dht(void) } saul_entries[(i * 2)].dev = &(dht_devs[i]); - saul_entries[(i * 2)].name = dht_saul_reg_info[i].name; + saul_entries[(i * 2)].name = dht_saul_info[i].name; saul_entries[(i * 2)].driver = &dht_temp_saul_driver; saul_entries[(i * 2) + 1].dev = &(dht_devs[i]); - saul_entries[(i * 2) + 1].name = dht_saul_reg_info[i].name; + saul_entries[(i * 2) + 1].name = dht_saul_info[i].name; saul_entries[(i * 2) + 1].driver = &dht_hum_saul_driver; saul_reg_add(&(saul_entries[(i * 2)])); saul_reg_add(&(saul_entries[(i * 2) + 1]));