mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2026-01-01 01:41:18 +01:00
tests: pkg_u8g2: add u8g2 test application.
This commit is contained in:
parent
6bb108c054
commit
4b2fca6f1a
51
tests/pkg_u8g2/Makefile
Normal file
51
tests/pkg_u8g2/Makefile
Normal file
@ -0,0 +1,51 @@
|
||||
APPLICATION = pkg_u8g2
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
USEPKG += u8g2
|
||||
|
||||
# set default device parameters in case they are undefined
|
||||
TEST_U8G2_OUTPUT ?= 1
|
||||
TEST_U8G2_DISPLAY ?= u8g2_Setup_ssd1306_128x64_noname_1
|
||||
|
||||
TEST_U8G2_I2C ?= 0
|
||||
TEST_U8G2_SPI ?= 0
|
||||
|
||||
TEST_U8G2_ADDR ?= 0x78
|
||||
|
||||
TEST_U8G2_PIN_CS ?= GPIO_PIN\(0,0\)
|
||||
TEST_U8G2_PIN_DC ?= GPIO_PIN\(0,0\)
|
||||
TEST_U8G2_PIN_RESET ?= GPIO_PIN\(0,0\)
|
||||
|
||||
# features depend on output type
|
||||
ifeq ($(TEST_U8G2_OUTPUT),1)
|
||||
USEMODULE += u8g2_utf8
|
||||
endif
|
||||
|
||||
ifeq ($(TEST_U8G2_OUTPUT),2)
|
||||
USEMODULE += u8g2_sdl
|
||||
endif
|
||||
|
||||
ifeq ($(TEST_U8G2_OUTPUT),3)
|
||||
FEATURES_REQUIRED += periph_gpio periph_spi
|
||||
endif
|
||||
|
||||
ifeq ($(TEST_U8G2_OUTPUT),4)
|
||||
FEATURES_REQUIRED += periph_gpio periph_i2c
|
||||
endif
|
||||
|
||||
# export parameters
|
||||
CFLAGS += -DTEST_U8G2_OUTPUT=$(TEST_U8G2_OUTPUT)
|
||||
CFLAGS += -DTEST_U8G2_DISPLAY=$(TEST_U8G2_DISPLAY)
|
||||
|
||||
CFLAGS += -DTEST_U8G2_SPI=$(TEST_U8G2_SPI)
|
||||
CFLAGS += -DTEST_U8G2_I2C=$(TEST_U8G2_I2C)
|
||||
|
||||
CFLAGS += -DTEST_U8G2_ADDR=$(TEST_U8G2_ADDR)
|
||||
|
||||
CFLAGS += -DTEST_U8G2_PIN_CS=$(TEST_U8G2_PIN_CS)
|
||||
CFLAGS += -DTEST_U8G2_PIN_DC=$(TEST_U8G2_PIN_DC)
|
||||
CFLAGS += -DTEST_U8G2_PIN_RESET=$(TEST_U8G2_PIN_RESET)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
42
tests/pkg_u8g2/README.md
Normal file
42
tests/pkg_u8g2/README.md
Normal file
@ -0,0 +1,42 @@
|
||||
# U8g2 Package Test
|
||||
|
||||
## About
|
||||
This is a test application for the U8g2 package. This package is a graphical display library, including display drivers.
|
||||
|
||||
## Usage
|
||||
This test application will initialize the U8g2 to output on one of the following:
|
||||
|
||||
* output to stdout virtual screen.
|
||||
* output to SDL virtual screen.
|
||||
* output to I2C graphics screen.
|
||||
* output to SPI graphics screen.
|
||||
|
||||
### Output to stdout
|
||||
To output to this virtual screen, supply `TEST_U8G2_OUTPUT=1` to the `make` command.
|
||||
|
||||
### Output to SDL
|
||||
To output to this virtual screen, supply `TEST_U8G2_OUTPUT=2` to the `make` command.
|
||||
|
||||
This is a native-only option.
|
||||
|
||||
### Output to SPI
|
||||
To output to screen, supply `TEST_U8G2_OUTPUT=3` to the `make` command.
|
||||
|
||||
* `TEST_U8G2_SPI` — The SPI device.
|
||||
* `TEST_U8G2_PIN_CS` — If applicable, the CS pin.
|
||||
* `TEST_U8G2_PIN_DC` — If applicable, the Command/Data pin.
|
||||
* `TEST_U8G2_PIN_RESET` — If applicable, the reset pin.
|
||||
* `TEST_U8G2_DISPLAY` — The used display driver (see https://github.com/olikraus/u8g2/wiki/u8g2setupc). Make sure you select a SPI compatible display.
|
||||
|
||||
### Output to I2C
|
||||
To output to screen, supply `TEST_U8G2_OUTPUT=4` to the `make` command.
|
||||
|
||||
Furthermore, you can configure the following:
|
||||
|
||||
* `TEST_U8G2_I2C` — The I2C device.
|
||||
* `TEST_U8G2_ADDR` — The address to write commands to.
|
||||
* `TEST_U8G2_PIN_RESET` — If applicable, the reset pin.
|
||||
* `TEST_U8G2_DISPLAY` — The used display driver (see https://github.com/olikraus/u8g2/wiki/u8g2setupc). Make sure you select an I2C compatible display.
|
||||
|
||||
## 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'.
|
||||
195
tests/pkg_u8g2/main.c
Normal file
195
tests/pkg_u8g2/main.c
Normal file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 U8g2 package.
|
||||
*
|
||||
* @author Bas Stottelaar <basstottelaar@gmail.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#define TEST_U8G2_OUTPUT_STDOUT 1
|
||||
#define TEST_U8G2_OUTPUT_SDL 2
|
||||
#define TEST_U8G2_OUTPUT_SPI 3
|
||||
#define TEST_U8G2_OUTPUT_I2C 4
|
||||
|
||||
#ifndef TEST_U8G2_OUTPUT
|
||||
#error "TEST_U8G2_OUTPUT not defined"
|
||||
#endif
|
||||
#ifndef TEST_U8G2_DISPLAY
|
||||
#error "TEST_U8G2_DISPLAY not defined"
|
||||
#endif
|
||||
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_I2C
|
||||
#ifndef TEST_U8G2_I2C
|
||||
#error "TEST_U8G2_I2C not defined"
|
||||
#endif
|
||||
#ifndef TEST_U8G2_ADDR
|
||||
#error "TEST_U8G2_ADDR not defined"
|
||||
#endif
|
||||
#ifndef TEST_U8G2_PIN_RESET
|
||||
#error "TEST_U8G2_PIN_RESET not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SPI
|
||||
#ifndef TEST_U8G2_SPI
|
||||
#error "TEST_U8G2_SPI not defined"
|
||||
#endif
|
||||
#ifndef TEST_U8G2_PIN_CS
|
||||
#error "TEST_U8G2_PIN_CS not defined"
|
||||
#endif
|
||||
#ifndef TEST_U8G2_PIN_DC
|
||||
#error "TEST_U8G2_PIN_DC not defined"
|
||||
#endif
|
||||
#ifndef TEST_U8G2_PIN_RESET
|
||||
#error "TEST_U8G2_PIN_RESET not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "periph/gpio.h"
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "u8g2.h"
|
||||
|
||||
/**
|
||||
* @brief RIOT-OS logo, 64x32 pixels at 8 pixels per byte.
|
||||
*/
|
||||
static const uint8_t logo[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x3C,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1E, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x70, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0E,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0E, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF0, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x1E,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF0, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0xF8,
|
||||
0x30, 0x3C, 0x3F, 0xC0, 0x00, 0x0C, 0x77, 0xF0, 0x38, 0x7E, 0x3F, 0xC0,
|
||||
0x00, 0x7E, 0x73, 0xC0, 0x38, 0xE7, 0x06, 0x00, 0x00, 0xFC, 0x71, 0x00,
|
||||
0x38, 0xE3, 0x06, 0x00, 0x01, 0xF0, 0x70, 0x00, 0x38, 0xE3, 0x06, 0x00,
|
||||
0x01, 0xC0, 0x70, 0x00, 0x38, 0xE3, 0x06, 0x00, 0x03, 0x80, 0x70, 0xC0,
|
||||
0x38, 0xE3, 0x06, 0x00, 0x03, 0x80, 0x71, 0xE0, 0x38, 0xE3, 0x06, 0x00,
|
||||
0x03, 0x80, 0x70, 0xE0, 0x38, 0xE3, 0x06, 0x00, 0x03, 0x80, 0x70, 0xF0,
|
||||
0x38, 0xE3, 0x06, 0x00, 0x03, 0x80, 0x70, 0x70, 0x38, 0xE3, 0x06, 0x00,
|
||||
0x03, 0x80, 0xF0, 0x78, 0x38, 0xE3, 0x06, 0x00, 0x03, 0xC1, 0xE0, 0x3C,
|
||||
0x38, 0xE7, 0x06, 0x00, 0x01, 0xE3, 0xE0, 0x3C, 0x38, 0x7E, 0x06, 0x00,
|
||||
0x01, 0xFF, 0xC0, 0x1C, 0x30, 0x3C, 0x06, 0x00, 0x00, 0x7F, 0x80, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
#if (TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_I2C) || (TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SPI)
|
||||
/**
|
||||
* @brief RIOT-OS pin maping of U8g2 pin numbers to RIOT-OS GPIO pins.
|
||||
* @note To minimize the overhead, you can implemente an alternative for
|
||||
* u8x8_gpio_and_delay_riotos.
|
||||
*/
|
||||
static gpio_t pins[] = {
|
||||
[U8X8_PIN_CS] = TEST_U8G2_PIN_CS,
|
||||
[U8X8_PIN_DC] = TEST_U8G2_PIN_DC,
|
||||
[U8X8_PIN_RESET] = TEST_U8G2_PIN_RESET
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Bit mapping to indicate which pins are set.
|
||||
*/
|
||||
static uint32_t pins_enabled = (
|
||||
(1 << U8X8_PIN_CS) +
|
||||
(1 << U8X8_PIN_DC) +
|
||||
(1 << U8X8_PIN_RESET)
|
||||
);
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t screen = 0;
|
||||
u8g2_t u8g2;
|
||||
|
||||
/* initialize to stdout */
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT
|
||||
puts("initializing to stdout.");
|
||||
|
||||
u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0);
|
||||
#endif
|
||||
|
||||
/* initialize to virtual SDL (native only) */
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SDL
|
||||
puts("initializing to SDL.");
|
||||
|
||||
u8g2_SetupBuffer_SDL_128x64_4(&u8g2, U8G2_R0);
|
||||
#endif
|
||||
|
||||
/* initialize to SPI */
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SPI
|
||||
puts("initializing to SPI.");
|
||||
|
||||
TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_spi, u8x8_gpio_and_delay_riotos);
|
||||
|
||||
u8x8_SetPins(u8g2_GetU8x8(&u8g2), pins, pins_enabled);
|
||||
u8x8_SetDevice(u8g2_GetU8x8(&u8g2), TEST_U8G2_SPI);
|
||||
#endif
|
||||
|
||||
/* initialize to I2C */
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_I2C
|
||||
puts("initializing to I2C.");
|
||||
|
||||
TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_i2c, u8x8_gpio_and_delay_riotos);
|
||||
|
||||
u8x8_SetPins(u8g2_GetU8x8(&u8g2), pins, pins_enabled);
|
||||
u8x8_SetDevice(u8g2_GetU8x8(&u8g2), TEST_U8G2_I2C);
|
||||
u8g2_SetI2CAddress(&u8g2, TEST_U8G2_ADDR);
|
||||
#endif
|
||||
|
||||
/* initialze the display */
|
||||
puts("Initializing display.");
|
||||
|
||||
u8g2_InitDisplay(&u8g2);
|
||||
u8g2_SetPowerSave(&u8g2, 0);
|
||||
|
||||
/* start drawing in a loop */
|
||||
puts("Drawing on screen.");
|
||||
|
||||
while (true) {
|
||||
u8g2_FirstPage(&u8g2);
|
||||
|
||||
do {
|
||||
u8g2_SetDrawColor(&u8g2, 1);
|
||||
u8g2_SetFont(&u8g2, u8g2_font_helvB12_tf);
|
||||
|
||||
if (screen == 0) {
|
||||
u8g2_DrawStr(&u8g2, 12, 22, "THIS");
|
||||
} else if (screen == 1) {
|
||||
u8g2_DrawStr(&u8g2, 24, 22, "IS");
|
||||
} else if (screen == 2) {
|
||||
u8g2_DrawBitmap(&u8g2, 0, 0, 8, 32, logo);
|
||||
}
|
||||
} while (u8g2_NextPage(&u8g2));
|
||||
|
||||
#if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT
|
||||
/* transfer screen buffer to stdout */
|
||||
utf8_show();
|
||||
#endif
|
||||
|
||||
/* show screen in next iteration */
|
||||
screen = (screen + 1) % 3;
|
||||
|
||||
/* sleep a little */
|
||||
xtimer_sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user