1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/lm75: add SAUL integration

This commit is contained in:
Benjamin Valentin 2021-08-20 18:08:18 +02:00
parent be85777cd1
commit 42a5807845
3 changed files with 110 additions and 0 deletions

41
drivers/lm75/lm75_saul.c Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* 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 drivers_lm75
* @{
*
* @file
* @brief SAUL adaption for lm75 compatible device
*
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
*
* @}
*/
#include <string.h>
#include "saul.h"
#include "lm75.h"
static int read_temperature(const void *dev, phydat_t *res)
{
int temperature;
lm75_get_temperature((lm75_t *)dev, &temperature);
res->val[0] = temperature / 10; /* phydat_t is 16 bit */
res->unit = UNIT_TEMP_C;
res->scale = -2;
return 1;
}
const saul_driver_t lm75_temperature_saul_driver = {
.read = read_temperature,
.write = saul_notsup,
.type = SAUL_SENSE_TEMP
};

View File

@ -0,0 +1,65 @@
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* 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_saul
* @{
*
* @file
* @brief Auto initialization of lm75 compatible driver.
*
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
*
* @}
*/
#include "assert.h"
#include "log.h"
#include "saul_reg.h"
#include "lm75.h"
#include "lm75_params.h"
/**
* @brief Define the number of configured sensors
*/
#define LM75_NUMOF ARRAY_SIZE(lm75_params)
/**
* @brief Allocation of memory for device descriptors
*/
static lm75_t lm75_devs[LM75_NUMOF];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[LM75_NUMOF];
/**
* @brief Reference the driver structs.
*/
extern const saul_driver_t lm75_temperature_saul_driver;
void auto_init_lm75(void)
{
for (unsigned i = 0; i < LM75_NUMOF; i++) {
LOG_DEBUG("[auto_init_saul] initializing lm75 #%u\n", i);
if (lm75_init(&lm75_devs[i], &lm75_params[i]) < 0) {
LOG_ERROR("[auto_init_saul] error initializing lm75 #%u\n", i);
continue;
}
/* temperature */
saul_entries[i].dev = &lm75_devs[i];
saul_entries[i].name = "lm75";
saul_entries[i].driver = &lm75_temperature_saul_driver;
/* register to saul */
saul_reg_add(&(saul_entries[i]));
}
}

View File

@ -167,6 +167,10 @@ void saul_init_devs(void)
extern void auto_init_lis3mdl(void);
auto_init_lis3mdl();
}
if (IS_USED(MODULE_LM75)) {
extern void auto_init_lm75(void);
auto_init_lm75();
}
if (IS_USED(MODULE_LPSXXX)) {
extern void auto_init_lpsxxx(void);
auto_init_lpsxxx();