【LTDC】在 RGBLCD 屏上實現任意位置畫點和讀點
引言
此篇文章僅作筆記分享,內容來源為:
這篇文章的目的就是熟悉在 RGBLCD 上的繪圖操作,了解如何往顯存中對應的位置寫數據。
繪圖實質
- 由于我們的屏幕是 ATK 4.3 800 * 480,所以會對應在 SDRAM 中按順序開辟一個大小為 800 * 480 * 2 的內存,其中 2為一個像素的大小(RGB565一個像素點為兩個字節)。
- 幀緩沖的起始地址就是 SDRAM 中為屏幕所開辟的第一個內存地址(S_Addr)。
- 對于定位(x, y),我們就是要計算某個點對于顯存首地址的內存偏移是多少,其中分為了行上的 a 距離,和列上的 b 距離。
- 橫屏:位置 = (width * y + x) * 2,其中 width 是寬度 800,x 是列數(單位是像素),y 是行數(單位是像素),2是單個像素大?。?br>
(uint16_t*)((uint32_t)s_addr + pixsize * (pwidth * y + x))- 豎屏:位置 = (width * (height - x - 1) + y) * 2,其中 width 是寬度 800,其中 height 是寬度 480,x 是行數(單位是像素),y 是列數(單位是像素),2是單個像素大?。?br>
(uint16_t*) ((uint32_t)s_addr + pixsize * (pwidth * (pheight - x - 1) + y))

程序
LTDC 程序
點擊查看代碼
__attribute__((section (".RAM_SDRAM"))) uint16_t framebuf[pHeight][pWidth];
#define LTDC_ADDR 0xC0000000
/* 常用畫筆顏色 */
#define WHITE 0xFFFF /* 白色 */
#define BLACK 0x0000 /* 黑色 */
#define RED 0xF800 /* 紅色 */
#define GREEN 0x07E0 /* 綠色 */
#define BLUE 0x001F /* 藍色 */
#define MAGENTA 0xF81F /* 品紅色/紫紅色 = BLUE + RED */
#define YELLOW 0xFFE0 /* 黃色 = GREEN + RED */
#define CYAN 0x07FF /* 青色 = GREEN + BLUE */
/* 非常用顏色 */
#define BROWN 0xBC40 /* 棕色 */
#define BRRED 0xFC07 /* 棕紅色 */
#define GRAY 0x8430 /* 灰色 */
#define DARKBLUE 0x01CF /* 深藍色 */
#define LIGHTBLUE 0x7D7C /* 淺藍色 */
#define GRAYBLUE 0x5458 /* 灰藍色 */
#define LIGHTGREEN 0x841F /* 淺綠色 */
#define LGRAY 0xC618 /* 淺灰色(PANNEL),窗體背景色 */
#define LGRAYBLUE 0xA651 /* 淺灰藍色(中間層顏色) */
#define LBBLUE 0x2B12 /* 淺棕藍色(選擇條目的反色) */
/* 寬度和高度 */
#define pWidth 800
#define pHeight 480
/* 橫屏和豎屏 */
#define HOR true // 橫屏
#define VER false // 豎屏
/* RGB類型 */
#define RGB888 1
#define RGB565 2
#define RGB_TYPE RGB565
/* 像素大小 */
#if RGB_TYPE == RGB888
#define PIXSIZE 3 // 單個像素大小
#endif
#if RGB_TYPE == RGB565
#define PIXSIZE 2 // 單個像素大小
#endif
void ltdc_draw_point(uint16_t x, uint16_t y, uint32_t color)
{
if (HOR) { // 橫屏
*(uint16_t*)((uint32_t)framebuf + PIXSIZE * (pWidth * y + x)) = color;
} else { // 豎屏
*(uint16_t*)((uint32_t)framebuf + PIXSIZE * (pWidth * (pHeight - x - 1) + y)) = color;
}
}
uint32_t ltdc_read_point(uint16_t x, uint16_t y, uint32_t color)
{
if (HOR) { // 橫屏
return *(uint16_t*)((uint32_t)framebuf + PIXSIZE * (pWidth * y + x)) = color;
} else { // 豎屏
return *(uint16_t*)((uint32_t)framebuf + PIXSIZE * (pWidth * (pHeight - x - 1) + y)) = color;
}
}
main() 測試程序
點擊查看代碼
ltdc_draw_point(100, 100, RED);
ltdc_draw_point(110, 110, RED);
ltdc_draw_point(120, 120, RED);
ltdc_draw_point(130, 130, RED);
ltdc_draw_point(140, 140, RED);
ltdc_draw_point(150, 150, RED);
ltdc_draw_point(160, 160, RED);
ltdc_draw_point(170, 170, RED);
ltdc_draw_point(180, 180, RED);
ltdc_draw_point(190, 190, RED);
ltdc_draw_point(200, 200, RED);
printf("pixcolor = %x \r\n", ltdc_read_point(140, 140, RED));
測試結果


博客導航
本文來自博客園,作者:膝蓋中箭衛兵,轉載請注明原文鏈接:http://www.rzrgm.cn/Skyrim-sssuuu/p/19163646

浙公網安備 33010602011771號
https://orcid.org/0000-0001-5102-772X