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
diff --git a/firmware/target/arm/sandisk/sansa-c200/lcd-c200.c b/firmware/target/arm/sandisk/sansa-c200/lcd-c200.c
index 6957845..9cef5c9 100644
--- a/firmware/target/arm/sandisk/sansa-c200/lcd-c200.c
+++ b/firmware/target/arm/sandisk/sansa-c200/lcd-c200.c
@@ -73,19 +73,24 @@ static inline void lcd_wait_write(void)
 }

 /* send LCD data */
-static void lcd_send_data(unsigned data)
+static void lcd_send_data(const fb_data *data, int width)
 {
-    lcd_wait_write();
-    LCD1_DATA = data >> 8;
-    lcd_wait_write();
-    LCD1_DATA = data & 0xff;
+    while(width--)
+    {
+        lcd_wait_write();
+        LCD1_DATA = *data >> 8;
+        lcd_wait_write();
+        LCD1_DATA = *data++ & 0xff;
+    }
 }

 /* send LCD command */
-static void lcd_send_command(unsigned cmd)
+static void lcd_send_command(unsigned char cmd, unsigned char arg)
 {
     lcd_wait_write();
     LCD1_CMD = cmd;
+    lcd_wait_write();
+    LCD1_CMD = arg;
 }

 /* LCD init */
@@ -107,69 +112,54 @@ void lcd_init_device(void)
     LCD1_CONTROL = 0x0084; /* bits (9,10) = 00 -> fastest setting */
     udelay(10000);

-    lcd_send_command(R_STANDBY_OFF);
+    lcd_send_command(R_STANDBY_OFF, 0);
     udelay(20000);

-    lcd_send_command(R_OSCILLATION_MODE);
-    lcd_send_command(0x01);
+    lcd_send_command(R_OSCILLATION_MODE, 0x01);
     udelay(20000);

-    lcd_send_command(R_DCDC_AMP_ONOFF);
-    lcd_send_command(0x01);
+    lcd_send_command(R_DCDC_AMP_ONOFF, 0x01);
     udelay(20000);

-    lcd_send_command(R_DCDC_AMP_ONOFF);
-    lcd_send_command(0x09);
+    lcd_send_command(R_DCDC_AMP_ONOFF, 0x09);
     udelay(20000);

-    lcd_send_command(R_DCDC_AMP_ONOFF);
-    lcd_send_command(0x0b);
+    lcd_send_command(R_DCDC_AMP_ONOFF, 0x0b);
     udelay(20000);

-    lcd_send_command(R_DCDC_AMP_ONOFF);
-    lcd_send_command(0x0f);
+    lcd_send_command(R_DCDC_AMP_ONOFF, 0x0f);
     udelay(20000);

-    lcd_send_command(R_DRIVER_OUTPUT_MODE);
-    lcd_send_command(0x07);
+    lcd_send_command(R_DRIVER_OUTPUT_MODE, 0x07);

-    lcd_send_command(R_DCDC_SET);
-    lcd_send_command(0x03);
+    lcd_send_command(R_DCDC_SET, 0x03);

-    lcd_send_command(R_DCDC_CLOCK_DIV);
-    lcd_send_command(0x03);
+    lcd_send_command(R_DCDC_CLOCK_DIV, 0x03);

-    lcd_send_command(R_TEMP_COMPENSATION);
-    lcd_send_command(0x01);
+    lcd_send_command(R_TEMP_COMPENSATION, 0x01);

-    lcd_send_command(R_CONTRAST_CONTROL1);
-    lcd_send_command(0x55);
+    lcd_send_command(R_CONTRAST_CONTROL1, 0x55);

-    lcd_send_command(R_ADDRESSING_MODE);
-    lcd_send_command(0x10);
+    lcd_send_command(R_ADDRESSING_MODE, 0x10);

-    lcd_send_command(R_ROW_VECTOR_MODE);
-    lcd_send_command(0x0e);
+    lcd_send_command(R_ROW_VECTOR_MODE, 0x0e);

-    lcd_send_command(R_N_LINE_INVERSION);
-    lcd_send_command(0x0d);
+    lcd_send_command(R_N_LINE_INVERSION, 0x0d);

-    lcd_send_command(R_FRAME_FREQ_CONTROL);
-    lcd_send_command(0);
+    lcd_send_command(R_FRAME_FREQ_CONTROL, 0);

-    lcd_send_command(R_ENTRY_MODE);
-    lcd_send_command(0x82);
+    lcd_send_command(R_ENTRY_MODE, 0x82);

-    lcd_send_command(R_Y_ADDR_AREA);         /* vertical dimensions */
-    lcd_send_command(0x1a);                  /* y1 + 0x1a */
-    lcd_send_command(LCD_HEIGHT - 1 + 0x1a); /* y2 + 0x1a */
+    /* vertical dimensions */
+    lcd_send_command(R_Y_ADDR_AREA, 0x1a);      /* y1 + 0x1a */
+    lcd_send_command(LCD_HEIGHT - 1 + 0x1a, 0); /* y2 + 0x1a */

-    lcd_send_command(R_X_ADDR_AREA);         /* horizontal dimensions */
-    lcd_send_command(0);                     /* x1 */
-    lcd_send_command(LCD_WIDTH - 1);         /* x2 */
+    /* horizontal dimensions */
+    lcd_send_command(R_X_ADDR_AREA, 0); /* x1 */
+    lcd_send_command(LCD_WIDTH - 1, 0); /* x2 */
     udelay(100000);

-    lcd_send_command(R_DISPLAY_ON);
+    lcd_send_command(R_DISPLAY_ON, 0);
 }

 /*** hardware configuration ***/
@@ -180,8 +170,7 @@ int lcd_default_contrast(void)

 void lcd_set_contrast(int val)
 {
-    lcd_send_command(R_CONTRAST_CONTROL1);
-    lcd_send_command(val);
+    lcd_send_command(R_CONTRAST_CONTROL1, val);
 }

 void lcd_set_invert_display(bool yesno)
@@ -198,13 +187,13 @@ void lcd_enable(bool yesno)

     if ((is_lcd_enabled = yesno))
     {
-        lcd_send_command(R_STANDBY_OFF);
-        lcd_send_command(R_DISPLAY_ON);
+        lcd_send_command(R_STANDBY_OFF, 0);
+        lcd_send_command(R_DISPLAY_ON, 0);
         lcd_activation_call_hook();
     }
     else
     {
-        lcd_send_command(R_STANDBY_ON);
+        lcd_send_command(R_STANDBY_ON, 0);
     }
 }
 #endif
@@ -220,8 +209,7 @@ bool lcd_active(void)
 /* turn the display upside down (call lcd_update() afterwards) */
 void lcd_set_flip(bool yesno)
 {
-    lcd_send_command(R_DRIVER_OUTPUT_MODE);
-    lcd_send_command(yesno ? 0x02 : 0x07);
+    lcd_send_command(R_DRIVER_OUTPUT_MODE, yesno ? 0x02 : 0x07);
 }

 /*** update functions ***/
@@ -259,25 +247,17 @@ void lcd_blit_yuv(unsigned char * const src[3],
     yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
     yuv_src[2] = src[2] + (yuv_src[1] - src[1]);

-    lcd_send_command(R_ENTRY_MODE);
-    lcd_send_command(0x80);
+    lcd_send_command(R_ENTRY_MODE, 0x80);

-    lcd_send_command(R_X_ADDR_AREA);
-    lcd_send_command(x);
-    lcd_send_command(x + width - 1);
+    lcd_send_command(R_X_ADDR_AREA, x);
+    lcd_send_command(x + width - 1, 0);

     if (lcd_yuv_options & LCD_YUV_DITHER)
     {
         do
         {
-            lcd_send_command(R_Y_ADDR_AREA);
-            lcd_send_command(y);
-            lcd_send_command(y + 1);
-
-            /* NOP needed because on some c200s, the previous lcd_send_command
-               is interpreted as a separate command instead of part of
-               R_Y_ADDR_AREA. */
-            lcd_send_command(R_NOP);
+            lcd_send_command(R_Y_ADDR_AREA, y);
+            lcd_send_command(y + 1, 0);

             lcd_write_yuv420_lines_odither(yuv_src, width, stride, x, y);
             yuv_src[0] += stride << 1; /* Skip down two luma lines */
@@ -291,11 +271,8 @@ void lcd_blit_yuv(unsigned char * const src[3],
     {
         do
         {
-            lcd_send_command(R_Y_ADDR_AREA);
-            lcd_send_command(y);
-            lcd_send_command(y + 1);
-
-            lcd_send_command(R_NOP);
+            lcd_send_command(R_Y_ADDR_AREA, y);
+            lcd_send_command(y + 1, 0);

             lcd_write_yuv420_lines(yuv_src, width, stride);
             yuv_src[0] += stride << 1; /* Skip down two luma lines */
@@ -329,33 +306,24 @@ void lcd_update_rect(int x, int y, int width, int height)

     addr = &lcd_framebuffer[y][x];

-    if (width <= 1) {                    
-        lcd_send_command(R_ENTRY_MODE);  /* The X end address must be larger */
-        lcd_send_command(0x80);          /* that the X start address, so we */
-        lcd_send_command(R_X_ADDR_AREA); /* switch to vertical mode for */
-        lcd_send_command(x);             /* single column updates and set */
-        lcd_send_command(x + 1);         /* the window width to 2 */
+    if (width <= 1) {
+        /* The X end address must be larger than the X start address, so we
+         * switch to vertical mode for single column updates and set the
+         * window width to 2 */
+        lcd_send_command(R_ENTRY_MODE, 0x80);
+        lcd_send_command(R_X_ADDR_AREA, x);
+        lcd_send_command(x + 1, 0);
     } else {
-        lcd_send_command(R_ENTRY_MODE);
-        lcd_send_command(0x82);
-        lcd_send_command(R_X_ADDR_AREA);
-        lcd_send_command(x);
-        lcd_send_command(x + width - 1);
+        lcd_send_command(R_ENTRY_MODE, 0x82);
+        lcd_send_command(R_X_ADDR_AREA, x);
+        lcd_send_command(x + width - 1, 0);
     }

-    lcd_send_command(R_Y_ADDR_AREA);
-    lcd_send_command(y + 0x1a);
-    lcd_send_command(y + height - 1 + 0x1a);
-
-    /* NOP needed because on some c200s, the previous lcd_send_command is
-       interpreted as a separate command instead of part of R_Y_ADDR_AREA. */
-    lcd_send_command(R_NOP);
+    lcd_send_command(R_Y_ADDR_AREA, y + 0x1a);
+    lcd_send_command(y + height - 1 + 0x1a, 0);

     do {
-        int w = width;
-        do {
-            lcd_send_data(*addr++);
-        } while (--w > 0);
-        addr += LCD_WIDTH - width;
+        lcd_send_data(addr, width);
+        addr += LCD_WIDTH;
     } while (--height > 0);
 }