summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c140
1 files changed, 65 insertions, 75 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
index dd169c3a44..0f1cfca937 100644
--- a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
+++ b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
@@ -22,21 +22,22 @@
22#include "config.h" 22#include "config.h"
23#include "system.h" 23#include "system.h"
24#include "jz4740.h" 24#include "jz4740.h"
25#include "button.h"
25#include "button-target.h" 26#include "button-target.h"
26 27
27#define BTN_VOL_DOWN (1 << 27)
28#define BTN_VOL_UP (1 << 0)
29#define BTN_MENU (1 << 1)
30#define BTN_OFF (1 << 29) 28#define BTN_OFF (1 << 29)
29#define BTN_VOL_DOWN (1 << 27)
31#define BTN_HOLD (1 << 16) 30#define BTN_HOLD (1 << 16)
32#define BTN_MASK (BTN_VOL_DOWN | BTN_VOL_UP \ 31#define BTN_MENU (1 << 1)
33 | BTN_MENU | BTN_OFF ) 32#define BTN_VOL_UP (1 << 0)
33#define BTN_MASK (BTN_OFF | BTN_VOL_DOWN | \
34 BTN_MENU | BTN_VOL_UP)
34 35
35 36
36#define TS_AD_COUNT 5 37#define TS_AD_COUNT 5
37#define M_SADC_CFG_SNUM ((TS_AD_COUNT - 1) << SADC_CFG_SNUM_BIT) 38#define M_SADC_CFG_SNUM ((TS_AD_COUNT - 1) << SADC_CFG_SNUM_BIT)
38 39
39#define SADC_CFG_INIT ( \ 40#define SADC_CFG_INIT ( \
40 (2 << SADC_CFG_CLKOUT_NUM_BIT) | \ 41 (2 << SADC_CFG_CLKOUT_NUM_BIT) | \
41 SADC_CFG_XYZ1Z2 | \ 42 SADC_CFG_XYZ1Z2 | \
42 M_SADC_CFG_SNUM | \ 43 M_SADC_CFG_SNUM | \
@@ -45,20 +46,23 @@
45 SADC_CFG_CMD_INT_PEN \ 46 SADC_CFG_CMD_INT_PEN \
46 ) 47 )
47 48
48static bool pendown_flag = false;
49static short x_pos = -1, y_pos = -1, datacount = 0; 49static short x_pos = -1, y_pos = -1, datacount = 0;
50static short stable_x_pos = -1, stable_y_pos = -1; 50static bool pen_down = false;
51static int cur_touch = 0;
51 52
52bool button_hold(void) 53static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT;
54static int touchscreen_buttons[3][3] =
53{ 55{
54 return (~REG_GPIO_PXPIN(3) & BTN_HOLD ? 1 : 0); 56 {BUTTON_TOPLEFT, BUTTON_TOPMIDDLE, BUTTON_TOPRIGHT},
55} 57 {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
58 {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT}
59};
56 60
57void button_init_device(void) 61void button_init_device(void)
58{ 62{
59 REG_SADC_ENA = 0; 63 REG_SADC_ENA = 0;
60 REG_SADC_STATE &= (~REG_SADC_STATE); 64 REG_SADC_STATE &= (~REG_SADC_STATE);
61 REG_SADC_CTRL = 0x1f; 65 REG_SADC_CTRL = 0x1F;
62 66
63 __cpm_start_sadc(); 67 __cpm_start_sadc();
64 REG_SADC_CFG = SADC_CFG_INIT; 68 REG_SADC_CFG = SADC_CFG_INIT;
@@ -71,15 +75,15 @@ void button_init_device(void)
71 REG_SADC_CTRL &= (~(SADC_CTRL_PENDM | SADC_CTRL_PENUM | SADC_CTRL_TSRDYM)); 75 REG_SADC_CTRL &= (~(SADC_CTRL_PENDM | SADC_CTRL_PENUM | SADC_CTRL_TSRDYM));
72 REG_SADC_ENA = SADC_ENA_TSEN; //| SADC_ENA_PBATEN | SADC_ENA_SADCINEN); 76 REG_SADC_ENA = SADC_ENA_TSEN; //| SADC_ENA_PBATEN | SADC_ENA_SADCINEN);
73 77
74 __gpio_port_as_input(3, 29); 78 __gpio_as_input(32*3 + 29);
75 __gpio_port_as_input(3, 27); 79 __gpio_as_input(32*3 + 27);
76 __gpio_port_as_input(3, 16); 80 __gpio_as_input(32*3 + 16);
77 __gpio_port_as_input(3, 1); 81 __gpio_as_input(32*3 + 1);
78 __gpio_port_as_input(3, 0); 82 __gpio_as_input(32*3 + 0);
79} 83}
80 84
81static int touch_to_pixels(short x, short y) 85static int touch_to_pixels(short x, short y)
82{ 86{
83 /* X:300 -> 3800 Y:300->3900 */ 87 /* X:300 -> 3800 Y:300->3900 */
84 x -= 300; 88 x -= 300;
85 y -= 300; 89 y -= 300;
@@ -102,68 +106,56 @@ static int touch_to_pixels(short x, short y)
102#endif 106#endif
103} 107}
104 108
109bool button_hold(void)
110{
111 return ((~REG_GPIO_PXPIN(3)) & BTN_HOLD ? true : false);
112}
113
105int button_read_device(int *data) 114int button_read_device(int *data)
106{ 115{
107 if(button_hold()) 116 int ret = 0, tmp;
117
118 if((~REG_GPIO_PXPIN(3)) & BTN_HOLD)
108 return 0; 119 return 0;
109 120
110 unsigned int key = ~(__gpio_get_port(3)); 121 tmp = (~REG_GPIO_PXPIN(3)) & BTN_MASK;
111 int ret = 0; 122
112 123 if(tmp & BTN_VOL_DOWN)
113 if(key & BTN_MASK) 124 ret |= BUTTON_VOL_DOWN;
125 if(tmp & BTN_VOL_UP)
126 ret |= BUTTON_VOL_UP;
127 if(tmp & BTN_MENU)
128 ret |= BUTTON_MENU;
129 if(tmp & BTN_OFF)
130 ret |= BUTTON_POWER;
131
132 if(current_mode == TOUCHSCREEN_BUTTON && cur_touch != 0)
114 { 133 {
115 if(key & BTN_VOL_DOWN) 134 int px_x = cur_touch >> 16;
116 ret |= BUTTON_VOL_DOWN; 135 int px_y = cur_touch & 0xFFFF;
117 if(key & BTN_VOL_UP) 136 ret |= touchscreen_buttons[px_y/(LCD_HEIGHT/3)]
118 ret |= BUTTON_VOL_UP; 137 [px_x/(LCD_WIDTH/3)];
119 if(key & BTN_MENU)
120 ret |= BUTTON_MENU;
121 if(key & BTN_OFF)
122 ret |= BUTTON_POWER;
123 } 138 }
124 139 else if(pen_down)
125 if(data != NULL)
126 { 140 {
127 if(pendown_flag) 141 ret |= BUTTON_TOUCH;
128 { 142 if(data != NULL)
129 *data = touch_to_pixels(stable_x_pos, stable_y_pos); 143 *data = cur_touch;
130 ret |= BUTTON_TOUCH;
131 }
132 else
133 *data = 0;
134 } 144 }
135 145
136 return ret; 146 return ret;
137} 147}
138 148
139/* 149void touchscreen_set_mode(enum touchscreen_mode mode)
140static enum touchpad_mode current_mode = TOUCHPAD_POINT;
141
142static bool touch_available = false;
143
144static int touchpad_buttons[3][3] =
145{
146 {BUTTON_TOPLEFT, BUTTON_TOPMIDDLE, BUTTON_TOPRIGHT},
147 {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
148 {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT}
149};
150
151void touchpad_set_mode(enum touchpad_mode mode)
152{ 150{
153 current_mode = mode; 151 current_mode = mode;
154} 152}
155 153
156enum touchpad_mode touchpad_get_mode(void) 154enum touchscreen_mode touchscreen_get_mode(void)
157{ 155{
158 return current_mode; 156 return current_mode;
159} 157}
160 158
161void button_set_touch_available(void)
162{
163 touch_available = true;
164}
165*/
166
167/* Interrupt handler */ 159/* Interrupt handler */
168void SADC(void) 160void SADC(void)
169{ 161{
@@ -179,18 +171,17 @@ void SADC(void)
179 /* Pen down IRQ */ 171 /* Pen down IRQ */
180 REG_SADC_CTRL &= (~(SADC_CTRL_PENUM | SADC_CTRL_TSRDYM)); 172 REG_SADC_CTRL &= (~(SADC_CTRL_PENUM | SADC_CTRL_TSRDYM));
181 REG_SADC_CTRL |= (SADC_CTRL_PENDM); 173 REG_SADC_CTRL |= (SADC_CTRL_PENDM);
182 pendown_flag = true; 174 pen_down = true;
183 } 175 }
184 if(state & SADC_CTRL_PENUM) 176 if(state & SADC_CTRL_PENUM)
185 { 177 {
186 /* Pen up IRQ */ 178 /* Pen up IRQ */
187 REG_SADC_CTRL &= (~SADC_CTRL_PENDM ); 179 REG_SADC_CTRL &= (~SADC_CTRL_PENDM );
188 REG_SADC_CTRL |= SADC_CTRL_PENUM; 180 REG_SADC_CTRL |= SADC_CTRL_PENUM;
189 pendown_flag = false; 181 pen_down = false;
190 x_pos = -1; 182 x_pos = -1;
191 y_pos = -1; 183 y_pos = -1;
192 stable_x_pos = -1; 184 cur_touch = 0;
193 stable_y_pos = -1;
194 } 185 }
195 if(state & SADC_CTRL_TSRDYM) 186 if(state & SADC_CTRL_TSRDYM)
196 { 187 {
@@ -200,15 +191,15 @@ void SADC(void)
200 191
201 dat = REG_SADC_TSDAT; 192 dat = REG_SADC_TSDAT;
202 193
203 xData = (dat >> 0) & 0xfff; 194 xData = (dat >> 0) & 0xFFF;
204 yData = (dat >> 16) & 0xfff; 195 yData = (dat >> 16) & 0xFFF;
205 196
206 dat = REG_SADC_TSDAT; 197 dat = REG_SADC_TSDAT;
207 tsz1Data = (dat >> 0) & 0xfff; 198 tsz1Data = (dat >> 0) & 0xFFF;
208 tsz2Data = (dat >> 16) & 0xfff; 199 tsz2Data = (dat >> 16) & 0xFFF;
209 200
210 if(!pendown_flag) 201 if( !pen_down )
211 return ; 202 return;
212 203
213 tsz1Data = tsz2Data - tsz1Data; 204 tsz1Data = tsz2Data - tsz1Data;
214 205
@@ -231,8 +222,7 @@ void SADC(void)
231 { 222 {
232 if(x_pos != -1) 223 if(x_pos != -1)
233 { 224 {
234 stable_x_pos = x_pos; 225 cur_touch = touch_to_pixels(x_pos, y_pos);
235 stable_y_pos = y_pos;
236 x_pos = -1; 226 x_pos = -1;
237 y_pos = -1; 227 y_pos = -1;
238 } 228 }