drv_glcd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*************************************************************************
  2. *
  3. * Used with ICCARM and AARM.
  4. *
  5. * (c) Copyright IAR Systems 2008
  6. *
  7. * File name : drv_glcd.c
  8. * Description : Graphical LCD driver
  9. *
  10. * History :
  11. * 1. Date : 6, March 2008
  12. * Author : Stanimir Bonev
  13. * Description : Create
  14. *
  15. *
  16. * $Revision: 24636 $
  17. *
  18. * @Modify: NXP MCU Application Team - NguyenCao
  19. * @Date: 04. March. 2011
  20. **************************************************************************/
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <assert.h>
  24. //#include "ConstGlbPtrs.h"
  25. //#include "Ex_sdram.h"
  26. #include "drv_glcd.h"
  27. #include "lpc177x_8x_clkpwr.h"
  28. #include "lpc177x_8x_pinsel.h"
  29. //#include "Cursor.h"
  30. //#include "logo.h"
  31. //#define MHZ
  32. #define C_GLCD_CLK_PER_LINE (C_GLCD_H_SIZE + C_GLCD_H_PULSE + C_GLCD_H_FRONT_PORCH + C_GLCD_H_BACK_PORCH)
  33. #define C_GLCD_LINES_PER_FRAME (C_GLCD_V_SIZE + C_GLCD_V_PULSE + C_GLCD_V_FRONT_PORCH + C_GLCD_V_BACK_PORCH)
  34. #define C_GLCD_PIX_CLK (C_GLCD_CLK_PER_LINE * C_GLCD_LINES_PER_FRAME)
  35. //LPC_LCD_TypeDef * const g_pLCD = ((LPC_LCD_TypeDef*) LPC_LCD_BASE);
  36. //LPC_SC_TypeDef * const g_pSC = ((LPC_SC_TypeDef*) LPC_SC_BASE);
  37. #define SDRAM_BASE 0xA0000000 /* CS0 */
  38. #define SDRAM_BASE_ADDR SDRAM_BASE
  39. #define LCD_VRAM_BASE_ADDR ((unsigned long)SDRAM_BASE_ADDR + 0x00000000)
  40. #define LCD_CURSOR_BASE_ADDR ((unsigned long)0x20088800)
  41. static pFontType_t pCurrFont = NULL;
  42. static LdcPixel_t TextColour;
  43. static LdcPixel_t TextBackgndColour;
  44. static unsigned long TextX_Pos = 0;
  45. static unsigned long TextY_Pos = 0;
  46. static unsigned long XL_Win = 0;
  47. static unsigned long YU_Win = 0;
  48. static unsigned long XR_Win = C_GLCD_H_SIZE-1;
  49. static unsigned long YD_Win = C_GLCD_V_SIZE-1;
  50. static unsigned long TabSize = TEXT_DEF_TAB_SIZE;
  51. static unsigned long WindY_Size, WindX_Size;
  52. static unsigned long CurrY_Size, CurrX_Size;
  53. static unsigned long *pWind;
  54. static unsigned long *pPix;
  55. /*************************************************************************
  56. * Function Name: GLCD_Cursor_Cnfg
  57. * Parameters:
  58. *
  59. * Return: none
  60. *
  61. * Description: Configure the cursor
  62. *
  63. *************************************************************************/
  64. void GLCD_Cursor_Cfg(int Cfg)
  65. {
  66. LPC_LCD->CRSR_CFG = Cfg;
  67. }
  68. /*************************************************************************
  69. * Function Name: GLCD_Cursor_En
  70. * Parameters: cursor - Cursor Number
  71. *
  72. * Return: none
  73. *
  74. * Description: Enable Cursor
  75. *
  76. *************************************************************************/
  77. void GLCD_Cursor_En(int cursor)
  78. {
  79. LPC_LCD->CRSR_CTRL |= (cursor<<4);
  80. LPC_LCD->CRSR_CTRL |= 1;
  81. }
  82. /*************************************************************************
  83. * Function Name: GLCD_Cursor_Dis
  84. * Parameters: None
  85. *
  86. * Return: none
  87. *
  88. * Description: Disable Cursor
  89. *
  90. *************************************************************************/
  91. void GLCD_Cursor_Dis(int cursor)
  92. {
  93. LPC_LCD->CRSR_CTRL &= (1<<0);
  94. }
  95. /*************************************************************************
  96. * Function Name: GLCD_Move_Cursor
  97. * Parameters: x - cursor x position
  98. * y - cursor y position
  99. *
  100. * Return: none
  101. *
  102. * Description: Moves cursor on position (x,y). Negativ values are posible.
  103. *
  104. *************************************************************************/
  105. void GLCD_Move_Cursor(int x, int y)
  106. {
  107. LPC_LCD->CRSR_CLIP = 0;
  108. LPC_LCD->CRSR_XY = 0;
  109. if(0 <= x)
  110. {//no clipping
  111. LPC_LCD->CRSR_XY |= (x & 0x3FF);
  112. }
  113. else
  114. {//clip x
  115. LPC_LCD->CRSR_CLIP |= -x;
  116. }
  117. if(0 <= y)
  118. {//no clipping
  119. LPC_LCD->CRSR_XY |= (y << 16);
  120. }
  121. else
  122. {//clip y
  123. LPC_LCD->CRSR_CLIP |= (-y << 8);
  124. }
  125. }
  126. /*************************************************************************
  127. * Function Name: GLCD_Copy_Cursor
  128. * Parameters: pCursor - pointer to cursor conts image
  129. * cursor - cursor Number (0,1,2 or 3)
  130. * for 64x64(size 256) pix cursor always use 0
  131. * size - cursor size in words
  132. * Return: none
  133. *
  134. * Description: Copy Cursor from const image to LCD RAM image
  135. *
  136. *************************************************************************/
  137. void GLCD_Copy_Cursor (const unsigned long *pCursor, int cursor, int size)
  138. {
  139. unsigned long i ;
  140. unsigned long * pDst = (unsigned long *)LCD_CURSOR_BASE_ADDR;
  141. pDst += cursor*64;
  142. for(i = 0; i < size ; i++)
  143. // *pDst++ = *pCursor++;
  144. {
  145. *pDst = *pCursor;
  146. pDst++;
  147. pCursor++;
  148. }
  149. }
  150. /*************************************************************************
  151. * Function Name: GLCD_Init
  152. * Parameters: const unsigned long *pPain, const unsigned long * pPallete
  153. *
  154. * Return: none
  155. *
  156. * Description: GLCD controller init
  157. *
  158. *************************************************************************/
  159. void GLCD_Init (void* VRAMBase)
  160. {
  161. // unsigned long i;
  162. // Assign pins
  163. LPC_IOCON->P2_9 = 0x06; // VD3, R0
  164. LPC_IOCON->P2_6 = 0x07; // VD4, R1
  165. LPC_IOCON->P2_7 = 0x07; // VD5, R2
  166. LPC_IOCON->P4_28 = 0x05; // VD6, R3
  167. LPC_IOCON->P4_29 = 0x05; // VD7, R4
  168. LPC_IOCON->P1_20 = 0x07; // VD10, G0
  169. LPC_IOCON->P1_21 = 0x07; // VD11, G1
  170. LPC_IOCON->P1_22 = 0x07; // VD12, G2
  171. LPC_IOCON->P1_23 = 0x07; // VD13, G3
  172. LPC_IOCON->P1_24 = 0x07; // VD14, G4
  173. LPC_IOCON->P1_25 = 0x07; // VD15, G5
  174. LPC_IOCON->P2_13 = 0x07; // VD19, B0
  175. LPC_IOCON->P1_26 = 0x07; // VD20, B1
  176. LPC_IOCON->P1_27 = 0x07; // VD21, B2
  177. LPC_IOCON->P1_28 = 0x07; // VD22, B3
  178. LPC_IOCON->P1_29 = 0x07; // VD23, B4
  179. LPC_IOCON->P2_2 = 0x07; // DCLK
  180. LPC_IOCON->P2_0 = 0x07; // DSIP(power)
  181. LPC_IOCON->P2_5 = 0x07; // HSYNC
  182. LPC_IOCON->P2_3 = 0x07; // VSYNC
  183. LPC_IOCON->P2_4 = 0x07; // DataEn
  184. // LPC_IOCON->P5_4 = 0x00; // Backlight
  185. // >>> debug >>>
  186. // <<< debug <<<
  187. /*Back light enable*/
  188. // LPC_GPIO5->DIR = (1<<4);
  189. // LPC_GPIO5->SET= (5<<4);
  190. //Turn on LCD clock
  191. CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE);
  192. // Disable cursor
  193. LPC_LCD->CRSR_CTRL &=~(1<<0);
  194. // disable GLCD controller
  195. LPC_LCD->CTRL = 0;
  196. // RGB888
  197. LPC_LCD->CTRL &= ~(0x07 <<1);
  198. LPC_LCD->CTRL |= (6<<1);
  199. // TFT panel
  200. LPC_LCD->CTRL |= (1<<5);
  201. // single panel
  202. LPC_LCD->CTRL &= ~(1<<7);
  203. // notmal output
  204. LPC_LCD->CTRL &= ~(1<<8);
  205. // little endian byte order
  206. LPC_LCD->CTRL &= ~(1<<9);
  207. // little endian pix order
  208. LPC_LCD->CTRL &= ~(1<<10);
  209. // disable power
  210. LPC_LCD->CTRL &= ~(1<<11);
  211. // init pixel clock
  212. // g_pSC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK);
  213. LPC_SC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK);
  214. // bypass inrenal clk divider
  215. LPC_LCD->POL |=(1<<26);
  216. // clock source for the LCD block is HCLK
  217. LPC_LCD->POL &= ~(1<<5);
  218. // LCDFP pin is active LOW and inactive HIGH
  219. LPC_LCD->POL |= (1<<11);
  220. // LCDLP pin is active LOW and inactive HIGH
  221. LPC_LCD->POL |= (1<<12);
  222. // data is driven out into the LCD on the falling edge
  223. LPC_LCD->POL &= ~(1<<13);
  224. // active high
  225. LPC_LCD->POL &= ~(1<<14);
  226. LPC_LCD->POL &= ~(0x3FF <<16);
  227. LPC_LCD->POL |= (C_GLCD_H_SIZE-1)<<16;
  228. // init Horizontal Timing
  229. LPC_LCD->TIMH = 0; //reset TIMH before set value
  230. LPC_LCD->TIMH |= (C_GLCD_H_BACK_PORCH - 1)<<24;
  231. LPC_LCD->TIMH |= (C_GLCD_H_FRONT_PORCH - 1)<<16;
  232. LPC_LCD->TIMH |= (C_GLCD_H_PULSE - 1)<<8;
  233. LPC_LCD->TIMH |= ((C_GLCD_H_SIZE/16) - 1)<<2;
  234. // init Vertical Timing
  235. LPC_LCD->TIMV = 0; //reset TIMV value before setting
  236. LPC_LCD->TIMV |= (C_GLCD_V_BACK_PORCH)<<24;
  237. LPC_LCD->TIMV |= (C_GLCD_V_FRONT_PORCH)<<16;
  238. LPC_LCD->TIMV |= (C_GLCD_V_PULSE - 1)<<10;
  239. LPC_LCD->TIMV |= C_GLCD_V_SIZE - 1;
  240. // Frame Base Address doubleword aligned
  241. LPC_LCD->UPBASE = (unsigned long)VRAMBase & ~7UL ;
  242. LPC_LCD->LPBASE = (unsigned long)VRAMBase & ~7UL ;
  243. }
  244. /*************************************************************************
  245. * Function Name: GLCD_SetPallet
  246. * Parameters: const unsigned long * pPallete
  247. *
  248. * Return: none
  249. *
  250. * Description: GLCD init colour pallete
  251. *
  252. *************************************************************************/
  253. void GLCD_SetPallet (const unsigned long * pPallete)
  254. {
  255. unsigned long i;
  256. unsigned long * pDst = (unsigned long *)LPC_LCD->PAL;
  257. // //assert(pPallete);
  258. for (i = 0; i < 128; i++)
  259. {
  260. *pDst++ = *pPallete++;
  261. }
  262. }
  263. /*************************************************************************
  264. * Function Name: GLCD_Ctrl
  265. * Parameters: Bool bEna
  266. *
  267. * Return: none
  268. *
  269. * Description: GLCD enable disabe sequence
  270. *
  271. *************************************************************************/
  272. void GLCD_Ctrl (Bool bEna)
  273. {
  274. volatile unsigned long i;
  275. if (bEna)
  276. {
  277. // LCD_CTRL_bit.LcdEn = 1;
  278. LPC_LCD->CTRL |= (1<<0);
  279. for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
  280. // LCD_CTRL_bit.LcdPwr= 1; // enable power
  281. LPC_LCD->CTRL |= (1<<11);
  282. }
  283. else
  284. {
  285. // LCD_CTRL_bit.LcdPwr= 0; // disable power
  286. LPC_LCD->CTRL &= ~(1<<11);
  287. for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
  288. // LCD_CTRL_bit.LcdEn = 0;
  289. LPC_LCD->CTRL &= ~(1<<0);
  290. }
  291. }
  292. /*************************************************************************
  293. * Function Name: GLCD_SetFont
  294. * Parameters: pFontType_t pFont, LdcPixel_t Color
  295. * LdcPixel_t BackgndColor
  296. *
  297. * Return: none
  298. *
  299. * Description: Set current font, font color and background color
  300. *
  301. *************************************************************************/
  302. void GLCD_SetFont(pFontType_t pFont, LdcPixel_t Color, LdcPixel_t BackgndColor)
  303. {
  304. pCurrFont = pFont;
  305. TextColour = Color;
  306. TextBackgndColour = BackgndColor;
  307. }
  308. /*************************************************************************
  309. * Function Name: GLCD_SetWindow
  310. * Parameters: unsigned long X_Left, unsigned long Y_Up,
  311. * unsigned long X_Right, unsigned long Y_Down
  312. *
  313. * Return: none
  314. *
  315. * Description: Set draw window XY coordinate in pixels
  316. *
  317. *************************************************************************/
  318. void GLCD_SetWindow(unsigned long X_Left, unsigned long Y_Up,
  319. unsigned long X_Right, unsigned long Y_Down)
  320. {
  321. // //assert(X_Right < C_GLCD_H_SIZE);
  322. // //assert(Y_Down < C_GLCD_V_SIZE);
  323. // //assert(X_Left < X_Right);
  324. //assert(Y_Up < Y_Down);
  325. XL_Win = X_Left;
  326. YU_Win = Y_Up;
  327. XR_Win = X_Right;
  328. YD_Win = Y_Down;
  329. }
  330. /*************************************************************************
  331. * Function Name: GLCD_TextSetPos
  332. * Parameters: unsigned long X_UpLeft, unsigned long Y_UpLeft,
  333. * unsigned long X_DownLeft, unsigned long Y_DownLeft
  334. *
  335. * Return: none
  336. *
  337. * Description: Set text X,Y coordinate in characters
  338. *
  339. *************************************************************************/
  340. void GLCD_TextSetPos(unsigned long X, unsigned long Y)
  341. {
  342. TextX_Pos = X;
  343. TextY_Pos = Y;
  344. }
  345. /*************************************************************************
  346. * Function Name: GLCD_TextSetTabSize
  347. * Parameters: unsigned long Size
  348. *
  349. * Return: none
  350. *
  351. * Description: Set text tab size in characters
  352. *
  353. *************************************************************************/
  354. void GLCD_TextSetTabSize(unsigned long Size)
  355. {
  356. TabSize = Size;
  357. }
  358. /*************************************************************************
  359. * Function Name: LCD_SET_WINDOW
  360. * Parameters: int c
  361. *
  362. * Return: none
  363. *
  364. * Description: Put char function
  365. *
  366. *************************************************************************/
  367. static
  368. void LCD_SET_WINDOW (unsigned long X_Left, unsigned long X_Right,
  369. unsigned long Y_Up, unsigned long Y_Down)
  370. {
  371. pPix = pWind = ((unsigned long *)LCD_VRAM_BASE_ADDR) + X_Left + (Y_Up*C_GLCD_H_SIZE);
  372. WindX_Size = X_Right - X_Left;
  373. WindY_Size = Y_Down - Y_Up;
  374. CurrX_Size = CurrY_Size = 0;
  375. }
  376. /*************************************************************************
  377. * Function Name: LCD_SET_WINDOW
  378. * Parameters: int c
  379. *
  380. * Return: none
  381. *
  382. * Description: Put char function
  383. *
  384. *************************************************************************/
  385. static
  386. void LCD_WRITE_PIXEL (unsigned long Pixel)
  387. {
  388. *pPix++ = Pixel;
  389. if (++CurrX_Size > WindX_Size)
  390. {
  391. CurrX_Size = 0;
  392. if(++CurrY_Size > WindY_Size)
  393. {
  394. CurrY_Size = 0;
  395. }
  396. pPix = pWind + CurrY_Size * C_GLCD_H_SIZE;
  397. }
  398. }
  399. /*************************************************************************
  400. * Function Name: GLCD_TextCalcWindow
  401. * Parameters: unsigned long * pXL, unsigned long * pXR,
  402. * unsigned long * pYU, unsigned long * pYD,
  403. * unsigned long * pH_Size, unsigned long * pV_Size
  404. *
  405. * Return: Bool
  406. * FALSE - out of window coordinate aren't valid
  407. * TRUE - the returned coordinate are valid
  408. *
  409. * Description: Calculate character window
  410. *
  411. *************************************************************************/
  412. static
  413. Bool GLCD_TextCalcWindow (unsigned long * pXL, unsigned long * pXR,
  414. unsigned long * pYU, unsigned long * pYD,
  415. unsigned long * pH_Size, unsigned long * pV_Size)
  416. {
  417. *pH_Size = pCurrFont->H_Size;
  418. *pV_Size = pCurrFont->V_Size;
  419. *pXL = XL_Win + (TextX_Pos*pCurrFont->H_Size);
  420. if(*pXL > XR_Win)
  421. {
  422. return(FALSE);
  423. }
  424. *pYU = YU_Win + (TextY_Pos*pCurrFont->V_Size);
  425. if(*pYU > YD_Win)
  426. {
  427. return(FALSE);
  428. }
  429. *pXR = XL_Win + ((TextX_Pos+1)*pCurrFont->H_Size) - 1;
  430. if(*pXR > XR_Win)
  431. {
  432. *pH_Size -= *pXR - XR_Win;
  433. *pXR = XR_Win;
  434. }
  435. *pYD = YU_Win + ((TextY_Pos+1)*pCurrFont->V_Size) - 1;
  436. if(*pYD > YD_Win)
  437. {
  438. *pV_Size -= *pYD - YD_Win;
  439. *pYD = YD_Win;
  440. }
  441. return(TRUE);
  442. }
  443. /*************************************************************************
  444. * Function Name: putchar
  445. * Parameters: int c
  446. *
  447. * Return: none
  448. *
  449. * Description: Put char function
  450. *
  451. *************************************************************************/
  452. int _putchar (int c)
  453. {
  454. uint8_t *pSrc;
  455. unsigned long H_Line;
  456. unsigned long xl,xr,yu,yd,Temp,V_Size, H_Size, SrcInc = 1;
  457. unsigned long WhiteSpaceNumb;
  458. unsigned long i, j, k;
  459. if(pCurrFont == NULL)
  460. {
  461. return(EOF);
  462. }
  463. H_Line = (pCurrFont->H_Size / 8) + ((pCurrFont->H_Size % 8)?1:0);
  464. switch(c)
  465. {
  466. case '\n': // go to begin of next line (NewLine)
  467. ++TextY_Pos;
  468. break;
  469. case '\r': // go to begin of this line (Carriage Return)
  470. // clear from current position to end of line
  471. while(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
  472. {
  473. LCD_SET_WINDOW(xl,xr,yu,yd);
  474. for(i = 0; i < V_Size; ++i)
  475. {
  476. for(j = 0; j < H_Size; ++j)
  477. {
  478. LCD_WRITE_PIXEL(TextBackgndColour);
  479. }
  480. }
  481. ++TextX_Pos;
  482. }
  483. TextX_Pos = 0;
  484. break;
  485. case '\b': // go back one position (BackSpace)
  486. if(TextX_Pos)
  487. {
  488. --TextX_Pos;
  489. // del current position
  490. if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
  491. {
  492. LCD_SET_WINDOW(xl,xr,yu,yd);
  493. for(i = 0; i < V_Size; ++i)
  494. {
  495. for(j = 0; j < H_Size; ++j)
  496. {
  497. LCD_WRITE_PIXEL(TextBackgndColour);
  498. }
  499. }
  500. }
  501. }
  502. break;
  503. case '\t': // go to next Horizontal Tab stop
  504. WhiteSpaceNumb = TabSize - (TextX_Pos%TabSize);
  505. for(k = 0; k < WhiteSpaceNumb; ++k)
  506. {
  507. LCD_SET_WINDOW(xl,xr,yu,yd);
  508. if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
  509. {
  510. for(i = 0; i < V_Size; ++i)
  511. {
  512. for(j = 0; j < H_Size; ++j)
  513. {
  514. LCD_WRITE_PIXEL(TextBackgndColour);
  515. }
  516. }
  517. ++TextX_Pos;
  518. }
  519. else
  520. {
  521. break;
  522. }
  523. }
  524. break;
  525. case '\f': // go to top of page (Form Feed)
  526. // clear entire window
  527. H_Size = XR_Win - XL_Win;
  528. V_Size = YD_Win - YU_Win;
  529. // set character window X left, Y right
  530. LCD_SET_WINDOW(XL_Win,XR_Win,YU_Win,YD_Win);
  531. // Fill window with background font color
  532. for(i = 0; i <= V_Size; ++i)
  533. {
  534. for(j = 0; j <= H_Size; ++j)
  535. {
  536. LCD_WRITE_PIXEL(TextBackgndColour);
  537. }
  538. }
  539. TextX_Pos = TextY_Pos = 0;
  540. break;
  541. case '\a': // signal an alert (BELl)
  542. TEXT_BEL1_FUNC();
  543. break;
  544. default:
  545. // Calculate the current character base address from stream
  546. // and the character position
  547. if((c < pCurrFont->CharacterOffset) &&
  548. (c >= pCurrFont->CharactersNuber))
  549. {
  550. c = 0;
  551. }
  552. else
  553. {
  554. c -= pCurrFont->CharacterOffset;
  555. }
  556. pSrc = pCurrFont->pFontStream + (H_Line * pCurrFont->V_Size * c);
  557. // Calculate character window and fit it in the text window
  558. if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
  559. {
  560. // set character window X left, Y right
  561. LCD_SET_WINDOW(xl,xr,yu,yd);
  562. // Send char data
  563. for(i = 0; i < V_Size; ++i)
  564. {
  565. SrcInc = H_Line;
  566. for(j = 0; j < H_Size; ++j)
  567. {
  568. Temp = (*pSrc & (1UL << (j&0x7)))?TextColour:TextBackgndColour;
  569. LCD_WRITE_PIXEL(Temp);
  570. if((j&0x7) == 7)
  571. {
  572. ++pSrc;
  573. --SrcInc;
  574. }
  575. }
  576. // next line of character
  577. pSrc += SrcInc;
  578. }
  579. }
  580. ++TextX_Pos;
  581. }
  582. return(c);
  583. }
  584. /*************************************************************************
  585. * Function Name: GLCD_LoadPic
  586. * Parameters: unsigned long X_Left, unsigned long Y_Up, Bmp_t * pBmp
  587. *
  588. * Return: none
  589. *
  590. * Description: Load picture in VRAM memory area
  591. *
  592. *************************************************************************/
  593. void GLCD_LoadPic (unsigned long X_Left, unsigned long Y_Up, Bmp_t * pBmp, unsigned long Mask)
  594. {
  595. unsigned long i, j;
  596. unsigned long * pData = ((unsigned long *) LCD_VRAM_BASE_ADDR) + X_Left + (Y_Up * C_GLCD_H_SIZE);
  597. unsigned long * pSrc = pBmp->pPicStream;
  598. unsigned long X_LeftHold;
  599. for(i = 0; i < pBmp->V_Size; i++)
  600. {
  601. if(Y_Up++ >= C_GLCD_V_SIZE)
  602. {
  603. break;
  604. }
  605. for(j = 0; j < pBmp->H_Size; j++)
  606. {
  607. if(X_LeftHold++ >= C_GLCD_H_SIZE)
  608. {
  609. pSrc += pBmp->H_Size - j;
  610. break;
  611. }
  612. *(pData+j) = *pSrc++ ^ Mask;
  613. }
  614. X_LeftHold = X_Left;
  615. pData += C_GLCD_H_SIZE;
  616. }
  617. }