Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One pixel transformation for ILI948x #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions lvgl_tft/ili9481.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,6 @@ void ili9481_init(void)
// Flush function based on mvturnho repo
void ili9481_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
{
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);

lv_color16_t *buffer_16bit = (lv_color16_t *) color_map;
uint8_t *mybuf;
do {
mybuf = (uint8_t *) heap_caps_malloc(3 * size * sizeof(uint8_t), MALLOC_CAP_DMA);
if (mybuf == NULL) ESP_LOGW(TAG, "Could not allocate enough DMA memory!");
} while (mybuf == NULL);

uint32_t LD = 0;
uint32_t j = 0;

for (uint32_t i = 0; i < size; i++) {
LD = buffer_16bit[i].full;
mybuf[j] = (uint8_t) (((LD & 0xF800) >> 8) | ((LD & 0x8000) >> 13));
j++;
mybuf[j] = (uint8_t) ((LD & 0x07E0) >> 3);
j++;
mybuf[j] = (uint8_t) (((LD & 0x001F) << 3) | ((LD & 0x0010) >> 2));
j++;
}

/* Column addresses */
uint8_t xb[] = {
(uint8_t) (area->x1 >> 8) & 0xFF,
Expand Down Expand Up @@ -160,8 +138,17 @@ void ili9481_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
/*Memory write*/
ili9481_send_cmd(ILI9481_CMD_MEMORY_WRITE);

ili9481_send_color((void *) mybuf, size * 3);
heap_caps_free(mybuf);
// ILI9488/9481 doesn't support 16bit color data in SPI mode, only 18bit color data
// So here we have to transform every pixel from RGB565 to 6bits for every color, aligned to the left
const uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
lv_color16_t *color_565 = (lv_color16_t *) color_map;
for (uint32_t i = 0; i < size; i++, color_565++) {
uint8_t spi_buf[3];
spi_buf[0] = color_565->ch.blue << 3; // Blue is 5bits wide, align to 8 bits
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way there is no maxima blue. E.g. 0b11111 << 3 is 0b11111000 instead of 0b11111111.

The original code converted to RGB666 and added the LSB twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I couldn't get me head around the old conversion function. Will fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that on UI there are a lot of adjacent same color (e.g. a large white background, a blue button, etc) calculating only if the current color is different from the previous else coping the previous result might cause significant speed up.

spi_buf[1] = color_565->ch.green << 2; // Green is 6bits wide, align to 8 bits
spi_buf[2] = color_565->ch.red << 3; // Red is 5bits wide, align to 8 bits
ili9481_send_color((void *) spi_buf, sizeof(spi_buf));
tore-espressif marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**********************
Expand Down
35 changes: 11 additions & 24 deletions lvgl_tft/ili9488.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,6 @@ void ili9488_init(void)
// Flush function based on mvturnho repo
void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
{
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);

lv_color16_t *buffer_16bit = (lv_color16_t *) color_map;
uint8_t *mybuf;
do {
mybuf = (uint8_t *) heap_caps_malloc(3 * size * sizeof(uint8_t), MALLOC_CAP_DMA);
if (mybuf == NULL) ESP_LOGW(TAG, "Could not allocate enough DMA memory!");
} while (mybuf == NULL);

uint32_t LD = 0;
uint32_t j = 0;

for (uint32_t i = 0; i < size; i++) {
LD = buffer_16bit[i].full;
mybuf[j] = (uint8_t) (((LD & 0xF800) >> 8) | ((LD & 0x8000) >> 13));
j++;
mybuf[j] = (uint8_t) ((LD & 0x07E0) >> 3);
j++;
mybuf[j] = (uint8_t) (((LD & 0x001F) << 3) | ((LD & 0x0010) >> 2));
j++;
}

/* Column addresses */
uint8_t xb[] = {
(uint8_t) (area->x1 >> 8) & 0xFF,
Expand Down Expand Up @@ -162,8 +140,17 @@ void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
/*Memory write*/
ili9488_send_cmd(ILI9488_CMD_MEMORY_WRITE);

ili9488_send_color((void *) mybuf, size * 3);
heap_caps_free(mybuf);
// ILI9488/9481 doesn't support 16bit color data in SPI mode, only 18bit color data
// So here we have to transform every pixel from RGB565 to 6bits for every color, aligned to the left
const uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
lv_color16_t *color_565 = (lv_color16_t *) color_map;
for (uint32_t i = 0; i < size; i++, color_565++) {
uint8_t spi_buf[3];
spi_buf[0] = color_565->ch.blue << 3; // Blue is 5bits wide, align to 8 bits
spi_buf[1] = color_565->ch.green << 2; // Green is 6bits wide, align to 8 bits
spi_buf[2] = color_565->ch.red << 3; // Red is 5bits wide, align to 8 bits
ili9488_send_color((void *) spi_buf, sizeof(spi_buf));
}
}

/**********************
Expand Down