diff --git a/pkg/u8g2/Makefile b/pkg/u8g2/Makefile index df94ec04ed17790bd8265e03345c1f8b5c1f1ef0..310b6b9cb1bb8f0ec25c16b7713742d28060a9ce 100644 --- a/pkg/u8g2/Makefile +++ b/pkg/u8g2/Makefile @@ -1,11 +1,16 @@ PKG_NAME=u8g2 PKG_URL=https://github.com/olikraus/u8g2 -PKG_VERSION=4dc79943020d9512207aea4cf914740556173793 +PKG_VERSION=f08ff974c03e5c848bc5d2ae3fddb6a97897881a PKG_LICENSE=BSD-2-Clause .PHONY: all all: git-download + cp $(RIOTBASE)/pkg/u8g2/src/Makefile $(PKG_BUILDDIR)/Makefile + cp $(RIOTBASE)/pkg/u8g2/src/csrc/Makefile $(PKG_BUILDDIR)/csrc/Makefile + cp $(RIOTBASE)/pkg/u8g2/src/csrc/u8g2_riotos.c $(PKG_BUILDDIR)/csrc/u8g2_riotos.c + cp $(RIOTBASE)/pkg/u8g2/src/sys/sdl/common/Makefile $(PKG_BUILDDIR)/sys/sdl/common/Makefile + cp $(RIOTBASE)/pkg/u8g2/src/sys/utf8/common/Makefile $(PKG_BUILDDIR)/sys/utf8/common/Makefile "$(MAKE)" -C $(PKG_BUILDDIR) include $(RIOTBASE)/pkg/pkg.mk diff --git a/pkg/u8g2/Makefile.include b/pkg/u8g2/Makefile.include index 98bbc699d47a624785c44292fede2c8b713a3736..1dac566a42bb3eccacbab2366edba540132b6843 100644 --- a/pkg/u8g2/Makefile.include +++ b/pkg/u8g2/Makefile.include @@ -2,5 +2,5 @@ INCLUDES += -I$(PKGDIRBASE)/u8g2/csrc # Link SDL if enabled. ifneq (,$(filter u8g2_sdl,$(USEMODULE))) - LINKFLAGS += `sdl-config --libs` + LINKFLAGS += `sdl2-config --libs` endif diff --git a/pkg/u8g2/README.md b/pkg/u8g2/README.md index 8eaae174aba57d69793f5254f35e8e3718e702a0..97dcb818bddb094350530cfbab89f4667a18b92a 100644 --- a/pkg/u8g2/README.md +++ b/pkg/u8g2/README.md @@ -53,7 +53,7 @@ u8g2_SetDevice(&u8g2, SPI_DEV(0)); For targets without an I2C or SPI, virtual displays are available. These displays are part of U8g2, but are not compiled by default. * By adding `USEMODULE += u8g2_utf8`, a terminal display is used as virtual display, using UTF8 block characters that are printed to stdout. -* By adding `USEMODULE += u8g2_sdl`, a SDL virtual display will be used. This is only available on native targets that have SDL installed. It uses `sdl-config` to find the headers and libraries. Note that RIOT-OS builds 32-bit binaries and requires 32-bit SDL libraries. +* By adding `USEMODULE += u8g2_sdl`, a SDL virtual display will be used. This is only available on native targets that have SDL installed. It uses `sdl2-config` to find the headers and libraries. Note that RIOT-OS builds 32-bit binaries and requires 32-bit SDL libraries. ### Example ``` diff --git a/pkg/u8g2/patches/0001-add-RIOT-OS-interface.patch b/pkg/u8g2/patches/0001-add-RIOT-OS-interface.patch new file mode 100644 index 0000000000000000000000000000000000000000..bd9e3270935243a09456c3d19b81c7b911e422f6 Binary files /dev/null and b/pkg/u8g2/patches/0001-add-RIOT-OS-interface.patch differ diff --git a/pkg/u8g2/patches/0001-u8g2-add-RIOT-makefiles.patch b/pkg/u8g2/patches/0001-u8g2-add-RIOT-makefiles.patch deleted file mode 100644 index 6f81d3c212513499de80c6d232930b7cfc01db63..0000000000000000000000000000000000000000 Binary files a/pkg/u8g2/patches/0001-u8g2-add-RIOT-makefiles.patch and /dev/null differ diff --git a/pkg/u8g2/patches/0002-add-RIOT-interface.patch b/pkg/u8g2/patches/0002-add-RIOT-interface.patch deleted file mode 100644 index dcca03af4ce2d5818e26c9237222876be066aa78..0000000000000000000000000000000000000000 Binary files a/pkg/u8g2/patches/0002-add-RIOT-interface.patch and /dev/null differ diff --git a/pkg/u8g2/patches/0003-Change-conflicting-module-name-for-pkg-root-director.patch b/pkg/u8g2/patches/0003-Change-conflicting-module-name-for-pkg-root-director.patch deleted file mode 100644 index 29af20dbaba93cb361d2348847dae201be7b1d46..0000000000000000000000000000000000000000 Binary files a/pkg/u8g2/patches/0003-Change-conflicting-module-name-for-pkg-root-director.patch and /dev/null differ diff --git a/pkg/u8g2/src/Makefile b/pkg/u8g2/src/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..419ebdb198ded71e26349e236ffeae27bb96ddaf --- /dev/null +++ b/pkg/u8g2/src/Makefile @@ -0,0 +1,24 @@ +MODULE = pkg-u8g2 + +DIRS += csrc + +# SDL can be used as a virtual display, but is for native target only. +ifneq (,$(filter u8g2_sdl,$(USEMODULE))) + DIRS += sys/sdl/common +endif + +# UTF8 virtual display is not part of core. Therefore it is a separate module. +ifneq (,$(filter u8g2_utf8,$(USEMODULE))) + DIRS += sys/utf8/common +endif + +# Compiling U8g2 will generate a lot of compiler warnings, which are treated +# as errors. For the sake of simplicity, ignore them. +CFLAGS += -Wno-empty-translation-unit \ + -Wno-newline-eof \ + -Wno-unused-parameter \ + -Wno-unused \ + -Wno-overlength-strings \ + -Wno-pointer-arith + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/u8g2/src/csrc/Makefile b/pkg/u8g2/src/csrc/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1023a87a81565981136fc126695957ffeeb6a851 --- /dev/null +++ b/pkg/u8g2/src/csrc/Makefile @@ -0,0 +1,3 @@ +MODULE = u8g2 + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/u8g2/src/csrc/u8g2_riotos.c b/pkg/u8g2/src/csrc/u8g2_riotos.c new file mode 100644 index 0000000000000000000000000000000000000000..7c4245536da70fd1b69dcd42fe3779a10b34b75c --- /dev/null +++ b/pkg/u8g2/src/csrc/u8g2_riotos.c @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2016-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 pkg_u8g2 + * @{ + * + * @file + * @brief U8g2 driver for interacting with RIOT-OS drivers + * + * @author Bas Stottelaar <basstottelaar@gmail.com> + * + * @} + */ + +#include <stdio.h> +#include <string.h> + +#include "u8g2.h" + +#include "xtimer.h" +#include "periph/spi.h" +#include "periph/i2c.h" +#include "periph/gpio.h" + +#ifdef SPI_NUMOF +static spi_clk_t u8x8_pulse_width_to_spi_speed(uint32_t pulse_width) +{ + uint32_t cycle_time = 2 * pulse_width; + + if (cycle_time < 100) { + return SPI_CLK_10MHZ; + } else if (cycle_time < 200) { + return SPI_CLK_5MHZ; + } else if (cycle_time < 1000) { + return SPI_CLK_1MHZ; + } else if (cycle_time < 2500) { + return SPI_CLK_400KHZ; + } + + return SPI_CLK_100KHZ; +} +#endif /* SPI_NUMOF */ + +#ifdef SPI_NUMOF +static spi_mode_t u8x8_spi_mode_to_spi_conf(uint32_t spi_mode) +{ + return (spi_mode_t) spi_mode; +} +#endif /* SPI_NUMOF */ + +static void u8x8_enable_pins(gpio_t* pins, uint32_t pins_enabled) +{ + uint8_t i; + + for (i = 0; i < 32; i++) { + if (pins_enabled & (1 << i)) { + if (pins[i] != GPIO_UNDEF) { + if (i < U8X8_PIN_OUTPUT_CNT) { + gpio_init(pins[i], GPIO_OUT); + } else { + gpio_init(pins[i], GPIO_IN); + } + } + } + } +} + +uint8_t u8x8_gpio_and_delay_riotos(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + (void) arg_ptr; + + switch (msg) { + case U8X8_MSG_GPIO_AND_DELAY_INIT: + u8x8_enable_pins(u8g2->pins, u8g2->pins_enabled); + break; + case U8X8_MSG_DELAY_MILLI: + xtimer_usleep(arg_int * 1000); + break; + case U8X8_MSG_DELAY_10MICRO: + xtimer_usleep(arg_int * 10); + break; + case U8X8_MSG_DELAY_100NANO: + xtimer_nanosleep(arg_int * 100); + break; + case U8X8_MSG_GPIO_CS: + if (u8g2->pins_enabled & (1 << U8X8_PIN_CS)) { + gpio_write(u8g2->pins[U8X8_PIN_CS], arg_int); + } + break; + case U8X8_MSG_GPIO_DC: + if (u8g2->pins_enabled & (1 << U8X8_PIN_DC)) { + gpio_write(u8g2->pins[U8X8_PIN_DC], arg_int); + } + break; + case U8X8_MSG_GPIO_RESET: + if (u8g2->pins_enabled & (1 << U8X8_PIN_RESET)) { + gpio_write(u8g2->pins[U8X8_PIN_RESET], arg_int); + } + break; + default: + return 0; + } + + return 1; +} + +#ifdef SPI_NUMOF +uint8_t u8x8_byte_riotos_hw_spi(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + spi_t dev = (spi_t) u8g2->dev; + + switch (msg) { + case U8X8_MSG_BYTE_SEND: + spi_transfer_bytes(dev, GPIO_UNDEF, true, + arg_ptr, NULL, (size_t)arg_int); + break; + case U8X8_MSG_BYTE_INIT: + spi_init_pins(dev); + break; + case U8X8_MSG_BYTE_SET_DC: + u8x8_gpio_SetDC(u8g2, arg_int); + break; + case U8X8_MSG_BYTE_START_TRANSFER: + spi_acquire(dev, GPIO_UNDEF, + u8x8_spi_mode_to_spi_conf(u8g2->display_info->spi_mode), + u8x8_pulse_width_to_spi_speed(u8g2->display_info->sck_pulse_width_ns)); + + u8x8_gpio_SetCS(u8g2, u8g2->display_info->chip_enable_level); + u8g2->gpio_and_delay_cb(u8g2, U8X8_MSG_DELAY_NANO, u8g2->display_info->post_chip_enable_wait_ns, NULL); + break; + case U8X8_MSG_BYTE_END_TRANSFER: + u8g2->gpio_and_delay_cb(u8g2, U8X8_MSG_DELAY_NANO, u8g2->display_info->pre_chip_disable_wait_ns, NULL); + u8x8_gpio_SetCS(u8g2, u8g2->display_info->chip_disable_level); + + spi_release(dev); + break; + default: + return 0; + } + + return 1; +} +#endif /* SPI_NUMOF */ + +#ifdef I2C_NUMOF +uint8_t u8x8_byte_riotos_hw_i2c(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + static uint8_t buffer[255]; + static uint8_t index; + + i2c_t dev = (i2c_t) u8g2->dev; + + switch (msg) { + case U8X8_MSG_BYTE_SEND: + memcpy(&buffer[index], arg_ptr, arg_int); + index += arg_int; + break; + case U8X8_MSG_BYTE_INIT: + i2c_init_master(dev, I2C_SPEED_FAST); + break; + case U8X8_MSG_BYTE_SET_DC: + break; + case U8X8_MSG_BYTE_START_TRANSFER: + i2c_acquire(dev); + index = 0; + break; + case U8X8_MSG_BYTE_END_TRANSFER: + i2c_write_bytes(dev, u8x8_GetI2CAddress(u8g2), buffer, index); + i2c_release(dev); + break; + default: + return 0; + } + + return 1; +} +#endif /* I2C_NUMOF */ diff --git a/pkg/u8g2/src/sys/sdl/common/Makefile b/pkg/u8g2/src/sys/sdl/common/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5d0aed401558143d53d025fb6041304269c24a7f --- /dev/null +++ b/pkg/u8g2/src/sys/sdl/common/Makefile @@ -0,0 +1,5 @@ +MODULE = u8g2_sdl + +CFLAGS += `sdl2-config --cflags` + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/u8g2/src/sys/utf8/common/Makefile b/pkg/u8g2/src/sys/utf8/common/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..32e79133df0d5e1d99a330fa9949c6ee81c57ca2 --- /dev/null +++ b/pkg/u8g2/src/sys/utf8/common/Makefile @@ -0,0 +1,3 @@ +MODULE = u8g2_utf8 + +include $(RIOTBASE)/Makefile.base diff --git a/tests/pkg_u8g2/main.c b/tests/pkg_u8g2/main.c index 4787e441b477af202f9738e6add0b33bd07bfc32..2ffaa2cd256ef6268d82194537c7075c591177d3 100644 --- a/tests/pkg_u8g2/main.c +++ b/tests/pkg_u8g2/main.c @@ -63,6 +63,12 @@ #include <stdio.h> #include "periph/gpio.h" +#if TEST_OUTPUT == TEST_OUTPUT_SPI +#include "periph/spi.h" +#endif +#if TEST_OUTPUT == TEST_OUTPUT_I2C +#include "periph/i2c.h" +#endif #include "xtimer.h" #include "u8g2.h" @@ -143,7 +149,7 @@ int main(void) TEST_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_spi, u8x8_gpio_and_delay_riotos); u8g2_SetPins(&u8g2, pins, pins_enabled); - u8g2_SetDevice(&u8g2, TEST_SPI); + u8g2_SetDevice(&u8g2, SPI_DEV(TEST_SPI)); #endif /* initialize to I2C */ @@ -153,7 +159,7 @@ int main(void) TEST_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_i2c, u8x8_gpio_and_delay_riotos); u8g2_SetPins(&u8g2, pins, pins_enabled); - u8g2_SetDevice(&u8g2, TEST_I2C); + u8g2_SetDevice(&u8g2, I2C_DEV(TEST_I2C)); u8g2_SetI2CAddress(&u8g2, TEST_ADDR); #endif @@ -166,21 +172,23 @@ int main(void) /* start drawing in a loop */ puts("Drawing on screen."); - while (true) { + while (1) { 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); + switch (screen) { + case 0: + u8g2_DrawStr(&u8g2, 12, 22, "THIS"); + break; + case 1: + u8g2_DrawStr(&u8g2, 24, 22, "IS"); + break; + case 2: + u8g2_DrawBitmap(&u8g2, 0, 0, 8, 32, logo); + break; } } while (u8g2_NextPage(&u8g2)); @@ -189,6 +197,11 @@ int main(void) utf8_show(); #endif +#if TEST_OUTPUT == TEST_OUTPUT_SDL + /* handle SDL events */ + u8g_sdl_get_key(); +#endif + /* show screen in next iteration */ screen = (screen + 1) % 3; diff --git a/tests/pkg_u8g2/tests/01-run.py b/tests/pkg_u8g2/tests/01-run.py index 0f092935e29b21b5d349329eb3dbacc79e78f41c..9956628ab1f4952804995a226b0de4afceeb2bd1 100755 --- a/tests/pkg_u8g2/tests/01-run.py +++ b/tests/pkg_u8g2/tests/01-run.py @@ -10,54 +10,108 @@ import os import sys EXPECTED_STDOUT = ( - '00| |', - '02| |', - '04| |', - '06| |', - '08| |', - '10| █████â–â–‹ â–â–‹â–â–‹ ▟██▖ |', - '12| â–ˆ â–â–‹ â–â–‹â–â–‹â–â–› â–â–ˆ |', - '14| â–ˆ â–████▋â–â–‹â–█▙▄ |', - '16| â–ˆ â–â–‹ â–â–‹â–â–‹ ▀▜▙ |', - '18| â–ˆ â–â–‹ â–â–‹â–â–‹â–â–™ â–—â–ˆ |', - '20| â–ˆ â–â–‹ â–â–‹â–â–‹ ▜██▘ |', - '22| |', - '24| |', - '26| |', - '28| |', - '30| |', - '00| |', - '02| |', - '04| |', - '06| |', - '08| |', - '10| â–â–‹ ▟██▖ |', - '12| â–â–‹â–â–› â–â–ˆ |', - '14| â–â–‹â–█▙▄ |', - '16| â–â–‹ ▀▜▙ |', - '18| â–â–‹â–â–™ â–—â–ˆ |', - '20| â–â–‹ ▜██▘ |', - '22| |', - '24| |', - '26| |', - '28| |', - '30| |', - '00| â–„â–„â–– |', - '02| ▗████▋ |', - '04| ▗█▛▘ ▜█▖ |', - '06| â–â–ˆ █▋ |', - '08| ██ █▋ |', - '10| ██ ▟█▘ |', - '12| ▜█ ▄▟█▛ â–„ â–„â–„ â–„â–„â–„â–„ |', - '14| ▗▄█▖â–â–ˆâ–██▀ █▋ ▟▛▜▙ ▀▜▛▀ |', - '16| ▗██▀ â–â–ˆ ■█▋ █▋ â–ˆ â–â–‹ |', - '18| â–Ÿâ–› â–â–ˆ â–„ █▋ █▋ â–ˆ â–â–‹ |', - '20| █▋ â–â–ˆ â–█▋ █▋ █▋ â–ˆ â–â–‹ |', - '22| █▋ â–â–ˆ ▜█ █▋ █▋ â–ˆ â–â–‹ |', - '24| █▙ ▗█▛ â–█▙ █▋ █▋▗█ â–â–‹ |', - '26| â–█▙▄██▘ ▜█ █▘ â–██▘ â–â–‹ |', - '28| â–▜█▀▘ |', - '30| |', + '00| |', + '02| |', + '04| |', + '06| |', + '08| |', + '10| █████â–â–‹ â–â–‹â–â–‹ ▟██▖ |', + '12| â–ˆ â–â–‹ â–â–‹â–â–‹â–â–› â–â–ˆ |', + '14| â–ˆ â–████▋â–â–‹â–█▙▄ |', + '16| â–ˆ â–â–‹ â–â–‹â–â–‹ ▀▜▙ |', + '18| â–ˆ â–â–‹ â–â–‹â–â–‹â–â–™ â–—â–ˆ |', + '20| â–ˆ â–â–‹ â–â–‹â–â–‹ ▜██▘ |', + '22| |', + '24| |', + '26| |', + '28| |', + '30| |', + '32| |', + '34| |', + '36| |', + '38| |', + '40| |', + '42| |', + '44| |', + '46| |', + '48| |', + '50| |', + '52| |', + '54| |', + '56| |', + '58| |', + '60| |', + '62| |', + '64| |', + '66| |', + '00| |', + '02| |', + '04| |', + '06| |', + '08| |', + '10| â–â–‹ ▟██▖ |', + '12| â–â–‹â–â–› â–â–ˆ |', + '14| â–â–‹â–█▙▄ |', + '16| â–â–‹ ▀▜▙ |', + '18| â–â–‹â–â–™ â–—â–ˆ |', + '20| â–â–‹ ▜██▘ |', + '22| |', + '24| |', + '26| |', + '28| |', + '30| |', + '32| |', + '34| |', + '36| |', + '38| |', + '40| |', + '42| |', + '44| |', + '46| |', + '48| |', + '50| |', + '52| |', + '54| |', + '56| |', + '58| |', + '60| |', + '62| |', + '64| |', + '66| |', + '00| â–„â–„â–– |', + '02| ▗████▋ |', + '04| ▗█▛▘ ▜█▖ |', + '06| â–â–ˆ █▋ |', + '08| ██ █▋ |', + '10| ██ ▟█▘ |', + '12| ▜█ ▄▟█▛ â–„ â–„â–„ â–„â–„â–„â–„ |', + '14| ▗▄█▖â–â–ˆâ–██▀ █▋ ▟▛▜▙ ▀▜▛▀ |', + '16| ▗██▀ â–â–ˆ ■█▋ █▋ â–ˆ â–â–‹ |', + '18| â–Ÿâ–› â–â–ˆ â–„ █▋ █▋ â–ˆ â–â–‹ |', + '20| █▋ â–â–ˆ â–█▋ █▋ █▋ â–ˆ â–â–‹ |', + '22| █▋ â–â–ˆ ▜█ █▋ █▋ â–ˆ â–â–‹ |', + '24| █▙ ▗█▛ â–█▙ █▋ █▋▗█ â–â–‹ |', + '26| â–█▙▄██▘ ▜█ █▘ â–██▘ â–â–‹ |', + '28| â–▜█▀▘ |', + '30| |', + '32| |', + '34| |', + '36| |', + '38| |', + '40| |', + '42| |', + '44| |', + '46| |', + '48| |', + '50| |', + '52| |', + '54| |', + '56| |', + '58| |', + '60| |', + '62| |', + '64| |', + '66| |', )