Button
Source code path: example/misc/button
Supported Platforms
sf32lb52-lcd_n16r8
sf32lb58-lcd_n16r64n4
Overview
The button library uses pin devices to detect various button actions. It uses one timer to handle debouncing, and another timer to detect long press actions.
It supports the following operations:
Press: Button is pressed
Release: Button is released
Long Press: Button is pressed and held for the time specified by
BUTTON_ADV_ACTION_CHECK_DELAY
Click: Button is pressed and released without triggering a long press action in between
Users can register handlers for each button to be notified when any action occurs. Button active state is configurable.
Example Usage
Compilation and Programming
Switch to the example project directory and run the scons command to execute compilation (board=board type):
scons --board=sf32lb52-lcd_n16r8 -j8
Run build_sf32lb52-lcd_n16r8_hcpu\uart_download.bat
, select the port as prompted for download:
build_sf32lb52-lcd_n16r8_hcpu\uart_download.bat
Uart Download
please input the serial port num:5
Confirm that rtconfig.h contains the following two macros. The maximum number of supported buttons and long press action detection threshold are configured by the following macros:
#define BUTTON_MAX_NUM 2
#define BUTTON_ADV_ACTION_CHECK_DELAY 3000
They can be configured under SiFli Middleware->Enable button library
. You can enter by typing menuconfig
in the compilation interface:
Exception Diagnosis
If button press does not produce expected print results, troubleshooting can be performed from the following aspects:
Whether hardware connections are normal
Whether pin configuration (especially pin mode configuration) is correct
Update History
Version |
Date |
Release Notes |
---|---|---|
0.0.1 |
10/2024 |
Initial version |
0.0.2 |
12/2024 |
2.0 |