{"id":13802197,"url":"https://github.com/russhughes/st7789_mpy","last_synced_at":"2025-04-12T23:39:05.487Z","repository":{"id":37648158,"uuid":"237678059","full_name":"russhughes/st7789_mpy","owner":"russhughes","description":"Fast MicroPython driver for  ST7789 display module written in C","archived":false,"fork":false,"pushed_at":"2024-08-16T08:30:25.000Z","size":112818,"stargazers_count":609,"open_issues_count":29,"forks_count":113,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-12T23:38:55.211Z","etag":null,"topics":["bitmap-font","driver","esp32","firmware","ili9341","ili9342","m5stack-core","m5stack-core2","micropython","pyboard","st7735","st7789","t-display","t-dongle-s3","twatch-2020","wio-terminal"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/russhughes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-01T21:07:38.000Z","updated_at":"2025-04-08T19:18:53.000Z","dependencies_parsed_at":"2024-09-10T05:18:20.737Z","dependency_job_id":null,"html_url":"https://github.com/russhughes/st7789_mpy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russhughes%2Fst7789_mpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russhughes%2Fst7789_mpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russhughes%2Fst7789_mpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russhughes%2Fst7789_mpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/russhughes","download_url":"https://codeload.github.com/russhughes/st7789_mpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647255,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitmap-font","driver","esp32","firmware","ili9341","ili9342","m5stack-core","m5stack-core2","micropython","pyboard","st7735","st7789","t-display","t-dongle-s3","twatch-2020","wio-terminal"],"created_at":"2024-08-04T00:01:38.882Z","updated_at":"2025-04-12T23:39:05.465Z","avatar_url":"https://github.com/russhughes.png","language":"Python","funding_links":[],"categories":["Libraries","Python"],"sub_categories":["Display"],"readme":"\n# ST7789 Driver for MicroPython\n\nThis driver is based on [devbis' st7789_mpy driver.](https://github.com/devbis/st7789_mpy)\nI modified the original driver for one of my projects to add:\n\n- Display Rotation.\n- Scrolling\n- Writing text using bitmaps converted from True Type fonts\n- Drawing text using 8 and 16-bit wide bitmap fonts\n- Drawing text using Hershey vector fonts\n- Drawing JPGs, including a SLOW mode to draw jpg's larger than available ram\n  using the TJpgDec - Tiny JPEG Decompressor R0.01d. from\n  http://elm-chan.org/fsw/tjpgd/00index.html\n- Drawing PNGs using the pngle library from https://github.com/kikuchan/pngle\n- Drawing and rotating Polygons and filled Polygons.\n- Tracking bounds\n- Custom init capability to support st7735, ili9341, ili9342 and other displays. See the examples/configs folder for M5Stack Core, M5Stack Core2, T-DONGLE-S3 and Wio_Terminal devices.\n\nIncluded are 12 bitmap fonts derived from classic pc text mode fonts, 26\nHershey vector fonts and several example programs for different devices.\n\n## Display Configuration\n\nSome displays may use a BGR color order or inverted colors. The `cfg_helper.py`\nprogram can be used to determine the color order, inversion_mode, colstart, and\nrowstart values needed for a display.\n\n### Color Modes\n\nYou can test for the correct color order needed by a display by filling it with\nthe `st7789.RED` color and observing the actual color displayed.\n\n  - If the displayed color is RED, the settings are correct.\n  - If the displayed color is BLUE, `color_order` should be `st7789.BGR`.\n  - If the displayed color is YELLOW, `inversion_mode` should be `True.`\n  - If the displayed color is CYAN, `color_order` should be `st7789.BGR` and\n    `inversion_mode` should be `True.`\n\n### colstart and rowstart\n\nSome displays have a frame buffer memory larger than the physical display\nmatrix. In these cases, the driver must be configured with the position of the\nfirst physical column and row pixels relative to the frame buffer. Each\nrotation setting of the display may require different colstart and rowstart\nvalues.\n\nThe driver automatically sets the `colstart` and `rowstart` values for common\n135x240, 240x240, 170x320 and 240x320 displays. If the default values do not work for\nyour display, these values can be overridden using the `offsets` method. The\n`offsets` method should be called after any `rotation` method calls.\n\n#### 128x128 st7735 cfg_helper.py example\n\n```\ninversion_mode(False)\ncolor_order = st7789.BGR\nfor rotation 0 use offset(2, 1)\nfor rotation 1 use offset(1, 2)\nfor rotation 2 use offset(2, 3)\nfor rotation 3 use offset(3, 2)\n```\n\n#### 128x160 st7735 cfg_helper.py example\n\n```\ninversion_mode(False)\ncolor_order = st7789.RGB\nfor rotation 0 use offset(0, 0)\nfor rotation 1 use offset(0, 0)\nfor rotation 2 use offset(0, 0)\nfor rotation 3 use offset(0, 0)\n```\n\n## Pre-compiled firmware files\n\nThe firmware directory contains pre-compiled firmware for various devices with\nthe st7789 C driver and frozen python font files. See the README.md file in the\nfonts folder for more information on the font files.\n\nMicroPython MicroPython v1.20.0 compiled with ESP IDF v4.4.4 using CMake\n\nDirectory             | File         | Device\n--------------------- | ------------ | ----------------------------------\nGENERIC-7789          | firmware.bin | Generic ESP32 devices\nGENERIC_SPIRAM-7789   | firmware.bin | Generic ESP32 devices with SPI Ram\nGENERIC_C3            | firmware.bin | Generic ESP32-C3 devices\nLOLIN_S2_MINI         | firmware.bin | Wemos S2 mini\nPYBV11                | firmware.dfu | Pyboard v1.1 (No PNG)\nRP2                   | firmware.uf2 | Raspberry Pi Pico RP2040\nRP2W                  | firmware.uf2 | Raspberry Pi PicoW RP2040\nT-DISPLAY             | firmware.bin | LILYGO® TTGO T-Display\nT-Watch-2020          | firmware.bin | LILYGO® T-Watch 2020\nWIO_TERMINAL          | firmware.bin | Seeed Wio Terminal\n\n\n## Additional Modules\n\nModule             | Source\n------------------ | -----------------------------------------------------------\naxp202c            | https://github.com/lewisxhe/AXP202X_Libraries\nfocaltouch         | https://gitlab.com/mooond/t-watch2020-esp32-with-micropython\n\n## Video Examples\n\nExample               | Video\n--------------------- | -----------------------------------------------------------\nPYBV11 hello.py       | https://youtu.be/OtcERmad5ps\nPYBV11 scroll.py      | https://youtu.be/ro13rvaLKAc\nT-DISPLAY fonts.py    | https://youtu.be/2cnAhEucPD4\nT-DISPLAY hello.py    | https://youtu.be/z41Du4GDMSY\nT-DISPLAY scroll.py   | https://youtu.be/GQa-RzHLBak\nT-DISPLAY roids.py    | https://youtu.be/JV5fPactSPU\nTWATCH-2020 draw.py   | https://youtu.be/O_lDBnvH1Sw\nTWATCH-2020 hello.py  | https://youtu.be/Bwq39tuMoY4\nTWATCH-2020 bitmap.py | https://youtu.be/DgYzgnAW2d8\nTWATCH-2020 watch.py  | https://youtu.be/NItKb6umMc4\n\nThis is a work in progress.\n\n## Thanks go out to:\n\n- https://github.com/devbis for the original driver this is based on.\n- https://github.com/hklang10 for letting me know of the new mp_raise_ValueError().\n- https://github.com/aleggon for finding the correct offsets for 240x240\n  displays and for discovering issues compiling STM32 ports.\n\n-- Russ\n\n## Overview\n\nThis is a driver for MicroPython to handle cheap displays based on the ST7789\nchip. The driver is written in C. Firmware is provided for ESP32, ESP32 with SPIRAM,\npyboard1.1, and Raspberry Pi Pico devices.\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/ST7789.jpg\" alt=\"ST7789 display photo\"/\u003e\n\u003c/p\u003e\n\n\n# Setup MicroPython Build Environment in Ubuntu 20.04.2\n\nSee the MicroPython\n[README.md](https://github.com/micropython/micropython/blob/master/ports/esp32/README.md#setting-up-esp-idf-and-the-build-environment)\nif you run into any build issues not directly related to the st7789 driver. The\nrecommended MicroPython build instructions may have changed.\n\nUpdate and upgrade Ubuntu using apt-get if you are using a new install of\nUbuntu or the Windows Subsystem for Linux.\n\n```bash\nsudo apt-get -y update\nsudo apt-get -y upgrade\n```\n\nUse apt-get to install the required build tools.\n\n```bash\nsudo apt-get -y install build-essential libffi-dev git pkg-config cmake virtualenv python3-pip python3-virtualenv\n```\n\n### Install a compatible esp-idf SDK\n\nThe MicroPython README.md states: \"The ESP-IDF changes quickly, and MicroPython\nonly supports certain versions. Currently, MicroPython supports v4.0.2, v4.1.1,\nand v4.2 although other IDF v4 versions may also work.\"  I have had good luck\nusing IDF v4.4\n\nClone the esp-idf SDK repo -- this usually takes several minutes.\n\n```bash\ngit clone -b v4.4 --recursive https://github.com/espressif/esp-idf.git\ncd esp-idf/\ngit pull\n```\n\nIf you already have a copy of the IDF, you can checkout a version compatible\nwith MicroPython and update the submodules using:\n\n```bash\n$ cd esp-idf\n$ git checkout v4.4\n$ git submodule update --init --recursive\n```\n\nInstall the esp-idf SDK.\n\n```bash\n./install.sh\n```\n\nSource the esp-idf export.sh script to set the required environment variables.\nYou must source the file and not run it using ./export.sh. You will need to\nsource this file before compiling MicroPython.\n\n```bash\nsource export.sh\ncd ..\n```\n\nClone the MicroPython repo.\n\n```bash\ngit clone https://github.com/micropython/micropython.git\n```\n\nClone the st7789 driver repo.\n\n```bash\ngit clone https://github.com/russhughes/st7789_mpy.git\n```\n\nUpdate the git submodules and compile the MicroPython cross-compiler\n\n```bash\ncd micropython/\ngit submodule update --init\ncd mpy-cross/\nmake\ncd ..\ncd ports/esp32\n```\n\nCopy any .py files you want to include in the firmware as frozen python modules\nto the modules subdirectory in ports/esp32. Be aware there is a limit to the\nflash space available. You will know you have exceeded this limit if you\nreceive an error message saying the code won't fit in the partition or if your\nfirmware continuously reboots with an error.\n\nFor example:\n\n```bash\ncp ../../../st7789_mpy/fonts/bitmap/vga1_16x16.py modules\ncp ../../../st7789_mpy/fonts/truetype/NotoSans_32.py modules\ncp ../../../st7789_mpy/fonts/vector/scripts.py modules\n```\n\nBuild the MicroPython firmware with the driver and frozen .py files in the\nmodules directory. If you did not add any .py files to the modules directory,\nyou can leave out the FROZEN_MANIFEST and FROZEN_MPY_DIR settings.\n\n```bash\nmake USER_C_MODULES=../../../../st7789_mpy/st7789/micropython.cmake FROZEN_MANIFEST=\"\" FROZEN_MPY_DIR=$UPYDIR/modules\n```\n\nErase and flash the firmware to your device. Set PORT= to the ESP32's usb\nserial port. I could not get the USB serial port to work under the Windows\nSubsystem (WSL2) for Linux. If you have the same issue, you can copy the\nfirmware.bin file and use the Windows esptool.py to flash your device.\n\n```bash\nmake USER_C_MODULES=../../../../st7789_mpy/st7789/micropython.cmake PORT=/dev/ttyUSB0 erase\nmake USER_C_MODULES=../../../../st7789_mpy/st7789/micropython.cmake PORT=/dev/ttyUSB0 deploy\n```\n\nThe firmware.bin file will be in the build-GENERIC directory. To flash using\nthe python esptool.py utility. Use pip3 to install the esptool if it's not\nalready installed.\n\n```bash\npip3 install esptool\n```\n\nSet PORT= to the ESP32's USB serial port\n\n```bash\nesptool.py --port COM3 erase_flash\nesptool.py --chip esp32 --port COM3 write_flash -z 0x1000 firmware.bin\n```\n## CMake building instructions for MicroPython 1.14 and later\n\nfor ESP32:\n\n    $ cd micropython/ports/esp32\n\nAnd then compile the module with specified USER_C_MODULES dir.\n\n    $ make USER_C_MODULES=../../../../st7789_mpy/st7789/micropython.cmake\n\nfor Raspberry Pi PICO:\n\n    $ cd micropython/ports/rp2\n\nAnd then compile the module with specified USER_C_MODULES dir.\n\n    $ make USER_C_MODULES=../../../st7789_mpy/st7789/micropython.cmake\n\n## Working examples\n\nThis module was tested on ESP32, STM32 based pyboard v1.1, and the Raspberry Pi\nPico. You have to provide an `SPI` object and the pin to use for the `dc' input\nof the screen.\n\n\n    # ESP32 Example\n    # To use baudrates above 26.6MHz you must use my firmware or modify the micropython\n    # source code to increase the SPI baudrate limit by adding SPI_DEVICE_NO_DUMMY to the\n    # .flag member of the spi_device_interface_config_t struct in the machine_hw_spi_init_internal.c\n    # file.  Not doing so will cause the ESP32 to crash if you use a baudrate that is too high.\n\n    import machine\n    import st7789\n    spi = machine.SPI(2, baudrate=40000000, polarity=1, sck=machine.Pin(18), mosi=machine.Pin(23))\n    display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(4, machine.Pin.OUT), dc=machine.Pin(2, machine.Pin.OUT))\n    display.init()\n\n\n## Methods\n\n- `st7789.ST7789(spi, width, height, dc, reset, cs, backlight, rotations, rotation, custom_init, color_order, inversion, options, buffer_size)`\n\n    ### Required positional arguments:\n    - `spi` spi device\n    - `width` display width\n    - `height` display height\n\n    ### Required keyword arguments:\n    - `dc` sets the pin connected to the display data/command selection input.\n      This parameter is always required.\n\n    ### Optional keyword arguments:\n\n    - `reset` sets the pin connected to the display's hardware reset input. If\n      the displays reset pin is tied high, the `reset` parameter is not\n      required.\n\n    - `cs` sets the pin connected to the displays chip select input. If the\n      display's CS pin is tied low, the display must be the only device\n      connected to the SPI port. The display will always be the selected\n      device, and the `cs` parameter is not required.\n\n    - `backlight` sets the pin connected to the display's backlight enable\n      input. The display's backlight input can often be left floating or\n      disconnected as the backlight on some displays is always powered on and\n      cannot be turned off.\n\n    - `rotations` sets the orientation table. The orientation table is a list\n      of tuples for each `rotation` used to set the MADCTL register, display width,\n      display height, start_x, and start_y values.\n\n      Default `rotations` are included for the following st7789 and st7735\n      display sizes:\n\n      Display | Default Orientation Tables\n      ------- | --------------------------\n      240x320 | [(0x00, 240, 320,  0,  0), (0x60, 320, 240,  0,  0), (0xc0, 240, 320,  0,  0), (0xa0, 320, 240,  0,  0)]\n      170x320 |\t[(0x00, 170, 320, 35, 0), (0x60, 320, 170, 0, 35), (0xc0, 170, 320, 35, 0), (0xa0, 320, 170, 0, 35)]\n      240x240 | [(0x00, 240, 240,  0,  0), (0x60, 240, 240,  0,  0), (0xc0, 240, 240,  0, 80), (0xa0, 240, 240, 80,  0)]\n      135x240 | [(0x00, 135, 240, 52, 40), (0x60, 240, 135, 40, 53), (0xc0, 135, 240, 53, 40), (0xa0, 240, 135, 40, 52)]\n      128x160 | [(0x00, 128, 160,  0,  0), (0x60, 160, 128,  0,  0), (0xc0, 128, 160,  0,  0), (0xa0, 160, 128,  0,  0)]\n      128x128 | [(0x00, 128, 128,  2,  1), (0x60, 128, 128,  1,  2), (0xc0, 128, 128,  2,  3), (0xa0, 128, 128,  3,  2)]\n       other  | [(0x00, width, height, 0, 0)]\n\n      You may define as many rotations as you wish.\n\n    - `rotation` sets the display rotation according to the orientation table.\n\n      The default orientation table defines four counter-clockwise rotations for 240x320, 240x240,\n      134x240, 128x160 and 128x128 displays with the LCD's ribbon cable at the bottom of the display.\n      The default rotation is Portrait (0 degrees).\n\n      Index | Rotation\n      ----- | --------\n      0     | Portrait (0 degrees)\n      1     | Landscape (90 degrees)\n      2     | Reverse Portrait (180 degrees)\n      3     | Reverse Landscape (270 degrees)\n\n    - `custom_init` List of display configuration commands to send to the display during the display init().\n        The list contains tuples with a bytes object, optionally followed by a delay specified in ms. The first\n        byte of the bytes object contains the command to send optionally followed by data bytes.\n        See the `examples/configs/t_dongle_s3/tft_config.py` file or an example.\n\n    - `color_order` Sets the color order used by the driver (st7789.RGB or st7789.BGR)\n\n    - `inversion` Sets the display color inversion mode if True, clears the\n      display color inversion mode if false.\n\n    - `options` Sets driver option flags.\n\n      Option        | Description\n      ------------- | -----------\n      st7789.WRAP   | pixels, lines, polygons, and Hershey text will wrap around the display both horizontally and vertically.\n      st7789.WRAP_H | pixels, lines, polygons, and Hershey text will wrap around the display horizontally.\n      st7789.WRAP_V | pixels, lines, polygons, and Hershey text will wrap around the display vertically.\n\n    - `buffer_size` If a buffer_size is not specified, a dynamically allocated\n      buffer is created and freed as needed. If a buffer_size is set, it must\n      be large enough to contain the largest bitmap, font character, and\n      decoded JPG image used (Rows * Columns * 2 bytes, 16bit colors in RGB565\n      notation). Dynamic allocation is slower and can cause heap fragmentation,\n      so garbage collection (GC) should be enabled.\n\n- `inversion_mode(bool)` Sets the display color inversion mode if True, clears\n  the display color inversion mode if False.\n\n- `madctl(value)` Returns the current value of the MADCTL register or sets the MADCTL register if a value is passed to the\n   method. The MADCTL register is used to set the display rotation and color order.\n\n  #### [MADCTL constants](#madctl-constants)\n\n    Constant Name    | Value | Description\n    ---------------- | ----- | ----------------------\n    st7789.MADCTL_MY | 0x80  | Page Address Order\n    st7789_MADCTL_MX | 0x40  | Column Address Order\n    st7789_MADCTL_MV | 0x20  | Page/Column Order\n    st7789_MADCTL_ML | 0x10  | Line Address Order\n    st7789_MADCTL_MH | 0x04  | Display Data Latch Order\n    st7789_RGB       | 0x00  | RGB color order\n    st7789_BGR       | 0x08  | BGR color order\n\n   #### [MADCTL examples](#madctl-examples)\n\n\n     Orientation | MADCTL Values for RGB color order, for BGR color order add 0x08 to the value.\n     ----------- | ---------------------------------------------------------------------------------\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_0.png\" /\u003e | 0x00\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_y.png\" /\u003e | 0x80 ( MADCTL_MY )\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_x.png\" /\u003e | 0x40 ( MADCTL_MX )\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_xy.png\" /\u003e | 0xC0 ( MADCTL_MX + MADCTL_MY )\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_v.png\" /\u003e | 0x20 ( MADCTL_MV )\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_vy.png\" /\u003e | 0xA0 ( MADCTL_MV + MADCTL_MY )\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_vx.png\" /\u003e | 0x60 ( MADCTL_MV + MADCTL_MX )\n     \u003cimg src=\"https://raw.githubusercontent.com/russhughes/st7789_mpy/master/docs/madctl_vxy.png\" /\u003e | 0xE0 ( MADCTL_MV + MADCTL_MX + MADCTL_MY )\n\n- `init()`\n\n  Must be called to initialize the display.\n\n- `on()`\n\n  Turn on the backlight pin if one was defined during init.\n\n- `off()`\n\n  Turn off the backlight pin if one was defined during init.\n\n- `sleep_mode(value)`\n\n  If value is True, cause the display to enter sleep mode, otherwise wake up if value is False. During sleep display content may not be preserved.\n\n\n- `fill(color)`\n\n  Fill the display with the specified color.\n\n- `pixel(x, y, color)`\n\n  Set the specified pixel to the given `color`.\n\n- `line(x0, y0, x1, y1, color)`\n\n  Draws a single line with the provided `color` from (`x0`, `y0`) to\n  (`x1`, `y1`).\n\n- `hline(x, y, length, color)`\n\n  Draws a single horizontal line with the provided `color` and `length`\n  in pixels. Along with `vline`, this is a fast version with fewer SPI calls.\n\n- `vline(x, y, length, color)`\n\n  Draws a single horizontal line with the provided `color` and `length`\n  in pixels.\n\n- `rect(x, y, width, height, color)`\n\n  Draws a rectangle from (`x`, `y`) with corresponding dimensions\n\n- `fill_rect(x, y, width, height, color)`\n\n  Fill a rectangle starting from (`x`, `y`) coordinates\n\n- `circle(x, y, r, color)`\n\n  Draws a circle with radius `r` centered at the (`x`, `y`) coordinates in the given\n  `color`.\n\n- `fill_circle(x, y, r, color)`\n\n  Draws a filled circle with radius `r` centered at the (`x`, `y`) coordinates\n  in the given `color`.\n\n- `blit_buffer(buffer, x, y, width, height)`\n\n  Copy bytes() or bytearray() content to the screen internal memory. Note:\n  every color requires 2 bytes in the array\n\n- `text(font, s, x, y[, fg, bg])`\n\n  Write `s` (integer, string or bytes) to the display using the specified bitmap\n  `font` with the coordinates as the upper-left corner of the text. The optional\n  arguments `fg` and `bg` can set the foreground and background colors of the\n  text; otherwise the foreground color defaults to `WHITE`, and the background\n  color defaults to `BLACK`. See the `README.md` in the `fonts/bitmap` directory\n  for example fonts.\n\n- `write(bitmap_font, s, x, y[, fg, bg, background_tuple, fill_flag])`\n\n  Write text to the display using the specified proportional or Monospace bitmap\n  font module with the coordinates as the upper-left corner of the text. The\n  foreground and background colors of the text can be set by the optional\n  arguments `fg` and `bg`, otherwise the foreground color defaults to `WHITE`\n  and the background color defaults to `BLACK`.\n\n  Transparency can be emulated by providing a `background_tuple` containing\n  (bitmap_buffer, width, height). This is the same format used by the jpg_decode\n  method. See examples/T-DISPLAY/clock/clock.py for an example.\n\n  See the `README.md` in the `truetype/fonts` directory for example fonts.\n  Returns the width of the string as printed in pixels. Accepts UTF8 encoded strings.\n\n  The `font2bitmap` utility creates compatible 1 bit per pixel bitmap modules\n  from Proportional or Monospaced True Type fonts. The character size,\n  foreground, background colors, and characters in the bitmap\n  module may be specified as parameters. Use the -h option for details. If you\n  specify a buffer_size during the display initialization, it must be large\n  enough to hold the widest character (HEIGHT * MAX_WIDTH * 2).\n\n- `write_len(bitap_font, s)`\n\n  Returns the string's width in pixels if printed in the specified font.\n\n- `draw(vector_font, s, x, y[, fg, scale])`\n\n  Draw text to the display using the specified Hershey vector font with the\n  coordinates as the lower-left corner of the text. The foreground color of the\n  text can be set by the optional argument `fg`. Otherwise the foreground color\n  defaults to `WHITE`. The size of the text can be scaled by specifying a\n  `scale` value. The `scale` value must be larger than 0 and can be a\n  floating-point or an integer value. The `scale` value defaults to 1.0. See\n  the README.md in the `vector/fonts` directory, for example fonts and the\n  utils directory for a font conversion program.\n\n- `draw_len(vector_font, s[, scale])`\n\n  Returns the string's width in pixels if drawn with the specified font.\n\n- `jpg(jpg, x, y [, method])`\n\n  Draw a `jpg` on the display with the given `x` and `y` coordinates as the\n  upper left corner of the image. `jpg` may be a string containing a filename\n  or a buffer containing the JPEG image data.\n\n  The memory required to decode and display a JPG can be considerable as a full-screen\n  320x240 JPG would require at least 3100 bytes for the working area + 320 * 240 * 2\n  bytes of ram to buffer the image. Jpg images that would require a buffer larger than\n  available memory can be drawn by passing `SLOW` for the `method`. The `SLOW` `method`\n  will draw the image one piece at a time using the Minimum Coded Unit (MCU, typically\n  a multiple of 8x8) of the image. The default method is `FAST`.\n\n- `jpg_decode(jpg_filename [, x, y, width, height])`\n\n  Decode a jpg file and return it or a portion of it as a tuple composed of\n  (buffer, width, height). The buffer is a color565 blit_buffer compatible byte\n  array. The buffer will require width * height * 2 bytes of memory.\n\n  If the optional x, y, width, and height parameters are given, the buffer will\n  only contain the specified area of the image. See examples/T-DISPLAY/clock/clock.py\n  examples/T-DISPLAY/toasters_jpg/toasters_jpg.py for examples.\n\n- `png(png_filename, x, y [, mask])`\n\n  Draw a PNG file on the display with upper left corner of the image at the given `x` and `y`\n  coordinates. The PNG will be clipped if it is not able to fit fully on the display. The\n  PNG will be drawn one line at a time. Since the driver does not contain a frame buffer, \n  transparency is not supported. Providing a `True` value for the `mask` parameter\n  will prevent pixels with a zero alpha channel value from being displayed.  Drawing masked PNG's is\n  slower than non-masked as each visible line segment is drawn separately. For an example of using a\n  mask, see the alien.py program in the examples/png folder.\n\n- `polygon_center(polygon)`\n\n   Return the center of the `polygon` as an (x, y) tuple. The `polygon` should\n   consist of a list of (x, y) tuples forming a closed convex polygon.\n\n- `fill_polygon(polygon, x, y, color[, angle, center_x, center_y])`\n\n  Draw a filled `polygon` at the `x`, and `y` coordinates in the `color` given.\n  The polygon may be rotated `angle` radians about the `center_x` and\n  `center_y` point. The polygon should consist of a list of (x, y) tuples\n  forming a closed convex polygon.\n\n  See the TWATCH-2020 `watch.py` demo for an example.\n\n- `polygon(polygon, x, y, color, angle, center_x, center_y)`\n\n  Draw a `polygon` at the `x`, and `y` coordinates in the `color` given. The\n  polygon may be rotated `angle` radians about the `center_x` and `center_y`\n  point. The polygon should consist of a list of (x, y) tuples forming a closed\n  convex polygon.\n\n  See the T-Display `roids.py` for an example.\n\n- `bounding({status, as_rect})`\n\n  Bounding enables or disables tracking the display area that has been written\n  to. Initially, tracking is disabled; pass a True value to enable tracking and\n  False to disable it. Passing a True or False parameter will reset the current\n  bounding rectangle to (display_width, display_height, 0, 0).\n\n  Returns a four integer tuple containing (min_x, min_y, max_x, max_y)\n  indicating the area of the display that has been written to since the last\n  clearing.\n\n  If `as_rect` parameter is True, the returned tuple will contain (min_x,\n  min_y, width, height) values.\n\n  See the TWATCH-2020 `watch.py` demo for an example.\n\n- `bitmap(bitmap, x , y [, index])`\n\n  Draw `bitmap` using the specified `x`, `y` coordinates as the upper-left\n  corner of the `bitmap`. The optional `index` parameter provides a method to\n  select from multiple bitmaps contained a `bitmap` module. The `index` is used\n  to calculate the offset to the beginning of the desired bitmap using the\n  modules HEIGHT, WIDTH, and BPP values.\n\n  The `imgtobitmap.py` utility creates compatible 1 to 8 bit per pixel bitmap\n  modules from image files using the Pillow Python Imaging Library.\n\n  The `monofont2bitmap.py` utility creates compatible 1 to 8 bit per pixel\n  bitmap modules from Monospaced True Type fonts. See the `inconsolata_16.py`,\n  `inconsolata_32.py` and `inconsolata_64.py` files in the `examples/lib`\n  folder for sample modules and the `mono_font.py` program for an example using\n  the generated modules.\n\n  The character sizes, bit per pixel, foreground, background colors, and the\n  characters to include in the bitmap module may be specified as parameters.\n  Use the -h option for details. Bits per pixel settings larger than one may be\n  used to create antialiased characters at the expense of memory use. If you\n  specify a buffer_size during the display initialization, it must be large\n  enough to hold the one character (HEIGHT * WIDTH * 2).\n\n- `width()`\n\n  Returns the current logical width of the display. (ie a 135x240 display\n  rotated 90 degrees is 240 pixels wide)\n\n- `height()`\n\n  Returns the current logical height of the display. (ie a 135x240 display\n  rotated 90 degrees is 135 pixels high)\n\n- `rotation(r)`\n\n  Set the rotates the logical display in a counter-clockwise direction.\n  0-Portrait (0 degrees), 1-Landscape (90 degrees), 2-Inverse Portrait (180\n  degrees), 3-Inverse Landscape (270 degrees)\n\n- `offset(x_start, y_start)` The memory in the ST7789 controller is configured\n  for a 240x320 display. When using a smaller display like a 240x240 or\n  135x240, an offset needs to be added to the x and y parameters so that the\n    pixels are written to the memory area corresponding to the visible display.\n  The offsets may need to be adjusted when rotating the display.\n\n  For example, the TTGO-TDisplay is 135x240 and uses the following offsets.\n\n  | Rotation | x_start | y_start |\n  |----------|---------|---------|\n  | 0        | 52      | 40      |\n  | 1        | 40      | 53      |\n  | 2        | 53      | 40      |\n  | 3        | 40      | 52      |\n\n  When the rotation method is called, the driver will adjust the offsets for a\n  135x240 or 240x240 display. Your display may require using different offset\n  values; if so, use the `offset` method after `rotation` to set the offset\n  values.\n\n  The values needed for a particular display may not be documented and may\n  require some experimentation to determine the correct values. One technique\n  is to draw a box the same size as the display and then make small changes to\n  the offsets until the display looks correct. See the `cfg_helper.py` program\n  in the examples folder for more information.\n\n\nThe module exposes predefined colors:\n  `BLACK`, `BLUE`, `RED`, `GREEN`, `CYAN`, `MAGENTA`, `YELLOW`, and `WHITE`\n\n## Scrolling\n\nThe st7789 display controller contains a 240 by 320-pixel frame buffer used to\nstore the pixels for the display. For scrolling, the frame buffer consists of\nthree separate areas; The (`tfa`) top fixed area, the (`height`) scrolling\narea, and the (`bfa`) bottom fixed area. The `tfa` is the upper portion of the\nframe buffer in pixels not to scroll. The `height` is the center portion of the\nframe buffer in pixels to scroll. The `bfa` is the lower portion of the frame\nbuffer in pixels not to scroll. These values control the ability to scroll the\nentire or a part of the display.\n\nFor displays that are 320 pixels high, setting the `tfa` to 0, `height` to 320,\nand `bfa` to 0 will allow scrolling of the entire display. You can set the\n`tfa` and `bfa` to a non-zero value to scroll a portion of the display. `tfa` +\n`height` + `bfa` = should equal 320, otherwise the scrolling mode is undefined.\n\nDisplays less than 320 pixels high, the `tfa`, `height`, and `bfa` will need to\nbe adjusted to compensate for the smaller LCD panel. The actual values will\nvary depending on the configuration of the LCD panel. For example, scrolling\nthe entire 135x240 TTGO T-Display requires a `tfa` value of 40, `height` value\nof 240, and `bfa` value of 40 (40+240+40=320) because the T-Display LCD shows\n240 rows starting at the 40th row of the frame buffer, leaving the last 40 rows\nof the frame buffer undisplayed.\n\nOther displays like the Waveshare Pico LCD 1.3 inch 240x240 display require the\n`tfa` set to 0, `height` set to 240, and `bfa` set to 80 (0+240+80=320) to\nscroll the entire display. The Pico LCD 1.3 shows 240 rows starting at the 0th\nrow of the frame buffer, leaving the last 80 rows of the frame buffer\nundisplayed.\n\nThe `vscsad` method sets the (VSSA) Vertical Scroll Start Address. The VSSA\nsets the line in the frame buffer that will be the first line after the `tfa`.\n\n    The ST7789 datasheet warns:\n\n    The value of the vertical scrolling start address is absolute (with reference to the frame memory),\n    it must not enter the fixed area (defined by Vertical Scrolling Definition, otherwise undesirable\n    image will be displayed on the panel.\n\n- `vscrdef(tfa, height, bfa)` Set the vertical scrolling parameters.\n\n  `tfa` is the top fixed area in pixels. The top fixed area is the upper\n  portion of the display frame buffer that will not be scrolled.\n\n  `height` is the total height in pixels of the area scrolled.\n\n  `bfa` is the bottom fixed area in pixels. The bottom fixed area is the lower\n  portion of the display frame buffer that will not be scrolled.\n\n- `vscsad(vssa)` Set the vertical scroll address.\n\n  `vssa` is the vertical scroll start address in pixels. The vertical scroll\n  start address is the line in the frame buffer will be the first line shown\n  after the TFA.\n\n## Helper functions\n\n- `color565(r, g, b)`\n\n  Pack a color into 2-bytes rgb565 format\n\n- `map_bitarray_to_rgb565(bitarray, buffer, width, color=WHITE, bg_color=BLACK)`\n\n  Convert a `bitarray` to the rgb565 color `buffer` suitable for blitting. Bit\n  1 in `bitarray` is a pixel with `color` and 0 - with `bg_color`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusshughes%2Fst7789_mpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusshughes%2Fst7789_mpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusshughes%2Fst7789_mpy/lists"}