Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 151 Ver.1.0.0
#define PA4_INPUT_ENABLE 1
#define PA3_INPUT_ENABLE 1
#define PA2_INPUT_ENABLE 1
#define PA1_INPUT_ENABLE 1
7.2 Keyscan, Keymap and Keycode
7.2.1 Keyscan
After configuration as shown in section 7.1, the function below is invoked in mainloop to
implement keyscan.
u32 kb_scan_key (int numlock_status, int read_key)
numlock_status: Generally set as 0 when invoked in mainloop. Set as
“KB_NUMLOCK_STATUS_POWERON” only for fast keyscan after wakeup from
deepsleep (refer to section 7.5, corresponding to
DEEPBACK_FAST_KEYSCAN_ENABLE).
read_key: Buffer processing for key values, generally not used and set as 1 (if it’s set
as 0, key values will be pushed into buffer and not reported to upper layer).
The return value is used to inform user whether matrix keyboard update is detected
by current scan: if yes, return 1; otherwise return 0.
The kb_scan_key function is invoked in mainloop. As introduced in section 3.2.4, each
main loop is an adv_interval or conn_interval. In advertising state (suppose adv_interval
is 30ms), key scan is processed once for each 30ms; in connection state (suppose
conn_interval is 10ms), key scan is processed once for each 10ms.
In theory, when button states in matrix are different during two adjacent key scans, it’s
considered as an update. In actual code, a debounce filtering processing is enabled: It
will be considered as a valid update, only when button states stay the same during two
adjacent key scans, but different with the latest stored matrix keyboard state. “1” will be
returned by the function to indicate valid update, matrix keyboard state will be indicated
by the structure “kb_event”, and current button state will be updated to the newest matrix
keyboard state. Corresponding code in keyboard.c is shown as below:
unsigned int key_debounce_filter( u32 mtrx_cur[], u32 filt_en );
The newest button state means press or release state set of all (30) buttons in the matrix.
When power on, initial matrix keyboard state shows all buttons are “released” by default,
and debounce filtering processing is enabled; as long as valid update occurs to the
button state, “1” will be returned, otherwise “0” will be returned. For example: press a
button, a valid update is returned; release a button, a valid update is returned; press
another button with a button held, a valid update is returned; press the third button with
two buttons held, a valid update is returned; release a button of the two pressed buttons,
a valid update is returned……
7.2.2 Keymap &kb_event
If a valid button state update is detected by invoking the “kb_scan_key”, user can obtain
current button state via a global structure variable “kb_event”.