kopia lustrzana https://github.com/devbis/st7789_mpy
add RGB/BGR inversion on init
merge rotation functions into one (always returns final state) rename EXPOSE_EXTRA_METHODS to ST77XX_EXPOSE_EXTRA_METHODSpull/15/head
rodzic
7d8fdb2cb8
commit
5e320ac4b5
117
README.md
117
README.md
|
@ -1,17 +1,17 @@
|
|||
ST7789 Driver for MicroPython
|
||||
ST77xx Driver for MicroPython
|
||||
=============================
|
||||
|
||||
|
||||
Overview
|
||||
--------
|
||||
This is a driver for MicroPython to handle cheap displays
|
||||
based on ST7789 chip.
|
||||
based on ST77xx chip.
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/devbis/st7789_mpy/master/docs/ST7789.jpg" alt="ST7789 display photo"/>
|
||||
<img src="https://raw.githubusercontent.com/devbis/st7789_mpy/master/docs/ST7789.jpg" alt="ST77xx display photo"/>
|
||||
</p>
|
||||
|
||||
It supports both 240x240 and 135x240 variants of displays.
|
||||
It supports 80x160, 240x240 and 135x240 variants of displays.
|
||||
|
||||
It is written in pure C, so you have to build
|
||||
firmware by yourself.
|
||||
|
@ -27,7 +27,7 @@ ensure that you can build the firmware without this display module.
|
|||
|
||||
Clone this module alongside the MPY sources:
|
||||
|
||||
$ git clone https://github.com/devbis/st7789_mpy.git
|
||||
$ git clone https://github.com/nexus166/st77xx_mpy.git
|
||||
|
||||
Go to MicroPython ports directory and for ESP8266 run:
|
||||
|
||||
|
@ -39,10 +39,10 @@ for ESP32:
|
|||
|
||||
And then compile the module with specified USER_C_MODULES dir
|
||||
|
||||
$ make USER_C_MODULES=../../../st7789_mpy/ all
|
||||
$ make USER_C_MODULES=../../../st77xx_mpy/ all
|
||||
|
||||
|
||||
If you have other user modules, copy the st7789_driver/st7789 to
|
||||
If you have other user modules, copy the st77xx_driver/st77xx to
|
||||
the user modules directory
|
||||
|
||||
Upload the resulting firmware to your MCU as usual with esptool.py
|
||||
|
@ -60,15 +60,15 @@ This module was tested on ESP32 and ESP8266 MCUs.
|
|||
You have to provide `machine.SPI` object and at least two pins for RESET and
|
||||
DC pins on the screen for the display object.
|
||||
|
||||
|
||||
```python
|
||||
# ESP 8266
|
||||
|
||||
import machine
|
||||
import st7789
|
||||
import st77xx
|
||||
spi = machine.SPI(1, baudrate=40000000, polarity=1)
|
||||
display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(5, machine.Pin.OUT), dc=machine.Pin(4, machine.Pin.OUT))
|
||||
display = st77xx.ST77xx(spi, 240, 240, reset=machine.Pin(5, machine.Pin.OUT), dc=machine.Pin(4, machine.Pin.OUT))
|
||||
display.init()
|
||||
|
||||
```
|
||||
|
||||
For ESP32 modules you have to provide specific pins for SPI.
|
||||
Unfortunately, I was unable to run this display on SPI(1) interface.
|
||||
|
@ -79,28 +79,76 @@ For machine.SPI(2) == VSPI you have to use
|
|||
|
||||
Other SPI pins are not used.
|
||||
|
||||
|
||||
```python
|
||||
# ESP32
|
||||
|
||||
import machine
|
||||
import st7789
|
||||
import st77xx
|
||||
spi = machine.SPI(2, baudrate=40000000, polarity=1, sck=machine.Pin(18), mosi=machine.Pin(23))
|
||||
display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(4, machine.Pin.OUT), dc=machine.Pin(2, machine.Pin.OUT))
|
||||
display = st77xx.ST77xx(spi, 240, 240, reset=machine.Pin(4, machine.Pin.OUT), dc=machine.Pin(2, machine.Pin.OUT))
|
||||
display.init()
|
||||
|
||||
```
|
||||
|
||||
I couldn't run the display on an SPI with baudrate higher than 40MHZ
|
||||
|
||||
Also, the driver was tested on STM32 board:
|
||||
|
||||
|
||||
```python
|
||||
# STM32
|
||||
|
||||
import machine
|
||||
import st7789
|
||||
import st77xx
|
||||
spi = machine.SPI(2, baudrate=12000000, polarity=1)
|
||||
display = st7789.ST7789(spi, 135, 240, reset=machine.Pin('B3', machine.Pin.OUT), dc=machine.Pin('B6', machine.Pin.OUT))
|
||||
display = st77xx.ST77xx(spi, 135, 240, reset=machine.Pin('B3', machine.Pin.OUT), dc=machine.Pin('B6', machine.Pin.OUT))
|
||||
display.init()
|
||||
```
|
||||
|
||||
This module was also tested on TINYPICO M5StickC/M5StickC+ devices
|
||||
|
||||
```python
|
||||
import machine
|
||||
import st77xx
|
||||
|
||||
tft = None
|
||||
spi = None
|
||||
tft_width = None
|
||||
tft_height = None
|
||||
|
||||
def init_screen(isPlus=True):
|
||||
global tft
|
||||
global spi
|
||||
global tft_width
|
||||
global tft_height
|
||||
rot = None
|
||||
xstart = None
|
||||
ystart = None
|
||||
pol = None
|
||||
rgb = None
|
||||
""" pre-init """
|
||||
if not isPlus:
|
||||
x = 0
|
||||
y = 25
|
||||
rot = 1
|
||||
tft_width = 160
|
||||
tft_height = 80
|
||||
pol = 0
|
||||
rgb = 0
|
||||
else:
|
||||
x = 40
|
||||
y = 52
|
||||
rot = 3
|
||||
tft_width = 240
|
||||
tft_height = 135
|
||||
pol = 1
|
||||
rgb = 1
|
||||
""" init """
|
||||
if spi is None:
|
||||
spi = SPI(2, baudrate=30000000, polarity=pol, sck=Pin(13), mosi=Pin(15), miso=Pin(36))
|
||||
if tft is None:
|
||||
tft = st77xx.ST77XX(spi, tft_width, tft_height, rot, reset=Pin(18, Pin.OUT, Pin.PULL_DOWN), dc=Pin(23, Pin.OUT, Pin.PULL_DOWN), cs=Pin(5, Pin.OUT, Pin.PULL_DOWN), rgb=rgb, xstart=x, ystart=y)
|
||||
tft.init()
|
||||
tft.fill(st77xx.BLACK)
|
||||
```
|
||||
|
||||
|
||||
Methods
|
||||
|
@ -109,43 +157,49 @@ Methods
|
|||
This driver supports only 16bit colors in RGB565 notation.
|
||||
|
||||
|
||||
- `ST7789.fill(color)`
|
||||
- `ST77xx.fill(color)`
|
||||
|
||||
Fill the entire display with the specified color.
|
||||
|
||||
- `ST7789.pixel(x, y, color)`
|
||||
- `ST77xx.pixel(x, y, color)`
|
||||
|
||||
Set the specified pixel to the given color.
|
||||
|
||||
- `ST7789.line(x0, y0, x1, y1, color)`
|
||||
- `ST77xx.line(x0, y0, x1, y1, color)`
|
||||
|
||||
Draws a single line with the provided `color` from (`x0`, `y0`) to
|
||||
(`x1`, `y1`).
|
||||
|
||||
- `ST7789.hline(x, y, length, color)`
|
||||
- `ST77xx.hline(x, y, length, color)`
|
||||
|
||||
Draws a single horizontal line with the provided `color` and `length`
|
||||
in pixels. Along with `vline`, this is a fast version with reduced
|
||||
number of SPI calls.
|
||||
|
||||
- `ST7789.vline(x, y, length, color)`
|
||||
- `ST77xx.vline(x, y, length, color)`
|
||||
|
||||
Draws a single horizontal line with the provided `color` and `length`
|
||||
in pixels.
|
||||
|
||||
- `ST7789.rect(x, y, width, height, color)`
|
||||
- `ST77xx.rect(x, y, width, height, color)`
|
||||
|
||||
Draws a rectangle from (`x`, `y`) with corresponding dimensions
|
||||
|
||||
- `ST7789.fill_rect(x, y, width, height, color)`
|
||||
- `ST77xx.fill_rect(x, y, width, height, color)`
|
||||
|
||||
Fill a rectangle starting from (`x`, `y`) coordinates
|
||||
|
||||
- `ST7789.blit_buffer(buffer, x, y, width, height)`
|
||||
- `ST77xx.blit_buffer(buffer, x, y, width, height)`
|
||||
|
||||
Copy bytes() or bytearray() content to the screen internal memory.
|
||||
Note: every color requires 2 bytes in the array
|
||||
|
||||
- `ST77xx.rotation(n)`
|
||||
|
||||
Configure screen rotation. Takes care of swapping width/height and offset.
|
||||
0 = no rotation, 1 = 90, 2 = 180, 3 = 270
|
||||
Without arguments will return current rotation parameter (0..3)
|
||||
|
||||
Also, the module exposes predefined colors:
|
||||
`BLACK`, `BLUE`, `RED`, `GREEN`, `CYAN`, `MAGENTA`, `YELLOW`, and `WHITE`
|
||||
|
||||
|
@ -174,16 +228,16 @@ Performance
|
|||
For the comparison I used an excellent library for Arduino
|
||||
that can handle this screen.
|
||||
|
||||
https://github.com/ananevilya/Arduino-ST7789-Library/
|
||||
https://github.com/ananevilya/Arduino-ST77xx-Library/
|
||||
|
||||
Also, I used my slow driver for this screen, written in pure python.
|
||||
|
||||
https://github.com/devbis/st7789py_mpy/
|
||||
https://github.com/devbis/st77xxpy_mpy/
|
||||
|
||||
I used these modules to draw a line from 0,0 to 239,239
|
||||
The table represents the time in milliseconds for each case
|
||||
|
||||
| | Arduino-ST7789 | st7789py_mpy | st7789_mpy |
|
||||
| | Arduino-ST77xx | st77xxpy_mpy | st77xx_mpy |
|
||||
|---------|----------------|--------------|---------------|
|
||||
| ESP8266 | 26 | 450 | 12 |
|
||||
| ESP32 | 23 | 450 | 47 |
|
||||
|
@ -206,17 +260,16 @@ the linker:
|
|||
xtensa-lx106-elf-ld: region `iram1_0_seg' overflowed by 292 bytes
|
||||
Makefile:192: recipe for target 'build/firmware.elf' failed
|
||||
|
||||
To fix this issue, you have to put st7789 module to irom0 section.
|
||||
To fix this issue, you have to put st77xx module to irom0 section.
|
||||
Edit `esp8266_common.ld` file in the `ports/esp8266` dir and add a line
|
||||
|
||||
*st7789/*.o(.literal* .text*)
|
||||
*st77xx/*.o(.literal* .text*)
|
||||
|
||||
in the `.irom0.text : ALIGN(4)` section
|
||||
|
||||
|
||||
#### Unsupported dimensions
|
||||
|
||||
This driver supports only 240x240 and 135x240 pixel displays.
|
||||
If you have a display with an unsupported resolution, you can pass
|
||||
`xstart` and `ystart` parameters to the display constructor to set the
|
||||
required offsets.
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.1.5
|
||||
0.2
|
||||
|
|
|
@ -3,4 +3,4 @@ SRC_USERMOD += $(addprefix $(ST77XX_MOD_DIR)/, \
|
|||
st77xx.c \
|
||||
)
|
||||
CFLAGS_USERMOD += -I$(ST77XX_MOD_DIR) -DMODULE_ST77XX_ENABLED=1
|
||||
# CFLAGS_USERMOD += -DEXPOSE_EXTRA_METHODS=1
|
||||
# CFLAGS_USERMOD += -DST77XX_EXPOSE_EXTRA_METHODS=1
|
||||
|
|
123
st77xx/st77xx.c
123
st77xx/st77xx.c
|
@ -2,6 +2,7 @@
|
|||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ivan Belokobylskiy
|
||||
* Copyright (c) 2020 + Silvano Zampardi
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -22,6 +23,8 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define __ST77XX_VERSION__ "0.2"
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/builtin.h"
|
||||
|
@ -69,6 +72,7 @@ typedef struct _st77xx_ST77XX_obj_t {
|
|||
mp_hal_pin_obj_t dc;
|
||||
mp_hal_pin_obj_t cs;
|
||||
mp_hal_pin_obj_t backlight;
|
||||
uint8_t rgb;
|
||||
} st77xx_ST77XX_obj_t;
|
||||
|
||||
// just a definition
|
||||
|
@ -81,7 +85,7 @@ STATIC void st77xx_ST77XX_print( const mp_print_t *print,
|
|||
mp_print_kind_t kind ) {
|
||||
(void)kind;
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<ST77XX width=%u, height=%u, rotation=%u, spi=%p>", self->width, self->height, self->rotation, self->spi_obj);
|
||||
mp_printf(print, "<ST77XX width=%u, height=%u, rotation=%u, offset=%u/%u, spi=%p>", self->width, self->height, self->rotation, self->xstart, self->ystart, self->spi_obj);
|
||||
}
|
||||
|
||||
/* methods start */
|
||||
|
@ -113,7 +117,7 @@ STATIC void set_window(st77xx_ST77XX_obj_t *self, uint8_t x0, uint8_t y0, uint8_
|
|||
write_cmd(self, ST77XX_RAMWR, NULL, 0);
|
||||
}
|
||||
|
||||
STATIC void rotate(st77xx_ST77XX_obj_t *self, uint8_t n) {
|
||||
STATIC int rotation(st77xx_ST77XX_obj_t *self, uint8_t n) {
|
||||
if (0 <= n && n < 4) {
|
||||
int chg = self->rotation ^ n;
|
||||
self->rotation = n;
|
||||
|
@ -122,13 +126,14 @@ STATIC void rotate(st77xx_ST77XX_obj_t *self, uint8_t n) {
|
|||
uint8_t oh = self->height;
|
||||
self->width = oh;
|
||||
self->height = ow;
|
||||
uint8_t ox = self->xstart;
|
||||
uint8_t oy = self->ystart;
|
||||
self->xstart = oy;
|
||||
self->ystart = ox;
|
||||
}
|
||||
uint8_t bufr[1] = { ST77XX_MADCTL_ROT[n] | ST77XX_MADCTL_RGB };
|
||||
uint8_t bufr[1] = { ST77XX_MADCTL_ROT[n] | self->rgb };
|
||||
write_cmd(self, ST77XX_MADCTL, bufr, 1);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int rotation(st77xx_ST77XX_obj_t *self) {
|
||||
return self->rotation;
|
||||
}
|
||||
|
||||
|
@ -155,7 +160,6 @@ STATIC void fill_color_buffer(mp_obj_base_t* spi_obj, uint16_t color, int length
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
STATIC void draw_pixel(st77xx_ST77XX_obj_t *self, uint8_t x, uint8_t y, uint16_t color) {
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
set_window(self, x, y, x, y);
|
||||
|
@ -199,16 +203,6 @@ STATIC mp_obj_t st77xx_ST77XX_hard_reset(mp_obj_t self_in) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_soft_reset(mp_obj_t self_in) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
write_cmd(self, ST77XX_SWRESET, NULL, 0);
|
||||
mp_hal_delay_ms(150);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
// do not expose extra method to reduce size
|
||||
#ifdef EXPOSE_EXTRA_METHODS
|
||||
STATIC mp_obj_t st77xx_ST77XX_write(mp_obj_t self_in, mp_obj_t command, mp_obj_t data) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
|
@ -224,6 +218,16 @@ STATIC mp_obj_t st77xx_ST77XX_write(mp_obj_t self_in, mp_obj_t command, mp_obj_t
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(st77xx_ST77XX_write_obj, st77xx_ST77XX_write);
|
||||
|
||||
#ifdef ST77XX_EXPOSE_EXTRA_METHODS
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_soft_reset(mp_obj_t self_in) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
write_cmd(self, ST77XX_SWRESET, NULL, 0);
|
||||
mp_hal_delay_ms(150);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(st77xx_ST77XX_hard_reset_obj, st77xx_ST77XX_hard_reset);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(st77xx_ST77XX_soft_reset_obj, st77xx_ST77XX_soft_reset);
|
||||
|
||||
|
@ -238,6 +242,8 @@ STATIC mp_obj_t st77xx_ST77XX_sleep_mode(mp_obj_t self_in, mp_obj_t value) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(st77xx_ST77XX_sleep_mode_obj, st77xx_ST77XX_sleep_mode);
|
||||
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_set_window(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t x0 = mp_obj_get_int(args[1]);
|
||||
|
@ -250,21 +256,36 @@ STATIC mp_obj_t st77xx_ST77XX_set_window(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_set_window_obj, 5, 5, st77xx_ST77XX_set_window);
|
||||
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_rotate(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t n = mp_obj_get_int(args[1]);
|
||||
rotate(self, n);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_rotate_obj, 2, 2, st77xx_ST77XX_rotate);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_rotation(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
return MP_OBJ_NEW_SMALL_INT(rotation(self));
|
||||
mp_int_t n = mp_obj_get_int(args[1]);
|
||||
return MP_OBJ_NEW_SMALL_INT(rotation(self, n));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_rotation_obj, 1, 1, st77xx_ST77XX_rotation);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_rotation_obj, 2, 2, st77xx_ST77XX_rotation);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_width(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
return MP_OBJ_NEW_SMALL_INT(self->width);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_width_obj, 1, 1, st77xx_ST77XX_width);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_height(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
return MP_OBJ_NEW_SMALL_INT(self->height);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_height_obj, 1, 1, st77xx_ST77XX_height);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_xstart(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
return MP_OBJ_NEW_SMALL_INT(self->xstart);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_xstart_obj, 1, 1, st77xx_ST77XX_xstart);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_ystart(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
return MP_OBJ_NEW_SMALL_INT(self->ystart);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_ystart_obj, 1, 1, st77xx_ST77XX_ystart);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_inversion_mode(mp_obj_t self_in, mp_obj_t value) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -321,6 +342,19 @@ STATIC mp_obj_t st77xx_ST77XX_pixel(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_pixel_obj, 4, 4, st77xx_ST77XX_pixel);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_pushcolor(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t color = mp_obj_get_int(args[1]);
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
DC_HIGH();
|
||||
CS_LOW();
|
||||
write_spi(self->spi_obj, &hi, 1);
|
||||
write_spi(self->spi_obj, &lo, 1);
|
||||
CS_HIGH();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_pushcolor_obj, 2, 2, st77xx_ST77XX_pushcolor);
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_line(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t x0 = mp_obj_get_int(args[1]);
|
||||
|
@ -378,7 +412,7 @@ STATIC mp_obj_t st77xx_ST77XX_line(size_t n_args, const mp_obj_t *args) {
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_line_obj, 6, 6, st77xx_ST77XX_line);
|
||||
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_blit_buffer(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t st77xx_ST77XX_blit(size_t n_args, const mp_obj_t *args) {
|
||||
st77xx_ST77XX_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_buffer_info_t buf_info;
|
||||
mp_get_buffer_raise(args[1], &buf_info, MP_BUFFER_READ);
|
||||
|
@ -406,7 +440,7 @@ STATIC mp_obj_t st77xx_ST77XX_blit_buffer(size_t n_args, const mp_obj_t *args) {
|
|||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_blit_buffer_obj, 6, 6, st77xx_ST77XX_blit_buffer);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(st77xx_ST77XX_blit_obj, 6, 6, st77xx_ST77XX_blit);
|
||||
|
||||
|
||||
STATIC mp_obj_t st77xx_ST77XX_init(mp_obj_t self_in) {
|
||||
|
@ -418,7 +452,7 @@ STATIC mp_obj_t st77xx_ST77XX_init(mp_obj_t self_in) {
|
|||
const uint8_t color_mode[] = { COLOR_MODE_65K | COLOR_MODE_16BIT};
|
||||
write_cmd(self, ST77XX_COLMOD, color_mode, 1);
|
||||
mp_hal_delay_ms(10);
|
||||
const uint8_t madctl[] = { ST77XX_MADCTL_ML | ST77XX_MADCTL_RGB };
|
||||
const uint8_t madctl[] = { ST77XX_MADCTL_ML | self->rgb };
|
||||
write_cmd(self, ST77XX_MADCTL, madctl, 1);
|
||||
|
||||
write_cmd(self, ST77XX_INVON, NULL, 0);
|
||||
|
@ -438,7 +472,7 @@ STATIC mp_obj_t st77xx_ST77XX_init(mp_obj_t self_in) {
|
|||
write_cmd(self, ST77XX_DISPON, NULL, 0);
|
||||
mp_hal_delay_ms(100);
|
||||
if (self->rotation > 0) {
|
||||
rotate(self, self->rotation);
|
||||
rotation(self, self->rotation);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -515,14 +549,18 @@ STATIC const mp_rom_map_elem_t st77xx_ST77XX_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_sleep_mode), MP_ROM_PTR(&st77xx_ST77XX_sleep_mode_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_inversion_mode), MP_ROM_PTR(&st77xx_ST77XX_inversion_mode_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_window), MP_ROM_PTR(&st77xx_ST77XX_set_window_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rotate), MP_ROM_PTR(&st77xx_ST77XX_rotate_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&st77xx_ST77XX_rotation_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&st77xx_ST77XX_width_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&st77xx_ST77XX_height_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_xstart), MP_ROM_PTR(&st77xx_ST77XX_xstart_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ystart), MP_ROM_PTR(&st77xx_ST77XX_ystart_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&st77xx_ST77XX_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&st77xx_ST77XX_on_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&st77xx_ST77XX_off_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&st77xx_ST77XX_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pushcolor), MP_ROM_PTR(&st77xx_ST77XX_pushcolor_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&st77xx_ST77XX_line_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_blit_buffer), MP_ROM_PTR(&st77xx_ST77XX_blit_buffer_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_blit), MP_ROM_PTR(&st77xx_ST77XX_blit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_fill_rect), MP_ROM_PTR(&st77xx_ST77XX_fill_rect_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&st77xx_ST77XX_fill_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_hline), MP_ROM_PTR(&st77xx_ST77XX_hline_obj) },
|
||||
|
@ -548,7 +586,7 @@ mp_obj_t st77xx_ST77XX_make_new(const mp_obj_type_t *type,
|
|||
const mp_obj_t *all_args ) {
|
||||
enum {
|
||||
ARG_spi, ARG_width, ARG_height, ARG_rotation, ARG_reset, ARG_dc, ARG_cs,
|
||||
ARG_backlight, ARG_xstart, ARG_ystart
|
||||
ARG_backlight, ARG_rgb, ARG_xstart, ARG_ystart
|
||||
};
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_spi, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} },
|
||||
|
@ -559,6 +597,7 @@ mp_obj_t st77xx_ST77XX_make_new(const mp_obj_type_t *type,
|
|||
{ MP_QSTR_dc, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_cs, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_backlight, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_rgb, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_xstart, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_ystart, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
};
|
||||
|
@ -606,6 +645,18 @@ mp_obj_t st77xx_ST77XX_make_new(const mp_obj_type_t *type,
|
|||
self->backlight = mp_hal_get_pin_obj(args[ARG_backlight].u_obj);
|
||||
}
|
||||
|
||||
mp_int_t rgbbgr;
|
||||
if (args[ARG_rgb].u_obj != MP_OBJ_NULL) {
|
||||
rgbbgr = args[ARG_rgb].u_int;
|
||||
} else {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("must specify RGB/BGR mode (0/1)"));
|
||||
}
|
||||
if (rgbbgr <= 0) {
|
||||
self->rgb = ST77XX_MADCTL_RGB;
|
||||
} else {
|
||||
self->rgb = ST77XX_MADCTL_BGR;
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue