Commit b8b4b8e9 authored by Russ's avatar Russ

Added offset method, offsets for 240x240, new firware.bin

parent 30087b4e
......@@ -9,8 +9,18 @@ display rotation, scrolling and drawing text using 8 and 16 bit wide bitmap
fonts. Included are 12 bitmap fonts derived from classic pc text mode fonts
and a couple of example programs that run on the TTGO T-Display.
A firmware.bin file containing MicroPython v1.12-464-gcae77daf0 compiled
using ESP IDF v3 with the st7789 C driver and the frozen python font files is
available in the firmware directory.
This is a work in progress.
Thanks go out to:
- https://github.com/devbis for the original driver this is based on.
- https://github.com/hklang10 for letting me know of the new mp_raise_ValueError().
- https://github.com/aleggon for finding the correct offsets for a 240x240 display.
-- Russ
Overview
......@@ -184,7 +194,33 @@ This driver supports only 16bit colors in RGB565 notation.
(0 degrees), 1-Landscape (90 degrees), 2-Inverse Portrait (180 degrees),
3-Inverse Landscape (270 degrees)
Also, the module exposes predefined colors:
- `ST7789.offset(x_start, y_start)` The memory in the ST7789 controller is
configured for a 240x320 display. When using a smaller display like a
240x240 or 135x240 an offset needs to added to the x and y parameters so
that the pixels are written to the memory area that corresponds to the
visible display. The offsets may need to be adjusted when rotating the
display.
For example the TTGO-TDisplay is 135x240 and uses the following offsets.
| Rotation | x_start | y_start |
|----------|---------|---------|
| 0 | 52 | 40 |
| 1 | 40 | 53 |
| 2 | 53 | 40 |
| 3 | 40 | 52 |
When the rotation method is called the driver will adjust the offsets for a
135x240 or 240x240 display. Your display may require using different offset
values, if so, use the `offset` method after `rotation` to set the offset
values.
The values needed for particular display may not be documented and may
require some experimentation to determine the correct values. One technique
is to draw a box the same size as the display and then make small changes
to the offsets until the display looks correct.
The module exposes predefined colors:
`BLACK`, `BLUE`, `RED`, `GREEN`, `CYAN`, `MAGENTA`, `YELLOW`, and `WHITE`
......
......@@ -18,3 +18,13 @@ with the st7789 C driver and the frozen python font files:
- vga1_bold_16x32.py
- vga2_bold_16x32.py
When using this firmware you can use the VGA fonts directly from flash to
save RAM. For example, in the ttgo_hello.py program change the font import
line from:
`from fonts import vga2_bold_16x32 as font`
to:
`import vga2_bold_16x32 as font`
No preview for this file type
......@@ -468,6 +468,11 @@ STATIC void set_rotation(st7789_ST7789_obj_t *self) {
self->xstart = 52;
self->ystart = 40;
}
else if (self->display_width == 240) {
self->xstart = 0;
self->ystart = 0;
}
}
else if (self->rotation == 1) { // Landscape
madctl_value |= ST7789_MADCTL_MX | ST7789_MADCTL_MV;
......@@ -477,6 +482,11 @@ STATIC void set_rotation(st7789_ST7789_obj_t *self) {
self->xstart = 40;
self->ystart = 53;
}
else if (self->display_width == 240) {
self->xstart = 0;
self->ystart = 0;
}
}
else if (self->rotation == 2) { // Inverted Portrait
madctl_value |= ST7789_MADCTL_MX | ST7789_MADCTL_MY;
......@@ -486,6 +496,11 @@ STATIC void set_rotation(st7789_ST7789_obj_t *self) {
self->xstart = 53;
self->ystart = 40;
}
else if (self->display_width == 240) {
self->xstart = 0;
self->ystart = 80;
}
}
else if (self->rotation == 3) { // Inverted Landscape
madctl_value |= ST7789_MADCTL_MV | ST7789_MADCTL_MY;
......@@ -495,6 +510,10 @@ STATIC void set_rotation(st7789_ST7789_obj_t *self) {
self->xstart = 40;
self->ystart = 52;
}
else if (self->display_width == 240) {
self->xstart = 80;
self->ystart = 0;
}
}
const uint8_t madctl[] = { madctl_value };
write_cmd(self, ST7789_MADCTL, madctl, 1);
......@@ -638,6 +657,18 @@ STATIC mp_obj_t st7789_ST7789_rect(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st7789_ST7789_rect_obj, 6, 6, st7789_ST7789_rect);
STATIC mp_obj_t st7789_ST7789_offset(size_t n_args, const mp_obj_t *args) {
st7789_ST7789_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_int_t xstart = mp_obj_get_int(args[1]);
mp_int_t ystart = mp_obj_get_int(args[2]);
self->xstart = xstart;
self->ystart = ystart;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st7789_ST7789_offset_obj, 3, 3, st7789_ST7789_offset);
STATIC const mp_rom_map_elem_t st7789_ST7789_locals_dict_table[] = {
// Do not expose internal functions to fit iram_0 section
......@@ -664,6 +695,7 @@ STATIC const mp_rom_map_elem_t st7789_ST7789_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&st7789_ST7789_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_vscrdef), MP_ROM_PTR(&st7789_ST7789_vscrdef_obj) },
{ MP_ROM_QSTR(MP_QSTR_vscsad), MP_ROM_PTR(&st7789_ST7789_vscsad_obj) },
{ MP_ROM_QSTR(MP_QSTR_offset), MP_ROM_PTR(&st7789_ST7789_offset_obj) },
};
......
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