RT-Thread论坛
直播中

donatello1996

8年用户 687经验值
擅长:处理器/DSP 控制/MCU RF/无线
私信 关注
[经验]

【Vision Board创客营连载体验】RA8D1-Vision Board 驱动正点原子7寸RGB液晶屏

      RA8D1-Vision Board开发板带了跟正点原子一样的RGB液晶屏接口,因此是可以接原子的屏的:
1.jpg

RASC配置RGB565十六位色接口(引脚为RGB666十八位色,但是屏幕只用到了前十六位,也就是DATA0~DATA15):
2.jpg

配置TCON0 TCON1 TCON3分别为HSYNC VSYNC DE:
3.jpg

由于我之前已经使用RA6M3接过原子的4.3寸屏,所以很多参数可以照搬,但有部分参数是需要参考原子的例程:
Output|timing|Horizontal total cycles        1165
Output|Timing|Horizontal active video cycles        1024
Output|Timing|Horizontal back porch cycles        140
Output|Timing|Horizontal sync signal cycles        1
Output|Timing|Horizontal sync signal polarity        Low active
Output|Timing|Vertical total lines        621
Output|Timing|Vertical active video lines        600
Output|Timing|Vertical back porch lines        20
Output|Timing|Vertical sync signal lines        1
Output|Timing|Vertical sync signal polarity        Low active
Output|Timing|Data Enable Signal Polarity        High active
Output|Timing|Sync edge        Falling edge
Output|Format|Color format        16bits RGB565
Output|Format|Color order        RGB
Output|Format|Endian        Little endian
4.jpg

由于原子的7寸屏是1024*600的分辨率,RA8D1芯片内部SRAM是不够存放显存缓存的,必须要放在外部的SDRAM:
Input|Graphics Layer 1|Framebuffer|Framebuffer name        fb_background
Input|Graphics Layer 1|Framebuffer|Section for framebuffer allocation        .sdram

TCON功能脚和HSYNC VSYNC等控制引脚也没有一一对应关系,都是通过分配实现的:
TCON|Hsync pin select        LCD_TCON1
TCON|Vsync pin select        LCD_TCON0
TCON|Data enable (DE) pin select        LCD_TCON3
TCON|Panel clock source        Internal clock (GLCDCLK)
TCON|Panel clock division ratio        1/8

SDRAM配置则直接照搬RTT工程即可:
5.jpg
显示屏驱动代码:
  1. #define LCD_WIDTH           1024
  2. #define LCD_HEIGHT          600
  3. uint16_t *lcd_current_working_buffer = (uint16_t *) &fb_background[0];
  4. void ra_bsp_lcd_clear(uint16_t color)
  5. {
  6.     for (uint32_t i = 0; i < (LCD_WIDTH * LCD_HEIGHT); i++)
  7.     {
  8.         lcd_current_working_buffer[i] = color;
  9.     }
  10. }
  11. void bsp_lcd_draw_pixel(uint32_t x, uint32_t y, uint16_t color)
  12. {
  13.         lcd_current_working_buffer[(y * LCD_WIDTH) + x] = color;
  14. }
  15. void lcd_fill_rectangle(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, uint16_t pixcolor)
  16. {
  17.     uint16_t cycle_y, x_offset = 0;
  18.     for (cycle_y = y_start; cycle_y <= y_end;)
  19.     {
  20.         for (x_offset = 0; x_start + x_offset <= x_end; x_offset++)
  21.         {
  22.             bsp_lcd_draw_pixel(x_start + x_offset, cycle_y, pixcolor);
  23.         }
  24.         cycle_y++;
  25.     }
  26. }

SDRAM驱动代码:
  1. #define BSP_PRV_SDRAM_SDIR_REF_TIMES           (2U)
  2. #define BSP_PRV_SDRAM_BUS_WIDTH                (0U)
  3. #define BSP_PRV_SDRAM_CONTINUOUS_ACCESSMODE    (1U)
  4. #define BSP_PRV_SDRAM_ENDIAN_MODE              (0U)
  5. #define BSP_PRV_SDRAM_MR_WB_SINGLE_LOC_ACC    (1U) /* MR.M9                : Single Location Access */
  6. #define BSP_PRV_SDRAM_MR_OP_MODE              (0U) /* MR.M8:M7             : Standard Operation */
  7. #define BSP_PRV_SDRAM_MR_BT_SEQUENCTIAL       (0U) /* MR.M3 Burst Type     : Sequential */
  8. #define BSP_PRV_SDRAM_MR_BURST_LENGTH         (0U) /* MR.M2:M0 Burst Length: 0(1 burst) */
  9. #define BSP_PRV_SDRAM_CL                       (3U)
  10. #define BSP_PRV_SDRAM_TRP                      (3U)
  11. #define BSP_PRV_SDRAM_TWR                      (2U)
  12. #define BSP_PRV_SDRAM_TRAS                     (6U)
  13. #define BSP_PRV_SDRAM_TRCD                     (3U)
  14. #define BSP_PRV_SDRAM_SDADR_ROW_ADDR_OFFSET    (9U)
  15. #define BSP_PRV_SDRAM_TRFC                     (8U)
  16. #define BSP_PRV_SDRAM_REF_CMD_INTERVAL         (937U)
  17. void bsp_sdram_init (void)
  18. {
  19.     /** Setting for SDRAM initialization sequence */
  20. #if (BSP_PRV_SDRAM_TRP < 3)
  21.     R_BUS->SDRAM.SDIR_b.PRC = 3U;
  22. #else
  23.     R_BUS->SDRAM.SDIR_b.PRC = BSP_PRV_SDRAM_TRP - 3U;
  24. #endif
  25.     while (R_BUS->SDRAM.SDSR)
  26.     {
  27.         /* According to h/w maual, need to confirm that all the status bits in SDSR are 0 before SDIR modification. */
  28.     }
  29.     R_BUS->SDRAM.SDIR_b.ARFC = BSP_PRV_SDRAM_SDIR_REF_TIMES;
  30.     while (R_BUS->SDRAM.SDSR)
  31.     {
  32.         /* According to h/w maual, need to confirm that all the status bits in SDSR are 0 before SDIR modification. */
  33.     }
  34. #if (BSP_PRV_SDRAM_TRFC < 3)
  35.     R_BUS->SDRAM.SDIR_b.ARFI = 0U;
  36. #else
  37.     R_BUS->SDRAM.SDIR_b.ARFI = BSP_PRV_SDRAM_TRFC - 3U;
  38. #endif
  39.     while (R_BUS->SDRAM.SDSR)
  40.     {
  41.         /* According to h/w maual, need to confirm that all the status bits in SDSR are 0 before SDICR modification. */
  42.     }
  43.     /** Start SDRAM initialization sequence.
  44.      * Following operation is automatically done when set SDICR.INIRQ bit.
  45.      * Perform a PRECHARGE ALL command and wait at least tRP time.
  46.      * Issue an AUTO REFRESH command and wait at least tRFC time.
  47.      * Issue an AUTO REFRESH command and wait at least tRFC time.
  48.      */
  49.     R_BUS->SDRAM.SDICR_b.INIRQ = 1U;
  50.     while (R_BUS->SDRAM.SDSR_b.INIST)
  51.     {
  52.         /* Wait the end of initialization sequence. */
  53.     }
  54.     /** Setting for SDRAM controller */
  55.     R_BUS->SDRAM.SDCCR_b.BSIZE  = BSP_PRV_SDRAM_BUS_WIDTH;             /* set SDRAM bus width */
  56.     R_BUS->SDRAM.SDAMOD_b.BE    = BSP_PRV_SDRAM_CONTINUOUS_ACCESSMODE; /* enable continuous access */
  57.     R_BUS->SDRAM.SDCMOD_b.EMODE = BSP_PRV_SDRAM_ENDIAN_MODE;           /* set endian mode for SDRAM address space */
  58.     while (R_BUS->SDRAM.SDSR)
  59.     {
  60.         /* According to h/w maual, need to confirm that all the status bits in SDSR are 0 before SDMOD modification. */
  61.     }
  62.     /** Using LMR command, program the mode register */
  63.     R_BUS->SDRAM.SDMOD = ((((uint16_t) (BSP_PRV_SDRAM_MR_WB_SINGLE_LOC_ACC << 9) |
  64.                             (uint16_t) (BSP_PRV_SDRAM_MR_OP_MODE << 7)) |
  65.                            (uint16_t) (BSP_PRV_SDRAM_CL << 4)) |
  66.                           (uint16_t) (BSP_PRV_SDRAM_MR_BT_SEQUENCTIAL << 3)) |
  67.                          (uint16_t) (BSP_PRV_SDRAM_MR_BURST_LENGTH << 0);
  68.     /** wait at least tMRD time */
  69.     while (R_BUS->SDRAM.SDSR_b.MRSST)
  70.     {
  71.         /* Wait until Mode Register setting done. */
  72.     }
  73.     /** Set timing parameters for SDRAM */
  74.     R_BUS->SDRAM.SDTR_b.RAS = BSP_PRV_SDRAM_TRAS - 1U; /* set ACTIVE-to-PRECHARGE command cycles*/
  75.     R_BUS->SDRAM.SDTR_b.RCD = BSP_PRV_SDRAM_TRCD - 1U; /* set ACTIVE to READ/WRITE delay cycles */
  76.     R_BUS->SDRAM.SDTR_b.RP  = BSP_PRV_SDRAM_TRP - 1U;  /* set PRECHARGE command period cycles */
  77.     R_BUS->SDRAM.SDTR_b.WR  = BSP_PRV_SDRAM_TWR - 1U;  /* set write recovery cycles */
  78.     R_BUS->SDRAM.SDTR_b.CL  = BSP_PRV_SDRAM_CL;        /* set SDRAM column latency cycles */
  79.     /** Set row address offset for target SDRAM */
  80.     R_BUS->SDRAM.SDADR_b.MXC = BSP_PRV_SDRAM_SDADR_ROW_ADDR_OFFSET - 8U;
  81.     R_BUS->SDRAM.SDRFCR_b.REFW = (uint16_t) (BSP_PRV_SDRAM_TRFC - 1U); /* set Auto-Refresh issuing cycle */
  82.     R_BUS->SDRAM.SDRFCR_b.RFC  = BSP_PRV_SDRAM_REF_CMD_INTERVAL - 1U;  /* set Auto-Refresh period */
  83.     /** Start Auto-refresh */
  84.     R_BUS->SDRAM.SDRFEN_b.RFEN = 1U;
  85.     /** Enable SDRAM access */
  86.     R_BUS->SDRAM.SDCCR_b.EXENB = 1U;
  87. }

显示效果:
微信图片_20240507204421.jpg

更多回帖

发帖
×
20
完善资料,
赚取积分