Browse Source

drivers/dht: some cleanup

master
Alexandre Abadie 5 years ago
parent
commit
f1a93bf36e
  1. 7
      drivers/dht/include/dht_params.h
  2. 9
      drivers/include/dht.h
  3. 22
      sys/auto_init/saul/auto_init_dht.c

7
drivers/dht/include/dht_params.h

@ -67,12 +67,9 @@ static const dht_params_t dht_params[] =
/**
* @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-temp" },
{ .name = "dht-hum" }
}
{ .name = "dht" }
};
#endif

9
drivers/include/dht.h

@ -30,7 +30,6 @@
#include <stdint.h>
#include "saul.h"
#include "periph/gpio.h"
#ifdef __cplusplus
@ -78,14 +77,6 @@ typedef struct {
*/
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
*/

22
sys/auto_init/saul/auto_init_dht.c

@ -23,27 +23,35 @@
#include "log.h"
#include "saul_reg.h"
#include "dht.h"
#include "dht_params.h"
#include "dht.h"
/**
* @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
*/
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
*/
static saul_reg_t saul_entries[DHT_NUM * 2];
static saul_reg_t saul_entries[DHT_NUMOF * 2];
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);
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)].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) + 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_reg_add(&(saul_entries[(i * 2)]));
saul_reg_add(&(saul_entries[(i * 2) + 1]));

Loading…
Cancel
Save