SPI TFT-LCD drawBitmap

Application: Muse-Charm
EVB : AMB82-mini
SPI : ILI9341 TFTLCD
example : EdgeAI-AmebaPro2/Arduino/AMB82-mini/ILI9341_Bitmap at main · rkuo2000/EdgeAI-AmebaPro2 · GitHub

failed code : ILI9341_Bitmap_org.ino

void drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const unsigned short *color)
{
tft.drawBitmap(x, y, w, h, color);
delay(500);
}

bug found by codex :
The loop itself is fine. The likely cause is your installed AmebaILI9341::drawBitmap() (/home/rkuo/.arduino15/packages/realtek/hardware/AmebaPro2/4.1.1-build20260922/libraries/SPI/src/AmebaILI9341.cpp:248):

  • It casts away const and swaps the source image’s bytes in place.
  • It passes that array to SPI as both the transmit and receive buffer, allowing received data to overwrite the image.

That is unsafe for your const ... PROGMEM images and can break repeated drawing. All seven image arrays have the correct size and contain nonblack pixels.

I updated ILI9341_Bitmap.ino (ILI9341_Bitmap.ino:25) to transmit RGB565 bytes directly, preserving the image arrays and bypassing the faulty bulk transfer.

The modified sketch compiles successfully with your AMB82 toolchain. Upload it to verify the display; drawing may be slower with this workaround.

fixed code : ILI9341_Bitmap.ino

  1. This is drawing much slower, is it possible to fix ILI9341 SPI driver ?

  2. SPI1 did not work :
    #define TFT_CS SPI1_SS
    AmebaILI9341 tft = AmebaILI9341(TFT_CS, TFT_DC, TFT_RESET, &SPI1);

Hi @rkuo2000 ,

  1. Please find the attached patch of AmebaILI9341.cpp and AmebaILI9341.h for replacement. We have updated the drawBitmap() such that data is transmitted through the TX-only stream API via a private staging buffer and wait on TX_BUSY between chunks.
  2. To use SPI1, kindly rename object SPI to SPI1 in your example code.

Thank you.

AmebaILI9341_patch.zip (5.4 KB)

  1. drawBitmap works fine

  2. spi_master_write_stream is broken

blank screen if use spi_master_write_stream
ILI9341_Giraffe_SPI.ino

drawPackedFace works fine by SPI.transfer
ILI9341_Giraffe.ino

Hi @rkuo2000 ,

Please test with the modified version for ILI9341_Giraffe_SPI.ino. We have added a few guards against transmit failure.

ILI9341_Giraffe_SPI_modified.zip (12.1 KB)

Thank you.

Hi Kevin,
Yes, it works pretty fast to fill up bitmap on TFT-LCD now.
Definitely big help for Ameba agentic device (muse-charm like).

Will there be an library update for using spi_master_write_stream in drawBitmap ?

I recommend to add the following two TFT support in the library.
ILI9341 is 240x320 16-bit RGB565
GC9A01 is 240x240 16-bit RGB565

the bmp2hpp.py will convert 240x320 RGB565 .bmp to .hpp

Regards,

Richard

Hi @rkuo2000 ,

Thank you for your suggestion. Yes, we will evaluate all requests according to user’s needs and update any necessary fix in the SDK.