Skip to content

Commit

Permalink
Added routines for TTGO TFT display
Browse files Browse the repository at this point in the history
The dumb display has offsets from Zero... X and Y are offset to the visible area.
  • Loading branch information
RichardPar authored Feb 15, 2020
1 parent aa21772 commit 954110c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 70 deletions.
45 changes: 34 additions & 11 deletions components/tft/tftspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "freertos/task.h"
#include "esp_heap_caps.h"
#include "soc/spi_reg.h"
#include "driver/gpio.h"


// ====================================================
Expand All @@ -24,6 +25,10 @@ uint8_t gray_scale = 0;
// Spi clock for reading data from display memory in Hz
uint32_t max_rdclock = 8000000;

int _xoffset = 53;
int _yoffset = 40;


// Default display dimensions
int _width = DEFAULT_TFT_DISPLAY_WIDTH;
int _height = DEFAULT_TFT_DISPLAY_HEIGHT;
Expand Down Expand Up @@ -190,11 +195,20 @@ static void IRAM_ATTR disp_spi_transfer_addrwin(uint16_t x1, uint16_t x2, uint16

disp_spi->host->hw->cmd.usr = 1; // Start transfer

wd = (uint32_t)(x1>>8);
wd |= (uint32_t)(x1&0xff) << 8;
wd |= (uint32_t)(x2>>8) << 16;
wd |= (uint32_t)(x2&0xff) << 24;

if (_width < _height)
{
wd = (uint32_t)((x1+_xoffset)>>8);
wd |= (uint32_t)((x1+_xoffset)&0xff) << 8;
wd |= (uint32_t)((x2+_xoffset)>>8) << 16;
wd |= (uint32_t)((x2+_xoffset)&0xff) << 24;
} else
{
wd = (uint32_t)((x1+_yoffset)>>8);
wd |= (uint32_t)((x1+_yoffset)&0xff) << 8;
wd |= (uint32_t)((x2+_yoffset)>>8) << 16;
wd |= (uint32_t)((x2+_yoffset)&0xff) << 24;
}

while (disp_spi->host->hw->cmd.usr); // wait transfer end
gpio_set_level(PIN_NUM_DC, 1);
disp_spi->host->hw->data_buf[0] = wd;
Expand All @@ -207,11 +221,20 @@ static void IRAM_ATTR disp_spi_transfer_addrwin(uint16_t x1, uint16_t x2, uint16
disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 7;
disp_spi->host->hw->cmd.usr = 1; // Start transfer

wd = (uint32_t)(y1>>8);
wd |= (uint32_t)(y1&0xff) << 8;
wd |= (uint32_t)(y2>>8) << 16;
wd |= (uint32_t)(y2&0xff) << 24;

if (_width < _height)
{
wd = (uint32_t)((y1+_yoffset)>>8);
wd |= (uint32_t)((y1+_yoffset)&0xff) << 8;
wd |= (uint32_t)((y2+_yoffset)>>8) << 16;
wd |= (uint32_t)((y2+_yoffset)&0xff) << 24;
} else
{
wd = (uint32_t)((y1+_xoffset)>>8);
wd |= (uint32_t)((y1+_xoffset)&0xff) << 8;
wd |= (uint32_t)((y2+_xoffset)>>8) << 16;
wd |= (uint32_t)((y2+_xoffset)&0xff) << 24;
}

while (disp_spi->host->hw->cmd.usr);
gpio_set_level(PIN_NUM_DC, 1);

Expand Down Expand Up @@ -936,7 +959,7 @@ void TFT_display_init()
assert(ret==ESP_OK);

// Clear screen
_tft_setRotation(PORTRAIT);
_tft_setRotation(PORTRAIT);
TFT_pushColorRep(0, 0, _width-1, _height-1, (color_t){0,0,0}, (uint32_t)(_height*_width));

///Enable backlight
Expand Down
94 changes: 35 additions & 59 deletions components/tft/tftspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
// ** Set the correct configuration for M5Stack TFT
// ---------------------------------------------------------
#define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
#define DEFAULT_TFT_DISPLAY_WIDTH 320
#define DEFAULT_TFT_DISPLAY_HEIGHT 240
#define DEFAULT_TFT_DISPLAY_WIDTH 240
#define DEFAULT_TFT_DISPLAY_HEIGHT 320
#define DISP_COLOR_BITS_24 0x66
#define DEFAULT_GAMMA_CURVE 0
#define DEFAULT_SPI_CLOCK 26000000
Expand All @@ -126,65 +126,41 @@

#else

// Configuration for other boards, set the correct values for the display used
//----------------------------------------------------------------------------
#define DISP_COLOR_BITS_24 0x66
//#define DISP_COLOR_BITS_16 0x55 // Do not use!

// #############################################
// ### Set to 1 for some displays, ###
// for example the one on ESP-WROWER-KIT ###
// #############################################
#define TFT_INVERT_ROTATION 0
#define TFT_INVERT_ROTATION1 0

// ################################################
// ### SET TO 0X00 FOR DISPLAYS WITH RGB MATRIX ###
// ### SET TO 0X08 FOR DISPLAYS WITH BGR MATRIX ###
// ### For ESP-WROWER-KIT set to 0x00 ###
// ################################################
#define TFT_RGB_BGR 0x08

// ##############################################################
// ### Define ESP32 SPI pins to which the display is attached ###
// ##############################################################

// The pins configured here are the native spi pins for HSPI interface
// Any other valid pin combination can be used
#define PIN_NUM_MISO 19 // SPI MISO
#define PIN_NUM_MOSI 23 // SPI MOSI
#define PIN_NUM_CLK 18 // SPI CLOCK pin
#define PIN_NUM_CS 5 // Display CS pin
#define PIN_NUM_DC 26 // Display command/data pin
#define PIN_NUM_TCS 25 // Touch screen CS pin (NOT used if USE_TOUCH=0)

// --------------------------------------------------------------
// ** Set Reset and Backlight pins to 0 if not used !
// ** If you want to use them, set them to some valid GPIO number
#define PIN_NUM_RST 0 // GPIO used for RESET control

#define PIN_NUM_BCKL 0 // GPIO used for backlight control
#define PIN_BCKL_ON 0 // GPIO value for backlight ON
#define PIN_BCKL_OFF 1 // GPIO value for backlight OFF
// --------------------------------------------------------------

// #######################################################
// Set this to 1 if you want to use touch screen functions
// #######################################################
#define USE_TOUCH TOUCH_TYPE_NONE
// #######################################################

// #######################################################################
// Default display width (smaller dimension) and height (larger dimension)
// #######################################################################
#define DEFAULT_TFT_DISPLAY_WIDTH 240
#define DEFAULT_TFT_DISPLAY_HEIGHT 320
// #######################################################################
// ** Set the correct configuration for GENERIC
// --------------------------------------------------------
#define DEFAULT_DISP_TYPE DISP_TYPE_ST7789V
#define DEFAULT_TFT_DISPLAY_WIDTH 188-52
#define DEFAULT_TFT_DISPLAY_HEIGHT 240
#define DISP_COLOR_BITS_24 0x66
#define DEFAULT_GAMMA_CURVE 0
#define DEFAULT_SPI_CLOCK 26000000
#define TFT_INVERT_ROTATION 0
#define TFT_INVERT_ROTATION1 1
#define TFT_RGB_BGR 0x00

#define DEFAULT_GAMMA_CURVE 0
#define DEFAULT_SPI_CLOCK 26000000
#define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
//----------------------------------------------------------------------------
#define USE_TOUCH TOUCH_TYPE_NONE

//#define TFT_MOSI 19
//#define TFT_SCLK 18
//#define TFT_CS 5
//#define TFT_DC 16
//#define TFT_RST 23
//#define TFT_BL 4 // Display backlight control pin

#define PIN_NUM_MISO 0 // SPI MISO
#define PIN_NUM_MOSI 19 // SPI MOSI
#define PIN_NUM_CLK 18 // SPI CLOCK pin
#define PIN_NUM_CS 5 // Display CS pin
#define PIN_NUM_DC 16 // Display command/data pin
#define PIN_NUM_TCS 0 // Touch screen CS pin

#define PIN_NUM_RST 23 // GPIO used for RESET control
#define PIN_NUM_BCKL 4 // GPIO used for backlight control
#define PIN_BCKL_ON 1 // GPIO value for backlight ON
#define PIN_BCKL_OFF 0 // GPIO value for backlight OFF
// --------------------------------------------------------

#endif // CONFIG_EXAMPLE_ESP_WROVER_KIT

Expand Down Expand Up @@ -674,4 +650,4 @@ uint32_t stmpe610_getID();

// ===============================================================================

#endif
#endif

0 comments on commit 954110c

Please sign in to comment.