1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/lis2dh12: power mode -> resolution

This is easier to understand.
This commit is contained in:
Benjamin Valentin 2021-04-23 17:16:22 +02:00
parent 0ede891755
commit db0edd3ec1
3 changed files with 57 additions and 41 deletions

View File

@ -74,28 +74,28 @@ typedef enum {
*
*/
typedef enum {
LIS2DH12_RATE_1HZ = 0x1, /**< sample with 1Hz @ all power modes */
LIS2DH12_RATE_10HZ = 0x2, /**< sample with 10Hz @ all power modes */
LIS2DH12_RATE_25HZ = 0x3, /**< sample with 25Hz @ all power modes */
LIS2DH12_RATE_50HZ = 0x4, /**< sample with 50Hz @ all power modes */
LIS2DH12_RATE_100HZ = 0x5, /**< sample with 100Hz @ all power modes */
LIS2DH12_RATE_200HZ = 0x6, /**< sample with 200Hz @ all power modes */
LIS2DH12_RATE_400HZ = 0x7, /**< sample with 400Hz @ all power modes */
LIS2DH12_RATE_1620HZ = 0x8, /**< sample with 1620HZ @ Low Power*/
LIS2DH12_RATE_1HZ = 0x1, /**< sample with 1Hz @ all resolutions */
LIS2DH12_RATE_10HZ = 0x2, /**< sample with 10Hz @ all resolutions */
LIS2DH12_RATE_25HZ = 0x3, /**< sample with 25Hz @ all resolutions */
LIS2DH12_RATE_50HZ = 0x4, /**< sample with 50Hz @ all resolutions */
LIS2DH12_RATE_100HZ = 0x5, /**< sample with 100Hz @ all resolutions */
LIS2DH12_RATE_200HZ = 0x6, /**< sample with 200Hz @ all resolutions */
LIS2DH12_RATE_400HZ = 0x7, /**< sample with 400Hz @ all resolutions */
LIS2DH12_RATE_1620HZ = 0x8, /**< sample with 1620HZ @ 8-bit */
LIS2DH12_RATE_VERYHIGH = 0x9, /**< sample with 1344Hz @ High resolution or \
5376Hz @ Low Power*/
5376Hz @ 8-bit */
} lis2dh12_rate_t;
/**
* @brief Available power modes
* @brief Available resolutions
*
*/
typedef enum {
LIS2DH12_POWER_DOWN = 0, /**< power down the device */
LIS2DH12_POWER_LOW = 1, /**< low power mode */
LIS2DH12_POWER_NORMAL = 2, /**< normal mode */
LIS2DH12_POWER_HIGH = 3, /**< high resolution */
} lis2dh12_powermode_t;
LIS2DH12_POWER_LOW = 1, /**< 8-bit mode */
LIS2DH12_POWER_NORMAL = 2, /**< 10-bit mode */
LIS2DH12_POWER_HIGH = 3, /**< 12-bit mode */
} lis2dh12_resolution_t;
/**
* @brief LIS2DH12 configuration parameters
@ -114,7 +114,7 @@ typedef struct {
#endif
lis2dh12_scale_t scale; /**< sampling sensitivity used */
lis2dh12_rate_t rate; /**< sampling rate used */
lis2dh12_powermode_t powermode; /**< power mode used*/
lis2dh12_resolution_t resolution; /**< resolution used */
} lis2dh12_params_t;
/**
@ -387,27 +387,23 @@ int lis2dh12_set_powermode(const lis2dh12_t *dev, lis2dh12_powermode_t powermode
int lis2dh12_set_highpass(const lis2dh12_t *dev, const lis2dh12_highpass_t *config);
/**
* @brief Set the reference value to control the high-pass reference.
* In LIS2DH12_HP_MODE_REFERENCE the reference value is used to filter data
* on all axis. Subtracts reference value from acceleration.
* Note: LSB changes according to LIS2DH12_SCALE
* @brief Change device resolution
*
* @param[in] dev device descriptor
* @param[in] reference reference value [8 Bit]
* @param[in] resolution change to given resolution
*
* @return LIS2DH12_OK on success
*/
int lis2dh12_set_reference(const lis2dh12_t *dev, uint8_t reference);
int lis2dh12_set_resolution(const lis2dh12_t *dev, lis2dh12_resolution_t resolution);
/**
* @brief Read the reference value
* @brief Get device resolution
*
* @param[in] dev device descriptor
* @param[out] data reference value read from device
* @param[in] dev device descriptor
*
* @return LIS2DH12_OK on success
* @return Current device resolution settings
*/
int lis2dh12_read_reference(const lis2dh12_t *dev, uint8_t *data);
lis2dh12_resolution_t lis2dh12_get_resolution(const lis2dh12_t *dev);
/**
* @brief Set click configuration

View File

@ -67,8 +67,8 @@ extern "C" {
#ifndef LIS2DH12_PARAM_RATE
#define LIS2DH12_PARAM_RATE LIS2DH12_RATE_100HZ
#endif
#ifndef LIS2DH12_PARAM_POWERMODE
#define LIS2DH12_PARAM_POWERMODE LIS2DH12_POWER_NORMAL
#ifndef LIS2DH12_PARAM_RESOLUTION
#define LIS2DH12_PARAM_RESOLUTION LIS2DH12_POWER_NORMAL
#endif
#ifndef LIS2DH12_PARAMS
@ -79,14 +79,14 @@ extern "C" {
.int2_pin = LIS2DH12_PARAM_INT_PIN2, \
.scale = LIS2DH12_PARAM_SCALE, \
.rate = LIS2DH12_PARAM_RATE, \
.powermode = LIS2DH12_PARAM_POWERMODE, \
.resolution = LIS2DH12_PARAM_RESOLUTION, \
}
#else /* MODULE_LIS2DH12_INT */
#define LIS2DH12_PARAMS { \
LIS2DH12_PARAMS_BUSCFG, \
.scale = LIS2DH12_PARAM_SCALE, \
.rate = LIS2DH12_PARAM_RATE, \
.powermode = LIS2DH12_PARAM_POWERMODE, \
.resolution = LIS2DH12_PARAM_RESOLUTION, \
}
#endif /* MODULE_LIS2DH12_INT */
#endif /* LIS2DH12_PARAMS */

View File

@ -167,9 +167,6 @@ int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params)
_release(dev);
/* set powermode */
lis2dh12_set_powermode(dev, dev->p->powermode);
DEBUG("[lis2dh12] initialization successful\n");
return LIS2DH12_OK;
}
@ -460,27 +457,27 @@ int lis2dh12_read_click_src(const lis2dh12_t *dev, LIS2DH12_CLICK_SRC_t *data) {
return LIS2DH12_OK;
}
int lis2dh12_set_powermode(const lis2dh12_t *dev, lis2dh12_powermode_t powermode) {
int lis2dh12_set_resolution(const lis2dh12_t *dev, lis2dh12_resolution_t resolution)
{
assert(dev);
LIS2DH12_CTRL_REG1_t reg1 = {0};
LIS2DH12_CTRL_REG4_t reg4 = {0};
LIS2DH12_CTRL_REG1_t reg1;
LIS2DH12_CTRL_REG4_t reg4;
_acquire(dev);
reg1.reg = _read(dev, REG_CTRL_REG1);
reg4.reg = _read(dev, REG_CTRL_REG4);
/* set power mode */
if (powermode == LIS2DH12_POWER_LOW) {
if (resolution == LIS2DH12_POWER_LOW) {
reg1.bit.LPen = 1;
reg4.bit.HR = 0;
}
else if (powermode == LIS2DH12_POWER_HIGH) {
else if (resolution == LIS2DH12_POWER_HIGH) {
reg1.bit.LPen = 0;
reg4.bit.HR = 1;
}
else if (powermode == LIS2DH12_POWER_NORMAL) {
else if (resolution == LIS2DH12_POWER_NORMAL) {
reg1.bit.LPen = 0;
reg4.bit.HR = 0;
}
@ -495,6 +492,29 @@ int lis2dh12_set_powermode(const lis2dh12_t *dev, lis2dh12_powermode_t powermode
return LIS2DH12_OK;
}
lis2dh12_resolution_t lis2dh12_get_resolution(const lis2dh12_t *dev)
{
assert(dev);
LIS2DH12_CTRL_REG1_t reg1;
LIS2DH12_CTRL_REG4_t reg4;
_acquire(dev);
reg1.reg = _read(dev, REG_CTRL_REG1);
reg4.reg = _read(dev, REG_CTRL_REG4);
_release(dev);
if (!reg1.bit.ODR) {
return LIS2DH12_POWER_DOWN;
}
if (reg1.bit.LPen) {
return LIS2DH12_POWER_LOW;
}
if (reg4.bit.HR) {
return LIS2DH12_POWER_HIGH;
}
return LIS2DH12_POWER_NORMAL;
}
int lis2dh12_set_datarate(const lis2dh12_t *dev, lis2dh12_rate_t rate) {
assert(dev);
@ -539,7 +559,7 @@ int lis2dh12_poweron(const lis2dh12_t *dev)
/* set default param values */
lis2dh12_set_datarate(dev, dev->p->rate);
lis2dh12_set_powermode(dev, dev->p->powermode);
lis2dh12_set_resolution(dev, dev->p->resolution);
return LIS2DH12_OK;
}