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:
+34
-4
@@ -38,6 +38,7 @@ static volatile bool s_int_pending;
|
||||
static SemaphoreHandle_t s_accel_mutex;
|
||||
static bma456_tap_handler_t s_tap_handler;
|
||||
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);
|
||||
|
||||
@@ -263,19 +264,48 @@ static esp_err_t configure_tap_interrupt(void) {
|
||||
if (check_bma4("bma456h_tap_get_parameter", ret) != ESP_OK) {
|
||||
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);
|
||||
if (check_bma4("bma456h_tap_set_parameter", ret) != ESP_OK) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ret = bma456h_feature_enable(
|
||||
(BMA456H_SINGLE_TAP_EN | BMA456H_DOUBLE_TAP_EN | BMA456H_TRIPLE_TAP_EN),
|
||||
BMA4_ENABLE, &s_bma456);
|
||||
uint16_t tap_features = 0;
|
||||
if (s_tap_config.enable_single) {
|
||||
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) {
|
||||
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,
|
||||
&s_bma456);
|
||||
if (check_bma4("bma456h_map_interrupt", ret) != ESP_OK) {
|
||||
|
||||
Reference in New Issue
Block a user