u8g2-copy/sys/arm-linux
servadmin ba8e0f3170 NULL GPIO pin array 2021-11-11 18:42:59 -05:00
..
drivers SPI working 2021-11-03 12:35:17 -04:00
examples Create init user data functions for I2C/SPI HW/SW and optimize SW I2C 2021-11-11 13:43:37 -05:00
port NULL GPIO pin array 2021-11-11 18:42:59 -05:00
tools/codebuild [rt-thread] copy controller list from parent codebuild.c 2021-10-06 21:07:02 +01:00
.gitignore [add] arm-linux cpp support 2021-10-04 22:28:26 +01:00
Makefile [add] arm-linux support 2021-10-04 21:57:19 +01:00
README.md Small fix 2021-11-07 12:23:49 -05:00

README.md

U8g2 for arm-linux has been modified to use c-periphery userspace library.

  • Deprecated sysfs method is no longer used for GPIO thus increasing speed and stability, but you can still use sysfs for legacy kernels.
  • GPIO, I2C and SPI can be closed and unallocated.
  • Overall performance should be better.
  • Run as non-root user.

Non-root access

If you want to access devices without root do the following (you can try udev rules instead if you wish):

  • sudo groupadd u8g2
  • sudo usermod -a -G u8g2 username (Use a non-root username)
  • sudo nano /etc/rc.local
chown -R root:u8g2 /dev/gpiochip*
chmod -R ug+rw /dev/gpiochip*
chown -R root:u8g2 /dev/i2c*
chmod -R ug+rw /dev/i2c*
chown -R root:u8g2 /dev/spidev*
chmod -R ug+rw /dev/spidev*
  • sudo reboot

Download U8g2 project

  • cd ~/
  • git clone --depth 1 https://github.com/olikraus/u8g2.git

Modify source as needed

  • Change example (SPI 4 wire hardware for instance)
  • nano ~/u8g2/sys/arm-linux/examples/c-examples/u8g2_4wire_hw_spi\u8g2_4wire_hw_spi.c
  • Change the GPIO chip number (0 uses /dev/gpiochip0)
  • #define GPIO_CHIP_NUM 0
  • Change the SPI bus number (0x10 uses /dev/spidev1.0)
  • #define SPI_BUS 0x10
  • Change the DC and RESET as needed (NanoPi Duo here using tx1 and rx1)
  • #define OLED_SPI_PIN_RES 199
  • #define OLED_SPI_PIN_DC 198

Build source with GPIO character device

  • cd ~/u8g2/sys/arm-linux
  • make clean
  • make CPPFLAGS=-DPERIPHERY_GPIO_CDEV_SUPPORT=1 CC=gcc CXX=g++

Build source with GPIO sysfs

  • cd ~/u8g2/sys/arm-linux
  • make clean
  • make CC=gcc CXX=g++