1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/ltc4150/ltc4150_saul.c
Marian Buschsieweke 16f859dafd
drivers/saul: use const qualifier for data to write
This makes life easier when calling e.g. `saul_reg_write()` with data
stored in flash.

As now the signatures for reading and writing differ (in that `const`
qualifier only), `saul_notsup()` is split into `saul_write_notsup()`
and `saul_read_notsup()`. However, one is implemented as a symbol alias
of the other, so that ROM consumption remains unchanged.
2022-05-23 08:35:27 +02:00

68 lines
1.5 KiB
C

/*
* Copyright 2019 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 drivers_ltc4150
* @{
*
* @file
* @brief SAUL adaption for LTC4150 devices
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "phydat.h"
#include "saul.h"
#include "ltc4150.h"
static int read_charge(const void *_dev, phydat_t *res)
{
ltc4150_dev_t *dev = (ltc4150_dev_t *)_dev;
int32_t temp[3];
if (ltc4150_charge(dev, (uint32_t *)&temp[1], (uint32_t *)&temp[2]) == 0) {
res->scale = -3;
res->unit = UNIT_COULOMB;
temp[0] = temp[2] - temp[1];
int dim = (gpio_is_valid(dev->params.polarity)) ? 3 : 1;
phydat_fit(res, temp, (unsigned)dim);
return dim;
}
return -ECANCELED;
}
static int read_current(const void *dev, phydat_t *res)
{
if (ltc4150_avg_current((ltc4150_dev_t *)dev, res->val) == 0) {
res->unit = UNIT_A;
res->scale = -4;
return 1;
}
return -ECANCELED;
}
const saul_driver_t ltc4150_saul_charge_driver = {
.read = read_charge,
.write = saul_write_notsup,
.type = SAUL_SENSE_CHARGE
};
const saul_driver_t ltc4150_saul_current_driver = {
.read = read_current,
.write = saul_write_notsup,
.type = SAUL_SENSE_CURRENT
};