Skip to content

Commit

Permalink
os/drivers: mipi st7785 and st7701 lcd driver
Browse files Browse the repository at this point in the history
os/board/rtl8730e : rtl8730 lcd controller for mipi
apps/examples/lcd_test: app updated to show requested demo pattern

Add lcd display on/off command for st7785 as backlight is not complete 0
  • Loading branch information
anjana348 authored and sunghan-chang committed Jun 3, 2024
1 parent c47151e commit f944f3b
Show file tree
Hide file tree
Showing 31 changed files with 4,573 additions and 146 deletions.
207 changes: 116 additions & 91 deletions apps/examples/lcd_test/example_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
#define RED 0xF800
#define WHITE 0xFFFF
#define BLACK 0x0000
#define OFFSET 60
#define GREEN 0xE007
#define BLUE 0x00F8
#define SIZE 40

#define COLINDEX 10
#define ROWINDEX 10
Expand All @@ -77,16 +79,16 @@ static void putarea(int x1, int x2, int y1, int y2, int color)
int p = 0;
size_t len;
len = xres * yres * 2 + 1;
uint8_t *spi_data_big = (uint8_t *)malloc(len);
if (spi_data_big == NULL) {
uint8_t *lcd_data = (uint8_t *)malloc(len);
if (lcd_data == NULL) {
printf("malloc failed for lcd data : %d\n", len);
return;
}
sprintf(port, LCD_DEV_PATH, p);
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
free(spi_data_big);
free(lcd_data);
return;
}
area.planeno = 0;
Expand All @@ -96,69 +98,74 @@ static void putarea(int x1, int x2, int y1, int y2, int color)
area.col_end = y2;
area.stride = 2 * xres;
for (int i = 0; i < xres * yres * 2; i += 2) {
spi_data_big[i] = (color & 0xFF00) >> 8;
spi_data_big[i + 1] = color & 0x00FF;
lcd_data[i] = (color & 0xFF00) >> 8;
lcd_data[i + 1] = color & 0x00FF;
}

area.data = spi_data_big;
area.data = lcd_data;
ioctl(fd, LCDDEVIO_PUTAREA, (unsigned long)(uintptr_t)&area);
close(fd);
free(spi_data_big);
free(lcd_data);
}

static void test_put_area(void)
static void test_init(void)
{
int ret;
int fd = 0;
int p = 0;
char port[20] = { '\0' };

sprintf(port, LCD_DEV_PATH, p);
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
return -1;
return;
}
struct fb_videoinfo_s vinfo;
ioctl(fd, LCDDEVIO_GETVIDEOINFO, (unsigned long)(uintptr_t)&vinfo);
xres = vinfo.xres;
yres = vinfo.yres;
printf("xres : %d, yres:%d\n", xres, yres);
ioctl(fd, LCDDEVIO_INIT, &ret);
close(fd);
putarea(0, yres - 1, 0, xres - 1, RED);
/* fill square with side = OFFSET */
putarea(0, OFFSET, 0, OFFSET, WHITE);
}

/* Draws horizontal line at a point */
static void test_put_run(void)
static void test_orientation(void)
{
int fd = 0;
int p = 0;
int i;
char port[20] = { '\0' };
sprintf(port, LCD_DEV_PATH, p);
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
return -1;
return;
}
struct lcddev_run_s run;
run.planeno = 0;
run.col = COLINDEX;
run.row = ROWINDEX;
run.npixels = NOPIXELS;
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_RLANDSCAPE);

uint8_t spi_data[2 * NOPIXELS + 1];
run.data = &spi_data;
for (i = 0; i <= (NOPIXELS * 2); i += 2) {
spi_data[i + 1] = WHITE & 0X00FF;
spi_data[i] = (WHITE & 0xFF00) >> 8;
}
ioctl(fd, LCDDEVIO_PUTRUN, (unsigned long)(uintptr_t)&run);
test_put_run();

sleep(1);
/* resolution should be swapped now as orientation is changed */
#if defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_RPORTRAIT)
putarea(0, xres - 1, 0, yres - 1, RED);
#else
putarea(0, yres - 1, 0, xres - 1, RED);
#endif
/* fill square with side = OFFSET */
putarea(0, SIZE, 0, SIZE, WHITE);

sleep(1);
/* resetting original orientation - the one defined in config */
#if defined(CONFIG_LCD_PORTRAIT)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_PORTRAIT);
#elif defined(CONFIG_LCD_LANDSCAPE)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_LANDSCAPE);
#elif defined(CONFIG_LCD_RLANDSCAPE)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_RLANDSCAPE);
#elif defined(CONFIG_LCD_RPORTRAIT)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_RPORTRAIT);
#else
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_LANDSCAPE);
#endif
close(fd);
}

static void test_clear(void)
static void test_put_area_pattern(void)
{
int fd = 0;
int p = 0;
Expand All @@ -167,71 +174,84 @@ static void test_clear(void)
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
return -1;
return;
}
struct fb_videoinfo_s vinfo;
ioctl(fd, LCDDEVIO_GETVIDEOINFO, (unsigned long)(uintptr_t)&vinfo);
xres = vinfo.xres;
yres = vinfo.yres;
printf("xres : %d, yres:%d\n", xres, yres);
close(fd);
putarea(0, yres - 1, 0, xres - 1, BLUE);
sleep(3);
putarea(0, yres - 1, 0, xres - 1, GREEN);
sleep(3);
putarea(0, yres - 1, 0, xres - 1, RED);
sleep(3);
putarea(0, yres - 1, 0, xres - 1, BLACK);
sleep(3);
putarea(0, yres - 1, 0, xres - 1, WHITE);
sleep(3);
}

static void test_init(void)
static unsigned short generate_color_code(int red, int green, int blue)
{
int ret;
int fd = 0;
int p = 0;
char port[20] = { '\0' };
sprintf(port, LCD_DEV_PATH, p);
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
return -1;
}
ioctl(fd, LCDDEVIO_INIT, &ret);
close(fd);
// Ensure that RGB values are within the valid range (0-31)
red = red % 31;
green = green % 31;
blue = blue % 31;
// Combine RGB components into a 16-bit hex color code
unsigned short colorCode = (red << 11) | (green << 5) | blue;
return colorCode;
}

static void test_orientation(void)
static void test_bit_map(void)
{
int fd = 0;
int p = 0;
char port[20] = { '\0' };
struct lcddev_area_s area;
size_t len;
int idx = 0;
sprintf(port, LCD_DEV_PATH, p);
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
return -1;
return;
}
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_RLANDSCAPE);

test_put_run();

sleep(1);
/* resolution should be swapped now as orientation is changed */
#if defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_RPORTRAIT)
putarea(0, xres - 1, 0, yres - 1, RED);
#else
putarea(0, yres - 1, 0, xres - 1, RED);
#endif
/* fill square with side = OFFSET */
putarea(0, OFFSET, 0, OFFSET, WHITE);

sleep(1);
/* resetting original orientation - the one defined in config */
#if defined(CONFIG_LCD_PORTRAIT)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_PORTRAIT);
#elif defined(CONFIG_LCD_LANDSCAPE)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_LANDSCAPE);
#elif defined(CONFIG_LCD_RLANDSCAPE)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_RLANDSCAPE);
#elif defined(CONFIG_LCD_RPORTRAIT)
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_RPORTRAIT);
#else
ioctl(fd, LCDDEVIO_SETORIENTATION, LCD_LANDSCAPE);
#endif
struct fb_videoinfo_s vinfo;
ioctl(fd, LCDDEVIO_GETVIDEOINFO, (unsigned long)(uintptr_t)&vinfo);
xres = vinfo.xres;
yres = vinfo.yres;
len = xres * yres * 2 + 1;
uint8_t *lcd_data = (uint8_t *)malloc(len);
if (lcd_data == NULL) {
printf("malloc failed for lcd data : %d\n", len);
return;
}
area.planeno = 0;
area.row_start = 0;
area.row_end = yres - 1;
area.col_start = 0;
area.col_end = xres - 1;
area.stride = 2 * xres;
area.data = lcd_data;
uint16_t color;
for (int y = 0; y < yres / SIZE * 2; y++) {
for (int x = 0; x < xres / SIZE; x++) {
color = generate_color_code(rand() % 31, rand() % 31, rand() % 31);
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
int pixel_x = x * SIZE + i;
int pixel_y = y * SIZE + j;
lcd_data[pixel_y * xres + pixel_x] = (color & 0xFF00) >> 8;
}
}
}
}
ioctl(fd, LCDDEVIO_PUTAREA, (unsigned long)(uintptr_t)&area);
close(fd);
free(lcd_data);
}

#ifdef CONFIG_BUILD_KERNEL
Expand All @@ -242,19 +262,24 @@ int lcd_test_main(int argc, char *argv[])
{
printf("=== LCD demo ===");
int count = 0;
test_init();
sleep(1);
int fd = 0;
int p = 0;
char port[20] = { '\0' };
sprintf(port, LCD_DEV_PATH, p);
fd = open(port, O_RDWR | O_SYNC, 0666);
if (fd < 0) {
printf("ERROR: Failed to open lcd port : %s error:%d\n", port, fd);
return;
}
while (count < 5) {
test_clear();
sleep(1);
test_put_run();
sleep(1);
test_put_area();
sleep(1);
test_clear();
sleep(1);
test_orientation();
sleep(1);
test_put_area_pattern();
test_bit_map();
sleep(3);
ioctl(fd, LCDDEVIO_SETPOWER, 0);
sleep(15);
ioctl(fd, LCDDEVIO_SETPOWER, 100);
count++;
printf("count :%d\n", count);
}
return 0;
}
38 changes: 35 additions & 3 deletions build/configs/rtl8730e/loadable_ext/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ CONFIG_RTL8730E_UART1=y
# CONFIG_RTL8730E_UART3 is not set
CONFIG_RTL8730E_UART4=y
CONFIG_RTL8730E_SERIAL_FIFO=y
CONFIG_AMEBASMART_MIPI=y
CONFIG_AMEBASMART_SPI=y
CONFIG_AMEBASMART_SPI0=y
CONFIG_AMEBASMART_SPI1=y
CONFIG_AMEBASMART_SPI_EXCHANGE=y
# CONFIG_AMEBASMART_SPI_DMA is not set
# CONFIG_SPI_CS is not set
# CONFIG_AMEBASMART_MIPI is not set
CONFIG_AMEBASMART_I2C=y
CONFIG_AMEBASMART_I2C0=y
# CONFIG_AMEBASMART_I2C1 is not set
Expand Down Expand Up @@ -517,6 +517,8 @@ CONFIG_SPI_USERIO=y
CONFIG_SPI_EXCHANGE=y
# CONFIG_SPI_CMDDATA is not set
# CONFIG_SPI_BITBANG is not set
CONFIG_MIPI_DSI=y
# CONFIG_MIPI_DSI_DRIVER is not set
# CONFIG_GPIO is not set
CONFIG_I2S=y
CONFIG_AUDIO_DEVICES=y
Expand All @@ -542,7 +544,35 @@ CONFIG_AUDIO_ALC1019=y
#
# LCD Driver Support
#
# CONFIG_LCD is not set
CONFIG_LCD=y
# CONFIG_LCD_HWCURSOR is not set
# CONFIG_LCD_PACKEDMSFIRST is not set
# CONFIG_LCD_UPDATE is not set

#
# Common Graphic LCD Settings
#
# CONFIG_LCD_FRAMEBUFFER is not set

#
# LCD driver selection
#
# CONFIG_LCD_NOGETRUN is not set
# CONFIG_LCD_DMA_SUPPORT is not set

#
# Graphic LCD Devices
#
CONFIG_LCD_LANDSCAPE=y
# CONFIG_LCD_PORTRAIT is not set
# CONFIG_LCD_RPORTRAIT is not set
# CONFIG_LCD_RLANDSCAPE is not set
# CONFIG_LCD_ST7701 is not set
CONFIG_LCD_XRES=240
CONFIG_LCD_YRES=320
CONFIG_LCD_ST7785=y
# CONFIG_LCD_ST7789 is not set
# CONFIG_LCD_ILI9341 is not set
CONFIG_BCH=y
CONFIG_RTC=y
# CONFIG_RTC_DATETIME is not set
Expand Down Expand Up @@ -1285,6 +1315,8 @@ CONFIG_DEBUG_MM_HEAPINFO=y
#
# CONFIG_DEBUG_ANALOG is not set
# CONFIG_DEBUG_I2S is not set
# CONFIG_DEBUG_MIPI is not set
# CONFIG_DEBUG_LCD is not set
# CONFIG_DEBUG_RTC is not set
# CONFIG_DEBUG_SPI is not set
# CONFIG_DEBUG_WATCHDOG is not set
Expand Down Expand Up @@ -1550,7 +1582,7 @@ CONFIG_EXAMPLES_HELLO=y
# CONFIG_EXAMPLES_IOTJS_STARTUP is not set
# CONFIG_EXAMPLES_KERNEL_SAMPLE is not set
# CONFIG_EXAMPLES_KERNEL_UPDATE is not set
# CONFIG_EXAMPLES_LCD is not set
CONFIG_EXAMPLES_LCD=y

#
# Libcoap
Expand Down
Loading

0 comments on commit f944f3b

Please sign in to comment.