Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ST7735S vscrolling & 160x80 BGR display #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 65 additions & 7 deletions Adafruit_ST7735.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ static const uint8_t PROGMEM
0x00, 0x00, // XSTART = 0
0x00, 0x9F }, // XEND = 159

Rcmd2green160x80bgr[] = { // 7735S init, part 2 (mini 160x80 bgr)
3, // 3 commands in list:
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x4F, // XEND = 79
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x9F, // XEND = 159
ST77XX_INVON, 0 }, // 3: Invert display, no args

Rcmd3[] = { // 7735R init, part 3 (red or green tab)
4, // 4 commands in list:
ST7735_GMCTRP1, 16 , // 1: Gamma Adjustments (pos. polarity), 16 args + delay:
Expand Down Expand Up @@ -234,6 +244,12 @@ void Adafruit_ST7735::initR(uint8_t options) {
displayInit(Rcmd2green160x80);
_colstart = 24;
_rowstart = 0;
} else if (options == INITR_MINI160x80BGR) {
_height = ST7735_TFTHEIGHT_160;
_width = ST7735_TFTWIDTH_80;
displayInit(Rcmd2green160x80bgr);
_colstart = 26;
_rowstart = 1;
} else {
// colstart, rowstart left at default '0' values
displayInit(Rcmd2red);
Expand All @@ -242,10 +258,16 @@ void Adafruit_ST7735::initR(uint8_t options) {

// Black tab, change MADCTL color filter
if ((options == INITR_BLACKTAB) || (options == INITR_MINI160x80)) {
uint8_t data = 0xC0;
sendCommand(ST77XX_MADCTL, &data, 1);
madctl = 0xC0;
sendCommand(ST77XX_MADCTL, &madctl, 1);
}

if (options == INITR_MINI160x80BGR)
{
invertOnCommand = ST77XX_INVOFF;
invertOffCommand = ST77XX_INVON;
}

if (options == INITR_HALLOWING) {
// Hallowing is simply a 1.44" green tab upside-down:
tabcolor = INITR_144GREENTAB;
Expand All @@ -265,7 +287,6 @@ void Adafruit_ST7735::initR(uint8_t options) {
*/
/**************************************************************************/
void Adafruit_ST7735::setRotation(uint8_t m) {
uint8_t madctl = 0;

rotation = m & 3; // can't be higher than 3

Expand All @@ -286,7 +307,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) {
if (tabcolor == INITR_144GREENTAB) {
_height = ST7735_TFTHEIGHT_128;
_width = ST7735_TFTWIDTH_128;
} else if (tabcolor == INITR_MINI160x80) {
} else if (tabcolor == INITR_MINI160x80 || tabcolor == INITR_MINI160x80BGR) {
_height = ST7735_TFTHEIGHT_160;
_width = ST7735_TFTWIDTH_80;
} else {
Expand All @@ -306,7 +327,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) {
if (tabcolor == INITR_144GREENTAB) {
_width = ST7735_TFTHEIGHT_128;
_height = ST7735_TFTWIDTH_128;
} else if (tabcolor == INITR_MINI160x80) {
} else if (tabcolor == INITR_MINI160x80 || tabcolor == INITR_MINI160x80BGR) {
_width = ST7735_TFTHEIGHT_160;
_height = ST7735_TFTWIDTH_80;
} else {
Expand All @@ -326,7 +347,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) {
if (tabcolor == INITR_144GREENTAB) {
_height = ST7735_TFTHEIGHT_128;
_width = ST7735_TFTWIDTH_128;
} else if (tabcolor == INITR_MINI160x80) {
} else if (tabcolor == INITR_MINI160x80 || tabcolor == INITR_MINI160x80BGR) {
_height = ST7735_TFTHEIGHT_160;
_width = ST7735_TFTWIDTH_80;
} else {
Expand All @@ -346,7 +367,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) {
if (tabcolor == INITR_144GREENTAB) {
_width = ST7735_TFTHEIGHT_128;
_height = ST7735_TFTWIDTH_128;
} else if (tabcolor == INITR_MINI160x80) {
} else if (tabcolor == INITR_MINI160x80 || tabcolor == INITR_MINI160x80BGR) {
_width = ST7735_TFTHEIGHT_160;
_height = ST7735_TFTWIDTH_80;
} else {
Expand All @@ -360,3 +381,40 @@ void Adafruit_ST7735::setRotation(uint8_t m) {

sendCommand(ST77XX_MADCTL, &madctl, 1);
}


/**************************************************************************/
/*!
@brief Only for ST7735S. Sets Vertical Scrolling Area basic config, VSA must be within TFA and BFA.
@param top_fix_height TFA Top Fixed Area in pixels, >= 1
@param bottom_fix_height BFA Bottom Fixed Area in pixels, >=1
@param bottom_to_top Scroll direction
*/
/**************************************************************************/
void Adafruit_ST7735::setVerticalScrollConfig(uint8_t top_fix_height, uint8_t bottom_fix_height, bool bottom_to_top) {
uint8_t scroll_height;
scroll_height = _height - top_fix_height - bottom_fix_height; // TFA + VSA + BFA = 162

uint8_t args [6] = {0x00, top_fix_height, 0x00, scroll_height, 0x00, bottom_fix_height};
sendCommand(ST7735_SCRLAR, args, 6);

if(bottom_to_top)
madctl |= ST77XX_MADCTL_ML; // sets ML bit = 1
else
madctl &= ~ST77XX_MADCTL_ML; // sets ML bit = 0

sendCommand(ST77XX_MADCTL, &madctl, 1);
}


/**************************************************************************/
/*!
@brief Only for ST7735S. Sets Vertical Scroll Pointer, vsp must be within TFA and BFA.
@param vsp Vertical Scroll Pointer
*/
/**************************************************************************/
void Adafruit_ST7735::setVerticalScrollPointer(uint8_t vsp) {
uint8_t args[2] = {0x00, vsp};
sendCommand(ST7735_VSCSAD, args, 2);
}

9 changes: 9 additions & 0 deletions Adafruit_ST7735.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define INITR_144GREENTAB 0x01
#define INITR_MINI160x80 0x04
#define INITR_HALLOWING 0x05
#define INITR_MINI160x80BGR 0x06 // ST7735S

// Some register settings
#define ST7735_MADCTL_BGR 0x08
Expand All @@ -36,6 +37,10 @@
#define ST7735_GMCTRP1 0xE0
#define ST7735_GMCTRN1 0xE1

// Vertical Scrolling
#define ST7735_SCRLAR 0x33
#define ST7735_VSCSAD 0x37

// Some ready-made 16-bit ('565') color settings:
#define ST7735_BLACK ST77XX_BLACK
#define ST7735_WHITE ST77XX_WHITE
Expand Down Expand Up @@ -63,8 +68,12 @@ class Adafruit_ST7735 : public Adafruit_ST77xx {

void setRotation(uint8_t m);

void setVerticalScrollConfig(uint8_t top_fix_height = 1, uint8_t bottom_fix_height = 1, bool bottom_to_top = true);
void setVerticalScrollPointer(uint8_t vsp);

private:
uint8_t tabcolor;
uint8_t madctl;
};

#endif // _ADAFRUIT_ST7735H_
Empty file.