# 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
#
    def setBGColor(self, bgcolor):
        self.BGcolor = bgcolor
        self.BGcolorvect = bytearray(self.BGcolor)  # prepare byte array
        self.BMPcolortable = bytearray([self.BGcolorvect[2], # create colortable
            self.BGcolorvect[1], self.BGcolorvect[0],0,
            self.colorvect[2], self.colorvect[1], self.colorvect[0],0])
#
# get the color used for the draw commands
#
    def getColor(self):
        return self.color
#
# get BG color used for
#
    def getBGColor(self):
        return self.BGcolor
#
# Draw a single pixel at location x, y with color
# Rather slow at 40µs/Pixel
#
    def drawPixel_py(self, x, y, color):
        self.setXY(x, y, x, y)
        TFT_io.displaySCR_AS(color, 1)  #
#
# clear screen, set it to BG color.
#
    def clrSCR(self, color = None):
        colorvect = self.BGcolorvect if color is None else bytearray(color)
        self.clrXY()

# 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

#
    def setBGColor(self, bgcolor):
        self.BGcolor = bgcolor
        self.BGcolorvect = bytearray(self.BGcolor)  # prepare byte array
        self.BMPcolortable = bytearray([self.BGcolorvect[2], # create colortable
            self.BGcolorvect[1], self.BGcolorvect[0],0,
            self.colorvect[2], self.colorvect[1], self.colorvect[0],0])
#
# get the color used for the draw commands
#
    def getColor(self):
        return self.color
#
# get BG color used for
#
    def getBGColor(self):
        return self.BGcolor
#
# Draw a single pixel at location x, y with color
# Rather slow at 40µs/Pixel
#
    def drawPixel_py(self, x, y, color):
        self.setXY(x, y, x, y)
        TFT_io.displaySCR_AS(color, 1)  #
#
# clear screen, set it to BG color.
#
    def clrSCR(self, color = None):
        colorvect = self.BGcolorvect if color is None else bytearray(color)
        self.clrXY()

        TFT_io.fillSCR_AS(colorvect, (self.disp_x_size + 1) * (self.disp_y_size + 1))