Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg: u8g2: add graphics library #5549

Merged
merged 7 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/u8g2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PKG_NAME=u8g2
PKG_URL=https://github.com/olikraus/u8g2
PKG_VERSION=4c7ecf099e766b9c678d3453d6b932c8290bdb6b

.PHONY: all

all: git-download
"$(MAKE)" -C $(PKG_BUILDDIR)

include $(RIOTBASE)/pkg/pkg.mk
6 changes: 6 additions & 0 deletions pkg/u8g2/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INCLUDES += -I$(BINDIRBASE)/pkg/$(BOARD)/u8g2/csrc

# Link SDL if enabled.
ifneq (,$(filter u8g2_sdl,$(USEMODULE)))
LINKFLAGS += `sdl-config --libs`
endif
63 changes: 63 additions & 0 deletions pkg/u8g2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# U8g2

## 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 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 "u8g2.h"` to your code. Refer to the [U8g2 wiki](https://github.com/olikraus/u8g2/wiki) for more information on the API.

## RIOT-OS interface
This package patches the original source to add an interface for RIOT-OS.

The following two callbacks add support for the included drivers via I2C and SPI peripherals:

* `u8x8_byte_riotos_hw_spi`
* `u8x8_byte_riotos_hw_i2c`

For timing and GPIO related operations, the following callback is available.

* `u8x8_gpio_and_delay_riotos`

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.

* `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, 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.

### Example
```
u8g2_t u8g2;

u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0);
```
76 changes: 76 additions & 0 deletions pkg/u8g2/patches/0001-u8g2-add-riot-os-makefiles.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
From 09dad731ec608609836aae37ab32fbceec8f3eaa Mon Sep 17 00:00:00 2001
From: Bas Stottelaar <basstottelaar@gmail.com>
Date: Tue, 24 May 2016 20:17:39 +0200
Subject: [PATCH 1/2] u8g2: add riot-os makefiles.

---
Makefile | 22 ++++++++++++++++++++++
csrc/Makefile | 3 +++
sys/sdl/common/Makefile | 5 +++++
sys/utf8/common/Makefile | 3 +++
4 files changed, 33 insertions(+)
create mode 100644 Makefile
create mode 100644 csrc/Makefile
create mode 100644 sys/sdl/common/Makefile
create mode 100644 sys/utf8/common/Makefile

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ec64fab
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,22 @@
+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/csrc/Makefile b/csrc/Makefile
new file mode 100644
index 0000000..1023a87
--- /dev/null
+++ b/csrc/Makefile
@@ -0,0 +1,3 @@
+MODULE = u8g2
+
+include $(RIOTBASE)/Makefile.base
diff --git a/sys/sdl/common/Makefile b/sys/sdl/common/Makefile
new file mode 100644
index 0000000..ce8b90b
--- /dev/null
+++ b/sys/sdl/common/Makefile
@@ -0,0 +1,5 @@
+MODULE = u8g2_sdl
+
+CFLAGS += `sdl-config --cflags`
+
+include $(RIOTBASE)/Makefile.base
diff --git a/sys/utf8/common/Makefile b/sys/utf8/common/Makefile
new file mode 100644
index 0000000..32e7913
--- /dev/null
+++ b/sys/utf8/common/Makefile
@@ -0,0 +1,3 @@
+MODULE = u8g2_utf8
+
+include $(RIOTBASE)/Makefile.base
--
2.8.1

Loading