Skip to content

Commit

Permalink
Merge pull request #4 from frhun/ttgo-t-display
Browse files Browse the repository at this point in the history
Adding offset and inversion handling
  • Loading branch information
jeremyjh authored Mar 26, 2020
2 parents 0933f83 + 8d7dc5a commit a06a578
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
38 changes: 19 additions & 19 deletions components/tft/tft.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ uint32_t tft_tp_calx = 7472920;
uint32_t tft_tp_caly = 122224794;

dispWin_t tft_dispWin = {
.x1 = 0,
.y1 = 0,
.x2 = DEFAULT_TFT_DISPLAY_WIDTH,
.y2 = DEFAULT_TFT_DISPLAY_HEIGHT,
.x1 = TFT_STATIC_WIDTH_OFFSET,
.y1 = TFT_STATIC_HEIGHT_OFFSET,
.x2 = DEFAULT_TFT_DISPLAY_WIDTH + TFT_STATIC_WIDTH_OFFSET,
.y2 = DEFAULT_TFT_DISPLAY_HEIGHT + TFT_STATIC_HEIGHT_OFFSET,
};

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

//==================================
void TFT_fillScreen(color_t color) {
TFT_pushColorRep(0, 0, tft_width-1, tft_height-1, color, (uint32_t)(tft_height*tft_width));
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));
}

//==================================
Expand Down Expand Up @@ -2056,10 +2056,10 @@ void TFT_setRotation(uint8_t rot) {
_tft_setRotation(rot);
}

tft_dispWin.x1 = 0;
tft_dispWin.y1 = 0;
tft_dispWin.x2 = tft_width-1;
tft_dispWin.y2 = tft_height-1;
tft_dispWin.x1 = TFT_STATIC_X_OFFSET;
tft_dispWin.y1 = TFT_STATIC_Y_OFFSET;
tft_dispWin.x2 = tft_width + TFT_STATIC_X_OFFSET -1;
tft_dispWin.y2 = tft_height + TFT_STATIC_Y_OFFSET -1;

TFT_fillScreen(tft_bg);
}
Expand Down Expand Up @@ -2157,24 +2157,24 @@ color_t HSBtoRGB(float _hue, float _sat, float _brightness) {
//=====================================================================
void TFT_setclipwin(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
tft_dispWin.x1 = x1;
tft_dispWin.y1 = y1;
tft_dispWin.x2 = x2;
tft_dispWin.y2 = y2;
tft_dispWin.x1 = x1 + TFT_STATIC_X_OFFSET;
tft_dispWin.y1 = y1 + TFT_STATIC_Y_OFFSET;
tft_dispWin.x2 = x2 + TFT_STATIC_X_OFFSET;
tft_dispWin.y2 = y2 + TFT_STATIC_Y_OFFSET;

if (tft_dispWin.x2 >= tft_width) tft_dispWin.x2 = tft_width-1;
if (tft_dispWin.y2 >= tft_height) tft_dispWin.y2 = tft_height-1;
if (tft_dispWin.x2 >= tft_width + TFT_STATIC_X_OFFSET) tft_dispWin.x2 = tft_width + TFT_STATIC_X_OFFSET -1;
if (tft_dispWin.y2 >= tft_height + TFT_STATIC_Y_OFFSET) tft_dispWin.y2 = tft_height + TFT_STATIC_Y_OFFSET -1;
if (tft_dispWin.x1 > tft_dispWin.x2) tft_dispWin.x1 = tft_dispWin.x2;
if (tft_dispWin.y1 > tft_dispWin.y2) tft_dispWin.y1 = tft_dispWin.y2;
}

//=====================
void TFT_resetclipwin()
{
tft_dispWin.x2 = tft_width-1;
tft_dispWin.y2 = tft_height-1;
tft_dispWin.x1 = 0;
tft_dispWin.y1 = 0;
tft_dispWin.x2 = tft_width + TFT_STATIC_X_OFFSET -1;
tft_dispWin.y2 = tft_height + TFT_STATIC_Y_OFFSET -1;
tft_dispWin.x1 = TFT_STATIC_X_OFFSET;
tft_dispWin.y1 = TFT_STATIC_Y_OFFSET;
}

//==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion components/tft/tftspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ void TFT_display_init()

// Clear screen
_tft_setRotation(PORTRAIT);
TFT_pushColorRep(0, 0, tft_width-1, tft_height-1, (color_t){0,0,0}, (uint32_t)(tft_height*tft_width));
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));

///Enable backlight
#if PIN_NUM_BCKL
Expand Down
22 changes: 20 additions & 2 deletions components/tft/tftspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,21 @@
#elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 5
//CONFIG FOR TTGO T-DISPLAY
#define DEFAULT_DISP_TYPE DISP_TYPE_ST7789V
#define DEFAULT_TFT_DISPLAY_WIDTH 240
#define DEFAULT_TFT_DISPLAY_HEIGHT 320
#define DEFAULT_TFT_DISPLAY_WIDTH 135
#define DEFAULT_TFT_DISPLAY_HEIGHT 240

//Need to be defined together so they can be swapped for x;y when rotating
#define TFT_STATIC_WIDTH_OFFSET 53
#define TFT_STATIC_HEIGHT_OFFSET 40

#define DISP_COLOR_BITS_24 0x66
#define DEFAULT_GAMMA_CURVE 0
#define DEFAULT_SPI_CLOCK 20000000
#define TFT_INVERT_ROTATION 0
#define TFT_INVERT_ROTATION1 1
#define TFT_RGB_BGR 0x00
//To be used by user application for initialization
#define TFT_START_COLORS_INVERTED

#define USE_TOUCH TOUCH_TYPE_NONE

Expand Down Expand Up @@ -244,6 +251,17 @@

#endif // CONFIG_PREDEFINED_DISPLAY_TYPE

// Define offset generation, or ignore offsets if none are needed
#ifdef TFT_STATIC_WIDTH_OFFSET
#define TFT_STATIC_X_OFFSET (tft_orientation & 1 ? TFT_STATIC_HEIGHT_OFFSET : TFT_STATIC_WIDTH_OFFSET)
#define TFT_STATIC_Y_OFFSET (tft_orientation & 1 ? TFT_STATIC_WIDTH_OFFSET : TFT_STATIC_HEIGHT_OFFSET)
#else
#define TFT_STATIC_WIDTH_OFFSET 0
#define TFT_STATIC_X_OFFSET 0
#define TFT_STATIC_HEIGHT_OFFSET 0
#define TFT_STATIC_Y_OFFSET 0
#endif


// ##############################################################
// #### Global variables ####
Expand Down
5 changes: 4 additions & 1 deletion main/tft_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static void test_times() {
tstart = clock();
for (int n=0; n<1000; n++) {
if (gsline) memcpy(color_line, gsline, tft_width*3);
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);
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);
wait_trans_finish(1);
}
t2 = clock() - tstart;
Expand Down Expand Up @@ -1344,6 +1344,9 @@ void app_main()

printf("SPI: display init...\r\n");
TFT_display_init();
#ifdef TFT_START_COLORS_INVERTED
TFT_invertDisplay(1);
#endif
printf("OK\r\n");
#if USE_TOUCH == TOUCH_TYPE_STMPE610
stmpe610_Init();
Expand Down

0 comments on commit a06a578

Please sign in to comment.