Commit a675dcd3 authored by russhughes's avatar russhughes

New init args: rotations, inversion, options

parent 4c801884
......@@ -66,7 +66,7 @@ The firmware directory contains pre-compiled firmware for various devices with
the st7789 C driver and frozen python font files. See the README.md file in the
fonts folder for more information on the font files.
MicroPython v1.17-231-g0892ebe09 compiled with ESP IDF v4.2 using CMake
MicroPython v1.17-333-gcf258c898 compiled with ESP IDF v4.2 using CMake
Directory | File | Device
--------------------- | ------------ | ----------------------------------
......@@ -125,7 +125,7 @@ pyboard1.1, and Raspberry Pi Pico devices.
# Setup MicroPython Build Environment in Ubuntu 20.04.2
See the MicroPython [README.md](https://github.com/micropython/micropython/blob/master/ports/esp32/README.md#setting-up-esp-idf-and-the-build-environment) if you run into any build issues not directly related to the st7789 driver. The recommended MicroPython build instructions may have changed.
See the MicroPython [README.md](https://github.com/micropython/micropython/blob/master/ports/esp32/README.md#setting-up-esp-idf-and-the-build-environment) if you run into any build issues not directly related to the st7789 driver. The recommended MicroPython build instructions may have changed.
Update and upgrade Ubuntu using apt-get if you are using a new install of Ubuntu or the Windows Subsystem for Linux.
......@@ -268,12 +268,13 @@ I was not able to run the display with a baud rate over 40MHZ.
## Methods
- `st7789.ST7789(spi, width, height, dc, reset, cs, backlight, rotation, color_order, inversion_mode, buffer_size)`
- `st7789.ST7789(spi, width, height, dc, reset, cs, backlight, rotations, rotation, color_order, inversion, options, buffer_size)`
### Required positional arguments:
- `spi` spi device
- `width` display width
- `height` display height
### Required keyword arguments:
- `dc` sets the pin connected to the display data/command selection input. This parameter is always required.
......@@ -285,16 +286,34 @@ I was not able to run the display with a baud rate over 40MHZ.
- `backlight` sets the pin connected to the displays backlight enable input. The displays backlight input can often be left floating or disconnected as the backlight on some displays are always powered on and cannot be turned off.
- `rotation` 0-0 degrees, 1-90 degrees, 2-180 degrees, 3-270 degrees
- `rotations` sets the orientation table for each of the rotations. The orientation table is a list of tuples for each rotation that define the MADCTL register, width, height, start_x, and start_y values.
Display | Default Orientation Tables
------- | --------------------------
240x320 | [(0x00, 240, 320, 0, 0), (0x60, 320, 240, 0, 0), (0xc0, 240, 320, 0, 0), (0xa0, 320, 240, 0, 0)]
240x240 | [(0x00, 240, 240, 0, 0), (0x60, 240, 240, 0, 0), (0xc0, 240, 240, 0, 80), (0xa0, 240, 240, 80, 0)]
135x240 | [(0x00, 135, 240, 52, 40), (0x60, 240, 135, 40, 53), (0xc0, 135, 240, 53, 40), (0xa0, 240, 135, 40, 52)]
other | [(0x00, width, height, 0, 0)]
You may define as many rotations in the list as you wish.
- `rotation` sets the display rotation according to the orientation table. The default orientation table defines four counter-clockwise rotations as 0-Portrait (0 degrees), 1- Landscape (90 degrees), 2- Reverse Portrait (180 degrees), and 3- Reverse Landscape (270 degrees) for 240x320, 240x240 and 123x240 displays with the LCD's ribbon cable at the bottom of the display. The default rotation being Portrait (0 degrees).
- `color_order` set the color order used by the driver st7789.RGB and st7789.BGR are supported.
- `inversion` Sets the display color inversion mode if True, clears the display color inversion mode if false.
- `options` Sets driver option flags.
Option | Description
------ | -----------
st7789.WRAP | pixels, lines, polygons and Hershey text will wrap around the display both horizontally and vertically.
st7789.WRAP_H | pixels, lines, polygons and Hershey text will wrap around the display horizontally.
st7789.WRAP_V | pixels, lines, polygons and Hershey text will wrap around the display vertically.
- `buffer_size` If a buffer_size is not specified a dynamically allocated buffer is created and freed as needed. If a buffer_size is specified it must be large enough to contain the largest bitmap, font character and/or decoded JPG image used (Rows * Columns * 2 bytes, 16bit colors in RGB565 notation). Dynamic allocation is slower and can cause heap fragmentation so garbage collection (GC) should be enabled.
- `inversion_mode(bool)` Sets the display color inversion mode if True,
clears the display color inversion mode if false.
- `inversion_mode(bool)` Sets the display color inversion mode if True, clears the display color inversion mode if False.
- `madctl(value)` Returns the current value of the MADCTL register.
Optionally sets the MADCTL register if a value is passed to the method.
......@@ -405,6 +424,10 @@ I was not able to run the display with a baud rate over 40MHZ.
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 width of the string in pixels if drawn with the specified font.
- `jpg(jpg_filename, x, y [, method])`
Draw JPG file on the display at the given `x` and `y` coordinates as the upper
......@@ -449,7 +472,7 @@ I was not able to run the display with a baud rate over 40MHZ.
See the T-Display `roids.py` for an example.
- `bounding([status])`
- `bounding({status, as_rect})`
Bounding turns on and off tracking the area of the display that has been
written to. Initially tracking is disabled, pass a True value to enable
......@@ -459,6 +482,9 @@ I was not able to run the display with a baud rate over 40MHZ.
Returns a four integer tuple containing (min_x, min_y, max_x, max_y) indicating
the area of the display that has been written to since the last clearing.
If `as_rect` parameter is True, the returned tuple will contain (min_x, min_y, width, height)
values.
See the TWATCH-2020 `watch.py` demo for an example.
- `bitmap(bitmap, x , y [, index])`
......@@ -497,7 +523,7 @@ I was not able to run the display with a baud rate over 40MHZ.
- `rotation(r)`
Set the rotates the logical display in a clockwise direction. 0-Portrait
Set the rotates the logical display in a counter-clockwise direction. 0-Portrait
(0 degrees), 1-Landscape (90 degrees), 2-Inverse Portrait (180 degrees),
3-Inverse Landscape (270 degrees)
......
This diff is collapsed.
......@@ -5,12 +5,6 @@
extern "C" {
#endif
#define ST7789_240x240_XSTART 0
#define ST7789_240x240_YSTART 0
#define ST7789_135x240_XSTART 52
#define ST7789_135x240_YSTART 40
// color modes
#define COLOR_MODE_65K 0x50
#define COLOR_MODE_262K 0x60
......@@ -68,6 +62,10 @@ extern "C" {
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define OPTIONS_WRAP_V 0x01
#define OPTIONS_WRAP_H 0x02
#define OPTIONS_WRAP 0x03
typedef struct _Point {
mp_float_t x;
mp_float_t y;
......@@ -78,6 +76,13 @@ typedef struct _Polygon {
Point *points;
} Polygon;
typedef struct _st7789_rotation_t {
uint8_t madctl;
uint16_t width;
uint16_t height;
uint16_t colstart;
uint16_t rowstart;
} st7789_rotation_t;
// this is the actual C-structure for our new object
typedef struct _st7789_ST7789_obj_t {
......@@ -95,9 +100,12 @@ typedef struct _st7789_ST7789_obj_t {
uint8_t colstart;
uint8_t rowstart;
uint8_t rotation;
st7789_rotation_t *rotations; // list of rotation tuples [(madctl, colstart, rowstart)]
uint8_t rotations_len; // number of rotations
uint8_t color_order;
bool inversion;
uint8_t madctl;
uint8_t options; // options bit array
mp_hal_pin_obj_t reset;
mp_hal_pin_obj_t dc;
mp_hal_pin_obj_t cs;
......@@ -113,7 +121,7 @@ typedef struct _st7789_ST7789_obj_t {
mp_obj_t st7789_ST7789_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
extern void draw_pixel(st7789_ST7789_obj_t *self, uint16_t x, uint16_t y, uint16_t color);
extern void draw_pixel(st7789_ST7789_obj_t *self, int16_t x, int16_t y, uint16_t color);
extern void fast_hline(st7789_ST7789_obj_t *self, int16_t x, int16_t y, int16_t w, uint16_t color);
#ifdef __cplusplus
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment