diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/button-imx31.c | 29 | ||||
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/button-target.h | 44 |
2 files changed, 32 insertions, 41 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 | ||
39 | static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void) | 39 | static __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. */ |
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-target.h b/firmware/target/arm/imx31/gigabeat-s/button-target.h index 836a4c02cd..e2f68162f7 100644 --- a/firmware/target/arm/imx31/gigabeat-s/button-target.h +++ b/firmware/target/arm/imx31/gigabeat-s/button-target.h | |||
@@ -31,32 +31,26 @@ void button_power_set_state(bool pressed); | |||
31 | void set_headphones_inserted(bool inserted); | 31 | void set_headphones_inserted(bool inserted); |
32 | bool headphones_inserted(void); | 32 | bool headphones_inserted(void); |
33 | 33 | ||
34 | /* Toshiba Gigabeat specific button codes */ | 34 | /* Toshiba Gigabeat S-specific button codes */ |
35 | 35 | ||
36 | #define BUTTON_BACK (1 << 0) | 36 | /* These shifts are selected to optimize scanning of the keypad port */ |
37 | #define BUTTON_MENU (1 << 1) | 37 | #define BUTTON_LEFT (1 << 0) |
38 | 38 | #define BUTTON_UP (1 << 1) | |
39 | #define BUTTON_LEFT (1 << 2) | 39 | #define BUTTON_DOWN (1 << 2) |
40 | #define BUTTON_RIGHT (1 << 3) | 40 | #define BUTTON_RIGHT (1 << 3) |
41 | #define BUTTON_UP (1 << 4) | 41 | #define BUTTON_SELECT (1 << 4) |
42 | #define BUTTON_DOWN (1 << 5) | 42 | #define BUTTON_BACK (1 << 5) |
43 | #define BUTTON_SELECT (1 << 6) | 43 | #define BUTTON_MENU (1 << 6) |
44 | 44 | #define BUTTON_VOL_UP (1 << 7) | |
45 | #define BUTTON_POWER (1 << 7) | 45 | #define BUTTON_VOL_DOWN (1 << 8) |
46 | #define BUTTON_VOL_UP (1 << 8) | 46 | #define BUTTON_PREV (1 << 9) |
47 | #define BUTTON_VOL_DOWN (1 << 9) | 47 | #define BUTTON_PLAY (1 << 10) |
48 | #define BUTTON_NEXT (1 << 10) | 48 | #define BUTTON_NEXT (1 << 11) |
49 | #define BUTTON_PREV (1 << 11) | 49 | #define BUTTON_POWER (1 << 12) /* Read from PMIC */ |
50 | #define BUTTON_PLAY (1 << 12) | 50 | |
51 | 51 | #define BUTTON_REMOTE 0 | |
52 | #define BUTTON_MAIN (BUTTON_BACK|BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT \ | 52 | |
53 | |BUTTON_UP|BUTTON_DOWN|BUTTON_SELECT|BUTTON_POWER \ | 53 | #define POWEROFF_BUTTON BUTTON_POWER |
54 | |BUTTON_VOL_UP|BUTTON_VOL_DOWN|BUTTON_NEXT|BUTTON_PREV \ | 54 | #define POWEROFF_COUNT 10 |
55 | |BUTTON_PLAY) | ||
56 | |||
57 | #define BUTTON_REMOTE 0 | ||
58 | |||
59 | #define POWEROFF_BUTTON BUTTON_POWER | ||
60 | #define POWEROFF_COUNT 10 | ||
61 | 55 | ||
62 | #endif /* _BUTTON_TARGET_H_ */ | 56 | #endif /* _BUTTON_TARGET_H_ */ |