This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ST7735 driver implementation of nrf_gfx_display (data from an internal frame buffer)

So I am doing a project with a 160x80 TFT display, using the ST7735 driver. I have slightly modified the ST7735 functions to work with my display, and everything is running perfectly (great job with the driver). Now I am trying to build an interface and would like to update text on the display without it flickering. In my previous projects, I used an internal frame buffer/canvas to hold the text and background, while using some write_bitmap function to write the buffer to the display. 

I would like to do this with the nRF52 SDK and found the function nrf_gfx_display() in the documentation.

/**
 * @brief Function for displaying data from an internal frame buffer.
 *
 * @param[in] p_instance            Pointer to the LCD instance.
 */
void nrf_gfx_display(nrf_lcd_t const * p_instance);

However, as I understand, this has never been implemented and is up to the individual developer to do so - is this correct? In that case I do have some questions as of how what is the best practise for implementing this. Personally I don't think it makes sense to implement it in the modified ST7735 driver as I would not have access to any of the helper functions in nrf_gxf such as write_line() etc. Also I am having a hard time thinking how I should implement this with only the function nrf_gfx_display() without any arguments or anything.

No matter what I think of I end up with the need to modify the nrf_lcd_t struct in order to get more functions. F.x. I am thinking of creating a new "driver" file called canvas in the same manner as the ST7735, however in order to retrieve the buffered canvas I would have to add another function pointer in the nrf_lcd_t struct - something like get_buffer. Is this a good practice? 

I come from a C++ programming background and are used to classes, however I am having a hard time adjusting to the none-class nature of C. Any good advice is much appreciated!

Thanks :-)

Parents
  • Hi thanks for your reply! 

    I chose to implement a canvas buffer directly in the GFX library, as I did not like the method of storing the entire screen in a buffer. My implementation is simple, I made a structure to hold my canvas data (position, width, height and buffer).

    typedef struct{
        nrf_gfx_rect_t rect;
        bool enabled;
        uint8_t * buffer;
    }nrf_gfx_canvas_t; 

    I created the struct inside nrf_gfx.c "static nrf_gfx_canvas_t m_canvas" and added a few functions in order to manipulate the struct. I then simply added an if statement in the pixel_draw and rect_draw functions, as to pass the data to the canvas if it is enabled. 

    pixel_draw(nrf_lcd_t const * p_instanceuint16_t xuint16_t y,uint32_t color):

    if( m_canvas.enabled ){
    
        // Subtract canvas start-coordinates form actual coordinates.
        x -= m_canvas.rect.x;
        y -= m_canvas.rect.y;
    
        // Get pointer to the byte holding information for this x and y
        uint8_t *ptr = &m_canvas.buffer[(x / 8) + y * ((m_canvas.rect.width + 7) / 8)];
    
        if (color)
            *ptr |= 0x80 >> (x & 7);
        else
            *ptr &= ~(0x80 >> (x & 7));
    
    }else{
        p_instance->lcd_pixel_draw(x, y, color);
    }

    rect_draw(nrf_lcd_t const * p_instance, uint16_t x, uint16_t y,uint32_t color):

    if( m_canvas.enabled ){
        for (int16_t i = x; i < x + width; i++) {
            // Write vertical lines to canvas
            line_draw(p_instance, i, y, i, y + height - 1, color);
        }
    }else{
        p_instance->lcd_rect_draw(x, y, width, height, color);
    }

    My implementation is heavily inspired by that of Adafruits GXF library, and their GXFcanvas1 class:

    https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp#L1745

    best regards.

    Emil 

Reply
  • Hi thanks for your reply! 

    I chose to implement a canvas buffer directly in the GFX library, as I did not like the method of storing the entire screen in a buffer. My implementation is simple, I made a structure to hold my canvas data (position, width, height and buffer).

    typedef struct{
        nrf_gfx_rect_t rect;
        bool enabled;
        uint8_t * buffer;
    }nrf_gfx_canvas_t; 

    I created the struct inside nrf_gfx.c "static nrf_gfx_canvas_t m_canvas" and added a few functions in order to manipulate the struct. I then simply added an if statement in the pixel_draw and rect_draw functions, as to pass the data to the canvas if it is enabled. 

    pixel_draw(nrf_lcd_t const * p_instanceuint16_t xuint16_t y,uint32_t color):

    if( m_canvas.enabled ){
    
        // Subtract canvas start-coordinates form actual coordinates.
        x -= m_canvas.rect.x;
        y -= m_canvas.rect.y;
    
        // Get pointer to the byte holding information for this x and y
        uint8_t *ptr = &m_canvas.buffer[(x / 8) + y * ((m_canvas.rect.width + 7) / 8)];
    
        if (color)
            *ptr |= 0x80 >> (x & 7);
        else
            *ptr &= ~(0x80 >> (x & 7));
    
    }else{
        p_instance->lcd_pixel_draw(x, y, color);
    }

    rect_draw(nrf_lcd_t const * p_instance, uint16_t x, uint16_t y,uint32_t color):

    if( m_canvas.enabled ){
        for (int16_t i = x; i < x + width; i++) {
            // Write vertical lines to canvas
            line_draw(p_instance, i, y, i, y + height - 1, color);
        }
    }else{
        p_instance->lcd_rect_draw(x, y, width, height, color);
    }

    My implementation is heavily inspired by that of Adafruits GXF library, and their GXFcanvas1 class:

    https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp#L1745

    best regards.

    Emil 

Children
No Data
Related