Skip to content

Commit db65120

Browse files
Merge pull request #7509 from PeterKietzmann/pr_lps331ap_saul_temp
drivers/lps331ap: add saul support for temperature sensor
2 parents d54c849 + e529571 commit db65120

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

drivers/lps331ap/lps331ap_saul.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,31 @@
2323
#include "saul.h"
2424
#include "lps331ap.h"
2525

26-
static int read(const void *dev, phydat_t *res)
26+
static int read_pres(const void *dev, phydat_t *res)
2727
{
2828
res->val[0] = (int16_t)lps331ap_read_pres((const lps331ap_t *)dev);
29-
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
3029
res->unit = UNIT_BAR;
3130
res->scale = -3;
3231
return 1;
3332
}
3433

35-
const saul_driver_t lps331ap_saul_driver = {
36-
.read = read,
34+
static int read_temp(const void *dev, phydat_t *res)
35+
{
36+
res->val[0] = (int16_t)(lps331ap_read_temp((const lps331ap_t *)dev) / 10);
37+
res->unit = UNIT_TEMP_C;
38+
/* above division by ten leads to °C * 10^-2*/
39+
res->scale = -2;
40+
return 1;
41+
}
42+
43+
const saul_driver_t lps331ap_saul_pres_driver = {
44+
.read = read_pres,
3745
.write = saul_notsup,
3846
.type = SAUL_SENSE_PRESS,
3947
};
48+
49+
const saul_driver_t lps331ap_saul_temp_driver = {
50+
.read = read_temp,
51+
.write = saul_notsup,
52+
.type = SAUL_SENSE_TEMP,
53+
};

sys/auto_init/saul/auto_init_lps331ap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ static lps331ap_t lps331ap_devs[LPS331AP_NUM];
3939
/**
4040
* @brief Memory for the SAUL registry entries
4141
*/
42-
static saul_reg_t saul_entries[LPS331AP_NUM];
42+
static saul_reg_t saul_entries[LPS331AP_NUM * 2];
4343

4444
/**
4545
* @brief Reference the driver struct
4646
*/
47-
extern saul_driver_t lps331ap_saul_driver;
47+
extern saul_driver_t lps331ap_saul_pres_driver;
48+
extern saul_driver_t lps331ap_saul_temp_driver;
4849

4950

5051
void auto_init_lps331ap(void)
@@ -62,8 +63,12 @@ void auto_init_lps331ap(void)
6263

6364
saul_entries[i].dev = &(lps331ap_devs[i]);
6465
saul_entries[i].name = lps331ap_saul_info[i].name;
65-
saul_entries[i].driver = &lps331ap_saul_driver;
66+
saul_entries[i].driver = &lps331ap_saul_pres_driver;
6667
saul_reg_add(&(saul_entries[i]));
68+
saul_entries[(i * 2) + 1].dev = &(lps331ap_devs[i]);
69+
saul_entries[(i * 2) + 1].name = lps331ap_saul_info[i].name;
70+
saul_entries[(i * 2) + 1].driver = &lps331ap_saul_temp_driver;
71+
saul_reg_add(&(saul_entries[(i * 2) + 1]));
6772
}
6873
}
6974

0 commit comments

Comments
 (0)