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

tests/pkg_qr-code-generator: extend with disp_dev API

This commit is contained in:
Alexandre Abadie 2021-05-10 12:42:32 +02:00
parent 08ae97257c
commit 4e37e1ad44
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
4 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,11 @@
config APPLICATION
bool
default y
imply MODULE_AUTO_INIT_SCREEN if BOARD_HAS_DISPLAY
imply MODULE_DISP_DEV if BOARD_HAS_DISPLAY
depends on TEST_KCONFIG
config BOARD_HAS_DISPLAY
bool
default y
depends on BOARD_PINETIME || BOARD_ADAFRUIT_CLUE || BOARD_STM32F429I_DISC1 || BOARD_STM32F429I_DISCO

View File

@ -6,4 +6,8 @@ MESSAGE_TO_ENCODE ?= "https://riot-os.org"
CFLAGS += -DMESSAGE_TO_ENCODE=\"$(MESSAGE_TO_ENCODE)\"
# This application provides a 'Kconfig' file and we want to explicitly disable
# Kconfig by default by setting this variable to empty
SHOULD_RUN_KCONFIG ?=
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,5 @@
# Boards with a screen can use disp_dev
ifneq (,$(filter stm32f429i-disc% pinetime adafruit-clue,$(BOARD)))
USEMODULE += auto_init_screen
USEMODULE += disp_dev
endif

View File

@ -24,6 +24,10 @@
#include <stdint.h>
#include "qrcodegen.h"
#ifdef MODULE_DISP_DEV
#include "disp_dev.h"
#endif
#ifndef MESSAGE_TO_ENCODE
#define MESSAGE_TO_ENCODE "unknown"
#endif
@ -42,9 +46,44 @@ int main(void)
}
int size = qrcodegen_getSize(qr0);
#ifdef MODULE_DISP_DEV
/* Use the first screen */
disp_dev_reg_t *disp_dev = disp_dev_reg_find_screen(0);
if (!disp_dev) {
puts("No screen found!");
return -1;
}
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);
}
}
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;
#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);
}
}
}
#endif
printf("%s", qrcodegen_getModule(qr0, x, y) ? "██" : " ");
}
puts("");
}