Floyd-Fish / ST7789-STM32

using STM32's Hardware SPI to drive a ST7789 based IPS displayer
GNU General Public License v3.0
276 stars 55 forks source link

Fix function ST7789_Fill_Color not fill correct color #26

Open codead opened 1 year ago

codead commented 1 year ago

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; } } /**

JorikWit commented 2 months ago

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 commented 4 weeks ago

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.