mtk_cfb.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2016. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER\'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER\'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER\'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK\'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK\'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #include <string.h>
  36. #include <printf.h>
  37. #include <video_fb.h>
  38. #include <libfdt.h>
  39. #include <platform/disp_drv_platform.h>
  40. #include <target/board.h>
  41. #include <env.h>
  42. #include "lcm_drv.h"
  43. #include <platform/mt_gpt.h>
  44. #include <platform/primary_display.h>
  45. #include <arch/arm/mmu.h>
  46. #include <platform/disp_drv_log.h>
  47. #include <platform/mt_disp_drv.h>
  48. #include "memory_layout.h"
  49. /* ////////////////////////////////macro///////////////////////////////////////////////////////////////// */
  50. /* COLOR Format */
  51. #define FC_5B (CS_FG_COL >> 3)
  52. #define FC_6B (CS_FG_COL >> 2)
  53. #define BC_5B (CS_BG_COL >> 3)
  54. #define BC_6B (CS_BG_COL >> 2)
  55. #define DR_TB_0 0x00000000
  56. #define DR_TB_1 0x000000ff
  57. #define DR_TB_3 0x0000ffff
  58. #define DR_TB_7 0x00ffffff
  59. #define DR_TB_8 0xff000000
  60. #define DR_TB_C 0xffff0000
  61. #define DR_TB_E 0xffffff00
  62. #define DR_TB_F 0xffffffff
  63. #include <video_font.h>
  64. #include <video_fb.h>
  65. #include <target/board.h>
  66. #include <stdarg.h>
  67. #define SIZE_X (pGD->winSizeX)
  68. #define SIZE_Y (pGD->winSizeY)
  69. #define DATA_FMT (pGD->gdfIndex)
  70. #define PIXEL_SIZE (pGD->gdfBytesPP)
  71. #define VDO_CFB_SIZE (pGD->memSize)
  72. #define VDO_CFB_ADDRS (pGD->frameAdrs)
  73. #include <platform/mt_disp_drv.h>
  74. #define CFB_HEIGHT 0
  75. #define CFB_WIDTH 0
  76. #define VDO_COLS SIZE_X
  77. #define VDO_ROWS SIZE_Y
  78. #define VDO_SIZE (PIXEL_SIZE*VDO_COLS*VDO_ROWS)
  79. #define LINE_LEN (PIXEL_SIZE*VDO_COLS)
  80. static unsigned long g_cfb[2];
  81. #define FONT_HEIGHT (MTK_VFH)
  82. #define CFB_ROW g_cfb[0]
  83. #define FONT_WIDTH (MTK_VFW)
  84. #define CFB_COL g_cfb[1]
  85. #define CFB_ROW_SIZE (FONT_HEIGHT * LINE_LEN)
  86. #define CFB_SIZE (CFB_ROW * CFB_ROW_SIZE)
  87. #define CFB_SCROLL_SIZE (CFB_SIZE - CFB_ROW_SIZE)
  88. #ifdef CFB_LIT_END
  89. #define SWAP16(x) ((((x) & 0x00ff) << 8) | ((x) >> 8))
  90. #define SHTSWAP32(x) ((((x) & 0x000000ff) << 8) | (((x) & 0x0000ff00) >> 8)|\
  91. (((x) & 0x00ff0000) << 8) | (((x) & 0xff000000) >> 8))
  92. #define SWAP32(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\
  93. (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24))
  94. #else
  95. #define SWAP16(x) (x)
  96. #define SWAP32(x) (x)
  97. #define SWAP32_16(x) ((((x) & 0x0000ffff) << 16) | (((x) & 0xffff0000) >> 16))
  98. #define SHTSWAP32(x) (x)
  99. #endif
  100. /* /////////local variable//////////////////////////////////////////////////////// */
  101. static GraphicDevice *pGD; /* Pointer-to-Graphic-array */
  102. static void *cfb_buf_addrs; /* console-buffer-start-address / */
  103. static void *cfb_fb_addrs; /* frame-buffer-address */
  104. static int cfb_rows;
  105. static int cfb_cols;
  106. /* color pats */
  107. static unsigned int cfb_eorx;
  108. static unsigned int cfb_bgx;
  109. static unsigned int cfb_fgx;
  110. static unsigned int cfb_bg_alpha;
  111. static unsigned int cfb_fg_alpha;
  112. static unsigned int cfb_eorx_default;
  113. static unsigned int cfb_fgx_default;
  114. static unsigned int cfb_bgx_default;
  115. // pixe coordinate
  116. static unsigned int cfb_pixel_position_x;
  117. static unsigned int cfb_pixel_position_y;
  118. static int vdo_fb_height = CFB_HEIGHT;
  119. extern UINT32 DISP_GetScreenHeight(void);
  120. extern UINT32 DISP_GetScreenWidth(void);
  121. void video_set_bgfg_colors(unsigned bg, unsigned fg);
  122. void video_clean_screen_by_bg(void);
  123. void video_set_position(int x, int y);
  124. void video_disp_string(char *str);
  125. void video_set_bold(int id);
  126. void video_display_image(const unsigned int data[],
  127. unsigned int xpos, unsigned int ypos, unsigned int width, unsigned int height);
  128. void video_clear_image_by_color(const unsigned int data,
  129. unsigned int xpos, unsigned int ypos, unsigned int width, unsigned int height);
  130. //pixel position
  131. void fbcon_set_position(unsigned int x, unsigned int y );
  132. void fbcon_get_position(unsigned int *x, unsigned int *y);
  133. /* Disrupted defined sequence */
  134. static const int lk_cfb_font_dtb24[16][3] = {
  135. {DR_TB_0, DR_TB_0, DR_TB_0},
  136. {DR_TB_0, DR_TB_0, DR_TB_7},
  137. {DR_TB_0, DR_TB_3, DR_TB_8},
  138. {DR_TB_0, DR_TB_3, DR_TB_F},
  139. {DR_TB_1, DR_TB_C, DR_TB_0},
  140. {DR_TB_1, DR_TB_C, DR_TB_7},
  141. {DR_TB_1, DR_TB_F, DR_TB_8},
  142. {DR_TB_1, DR_TB_F, DR_TB_F},
  143. {DR_TB_E, DR_TB_0, DR_TB_0},
  144. {DR_TB_E, DR_TB_0, DR_TB_7},
  145. {DR_TB_E, DR_TB_3, DR_TB_8},
  146. {DR_TB_E, DR_TB_3, DR_TB_F},
  147. {DR_TB_F, DR_TB_C, DR_TB_0},
  148. {DR_TB_F, DR_TB_C, DR_TB_7},
  149. {DR_TB_F, DR_TB_F, DR_TB_8},
  150. {DR_TB_F, DR_TB_F, DR_TB_F}
  151. };
  152. static const int lk_cfb_font_dtable32[16][4] = {
  153. {DR_TB_0, DR_TB_0, DR_TB_0, DR_TB_0},
  154. {DR_TB_0, DR_TB_0, DR_TB_0, DR_TB_7},
  155. {DR_TB_0, DR_TB_0, DR_TB_7, DR_TB_0},
  156. {DR_TB_0, DR_TB_0, DR_TB_7, DR_TB_7},
  157. {DR_TB_0, DR_TB_7, DR_TB_0, DR_TB_0},
  158. {DR_TB_0, DR_TB_7, DR_TB_0, DR_TB_7},
  159. {DR_TB_0, DR_TB_7, DR_TB_7, DR_TB_0},
  160. {DR_TB_0, DR_TB_7, DR_TB_7, DR_TB_7},
  161. {DR_TB_7, DR_TB_0, DR_TB_0, DR_TB_0},
  162. {DR_TB_7, DR_TB_0, DR_TB_0, DR_TB_7},
  163. {DR_TB_7, DR_TB_0, DR_TB_7, DR_TB_0},
  164. {DR_TB_7, DR_TB_0, DR_TB_7, DR_TB_7},
  165. {DR_TB_7, DR_TB_7, DR_TB_0, DR_TB_0},
  166. {DR_TB_7, DR_TB_7, DR_TB_0, DR_TB_7},
  167. {DR_TB_7, DR_TB_7, DR_TB_7, DR_TB_0},
  168. {DR_TB_7, DR_TB_7, DR_TB_7, DR_TB_7}
  169. };
  170. static const int lk_cfb_font_dtable16[] = {
  171. #if 0
  172. 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
  173. };
  174. #else /* Jett Patch: RGB565 with Little Endian Table */
  175. 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
  176. };
  177. #endif
  178. static const int lk_cfb_font_dtable15[] = {
  179. 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
  180. };
  181. static const int lk_cfb_font_dtable8[] = {
  182. 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
  183. 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  184. 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
  185. 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
  186. };
  187. static void cfb_memset(int *cfb_p, int cfb_c, int cfb_v)
  188. {
  189. while (cfb_c--) {
  190. *cfb_p = cfb_v;
  191. ++cfb_p;
  192. }
  193. }
  194. static void cfb_memcpy(int *cfb_d, int *cfb_s, int cfb_c)
  195. {
  196. while (cfb_c--) {
  197. *cfb_d = *cfb_s;
  198. ++cfb_d;
  199. ++cfb_s;
  200. }
  201. }
  202. static int get_cols(void)
  203. {
  204. return cfb_cols;
  205. }
  206. static void set_cols(int value)
  207. {
  208. cfb_cols = value;
  209. }
  210. static void inc_cols(int value)
  211. {
  212. cfb_cols += value;
  213. }
  214. static int get_rows(void)
  215. {
  216. return cfb_rows;
  217. }
  218. static void set_rows(int value)
  219. {
  220. cfb_rows = value;
  221. }
  222. static void inc_rows(int value)
  223. {
  224. cfb_rows += value;
  225. }
  226. static void cfb_lk_dchars(int xx, int yy, unsigned char *s, int count)
  227. {
  228. unsigned char *pos = NULL;
  229. unsigned char *tdest = NULL;
  230. unsigned char *pdest = NULL;
  231. unsigned char *pfont = NULL;
  232. int row = 0;
  233. unsigned int data_fmt = 0;
  234. int offs = 0;
  235. pdest = cfb_fb_addrs + yy * LINE_LEN + xx * PIXEL_SIZE;
  236. data_fmt = DATA_FMT;
  237. pfont = mtk_vdo_fntdata;
  238. switch (data_fmt) {
  239. case CFB_555RGB_15BIT:
  240. while (count--) {
  241. offs = (*s++) * MTK_VFH;
  242. pos = pfont + offs;
  243. row = MTK_VFH;
  244. for (tdest = pdest; row--; tdest += LINE_LEN) {
  245. unsigned char bits = *pos++;
  246. ((unsigned int *)tdest)[0] =
  247. SHTSWAP32((lk_cfb_font_dtable15[bits >> 6] & cfb_eorx) ^
  248. cfb_bgx);
  249. ((unsigned int *)tdest)[1] =
  250. SHTSWAP32((lk_cfb_font_dtable15[bits >> 4 & 3] & cfb_eorx) ^
  251. cfb_bgx);
  252. ((unsigned int *)tdest)[2] =
  253. SHTSWAP32((lk_cfb_font_dtable15[bits >> 2 & 3] & cfb_eorx) ^
  254. cfb_bgx);
  255. ((unsigned int *)tdest)[3] =
  256. SHTSWAP32((lk_cfb_font_dtable15[bits & 3] & cfb_eorx) ^
  257. cfb_bgx);
  258. }
  259. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  260. }
  261. break;
  262. case CFB_565RGB_16BIT:
  263. while (count--) {
  264. offs = (*s++) * MTK_VFH;
  265. pos = pfont + offs;
  266. row = MTK_VFH;
  267. if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3)) {
  268. for (tdest = pdest + row * LINE_LEN; row--; tdest -= LINE_LEN) {
  269. unsigned char bits = *pos++;
  270. ((unsigned int *)tdest)[0] =
  271. SWAP32_16((lk_cfb_font_dtable16[bits & 3] & cfb_eorx) ^
  272. cfb_bgx);
  273. ((unsigned int *)tdest)[1] =
  274. SWAP32_16((lk_cfb_font_dtable16[bits >> 2 & 3] &
  275. cfb_eorx) ^ cfb_bgx);
  276. ((unsigned int *)tdest)[2] =
  277. SWAP32_16((lk_cfb_font_dtable16[bits >> 4 & 3] &
  278. cfb_eorx) ^ cfb_bgx);
  279. ((unsigned int *)tdest)[3] =
  280. SWAP32_16((lk_cfb_font_dtable16[bits >> 6] & cfb_eorx) ^
  281. cfb_bgx);
  282. }
  283. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  284. } else {
  285. for (tdest = pdest; row--; tdest += LINE_LEN) {
  286. unsigned char bits = *pos++;
  287. ((unsigned int *)tdest)[0] =
  288. SHTSWAP32((lk_cfb_font_dtable16[bits >> 6] & cfb_eorx) ^
  289. cfb_bgx);
  290. ((unsigned int *)tdest)[1] =
  291. SHTSWAP32((lk_cfb_font_dtable16[bits >> 4 & 3] &
  292. cfb_eorx) ^ cfb_bgx);
  293. ((unsigned int *)tdest)[2] =
  294. SHTSWAP32((lk_cfb_font_dtable16[bits >> 2 & 3] &
  295. cfb_eorx) ^ cfb_bgx);
  296. ((unsigned int *)tdest)[3] =
  297. SHTSWAP32((lk_cfb_font_dtable16[bits & 3] & cfb_eorx) ^
  298. cfb_bgx);
  299. }
  300. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  301. }
  302. }
  303. break;
  304. case CFB_332RGB_8BIT:
  305. case CFB_FMT_8BIT:
  306. while (count--) {
  307. offs = (*s++) * MTK_VFH;
  308. pos = pfont + offs;
  309. row = MTK_VFH;
  310. for (tdest = pdest; row--; tdest += LINE_LEN) {
  311. unsigned char bits = *pos++;
  312. ((unsigned int *)tdest)[0] =
  313. (lk_cfb_font_dtable8[bits >> 4] & cfb_eorx) ^ cfb_bgx;
  314. ((unsigned int *)tdest)[1] =
  315. (lk_cfb_font_dtable8[bits & 15] & cfb_eorx) ^ cfb_bgx;
  316. }
  317. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  318. }
  319. break;
  320. case CFB_888RGB_24BIT:
  321. while (count--) {
  322. offs = (*s++) * MTK_VFH;
  323. pos = pfont + offs;
  324. row = MTK_VFH;
  325. for (tdest = pdest; row--; tdest += LINE_LEN) {
  326. unsigned char bits = *pos++;
  327. ((unsigned int *)tdest)[0] =
  328. (lk_cfb_font_dtb24[bits >> 4][0] & cfb_eorx) ^ cfb_bgx;
  329. ((unsigned int *)tdest)[1] =
  330. (lk_cfb_font_dtb24[bits >> 4][1] & cfb_eorx) ^ cfb_bgx;
  331. ((unsigned int *)tdest)[2] =
  332. (lk_cfb_font_dtb24[bits >> 4][2] & cfb_eorx) ^ cfb_bgx;
  333. ((unsigned int *)tdest)[3] =
  334. (lk_cfb_font_dtb24[bits & 15][0] & cfb_eorx) ^ cfb_bgx;
  335. ((unsigned int *)tdest)[4] =
  336. (lk_cfb_font_dtb24[bits & 15][1] & cfb_eorx) ^ cfb_bgx;
  337. ((unsigned int *)tdest)[5] =
  338. (lk_cfb_font_dtb24[bits & 15][2] & cfb_eorx) ^ cfb_bgx;
  339. }
  340. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  341. }
  342. break;
  343. case CFB_X888RGB_32BIT:
  344. while (count--) {
  345. offs = (*s++) * MTK_VFH;
  346. pos = pfont + offs;
  347. row = MTK_VFH;
  348. if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2)) {
  349. for (tdest = pdest + row * PIXEL_SIZE; row--; tdest -= PIXEL_SIZE) {
  350. unsigned char bits = *pos++;
  351. ((unsigned int *)tdest)[0 * VDO_COLS + MTK_VFH * VDO_COLS] =
  352. 0xff000000 |
  353. SWAP32((lk_cfb_font_dtable32[bits >> 4][0] & cfb_eorx) ^
  354. cfb_bgx);
  355. ((unsigned int *)tdest)[1 * VDO_COLS + MTK_VFH * VDO_COLS] =
  356. 0xff000000 |
  357. SWAP32((lk_cfb_font_dtable32[bits >> 4][1] & cfb_eorx) ^
  358. cfb_bgx);
  359. ((unsigned int *)tdest)[2 * VDO_COLS + MTK_VFH * VDO_COLS] =
  360. 0xff000000 |
  361. SWAP32((lk_cfb_font_dtable32[bits >> 4][2] & cfb_eorx) ^
  362. cfb_bgx);
  363. ((unsigned int *)tdest)[3 * VDO_COLS + MTK_VFH * VDO_COLS] =
  364. 0xff000000 |
  365. SWAP32((lk_cfb_font_dtable32[bits >> 4][3] & cfb_eorx) ^
  366. cfb_bgx);
  367. ((unsigned int *)tdest)[4 * VDO_COLS + MTK_VFH * VDO_COLS] =
  368. 0xff000000 |
  369. SWAP32((lk_cfb_font_dtable32[bits & 15][0] & cfb_eorx) ^
  370. cfb_bgx);
  371. ((unsigned int *)tdest)[5 * VDO_COLS + MTK_VFH * VDO_COLS] =
  372. 0xff000000 |
  373. SWAP32((lk_cfb_font_dtable32[bits & 15][1] & cfb_eorx) ^
  374. cfb_bgx);
  375. ((unsigned int *)tdest)[6 * VDO_COLS + MTK_VFH * VDO_COLS] =
  376. 0xff000000 |
  377. SWAP32((lk_cfb_font_dtable32[bits & 15][2] & cfb_eorx) ^
  378. cfb_bgx);
  379. ((unsigned int *)tdest)[7 * VDO_COLS + MTK_VFH * VDO_COLS] =
  380. 0xff000000 |
  381. SWAP32((lk_cfb_font_dtable32[bits & 15][3] & cfb_eorx) ^
  382. cfb_bgx);
  383. }
  384. pdest = pdest + MTK_VFH * PIXEL_SIZE;
  385. } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3)) {
  386. for (tdest = pdest + row * LINE_LEN; row--; tdest -= LINE_LEN) {
  387. unsigned char bits = *pos++;
  388. ((unsigned int *)tdest)[7] =
  389. 0xff000000 |
  390. SWAP32((lk_cfb_font_dtable32[bits >> 4][0] & cfb_eorx) ^
  391. cfb_bgx);
  392. ((unsigned int *)tdest)[6] =
  393. 0xff000000 |
  394. SWAP32((lk_cfb_font_dtable32[bits >> 4][1] & cfb_eorx) ^
  395. cfb_bgx);
  396. ((unsigned int *)tdest)[5] =
  397. 0xff000000 |
  398. SWAP32((lk_cfb_font_dtable32[bits >> 4][2] & cfb_eorx) ^
  399. cfb_bgx);
  400. ((unsigned int *)tdest)[4] =
  401. 0xff000000 |
  402. SWAP32((lk_cfb_font_dtable32[bits >> 4][3] & cfb_eorx) ^
  403. cfb_bgx);
  404. ((unsigned int *)tdest)[3] =
  405. 0xff000000 |
  406. SWAP32((lk_cfb_font_dtable32[bits & 15][0] & cfb_eorx) ^
  407. cfb_bgx);
  408. ((unsigned int *)tdest)[2] =
  409. 0xff000000 |
  410. SWAP32((lk_cfb_font_dtable32[bits & 15][1] & cfb_eorx) ^
  411. cfb_bgx);
  412. ((unsigned int *)tdest)[1] =
  413. 0xff000000 |
  414. SWAP32((lk_cfb_font_dtable32[bits & 15][2] & cfb_eorx) ^
  415. cfb_bgx);
  416. ((unsigned int *)tdest)[0] =
  417. 0xff000000 |
  418. SWAP32((lk_cfb_font_dtable32[bits & 15][3] & cfb_eorx) ^
  419. cfb_bgx);
  420. }
  421. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  422. } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
  423. for (tdest = pdest; row--; tdest += PIXEL_SIZE) {
  424. unsigned char bits = *pos++;
  425. ((unsigned int *)tdest)[7 * VDO_COLS + MTK_VFH * VDO_COLS] =
  426. 0xff000000 |
  427. SWAP32((lk_cfb_font_dtable32[bits >> 4][0] & cfb_eorx) ^
  428. cfb_bgx);
  429. ((unsigned int *)tdest)[6 * VDO_COLS + MTK_VFH * VDO_COLS] =
  430. 0xff000000 |
  431. SWAP32((lk_cfb_font_dtable32[bits >> 4][1] & cfb_eorx) ^
  432. cfb_bgx);
  433. ((unsigned int *)tdest)[5 * VDO_COLS + MTK_VFH * VDO_COLS] =
  434. 0xff000000 |
  435. SWAP32((lk_cfb_font_dtable32[bits >> 4][2] & cfb_eorx) ^
  436. cfb_bgx);
  437. ((unsigned int *)tdest)[4 * VDO_COLS + MTK_VFH * VDO_COLS] =
  438. 0xff000000 |
  439. SWAP32((lk_cfb_font_dtable32[bits >> 4][3] & cfb_eorx) ^
  440. cfb_bgx);
  441. ((unsigned int *)tdest)[3 * VDO_COLS + MTK_VFH * VDO_COLS] =
  442. 0xff000000 |
  443. SWAP32((lk_cfb_font_dtable32[bits & 15][0] & cfb_eorx) ^
  444. cfb_bgx);
  445. ((unsigned int *)tdest)[2 * VDO_COLS + MTK_VFH * VDO_COLS] =
  446. 0xff000000 |
  447. SWAP32((lk_cfb_font_dtable32[bits & 15][1] & cfb_eorx) ^
  448. cfb_bgx);
  449. ((unsigned int *)tdest)[1 * VDO_COLS + MTK_VFH * VDO_COLS] =
  450. 0xff000000 |
  451. SWAP32((lk_cfb_font_dtable32[bits & 15][2] & cfb_eorx) ^
  452. cfb_bgx);
  453. ((unsigned int *)tdest)[0 * VDO_COLS + MTK_VFH * VDO_COLS] =
  454. 0xff000000 |
  455. SWAP32((lk_cfb_font_dtable32[bits & 15][3] & cfb_eorx) ^
  456. cfb_bgx);
  457. }
  458. pdest = pdest + MTK_VFH * PIXEL_SIZE;
  459. } else {
  460. for (tdest = pdest; row--; tdest += LINE_LEN) {
  461. unsigned char bits = *pos++;
  462. ((unsigned int *)tdest)[0] =
  463. 0xff000000 |
  464. SWAP32((lk_cfb_font_dtable32[bits >> 4][0] & cfb_eorx) ^
  465. cfb_bgx);
  466. ((unsigned int *)tdest)[1] =
  467. 0xff000000 |
  468. SWAP32((lk_cfb_font_dtable32[bits >> 4][1] & cfb_eorx) ^
  469. cfb_bgx);
  470. ((unsigned int *)tdest)[2] =
  471. 0xff000000 |
  472. SWAP32((lk_cfb_font_dtable32[bits >> 4][2] & cfb_eorx) ^
  473. cfb_bgx);
  474. ((unsigned int *)tdest)[3] =
  475. 0xff000000 |
  476. SWAP32((lk_cfb_font_dtable32[bits >> 4][3] & cfb_eorx) ^
  477. cfb_bgx);
  478. ((unsigned int *)tdest)[4] =
  479. 0xff000000 |
  480. SWAP32((lk_cfb_font_dtable32[bits & 15][0] & cfb_eorx) ^
  481. cfb_bgx);
  482. ((unsigned int *)tdest)[5] =
  483. 0xff000000 |
  484. SWAP32((lk_cfb_font_dtable32[bits & 15][1] & cfb_eorx) ^
  485. cfb_bgx);
  486. ((unsigned int *)tdest)[6] =
  487. 0xff000000 |
  488. SWAP32((lk_cfb_font_dtable32[bits & 15][2] & cfb_eorx) ^
  489. cfb_bgx);
  490. ((unsigned int *)tdest)[7] =
  491. 0xff000000 |
  492. SWAP32((lk_cfb_font_dtable32[bits & 15][3] & cfb_eorx) ^
  493. cfb_bgx);
  494. }
  495. pdest = pdest + MTK_VFW * PIXEL_SIZE;
  496. }
  497. }
  498. break;
  499. default:
  500. break;
  501. }
  502. }
  503. #define MAKE_TWO_RGB565_COLOR(high, low) (((low) << 16) | (high))
  504. static void cfg_lk_dchar_scale(unsigned int x, unsigned int y, int font_scale, char c)
  505. {
  506. unsigned char ch = *((unsigned char *)&c);
  507. const unsigned char *cdat;
  508. unsigned char *dest;
  509. int rows, cols;
  510. int cols_mul, rows_mul;
  511. unsigned char *pfont = NULL;
  512. int font_draw_table16[4];
  513. if (x > (CFG_DISPLAY_WIDTH - MTK_VFW * font_scale)) {
  514. printf("draw width too large,x=%d\n", x);
  515. return;
  516. }
  517. if (y > (CFG_DISPLAY_HEIGHT - MTK_VFH * font_scale)) {
  518. printf("draw hight too large,y=%d\n", y);
  519. return;
  520. }
  521. dest = cfb_fb_addrs + y * LINE_LEN + x * PIXEL_SIZE;
  522. pfont = mtk_vdo_fntdata;
  523. switch (PIXEL_SIZE) {
  524. case 2:
  525. font_draw_table16[0] =
  526. MAKE_TWO_RGB565_COLOR(cfb_bgx, cfb_bgx);
  527. font_draw_table16[1] =
  528. MAKE_TWO_RGB565_COLOR(cfb_bgx, cfb_fgx);
  529. font_draw_table16[2] =
  530. MAKE_TWO_RGB565_COLOR(cfb_fgx, cfb_bgx);
  531. font_draw_table16[3] =
  532. MAKE_TWO_RGB565_COLOR(cfb_fgx, cfb_fgx);
  533. cdat = (const unsigned char *)pfont + ch * MTK_VFH;
  534. for (rows = MTK_VFH; rows--; dest += LINE_LEN) {
  535. unsigned char bits = *cdat++;
  536. ((UINT32 *)dest)[0] =
  537. font_draw_table16[bits >> 6];
  538. ((UINT32 *)dest)[1] =
  539. font_draw_table16[bits >> 4 & 3];
  540. ((UINT32 *)dest)[2] =
  541. font_draw_table16[bits >> 2 & 3];
  542. ((UINT32 *)dest)[3] =
  543. font_draw_table16[bits & 3];
  544. }
  545. break;
  546. case 3:
  547. cdat = (const unsigned char *)pfont + ch * MTK_VFH;
  548. for (rows = MTK_VFH; rows--; dest += LINE_LEN*font_scale) {
  549. unsigned char bits = *cdat++;
  550. unsigned char *temp_row = dest;
  551. for (rows_mul = 0; rows_mul < font_scale; rows_mul++) {
  552. unsigned char *tmp = temp_row;
  553. for (cols = 0; cols < 8; ++cols) {
  554. UINT32 color = ((bits >> (7 - cols)) & 0x1) ? cfb_fgx : cfb_bgx;
  555. for (cols_mul = 0; cols_mul < font_scale; cols_mul++) {
  556. ((unsigned char *)tmp)[0] =
  557. color & 0xff;
  558. ((unsigned char *)tmp)[1] =
  559. (color >> 8) & 0xff;
  560. ((unsigned char *)tmp)[2] =
  561. (color >> 16) & 0xff;
  562. tmp += 3;
  563. }
  564. }
  565. temp_row += LINE_LEN;
  566. }
  567. }
  568. break;
  569. case 4:
  570. cdat = (const unsigned char *)pfont + ch * MTK_VFH;
  571. for (rows = MTK_VFH; rows--; dest += LINE_LEN*font_scale) {
  572. unsigned char bits = *cdat++;
  573. unsigned char *temp_row = dest;
  574. for (rows_mul = 0; rows_mul < font_scale; rows_mul++) {
  575. unsigned char *tmp = temp_row;
  576. for (cols = 0; cols < 8; ++cols) {
  577. unsigned int color = ((bits >> (7 - cols)) & 0x1) ? cfb_fgx : cfb_bgx;
  578. for (cols_mul = 0; cols_mul < font_scale; cols_mul++) {
  579. ((unsigned char *)tmp)[0] =
  580. color & 0xff;
  581. ((unsigned char *)tmp)[1] =
  582. (color >> 8) & 0xff;
  583. ((unsigned char *)tmp)[2] =
  584. (color >> 16) & 0xff;
  585. ((unsigned char *)tmp)[3] =
  586. (color >> 24) | 0xff;
  587. tmp += 4;
  588. }
  589. }
  590. temp_row += LINE_LEN;
  591. }
  592. }
  593. break;
  594. default:
  595. printf("draw char fail,PIXEL_SIZE=%d\n", PIXEL_SIZE);
  596. }
  597. }
  598. void video_drawstr_scale(int font_scale, const char *s)
  599. {
  600. unsigned int cfb_count = strlen(s);
  601. int i = 0;
  602. while (cfb_count--) {
  603. cfg_lk_dchar_scale((get_cols() + i * font_scale) * MTK_VFW, get_rows() * MTK_VFH, font_scale, *s);
  604. s++;
  605. i++;
  606. }
  607. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  608. }
  609. void video_drawstr_scale_by_pixel(unsigned int x, unsigned int y, int font_scale, const char *s)
  610. {
  611. unsigned int cfb_count = strlen(s);
  612. int i = 0;
  613. while (cfb_count--) {
  614. cfg_lk_dchar_scale(x + i * font_scale * MTK_VFW, y, font_scale, *s);
  615. s++;
  616. i++;
  617. }
  618. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  619. }
  620. static inline void cfb_lk_drawstr(int this_xx, int this_yy, unsigned char *this_s)
  621. {
  622. cfb_lk_dchars(this_xx, this_yy, this_s, strlen((char *)this_s));
  623. }
  624. static void cfb_lk_putchar(int this_xx, int this_yy, unsigned char this_c)
  625. {
  626. cfb_lk_dchars(this_xx, vdo_fb_height + this_yy, &this_c, 1);
  627. }
  628. static void cfb_lk_scrollup(void)
  629. {
  630. /* * *copy* up *rows* ignoring *the* first *one */
  631. cfb_memcpy((int *)cfb_buf_addrs, (int *)((char *)cfb_buf_addrs + CFB_ROW_SIZE), CFB_SCROLL_SIZE >> 2);
  632. cfb_memset((int *)((char *)cfb_buf_addrs - CFB_ROW_SIZE + CFB_SIZE), CFB_ROW_SIZE >> 2, CS_BG_COL);
  633. }
  634. static void cfb_lk_backsp(void)
  635. {
  636. inc_cols(-1);
  637. if (get_cols() < 0) {
  638. set_cols(CFB_COL - 1);
  639. inc_rows(-1);
  640. if (get_rows() < 0)
  641. set_rows(0);
  642. }
  643. cfb_lk_putchar(get_cols() * MTK_VFW, get_rows() * MTK_VFH, ' ');
  644. }
  645. static void cfb_lk_newline(void)
  646. {
  647. /* Check if last character in the line was just drawn. If so, cursor was */
  648. /* overwriten and need not to be cleared. Cursor clearing without this */
  649. /* check causes overwriting the 1st character of the line if line lenght */
  650. /* is >= CFB_COL */
  651. inc_rows(1);
  652. set_cols(0);
  653. /* -Check if we need to scrol the terminal */
  654. if (get_rows() >= (int)(CFB_ROW)) {
  655. cfb_lk_scrollup();
  656. inc_rows(-1);
  657. }
  658. }
  659. static void cfb_lk_colback(void)
  660. {
  661. set_cols(0);
  662. }
  663. void video_putc(const char c)
  664. {
  665. static int next_line = 1;
  666. /* Jett: check newline here in order to */
  667. /* scroll the screen immediately for the first time video_printf() */
  668. if (cfb_cols >= (int)(CFB_COL))
  669. cfb_lk_newline();
  670. switch (c) {
  671. case 13:
  672. /* back to first column */
  673. cfb_lk_colback();
  674. break;
  675. case '\n':
  676. /* next line */
  677. if (cfb_cols || (!cfb_cols && next_line))
  678. cfb_lk_newline();
  679. next_line = 1;
  680. break;
  681. case 8:
  682. /* back space */
  683. cfb_lk_backsp();
  684. break;
  685. case 9:
  686. /* tab-8 */
  687. cfb_cols |= 0x0008;
  688. cfb_cols &= ~0x0007;
  689. if (get_cols() >= (int)(CFB_COL))
  690. cfb_lk_newline();
  691. break;
  692. default:
  693. /* draw-the-char */
  694. if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2))
  695. cfb_lk_putchar((CFB_ROW - get_rows()) * MTK_VFH, get_cols() * MTK_VFW, c);
  696. else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3))
  697. cfb_lk_putchar((CFB_COL - get_cols() - 1) * MTK_VFW,
  698. (CFB_ROW - get_rows()) * MTK_VFH, c);
  699. else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3))
  700. cfb_lk_putchar((CFB_COL - CFB_ROW + get_rows()) * MTK_VFH,
  701. (CFB_ROW - get_cols() - 10) * MTK_VFW, c);
  702. else
  703. cfb_lk_putchar(get_cols() * MTK_VFW, get_rows() * MTK_VFH, c);
  704. inc_cols(1);
  705. /* check-for-newline */
  706. if (get_cols() >= (int)(CFB_COL)) {
  707. cfb_lk_newline();
  708. next_line = 0;
  709. }
  710. }
  711. }
  712. void video_puts(const char *s)
  713. {
  714. unsigned int cfb_count = strlen(s);
  715. while (cfb_count--) {
  716. video_putc(*s);
  717. s++;
  718. }
  719. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  720. }
  721. void video_printf(const char *fmt, ...)
  722. {
  723. #ifdef CFB_CONSOLE_ON
  724. va_list args;
  725. /* unsigned int i; */
  726. char printbuffer[CONFIG_SYS_PBSIZE];
  727. va_start(args, fmt);
  728. /* /For this to work, printbuffer must be larger than */
  729. /* anything we ever want to print. */
  730. /* */
  731. vsprintf(printbuffer, fmt, args);
  732. va_end(args);
  733. /* Print the string */
  734. video_puts(printbuffer);
  735. #else
  736. printf("%s\n", fmt);
  737. #endif
  738. }
  739. static int video_lk_init(void)
  740. {
  741. unsigned char color8bit = 0;
  742. unsigned int data_fmt = 0;
  743. pGD = video_hw_init();
  744. if (pGD == NULL)
  745. return -1;
  746. if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2)
  747. || 0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
  748. g_cfb[0] = (SIZE_Y / FONT_WIDTH);
  749. g_cfb[1] = (SIZE_X / FONT_HEIGHT);
  750. } else {
  751. g_cfb[0] = (SIZE_Y / FONT_HEIGHT);
  752. g_cfb[1] = (SIZE_X / FONT_WIDTH);
  753. }
  754. cfb_fb_addrs = (void *)VDO_CFB_ADDRS;
  755. data_fmt = DATA_FMT;
  756. /* Init drawing pats */
  757. switch (data_fmt) {
  758. case CFB_555RGB_15BIT:
  759. cfb_fgx = ((FC_5B << 26) | (FC_5B << 21) | (FC_5B << 16) | /* high 16 0555 */
  760. (FC_5B << 10) | (FC_5B << 5) | FC_5B); /* / low 16 0555 */
  761. cfb_bgx = ((BC_5B << 26) | (BC_5B << 21) | (BC_5B << 16) | /* high 16 0555 */
  762. (BC_5B << 10) | (BC_5B << 5) | BC_5B); /* low 16 0555 */
  763. break;
  764. case CFB_565RGB_16BIT:
  765. cfb_fgx = ((FC_5B << 27) | (FC_6B << 21) | (FC_5B << 16) | /* high 16 565 */
  766. (FC_5B << 11) | (FC_6B << 5) | FC_5B); /* low 16 565 */
  767. cfb_bgx = ((BC_5B << 27) | (BC_6B << 21) | (BC_5B << 16) | /* high 16 565 */
  768. (BC_5B << 11) | (BC_6B << 5) | BC_5B); /* low 16 565 */
  769. break;
  770. case CFB_FMT_8BIT:
  771. video_set_lut(0x01, CS_FG_COL, CS_FG_COL, CS_FG_COL);
  772. video_set_lut(0x00, CS_BG_COL, CS_BG_COL, CS_BG_COL);
  773. cfb_fgx = 0x01010101;
  774. cfb_bgx = 0x00000000;
  775. break;
  776. case CFB_X888RGB_32BIT:
  777. cfb_fgx = (CS_FG_COL << 16) | (CS_FG_COL << 8) | CS_FG_COL;
  778. cfb_bgx = (CS_BG_COL << 16) | (CS_BG_COL << 8) | CS_BG_COL;
  779. break;
  780. case CFB_332RGB_8BIT:
  781. color8bit = ((CS_FG_COL & 0xe0) | ((CS_FG_COL >> 3) & 0x1c) | CS_FG_COL >> 6);
  782. cfb_fgx = (color8bit << 24) | (color8bit << 16) | (color8bit << 8) | color8bit;
  783. color8bit = ((CS_BG_COL & 0xe0) | ((CS_BG_COL >> 3) & 0x1c) | CS_BG_COL >> 6);
  784. cfb_bgx = (color8bit << 24) | (color8bit << 16) | (color8bit << 8) | color8bit;
  785. break;
  786. case CFB_888RGB_24BIT:
  787. cfb_fgx = (CS_FG_COL << 24) | (CS_FG_COL << 16) | (CS_FG_COL << 8) | CS_FG_COL;
  788. cfb_bgx = (CS_BG_COL << 24) | (CS_BG_COL << 16) | (CS_BG_COL << 8) | CS_BG_COL;
  789. break;
  790. default:
  791. break;
  792. }
  793. cfb_eorx = cfb_fgx ^ cfb_bgx;
  794. cfb_eorx_default = cfb_eorx;
  795. cfb_fgx_default = cfb_fgx;
  796. cfb_bgx_default = cfb_bgx;
  797. cfb_buf_addrs = cfb_fb_addrs;
  798. /* Initialize cfb char position */
  799. set_cols(0);
  800. set_rows(0);
  801. return 0;
  802. }
  803. void video_set_cursor(int row, int col)
  804. {
  805. if (row >= 0 && row < (int)(CFB_ROW) && col >= 0 && col <= (int)(CFB_COL)) {
  806. cfb_rows = row;
  807. cfb_cols = col;
  808. }
  809. }
  810. void video_set_fg_color(unsigned char r, unsigned char g, unsigned char b)
  811. {
  812. unsigned char color8bit = 0;
  813. unsigned int data_fmt = 0;
  814. unsigned char r_5B = r >> 3;
  815. unsigned char g_5B = g >> 3;
  816. unsigned char g_6B = g >> 2;
  817. unsigned char b_5B = b >> 3;
  818. data_fmt = DATA_FMT;
  819. printf("%s,(r-%u,g-%u,b-%u)\n",__func__, r, g, b);
  820. switch (data_fmt) {
  821. case CFB_555RGB_15BIT:
  822. cfb_fgx = ((r_5B << 26) | (g_5B << 21) | (b_5B << 16) | /* high 16 0555 */
  823. (r_5B << 10) | (r_5B << 5) | b_5B); /* / low 16 0555 */
  824. break;
  825. case CFB_565RGB_16BIT:
  826. cfb_fgx = ((r_5B << 27) | (g_6B << 21) | (b_5B << 16) | /* high 16 565 */
  827. (r_5B << 11) | (g_6B << 5) | b_5B); /* low 16 565 */
  828. break;
  829. case CFB_X888RGB_32BIT:
  830. cfb_fgx = (r << 16) | (g << 8) | b;
  831. break;
  832. case CFB_332RGB_8BIT:
  833. color8bit = ((r & 0xe0) | ((g >> 3) & 0x1c) | b >> 6);
  834. cfb_fgx = (color8bit << 24) | (color8bit << 16) | (color8bit << 8) | color8bit;
  835. break;
  836. default:
  837. printf("%s,not supported data_fmt:%u\n",__func__,data_fmt);
  838. break;
  839. }
  840. cfb_eorx = cfb_fgx ^ cfb_bgx;
  841. }
  842. void video_set_bg_color(unsigned char r, unsigned char g, unsigned char b)
  843. {
  844. unsigned char color8bit = 0;
  845. unsigned int data_fmt = 0;
  846. unsigned char r_5B = r >> 3;
  847. unsigned char g_5B = g >> 3;
  848. unsigned char g_6B = g >> 2;
  849. unsigned char b_5B = b >> 3;
  850. data_fmt = DATA_FMT;
  851. printf("%s,(r-%u,g-%u,b-%u)\n",__func__, r, g, b);
  852. switch (data_fmt) {
  853. case CFB_555RGB_15BIT:
  854. cfb_bgx = ((r_5B << 26) | (g_5B << 21) | (b_5B << 16) | /* high 16 0555 */
  855. (r_5B << 10) | (r_5B << 5) | b_5B); /* / low 16 0555 */
  856. break;
  857. case CFB_565RGB_16BIT:
  858. cfb_bgx = ((r_5B << 27) | (g_6B << 21) | (b_5B << 16) | /* high 16 565 */
  859. (r_5B << 11) | (g_6B << 5) | b_5B); /* low 16 565 */
  860. break;
  861. case CFB_X888RGB_32BIT:
  862. cfb_bgx = (r << 16) | (g << 8) | b;
  863. break;
  864. case CFB_332RGB_8BIT:
  865. color8bit = ((r & 0xe0) | ((g >> 3) & 0x1c) | b >> 6);
  866. cfb_bgx = (color8bit << 24) | (color8bit << 16) | (color8bit << 8) | color8bit;
  867. break;
  868. default:
  869. printf("%s,not supported data_fmt:%u\n",__func__,data_fmt);
  870. break;
  871. }
  872. cfb_eorx = cfb_fgx ^ cfb_bgx;
  873. }
  874. void video_set_default_color(void)
  875. {
  876. printf("%s\n",__func__);
  877. cfb_eorx = cfb_eorx_default;
  878. cfb_fgx = cfb_fgx_default;
  879. cfb_bgx = cfb_bgx_default;
  880. }
  881. int video_get_rows(void)
  882. {
  883. return CFB_ROW;
  884. }
  885. int video_get_colums(void)
  886. {
  887. return CFB_COL;
  888. }
  889. void video_clean_screen(void)
  890. {
  891. memset((void *)VDO_CFB_ADDRS, 0, VDO_CFB_SIZE);
  892. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  893. }
  894. static void video_draw_image(void *addr, unsigned int x, unsigned int y,
  895. unsigned int w, unsigned int h, const unsigned int *color)
  896. {
  897. unsigned int i = 0;
  898. unsigned int j = 0;
  899. void *start_addr = addr + y * LINE_LEN + x * PIXEL_SIZE;
  900. unsigned int *line_addr = start_addr;
  901. for (j=0; j<h; j++) {
  902. line_addr = start_addr;
  903. for (i = 0; i<w; i++) {
  904. line_addr[i] = (color[j * w + i] & 0xFFFFFF) | 0xFF000000;
  905. }
  906. start_addr += LINE_LEN;
  907. }
  908. mt_disp_update(0, 0, 0, 0);
  909. }
  910. static void video_clear_image(void *addr, unsigned int x, unsigned int y,
  911. unsigned int w, unsigned int h, const unsigned int color)
  912. {
  913. unsigned int i = 0;
  914. unsigned int j = 0;
  915. void *start_addr = addr + y * LINE_LEN + x * PIXEL_SIZE;
  916. unsigned int *line_addr = start_addr;
  917. for (j=0; j<h; j++) {
  918. line_addr = start_addr;
  919. for (i = 0; i<w; i++) {
  920. line_addr[i] = color | 0xFF000000;
  921. }
  922. start_addr += LINE_LEN;
  923. }
  924. mt_disp_update(0, 0, 0, 0);
  925. }
  926. //set bg & fg colors, now only support color format ARGB
  927. void video_set_bgfg_colors(unsigned int bg, unsigned int fg)
  928. {
  929. unsigned char r,g,b;
  930. r = bg >> 16 & 0xFF;
  931. g = bg >> 8 & 0xFF;
  932. b = bg & 0xFF;
  933. cfb_bg_alpha = bg & 0xFF000000;
  934. video_set_bg_color(r, g, b);
  935. r = fg >> 16 & 0xFF;
  936. g = fg >> 8 & 0xFF;
  937. b = fg & 0xFF;
  938. cfb_fg_alpha = fg & 0xFF000000;
  939. video_set_fg_color(r, g, b);
  940. }
  941. //set fg colors, now only support color format ARGB
  942. void video_set_fgcolor(unsigned int fg)
  943. {
  944. unsigned char r,g,b;
  945. r = fg >> 16 & 0xFF;
  946. g = fg >> 8 & 0xFF;
  947. b = fg & 0xFF;
  948. cfb_fg_alpha = fg & 0xFF000000;
  949. video_set_fg_color(r, g, b);
  950. }
  951. //set bg color, now only support color format ARGB
  952. void video_set_bgcolor(unsigned int bg)
  953. {
  954. unsigned char r,g,b;
  955. r = bg >> 16 & 0xFF;
  956. g = bg >> 8 & 0xFF;
  957. b = bg & 0xFF;
  958. cfb_bg_alpha = bg & 0xFF000000;
  959. video_set_bg_color(r, g, b);
  960. }
  961. //clear screen by bg
  962. void video_clean_screen_by_bg(void)
  963. {
  964. video_clear_image(cfb_fb_addrs, 0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT, cfb_bgx | cfb_bg_alpha);
  965. }
  966. //set x & y
  967. void video_set_position(int x, int y)
  968. {
  969. video_set_cursor(y, x);
  970. }
  971. //show string
  972. void video_disp_string(char *str)
  973. {
  974. video_printf("%s\n", str);
  975. }
  976. //show image
  977. void fbcon_display_image(const unsigned int data[],
  978. unsigned int xpos, unsigned int ypos, unsigned int width, unsigned int height)
  979. {
  980. video_draw_image(cfb_fb_addrs, xpos, ypos, width, height, data);
  981. }
  982. //clear image
  983. void video_clear_image_by_color(const unsigned int data,
  984. unsigned int xpos, unsigned int ypos, unsigned int width, unsigned int height)
  985. {
  986. video_clear_image(cfb_fb_addrs, xpos, ypos, width, height, data);
  987. }
  988. //package second
  989. void fbcon_set_color(unsigned int bg, unsigned int fg)
  990. {
  991. video_set_bgfg_colors(bg, fg);
  992. return;
  993. }
  994. void fbcon_clear(void)
  995. {
  996. video_clean_screen_by_bg();
  997. return;
  998. }
  999. void fbcon_set_position(unsigned int x, unsigned int y)
  1000. {
  1001. if ((x > CFG_DISPLAY_WIDTH) || (y > CFG_DISPLAY_HEIGHT)) {
  1002. printf("coordinate set error \n");
  1003. }
  1004. cfb_pixel_position_x = x;
  1005. cfb_pixel_position_y = y;
  1006. return;
  1007. }
  1008. void fbcon_get_position(unsigned int *x, unsigned int *y)
  1009. {
  1010. if((x == NULL ) || (y == NULL)) {
  1011. printf("ERROR, pointer is NULL\n");
  1012. return;
  1013. }
  1014. *x = cfb_pixel_position_x;
  1015. *y = cfb_pixel_position_y;
  1016. }
  1017. void fbcon_disp_string(int font_scale,const char *s)
  1018. {
  1019. unsigned int x = 0, y = 0;
  1020. if(font_scale < 1){
  1021. printf("font_scale error\n");
  1022. return;
  1023. }
  1024. if(s == NULL){
  1025. printf("error, string is null\n");
  1026. return;
  1027. }
  1028. fbcon_get_position(&x, &y);
  1029. video_drawstr_scale_by_pixel(x, y, font_scale, s);
  1030. return;
  1031. }
  1032. void fbcon_clear_image(const unsigned int data,
  1033. unsigned int xpos, unsigned int ypos, unsigned int width, unsigned int height)
  1034. {
  1035. video_clear_image_by_color(data, xpos, ypos, width, height);
  1036. return;
  1037. }
  1038. int drv_video_init(void)
  1039. {
  1040. if (video_lk_init() == -1)
  1041. return 0;
  1042. /* Jett: set cursor to the right-bottom corner */
  1043. /* scroll screen immediately for the first time video_printf() */
  1044. video_set_cursor(CFB_ROW - 1, CFB_COL);
  1045. return 0;
  1046. }