lovyan03 / LovyanGFX

SPI LCD graphics library for ESP32 (ESP-IDF/ArduinoESP32) / ESP8266 (ArduinoESP8266) / SAMD51(Seeed ArduinoSAMD51)
Other
1.19k stars 209 forks source link

add RA8875 Touch #605

Closed tobi807 closed 3 months ago

tobi807 commented 3 months ago

Added two header files to utilize the touch functionality of the RA8875 display driver. Copied from existing touch drivers, did'nt understand the meaning of all functions and variables but works so far. display.calibrateTouch(...) and subsequent transfomation in display coordinates works nicely with the driver.

Sample Config

lgfx::Touch_RA8875  _touch_instance;

...

{ // タッチスクリーン制御の設定を行います。(必要なければ削除)
      auto cfg = _touch_instance.config();

      // SPI接続の場合
      cfg.bus_shared = true; // 画面と共通のバスを使用している場合 trueを設定
      cfg.spi_host = VSPI_HOST;// 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
      cfg.freq = 1000000;     // SPIクロックを設定
      cfg.pin_sclk = 18;
      cfg.pin_mosi = 23;
      cfg.pin_miso = 19;
      cfg.pin_cs   =  5;     //   CSが接続されているピン番号

      _touch_instance.config(cfg);
      _panel_instance.setTouch(&_touch_instance);  // タッチスクリーンをパネルにセットします。
}
tobozo commented 3 months ago

Hi, thanks for your contribution :+1:

The test build failed for esp-idf, this is because digitalWrite() (an arduino-only function) is used in Touch_RA8875::init(void). Also digitalWrite() uses a hardcoded pin value.

    // enable Touch Panel
    // RA8875_TPCR0: RA8875_TPCR0_ENABLE | RA8875_TPCR0_WAIT_4096CLK | RA8875_TPCR0_WAKEENABLE | adcClk
    digitalWrite(4, HIGH);
    writeRegister8(0x70, 0x80 | 0x30 | 0x08 | 0x04); // 10mhz max!
    digitalWrite(4, LOW);

These two points should be addressed:

1) assign GPIO pin 4 from the configuration block

    auto cfg = _touch_instance.config();
    cfg.pin_int = GPIO_NUM_4;

2) use lgfx gpio functions instead of digitalWrite():

    lgfx::gpio_hi(_cfg.pin_int);
    lgfx::pinMode(_cfg.pin_int, pin_mode_t::output);
    writeRegister8(0x70, 0x80 | 0x30 | 0x08 | 0x04); // 10mhz max!
    lgfx::gpio_lo(_cfg.pin_int);
tobi807 commented 3 months ago

Ahh my bad. The digitalWrite is only used for my debugging. I'll remove it and create a new pull request