This is a driver for MicroPython for devices using the esp_lcd intel 8080 8-bit parallel bus and SPI interfaces. The driver is written in C and is based on devbis’ st7789_mpy driver.
The firmware directory contains pre-compiled MicroPython v1.20.0 firmware compiled using ESP IDF v4.4.4. In addition, the firmware includes the C driver and several frozen Python font files. See the README.md file in the fonts folder for more information about the font files.
-
s3lcd.ESPLCD(bus, width, height, {reset, rotations, rotation, inversion, dma_rows, options})
Required positional arguments:
bus I80_BUS or SPI_BUS object
width display width
height display height
Optional keyword arguments:
-
reset reset pin number
-
rotations Creates a custom rotation table. A rotation table is a list of tuples for each rotation containing the width, height, x_gap, y_gap, swap_xy, mirror_x, and mirror_y values for each rotation.
Default rotations are included for the following display sizes:
| Display |
Default Orientation Tables |
| 320x480 |
((320, 480, 0, 0, false, true, false), (480, 320, 0, 0, true, false, false), (320, 480, 0, 0, false, false, true), (480, 320, 0, 0, true, true, true)) |
| 240x320 |
((240, 320, 0, 0, false, false, false), (320, 240, 0, 0, true, true, false), (240, 320, 0, 0, false, true, true), (320, 240, 0, 0, true, false, true)) |
| 170x320 |
((170, 320, 35, 0, false, false, false), (320, 170, 0, 35, true, true, false), (170, 320, 35, 0, false, true, true), (320, 170, 0, 35, true, false, true)) |
| 240x240 |
((240, 240, 0, 0, false, false, false), (240, 240, 0, 0, true, true, false), (240, 240, 0, 80, false, true, true), (240, 240, 80, 0, true, false, true)) |
| 135x240 |
((135, 240, 52, 40, false, false, false), (240, 135, 40, 53, true, true, false), (135, 240, 53, 40, false, true, true), (240, 135, 40, 52, true, false, true)) |
| 128x160 |
((128, 160, 0, 0, false, false, false), (160, 128, 0, 0, true, true, false), (128, 160, 0, 0, false, true, true), (160, 128, 0, 0, true, false, true)) |
| 80x160 |
((80, 160, 26, 1, false, false, false), (160, 80, 1, 26, true, true, false), (80, 160, 26, 1, false, true, true), (160, 80, 1, 26, true, false, true)) |
| 128x128 |
((128, 128, 2, 1, false, false, false), (128, 128, 1, 2, true, true, false), (128, 128, 2, 3, false, true, true), (128, 128, 3, 2, true, false, true)) |
You may define up to 4 rotations.
-
rotation sets the active display rotation according to the orientation table.
The default orientation table defines four counterclockwise rotations for 240x320, 240x240, 134x240, 128x160, 80x160, and 128x128 displays with the LCD’s ribbon cable at the bottom of the display. The default rotation is Portrait (0 degrees).
| Index |
Rotation |
| 0 |
Portrait (0 degrees) |
| 1 |
Landscape (90 degrees) |
| 2 |
Reverse Portrait (180 degrees) |
| 3 |
Reverse Landscape (270 degrees) |
-
inversion Sets the display color inversion mode if True and clears the color inversion mode if false.
-
dma_rows Sets the number of the framebuffer rows to transfer to the display in a single DMA transaction. The default value is 16 rows. Larger values may perform better but use more DMA-capable memory from the ESP-IDF heap. On the other hand, using a large value may starve other ESP-IDF functions like WiFi of memory.
-
options Sets driver option flags.
| Option |
Description |
| s3lcd.WRAP |
pixels, lines, polygons, and Hershey text will wrap around the display both horizontally and vertically. |
| s3lcd.WRAP_H |
pixels, lines, polygons, and Hershey text will wrap around the display horizontally. |
| s3lcd.WRAP_V |
pixels, lines, polygons, and Hershey text will wrap around the display vertically. |
-
deinit()
Frees the buffer memory and deinitializes the I80_BUF or SPI_BUF object. Call this method before reinitializing the display without performing a hard reset.
-
idle_mode(value)
Set idle mode
value: True to enable idle mode, False to idle disable idle mode.
-
show()
Update the display from the framebuffer. You must use the show() method to transfer the framebuffer to the display. This method blocks until the display refresh is complete.
-
inversion_mode(bool) Sets the display color inversion mode if True, clears the display color inversion mode if False.
-
init()
Must be called to initialize the display.
-
clear({ 8_bit_color})
Fast clear the framebuffer by setting the high and low bytes of the color to the specified value.
Optional parameters:
– 8_bit_color defaults to 0x00 BLACK
-
fill({color, alpha})
Fill the framebuffer with the specified color, optionally alpha blended with the background. The color defaults to BLACK, and the alpha defaults to 255.
-
pixel(x, y {, color, alpha})
Set the specified pixel to the given color. The color defaults to WHITE, and the alpha defaults to 255.
-
line(x0, y0, x1, y1 {, color, alpha})
Draws a single line with the provided color from (x0, y0) to (x1, y1). The color defaults to BLACK, and the alpha defaults to 255.
-
hline(x, y, w {, color, alpha})
Draws a horizontal line with the provided color and length in pixels. The color defaults to BLACK, and the alpha defaults to 255.
-
vline(x, y, length {, color, alpha})
Draws a vertical line with the provided color and length in pixels. The color defaults to BLACK, and the alpha defaults to 255.
-
rect(x, y, width, height {, color, alpha})
Draws a rectangle with the specified dimensions from (x, y'). The colordefaults to BLACK, and thealpha` defaults to 255.
-
fill_rect(x, y, width, height {, color, alpha})
Fills a rectangle width by height starting at x, y' with coloroptionallyalphablended with the background. Thecolordefaults to BLACK, andalpha` defaults to 255.
-
circle(x, y, r {, color, alpha})
Draws a circle with radius r centered at the (x, y') coordinates in the given color. The colordefaults to BLACK, and thealpha` defaults to 255.
-
fill_circle(x, y, r {, color, alpha})
Draws a filled circle with radius r centered at the (x, y') coordinates in the given color. The colordefaults to BLACK, and thealpha` defaults to 255.
-
blit_buffer(buffer, x, y, width, height {, alpha})
Copy bytes() or bytearray() content to the framebuffer. Note: every color requires 2 bytes in the array, the alpha defaults to 255.
-
text(font, s, x, y {, fg, bg, alpha})
Writes text to the framebuffer using the specified bitmap font with the coordinates as the upper-left corner of the text. The optional arguments fg and bg can set the foreground and background colors of the text; otherwise, the foreground color defaults to WHITE, and the background color defaults to BLACK. alpha defaults to 255. See the README.md in the fonts/bitmap directory, for example fonts.
-
write(bitmap_font, s, x, y {, fg, bg, alpha})
Writes text to the framebuffer using the specified proportional or Monospace bitmap font module starting with the coordinates as the upper-left corner of the text. The foreground and background colors of the text are set by the optional arguments fg and bg; otherwise, the foreground color defaults to WHITE, and the background color defaults to BLACK. The alpha defaults to 255.
See the README.md in the truetype/fonts directory, for example fonts. Returns the width of the string as printed in pixels. This method accepts UTF8 encoded strings.
The font2bitmap utility creates compatible 1-bit per pixel bitmap modules from Proportional or Monospaced True Type fonts. The character size, foreground, background colors, and characters in the bitmap module may be specified as parameters. Use the -h option for details.
-
write_len(bitap_font, s)
Returns the string’s width in pixels if printed in the specified font.
-
draw(vector_font, s, x, y {, fg, scale, alpha})
Draws text to the framebuffer using the specified Hershey vector font with the coordinates as the lower-left corner of the text. The foreground color of the text can be set by the optional argument fg. Otherwise, the foreground color defaults to WHITE. The size of the text is modified by specifying a scale value. The scale value must be larger than 0 and can be a floating-point or an integer value. The scale value defaults to 1.0. The alpha defaults to 255. See the README.md in the vector/fonts directory, for example fonts and the utils directory for a font conversion program.
-
draw_len(vector_font, s {, scale})
Returns the string’s width in pixels if drawn with the specified font.
-
jpg(jpg, x, y)
Draws a JPG file in the framebuffer at the given x and `y’ coordinates as the upper left corner of the image. This method requires an additional 3100 bytes of memory for its work buffer. The jpg may be a filename or a bytes() or bytearray() object. The jpg will wil be clipped if is not able to fit fully in the framebuffer.
-
jpg_decode(jpg_filename {, x, y, width, height})
Decodes a jpg file and returns it or a portion of it as a tuple composed of (buffer, width, height). The buffer is a color565 blit_buffer compatible byte array. The buffer will require width * height * 2 bytes of memory.
If the optional x, y, width, and height parameters are given, the buffer will only contain the specified area of the image. See examples/T-DISPLAY/clock/clock.py and examples/T-DISPLAY/toasters_jpg/toasters_jpg.py for examples.
-
png(png, x, y)
Draws a PNG file in the framebuffer with the upper left corner of the image at the given x and `y’ coordinates. The png may be a filename or a bytes() or bytearray() object. The png will wil be clipped if it is not able to fit fully in the framebuffer. Transparency is supported; see the alien.py program in the examples/png folder.
-
png_write(file_name{ x, y, width, height})
Writes the framebuffer to a png file named file_name using PNGenc from https://github.com/bitbank2/PNGenc.
optional parameters:
- x: the first column of the framebuffer to start writing.
- y: the first row of the framebuffer to start writing.
- width: the width of the area to write
- height: the height of the area to write
Returns file size in bytes.
-
polygon_center(polygon)
Returns the center of the polygon as an (x, y) tuple. The polygon should consist of a list of (x, y) tuples forming a closed convex polygon.
-
fill_polygon(polygon, x, y, color {, alpha, angle, center_x, center_y})
Draws a filled polygon at the x, and y' coordinates in the colorgiven. Thealphadefaults to 255. The polygon may be rotatedangleradians about thecenter_xandcenter_y` points. The polygon should consist of a list of (x, y) tuples forming a closed convex polygon.
See the TWATCH-2020 watch.py demo for an example.
-
polygon(polygon, x, y, color {, alpha, angle, center_x, center_y)
Draws a polygon at the x, and y' coordinates in the colorgiven. Thealphadefaults to 255. The polygon may be rotatedangleradians about thecenter_xandcenter_y` points. The polygon should consist of a list of (x, y) tuples forming a closed convex polygon.
See the roids.py for an example.
-
bitmap(bitmap, x , y {, alpha, index}) or bitmap((bitmap_as_bytes, w, h), x , y {, alpha})
Draws a bitmap using the specified x, y' coordinates as the upper-left corner of the bitmap`.
-
If the bitmap parameter is a bitmap module, the index parameter may be specified to select a specific bitmap from the module. The index parameter must be an integer value greater than or equal to 0 and less than the number of bitmaps in the module. The index value defaults to 0. 8-bit per pixel.
-
If the bitmap_module parameter is a tuple, the tuple must contain a bitmap as a byte array, the width of the bitmap in pixels, and the height of the bitmap in pixels. alpha defaults to 255.
Using the Pillow Python Imaging Library, the imgtobitmap.py utility creates compatible 1 to 8-bit per-pixel bitmap modules from image files.
The monofont2bitmap.py utility creates compatible 1 to 8-bit per-pixel bitmap modules from Monospaced True Type fonts. See the inconsolata_16.py, inconsolata_32.py and inconsolata_64.py files in the examples/mono_fonts folder for sample modules and the mono_font.py program for an example using the generated modules.
You can specify the character sizes, foreground and background colors, bit per pixel, and characters to include in the bitmap module as parameters. To learn more, use the -h option. Using bit-per-pixel settings larger than one can create antialiased characters at the cost of increased memory usage.
-
width()
Returns the current width of the display in pixels. (i.e., a 135x240 display rotated 90 degrees is 240 pixels wide)
-
height()
Returns the current height of the display in pixels. (i.e., a 135x240 display rotated 90 degrees is 135 pixels high)
-
rotation(r)
Sets the rotation of the logical display in a counterclockwise direction. 0-Portrait (0 degrees), 1-Landscape (90 degrees), 2-Inverse Portrait (180 degrees), 3-Inverse Landscape (270 degrees)
-
scroll(xstep, ystep{, fill=0})
Scrolls the framebuffer using software in the given direction.
Required parameters:
- xstep: Number of pixels to scroll in the x direction. Negative values scroll left, positive values scroll right.
- ystep: Number of pixels to scroll in the y direction. Negative values scroll up, positive values scroll down.
Optional parameters:
- fill: Fill color for the new pixels.
The st7789 display controller contains a 240 by 320-pixel frame buffer used to store the pixels for the display. For scrolling, the frame buffer consists of three separate areas: The (tfa) top fixed area, the (height) scrolling area, and the (bfa) bottom fixed area. The tfa is the upper portion of the frame buffer in pixels not to scroll. The height is the center portion of the frame buffer in pixels to scroll. The bfa is the lower portion of the frame buffer in pixels not to scroll. These values control the ability to scroll the entire or a part of the display.
Other displays, like the Waveshare Pico LCD 1.3-inch 240x240 display, require the tfa set to 0, height set to 240, and bfa set to 80 (0+240+80=320) to scroll the entire display. The Pico LCD 1.3 shows 240 rows starting at the 0th row of the frame buffer, leaving the last 80 rows undisplayed.
Flash the firmware.uf2 file from the build-${BOARD} directory to your device.
评论