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
diff --git a/firmware/export/config/sansafuze.h b/firmware/export/config/sansafuze.h
index a0ec8ef..6c8ba82 100644
--- a/firmware/export/config/sansafuze.h
+++ b/firmware/export/config/sansafuze.h
@@ -59,7 +59,7 @@
 */

 /* define this if you can flip your LCD */
-//#define HAVE_LCD_FLIP
+#define HAVE_LCD_FLIP

 /* define this if you can invert the colours on your LCD */
 #define HAVE_LCD_INVERT
diff --git a/firmware/export/config/sansafuzev2.h b/firmware/export/config/sansafuzev2.h
index d2c49f4..f3d8e08 100644
--- a/firmware/export/config/sansafuzev2.h
+++ b/firmware/export/config/sansafuzev2.h
@@ -56,7 +56,7 @@
 */

 /* define this if you can flip your LCD */
-//#define HAVE_LCD_FLIP
+#define HAVE_LCD_FLIP

 /* define this if you can invert the colours on your LCD */
 #define HAVE_LCD_INVERT
diff --git a/firmware/target/arm/as3525/lcd-fuze.c b/firmware/target/arm/as3525/lcd-fuze.c
index ef4791e..d7636f6 100644
--- a/firmware/target/arm/as3525/lcd-fuze.c
+++ b/firmware/target/arm/as3525/lcd-fuze.c
@@ -34,13 +34,14 @@
    HD66789R */
 static bool display_on = false; /* is the display turned on? */

-/* Flip Flag */
-static unsigned short r_entry_mode = R_ENTRY_MODE_HORZ_NORMAL;
-
 /* Reverse Flag */
-static unsigned short r_disp_control_rev = R_DISP_CONTROL_NORMAL;
+static int r_disp_control_rev = R_DISP_CONTROL_NORMAL;
+
+/* Flip flag */
+static int r_drv_output_control = R_DRV_OUTPUT_CONTROL_NORMAL;
+static int r_gate_scan_pos = R_GATE_SCAN_POS_NORMAL;

-static const int xoffset = 20;
+static int xoffset = 20;

 /*** hardware configuration ***/

@@ -62,15 +63,27 @@ void lcd_set_invert_display(bool yesno)
 }

 #ifdef HAVE_LCD_FLIP
-static bool display_flipped = false;
-
 /* turn the display upside down  */
 void lcd_set_flip(bool yesno)
 {
-    display_flipped = yesno;
+    if (yesno)
+    {
+        xoffset = 0;
+        r_drv_output_control = R_DRV_OUTPUT_CONTROL_FLIPPED;
+        r_gate_scan_pos = R_GATE_SCAN_POS_FLIPPED;
+    }
+    else
+    {
+        xoffset = 20;
+        r_drv_output_control = R_DRV_OUTPUT_CONTROL_NORMAL;
+        r_gate_scan_pos = R_GATE_SCAN_POS_NORMAL;
+    }

-    r_entry_mode = yesno ? R_ENTRY_MODE_HORZ_FLIPPED :
-                           R_ENTRY_MODE_HORZ_NORMAL;
+    if (display_on)
+    {
+        lcd_write_reg(R_GATE_SCAN_POS, r_gate_scan_pos);
+        lcd_write_reg(R_DRV_OUTPUT_CONTROL, r_drv_output_control);
+    }
 }
 #endif

@@ -89,9 +102,9 @@ void fuze_display_on(void)
     lcd_write_reg(R_POWER_CONTROL4, 0x60);

     lcd_write_reg(R_POWER_CONTROL4, 0x70);
-    lcd_write_reg(R_DRV_OUTPUT_CONTROL, 277);
+    lcd_write_reg(R_DRV_OUTPUT_CONTROL, r_drv_output_control);
     lcd_write_reg(R_DRV_WAVEFORM_CONTROL, (7<<8));
-    lcd_write_reg(R_ENTRY_MODE, r_entry_mode);
+    lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);
     lcd_write_reg(R_DISP_CONTROL2, 0x01);
     lcd_write_reg(R_FRAME_CYCLE_CONTROL, (1<<10));
     lcd_write_reg(R_EXT_DISP_IF_CONTROL, 0);
@@ -140,6 +153,8 @@ void lcd_enable(bool on)
         lcd_write_reg(R_POWER_CONTROL4, 112);
         lcd_write_reg(R_DISP_CONTROL1, 0x11);
         lcd_write_reg(R_DISP_CONTROL1, 0x13 | r_disp_control_rev);
+        lcd_write_reg(R_DRV_OUTPUT_CONTROL, r_drv_output_control);
+        lcd_write_reg(R_GATE_SCAN_POS, r_gate_scan_pos);
         display_on = true;
         lcd_update();      /* Resync display */
         send_event(LCD_EVENT_ACTIVATION, NULL);
@@ -173,15 +188,15 @@ static void lcd_window_x(int xmin, int xmax)
 {
     xmin += xoffset;
     xmax += xoffset;
-    lcd_write_reg(R_HORIZ_RAM_ADDR_POS + 2, (xmax << 8) | xmin);
-    lcd_write_reg(R_RAM_ADDR_SET - 1, xmin);
+    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)
 {
-    lcd_write_reg(R_VERT_RAM_ADDR_POS + 2, ymax);
-    lcd_write_reg(R_VERT_RAM_ADDR_POS + 3, ymin);
+    lcd_write_reg(0x47, ymax);
+    lcd_write_reg(0x48, ymin);
     lcd_write_reg(R_RAM_ADDR_SET, ymin);
 }

@@ -224,13 +239,7 @@ 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]);

-#ifdef HAVE_LCD_FLIP
-    lcd_write_reg(R_ENTRY_MODE,
-        display_flipped ? R_ENTRY_MODE_VIDEO_FLIPPED : R_ENTRY_MODE_VIDEO_NORMAL
-    );
-#else
-    lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VIDEO_NORMAL);
-#endif
+    lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VIDEO);

     lcd_window_x(x, x + width - 1);

@@ -278,7 +287,7 @@ void lcd_update(void)
     if (!display_on)
         return;

-    lcd_write_reg(R_ENTRY_MODE, r_entry_mode);
+    lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);

     lcd_window_x(0, LCD_WIDTH - 1);
     lcd_window_y(0, LCD_HEIGHT - 1);
@@ -316,7 +325,7 @@ void lcd_update_rect(int x, int y, int width, int height)
     if (y + height > LCD_HEIGHT)
         height = LCD_HEIGHT - y; /* clip bottom */

-    lcd_write_reg(R_ENTRY_MODE, r_entry_mode);
+    lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);

     /* we need to make x and width even to enable 32bit transfers */
     width = (width + (x & 1) + 1) & ~1;
diff --git a/firmware/target/arm/as3525/lcd-fuze.h b/firmware/target/arm/as3525/lcd-fuze.h
index 00bb960..50bec9b 100644
--- a/firmware/target/arm/as3525/lcd-fuze.h
+++ b/firmware/target/arm/as3525/lcd-fuze.h
@@ -41,16 +41,19 @@
 #define R_HORIZ_RAM_ADDR_POS    0x44
 #define R_VERT_RAM_ADDR_POS     0x45

-/* Flip Flag */
-#define R_ENTRY_MODE_HORZ_NORMAL 0x1030
-#define R_ENTRY_MODE_HORZ_FLIPPED 0x1000
-#define R_ENTRY_MODE_VIDEO_NORMAL 0x1038
-#define R_ENTRY_MODE_VIDEO_FLIPPED 0x1018
+#define R_ENTRY_MODE_HORZ   0x1030
+#define R_ENTRY_MODE_VIDEO  0x1038

 /* Reverse Flag */
 #define R_DISP_CONTROL_NORMAL 0x0004
 #define R_DISP_CONTROL_REV    0x0000

+#define R_DRV_OUTPUT_CONTROL_NORMAL     0x115
+#define R_DRV_OUTPUT_CONTROL_FLIPPED    0x215
+
+#define R_GATE_SCAN_POS_NORMAL  0
+#define R_GATE_SCAN_POS_FLIPPED 18
+
 void lcd_write_cmd(int16_t cmd);
 void lcd_write_reg(int reg, int value);
 void fuze_display_on(void);