]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blob - displayio/__init__.py
More displayio code updates
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / __init__.py
1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4
5 """
6 `displayio`
7 ================================================================================
8
9 displayio for Blinka
10
11 **Software and Dependencies:**
12
13 * Adafruit Blinka:
14   https://github.com/adafruit/Adafruit_Blinka/releases
15
16 * Author(s): Melissa LeBlanc-Williams
17
18 """
19 import threading
20 from typing import Union
21 from ._fourwire import FourWire
22 from ._i2cdisplay import I2CDisplay
23 from ._bitmap import Bitmap
24 from ._colorspace import Colorspace
25 from ._colorconverter import ColorConverter
26 from ._display import Display
27 from ._epaperdisplay import EPaperDisplay
28 from ._group import Group
29 from ._ondiskbitmap import OnDiskBitmap
30 from ._palette import Palette
31 from ._shape import Shape
32 from ._tilegrid import TileGrid
33 from ._displaybus import _DisplayBus
34 from ._constants import CIRCUITPY_DISPLAY_LIMIT
35
36 __version__ = "0.0.0+auto.0"
37 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
38
39
40 displays = []
41 display_buses = []
42
43
44 def _background():
45     """Main thread function to loop through all displays and update them"""
46     for display in displays:
47         display.background()
48
49
50 def release_displays() -> None:
51     """Releases any actively used displays so their busses and pins can be used again.
52
53     Use this once in your code.py if you initialize a display. Place it right before the
54     initialization so the display is active as long as possible.
55     """
56     for display in displays:
57         display.release()
58     displays.clear()
59
60     for display_bus in display_buses:
61         display_bus.deinit()
62     display_buses.clear()
63
64
65 def allocate_display(new_display: Union[Display, EPaperDisplay]) -> None:
66     """Add a display to the displays pool and return the new display"""
67     if len(displays) >= CIRCUITPY_DISPLAY_LIMIT:
68         raise RuntimeError("Too many displays")
69     displays.append(new_display)
70
71
72 def allocate_display_bus(new_display_bus: _DisplayBus) -> None:
73     """Add a display bus to the display_buses pool and return the new display bus"""
74     if len(display_buses) >= CIRCUITPY_DISPLAY_LIMIT:
75         raise RuntimeError(
76             "Too many display busses; forgot displayio.release_displays() ?"
77         )
78     display_buses.append(new_display_bus)
79
80
81 background_thread = threading.Thread(target=_background, daemon=True)
82
83
84 # Start the background thread
85 def _start_background():
86     if not background_thread.is_alive():
87         background_thread.start()
88
89
90 def _stop_background():
91     if background_thread.is_alive():
92         # Stop the thread
93         background_thread.join()
94
95
96 _start_background()