drivers/sensor: iis2dlpc: Move trigger pulse Kconfig property into DT
Move iis2dlpc trigger pulse configurations from Kconfigs to Device Tree. Moreover the dts properties have been renamed as 'tap', which sounds a better name to immediately catch the feature behind it. Since tap threshold cannot be zero, this value (which is the default in dts binding) is used to enable/disable the device feature per each axis. The event can be generated on INT1 only. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
6ceffe8a94
commit
e4f95863f9
5 changed files with 128 additions and 142 deletions
|
@ -52,93 +52,10 @@ config IIS2DLPC_THREAD_STACK_SIZE
|
|||
help
|
||||
Stack size of thread used by the driver to handle interrupts.
|
||||
|
||||
menuconfig IIS2DLPC_PULSE
|
||||
bool "Pulse detection"
|
||||
config IIS2DLPC_TAP
|
||||
bool "Tap and Tap-Tap detection"
|
||||
help
|
||||
Enable pulse (single/double tap) detection
|
||||
|
||||
if IIS2DLPC_PULSE
|
||||
|
||||
choice
|
||||
prompt "Pulse interrupt source"
|
||||
default IIS2DLPC_ONLY_SINGLE
|
||||
|
||||
config IIS2DLPC_ONLY_SINGLE
|
||||
bool "single"
|
||||
|
||||
config IIS2DLPC_SINGLE_DOUBLE
|
||||
bool "single/double"
|
||||
|
||||
endchoice
|
||||
|
||||
config IIS2DLPC_PULSE_THSX
|
||||
hex "Pulse X-axis threshold"
|
||||
range 0 0x1F
|
||||
default 0x0E
|
||||
help
|
||||
Threshold to start the pulse-event detection procedure on the X-axis.
|
||||
Threshold values for each axis are unsigned 5-bit corresponding
|
||||
to an 2g acceleration full-scale range.
|
||||
|
||||
config IIS2DLPC_PULSE_THSY
|
||||
hex "Pulse Y-axis threshold"
|
||||
range 0 0x1F
|
||||
default 0x0E
|
||||
help
|
||||
Threshold to start the pulse-event detection procedure on the Y-axis.
|
||||
Threshold values for each axis are unsigned 5-bit corresponding
|
||||
to an 2g acceleration full-scale range.
|
||||
|
||||
config IIS2DLPC_PULSE_THSZ
|
||||
hex "Pulse Z-axis threshold"
|
||||
range 0 0x1F
|
||||
default 0x0E
|
||||
help
|
||||
Threshold to start the pulse-event detection procedure on the Z-axis.
|
||||
Threshold values for each axis are unsigned 5-bit corresponding
|
||||
to an 2g acceleration full-scale range.
|
||||
|
||||
config IIS2DLPC_PULSE_X
|
||||
bool "Enable X axis for pulse"
|
||||
default y
|
||||
|
||||
config IIS2DLPC_PULSE_Y
|
||||
bool "Enable Y axis for pulse"
|
||||
default y
|
||||
|
||||
config IIS2DLPC_PULSE_Z
|
||||
bool "Enable Z axis for pulse"
|
||||
default y
|
||||
|
||||
config IIS2DLPC_PULSE_SHOCK
|
||||
hex "Shock value"
|
||||
range 0 0x03
|
||||
default 0x00
|
||||
help
|
||||
Maximum duration of over-threshold event: this register represents
|
||||
the maximum time of an over-threshold signal detection to be
|
||||
recognized as a tap event. Where 0 equals 4*1/ODR and 1LSB = 8*1/ODR.
|
||||
|
||||
config IIS2DLPC_PULSE_LTNCY
|
||||
hex "Latency value"
|
||||
range 0 0x0F
|
||||
default 0x05
|
||||
help
|
||||
When double-tap recognition is enabled, this register expresses
|
||||
the maximum time between two successive detected taps to
|
||||
determine a double-tap event. Where 0 equals 16*1/ODR and
|
||||
1LSB = 32*1/ODR.
|
||||
|
||||
config IIS2DLPC_PULSE_QUIET
|
||||
hex "Quiet value"
|
||||
range 0 0x03
|
||||
default 0x00
|
||||
help
|
||||
Expected quiet time after a tap detection: this register represents
|
||||
the time after the first detected tap in which there must not be
|
||||
any overthreshold event. Where 0 equals 2*1/ODR and 1LSB = 4*1/ODR.
|
||||
|
||||
endif # IIS2DLPC_PULSE
|
||||
Enable tap (single/double) detection
|
||||
|
||||
endif # IIS2DLPC_TRIGGER
|
||||
|
||||
|
|
|
@ -310,63 +310,76 @@ static int iis2dlpc_init(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
if (iis2dlpc_tap_mode_set(iis2dlpc->ctx, cfg->pulse_trigger) < 0) {
|
||||
LOG_ERR("Failed to select pulse trigger mode");
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
LOG_INF("TAP: tap mode is %d", cfg->tap_mode);
|
||||
if (iis2dlpc_tap_mode_set(iis2dlpc->ctx, cfg->tap_mode) < 0) {
|
||||
LOG_ERR("Failed to select tap trigger mode");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
LOG_INF("TAP: ths_x is %02x", cfg->tap_threshold[0]);
|
||||
if (iis2dlpc_tap_threshold_x_set(iis2dlpc->ctx,
|
||||
cfg->pulse_ths[0]) < 0) {
|
||||
cfg->tap_threshold[0]) < 0) {
|
||||
LOG_ERR("Failed to set tap X axis threshold");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
LOG_INF("TAP: ths_y is %02x", cfg->tap_threshold[1]);
|
||||
if (iis2dlpc_tap_threshold_y_set(iis2dlpc->ctx,
|
||||
cfg->pulse_ths[1]) < 0) {
|
||||
cfg->tap_threshold[1]) < 0) {
|
||||
LOG_ERR("Failed to set tap Y axis threshold");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
LOG_INF("TAP: ths_z is %02x", cfg->tap_threshold[2]);
|
||||
if (iis2dlpc_tap_threshold_z_set(iis2dlpc->ctx,
|
||||
cfg->pulse_ths[2]) < 0) {
|
||||
cfg->tap_threshold[2]) < 0) {
|
||||
LOG_ERR("Failed to set tap Z axis threshold");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (iis2dlpc_tap_detection_on_x_set(iis2dlpc->ctx,
|
||||
CONFIG_IIS2DLPC_PULSE_X) < 0) {
|
||||
if (cfg->tap_threshold[0] > 0) {
|
||||
LOG_INF("TAP: tap_x enabled");
|
||||
if (iis2dlpc_tap_detection_on_x_set(iis2dlpc->ctx, 1) < 0) {
|
||||
LOG_ERR("Failed to set tap detection on X axis");
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
|
||||
if (iis2dlpc_tap_detection_on_y_set(iis2dlpc->ctx,
|
||||
CONFIG_IIS2DLPC_PULSE_Y) < 0) {
|
||||
if (cfg->tap_threshold[1] > 0) {
|
||||
LOG_INF("TAP: tap_y enabled");
|
||||
if (iis2dlpc_tap_detection_on_y_set(iis2dlpc->ctx, 1) < 0) {
|
||||
LOG_ERR("Failed to set tap detection on Y axis");
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
|
||||
if (iis2dlpc_tap_detection_on_z_set(iis2dlpc->ctx,
|
||||
CONFIG_IIS2DLPC_PULSE_Z) < 0) {
|
||||
if (cfg->tap_threshold[2] > 0) {
|
||||
LOG_INF("TAP: tap_z enabled");
|
||||
if (iis2dlpc_tap_detection_on_z_set(iis2dlpc->ctx, 1) < 0) {
|
||||
LOG_ERR("Failed to set tap detection on Z axis");
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
|
||||
if (iis2dlpc_tap_shock_set(iis2dlpc->ctx, cfg->pulse_shock) < 0) {
|
||||
LOG_INF("TAP: shock is %02x", cfg->tap_shock);
|
||||
if (iis2dlpc_tap_shock_set(iis2dlpc->ctx, cfg->tap_shock) < 0) {
|
||||
LOG_ERR("Failed to set tap shock duration");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (iis2dlpc_tap_dur_set(iis2dlpc->ctx, cfg->pulse_ltncy) < 0) {
|
||||
LOG_INF("TAP: latency is %02x", cfg->tap_latency);
|
||||
if (iis2dlpc_tap_dur_set(iis2dlpc->ctx, cfg->tap_latency) < 0) {
|
||||
LOG_ERR("Failed to set tap latency");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (iis2dlpc_tap_quiet_set(iis2dlpc->ctx, cfg->pulse_quiet) < 0) {
|
||||
LOG_INF("TAP: quiet time is %02x", cfg->tap_quiet);
|
||||
if (iis2dlpc_tap_quiet_set(iis2dlpc->ctx, cfg->tap_quiet) < 0) {
|
||||
LOG_ERR("Failed to set tap quiet time");
|
||||
return -EIO;
|
||||
}
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER */
|
||||
|
||||
return 0;
|
||||
|
@ -380,21 +393,15 @@ const struct iis2dlpc_device_config iis2dlpc_cfg = {
|
|||
.int_gpio_port = DT_INST_GPIO_LABEL(0, drdy_gpios),
|
||||
.int_gpio_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
|
||||
.int_gpio_flags = DT_INST_GPIO_FLAGS(0, drdy_gpios),
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
#if defined(CONFIG_IIS2DLPC_ONLY_SINGLE)
|
||||
.pulse_trigger = IIS2DLPC_ONLY_SINGLE,
|
||||
#elif defined(CONFIG_IIS2DLPC_SINGLE_DOUBLE)
|
||||
.pulse_trigger = IIS2DLPC_BOTH_SINGLE_DOUBLE,
|
||||
#endif
|
||||
.pulse_ths[0] = CONFIG_IIS2DLPC_PULSE_THSX,
|
||||
.pulse_ths[1] = CONFIG_IIS2DLPC_PULSE_THSY,
|
||||
.pulse_ths[2] = CONFIG_IIS2DLPC_PULSE_THSZ,
|
||||
.pulse_shock = CONFIG_IIS2DLPC_PULSE_SHOCK,
|
||||
.pulse_ltncy = CONFIG_IIS2DLPC_PULSE_LTNCY,
|
||||
.pulse_quiet = CONFIG_IIS2DLPC_PULSE_QUIET,
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
.drdy_int = DT_INST_PROP(0, drdy_int),
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
.tap_mode = DT_INST_PROP(0, tap_mode),
|
||||
.tap_threshold = DT_INST_PROP(0, tap_threshold),
|
||||
.tap_shock = DT_INST_PROP(0, tap_shock),
|
||||
.tap_latency = DT_INST_PROP(0, tap_latency),
|
||||
.tap_quiet = DT_INST_PROP(0, tap_quiet),
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER */
|
||||
};
|
||||
|
||||
|
|
|
@ -63,13 +63,13 @@ struct iis2dlpc_device_config {
|
|||
uint8_t int_gpio_pin;
|
||||
uint8_t int_gpio_flags;
|
||||
uint8_t drdy_int;
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
uint8_t pulse_trigger;
|
||||
uint8_t pulse_ths[3];
|
||||
uint8_t pulse_shock;
|
||||
uint8_t pulse_ltncy;
|
||||
uint8_t pulse_quiet;
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
uint8_t tap_mode;
|
||||
uint8_t tap_threshold[3];
|
||||
uint8_t tap_shock;
|
||||
uint8_t tap_latency;
|
||||
uint8_t tap_quiet;
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER */
|
||||
};
|
||||
|
||||
|
@ -88,10 +88,10 @@ struct iis2dlpc_data {
|
|||
uint8_t gpio_pin;
|
||||
struct gpio_callback gpio_cb;
|
||||
sensor_trigger_handler_t drdy_handler;
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
sensor_trigger_handler_t tap_handler;
|
||||
sensor_trigger_handler_t double_tap_handler;
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
#if defined(CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD)
|
||||
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS2DLPC_THREAD_STACK_SIZE);
|
||||
struct k_thread thread;
|
||||
|
|
|
@ -49,7 +49,7 @@ static int iis2dlpc_enable_int(const struct device *dev,
|
|||
&int_route.ctrl5_int2_pad_ctrl);
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
case SENSOR_TRIG_TAP:
|
||||
/* set interrupt for pin INT1 */
|
||||
iis2dlpc_pin_int1_route_get(iis2dlpc->ctx,
|
||||
|
@ -66,7 +66,7 @@ static int iis2dlpc_enable_int(const struct device *dev,
|
|||
|
||||
return iis2dlpc_pin_int1_route_set(iis2dlpc->ctx,
|
||||
&int_route.ctrl4_int1_pad_ctrl);
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
default:
|
||||
LOG_ERR("Unsupported trigger interrupt route %d", type);
|
||||
return -ENOTSUP;
|
||||
|
@ -92,14 +92,14 @@ int iis2dlpc_trigger_set(const struct device *dev,
|
|||
iis2dlpc_acceleration_raw_get(iis2dlpc->ctx, raw);
|
||||
}
|
||||
return iis2dlpc_enable_int(dev, SENSOR_TRIG_DATA_READY, state);
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
case SENSOR_TRIG_TAP:
|
||||
iis2dlpc->tap_handler = handler;
|
||||
return iis2dlpc_enable_int(dev, SENSOR_TRIG_TAP, state);
|
||||
case SENSOR_TRIG_DOUBLE_TAP:
|
||||
iis2dlpc->double_tap_handler = handler;
|
||||
return iis2dlpc_enable_int(dev, SENSOR_TRIG_DOUBLE_TAP, state);
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
default:
|
||||
LOG_ERR("Unsupported sensor trigger");
|
||||
return -ENOTSUP;
|
||||
|
@ -122,19 +122,19 @@ static int iis2dlpc_handle_drdy_int(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
static int iis2dlpc_handle_single_tap_int(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *data = dev->data;
|
||||
sensor_trigger_handler_t handler = data->tap_handler;
|
||||
|
||||
struct sensor_trigger pulse_trig = {
|
||||
struct sensor_trigger tap_trig = {
|
||||
.type = SENSOR_TRIG_TAP,
|
||||
.chan = SENSOR_CHAN_ALL,
|
||||
};
|
||||
|
||||
if (handler) {
|
||||
handler(dev, &pulse_trig);
|
||||
handler(dev, &tap_trig);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -145,18 +145,18 @@ static int iis2dlpc_handle_double_tap_int(const struct device *dev)
|
|||
struct iis2dlpc_data *data = dev->data;
|
||||
sensor_trigger_handler_t handler = data->double_tap_handler;
|
||||
|
||||
struct sensor_trigger pulse_trig = {
|
||||
struct sensor_trigger tap_trig = {
|
||||
.type = SENSOR_TRIG_DOUBLE_TAP,
|
||||
.chan = SENSOR_CHAN_ALL,
|
||||
};
|
||||
|
||||
if (handler) {
|
||||
handler(dev, &pulse_trig);
|
||||
handler(dev, &tap_trig);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
|
||||
/**
|
||||
* iis2dlpc_handle_interrupt - handle the drdy event
|
||||
|
@ -173,14 +173,14 @@ static void iis2dlpc_handle_interrupt(const struct device *dev)
|
|||
if (sources.status_dup.drdy) {
|
||||
iis2dlpc_handle_drdy_int(dev);
|
||||
}
|
||||
#ifdef CONFIG_IIS2DLPC_PULSE
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
if (sources.status_dup.single_tap) {
|
||||
iis2dlpc_handle_single_tap_int(dev);
|
||||
}
|
||||
if (sources.status_dup.double_tap) {
|
||||
iis2dlpc_handle_double_tap_int(dev);
|
||||
}
|
||||
#endif /* CONFIG_IIS2DLPC_PULSE */
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
|
||||
gpio_pin_interrupt_configure(iis2dlpc->gpio, cfg->int_gpio_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
|
|
|
@ -47,3 +47,65 @@ properties:
|
|||
- 2 # Low Power M3
|
||||
- 3 # Low Power M4
|
||||
- 4 # High Performance
|
||||
|
||||
# tap and tap-tap configuration section
|
||||
# All default values are selected to match the power-up values.
|
||||
# tap and tap-tap events can be generated on INT1 only.
|
||||
|
||||
tap-mode:
|
||||
type: int
|
||||
required: false
|
||||
default: 0
|
||||
description: Tap mode. Default is power-up configuration.
|
||||
enum:
|
||||
- 0 # Only Single Tap
|
||||
- 1 # Single and Double Tap
|
||||
|
||||
tap-threshold:
|
||||
type: array
|
||||
required: false
|
||||
default: [0, 0, 0]
|
||||
description: Tap X/Y/Z axes threshold. Default is power-up configuration.
|
||||
(X/Y/Z values range from 0x00 to 0x1F)
|
||||
|
||||
Thresholds to start the tap-event detection procedure on the X/Y/Z axes.
|
||||
Threshold values for each axis are unsigned 5-bit corresponding
|
||||
to a 2g acceleration full-scale range. A threshold value equal to zero
|
||||
corresponds to disable the tap detection on that axis.
|
||||
|
||||
For example, if you want to set the threshold for X to 12, for Z to 14
|
||||
and want to disable tap detection on Y, you should specify in Device Tree
|
||||
|
||||
tap-threshold = <12>, <0>, <14>
|
||||
|
||||
which is equivalent to X = 12 * 2g/32 = 750mg and Z = 14 * 2g/32 = 875mg.
|
||||
|
||||
tap-shock:
|
||||
type: int
|
||||
required: false
|
||||
default: 0x0
|
||||
description: Tap shock value. Default is power-up configuration.
|
||||
(values range from 0x0 to 0x3)
|
||||
This register represents the maximum time of an over-threshold signal
|
||||
detection to be recognized as a tap event. Where 0 equals 4*1/ODR and
|
||||
1LSB = 8*1/ODR.
|
||||
|
||||
tap-latency:
|
||||
type: int
|
||||
required: false
|
||||
default: 0x0
|
||||
description: Tap latency. Default is power-up configuration.
|
||||
(values range from 0x0 to 0xF)
|
||||
When double-tap recognition is enabled, this register expresses the
|
||||
maximum time between two successive detected taps to determine a
|
||||
double-tap event. Where 0 equals 16*1/ODR and 1LSB = 32*1/ODR.
|
||||
|
||||
tap-quiet:
|
||||
type: int
|
||||
required: false
|
||||
default: 0x0
|
||||
description: Expected quiet time after a tap detection. Default is power-up configuration.
|
||||
(values range from 0x0 to 0x3)
|
||||
This register represents the time after the first detected tap in which
|
||||
there must not be any overthreshold event. Where 0 equals 2*1/ODR
|
||||
and 1LSB = 4*1/ODR.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue