olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
4.94k stars 1.03k forks source link

Explicitly Define HW SPI Interface Pins - MOSI & SLCK #377

Closed neilpanchal closed 6 years ago

neilpanchal commented 6 years ago

Hello,

U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI display1(U8G2_R0, /* cs=*/ 5, /* dc=*/ 2, /* reset=*/ 4);

Doesn't allow the user to define the MOSI and SCLK pins in the constructor.

It is especially useful on boards with 2 or more SPI modules such as on the ESP32. I probed around with a scope and found out that the constructor selects VSPI as opposed to HSPI module.

A couple of questions to try to understand the rationality behind protecting the user from defining the pins themselves.

  1. Is it possible to connect displays on both HSPI and VSPI lines? I understand that I can use the chip-select (CS) pin to select between displays, however, I am trying to avoid robbing clock cycles and therefore reducing the framerate (not sure how true my claim is...but I just want to try it out).

  2. I am curious why there are some drivers whose constructors allow for data and clock pin definition and others whose constructors don't. I am using SSD1306.

  3. Is this something that needs to be handled by the ESP32 HAL? I haven't had a chance to delve into the U8G2 code, or the ESP32 IDF and/or espressif32 for Arduino.

Thank you!

rohanrehman commented 3 months ago

@olikraus looks like this is still an issue with a Esp32 s2 mini.

Ssd1309 4Wire HW SPI on an Esp32 v1 when pin connect to D23 for data and D18 for clock

There is no D23 on Esp32 S2 mini.

Not seeing a way to set data(MOSI) and clock in the 4W SPI HW constructor.

WebDust21 commented 3 months ago

Not seeing a way to set data(MOSI) and clock in the 4W SPI HW constructor.

The PR/corrections did not change this. Use the custom constructor I detailed above, namely, using an HW constructor (so U8G2 uses HW SPI), but using the SW pin configuration function. Repeated here:

#include "U8x8lib.h"
#include "clib/u8g2.h"
// modified constructor to expose the clock/data pin fields...
class U8G2_SSD1309_128X64_NONAME2_F_4W_HW_SPI_CUST : public U8G2 {
  public: U8G2_SSD1309_128X64_NONAME2_F_4W_HW_SPI_CUST(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
    u8g2_Setup_ssd1309_128x64_noname2_f(&u8g2, rotation, u8x8_byte_arduino_hw_spi, u8x8_gpio_and_delay_arduino);
    u8x8_SetPin_4Wire_SW_SPI(getU8x8(), clock, data, cs, dc, reset);        // YES, we're using the "SW" pin constructor.  Only difference between "SW" and "HW" is that "HW" doesn't expose the rest of the pin setup fields
  }
};
sebastianmach commented 2 months ago

I'm trying to use alternative SPI pins on an ESP32S3 and found this issue, but I couldn't get it to work.

Can you share a full example of how to use u8g2 using custom SPI pins?

kazetsukaimiko commented 2 months ago

I'm trying to use alternative SPI pins on an ESP32S3 and found this issue, but I couldn't get it to work.

Can you share a full example of how to use u8g2 using custom SPI pins?

@sebastianmach Can you provide more details... what screen are you using, what pins are you trying to use