Git Product home page Git Product logo

Comments (8)

tobozo avatar tobozo commented on September 28, 2024

hi,

thanks for your feedback 👍

cfg.freq_write = 10 * 1000 * 1000; (=10MHz) seems rather low considering the parent model ST7789 can handle 40-80MHz

the HardwareTest example code uses Panel_ILI9342 as the panel object but your display is ST7789P3, unless both display use the same registers, the init sequence from ILI9342 is just ignored and has no effect on the ST7789P3.

I took the 'working' init sequence from the HardwareTest to create a Panel_ST7789P3 class, please let me know if this works for you:

src/lgfx/v1/panel/Panel_ST7789P3.hpp

/*----------------------------------------------------------------------------/
 * Lovyan GFX - Graphics library for embedded devices.
 *
 O *riginal Source:
 https://github.com/lovyan03/LovyanGFX/

 Licence:
 [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt)

 Author:
 [lovyan03](https://twitter.com/lovyan03)

 Contributors:
 [ciniml](https://github.com/ciniml)
 [mongonta0716](https://github.com/mongonta0716)
 [tobozo](https://github.com/tobozo)
 /----------------------------------------------------------------------------*/
#pragma once

#include "Panel_LCD.hpp"

namespace lgfx
{
    inline namespace v1
    {
        //----------------------------------------------------------------------------

        struct Panel_ST7789P3  : public Panel_LCD
        {
            Panel_ST7789P3(void)
            {
                _cfg.panel_height = _cfg.memory_height = 320;
                _cfg.dummy_read_pixel = 16;
            }

        protected:

            const uint8_t* getInitCommands(uint8_t listno) const override {

                static constexpr uint8_t list0[] = {
                    0x11, 0+CMD_INIT_DELAY, 120,
                    0x36, 1, 0x00,
                    0x3A, 1, 0x05,
                    0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
                    0xb7, 1, 0x56,
                    0xbb, 1, 0x1d,
                    0xc0, 1, 0x2c,
                    0xc2, 1, 0x01,
                    0xc3, 1, 0x0f,
                    0xc6, 1, 0x0f,
                    0xd0, 1, 0xa7,
                    0xd0, 2, 0xa4, 0xa1,
                    0xd6, 1, 0xa1,
                    0xe0, 14, 0xF0, 0x02, 0x07, 0x05, 0x06, 0x14, 0x2F, 0x54, 0x46, 0x38, 0x13, 0x11, 0x2E, 0x35,
                    0xe1, 14, 0xF0, 0x08, 0x0C, 0x0C, 0x09, 0x05, 0x2F, 0x43, 0x46, 0x36, 0x10, 0x12, 0x2C, 0x32,
                    0x21, 0,
                    0x29, 0,
                    0x2c, 0+CMD_INIT_DELAY, 100,
                    0x2a, 4, 0x00, 0x00, 0x01, 0x3f,
                    0x2b, 4, 0x00, 0x00, 0x00, 0xef,
                    0x2c, 0,
                    0xFF,0xFF, // end
                };
                switch (listno) {
                    case 0: return list0;
                    default: return nullptr;
                }
            }
        };

        //----------------------------------------------------------------------------
    }
}

from lovyangfx.

lbuque avatar lbuque commented on September 28, 2024

@tobozo Thanks for your reply and helping me find the bug.

I followed your suggestion and tried using Panel_ST7789 and Panel_ST7789P3, but found that tft still did not work properly.

I am about to connect a logic analyzer to the board to check the spi timings.

Finally, thank you again for your quick response.

from lovyangfx.

lbuque avatar lbuque commented on September 28, 2024

I lowered the spi frequency to 4MHZ to prevent the logic from interfering when collecting data, however, I could only collect 0x00.

image

What am I doing wrong?

from lovyangfx.

tobozo avatar tobozo commented on September 28, 2024

pin assignation seems wrong (same pin for miso and mosi?):

#define MOSI_PIN 3
#define MISO_PIN 3 // should be -1 according to SPI_3Wire_Interface_Init() !!

anyway, given the contents of platformio.ini it's already a miracle the esp even starts:

  • it selects esp32-c3, but should select esp32-s3
  • it uses an old version of espressif core (2.1.4)
  • it sets the cpu speed to 160MHz

please try with this platformio env instead, it'll use the latest espressif core:

[env:stamp-s3]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.04/platform-espressif32.zip
board = m5stack-stamps3
framework = arduino
lib_deps =
    mathertel/OneButton@^2.0.3
    bblanchon/ArduinoJson @ ^6.21.3
    lovyan03/LovyanGFX @ 1.1.16
upload_speed = 1500000
upload_protocol = esptool
monitor_speed = 115200
build_flags =
    -D CORE_DEBUG_LEVEL=3
board_build.filesystem = littlefs

and here's a fixed version of your sketch:

#include <LovyanGFX.hpp>

namespace lgfx
{
  inline namespace v1
  {
    //----------------------------------------------------------------------------

    struct Panel_ST7789P3  : public Panel_LCD
    {
      Panel_ST7789P3(void)
      {
        _cfg.panel_height = _cfg.memory_height = 320;
        _cfg.dummy_read_pixel = 16;
      }

    protected:

      const uint8_t* getInitCommands(uint8_t listno) const override {

        static constexpr uint8_t list0[] = {
          0x11, 0+CMD_INIT_DELAY, 120,
          0x36, 1, 0x00,
          0x3A, 1, 0x05,
          0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
          0xb7, 1, 0x56,
          0xbb, 1, 0x1d,
          0xc0, 1, 0x2c,
          0xc2, 1, 0x01,
          0xc3, 1, 0x0f,
          0xc6, 1, 0x0f,
          0xd0, 1, 0xa7,
          0xd0, 2, 0xa4, 0xa1,
          0xd6, 1, 0xa1,
          0xe0, 14, 0xF0, 0x02, 0x07, 0x05, 0x06, 0x14, 0x2F, 0x54, 0x46, 0x38, 0x13, 0x11, 0x2E, 0x35,
          0xe1, 14, 0xF0, 0x08, 0x0C, 0x0C, 0x09, 0x05, 0x2F, 0x43, 0x46, 0x36, 0x10, 0x12, 0x2C, 0x32,
          0x21, 0,
          0x29, 0,
          0x2c, 0+CMD_INIT_DELAY, 100,
          0x2a, 4, 0x00, 0x00, 0x01, 0x3f,
          0x2b, 4, 0x00, 0x00, 0x00, 0xef,
          0x2c, 0,
          0xFF,0xFF, // end
        };
        switch (listno) {
          case 0: return list0;
          default: return nullptr;
        }
      }
    };

    //----------------------------------------------------------------------------
  }
}


class C3GFX: public lgfx::LGFX_Device {
  lgfx::Panel_ST7789P3 _panel_instance;
  lgfx::Bus_SPI        _spi_bus_instance;
  lgfx::Light_PWM      _light_instance;

public:

  C3GFX() {

    {
      auto cfg = _light_instance.config();
      cfg.pin_bl = GPIO_NUM_5;
      cfg.invert = false;
      cfg.freq = 1000;
      cfg.pwm_channel = 5;
      _light_instance.config(cfg);
    }

    {
      auto cfg = _spi_bus_instance.config();
      //cfg.spi_host = LCD_HOST;
      cfg.spi_mode = 0;
      cfg.freq_write = 40000000;
      cfg.freq_read = 16000000;
      cfg.spi_3wire = true;
      cfg.pin_sclk = GPIO_NUM_1;
      cfg.pin_mosi = GPIO_NUM_3;
      cfg.pin_miso = -1;
      cfg.pin_dc = -1;
      _spi_bus_instance.config(cfg);
    }

    {
      auto cfg = _panel_instance.config();
      cfg.invert       = false;
      cfg.pin_cs       = GPIO_NUM_2;
      cfg.pin_rst      = GPIO_NUM_4;
      cfg.pin_busy     = -1;
      cfg.panel_width  = 320;
      cfg.panel_height = 240;
      cfg.offset_x     = 0;
      cfg.offset_y     = 0;
      cfg.rgb_order = false;
      _panel_instance.setBus(&_spi_bus_instance);
      _panel_instance.config(cfg);
    }

    _panel_instance.setLight(&_light_instance);
    setPanel(&_panel_instance);
  };

  // override the init()
  inline bool init(void)
  {
    // HW_Reset();
    lgfx::pinMode(GPIO_NUM_4, lgfx::pin_mode_t::output);
    lgfx::gpio_hi(GPIO_NUM_4);
    lgfx::delay(100);
    lgfx::gpio_lo(GPIO_NUM_4);
    lgfx::delay(120);
    lgfx::gpio_hi(GPIO_NUM_4);
    delay(120); // ms

    /* Lgfx */
    return lgfx::LGFX_Device::init();
  }


};

C3GFX lcd;

void setup()
{
  Serial.begin(115200);
  lcd.init();
  lcd.println("Hello World");
  delay(1000);
  lcd.clear(TFT_RED);
}

void loop()
{
}

from lovyangfx.

lbuque avatar lbuque commented on September 28, 2024

@tobozo The chip I use is esp32-c3. I don't have stamps3 now.

from lovyangfx.

lovyan03 avatar lovyan03 commented on September 28, 2024

hello, @lbuque
I think you're misunderstanding something.
3Wire mode is a mode that transmits and receives via the MOSI pin, not a mode that omits the D/C pin.

from lovyangfx.

lbuque avatar lbuque commented on September 28, 2024

@lovyan03 Thank you for your answer!

Will lgfx support SPI3WIRE 9BIT?

image

If you don't consider it for the time being, I think this issue can be closed.

from lovyangfx.

lbuque avatar lbuque commented on September 28, 2024

Thanks for your reply! I think SPI3WIRE 9BIT is unreasonable, this issue will be closed. I will use other TFT.

from lovyangfx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.