8000 expose picodvi.framebuffer.color_depth to python by FoamyGuy · Pull Request #10431 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

expose picodvi.framebuffer.color_depth to python #10431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025

Conversation

FoamyGuy
Copy link
Collaborator

resolves: #10420

Tested very briefly in REPL on a Fruit Jam and it seems to work as intended.

>>> import supervisor
>>> supervisor.runtime.display.framebuffer.color_depth
8

ping @samblenny incase you're interested in trying this

@samblenny
Copy link

I want to try the Fruit Jam build of this. Should there be a CI build of the uf2 for this on S3? When I looked just now, I didn't see anything for this PR. It looks like the CI Build job ran though? Maybe I just need to wait longer for the file to show up?

@dhalbert
Copy link
Collaborator

I want to try the Fruit Jam build of this. Should there be a CI build of the uf2 for this on S3? When I looked just now, I didn't see anything for this PR. It looks like the CI Build job ran though? Maybe I just need to wait longer for the file to show up?

Only merged PR's and releases show up on S3. But the build artifacts are available. Click on any board build in the list below, Click summary on the left side, somewhat near the top, and then look for the "Artifacts" list.

@samblenny
Copy link

Click on any board build in the list below, Click summary on the left side, somewhat near the top, and then look for the "Artifacts" list.

Wasn't able to find this. Closest I came was a link in the Upload Artifact section of the ports (raspberrypi) / board (adafruit_fruit_jam) CI Build job page. But, that file is 10.7 MB instead of the usual 1.7MB for a Fruit Jam uf2 firmware file.

@samblenny
Copy link

oh... actually. looks like that's actually a zip file instead of a uf2? The link doesn't include an extension, but it seems to work as a .zip. I found a file inside of that that looks 8000 promising.

@dhalbert
Copy link
Collaborator

Yup, that's it. I meant this:
image

image

image

@samblenny
Copy link
samblenny commented Jun 17, 2025

Tested on Fruit Jam Rev B for switching between video modes (320, 240, 8) and (320, 240, 16). Looks good.

The color_depth property shows up as supervisor.runtime.display.framebuffer.color_depth:

Adafruit CircuitPython 10.0.0-alpha.7-1-g5a401d545e on 2025-06-17; Adafruit Fruit Jam with rp2350b
>>> import supervisor
>>> d = supervisor.runtime.display
>>> dir(d)
['__class__', 'auto_refresh', 'fill_row', 'framebuffer', 'height', 'refresh', 'root_group', 'rotation', 'show', 'width']
>>> dir(d.framebuffer)
['__class__', 'color_depth', 'deinit', 'height', 'width']
>>> (d.framebuffer.width, d.framebuffer.height, d.framebuffer.color_depth)
(320, 240, 8)
>>> 

This is what I used for detecting the video mode and re-initializing the display if needed (anyone is welcome to use this code for whatever):

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)

[edit: added the init_display function definition that I initially forgot]

@samblenny
Copy link
samblenny commented Jun 17, 2025

Tested on Metro RP2350 (no PSRAM), and I got this:

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Heap allocation when VM not running.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.

This happens even when code.py is empty

[edit: never mind. I flashed the wrong uf2 file]

@samblenny
Copy link

Actually... Metro RP2350 is fine. I mistakenly flashed the wrong uf2 build file. This works great on Metro RP2350 no PSRAM for (320, 240, 8) and (320, 240, 16) when using the correct uf2.

Copy link
Collaborator
@eightycc eightycc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine. Thank you!

@eightycc eightycc merged commit 2513277 into adafruit:main Jun 18, 2025
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add picodvi.Framebuffer.color_depth property for RP2350 video mode detection?
4 participants
0