Browse Source

Merge pull request #7245 from smlng/enh/saul/const

saul: use const for device parameter
master
Martine Lenders 6 years ago committed by GitHub
parent
commit
6d878b112a
  1. 4
      drivers/adcxx1c/adcxx1c_saul.c
  2. 5
      drivers/adxl345/adxl345_saul.c
  3. 12
      drivers/bmp180/bmp180_saul.c
  4. 18
      drivers/bmx280/bmx280_saul.c
  5. 12
      drivers/dht/dht_saul.c
  6. 12
      drivers/hdc1000/hdc1000_saul.c
  7. 8
      drivers/include/saul.h
  8. 5
      drivers/io1_xplained/io1_xplained_saul.c
  9. 5
      drivers/isl29020/isl29020_saul.c
  10. 5
      drivers/jc42/jc42_saul.c
  11. 5
      drivers/l3g4200d/l3g4200d_saul.c
  12. 5
      drivers/lis3dh/lis3dh_saul.c
  13. 5
      drivers/lps331ap/lps331ap_saul.c
  14. 9
      drivers/lsm303dlhc/lsm303dlhc_saul.c
  15. 9
      drivers/lsm6dsl/lsm6dsl_saul.c
  16. 4
      drivers/mag3110/mag3110_saul.c
  17. 4
      drivers/mma8x5x/mma8x5x_saul.c
  18. 2
      drivers/saul/adc_saul.c
  19. 8
      drivers/saul/gpio_saul.c
  20. 2
      drivers/saul/saul.c
  21. 2
      drivers/saul/saul_str.c
  22. 12
      drivers/si70xx/si70xx_saul.c
  23. 5
      drivers/tcs37727/tcs37727_saul.c
  24. 5
      drivers/tmp006/tmp006_saul.c
  25. 6
      drivers/tsl2561/tsl2561_saul.c
  26. 6
      drivers/veml6070/veml6070_saul.c

4
drivers/adcxx1c/adcxx1c_saul.c

@ -24,9 +24,9 @@
#include "saul.h"
#include "adcxx1c.h"
static int read_adc(void *dev, phydat_t *res)
static int read_adc(const void *dev, phydat_t *res)
{
adcxx1c_read_raw((adcxx1c_t *)dev, res->val);
adcxx1c_read_raw((const adcxx1c_t *)dev, res->val);
res->unit = UNIT_NONE;
res->scale = 0;

5
drivers/adxl345/adxl345_saul.c

@ -21,10 +21,9 @@
#include "saul.h"
#include "adxl345.h"
static int read_acc(void *dev, phydat_t *res)
static int read_acc(const void *dev, phydat_t *res)
{
adxl345_t *d = (adxl345_t *)dev;
adxl345_read(d, (adxl345_data_t *)res->val);
adxl345_read((const adxl345_t *)dev, (adxl345_data_t *)res->val);
res->unit = UNIT_G;
res->scale = -3;

12
drivers/bmp180/bmp180_saul.c

@ -25,21 +25,17 @@
#include "bmp180.h"
#include "xtimer.h"
static int read_temperature(void *dev, phydat_t *res)
static int read_temperature(const void *dev, phydat_t *res)
{
bmp180_t *d = (bmp180_t *)dev;
res->val[0] = bmp180_read_temperature(d);
res->val[0] = bmp180_read_temperature((const bmp180_t *)dev);
res->unit = UNIT_TEMP_C;
res->scale = -1;
return 1;
}
static int read_pressure(void *dev, phydat_t *res)
static int read_pressure(const void *dev, phydat_t *res)
{
bmp180_t *d = (bmp180_t *)dev;
res->val[0] = bmp180_read_pressure(d) / 100;
res->val[0] = bmp180_read_pressure((const bmp180_t *)dev) / 100;
res->unit = UNIT_PA;
res->scale = 2;
return 1;

18
drivers/bmx280/bmx280_saul.c

@ -24,22 +24,18 @@
#include "bmx280.h"
static int read_temperature(void *dev, phydat_t *res)
static int read_temperature(const void *dev, phydat_t *res)
{
bmx280_t *d = (bmx280_t *)dev;
res->val[0] = bmx280_read_temperature(d);
res->val[0] = bmx280_read_temperature((const bmx280_t *)dev);
res->unit = UNIT_TEMP_C;
res->scale = -2;
return 1;
}
static int read_pressure(void *dev, phydat_t *res)
static int read_pressure(const void *dev, phydat_t *res)
{
bmx280_t *d = (bmx280_t *)dev;
res->val[0] = bmx280_read_pressure(d) / 100;
res->val[0] = bmx280_read_pressure((const bmx280_t *)dev) / 100;
res->unit = UNIT_PA;
res->scale = 2;
@ -47,11 +43,9 @@ static int read_pressure(void *dev, phydat_t *res)
}
#ifdef MODULE_BME280
static int read_relative_humidity(void *dev, phydat_t *res)
static int read_relative_humidity(const void *dev, phydat_t *res)
{
bmx280_t *d = (bmx280_t *)dev;
res->val[0] = bme280_read_humidity(d);
res->val[0] = bme280_read_humidity((const bmx280_t *)dev);
res->unit = UNIT_PERCENT;
res->scale = -2;

12
drivers/dht/dht_saul.c

@ -37,18 +37,14 @@
static int16_t temp, hum;
static uint32_t last = 0;
static int check_and_read(void *dev, phydat_t *res, int16_t *val, uint8_t unit)
static int check_and_read(const void *dev, phydat_t *res, int16_t *val, uint8_t unit)
{
dht_t *d = (dht_t *)dev;
uint32_t now = xtimer_now_usec();
if ((now - last) > DHT_SAUL_HOLD_TIME) {
dht_read(d, &temp, &hum);
dht_read((const dht_t *)dev, &temp, &hum);
last = now;
}
else {
(void)d;
}
res->val[0] = *val;
memset(&res->val[1], 0, 2 * sizeof(int16_t));
@ -57,12 +53,12 @@ static int check_and_read(void *dev, phydat_t *res, int16_t *val, uint8_t unit)
return 1;
}
static int read_temp(void *dev, phydat_t *res)
static int read_temp(const void *dev, phydat_t *res)
{
return check_and_read(dev, res, &temp, UNIT_TEMP_C);
}
static int read_hum(void *dev, phydat_t *res)
static int read_hum(const void *dev, phydat_t *res)
{
return check_and_read(dev, res, &hum, UNIT_PERCENT);
}

12
drivers/hdc1000/hdc1000_saul.c

@ -23,11 +23,9 @@
#include "saul.h"
#include "hdc1000.h"
static int read_temp(void *dev, phydat_t *res)
static int read_temp(const void *dev, phydat_t *res)
{
hdc1000_t *d = (hdc1000_t *)dev;
if (hdc1000_read(d, &(res->val[0]), NULL) != HDC1000_OK) {
if (hdc1000_read((const hdc1000_t *)dev, &(res->val[0]), NULL) != HDC1000_OK) {
return -ECANCELED;
}
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
@ -37,11 +35,9 @@ static int read_temp(void *dev, phydat_t *res)
return 1;
}
static int read_hum(void *dev, phydat_t *res)
static int read_hum(const void *dev, phydat_t *res)
{
hdc1000_t *d = (hdc1000_t *)dev;
if (hdc1000_read(d, NULL, &(res->val[0])) != HDC1000_OK) {
if (hdc1000_read((const hdc1000_t *)dev, NULL, &(res->val[0])) != HDC1000_OK) {
return -ECANCELED;
}
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));

8
drivers/include/saul.h

@ -112,7 +112,7 @@ enum {
* @return -ENOTSUP if the device does not support this operation
* @return -ECANCELED on other errors
*/
typedef int(*saul_read_t)(void *dev, phydat_t *res);
typedef int(*saul_read_t)(const void *dev, phydat_t *res);
/**
* @brief Write a value (a set of values) to a device
@ -132,7 +132,7 @@ typedef int(*saul_read_t)(void *dev, phydat_t *res);
* @return -ENOTSUP if the device does not support this operation
* @return -ECANCELED on other errors
*/
typedef int(*saul_write_t)(void *dev, phydat_t *data);
typedef int(*saul_write_t)(const void *dev, phydat_t *data);
/**
* @brief Definition of the RIOT actuator/sensor interface
@ -146,7 +146,7 @@ typedef struct {
/**
* @brief Default not supported function
*/
int saul_notsup(void *dev, phydat_t *dat);
int saul_notsup(const void *dev, phydat_t *dat);
/**
* @brief Helper function converts a class ID to a string
@ -156,7 +156,7 @@ int saul_notsup(void *dev, phydat_t *dat);
* @return string representation of the device class
* @return NULL if class ID is not known
*/
const char *saul_class_to_str(uint8_t class_id);
const char *saul_class_to_str(const uint8_t class_id);
#ifdef __cplusplus
}

5
drivers/io1_xplained/io1_xplained_saul.c

@ -25,10 +25,9 @@
static float temperature;
static int read_temperature(void *dev, phydat_t *res)
static int read_temperature(const void *dev, phydat_t *res)
{
io1_xplained_t *d = (io1_xplained_t *)dev;
io1_xplained_read_temperature(d, &temperature);
io1_xplained_read_temperature((const io1_xplained_t *)dev, &temperature);
res->val[0] = (int)(temperature * 100.0);
res->unit = UNIT_TEMP_C;
res->scale = -2;

5
drivers/isl29020/isl29020_saul.c

@ -23,10 +23,9 @@
#include "saul.h"
#include "isl29020.h"
static int read(void *dev, phydat_t *res)
static int read(const void *dev, phydat_t *res)
{
isl29020_t *d = (isl29020_t *)dev;
res->val[0] = (int16_t)isl29020_read(d);
res->val[0] = (int16_t)isl29020_read((const isl29020_t *)dev);
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
res->unit = UNIT_CD;
res->scale = 0;

5
drivers/jc42/jc42_saul.c

@ -25,12 +25,11 @@
static int read_temperature(void *dev, phydat_t *res)
static int read_temperature(const void *dev, phydat_t *res)
{
int16_t temperature;
jc42_t *d = (jc42_t *)dev;
jc42_get_temperature(d, &temperature);
jc42_get_temperature((const jc42_t *)dev, &temperature);
res->val[0] = temperature;
res->unit = UNIT_TEMP_C;
res->scale = -2;

5
drivers/l3g4200d/l3g4200d_saul.c

@ -23,10 +23,9 @@
#include "saul.h"
#include "l3g4200d.h"
static int read(void *dev, phydat_t *res)
static int read(const void *dev, phydat_t *res)
{
l3g4200d_t *d = (l3g4200d_t *)dev;
l3g4200d_read(d, (l3g4200d_data_t *)res);
l3g4200d_read((const l3g4200d_t *)dev, (l3g4200d_data_t *)res);
res->unit = UNIT_DPS;
res->scale = 0;
return 3;

5
drivers/lis3dh/lis3dh_saul.c

@ -24,12 +24,11 @@
#include "saul.h"
#include "lis3dh.h"
static int read_acc(void *dev, phydat_t *res)
static int read_acc(const void *dev, phydat_t *res)
{
lis3dh_data_t xyz;
lis3dh_t *d = (lis3dh_t *)dev;
int err = lis3dh_read_xyz(d, &xyz);
int err = lis3dh_read_xyz((const lis3dh_t *)dev, &xyz);
if (err != 0) {
/* Something went wrong in the LIS3DH driver */
return -ECANCELED;

5
drivers/lps331ap/lps331ap_saul.c

@ -23,10 +23,9 @@
#include "saul.h"
#include "lps331ap.h"
static int read(void *dev, phydat_t *res)
static int read(const void *dev, phydat_t *res)
{
lps331ap_t *d = (lps331ap_t *)dev;
res->val[0] = (int16_t)lps331ap_read_pres(d);
res->val[0] = (int16_t)lps331ap_read_pres((const lps331ap_t *)dev);
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
res->unit = UNIT_BAR;
res->scale = -3;

9
drivers/lsm303dlhc/lsm303dlhc_saul.c

@ -23,9 +23,9 @@
#include "saul.h"
#include "lsm303dlhc.h"
static int read_acc(void *dev, phydat_t *res)
static int read_acc(const void *dev, phydat_t *res)
{
lsm303dlhc_t *d = (lsm303dlhc_t *)dev;
const lsm303dlhc_t *d = (const lsm303dlhc_t *)dev;
lsm303dlhc_read_acc(d, (lsm303dlhc_3d_data_t *)res);
/* normalize result */
@ -39,9 +39,10 @@ static int read_acc(void *dev, phydat_t *res)
return 3;
}
static int read_mag(void *dev, phydat_t *res)
static int read_mag(const void *dev, phydat_t *res)
{
lsm303dlhc_t *d = (lsm303dlhc_t *)dev;
const lsm303dlhc_t *d = (const lsm303dlhc_t *)dev;
lsm303dlhc_read_mag(d, (lsm303dlhc_3d_data_t *)res);
/* normalize results */

9
drivers/lsm6dsl/lsm6dsl_saul.c

@ -17,9 +17,9 @@
#include "lsm6dsl.h"
#include "saul.h"
static int read_acc(void *dev, phydat_t *res)
static int read_acc(const void *dev, phydat_t *res)
{
int ret = lsm6dsl_read_acc(dev, (lsm6dsl_3d_data_t *)res);
int ret = lsm6dsl_read_acc((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res);
if (ret < 0) {
return -ECANCELED;
}
@ -30,9 +30,9 @@ static int read_acc(void *dev, phydat_t *res)
return 3;
}
static int read_gyro(void *dev, phydat_t *res)
static int read_gyro(const void *dev, phydat_t *res)
{
int ret = lsm6dsl_read_gyro(dev, (lsm6dsl_3d_data_t *)res);
int ret = lsm6dsl_read_gyro((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res);
if (ret < 0) {
return -ECANCELED;
}
@ -49,7 +49,6 @@ const saul_driver_t lsm6dsl_saul_acc_driver = {
.type = SAUL_SENSE_ACCEL,
};
const saul_driver_t lsm6dsl_saul_gyro_driver = {
.read = read_gyro,
.write = saul_notsup,

4
drivers/mag3110/mag3110_saul.c

@ -24,9 +24,9 @@
#include "saul.h"
#include "mag3110.h"
static int read_mag(void *dev, phydat_t *res)
static int read_mag(const void *dev, phydat_t *res)
{
mag3110_read((mag3110_t *)dev, (mag3110_data_t *)res);
mag3110_read((const mag3110_t *)dev, (mag3110_data_t *)res);
res->unit = UNIT_GS;
res->scale = 2;

4
drivers/mma8x5x/mma8x5x_saul.c

@ -25,9 +25,9 @@
#include "saul.h"
#include "mma8x5x.h"
static int read_acc(void *dev, phydat_t *res)
static int read_acc(const void *dev, phydat_t *res)
{
mma8x5x_read((mma8x5x_t *)dev, (mma8x5x_data_t *)res);
mma8x5x_read((const mma8x5x_t *)dev, (mma8x5x_data_t *)res);
res->unit = UNIT_G;
res->scale = -3;

2
drivers/saul/adc_saul.c

@ -26,7 +26,7 @@
#include "periph/adc.h"
static int read_adc(void *dev, phydat_t *res)
static int read_adc(const void *dev, phydat_t *res)
{
const saul_adc_params_t *params = *((const saul_adc_params_t **)dev);
res->val[0] = adc_sample(params->line, params->res);

8
drivers/saul/gpio_saul.c

@ -25,9 +25,9 @@
#include "periph/gpio.h"
static int read(void *dev, phydat_t *res)
static int read(const void *dev, phydat_t *res)
{
gpio_t pin = *((gpio_t *)dev);
gpio_t pin = *((const gpio_t *)dev);
res->val[0] = (gpio_read(pin)) ? 1 : 0;
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
res->unit = UNIT_BOOL;
@ -35,9 +35,9 @@ static int read(void *dev, phydat_t *res)
return 1;
}
static int write(void *dev, phydat_t *state)
static int write(const void *dev, phydat_t *state)
{
gpio_t pin = *((gpio_t *)dev);
gpio_t pin = *((const gpio_t *)dev);
gpio_write(pin, state->val[0]);
return 1;
}

2
drivers/saul/saul.c

@ -22,7 +22,7 @@
#include "saul.h"
int saul_notsup(void *dev, phydat_t *dat)
int saul_notsup(const void *dev, phydat_t *dat)
{
(void)dev;
(void)dat;

2
drivers/saul/saul_str.c

@ -26,7 +26,7 @@
* This is surely not the most beautiful implementation of a stringification
* function, but works...
*/
const char *saul_class_to_str(uint8_t class_id)
const char *saul_class_to_str(const uint8_t class_id)
{
switch (class_id) {
case SAUL_CLASS_UNDEF: return "CLASS_UNDEF";

12
drivers/si70xx/si70xx_saul.c

@ -22,22 +22,18 @@
#include "si70xx.h"
static int read_temperature(void *dev, phydat_t *res)
static int read_temperature(const void *dev, phydat_t *res)
{
si70xx_t *d = (si70xx_t *)dev;
res->val[0] = (int32_t) si70xx_get_temperature(d);
res->val[0] = (int32_t) si70xx_get_temperature((const si70xx_t *)dev);
res->unit = UNIT_TEMP_C;
res->scale = -2;
return 1;
}
static int read_relative_humidity(void *dev, phydat_t *res)
static int read_relative_humidity(const void *dev, phydat_t *res)
{
si70xx_t *d = (si70xx_t *)dev;
res->val[0] = (int32_t) si70xx_get_relative_humidity(d);
res->val[0] = (int32_t) si70xx_get_relative_humidity((const si70xx_t *)dev);
res->unit = UNIT_PERCENT;
res->scale = -2;

5
drivers/tcs37727/tcs37727_saul.c

@ -23,12 +23,11 @@
#include "saul.h"
#include "tcs37727.h"
static int read(void *dev, phydat_t *res)
static int read(const void *dev, phydat_t *res)
{
tcs37727_t *d = (tcs37727_t *)dev;
tcs37727_data_t val;
tcs37727_read(d, &val);
tcs37727_read((const tcs37727_t *)dev, &val);
res->val[0] = (int16_t)val.red;
res->val[1] = (int16_t)val.green;

5
drivers/tmp006/tmp006_saul.c

@ -23,9 +23,10 @@
#include "saul.h"
#include "tmp006.h"
static int read_temp(void *dev, phydat_t *res)
static int read_temp(const void *dev, phydat_t *res)
{
if (tmp006_read_temperature((tmp006_t *)dev, &res->val[0], &res->val[1]) != TMP006_OK) {
if (tmp006_read_temperature((const tmp006_t *)dev, &res->val[0],
&res->val[1]) != TMP006_OK) {
return -ECANCELED;
}
res->val[2] = 0;

6
drivers/tsl2561/tsl2561_saul.c

@ -23,11 +23,9 @@
#include "tsl2561.h"
#include "xtimer.h"
static int read_illuminance(void *dev, phydat_t *res)
static int read_illuminance(const void *dev, phydat_t *res)
{
tsl2561_t *d = (tsl2561_t *)dev;
res->val[0] = tsl2561_read_illuminance(d);
res->val[0] = tsl2561_read_illuminance((const tsl2561_t *)dev);
res->unit = UNIT_LUX;
res->scale = 0;
return 1;

6
drivers/veml6070/veml6070_saul.c

@ -24,11 +24,9 @@
#include "veml6070.h"
#include "xtimer.h"
static int read_uv(void *dev, phydat_t *res)
static int read_uv(const void *dev, phydat_t *res)
{
veml6070_t *d = (veml6070_t *)dev;
res->val[0] = veml6070_read_uv(d);
res->val[0] = veml6070_read_uv((const veml6070_t *)dev);
res->unit = UNIT_NONE;
res->scale = -1;
return 1;

Loading…
Cancel
Save