-
Notifications
You must be signed in to change notification settings - Fork 4
Description
request_display_config is one of the best current ways of setting up a DVI display at the moment.
#1. It would be good to have a function get_display_config returning a tuple (w, h, bit_depth) to ensure the display is in the correct mode for using supervisor.runtime.display
#2 request_display_config provides a fixed 8 bit buffer. Suggest using a modified version of Sam's code to provide a robust display configuration routine as this would preclude including a bunch of display code in each use, similar to using some other Adafruit boards.
adafruit/circuitpython#10431 (comment)
Likely some additional exception catching would be needed. Perhaps return a status or True/False if it worked
Example:
status = request_display_config(640, 480, 8)
If not status:
print("Display configuration not supported by this board")
raise status
Requested video mode is available and set, now do your thing
`def init_display(width, height, color_depth):
"""Initialize the picodvi display
Video mode compatibility (only tested these--unsure about other boards):
| Video Mode | Fruit Jam | Metro RP2350 No PSRAM |
| --------------- | --------- | ------------------------ |
| 320x240, 8-bit | Yes! | Yes! |
| 320x240, 16-bit | Yes! | Yes! |
| 640x480, 8-bit | Yes! | MemoryError exception :( |
"""
displayio.release_displays()
gc.collect()
fb = picodvi.Framebuffer(width, height, clk_dp=CKP, clk_dn=CKN,
red_dp=D0P, red_dn=D0N, green_dp=D1P, green_dn=D1N,
blue_dp=D2P, blue_dn=D2N, color_depth=color_depth)
display = framebufferio.FramebufferDisplay(fb)
supervisor.runtime.display = display
return display
Pick a video mode (comment out the one you don't want):
requested_mode = (320, 240, 8)
#requested_mode = (320, 240, 16)
#requested_mode = (640, 480, 8) # This needs board with PSRAM
(width, height, color_depth) = requested_mode
Detect if an existing display matches requested video mode
display = supervisor.runtime.display
if display is None:
current_mode = None # Metro RP2350 runtime.display may be None
else:
current_mode = (
display.width,
display.height,
display.framebuffer.color_depth
)
if requested_mode != current_mode:
# Didn't find a display configured as we need, so initialize a new one
print("Re-initializing display for mode:", requested_mode)
try:
display = init_display(width, height, color_depth)
except MemoryError as e:
# Fall back to low resolution so the error message will be readable
display = init_display(320, 240, 8)
print("---\nREQUESTED VIDEO MODE NEEDS A BOARD WITH PSRAM\n---")
raise e
else:
print("Using existing display mode:", requested_mode)`