summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/button-imx31.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/button-imx31.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
index 28b711902b..e80166bca7 100644
--- a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
@@ -38,18 +38,18 @@ static bool hold_button_old = false;
38 38
39static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void) 39static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
40{ 40{
41 static const int key_mtx[5][3] = 41 static const struct key_mask_shift
42 { 42 {
43 { BUTTON_LEFT, BUTTON_BACK, BUTTON_VOL_UP }, 43 uint8_t mask;
44 { BUTTON_UP, BUTTON_MENU, BUTTON_VOL_DOWN }, 44 uint8_t shift;
45 { BUTTON_DOWN, BUTTON_NONE, BUTTON_PREV }, 45 } kms[3] =
46 { BUTTON_RIGHT, BUTTON_NONE, BUTTON_PLAY }, 46 {
47 { BUTTON_SELECT, BUTTON_NONE, BUTTON_NEXT }, 47 { 0x1f, 0 }, /* BUTTON_LEFT...BUTTON_SELECT */
48 { 0x03, 5 }, /* BUTTON_BACK...BUTTON_MENU */
49 { 0x1f, 7 }, /* BUTTON_VOL_UP...BUTTON_NEXT */
48 }; 50 };
49 51
50 unsigned short reg_val; 52 int col;
51 int col, row;
52 int i;
53 /* Power button is handled separately on PMIC */ 53 /* Power button is handled separately on PMIC */
54 int button = int_btn & BUTTON_POWER; 54 int button = int_btn & BUTTON_POWER;
55 55
@@ -60,6 +60,8 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
60 60
61 for (col = 0; col < 3; col++) /* Col */ 61 for (col = 0; col < 3; col++) /* Col */
62 { 62 {
63 int i;
64
63 /* 2. Write 1s to KPDR[10:8] setting column data to 1s */ 65 /* 2. Write 1s to KPDR[10:8] setting column data to 1s */
64 KPP_KPDR |= (0x7 << 8); 66 KPP_KPDR |= (0x7 << 8);
65 67
@@ -80,7 +82,7 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
80 * 7. Repeat steps 2 - 6 for remaining columns. */ 82 * 7. Repeat steps 2 - 6 for remaining columns. */
81 83
82 /* Col bit starts at 8th bit in KPDR */ 84 /* Col bit starts at 8th bit in KPDR */
83 KPP_KPDR &= ~(1 << (8 + col)); 85 KPP_KPDR &= ~(0x100 << col);
84 86
85 /* Delay added to avoid propagating the 0 from column to row 87 /* Delay added to avoid propagating the 0 from column to row
86 * when scanning. */ 88 * when scanning. */
@@ -88,12 +90,7 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
88 asm volatile (""); 90 asm volatile ("");
89 91
90 /* Read row input */ 92 /* Read row input */
91 reg_val = KPP_KPDR; 93 button |= (~KPP_KPDR & kms[col].mask) << kms[col].shift;
92 for (row = 0; row < 5; row++) /* sample row */
93 {
94 if (!(reg_val & (1 << row)))
95 button |= key_mtx[row][col];
96 }
97 } 94 }
98 95
99 /* 8. Return all columns to 0 in preparation for standby mode. */ 96 /* 8. Return all columns to 0 in preparation for standby mode. */