Skip to content

Commit

Permalink
Merge pull request #69 from makermelissa/master
Browse files Browse the repository at this point in the history
Implemented sendCommand
  • Loading branch information
ladyada authored Apr 29, 2019
2 parents 72e3f29 + e604b3d commit fb92956
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 60 deletions.
78 changes: 36 additions & 42 deletions Adafruit_ST7735.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,38 @@ static const uint8_t PROGMEM
18, // 18 commands in list:
ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, no args, w/delay
50, // 50 ms delay
ST77XX_SLPOUT , ST_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay
ST77XX_SLPOUT, ST_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay
255, // 255 = max (500 ms) delay
ST77XX_COLMOD , 1+ST_CMD_DELAY, // 3: Set color mode, 1 arg + delay:
ST77XX_COLMOD, 1+ST_CMD_DELAY, // 3: Set color mode, 1 arg + delay:
0x05, // 16-bit color
10, // 10 ms delay
ST7735_FRMCTR1, 3+ST_CMD_DELAY, // 4: Frame rate control, 3 args + delay:
0x00, // fastest refresh
0x06, // 6 lines front porch
0x03, // 3 lines back porch
10, // 10 ms delay
ST77XX_MADCTL , 1, // 5: Mem access ctl (directions), 1 arg:
ST77XX_MADCTL, 1, // 5: Mem access ctl (directions), 1 arg:
0x08, // Row/col addr, bottom-top refresh
ST7735_DISSET5, 2, // 6: Display settings #5, 2 args:
0x15, // 1 clk cycle nonoverlap, 2 cycle gate
// rise, 3 cycle osc equalize
0x02, // Fix on VTL
ST7735_INVCTR , 1, // 7: Display inversion control, 1 arg:
ST7735_INVCTR, 1, // 7: Display inversion control, 1 arg:
0x0, // Line inversion
ST7735_PWCTR1 , 2+ST_CMD_DELAY, // 8: Power control, 2 args + delay:
ST7735_PWCTR1, 2+ST_CMD_DELAY, // 8: Power control, 2 args + delay:
0x02, // GVDD = 4.7V
0x70, // 1.0uA
10, // 10 ms delay
ST7735_PWCTR2 , 1, // 9: Power control, 1 arg, no delay:
ST7735_PWCTR2, 1, // 9: Power control, 1 arg, no delay:
0x05, // VGH = 14.7V, VGL = -7.35V
ST7735_PWCTR3 , 2, // 10: Power control, 2 args, no delay:
ST7735_PWCTR3, 2, // 10: Power control, 2 args, no delay:
0x01, // Opamp current small
0x02, // Boost frequency
ST7735_VMCTR1 , 2+ST_CMD_DELAY, // 11: Power control, 2 args + delay:
ST7735_VMCTR1, 2+ST_CMD_DELAY, // 11: Power control, 2 args + delay:
0x3C, // VCOMH = 4V
0x38, // VCOML = -1.1V
10, // 10 ms delay
ST7735_PWCTR6 , 2, // 12: Power control, 2 args, no delay:
ST7735_PWCTR6, 2, // 12: Power control, 2 args, no delay:
0x11, 0x15,
ST7735_GMCTRP1,16, // 13: Gamma settings, I think?
0x09, 0x16, 0x09, 0x20,
Expand All @@ -95,22 +95,22 @@ static const uint8_t PROGMEM
0x1B, 0x1A, 0x24, 0x2B,
0x06, 0x06, 0x02, 0x0F,
10, // 10 ms delay
ST77XX_CASET , 4, // 15: Column addr set, 4 args, no delay:
ST77XX_CASET, 4, // 15: Column addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 2
0x00, 0x81, // XEND = 129
ST77XX_RASET , 4, // 16: Row addr set, 4 args, no delay:
ST77XX_RASET, 4, // 16: Row addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 1
0x00, 0x81, // XEND = 160
ST77XX_NORON , ST_CMD_DELAY, // 17: Normal display on, no args, w/delay
ST77XX_NORON, ST_CMD_DELAY, // 17: Normal display on, no args, w/delay
10, // 10 ms delay
ST77XX_DISPON , ST_CMD_DELAY, // 18: Main screen turn on, no args, delay
ST77XX_DISPON, ST_CMD_DELAY, // 18: Main screen turn on, no args, delay
255 }, // 255 = max (500 ms) delay

Rcmd1[] = { // 7735R init, part 1 (red or green tab)
15, // 15 commands in list:
ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, 0 args, w/delay
150, // 150 ms delay
ST77XX_SLPOUT , ST_CMD_DELAY, // 2: Out of sleep mode, 0 args, w/delay
ST77XX_SLPOUT, ST_CMD_DELAY, // 2: Out of sleep mode, 0 args, w/delay
255, // 500 ms delay
ST7735_FRMCTR1, 3, // 3: Framerate ctrl - normal mode, 3 arg:
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
Expand All @@ -119,63 +119,63 @@ static const uint8_t PROGMEM
ST7735_FRMCTR3, 6, // 5: Framerate - partial mode, 6 args:
0x01, 0x2C, 0x2D, // Dot inversion mode
0x01, 0x2C, 0x2D, // Line inversion mode
ST7735_INVCTR , 1, // 6: Display inversion ctrl, 1 arg:
ST7735_INVCTR, 1, // 6: Display inversion ctrl, 1 arg:
0x07, // No inversion
ST7735_PWCTR1 , 3, // 7: Power control, 3 args, no delay:
ST7735_PWCTR1, 3, // 7: Power control, 3 args, no delay:
0xA2,
0x02, // -4.6V
0x84, // AUTO mode
ST7735_PWCTR2 , 1, // 8: Power control, 1 arg, no delay:
ST7735_PWCTR2, 1, // 8: Power control, 1 arg, no delay:
0xC5, // VGH25=2.4C VGSEL=-10 VGH=3 * AVDD
ST7735_PWCTR3 , 2, // 9: Power control, 2 args, no delay:
ST7735_PWCTR3, 2, // 9: Power control, 2 args, no delay:
0x0A, // Opamp current small
0x00, // Boost frequency
ST7735_PWCTR4 , 2, // 10: Power control, 2 args, no delay:
ST7735_PWCTR4, 2, // 10: Power control, 2 args, no delay:
0x8A, // BCLK/2,
0x2A, // opamp current small & medium low
ST7735_PWCTR5 , 2, // 11: Power control, 2 args, no delay:
ST7735_PWCTR5, 2, // 11: Power control, 2 args, no delay:
0x8A, 0xEE,
ST7735_VMCTR1 , 1, // 12: Power control, 1 arg, no delay:
ST7735_VMCTR1, 1, // 12: Power control, 1 arg, no delay:
0x0E,
ST77XX_INVOFF , 0, // 13: Don't invert display, no args
ST77XX_MADCTL , 1, // 14: Mem access ctl (directions), 1 arg:
ST77XX_INVOFF, 0, // 13: Don't invert display, no args
ST77XX_MADCTL, 1, // 14: Mem access ctl (directions), 1 arg:
0xC8, // row/col addr, bottom-top refresh
ST77XX_COLMOD , 1, // 15: set color mode, 1 arg, no delay:
ST77XX_COLMOD, 1, // 15: set color mode, 1 arg, no delay:
0x05 }, // 16-bit color

Rcmd2green[] = { // 7735R init, part 2 (green tab only)
2, // 2 commands in list:
ST77XX_CASET , 4, // 1: Column addr set, 4 args, no delay:
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 0
0x00, 0x7F+0x02, // XEND = 127
ST77XX_RASET , 4, // 2: Row addr set, 4 args, no delay:
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
0x00, 0x01, // XSTART = 0
0x00, 0x9F+0x01 }, // XEND = 159

Rcmd2red[] = { // 7735R init, part 2 (red tab only)
2, // 2 commands in list:
ST77XX_CASET , 4, // 1: Column addr set, 4 args, no delay:
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x7F, // XEND = 127
ST77XX_RASET , 4, // 2: Row addr set, 4 args, no delay:
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x9F }, // XEND = 159

Rcmd2green144[] = { // 7735R init, part 2 (green 1.44 tab)
2, // 2 commands in list:
ST77XX_CASET , 4, // 1: Column addr set, 4 args, no delay:
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x7F, // XEND = 127
ST77XX_RASET , 4, // 2: Row addr set, 4 args, no delay:
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x7F }, // XEND = 127

Rcmd2green160x80[] = { // 7735R init, part 2 (mini 160x80)
2, // 2 commands in list:
ST77XX_CASET , 4, // 1: Column addr set, 4 args, no delay:
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x7F, // XEND = 79
ST77XX_RASET , 4, // 2: Row addr set, 4 args, no delay:
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x9F }, // XEND = 159

Expand All @@ -191,9 +191,9 @@ static const uint8_t PROGMEM
0x2E, 0x2C, 0x29, 0x2D,
0x2E, 0x2E, 0x37, 0x3F,
0x00, 0x00, 0x02, 0x10,
ST77XX_NORON , ST_CMD_DELAY, // 3: Normal display on, no args, w/delay
ST77XX_NORON, ST_CMD_DELAY, // 3: Normal display on, no args, w/delay
10, // 10 ms delay
ST77XX_DISPON , ST_CMD_DELAY, // 4: Main screen turn on, no args w/delay
ST77XX_DISPON, ST_CMD_DELAY, // 4: Main screen turn on, no args w/delay
100 }; // 100 ms delay

/**************************************************************************/
Expand Down Expand Up @@ -238,10 +238,7 @@ void Adafruit_ST7735::initR(uint8_t options) {

// Black tab, change MADCTL color filter
if((options == INITR_BLACKTAB) || (options == INITR_MINI160x80)) {
startWrite();
writeCommand(ST77XX_MADCTL);
spiWrite(0xC0);
endWrite();
sendCommand(ST77XX_MADCTL, (uint8_t *) 0xC0, 1);
}

if(options == INITR_HALLOWING) {
Expand Down Expand Up @@ -356,8 +353,5 @@ void Adafruit_ST7735::setRotation(uint8_t m) {
break;
}

startWrite();
writeCommand(ST77XX_MADCTL);
spiWrite(madctl);
endWrite();
sendCommand(ST77XX_MADCTL, &madctl, 1);
}
6 changes: 2 additions & 4 deletions Adafruit_ST7789.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ void Adafruit_ST7789::setRotation(uint8_t m) {
_ystart = 0;
break;
}
startWrite();
writeCommand(ST77XX_MADCTL);
spiWrite(madctl);
endWrite();

sendCommand(ST77XX_MADCTL, &madctl, 1);
}
18 changes: 6 additions & 12 deletions Adafruit_ST77xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,17 @@ Adafruit_ST77xx::Adafruit_ST77xx(SPIClass *spiClass, int8_t cs, int8_t dc,
/**************************************************************************/
void Adafruit_ST77xx::displayInit(const uint8_t *addr) {

uint8_t numCommands, numArgs;
uint8_t numCommands, cmd, numArgs;
uint16_t ms;

startWrite();
numCommands = pgm_read_byte(addr++); // Number of commands to follow
while(numCommands--) { // For each command...

writeCommand(pgm_read_byte(addr++)); // Read, issue command
cmd = pgm_read_byte(addr++); // Read command
numArgs = pgm_read_byte(addr++); // Number of args to follow
ms = numArgs & ST_CMD_DELAY; // If hibit set, delay follows args
numArgs &= ~ST_CMD_DELAY; // Mask out delay bit
while(numArgs--) { // For each argument...
spiWrite(pgm_read_byte(addr++)); // Read, issue argument
}
sendCommand(cmd, addr, numArgs);
addr += numArgs;
SPI_CS_HIGH(); SPI_CS_LOW(); // ST7789 needs chip deselect after each

if(ms) {
Expand All @@ -107,7 +104,6 @@ void Adafruit_ST77xx::displayInit(const uint8_t *addr) {
delay(ms);
}
}
endWrite();
}

/**************************************************************************/
Expand Down Expand Up @@ -201,10 +197,8 @@ void Adafruit_ST77xx::setRotation(uint8_t m) {
_xstart = _rowstart;
break;
}
startWrite();
writeCommand(ST77XX_MADCTL);
spiWrite(madctl);
endWrite();

sendCommand(ST77XX_MADCTL, &madctl, 1);
}

/**************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions examples/graphicstest/graphicstest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#define TFT_RST 37 // Display reset
#define TFT_DC 38 // Display data/command select
#define TFT_BACKLIGHT 7 // Display backlight pin
#elif defined(ESP8266)
#define TFT_CS 4
#define TFT_RST 16
#define TFT_DC 5
#else
// For the breakout board, you can use any 2 or 3 pins.
// These pins will also work for the 1.8" TFT shield.
Expand Down
1 change: 0 additions & 1 deletion examples/rotationtest/rotationtest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,3 @@ void rotateString(void) {
tft.setRotation(tft.getRotation()+1);
}
}

2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit ST7735 and ST7789 Library
version=1.2.8
version=1.3.0
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=This is a library for the Adafruit ST7735 and ST7789 SPI displays.
Expand Down

0 comments on commit fb92956

Please sign in to comment.