Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
156
Ver.1.0.0
VK_ZOOM_IN
=
(
VK_MEDIA_END
+ 1),
//0xb6
VK_ZOOM_OUT
,
//0xb7
}
7.4 Keyscan Flow
7.4.1 Basic Keyscan Flow
When kb_scan_key is called, a basic keyscan flow is shown as below:
1) Initial full scan through the whole matrix.
All drive pins output drive level (0). Meanwhile read all scan pins, check for valid
level, and record the column on which valid level is read. (The scan_pin_need is
used to mark valid column number.)
If row-by-row scan is directly adopted without initial full scan through the whole
matrix, each time all rows (five rows in current demo firmware) should be scanned at
least, even if no button is pressed. To save scan time, initial full scan through the
whole matrix can be added, thus it will directly exit keyscan if no button press is
detected on any column.
scan_pin_need = kb_key_pressed (gpio);
In the function kb_key_pressed, all rows output low level, and stabilized level of scan
pins will be read after 20us delay. A release_cnt is set as 6; if a detection shows all
pressed buttons in the matrix are released, it
won’t consider no button is pressed
and stop row-by-row scan immediately, but buffers for six frames. If six successive
detections show buttons are all released, it will stop row-by-row scan. Thus key
debounce processing is realized.
2) Scan row by row according to full scan result through the whole matrix.
If button press is detected by full scan, row-by-row scan is started: Drive pins
(ROW0~ROW4) output valid drive level row by row; read level on columns, and find
the pressed button. Following is related code:
u32
pressed_matrix[ARRAY_SIZE(drive_pins)] = {0};
kb_scan_row (0, gpio);
for
(
int
i=0; i<=ARRAY_SIZE(drive_pins); i++) {
u32
r = kb_scan_row (i < ARRAY_SIZE(drive_pins) ? i : 0,
gpio);
if
(i) {
pressed_matrix[i - 1] = r;
}
}