48
48
}
49
49
50
50
51
- def request_display_config (width , height ):
51
+ def request_display_config (width , height , color_depth = None ):
52
52
"""
53
53
Request a display size configuration. If the display is un-initialized,
54
54
or is currently using a different configuration it will be initialized
@@ -58,42 +58,54 @@ def request_display_config(width, height):
58
58
59
59
:param width: The width of the display in pixels.
60
60
: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.
61
66
:return: None
62
67
"""
63
68
if (width , height ) not in VALID_DISPLAY_SIZES :
64
69
raise ValueError (f"Invalid display size. Must be one of: { VALID_DISPLAY_SIZES } " )
65
70
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 )
81
94
82
95
83
96
def get_display_config ():
84
97
"""
85
98
Get the current display size configuration.
86
99
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.
90
102
"""
91
103
92
- try :
93
- display = supervisor . runtime . display
104
+ display = supervisor . runtime . display
105
+ if display is not None :
94
106
display_config = (display .width , display .height , display .framebuffer .color_depth )
95
107
return display_config
96
- except ValueError :
108
+ else :
97
109
return (None , None , None )
98
110
99
111
0 commit comments