Skip to content
Han Wu edited this page Sep 22, 2023 · 17 revisions

U8g2 on ARM Linux

Todo List

[●] Hardware I2C
[●] Hardware SPI
[●] Software I2C
[●] Software SPI
[●] 8080 mode
[●] Add C++ wrapper
[●] Faster GPIO by tracking fd
[●] Better build system
[●] Upstream the port
[●] Replace sysfs with gpiod
[  ] Benchmark

Software I2C

[1] Linux Kernel

Select following options:

--> Device Drivers
    --> I2C Support
        <*> I2C device interface
        I2C Hardware Bus support  --->
            <*> GPIO-based bitbanging I2C

[2] Modify device tree: (eg: arch/csky/boot/dts/gx6605s.dts)

#include <dt-bindings/gpio/gpio.h>
i2c@0 {
    compatible = "i2c-gpio";
    sda-gpios = <&gpio0 14 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
    scl-gpios = <&gpio0 15 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
    i2c-gpio,delay-us = <2>;        /* ~100 kHz */
    #address-cells = <1>;
    #size-cells = <0>;
};

[3] Make sure i2c devices are available

$ls /dev/i2c-*

Hardware I2C

[1] Linux Kernel

Select following options:

--> Device Drivers
    --> I2C Support
        <*> I2C device interface

[2] Modify device tree: (eg: arch/csky/boot/dts/gx6605s.dts)

&i2c0 {
    pinctrl-0 = <&i2c0_pins>;
    pinctrl-names = "default";
    status = "okay";
};

[3] Make sure i2c devices are accessible

$ls /dev/i2c-*

Software SPI

Coming Soon

Hardware SPI

Coming Soon

How to compile

First, clone this repo:

$ git clone --recursive https://github.com/wuhanstudio/u8g2-arm-linux.git
$ cd u8g2-arm-linux

Change cross-compiler in according to your board.

# Chosse proper compiler for your PI
# NanoPi:             arm-linux-gnueabi-gcc
# Raspberry Pi Zero:  arm-none-linux-gnueabi-gcc

# Raspberry Pi 2:     arm-linux-gnueabihf-gcc
# OrangePi Zero:      arm-linux-gnueabihf-gcc
# NanoPi NEO:         arm-linux-gnueabihf-gcc
# NanoPi NEO Plus 2:  arm-linux-gnueabihf-gcc
# C-SKY:              csky-linux-gcc

CC = arm-linux-gnueabihf-gcc

For example:

arm-none-linux-gnueabi-gcc   for armv6  
arm-none-linux-gnueabihf-gcc for armv7

For native-compile (compile on your board), simply use:

CC = gcc

Finally, time to compile:

# Build source with GPIO character device
$ make CPPFLAGS=-DPERIPHERY_GPIO_CDEV_SUPPORT=1 CC=gcc CXX=g++

# Build source with GPIO sysfs (legacy)
$ make CC=gcc CXX=g++

Run Examples

Before running, you can check your I2C devices using i2c-tools:

$ sudo apt-get install i2c-tools

List your devices:

$ ls /dev/i2c*
/dev/i2c-0  /dev/i2c-1

Probe your devices on bus 1:

$ i2cdetect -y -r 1

Now, execute:

$ sudo ./bin/u8g2_hw_i2c

Related Projects

Contact