예제 #1
0
 def set_tft_mode(self, v_flip = False, h_flip = False, c_flip = False, orientation = LANDSCAPE):
     self.v_flip = v_flip # flip vertical
     self.h_flip = h_flip # flip horizontal
     self.c_flip = c_flip # flip blue/red
     self.orientation = orientation # LANDSCAPE/PORTRAIT
     TFT_io.tft_cmd_data_AS(0x36,
         bytearray([(self.orientation << 5) |(self.c_flip << 3) | (self.h_flip & 1) << 1 | (self.v_flip) & 1]), 1)
예제 #2
0
 def setScrollArea(self, tfa, vsa, bfa):
     TFT_io.tft_cmd_data_AS(0x33, bytearray(  #set scrolling range
                 [(tfa >> 8) & 0xff, tfa & 0xff,
                  (vsa >> 8) & 0xff, vsa & 0xff,
                  (bfa >> 8) & 0xff, bfa & 0xff]), 6)
     self.scroll_tfa = tfa
     self.scroll_vsa = vsa
     self.scroll_bfa = bfa
     self.setScrollStart(self.scroll_tfa)
     x, y = self.getTextPos()
     self.setTextPos(x, y) # realign pointers
예제 #3
0
 def setScrollArea(self, tfa, vsa, bfa):
     TFT_io.tft_cmd_data_AS(
         0x33,
         bytearray(  #set scrolling range
             [(tfa >> 8) & 0xff, tfa & 0xff, (vsa >> 8) & 0xff, vsa & 0xff,
              (bfa >> 8) & 0xff, bfa & 0xff]),
         6)
     self.scroll_tfa = tfa
     self.scroll_vsa = vsa
     self.scroll_bfa = bfa
     self.setScrollStart(self.scroll_tfa)
     x, y = self.getTextPos()
     self.setTextPos(x, y)  # realign pointers
예제 #4
0
 def set_tft_mode(self,
                  v_flip=False,
                  h_flip=False,
                  c_flip=False,
                  orientation=LANDSCAPE):
     self.v_flip = v_flip  # flip vertical
     self.h_flip = h_flip  # flip horizontal
     self.c_flip = c_flip  # flip blue/red
     self.orientation = orientation  # LANDSCAPE/PORTRAIT
     TFT_io.tft_cmd_data_AS(
         0x36,
         bytearray([(self.orientation << 5) | (self.c_flip << 3) |
                    (self.h_flip & 1) << 1 | (self.v_flip) & 1]), 1)
예제 #5
0
    def tft_init(self, controller = "SSD1963", lcd_type = "LB04301", orientation = LANDSCAPE,  
                 v_flip = False, h_flip = False, power_control = True):
#
# For convenience, define X1..X1 and Y9..Y12 as output port using thy python functions.
# X1..X8 will be redefind on the fly as Input by accessing the MODER control registers
# when needed. Y9 is treate seperately, since it is used for Reset, which is done at python level
# since it need long delays anyhow, 5 and 15 ms vs. 10 µs.
#
# Set TFT general defaults
        self.controller = controller
        self.lcd_type = lcd_type
        self.orientation = orientation
        self.v_flip = v_flip # flip vertical
        self.h_flip = h_flip # flip horizontal
        self.c_flip = 0 # flip blue/red
        self.rc_flip = 0 # flip row/column

        self.setColor((255, 255, 255)) # set FG color to white as can be.
        self.setBGColor((0, 0, 0))     # set BG to black
        self.bg_buf = bytearray()
#
        self.pin_led = None     # deferred init Flag
        self.power_control = power_control
        if self.power_control:
# special treat for Power Pin
            self.pin_power = pyb.Pin("Y4", pyb.Pin.OUT_PP)
            self.power(True)    ## switch Power on
#            
        pyb.delay(10)
# this may have to be moved to the controller specific section
        if orientation == PORTRAIT:
            self.setXY = TFT_io.setXY_P
            self.drawPixel = TFT_io.drawPixel_P
        else:
            self.setXY = TFT_io.setXY_L
            self.drawPixel = TFT_io.drawPixel_L
        self.swapbytes = TFT_io.swapbytes
        self.swapcolors = TFT_io.swapcolors
#  ----------
        for pin_name in ["X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8",
                   "Y10", "Y11", "Y12"]:
            pin = pyb.Pin(pin_name, pyb.Pin.OUT_PP) # set as output
            pin.value(1)  ## set high as default
# special treat for Reset
        self.pin_reset = pyb.Pin("Y9", pyb.Pin.OUT_PP)
# Reset the device
        self.pin_reset.value(1)  ## do a hard reset
        pyb.delay(10)
        self.pin_reset.value(0)  ## Low
        pyb.delay(20)
        self.pin_reset.value(1)  ## set high again
        pyb.delay(20)
#
# Now initialiize the LCD
# This is for the SSD1963 controller and two specific LCDs. More may follow.
# Data taken from the SSD1963 data sheet, SSD1963 Application Note and the LCD Data sheets
#
        if controller == "SSD1963":           # 1st approach for 480 x 272
            TFT_io.tft_cmd_data(0xe2, bytearray(b'\x1d\x02\x54'), 3) # PLL multiplier, set PLL clock to 100M
              # N=0x2D for 6.5MHz, 0x1D for 10MHz crystal
              # PLLClock = Crystal * (Mult + 1) / (Div + 1)
              # The intermediate value Crystal * (Mult + 1) must be between 250MHz and 750 MHz
            TFT_io.tft_cmd_data(0xe0, bytearray(b'\x01'), 1) # PLL Enable
            pyb.delay(10)
            TFT_io.tft_cmd_data(0xe0, bytearray(b'\x03'), 1)
            pyb.delay(10)
            TFT_io.tft_cmd(0x01)                     # software reset
            pyb.delay(10)
#
# Settings for the LCD
#
# The LCDC_FPR depends on PLL clock and the reccomended LCD Dot clock DCLK
#
# LCDC_FPR = (DCLK * 1048576 / PLLClock) - 1
#
# The other settings are less obvious, since the definitions of the SSD1963 data sheet and the
# LCD data sheets differ. So what' common, even if the names may differ:
# HDP  Horizontal Panel width (also called HDISP, Thd). The value store in the register is HDP - 1
# VDP  Vertical Panel Width (also called VDISP, Tvd). The value stored in the register is VDP - 1
# HT   Total Horizontal Period, also called HP, th... The exact value does not matter
# VT   Total Vertical Period, alco called VT, tv, ..  The exact value does not matter
# HPW  Width of the Horizontal sync pulse, also called HS, thpw.
# VPW  Width of the Vertical sync pulse, also called VS, tvpw
# Front Porch (HFP and VFP) Time between the end of display data and the sync pulse
# Back Porch (HBP  and VBP Time between the start of the sync pulse and the start of display data.
#      HT = FP + HDP + BP  and VT = VFP + VDP + VBP (sometimes plus sync pulse width)
# Unfortunately, the controller does not use these front/back porch times, instead it uses an starting time
# in the front porch area and defines (see also figures in chapter 13.3 of the SSD1963 data sheet)
# HPS  Time from that horiz. starting point to the start of the horzontal display area
# LPS  Time from that horiz. starting point to the horizontal sync pulse
# VPS  Time from the vert. starting point to the first line
# FPS  Time from the vert. starting point to the vertical sync pulse
#
# So the following relations must be held:
#
# HT >  HDP + HPS
# HPS >= HPW + LPS
# HPS = Back Porch - LPS, or HPS = Horizontal back Porch
# VT > VDP + VPS
# VPS >= VPW + FPS
# VPS = Back Porch - FPS, or VPS = Vertical back Porch
#
# LPS or FPS may have a value of zero, since the length of the front porch is detemined by the
# other figures
#
# The best is to start with the recomendations of the lCD data sheet for Back porch, grab a
# sync pulse with and the determine the other, such that they meet the relations. Typically, these
# values allow for some ambuigity.
#
            if lcd_type == "LB04301":  # Size 480x272, 4.3", 24 Bit, 4.3"
                #
                # Value            Min    Typical   Max
                # DotClock        5 MHZ    9 MHz    12 MHz
                # HT (Hor. Total   490     531      612
                # HDP (Hor. Disp)          480
                # HBP (back porch)  8      43
                # HFP (Fr. porch)   2       8
                # HPW (Hor. sync)   1
                # VT (Vert. Total) 275     288      335
                # VDP (Vert. Disp)         272
                # VBP (back porch)  2       12
                # VFP (fr. porch)   1       4
                # VPW (vert. sync)  1       10
                #
                # This table in combination with the relation above leads to the settings:
                # HPS = 43, HPW = 8, LPS = 0, HT = 531
                # VPS = 14, VPW = 10, FPS = 0, VT = 288
                #
                self.disp_x_size = 479
                self.disp_y_size = 271
                TFT_io.tft_cmd_data_AS(0xe6, bytearray(b'\x01\x70\xa3'), 3) # PLL setting for PCLK
                    # (9MHz * 1048576 / 100MHz) - 1 = 94371 = 0x170a3
                TFT_io.tft_cmd_data_AS(0xb0, bytearray(  # # LCD SPECIFICATION
                    [0x20,                # 24 Color bits, HSync/VSync low, No Dithering
                     0x00,                # TFT mode
                     self.disp_x_size >> 8, self.disp_x_size & 0xff, # physical Width of TFT
                     self.disp_y_size >> 8, self.disp_y_size & 0xff, # physical Height of TFT
                     0x00]), 7)  # Last byte only required for a serial TFT
                TFT_io.tft_cmd_data_AS(0xb4, bytearray(b'\x02\x13\x00\x2b\x08\x00\x00\x00'), 8)
                        # HSYNC,  Set HT 531  HPS 43   HPW=Sync pulse 8 LPS 0
                TFT_io.tft_cmd_data_AS(0xb6, bytearray(b'\x01\x20\x00\x0e\x0a\x00\x00'), 7)
                        # VSYNC,  Set VT 288  VPS 14 VPW 10 FPS 0
                TFT_io.tft_cmd_data_AS(0x36, bytearray([(orientation & 1) << 5 | (h_flip & 1) << 1 | (v_flip) & 1]), 1)
                        # rotation/ flip, etc., t.b.d.
            elif lcd_type == "AT070TN92": # Size 800x480, 7", 18 Bit, lower color bits ignored
                #
                # Value            Min     Typical   Max
                # DotClock       26.4 MHz 33.3 MHz  46.8 MHz
                # HT (Hor. Total   862     1056     1200
                # HDP (Hor. Disp)          800
                # HBP (back porch)  46      46       46
                # HFP (Fr. porch)   16     210      254
                # HPW (Hor. sync)   1                40
                # VT (Vert. Total) 510     525      650
                # VDP (Vert. Disp)         480
                # VBP (back porch)  23      23       23
                # VFP (fr. porch)   7       22      147
                # VPW (vert. sync)  1                20
                #
                # This table in combination with the relation above leads to the settings:
                # HPS = 46, HPW = 8,  LPS = 0, HT = 1056
                # VPS = 23, VPW = 10, VPS = 0, VT = 525
                #
                self.disp_x_size = 799
                self.disp_y_size = 479
                TFT_io.tft_cmd_data_AS(0xe6, bytearray(b'\x05\x53\xf6'), 3) # PLL setting for PCLK
                    # (33.3MHz * 1048576 / 100MHz) - 1 = 349174 = 0x553f6
                TFT_io.tft_cmd_data_AS(0xb0, bytearray(  # # LCD SPECIFICATION
                    [0x00,                # 18 Color bits, HSync/VSync low, No Dithering/FRC
                     0x00,                # TFT mode
                     self.disp_x_size >> 8, self.disp_x_size & 0xff, # physical Width of TFT
                     self.disp_y_size >> 8, self.disp_y_size & 0xff, # physical Height of TFT
                     0x00]), 7)  # Last byte only required for a serial TFT
                TFT_io.tft_cmd_data_AS(0xb4, bytearray(b'\x04\x1f\x00\x2e\x08\x00\x00\x00'), 8)
                        # HSYNC,      Set HT 1056  HPS 46  HPW 8 LPS 0
                TFT_io.tft_cmd_data_AS(0xb6, bytearray(b'\x02\x0c\x00\x17\x08\x00\x00'), 7)
                        # VSYNC,   Set VT 525  VPS 23 VPW 08 FPS 0
                TFT_io.tft_cmd_data_AS(0x36, bytearray([(orientation & 1) << 5 | (h_flip & 1) << 1 | (v_flip) & 1]), 1)
                        # rotation/ flip, etc., t.b.d.
            else:
                print("Wrong Parameter lcd_type: ", lcd_type)
                return
            TFT_io.tft_cmd_data_AS(0xBA, bytearray(b'\x0f'), 1) # GPIO[3:0] out 1
            TFT_io.tft_cmd_data_AS(0xB8, bytearray(b'\x07\x01'), 1) # GPIO3=input, GPIO[2:0]=output

            TFT_io.tft_cmd_data_AS(0xf0, bytearray(b'\x00'), 1) # Pixel data Interface 8 Bit

            TFT_io.tft_cmd(0x29)             # Display on
            TFT_io.tft_cmd_data_AS(0xbe, bytearray(b'\x06\xf0\x01\xf0\x00\x00'), 6)
                    # Set PWM for B/L
            TFT_io.tft_cmd_data_AS(0xd0, bytearray(b'\x0d'), 1) # Set DBC: enable, agressive
        else:
            print("Wrong Parameter controller: ", controller)
            return
#
# Set character printing defaults
#
        self.text_font = None
        self.setTextStyle(self.color, self.BGcolor, 0, None, 0)
#
# Init done. clear Screen and switch BG LED on
#
        self.text_x = self.text_y = self.text_yabs = 0
        self.clrSCR()           # clear the display
예제 #6
0
 def setScrollStart(self, lline):
     self.scroll_start = lline # store the logical first line
     TFT_io.tft_cmd_data_AS(0x37, bytearray([(lline >> 8) & 0xff, lline & 0xff]), 2)
예제 #7
0
 def setScrollStart(self, lline):
     self.scroll_start = lline  # store the logical first line
     TFT_io.tft_cmd_data_AS(0x37,
                            bytearray([(lline >> 8) & 0xff, lline & 0xff]),
                            2)
예제 #8
0
    def tft_init(self,
                 controller="SSD1963",
                 lcd_type="LB04301",
                 orientation=LANDSCAPE,
                 v_flip=False,
                 h_flip=False,
                 power_control=True):
        #
        # For convenience, define X1..X1 and Y9..Y12 as output port using thy python functions.
        # X1..X8 will be redefind on the fly as Input by accessing the MODER control registers
        # when needed. Y9 is treate seperately, since it is used for Reset, which is done at python level
        # since it need long delays anyhow, 5 and 15 ms vs. 10 µs.
        #
        # Set TFT general defaults
        self.controller = controller
        self.lcd_type = lcd_type
        self.orientation = orientation
        self.v_flip = v_flip  # flip vertical
        self.h_flip = h_flip  # flip horizontal
        self.c_flip = 0  # flip blue/red
        self.rc_flip = 0  # flip row/column

        self.setColor((255, 255, 255))  # set FG color to white as can be.
        self.setBGColor((0, 0, 0))  # set BG to black
        #
        self.pin_led = None  # deferred init Flag
        self.power_control = power_control
        if self.power_control:
            # special treat for Power Pin
            self.pin_power = pyb.Pin("Y4", pyb.Pin.OUT_PP)
            self.power(True)  ## switch Power on
#
        pyb.delay(10)
        # this may have to be moved to the controller specific section
        if orientation == PORTRAIT:
            self.setXY = TFT_io.setXY_P
            self.drawPixel = TFT_io.drawPixel_P
        else:
            self.setXY = TFT_io.setXY_L
            self.drawPixel = TFT_io.drawPixel_L
        self.swapbytes = TFT_io.swapbytes
        self.swapcolors = TFT_io.swapcolors
        #  ----------
        for pin_name in [
                "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "Y10", "Y11",
                "Y12"
        ]:
            pin = pyb.Pin(pin_name, pyb.Pin.OUT_PP)  # set as output
            pin.value(1)  ## set high as default
# special treat for Reset
        self.pin_reset = pyb.Pin("Y9", pyb.Pin.OUT_PP)
        # Reset the device
        self.pin_reset.value(1)  ## do a hard reset
        pyb.delay(10)
        self.pin_reset.value(0)  ## Low
        pyb.delay(20)
        self.pin_reset.value(1)  ## set high again
        pyb.delay(20)
        #
        # Now initialiize the LCD
        # This is for the SSD1963 controller and two specific LCDs. More may follow.
        # Data taken from the SSD1963 data sheet, SSD1963 Application Note and the LCD Data sheets
        #
        if controller == "SSD1963":  # 1st approach for 480 x 272
            TFT_io.tft_cmd_data(0xe2, bytearray(b'\x1d\x02\x54'),
                                3)  # PLL multiplier, set PLL clock to 100M
            # N=0x2D for 6.5MHz, 0x1D for 10MHz crystal
            # PLLClock = Crystal * (Mult + 1) / (Div + 1)
            # The intermediate value Crystal * (Mult + 1) must be between 250MHz and 750 MHz
            TFT_io.tft_cmd_data(0xe0, bytearray(b'\x01'), 1)  # PLL Enable
            pyb.delay(10)
            TFT_io.tft_cmd_data(0xe0, bytearray(b'\x03'), 1)
            pyb.delay(10)
            TFT_io.tft_cmd(0x01)  # software reset
            pyb.delay(10)
            #
            # Settings for the LCD
            #
            # The LCDC_FPR depends on PLL clock and the reccomended LCD Dot clock DCLK
            #
            # LCDC_FPR = (DCLK * 1048576 / PLLClock) - 1
            #
            # The other settings are less obvious, since the definitions of the SSD1963 data sheet and the
            # LCD data sheets differ. So what' common, even if the names may differ:
            # HDP  Horizontal Panel width (also called HDISP, Thd). The value store in the register is HDP - 1
            # VDP  Vertical Panel Width (also called VDISP, Tvd). The value stored in the register is VDP - 1
            # HT   Total Horizontal Period, also called HP, th... The exact value does not matter
            # VT   Total Vertical Period, alco called VT, tv, ..  The exact value does not matter
            # HPW  Width of the Horizontal sync pulse, also called HS, thpw.
            # VPW  Width of the Vertical sync pulse, also called VS, tvpw
            # Front Porch (HFP and VFP) Time between the end of display data and the sync pulse
            # Back Porch (HBP  and VBP Time between the start of the sync pulse and the start of display data.
            #      HT = FP + HDP + BP  and VT = VFP + VDP + VBP (sometimes plus sync pulse width)
            # Unfortunately, the controller does not use these front/back porch times, instead it uses an starting time
            # in the front porch area and defines (see also figures in chapter 13.3 of the SSD1963 data sheet)
            # HPS  Time from that horiz. starting point to the start of the horzontal display area
            # LPS  Time from that horiz. starting point to the horizontal sync pulse
            # VPS  Time from the vert. starting point to the first line
            # FPS  Time from the vert. starting point to the vertical sync pulse
            #
            # So the following relations must be held:
            #
            # HT >  HDP + HPS
            # HPS >= HPW + LPS
            # HPS = Back Porch - LPS, or HPS = Horizontal back Porch
            # VT > VDP + VPS
            # VPS >= VPW + FPS
            # VPS = Back Porch - FPS, or VPS = Vertical back Porch
            #
            # LPS or FPS may have a value of zero, since the length of the front porch is detemined by the
            # other figures
            #
            # The best is to start with the recomendations of the lCD data sheet for Back porch, grab a
            # sync pulse with and the determine the other, such that they meet the relations. Typically, these
            # values allow for some ambuigity.
            #
            if lcd_type == "LB04301":  # Size 480x272, 4.3", 24 Bit, 4.3"
                #
                # Value            Min    Typical   Max
                # DotClock        5 MHZ    9 MHz    12 MHz
                # HT (Hor. Total   490     531      612
                # HDP (Hor. Disp)          480
                # HBP (back porch)  8      43
                # HFP (Fr. porch)   2       8
                # HPW (Hor. sync)   1
                # VT (Vert. Total) 275     288      335
                # VDP (Vert. Disp)         272
                # VBP (back porch)  2       12
                # VFP (fr. porch)   1       4
                # VPW (vert. sync)  1       10
                #
                # This table in combination with the relation above leads to the settings:
                # HPS = 43, HPW = 8, LPS = 0, HT = 531
                # VPS = 14, VPW = 10, FPS = 0, VT = 288
                #
                self.disp_x_size = 479
                self.disp_y_size = 271
                TFT_io.tft_cmd_data_AS(0xe6, bytearray(b'\x01\x70\xa3'),
                                       3)  # PLL setting for PCLK
                # (9MHz * 1048576 / 100MHz) - 1 = 94371 = 0x170a3
                TFT_io.tft_cmd_data_AS(
                    0xb0,
                    bytearray(  # # LCD SPECIFICATION
                        [
                            0x20,  # 24 Color bits, HSync/VSync low, No Dithering
                            0x00,  # TFT mode
                            self.disp_x_size >> 8,
                            self.disp_x_size & 0xff,  # physical Width of TFT
                            self.disp_y_size >> 8,
                            self.disp_y_size & 0xff,  # physical Height of TFT
                            0x00
                        ]),
                    7)  # Last byte only required for a serial TFT
                TFT_io.tft_cmd_data_AS(
                    0xb4, bytearray(b'\x02\x13\x00\x2b\x08\x00\x00\x00'), 8)
                # HSYNC,  Set HT 531  HPS 43   HPW=Sync pulse 8 LPS 0
                TFT_io.tft_cmd_data_AS(
                    0xb6, bytearray(b'\x01\x20\x00\x0e\x0a\x00\x00'), 7)
                # VSYNC,  Set VT 288  VPS 14 VPW 10 FPS 0
                TFT_io.tft_cmd_data_AS(
                    0x36,
                    bytearray([(orientation & 1) << 5 | (h_flip & 1) << 1 |
                               (v_flip) & 1]), 1)
                # rotation/ flip, etc., t.b.d.
            elif lcd_type == "AT070TN92":  # Size 800x480, 7", 18 Bit, lower color bits ignored
                #
                # Value            Min     Typical   Max
                # DotClock       26.4 MHz 33.3 MHz  46.8 MHz
                # HT (Hor. Total   862     1056     1200
                # HDP (Hor. Disp)          800
                # HBP (back porch)  46      46       46
                # HFP (Fr. porch)   16     210      254
                # HPW (Hor. sync)   1                40
                # VT (Vert. Total) 510     525      650
                # VDP (Vert. Disp)         480
                # VBP (back porch)  23      23       23
                # VFP (fr. porch)   7       22      147
                # VPW (vert. sync)  1                20
                #
                # This table in combination with the relation above leads to the settings:
                # HPS = 46, HPW = 8,  LPS = 0, HT = 1056
                # VPS = 23, VPW = 10, VPS = 0, VT = 525
                #
                self.disp_x_size = 799
                self.disp_y_size = 479
                TFT_io.tft_cmd_data_AS(0xe6, bytearray(b'\x05\x53\xf6'),
                                       3)  # PLL setting for PCLK
                # (33.3MHz * 1048576 / 100MHz) - 1 = 349174 = 0x553f6
                TFT_io.tft_cmd_data_AS(
                    0xb0,
                    bytearray(  # # LCD SPECIFICATION
                        [
                            0x00,  # 18 Color bits, HSync/VSync low, No Dithering/FRC
                            0x00,  # TFT mode
                            self.disp_x_size >> 8,
                            self.disp_x_size & 0xff,  # physical Width of TFT
                            self.disp_y_size >> 8,
                            self.disp_y_size & 0xff,  # physical Height of TFT
                            0x00
                        ]),
                    7)  # Last byte only required for a serial TFT
                TFT_io.tft_cmd_data_AS(
                    0xb4, bytearray(b'\x04\x1f\x00\x2e\x08\x00\x00\x00'), 8)
                # HSYNC,      Set HT 1056  HPS 46  HPW 8 LPS 0
                TFT_io.tft_cmd_data_AS(
                    0xb6, bytearray(b'\x02\x0c\x00\x17\x08\x00\x00'), 7)
                # VSYNC,   Set VT 525  VPS 23 VPW 08 FPS 0
                TFT_io.tft_cmd_data_AS(
                    0x36,
                    bytearray([(orientation & 1) << 5 | (h_flip & 1) << 1 |
                               (v_flip) & 1]), 1)
                # rotation/ flip, etc., t.b.d.
            elif lcd_type == "AT090TN10":  # Size 800x480, 9", 24 Bit, lower color bits ignored
                #
                # Value            Min     Typical   Max
                # DotClock       26.4 MHz 33.3 MHz  46.8 MHz
                # HT (Hor. Total   862     1056     1200
                # HDP (Hor. Disp)          800
                # HBP (back porch)  46      46       46
                # HFP (Fr. porch)   16     210      354
                # HPW (Hor. sync)   1                40
                # VT (Vert. Total) 510     525      650
                # VDP (Vert. Disp)         480
                # VBP (back porch)  23      23       23
                # VFP (fr. porch)   7       22      147
                # VPW (vert. sync)  1                20
                #
                # This table in combination with the relation above leads to the settings:
                # HPS = 46, HPW = 8,  LPS = 0, HT = 1056
                # VPS = 23, VPW = 10, VPS = 0, VT = 525
                #
                self.disp_x_size = 799
                self.disp_y_size = 479
                TFT_io.tft_cmd_data_AS(0xe6, bytearray(b'\x05\x53\xf6'),
                                       3)  # PLL setting for PCLK
                # (33.3MHz * 1048576 / 100MHz) - 1 = 349174 = 0x553f6
                TFT_io.tft_cmd_data_AS(
                    0xb0,
                    bytearray(  # # LCD SPECIFICATION
                        [
                            0x20,  # 24 Color bits, HSync/VSync low, No Dithering/FRC
                            0x00,  # TFT mode
                            self.disp_x_size >> 8,
                            self.disp_x_size & 0xff,  # physical Width of TFT
                            self.disp_y_size >> 8,
                            self.disp_y_size & 0xff,  # physical Height of TFT
                            0x00
                        ]),
                    7)  # Last byte only required for a serial TFT
                TFT_io.tft_cmd_data_AS(
                    0xb4, bytearray(b'\x04\x1f\x00\x2e\x08\x00\x00\x00'), 8)
                # HSYNC,      Set HT 1056  HPS 46  HPW 8 LPS 0
                TFT_io.tft_cmd_data_AS(
                    0xb6, bytearray(b'\x02\x0c\x00\x17\x08\x00\x00'), 7)
                # VSYNC,   Set VT 525  VPS 23 VPW 08 FPS 0
                TFT_io.tft_cmd_data_AS(
                    0x36,
                    bytearray([(orientation & 1) << 5 | (h_flip & 1) << 1 |
                               (v_flip) & 1]), 1)
                # rotation/ flip, etc., t.b.d.
            else:
                print("Wrong Parameter lcd_type: ", lcd_type)
                return
            TFT_io.tft_cmd_data_AS(0xBA, bytearray(b'\x0f'),
                                   1)  # GPIO[3:0] out 1
            TFT_io.tft_cmd_data_AS(0xB8, bytearray(b'\x07\x01'),
                                   1)  # GPIO3=input, GPIO[2:0]=output

            TFT_io.tft_cmd_data_AS(0xf0, bytearray(b'\x00'),
                                   1)  # Pixel data Interface 8 Bit

            TFT_io.tft_cmd(0x29)  # Display on
            TFT_io.tft_cmd_data_AS(0xbe,
                                   bytearray(b'\x06\xf0\x01\xf0\x00\x00'), 6)
            # Set PWM for B/L
            TFT_io.tft_cmd_data_AS(0xd0, bytearray(b'\x0d'),
                                   1)  # Set DBC: enable, agressive
        else:
            print("Wrong Parameter controller: ", controller)
            return
#
# Set character printing defaults
#
        self.text_font = None
        self.setTextStyle(self.color, self.BGcolor, 0, None, 0)
        #
        # Init done. clear Screen and switch BG LED on
        #
        self.text_x = self.text_y = self.text_yabs = 0
        self.clrSCR()  # clear the display