Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
157
Ver.1.0.0
The following methods are used to optimize code execution time for row-by-row
scan.
When a row outputs drive level, it
’s not needed to read level of all columns
(CoL0~CoL5). Since the scan_pin_need marks valid column number, user can read
the marked columns only.
After a row outputs drive level, a 20us or so delay is needed to read stabilized level
of scan pins, and a buffer processing is used to utilize the waiting duration.
The
array variable “u32 pressed_matrix[5]” (up to 32 columns are supported) is used
to store final matrix keyboard state: pressed_matrix[0] bit0~bit5 mark button state on
CoL0~CoL5 crossed with Row0……pressed_matrix[3] bit0~bit5 mark button state on
CoL0~CoL5 crossed with Row3.
3) Debounce filtering for pressed_matrix[]
unsigned int
key_debounce_filter
(
u32
mtrx_cur[],
u32
filt_en );
u32
key_changed = key_debounce_filter( pressed_matrix, \
(numlock_status & KB_NUMLOCK_STATUS_POWERON) ? 0 : 1);
During
fast keyscan after wakeup from deepsleep, “numlock_status” equals
“KB_NUMLOCK_STATUS_POWERON”, the “filt_en” is set as 0 to skip filtering and
fast obtain key values. In other cases, the
“filt_en” is set as 1 to enable filtering. Only
when pressed_matrix[] stays the same during two adjacent key scans, but different
from t
he latest valid pressed_matrix[], the “key_changed” is set as 1 to indicate valid
update in matrix keyboard.
4) Buffer processing for pressed_matrix[]
Push
pressed_matrix[] into buffer. When the “read_key” in “
kb_scan_key
(
int
numlock_status,
int
read_key)
” is set as 1, the data in the buffer will be read
out immediately. When the “read_key” is set as 0, the buffer stores the data without
notification to the upper layer; the buffered data won’t be read until the read_key is 1.
In current SDK, the
“read_key” is fixed as 1, i.e. the buffer does not take effect
actually.
5) According to pressed_matrix[], look up the KB_MAP_NORMAL table and return key
values.
Corresponding functions are
“kb_remap_key_code” and “kb_remap_key_row”.
7.4.2 Keyscan Flow Timing Optimization
As introduced above, even if no button is pressed, each mainloop takes about 100us to
execute initial full scan through the whole matrix at least.
GPIO IRQ status bit inquiry can be used to optimize the time for full scan with no button
pressed.
As shown in
PM section, in “user_init” all drive GPIO pins are configured as high-level
CORE wakeup for suspend.
u32
pin[] = KB_DRIVE_PINS;