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);
}