cancel
Showing results for 
Search instead for 
Did you mean: 

Using qrcode with display BW 1bpp

EmanueleC
Associate

I'm using an STM32G0 with a 240 x 160 monochrome 1bpp SPI display. Is it possible to use the QR code component from the TouchGFX library?

I'm using TouchGFX version 4.26.0.

Many thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
JohanAstrup
ST Employee

Hello @EmanueleC.

1bpp support is not implemented in the QR code widget currently bundled with TouchGFX. However, the widgets are open source, so you can add it yourself. You can find QRCode.cpp here: Middlewares\ST\touchgfx\framework\source\touchgfx\widgets

I recommend copying this file to gui\src\common and modifying the copy. The project will automatically use your version instead of the default one.

You’ll need to implement a draw function for 1bpp and then extend the switch statement in the draw function to call this 1bpp-specific function when the bit depth is 1:

void QRCode::draw(const Rect& invalidatedArea) const
{
    ...

    // Select correct drawing function for framebuffer format and alpha
    switch (bpp)
    {
    case 1:
        // Your 1bpp implementation goes here
        break;
    case 16:
        // RGB565
        drawfunc = (alpha < 255) ? &QRCode::drawBitRGB565Blend : &QRCode::drawBitRGB565;
        break;
    case 24:
        // RGB888
        drawfunc = (alpha < 255) ? &QRCode::drawBitRGB888Blend : &QRCode::drawBitRGB888;
        break;
    case 32:
        // ARGB8888
        drawfunc = (alpha < 255) ? &QRCode::drawBitARGB8888Blend : &QRCode::drawBitARGB8888;
        break;
    default:
        return;
    }

    ...
}

Best regards,
Johan

View solution in original post

1 REPLY 1
JohanAstrup
ST Employee

Hello @EmanueleC.

1bpp support is not implemented in the QR code widget currently bundled with TouchGFX. However, the widgets are open source, so you can add it yourself. You can find QRCode.cpp here: Middlewares\ST\touchgfx\framework\source\touchgfx\widgets

I recommend copying this file to gui\src\common and modifying the copy. The project will automatically use your version instead of the default one.

You’ll need to implement a draw function for 1bpp and then extend the switch statement in the draw function to call this 1bpp-specific function when the bit depth is 1:

void QRCode::draw(const Rect& invalidatedArea) const
{
    ...

    // Select correct drawing function for framebuffer format and alpha
    switch (bpp)
    {
    case 1:
        // Your 1bpp implementation goes here
        break;
    case 16:
        // RGB565
        drawfunc = (alpha < 255) ? &QRCode::drawBitRGB565Blend : &QRCode::drawBitRGB565;
        break;
    case 24:
        // RGB888
        drawfunc = (alpha < 255) ? &QRCode::drawBitRGB888Blend : &QRCode::drawBitRGB888;
        break;
    case 32:
        // ARGB8888
        drawfunc = (alpha < 255) ? &QRCode::drawBitARGB8888Blend : &QRCode::drawBitARGB8888;
        break;
    default:
        return;
    }

    ...
}

Best regards,
Johan