1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests: pkg_ucglib: add test application.

This commit is contained in:
Bas Stottelaar 2018-04-05 14:20:57 +02:00
parent ebdf7a5aa9
commit bfccf3182a
5 changed files with 1496 additions and 0 deletions

45
tests/pkg_ucglib/Makefile Normal file
View File

@ -0,0 +1,45 @@
include ../Makefile.tests_common
USEMODULE += xtimer
USEPKG += ucglib
# set default device parameters in case they are undefined
TEST_OUTPUT ?= 1
TEST_SPI ?= 0
TEST_PIN_CS ?= GPIO_PIN\(0,0\)
TEST_PIN_CD ?= GPIO_PIN\(0,0\)
TEST_PIN_RESET ?= GPIO_PIN\(0,0\)
ifeq ($(TEST_OUTPUT),3)
TEST_DISPLAY ?= ucg_dev_ssd1331_18x96x64_univision
TEST_DISPLAY_EXT ?= ucg_ext_ssd1331_18
endif
# features depend on output type
ifeq ($(TEST_OUTPUT),2)
USEMODULE += ucglib_sdl
endif
ifeq ($(TEST_OUTPUT),3)
FEATURES_REQUIRED += periph_gpio periph_spi
endif
# export parameters
CFLAGS += -DTEST_OUTPUT=$(TEST_OUTPUT)
CFLAGS += -DTEST_SPI=$(TEST_SPI)
CFLAGS += -DTEST_PIN_CS=$(TEST_PIN_CS)
CFLAGS += -DTEST_PIN_CD=$(TEST_PIN_CD)
CFLAGS += -DTEST_PIN_RESET=$(TEST_PIN_RESET)
CFLAGS += -DTEST_DISPLAY=$(TEST_DISPLAY)
CFLAGS += -DTEST_DISPLAY_EXT=$(TEST_DISPLAY_EXT)
include $(RIOTBASE)/Makefile.include
test:
tests/01-run.py

View File

@ -0,0 +1,36 @@
# Ucglib Package Test
## About
This is a test application for the Ucglib package. This package is a graphical color display library, including display drivers.
## Usage
This test application will initialize the Ucglib to output on one of the following:
* output to dummy screen.
* output to SDL virtual screen.
* output to SPI graphics screen.
Note: you may have to run `make clean` between different output modes.
### Output to dummy
To output to this virtual screen, supply `TEST_OUTPUT=1` to the `make` command.
It logs internal calls to screen and is used for testing the package internals only.
### Output to SDL
To output to this virtual screen, supply `TEST_OUTPUT=2` to the `make` command.
This is a native-only option and requires SDL2 (32-bits) to be installed.
### Output to SPI
To output to screen, supply `TEST_OUTPUT=3` to the `make` command.
* `TEST_SPI` — The SPI device.
* `TEST_PIN_CS` — If applicable, the CS pin.
* `TEST_PIN_CD` — If applicable, the Command/Data pin.
* `TEST_PIN_RESET` — If applicable, the reset pin.
* `TEST_DISPLAY` — The used display driver (see https://github.com/olikraus/ucglib/wiki/displays). Make sure you select a SPI compatible display.
* `TEST_DISPLAY_EXT` — The applicable display extension (additional commands).
## Expected result
The output of this test depends on the output mode and used hardware. If it works, the application cycles through three screens with the text: 'This is RIOT-OS'.

1190
tests/pkg_ucglib/logo.h Normal file

File diff suppressed because it is too large Load Diff

159
tests/pkg_ucglib/main.c Normal file
View File

@ -0,0 +1,159 @@
/*
* Copyright (C) 2018 Bas Stottelaar <basstottelaar@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Test application for the Ucglib package.
*
* @author Bas Stottelaar <basstottelaar@gmail.com>
*
* @}
*/
#define TEST_OUTPUT_DUMMY 1
#define TEST_OUTPUT_SDL 2
#define TEST_OUTPUT_SPI 3
#ifndef TEST_OUTPUT
#error "TEST_OUTPUT not defined"
#endif
#if TEST_OUTPUT == TEST_OUTPUT_SPI
#ifndef TEST_SPI
#error "TEST_SPI not defined"
#endif
#ifndef TEST_DISPLAY
#error "TEST_DISPLAY not defined"
#endif
#ifndef TEST_DISPLAY_EXT
#error "TEST_DISPLAY_EXT not defined"
#endif
#ifndef TEST_PIN_CS
#error "TEST_PIN_CS not defined"
#endif
#ifndef TEST_PIN_CD
#error "TEST_PIN_CD not defined"
#endif
#ifndef TEST_PIN_RESET
#error "TEST_PIN_RESET not defined"
#endif
#endif
#include <stdio.h>
#include "periph/gpio.h"
#if TEST_OUTPUT == TEST_OUTPUT_SPI
#include "periph/spi.h"
#endif
#include "xtimer.h"
#include "ucg.h"
#include "logo.h"
#if TEST_OUTPUT == TEST_OUTPUT_SPI
/**
* @brief RIOT-OS pin maping of Ucglib pin numbers to RIOT-OS GPIO pins.
* @note To minimize the overhead, you can implement an alternative for
* ucg_com_riotos_hw_spi.
*/
static gpio_t pins[] = {
[UCG_PIN_CS] = TEST_PIN_CS,
[UCG_PIN_CD] = TEST_PIN_CD,
[UCG_PIN_RST] = TEST_PIN_RESET
};
/**
* @brief Bit mapping to indicate which pins are set.
*/
static uint32_t pins_enabled = (
(1 << UCG_PIN_CS) +
(1 << UCG_PIN_CD) +
(1 << UCG_PIN_RST)
);
#endif
int main(void)
{
uint32_t screen = 0;
ucg_t ucg;
#if TEST_OUTPUT == TEST_OUTPUT_DUMMY
/* initialize dummy output */
puts("Initializing dummy output.");
ucg_Init(&ucg, ucg_dev_dummy_cb, ucg_ext_none, NULL);
#endif
#if TEST_OUTPUT == TEST_OUTPUT_SDL
/* initialize to virtual SDL (native only) */
puts("Initializing to SDL.");
ucg_Init(&ucg, ucg_sdl_dev_cb, ucg_ext_none, NULL);
#endif
#if TEST_OUTPUT == TEST_OUTPUT_SPI
/* initialize to SPI */
puts("Initializing to SPI.");
ucg_SetPins(&ucg, pins, pins_enabled);
ucg_SetDevice(&ucg, SPI_DEV(TEST_SPI));
ucg_Init(&ucg, TEST_DISPLAY, TEST_DISPLAY_EXT, ucg_com_riotos_hw_spi);
#endif
/* initialize the display */
puts("Initializing display.");
ucg_SetFontMode(&ucg, UCG_FONT_MODE_TRANSPARENT);
ucg_SetFont(&ucg, ucg_font_helvB12_tf);
/* start drawing in a loop */
puts("Drawing on screen.");
while (1) {
ucg_ClearScreen(&ucg);
switch (screen) {
case 0:
ucg_SetColor(&ucg, 0, 189, 32, 43);
ucg_DrawString(&ucg, 0, 20, 0, "THIS");
break;
case 1:
ucg_SetColor(&ucg, 0, 63, 167, 136);
ucg_DrawString(&ucg, 0, 20, 0, "IS");
break;
case 2:
for (int y = 0; y < 48; y++) {
for (int x = 0; x < 96; x++) {
uint32_t offset = (x + (y * 96)) * 3;
ucg_SetColor(&ucg, 0, logo[offset + 0], logo[offset + 1], logo[offset + 2]);
ucg_DrawPixel(&ucg, x, y);
}
}
break;
}
#if TEST_OUTPUT == TEST_OUTPUT_SDL
/* handle SDL events */
ucg_sdl_get_key();
#endif
/* show screen in next iteration */
screen = (screen + 1) % 3;
/* sleep a little */
xtimer_sleep(1);
}
return 0;
}

View File

@ -0,0 +1,66 @@
#!/usr/bin/env python3
# Copyright (C) 2018 Bas Stottelaar <basstottelaar@gmail.com>
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import os
import sys
EXPECTED_STDOUT = (
'ucg: UCG_MSG_DRAW_PIXEL (128)',
'ucg: UCG_MSG_DRAW_PIXEL (256)',
'ucg: UCG_MSG_DRAW_PIXEL (384)',
'ucg: UCG_MSG_DRAW_PIXEL (512)',
'ucg: UCG_MSG_DRAW_PIXEL (640)',
'ucg: UCG_MSG_DRAW_PIXEL (768)',
'ucg: UCG_MSG_DRAW_PIXEL (896)',
'ucg: UCG_MSG_DRAW_PIXEL (1024)',
'ucg: UCG_MSG_DRAW_PIXEL (1152)',
'ucg: UCG_MSG_DRAW_PIXEL (1280)',
'ucg: UCG_MSG_DRAW_PIXEL (1408)',
'ucg: UCG_MSG_DRAW_PIXEL (1536)',
'ucg: UCG_MSG_DRAW_PIXEL (1664)',
'ucg: UCG_MSG_DRAW_PIXEL (1792)',
'ucg: UCG_MSG_DRAW_PIXEL (1920)',
'ucg: UCG_MSG_DRAW_PIXEL (2048)',
'ucg: UCG_MSG_DRAW_PIXEL (2176)',
'ucg: UCG_MSG_DRAW_PIXEL (2304)',
'ucg: UCG_MSG_DRAW_PIXEL (2432)',
'ucg: UCG_MSG_DRAW_PIXEL (2560)',
'ucg: UCG_MSG_DRAW_PIXEL (2688)',
'ucg: UCG_MSG_DRAW_PIXEL (2816)',
'ucg: UCG_MSG_DRAW_PIXEL (2944)',
'ucg: UCG_MSG_DRAW_PIXEL (3072)',
'ucg: UCG_MSG_DRAW_PIXEL (3200)',
'ucg: UCG_MSG_DRAW_PIXEL (3328)',
'ucg: UCG_MSG_DRAW_PIXEL (3456)',
'ucg: UCG_MSG_DRAW_PIXEL (3584)',
'ucg: UCG_MSG_DRAW_PIXEL (3712)',
'ucg: UCG_MSG_DRAW_PIXEL (3840)',
'ucg: UCG_MSG_DRAW_PIXEL (3968)',
'ucg: UCG_MSG_DRAW_PIXEL (4096)',
'ucg: UCG_MSG_DRAW_PIXEL (4224)',
'ucg: UCG_MSG_DRAW_PIXEL (4352)',
'ucg: UCG_MSG_DRAW_PIXEL (4480)',
'ucg: UCG_MSG_DRAW_PIXEL (4608)',
)
def testfunc(child):
child.expect_exact('Initializing dummy output.')
child.expect_exact('ucg: UCG_MSG_DEV_POWER_UP')
child.expect_exact('ucg: UCG_MSG_GET_DIMENSION')
child.expect_exact('Initializing display.')
child.expect_exact('Drawing on screen.')
for line in EXPECTED_STDOUT:
child.expect_exact(line)
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
from testrunner import run
sys.exit(run(testfunc))