Merge pull request #4 from FoamyGuy/color_depth_support
Some checks failed
Build CI / test (push) Has been cancelled

support requesting color depth
This commit is contained in:
Anne Barela 2025-07-09 17:38:44 -04:00 committed by GitHub
commit 76d4f22524
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,7 +48,7 @@ COLOR_DEPTH_LUT = {
} }
def request_display_config(width, height): def request_display_config(width, height, color_depth=None):
""" """
Request a display size configuration. If the display is un-initialized, Request a display size configuration. If the display is un-initialized,
or is currently using a different configuration it will be initialized or is currently using a different configuration it will be initialized
@ -58,42 +58,54 @@ def request_display_config(width, height):
:param width: The width of the display in pixels. :param width: The width of the display in pixels.
:param height: The height of the display in pixels. :param height: The height of the display in pixels.
:param color_depth: The color depth of the display in bits.
Valid values are 1, 2, 4, 8, 16, 32. Larger resolutions must use
smaller color_depths due to RAM limitations. Default color_depth for
720 and 640 width is 8, and default color_depth for 320 and 360 width
is 16.
:return: None :return: None
""" """
if (width, height) not in VALID_DISPLAY_SIZES: if (width, height) not in VALID_DISPLAY_SIZES:
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}") raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
displayio.release_displays() # if user does not specify a requested color_depth
fb = picodvi.Framebuffer( if color_depth is None:
width, # use the maximum color depth for given width
height, color_depth = COLOR_DEPTH_LUT[width]
clk_dp=board.CKP,
clk_dn=board.CKN, requested_config = (width, height, color_depth)
red_dp=board.D0P,
red_dn=board.D0N, if requested_config != get_display_config():
green_dp=board.D1P, displayio.release_displays()
green_dn=board.D1N, fb = picodvi.Framebuffer(
blue_dp=board.D2P, width,
blue_dn=board.D2N, height,
color_depth=COLOR_DEPTH_LUT[width], clk_dp=board.CKP,
) clk_dn=board.CKN,
supervisor.runtime.display = framebufferio.FramebufferDisplay(fb) red_dp=board.D0P,
red_dn=board.D0N,
green_dp=board.D1P,
green_dn=board.D1N,
blue_dp=board.D2P,
blue_dn=board.D2N,
color_depth=color_depth,
)
supervisor.runtime.display = framebufferio.FramebufferDisplay(fb)
def get_display_config(): def get_display_config():
""" """
Get the current display size configuration. Get the current display size configuration.
:return: width: The width of the display in pixels. :return: display_config: Tuple containing the width, height, and color_depth of the display
:return: height: The height of the display in pixels. in pixels and bits respectively.
:return: pixel_depth of the display in pixels
""" """
try: display = supervisor.runtime.display
display = supervisor.runtime.display if display is not None:
display_config = (display.width, display.height, display.framebuffer.color_depth) display_config = (display.width, display.height, display.framebuffer.color_depth)
return display_config return display_config
except ValueError: else:
return (None, None, None) return (None, None, None)