lcdc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * File : lcdc.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. */
  13. #include "lcdc.h"
  14. #include <sep4020.h>
  15. #define writel(DATA,ADDRESS) *((volatile rt_off_t *) ADDRESS)= DATA;
  16. unsigned long pVideoBuffer;
  17. rt_err_t sep4020_lcd_init(void)
  18. {
  19. pVideoBuffer =(unsigned long)rt_malloc(LCDWIDTH * LCDHEIGHT * 2);
  20. *(RP)GPIO_PORTC_SEL |= 0X0008; //Portc8设置为通用口
  21. *(RP)GPIO_PORTC_DIR &= (~0X0008); //Portc8设置为输出
  22. *(RP)GPIO_PORTC_DATA |= 0X0008; //Portc8输出高电平
  23. writel(0x00000000,LCDC_LECR); //禁用LCDC
  24. writel(pVideoBuffer,LCDC_SSA); //lcd数据帧的起始地址
  25. writel(YMAX | XMAX,LCDC_SIZE);
  26. writel(TFT|COLOR|PBSIZE|BPIX|PIXPOL|FLMPOL|LPPOL|CLKPOL|OEPOL|END_SEL|ACD_SEL|ACD|PCD,LCDC_PCR);
  27. writel(H_WIDTH|H_WAIT_1|H_WAIT_2,LCDC_HCR);
  28. writel(V_WIDTH|PASS_FRAME_WAIT|V_WAIT_1|V_WAIT_2,LCDC_VCR);
  29. writel(SCR|CC_EN|PW,LCDC_PWMR);
  30. writel(BL|HM|TM,LCDC_DMACR);
  31. writel(0x00000001,LCDC_LECR); //使能LCDC
  32. writel(0x00000000,LCDC_LCDISREN); //中断在加载帧的最后一个或第一个数据时设置,到LCD之间会有一个延时
  33. return RT_EOK;
  34. }
  35. void lcd_set_pixel(rtgui_color_t *c, int x, int y)
  36. {
  37. unsigned short p;
  38. /* get color pixel */
  39. p = rtgui_color_to_565p(*c);
  40. *(unsigned short *)(pVideoBuffer + 2*y*LCDWIDTH + 2*x) = p;
  41. }
  42. void lcd_get_pixel(rtgui_color_t *c, int x, int y)
  43. {
  44. *c = rtgui_color_from_565p( *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x));
  45. }
  46. void lcd_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
  47. {
  48. unsigned short p;
  49. /* get color pixel */
  50. p = rtgui_color_to_565p(*c);
  51. while (x1 < x2)
  52. {
  53. *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x1)=p;
  54. x1 ++;
  55. }
  56. }
  57. void lcd_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
  58. {
  59. unsigned short p;
  60. /* get color pixel */
  61. p = rtgui_color_to_565p(*c);
  62. while (y1 < y2)
  63. {
  64. *(unsigned short *)(pVideoBuffer+2*y1*LCDWIDTH+2*x)=p;
  65. y1 ++;
  66. }
  67. }
  68. void lcd_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
  69. {
  70. rt_uint16_t *ptr;
  71. /* get pixel */
  72. ptr = (rt_uint16_t*) pixels;
  73. while (x1 < x2)
  74. {
  75. *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x1)=*ptr;
  76. x1 ++;
  77. ptr ++;
  78. }
  79. }
  80. void lcd_update(rtgui_rect_t *rect)
  81. {
  82. /* nothing for none-DMA mode driver */
  83. }
  84. rt_uint8_t *lcd_get_framebuffer(void)
  85. {
  86. return RT_NULL; /* no framebuffer driver */
  87. }