Giter Club home page Giter Club logo

st7735_gfx's Introduction

st7735_gfx

ST7735 LCD Display Driver

Adapted from https://github.com/adafruit/Adafruit-ST7735-Library and related resources. Heavily refactored to C, and to my design style. (The init data/code is about all that's copied; the rest has been heavily rewritten, or composed from scratch, taking guidance from here.)

Interface

The SPI_ macros are provided by your project header; they do what they say. Example (for XMega64 and the like):

#define PIN_SPI_CS		PIN4
#define BIT_SPI_CS		(1 << PIN4)
#define PORT_SPI_CS		PORTD
...
#define SPI_PORT		SPID
#define SPI_DATA		SPID.DATA
#define SPI_CSON()		PORT_SPI_CS.OUTCLR = BIT_SPI_CS
#define SPI_CSOFF()		PORT_SPI_CS.OUTSET = BIT_SPI_CS
#define SPI_DC_DATA()		PORT_SPI_DC.OUTSET = BIT_SPI_DC
#define SPI_DC_CMD()		PORT_SPI_DC.OUTCLR = BIT_SPI_DC
#define SPI_TXWAIT()		while (!(SPI_PORT.STATUS & SPI_IF_bm) && (SPI_PORT.CTRL & SPI_ENABLE_bm))

All (currently known?) display registers and bits have been named. This is formatted consistent with Atmel's MCU header style, so should be familiar to the bare-ish-bones AVR user (if rather messy to an Arduino user.. who probably shouldn't be looking at this, anyway?). The one customization is that the length of a register is variable, and not apparent from its name -- the _WRB and _RDB (Write Bytes and Read Bytes, respectively) macros supply this.

initLcd() is the initializer entry point. ST7735_displayInit() could be folded into it since it isn't used elsewhere and I'm not working with other display types at this time -- but if you are, add them here. The Adafruit libraries show several supported variants, which should be easy to plug in with few changes.

There are no display-read functions implemented (except for sendByte), because my implementation ran out of pins, and because strapping SDA (bidirectional) to MOSI and MISO is a bit of a juggle. Since VRAM is much larger than SRAM on most small MCUs (such as AVRs), this would be a convenient (if somewhat slow) way to implement alpha blending, say, or anything else that depends on a frame buffer.

The big step that brought on this repo is the drawImage() function. Like the init system, this processes a PROGMEM array as a series of variable-length commands. The format is like an RLE (run length encoded) image, but rather than a linear (scanline or string based) code, it's 2-dimensional -- ultimately because the ST7735 only has one set-region command and no RAM address control, so it's optimal to write blocks at a time.

So, I embarked on writing an encoder, which took about two weeks to complete. Run it here: https://htmlpreview.github.io/?https://github.com/T3sl4co1l/st7735_gfx/blob/master/compr.html

This page contains the JS encoder, an HTML interface, and documents the format. Output is verbose (English) text, and C header output. TODO: the binary output doesn't actually download anything right now. File download function is borrowed from: https://github.com/eligrey/FileSaver.js/

A greedy algorithm is used, and has compression ratio comparable to Windows RLE (an example, and its H output, is provided here). I'm quite satisfied with the results!

A number of optimizations could be made, give or take towards file size, or draw speed (which is dominated by the amount of SPI traffic, especially setRegion commands), but aren't going to be easy to patch into the middle of the encoder mega-function.

st7735_gfx's People

Contributors

t3sl4co1l avatar

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.