Determining the colormode, invert, and rot parameters

December 10, 2021 ยท View on GitHub

The madctl_helper.py program can help determine the colormode, invert, and rot parameters for a display. Set the mosi, clk, dc, cs, backlight, width, and height parameters for your display. Start with rot=0, colormode=COLOR_MODE_RGB, and rot=0. Run the program with the display in the orientation you would like to configure.

Setting the colormode and invert parameter

The program will draw a large red full-screen button with an 'F' character centered in the button. You can determine the colormode and invert parameters by observing the button's color.

  • If the button is RED, the colormode and invert parameters are correct.
  • If the button is BLUE, colormode should be COLOR_MODE_BGR.
  • If the button is YELLOW, invert should be True.
  • If the button is CYAN, colormode should be COLOR_MODE_BGR and invert should be True.

Setting the rot parameter

The rot parameter is used to set the MADCTL register of the display. The MADCTL register controls the order that pixels are written to the framebuffer. This sets the Orientation or Rotation of the display. Match the orientation and direction of the 'F' character as drawn on the display by the madctl_helper.py program with the examples in the table below to determine the rot parameter value.

Imagerot parameter
MADCTL_0rot=0
MADCTL_MYrot=MADCTL_MY
MADCTL_MXrot=MADCTL_MX
MADCTL_MX | MADCTL_MYrot=MADCTL_MX | MADCTL_MY
MADCTL_MVrot=MADCTL_MV
MADCTL_MV | MADCTL_MYrot=MADCTL_MV | MADCTL_MY
MADCTL_MV | MADCTL_MXrot=MADCTL_MV | MADCTL_MX
MADCTL_MV | MADCTL_MX | MADCTL_MYrot=MADCTL_MV | MADCTL_MX | MADCTL_MX

MADCTL Constants

The following table shows the MADCTL bit flags and their effects.

ConstantValueDescription
MADCTL_MY0x80Page Address Order
MADCTL_MX0x40Column Address Order
MADCTL_MV0x20Page/Column Order
MADCTL_ML0x10Line Address Order
MADCTL_MH0x04Display Data Latch Order
COLOR_MODE_RGB0x00RGB color order
COLOR_MODE_BGR0x08BGR color order