Add configurable BMA456 tap detection profile in bosch456.h.
Centralize multitap tuning so sensitivity and timing can be adjusted without changing driver init logic. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
41a66d4417
commit
35b39fce46
@ -38,6 +38,7 @@ static volatile bool s_int_pending;
|
|||||||
static SemaphoreHandle_t s_accel_mutex;
|
static SemaphoreHandle_t s_accel_mutex;
|
||||||
static bma456_tap_handler_t s_tap_handler;
|
static bma456_tap_handler_t s_tap_handler;
|
||||||
static void *s_tap_handler_ctx;
|
static void *s_tap_handler_ctx;
|
||||||
|
static const bma456_tap_config_t s_tap_config = BMA456_TAP_CONFIG_DEFAULT;
|
||||||
|
|
||||||
static esp_err_t check_bma4(const char *api_name, int8_t rslt);
|
static esp_err_t check_bma4(const char *api_name, int8_t rslt);
|
||||||
|
|
||||||
@ -263,19 +264,48 @@ static esp_err_t configure_tap_interrupt(void) {
|
|||||||
if (check_bma4("bma456h_tap_get_parameter", ret) != ESP_OK) {
|
if (check_bma4("bma456h_tap_get_parameter", ret) != ESP_OK) {
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
tap_settings.tap_sens_thres = 0;
|
tap_settings.tap_sens_thres = s_tap_config.tap_sens_thres;
|
||||||
|
tap_settings.max_gest_dur = s_tap_config.max_gest_dur;
|
||||||
|
tap_settings.tap_shock_dur = s_tap_config.tap_shock_dur;
|
||||||
|
tap_settings.quite_time_after_gest = s_tap_config.quite_time_after_gest;
|
||||||
|
tap_settings.wait_for_timeout = s_tap_config.wait_for_timeout;
|
||||||
|
tap_settings.axis_sel = s_tap_config.axis_sel;
|
||||||
ret = bma456h_tap_set_parameter(&tap_settings, &s_bma456);
|
ret = bma456h_tap_set_parameter(&tap_settings, &s_bma456);
|
||||||
if (check_bma4("bma456h_tap_set_parameter", ret) != ESP_OK) {
|
if (check_bma4("bma456h_tap_set_parameter", ret) != ESP_OK) {
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bma456h_feature_enable(
|
uint16_t tap_features = 0;
|
||||||
(BMA456H_SINGLE_TAP_EN | BMA456H_DOUBLE_TAP_EN | BMA456H_TRIPLE_TAP_EN),
|
if (s_tap_config.enable_single) {
|
||||||
BMA4_ENABLE, &s_bma456);
|
tap_features |= BMA456H_SINGLE_TAP_EN;
|
||||||
|
}
|
||||||
|
if (s_tap_config.enable_double) {
|
||||||
|
tap_features |= BMA456H_DOUBLE_TAP_EN;
|
||||||
|
}
|
||||||
|
if (s_tap_config.enable_triple) {
|
||||||
|
tap_features |= BMA456H_TRIPLE_TAP_EN;
|
||||||
|
}
|
||||||
|
if (tap_features == 0) {
|
||||||
|
ESP_LOGW(TAG, "tap config: no tap kinds enabled");
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bma456h_feature_enable(tap_features, BMA4_ENABLE, &s_bma456);
|
||||||
if (check_bma4("bma456h_feature_enable", ret) != ESP_OK) {
|
if (check_bma4("bma456h_feature_enable", ret) != ESP_OK) {
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG,
|
||||||
|
"tap config sens=%u max_gest=%u shock=%u quiet=%u wait=%u axis=%u "
|
||||||
|
"(single=%d double=%d triple=%d)",
|
||||||
|
(unsigned)s_tap_config.tap_sens_thres,
|
||||||
|
(unsigned)s_tap_config.max_gest_dur,
|
||||||
|
(unsigned)s_tap_config.tap_shock_dur,
|
||||||
|
(unsigned)s_tap_config.quite_time_after_gest,
|
||||||
|
(unsigned)s_tap_config.wait_for_timeout,
|
||||||
|
(unsigned)s_tap_config.axis_sel, s_tap_config.enable_single,
|
||||||
|
s_tap_config.enable_double, s_tap_config.enable_triple);
|
||||||
|
|
||||||
ret = bma456h_map_interrupt(int_line, BMA456H_TAP_OUT_INT, BMA4_ENABLE,
|
ret = bma456h_map_interrupt(int_line, BMA456H_TAP_OUT_INT, BMA4_ENABLE,
|
||||||
&s_bma456);
|
&s_bma456);
|
||||||
if (check_bma4("bma456h_map_interrupt", ret) != ESP_OK) {
|
if (check_bma4("bma456h_map_interrupt", ret) != ESP_OK) {
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "driver/i2c_types.h"
|
#include "driver/i2c_types.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/** 7-bit I2C address (SDO low). */
|
/** 7-bit I2C address (SDO low). */
|
||||||
#define BMA456_I2C_ADDR 0x18
|
#define BMA456_I2C_ADDR 0x18
|
||||||
@ -20,6 +22,40 @@
|
|||||||
/** Software filter: log accel only when |axis - last| > deadzone (raw LSB). */
|
/** Software filter: log accel only when |axis - last| > deadzone (raw LSB). */
|
||||||
#define BMA456_DEFAULT_ACCEL_DEADZONE 100u
|
#define BMA456_DEFAULT_ACCEL_DEADZONE 100u
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BMA456H multitap tuning (see BST-BMA456-AN000).
|
||||||
|
*
|
||||||
|
* Time fields use register units: value × 5 ms (e.g. 100 → 500 ms).
|
||||||
|
* tap_sens_thres: 0 = most sensitive … 15 = least (~78 mg per LSB).
|
||||||
|
* axis_sel: 0 = X, 1 = Y, 2 = Z.
|
||||||
|
* wait_for_timeout: 0 = report immediately, 1 = wait max_gest_dur for classification.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint16_t tap_sens_thres;
|
||||||
|
uint16_t max_gest_dur;
|
||||||
|
uint16_t tap_shock_dur;
|
||||||
|
uint16_t quite_time_after_gest;
|
||||||
|
uint16_t wait_for_timeout;
|
||||||
|
uint16_t axis_sel;
|
||||||
|
bool enable_single;
|
||||||
|
bool enable_double;
|
||||||
|
bool enable_triple;
|
||||||
|
} bma456_tap_config_t;
|
||||||
|
|
||||||
|
/** Edit these values to tune tap detection, then rebuild. */
|
||||||
|
#define BMA456_TAP_CONFIG_DEFAULT \
|
||||||
|
{ \
|
||||||
|
.tap_sens_thres = 5, /* sensitive; 0=max, Bosch default=9 */ \
|
||||||
|
.max_gest_dur = 100, /* 500 ms window for double/triple */ \
|
||||||
|
.tap_shock_dur = 6, /* 30 ms debounce after each impulse */ \
|
||||||
|
.quite_time_after_gest = 60, /* 300 ms min gap between gestures */ \
|
||||||
|
.wait_for_timeout = 0, /* 0 = faster single-tap response */ \
|
||||||
|
.axis_sel = 2, /* Z axis */ \
|
||||||
|
.enable_single = true, \
|
||||||
|
.enable_double = true, \
|
||||||
|
.enable_triple = true, \
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Probe and configure the sensor on bus_handle (100 kHz device).
|
* Probe and configure the sensor on bus_handle (100 kHz device).
|
||||||
* On failure the device is removed and ESP_ERR_NOT_FOUND / ESP_FAIL is returned;
|
* On failure the device is removed and ESP_ERR_NOT_FOUND / ESP_FAIL is returned;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user