+
+ for display_bus in display_buses:
+ display_bus.deinit()
+ display_buses.clear()
+
+
+def allocate_display(new_display: Union[BusDisplay, EPaperDisplay]) -> None:
+ """Add a display to the displays pool and return the new display"""
+ if len(displays) >= CIRCUITPY_DISPLAY_LIMIT:
+ raise RuntimeError("Too many displays")
+ displays.append(new_display)
+
+
+def allocate_display_bus(new_display_bus: _DisplayBus) -> None:
+ """Add a display bus to the display_buses pool and return the new display bus"""
+ if len(display_buses) >= CIRCUITPY_DISPLAY_LIMIT:
+ raise RuntimeError(
+ "Too many display busses; forgot displayio.release_displays() ?"
+ )
+ display_buses.append(new_display_bus)
+
+
+background_thread_stop_event = threading.Event()
+background_thread = threading.Thread(
+ target=_background, args=(background_thread_stop_event,), daemon=True
+)
+
+
+# Start the background thread
+def _start_background():
+ if not background_thread.is_alive():
+ background_thread.start()
+
+
+def _stop_background():
+ if background_thread.is_alive():
+ background_thread_stop_event.set()
+ # Stop the thread
+ background_thread.join()
+
+
+_start_background()