Optimized ST7735 1.8" LCD library + antialiased lines

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
mike_ekim1024
 
Posts: 5
Joined: Thu Aug 23, 2012 1:56 pm

Optimized ST7735 1.8" LCD library + antialiased lines

Post by mike_ekim1024 »

Hi guys, I'm fairly new to Arduino but I've jumped in head first and now have 3 little gadgets to play with. While working with the ST7735 and learning SPI, I found out what the word slow really means - especially drawing pixel by pixel. I wanted anti-aliased lines, so that's how it needed to be done. So I tried optimizing routines - use of some C++ templates, liberal use of inline and const, and cutting some corners and only supporting hardware SPI. I also added Xiaolin Wu's antialiased line drawing algorithm to replace the jaggies. Because of the other optimizations, it's only slightly slower than non-antialiased lines.

It's a drop in extension to Adafruit_ST7735 once you supply a few template parameters:

template <uint8_t Width, uint8_t Height, uint8_t RowStart, uint8_t ColStart>
class ST7735 : public Adafruit_ST7735

//Adafruit_ST7735 TFT(CS_PIN, DC_PIN, RST_PIN);
ST7735<128, 160, 0, 0> TFT(CS_PIN, DC_PIN, RST_PIN);


Enjoy!
Mike
Attachments
ST7735.h
Subclass of Adafruit_ST7735 with some optimizations and antialiased lines
(5.76 KiB) Downloaded 360 times

mike_ekim1024
 
Posts: 5
Joined: Thu Aug 23, 2012 1:56 pm

Re: Optimized ST7735 1.8" LCD library + antialiased lines

Post by mike_ekim1024 »

Forgot to provide the color multiply operator:

inline class Color operator *(float scalar, Color::Components color)
{
return Color(color.r() * scalar, color.g() * scalar, color.b() * scalar);
}

Mike

robvoi
 
Posts: 1
Joined: Wed Jan 23, 2013 3:24 am

Re: Optimized ST7735 1.8" LCD library + antialiased lines

Post by robvoi »

Hi,

thanks for sharing your code.
Can you please give a more detailed eplanation on how to bind in your extension? I get compilation errors with the way I tried it.


I tried:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <ST7735.h>
#include <SPI.h>

template <uint8_t Width, uint8_t Height, uint8_t RowStart, uint8_t ColStart>
class ST7735 : public Adafruit_ST7735

Adafruit_ST7735 tft = ST7735<128, 160, 0, 0> tft(cs, dc, rst);
Thanks
Robert

blackstealth
 
Posts: 1
Joined: Wed May 22, 2013 1:29 pm

Re: Optimized ST7735 1.8" LCD library + antialiased lines

Post by blackstealth »

Fantastic work, but could you please provide a simple example sketch so we can learn from it? I know C very well, but C++ not so much. While I wait for a reply, I will research templates because I don't know how to use them. Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”