drivers/dht: some cleanup

This commit is contained in:
Alexandre Abadie 2017-06-27 18:03:01 +02:00
parent ce0a8ac744
commit f1a93bf36e
3 changed files with 17 additions and 21 deletions

View File

@ -67,12 +67,9 @@ static const dht_params_t dht_params[] =
/** /**
* @brief Allocate and configure entries to the SAUL registry * @brief Allocate and configure entries to the SAUL registry
*/ */
static const saul_reg_info_t dht_saul_info[][2] = static const saul_reg_info_t dht_saul_reg_info[] =
{ {
{ { .name = "dht" }
{ .name = "dht-temp" },
{ .name = "dht-hum" }
}
}; };
#endif #endif

View File

@ -30,7 +30,6 @@
#include <stdint.h> #include <stdint.h>
#include "saul.h"
#include "periph/gpio.h" #include "periph/gpio.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -78,14 +77,6 @@ typedef struct {
*/ */
typedef dht_t dht_params_t; typedef dht_t dht_params_t;
/**
* @brief export SAUL endpoints
* @{
*/
extern const saul_driver_t dht_temp_saul_driver;
extern const saul_driver_t dht_hum_saul_driver;
/** @} */
/** /**
* @brief auto-initialize all configured DHT devices * @brief auto-initialize all configured DHT devices
*/ */

View File

@ -23,27 +23,35 @@
#include "log.h" #include "log.h"
#include "saul_reg.h" #include "saul_reg.h"
#include "dht.h"
#include "dht_params.h" #include "dht_params.h"
#include "dht.h"
/** /**
* @brief Define the number of configured sensors * @brief Define the number of configured sensors
*/ */
#define DHT_NUM (sizeof(dht_params) / sizeof(dht_params[0])) #define DHT_NUMOF (sizeof(dht_params) / sizeof(dht_params[0]))
/** /**
* @brief Allocate memory for the device descriptors * @brief Allocate memory for the device descriptors
*/ */
static dht_t dht_devs[DHT_NUM]; static dht_t dht_devs[DHT_NUMOF];
/**
* @brief 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 * @brief Memory for the SAUL registry entries
*/ */
static saul_reg_t saul_entries[DHT_NUM * 2]; static saul_reg_t saul_entries[DHT_NUMOF * 2];
void auto_init_dht(void) void auto_init_dht(void)
{ {
for (unsigned int i = 0; i < DHT_NUM; i++) { for (unsigned int i = 0; i < DHT_NUMOF; i++) {
LOG_DEBUG("[auto_init_saul] initializing dht #%u\n", i); LOG_DEBUG("[auto_init_saul] initializing dht #%u\n", i);
if (dht_init(&dht_devs[i], &dht_params[i]) != DHT_OK) { if (dht_init(&dht_devs[i], &dht_params[i]) != DHT_OK) {
@ -52,10 +60,10 @@ void auto_init_dht(void)
} }
saul_entries[(i * 2)].dev = &(dht_devs[i]); saul_entries[(i * 2)].dev = &(dht_devs[i]);
saul_entries[(i * 2)].name = dht_saul_info[i][0].name; saul_entries[(i * 2)].name = dht_saul_reg_info[i].name;
saul_entries[(i * 2)].driver = &dht_temp_saul_driver; saul_entries[(i * 2)].driver = &dht_temp_saul_driver;
saul_entries[(i * 2) + 1].dev = &(dht_devs[i]); saul_entries[(i * 2) + 1].dev = &(dht_devs[i]);
saul_entries[(i * 2) + 1].name = dht_saul_info[i][1].name; saul_entries[(i * 2) + 1].name = dht_saul_reg_info[i].name;
saul_entries[(i * 2) + 1].driver = &dht_hum_saul_driver; saul_entries[(i * 2) + 1].driver = &dht_hum_saul_driver;
saul_reg_add(&(saul_entries[(i * 2)])); saul_reg_add(&(saul_entries[(i * 2)]));
saul_reg_add(&(saul_entries[(i * 2) + 1])); saul_reg_add(&(saul_entries[(i * 2) + 1]));