4848}
4949
5050
51- def request_display_config (width , height ):
51+ def request_display_config (width , height , color_depth = None ):
5252 """
5353 Request a display size configuration. If the display is un-initialized,
5454 or is currently using a different configuration it will be initialized
@@ -58,42 +58,54 @@ def request_display_config(width, height):
5858
5959 :param width: The width of the display in pixels.
6060 :param height: The height of the display in pixels.
61+ :param color_depth: The color depth of the display in bits.
62+ Valid values are 1, 2, 4, 8, 16, 32. Larger resolutions must use
63+ smaller color_depths due to RAM limitations. Default color_depth for
64+ 720 and 640 width is 8, and default color_depth for 320 and 360 width
65+ is 16.
6166 :return: None
6267 """
6368 if (width , height ) not in VALID_DISPLAY_SIZES :
6469 raise ValueError (f"Invalid display size. Must be one of: { VALID_DISPLAY_SIZES } " )
6570
66- displayio .release_displays ()
67- fb = picodvi .Framebuffer (
68- width ,
69- height ,
70- clk_dp = board .CKP ,
71- clk_dn = board .CKN ,
72- red_dp = board .D0P ,
73- red_dn = board .D0N ,
74- green_dp = board .D1P ,
75- green_dn = board .D1N ,
76- blue_dp = board .D2P ,
77- blue_dn = board .D2N ,
78- color_depth = COLOR_DEPTH_LUT [width ],
79- )
80- supervisor .runtime .display = framebufferio .FramebufferDisplay (fb )
71+ # if user does not specify a requested color_depth
72+ if color_depth is None :
73+ # use the maximum color depth for given width
74+ color_depth = COLOR_DEPTH_LUT [width ]
75+
76+ requested_config = (width , height , color_depth )
77+
78+ if requested_config != get_display_config ():
79+ displayio .release_displays ()
80+ fb = picodvi .Framebuffer (
81+ width ,
82+ height ,
83+ clk_dp = board .CKP ,
84+ clk_dn = board .CKN ,
85+ red_dp = board .D0P ,
86+ red_dn = board .D0N ,
87+ green_dp = board .D1P ,
88+ green_dn = board .D1N ,
89+ blue_dp = board .D2P ,
90+ blue_dn = board .D2N ,
91+ color_depth = color_depth ,
92+ )
93+ supervisor .runtime .display = framebufferio .FramebufferDisplay (fb )
8194
8295
8396def get_display_config ():
8497 """
8598 Get the current display size configuration.
8699
87- :return: width: The width of the display in pixels.
88- :return: height: The height of the display in pixels.
89- :return: pixel_depth of the display in pixels
100+ :return: display_config: Tuple containing the width, height, and color_depth of the display
101+ in pixels and bits respectively.
90102 """
91103
92- try :
93- display = supervisor . runtime . display
104+ display = supervisor . runtime . display
105+ if display is not None :
94106 display_config = (display .width , display .height , display .framebuffer .color_depth )
95107 return display_config
96- except ValueError :
108+ else :
97109 return (None , None , None )
98110
99111
0 commit comments