1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #16466 from aabadie/pr/tests/qr-code-generator-opt

tests/pkg_qr-code-generator: improve display speed in test application
This commit is contained in:
Leandro Lanzieri 2021-05-11 14:30:34 +02:00 committed by GitHub
commit b628d93731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 18 deletions

View File

@ -52,6 +52,7 @@ tests/pkg_nanocbor
tests/pkg_nanopb
tests/pkg_qDSA
tests/pkg_qcbor
tests/pkg_qr-code-generator
tests/pkg_relic
tests/pkg_tiny-asn1
tests/pkg_tinycbor

View File

@ -22,6 +22,9 @@
#include <stdbool.h>
#include <stdint.h>
#include "test_utils/expect.h"
#include "qrcodegen.h"
#ifdef MODULE_DISP_DEV
@ -32,11 +35,21 @@
#define MESSAGE_TO_ENCODE "unknown"
#endif
static uint8_t qr0[qrcodegen_BUFFER_LEN_FOR_VERSION(2)];
static uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(2)];
/* Compute buffer sizes based on the message to encode len to avoid a
* failed assertion in qrcodegen */
#define ENCODER_VERSION (sizeof(MESSAGE_TO_ENCODE) >> 3)
static uint8_t qr0[qrcodegen_BUFFER_LEN_FOR_VERSION(ENCODER_VERSION)];
static uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(ENCODER_VERSION)];
#ifdef MODULE_DISP_DEV
#define DISPLAY_BUFFER_MAX_SIZE (320)
static uint16_t display_buffer[DISPLAY_BUFFER_MAX_SIZE] = { 0 };
#endif
int main(void)
{
expect(ENCODER_VERSION <= qrcodegen_VERSION_MAX);
if (!qrcodegen_encodeText(MESSAGE_TO_ENCODE,
buffer, qr0, qrcodegen_Ecc_MEDIUM,
qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX,
@ -56,30 +69,32 @@ int main(void)
}
disp_dev_backlight_on();
uint16_t white = UINT16_MAX;
uint16_t black = 0;
for (uint16_t y = 0; y < disp_dev_height(disp_dev->dev); y++) {
for (uint16_t x = 0; x < disp_dev_width(disp_dev->dev); x++) {
disp_dev_map(disp_dev->dev, x, x, y, y, &black);
}
}
/* Compute scaling factor and height/width offsets */
const uint8_t scale = disp_dev_height(disp_dev->dev) / size;
const uint8_t w_offset = (disp_dev_width(disp_dev->dev) - (size * scale)) / 2;
const uint8_t h_offset = (disp_dev_height(disp_dev->dev) - (size * scale)) / 2;
/* Clear the screen */
for (uint16_t y = 0; y < disp_dev_height(disp_dev->dev); y ++) {
disp_dev_map(disp_dev->dev, 0, disp_dev_width(disp_dev->dev) - 1, y, y, display_buffer);
}
/* Prepare a subset of the display buffer for white tiles */
for (int w = 0; w < scale; w++) {
for (int h = 0; h < scale; h++) {
display_buffer[w + h * scale] = UINT16_MAX;
}
}
#endif
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
#ifdef MODULE_DISP_DEV
for (int w = x * scale; w < (x + 1) * scale; w++) {
for (int h = y * scale; h < (y + 1) * scale; h++) {
if (qrcodegen_getModule(qr0, x, y)) {
disp_dev_map(disp_dev->dev,
w + w_offset, w + w_offset, h + h_offset, h + h_offset,
&white);
}
}
if (qrcodegen_getModule(qr0, x, y)) {
disp_dev_map(disp_dev->dev,
w_offset + (x * scale), w_offset + ((x + 1)* scale) - 1,
h_offset + (y * scale), h_offset + ((y + 1)* scale) - 1,
display_buffer);
}
#endif
printf("%s", qrcodegen_getModule(qr0, x, y) ? "██" : " ");