1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

drivers, lsm6dsl: add SAUL for temperature

This commit is contained in:
smlng 2017-07-02 16:19:52 +02:00
parent 2b9eddfbeb
commit 6d25209967
2 changed files with 31 additions and 9 deletions

View File

@ -49,6 +49,17 @@ static int read_gyro(const void *dev, phydat_t *res)
return 3;
}
static int read_temp(const void *dev, phydat_t *res)
{
if (lsm6dsl_read_temp((const lsm6dsl_t *)dev, (int16_t *)&res[0]) < 0) {
return -ECANCELED;
}
res->scale = -2;
res->unit = UNIT_TEMP_C;
return 1;
}
const saul_driver_t lsm6dsl_saul_acc_driver = {
.read = read_acc,
.write = saul_notsup,
@ -60,3 +71,9 @@ const saul_driver_t lsm6dsl_saul_gyro_driver = {
.write = saul_notsup,
.type = SAUL_SENSE_GYRO,
};
const saul_driver_t lsm6dsl_saul_temp_driver = {
.read = read_temp,
.write = saul_notsup,
.type = SAUL_SENSE_TEMP,
};

View File

@ -39,7 +39,7 @@ static lsm6dsl_t lsm6dsl_devs[LSM6DSL_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[LSM6DSL_NUM * 2];
static saul_reg_t saul_entries[LSM6DSL_NUM * 3];
/**
* @brief Reference the driver structs
@ -47,6 +47,7 @@ static saul_reg_t saul_entries[LSM6DSL_NUM * 2];
*/
extern saul_driver_t lsm6dsl_saul_acc_driver;
extern saul_driver_t lsm6dsl_saul_gyro_driver;
extern saul_driver_t lsm6dsl_saul_temp_driver;
/** @} */
@ -61,14 +62,18 @@ void auto_init_lsm6dsl(void)
continue;
}
saul_entries[(i * 2)].dev = &(lsm6dsl_devs[i]);
saul_entries[(i * 2)].name = lsm6dsl_saul_info[i].name;
saul_entries[(i * 2)].driver = &lsm6dsl_saul_acc_driver;
saul_reg_add(&(saul_entries[(i * 2)]));
saul_entries[(i * 2) + 1].dev = &(lsm6dsl_devs[i]);
saul_entries[(i * 2) + 1].name = lsm6dsl_saul_info[i].name;
saul_entries[(i * 2) + 1].driver = &lsm6dsl_saul_gyro_driver;
saul_reg_add(&(saul_entries[(i * 2) + 1]));
saul_entries[(i * 3)].dev = &(lsm6dsl_devs[i]);
saul_entries[(i * 3)].name = lsm6dsl_saul_info[i].name;
saul_entries[(i * 3)].driver = &lsm6dsl_saul_acc_driver;
saul_reg_add(&(saul_entries[(i * 3)]));
saul_entries[(i * 3) + 1].dev = &(lsm6dsl_devs[i]);
saul_entries[(i * 3) + 1].name = lsm6dsl_saul_info[i].name;
saul_entries[(i * 3) + 1].driver = &lsm6dsl_saul_gyro_driver;
saul_reg_add(&(saul_entries[(i * 3) + 1]));
saul_entries[(i * 3) + 2].dev = &(lsm6dsl_devs[i]);
saul_entries[(i * 3) + 2].name = lsm6dsl_saul_info[i].name;
saul_entries[(i * 3) + 2].driver = &lsm6dsl_saul_temp_driver;
saul_reg_add(&(saul_entries[(i * 3) + 2]));
}
}