1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
RIOT/sys/auto_init/auto_init_sht1x.c
Marian Buschsieweke de9b67bdc2
drivers/sht1x: Major refactoring
- Use RIOT's GPIO interface to access the sensor to increase portability
- Changed API to allow more than one sensor per board
- Added `sht1x_params.h` that specifies how the sensors is connected - each
  board can overwrite default settings by #defining SHT1X_PARAM_CLK and
  SHT1X_PARAM_DATA
- Changed arithmetic to use integer calculations only instead of floating point
  arithmetic
- Added support for checking the CRC sum
- Allow optional skipping of the CRC check to speed up measuring
- Added support for advanced features like reducing the resolution and skipping
  calibration to speed up measuring
- Allow specifying the supply voltage of sensor which heavily influences the
  temperature result (and use that information to calculate the correct
  temperature)
- Reset sensor on initialization to bring it in a well known state
- Support for the obscure heater feature. (Can be useful to check the
  temperature sensor?)
- Updated old SHT11 shell commands to the new driver interface, thus allowing
  more than one SHT10/11/15 sensor to be used
- Added new shell command to allow full configuration of all attached SHT1x
  sensors
- Removed old command for setting the SHT11 temperature offset, as this feature
  is implemented in the new configuration command
2018-06-27 08:58:00 +02:00

75 lines
1.8 KiB
C

/*
* Copyright 2018 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
*/
/*
* @ingroup sys_auto_init
* @{
*
* @file
* @brief Auto initialization for SHT1X temperature/humidity sensors
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/
#ifdef MODULE_SHT1X
#include "log.h"
#include "sht1x_params.h"
#include "sht1x.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Define the number of configured sensors
*/
#define SHT1X_NUM (sizeof(sht1x_params) / sizeof(sht1x_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
sht1x_dev_t sht1x_devs[SHT1X_NUM];
static void sht1x_error(unsigned int num, const char *reason)
{
LOG_ERROR("[auto_init] error initializing SHT10/SHT11/SHT15 sensor "
"#%u: %s\n", num, reason);
}
void auto_init_sht1x(void)
{
for (unsigned int i = 0; i < SHT1X_NUM; i++) {
DEBUG("[auto_init_sht1x] Initializing SHT1X sensor #%u\n", i);
switch (sht1x_init(&sht1x_devs[i], &sht1x_params[i])) {
case 0:
break;
case -EIO:
sht1x_error(i, "Failed to initialize GPIOs");
continue;
case -EINVAL:
sht1x_error(i, "Invalid configuration for VDD");
continue;
case -EPROTO:
sht1x_error(i, "Reset command not acknowledged");
continue;
default:
/* Should not happen, but better safe than sorry */
sht1x_error(i, "?");
continue;
}
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_SHT1X */