diff --git a/pkg/u8g2/Makefile b/pkg/u8g2/Makefile index 24a7ef75c4..16217dafde 100644 --- a/pkg/u8g2/Makefile +++ b/pkg/u8g2/Makefile @@ -1,6 +1,6 @@ PKG_NAME=u8g2 PKG_URL=https://github.com/olikraus/u8g2 -PKG_VERSION=94dacdb84e06a6088b9d17a1e7ba009dbd3618be +PKG_VERSION=4c7ecf099e766b9c678d3453d6b932c8290bdb6b .PHONY: all diff --git a/pkg/u8g2/README.md b/pkg/u8g2/README.md index 27fd426e30..ee1ba87ccd 100644 --- a/pkg/u8g2/README.md +++ b/pkg/u8g2/README.md @@ -3,26 +3,61 @@ ## Introduction [U8g2](https://github.com/olikraus/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's, but it runs fine on other platforms if the right drivers are available. +The library is originally written for Arduino boards, but it runs just fine on other platforms, as long as the right drivers are available. ## Usage -Just put `USEPKG += u8g2` in your Makefile and `#include "u8g.h"` to your code. +Just put `USEPKG += u8g2` in your Makefile and `#include "u8g2.h"` to your code. Refer to the [U8g2 wiki](https://github.com/olikraus/u8g2/wiki) for more information on the API. -## API -This package patches the original source to add an interface for RIOT-OS peripherals and removing most of the device/platform specific code. +## RIOT-OS interface +This package patches the original source to add an interface for RIOT-OS. -The following two interfaces add add support for the included drivers via I2C and SPI peripherals: +The following two callbacks add support for the included drivers via I2C and SPI peripherals: -* `u8g_com_riotos_hw_spi_init` — Interface for U8g2 included SPI displays. -* `u8g_com_riotos_ssd_i2c_init` — Interface for U8g2 included I2C SSD displays. +* `u8x8_byte_riotos_hw_spi` +* `u8x8_byte_riotos_hw_i2c` -In addition, the following three drivers are general-purpose interfaces to write your own display driver: +For timing and GPIO related operations, the following callback is available. -* `u8g_com_riotos_i2c_init` — Generic I2C display driver interface. -* `u8g_com_riotos_spi_init` — Generic SPI display driver interface. -* `u8g_com_riotos_init` — General-purpose interface that accepts a void pointer argument. +* `u8x8_gpio_and_delay_riotos` -For targets without an I2C or SPI, the following two interfaces emulate a display: +U8g2 needs to map pin numbers to RIOT-OS pin numbers. It also needs to know which peripheral to use. The following two methods can be used to set this information. -* `u8g_dev_riotos_stdout_init` — Virtual display via stdout. -* `u8g_dev_riotos_stdout_ansi_init` — Virtual display via stdout using ANSI control characters. +* `u8g2_SetPins(u8g2_dev, pins, bitmap)` +* `u8g2_SetDevice(u8g2_dev, dev)` + +Note: `pins` should point to `gpio_t` array of U8g2 pin numbers to RIOT-OS pins. Due to this, `pins` can take up an additional 100 bytes, because it will use memory for the pins you do not map. You can overcome this limitation by implementing `u8x8_gpio_and_delay_riotos` yourself and hardcode the pins. + +### Example +``` +u8g2_t u8g2; + +gpio_t pins[] = { + [U8X8_PIN_CS] = GPIO(PA, 0), + [U8X8_PIN_DC] = GPIO(PA, 1), + [U8X8_PIN_RESET] = GPIO(PA, 2) +}; + +uint32_t bitmap = ( + (1 << U8X8_PIN_CS) + + (1 << U8X8_PIN_DC) + + (1 << U8X8_PIN_RESET) +); + +u8g2_Setup_ssd1306_128x64_noname_1(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_spi, u8x8_gpio_and_delay_riotos); + +u8g2_SetPins(&u8g2, pins, bitmap); +u8g2_SetDevice(&u8g2, SPI_0); +``` + +## Virtual displays +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. +* By adding `USEMODULE += u8g2_sdl`, a SDL virtual display will be used. This is only available on native targets that have SDL installed. + +### Example +``` +u8g2_t u8g2; + +u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0); +``` diff --git a/pkg/u8g2/patches/0001-u8g2-add-riot-os-makefiles.patch b/pkg/u8g2/patches/0001-u8g2-add-riot-os-makefiles.patch index c7a4a41e36..ffb942614f 100644 --- a/pkg/u8g2/patches/0001-u8g2-add-riot-os-makefiles.patch +++ b/pkg/u8g2/patches/0001-u8g2-add-riot-os-makefiles.patch @@ -1,4 +1,4 @@ -From e074858e002cd96e86d7400e377897e6b646bbd5 Mon Sep 17 00:00:00 2001 +From 96295dd6b68eee06e736ccf84b3225682a912230 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Tue, 24 May 2016 20:17:39 +0200 Subject: [PATCH 1/2] u8g2: add riot-os makefiles. diff --git a/pkg/u8g2/patches/0002-u8g2-add-riot-os-interface.patch b/pkg/u8g2/patches/0002-u8g2-add-riot-os-interface.patch index 11e3bc2744..3e0b649f1b 100644 --- a/pkg/u8g2/patches/0002-u8g2-add-riot-os-interface.patch +++ b/pkg/u8g2/patches/0002-u8g2-add-riot-os-interface.patch @@ -1,17 +1,37 @@ -From 4f00ec2e28975b6fddbf82e5bfe9a86647aa6c58 Mon Sep 17 00:00:00 2001 +From 454b1b8fd9732642a74d1269b74a569e418ae9db Mon Sep 17 00:00:00 2001 From: Bas Stottelaar -Date: Sat, 11 Jun 2016 15:54:41 +0200 +Date: Wed, 22 Jun 2016 18:04:31 +0200 Subject: [PATCH 2/2] u8g2: add riot-os interface. --- + csrc/u8g2.h | 4 +- csrc/u8g2_riotos.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++ csrc/u8x8.h | 17 +++++- - 2 files changed, 175 insertions(+), 3 deletions(-) + 3 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 csrc/u8g2_riotos.c +diff --git a/csrc/u8g2.h b/csrc/u8g2.h +index 32a9570..c8cc1de 100644 +--- a/csrc/u8g2.h ++++ b/csrc/u8g2.h +@@ -343,6 +343,9 @@ struct u8g2_struct + #define u8g2_SetMenuDownPin(u8g2, val) u8x8_SetMenuDownPin(u8g2_GetU8x8(u8g2), (val)) + #endif + ++#define u8g2_SetPins(u8x8,pins,pins_enabled) u8x8_SetPins(u8g2_GetU8x8(&u8g2), pins, pins_enabled) ++#define u8g2_SetDevice(u8x8,device) u8x8_SetDevice(u8g2_GetU8x8(&u8g2), device) ++ + /*==========================================*/ + /* u8g2_setup.c */ + +@@ -1441,4 +1444,3 @@ extern const uint8_t u8g2_font_pcsenior_8u[] U8G2_FONT_SECTION("u8g2_font_pcseni + + + #endif +- diff --git a/csrc/u8g2_riotos.c b/csrc/u8g2_riotos.c new file mode 100644 -index 0000000..cf171f9 +index 0000000..4b0f896 --- /dev/null +++ b/csrc/u8g2_riotos.c @@ -0,0 +1,161 @@ @@ -58,7 +78,7 @@ index 0000000..cf171f9 +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) { @@ -115,8 +135,8 @@ index 0000000..cf171f9 + spi_transfer_bytes(dev, (char *) arg_ptr, NULL, arg_int); + break; + case U8X8_MSG_BYTE_INIT: -+ spi_init_master(dev, -+ u8x8_takeover_edge_to_spi_conf(u8g2->display_info->sck_takeover_edge), ++ spi_init_master(dev, ++ u8x8_takeover_edge_to_spi_conf(u8g2->display_info->sck_takeover_edge), + u8x8_pulse_width_to_spi_speed(u8g2->display_info->sck_pulse_width_ns)); + break; + case U8X8_MSG_BYTE_SET_DC: @@ -177,7 +197,7 @@ index 0000000..cf171f9 +} +#endif /* I2C_NUMOF */ diff --git a/csrc/u8x8.h b/csrc/u8x8.h -index 1a8fff9..d3c4022 100644 +index 13050f6..36eeab0 100644 --- a/csrc/u8x8.h +++ b/csrc/u8x8.h @@ -107,6 +107,8 @@ @@ -213,8 +233,8 @@ index 1a8fff9..d3c4022 100644 }; #define u8x8_GetCols(u8x8) ((u8x8)->display_info->tile_width) -@@ -325,6 +331,8 @@ struct u8x8_struct - #define u8x8_SetMenuHomePin(u8x8, val) u8x8_SetPin((u8x8),U8X8_PIN_MENU_HOME,(val)) +@@ -327,6 +333,8 @@ struct u8x8_struct + #define u8x8_SetMenuDownPin(u8x8, val) u8x8_SetPin((u8x8),U8X8_PIN_MENU_DOWN,(val)) #endif +#define u8x8_SetPins(u8x8,pins,pins_enabled) {(u8x8)->pins = (pins); (u8x8)->pins_enabled = (pins_enabled);} @@ -222,7 +242,7 @@ index 1a8fff9..d3c4022 100644 /*==========================================*/ -@@ -777,6 +785,9 @@ extern const uint8_t u8x8_font_pcsenior_u[] U8X8_FONT_SECTION("u8x8_font_pcsenio +@@ -781,6 +789,9 @@ extern const uint8_t u8x8_font_pcsenior_u[] U8X8_FONT_SECTION("u8x8_font_pcsenio /* end font list */