U8G2 is a monochrome graphics library for LCDs and OLEDs. It contains both drivers and high-level drawing routines. The library is originally written for Arduino boards, but it runs just fine on other platforms, as long as the right drivers are available.
For a complete list of supported displays, check the u8g2 documentation: https://github.com/olikraus/u8g2/wiki/u8g2setupc#setup-function-reference
You can use the package directly via its API (see this section), or via the integration to Display device generic API (see this section)
RIOT's Display device generic API abstracts different display drivers and provides simplified access to them. This package is integrated to it, meaning that all drivers provided by U8G2 can be used via this generic interface. This integration is particularly useful to use monochrome drivers with higher-level graphics libraries, such as the LVGL - Open-Source Embedded GUI Library package. For details on how to use the generic API, check Display device generic API. The integration is provided by the module Display device generic API implementation for U8G2. It will provide default configurations, as well as auto-initialization.
By default, the parameters defined in Default configuration for U8G2 displays are used to initialize displays. The following examples show you how to configure a display for I2C or SPI via the application's makefile. You can also override these parameters in a header file of your board or application.
Let's say you have an I2C monochrome display with the 1306 controller, and you want to use it with the generic display interface.
Add the following to your application's Makefile:
U8G2 supports both I2C and SPI to communicate with displays, so it will not automatically pull any peripheral dependency. Therefore, you need to additionally add the corresponding feature to the application's Makefile:
You'll need to configure the I2C device (bus), to which the display is connected on your board, the I2C address, and the initialization function. To determine the initialization function, refer to the setup documentation of the package: https://github.com/olikraus/u8g2/wiki/u8g2setupc#setup-function-reference. You can set these values in your Makefile, for example:
Let's say you have an SPI monochrome display with the 1306 controller, and you want to use it with the generic display interface.
Add the following to your application's Makefile:
U8G2 supports both I2C and SPI to communicate with displays, so it will not automatically pull any peripheral dependency. Therefore, you need to additionally add the corresponding feature to the application's Makefile:
You'll need to configure the SPI device (bus), to which the display is connected on your board, set the I2C address to 0 (indicates that this is an SPI connection), and the initialization function. To determine the initialization function, refer to the setup documentation of the package: https://github.com/olikraus/u8g2/wiki/u8g2setupc#setup-function-reference. You can set these values in your Makefile, for example:
If you prefer to use the package directly, you first need to add it to your application's Makefile:
Then, add the header in your code: #include "u8g2.h"
. Refer to the U8g2 wiki for more information on the API.
The following two callbacks add support for the included drivers via I2C and SPI peripherals:
u8x8_byte_hw_spi_riotos
u8x8_byte_hw_i2c_riotos
For timing and GPIO related operations, the following callback is available.
u8x8_gpio_and_delay_riotos
These methods require a structure containing peripheral information (u8x8_riotos_t
), that is set using the u8g2_SetUserPtr
function. This structure contains the peripheral and pin mapping.
If the above interface is not sufficient, it is still possible to write a dedicated interface by (re-)implementing the methods above. Refer to the U8g2 wiki for more information.
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.
Here's an example on how you would use the UTF-8 display:
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. Using SDL requires more stack so in case you are using it add the following to your Makefile:
48kB is enough for the test application in RIOT, other uses may need more or may need this to be applied to other threads using THREAD_STACKSIZE_DEFAULT
.
Topics | |
Display device generic API implementation for U8G2 | |
Implementation of display device generic API for U8G2 monochrome displays. | |
Files | |
file | u8x8_riotos.h |
U8g2 driver for interacting with RIOT-OS peripherals. | |