From dfff88562e700ab1772c9bbb50c47bff00b9a002 Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Tue, 13 Dec 2011 23:12:21 +0000 Subject: Sansa Clip: simplify matrix key scan Merge clipv1/clipv2 code since they use the same 3x3 matrix clipzip keyscan buttons now work in bootloader clipplus untouched (no matrix) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31235 a1c6a512-1295-4272-9138-f99709370657 --- .../arm/as3525/sansa-clipzip/button-clipzip.c | 97 +++++++--------------- 1 file changed, 32 insertions(+), 65 deletions(-) (limited to 'firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c') diff --git a/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c b/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c index 40b20cdce3..c22c5e24e9 100644 --- a/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c +++ b/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c @@ -21,97 +21,64 @@ ****************************************************************************/ #include "config.h" - #include "button-target.h" #include "as3525v2.h" +#include "system.h" #include "kernel.h" -#include "system-target.h" static int keyscan(void) { - static int buttons = 0; - static int row = 1; + static int buttons, row; + static const int matrix[2][3] = { + { BUTTON_RIGHT, BUTTON_SELECT, BUTTON_UP }, + { BUTTON_HOME, BUTTON_DOWN, BUTTON_LEFT }, + }; + + for (int i = 0; i < 3; i++) + if (GPIOC_PIN(3 + i)) + buttons |= matrix[row][i]; + else + buttons &= ~matrix[row][i]; - switch (row) { - - case 1: - /* read row 1 */ - buttons &= ~(BUTTON_RIGHT | BUTTON_SELECT | BUTTON_UP); - if (GPIOC_PIN(3)) { - buttons |= BUTTON_RIGHT; - } - if (GPIOC_PIN(4)) { - buttons |= BUTTON_SELECT; - } - if (GPIOC_PIN(5)) { - buttons |= BUTTON_UP; - } - - /* prepare row 2 */ - GPIOC_PIN(1) = 0; - GPIOC_PIN(2) = (1 << 2); - row = 2; - break; - - case 2: - /* read row 2 */ - buttons &= ~(BUTTON_HOME | BUTTON_DOWN | BUTTON_LEFT); - if (GPIOC_PIN(3)) { - buttons |= BUTTON_HOME; - } - if (GPIOC_PIN(4)) { - buttons |= BUTTON_DOWN; - } - if (GPIOC_PIN(5)) { - buttons |= BUTTON_LEFT; - } - - /* prepare row 1 */ - GPIOC_PIN(1) = (1 << 1); - GPIOC_PIN(2) = 0; - row = 1; - break; + /* prepare next row */ + GPIOC_PIN(1) = row << 1; + row ^= 1; + GPIOC_PIN(2) = row << 2; + + /* delay a bit if interrupts are disabled, to be sure next row will read */ + if (!irq_enabled()) + for (volatile int i = 0; i < 0x500; i++) ; - default: - row = 1; - break; - } - return buttons; } void button_init_device(void) { /* GPIO A6, A7 and D6 are direct button inputs */ - GPIOA_DIR &= ~(1 << 6); - GPIOA_DIR &= ~(1 << 7); + GPIOA_DIR &= ~(1 << 6 | 1<< 7); GPIOD_DIR &= ~(1 << 6); - + /* GPIO C1, C2, C3, C4, C5 are used in a column/row key scan matrix */ GPIOC_DIR |= ((1 << 1) | (1 << 2)); GPIOC_DIR &= ~((1 << 3) | (1 << 4) | (1 << 5)); + + /* initial reading */ + button_read_device(); + sleep(1); + button_read_device(); + sleep(1); } int button_read_device(void) { int buttons = 0; - /* power */ - if (GPIOD_PIN(6)) { + if (GPIOD_PIN(6)) buttons |= BUTTON_POWER; - } - - /* volume */ - if (GPIOA_PIN(6)) { + if (GPIOA_PIN(6)) buttons |= BUTTON_VOL_DOWN; - } - if (GPIOA_PIN(7)) { + if (GPIOA_PIN(7)) buttons |= BUTTON_VOL_UP; - } - - /* keyscan buttons */ - buttons |= keyscan(); - return buttons; + return buttons | keyscan(); } - -- cgit v1.2.3