summaryrefslogtreecommitdiff
path: root/firmware/target/arm/philips/sa9200/button-sa9200.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/philips/sa9200/button-sa9200.c')
-rwxr-xr-xfirmware/target/arm/philips/sa9200/button-sa9200.c79
1 files changed, 54 insertions, 25 deletions
diff --git a/firmware/target/arm/philips/sa9200/button-sa9200.c b/firmware/target/arm/philips/sa9200/button-sa9200.c
index d965966075..be37111ecb 100755
--- a/firmware/target/arm/philips/sa9200/button-sa9200.c
+++ b/firmware/target/arm/philips/sa9200/button-sa9200.c
@@ -22,11 +22,58 @@
22#include "system.h" 22#include "system.h"
23#include "button.h" 23#include "button.h"
24#include "backlight.h" 24#include "backlight.h"
25#include "synaptics-mep.h"
25 26
27#define LOGF_ENABLE
28#include "logf.h"
29
30static int int_btn = BUTTON_NONE;
31
32#ifndef BOOTLOADER
26void button_init_device(void) 33void button_init_device(void)
27{ 34{
28 /* TODO...for now, hardware initialisation is done by the c200 bootloader */ 35 /* The touchpad is powered on and initialized in power-sa9200.c
36 since it needs to be ready for both buttons and button lights. */
37}
38
39/*
40 * Button interrupt handler
41 */
42void button_int(void)
43{
44 char data[4];
45 int val;
46
47 int_btn = BUTTON_NONE;
48
49 val = touchpad_read_device(data, 4);
50
51 if (val == MEP_BUTTON_HEADER)
52 {
53 /* Buttons packet */
54 if (data[1] & 0x1) int_btn |= BUTTON_FFWD;
55 if (data[1] & 0x2) int_btn |= BUTTON_RIGHT;
56 if (data[1] & 0x4) int_btn |= BUTTON_LEFT;
57 if (data[1] & 0x8) int_btn |= BUTTON_REW;
58 if (data[2] & 0x1) int_btn |= BUTTON_MENU;
59 }
60 else if (val == MEP_ABSOLUTE_HEADER)
61 {
62 /* Absolute packet - the finger is on the vertical strip.
63 Position ranges from 1-4095, with 1 at the bottom. */
64 val = ((data[1] >> 4) << 8) | data[2]; /* position */
65
66 if ((val > 0) && (val <= 1365))
67 int_btn |= BUTTON_DOWN;
68 else if ((val > 1365) && (val <= 2730))
69 int_btn |= BUTTON_PLAY;
70 else if ((val > 2730) && (val <= 4095))
71 int_btn |= BUTTON_UP;
72 }
29} 73}
74#else
75void button_init_device(void){}
76#endif /* bootloader */
30 77
31bool button_hold(void) 78bool button_hold(void)
32{ 79{
@@ -38,32 +85,14 @@ bool button_hold(void)
38 */ 85 */
39int button_read_device(void) 86int button_read_device(void)
40{ 87{
41 int btn = BUTTON_NONE; 88 int btn = int_btn;
42 static bool hold_button = false;
43 bool hold_button_old;
44
45 /* Hold */
46 hold_button_old = hold_button;
47 hold_button = button_hold();
48 89
49#ifndef BOOTLOADER 90 if (button_hold())
50 if (hold_button != hold_button_old) 91 return BUTTON_NONE;
51 backlight_hold_changed(hold_button);
52#endif
53 92
54 /* device buttons */ 93 if (!(GPIOB_INPUT_VAL & 0x20)) btn |= BUTTON_POWER;
55 if (!hold_button) 94 if (!(GPIOF_INPUT_VAL & 0x10)) btn |= BUTTON_VOL_UP;
56 { 95 if (!(GPIOF_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
57#if 0
58 if (!(GPIOB_INPUT_VAL & 0x20)) btn |= BUTTON_POWER;
59 if (!(GPIOF_INPUT_VAL & 0x10)) btn |= BUTTON_VOL_UP;
60 if (!(GPIOF_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
61#endif
62 /* A hack until the touchpad works */
63 if (!(GPIOB_INPUT_VAL & 0x20)) btn |= BUTTON_SELECT;
64 if (!(GPIOF_INPUT_VAL & 0x10)) btn |= BUTTON_UP;
65 if (!(GPIOF_INPUT_VAL & 0x04)) btn |= BUTTON_DOWN;
66 }
67 96
68 return btn; 97 return btn;
69} 98}