gc9a01py Reference¶
Copyright (c) 2020, 2021 Russ Hughes
This file incorporates work covered by the following copyright and permission notice and is licensed under the same terms:
The MIT License (MIT)
Copyright (c) 2019 Ivan Belokobylskiy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
GC9A01 Display driver in MicroPython based on devbis st7789py_mpy module from https://github.com/devbis/st7789py_mpy modified to drive 240x240 pixel GC9A01 displays.
The driver supports display rotation, mirroring, scrolling and drawing text using 8 and 16 bit wide bitmap fonts with heights that are multiples of 8. Included are 12 bitmap fonts derived from classic pc text mode fonts and a couple of example programs.
This is a work in progress. Documentation can be found at https://penfold.owt.com/gc9a01py/.
If you are looking for a faster driver with additional features, check out the C version of the driver at https://github.com/russhughes/gc9a01_mpy
-
gc9a01py.
color565
(red, green=0, blue=0)[source]¶ Convert red, green and blue values (0-255) into a 16-bit 565 encoded color.
-
class
gc9a01py.
GC9A01
(spi=None, dc=None, cs=None, reset=None, backlight=None, rotation=0)[source]¶ GC9A01 driver class
- Parameters
spi (spi) – spi object (Required)
dc (pin) – dc pin (Required)
cs (pin) – cs pin {optional}
reset (pin) – reset pin
backlight (pin) – backlight pin
rotation (int) – display rotation
-
sleep_mode
(value)[source]¶ Enable or disable display sleep mode.
- Parameters
value (bool) – if True enable sleep mode. if False disable sleep mode
-
inversion_mode
(value)[source]¶ Enable or disable display inversion mode.
- Parameters
value (bool) – if True enable inversion mode. if False disable inversion mode
-
rotation
(rotation)[source]¶ Set display rotation.
- Parameters
rotation (int) –
0 - PORTRAIT
1 - LANDSCAPE
2 - INVERTED PORTRAIT
3 - INVERTED LANDSCAPE
4 - PORTRAIT MIRRORED
5 - LANDSCAPE MIRRORED
6 - INVERTED PORTRAIT MIRRORED
7 - INVERTED LANDSCAPE MIRRORED
-
vline
(x, y, length, color)[source]¶ Draw vertical line at the given location and color.
- Parameters
x (int) – x coordinate
Y (int) – y coordinate
length (int) – length of line
color (int) – 565 encoded color
-
hline
(x, y, length, color)[source]¶ Draw horizontal line at the given location and color.
- Parameters
x (int) – x coordinate
Y (int) – y coordinate
length (int) – length of line
color (int) – 565 encoded color
-
pixel
(x, y, color)[source]¶ Draw a pixel at the given location and color.
- Parameters
x (int) – x coordinate
Y (int) – y coordinate
color (int) – 565 encoded color
-
blit_buffer
(buffer, x, y, width, height)[source]¶ Copy buffer to display at the given location.
- Parameters
buffer (bytes) – Data to copy to display
x (int) – Top left corner x coordinate
Y (int) – Top left corner y coordinate
width (int) – Width
height (int) – Height
-
rect
(x, y, w, h, color)[source]¶ Draw a rectangle at the given location, size and color.
- Parameters
x (int) – Top left corner x coordinate
y (int) – Top left corner y coordinate
width (int) – Width in pixels
height (int) – Height in pixels
color (int) – 565 encoded color
-
fill_rect
(x, y, width, height, color)[source]¶ Draw a rectangle at the given location, size and filled with color.
- Parameters
x (int) – Top left corner x coordinate
y (int) – Top left corner y coordinate
width (int) – Width in pixels
height (int) – Height in pixels
color (int) – 565 encoded color
-
fill
(color)[source]¶ Fill the entire FrameBuffer with the specified color.
- Parameters
color (int) – 565 encoded color
-
line
(x0, y0, x1, y1, color)[source]¶ Draw a single pixel wide line starting at x0, y0 and ending at x1, y1.
- Parameters
x0 (int) – Start point x coordinate
y0 (int) – Start point y coordinate
x1 (int) – End point x coordinate
y1 (int) – End point y coordinate
color (int) – 565 encoded color
-
vscrdef
(tfa, vsa, bfa)[source]¶ Set Vertical Scrolling Definition.
To scroll a 135x240 display these values should be 40, 240, 40. There are 40 lines above the display that are not shown followed by 240 lines that are shown followed by 40 more lines that are not shown. You could write to these areas off display and scroll them into view by changing the TFA, VSA and BFA values.
- Parameters
tfa (int) – Top Fixed Area
vsa (int) – Vertical Scrolling Area
bfa (int) – Bottom Fixed Area
-
vscsad
(vssa)[source]¶ Set Vertical Scroll Start Address of RAM.
Defines which line in the Frame Memory will be written as the first line after the last line of the Top Fixed Area on the display
Example
- for line in range(40, 280, 1):
tft.vscsad(line) utime.sleep(0.01)
- Parameters
vssa (int) – Vertical Scrolling Start Address
-
text
(font, text, x0, y0, color=micropython.const, background=micropython.const)[source]¶ Draw text on display in specified font and colors. 8 and 16 bit wide fonts are supported.
- Parameters
font (module) – font module to use.
text (str) – text to write
x0 (int) – column to start drawing at
y0 (int) – row to start drawing at
color (int) – 565 encoded color to use for characters
background (int) – 565 encoded color to use for background
-
bitmap
(bitmap, x, y, index=0)[source]¶ Draw a bitmap on display at the specified column and row
- Parameters
bitmap (bitmap_module) – The module containing the bitmap to draw
x (int) – column to start drawing at
y (int) – row to start drawing at
index (int) – Optional index of bitmap to draw from multiple bitmap module
-
write
(font, string, x, y, fg=micropython.const, bg=micropython.const)[source]¶ Write a string using a converted true-type font on the display starting at the specified column and row
- Parameters
font (font) – The module containing the converted true-type font
s (string) – The string to write
x (int) – column to start writing
y (int) – row to start writing
fg (int) – foreground color, optional, defaults to WHITE
bg (int) – background color, optional, defaults to BLACK