loboris / ESP32_TFT_library

Full featured TFT library for ESP32 with demo application
553 stars 219 forks source link

Question: Help for 3 Wire SPI? (Esp32 + St7789V) #62

Open shr1Khr opened 5 years ago

shr1Khr commented 5 years ago

Hi Loboris,

Could you please guide me where to modify the library for the 3wire SPI? The D/CM pin is missing, and that is used as 9th MSB.

ril3y commented 5 years ago

@shr1Khr I am in the same boat. I ordered about 50x of these and didnt realize that it was missing the d/c pin which means just as you said. It will only work with 3 bit serial mode. @loboris if you have any time we would very grateful.

MarsPlanet commented 4 years ago

Was anyone able to solve this?

willjkeller commented 4 years ago

I came across the description in the datasheet the other day when I was trying to get this library to work with a 7735S. I don't have any displays to test it, but if you want to try it, have a look at page 44 of 201 , v1.1 of the 7735S datasheet.

The change in the protocol is pretty simple -- you just send the value of what the d/c line would be before the MSB of each byte.

Currently the DC transitions are hardcoded with gpio_set_level, so what you would need to do is find everywhere in tftspi.c PIN_NUM_DC is set, remove it, and extend the length of the data by 1 so you can add the value to the front.

It shouldn't be too bad. Good luck!

ril3y commented 4 years ago

If anyone wants to implement this I have about 200x of these 3 wire displays I would be willing to send out to the dev that wants to take a swing at it.

Riley

On Sun, Aug 25, 2019 at 4:08 PM willjkeller notifications@github.com wrote:

I came across the description in the datasheet the other day when I was trying to get this library to work with a 7735S. I don't have any displays to test it, but if you want to try it, have a look at page 44 of 201 , v1.1 of the 7735S datasheet.

The change in the protocol is pretty simple -- you just send the value of what the d/c line would be before the MSB of each byte.

Currently the DC transitions are hardcoded with gpio_set_level, so what you would need to do is find everywhere in tftspi.c PIN_NUM_DC is set, remove it, and extend the length of the data by 1 so you can add the value to the front.

It shouldn't be too bad. Good luck!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/loboris/ESP32_TFT_library/issues/62?email_source=notifications&email_token=AABYSM63TS3RMM3RNDZ32XLQGLRFDA5CNFSM4GHUXWBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5C2YVI#issuecomment-524659797, or mute the thread https://github.com/notifications/unsubscribe-auth/AABYSMZ3VJ2S4VLHNTWYPIDQGLRFDANCNFSM4GHUXWBA .

shr1Khr commented 4 years ago

Hey guys,

So to solve this, we need to define two functions, one for command and one for parameters, and for EVERY 8 bits we are sending, a parameter/command bit needs to be added at the start.


void Init:: command(uint8_t val){
    //pinMode(_mosi, OUTPUT);  
        digitalWrite(_dc, 0);
        digitalWrite(_mosi, 0);  
        digitalWrite(_sck, HIGH);
        digitalWrite(_sck, LOW);

    for (int i = 0; i < 8; i++) {   //send command
        digitalWrite(_mosi, (val & 0x80) != 0);
        digitalWrite(_sck, HIGH);
        digitalWrite(_sck, LOW);
        val <<= 1;
    }
}

void Init::chipEnable(){
  digitalWrite(_cs, LOW);
  }

void Init::chipDisable(){
  digitalWrite(_cs, HIGH);
  }

void Init::chipToggle(){
  digitalWrite(_cs, HIGH);
  delay(1);
  digitalWrite(_cs, LOW);

  }

void Init:: param(uint8_t val){
    //pinMode(_mosi, OUTPUT);  
    digitalWrite(_dc, 1);
    digitalWrite(_mosi, 1);  
    digitalWrite(_sck, HIGH);
    digitalWrite(_sck, LOW);

    for (int i = 0; i < 8; i++) {   //send command
        digitalWrite(_mosi, (val & 0x80) != 0);
        digitalWrite(_sck, HIGH);
        digitalWrite(_sck, LOW);
        val <<= 1;
    }
  }

I tried with SPI and bit banging, and I found that bitbanging is a bit faster compared to SPI. Im using esp32 for this btw. Also, DC pin is the second serial pin to send the data to LCD. It's called dual SPI mode. In esp32, the flash we use uses quad SPI. You need to look these protocols up, I wasn't able to crack the dual SPI mode of this LCD, so I'm just setting it 1 or 0 as per parameter or command, but this pin can be safely ignored. The above functions are just to interface with the LCD. You must have received some initialization code or driver code with the LCD that is required with the above functions. Hope this helps. @ril3y could you please post the pics of the LCD or the link of the seller so that I can check it out?

shr1Khr commented 4 years ago

One more thing- To read a register of the LCD screen, you need to first send the command, then make the mosi pin as input and pulse the clock as per the length of the data to be received. After that, you need to set the mosi to output to again send next command, and so on...

ril3y commented 4 years ago

This is the lcd's I ordered. https://www.alibaba.com/product-detail/Spi-Tft-Lcd-2-4-Inch_60738085465.html?spm=a2756.order-detail-ta-ta-b.0.0.7c0c2fc2ZLLeth

On Sun, Aug 25, 2019 at 8:16 PM Shravan Khare notifications@github.com wrote:

One more thing- To read a register of the LCD screen, you need to first send the command, then make the mosi pin as input and pulse the clock as per the length of the data to be received. After that, you need to set the mosi to output to again send next command, and so on...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/loboris/ESP32_TFT_library/issues/62?email_source=notifications&email_token=AABYSMZ7XAQ6KCMHD642DLDQGMOHDA5CNFSM4GHUXWBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5C63QI#issuecomment-524676545, or mute the thread https://github.com/notifications/unsubscribe-auth/AABYSM5TFFJP3UDTPT3MPZ3QGMOHDANCNFSM4GHUXWBA .

shr1Khr commented 4 years ago

Wow that's a completely different lcd I have, anyways, check out the datasheet of the lcd, one of the following- my code or adafruit's or bodmer's tft code should work.

Here is mine- https://m.alibaba.com/product/60716482741/1-54-inch-240-240-small.html?spm=a2706.wap_new_search.1998817009.2.3b5c284fkoDZJb&__detailProductImg=%2F%2Fsc02.alicdn.com%2Fkf%2FHTB1fkfSeCtYBeNjSspaq6yOOFXae%2F1-54-inch-240-240-small-IPS.jpg_140x140xz.jpg

monkeytronics commented 3 years ago

Possibly a daft question on this topic, folks. I want to use a display (Winstar WF32DTLAJDNN0# : Link ) in which the data sheet says it has optional 3-wire 9-bit / 4-wire 8-bit serial interface modes. However, there is only one data line which is bidirectional! I am confused by this definition of 3 wire.

The only way I can make sense of this definition is if the MISO is not used. I.e. the lvgl library never actually reads anything back from the display or is currently doing so it in half duplex mode over a single data pin? In which case, I can ignore this factor? Or else, how do we address this?

Thanks all.

Edit I've hooked a scope up to the MOSI & MISO on my board to be 100% certain. Nice 40MBaud comms on the MOSI. Not a sausage on the MISO line. But I expect everyone but me already knew that!