From ca13033791da5450c199176358642839d7354e7b Mon Sep 17 00:00:00 2001 From: Ryan Monhollon Date: Wed, 22 Jul 2015 11:04:25 -0400 Subject: [PATCH] Add support for scroll functions --- Adafruit_RA8875.cpp | 44 ++++++++++++++++++++++++++++++ Adafruit_RA8875.h | 10 +++++++ examples/scroll/scroll.ino | 55 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 examples/scroll/scroll.ino diff --git a/Adafruit_RA8875.cpp b/Adafruit_RA8875.cpp index 794609b..5f6a552 100644 --- a/Adafruit_RA8875.cpp +++ b/Adafruit_RA8875.cpp @@ -989,6 +989,50 @@ void Adafruit_RA8875::curveHelper(int16_t xCenter, int16_t yCenter, int16_t long waitPoll(RA8875_ELLIPSE, RA8875_ELLIPSE_STATUS); } +void Adafruit_RA8875::setScrollWindow(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t mode) { + // Horizontal Start point of Scroll Window + writeCommand(0x38); + writeData(x); + writeCommand(0x39); + writeData(x>>8); + + // Vertical Start Point of Scroll Window + writeCommand(0x3a); + writeData(y); + writeCommand(0x3b); + writeData(y>>8); + + // Horizontal End Point of Scroll Window + writeCommand(0x3c); + writeData(x+w); + writeCommand(0x3d); + writeData((x+w)>>8); + + // Vertical End Point of Scroll Window + writeCommand(0x3e); + writeData(y+h); + writeCommand(0x3f); + writeData((y+h)>>8); + + // Scroll function setting + writeCommand(0x52); + writeData(0x00); +} + +void Adafruit_RA8875::scrollX(int16_t dist) { + writeCommand(0x24); + writeData(dist); + writeCommand(0x25); + writeData(dist>>8); +} + +void Adafruit_RA8875::scrollY(int16_t dist) { + writeCommand(0x26); + writeData(dist); + writeCommand(0x27); + writeData(dist>>8); +} + /************************* Mid Level ***********************************/ /**************************************************************************/ diff --git a/Adafruit_RA8875.h b/Adafruit_RA8875.h index 82cd6a7..b651497 100644 --- a/Adafruit_RA8875.h +++ b/Adafruit_RA8875.h @@ -104,6 +104,11 @@ class Adafruit_RA8875 : public Adafruit_GFX { void fillEllipse(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color); void drawCurve(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color); void fillCurve(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color); + + /* Scroll */ + void setScrollWindow(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t mode); + void scrollX(int16_t dist); + void scrollY(int16_t dist); /* Backlight */ void GPIOX(boolean on); @@ -359,4 +364,9 @@ class Adafruit_RA8875 : public Adafruit_GFX { #define RA8875_INTC2_TP 0x04 #define RA8875_INTC2_BTE 0x02 +#define RA8875_SCROLL_BOTH 0x00 +#define RA8875_SCROLL_LAYER1 0x40 +#define RA8875_SCROLL_LAYER2 0x80 +#define RA8875_SCROLL_BUFFER 0xC0 + #endif diff --git a/examples/scroll/scroll.ino b/examples/scroll/scroll.ino new file mode 100644 index 0000000..2f94277 --- /dev/null +++ b/examples/scroll/scroll.ino @@ -0,0 +1,55 @@ +#include +#include +#include +#include "Adafruit_GFX.h" +#include "Adafruit_RA8875.h" + +// LCD +// Library only supports hardware SPI at this time +// Connect SCLK to UNO Digital #13 (Hardware SPI clock) +// Connect MISO to UNO Digital #12 (Hardware SPI MISO) +// Connect MOSI to UNO Digital #11 (Hardware SPI MOSI) +#define RA8875_INT 3 +#define RA8875_CS 10 +#define RA8875_RESET 9 + +#define NUMINPUTS 4 + +Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET); + +void setup() { + Serial.begin(9600); + + if (!tft.begin(RA8875_800x480)) { + Serial.println("LCD not found!"); + while (1); + } + + tft.displayOn(true); + tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX + tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight + tft.PWM1out(255); + + tft.fillScreen(RA8875_BLACK); + tft.setScrollWindow(0,0,800,480,RA8875_SCROLL_BOTH); + tft.fillCircle(690, 370, 100, RA8875_WHITE); +} + + +void loop() { + static int Scroll=0; + static int Dir=1; + + tft.scrollX(Scroll); + tft.scrollY(Scroll); + + Scroll+=Dir; + if(Scroll >= 250) { + Dir=-1;; + } else if(Scroll <= 0) { + Dir=1; + } + + delay(10); +} +