summaryrefslogtreecommitdiff
path: root/firmware/target/arm/philips/hdd1630/button-hdd1630.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/philips/hdd1630/button-hdd1630.c')
-rwxr-xr-xfirmware/target/arm/philips/hdd1630/button-hdd1630.c156
1 files changed, 128 insertions, 28 deletions
diff --git a/firmware/target/arm/philips/hdd1630/button-hdd1630.c b/firmware/target/arm/philips/hdd1630/button-hdd1630.c
index 84cb8f0c06..8976e7325c 100755
--- a/firmware/target/arm/philips/hdd1630/button-hdd1630.c
+++ b/firmware/target/arm/philips/hdd1630/button-hdd1630.c
@@ -22,9 +22,16 @@
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
26/* Remember last buttons, to make single buzz sound */ 27#define LOGF_ENABLE
27int btn_old; 28#include "logf.h"
29
30#define MEP_BUTTON_HEADER 0x19
31#define MEP_BUTTON_ID 0x9
32#define MEP_ABSOLUTE_HEADER 0x0b
33
34static int int_btn = BUTTON_NONE;
28 35
29/* 36/*
30 * Generate a click sound from the player (not in headphones yet) 37 * Generate a click sound from the player (not in headphones yet)
@@ -38,10 +45,117 @@ void button_click(void)
38 GPO32_VAL &= ~0x2000; 45 GPO32_VAL &= ~0x2000;
39} 46}
40 47
48#ifndef BOOTLOADER
49static int syn_status = 0;
50
41void button_init_device(void) 51void button_init_device(void)
42{ 52{
43 /* TODO...for now, hardware initialisation is done by the bootloader */ 53 /* enable touchpad */
54 GPO32_ENABLE |= 0x80;
55 GPO32_VAL &= ~0x80;
56 udelay(1000);
57
58 /* enable ACK, CLK, DATA lines */
59 GPIOD_ENABLE |= 0x80;
60 GPIOA_ENABLE |= (0x10 | 0x20);
61
62 GPIOD_OUTPUT_EN |= 0x80; /* ACK */
63 GPIOD_OUTPUT_VAL |= 0x80; /* high */
64
65 GPIOA_OUTPUT_EN &= ~0x20; /* CLK */
66
67 GPIOA_OUTPUT_EN |= 0x10; /* DATA */
68 GPIOA_OUTPUT_VAL |= 0x10; /* high */
69
70 if (syn_init())
71 {
72#ifdef ROCKBOX_HAS_LOGF
73 syn_info();
74#endif
75 syn_status = 1;
76
77 /* enable interrupts */
78 GPIOA_INT_LEV &= ~0x20;
79 GPIOA_INT_CLR |= 0x20;
80 GPIOA_INT_EN |= 0x20;
81
82 CPU_INT_EN |= HI_MASK;
83 CPU_HI_INT_EN |= GPIO0_MASK;
84 }
85}
86
87/*
88 * Button interrupt handler
89 */
90void button_int(void)
91{
92 int data[4];
93 int val, id;
94
95 int_btn = BUTTON_NONE;
96
97 if (syn_status)
98 {
99 /* disable interrupt while we read the touchpad */
100 GPIOA_INT_EN &= ~0x20;
101 GPIOA_INT_CLR |= 0x20;
102
103 val = syn_read_device(data, 4);
104 if (val > 0)
105 {
106 val = data[0] & 0xff; /* packet header */
107 id = (data[1] >> 4) & 0xf; /* packet id */
108
109 logf("button_read_device...");
110 logf(" data[0] = 0x%08x", data[0]);
111 logf(" data[1] = 0x%08x", data[1]);
112 logf(" data[2] = 0x%08x", data[2]);
113 logf(" data[3] = 0x%08x", data[3]);
114
115 if ((val == MEP_BUTTON_HEADER) && (id == MEP_BUTTON_ID))
116 {
117 /* Buttons packet */
118 if (data[1] & 0x1)
119 int_btn |= BUTTON_LEFT;
120 if (data[1] & 0x2)
121 int_btn |= BUTTON_RIGHT;
122
123 /* An Absolute packet should follow which we ignore */
124 val = syn_read_device(data, 4);
125 logf(" int_btn = 0x%04x", int_btn);
126 }
127 else if (val == MEP_ABSOLUTE_HEADER)
128 {
129 /* Absolute packet - the finger is on the vertical strip.
130 Position ranges from 1-4095, with 1 at the bottom. */
131 val = ((data[1] >> 4) << 8) | data[2]; /* position */
132
133 logf(" pos %d", val);
134 logf(" z %d", data[3]);
135 logf(" finger %d", data[1] & 0x1);
136 logf(" gesture %d", data[1] & 0x2);
137 logf(" RelPosVld %d", data[1] & 0x4);
138
139 if(data[1] & 0x1) /* if finger on touch strip */
140 {
141 if ((val > 0) && (val <= 1365))
142 int_btn |= BUTTON_DOWN;
143 else if ((val > 1365) && (val <= 2730))
144 int_btn |= BUTTON_SELECT;
145 else if ((val > 2730) && (val <= 4095))
146 int_btn |= BUTTON_UP;
147 }
148 }
149 }
150
151 /* re-enable interrupts */
152 GPIOA_INT_LEV &= ~0x20;
153 GPIOA_INT_EN |= 0x20;
154 }
44} 155}
156#else
157void button_init_device(void){}
158#endif /* bootloader */
45 159
46bool button_hold(void) 160bool button_hold(void)
47{ 161{
@@ -53,34 +167,20 @@ bool button_hold(void)
53 */ 167 */
54int button_read_device(void) 168int button_read_device(void)
55{ 169{
56 int btn = BUTTON_NONE; 170 static int btn_old = BUTTON_NONE;
57 static bool hold_button = false; 171 int btn = int_btn;
58 bool hold_button_old;
59 172
60 /* Hold */ 173 /* Hold */
61 hold_button_old = hold_button; 174 if(button_hold())
62 hold_button = button_hold(); 175 return BUTTON_NONE;
63 176
64 /* device buttons */ 177 /* Device buttons */
65 if (!hold_button) 178 if (!(GPIOA_INPUT_VAL & 0x01)) btn |= BUTTON_MENU;
66 { 179 if (!(GPIOA_INPUT_VAL & 0x02)) btn |= BUTTON_VOL_UP;
67 /* These are the correct button definitions 180 if (!(GPIOA_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
68 if (!(GPIOA_INPUT_VAL & 0x01)) btn |= BUTTON_MENU; 181 if (!(GPIOA_INPUT_VAL & 0x08)) btn |= BUTTON_VIEW;
69 if (!(GPIOA_INPUT_VAL & 0x02)) btn |= BUTTON_VOL_UP; 182 if (!(GPIOD_INPUT_VAL & 0x20)) btn |= BUTTON_PLAYLIST;
70 if (!(GPIOA_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN; 183 if (!(GPIOD_INPUT_VAL & 0x40)) btn |= BUTTON_POWER;
71 if (!(GPIOA_INPUT_VAL & 0x08)) btn |= BUTTON_VIEW;
72 if (!(GPIOD_INPUT_VAL & 0x20)) btn |= BUTTON_PLAYLIST;
73 if (!(GPIOD_INPUT_VAL & 0x40)) btn |= BUTTON_POWER;
74 */
75
76 /* This is a hack until the touchpad works */
77 if (!(GPIOA_INPUT_VAL & 0x01)) btn |= BUTTON_LEFT; /* BUTTON_MENU */
78 if (!(GPIOA_INPUT_VAL & 0x02)) btn |= BUTTON_UP; /* BUTTON_VOL_UP */
79 if (!(GPIOA_INPUT_VAL & 0x04)) btn |= BUTTON_DOWN; /* BUTTON_VOL_DOWN */
80 if (!(GPIOA_INPUT_VAL & 0x08)) btn |= BUTTON_RIGHT; /* BUTTON_VIEW */
81 if (!(GPIOD_INPUT_VAL & 0x20)) btn |= BUTTON_SELECT; /* BUTTON_PLAYLIST */
82 if (!(GPIOD_INPUT_VAL & 0x40)) btn |= BUTTON_POWER;
83 }
84 184
85 if ((btn != btn_old) && (btn != BUTTON_NONE)) 185 if ((btn != btn_old) && (btn != BUTTON_NONE))
86 button_click(); 186 button_click();