# Path: tft/driver/TFT_io.py
# RESET  = const(1 << 10)  ## Y9
# RD     = const(1 << 11)  ## Y10
# WR     = const(0x01)  ## Y11
# D_C    = const(0x02)  ## Y12
# LED    = const(1 << 8) ## Y3
# POWER  = const(1 << 9) ## Y4
# PORTRAIT = const(1)
# LANDSCAPE = const(0)
# def displaySCR_charbitmap(bits: ptr8, size: int, control: ptr8, bg_buf: ptr8):
# def displaySCR_bmp(data: ptr8, size: int, bits: int, colortable: ptr8):
# def setXY_L(r0, r1, r2, r3):  
# def setXY_P(r0, r1, r2, r3):  
# def drawPixel_L(r0, r1, r2):  
# def drawPixel_P(r0, r1, r2):  
# def fillSCR_AS(r0, r1):  # r0: ptr to data, r1: number of pixels (3 bytes/pixel)
# def displaySCR_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def displaySCR565_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def tft_cmd_data(cmd: int, data: ptr8, size: int):
# def tft_cmd_data_AS(r0, r1, r2):  # r0: command, r1: ptr to data, r2 is size in bytes
# def tft_cmd(cmd: int):
# def tft_write_data_AS(r0, r1):  # r0: ptr to data, r1: is size in Bytes
# def tft_read_cmd_data_AS(r0, r1, r2):  
# def swapbytes(r0, r1):               # bytearray, len(bytearray)
# def swapcolors(r0, r1):               # bytearray, len(bytearray)


import pyb, stm
import gc
from uctypes import addressof
from tft.driver import TFT_io
        if y1 > y2:
            y1, y2 = y2, y1
    	self.drawHLine(x1, y1, x2 - x1 + 1, color)
        self.drawHLine(x1, y2, x2 - x1 + 1, color)
        self.drawVLine(x1, y1, y2 - y1 + 1, color)
        self.drawVLine(x2, y1, y2 - y1 + 1, color)
#
# Fill rectangle
# Almost straight port from the UTFT Library at Rinky-Dink Electronics
#
    def fillRectangle(self, x1, y1, x2, y2, color=None):
        if x1 > x2:
            x1, x2 = x2, x1
        if y1 > y2:
            y1, y2 = y2, y1
        self.setXY(x1, y1, x2, y2) # set display window
        if color:
            TFT_io.fillSCR_AS(bytearray(color), (x2 - x1 + 1) * (y2 - y1 + 1))
        else:
            TFT_io.fillSCR_AS(self.colorvect, (x2 - x1 + 1) * (y2 - y1 + 1))

#
# Draw smooth rectangle from x1, y1, to x2, y2
# Straight port from the UTFT Library at Rinky-Dink Electronics
#
    def drawClippedRectangle(self, x1, y1, x2, y2, color = None):
        if x1 > x2:
            x1, x2 = x2, x1
        if y1 > y2:
            y1, y2 = y2, y1

# Path: tft/driver/TFT_io.py
# RESET  = const(1 << 10)  ## Y9
# RD     = const(1 << 11)  ## Y10
# WR     = const(0x01)  ## Y11
# D_C    = const(0x02)  ## Y12
# LED    = const(1 << 8) ## Y3
# POWER  = const(1 << 9) ## Y4
# PORTRAIT = const(1)
# LANDSCAPE = const(0)
# def displaySCR_charbitmap(bits: ptr8, size: int, control: ptr8, bg_buf: ptr8):
# def displaySCR_bmp(data: ptr8, size: int, bits: int, colortable: ptr8):
# def setXY_L(r0, r1, r2, r3):  
# def setXY_P(r0, r1, r2, r3):  
# def drawPixel_L(r0, r1, r2):  
# def drawPixel_P(r0, r1, r2):  
# def fillSCR_AS(r0, r1):  # r0: ptr to data, r1: number of pixels (3 bytes/pixel)
# def displaySCR_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def displaySCR565_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def tft_cmd_data(cmd: int, data: ptr8, size: int):
# def tft_cmd_data_AS(r0, r1, r2):  # r0: command, r1: ptr to data, r2 is size in bytes
# def tft_cmd(cmd: int):
# def tft_write_data_AS(r0, r1):  # r0: ptr to data, r1: is size in Bytes
# def tft_read_cmd_data_AS(r0, r1, r2):  
# def swapbytes(r0, r1):               # bytearray, len(bytearray)
# def swapcolors(r0, r1):               # bytearray, len(bytearray)


# Path: tft/driver/tft.py
import pyb, stm
import gc
from uctypes import addressof
from tft.driver import TFT_io

        if y1 > y2:
            y1, y2 = y2, y1
    	self.drawHLine(x1, y1, x2 - x1 + 1, color)
        self.drawHLine(x1, y2, x2 - x1 + 1, color)
        self.drawVLine(x1, y1, y2 - y1 + 1, color)
        self.drawVLine(x2, y1, y2 - y1 + 1, color)
#
# Fill rectangle
# Almost straight port from the UTFT Library at Rinky-Dink Electronics
#
    def fillRectangle(self, x1, y1, x2, y2, color=None):
        if x1 > x2:
            x1, x2 = x2, x1
        if y1 > y2:
            y1, y2 = y2, y1
        self.setXY(x1, y1, x2, y2) # set display window
        if color:
            TFT_io.fillSCR_AS(bytearray(color), (x2 - x1 + 1) * (y2 - y1 + 1))
        else:
            TFT_io.fillSCR_AS(self.colorvect, (x2 - x1 + 1) * (y2 - y1 + 1))

#
# Draw smooth rectangle from x1, y1, to x2, y2
# Straight port from the UTFT Library at Rinky-Dink Electronics
#
    def drawClippedRectangle(self, x1, y1, x2, y2, color = None):
        if x1 > x2:
            x1, x2 = x2, x1
        if y1 > y2:
            y1, y2 = y2, y1

        if (x2-x1) > 4 and (y2-y1) > 4: