Skip to content

Commit 7e56303

Browse files
version 2.6.0
1 parent 723f907 commit 7e56303

8 files changed

Lines changed: 126 additions & 21 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ pico_sdk_init()
1515

1616
# turn on all compiler warnings
1717
add_compile_options(-Wall -Wextra )
18+
1819
# print memory information
1920
string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--print-memory-usage")
2021

2122
# Tell CMake where to find the executable source file
2223
# Comment in ONE AND ONE ONLY
2324
add_executable(${PROJECT_NAME}
2425
examples/st7735/hello/main.cpp
26+
#examples/st7735/hello_128x160/main.cpp
27+
#examples/st7735/hello_80x160/main.cpp
2528
#examples/st7735/graphics/main.cpp
2629
#examples/st7735/functions_fps/main.cpp
2730
#examples/st7735/text/main.cpp

examples/st7735/hello/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@brief Example cpp file for st7735 library. Tests Hello World
55
@note See USER OPTIONS 0-3 in SETUP function
66
@test
7-
-# Test100 write out Hello world
7+
-# Test100 write out Hello world 128x128 display
88
*/
99

1010
// Section :: libraries
@@ -81,6 +81,7 @@ void Setup(void)
8181
}
8282

8383
void Test100(void) {
84+
myTFT.setRotation(myTFT.Degrees_0);
8485
myTFT.fillScreen(myTFT.C_BLACK);
8586
myTFT.setTextColor(myTFT.C_GREEN, myTFT.C_BLACK);
8687
myTFT.setCursor(5,5);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*!
2+
@file main.cpp
3+
@author Gavin Lyons
4+
@brief Example cpp file for st7735 library. Tests Hello World
5+
@note See USER OPTIONS 0-3 in SETUP function
6+
@test
7+
-# Test103 write out Hello world on 128x160 display
8+
*/
9+
10+
// Section :: libraries
11+
#include "pico/time.h"
12+
#include "pico/stdlib.h"
13+
#include "hardware/spi.h"
14+
#include "displaylib_16/st7735.hpp"
15+
16+
17+
/// @cond
18+
19+
#ifdef dislib16_ADVANCED_SCREEN_BUFFER_ENABLE
20+
#pragma message("gll: dislib16_ADVANCED_SCREEN_BUFFER_ENABLE is defined. This example is not for that mode")
21+
#endif
22+
23+
// Section :: Globals
24+
ST7735_TFT myTFT;
25+
26+
// Section :: Function Headers
27+
void Setup(void); // setup + user options
28+
void Test103(void);
29+
void EndTests(void);
30+
31+
// Section :: MAIN loop
32+
int main(void)
33+
{
34+
Setup();
35+
Test103();
36+
EndTests();
37+
}
38+
// *** End OF MAIN **
39+
40+
// Section :: Function Space
41+
42+
void Setup(void)
43+
{
44+
stdio_init_all(); // optional for error messages , Initialize chosen serial port, default 38400 baud
45+
MILLISEC_DELAY(1000);
46+
printf("TFT Start\r\n");
47+
48+
//*************** USER OPTION 0 SPI_SPEED + TYPE ***********
49+
bool bhardwareSPI = true; // true for hardware spi, false for software
50+
51+
if (bhardwareSPI == true) { // hw spi
52+
uint32_t TFT_SCLK_FREQ = 8000 ; // Spi freq in KiloHertz , 1000 = 1Mhz
53+
myTFT.TFTInitSPIType(TFT_SCLK_FREQ, spi0);
54+
} else { // sw spi
55+
uint16_t SWSPICommDelay = 0; // optional SW SPI GPIO delay in uS
56+
myTFT.TFTInitSPIType(SWSPICommDelay);
57+
}
58+
//*********************************************************
59+
// ******** USER OPTION 1 GPIO *********
60+
// NOTE if using Hardware SPI clock and data pins will be tied to
61+
// the chosen interface eg Spi0 CLK=18 DIN=19)
62+
int8_t SDIN_TFT = 19;
63+
int8_t SCLK_TFT = 18;
64+
int8_t DC_TFT = 3;
65+
int8_t CS_TFT = 2 ;
66+
int8_t RST_TFT = 4;
67+
myTFT.setupGPIO(RST_TFT, DC_TFT, CS_TFT, SCLK_TFT, SDIN_TFT);
68+
//**********************************************************
69+
70+
// ****** USER OPTION 2 Screen Setup ******
71+
uint8_t OFFSET_COL = 0; // 2, These offsets can be adjusted for any issues->
72+
uint8_t OFFSET_ROW = 0; // 3, with screen manufacture tolerance/defects
73+
uint16_t TFT_WIDTH = 128;// Screen width in pixels
74+
uint16_t TFT_HEIGHT = 160; // Screen height in pixels
75+
myTFT.TFTInitScreenSize(OFFSET_COL, OFFSET_ROW , TFT_WIDTH , TFT_HEIGHT);
76+
// ******************************************
77+
78+
// ******** USER OPTION 3 PCB_TYPE **************************
79+
myTFT.TFTInitPCBType(myTFT.TFT_ST7735S_Black); // pass enum,multi choice,see README
80+
//**********************************************************
81+
}
82+
83+
void Test103(void) {
84+
myTFT.setRotation(myTFT.Degrees_0);
85+
myTFT.fillScreen(myTFT.C_BLACK);
86+
myTFT.setTextColor(myTFT.C_RED, myTFT.C_BLACK);
87+
myTFT.setCursor(5,5);
88+
myTFT.setFont(font_default);
89+
myTFT.print("Hello World");
90+
MILLISEC_DELAY(5000);
91+
myTFT.fillScreen(myTFT.C_BLACK);
92+
MILLISEC_DELAY(1000);
93+
}
94+
95+
void EndTests(void)
96+
{
97+
myTFT.TFTPowerDown();
98+
printf("TFT: Tests Over");
99+
}
100+
101+
102+
/// @endcond

examples/st7735/hello_80x160/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@file main.cpp
33
@author Gavin Lyons
44
@brief Example cpp file for st7735 library. Tests Hello World
5-
@details This example file is for 96' 80x160 display
5+
@details This example file is for 0.96 inch 80x160 pixel display
66
See USER OPTIONS in SETUP function
77
Note PCB choice and offsets
88
@test
@@ -100,13 +100,10 @@ void Test101(void)
100100
}
101101

102102
// Colour Test :: Red, Green, Blue, Yellow, White — black background
103-
// If colours are wrong check: PCB type (option 3), setColorByteSwap(), TFTchangeInvertMode()
103+
// If colours are wrong check: PCB type (option 3), TFTchangeInvertMode()
104104
void ColorTest(void)
105105
{
106106
myTFT.fillScreen(myTFT.C_BLACK);
107-
// Five blocks stacked vertically, centred in 80x160
108-
// Each block: width=64, height=24, x=8 (4px margin each side), radius=8
109-
// Spacing: 28px per block (24 height + 4 gap), y_start=12 → last block ends at y=148
110107
myTFT.fillRoundRect(8, 12, 64, 24, 8, myTFT.C_RED);
111108
myTFT.fillRoundRect(8, 40, 64, 24, 8, myTFT.C_GREEN);
112109
myTFT.fillRoundRect(8, 68, 64, 24, 8, myTFT.C_BLUE);

extra/doc/st7735/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ Comment in one path and one path only.
2828

2929
| Filename | Function | Note |
3030
| --- | --- | --- |
31-
| hello | Hello world | --- |
31+
| hello | Hello world for 128x128 display | --- |
32+
| hello_80x160 | Hello world for 80x160 display | note offsets |
33+
| hello_128x160 | Hello world for 128x160 display | --- |
3234
| text | Text + fonts | --- |
3335
| graphics | Graphics | --- |
3436
| functions_fps | Functions(like rotate, scroll) + FPS tests | --- |
@@ -86,6 +88,8 @@ Default is "TFT_ST7735R_Red". If you select the wrong one if may still work but
8688
| 4 | ST7735S Black Tab | TFT_ST7735S_Black | Red PCB v1.2, 1.8 inch, 128x160 pixels |
8789
| 5 | ST7735S 80x160 | TFT_ST7735S_80160 | Blue PCB .96 inch 80x160 pixels |
8890

91+
The ST7735S 80x160 requires an offset of (26,1) or (24,0)
92+
8993
## Hardware
9094

9195
Connections as setup in main.cpp test file.

extra/image/filesystem.png

-1.49 KB
Loading

include/displaylib_16/gc9107.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class GC9107_TFT : public displaylib_16_graphics
102102
// Screen Offsets
103103
uint8_t _colOffset = 0; /**< Portrait col (X) dead-RAM offset – user supplied */
104104
uint8_t _rowOffset = 0; /**< Portrait row (Y) dead-RAM offset – user supplied */
105-
uint8_t _xstart = 0; /**< Applied offset for current rotation (X axis) */
106-
uint8_t _ystart = 0; /**< Applied offset for current rotation (Y axis) */
107105

108106
// GC9107 registers + Commands
109107
static constexpr uint8_t GC9107_SLPIN = 0x10; /**< Enter Sleep Mode */

src/displaylib_16/gc9107.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,29 +183,29 @@ void GC9107_TFT::TFTsetRotation(display_rotate_e mode) {
183183
case Degrees_0 : // 0x00
184184
_width =_widthStartTFT;
185185
_height = _heightStartTFT;
186-
_xstart = _colOffset;
187-
_ystart = _rowOffset;
186+
_XStart = _colOffset;
187+
_YStart = _rowOffset;
188188
break;
189189
case Degrees_90:
190190
madctl |= (MADCTL_FLAGS_t::ML | MADCTL_FLAGS_t::MV | MADCTL_FLAGS_t::MX ); // 0x70 0111-0000;
191191
_width =_heightStartTFT;
192192
_height = _widthStartTFT;
193-
_xstart = _rowOffset;
194-
_ystart = _colOffset;
193+
_XStart = _rowOffset;
194+
_YStart = _colOffset;
195195
break;
196196
case Degrees_180:
197197
madctl |= (MADCTL_FLAGS_t::MY | MADCTL_FLAGS_t::MX ); // 0xC0 1100-0000;
198198
_width =_widthStartTFT;
199199
_height = _heightStartTFT;
200-
_xstart = _RAM_WIDTH - _widthStartTFT - _colOffset;
201-
_ystart = _RAM_HEIGHT - _heightStartTFT - _rowOffset;
200+
_XStart = _RAM_WIDTH - _widthStartTFT - _colOffset;
201+
_YStart = _RAM_HEIGHT - _heightStartTFT - _rowOffset;
202202
break;
203203
case Degrees_270:
204204
madctl |= (MADCTL_FLAGS_t::MY |MADCTL_FLAGS_t::MV ); // 0xA0 1010-0000;
205205
_width =_heightStartTFT;
206206
_height = _widthStartTFT;
207-
_xstart = _RAM_HEIGHT - _heightStartTFT - _rowOffset;
208-
_ystart = _RAM_WIDTH - _widthStartTFT - _colOffset;
207+
_XStart = _RAM_HEIGHT - _heightStartTFT - _rowOffset;
208+
_YStart = _RAM_WIDTH - _widthStartTFT - _colOffset;
209209
break;
210210
}
211211
writeCommand(GC9107_MADCTL);
@@ -281,10 +281,10 @@ void GC9107_TFT::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h)
281281
h = y1;
282282
}
283283
// Translate panel coordinates → VRAM coordinates
284-
x1 += _xstart;
285-
w += _xstart;
286-
y1 += _ystart;
287-
h += _ystart;
284+
x1 += _XStart;
285+
w += _XStart;
286+
y1 += _YStart;
287+
h += _YStart;
288288
// Send to display coordinates
289289
uint8_t x1Higher = (x1 >> 8) ;
290290
uint8_t x1Lower = (x1 & 0xFF);

0 commit comments

Comments
 (0)