Skip to content

Commit a06a578

Browse files
authored
Merge pull request loboris#4 from frhun/ttgo-t-display
Adding offset and inversion handling
2 parents 0933f83 + 8d7dc5a commit a06a578

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

components/tft/tft.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ uint32_t tft_tp_calx = 7472920;
7979
uint32_t tft_tp_caly = 122224794;
8080

8181
dispWin_t tft_dispWin = {
82-
.x1 = 0,
83-
.y1 = 0,
84-
.x2 = DEFAULT_TFT_DISPLAY_WIDTH,
85-
.y2 = DEFAULT_TFT_DISPLAY_HEIGHT,
82+
.x1 = TFT_STATIC_WIDTH_OFFSET,
83+
.y1 = TFT_STATIC_HEIGHT_OFFSET,
84+
.x2 = DEFAULT_TFT_DISPLAY_WIDTH + TFT_STATIC_WIDTH_OFFSET,
85+
.y2 = DEFAULT_TFT_DISPLAY_HEIGHT + TFT_STATIC_HEIGHT_OFFSET,
8686
};
8787

8888
Font tft_cfont = {
@@ -296,7 +296,7 @@ void TFT_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color) {
296296

297297
//==================================
298298
void TFT_fillScreen(color_t color) {
299-
TFT_pushColorRep(0, 0, tft_width-1, tft_height-1, color, (uint32_t)(tft_height*tft_width));
299+
TFT_pushColorRep(TFT_STATIC_X_OFFSET, TFT_STATIC_Y_OFFSET, tft_width + TFT_STATIC_X_OFFSET -1, tft_height + TFT_STATIC_Y_OFFSET -1, color, (uint32_t)(tft_height*tft_width));
300300
}
301301

302302
//==================================
@@ -2056,10 +2056,10 @@ void TFT_setRotation(uint8_t rot) {
20562056
_tft_setRotation(rot);
20572057
}
20582058

2059-
tft_dispWin.x1 = 0;
2060-
tft_dispWin.y1 = 0;
2061-
tft_dispWin.x2 = tft_width-1;
2062-
tft_dispWin.y2 = tft_height-1;
2059+
tft_dispWin.x1 = TFT_STATIC_X_OFFSET;
2060+
tft_dispWin.y1 = TFT_STATIC_Y_OFFSET;
2061+
tft_dispWin.x2 = tft_width + TFT_STATIC_X_OFFSET -1;
2062+
tft_dispWin.y2 = tft_height + TFT_STATIC_Y_OFFSET -1;
20632063

20642064
TFT_fillScreen(tft_bg);
20652065
}
@@ -2157,24 +2157,24 @@ color_t HSBtoRGB(float _hue, float _sat, float _brightness) {
21572157
//=====================================================================
21582158
void TFT_setclipwin(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
21592159
{
2160-
tft_dispWin.x1 = x1;
2161-
tft_dispWin.y1 = y1;
2162-
tft_dispWin.x2 = x2;
2163-
tft_dispWin.y2 = y2;
2160+
tft_dispWin.x1 = x1 + TFT_STATIC_X_OFFSET;
2161+
tft_dispWin.y1 = y1 + TFT_STATIC_Y_OFFSET;
2162+
tft_dispWin.x2 = x2 + TFT_STATIC_X_OFFSET;
2163+
tft_dispWin.y2 = y2 + TFT_STATIC_Y_OFFSET;
21642164

2165-
if (tft_dispWin.x2 >= tft_width) tft_dispWin.x2 = tft_width-1;
2166-
if (tft_dispWin.y2 >= tft_height) tft_dispWin.y2 = tft_height-1;
2165+
if (tft_dispWin.x2 >= tft_width + TFT_STATIC_X_OFFSET) tft_dispWin.x2 = tft_width + TFT_STATIC_X_OFFSET -1;
2166+
if (tft_dispWin.y2 >= tft_height + TFT_STATIC_Y_OFFSET) tft_dispWin.y2 = tft_height + TFT_STATIC_Y_OFFSET -1;
21672167
if (tft_dispWin.x1 > tft_dispWin.x2) tft_dispWin.x1 = tft_dispWin.x2;
21682168
if (tft_dispWin.y1 > tft_dispWin.y2) tft_dispWin.y1 = tft_dispWin.y2;
21692169
}
21702170

21712171
//=====================
21722172
void TFT_resetclipwin()
21732173
{
2174-
tft_dispWin.x2 = tft_width-1;
2175-
tft_dispWin.y2 = tft_height-1;
2176-
tft_dispWin.x1 = 0;
2177-
tft_dispWin.y1 = 0;
2174+
tft_dispWin.x2 = tft_width + TFT_STATIC_X_OFFSET -1;
2175+
tft_dispWin.y2 = tft_height + TFT_STATIC_Y_OFFSET -1;
2176+
tft_dispWin.x1 = TFT_STATIC_X_OFFSET;
2177+
tft_dispWin.y1 = TFT_STATIC_Y_OFFSET;
21782178
}
21792179

21802180
//==========================================================================

components/tft/tftspi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ void TFT_display_init()
936936

937937
// Clear screen
938938
_tft_setRotation(PORTRAIT);
939-
TFT_pushColorRep(0, 0, tft_width-1, tft_height-1, (color_t){0,0,0}, (uint32_t)(tft_height*tft_width));
939+
TFT_pushColorRep(TFT_STATIC_WIDTH_OFFSET, TFT_STATIC_HEIGHT_OFFSET, tft_width + TFT_STATIC_WIDTH_OFFSET -1, tft_height + TFT_STATIC_HEIGHT_OFFSET -1, (color_t){0,0,0}, (uint32_t)(tft_height*tft_width));
940940

941941
///Enable backlight
942942
#if PIN_NUM_BCKL

components/tft/tftspi.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,21 @@
157157
#elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 5
158158
//CONFIG FOR TTGO T-DISPLAY
159159
#define DEFAULT_DISP_TYPE DISP_TYPE_ST7789V
160-
#define DEFAULT_TFT_DISPLAY_WIDTH 240
161-
#define DEFAULT_TFT_DISPLAY_HEIGHT 320
160+
#define DEFAULT_TFT_DISPLAY_WIDTH 135
161+
#define DEFAULT_TFT_DISPLAY_HEIGHT 240
162+
163+
//Need to be defined together so they can be swapped for x;y when rotating
164+
#define TFT_STATIC_WIDTH_OFFSET 53
165+
#define TFT_STATIC_HEIGHT_OFFSET 40
166+
162167
#define DISP_COLOR_BITS_24 0x66
163168
#define DEFAULT_GAMMA_CURVE 0
164169
#define DEFAULT_SPI_CLOCK 20000000
165170
#define TFT_INVERT_ROTATION 0
166171
#define TFT_INVERT_ROTATION1 1
167172
#define TFT_RGB_BGR 0x00
173+
//To be used by user application for initialization
174+
#define TFT_START_COLORS_INVERTED
168175

169176
#define USE_TOUCH TOUCH_TYPE_NONE
170177

@@ -244,6 +251,17 @@
244251

245252
#endif // CONFIG_PREDEFINED_DISPLAY_TYPE
246253

254+
// Define offset generation, or ignore offsets if none are needed
255+
#ifdef TFT_STATIC_WIDTH_OFFSET
256+
#define TFT_STATIC_X_OFFSET (tft_orientation & 1 ? TFT_STATIC_HEIGHT_OFFSET : TFT_STATIC_WIDTH_OFFSET)
257+
#define TFT_STATIC_Y_OFFSET (tft_orientation & 1 ? TFT_STATIC_WIDTH_OFFSET : TFT_STATIC_HEIGHT_OFFSET)
258+
#else
259+
#define TFT_STATIC_WIDTH_OFFSET 0
260+
#define TFT_STATIC_X_OFFSET 0
261+
#define TFT_STATIC_HEIGHT_OFFSET 0
262+
#define TFT_STATIC_Y_OFFSET 0
263+
#endif
264+
247265

248266
// ##############################################################
249267
// #### Global variables ####

main/tft_demo.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static void test_times() {
351351
tstart = clock();
352352
for (int n=0; n<1000; n++) {
353353
if (gsline) memcpy(color_line, gsline, tft_width*3);
354-
send_data(0, 40+(n&63), tft_dispWin.x2-tft_dispWin.x1, 40+(n&63), (uint32_t)(tft_dispWin.x2-tft_dispWin.x1+1), color_line);
354+
send_data(0 + TFT_STATIC_X_OFFSET, 40+(n&63) + TFT_STATIC_Y_OFFSET, tft_dispWin.x2-tft_dispWin.x1 + TFT_STATIC_X_OFFSET , 40+(n&63) + TFT_STATIC_Y_OFFSET, (uint32_t)(tft_dispWin.x2-tft_dispWin.x1+1), color_line);
355355
wait_trans_finish(1);
356356
}
357357
t2 = clock() - tstart;
@@ -1344,6 +1344,9 @@ void app_main()
13441344

13451345
printf("SPI: display init...\r\n");
13461346
TFT_display_init();
1347+
#ifdef TFT_START_COLORS_INVERTED
1348+
TFT_invertDisplay(1);
1349+
#endif
13471350
printf("OK\r\n");
13481351
#if USE_TOUCH == TOUCH_TYPE_STMPE610
13491352
stmpe610_Init();

0 commit comments

Comments
 (0)