lcdc.c 2.5 KB

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