00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include <stdint.h>
00048 #include <stdbool.h>
00049 #include <stddef.h>
00050 #include "compiler.h"
00051 #include "et024006dhu.h"
00052 #include "conf_et024006dhu.h"
00053
00054 #include "smc.h"
00055 #include "board.h"
00056 #include "gpio.h"
00057 #include "cycle_counter.h"
00058
00059
00060
00061
00062
00063 #define ET024006_DMA_USAGE_LIMIT 10
00064
00065 #define ET024006_ID 0x70
00066 #define ET024006_BS0 0x04
00067 #define ET024006_RS 0x02
00068 #define ET024006_RW 0x01
00069
00070
00071 #define HIMAX_DISPMODECTRL 0x01
00072 #define HIMAX_INVON 2
00073 #define HIMAX_NORON 1
00074
00075 #define HIMAX_COL_ADDR_START2 0x02
00076 #define HIMAX_COL_ADDR_START1 0x03
00077 #define HIMAX_COL_ADDR_END2 0x04
00078 #define HIMAX_COL_ADDR_END1 0x05
00079 #define HIMAX_ROW_ADDR_START2 0x06
00080 #define HIMAX_ROW_ADDR_START1 0x07
00081 #define HIMAX_ROW_ADDR_END2 0x08
00082 #define HIMAX_ROW_ADDR_END1 0x09
00083 #define HIMAX_PA_START_ROW_HB 0x0A
00084 #define HIMAX_PA_START_ROW_LB 0x0B
00085 #define HIMAX_PA_END_ROW_HB 0x0C
00086 #define HIMAX_PA_END_ROW_LB 0x0D
00087 #define HIMAX_VS_TFA_HB 0x0E
00088 #define HIMAX_VS_TFA_LB 0x0F
00089 #define HIMAX_VS_VSA_HB 0x10
00090 #define HIMAX_VS_VSA_LB 0x11
00091 #define HIMAX_VS_BFA_HB 0x12
00092 #define HIMAX_VS_BFA_LB 0x13
00093 #define HIMAX_VS_VSP_HB 0x14
00094 #define HIMAX_VS_VSP_LB 0x15
00095
00096
00097 #define HIMAX_MEMACCESSCTRL 0x16
00098 #define HIMAX_MY 7
00099 #define HIMAX_MX 6
00100 #define HIMAX_MV 5
00101 #define HIMAX_BGR 3
00102
00103 #define HIMAX_GATE_SCAN_CTRL 0x18
00104 #define HIMAX_SCROLL_ON 0x2
00105
00106 #define HIMAX_OSCCTRL1 0x19
00107 #define HIMAX_OSC_EN 0 // Default 0
00108
00109 #define HIMAX_OSCCTRL2 0x1A
00110
00111 #define HIMAX_POWERCTRL1 0x1B
00112 #define HIMAX_GASENB 7 // Default 0
00113 #define HIMAX_PON 4 // Default 0
00114 #define HIMAX_DK 3 // Default 1
00115 #define HIMAX_XDK 2 // Default 0
00116 #define HIMAX_VTFT_TRI 1 // Default 0
00117 #define HIMAX_STB 0 // Default 1
00118
00119 #define HIMAX_POWERCTRL2 0x1c
00120 #define HIMAX_AP2 2 // Default 0
00121 #define HIMAX_AP1 1 // Default 0
00122 #define HIMAX_AP0 0 // Default 0
00123
00124 #define HIMAX_POWERCTRL3 0x1D
00125 #define HIMAX_POWERCTRL4 0x1E
00126 #define HIMAX_POWERCTRL5 0x1F
00127 #define HIMAX_POWERCTRL6 0x20
00128
00129 #define HIMAX_SRAMWRITE 0x22
00130
00131 #define HIMAX_CYCLECTRL1_x 0x23
00132 #define HIMAX_CYCLECTRL2_x 0x24
00133 #define HIMAX_CYCLECTRL3_x 0x25
00134
00135 #define HIMAX_DISPCTRL1 0x26
00136 #define HIMAX_PT1 7 // Default 0
00137 #define HIMAX_PT0 6 // Default 0
00138 #define HIMAX_GON 5 // Default 1
00139 #define HIMAX_DTE 4 // Default 0
00140 #define HIMAX_D1 3 // Default 0
00141 #define HIMAX_D0 2 // Default 0
00142
00143 #define HIMAX_DISPCTRL2 0x27
00144 #define HIMAX_DISPCTRL3 0x28
00145 #define HIMAX_DISPCTRL4 0x29
00146 #define HIMAX_DISPCTRL5 0x2A
00147 #define HIMAX_DISPCTRL6 0x2C
00148 #define HIMAX_DISPCTRL7 0x2D
00149
00150 #define HIMAX_DISPCTRL9 0x35
00151 #define HIMAX_DISPCTRL10 0x36
00152
00153
00154 #define HIMAX_CYCLECTRL1 0x3A//11
00155 #define HIMAX_CYCLECTRL2 0x3B//12
00156 #define HIMAX_CYCLECTRL3 0x3C//13
00157 #define HIMAX_CYCLECTRL4 0x3D//14
00158 #define HIMAX_CYCLECTRL5 0x3E//15
00159 #define HIMAX_CYCLECTRL6 0x40//16
00160 #define HIMAX_CYCLECTRL14 0x41//17
00161
00162 #define HIMAX_VCOMCTRL1 0x43
00163 #define HIMAX_VCOMG 7 // Default 0
00164
00165 #define HIMAX_VCOMCTRL2 0x44
00166 #define HIMAX_VCOMCTRL3 0x45
00167
00168 #define HIMAX_GAMMACTRL1 0x46
00169 #define HIMAX_GAMMACTRL2 0x47
00170 #define HIMAX_GAMMACTRL3 0x48
00171 #define HIMAX_GAMMACTRL4 0x49
00172 #define HIMAX_GAMMACTRL5 0x4A
00173 #define HIMAX_GAMMACTRL6 0x4B
00174 #define HIMAX_GAMMACTRL7 0x4C
00175 #define HIMAX_GAMMACTRL8 0x4D
00176 #define HIMAX_GAMMACTRL9 0x4E
00177 #define HIMAX_GAMMACTRL10 0x4F
00178 #define HIMAX_GAMMACTRL11 0x50
00179 #define HIMAX_GAMMACTRL12 0x51
00180
00181 #define HIMAX_ID_CODE 0x67
00182 #define HIMAX_ID_CODE_VALUE 0x47
00183
00184 #define HIMAX_INTERNAL28 0x70
00185 #define HIMAX_TEON 3
00186
00187 #define HIMAX_SAP 0x90
00188 #define HIMAX_OSCCTRL3 0x93
00189 #define HIMAX_DISPCTRL8 0x90
00190
00191 const unsigned char FONT6x8[97][8] = {
00192 {0x06,0x08,0x08,0x00,0x00,0x00,0x00,0x00},
00193 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00194 {0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00},
00195 {0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00},
00196 {0x50,0x50,0xF8,0x50,0xF8,0x50,0x50,0x00},
00197 {0x20,0x78,0xA0,0x70,0x28,0xF0,0x20,0x00},
00198 {0xC0,0xC8,0x10,0x20,0x40,0x98,0x18,0x00},
00199 {0x40,0xA0,0xA0,0x40,0xA8,0x90,0x68,0x00},
00200 {0x30,0x30,0x20,0x40,0x00,0x00,0x00,0x00},
00201 {0x10,0x20,0x40,0x40,0x40,0x20,0x10,0x00},
00202 {0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x00},
00203 {0x00,0x20,0xA8,0x70,0x70,0xA8,0x20,0x00},
00204 {0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00},
00205 {0x00,0x00,0x00,0x00,0x30,0x30,0x20,0x40},
00206 {0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00},
00207 {0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00},
00208 {0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00},
00209 {0x70,0x88,0x88,0xA8,0x88,0x88,0x70,0x00},
00210 {0x20,0x60,0x20,0x20,0x20,0x20,0x70,0x00},
00211 {0x70,0x88,0x08,0x70,0x80,0x80,0xF8,0x00},
00212 {0xF8,0x08,0x10,0x30,0x08,0x88,0x70,0x00},
00213 {0x10,0x30,0x50,0x90,0xF8,0x10,0x10,0x00},
00214 {0xF8,0x80,0xF0,0x08,0x08,0x88,0x70,0x00},
00215 {0x38,0x40,0x80,0xF0,0x88,0x88,0x70,0x00},
00216 {0xF8,0x08,0x08,0x10,0x20,0x40,0x80,0x00},
00217 {0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00},
00218 {0x70,0x88,0x88,0x78,0x08,0x10,0xE0,0x00},
00219 {0x00,0x00,0x20,0x00,0x20,0x00,0x00,0x00},
00220 {0x00,0x00,0x20,0x00,0x20,0x20,0x40,0x00},
00221 {0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00},
00222 {0x00,0x00,0xF8,0x00,0xF8,0x00,0x00,0x00},
00223 {0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00},
00224 {0x70,0x88,0x08,0x30,0x20,0x00,0x20,0x00},
00225 {0x70,0x88,0xA8,0xB8,0xB0,0x80,0x78,0x00},
00226 {0x20,0x50,0x88,0x88,0xF8,0x88,0x88,0x00},
00227 {0xF0,0x88,0x88,0xF0,0x88,0x88,0xF0,0x00},
00228 {0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00},
00229 {0xF0,0x88,0x88,0x88,0x88,0x88,0xF0,0x00},
00230 {0xF8,0x80,0x80,0xF0,0x80,0x80,0xF8,0x00},
00231 {0xF8,0x80,0x80,0xF0,0x80,0x80,0x80,0x00},
00232 {0x78,0x88,0x80,0x80,0x98,0x88,0x78,0x00},
00233 {0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00},
00234 {0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00},
00235 {0x38,0x10,0x10,0x10,0x10,0x90,0x60,0x00},
00236 {0x88,0x90,0xA0,0xC0,0xA0,0x90,0x88,0x00},
00237 {0x80,0x80,0x80,0x80,0x80,0x80,0xF8,0x00},
00238 {0x88,0xD8,0xA8,0xA8,0xA8,0x88,0x88,0x00},
00239 {0x88,0x88,0xC8,0xA8,0x98,0x88,0x88,0x00},
00240 {0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00},
00241 {0xF0,0x88,0x88,0xF0,0x80,0x80,0x80,0x00},
00242 {0x70,0x88,0x88,0x88,0xA8,0x90,0x68,0x00},
00243 {0xF0,0x88,0x88,0xF0,0xA0,0x90,0x88,0x00},
00244 {0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00},
00245 {0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x00},
00246 {0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00},
00247 {0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00},
00248 {0x88,0x88,0x88,0xA8,0xA8,0xA8,0x50,0x00},
00249 {0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00},
00250 {0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00},
00251 {0xF8,0x08,0x10,0x70,0x40,0x80,0xF8,0x00},
00252 {0x78,0x40,0x40,0x40,0x40,0x40,0x78,0x00},
00253 {0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00},
00254 {0x78,0x08,0x08,0x08,0x08,0x08,0x78,0x00},
00255 {0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00},
00256 {0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00},
00257 {0x60,0x60,0x20,0x10,0x00,0x00,0x00,0x00},
00258 {0x00,0x00,0x60,0x10,0x70,0x90,0x78,0x00},
00259 {0x80,0x80,0xB0,0xC8,0x88,0xC8,0xB0,0x00},
00260 {0x00,0x00,0x70,0x88,0x80,0x88,0x70,0x00},
00261 {0x08,0x08,0x68,0x98,0x88,0x98,0x68,0x00},
00262 {0x00,0x00,0x70,0x88,0xF8,0x80,0x70,0x00},
00263 {0x10,0x28,0x20,0x70,0x20,0x20,0x20,0x00},
00264 {0x00,0x00,0x70,0x98,0x98,0x68,0x08,0x70},
00265 {0x80,0x80,0xB0,0xC8,0x88,0x88,0x88,0x00},
00266 {0x20,0x00,0x60,0x20,0x20,0x20,0x70,0x00},
00267 {0x10,0x00,0x10,0x10,0x10,0x90,0x60,0x00},
00268 {0x80,0x80,0x90,0xA0,0xC0,0xA0,0x90,0x00},
00269 {0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00},
00270 {0x00,0x00,0xD0,0xA8,0xA8,0xA8,0xA8,0x00},
00271 {0x00,0x00,0xB0,0xC8,0x88,0x88,0x88,0x00},
00272 {0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00},
00273 {0x00,0x00,0xB0,0xC8,0xC8,0xB0,0x80,0x80},
00274 {0x00,0x00,0x68,0x98,0x98,0x68,0x08,0x08},
00275 {0x00,0x00,0xB0,0xC8,0x80,0x80,0x80,0x00},
00276 {0x00,0x00,0x78,0x80,0x70,0x08,0xF0,0x00},
00277 {0x20,0x20,0xF8,0x20,0x20,0x28,0x10,0x00},
00278 {0x00,0x00,0x88,0x88,0x88,0x98,0x68,0x00},
00279 {0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00},
00280 {0x00,0x00,0x88,0x88,0xA8,0xA8,0x50,0x00},
00281 {0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00},
00282 {0x00,0x00,0x88,0x88,0x78,0x08,0x88,0x70},
00283 {0x00,0x00,0xF8,0x10,0x20,0x40,0xF8,0x00},
00284 {0x10,0x20,0x20,0x40,0x20,0x20,0x10,0x00},
00285 {0x20,0x20,0x20,0x00,0x20,0x20,0x20,0x00},
00286 {0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00},
00287 {0x40,0xA8,0x10,0x00,0x00,0x00,0x00,0x00},
00288 {0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00}
00289 };
00290
00291 const unsigned char FONT8x8[97][8] = {
00292 {0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00},
00293 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00294 {0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00},
00295 {0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00},
00296 {0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00},
00297 {0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00},
00298 {0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00},
00299 {0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00},
00300 {0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00},
00301 {0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00},
00302 {0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00},
00303 {0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00},
00304 {0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00},
00305 {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30},
00306 {0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00},
00307 {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00},
00308 {0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00},
00309 {0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00},
00310 {0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00},
00311 {0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00},
00312 {0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00},
00313 {0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00},
00314 {0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00},
00315 {0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00},
00316 {0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00},
00317 {0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00},
00318 {0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00},
00319 {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00},
00320 {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30},
00321 {0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00},
00322 {0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00},
00323 {0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00},
00324 {0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00},
00325 {0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00},
00326 {0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00},
00327 {0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00},
00328 {0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00},
00329 {0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00},
00330 {0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00},
00331 {0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00},
00332 {0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00},
00333 {0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00},
00334 {0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00},
00335 {0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00},
00336 {0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00},
00337 {0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00},
00338 {0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00},
00339 {0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00},
00340 {0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00},
00341 {0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00},
00342 {0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00},
00343 {0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00},
00344 {0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00},
00345 {0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00},
00346 {0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00},
00347 {0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00},
00348 {0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00},
00349 {0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00},
00350 {0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00},
00351 {0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00},
00352 {0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00},
00353 {0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00},
00354 {0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00},
00355 {0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00},
00356 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},
00357 {0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00},
00358 {0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00},
00359 {0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00},
00360 {0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00},
00361 {0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00},
00362 {0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00},
00363 {0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00},
00364 {0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C},
00365 {0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00},
00366 {0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00},
00367 {0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C},
00368 {0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00},
00369 {0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00},
00370 {0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00},
00371 {0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00},
00372 {0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00},
00373 {0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78},
00374 {0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F},
00375 {0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00},
00376 {0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00},
00377 {0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00},
00378 {0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00},
00379 {0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00},
00380 {0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00},
00381 {0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00},
00382 {0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C},
00383 {0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00},
00384 {0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00},
00385 {0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00},
00386 {0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00},
00387 {0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00},
00388 {0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}
00389 };
00390 const unsigned char FONT8x16[97][16] = {
00391 {0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00392 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00393 {0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},
00394 {0x00,0x63,0x63,0x63,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00395 {0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00},
00396 {0x0C,0x0C,0x3E,0x63,0x61,0x60,0x3E,0x03,0x03,0x43,0x63,0x3E,0x0C,0x0C,0x00,0x00},
00397 {0x00,0x00,0x00,0x00,0x00,0x61,0x63,0x06,0x0C,0x18,0x33,0x63,0x00,0x00,0x00,0x00},
00398 {0x00,0x00,0x00,0x1C,0x36,0x36,0x1C,0x3B,0x6E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},
00399 {0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00400 {0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00,0x00,0x00},
00401 {0x00,0x00,0x18,0x0C,0x0C,0x06,0x06,0x06,0x06,0x0C,0x0C,0x18,0x00,0x00,0x00,0x00},
00402 {0x00,0x00,0x00,0x00,0x42,0x66,0x3C,0xFF,0x3C,0x66,0x42,0x00,0x00,0x00,0x00,0x00},
00403 {0x00,0x00,0x00,0x00,0x18,0x18,0x18,0xFF,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00},
00404 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00},
00405 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00406 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00},
00407 {0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00},
00408 {0x00,0x00,0x3E,0x63,0x63,0x63,0x6B,0x6B,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00},
00409 {0x00,0x00,0x0C,0x1C,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,0x00,0x00},
00410 {0x00,0x00,0x3E,0x63,0x03,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00},
00411 {0x00,0x00,0x3E,0x63,0x03,0x03,0x1E,0x03,0x03,0x03,0x63,0x3E,0x00,0x00,0x00,0x00},
00412 {0x00,0x00,0x06,0x0E,0x1E,0x36,0x66,0x66,0x7F,0x06,0x06,0x0F,0x00,0x00,0x00,0x00},
00413 {0x00,0x00,0x7F,0x60,0x60,0x60,0x7E,0x03,0x03,0x63,0x73,0x3E,0x00,0x00,0x00,0x00},
00414 {0x00,0x00,0x1C,0x30,0x60,0x60,0x7E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00},
00415 {0x00,0x00,0x7F,0x63,0x03,0x06,0x06,0x0C,0x0C,0x18,0x18,0x18,0x00,0x00,0x00,0x00},
00416 {0x00,0x00,0x3E,0x63,0x63,0x63,0x3E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00},
00417 {0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x3F,0x03,0x03,0x06,0x3C,0x00,0x00,0x00,0x00},
00418 {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00},
00419 {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00},
00420 {0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00},
00421 {0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00},
00422 {0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00},
00423 {0x00,0x00,0x3E,0x63,0x63,0x06,0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,0x00,0x00},
00424 {0x00,0x00,0x3E,0x63,0x63,0x6F,0x6B,0x6B,0x6E,0x60,0x60,0x3E,0x00,0x00,0x00,0x00},
00425 {0x00,0x00,0x08,0x1C,0x36,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x00,0x00,0x00,0x00},
00426 {0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x33,0x33,0x33,0x33,0x7E,0x00,0x00,0x00,0x00},
00427 {0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x60,0x60,0x61,0x33,0x1E,0x00,0x00,0x00,0x00},
00428 {0x00,0x00,0x7C,0x36,0x33,0x33,0x33,0x33,0x33,0x33,0x36,0x7C,0x00,0x00,0x00,0x00},
00429 {0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00},
00430 {0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00},
00431 {0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x6F,0x63,0x63,0x37,0x1D,0x00,0x00,0x00,0x00},
00432 {0x00,0x00,0x63,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00},
00433 {0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00},
00434 {0x00,0x00,0x0F,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},
00435 {0x00,0x00,0x73,0x33,0x36,0x36,0x3C,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00},
00436 {0x00,0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00},
00437 {0x00,0x00,0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00},
00438 {0x00,0x00,0x63,0x63,0x73,0x7B,0x7F,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00},
00439 {0x00,0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,0x00,0x00},
00440 {0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00},
00441 {0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x63,0x6B,0x6F,0x3E,0x06,0x07,0x00,0x00},
00442 {0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00},
00443 {0x00,0x00,0x3E,0x63,0x63,0x30,0x1C,0x06,0x03,0x63,0x63,0x3E,0x00,0x00,0x00,0x00},
00444 {0x00,0x00,0xFF,0xDB,0x99,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00},
00445 {0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00},
00446 {0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x08,0x00,0x00,0x00,0x00},
00447 {0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x36,0x00,0x00,0x00,0x00},
00448 {0x00,0x00,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x00,0x00,0x00,0x00},
00449 {0x00,0x00,0xC3,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00},
00450 {0x00,0x00,0x7F,0x63,0x43,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00},
00451 {0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00},
00452 {0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00},
00453 {0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00},
00454 {0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00455 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00},
00456 {0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00457 {0x00,0x00,0x00,0x00,0x00,0x3C,0x46,0x06,0x3E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},
00458 {0x00,0x00,0x70,0x30,0x30,0x3C,0x36,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,0x00,0x00},
00459 {0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x60,0x60,0x60,0x63,0x3E,0x00,0x00,0x00,0x00},
00460 {0x00,0x00,0x0E,0x06,0x06,0x1E,0x36,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},
00461 {0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x7E,0x60,0x63,0x3E,0x00,0x00,0x00,0x00},
00462 {0x00,0x00,0x1C,0x36,0x32,0x30,0x7C,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00},
00463 {0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x66,0x3C,0x00,0x00},
00464 {0x00,0x00,0x70,0x30,0x30,0x36,0x3B,0x33,0x33,0x33,0x33,0x73,0x00,0x00,0x00,0x00},
00465 {0x00,0x00,0x0C,0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00},
00466 {0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00},
00467 {0x00,0x00,0x70,0x30,0x30,0x33,0x33,0x36,0x3C,0x36,0x33,0x73,0x00,0x00,0x00,0x00},
00468 {0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00},
00469 {0x00,0x00,0x00,0x00,0x00,0x6E,0x7F,0x6B,0x6B,0x6B,0x6B,0x6B,0x00,0x00,0x00,0x00},
00470 {0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x33,0x33,0x00,0x00,0x00,0x00},
00471 {0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00},
00472 {0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x30,0x78,0x00,0x00},
00473 {0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00,0x00},
00474 {0x00,0x00,0x00,0x00,0x00,0x6E,0x3B,0x33,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00},
00475 {0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x38,0x0E,0x03,0x63,0x3E,0x00,0x00,0x00,0x00},
00476 {0x00,0x00,0x08,0x18,0x18,0x7E,0x18,0x18,0x18,0x18,0x1B,0x0E,0x00,0x00,0x00,0x00},
00477 {0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},
00478 {0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x36,0x36,0x1C,0x1C,0x08,0x00,0x00,0x00,0x00},
00479 {0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x00,0x00,0x00,0x00},
00480 {0x00,0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x1C,0x36,0x63,0x00,0x00,0x00,0x00},
00481 {0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x3F,0x03,0x06,0x3C,0x00,0x00},
00482 {0x00,0x00,0x00,0x00,0x00,0x7F,0x66,0x0C,0x18,0x30,0x63,0x7F,0x00,0x00,0x00,0x00},
00483 {0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00},
00484 {0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00},
00485 {0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18,0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00},
00486 {0x00,0x00,0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00487 {0x00,0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
00488 };
00489
00492 static struct {
00493 unsigned long cpu_hz;
00494 unsigned long hsb_hz;
00495 } tft_data =
00496 {
00497 .cpu_hz = 0,
00498 .hsb_hz = 0
00499 };
00500
00501
00502
00503 static __inline__ void et024006_SelectRegister( uint8_t address );
00504 static __inline__ void et024006_WriteRegister( uint8_t address, uint8_t value );
00505 static __inline__ uint8_t et024006_ReadRegister( uint8_t address );
00506 static void et024006_SetRegister( uint8_t address, uint8_t bitmask );
00507
00508
00509 static void et024006_SetLimits( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 );
00510 static void et024006_SetQuickLimits( uint16_t x, uint16_t y );
00511 static void et024006_DrawQuickPixel( uint16_t x, uint16_t y, et024006_color_t color );
00512
00513 static void et024006_DuplicatePixel( et024006_color_t color, uint32_t count );
00514 static void et024006_CopyPixelsToScreen( et024006_color_t const * pixels, uint32_t count );
00515 static void et024006_CopyPixelsFromScreen( et024006_color_t * pixels, uint32_t count );
00516
00517
00518 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
00519 static void et024006_InitSPI( void );
00520 #endif
00521
00522 static void et024006_SetupInterface( void );
00523 static void et024006_ResetDisplay( void );
00524
00525 static void et024006_AdjustGamma( void );
00526 static void et024006_GeneralSettings( void );
00527 static void et024006_PowerSettings(void);
00528 static void et024006_InterfaceSettings(void);
00529 static void et024006_PowerUp(void);
00530 static void et024006_PowerOn( void );
00531
00532
00533
00534 #define et024006_SelectSPI() (PORTC.OUTCLR = PIN4_bm)
00535 #define et024006_DeselectSPI() (PORTC.OUTSET = PIN4_bm)
00536
00537 #define et024006_SendSPI(value) \
00538 SPIC.DATA = (value); \
00539 do {} while ((SPIC.STATUS & SPI_IF_bm) == 0x00);
00540
00541 #define et024006_SendDummySPI() \
00542 et024006_SendSPI( 0xff );
00543
00544 #define et024006_ReadSPI() \
00545 (SPIC.DATA)
00546
00547
00548
00549
00550
00556 void et024006_Init( unsigned long cpu_hz, unsigned long hsb_hz )
00557 {
00558 tft_data.cpu_hz = cpu_hz;
00559 tft_data.hsb_hz = hsb_hz;
00560
00561 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
00562 et024006_InitSPI();
00563 #endif
00564 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
00565 smc_init(tft_data.hsb_hz);
00566 #endif
00567 et024006_SetupInterface();
00568 et024006_ResetDisplay();
00569 et024006_AdjustGamma();
00570 et024006_GeneralSettings();
00571 et024006_InterfaceSettings();
00572 et024006_PowerSettings();
00573 et024006_PowerUp();
00574 et024006_PowerOn();
00575 }
00585 void et024006_ScrollAreaSetup(uint16_t tfa, uint16_t vsa, uint16_t bfa)
00586 {
00587 et024006_WriteRegister(HIMAX_VS_TFA_HB, tfa >> 8);
00588 et024006_WriteRegister(HIMAX_VS_TFA_LB, tfa);
00589
00590 et024006_WriteRegister(HIMAX_VS_VSA_HB, vsa >> 8);
00591 et024006_WriteRegister(HIMAX_VS_VSA_LB, vsa);
00592
00593 et024006_WriteRegister(HIMAX_VS_BFA_HB, bfa >> 8);
00594 et024006_WriteRegister(HIMAX_VS_BFA_LB, bfa);
00595 }
00596
00602 void et024006_Scroll(int16_t lines)
00603 {
00604 uint16_t current_vsp;
00605 uint16_t current_vsa;
00606 Assert(lines > ET024006_HEIGHT);
00607 Assert(lines < -ET024006_HEIGHT);
00608
00609 current_vsp = ((uint16_t) et024006_ReadRegister(HIMAX_VS_VSP_HB)) << 8;
00610 current_vsp |= et024006_ReadRegister(HIMAX_VS_VSP_LB);
00611
00612 current_vsa = ((uint16_t) et024006_ReadRegister(HIMAX_VS_VSA_HB)) << 8;
00613 current_vsa |= et024006_ReadRegister(HIMAX_VS_VSA_LB);
00614
00615 lines += current_vsp;
00616 if(lines < 0)
00617 lines = ET024006_HEIGHT + lines;
00618 else if ( lines > ET024006_HEIGHT)
00619 lines -= ET024006_HEIGHT;
00620
00621 et024006_WriteRegister(HIMAX_VS_VSP_HB,((uint16_t) lines) >> 8);
00622 et024006_WriteRegister(HIMAX_VS_VSP_LB,(uint16_t) lines);
00623 }
00624
00627 void et024006_ScrollEnable()
00628 {
00629 et024006_WriteRegister(HIMAX_GATE_SCAN_CTRL, HIMAX_SCROLL_ON);
00630 }
00631
00634 void et024006_ScrollDisable()
00635 {
00636 et024006_WriteRegister(HIMAX_GATE_SCAN_CTRL, 0x0);
00637 }
00638
00644 et024006_color_t et024006_Color( uint8_t r, uint8_t g, uint8_t b )
00645 {
00646 uint16_t red = r >> 3;
00647 uint16_t green = g >> 2;
00648 uint16_t blue = b >> 3;
00649
00650 red <<= (5 + 6);
00651 green <<= 5;
00652
00653 et024006_color_t color = red | green | blue;
00654 color = (color >> 8) | (color << 8);
00655 return color;
00656 }
00657
00658
00659 void et024006_DrawPixel( uint16_t x, uint16_t y, et024006_color_t color )
00660 {
00661
00662 Assert( x < ET024006_WIDTH );
00663 Assert( y < ET024006_HEIGHT );
00664
00665
00666 et024006_SetLimits( x, y, x, y );
00667 et024006_SelectRegister( HIMAX_SRAMWRITE );
00668
00669 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
00670 et024006_SelectSPI();
00671 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS );
00672 et024006_SendSPI( color & 0xff );
00673 et024006_SendSPI( color >> 8 );
00674 et024006_DeselectSPI();
00675 #else
00676 *ET024006_PARAM_ADDR = color;
00677 #endif
00678 }
00679
00680
00681 et024006_color_t et024006_GetPixel( uint16_t x, uint16_t y )
00682 {
00683 et024006_color_t color;
00684
00685
00686 Assert( x < ET024006_WIDTH );
00687 Assert( y < ET024006_HEIGHT );
00688
00689
00690 et024006_SetLimits( x, y, x, y );
00691 et024006_SelectRegister( HIMAX_SRAMWRITE );
00692
00693 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
00694 color = *ET024006_PARAM_ADDR;
00695 #endif
00696
00697 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
00698 et024006_SelectSPI();
00699 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS | ET024006_RW );
00700 et024006_SendDummySPI();
00701
00702 et024006_SendDummySPI();
00703 uint8_t red = et024006_ReadSPI();
00704 et024006_SendDummySPI();
00705 uint8_t green = et024006_ReadSPI();
00706 et024006_SendDummySPI();
00707 uint8_t blue = et024006_ReadSPI();
00708
00709 et024006_DeselectSPI();
00710
00711
00712 color = et024006_Color( red, green, blue );
00713 #endif
00714 return color;
00715 }
00716
00717
00718 void et024006_DrawHorizLine( uint16_t x, uint16_t y, uint16_t length, et024006_color_t color )
00719 {
00720 et024006_DrawFilledRect( x, y, length, 1, color );
00721 }
00722
00723
00724 void et024006_DrawVertLine( uint16_t x, uint16_t y, uint16_t length, et024006_color_t color )
00725 {
00726 et024006_DrawFilledRect( x, y, 1, length, color );
00727 }
00728
00729
00730 void et024006_DrawLine( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, et024006_color_t color )
00731 {
00732 et024006_SetLimits( 0, 0, ET024006_WIDTH - 1, ET024006_HEIGHT - 1 );
00733
00734
00735 Assert( x1 < ET024006_WIDTH );
00736 Assert( y1 < ET024006_HEIGHT );
00737 Assert( x2 < ET024006_WIDTH );
00738 Assert( y2 < ET024006_HEIGHT );
00739
00740
00741
00742 int16_t xinc = 1;
00743 int16_t dx = x2 - x1;
00744 if (dx < 0){
00745 xinc = -1;
00746 dx = -dx;
00747 }
00748 int16_t yinc = 1;
00749 int16_t dy = y2 - y1;
00750 if (dy < 0){
00751 yinc = -1;
00752 dy = -dy;
00753 }
00754
00755
00756 uint16_t x = x1;
00757 uint16_t y = y1;
00758 uint16_t i;
00759
00760 if (dx > dy) {
00761
00762 int16_t e = dx >> 1;
00763 for ( i = 0; i <= dx; ++i) {
00764 et024006_DrawQuickPixel(x,y,color);
00765
00766 if (e <= 0){
00767 e += dx;
00768 y += yinc;
00769 }
00770
00771 e -= dy;
00772 x += xinc;
00773 }
00774 } else {
00775
00776 int16_t e = dy >> 1;
00777 for (i = 0; i <= dy; ++i) {
00778 et024006_DrawQuickPixel(x,y,color);
00779
00780 if (e <= 0){
00781 e += dy;
00782 x += xinc;
00783 }
00784
00785 e -= dx;
00786 y += yinc;
00787 }
00788 }
00789 }
00790
00791
00792 void et024006_DrawFilledRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, et024006_color_t color )
00793 {
00794
00795 Assert( x < ET024006_WIDTH );
00796 Assert( y < ET024006_HEIGHT );
00797 Assert( width > 0 );
00798 Assert( height > 0 );
00799
00800
00801 uint16_t x2 = x + width - 1;
00802 uint16_t y2 = y + height - 1;
00803
00804
00805 Assert( x2 < ET024006_WIDTH );
00806 Assert( y2 < ET024006_HEIGHT );
00807
00808
00809 et024006_SetLimits( x, y, x2, y2 );
00810 uint32_t count = (uint32_t) width * height;
00811 et024006_DuplicatePixel( color, count );
00812 }
00813
00814 #define TFT_QUADRANT0 ((1 << 1) | (1 << 0))
00815 #define TFT_QUADRANT1 ((1 << 3) | (1 << 2))
00816 #define TFT_QUADRANT2 ((1 << 5) | (1 << 4))
00817 #define TFT_QUADRANT3 ((1 << 7) | (1 << 6))
00818
00834 void et024006_DrawFilledCircle(
00835 uint16_t x,
00836 uint16_t y,
00837 uint16_t radius,
00838 uint16_t color,
00839 uint8_t quadrantMask )
00840 {
00841
00842 if (radius == 0) {
00843 et024006_DrawPixel( x, y, color );
00844 return;
00845 }
00846
00847
00848 uint16_t offsetX = 0;
00849 uint16_t offsetY = radius;
00850 int16_t error = 3 - 2 * radius;
00851
00852
00853 while (offsetX <= offsetY) {
00854
00855 if (quadrantMask & TFT_QUADRANT0) {
00856 et024006_DrawVertLine( x + offsetY, y - offsetX,
00857 offsetX + 1, color );
00858 et024006_DrawVertLine( x + offsetX, y - offsetY,
00859 offsetY + 1, color );
00860 }
00861 if (quadrantMask & TFT_QUADRANT1) {
00862 et024006_DrawVertLine( x - offsetY, y - offsetX,
00863 offsetX + 1, color );
00864 et024006_DrawVertLine( x - offsetX, y - offsetY,
00865 offsetY + 1, color );
00866 }
00867 if (quadrantMask & TFT_QUADRANT2) {
00868 et024006_DrawVertLine( x - offsetY, y, offsetX + 1,
00869 color );
00870 et024006_DrawVertLine( x - offsetX, y, offsetY + 1,
00871 color );
00872 }
00873 if (quadrantMask & TFT_QUADRANT3) {
00874 et024006_DrawVertLine( x + offsetY, y, offsetX + 1,
00875 color );
00876 et024006_DrawVertLine( x + offsetX, y, offsetY + 1,
00877 color );
00878 }
00879
00880
00881 if (error < 0) {
00882 error += ((offsetX << 2) + 6);
00883 } else {
00884 error += (((offsetX - offsetY) << 2) + 10);
00885 --offsetY;
00886 }
00887
00888
00889 ++offsetX;
00890 }
00891 }
00892
00893 static void et024006_CopyBitsToScreen(
00894 void *bitmap,
00895 uint32_t count,
00896 et024006_color_t foreground_color,
00897 et024006_color_t background_color )
00898 {
00899 uint8_t *u8_bitmap = (uint8_t *) bitmap;
00900 uint8_t bit_mask;
00901 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
00902 while (count >= 8)
00903 {
00904 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x01))?foreground_color:background_color;
00905 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x02))?foreground_color:background_color;
00906 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x04))?foreground_color:background_color;
00907 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x08))?foreground_color:background_color;
00908 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x10))?foreground_color:background_color;
00909 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x20))?foreground_color:background_color;
00910 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x40))?foreground_color:background_color;
00911 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, 0x80))?foreground_color:background_color;
00912 u8_bitmap++;
00913 count -= 8;
00914 }
00915 bit_mask = 1;
00916 while (count)
00917 {
00918 *ET024006_PARAM_ADDR = (Tst_bits(*u8_bitmap, bit_mask))?foreground_color:background_color;
00919 bit_mask <<= 1;
00920 count--;
00921 }
00922 #endif
00923 }
00924
00925 void et024006_PutBitmap(
00926 void *bitmap,
00927 uint16_t map_width,
00928 uint16_t x,
00929 uint16_t y,
00930 uint16_t width,
00931 uint16_t height,
00932 et024006_color_t foreground_color,
00933 et024006_color_t background_color )
00934 {
00935 uint8_t *u8_bitmap = (uint8_t *) bitmap;
00936
00937
00938 Assert( bitmap != NULL );
00939 Assert( width <= map_width );
00940 Assert( x < ET024006_WIDTH );
00941 Assert( y < ET024006_HEIGHT );
00942 Assert( width > 0 );
00943 Assert( height > 0 );
00944
00945
00946 uint16_t x2 = x + width - 1;
00947 uint16_t y2 = y + height - 1;
00948
00949
00950 Assert( x2 < ET024006_WIDTH );
00951 Assert( y2 < ET024006_HEIGHT );
00952
00953
00954 et024006_SetLimits(x, y, x2, y2);
00955
00956
00957 et024006_SelectRegister( HIMAX_SRAMWRITE );
00958
00959
00960 if (ET024006_BITMAP_WIDTH(map_width) == map_width)
00961 {
00962
00963 uint32_t count = (uint32_t) width * height;
00964 et024006_CopyBitsToScreen(u8_bitmap, count, foreground_color, background_color);
00965 }
00966 else
00967 {
00968
00969 uint16_t lines_left = height;
00970 while (lines_left > 0)
00971 {
00972 et024006_CopyBitsToScreen(u8_bitmap, width, foreground_color, background_color);
00973 u8_bitmap += ET024006_BITMAP_WIDTH(map_width);
00974 --lines_left;
00975 }
00976 }
00977 }
00978
00979 void et024006_PutPixmap(
00980 et024006_color_t const * pixmap,
00981 uint16_t map_width,
00982 uint16_t map_x,
00983 uint16_t map_y,
00984 uint16_t x,
00985 uint16_t y,
00986 uint16_t width,
00987 uint16_t height )
00988 {
00989
00990 Assert( pixmap != NULL );
00991 Assert( width <= map_width );
00992 Assert( x < ET024006_WIDTH );
00993 Assert( y < ET024006_HEIGHT );
00994 Assert( width > 0 );
00995 Assert( height > 0 );
00996
00997
00998 uint16_t x2 = x + width - 1;
00999 uint16_t y2 = y + height - 1;
01000
01001
01002 Assert( x2 < ET024006_WIDTH );
01003 Assert( y2 < ET024006_HEIGHT );
01004
01005
01006 et024006_SetLimits( x, y, x2, y2 );
01007
01008
01009 pixmap += map_x;
01010 if (map_y > 0) {
01011 pixmap += (uint32_t) map_y * map_width;
01012 }
01013
01014 et024006_SelectRegister( HIMAX_SRAMWRITE );
01015
01016
01017 if ((map_width == width) && (map_x == 0)) {
01018
01019 uint32_t count = (uint32_t) width * height;
01020 et024006_CopyPixelsToScreen( pixmap, count );
01021 } else {
01022
01023 uint16_t lines_left = height;
01024 while (lines_left > 0) {
01025 et024006_CopyPixelsToScreen( pixmap, width );
01026 pixmap += map_width;
01027 --lines_left;
01028 }
01029 }
01030 }
01031
01032
01033 void et024006_GetPixmap(
01034 et024006_color_t * pixmap,
01035 uint16_t map_width,
01036 uint16_t map_x,
01037 uint16_t map_y,
01038 uint16_t x,
01039 uint16_t y,
01040 uint16_t width,
01041 uint16_t height )
01042 {
01043
01044 Assert( pixmap != NULL );
01045 Assert( width <= map_width );
01046 Assert( x < ET024006_WIDTH );
01047 Assert( y < ET024006_HEIGHT );
01048 Assert( width > 0 );
01049 Assert( height > 0 );
01050
01051
01052 uint16_t x2 = x + width - 1;
01053 uint16_t y2 = y + height - 1;
01054
01055
01056 Assert( x2 < ET024006_WIDTH );
01057 Assert( y2 < ET024006_HEIGHT );
01058
01059
01060 et024006_SetLimits( x, y, x2, y2 );
01061
01062
01063 pixmap += map_x;
01064 if (map_y > 0) {
01065 pixmap += (uint32_t) map_y * map_width;
01066 }
01067
01068
01069 if ((map_width == width) && (map_x == 0)) {
01070
01071 uint32_t count = (uint32_t) width * height;
01072 et024006_CopyPixelsFromScreen( pixmap, count );
01073 } else {
01074
01075 uint16_t lines_left = height;
01076 while (lines_left > 0) {
01077 et024006_CopyPixelsFromScreen( pixmap, width );
01078 pixmap += map_width;
01079 --lines_left;
01080 }
01081 }
01082 }
01101 void et024006_PrintString(char *lcd_string, const unsigned char *font_style,
01102 uint16_t x,
01103 uint16_t y,
01104 uint16_t fcolor,
01105 int bcolor)
01106 {
01107 uint16_t row, col;
01108 unsigned char mask = 0, xfont, yfont, font_size;
01109 const unsigned char *data;
01110
01111
01112 if( *lcd_string == '\0')
01113 return;
01114
01115 data = font_style;
01116 xfont = *data;
01117 data++;
01118 yfont = *data;
01119 data++;
01120 font_size = *data;
01121
01122
01123 if(bcolor == -1)
01124 {
01125
01126 et024006_SetLimits( 0, 0, ET024006_WIDTH - 1, ET024006_HEIGHT - 1 );
01127
01128 do
01129 {
01130
01131 data = (font_style + font_size) +
01132 (font_size * (int)(*lcd_string - 32));
01133
01134 for (row = y; row < (y + yfont); row++)
01135 {
01136 mask = 0x80;
01137 for (col = x; col < (x + xfont); col++)
01138 {
01139 if (*data & mask)
01140 {
01141 et024006_DrawQuickPixel( col, row, fcolor );
01142 }
01143 mask >>= 1;
01144 }
01145
01146 data++;
01147 }
01148
01149 x += xfont;
01150 lcd_string++;
01151
01152 }while(*lcd_string !='\0');
01153 }
01154 else
01155 {
01156 do
01157 {
01158
01159 data = (font_style + font_size) +
01160 (font_size * (int)(*lcd_string - 32));
01161
01162
01163 et024006_SetLimits( x, y, x + xfont - 1, y + yfont - 1 );
01164 et024006_SelectRegister( HIMAX_SRAMWRITE );
01165
01166 for (row=0; row < yfont;row++)
01167 {
01168 mask = 0x80;
01169 for (col = 0; col < xfont; col++)
01170 {
01171 if (*data & mask)
01172 {
01173 *ET024006_PARAM_ADDR = fcolor;
01174 }
01175 else
01176 {
01177 *ET024006_PARAM_ADDR = bcolor;
01178 }
01179 mask >>= 1;
01180 }
01181
01182
01183 data++;
01184 }
01185
01186 x += xfont;
01187 lcd_string++;
01188 }while(*lcd_string !='\0');
01189 }
01190 }
01191
01192
01193
01194
01195
01196
01197 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
01198 #if (defined __GNUC__)
01199 __attribute__((__always_inline__))
01200 #endif
01201 static __inline__ void et024006_WriteRegister( uint8_t address, uint8_t value )
01202 {
01203 *ET024006_CMD_ADDR = (uint16_t) address;
01204 *ET024006_PARAM_ADDR = (uint16_t) value;
01205 }
01206 #if (defined __GNUC__)
01207 __attribute__((__always_inline__))
01208 #endif
01209 static __inline__ uint8_t et024006_ReadRegister( uint8_t address )
01210 {
01211 *ET024006_CMD_ADDR = (uint16_t) address;
01212 return *ET024006_PARAM_ADDR;
01213 }
01214 #if (defined __GNUC__)
01215 __attribute__((__always_inline__))
01216 #endif
01217 static __inline__ void et024006_SelectRegister( uint8_t address )
01218 {
01219 *ET024006_CMD_ADDR = (uint16_t) address;
01220 }
01221
01222
01223 #elif(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
01224
01225
01226 static __inline__ uint8_t et024006_ReadRegister( uint8_t address )
01227 {
01228 et024006_SelectRegister( address );
01229 et024006_SelectSPI();
01230 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS | ET024006_RW );
01231 et024006_SendDummySPI();
01232 uint8_t value = et024006_ReadSPI();
01233 et024006_DeselectSPI();
01234 return value;
01235 }
01236
01237
01238 static void et024006_SelectRegister( uint8_t value )
01239 {
01240 et024006_SelectSPI();
01241 et024006_SendSPI( ET024006_ID | ET024006_BS0 );
01242 et024006_SendSPI( value );
01243 et024006_DeselectSPI();
01244 }
01245
01246
01247 static void et024006_WriteRegister( uint8_t address, uint8_t value )
01248 {
01249 et024006_SelectRegister( address );
01250 et024006_SelectSPI();
01251 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS );
01252 et024006_SendSPI( value );
01253 et024006_DeselectSPI();
01254 }
01255
01256 #else
01257 #error No TFT interface mode is selected
01258 #endif
01259
01260
01261
01262 static void et024006_SetRegister( uint8_t address, uint8_t bitmask )
01263 {
01264 uint8_t value = et024006_ReadRegister( address );
01265 value |= bitmask;
01266 et024006_WriteRegister( address, value );
01267 }
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01283 static void et024006_SetLimits( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 )
01284 {
01285 et024006_WriteRegister( HIMAX_COL_ADDR_START2, (x1 >> 8) );
01286 et024006_WriteRegister( HIMAX_COL_ADDR_START1, (x1 & 0xff) );
01287 et024006_WriteRegister( HIMAX_COL_ADDR_END2, (x2 >> 8) );
01288 et024006_WriteRegister( HIMAX_COL_ADDR_END1, (x2 & 0xff) );
01289 et024006_WriteRegister( HIMAX_ROW_ADDR_START2, (y1 >> 8) );
01290 et024006_WriteRegister( HIMAX_ROW_ADDR_START1, (y1 & 0xff) );
01291 et024006_WriteRegister( HIMAX_ROW_ADDR_END2, (y2 >> 8) );
01292 et024006_WriteRegister( HIMAX_ROW_ADDR_END1, (y2 & 0xff) );
01293 }
01294
01298 static void et024006_SetQuickLimits( uint16_t x, uint16_t y )
01299 {
01300 et024006_WriteRegister( HIMAX_COL_ADDR_START2, (x >> 8) );
01301 et024006_WriteRegister( HIMAX_COL_ADDR_START1, (x & 0xff) );
01302 et024006_WriteRegister( HIMAX_ROW_ADDR_START2, (y >> 8) );
01303 et024006_WriteRegister( HIMAX_ROW_ADDR_START1, (y & 0xff) );
01304 }
01305
01306
01307 static void et024006_DrawQuickPixel( uint16_t x, uint16_t y, et024006_color_t color )
01308 {
01309
01310 Assert( x < ET024006_WIDTH );
01311 Assert( y < ET024006_HEIGHT );
01312
01313
01314 et024006_SetQuickLimits( x, y );
01315 et024006_SelectRegister( HIMAX_SRAMWRITE );
01316 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
01317 et024006_SelectSPI();
01318 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS );
01319 et024006_SendSPI( color & 0xff );
01320 et024006_SendSPI( color >> 8 );
01321 et024006_DeselectSPI();
01322 #endif
01323 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
01324 *ET024006_PARAM_ADDR = color;
01325 #endif
01326
01327 }
01328
01329
01330
01331
01332
01333 static void et024006_DuplicatePixel( et024006_color_t color, uint32_t count )
01334 {
01335 Assert( (count >> 24) == 0 );
01336 Assert( count > 0 );
01337
01338 et024006_SelectRegister( HIMAX_SRAMWRITE );
01339 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
01340
01341 while (count >= 8) {
01342 *ET024006_PARAM_ADDR = color;
01343 *ET024006_PARAM_ADDR = color;
01344 *ET024006_PARAM_ADDR = color;
01345 *ET024006_PARAM_ADDR = color;
01346 *ET024006_PARAM_ADDR = color;
01347 *ET024006_PARAM_ADDR = color;
01348 *ET024006_PARAM_ADDR = color;
01349 *ET024006_PARAM_ADDR = color;
01350 count-=8;
01351 }
01352 while (count > 0) {
01353 *ET024006_PARAM_ADDR = color;
01354 --count;
01355 }
01356 #endif
01357 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
01358 et024006_SelectSPI();
01359 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS );
01360
01361 if (count < ET024006_DMA_USAGE_LIMIT) {
01362 Assert( ET024006_DMA_USAGE_LIMIT < 256 );
01363
01364 uint8_t countLowByte = count & 0xff;
01365 while (countLowByte > 0) {
01366 et024006_SendSPI( color & 0xff );
01367 et024006_SendSPI( color >> 8 );
01368 --countLowByte;
01369 }
01370 } else {
01371 DMA.CTRL = DMA_ENABLE_bm;
01372
01373 DMA.CH0.DESTADDR0 = (((uint32_t) &(SPIC.DATA)) >> 0) & 0xff;
01374 DMA.CH0.DESTADDR1 = (((uint32_t) &(SPIC.DATA)) >> 8) & 0xff;
01375 DMA.CH0.DESTADDR2 = (((uint32_t) &(SPIC.DATA)) >> 16) & 0xff;
01376
01377 DMA.CH0.TRFCNT = 2;
01378
01379 DMA.CH0.ADDRCTRL = (uint8_t)
01380 DMA_CH_SRCRELOAD_BLOCK_gc |
01381 DMA_CH_SRCDIR_INC_gc |
01382 DMA_CH_DESTRELOAD_NONE_gc |
01383 DMA_CH_DESTDIR_FIXED_gc;
01384 DMA.CH0.TRIGSRC = DMA_CH_TRIGSRC_SPIC_gc;
01385
01386 ++count;
01387
01388 while (count >= 255) {
01389 DMA.CH0.SRCADDR0 = (((uint32_t) &color) >> 0) & 0xff;
01390 DMA.CH0.SRCADDR1 = (((uint32_t) &color) >> 8) & 0xff;
01391 DMA.CH0.SRCADDR2 = (((uint32_t) &color) >> 16) & 0xff;
01392
01393 DMA.CH0.REPCNT = 255;
01394 DMA.CH0.CTRLA = (uint8_t)
01395 DMA_CH_ENABLE_bm |
01396 DMA_CH_REPEAT_bm |
01397 DMA_CH_TRFREQ_bm |
01398 DMA_CH_SINGLE_bm |
01399 DMA_CH_BURSTLEN_1BYTE_gc;
01400 do {} while ((DMA.CH0.CTRLB & DMA_CH_CHBUSY_bm) != 0x00);
01401
01402 count -= 255;
01403 }
01404
01405 if ((count & 0xff) > 0) {
01406 DMA.CH0.SRCADDR0 = (((uint32_t) &color) >> 0) & 0xff;
01407 DMA.CH0.SRCADDR1 = (((uint32_t) &color) >> 8) & 0xff;
01408 DMA.CH0.SRCADDR2 = (((uint32_t) &color) >> 16) & 0xff;
01409
01410 DMA.CH0.REPCNT = count & 0xff;
01411 DMA.CH0.CTRLA = (uint8_t)
01412 DMA_CH_ENABLE_bm |
01413 DMA_CH_REPEAT_bm |
01414 DMA_CH_TRFREQ_bm |
01415 DMA_CH_SINGLE_bm |
01416 DMA_CH_BURSTLEN_1BYTE_gc;
01417 do {} while ((DMA.CH0.CTRLB & DMA_CH_CHBUSY_bm) != 0x00);
01418 }
01419 }
01420
01421 et024006_DeselectSPI();
01422 #endif
01423 }
01424
01425 void et024006_DrawBitmap( const uint16_t data[], U16 columnOffset, U16 rowOffset )
01426 {
01427 int col, row;
01428 U16 columns = data[1];
01429 U16 rows = data[0];
01430 et024006_SetLimits( 0 + rowOffset, 0 + columnOffset, rows - 1 + rowOffset, columns - 1 + columnOffset );
01431 data += 2;
01432 et024006_SelectRegister( HIMAX_SRAMWRITE );
01433 U16 *pData = (U16 *)(&data[2]);
01434 for (col=columns;col>0;col--)
01435 {
01436 pData = (U16 *)(&data[2+col]);
01437 for (row=0;row<rows;row++)
01438 {
01439 *ET024006_PARAM_ADDR = *pData;
01440 pData = pData+columns;
01441 }
01442 }
01443 }
01444
01445
01446 static void et024006_CopyPixelsToScreen( et024006_color_t const * pixels, uint32_t count )
01447 {
01448 Assert( pixels != NULL );
01449 Assert( count > 0 );
01450
01451 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
01452 while (count >= 8)
01453 {
01454 *ET024006_PARAM_ADDR = *pixels++;
01455 *ET024006_PARAM_ADDR = *pixels++;
01456 *ET024006_PARAM_ADDR = *pixels++;
01457 *ET024006_PARAM_ADDR = *pixels++;
01458 *ET024006_PARAM_ADDR = *pixels++;
01459 *ET024006_PARAM_ADDR = *pixels++;
01460 *ET024006_PARAM_ADDR = *pixels++;
01461 *ET024006_PARAM_ADDR = *pixels++;
01462 count-=8;
01463 }
01464 while( count )
01465 {
01466 *ET024006_PARAM_ADDR = *pixels;
01467 pixels++;
01468 count--;
01469 }
01470 #endif
01471
01472 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
01473 et024006_SelectSPI();
01474 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS );
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486 {
01487 DMA.CTRL = DMA_ENABLE_bm;
01488
01489 DMA.CH0.DESTADDR0 = (((uint32_t) &(SPIC.DATA)) >> 0) & 0xff;
01490 DMA.CH0.DESTADDR1 = (((uint32_t) &(SPIC.DATA)) >> 8) & 0xff;
01491 DMA.CH0.DESTADDR2 = (((uint32_t) &(SPIC.DATA)) >> 16) & 0xff;
01492
01493 DMA.CH0.SRCADDR0 = (((uint32_t) pixels) >> 0) & 0xff;
01494 DMA.CH0.SRCADDR1 = (((uint32_t) pixels) >> 8) & 0xff;
01495 DMA.CH0.SRCADDR2 = (((uint32_t) pixels) >> 16) & 0xff;
01496
01497 DMA.CH0.ADDRCTRL = (uint8_t)
01498 DMA_CH_SRCRELOAD_NONE_gc |
01499 DMA_CH_SRCDIR_INC_gc |
01500 DMA_CH_DESTRELOAD_NONE_gc |
01501 DMA_CH_DESTDIR_FIXED_gc;
01502 DMA.CH0.TRIGSRC = DMA_CH_TRIGSRC_SPIC_gc;
01503
01504
01505 uint32_t byteCount = count * sizeof(et024006_color_t);
01506 ++byteCount;
01507 Assert( (byteCount >> 24) == 0x00 );
01508 uint8_t blockCount = byteCount >> 16;
01509 uint16_t remainderCount = byteCount & 0xffff;
01510
01511 if (blockCount > 0) {
01512 DMA.CH0.TRFCNT = 0;
01513 DMA.CH0.REPCNT = blockCount;
01514 DMA.CH0.CTRLA = (uint8_t)
01515 DMA_CH_ENABLE_bm |
01516 DMA_CH_REPEAT_bm |
01517 DMA_CH_TRFREQ_bm |
01518 DMA_CH_SINGLE_bm |
01519 DMA_CH_BURSTLEN_1BYTE_gc;
01520 do {} while ((DMA.CH0.CTRLB & DMA_CH_CHBUSY_bm) != 0x00);
01521 }
01522
01523 if (remainderCount > 0) {
01524 DMA.CH0.TRFCNT = remainderCount;
01525 DMA.CH0.CTRLA = (uint8_t)
01526 DMA_CH_ENABLE_bm |
01527 DMA_CH_TRFREQ_bm |
01528 DMA_CH_SINGLE_bm |
01529 DMA_CH_BURSTLEN_1BYTE_gc;
01530 do {} while ((DMA.CH0.CTRLB & DMA_CH_CHBUSY_bm) != 0x00);
01531 }
01532 }
01533
01534 et024006_DeselectSPI();
01535
01536
01537 #if 0
01538 Assert( pixels != NULL );
01539 Assert( (count >> 24) == 0 )
01540 Assert( count > 0 );
01541
01542 count *= sizeof( et024006_color_t );
01543 uint8_t const * buffer = (uint8_t const *) pixels;
01544
01545 uint8_t countHigh = (count >> 16);
01546 uint16_t countLow = count & 0xffff;
01547
01548 et024006_SelectRegister( HIMAX_SRAMWRITE );
01549 et024006_SelectSPI();
01550 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS );
01551
01552 if (countLow > 0) {
01553 do {
01554 et024006_SendSPI( *buffer );
01555 ++buffer;
01556 --countLow;
01557 } while (countLow > 0);
01558 }
01559
01560 if (countHigh > 0) {
01561 do {
01562 do {
01563 et024006_SendSPI( *buffer );
01564 ++buffer;
01565 --countLow;
01566 } while (countLow > 0);
01567 --countHigh;
01568 } while (countHigh > 0);
01569 }
01570
01571 et024006_DeselectSPI();
01572 #endif
01573
01574 #endif
01575 }
01576
01577
01578 static void et024006_CopyPixelsFromScreen( et024006_color_t * pixels, uint32_t count )
01579 {
01580 Assert( pixels != NULL );
01581
01582 et024006_SelectRegister( HIMAX_SRAMWRITE );
01583
01584 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
01585 while( count)
01586 {
01587 *pixels = *ET024006_PARAM_ADDR;
01588 pixels++;
01589 count--;
01590 }
01591 #endif
01592
01593 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
01594 et024006_SelectSPI();
01595 et024006_SendSPI( ET024006_ID | ET024006_BS0 | ET024006_RS | ET024006_RW );
01596 et024006_SendDummySPI();
01597
01598 while (count > 0) {
01599 et024006_SendDummySPI();
01600 uint8_t red = et024006_ReadSPI();
01601 et024006_SendDummySPI();
01602 uint8_t green = et024006_ReadSPI();
01603 et024006_SendDummySPI();
01604 uint8_t blue = et024006_ReadSPI();
01605
01606 *pixels = et024006_Color( red, green, blue );
01607
01608 ++pixels;
01609 --count;
01610 }
01611
01612 et024006_DeselectSPI();
01613 #endif
01614 }
01615
01616
01617
01618 #if(ET024006_IFACE_MODE == ET024006_IFACE_MODE_SPI)
01619 static void et024006_InitSPI( void )
01620 {
01621
01622 PORTC.DIRSET = PIN4_bm;
01623
01624 PORTC.DIRSET = PIN5_bm;
01625
01626 PORTC.DIRCLR = PIN6_bm;
01627
01628 PORTC.DIRSET = PIN7_bm;
01629
01630
01631 PORTC.OUTSET = PIN4_bm;
01632
01633 SPIC.INTCTRL = SPI_INTLVL_OFF_gc;
01634
01635 SPIC.CTRL = ( SPI_ENABLE_bm |
01636 SPI_MODE_3_gc |
01637 SPI_PRESCALER_DIV4_gc |
01638 SPI_MASTER_bm);
01639 }
01640 #endif
01641
01642 static void et024006_SetupInterface( void )
01643 {
01644
01645
01646
01647 gpio_enable_gpio_pin(ET024006DHU_TE_PIN);
01648
01649
01650 gpio_enable_module_pin(ET024006DHU_BL_PIN, ET024006DHU_BL_FUNCTION);
01651
01652
01653
01654
01655 gpio_set_gpio_pin(ET024006DHU_RESET_PIN);
01656 }
01657
01660 static void et024006_ResetDisplay( void )
01661 {
01662
01663 gpio_clr_gpio_pin(ET024006DHU_RESET_PIN);
01664
01665 cpu_delay_us( 50, tft_data.cpu_hz );
01666
01667 gpio_set_gpio_pin(ET024006DHU_RESET_PIN);
01668
01669 cpu_delay_ms( 5, tft_data.cpu_hz );
01670 }
01671
01693 int et024006_TestDisplay(void)
01694 {
01695 U16 tmp;
01696 int ret_value = 0;
01697
01698 #if 0
01699 U16 display_id;
01700
01701 display_id = et024006_ReadRegister(HIMAX_ID_CODE);
01702 if((display_id & 0x00FF) != 0x0047)
01703 {
01704 ret_value = -2;
01705 }
01706 #endif
01707
01708 #if( ET024006_IFACE_MODE == ET024006_IFACE_MODE_EBI)
01709
01710
01711
01712
01713
01714 {
01715
01716 et024006_SetQuickLimits( 0, 0 );
01717 et024006_SelectRegister( HIMAX_SRAMWRITE );
01718 *ET024006_PARAM_ADDR = 0xAAAA;
01719
01720
01721 et024006_SetQuickLimits( 0, 0 );
01722 et024006_SelectRegister( HIMAX_SRAMWRITE );
01723
01724
01725 tmp = *ET024006_PARAM_ADDR;
01726
01727
01728 tmp = *ET024006_PARAM_ADDR;
01729 if(tmp != 0x00AC)
01730 {
01731 ret_value = -1;
01732 }
01733
01734 tmp = *ET024006_PARAM_ADDR;
01735 if(tmp != 0x0054)
01736 {
01737 ret_value = -1;
01738 }
01739
01740 tmp = *ET024006_PARAM_ADDR;
01741 if(tmp != 0x0050)
01742 {
01743 ret_value = -1;
01744 }
01745
01746
01747 et024006_SetQuickLimits( 0, 0 );
01748 et024006_SelectRegister( HIMAX_SRAMWRITE );
01749 *ET024006_PARAM_ADDR = 0x5555;
01750
01751
01752 et024006_SetQuickLimits( 0, 0 );
01753 et024006_SelectRegister( HIMAX_SRAMWRITE );
01754
01755
01756 tmp = *ET024006_PARAM_ADDR;
01757
01758 tmp = *ET024006_PARAM_ADDR;
01759 if(tmp != 0x0050)
01760 {
01761 ret_value = -1;
01762 }
01763
01764 tmp = *ET024006_PARAM_ADDR;
01765 if(tmp != 0x00A8)
01766 {
01767 ret_value = -1;
01768 }
01769
01770 tmp = *ET024006_PARAM_ADDR;
01771 if(tmp != 0x00AC)
01772 {
01773 ret_value = -1;
01774 }
01775
01776 }
01777 #endif
01778 return ret_value;
01779 }
01780
01781
01786 static void et024006_AdjustGamma( void )
01787 {
01788 et024006_WriteRegister( HIMAX_GAMMACTRL1, 0x94 );
01789 et024006_WriteRegister( HIMAX_GAMMACTRL2, 0x41 );
01790 et024006_WriteRegister( HIMAX_GAMMACTRL3, 0x00 );
01791 et024006_WriteRegister( HIMAX_GAMMACTRL4, 0x33 );
01792 et024006_WriteRegister( HIMAX_GAMMACTRL5, 0x25 );
01793 et024006_WriteRegister( HIMAX_GAMMACTRL6, 0x45 );
01794 et024006_WriteRegister( HIMAX_GAMMACTRL7, 0x44 );
01795 et024006_WriteRegister( HIMAX_GAMMACTRL8, 0x77 );
01796 et024006_WriteRegister( HIMAX_GAMMACTRL9, 0x12 );
01797 et024006_WriteRegister( HIMAX_GAMMACTRL10, 0xCC );
01798 et024006_WriteRegister( HIMAX_GAMMACTRL11, 0x46 );
01799 et024006_WriteRegister( HIMAX_GAMMACTRL12, 0x82 );
01800 }
01801
01806 static void et024006_GeneralSettings(void)
01807 {
01808 et024006_WriteRegister( HIMAX_DISPMODECTRL, (1 << HIMAX_INVON) |
01809 (1 << HIMAX_NORON));
01810
01811 et024006_WriteRegister( HIMAX_CYCLECTRL1, 0x01 );
01812 et024006_WriteRegister( HIMAX_CYCLECTRL2, 0x01 );
01813 et024006_WriteRegister( HIMAX_CYCLECTRL3, 0xF0 );
01814 et024006_WriteRegister( HIMAX_CYCLECTRL4, 0x00 );
01815 et024006_WriteRegister( HIMAX_CYCLECTRL5, 0x38 );
01816 et024006_WriteRegister( HIMAX_CYCLECTRL6, 0x0F );
01817 et024006_WriteRegister( HIMAX_CYCLECTRL14, 0xF0 );
01818
01819
01820 et024006_WriteRegister( HIMAX_DISPCTRL2, 0x02 );
01821 et024006_WriteRegister( HIMAX_DISPCTRL3, 0x02 );
01822 et024006_WriteRegister( HIMAX_DISPCTRL4, 0x02 );
01823 et024006_WriteRegister( HIMAX_DISPCTRL5, 0x02 );
01824 et024006_WriteRegister( HIMAX_DISPCTRL6, 0x02 );
01825 et024006_WriteRegister( HIMAX_DISPCTRL7, 0x02 );
01826
01827 et024006_WriteRegister( HIMAX_OSCCTRL1, 0x49 );
01828 et024006_WriteRegister( HIMAX_OSCCTRL3, 0x08 );
01829 }
01830
01835 static void et024006_PowerSettings(void)
01836 {
01837 et024006_WriteRegister( HIMAX_CYCLECTRL1_x, 0x95 );
01838 et024006_WriteRegister( HIMAX_CYCLECTRL2_x, 0x95 );
01839 et024006_WriteRegister( HIMAX_CYCLECTRL3_x, 0xFF );
01840 et024006_WriteRegister( HIMAX_DISPCTRL8, 0x7F );
01841 et024006_WriteRegister( HIMAX_DISPCTRL9, 0x38 );
01842 et024006_WriteRegister( HIMAX_DISPCTRL10, 0x78 );
01843
01844 et024006_WriteRegister( HIMAX_POWERCTRL3, 0x07 );
01845 et024006_WriteRegister( HIMAX_POWERCTRL4, 0x00 );
01846 et024006_WriteRegister( HIMAX_POWERCTRL5, 0x04 );
01847 et024006_WriteRegister( HIMAX_POWERCTRL6, 0x40 );
01848 et024006_WriteRegister( HIMAX_VCOMCTRL2, 0x38 );
01849 et024006_WriteRegister( HIMAX_VCOMCTRL3, 0x12 );
01850 }
01851
01856 static void et024006_InterfaceSettings(void)
01857 {
01858
01859
01860 et024006_WriteRegister( HIMAX_MEMACCESSCTRL,
01861 (1 << HIMAX_MX)
01862 | (1 << HIMAX_MV)
01863 | (1 << HIMAX_BGR) );
01864
01865 }
01866
01871 static void et024006_PowerUp(void)
01872 {
01873 cpu_delay_ms( 10, tft_data.cpu_hz );
01874 et024006_WriteRegister( HIMAX_POWERCTRL2, 0x04 );
01875
01876 cpu_delay_ms( 20, tft_data.cpu_hz );
01877 et024006_WriteRegister( HIMAX_VCOMCTRL1, (1 << HIMAX_VCOMG) );
01878
01879 cpu_delay_ms( 5, tft_data.cpu_hz );
01880 et024006_WriteRegister( HIMAX_POWERCTRL1, (1 << HIMAX_DK) );
01881
01882 cpu_delay_ms( 40, tft_data.cpu_hz );
01883 et024006_WriteRegister( HIMAX_POWERCTRL1, (1 << HIMAX_PON) );
01884
01885
01886 cpu_delay_ms( 40, tft_data.cpu_hz );
01887 }
01888
01889
01892 static void et024006_PowerOn( void )
01893 {
01894 et024006_WriteRegister( HIMAX_DISPCTRL1, (1 << HIMAX_D0) );
01895
01896 cpu_delay_ms( 40, tft_data.cpu_hz );
01897 et024006_WriteRegister( HIMAX_DISPCTRL1, (1 << HIMAX_GON) |
01898 (1 << HIMAX_D0) );
01899 et024006_WriteRegister( HIMAX_DISPCTRL1, (1 << HIMAX_GON) |
01900 (1 << HIMAX_D1) | (1 << HIMAX_D0));
01901
01902 cpu_delay_ms( 40, tft_data.cpu_hz );
01903 et024006_WriteRegister( HIMAX_DISPCTRL1, (1 << HIMAX_GON)| (1 << HIMAX_DTE) |
01904 (1 << HIMAX_D1) | (1 << HIMAX_D0));
01905
01906 et024006_SetRegister( HIMAX_INTERNAL28, (1 << HIMAX_TEON) );
01907 }
01908