diff options
author | David Hendricks <dhendrix@chromium.org> | 2013-03-08 16:13:38 -0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-13 14:14:02 -0700 |
commit | 2f229ea226e557c9cc2103bafe9caadb85df7cd9 (patch) | |
tree | 8fc9310deb85443f2a785f73150c68ca7c16ceaa | |
parent | abc11d883c513043f2ca037ce3c79e75008d829d (diff) | |
download | chrome-ec-2f229ea226e557c9cc2103bafe9caadb85df7cd9.tar.gz |
stm32: make read_raw_input_state() more portable
This re-factors read_raw_input_state() to use GPIO port and mask
values from the board's gpio_list array. This eliminates the reliance
on hard-coded bit mask values and ports, thus making the code
adaptable for future designs.
As a slight optimization, the GPIO input data register is re-read
only if the port changes from the previous iteration. Thus, it's best
if the GPIOs are listed such that changes to the port address are
minimized.
BUG=none
BRANCH=none
TEST=Tested on Snow by running finger across keys.
Change-Id: I4a79363f060f37690bfebfd6763f7bfe6cb7991a
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/44993
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | chip/stm32/keyboard_scan.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/chip/stm32/keyboard_scan.c b/chip/stm32/keyboard_scan.c index 636aa5a8fa..30b522ee5b 100644 --- a/chip/stm32/keyboard_scan.c +++ b/chip/stm32/keyboard_scan.c @@ -289,40 +289,26 @@ static void print_state(const uint8_t *state, const char *msg) */ static uint8_t read_raw_input_state(void) { - uint16_t tmp; - uint8_t r = 0; + int i; + unsigned int port, prev_port = 0; + uint8_t state = 0; + uint16_t port_val = 0; + + for (i = 0; i < KB_INPUTS; i++) { + port = gpio_list[GPIO_KB_IN00 + i].port; + if (port != prev_port) { + port_val = STM32_GPIO_IDR_OFF(port); + prev_port = port; + } - /* - * TODO(sjg@chromium.org): This code can be improved by doing - * the job in 3 shift/or operations. - */ - tmp = STM32_GPIO_IDR(C); - /* KB_OUT00:04 = PC8:12 */ - if (tmp & (1 << 8)) - r |= 1 << 0; - if (tmp & (1 << 9)) - r |= 1 << 1; - if (tmp & (1 << 10)) - r |= 1 << 2; - if (tmp & (1 << 11)) - r |= 1 << 3; - if (tmp & (1 << 12)) - r |= 1 << 4; - /* KB_OUT05:06 = PC14:15 */ - if (tmp & (1 << 14)) - r |= 1 << 5; - if (tmp & (1 << 15)) - r |= 1 << 6; - - tmp = STM32_GPIO_IDR(D); - /* KB_OUT07 = PD2 */ - if (tmp & (1 << 2)) - r |= 1 << 7; + if (port_val & gpio_list[GPIO_KB_IN00 + i].mask) + state |= 1 << i; + } /* Invert it so 0=not pressed, 1=pressed */ - r ^= 0xff; + state ^= 0xff; - return r; + return state; } /** |