Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Show BMP image on display

Hi there!

I have an SD card reader and ST7735 connected to an nRF52850 DK, both working fine. Furthermore, I'm using ARMGCC in combination with Make, nRF5 SDK, nRF SDK for Mesh, FreeRTOS and C++. Now I've got the following question; how do I show bitmaps on the display that're stored on the sd card?

I couldn't find any examples that do so and I've actually wasted quite a lot of time on it by writing it pixel by pixel... Has anyone accomplished this, or does anyone have an idea how this could be tackled?

Kind regards,

Jochem

  • Hi

    I'm afraid what documentation we got regarding LCD control is limited to the GFX library and the GFX example project in our nRF5 SDK, so we don't have any examples for displaying data stored on an SD card I'm afraid. We do however have this thread on DevZone where control of an ST7789 LCD with an nRF52DK is the theme. This should be a similar screen to the one you're using, and has quite a bit of information on bitmaps with the ST-series LCDs, so I would suggest giving it a read to see if that helps with your understanding.

    Best regards,

    Simon

  • Hi Simon,

    Thanks for pointing that out! Got that working almost instantly. That topic, however, doesn't really provide any information with regards to writing an image from the SD card to a display. Since I couldn't get the function form the GFX library working, I decided to write my own that takes the filename and rectangle as input.

    ret_code_t display_c::show_image(nrf_gfx_rect_t const * p_rect, const char* file_name){
        UINT bytes_read;
        FIL f;
        if(f_open(&f, file_name, FA_READ) != FR_OK){
            NRF_LOG_WARNING("Opening \"%s\" failed.", file_name);
            return NRF_ERROR_NOT_FOUND;
        }
    
        if ((p_rect->x > nrf_gfx_width_get(&lcd)) || (p_rect->y > nrf_gfx_height_get(&lcd))){
            return NRF_ERROR_INVALID_PARAM;
        }
    
        uint16_t signature;
        f_read(&f, &signature, 2, &bytes_read);
    
        uint32_t size, creator_bytes, image_offset;
        f_read(&f, &size, 4, &bytes_read);
        f_read(&f, &creator_bytes, 4, &bytes_read);
        f_read(&f, &image_offset, 4, &bytes_read);
    
        f_lseek(&f, image_offset);
    
        uint16_t pixel;
        for (int32_t i = 0; i < p_rect->height; i++){
            for (uint32_t j = 0; j < p_rect->width; j++){
                f_read(&f, &pixel, 2, &bytes_read);
                lcd.lcd_pixel_draw(p_rect->x + j, p_rect->y + i, pixel);
            }
        }
    
        f_close(&f);
        NRF_LOG_WARNING("Image \"%s\" drawn.", file_name);
        return NRF_SUCCESS;
    }

    For anyone facing the same challenge; feel free to use it. 

    Kind regards,

    Jochem

Related