1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
7 ================================================================================
11 **Software and Dependencies:**
14 https://github.com/adafruit/Adafruit_Blinka/releases
16 * Author(s): Melissa LeBlanc-Williams
21 from typing import Union
23 from ._bitmap import Bitmap
24 from ._colorspace import Colorspace
25 from ._colorconverter import ColorConverter
26 from ._group import Group
27 from ._ondiskbitmap import OnDiskBitmap
28 from ._palette import Palette
29 from ._tilegrid import TileGrid
30 from ._constants import CIRCUITPY_DISPLAY_LIMIT
33 __version__ = "0.0.0+auto.0"
34 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
41 def _background(stop_event):
42 """Main thread function to loop through all displays and update them"""
43 while not stop_event.is_set():
44 for display in displays:
45 display._background() # pylint: disable=protected-access
47 # relax system when _background does nothing
48 # and we are in a while True loop consuming lots of CPU
52 def release_displays() -> None:
53 """Releases any actively used displays so their busses and pins can be used again.
55 Use this once in your code.py if you initialize a display. Place it right before the
56 initialization so the display is active as long as possible.
58 for display in displays:
59 display._release() # pylint: disable=protected-access
62 for display_bus in display_buses:
68 new_display: Union["busdisplay.BusDisplay", "epaperdisplay.EPaperDisplay"]
70 """Add a display to the displays pool and return the new display"""
71 if len(displays) >= CIRCUITPY_DISPLAY_LIMIT:
72 raise RuntimeError("Too many displays")
73 displays.append(new_display)
76 def allocate_display_bus(new_display_bus: "busdisplay._displaybus._DisplayBus") -> None:
77 """Add a display bus to the display_buses pool and return the new display bus"""
78 if len(display_buses) >= CIRCUITPY_DISPLAY_LIMIT:
80 "Too many display busses; forgot displayio.release_displays() ?"
82 display_buses.append(new_display_bus)
85 background_thread_stop_event = threading.Event()
86 background_thread = threading.Thread(
87 target=_background, args=(background_thread_stop_event,), daemon=True
91 # Start the background thread
92 def _start_background():
93 if not background_thread.is_alive():
94 background_thread.start()
97 def _stop_background():
98 if background_thread.is_alive():
99 background_thread_stop_event.set()
101 background_thread.join()