kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
ST7789 Add offset constructor arg.
rodzic
168e1bf91d
commit
d3759da107
17
DRIVERS.md
17
DRIVERS.md
|
@ -400,10 +400,19 @@ below. An example file for the Pi Pico is in `color_setup/ssd7789.py`.
|
||||||
* `width=240`
|
* `width=240`
|
||||||
* `disp_mode=0` By default the display chip operates in landscape mode. This
|
* `disp_mode=0` By default the display chip operates in landscape mode. This
|
||||||
arg enables portrait mode and other configurations. See below.
|
arg enables portrait mode and other configurations. See below.
|
||||||
* `init_spi=False` This optional arg enables flexible options in configuring
|
* `init_spi=False` For shared SPI bus applications. See note below.
|
||||||
the SPI bus. The default assumes exclusive access to the bus. In this normal
|
* `offset=(0, 0)` This is intended for display hardware where the display
|
||||||
case, `color_setup.py` initialises it and the settings will be left in place.
|
hardware's coordinate system is offset relative to the chip's RAM origin. An
|
||||||
If the bus is shared with devices which require different settings, a callback
|
`(x, y)` tuple (where `x` and `y` are positive integers) can offset this. In
|
||||||
|
practice, when other display hardware is supported, this doc will be amended
|
||||||
|
to specify the values to be used.
|
||||||
|
|
||||||
|
### init_spi
|
||||||
|
|
||||||
|
This optional arg enables flexible options in configuring the SPI bus. The
|
||||||
|
default assumes exclusive access to the bus. In this normal case,
|
||||||
|
`color_setup.py` initialises it and the settings will be left in place. If the
|
||||||
|
bus is shared with devices which require different settings, a callback
|
||||||
function should be passed. It will be called prior to each SPI bus write. The
|
function should be passed. It will be called prior to each SPI bus write. The
|
||||||
callback will receive a single arg being the SPI bus instance. It will
|
callback will receive a single arg being the SPI bus instance. It will
|
||||||
typically be a one-liner or lambda initialising the bus. A minimal example is
|
typically be a one-liner or lambda initialising the bus. A minimal example is
|
||||||
|
|
|
@ -53,13 +53,15 @@ class ST7789(framebuf.FrameBuffer):
|
||||||
return ((b & 0xf8) << 5 | (g & 0x1c) << 11 | (g & 0xe0) >> 5 | (r & 0xf8)) ^ 0xffff
|
return ((b & 0xf8) << 5 | (g & 0x1c) << 11 | (g & 0xe0) >> 5 | (r & 0xf8)) ^ 0xffff
|
||||||
|
|
||||||
# rst and cs are active low, SPI is mode 0
|
# rst and cs are active low, SPI is mode 0
|
||||||
def __init__(self, spi, cs, dc, rst, height=240, width=240, disp_mode=0, init_spi=False):
|
def __init__(self, spi, cs, dc, rst, height=240, width=240,
|
||||||
|
disp_mode=0, init_spi=False, offset=(0, 0):
|
||||||
self._spi = spi # Clock cycle time for write 16ns 62.5MHz max (read is 150ns)
|
self._spi = spi # Clock cycle time for write 16ns 62.5MHz max (read is 150ns)
|
||||||
self._rst = rst # Pins
|
self._rst = rst # Pins
|
||||||
self._dc = dc
|
self._dc = dc
|
||||||
self._cs = cs
|
self._cs = cs
|
||||||
self.height = height # Required by Writer class
|
self.height = height # Required by Writer class
|
||||||
self.width = width
|
self.width = width
|
||||||
|
self._offset = offset
|
||||||
self._spi_init = init_spi # Possible user callback
|
self._spi_init = init_spi # Possible user callback
|
||||||
self._lock = asyncio.Lock()
|
self._lock = asyncio.Lock()
|
||||||
mode = framebuf.GS4_HMSB # Use 4bit greyscale.
|
mode = framebuf.GS4_HMSB # Use 4bit greyscale.
|
||||||
|
@ -138,8 +140,10 @@ class ST7789(framebuf.FrameBuffer):
|
||||||
# Determine x and y start and end. Defaults for LANDSCAPE and PORTRAIT
|
# Determine x and y start and end. Defaults for LANDSCAPE and PORTRAIT
|
||||||
ys = 0 # y start
|
ys = 0 # y start
|
||||||
ye = wht - 1 # y end
|
ye = wht - 1 # y end
|
||||||
|
yoff = self._offset[1]
|
||||||
xs = 0
|
xs = 0
|
||||||
xe = wwd - 1
|
xe = wwd - 1
|
||||||
|
xoff = self._offset[0]
|
||||||
if mode & PORTRAIT:
|
if mode & PORTRAIT:
|
||||||
if mode & REFLECT:
|
if mode & REFLECT:
|
||||||
ys = rwd - wht
|
ys = rwd - wht
|
||||||
|
@ -154,9 +158,13 @@ class ST7789(framebuf.FrameBuffer):
|
||||||
if mode & USD:
|
if mode & USD:
|
||||||
ys = rht - wwd
|
ys = rht - wwd
|
||||||
ye = rht - 1
|
ye = rht - 1
|
||||||
# Col address set
|
# Col address set. Add in any offset.
|
||||||
|
xs += xoff
|
||||||
|
xe += xoff
|
||||||
self._wcd(b'\x2a', int.to_bytes(xs, 2, 'big') + int.to_bytes(xe, 2, 'big'))
|
self._wcd(b'\x2a', int.to_bytes(xs, 2, 'big') + int.to_bytes(xe, 2, 'big'))
|
||||||
# Row address set
|
# Row address set
|
||||||
|
ys += yoff
|
||||||
|
ye += yoff
|
||||||
self._wcd(b'\x2b', int.to_bytes(ys, 2, 'big') + int.to_bytes(ye, 2, 'big'))
|
self._wcd(b'\x2b', int.to_bytes(ys, 2, 'big') + int.to_bytes(ye, 2, 'big'))
|
||||||
|
|
||||||
#@micropython.native # Made virtually no difference to timing.
|
#@micropython.native # Made virtually no difference to timing.
|
||||||
|
|
Ładowanie…
Reference in New Issue