-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters