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

Conversation

basilfx
Copy link
Member

@basilfx basilfx commented Jun 14, 2016

This PR adds support for U8g2, the successor of U8glib. It replaces PR #5126.

The main advantages (so far):

  • Better architecture of library.
  • Less patches needed.
  • Interface is more generic (and if too generic, it can be replaced easily).

I'm currently testing it, so there is some work in progress and needs testing on other platforms/compilers. Furthermore, U8g2 is still under development.

@basilfx
Copy link
Member Author

basilfx commented Jun 14, 2016

Some screenshots and photos of the displays I tested so far (the test application is designed for 64x32 screens).

TEST_U8G2_OUTPUT=1 to virtual stdout display:
stdout

TEST_U8G2_OUTPUT=2 to virtual SDL display:
sdl

TEST_U8G2_OUTPUT=3 using a SSD1306 SPI display:
ssd1306_spi

TEST_U8G2_OUTPUT=3 using a LS013B7DH03 SPI display (driver contributed to U8g2):
ls013b7dh03

TEST_U8G2_OUTPUT=4 using a SSD1306 I2C display:
ssd1306_i2c

To conclude, I am working on a Game-of-Life application, for fun:
gol

@aabadie
Copy link
Contributor

aabadie commented Jun 14, 2016

Awesome !
I have 2 of theses modules (SSD1306, I2C and SPI, but we never know with those chinese things...), I'll give it a try again.
What kind of board did you use with your tests ?

@basilfx
Copy link
Member Author

basilfx commented Jun 14, 2016

I used the EFM32 based STK3600 and SLSTK3401A (includes low-power memory LCD).

There exist several versions of the SSD1306. Be sure to pick the right one. Also check the Makefile + README.md for more information on how to setup the display.

@aabadie aabadie added Type: new feature The issue requests / The PR implemements a new feature for RIOT State: archived State: The PR has been archived for possible future re-adaptation Area: pkg Area: External package ports and removed State: archived State: The PR has been archived for possible future re-adaptation labels Jun 16, 2016
@aabadie aabadie self-assigned this Jun 16, 2016
## API
This package patches the original source to add an interface for RIOT-OS peripherals and removing most of the device/platform specific code.

The following two interfaces add add support for the included drivers via I2C and SPI peripherals:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"two interfaces add support " (extra add)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out I forgot to update this file, It was still for U8g. Fixed it.

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

@basilfx, with a bit of luck (and tries), I could make this PR work with an I2C ssd1306 based module. The README is well explained.
Here is the command I issue (the I2C address may change depending on the module):

$ make BOARD=samr21-xpro TEST_U8G2_DISPLAY=u8g2_Setup_ssd1306_i2c_128x64_noname_1 TEST_U8G2_OUTPUT=4 TEST_U8G2_I2C=0 TEST_U8G2_ADDR=0x3C clean flash term

Result:
img_20160622_170543

Good job !

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

Default output to stdout works as well (using TEST_U8G2_OUTPUT=0).

@basilfx, can you fix the inline comments, so I can give this PR an ACK ?

@basilfx basilfx force-pushed the feature/pkg_u8g2 branch from eeec1f2 to 7866ef7 Compare June 22, 2016 16:39
@basilfx
Copy link
Member Author

basilfx commented Jun 22, 2016

I fixed the comments, updated the package and tested it again. Can you also take a quick look?

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

I wanted to test the SDL display with native but it doesn't compile although I have libSDL (1 and 2) installed on my Linux (Ubuntu 16.04). Any idea why ?

@basilfx
Copy link
Member Author

basilfx commented Jun 22, 2016

Does this work for you? Although I am on macOS, the first two should work:

basilfx:~/ $ sdl-config --libs
-L/opt/homebrew/lib -lSDLmain -lSDL -Wl,-framework,Cocoa

basilfx:~/ $ sdl-config --cflags
-I/opt/homebrew/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE

basilfx:~/ $ brew list sdl
/opt/homebrew/Cellar/sdl/1.2.15/bin/sdl-config
/opt/homebrew/Cellar/sdl/1.2.15/include/SDL/ (32 files)
/opt/homebrew/Cellar/sdl/1.2.15/lib/libSDL-1.2.0.dylib
/opt/homebrew/Cellar/sdl/1.2.15/lib/pkgconfig/sdl.pc
/opt/homebrew/Cellar/sdl/1.2.15/lib/ (3 other files)
/opt/homebrew/Cellar/sdl/1.2.15/libexec/SDLMain.nib/ (3 files)
/opt/homebrew/Cellar/sdl/1.2.15/libexec/ (4 files)
/opt/homebrew/Cellar/sdl/1.2.15/share/aclocal/sdl.m4
/opt/homebrew/Cellar/sdl/1.2.15/share/man/ (174 files)

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

I tried the 2 ones:

$ sdl-config --libs
-L/usr/lib/x86_64-linux-gnu -lSDL
$ sdl-config --cflags
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT

Which are the expected values : I could build a simple SDL example.

When building the SDL for native RIOT, I have other strange messages:

/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libdl.so when searching for -ldl
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libdl.a when searching for -ldl
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libSDL.so when searching for -lSDL
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libSDL.a when searching for -lSDL
/usr/bin/ld: cannot find -lSDL
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
collect2: error: ld returned 1 exit status

@basilfx
Copy link
Member Author

basilfx commented Jun 22, 2016

Ah I think that it has to do with RIOT-OS building a 32-bit binary while your SDL is 64-bit.

I'll look into that, otherwise it will be a limitation that I will document.

Edit: maybe try this: http://askubuntu.com/questions/510419/i-can-i-install-a-32-bit-version-of-libsdl1-2debian-on-a-64-bit-machine

@basilfx
Copy link
Member Author

basilfx commented Jun 22, 2016

I improved the comments a bit more, regarding SDL.

I also tried git format-path -n sha1 --unified=0 but it generates patches with too little context. In other words, the patch cannot be applied. I now used git format-patch -n sha1 --minimal, which should produce the smallest patch possible (according to the docs).

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

I now used git format-patch -n sha1 --minimal, which should produce the smallest patch possible (according to the docs).

Good to know. I was a bit optimistic with the --unified=0 option.

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

Another question: is it supposed to work when running RIOT in native and displaying in stdout (make term BOARD=native) ?

@basilfx
Copy link
Member Author

basilfx commented Jun 22, 2016

That should work. It should produce the output equal to the first display.

Characters are printed to stdout.

@aabadie
Copy link
Contributor

aabadie commented Jun 22, 2016

The stdout display was not working for me in native, I had to install missing 32bit libraries:

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6-dbg:i386

to make it work.

For SDL:

sudo apt-get install libsdl1.2debian:i386

but the it still doesn't work for me. I had to:

  • manually add:
    LINKGLAGS += -L/usr/lib/i386-linux-gnu/,
  • create a link to the installed library:
sudo apt-get install libc6-dbg:i386
  • and finally the program crashes at startup but gdb doesn't point to any RIOT code. I guess it's my setup which is wrong.

@aabadie
Copy link
Contributor

aabadie commented Jun 23, 2016

@basilfx, for SDL, the problem comes from sdl-config --libs that returns the path for the 64 bit version.
But that's a minor problem and you mentionned it in the README.
BTW, I'd like to push a bit more my tests with other modules (e.g SPI) before giving an ACK.

@basilfx
Copy link
Member Author

basilfx commented Jun 23, 2016

Sure, no problem!

For the showcase (and to prove that SPI works :-P) I created my own 'weather station' :-)

img_3329

@aabadie
Copy link
Contributor

aabadie commented Jun 23, 2016

For the showcase (and to prove that SPI works :-P) I created my own 'weather station' :-)

Neat :)

@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 12, 2016
@aabadie
Copy link
Contributor

aabadie commented Jul 12, 2016

ACK

@kYc0o
Copy link
Contributor

kYc0o commented Jul 12, 2016

Murdock is failing. Please add the boards that don't have enough memory to your tests as BOARD_INSUFFICIENT_MEMORY and/or BOARD_BLACKLIST.

@OlegHahm
Copy link
Member

Anyone wants to revive #1681 ? 😉

@basilfx
Copy link
Member Author

basilfx commented Jul 12, 2016

I'll fix this tonight.

@basilfx
Copy link
Member Author

basilfx commented Jul 12, 2016

I could simply blacklist arduino-mega2560, waspmote-pro, telosb, wsn430-v1_3b, wsn430-v1_4 and z1, but that does not feel right.

U8g2 (and U8glib) was designed for Arduino platforms, so it is strange that arduino-mega2560 and waspmote-pro fail. If I manually change the Makefile to add -Wl,--gc-sections (they are missing) to the linker, it compiles fine with a resulting file of 20KB (GCC 4.9). The Arduino IDE does the same, so is it a bug that these flags are missing?

I don't have a working MSP-430 compiler, but I presume it has a similar problem.

@kYc0o
Copy link
Contributor

kYc0o commented Jul 12, 2016

Hmmm... in the results we have:

/usr/lib/gcc/avr/4.8.1/../../../avr/bin/ld: region `text' overflowed by 739666 bytes

for arduino-mega2560 and

/usr/lib/gcc/avr/4.8.1/../../../avr/bin/ld: region `text' overflowed by 1656816 bytes

which are actually impossible...

Can you try to rebase and see what happen?

@basilfx
Copy link
Member Author

basilfx commented Jul 12, 2016

I did.

After rebase, without 'fix':

basilfx:pkg_u8g2/ (feature/pkg_u8g2) $ BOARD=arduino-mega2560 make
Building application "pkg_u8g2" for "arduino-mega2560" with MCU "atmega2560".

"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/pkg/u8g2
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/pkg/arduino-mega2560/u8g2
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/pkg/arduino-mega2560/u8g2/csrc
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/pkg/arduino-mega2560/u8g2/sys/utf8/common
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/boards/arduino-mega2560
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/core
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/cpu/atmega2560
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/cpu/atmega_common
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/cpu/atmega_common/periph
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/drivers
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/auto_init
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/tsrb
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/uart_stdio
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/xtimer
/opt/homebrew/opt/avr-binutils/bin/avr-ld: /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/arduino-mega2560/pkg_u8g2.elf section `.text' will not fit in region `text'
/opt/homebrew/opt/avr-binutils/bin/avr-ld: region `text' overflowed by 739852 bytes
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

After rebase, with 'fix'

basilfx:pkg_u8g2/ (feature/pkg_u8g2) $ BOARD=arduino-mega2560 make
Building application "pkg_u8g2" for "arduino-mega2560" with MCU "atmega2560".

"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/pkg/u8g2
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/pkg/arduino-mega2560/u8g2
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/pkg/arduino-mega2560/u8g2/csrc
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/pkg/arduino-mega2560/u8g2/sys/utf8/common
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/boards/arduino-mega2560
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/core
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/cpu/atmega2560
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/cpu/atmega_common
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/cpu/atmega_common/periph
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/drivers
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/auto_init
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/tsrb
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/uart_stdio
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -C /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/sys/xtimer
   text    data     bss     dec     hex filename
  16224     650    2361   19235    4b23 /Users/basilfx/Desktop/RIOT_Dev/RIOT_U8g2/tests/pkg_u8g2/bin/arduino-mega2560/pkg_u8g2.elf

Fix:

diff --git a/boards/arduino-mega2560/Makefile.include b/boards/arduino-mega2560/Makefile.include
index de5461b..c9f6ad5 100644
--- a/boards/arduino-mega2560/Makefile.include
+++ b/boards/arduino-mega2560/Makefile.include
@@ -41,6 +41,6 @@ export CFLAGS_OPT  ?= -Os

 export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
 export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
-export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -e reset_handler
+export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections -static -lgcc -e reset_handler
 export OFLAGS += -j .text -j .data -O ihex
 export FFLAGS += -p m2560 -c $(PROGRAMMER) $(PROGRAMMER_FLAGS) -F -D -U flash:w:bin/$(BOARD)/$(PROJECT)$(APPLICATION).hex

@basilfx basilfx force-pushed the feature/pkg_u8g2 branch from b19a85b to b27171d Compare July 12, 2016 23:11
@kYc0o
Copy link
Contributor

kYc0o commented Jul 12, 2016

What it means 'fix' ?

@basilfx
Copy link
Member Author

basilfx commented Jul 12, 2016

Adding -Wl,--gc-sections to the linker options of the Atmega 2560 Makefile. I updated my comment above with the diff of the fix.

This option is what the Arduino IDE also uses, but what is missing in the Makefile.

@OlegHahm
Copy link
Member

Looks sensible. Can you open a PR for that?

@kYc0o
Copy link
Contributor

kYc0o commented Jul 13, 2016

Can you rebase this one since #5632 was merged?

@kYc0o kYc0o added this to the Release 2016.07 milestone Jul 13, 2016
@basilfx basilfx force-pushed the feature/pkg_u8g2 branch from b27171d to 9516568 Compare July 13, 2016 19:23
@basilfx
Copy link
Member Author

basilfx commented Jul 13, 2016

Rebased. I have blacklisted the other failing boards for now.

@OlegHahm I did a quick try to revive #1681, but it will be difficult :-)

schermafbeelding 2016-07-13 om 02 01 41

@basilfx basilfx force-pushed the feature/pkg_u8g2 branch from 9516568 to 7033401 Compare July 13, 2016 20:33
@kaspar030
Copy link
Contributor

@basilfx I got tetris on the console working. Check out #5638.

@kYc0o
Copy link
Contributor

kYc0o commented Jul 14, 2016

So since @aabadie already ACKed, Murdock is green and the RIOT tetris game was revived, lets merge this one!

@kYc0o kYc0o merged commit 6d9c927 into RIOT-OS:master Jul 14, 2016
@basilfx basilfx mentioned this pull request Jul 26, 2016
@basilfx basilfx deleted the feature/pkg_u8g2 branch July 30, 2016 17:06
@aabadie aabadie added this to the Release 2016.10 milestone Oct 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants