GHIElectronics.Endpoint.Devices.Display 0.5.1__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/Devices/Display/__init__.py +539 -0
- ghielectronics_endpoint_devices_display-0.5.1.dist-info/METADATA +20 -0
- ghielectronics_endpoint_devices_display-0.5.1.dist-info/RECORD +5 -0
- ghielectronics_endpoint_devices_display-0.5.1.dist-info/WHEEL +5 -0
- ghielectronics_endpoint_devices_display-0.5.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
"""Display on Endpoint. DisplayController is an abstract class: customers
|
|
2
|
+
subclass it when they wire up a non-standard panel (SPI, I2C, or anything
|
|
3
|
+
else) and drive the hardware themselves. For the one transport the library
|
|
4
|
+
ships out of the box - the SoC's parallel RGB panel into /dev/fb0 - we
|
|
5
|
+
provide ParallelDisplayController; GetDefault() returns one when
|
|
6
|
+
``/config/display.json`` names type = ``parallel``.
|
|
7
|
+
|
|
8
|
+
from GHIElectronics.Endpoint.Devices.Display import DisplayController, PixelFormat
|
|
9
|
+
|
|
10
|
+
display = DisplayController.GetDefault()
|
|
11
|
+
if display is not None:
|
|
12
|
+
display.Enable()
|
|
13
|
+
display.ShowLogo()
|
|
14
|
+
display.Flush(bitmap_bytes, PixelFormat.Format32bppArgb)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import abc
|
|
18
|
+
import ctypes
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import struct
|
|
22
|
+
import tempfile
|
|
23
|
+
from enum import IntEnum
|
|
24
|
+
|
|
25
|
+
from GHIElectronics.Endpoint.Core._native import native
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
_CONFIG_PATH = "/config/display.json"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class DisplayType(IntEnum):
|
|
32
|
+
"""Which built-in transport the display uses. ``None_`` means the board
|
|
33
|
+
has no built-in display (and a custom subclass may still own a panel)."""
|
|
34
|
+
|
|
35
|
+
None_ = 0
|
|
36
|
+
Parallel = 1
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class PixelFormat(IntEnum):
|
|
40
|
+
"""Pixel format of a buffer passed to :meth:`DisplayController.Flush`.
|
|
41
|
+
Names and integer values mirror System.Drawing.Imaging.PixelFormat."""
|
|
42
|
+
|
|
43
|
+
Format1bppIndexed = 0x30101
|
|
44
|
+
Format8bppIndexed = 0x30803
|
|
45
|
+
Format16bppRgb555 = 0x21005
|
|
46
|
+
Format16bppRgb565 = 0x21006
|
|
47
|
+
Format24bppRgb = 0x21808
|
|
48
|
+
Format32bppRgb = 0x22009
|
|
49
|
+
Format32bppArgb = 0x26200A
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class SignalPolarity(IntEnum):
|
|
53
|
+
"""Polarity of a logic-level control signal."""
|
|
54
|
+
|
|
55
|
+
ActiveHigh = 0
|
|
56
|
+
ActiveLow = 1
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ClockEdge(IntEnum):
|
|
60
|
+
"""Which edge of the pixel clock the panel latches data on."""
|
|
61
|
+
|
|
62
|
+
Rising = 0
|
|
63
|
+
Falling = 1
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class BacklightSettings:
|
|
67
|
+
"""GPIO line driving the panel's backlight. ``Pin`` is the chip-neutral
|
|
68
|
+
packed pin number (e.g. ``EPM815.Gpio.Pin.PD14`` or
|
|
69
|
+
``EPDomino24.Backlight``); -1 means "no pin"."""
|
|
70
|
+
|
|
71
|
+
def __init__(self):
|
|
72
|
+
self.Pin = -1
|
|
73
|
+
self.ActivePolarity = SignalPolarity.ActiveHigh
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ParallelLcdSettings:
|
|
77
|
+
"""Timings for the SoC's built-in parallel RGB panel controller."""
|
|
78
|
+
|
|
79
|
+
def __init__(self):
|
|
80
|
+
self.Width = 0
|
|
81
|
+
self.Height = 0
|
|
82
|
+
self.PixelClockHz = 0
|
|
83
|
+
self.HFrontPorch = 0
|
|
84
|
+
self.HBackPorch = 0
|
|
85
|
+
self.HSync = 0
|
|
86
|
+
self.VFrontPorch = 0
|
|
87
|
+
self.VBackPorch = 0
|
|
88
|
+
self.VSync = 0
|
|
89
|
+
self.BitsPerPixel = 16
|
|
90
|
+
self.DataEnablePolarity = SignalPolarity.ActiveHigh
|
|
91
|
+
self.PixelClockEdge = ClockEdge.Rising
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class DisplaySettings:
|
|
95
|
+
"""Everything in /config/display.json."""
|
|
96
|
+
|
|
97
|
+
def __init__(self):
|
|
98
|
+
self.Type = DisplayType.None_
|
|
99
|
+
self.EnableAtBoot = False
|
|
100
|
+
self.Backlight = None
|
|
101
|
+
self.Logo = None
|
|
102
|
+
self.Parallel = None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class DisplayController(abc.ABC):
|
|
106
|
+
"""A display on the board. Abstract: subclass for custom SPI/I2C panels,
|
|
107
|
+
use :meth:`GetDefault` for the built-in parallel RGB transport."""
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
@abc.abstractmethod
|
|
111
|
+
def Width(self):
|
|
112
|
+
"""Visible width of the panel in pixels."""
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
@abc.abstractmethod
|
|
116
|
+
def Height(self):
|
|
117
|
+
"""Visible height of the panel in pixels."""
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
@abc.abstractmethod
|
|
121
|
+
def IsEnabled(self):
|
|
122
|
+
"""True once the panel driver / init path has run and the panel is ready to receive pixels."""
|
|
123
|
+
|
|
124
|
+
@abc.abstractmethod
|
|
125
|
+
def Enable(self):
|
|
126
|
+
"""Load the panel driver / run the init sequence. Throws on failure."""
|
|
127
|
+
|
|
128
|
+
@abc.abstractmethod
|
|
129
|
+
def Disable(self):
|
|
130
|
+
"""Reverse of Enable. Safe to call when nothing is enabled."""
|
|
131
|
+
|
|
132
|
+
def Flush(self, pixels, format_=None, x=None, y=None, width=None, height=None):
|
|
133
|
+
"""Push a frame. ``pixels`` is bytes / bytearray / memoryview.
|
|
134
|
+
``format_`` defaults to :attr:`PixelFormat.Format16bppRgb565`. If
|
|
135
|
+
x/y/width/height are omitted, the full panel is updated."""
|
|
136
|
+
if format_ is None:
|
|
137
|
+
format_ = PixelFormat.Format16bppRgb565
|
|
138
|
+
if x is None: x = 0
|
|
139
|
+
if y is None: y = 0
|
|
140
|
+
if width is None: width = self.Width
|
|
141
|
+
if height is None: height = self.Height
|
|
142
|
+
self._Flush(bytes(pixels), format_, x, y, width, height)
|
|
143
|
+
|
|
144
|
+
@abc.abstractmethod
|
|
145
|
+
def _Flush(self, pixels, format_, x, y, width, height):
|
|
146
|
+
"""Subclasses implement the full-form Flush."""
|
|
147
|
+
|
|
148
|
+
def ShowLogo(self):
|
|
149
|
+
"""Read the ``logo`` filename from /config/display.json, decode the
|
|
150
|
+
24-bit BMP, and Flush it. No-op if the file is missing."""
|
|
151
|
+
settings = DisplayController.GetSettings()
|
|
152
|
+
if not settings.Logo:
|
|
153
|
+
return
|
|
154
|
+
path = os.path.join("/config", settings.Logo)
|
|
155
|
+
result = _read_24bit_bmp(path)
|
|
156
|
+
if result is None:
|
|
157
|
+
return
|
|
158
|
+
pixels, w, h = result
|
|
159
|
+
self.Flush(pixels, PixelFormat.Format24bppRgb, 0, 0,
|
|
160
|
+
min(w, self.Width), min(h, self.Height))
|
|
161
|
+
|
|
162
|
+
@abc.abstractmethod
|
|
163
|
+
def Dispose(self):
|
|
164
|
+
"""Release the panel's resources (/dev/fb0 handle, etc.)."""
|
|
165
|
+
|
|
166
|
+
def __enter__(self):
|
|
167
|
+
return self
|
|
168
|
+
|
|
169
|
+
def __exit__(self, *_):
|
|
170
|
+
self.Dispose()
|
|
171
|
+
|
|
172
|
+
@staticmethod
|
|
173
|
+
def GetSettings():
|
|
174
|
+
"""Reads the built-in display's settings from /config/display.json."""
|
|
175
|
+
config = _load_config()
|
|
176
|
+
s = DisplaySettings()
|
|
177
|
+
s.Type = _parse_type(config.get("type"))
|
|
178
|
+
s.EnableAtBoot = bool(config.get("enableAtBoot", False))
|
|
179
|
+
s.Logo = config.get("logo") or None
|
|
180
|
+
s.Backlight = _read_backlight(config.get("backlight"))
|
|
181
|
+
s.Parallel = _read_parallel(config.get("parallel"))
|
|
182
|
+
return s
|
|
183
|
+
|
|
184
|
+
@staticmethod
|
|
185
|
+
def SetSettings(settings):
|
|
186
|
+
"""Writes the settings to /config/display.json. Does NOT apply them -
|
|
187
|
+
call :meth:`Enable` for that."""
|
|
188
|
+
if settings is None:
|
|
189
|
+
raise ValueError("settings must not be None")
|
|
190
|
+
config = _load_config()
|
|
191
|
+
config["version"] = 1
|
|
192
|
+
config["enableAtBoot"] = bool(settings.EnableAtBoot)
|
|
193
|
+
config["type"] = _type_to_string(settings.Type)
|
|
194
|
+
config["logo"] = settings.Logo
|
|
195
|
+
config["backlight"] = _write_backlight(settings.Backlight)
|
|
196
|
+
config["parallel"] = _write_parallel(settings.Parallel)
|
|
197
|
+
# Drop keys from older firmware schemas so the file stays tidy.
|
|
198
|
+
for stale in ("nativeLcd", "spi", "i2c", "touch"):
|
|
199
|
+
config.pop(stale, None)
|
|
200
|
+
_save_config(config)
|
|
201
|
+
|
|
202
|
+
@staticmethod
|
|
203
|
+
def GetDefault():
|
|
204
|
+
"""The built-in display controller for this board, or None when the
|
|
205
|
+
type in /config/display.json is None."""
|
|
206
|
+
settings = DisplayController.GetSettings()
|
|
207
|
+
if settings.Type != DisplayType.Parallel:
|
|
208
|
+
return None
|
|
209
|
+
return ParallelDisplayController()
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class ParallelDisplayController(DisplayController):
|
|
213
|
+
"""The built-in parallel RGB panel driven by the SoC's LCD controller.
|
|
214
|
+
Opens /dev/fb0 inside :meth:`Enable`, respects the real framebuffer
|
|
215
|
+
stride, converts source pixel formats to the panel's bit depth."""
|
|
216
|
+
|
|
217
|
+
def __init__(self):
|
|
218
|
+
self._fb = None
|
|
219
|
+
self._stride = 0
|
|
220
|
+
self._target_bpp = 16
|
|
221
|
+
self._width = 0
|
|
222
|
+
self._height = 0
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def Width(self):
|
|
226
|
+
if self._width:
|
|
227
|
+
return self._width
|
|
228
|
+
p = DisplayController.GetSettings().Parallel
|
|
229
|
+
return p.Width if p else 0
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def Height(self):
|
|
233
|
+
if self._height:
|
|
234
|
+
return self._height
|
|
235
|
+
p = DisplayController.GetSettings().Parallel
|
|
236
|
+
return p.Height if p else 0
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def IsEnabled(self):
|
|
240
|
+
result = ctypes.c_int()
|
|
241
|
+
native.display_is_enabled(native.ref(result))
|
|
242
|
+
return result.value != 0
|
|
243
|
+
|
|
244
|
+
def Enable(self):
|
|
245
|
+
native.display_enable()
|
|
246
|
+
p = DisplayController.GetSettings().Parallel or ParallelLcdSettings()
|
|
247
|
+
self._width = p.Width
|
|
248
|
+
self._height = p.Height
|
|
249
|
+
self._target_bpp = p.BitsPerPixel or 16
|
|
250
|
+
self._fb = open("/dev/fb0", "r+b", buffering=0)
|
|
251
|
+
# MA35D1 DCUltra pins fb0 at 32 bpp BGRX8888 regardless of what
|
|
252
|
+
# display.json's BitsPerPixel says; trust the kernel.
|
|
253
|
+
try:
|
|
254
|
+
with open("/sys/class/graphics/fb0/bits_per_pixel", "r") as bf:
|
|
255
|
+
parsed_bpp = int(bf.read().strip())
|
|
256
|
+
if parsed_bpp > 0:
|
|
257
|
+
self._target_bpp = parsed_bpp
|
|
258
|
+
except (OSError, ValueError):
|
|
259
|
+
pass
|
|
260
|
+
self._stride = self._width * (self._target_bpp // 8)
|
|
261
|
+
try:
|
|
262
|
+
with open("/sys/class/graphics/fb0/stride", "r") as sf:
|
|
263
|
+
parsed = int(sf.read().strip())
|
|
264
|
+
if parsed > 0:
|
|
265
|
+
self._stride = parsed
|
|
266
|
+
except (OSError, ValueError):
|
|
267
|
+
pass
|
|
268
|
+
|
|
269
|
+
def Disable(self):
|
|
270
|
+
if self._fb is not None:
|
|
271
|
+
self._fb.close()
|
|
272
|
+
self._fb = None
|
|
273
|
+
native.display_disable()
|
|
274
|
+
|
|
275
|
+
def _Flush(self, pixels, format_, x, y, width, height):
|
|
276
|
+
if self._fb is None:
|
|
277
|
+
raise RuntimeError("Flush called before Enable")
|
|
278
|
+
if (x < 0 or y < 0 or width <= 0 or height <= 0
|
|
279
|
+
or x + width > self._width or y + height > self._height):
|
|
280
|
+
raise ValueError("Flush region outside the panel")
|
|
281
|
+
|
|
282
|
+
source_bpp = {
|
|
283
|
+
PixelFormat.Format16bppRgb565: 2,
|
|
284
|
+
PixelFormat.Format24bppRgb: 3,
|
|
285
|
+
PixelFormat.Format32bppRgb: 4,
|
|
286
|
+
PixelFormat.Format32bppArgb: 4,
|
|
287
|
+
}.get(format_)
|
|
288
|
+
if source_bpp is None:
|
|
289
|
+
raise NotImplementedError(f"Unsupported source format: {format_}")
|
|
290
|
+
source_stride = width * source_bpp
|
|
291
|
+
if len(pixels) < source_stride * height:
|
|
292
|
+
raise ValueError("Pixel buffer is smaller than the region")
|
|
293
|
+
|
|
294
|
+
target_bytes_per_pixel = self._target_bpp // 8
|
|
295
|
+
row_bytes = width * target_bytes_per_pixel
|
|
296
|
+
row = bytearray(row_bytes)
|
|
297
|
+
for r in range(height):
|
|
298
|
+
src = pixels[r * source_stride : r * source_stride + source_stride]
|
|
299
|
+
_convert_row(src, row, format_, self._target_bpp, width)
|
|
300
|
+
self._fb.seek((y + r) * self._stride + x * target_bytes_per_pixel)
|
|
301
|
+
self._fb.write(row)
|
|
302
|
+
|
|
303
|
+
def Dispose(self):
|
|
304
|
+
try:
|
|
305
|
+
self.Disable()
|
|
306
|
+
except Exception:
|
|
307
|
+
pass
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
# ---------------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
def _load_config():
|
|
313
|
+
if not os.path.exists(_CONFIG_PATH):
|
|
314
|
+
return {"version": 1}
|
|
315
|
+
try:
|
|
316
|
+
with open(_CONFIG_PATH, "r") as f:
|
|
317
|
+
data = json.load(f)
|
|
318
|
+
return data if isinstance(data, dict) else {"version": 1}
|
|
319
|
+
except (OSError, json.JSONDecodeError):
|
|
320
|
+
return {"version": 1}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def _save_config(config):
|
|
324
|
+
directory = os.path.dirname(_CONFIG_PATH) or "."
|
|
325
|
+
fd, tmp = tempfile.mkstemp(prefix=".display", suffix=".json.tmp", dir=directory)
|
|
326
|
+
try:
|
|
327
|
+
with os.fdopen(fd, "w") as f:
|
|
328
|
+
json.dump(config, f, indent=2)
|
|
329
|
+
os.replace(tmp, _CONFIG_PATH)
|
|
330
|
+
except Exception:
|
|
331
|
+
try: os.unlink(tmp)
|
|
332
|
+
except OSError: pass
|
|
333
|
+
raise
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _parse_type(value):
|
|
337
|
+
if value is None:
|
|
338
|
+
return DisplayType.None_
|
|
339
|
+
return DisplayType.Parallel if str(value).lower() == "parallel" else DisplayType.None_
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _type_to_string(t):
|
|
343
|
+
return "parallel" if t == DisplayType.Parallel else "none"
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def _read_backlight(o):
|
|
347
|
+
if not isinstance(o, dict):
|
|
348
|
+
return None
|
|
349
|
+
# New schema: a single packed "pin" int (chip-neutral EPM/EPN pin).
|
|
350
|
+
pin = o.get("pin")
|
|
351
|
+
# Legacy schema from 0.3.x: "gpioChip" ("gpiochipN") + "gpioPin" (line).
|
|
352
|
+
# We can't losslessly reverse those to a packed pin without the original
|
|
353
|
+
# chip's port ordering, so leave Pin = -1 and rely on the next
|
|
354
|
+
# SetSettings call (migration-on-write) to put the new keys in place.
|
|
355
|
+
# The user's live backlight continues to work because the native
|
|
356
|
+
# Display.cpp still reads the legacy keys as a fallback.
|
|
357
|
+
legacy_chip = o.get("gpioChip")
|
|
358
|
+
legacy_pin = o.get("gpioPin")
|
|
359
|
+
if pin is None and legacy_chip is None and legacy_pin is None:
|
|
360
|
+
return None
|
|
361
|
+
b = BacklightSettings()
|
|
362
|
+
b.Pin = int(pin) if isinstance(pin, int) else -1
|
|
363
|
+
b.ActivePolarity = (SignalPolarity.ActiveLow
|
|
364
|
+
if str(o.get("activePolarity", "")).lower() == "activelow"
|
|
365
|
+
else SignalPolarity.ActiveHigh)
|
|
366
|
+
return b
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _chip_get_chip_id(pin):
|
|
370
|
+
"""Dispatch pin -> gpiochip number via the chip detected at import.
|
|
371
|
+
Chip-neutral mirror of .NET's PeripheralPins.ChipGetChipId."""
|
|
372
|
+
# Import lazily to avoid a circular import at package init time.
|
|
373
|
+
from GHIElectronics.Endpoint.Core._chip_detect import Current, Chip
|
|
374
|
+
if Current == Chip.Epn256:
|
|
375
|
+
from GHIElectronics.Endpoint.Core._epn256 import EPN256
|
|
376
|
+
return EPN256.Gpio.GetChipId(pin)
|
|
377
|
+
if Current == Chip.Epn128:
|
|
378
|
+
from GHIElectronics.Endpoint.Core._epn128 import EPN128
|
|
379
|
+
return EPN128.Gpio.GetChipId(pin)
|
|
380
|
+
# Epm815 and Unknown both fall back to EPM815 (its layout).
|
|
381
|
+
from GHIElectronics.Endpoint.Core._epm815 import EPM815
|
|
382
|
+
return EPM815.Gpio.GetChipId(pin)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _chip_get_line_id(pin):
|
|
386
|
+
"""Dispatch pin -> line number via the chip detected at import."""
|
|
387
|
+
from GHIElectronics.Endpoint.Core._chip_detect import Current, Chip
|
|
388
|
+
if Current == Chip.Epn256:
|
|
389
|
+
from GHIElectronics.Endpoint.Core._epn256 import EPN256
|
|
390
|
+
return EPN256.Gpio.GetLineId(pin)
|
|
391
|
+
if Current == Chip.Epn128:
|
|
392
|
+
from GHIElectronics.Endpoint.Core._epn128 import EPN128
|
|
393
|
+
return EPN128.Gpio.GetLineId(pin)
|
|
394
|
+
from GHIElectronics.Endpoint.Core._epm815 import EPM815
|
|
395
|
+
return EPM815.Gpio.GetLineId(pin)
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def _write_backlight(b):
|
|
399
|
+
polarity = b.ActivePolarity if b else SignalPolarity.ActiveHigh
|
|
400
|
+
out = {
|
|
401
|
+
"activePolarity": "activeLow" if polarity == SignalPolarity.ActiveLow else "activeHigh",
|
|
402
|
+
}
|
|
403
|
+
if b is not None and b.Pin >= 0:
|
|
404
|
+
# Resolve the packed pin via ChipDetect; the native Display.cpp
|
|
405
|
+
# reads these int keys.
|
|
406
|
+
out["pin"] = b.Pin
|
|
407
|
+
out["chip"] = _chip_get_chip_id(b.Pin)
|
|
408
|
+
out["line"] = _chip_get_line_id(b.Pin)
|
|
409
|
+
return out
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _read_parallel(o):
|
|
413
|
+
if not isinstance(o, dict):
|
|
414
|
+
return None
|
|
415
|
+
p = ParallelLcdSettings()
|
|
416
|
+
p.Width = int(o.get("width", 0) or 0)
|
|
417
|
+
p.Height = int(o.get("height", 0) or 0)
|
|
418
|
+
p.PixelClockHz = int(o.get("pixelClockHz", 0) or 0)
|
|
419
|
+
p.HFrontPorch = int(o.get("hFrontPorch", 0) or 0)
|
|
420
|
+
p.HBackPorch = int(o.get("hBackPorch", 0) or 0)
|
|
421
|
+
p.HSync = int(o.get("hSync", 0) or 0)
|
|
422
|
+
p.VFrontPorch = int(o.get("vFrontPorch", 0) or 0)
|
|
423
|
+
p.VBackPorch = int(o.get("vBackPorch", 0) or 0)
|
|
424
|
+
p.VSync = int(o.get("vSync", 0) or 0)
|
|
425
|
+
p.BitsPerPixel = int(o.get("bitsPerPixel", 16) or 16)
|
|
426
|
+
p.DataEnablePolarity = (SignalPolarity.ActiveLow
|
|
427
|
+
if bool(o.get("deActiveLow", False))
|
|
428
|
+
else SignalPolarity.ActiveHigh)
|
|
429
|
+
p.PixelClockEdge = (ClockEdge.Falling
|
|
430
|
+
if bool(o.get("pixelClockFalling", False))
|
|
431
|
+
else ClockEdge.Rising)
|
|
432
|
+
return p
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def _write_parallel(p):
|
|
436
|
+
if p is None:
|
|
437
|
+
p = ParallelLcdSettings()
|
|
438
|
+
return {
|
|
439
|
+
"width": p.Width,
|
|
440
|
+
"height": p.Height,
|
|
441
|
+
"pixelClockHz": p.PixelClockHz,
|
|
442
|
+
"hFrontPorch": p.HFrontPorch,
|
|
443
|
+
"hBackPorch": p.HBackPorch,
|
|
444
|
+
"hSync": p.HSync,
|
|
445
|
+
"vFrontPorch": p.VFrontPorch,
|
|
446
|
+
"vBackPorch": p.VBackPorch,
|
|
447
|
+
"vSync": p.VSync,
|
|
448
|
+
"bitsPerPixel": p.BitsPerPixel,
|
|
449
|
+
"deActiveLow": p.DataEnablePolarity == SignalPolarity.ActiveLow,
|
|
450
|
+
"pixelClockFalling": p.PixelClockEdge == ClockEdge.Falling,
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def _convert_row(src, dst, format_, target_bpp, pixels):
|
|
455
|
+
if format_ == PixelFormat.Format16bppRgb565 and target_bpp == 16:
|
|
456
|
+
dst[: pixels * 2] = src[: pixels * 2]
|
|
457
|
+
return
|
|
458
|
+
if target_bpp == 16:
|
|
459
|
+
src_bpp = 3 if format_ == PixelFormat.Format24bppRgb else 4
|
|
460
|
+
for p in range(pixels):
|
|
461
|
+
b = src[p * src_bpp + 0]
|
|
462
|
+
g = src[p * src_bpp + 1]
|
|
463
|
+
r = src[p * src_bpp + 2]
|
|
464
|
+
v = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
|
|
465
|
+
dst[p * 2 + 0] = v & 0xFF
|
|
466
|
+
dst[p * 2 + 1] = (v >> 8) & 0xFF
|
|
467
|
+
return
|
|
468
|
+
if target_bpp == 24:
|
|
469
|
+
if format_ == PixelFormat.Format24bppRgb:
|
|
470
|
+
dst[: pixels * 3] = src[: pixels * 3]
|
|
471
|
+
return
|
|
472
|
+
if format_ in (PixelFormat.Format32bppRgb, PixelFormat.Format32bppArgb):
|
|
473
|
+
for p in range(pixels):
|
|
474
|
+
dst[p * 3 + 0] = src[p * 4 + 0]
|
|
475
|
+
dst[p * 3 + 1] = src[p * 4 + 1]
|
|
476
|
+
dst[p * 3 + 2] = src[p * 4 + 2]
|
|
477
|
+
return
|
|
478
|
+
if target_bpp == 32:
|
|
479
|
+
# BGRX8888 target (MA35D1 DCUltra default). Source bytes are
|
|
480
|
+
# {B, G, R} / {B, G, R, A} little-endian; destination is
|
|
481
|
+
# {B, G, R, X}. Unpack RGB565 by replicating the top bits down.
|
|
482
|
+
if format_ == PixelFormat.Format16bppRgb565:
|
|
483
|
+
for p in range(pixels):
|
|
484
|
+
lo = src[p * 2 + 0]
|
|
485
|
+
hi = src[p * 2 + 1]
|
|
486
|
+
r5 = (hi >> 3) & 0x1F
|
|
487
|
+
g6 = ((hi & 0x07) << 3) | ((lo >> 5) & 0x07)
|
|
488
|
+
b5 = lo & 0x1F
|
|
489
|
+
dst[p * 4 + 0] = (b5 << 3) | (b5 >> 2)
|
|
490
|
+
dst[p * 4 + 1] = (g6 << 2) | (g6 >> 4)
|
|
491
|
+
dst[p * 4 + 2] = (r5 << 3) | (r5 >> 2)
|
|
492
|
+
dst[p * 4 + 3] = 0
|
|
493
|
+
return
|
|
494
|
+
if format_ == PixelFormat.Format24bppRgb:
|
|
495
|
+
for p in range(pixels):
|
|
496
|
+
dst[p * 4 + 0] = src[p * 3 + 0]
|
|
497
|
+
dst[p * 4 + 1] = src[p * 3 + 1]
|
|
498
|
+
dst[p * 4 + 2] = src[p * 3 + 2]
|
|
499
|
+
dst[p * 4 + 3] = 0
|
|
500
|
+
return
|
|
501
|
+
if format_ in (PixelFormat.Format32bppRgb, PixelFormat.Format32bppArgb):
|
|
502
|
+
dst[: pixels * 4] = src[: pixels * 4]
|
|
503
|
+
return
|
|
504
|
+
raise NotImplementedError(f"Cannot convert {format_} to {target_bpp}bpp")
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def _read_24bit_bmp(path):
|
|
508
|
+
"""Minimal 24-bit uncompressed BMP reader. Returns (pixels, width, height)
|
|
509
|
+
with pixels in top-down 24bppRgb (B,G,R) order, or None on failure."""
|
|
510
|
+
try:
|
|
511
|
+
with open(path, "rb") as f:
|
|
512
|
+
header = f.read(54)
|
|
513
|
+
if len(header) != 54 or header[0:2] != b"BM":
|
|
514
|
+
return None
|
|
515
|
+
data_offset = struct.unpack_from("<I", header, 10)[0]
|
|
516
|
+
w = struct.unpack_from("<i", header, 18)[0]
|
|
517
|
+
h = struct.unpack_from("<i", header, 22)[0]
|
|
518
|
+
bpp = struct.unpack_from("<H", header, 28)[0]
|
|
519
|
+
compression = struct.unpack_from("<I", header, 30)[0]
|
|
520
|
+
if bpp != 24 or compression != 0 or w <= 0:
|
|
521
|
+
return None
|
|
522
|
+
flip_y = h > 0
|
|
523
|
+
abs_h = h if flip_y else -h
|
|
524
|
+
row_bytes = w * 3
|
|
525
|
+
row_pad = (4 - (row_bytes & 3)) & 3
|
|
526
|
+
|
|
527
|
+
f.seek(data_offset)
|
|
528
|
+
pixels = bytearray(row_bytes * abs_h)
|
|
529
|
+
for r in range(abs_h):
|
|
530
|
+
dest_row = (abs_h - 1 - r) if flip_y else r
|
|
531
|
+
data = f.read(row_bytes)
|
|
532
|
+
if len(data) != row_bytes:
|
|
533
|
+
return None
|
|
534
|
+
pixels[dest_row * row_bytes : dest_row * row_bytes + row_bytes] = data
|
|
535
|
+
if row_pad:
|
|
536
|
+
f.read(row_pad)
|
|
537
|
+
return pixels, w, abs_h
|
|
538
|
+
except OSError:
|
|
539
|
+
return None
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.Devices.Display
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: Display on GHI Electronics Endpoint: native parallel LCDs, SPI and I2C panels configured in /config/display.json.
|
|
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-Libraries
|
|
9
|
+
Project-URL: Issues, https://github.com/ghi-electronics/Endpoint-Libraries/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.1
|
|
15
|
+
|
|
16
|
+
# GHIElectronics.Endpoint.Devices.Display
|
|
17
|
+
|
|
18
|
+
Display on GHI Electronics Endpoint: native parallel LCDs, SPI and I2C panels configured in /config/display.json.
|
|
19
|
+
|
|
20
|
+
Part of the [GHI Electronics Endpoint](https://github.com/ghi-electronics/Endpoint-Libraries) libraries. See the repository README for the full package list and getting-started guide.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
GHIElectronics/Endpoint/Devices/Display/__init__.py,sha256=S7pzr0RPE-SitScLtFFNzMD-OnU_wOYANbKJ6Fzp7A0,19335
|
|
2
|
+
ghielectronics_endpoint_devices_display-0.5.1.dist-info/METADATA,sha256=aBMXoyJ5dTcReoUyKrpGeebQUWBTuz61Gk4XrneGlDo,1089
|
|
3
|
+
ghielectronics_endpoint_devices_display-0.5.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_devices_display-0.5.1.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_devices_display-0.5.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|