lcdc.c 2.4 KB

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