Giter VIP home page Giter VIP logo

ribasco / ucgdisplay Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 2.0 82.19 MB

A character/graphics lcd library for single board computers (e.g. Raspberry Pi) written in Java. Provides drivers for graphics monochrome display devices (lcd, oled, e-ink etc) powered by U8g2

License: GNU Lesser General Public License v3.0

Java 21.11% CMake 0.84% C++ 33.07% Shell 0.14% FreeMarker 0.01% C 44.59% Objective-C 0.25%
graphics display lcd hd44780 oled i2c spi parallel raspberry-pi arm embedded-systems library u8g2 java 8-bit iot e-ink single-board-computers glcd

ucgdisplay's Introduction

Universal Character/Graphics LCD Library for Java

Github Workflow Build Status Release Deployment Maven Central Codacy Badge Javadocs

Change Log

3.0.0 (04/30/2021)

  • Modularized project (for jdk 11 above)
  • Dropped input and character display modules
  • Removed travis ci script.

2.0.0-alpha (07/04/2020)

  • Added drawPixels() and drawPixelsBgra() method
  • Added setPrimaryColor and setSecondaryColor methods in native class
  • Added direct native access for BGRA buffers.
  • Added GlcdInterfaceLookup utility class to provide additional information about a communication protocol
  • New meta data information for fonts
  • Renamed GlcdBufferType to GlcdBufferLayout
  • Renamed GlcdBusInterface to GlcdCommProtocol
  • Renamed GlcdBusType to GlcdCommType
  • Renamed GlcdControllerType to GlcdController
  • Apply alpha blending for primary and secondary colors in virtual mode

1.5.2-alpha (11/23/2019)

  • Fixed missing dependencies in the aggregate jar

1.5.1-alpha (11/22/2019)

  • Fixed 'symbol lookup error' (Issue: #22)
  • Added support for multiple I/O peripheral providers (libgpiod, pigpiod, c-periphery) (Issue #24)
  • 64 bit architectures are now fully supported for ARM and x86. Note that 32 bit support for OSX platform may be removed in the future versions.
  • Added native logging capability for improved traceability (all native logging is routed to SLF4J)
  • On Raspberry Pi platforms, GPIO pins are now automatically configured internally by the native library.
  • API changes on GlcdConfigBuilder.

Features


General features
  • Supports Graphics/Dot-Matrix display devices
  • Support for multiple I/O peripheral providers
  • Provides native bindings (via JNI) to the U8g2 library for graphics displays.
  • Provides a virtual driver interface allowing u8g2 native operations to be accessed in java. Useful for apps that needs to simulate u8g2 draw operations without the need for a real display device.
Display drivers
Graphic LCD driver features
  • SPI and I2C hardware capability and other software bit-banging implementations
  • Over 46+ controllers are supported. Refer to the table below for the list of supported display controllers.
  • The graphics display module wraps around the popular c/c++ U8g2 library by Oliver. All drawing operations present in the library should be similar to the ones found in U8g2 (Refer to the official U8g2 reference manual for more information).

Supported display controllers


Graphic/Dot-Matrix LCD
  • A2PRINTER, HX1230, IL3820, IST3020, KS0108, LC7981, LD7032, LS013B7DH03, LS027B7DH01, MAX7219, NT7534, PCD8544, PCF8812, RA8835, SBN1661, SED1330, SED1520, SH1106, SH1107, SH1108, SH1122, SSD1305, SSD1306, SSD1309, SSD1317, SSD1322, SSD1325, SSD1326, SSD1327, SSD1329, SSD1606, SSD1607, ST75256, ST7565, ST7567, ST7586S, ST7588, ST7920, T6963, UC1601, UC1604, UC1608, UC1610, UC1611, UC1638, UC1701

Supported bus interfaces (GLCD)

Interface Type Description Hardware Software
SPI 4-Wire 4-Wire interface YES YES
SPI 4-Wire (ST7920) 4-Wire interface with no DC YES YES
SPI 3-Wire 3-Wire interface NO YES
I2C Two-Wire I2C Two-Wire interface YES YES
Parallel 8080 Parallel Parallel 8080 (Intel) NO YES
Parallel 6800 Parallel Parallel 6800 (Motorola) NO YES
Parallel 6800 Parallel (KS0108) Special KS0108 protocol. Mostly identical to 6800, but has more chip select lines NO YES
SED1520 SED1520 Special SED1520 protocol NO YES

Project Resources


Pre-requisites


  • Java JDK 11+ (See AdoptOpenJDK)
  • (Optional) Libgpiod (v1.4.1 or higher) - C library and tools for interacting with the linux GPIO character device (gpiod stands for GPIO device).
  • (Optional) Pigpio (v71 above) - pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).

IMPORTANT: For libgpiod, make sure the c++ bindings are included when you install from source (--enable-bindings-cxx)

Downloading Snapshots from Sonatype


To be able to download snapshots from Sonatype, add the following profile entry to your .m2/settings.xml file and activate with mvn -P sonatype install <....>.

<profile>
    <id>sonatype</id>
    <repositories>
        <repository>
            <id>ossrh</id>
            <name>Sonatype OSS Maven Repository</name>
            <url>https://oss.sonatype.org/content/groups/public</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </repository>
    </repositories>
</profile>

Installation


  1. From maven repository - All in one package

    <dependencies>
        <!-- Ucgdisplay Uber Jar -->
         <dependency>
             <groupId>com.ibasco.ucgdisplay</groupId>
             <artifactId>ucg-display</artifactId>
             <version>3.0.1</version>
         </dependency>
    </dependencies>
  2. From maven repository - Specific module

    <dependencies>
         <!-- Graphics display driver -->
         <dependency>
             <groupId>com.ibasco.ucgdisplay</groupId>
             <artifactId>ucgd-drivers-glcd</artifactId>
             <version>3.0.1</version>
         </dependency>
    </dependencies>
  3. From source

    Clone from Github (Sub-modules included)

    git clone --recurse-submodules -j4 https://github.com/ribasco/ucgdisplay.git

    Switch to the project directory

    cd ucgdisplay

    Install to your local maven repository

    • Installing from a Linux system with ARM 32/64 bit architecture

      mvn install -Dcompile.native=true
    • Installing from a 64-bit Linux system for ARM architecture 32 and 64 bit versions

      mvn install -Dcompile.native=true -Dgraphics.target=native-build-cc-arm-all -Dinput.target=native-build-cc-arm-all -Dbuild.type=Debug
    • Installing from a 64-bit Linux system for all supported architectures

      mvn install -Dcompile.native=true -Dgraphics.target=native-build-cc-all -Dinput.target=native-build-cc-all -Dbuild.type=Debug

    Note: Please see the cross-compilation guide for more details

Usage examples


Simple hello world examples

Graphic LCD Example (ST7920 SPI Hardware)

Example forST7920 display controller using RPi's SPI Hardware capability (Other Examples).

Note: For I2C/SPI hardware capability, there is no need to map the pins explicitly.

import com.ibasco.ucgdisplay.drivers.glcd.*;
import com.ibasco.ucgdisplay.drivers.glcd.enums.*;
import com.ibasco.ucgdisplay.drivers.glcd.utils.XBMData;
import com.ibasco.ucgdisplay.drivers.glcd.utils.XBMUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.Objects;

/**
 * ST7920 Example - Hardware SPI
 */
public class GlcdST7920HWExample {

    private static final Logger log = LoggerFactory.getLogger(GlcdST7920HWExample.class);

    public static void main(String[] args) throws Exception {
        new GlcdST7920HWExample().run();
    }

    private void run() throws Exception {
        //SPI HW 4-Wire config for ST7920

        //NOTE: On Raspberry Pi, pins can be automatically configured for hardware 		   capability (setting pin modes to ALT*).
        //Automatic pin configuration for special modes will only take place if PIGPIO is installed

        //Pinout for Main SPI Peripheral 
        // - MOSI = 10
        // - SCLK = 11
        // - CE1 = 7
        GlcdConfig config = GlcdConfigBuilder
                //Use ST7920 - 128 x 64 display, SPI 4-wire Hardware
                .create(Glcd.ST7920.D_128x64, GlcdBusInterface.SPI_HW_4WIRE_ST7920)
                //Set to 180 rotation
                .option(GlcdOption.ROTATION, GlcdRotation.ROTATION_180)
                //Using system/c-periphery provider
                .option(GlcdOption.PROVIDER, Provider.SYSTEM)
                //Set to 1,000,000 Hz/bps (1.00 MHz)
                .option(GlcdOption.BUS_SPEED, 1000000)
                //The SPI Bus (RPI as two SPI buses available, the Main and Auxillary)
                .option(GlcdOption.SPI_BUS, SpiBus.MAIN)
                //Use CE1 or Chip Select 1 on Main SPI peripheral/bus
                .option(GlcdOption.SPI_CHANNEL, SpiChannel.CHANNEL_1)
                .build();

        GlcdDriver driver = new GlcdDriver(config);

        //Clear the GLCD buffer
        driver.clearBuffer();

        //Write Operations to the GLCD buffer
        driver.setFont(GlcdFont.FONT_6X12_MR);
        driver.drawString(10, 10, "Hello World");
            
        //Send all buffered data to the display
        driver.sendBuffer();

        //Clear the display
        driver.clearDisplay();
    }
}
Graphic LCD Example (ST7920 SPI Software)

Here is an alternative version of the above example using bit-bang method. (Other Examples)

Note: This is slower than SPI Hardware

import com.ibasco.ucgdisplay.drivers.glcd.*;
import com.ibasco.ucgdisplay.drivers.glcd.enums.*;
import com.ibasco.ucgdisplay.drivers.glcd.utils.XBMData;
import com.ibasco.ucgdisplay.drivers.glcd.utils.XBMUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.Objects;

/**
 * ST7920 Example - SPI Software Bit-Bang.
 *
 * Note: This is ALOT slower than SPI HW
 */
public class GlcdST7920SWExample {

    private static final Logger log = LoggerFactory.getLogger(GlcdST7920SWExample.class);

    public static void main(String[] args) throws Exception {
        new GlcdST7920SWExample().run();
    }

    private void run() throws Exception {
        //SPI Software config for ST7920

        //NOTE: For software/bit-bang implementation, pin modes will be automatically configured to OUTPUT by the native module

        //Pinout for Main SPI Peripheral 
        // - MOSI = 10
        // - SCLK = 11
        // - CE1 = 7
        GlcdConfig config = GlcdConfigBuilder
                //Use ST7920 - 128 x 64 display, SPI Software implementation
                .create(Glcd.ST7920.D_128x64, GlcdBusInterface.SPI_SW_4WIRE_ST7920)
                //Set to 180 rotation
                .option(GlcdOption.ROTATION, GlcdRotation.ROTATION_180)
                //Using system/c-periphery provider
                .option(GlcdOption.PROVIDER, Provider.SYSTEM)
                //Map GlcdPin to BCM pin number
                .mapPin(GlcdPin.SPI_MOSI, 10)
                .mapPin(GlcdPin.SPI_CLOCK, 11)
                .mapPin(GlcdPin.CS, 7)
                .build();

        GlcdDriver driver = new GlcdDriver(config);

        //Clear the GLCD buffer
        driver.clearBuffer();

        //Write Operations to the GLCD buffer
        driver.setFont(GlcdFont.FONT_6X12_MR);
        driver.drawString(10, 10, "Hello World");
            
        //Send all buffered data to the display
        driver.sendBuffer();
    }
}
Configuration options (All available options in GlcdOption enum)
Option Name Raw Type Enum Description Category
PROVIDER String Provider The default provider to use for communicating with the display. Available providers are libgpiod, pigpio, pigpiod and cperiphery. General
BUS_SPEED Integer N/A The SPI/I2C bus speed in Hz SPI/I2C
GPIO_CHIP Integer GpioChip GPIO chip number. Will be translated to the actual GPIO device path. GPIO
SPI_CHANNEL Integer SpiChannel The SPI channel (Chip-Select). In raspberry pi, we have CE0 and CE1 for Main SPI and CE0, CE1, CE2 for Auxiliary. SPI
SPI_BUS Integer SpiBus The primary bus to be used for SPI communication. In raspberry pi, there are two SPI peripherals available, the main and the auxillary. SPI
SPI_MODE Integer SpiMode SPI mode. Mode 0, 1, 2 or 3. Check source documentation for more info. (Default: 0) SPI
SPI_BIT_ORDER Integer SpiBitOrder SPI Bit Order. Can be either 0 = MSB First or 1 = LSB First. (Default: 0) SPI
SPI_BITS_PER_WORD Integer N/A SPI Bits per word. (Default: 8) SPI
SPI_FLAGS Integer N/A Provider specific SPI flags. Only use this if you know what you are doing. Read more information on the provider's website (Default: 0). SPI
I2C_DEVICE_ADDRESS Integer N/A The address of the display device on the I2C bus. I2C
I2C_BUS Integer I2CBus The primary bus to be used for I2C communication. I2C
I2C_FLAGS Integer N/A Provider specific I2C flags. I2C
ROTATION Integer GlcdRotation The default rotation to set for the display. General
PIGPIO_ADDRESS String N/A The IP address of the pigpio daemon. (Default: 127.0.0.1) General
PIGPIO_PORT Integer N/A The port number of the pigpio daemon. (Default: 8888) General
EXTRA_DEBUG_INFO Boolean N/A Enable/Disable extra debug information to be displayed on the console (Default: false) General

Limitations


  • Works only on linux kernel v4.8 or higher
  • The adapters for character lcd driver Mcp23008LcdAdapter and Pcf8574TLcdAdapter are not yet implemented.
  • Due to lack of hardware availability, I am currently unable to test the SPI, I2C and bit-bang interfaces for most of the display controllers. The code implementation for these interfaces are complete, so In theory, they should work but it not confirmed. I am going to rely on your feedback for this and I will do my best to support any issues you may encounter.

Cross-Compilation Guide (for the Virtual driver interface)


Contributions are always welcome. For starters, checkout the guide to setting up your Dev/Build environment for more information.

Planned Features

  • For the Character LCD library, I plan to move away from Pi4J (v1.2 still using Wiring Pi which is now deprecated) and use the native layer instead for device communication. This will allow us to use different peripheral providers of our choice.

Credits

Related projects


ucgdisplay's People

Contributors

codacy-badger avatar dependabot[bot] avatar gitter-badger avatar ribasco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ucgdisplay's Issues

Add travis-ci support

Make sure that

  • Project java sources are compiled/packaged correctly
  • Cross-compilation of native library (Linux/Windows) works

java: symbol lookup error: **.so: undefined symbol: spi_setup

Ran a test on Raspberry Pi 2. Error thrown during initialization.

21:37:52.225 [main] DEBUG com.ibasco.ucgdisplay.drivers.glcd.GlcdConfig - Using display setup procedure (Display: D_128x64, Protocol: SPI_HW_4WIRE_ST7920, Setup Proc: u8g2_Setup_st7920_s_128x64_f))
21:37:52.332 [main] DEBUG com.ibasco.ucgdisplay.common.utils.PidispJniExtractor - [JNI-EXTRACT #1]: Searching in path: /usr/java/packages/lib/arm:/lib:/usr/lib/libucgdisp.so
21:37:52.378 [main] DEBUG com.ibasco.ucgdisplay.common.utils.PidispJniExtractor - [JNI-EXTRACT] Os Name = linux, Os Arch = arm, Os version = 4.14.71-v7+
21:37:52.400 [main] DEBUG com.ibasco.ucgdisplay.common.utils.PidispJniExtractor - [JNI-EXTRACT #2] Searching in path: lib/linux/arm/
21:37:52.401 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - mappedLib is libucgdisp.so
21:37:52.402 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - URL is jar:file:/home/pi/IdeaProjects/ucg-demo/lib/ucgd-native-graphics-1.1-alpha-20181029.065708-1.jar!/lib/linux/arm/libucgdisp.so
21:37:52.403 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - URL path is file:/home/pi/IdeaProjects/ucg-demo/lib/ucgd-native-graphics-1.1-alpha-20181029.065708-1.jar!/lib/linux/arm/libucgdisp.so
21:37:52.484 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - Extracting 'jar:file:/home/pi/IdeaProjects/ucg-demo/lib/ucgd-native-graphics-1.1-alpha-20181029.065708-1.jar!/lib/linux/arm/libucgdisp.so' to '/tmp/libucgdisp5693912452735116357.so'
java: symbol lookup error: /tmp/libucgdisp5693912452735116357.so: undefined symbol: spi_setup

[Native] Exception in thread "main" java.lang.UnsatisfiedLinkError

Error running from Raspberry Pi:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/libucgdisp7530612871061594713.so: /tmp/libucgdisp7530612871061594713.so: undefined symbol: _Z21cb_byte_8bit_6800modeP11u8g2_info_tP11u8x8_structhhPv
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
	at java.lang.Runtime.load0(Runtime.java:809)
	at java.lang.System.load(System.java:1086)
	at org.scijava.nativelib.NativeLoader.loadLibrary(NativeLoader.java:126)
	at com.ibasco.ucgdisplay.core.utils.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:53)
	at com.ibasco.ucgdisplay.core.u8g2.U8g2Graphics.<clinit>(U8g2Graphics.java:160)
	at com.ibasco.ucgdisplay.drivers.glcd.GlcdBaseDriver.initialize(GlcdBaseDriver.java:132)
	at com.ibasco.ucgdisplay.drivers.glcd.GlcdDriver.<init>(GlcdDriver.java:58)
	at com.ibasco.ucgdisplay.drivers.glcd.GlcdDriver.<init>(GlcdDriver.java:49)
	at com.ibasco.ucgdisplay.drivers.glcd.GlcdDriver.<init>(GlcdDriver.java:41)
	at com.ibasco.ucgdemo.Demo.main(Demo.java:22)

Maven artifact stuck on "1.4.1"

Hi Rafael.
Following your work from behind ๐Ÿ‘
Noticed that the Maven artifact are still stuck on 1.4.1, not 1.5.0 as indicated by the readme.
Maybe are there some glitches in the Travis deploy script?

Kind regards

Getting 'java.lang.UnsatisfiedLinkError: Can't find dependent libraries' when using snapshots built by Travis

When in virtual mode, it seems that running snapshot versions built by Travis CI throws 'java.lang.UnsatisfiedLinkError: C:\Users\raffy\AppData\Local\Temp\ucgdisp4751649856605482962.dll: Can't find dependent libraries'.

However, using a locally built snapshot (same version) cross-compiled from my Ubuntu machine do not have this issue and works as expected.

Need to investigate this further.

Add/Implement getNativeBuffer in U8g2Graphics interface

The u8g2 2.7 update now provides the capability to process/manipulate the pixel buffer directly.

TODO:

Add a new method in U8g2Graphics which returns a bytebuffer instance that wraps around the native pixel buffer allocated off-heap.

  • getNativeBuffer()

Port code generation tool to Java

Issues with the current code generation tool

  • Needs to be re-compiled every time the controller header file (controller.h) has been updated.
  • Requires a local copy of the u8g2 repository for it to work
  • Not ci-friendly

Notes:

  • Port the cpp code of the gen tool to java. Should be in it's own separate module and packaged as a runnable jar.
  • All new controller/font data should be fetched directly from the u8g2 repository (master branch) via Github API.
  • Consider automating the code generation when a new display controller has been added/updated in the u8g2 repository.

Wrong arch identifier for macosx

The native library would throw an exception due to the library not being found. It is currently using the search path of 'lib/mac/amd64'. The actual arch identifier used is x86_64, so the path should be lib/mac/x86_64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.