fix(bsp): set button press timing explicitly (180 ms / 500 ms)
- bsp_pins.h gains BSP_BTN_SHORT_PRESS_MS (180) and BSP_BTN_LONG_PRESS_MS (500);
bsp_button.c passes both to button_config_t instead of { 0 }, so the press
timing no longer depends on the button component's Kconfig defaults.
- User-visible change: LONG now triggers at 500 ms instead of 1500 ms, which is
what the demo's OK-long-press-returns interaction uses. The component's
BUTTON_LONG_PRESS_TIME_MS Kconfig lower bound is also 500 ms, so a shorter long
press can only be passed in code.
- The init log reports both thresholds, and tests/test_bsp_button.c asserts the
values handed to iot_button_create().
- docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.{md,zh_CN.md} document the
explicit timings and why they are pinned.
This commit is contained in:
1 parent
1051209d80
commit
32de0ce795
5 files changed
+19
-4
No files matched your search
@@ -54,6 +54,13 @@
|
||||
#define BSP_BTN_ADC_CHANNEL ADC_CHANNEL_0 // GPIO0
|
||||
#define BSP_BTN_COUNT 3
|
||||
|
||||
// 按键判定时序(ms):由 BSP 显式下发给 button 组件,不依赖它的 Kconfig 默认值。
|
||||
// 短按判定窗口 180ms 与组件默认一致,写在这里是为了和应用手感放在一起调;
|
||||
// 长按组件默认 1500ms,要按住 1.5s 才触发,在这台三键小设备上明显偏迟钝,收敛到 500ms。
|
||||
// (组件对 BUTTON_LONG_PRESS_TIME_MS 的 Kconfig 下限同样是 500ms,想再短只能在代码里下发。)
|
||||
#define BSP_BTN_SHORT_PRESS_MS 180 // 短按(单击)判定窗口
|
||||
#define BSP_BTN_LONG_PRESS_MS 500 // 长按触发时间
|
||||
|
||||
// 每键的电压窗口 {min_mV, max_mV};边界取相邻档中点。
|
||||
// 确定键上界留宽到 1900,是为了和松开态的 3300mV 拉开距离。
|
||||
#define BSP_BTN_MV_TABLE { {0, 150}, {150, 447}, {447, 1900} }
|
||||
|
||||
@@ -176,7 +176,11 @@ esp_err_t bsp_button_init(bsp_btn_cb_t cb, void *user) {
|
||||
.base = { .get_key_level = button_level, .del = button_driver_delete },
|
||||
.index = (unsigned)i,
|
||||
};
|
||||
const button_config_t bc = { 0 };
|
||||
// 判定门限由 BSP 显式下发(见 bsp_pins.h):组件 Kconfig 默认的长按 1500ms 偏迟钝。
|
||||
const button_config_t bc = {
|
||||
.short_press_time = BSP_BTN_SHORT_PRESS_MS,
|
||||
.long_press_time = BSP_BTN_LONG_PRESS_MS,
|
||||
};
|
||||
esp_err_t e = iot_button_create(&bc, &s_drivers[i].base, &s_btn[i]);
|
||||
if (e != ESP_OK || !s_btn[i]) {
|
||||
ESP_LOGE(TAG, "按键 %d 创建失败 (%s) —— 检查 GPIO%d 的 ADC 配置与分压电阻",
|
||||
@@ -196,7 +200,8 @@ esp_err_t bsp_button_init(bsp_btn_cb_t cb, void *user) {
|
||||
|
||||
s_sample_valid = false;
|
||||
s_ready = true;
|
||||
ESP_LOGI(TAG, "按键就绪:ADC1_CH%d 三键分压", BSP_BTN_ADC_CHANNEL);
|
||||
ESP_LOGI(TAG, "按键就绪:ADC1_CH%d 三键分压,短按 %dms 长按 %dms",
|
||||
BSP_BTN_ADC_CHANNEL, BSP_BTN_SHORT_PRESS_MS, BSP_BTN_LONG_PRESS_MS);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ GPIO0 has an external 10 kΩ pull-up to 3.3 V. UP, DOWN, and OK connect it to gr
|
||||
| OK | about 595 mV | `[447, 1900)` mV |
|
||||
| Released | about 3300 mV | outside all windows |
|
||||
|
||||
Do not replace the external resistor with the inaccurate internal pull-up. The BSP owns one ADC1 oneshot unit and calibration handle, shared by its static drivers through the public `iot_button` driver interface and by voltage reads. Attenuation is `ADC_ATTEN_DB_12`; one averaged sample is reused across the three keys in each polling cycle. Half-open windows prevent overlapping keys at a boundary. Calibration failure aborts initialization and rolls back; read/conversion failures are inactive readings, never a zero-voltage UP press. The BSP avoids the dependency's ADC index registry so partial allocation failure cannot strand an occupied index on retry. Callbacks originate in the button component's shared `esp_timer` task and must only enqueue work or perform similarly bounded operations.
|
||||
Do not replace the external resistor with the inaccurate internal pull-up. The BSP owns one ADC1 oneshot unit and calibration handle, shared by its static drivers through the public `iot_button` driver interface and by voltage reads. Attenuation is `ADC_ATTEN_DB_12`; one averaged sample is reused across the three keys in each polling cycle. Half-open windows prevent overlapping keys at a boundary. Calibration failure aborts initialization and rolls back; read/conversion failures are inactive readings, never a zero-voltage UP press. The BSP avoids the dependency's ADC index registry so partial allocation failure cannot strand an occupied index on retry. The BSP also passes the press timing explicitly (`BSP_BTN_SHORT_PRESS_MS` = 180 ms, `BSP_BTN_LONG_PRESS_MS` = 500 ms, in `bsp_pins.h`) instead of relying on the component's Kconfig defaults of 180 / 1500 ms: holding a key for 1.5 s before a long press registers is slow on this three-key device. The component's `BUTTON_LONG_PRESS_TIME_MS` Kconfig lower bound is also 500 ms, so a shorter long press can only be passed in code. Callbacks originate in the button component's shared `esp_timer` task and must only enqueue work or perform similarly bounded operations.
|
||||
|
||||
Calibrate thresholds using multiple boards, charge levels, and reasonable temperatures; leave margin between measured distributions rather than relying only on divider theory.
|
||||
|
||||
|
||||
Loaded 3 of 5 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user