juj / fbcp-ili9341

A blazing fast display driver for SPI-based LCD displays for Raspberry Pi A, B, 2, 3, 4 and Zero
MIT License
1.62k stars 271 forks source link

ST7789V in portrait results in ultrawide resolution #230

Open SgtSiff opened 3 years ago

SgtSiff commented 3 years ago

I've managed to get my ST7789V based display working almost correctly, however, I noticed the cursor was disappearing off of the right hand side of the screen. I used the command:

xdpyinfo  | grep -oP 'dimensions:\s+\K\S+'

Which reports that my resolution is 960x320. 960 is a multiple of both 320 and 240 so I must have messed up a setting somewhere.

The display I am using is the Phoenix Contact 1226370.

Below are the changes I made to the files. This is on a fresh install of Raspbian on a CM4 plugged into the IO board. Ignore the [!], these aren't in the code, I just used them for syntax highlighting.

  1. config.h:
// If defined, rotates the display 180 degrees. This might not rotate the panel scan order though,
// so adding this can cause up to one vsync worth of extra display latency. It is best to avoid this and
// install the display in its natural rotation order, if possible.
!  #define DISPLAY_ROTATE_180_DEGREES

// If defined, displays in landscape. Undefine to display in portrait.
!  //#define DISPLAY_OUTPUT_LANDSCAPE
  1. st7735r.h:
#if defined(ST7789) || defined(ST7789VW)
#define DISPLAY_NATIVE_WIDTH 240
!#define DISPLAY_NATIVE_HEIGHT 320
  1. st7735r.cpp:
#endif
!   madctl ^= MADCTL_COLUMN_ADDRESS_ORDER_SWAP;
    SPI_TRANSFER(0x36/*MADCTL: Memory Access Control*/, madctl);
    usleep(10*1000);
  1. st7735r.cpp:
#ifdef ST7789
    // The ST7789 controller is actually a unit with 320x240 graphics memory area, but only 240x240 portion
    // of it is displayed. Therefore if we wanted to swap row address mode above, writes to Y=0...239 range will actually land in
    // memory in row addresses Y = 319-(0...239) = 319...80 range. To view this range, we must scroll the view by +80 units in Y
    // direction so that contents of Y=80...319 is displayed instead of Y=0...239.
    if ((madctl & MADCTL_ROW_ADDRESS_ORDER_SWAP))
!      SPI_TRANSFER(0x37/*VSCSAD: Vertical Scroll Start Address of RAM*/, 0, 0);
#endif
  1. /boot/config.txt:
!hdmi_group=2
!hdmi_mode=87
!hdmi_cvt=240 320 60 1 0 0 0
!hdmi_force_hotplug=1
  1. /etc/rc.local
sudo /home/pi/fbcp-ili9341/build/fbcp-ili9341 &

The cmake command I used was:

cmake -DST7789VW=ON -DGPIO_TFT_DATA_CONTROL=25 -DGPIO_TFT_RESET_PIN=27 -DSPI_BUS_CLOCK_DIVISOR=8 -DSTATISTICS=0 ..

Thank you in advance.

juj commented 3 years ago

Which reports that my resolution is 960x320.

If the system is reporting the display size to be 960x320, but you have hdmi_cvt at boot config set to 240x320, it is possible that some application/utility has changed the display size after the Pi has booted. You can run tvservice -s to check what the Pi thinks of the HDMI mode. See https://www.raspberrypi.org/documentation/computers/configuration.html#what-modes-does-my-device-support.

What does fbcp-ili9341 print at startup for the screen dimensions?

Gadgetoid commented 3 years ago

Is this an ST7789V2 based display? Does this work for you: https://github.com/juj/fbcp-ili9341/pull/242