summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525')
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c12
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/backlight-target.h4
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c85
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c429
4 files changed, 65 insertions, 465 deletions
diff --git a/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
index f036792fc0..858e9aed49 100644
--- a/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
+++ b/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
@@ -26,8 +26,12 @@
26#include "ascodec-target.h" 26#include "ascodec-target.h"
27#include "as3514.h" 27#include "as3514.h"
28 28
29/* TODO: This file is copy & pasted from backlight-e200v2-fuze.c, as I think 29bool _backlight_init(void)
30 * it'll be the same for c200v2; prove it */ 30{
31 GPIOA_DIR |= 1<<5;
32 return true;
33}
34
31void _backlight_set_brightness(int brightness) 35void _backlight_set_brightness(int brightness)
32{ 36{
33 if (brightness > 0) 37 if (brightness > 0)
@@ -41,12 +45,12 @@ void _backlight_on(void)
41#ifdef HAVE_LCD_ENABLE 45#ifdef HAVE_LCD_ENABLE
42 lcd_enable(true); /* power on lcd + visible display */ 46 lcd_enable(true); /* power on lcd + visible display */
43#endif 47#endif
44 ascodec_write(AS3514_DCDC15, backlight_brightness); 48 GPIOA_PIN(5) = 1<<5;
45} 49}
46 50
47void _backlight_off(void) 51void _backlight_off(void)
48{ 52{
49 ascodec_write(AS3514_DCDC15, 0x0); 53 GPIOA_PIN(5) = 0;
50#ifdef HAVE_LCD_ENABLE 54#ifdef HAVE_LCD_ENABLE
51 lcd_enable(false); /* power off visible display */ 55 lcd_enable(false); /* power off visible display */
52#endif 56#endif
diff --git a/firmware/target/arm/as3525/sansa-c200v2/backlight-target.h b/firmware/target/arm/as3525/sansa-c200v2/backlight-target.h
index e8a60fa881..06076dd39f 100644
--- a/firmware/target/arm/as3525/sansa-c200v2/backlight-target.h
+++ b/firmware/target/arm/as3525/sansa-c200v2/backlight-target.h
@@ -21,7 +21,9 @@
21#ifndef BACKLIGHT_TARGET_H 21#ifndef BACKLIGHT_TARGET_H
22#define BACKLIGHT_TARGET_H 22#define BACKLIGHT_TARGET_H
23 23
24#define _backlight_init() true 24#include <stdbool.h>
25
26bool _backlight_init(void);
25void _backlight_on(void); 27void _backlight_on(void);
26void _backlight_off(void); 28void _backlight_off(void);
27void _backlight_set_brightness(int brightness); 29void _backlight_set_brightness(int brightness);
diff --git a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c
index 86a6eb0c73..d3504c97e9 100644
--- a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c
+++ b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c
@@ -19,47 +19,70 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22/* Taken from button-h10.c by Barry Wardell and reverse engineering by MrH. */
23
24#include "system.h" 22#include "system.h"
23#include "button-target.h"
25#include "button.h" 24#include "button.h"
26#include "backlight.h" 25#include "backlight.h"
27#include "powermgmt.h" 26#include "powermgmt.h"
28 27
29 28
30#ifndef BOOTLOADER 29unsigned short _dbop_din = 0;
31/* Buttons */ 30
31/* in the lcd driver */
32extern bool lcd_button_support(void);
33
32static bool hold_button = false; 34static bool hold_button = false;
35#ifndef BOOTLOADER
33static bool hold_button_old = false; 36static bool hold_button_old = false;
34#define _button_hold() hold_button 37#endif
35#else
36#define _button_hold() false /* FIXME */
37#endif /* BOOTLOADER */
38static int int_btn = BUTTON_NONE;
39 38
40void button_init_device(void) 39void button_init_device(void)
41{ 40{
41 GPIOA_DIR &= ~(1<<3);
42} 42}
43 43
44bool button_hold(void) 44bool button_hold(void)
45{ 45{
46 return _button_hold(); 46 return hold_button;
47}
48
49static void button_read_dbop(void)
50{
51 /* Set up dbop for input */
52 DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */
53 DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */
54 DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */
55 DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */
56
57 int i = 50;
58 while(i--) asm volatile ("nop\n");
59
60 DBOP_CTRL |= (1<<15); /* start read */
61 while (!(DBOP_STAT & (1<<16))); /* wait for valid data */
62
63 _dbop_din = DBOP_DIN; /* Read dbop data*/
64
65 /* Reset dbop for output */
66 DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */
67 DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */
68 DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */
69 DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */
47} 70}
48 71
49/* device buttons */ 72/*
50void button_int(void) 73 * Get button pressed from hardware
74 */
75int button_read_device(void)
51{ 76{
52 int delay = 0x50; 77 int delay;
53 int dir_save_c = 0; 78 int dir_save_c = 0;
54 int afsel_save_c = 0; 79 int afsel_save_c = 0;
55 80 int btn = BUTTON_NONE;
56 int_btn = BUTTON_NONE;
57 81
58 /* Save the current direction and afsel */ 82 /* Save the current direction and afsel */
59 dir_save_c = GPIOC_DIR; 83 dir_save_c = GPIOC_DIR;
60 afsel_save_c = GPIOC_AFSEL; 84 afsel_save_c = GPIOC_AFSEL;
61 85
62 GPIOA_DIR &= ~(1<<3);
63 GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3); 86 GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3);
64 GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3); 87 GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3);
65 88
@@ -72,32 +95,32 @@ void button_int(void)
72 GPIOC_PIN(3) = (1<<3); 95 GPIOC_PIN(3) = (1<<3);
73 GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3); 96 GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3);
74 97
75 while(delay--); 98 delay = 100;
99 while(delay--)
100 asm volatile("nop\n");
76 101
77 /* direct GPIO connections */ 102 /* direct GPIO connections */
78 if (GPIOA_PIN(3)) 103 if (GPIOA_PIN(3))
79 int_btn |= BUTTON_POWER; 104 btn |= BUTTON_POWER;
80 if (!GPIOC_PIN(6)) 105 if (!GPIOC_PIN(6))
81 int_btn |= BUTTON_RIGHT; 106 btn |= BUTTON_RIGHT;
82 if (!GPIOC_PIN(5)) 107 if (!GPIOC_PIN(5))
83 int_btn |= BUTTON_UP; 108 btn |= BUTTON_UP;
84 if (!GPIOC_PIN(4)) 109 if (!GPIOC_PIN(4))
85 int_btn |= BUTTON_SELECT; 110 btn |= BUTTON_SELECT;
86 if (!GPIOC_PIN(3)) 111 if (!GPIOC_PIN(3))
87 int_btn |= BUTTON_DOWN; 112 btn |= BUTTON_DOWN;
88 113
89 /* return to settings needed for lcd */ 114 /* return to settings needed for lcd */
90 GPIOC_DIR = dir_save_c; 115 GPIOC_DIR = dir_save_c;
91 GPIOC_AFSEL = afsel_save_c; 116 GPIOC_AFSEL = afsel_save_c;
92}
93 117
94/* 118 if(lcd_button_support())
95 * Get button pressed from hardware 119 button_read_dbop();
96 */ 120
97int button_read_device(void) 121 if(_dbop_din & (1<<6))
98{ 122 btn |= BUTTON_LEFT;
99 /* Read buttons directly */ 123
100 button_int();
101#ifndef BOOTLOADER 124#ifndef BOOTLOADER
102 /* light handling */ 125 /* light handling */
103 if (hold_button != hold_button_old) 126 if (hold_button != hold_button_old)
@@ -107,5 +130,5 @@ int button_read_device(void)
107 } 130 }
108#endif /* BOOTLOADER */ 131#endif /* BOOTLOADER */
109 132
110 return int_btn; 133 return btn;
111} 134}
diff --git a/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c
deleted file mode 100644
index e16b082ce5..0000000000
--- a/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c
+++ /dev/null
@@ -1,429 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-e200v2.c 19453 2008-12-16 02:50:39Z saratoga $
9 *
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/* FIXME: Copied from e200v2 lcd driver, unlikely to work, but maybe */
23
24#include "config.h"
25
26#include "cpu.h"
27#include "lcd.h"
28#include "kernel.h"
29#include "thread.h"
30#include <string.h>
31#include <stdlib.h>
32#include "file.h"
33#include "debug.h"
34#include "system.h"
35#include "font.h"
36#include "bidi.h"
37#include "clock-target.h"
38
39static bool display_on = false; /* is the display turned on? */
40static bool display_flipped = false;
41static int y_offset = 0; /* needed for flip */
42
43/* register defines */
44#define R_START_OSC 0x00
45#define R_DRV_OUTPUT_CONTROL 0x01
46#define R_DRV_WAVEFORM_CONTROL 0x02
47#define R_ENTRY_MODE 0x03
48#define R_COMPARE_REG1 0x04
49#define R_COMPARE_REG2 0x05
50
51#define R_DISP_CONTROL1 0x07
52#define R_DISP_CONTROL2 0x08
53#define R_DISP_CONTROL3 0x09
54
55#define R_FRAME_CYCLE_CONTROL 0x0b
56#define R_EXT_DISP_IF_CONTROL 0x0c
57
58#define R_POWER_CONTROL1 0x10
59#define R_POWER_CONTROL2 0x11
60#define R_POWER_CONTROL3 0x12
61#define R_POWER_CONTROL4 0x13
62
63#define R_RAM_ADDR_SET 0x21
64#define R_WRITE_DATA_2_GRAM 0x22
65
66#define R_GAMMA_FINE_ADJ_POS1 0x30
67#define R_GAMMA_FINE_ADJ_POS2 0x31
68#define R_GAMMA_FINE_ADJ_POS3 0x32
69#define R_GAMMA_GRAD_ADJ_POS 0x33
70
71#define R_GAMMA_FINE_ADJ_NEG1 0x34
72#define R_GAMMA_FINE_ADJ_NEG2 0x35
73#define R_GAMMA_FINE_ADJ_NEG3 0x36
74#define R_GAMMA_GRAD_ADJ_NEG 0x37
75
76#define R_GAMMA_AMP_ADJ_RES_POS 0x38
77#define R_GAMMA_AMP_AVG_ADJ_RES_NEG 0x39
78
79#define R_GATE_SCAN_POS 0x40
80#define R_VERT_SCROLL_CONTROL 0x41
81#define R_1ST_SCR_DRV_POS 0x42
82#define R_2ND_SCR_DRV_POS 0x43
83#define R_HORIZ_RAM_ADDR_POS 0x44
84#define R_VERT_RAM_ADDR_POS 0x45
85
86#define R_ENTRY_MODE_HORZ 0x7030
87#define R_ENTRY_MODE_VERT 0x7038
88#define R_ENTRY_MODE_SOLID_VERT 0x1038
89
90/* TODO: Implement this function */
91static void lcd_delay(int x)
92{
93 /* This is just arbitrary - the OF does something more complex */
94 x *= 1024;
95 while (x--);
96}
97
98/* DBOP initialisation, do what OF does */
99static void ams3525_dbop_init(void)
100{
101 CGU_DBOP = (1<<3) | AS3525_DBOP_DIV;
102
103 DBOP_TIMPOL_01 = 0xe167e167;
104 DBOP_TIMPOL_23 = 0xe167006e;
105 DBOP_CTRL = 0x41008;
106
107 GPIOB_AFSEL = 0xfc;
108 GPIOC_AFSEL = 0xff;
109
110 DBOP_TIMPOL_23 = 0x6000e;
111 DBOP_CTRL = 0x51008;
112 DBOP_TIMPOL_01 = 0x6e167;
113 DBOP_TIMPOL_23 = 0xa167e06f;
114
115 /* TODO: The OF calls some other functions here, but maybe not important */
116}
117
118
119static void lcd_write_cmd(int cmd)
120{
121 /* Write register */
122 DBOP_CTRL &= ~(1<<14);
123
124 DBOP_TIMPOL_23 = 0xa167006e;
125
126 DBOP_DOUT = cmd;
127
128 /* Wait for fifo to empty */
129 while ((DBOP_STAT & (1<<10)) == 0);
130
131 DBOP_TIMPOL_23 = 0xa167e06f;
132}
133
134void lcd_write_data(const fb_data* p_bytes, int count)
135{
136 while (count--)
137 {
138 DBOP_DOUT = *p_bytes++;
139
140 /* Wait for fifo to empty */
141 while ((DBOP_STAT & (1<<10)) == 0);
142 }
143}
144
145static void lcd_write_reg(int reg, int value)
146{
147 unsigned short data = value;
148
149 lcd_write_cmd(reg);
150 lcd_write_data(&data, 1);
151}
152
153/*** hardware configuration ***/
154
155void lcd_set_contrast(int val)
156{
157 (void)val;
158}
159
160void lcd_set_invert_display(bool yesno)
161{
162 (void)yesno;
163}
164
165static void flip_lcd(bool yesno)
166{
167 (void)yesno;
168}
169
170
171/* turn the display upside down (call lcd_update() afterwards) */
172void lcd_set_flip(bool yesno)
173{
174 display_flipped = yesno;
175 y_offset = yesno ? 4 : 0; /* FIXME: Is a y_offset needed? */
176
177 if (display_on)
178 flip_lcd(yesno);
179}
180
181static void _display_on(void)
182{
183 /* Initialisation the display the same way as the original firmware */
184
185 lcd_write_reg(R_START_OSC, 0x0001); /* Start Oscilation */
186
187 lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x011b); /* 220 lines, GS=0, SS=1 */
188
189 /* B/C = 1: n-line inversion form
190 * EOR = 1: polarity inversion occurs by applying an EOR to odd/even
191 * frame select signal and an n-line inversion signal.
192 * FLD = 01b: 1 field interlaced scan, external display iface */
193 lcd_write_reg(R_DRV_WAVEFORM_CONTROL, 0x0700);
194
195 /* Address counter updated in horizontal direction; left to right;
196 * vertical increment horizontal increment.
197 * data format for 8bit transfer or spi = 65k (5,6,5) */
198 lcd_write_reg(R_ENTRY_MODE, 0x0030);
199
200 /* Replace data on writing to GRAM */
201 lcd_write_reg(R_COMPARE_REG1, 0);
202 lcd_write_reg(R_COMPARE_REG2, 0);
203
204 lcd_write_reg(R_DISP_CONTROL1, 0x0000); /* GON = 0, DTE = 0, D1-0 = 00b */
205
206 /* Front porch lines: 2; Back porch lines: 2; */
207 lcd_write_reg(R_DISP_CONTROL2, 0x0203);
208
209 /* Scan cycle = 0 frames */
210 lcd_write_reg(R_DISP_CONTROL3, 0x0000);
211
212 /* 16 clocks */
213 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0000);
214
215 /* 18-bit RGB interface (one transfer/pixel)
216 * internal clock operation;
217 * System interface/VSYNC interface */
218 lcd_write_reg(R_EXT_DISP_IF_CONTROL, 0x0000);
219
220
221 /* zero everything*/
222 lcd_write_reg(R_POWER_CONTROL1, 0x0000); /* STB = 0, SLP = 0 */
223
224 lcd_delay(10);
225
226 /* initialise power supply */
227
228 /* DC12-10 = 000b: Step-up1 = clock/8,
229 * DC02-00 = 000b: Step-up2 = clock/16,
230 * VC2-0 = 010b: VciOUT = 0.87 * VciLVL */
231 lcd_write_reg(R_POWER_CONTROL2, 0x0002);
232
233 /* VRH3-0 = 1000b: Vreg1OUT = REGP * 1.90 */
234 lcd_write_reg(R_POWER_CONTROL3, 0x0008);
235
236 lcd_delay(40);
237
238 lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG = 0 */
239
240 /* This register is unknown */
241 lcd_write_reg(0x56, 0x80f);
242
243
244 lcd_write_reg(R_POWER_CONTROL1, 0x4140);
245
246 lcd_delay(10);
247
248 lcd_write_reg(R_POWER_CONTROL2, 0x0000);
249 lcd_write_reg(R_POWER_CONTROL3, 0x0013);
250
251 lcd_delay(20);
252
253 lcd_write_reg(R_POWER_CONTROL4, 0x6d0e);
254
255 lcd_delay(20);
256
257 lcd_write_reg(R_POWER_CONTROL4, 0x6d0e);
258
259 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0002);
260 lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0707);
261 lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0182);
262 lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x0203);
263 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0706);
264 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 0x0006);
265 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0706);
266 lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 0x0000);
267 lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS, 0x030f);
268 lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG, 0x0f08);
269
270
271 lcd_write_reg(R_RAM_ADDR_SET, 0);
272 lcd_write_reg(R_GATE_SCAN_POS, 0);
273 lcd_write_reg(R_VERT_SCROLL_CONTROL, 0);
274
275 lcd_write_reg(R_1ST_SCR_DRV_POS, (LCD_HEIGHT-1) << 8);
276 lcd_write_reg(R_2ND_SCR_DRV_POS, (LCD_HEIGHT-1) << 8);
277
278 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_WIDTH-1) << 8);
279 lcd_write_reg(R_VERT_RAM_ADDR_POS, (LCD_HEIGHT-1) << 8);
280
281
282 lcd_write_reg(R_DISP_CONTROL1, 0x0037);
283
284 display_on=true; /* must be done before calling lcd_update() */
285 lcd_update();
286}
287
288/* LCD init */
289void lcd_init_device(void)
290{
291 ams3525_dbop_init();
292
293 /* Init GPIOs the same as the OF */
294
295 GPIOA_DIR |= (1<<5);
296 GPIOA_PIN(5) = 0;
297
298 GPIOA_PIN(3) = (1<<3);
299
300 GPIOA_DIR |= (3<<3);
301
302 GPIOA_PIN(3) = (1<<3);
303
304 GPIOA_PIN(4) = 0; /*c80b0040 := 0;*/
305
306 GPIOA_DIR |= (1<<7);
307 GPIOA_PIN(7) = 0;
308
309 lcd_delay(1);
310
311 GPIOA_PIN(5) = (1<<5);
312
313 lcd_delay(1);
314
315 _display_on();
316}
317
318void lcd_enable(bool on)
319{
320 if(display_on!=on)
321 {
322 if(on)
323 {
324 _display_on();
325 lcd_activation_call_hook();
326 }
327 else
328 {
329 /* TODO: Implement off sequence */
330 display_on=false;
331 }
332 }
333}
334
335bool lcd_active(void)
336{
337 return display_on;
338}
339
340void lcd_sleep(void)
341{
342 /* TODO */
343}
344
345/*** update functions ***/
346
347/* Performance function to blit a YUV bitmap directly to the LCD
348 * src_x, src_y, width and height should be even
349 * x, y, width and height have to be within LCD bounds
350 */
351void lcd_blit_yuv(unsigned char * const src[3],
352 int src_x, int src_y, int stride,
353 int x, int y, int width, int height)
354{
355 (void)src;
356 (void)src_x;
357 (void)src_y;
358 (void)stride;
359 (void)x;
360 (void)y;
361 (void)width;
362 (void)height;
363}
364
365/* Update the display.
366 This must be called after all other LCD functions that change the display. */
367void lcd_update(void)
368{
369 if (!display_on)
370 return;
371
372 lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);
373
374 /* Set start position and window */
375 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_WIDTH-1) << 8);
376 lcd_write_reg(R_VERT_RAM_ADDR_POS,
377 ((y_offset + LCD_HEIGHT-1) << 8) | y_offset);
378 lcd_write_reg(R_RAM_ADDR_SET, (y_offset) << 8);
379
380 lcd_write_cmd(R_WRITE_DATA_2_GRAM);
381
382 lcd_write_data((unsigned short *)lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT);
383
384} /* lcd_update */
385
386
387/* Update a fraction of the display. */
388void lcd_update_rect(int x, int y, int width, int height)
389{
390 int ymax;
391 const unsigned short *ptr;
392
393 if (!display_on)
394 return;
395
396 if (x + width > LCD_WIDTH)
397 width = LCD_WIDTH - x; /* Clip right */
398 if (x < 0)
399 width += x, x = 0; /* Clip left */
400 if (width <= 0)
401 return; /* nothing left to do */
402
403 ymax = y + height;
404 if (ymax > LCD_HEIGHT)
405 ymax = LCD_HEIGHT; /* Clip bottom */
406 if (y < 0)
407 y = 0; /* Clip top */
408 if (y >= ymax)
409 return; /* nothing left to do */
410
411 lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);
412 /* Set start position and window */
413 lcd_write_reg(R_HORIZ_RAM_ADDR_POS,
414 ((x + width-1) << 8) | x);
415 lcd_write_reg(R_VERT_RAM_ADDR_POS,
416 ((y_offset + y + height - 1) << 8) | (y_offset + y));
417 lcd_write_reg(R_RAM_ADDR_SET, ((y + y_offset) << 8) | x);
418
419 lcd_write_cmd(R_WRITE_DATA_2_GRAM);
420
421 ptr = (unsigned short *)&lcd_framebuffer[y][x];
422
423 do
424 {
425 lcd_write_data(ptr, width);
426 ptr += LCD_WIDTH;
427 }
428 while (++y < ymax);
429} /* lcd_update_rect */