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

Fix function ST7789_Fill_Color not fill correct color #26

Open
codead opened this issue Feb 11, 2023 · 2 comments
Open

Fix function ST7789_Fill_Color not fill correct color #26

codead opened this issue Feb 11, 2023 · 2 comments

Comments

@codead
Copy link

codead commented Feb 11, 2023

Hello,
function ST7789_Fill_Color is not correct because memset is not working with uint16_t data, and the uint16_t buffer should be swap 2 byte high and low . So, we have to modify this function to working correct:
`void MemsetBuffer(uint16_t buf, uint16_t data, uint32_t size)
{
while(size--)
{
buf++ = data;
}
}
/

  • @brief Fill the DisplayWindow with single color
  • @param color -> color to Fill with
  • @return none
    */
    void ST7789_Fill_Color(uint16_t color)
    {
    uint16_t i;
    uint16_t convert_color;
    ST7789_SetAddressWindow(0, 0, ST7789_WIDTH - 1, ST7789_HEIGHT - 1);
    ST7789_Select();
    convert_color = ((color & 0xFF) << 8) | ((color & 0xFF00) >> 8);
    #ifdef LCD_USE_DMA
    for (i = 0; i < ST7789_HEIGHT / HOR_LEN; i++)
    {
    MemsetBuffer(disp_buf, convert_color, ST7789_WIDTH * HOR_LEN);
    ST7789_WriteData((uint8_t *)disp_buf, sizeof(disp_buf));
    }
    #else
    uint16_t j;
    for (i = 0; i < ST7789_WIDTH; i++)
    for (j = 0; j < ST7789_HEIGHT; j++) {
    uint8_t data[] = {color >> 8, color & 0xFF};
    ST7789_WriteData(data, sizeof(data));
    }
    #endif
    ST7789_UnSelect();
    }`
@JorikWit
Copy link

I can confirm that this is a working fix. Had the same issue. To clarify, this fix is only needed if u use DMA.

@jorgie0
Copy link

jorgie0 commented Jul 23, 2024

I could not get MemsetBuffer to compile using STMCubeIDE so I changed it to:
`
void MemsetBuffer(void *m, uint16_t val, size_t count) {
{
char *buf = m;
union
{
uint8_t d8[2];
uint16_t d16;
}u16 = {.d16 = val};

    while(count--)
    {
        *buf++ = u16.d8[0];
        *buf++ = u16.d8[1];
    }
    return m;
}

}
I then called it using this slightly modified code:
MemsetBuffer(disp_buf, convert_color, ST7789_WIDTH * HOR_LEN);
for (i = 0; i < ST7789_HEIGHT / HOR_LEN; i++) {
ST7789_WriteData(&disp_buf, sizeof(disp_buf));
}
`
I moved the call to 'MemsetBuffer' out of the for loop as the buffer already contains what it needs to so we are just wasting clock cycles filling it up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants