kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
Improve display driver Viper code.
rodzic
7f54bb5049
commit
611863e90a
|
@ -27,6 +27,8 @@ Width and height are pixels.
|
|||
| 1.44C | 128 | 128 | TFT | [ST7735R][4d] | [Adafruit 2088][5m] | |
|
||||
| 1.5C | 160 | 128 | TFT | [ST7735R][4d] | [Adafruit 358][6m] | |
|
||||
| 1.3C | 240 | 240 | TFT | [ST7789][5d] | [Adafruit 4313][7m] | |
|
||||
| 1.28C Q| 240 | 240 | TFT | [GC9A01][17d] | [W'share 1.28 touch LCD][29m]| Round touch display |
|
||||
| 1.28C Q| 240 | 240 | TFT | [GC9A01][17d] | [W'share 1.28 touch LCD][30m]| Round touch display with embedded RP2 chip |
|
||||
| 1.5GS | 128 | 128 | OLED | [SSD1327][11d] | [Waveshare 13992][20m] | |
|
||||
| 2.0C | 320 | 240 | TFT | [ST7789][5d] | [Waveshare Pico LCD 2][18m] | For Pi Pico. |
|
||||
| 1.54C | 240 | 240 | TFT | [ST7789][5d] | [Adafruit 3787][8m] | |
|
||||
|
@ -110,6 +112,7 @@ simple. See [this doc](./DRIVERS.md#7-writing-device-drivers) for details.
|
|||
| R | [TSC2007][1t] | Resistive touch needs [external controller][1q] |
|
||||
| T | [XPT2046][2t] | Resistive touch, XPT2046 controller. |
|
||||
| K | [FT6206][3t] | Capacitive touch controller. |
|
||||
| Q | [CST816S][4t] | Capacitive touch controller. |
|
||||
|
||||
# Links
|
||||
|
||||
|
@ -137,6 +140,7 @@ simple. See [this doc](./DRIVERS.md#7-writing-device-drivers) for details.
|
|||
[14d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/drivers/ssd1306/ssd1306.py
|
||||
[15d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#54-weact-studio-ssd1680-eink-displays
|
||||
[16d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/drivers/st7567s/st7567s.py
|
||||
[17d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/drivers/gc9a01/gc9a01.py
|
||||
|
||||
[1m]: https://www.adafruit.com/product/684
|
||||
[2m]: https://www.adafruit.com/product/1673
|
||||
|
@ -166,10 +170,13 @@ simple. See [this doc](./DRIVERS.md#7-writing-device-drivers) for details.
|
|||
[26m]: https://aliexpress.com/item/1005004644515880.html
|
||||
[27m]: https://www.buydisplay.com/1-4-inch-graphic-128x64-lcd-module-serial-spi-st7567s-black-on-white
|
||||
[28m]: https://www.adafruit.com/product/1947
|
||||
[29m]: https://www.waveshare.com/wiki/1.28inch_Touch_LCD
|
||||
[30m]: https://www.waveshare.com/wiki/RP2040-Touch-LCD-1.28
|
||||
|
||||
[1t]: https://github.com/peterhinch/micropython-touch/blob/master/TOUCHPAD.md#tsc2007
|
||||
[2t]: https://github.com/peterhinch/micropython-touch/blob/master/TOUCHPAD.md#xpt2046
|
||||
[3t]: https://github.com/peterhinch/micropython-touch/blob/master/TOUCHPAD.md#ft6206-capacitive-controller
|
||||
[4t]: https://github.com/peterhinch/micropython-touch/blob/master/TOUCHPAD.md#cst816s-capacitive-controller
|
||||
|
||||
[1q]: https://www.adafruit.com/product/5423
|
||||
|
||||
|
|
14
DRIVERS.md
14
DRIVERS.md
|
@ -824,6 +824,7 @@ Clock rates up to 100MHz are supported according to the chip datasheet section
|
|||
PCB layout and grounding. I have run 33MHz without issue.
|
||||
|
||||
#### GC9A01 Constructor args:
|
||||
|
||||
* `spi` An initialised SPI bus instance.
|
||||
* `cs` An initialised output pin. Initial value should be 1.
|
||||
* `dc` An initialised output pin. Initial value should be 0.
|
||||
|
@ -859,9 +860,20 @@ some asyncio applications. The driver provides an asynchronous
|
|||
`do_refresh(split=4)` method. If this is run the display will be refreshed, but
|
||||
will periodically yield to the scheduler enabling other tasks to run. This is
|
||||
documented [here](./ASYNC.md).
|
||||
[micro-gui](https://github.com/peterhinch/micropython-micro-gui) uses this
|
||||
[micro-gui](https://github.com/peterhinch/micropython-micro-gui) and
|
||||
[micropython-touch](https://github.com/peterhinch/micropython-touch) use this
|
||||
automatically.
|
||||
|
||||
#### Driver design note
|
||||
|
||||
The display setup is based on [this driver](https://github.com/russhughes/gc9a01_mpy/)
|
||||
by Russ Hughes. It uses a number of undocumented registers. Under test the
|
||||
initialisation of most of these registers could be commented out without obvious
|
||||
effects, however two of them were necessary to avoid display corruption. All the
|
||||
calls were left in place with appropriate code comments. The source of the code
|
||||
in question was unclear. Russ Hughes indicated that it probably originated with
|
||||
a display manufacturer.
|
||||
|
||||
###### [Contents](./DRIVERS.md#contents)
|
||||
|
||||
# 4. Drivers for sharp displays
|
||||
|
|
|
@ -1,36 +1,18 @@
|
|||
# color_setup.py Customise for your hardware config
|
||||
# ili9486_pico.py Customise for your hardware config and rename
|
||||
|
||||
# Released under the MIT License (MIT). See LICENSE.
|
||||
# Copyright (c) 2024 Peter Hinch
|
||||
|
||||
# As written, supports:
|
||||
# gc9a01 240x240 circular display on Pi Pico
|
||||
# Edit the driver import for other displays.
|
||||
|
||||
# Demo of initialisation procedure designed to minimise risk of memory fail
|
||||
# when instantiating the frame buffer. The aim is to do this as early as
|
||||
# possible before importing other modules.
|
||||
|
||||
# WIRING
|
||||
# Pico Display
|
||||
# GPIO Pin
|
||||
# 3v3 36 Vin
|
||||
# IO6 9 CLK Hardware SPI0
|
||||
# IO7 10 DATA (AKA SI MOSI)
|
||||
# IO8 11 DC
|
||||
# IO9 12 Rst
|
||||
# Gnd 13 Gnd
|
||||
# IO10 14 CS
|
||||
# ILI9486 on Pi Pico
|
||||
# See DRIVERS.md for wiring details.
|
||||
|
||||
from machine import Pin, SPI
|
||||
import gc
|
||||
from drivers.gc9a01.gc9a01 import GC9A01 as SSD
|
||||
|
||||
pdc = Pin(8, Pin.OUT, value=0) # Arbitrary pins
|
||||
from drivers.ili94xx.ili9486 import ILI9486 as SSD
|
||||
|
||||
pdc = Pin(8, Pin.OUT, value=0)
|
||||
prst = Pin(9, Pin.OUT, value=1)
|
||||
pcs = Pin(10, Pin.OUT, value=1)
|
||||
|
||||
spi = SPI(0, sck=Pin(6), mosi=Pin(7), miso=Pin(4), baudrate=30_000_000)
|
||||
gc.collect() # Precaution before instantiating framebuf
|
||||
# See DRIVERS.md
|
||||
spi = SPI(0, sck=Pin(6), mosi=Pin(7), miso=Pin(4), baudrate=33_000_000)
|
||||
ssd = SSD(spi, dc=pdc, cs=pcs, rst=prst, lscape=False, usd=False, mirror=False)
|
||||
ssd = SSD(spi, pcs, pdc, prst)
|
||||
|
|
|
@ -11,8 +11,7 @@ import asyncio
|
|||
from drivers.boolpalette import BoolPalette
|
||||
|
||||
# Initialisation ported from Russ Hughes' C driver
|
||||
# https://github.com/russhughes/gc9a01_mpy/blob/main/src/gc9a01.h
|
||||
# https://github.com/russhughes/gc9a01_mpy/blob/main/src/gc9a01.c
|
||||
# https://github.com/russhughes/gc9a01_mpy/
|
||||
# Based on a ST7789 C driver: https://github.com/devbis/st7789_mpy
|
||||
# Many registers are undocumented. Lines initialising them are commented "?"
|
||||
# in cases where initialising them seems to have no effect.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# ILI9341 nano-gui driver for ili9341 displays
|
||||
|
||||
# Copyright (c) Peter Hinch 2020
|
||||
# Copyright (c) Peter Hinch 2020-2024
|
||||
# Released under the MIT license see LICENSE
|
||||
|
||||
# This work is based on the following sources.
|
||||
|
@ -15,16 +15,20 @@ import asyncio
|
|||
from drivers.boolpalette import BoolPalette
|
||||
|
||||
|
||||
# ~80μs on RP2 @ 250MHz.
|
||||
@micropython.viper
|
||||
def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int):
|
||||
# rgb565 - 16bit/pixel
|
||||
n = 0
|
||||
for x in range(length):
|
||||
n: int = 0
|
||||
x: int = 0
|
||||
while length:
|
||||
c = source[x]
|
||||
dest[n] = lut[c >> 4] # current pixel
|
||||
n += 1
|
||||
dest[n] = lut[c & 0x0F] # next pixel
|
||||
n += 1
|
||||
x += 1
|
||||
length -= 1
|
||||
|
||||
|
||||
class ILI9341(framebuf.FrameBuffer):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# ILI9486 nano-gui driver for ili9486 displays
|
||||
|
||||
# Copyright (c) Peter Hinch 2022
|
||||
# Copyright (c) Peter Hinch 2022-2024
|
||||
# Released under the MIT license see LICENSE
|
||||
|
||||
# Much help provided by @brave-ulysses in this thread
|
||||
|
@ -22,13 +22,16 @@ from drivers.boolpalette import BoolPalette
|
|||
@micropython.viper
|
||||
def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int):
|
||||
# rgb565 - 16bit/pixel
|
||||
n = 0
|
||||
for x in range(length):
|
||||
n: int = 0
|
||||
x: int = 0
|
||||
while length:
|
||||
c = source[x]
|
||||
dest[n] = lut[c >> 4] # current pixel
|
||||
n += 1
|
||||
dest[n] = lut[c & 0x0F] # next pixel
|
||||
n += 1
|
||||
x += 1
|
||||
length -= 1
|
||||
|
||||
|
||||
# FB is in landscape mode, hence issue a column at a time to portrait mode hardware.
|
||||
|
@ -41,7 +44,7 @@ def _lscopy(dest: ptr16, source: ptr8, lut: ptr16, ch: int):
|
|||
n = 0
|
||||
clsb = col & 1
|
||||
idx = col >> 1 # 2 pixels per byte
|
||||
for _ in range(height):
|
||||
while height:
|
||||
if clsb:
|
||||
c = source[idx] & 0x0F
|
||||
else:
|
||||
|
@ -49,6 +52,7 @@ def _lscopy(dest: ptr16, source: ptr8, lut: ptr16, ch: int):
|
|||
dest[n] = lut[c] # 16 bit transfer of rightmost 4-bit pixel
|
||||
n += 1 # 16 bit
|
||||
idx += wbytes
|
||||
height -= 1
|
||||
|
||||
|
||||
class ILI9486(framebuf.FrameBuffer):
|
||||
|
|
Ładowanie…
Reference in New Issue