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
Optimized ST7735 1.8" LCD library + antialiased lines
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 5
- Joined: Thu Aug 23, 2012 1:56 pm
Optimized ST7735 1.8" LCD library + antialiased lines
- Attachments
-
- ST7735.h
- Subclass of Adafruit_ST7735 with some optimizations and antialiased lines
- (5.76 KiB) Downloaded 360 times
-
- Posts: 5
- Joined: Thu Aug 23, 2012 1:56 pm
Re: Optimized ST7735 1.8" LCD library + antialiased lines
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
inline class Color operator *(float scalar, Color::Components color)
{
return Color(color.r() * scalar, color.g() * scalar, color.b() * scalar);
}
Mike
-
- Posts: 1
- Joined: Wed Jan 23, 2013 3:24 am
Re: Optimized ST7735 1.8" LCD library + antialiased lines
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:
Robert
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:
Thanks#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);
Robert
-
- Posts: 1
- Joined: Wed May 22, 2013 1:29 pm
Re: Optimized ST7735 1.8" LCD library + antialiased lines
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!
Please be positive and constructive with your questions and comments.