Add MRB3511 support

This commit is contained in:
fvanroie 2020-04-09 22:38:36 +02:00
parent ade134fdfd
commit 2463853d3f
2 changed files with 160 additions and 26 deletions

View File

@ -15,12 +15,12 @@
[platformio]
default_envs =
; Comment unneeded environments or create extra
esp32dev
esp32dev-mrb3511
d1mini-lolintft24
d1mini32-lolintft24
lolind32pro-lolintft24
esp12e-st7735
;d132-unoshield
d132-unoshield
;nodemcu32s-raspi
; -- Location of the configuration files
@ -127,6 +127,14 @@ raspberrypi =
-D SPI_TOUCH_FREQUENCY=2500000
-D USER_SETUP_LOADED=1
-D SUPPORT_TRANSACTIONS
mrb3511 =
-D ESP32_PARALLEL=1
-D ILI9488_DRIVER=1
-D TFT_WIDTH=320
-D TFT_HEIGHT=480
-D TFT_ROTATION=0 ; 0=0, 1=90, 2=180 or 3=270 degree
-D USER_SETUP_LOADED=1
-D SUPPORT_TRANSACTIONS
; Rotation params:
; 0 - 0 deg
@ -142,7 +150,7 @@ raspberrypi =
;***************************************************
; Generic ESP32 build
;***************************************************
[env:esp32dev]
[env:esp32dev-mrb3511]
platform = espressif32
board = esp32dev
upload_port = COM3 ; Change to the correct port
@ -154,19 +162,33 @@ debug_init_break = tbreak setup
build_flags =
${flags.esp32_flags}
; -- TFT_eSPI build options ------------------------
${lcd.lolin24}
${pins.vspi32}
-D TFT_DC=2
-D TFT_CS=5
-D TFT_RST=4
-D TFT_BCKL=-1 ; None, configurable via web UI (e.g. 20)
-D TOUCH_CS=21
${lcd.mrb3511}
-D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4)
-D TFT_CS=33 ; Chip select control pin
-D TFT_DC=15 ; =RS; Data Command control pin - must use a pin in the range 0-31
-D TFT_RST=32 ; Reset pin
-D TFT_WR=4 ; Write strobe control pin - must use a pin in the range 0-31
-D TFT_RD=2
-D TFT_D0=12 ; Must use pins in the range 0-31 for the data bus
-D TFT_D1=13 ; so a single register write sets/clears all bits
-D TFT_D2=26
-D TFT_D3=25
-D TFT_D4=17
-D TFT_D5=16
-D TFT_D6=27
-D TFT_D7=14
-D TOUCH_DRIVER=1 ; GT911 Capacitive touch panel driver
-D TOUCH_SDA=21
-D TOUCH_SCL=22
-D TOUCH_IRQ=23 ; not used or 23
-D TOUCH_RST=-1 ; not used, connected to 3.3V
; -- Debugging options -----------------------------
; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
; -- Library options -------------------------------
lib_deps =
${env.lib_deps}
https://github.com/netwizeBE/arduino-goodix.git ; GT911 touch screen driver
src_filter = +<*> +<../drivers/stm32f429_disco>
@ -177,8 +199,8 @@ src_filter = +<*> +<../drivers/stm32f429_disco>
[env:nodemcu32s-raspi]
platform = espressif32
board = nodemcu-32s
;upload_port = COM3 ; Change to the correct port
;monitor_port = COM3 ; Change to the correct port
upload_port = COM3 ; Change to the correct port
monitor_port = COM3 ; Change to the correct port
monitor_speed = 115200
debug_tool = esp-prog
debug_init_break = tbreak setup
@ -190,7 +212,7 @@ build_flags =
${pins.vspi32}
-D TFT_CS=5
-D TFT_DC=4
-D TFT_RST=-1
-D TFT_RST=32
-D TOUCH_CS=22
; -- Debugging options -----------------------------
@ -207,9 +229,11 @@ lib_deps =
[env:d132-unoshield]
platform = espressif32
board = esp32dev
upload_port = COM8 ; Change to the correct port
monitor_port = COM8 ; Change to the correct port
upload_protocol = espota ; Use ArduinoOTA after flashing over serial
upload_port = 10.1.0.137 ; IP of the ESP
upload_flags =
monitor_speed = 115200
monitor_port = COM7
build_flags =
${flags.esp32_flags}
@ -218,11 +242,12 @@ build_flags =
-D TFT_WIDTH=320
-D TFT_HEIGHT=480
-D USER_SETUP_LOADED=1
-D ST7796_DRIVER=1 ;3.95inch Arduino Display-UNO
; -D ILI9486_DRIVER=1 ;3.5inch Arduino Display-UNO
;-D ST7796_DRIVER=1 ;3.95inch Arduino Display-UNO
-D ILI9486_DRIVER=1 ;3.5inch Arduino Display-UNO
${pins.vspi32}
-D ESP32_PARALLEL=1
-D PSEUDO_8_BIT=1
-D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4)
-D TFT_CS=33 ; Chip select control pin
-D TFT_DC=15 ; Data Command control pin - must use a pin in the range 0-31
-D TFT_RST=32 ; Reset pin
@ -236,10 +261,10 @@ build_flags =
-D TFT_D5=16
-D TFT_D6=27
-D TFT_D7=14
;-D TOUCH_CS=5
;-D SPI_FREQUENCY=40000000
;-D SPI_TOUCH_FREQUENCY=2500000
;-D SPI_READ_FREQUENCY=20000000
-D SD_CS=5
-D SPI_FREQUENCY=40000000
;-D SPI_TOUCH_FREQUENCY=2500000 ; Uses ADC instead
-D SPI_READ_FREQUENCY=20000000
; -- Debugging options -----------------------------
; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
@ -317,9 +342,9 @@ build_flags =
${flags.esp8266_flags}
; -- TFT_eSPI build options ------------------------
${lcd.lolin24}
;-D TFT_MISO=12 ;D6 Default HSPI
;-D TFT_MOSI=13 ;D7 Default HSPI
;-D TFT_SCLK=14 ;D5 Default HSPI
;-D TFT_MISO=12 ;D6 Use default HSPI
;-D TFT_MOSI=13 ;D7 Use default HSPI
;-D TFT_SCLK=14 ;D5 Use default HSPI
-D TFT_DC=15 ;D8
-D TFT_CS=16 ;D0
-D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4)

View File

@ -4,7 +4,6 @@
#include "lv_conf.h"
#include "lvgl.h"
#include "lv_fs_if.h"
//#include "Touchscreen.h" // For Uno Shield or ADC based resistive touchscreens
#include "TFT_eSPI.h"
#include "lv_zifont.h"
@ -381,7 +380,9 @@ static void IRAM_ATTR lv_tick_handler(void)
// return false; /*Return `false` because we are not buffering and no more data to read*/
// }
#ifndef TOUCH_CS
#if TOUCH_DRIVER == 2
#include "Touchscreen.h" // For Uno Shield or ADC based resistive touchscreens
boolean Touch_getXY(uint16_t * x, uint16_t * y, boolean showTouch)
{
static const int coords[] = {3800, 500, 300, 3800}; // portrait - left, right, top, bottom
@ -434,6 +435,103 @@ boolean Touch_getXY(uint16_t * x, uint16_t * y, boolean showTouch)
}
#endif
#if TOUCH_DRIVER == 1
#include <Wire.h>
#include "Goodix.h"
#define INT_PIN (TOUCH_IRQ)
#define RST_PIN (TOUCH_RST) // -1 if pin is connected to VCC else set pin number
static Goodix touch = Goodix();
static int8_t GT911_num_touches;
static GTPoint * GT911_points;
void handleTouch(int8_t contacts, GTPoint * points)
{
GT911_num_touches = contacts;
GT911_points = points;
Log.trace("Contacts: %d", contacts);
for(uint8_t i = 0; i < contacts; i++) {
Log.trace("C%d: #%d %d,%d s:%d", i, points[i].trackId, points[i].x, points[i].y, points[i].area);
yield();
}
}
bool IRAM_ATTR GT911_getXY(uint16_t * touchX, uint16_t * touchY, bool debug)
{
static GTPoint points[5];
int16_t contacts = touch.readInput((uint8_t *)&points);
if(contacts <= 0) return false;
if(debug) {
Serial.print(contacts);
Serial.print(" : ");
Serial.print(points[0].x);
Serial.print(" x ");
Serial.println(points[0].y);
}
*touchX = points[0].x;
*touchY = points[0].y;
return true;
// ALTERNATE REGISTER READ METHOD
// static uint8_t touchBuffer[6];
// uint16_t first = 0x814E; // 8150
// uint16_t last = 0x8153;
// uint16_t len = first - last + 1;
// uint8_t res = touch.read(first, touchBuffer, len);
// if(res != GOODIX_OK || touchBuffer[0] - 128 == 0) return false;
// *touchX = touchBuffer[2] + touchBuffer[3] * 256;
// *touchY = touchBuffer[4] + touchBuffer[5] * 256;
// if (debug) {
// Serial.print(touchBuffer[0] - 128);
// Serial.print(" : ");
// Serial.print(*touchX);
// Serial.print(" x ");
// Serial.println(*touchY);
// }
// return true;
}
void touchStart()
{
if(touch.begin(INT_PIN, RST_PIN) != true) {
Serial.println("! Module reset failed");
} else {
Serial.println("Module reset OK");
}
Serial.print("Check ACK on addr request on 0x");
Serial.print(touch.i2cAddr, HEX);
Wire.beginTransmission(touch.i2cAddr);
int error = Wire.endTransmission();
if(error == 0) {
Serial.println(": SUCCESS");
} else {
Serial.print(": ERROR #");
Serial.println(error);
}
}
void GT911_setup()
{
Wire.setClock(400000);
Wire.begin();
delay(300);
touch.setHandler(handleTouch);
touchStart();
Log.verbose(F("Goodix GT911x touch driver started"));
}
#endif
bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
{
//#ifdef TOUCH_CS
@ -441,6 +539,9 @@ bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t *
#ifdef TOUCH_CS
bool touched = tft.getTouch(&touchX, &touchY, 600);
#elif TOUCH_DRIVER == 1
// return false;
bool touched = GT911_getXY(&touchX, &touchY, true);
#else
bool touched = Touch_getXY(&touchX, &touchY, false);
#endif
@ -638,12 +739,20 @@ void guiSetup()
/*Initialize the graphics library's tick*/
tick.attach_ms(guiTickPeriod, lv_tick_handler);
#if TOUCH_DRIVER == 1
GT911_setup();
#endif
}
void IRAM_ATTR guiLoop()
{
lv_task_handler(); /* let the GUI do its work */
guiCheckSleep();
#if TOUCH_DRIVER == 1
touch.loop();
#endif
}
void guiStop()