Code Monkey home page Code Monkey logo

spi_lcd's Introduction

*** SPI_LCD ***

SPI_LCD is a C library for working with the SPI-connected LCD displays which use the SSD1351, ST7735, ILI9341 or HX8357 controller chips. The idea is to provide a simple interface for C programmers to make use of those low-cost LCD displays without having to read the data sheet or figure out SPI programming. My main purpose of writing this library is not to replace the fbtft Linux driver, but to provide a small, efficient way for programs to talk directly to the LCD controller. My specific use case is my interest in retro gaming and my desire to get games to run at 60fps through an interface that only allows up to 33fps via smart buffer management and hardware scrolling.

ILI9341 at 60FPS

Unfortunately the display controller needs a couple of control lines (GPIO pins) for Reset and Data/Command; this requires making some changes to the code depending on which GPIO lines you choose to use. I added the flexibility to use either the SPI/GPIO kernel drivers, or wiringPi, BCM2835 or PIGPIO. Select the desired library by using the appropriate #ifdef in spi_lcd.c and in the make_sample makefile. From my testing, wiringPi is the slowest of the 3 due to its use of the Linux SPI kernel driver. The advantage to using it is that it doesn't require root privilege if you set up the SPI kernel driver to be automatically loaded at boot time. The BCM2835 driver is the next fastest and can potentially use fewer CPU cycles due to it's use of hardware DMA transfers. PIGPIO is the fastest of the 3 by a long shot. Part of the reason is that it talks directly to the SPI shift register; the downside is that it uses more CPU time to send the data. The included sample code will display the potential maximum frames per second possible, so you can see how each library performs on your hardware.

Features

  • Supports ssd1351 (128x128), st7735 (128x160), ili9341 (240x320) and hx8357 (320x480) displays
  • Includes several header pin to GPIO translation tables for non-RPI boards
  • Works in both landscape and portrait orientation
  • Two sizes of text drawing with custom fg/bg color
  • Fast tile drawing for gaming
  • Fast stretched tile drawing for scaling 160x144 to 320x216
  • Hardware scrolling (vertical/portrait direction only)
  • Single pixel drawing
  • Backlight on/off
  • Portable C code with wrapper functions for I/O; easy to compile on any system
  • GPIO wrapper functions for reading/writing in a simple way.
  • xpt2046 touch controller input

To build the library, simply type 'make' in the terminal. To build the sample app, type 'make -f make_sample'. This will build the 'lcd' executable to show that the library is working.

Copyright (c) 2017 by Larry Bank Project started 4/25/2017 [email protected]

If you find this code useful, please consider buying me a cup of coffee
paypal

spi_lcd's People

Contributors

bitbank2 avatar jetaudio avatar pconti31 avatar thehonestmaker avatar zo0x avatar

Stargazers

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

Watchers

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

spi_lcd's Issues

Armbian NEO

I'm not getting anywhere when trying to use this library on an Armbian mainline/ NanoPi NEO. I uncomment the #define USE_NANOPI2 line and use the #define USE_GENERIC lines. Do the 'make' and then the 'make -f make_sample' without any issues. However, when I try to run the lcd sample, I'm getting:

root@connectbox:~/SPI_LCD# ./lcd
Error setting SPI mode
Error setting SPI speed
Failed to open the SPI bus
Problem initializing spilcd library

Any ideas of what is missing and how I can get this running?

ST7735R in 128x128 support?

I have a ST7725R TFT LCD from Adafruit ( https://www.adafruit.com/product/2088 ) but it is 128x128, not 128*160.

It is connected to a Raspberry Pi with the following https://www.adafruit.com/product/3356 on SPI0.

I tried to modify your code to change all the instance of 160 by 128, but could not make it work. Your demo code does display garbage of color, and and the end I can almost read "Big rotd".

Would you know the difference between this and your reference ST7725 128*160 screen?

PS: No big deal, I can drive it and copy from fb0 with code from https://github.com/adafruit/Pi_Eyes but I was trying to use SPI_LCD and BB-CP (I know, it is supposed to be for ili9341 320x240 LCD). This might be silly on it's own since there might be no need for optimisation for such a small screen. Thanks anyway for all the code you are sharing, and the ultimate goal of 60fps for retrogaming on little screen.

HX8357C on Raspberry Pi

I have this display:
image
image
On the back of my display it also says HX8357C.
Can the display be used on the Raspberry Pi Zero W with your library? How would you connect the pins to the Raspberry Pi?
Where would I have to make modifications to the code to get it running?

Thank you for your help.

Arduino Sample

Not sure anyone is interested but I modified existing main.c to run as a Arduino .ino program.
Called it SPI_Sample.ino. It was tested on Arduino Due rev3 using AdaFruit's 2.8 tft with ILI9341 driver.
Only one mod to spi_lcd.cpp
changed line 187 from
SPI.transferBytes(pBuf, ucRXBuf, iLen);
To:
SPI.transfer(pBuf, iLen);
all files in the attached zip file
SPI_Sample.zip

NanoPi Duo 2 pin mappings

Hey! (I'm in the right repo this time haha)
Great work on this by the way.

I am trying to get this working on a NanoPi Duo2 but I cant seem to get them right, I looked at your mapping table in the spi_lcd.c file, chose NanoPi Duo2 as that has the same GPIO Pin out.

Any help where to map the final 2 pins of DC/X and Reset would be most helpful.

Thanks in advance.

Displaying the whole screen

Hi @bitbank2!

Thanks a lot for your work on the library.

I am currently building a small project using a raspi zero with a ili9341 screen. I want to run RetroPie/Recalbox on it but with all my tests (default drivers + fbcp) there's a small lag I can't get rid off.

I'd like to try using your driver and see if I can get better results. Is that possible? How should I do that do have the entire screen running on tft using your driver?

Thanks in advance!

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.