GHIElectronics.Endpoint.Drivers.HiLetgo.ILI9341 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- GHIElectronics/Endpoint/Drivers/HiLetgo/ILI9341/__init__.py +128 -0
- ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/METADATA +22 -0
- ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/RECORD +5 -0
- ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/WHEEL +5 -0
- ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""HiLetgo ILI9341 240x320 SPI TFT driver for GHI Endpoint (Python).
|
|
2
|
+
|
|
3
|
+
Companion to GHIElectronics.Endpoint.Drivers.HiLetgo.ILI9341 (.NET).
|
|
4
|
+
Drop this file into a project; the caller passes in an already-opened
|
|
5
|
+
SpiDevice plus a GpioController.
|
|
6
|
+
|
|
7
|
+
Wiring (any free GPIOs for CS/DC/RST):
|
|
8
|
+
ILI9341 EPDomino24
|
|
9
|
+
------- ----------
|
|
10
|
+
VCC mikroBUS 3.3V
|
|
11
|
+
GND mikroBUS GND
|
|
12
|
+
SCK mikroBUS SCK (e.g. PZ0 on mikroBUS #2)
|
|
13
|
+
SDI/MOSI mikroBUS MOSI (e.g. PZ2 on mikroBUS #2)
|
|
14
|
+
CS any free GPIO (driven in software by this driver)
|
|
15
|
+
DC / RS any free GPIO (low = command, high = data)
|
|
16
|
+
RST any free GPIO (active-low pulse at init)
|
|
17
|
+
LED / BL tie to +3.3V (backlight always on)
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
|
|
21
|
+
from GHIElectronics.Endpoint.Core import EPDomino24, EPM815, SpiController
|
|
22
|
+
from GHIElectronics.Endpoint.Devices.Spi import (
|
|
23
|
+
SpiDevice, SpiConnectionSettings, SpiMode)
|
|
24
|
+
from GHIElectronics.Endpoint.Devices.Gpio import GpioController
|
|
25
|
+
from GHIElectronics.Endpoint.Drivers.HiLetgo.ILI9341 import Ili9341
|
|
26
|
+
|
|
27
|
+
SpiController.Initialize(EPDomino24.Spi.Spi1, bufferSize=4096)
|
|
28
|
+
settings = SpiConnectionSettings(EPDomino24.Spi.Spi1)
|
|
29
|
+
settings.Mode = SpiMode.Mode0
|
|
30
|
+
settings.ClockFrequency = 10_000_000
|
|
31
|
+
spi = SpiDevice.Create(settings)
|
|
32
|
+
|
|
33
|
+
gpio = GpioController()
|
|
34
|
+
tft = Ili9341(gpio, spi,
|
|
35
|
+
cs_pin=EPM815.Gpio.Pin.PA14,
|
|
36
|
+
dc_pin=EPM815.Gpio.Pin.PF14,
|
|
37
|
+
rst_pin=EPM815.Gpio.Pin.PF4,
|
|
38
|
+
swap_red_blue=True) # set for modules where yellow shows as cyan
|
|
39
|
+
tft.initialize()
|
|
40
|
+
|
|
41
|
+
# Canvas drawing...
|
|
42
|
+
tft.flush(canvas.Buffer)
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
import time
|
|
46
|
+
from GHIElectronics.Endpoint.Devices.Gpio import PinMode, PinValue
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Ili9341:
|
|
50
|
+
"""ILI9341 SPI TFT driver. Caller owns the GpioController + SpiDevice.
|
|
51
|
+
`swap_red_blue` compensates for modules with physical BGR filter wiring
|
|
52
|
+
(yellow would otherwise render as cyan)."""
|
|
53
|
+
|
|
54
|
+
def __init__(self, gpio, spi, cs_pin, dc_pin, rst_pin, *,
|
|
55
|
+
width=240, height=320, swap_red_blue=False):
|
|
56
|
+
self._gpio, self._spi = gpio, spi
|
|
57
|
+
self._cs, self._dc, self._rst = cs_pin, dc_pin, rst_pin
|
|
58
|
+
self.width, self.height = width, height
|
|
59
|
+
self.swap_red_blue = swap_red_blue
|
|
60
|
+
for p in (self._cs, self._dc, self._rst):
|
|
61
|
+
self._gpio.OpenPin(p, PinMode.Output, PinValue.High)
|
|
62
|
+
# Staging buffer for the per-frame byte re-encode in flush. Allocated
|
|
63
|
+
# once; reused on every push.
|
|
64
|
+
self._swap = bytearray(width * height * 2)
|
|
65
|
+
|
|
66
|
+
def initialize(self):
|
|
67
|
+
# Hard reset: low 20 ms, high 150 ms before the chip answers.
|
|
68
|
+
self._gpio.Write(self._rst, PinValue.Low); time.sleep(0.02)
|
|
69
|
+
self._gpio.Write(self._rst, PinValue.High); time.sleep(0.15)
|
|
70
|
+
self._cmd(0x01); time.sleep(0.15) # SWRESET
|
|
71
|
+
self._cmd(0x11); time.sleep(0.12) # SLPOUT
|
|
72
|
+
self._cmd(0x3A, bytes([0x55])) # COLMOD: 16bpp
|
|
73
|
+
# MADCTL: MX only (0x40). Portrait 240x320, RGB filter. BGR-wired
|
|
74
|
+
# panels are handled via swap_red_blue in flush, not here.
|
|
75
|
+
self._cmd(0x36, bytes([0x40]))
|
|
76
|
+
self._cmd(0x29); time.sleep(0.02) # DISPON
|
|
77
|
+
|
|
78
|
+
def flush(self, pixels):
|
|
79
|
+
"""Push a full frame to the panel.
|
|
80
|
+
|
|
81
|
+
`pixels` is an RGB565 little-endian buffer (bytes / bytearray /
|
|
82
|
+
memoryview) as produced by Canvas.Buffer or by LVGL's custom
|
|
83
|
+
display flush callback. ILI9341 reads 16 bpp big-endian over SPI,
|
|
84
|
+
so we always byte-swap; swap_red_blue additionally swaps R and B
|
|
85
|
+
for BGR-wired modules."""
|
|
86
|
+
src, dst = pixels, self._swap
|
|
87
|
+
if len(dst) != len(src):
|
|
88
|
+
dst = bytearray(len(src))
|
|
89
|
+
self._swap = dst
|
|
90
|
+
if self.swap_red_blue:
|
|
91
|
+
for i in range(0, len(src), 2):
|
|
92
|
+
lo, hi = src[i], src[i + 1]
|
|
93
|
+
r = hi >> 3
|
|
94
|
+
g = ((hi & 0x07) << 3) | (lo >> 5)
|
|
95
|
+
b = lo & 0x1F
|
|
96
|
+
dst[i] = (b << 3) | (g >> 3)
|
|
97
|
+
dst[i + 1] = ((g & 0x07) << 5) | r
|
|
98
|
+
else:
|
|
99
|
+
for i in range(0, len(src), 2):
|
|
100
|
+
dst[i], dst[i + 1] = src[i + 1], src[i]
|
|
101
|
+
self._set_window(0, 0, self.width, self.height)
|
|
102
|
+
self._cmd(0x2C) # RAMWR
|
|
103
|
+
self._write_data(dst)
|
|
104
|
+
|
|
105
|
+
# ---- internals ---------------------------------------------------
|
|
106
|
+
|
|
107
|
+
def _cmd(self, cmd, data=None):
|
|
108
|
+
self._gpio.Write(self._cs, PinValue.Low)
|
|
109
|
+
self._gpio.Write(self._dc, PinValue.Low)
|
|
110
|
+
self._spi.Write(bytes([cmd]))
|
|
111
|
+
if data:
|
|
112
|
+
self._gpio.Write(self._dc, PinValue.High)
|
|
113
|
+
self._spi.Write(data)
|
|
114
|
+
self._gpio.Write(self._cs, PinValue.High)
|
|
115
|
+
|
|
116
|
+
def _write_data(self, data):
|
|
117
|
+
self._gpio.Write(self._cs, PinValue.Low)
|
|
118
|
+
self._gpio.Write(self._dc, PinValue.High)
|
|
119
|
+
# Linux spidev default bufsiz tops out near 4 KB per write(); chunk at 2 KB.
|
|
120
|
+
view = memoryview(data)
|
|
121
|
+
for off in range(0, len(view), 2048):
|
|
122
|
+
self._spi.Write(view[off: off + 2048])
|
|
123
|
+
self._gpio.Write(self._cs, PinValue.High)
|
|
124
|
+
|
|
125
|
+
def _set_window(self, x, y, w, h):
|
|
126
|
+
x1, x2, y1, y2 = x, x + w - 1, y, y + h - 1
|
|
127
|
+
self._cmd(0x2A, bytes([x1 >> 8, x1 & 0xFF, x2 >> 8, x2 & 0xFF]))
|
|
128
|
+
self._cmd(0x2B, bytes([y1 >> 8, y1 & 0xFF, y2 >> 8, y2 & 0xFF]))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.Drivers.HiLetgo.ILI9341
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: HiLetgo ILI9341 240x320 SPI TFT driver for Endpoint. Mirrors the .NET driver API.
|
|
5
|
+
Author-email: "GHI Electronics, LLC" <support@ghielectronics.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.ghielectronics.com/
|
|
8
|
+
Project-URL: Repository, https://github.com/ghi-electronics/endpoint-drivers
|
|
9
|
+
Project-URL: Issues, https://github.com/ghi-electronics/endpoint-drivers/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: GHIElectronics.Endpoint.Core<0.6,>=0.5.3
|
|
15
|
+
Requires-Dist: GHIElectronics.Endpoint.Devices.Gpio<0.6,>=0.5.3
|
|
16
|
+
Requires-Dist: GHIElectronics.Endpoint.Devices.Spi<0.6,>=0.5.3
|
|
17
|
+
|
|
18
|
+
# GHIElectronics.Endpoint.Drivers.HiLetgo.ILI9341
|
|
19
|
+
|
|
20
|
+
HiLetgo ILI9341 240x320 SPI TFT driver for Endpoint (Python). Mirrors the .NET driver API.
|
|
21
|
+
|
|
22
|
+
Part of the [GHI Electronics Endpoint drivers](https://github.com/ghi-electronics/endpoint-drivers). See the repository README for the full driver list.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
GHIElectronics/Endpoint/Drivers/HiLetgo/ILI9341/__init__.py,sha256=KEs5Gmwn98kJlE25m-npN1EqjcPain8SdhHE0WVuPk0,5470
|
|
2
|
+
ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/METADATA,sha256=gCKFzcexEGo15iJXvM9dmVcytp0TExfZCZ07JfMckSY,1144
|
|
3
|
+
ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_drivers_hiletgo_ili9341-0.5.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|