dt-bindings: sensor: lis2ds12: add macros for DT properties setting
Add macros for setting in a clear way lis2ds12 DT properties. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
a6cfa0bc15
commit
2fe89c1076
@ -18,6 +18,7 @@
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/sys/__assert.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/dt-bindings/sensor/lis2ds12.h>
|
||||
|
||||
#include "lis2ds12.h"
|
||||
|
||||
@ -40,8 +41,9 @@ static int lis2ds12_set_odr(const struct device *dev, uint8_t odr)
|
||||
* 12,5Hz <= odr <= 800Hz are available in LP and HR mode only
|
||||
* odr == 1Hz is available in LP mode only
|
||||
*/
|
||||
if ((odr >= 9 && cfg->pm != 3) || (odr < 9 && cfg->pm == 3) ||
|
||||
(odr == 1 && cfg->pm != 1)) {
|
||||
if ((odr >= LIS2DS12_DT_ODR_1600Hz && cfg->pm != LIS2DS12_DT_HIGH_FREQUENCY) ||
|
||||
(odr < LIS2DS12_DT_ODR_1600Hz && cfg->pm == LIS2DS12_DT_HIGH_FREQUENCY) ||
|
||||
(odr == LIS2DS12_DT_ODR_1Hz_LP && cfg->pm != LIS2DS12_DT_LOW_POWER)) {
|
||||
LOG_ERR("%s: bad odr and pm combination", dev->name);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@ -1,6 +1,20 @@
|
||||
# Copyright (c) 2021 STMicroelectronics
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
When setting the odr and power-mode properties in a .dts or .dtsi file you may include
|
||||
st_lis2ds12.h and use the macros defined there.
|
||||
|
||||
Example:
|
||||
#include <zephyr/dt-bindings/sensor/st_lis2ds12.h>
|
||||
|
||||
lis2ds12: lis2ds12@0 {
|
||||
...
|
||||
|
||||
power-mode = <LIS2DS12_DT_LOW_POWER>;
|
||||
odr = <LIS2DS12_DT_ODR_12Hz5>;
|
||||
};
|
||||
|
||||
include: sensor-device.yaml
|
||||
|
||||
properties:
|
||||
@ -19,23 +33,25 @@ properties:
|
||||
description: |
|
||||
Range in g. Default is power-up configuration.
|
||||
|
||||
enum:
|
||||
- 16 # 16g (0.488 mg/LSB)
|
||||
- 8 # 8g (0.244 mg/LSB)
|
||||
- 4 # 4g (0.122 mg/LSB)
|
||||
- 2 # 2g (0.061 mg/LSB)
|
||||
|
||||
enum: [16, 8, 4, 2]
|
||||
|
||||
power-mode:
|
||||
type: int
|
||||
default: 0
|
||||
description: |
|
||||
Specify the sensor power mode. Default is power-down mode
|
||||
|
||||
enum:
|
||||
- 0 # Power Down (PD)
|
||||
- 1 # Low Power (LP)
|
||||
- 2 # High Resolution (HR)
|
||||
- 3 # High Frequency (HF)
|
||||
- 0 # LIS2DS12_DT_POWER_DOWN
|
||||
- 1 # LIS2DS12_DT_LOW_POWER
|
||||
- 2 # LIS2DS12_DT_HIGH_RESOLUTION
|
||||
- 3 # LIS2DS12_DT_HIGH_FREQUENCY
|
||||
|
||||
enum: [0, 1, 2, 3]
|
||||
|
||||
odr:
|
||||
type: int
|
||||
@ -43,16 +59,18 @@ properties:
|
||||
description: |
|
||||
Specify the default output data rate expressed in samples per second (Hz).
|
||||
Default is power-down mode
|
||||
enum:
|
||||
- 0 # Power-Down
|
||||
- 1 # 1Hz (available in LP mode only)
|
||||
- 2 # 12.5Hz (available in LP and HR mode)
|
||||
- 3 # 25Hz (available in LP and HR mode)
|
||||
- 4 # 50Hz (available in LP and HR mode)
|
||||
- 5 # 100Hz (available in LP and HR mode)
|
||||
- 6 # 200Hz (available in LP and HR mode)
|
||||
- 7 # 400Hz (available in LP and HR mode)
|
||||
- 8 # 800Hz (available in LP and HR mode)
|
||||
- 9 # 1600Hz (available in HF mode only)
|
||||
- 10 # 3200Hz (available in HF mode only)
|
||||
- 11 # 6400Hz (available in HF mode only)
|
||||
|
||||
- 0 # LIS2DS12_DT_ODR_OFF
|
||||
- 1 # LIS2DS12_DT_ODR_1Hz_LP
|
||||
- 2 # LIS2DS12_DT_ODR_12Hz5
|
||||
- 3 # LIS2DS12_DT_ODR_25Hz
|
||||
- 4 # LIS2DS12_DT_ODR_50Hz
|
||||
- 5 # LIS2DS12_DT_ODR_100Hz
|
||||
- 6 # LIS2DS12_DT_ODR_200Hz
|
||||
- 7 # LIS2DS12_DT_ODR_400Hz
|
||||
- 8 # LIS2DS12_DT_ODR_800Hz
|
||||
- 9 # LIS2DS12_DT_ODR_1600Hz
|
||||
- 10 # LIS2DS12_DT_ODR_3200Hz_HF
|
||||
- 11 # LIS2DS12_DT_ODR_6400Hz_HF
|
||||
|
||||
enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
||||
|
||||
29
include/zephyr/dt-bindings/sensor/lis2ds12.h
Normal file
29
include/zephyr/dt-bindings/sensor/lis2ds12.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2023 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ST_LIS2DS12_H_
|
||||
#define ZEPHYR_INCLUDE_DT_BINDINGS_ST_LIS2DS12_H_
|
||||
|
||||
/* power-modes */
|
||||
#define LIS2DS12_DT_POWER_DOWN 0
|
||||
#define LIS2DS12_DT_LOW_POWER 1
|
||||
#define LIS2DS12_DT_HIGH_RESOLUTION 2
|
||||
#define LIS2DS12_DT_HIGH_FREQUENCY 3
|
||||
|
||||
/* Data rate */
|
||||
#define LIS2DS12_DT_ODR_OFF 0
|
||||
#define LIS2DS12_DT_ODR_1Hz_LP 1 /* available in LP mode only */
|
||||
#define LIS2DS12_DT_ODR_12Hz5 2 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_25Hz 3 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_50Hz 4 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_100Hz 5 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_200Hz 6 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_400Hz 7 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_800Hz 8 /* available in LP and HR mode */
|
||||
#define LIS2DS12_DT_ODR_1600Hz 9 /* available in HF mode only */
|
||||
#define LIS2DS12_DT_ODR_3200Hz_HF 10 /* available in HF mode only */
|
||||
#define LIS2DS12_DT_ODR_6400Hz_HF 11 /* available in HF mode only */
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ST_LIS2DS12_H_ */
|
||||
@ -11,6 +11,7 @@
|
||||
#include <zephyr/dt-bindings/sensor/lsm6dso16is.h>
|
||||
#include <zephyr/dt-bindings/sensor/lps22hh.h>
|
||||
#include <zephyr/dt-bindings/sensor/lps22df.h>
|
||||
#include <zephyr/dt-bindings/sensor/lis2ds12.h>
|
||||
|
||||
/****************************************
|
||||
* PLEASE KEEP REG ADDRESSES SEQUENTIAL *
|
||||
@ -289,6 +290,8 @@ test_i2c_lis2ds12: lis2ds12@2c {
|
||||
compatible = "st,lis2ds12";
|
||||
reg = <0x2c>;
|
||||
irq-gpios = <&test_gpio 0 0>;
|
||||
power-mode = <LIS2DS12_DT_LOW_POWER>;
|
||||
odr = <LIS2DS12_DT_ODR_12Hz5>;
|
||||
};
|
||||
|
||||
test_i2c_lis2dw12: lis2dw12@2d {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user