Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

RetiredWizard
Copy link

I was working on refactoring the new audio API into some of the Fruit Jam apps and realized that for apps that might be run on other boards like the Metro RP2350 with a TLV320 breakout, the library would crash when trying to use the defined I2S pins that the Fruit Jam has. I think we may have the same issue if we try and use the library's screen API but I didn't look closely at that. (maybe the Metro RP2350 has the same DVI pin names so at least that board would work)

This is the Fruit Jam library so I understand if we don't care that it doesn't work on other boards in which case I'll just stick to using the TLV320 library for Apps that may run on other boards.

I also found that the new volume settings were too soft. I set the default safe_volume_limit up to 17. The old value translated to -11.4dB and the 17 translates to about 10 which I found was still not loud on both headphones and the speaker. I'm going to also open an issue about the volume level so if you would like me to drop that change from this PR for now I can do that too.

@RetiredWizard
Copy link
Author

RetiredWizard commented Aug 29, 2025

I've removed the pins and added the suggested constructor objects. Here's a snippet from Chip's Challenge, refactored for use with the new library API:

if TLV320_PRESENT:
    if hasattr(board, "I2S_BCLK"):
        fjPeriphs = adafruit_fruitjam.Peripherals()
        audio_bus = fjPeriphs.audio

        # set sample rate & bit depth
        fjPeriphs.dac.configure_clocks(sample_rate=44100, bit_depth=16)

    elif hasattr(board, "D9") and hasattr(board, "D10") and hasattr(board, "D11"):
        i2c = board.I2C()
        dac = adafruit_tlv320.TLV320DAC3100(i2c)
        dac.configure_clocks(sample_rate=44100, bit_depth=16)
        audio_bus = audiobusio.I2SOut(board.D9, board.D10, board.D11)
        fjPeriphs = adafruit_fruitjam(dac=dac,i2s_audio=audio_bus)

    fjPeriphs.audio_output = "headphone"
    if "audio" in launcher_config:
        if launcher_config["audio"].get("output") == "speaker":
            # use speaker
            fjPeriphs.audio_output = "speaker"
        if "volume" in launcher_config["audio"]:
            fjPeriphs.volume = launcher_config["audio"]["volume"]  # fruitjam volume level (1-20)

Chip's challenge used the same I2C device for the RP2350 and the Fruit Jam, however Larsio Paint Music, used two different I2C definitions. I haven't looked to see if that was actually necessary but by passing the DAC object through the library allows supporting DACs connected to different I2C busses (not to mention potentially different DAC hardware).

Edit: I just noticed a problem with the volume setting in this snippet but it's fixed now. Nevermind 😁

@RetiredWizard
Copy link
Author

Closing in favor of #20

@RetiredWizard RetiredWizard deleted the fruitjamlibi2spins branch September 15, 2025 01:52
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.

2 participants