コード例 #1
0
def main():
    global tft, spi, axp, touch

    # try:
    # Turn power on display power
    axp = axp202c.PMU()
    axp.enablePower(axp202c.AXP202_LDO2)

    # initalize spi port
    spi = SPI(2,
              baudrate=32000000,
              polarity=1,
              phase=0,
              bits=8,
              firstbit=0,
              sck=Pin(18, Pin.OUT),
              mosi=Pin(19, Pin.OUT))

    # configure display
    tft = st7789.ST7789(spi,
                        240,
                        240,
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(27, Pin.OUT),
                        backlight=Pin(12, Pin.OUT),
                        rotation=0)

    # enable display
    tft.init()
    tft.fill(st7789.BLACK)

    initTouch()
コード例 #2
0
def main():
    '''
    Decode and draw jpg on display
    '''
    try:
        # Turn on display backlight
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize display spi port
        spi = SPI(
            2,
            baudrate=32000000,
            sck=Pin(18, Pin.OUT),
            mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(
            spi,
            240,
            240,
            cs=Pin(5, Pin.OUT),
            dc=Pin(27, Pin.OUT),
            backlight=Pin(12, Pin.OUT),
            rotation=2)

        # enable display and clear screen
        tft.init()

        # display jpg
        tft.jpg("bigbuckbunny.jpg", 0, 0, st7789.SLOW)

    finally:
        # shutdown spi
        spi.deinit()
コード例 #3
0
 def __init__(self):
     self.axp = axp = axp202.PMU()
     self.axp.enablePower(axp202.AXP202_LDO2)
     self.axp.enablePower(axp202.AXP202_DCDC3)
     # useful shorthands
     self.reset = reset
     self.shutdown = self.axp.shutdown
     self.bl = Pin(12, Pin.OUT)
     self.bl.on()
     self.ir = Pin(13, Pin.OUT)
     self.ir.off()
     self.buzz = Pin(4, Pin.OUT)
     self.disp = st7789.ST7789font(None,
                                   240,
                                   240,
                                   reset=None,
                                   cs=Pin(5, Pin.OUT),
                                   dc=Pin(27, Pin.OUT))
     self.i2c0 = axp.bus  # I2C(0,scl.Pin(22), sda=Pin(21))
     self.i2c1 = I2C(1, scl=Pin(32), sda=Pin(23))
     self.disp.init()
     self.disp.writestring("booting..", 0, 0)
     self.testimg = self.disp.testimg
     self.hwrtc = pcf8563.PCF8563(self.i2c0)
     datetime = self.hwrtc.datetime()
     #                      (20, 7, 9, 4, 1, 44, 13)
     yy, mon, dd, dow, hh, mm, ss = datetime
     self.disp.writestring(
         "%04d-%02d-%02d %02d:%02d:%02d" % (2000 + yy, mon, dd, hh, mm, ss),
         0, 10)
     # self.ft=focaltouch.FocalTouch(self.i2c1)
     self.orientation = 2  # 0 is same as touchscreen. button is on the upper right. 1 rotate ccw, 2 upside down. 3  cw
     self.xrange = [20, 220]  # position of touch on screen
     self.yrange = [20, 220]
コード例 #4
0
def main():
    '''
    Decode and draw the jpg on the display
    '''
    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

        # initialize display
        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0)

        # enable display and clear screen
        tft.init()

        # display jpg
        tft.jpg("bigbuckbunny.jpg", 0, 0, ili9342c.SLOW)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #5
0
ファイル: fonts.py プロジェクト: yoyojacky/st7789_mpy
def main():
    try:
        # Turn on display backlight
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize display spi port
        spi = SPI(
            2,
            baudrate=32000000,
            polarity=1,
            phase=0,
            bits=8,
            firstbit=0,
            sck=Pin(18),
            mosi=Pin(19))

        # configure display
        tft = st7789.ST7789(
            spi,
            240,
            240,
            cs=Pin(5, Pin.OUT),
            dc=Pin(27, Pin.OUT),
            backlight=Pin(12, Pin.OUT),
            rotation=2)

        tft.init()

        while True:
            for font in (font1, font2, font3, font4):
                tft.fill(st7789.BLUE)
                line = 0
                col = 0
                for char in range(font.FIRST, font.LAST):
                    tft.text(font, chr(char), col, line, st7789.WHITE, st7789.BLUE)
                    col += font.WIDTH
                    if col > tft.width() - font.WIDTH:
                        col = 0
                        line += font.HEIGHT

                        if line > tft.height()-font.HEIGHT:
                            utime.sleep(3)
                            tft.fill(st7789.BLUE)
                            line = 0
                            col = 0

                utime.sleep(3)

    finally:
        # shutdown spi
        spi.deinit()

        # turn off display backlight
        axp.disablePower(axp202c.AXP202_LDO2)
コード例 #6
0
def main():
    # Turn display power
    axp = axp202c.PMU(address=0x34)
    axp.enablePower(axp202c.AXP192_LDO2)
    # Set backlight voltage
    axp.setDC3Voltage(3000)

    spi = SPI(
        2,
        baudrate=60000000,
        sck=Pin(18),
        mosi=Pin(23))

    # initialize display

    tft = ili9342c.ILI9342C(
        spi,
        320,
        240,
        reset=Pin(33, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(15, Pin.OUT),
        rotation=0)

    tft.init()
    tft.fill(ili9342c.BLACK)
    utime.sleep(1)

    while True:
        for font in (font1, font2, font3, font4):
            tft.fill(ili9342c.BLUE)
            line = 0
            col = 0
            for char in range(font.FIRST, font.LAST):
                tft.text(
                    font,
                    chr(char),
                    col,
                    line,
                    ili9342c.WHITE,
                    ili9342c.BLUE)

                col += font.WIDTH
                if col > tft.width() - font.WIDTH:
                    col = 0
                    line += font.HEIGHT

                    if line > tft.height()-font.HEIGHT:
                        utime.sleep(3)
                        tft.fill(ili9342c.BLUE)
                        line = 0
                        col = 0

            utime.sleep(3)
コード例 #7
0
ファイル: mono_fonts.py プロジェクト: skylin008/st7789_mpy
def main():
    fast = False

    def display_font(font):
        tft.fill(st7789.BLUE)
        column = 0
        row = 0
        for char in font.MAP:
            tft.bitmap(font, column, row, font.MAP.index(char))
            column += font.WIDTH
            if column >= tft.width() - font.WIDTH:
                row += font.HEIGHT
                column = 0

                if row > tft.height() - font.HEIGHT:
                    row = 0

            if not fast:
                time.sleep(0.05)

    try:
        # Turn power on display power
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize spi port
        spi = SPI(1,
                  baudrate=32000000,
                  sck=Pin(18, Pin.OUT),
                  mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            240,
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(12, Pin.OUT),
                            rotation=2,
                            buffer_size=66 * 32 * 2)

        tft.init()

        while True:
            for font in [font_16, font_32, font_64]:
                display_font(font)

            fast = not fast

    finally:
        # shutdown spi
        spi.deinit()
        # turn off display power
        axp.disablePower(axp202c.AXP202_LDO2)
コード例 #8
0
def main():
    def center(font, s, row, color=st7789.WHITE):
        screen = tft.width()  # get screen width
        width = tft.write_len(font, s)  # get the width of the string
        if width and width < screen:  # if the string < display
            col = tft.width() // 2 - width // 2  # find the column to center
        else:  # otherwise
            col = 0  # left justify

        tft.write(font, s, col, row, color)  # and write the string

    try:
        # Turn power on display power
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize spi port
        spi = SPI(1,
                  baudrate=32000000,
                  sck=Pin(18, Pin.OUT),
                  mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            240,
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(12, Pin.OUT),
                            rotation=2,
                            buffer_size=16 * 32 * 2)

        # enable display
        tft.init()
        tft.fill(st7789.BLACK)

        # center the name of the first font, using the font
        row = 16
        center(noto_sans, "NotoSans", row, st7789.RED)
        row += noto_sans.HEIGHT

        # center the name of the second font, using the font
        center(noto_serif, "NotoSerif", row, st7789.GREEN)
        row += noto_serif.HEIGHT

        # center the name of the third font, using the font
        center(noto_mono, "NotoSansMono", row, st7789.BLUE)
        row += noto_mono.HEIGHT

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #9
0
ファイル: toasters.py プロジェクト: lumpynose/ili9342c_mpy
def main():
    '''
    Draw and move sprite
    '''
    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

        # initialize display

        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0)

        # enable display and clear screen
        tft.init()
        tft.fill(ili9342c.BLACK)

        # create toast spites in random positions
        sprites = [
            toast(TOASTERS, 320 - 64, 0),
            toast(TOAST, 320 - 64 * 2, 80),
            toast(TOASTERS, 320 - 64 * 4, 160)
        ]

        # move and draw sprites
        while True:
            for man in sprites:
                bitmap = man.sprites[man.step]
                tft.fill_rect(man.x + bitmap.WIDTH - man.speed, man.y,
                              man.speed, bitmap.HEIGHT, ili9342c.BLACK)

                man.move()

                if man.x > 0:
                    tft.bitmap(bitmap, man.x, man.y)
                else:
                    tft.fill_rect(0, man.y, bitmap.WIDTH, bitmap.HEIGHT,
                                  ili9342c.BLACK)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #10
0
ファイル: watch_hershey.py プロジェクト: mcu786/st7789_mpy
def main():
    '''
    Draw greetings on display cycling thru hershey fonts and colors
    '''
    try:
        # Turn power on display power
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)
        axp.enablePower(axp202c.AXP202_DCDC3)

        # initialize spi port
        spi = SoftSPI(
            2,
            baudrate=32000000,
            polarity=1,
            phase=0,
            bits=8,
            firstbit=0,
            sck=Pin(18, Pin.OUT),
            mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(
            spi,
            240,
            240,
            cs=Pin(5, Pin.OUT),
            dc=Pin(27, Pin.OUT),
            backlight=Pin(12, Pin.OUT),
            rotation=2)

        tft.init()
        tft.fill(st7789.BLACK)
        height = tft.height()
        width = tft.width()
        row = 0

        while True:
            row += 32
            color = next(COLORS)
            tft.fill_rect(0, row-16, width, 32, st7789.BLACK)
            tft.draw(next(FONTS), next(GREETINGS), 0, row, color)

            if row > 192:
                row = 0

            utime.sleep(0.25)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #11
0
ファイル: tft_config.py プロジェクト: russhughes/st7789_mpy
def config(rotation=0, buffer_size=0, options=0):
    axp = axp202c.PMU()
    axp.enablePower(axp202c.AXP202_LDO2)
    return st7789.ST7789(SPI(1,
                             baudrate=32000000,
                             sck=Pin(18, Pin.OUT),
                             mosi=Pin(19, Pin.OUT)),
                         240,
                         240,
                         cs=Pin(5, Pin.OUT),
                         dc=Pin(27, Pin.OUT),
                         backlight=Pin(12, Pin.OUT),
                         rotation=rotation,
                         options=options,
                         buffer_size=buffer_size)
コード例 #12
0
def main():
    try:
        # Turn power on display power
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize spi port
        spi = SPI(1,
                  baudrate=32000000,
                  sck=Pin(18, Pin.OUT),
                  mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            240,
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(12, Pin.OUT),
                            rotation=2)

        tft.init()
        tft.fill(st7789.BLUE)
        row = font_16.HEIGHT

        tft.write(font_16, "abcdefghijklmnopqrst", 0, row, st7789.WHITE,
                  st7789.BLUE)
        row += font_16.HEIGHT

        tft.write(font_32, "abcdefghij", 0, row, st7789.WHITE, st7789.BLUE)
        row += font_32.HEIGHT

        tft.write(font_32, "klmnopqrs", 0, row, st7789.WHITE, st7789.BLUE)
        row += font_32.HEIGHT

        tft.write(font_32, "tuvwxyz", 0, row, st7789.WHITE, st7789.BLUE)
        row += font_32.HEIGHT

        tft.write(font_64, "abcd", 0, row, st7789.WHITE, st7789.BLUE)
        row += font_64.HEIGHT

    finally:
        # shutdown spi
        spi.deinit()
コード例 #13
0
def main():
    '''
    Draw greetings on display cycling thru hershey fonts and colors
    '''
    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

        # Configure display
        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0)

        tft.init()
        tft.fill(ili9342c.BLACK)
        height = tft.height()
        width = tft.width()
        row = 0

        while True:
            row += 32
            tft.fill_rect(0, row - 16, width, 32, ili9342c.BLACK)
            tft.draw(next(FONTS), next(GREETINGS), 0, row, next(COLORS))

            if row > 192:
                row = 0

            utime.sleep(0.25)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #14
0
def main():
    # Turn display power
    axp = axp202c.PMU(address=0x34)
    axp.enablePower(axp202c.AXP192_LDO2)
    # Set backlight voltage
    axp.setDC3Voltage(3000)

    spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

    # initialize display

    tft = ili9342c.ILI9342C(spi,
                            320,
                            240,
                            reset=Pin(33, Pin.OUT),
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(15, Pin.OUT),
                            rotation=0)

    tft.init()
    tft.fill(ili9342c.BLACK)
    time.sleep(1)

    while True:
        for rotation in range(4):
            tft.rotation(rotation)
            tft.fill(0)
            col_max = tft.width() - font.WIDTH * 6
            row_max = tft.height() - font.HEIGHT

            for _ in range(1000):
                tft.text(
                    font, "Hello!", random.randint(0, col_max),
                    random.randint(0, row_max),
                    ili9342c.color565(random.getrandbits(8),
                                      random.getrandbits(8),
                                      random.getrandbits(8)),
                    ili9342c.color565(random.getrandbits(8),
                                      random.getrandbits(8),
                                      random.getrandbits(8)))
コード例 #15
0
def main():

    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2,
                  baudrate=20000000,
                  sck=Pin(18),
                  miso=Pin(38),
                  mosi=Pin(23))

        # initialize and mount the sdcard
        sd_device = sdcard.SDCard(spi, cs=Pin(4), baudrate=20000000)
        uos.mount(sd_device, '/sd')

        # initialize display

        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0,
                                buffer_size=38400)

        tft.init()

        for i in range(1, 2387):
            frame = "/sd/160x120/{:04d}.jpg".format(i)
            tft.jpg(frame, 80, 60, ili9342c.FAST)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #16
0
def main():
    '''
    Draw and move sprite
    '''
    try:
        # Turn power on display power
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize spi port
        spi = SPI(
            2,
            baudrate=32000000,
            sck=Pin(18, Pin.OUT),
            mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(
            spi,
            240,
            240,
            cs=Pin(5, Pin.OUT),
            dc=Pin(27, Pin.OUT),
            backlight=Pin(12, Pin.OUT),
            rotation=2)

        # enable display and clear screen
        tft.init()
        tft.fill(st7789.BLACK)

        # create toast spites in random positions
        sprites = [
            toast(TOASTERS, 320-64, 0),
            toast(TOAST, 320-64*2, 80),
            toast(TOASTERS, 320-64*4, 160)
        ]

        # move and draw sprites
        while True:
            for man in sprites:
                bitmap = man.sprites[man.step]
                tft.fill_rect(
                    man.x+bitmap.WIDTH-man.speed,
                    man.y,
                    man.speed,
                    bitmap.HEIGHT,
                    st7789.BLACK)

                man.move()

                if man.x > 0:
                    tft.bitmap(bitmap, man.x, man.y)
                else:
                    tft.fill_rect(
                        0,
                        man.y,
                        bitmap.WIDTH,
                        bitmap.HEIGHT,
                        st7789.BLACK)

            time.sleep(0.05)

    finally:
        # shutdown spi
        spi.deinit()
コード例 #17
0
def main():
    '''
    Draw on screen using map_bitarray_to_rgb565
    '''
    try:
        # Turn on display backlight
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize display spi port
        spi = SPI(2,
                  baudrate=32000000,
                  sck=Pin(18, Pin.OUT),
                  mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            240,
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(12, Pin.OUT),
                            rotation=2)

        # enable display and clear screen
        tft.init()
        tft.fill(st7789.BLACK)
        sprite = bytearray(512)

        # create pacman spites in random positions
        sprites = []
        for man in range(SPRITES):
            sprites.append(
                pacman(random.randint(0,
                                      tft.width() - SPRITE_WIDTH),
                       random.randint(0,
                                      tft.height() - SPRITE_HEIGHT),
                       random.randint(0, SPRITE_STEPS - 1)))

        # move and draw sprites
        while True:
            for man in sprites:
                # move the sprite
                man.move()

                # convert bitmap into rgb565 blitable buffer
                tft.map_bitarray_to_rgb565(SPRITE_BITMAPS[man.step], sprite,
                                           SPRITE_WIDTH, st7789.YELLOW,
                                           st7789.BLACK)

                # blit the buffer to the display
                tft.blit_buffer(sprite, man.x, man.y, SPRITE_WIDTH,
                                SPRITE_HEIGHT)

            time.sleep(0.1)

    finally:
        # shutdown spi
        spi.deinit()

        # turn off display backlight
        axp.disablePower(axp202c.AXP202_LDO2)
コード例 #18
0
ファイル: watch_draw.py プロジェクト: mcu786/st7789_mpy
def main():
    '''
    Draw on screen using focaltouch sensor
    '''
    try:
        # Turn on display backlight
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize display spi port
        spi = machine.SoftSPI(2,
                              baudrate=32000000,
                              polarity=1,
                              phase=0,
                              bits=8,
                              firstbit=0,
                              sck=machine.Pin(18, machine.Pin.OUT),
                              mosi=machine.Pin(19, machine.Pin.OUT))

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            240,
                            cs=machine.Pin(5, machine.Pin.OUT),
                            dc=machine.Pin(27, machine.Pin.OUT),
                            backlight=machine.Pin(12, machine.Pin.OUT),
                            rotation=2)

        # enable display and clear screen
        tft.init()
        tft.fill(st7789.BLACK)
        tft.text(font, "Draw", 104, 1, st7789.WHITE)

        # enable focaltouch touchscreen
        touch_i2c = machine.I2C(scl=machine.Pin(32), sda=machine.Pin(23))
        touch = focaltouch.FocalTouch(touch_i2c)

        color_index = 0
        color = 0
        # draw color swatches used to select color to draw
        for color_index, color in enumerate(COLORS):
            tft.fill_rect(color_index * 30, 210, 30, 30, color)

        # draw box around currently selected color
        tft.rect(color_index * 30, 210, 30, 30, st7789.WHITE)
        tft.rect(color_index * 30 + 1, 211, 28, 28, st7789.BLACK)
        tft.rect(color_index * 30 + 2, 212, 26, 26, st7789.BLACK)

        while True:
            # can be up to two touches
            if touch.touched == 1:

                # get x and y points of the first touch
                p_x = touch.touches[0]['x']
                p_y = touch.touches[0]['y']

                # If point is in the lowest 30 rows of the screen
                # change color to swatch pressed.
                if p_y > 209:
                    # remove box from around previous color swatch
                    tft.rect(color_index * 30, 210, 30, 30, color)
                    tft.rect(color_index * 30 + 1, 211, 28, 28, color)
                    tft.rect(color_index * 30 + 2, 212, 26, 26, color)

                    # update new color
                    color_index = p_x // 30
                    color = COLORS[color_index]

                    # draw box around newly selected color swatch
                    tft.rect(color_index * 30, 210, 30, 30, st7789.WHITE)
                    tft.rect(color_index * 30 + 1, 211, 28, 28, st7789.BLACK)
                    tft.rect(color_index * 30 + 2, 212, 26, 26, st7789.BLACK)

                else:
                    # draw the pixel - would be better with lines
                    tft.pixel(p_x, p_y, color)

    finally:
        # shutdown i2c
        if 'touch_i2c' in locals():
            touch_i2c.deinit()

        # shutdown spi
        if 'spi' in locals():
            spi.deinit()

        # turn off display backlight
        axp.disablePower(axp202c.AXP202_LDO2)
コード例 #19
0
def main():
    try:
        # Turn power on display power
        axp = axp202c.PMU()
        axp.enablePower(axp202c.AXP202_LDO2)

        # initialize spi port
        spi = SPI(2,
                  baudrate=32000000,
                  sck=Pin(18, Pin.OUT),
                  mosi=Pin(19, Pin.OUT))

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            240,
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(12, Pin.OUT),
                            rotation=2,
                            buffer_size=16 * 32 * 2)

        # enable display
        tft.init()
        tft.fill(st7789.BLACK)
        time.sleep(2)

        while True:
            # say Hello! and show off some colors
            tft.fill(st7789.BLUE)
            tft.text(font, "Hello!", 76, 96, st7789.WHITE, st7789.BLUE)
            time.sleep(1)
            tft.fill(0)
            for _ in range(2):
                for i in range(256):
                    j = i % 64
                    tft.rect(68 - j, 96 - j, j * 2 + 104, j * 2 + 32, wheel(i))
                    tft.text(font, "Hello!", 76, 96, wheel(i))

            time.sleep(1)

            # display some random letters
            tft.fill(0)
            col_max = tft.width() - font.WIDTH
            row_max = tft.height() - font.HEIGHT

            for _ in range(5):
                for c in range(0, 128):
                    tft.text(font, c, random.randint(0, col_max),
                             random.randint(0, row_max), random_color())
                    time.sleep(0.005)

            time.sleep(1)

            # write hello! randomly on display running through each rotation
            for rotation in range(9):
                tft.fill(0)
                tft.rotation(rotation % 4 + 2)
                col_max = tft.width() - font.WIDTH * 6
                row_max = tft.height() - font.HEIGHT

                for _ in range(250):
                    tft.text(font, "Hello!", random.randint(0, col_max),
                             random.randint(0, row_max), random_color(),
                             random_color())

    finally:
        # shutdown spi
        spi.deinit()
        # turn off display power
        axp.disablePower(axp202c.AXP202_LDO2)
コード例 #20
0
def main():
    # Turn display power
    axp = axp202c.PMU(address=0x34)
    axp.enablePower(axp202c.AXP192_LDO2)
    # Set backlight voltage
    axp.setDC3Voltage(3000)

    spi = SPI(
        2,
        baudrate=60000000,
        sck=Pin(18),
        mosi=Pin(23))

    # initialize display

    tft = ili9342c.ILI9342C(
        spi,
        320,
        240,
        reset=Pin(33, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(15, Pin.OUT),
        rotation=0)

    colors = cycle([0xe000, 0xece0, 0xe7e0, 0x5e0, 0x00d3, 0x7030])
    foreground = next(colors)
    background = ili9342c.BLACK

    tft.init()
    tft.fill(background)
    utime.sleep(1)

    height = tft.height()
    width = tft.width()
    last_line = height - font.HEIGHT

    tfa = 0        # top free area
    tfb = 0        # bottom free area
    tft.vscrdef(tfa, height, tfb)

    scroll = 0
    character = 32

    while True:
        # clear top line before scrolling off display
        tft.fill_rect(0, scroll, width, 1, background)

        # Write new line when we have scrolled the height of a character
        if scroll % font.HEIGHT == 0:
            line = (scroll + last_line) % height

            # write character hex value as a string
            tft.text(
                font,
                'x{:02x}'.format(character),
                16,
                line,
                foreground,
                background)

            # write character using a integer (could be > 0x7f)
            tft.text(
                font,
                character,
                90,
                line,
                foreground,
                background)

            # change color for next line
            foreground = next(colors)

            # next character with rollover at 256
            character += 1
            if character > 127:
                character = 32

        # scroll the screen up 1 row
        tft.vscsad(scroll+tfa)
        scroll += 1
        scroll %= height

        utime.sleep(0.01)
コード例 #21
0
import machine
from machine import Pin
import debug
import gfx
import utime
import axp202c as axp202

# import webrepl

# DO NOT GO BELOW 80Mhz!!!  Will break wifi and complicate serial!
machine.freq(240000000)
utime.sleep_ms(100)

micropython.alloc_emergency_exception_buf(100)
print('Booting...')
axp = axp202.PMU()
axp.enablePower(axp202.AXP202_LDO2)
axp.enablePower(axp202.AXP202_DCDC3)
axp.clearIRQ()

gfx.boot()

# webrepl.start(password="******")

debug.space_free()
debug.m_freq()
debug.raw_temp()
debug.showVoltage()

gc.collect()