1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
Index: firmware/target/arm/as3525/debug-as3525.c
===================================================================
--- firmware/target/arm/as3525/debug-as3525.c	(Revision 20001)
+++ firmware/target/arm/as3525/debug-as3525.c	(Arbeitskopie)
@@ -54,6 +54,7 @@
         _DEBUG_PRINTF("GPIOB: %2x DIR: %2x", GPIOB_DATA, GPIOB_DIR);
         _DEBUG_PRINTF("GPIOC: %2x DIR: %2x", GPIOC_DATA, GPIOC_DIR);
         _DEBUG_PRINTF("GPIOD: %2x DIR: %2x", GPIOD_DATA, GPIOD_DIR);
+#define TRACK_DBOP_DIN
 #ifdef TRACK_DBOP_DIN
         line++;
         _DEBUG_PRINTF("[DBOP_DIN]");
Index: firmware/target/arm/as3525/debug-target.h
===================================================================
--- firmware/target/arm/as3525/debug-target.h	(Revision 20001)
+++ firmware/target/arm/as3525/debug-target.h	(Arbeitskopie)
@@ -22,5 +22,7 @@
 #include <stdbool.h>

 #define DEBUG_CANCEL BUTTON_LEFT
+#define TRACK_DBOP_DIN
+extern volatile short _dbop_din;
 bool __dbg_hw_info(void);
 bool __dbg_ports(void);
Index: firmware/target/arm/as3525/sansa-fuze/debug-target.h
===================================================================
--- firmware/target/arm/as3525/sansa-fuze/debug-target.h	(Revision 20001)
+++ firmware/target/arm/as3525/sansa-fuze/debug-target.h	(Arbeitskopie)
@@ -23,6 +23,6 @@

 #define DEBUG_CANCEL BUTTON_LEFT
 #define TRACK_DBOP_DIN
-extern short _dbop_din;
+extern volatile short _dbop_din;
 bool __dbg_hw_info(void);
 bool __dbg_ports(void);
Index: firmware/target/arm/as3525/sansa-fuze/button-fuze.c
===================================================================
--- firmware/target/arm/as3525/sansa-fuze/button-fuze.c	(Revision 20001)
+++ firmware/target/arm/as3525/sansa-fuze/button-fuze.c	(Arbeitskopie)
@@ -42,7 +42,6 @@
 #else
 #define hold_button false
 #endif /* !BOOTLOADER */
-static int  int_btn         = BUTTON_NONE;
 short      _dbop_din        = BUTTON_NONE;

 void button_init_device(void)
@@ -126,30 +125,15 @@
 }
 #endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */

-#if !defined(BOOTLOADER)
-/* get hold button state */
-static void get_hold(void)
-{
-    hold_button = _dbop_din & (1<<12);
-}
-#endif
-
 bool button_hold(void)
 {
     return hold_button;
 }

-static void get_power(void)
+static int get_button_from_dbob(void)
 {
-    if (_dbop_din & (1<<8))
-        int_btn |= BUTTON_POWER;
-}
-
-static void get_button_from_dbob(void)
-{
-    int_btn &= ~(BUTTON_HOLD|
-                BUTTON_POWER);
-
+    int ret = 0;
+    lcd_button_support();
     /* Wait for fifo to empty */
     while ((DBOP_STAT & (1<<10)) == 0);

@@ -181,24 +165,24 @@
     DBOP_CTRL &= ~(1<<19);

 #if !defined(BOOTLOADER)
-    get_hold();
-#if defined(HAVE_SCROLLWHEEL)
-    get_wheel();
+    hold_button = _dbop_din & (1<<12);
+    if (hold_button)
+        return ret;
 #endif
-#endif
-    get_power();
+    /* read power */
+    if (_dbop_din & (1<<8))
+        ret |= BUTTON_POWER;
+    if(!(_dbop_din & (1<<15)))
+        ret |= BUTTON_HOME;
+
+    return ret;
 }

-static void get_button_from_gpio(void)
+static int get_button_from_gpio(void)
 {
-    /* reset buttons we're going to read */
-    int_btn &= ~(BUTTON_LEFT|
-                BUTTON_RIGHT|
-                BUTTON_UP|
-                BUTTON_DOWN|
-                BUTTON_SELECT);
+    int btn = BUTTON_NONE;
     if(hold_button)
-        return;
+        return btn;
     /* set afsel, so that we can read our buttons */
     GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6);
     /* set dir so we can read our buttons (but reset the C pins first) */
@@ -218,31 +202,39 @@

     /* direct GPIO connections */
     if (!GPIOC_PIN(3))
-        int_btn |= BUTTON_LEFT;
+        btn |= BUTTON_LEFT;
     if (!GPIOC_PIN(2))
-        int_btn |= BUTTON_UP;
+        btn |= BUTTON_UP;
     if (!GPIOC_PIN(6))
-        int_btn |= BUTTON_DOWN;
+        btn |= BUTTON_DOWN;
     if (!GPIOC_PIN(5))
-        int_btn |= BUTTON_RIGHT;
+        btn |= BUTTON_RIGHT;
     if (!GPIOC_PIN(4))
-        int_btn |= BUTTON_SELECT;
+        btn |= BUTTON_SELECT;
     /* return to settings needed for lcd */
     GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6);
     GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6);
+
+    return btn;
 }

-static inline void get_buttons_from_hw(void)
+static inline int get_buttons_from_hw(void)
 {
-    get_button_from_dbob();
-    get_button_from_gpio();
+    int ret = BUTTON_NONE;
+    ret |= get_button_from_dbob();
+    ret |= get_button_from_gpio();
+    return ret;
 }
 /*
  * Get button pressed from hardware
  */
 int button_read_device(void)
 {
-    get_buttons_from_hw();
+    int ret = get_buttons_from_hw();
+#if defined(HAVE_SCROLLWHEEL)
+    if (!hold_button)
+        get_wheel();
+#endif
 #ifndef BOOTLOADER
     /* light handling */
     if (hold_button != hold_button_old)
@@ -252,5 +244,5 @@
     }
 #endif /* BOOTLOADER */

-    return int_btn; /* set in button_int */
+    return ret;
 }
Index: firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c
===================================================================
--- firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c	(Revision 20001)
+++ firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c	(Arbeitskopie)
@@ -42,6 +42,8 @@
 static bool display_flipped = false;
 static int xoffset = 20; /* needed for flip */

+static volatile int _ystart, _ymax, _xstart, _xmax;
+
 static void as3525_dbop_init(void)
 {
     CGU_DBOP = (1<<3) | CLK_DIV(AS3525_PCLK_FREQ, AS3525_DBOP_FREQ);
@@ -258,24 +260,37 @@
 }

 /* Set horizontal window addresses */
-static void lcd_window_x(int xmin, int xmax)
+void lcd_window_x(int xmin, int xmax)
 {
     xmin += xoffset;
     xmax += xoffset;
-
     lcd_write_reg(0x46, (xmax << 8) | xmin);
     lcd_write_reg(0x20, xmin);
 }

 /* Set vertical window addresses */
-static void lcd_window_y(int ymin, int ymax)
+void lcd_window_y(int ymin, int ymax)
 {
     lcd_write_reg(0x47, ymax);
     lcd_write_reg(0x48, ymin);
     lcd_write_reg(0x21, ymin);
-    lcd_write_cmd(0x22);
 }

+void lcd_button_support(void)
+{
+    fb_data data = 0xf<<12;
+    lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);
+    /* Set start position and window */
+
+    lcd_window_x(-1, 1);
+/*
+    lcd_window_y(LCD_HEIGHT+4, 1);
+*/
+    lcd_write_cmd(R_WRITE_DATA_2_GRAM);
+
+    lcd_write_data(&data, 1);
+}
+
 /* Update the display.
    This must be called after all other LCD functions that change the display. */
 void lcd_update(void)
@@ -285,6 +300,7 @@

     lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);

+    disable_irq();
     lcd_window_x(0, LCD_WIDTH - 1);
     lcd_window_y(0, LCD_HEIGHT - 1);

@@ -293,6 +309,7 @@

     /* Write data */
     lcd_write_data((unsigned short *)lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT);
+    enable_irq();
 }

 /* Update a fraction of the display. */
@@ -324,6 +341,7 @@

     lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);

+    disable_irq();
     lcd_window_x(x, xmax);
     lcd_window_y(y, ymax);

@@ -338,4 +356,5 @@
         ptr += LCD_WIDTH;
     }
     while (++y <= ymax);
+    enable_irq();
 }