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

Skip to content

Conversation

relic-se
Copy link
Contributor

@relic-se relic-se commented Sep 5, 2025

This update works to make the implementation of the DAC consistent with other implementations and to allow more control over its configuration. The following changes have been applied:

  • Check if the TLV320DAC3100 is available prior to initialization. If not present, all audio related features are still available without raising errors (ie: Peripherals.play_file) and Peripherals.dac and Peripherals.audio return None.
  • Added Peripherals.dac_present property.
    DAC and audio output availability are tested by checking against None.
  • Added sample_rate and bit_depth to constructor arguments.
  • Default sample rate changed from 11030 to 11025.
  • Configurable dac and audio properties.
  • i2c constructor argument (set to False to disable dac & audio initialization).

@dhalbert dhalbert requested a review from FoamyGuy September 5, 2025 16:18
@RetiredWizard
Copy link

This deals with most of what #18 was trying to do (but better) except for supporting I2SOut objects on different pins. Would it make sense to allow, optionally, the I2SOut object to be passed in?

@relic-se
Copy link
Contributor Author

relic-se commented Sep 5, 2025

This deals with most of what #18 was trying to do (but better) except for supporting I2SOut objects on different pins.

Sorry for stepping on your toes a little bit. 😆

Would it make sense to allow, optionally, the I2SOut object to be passed in?

What if we did a check like:

if "I2S_BCLK" in dir(board):
    self._audio = ...

If the pin(s) isn't available, it'll just set self._audio = None. And then we can add @audio.setter to change it after initialization? It'll have to do some de-initialization if necessary, but that shouldn't be a problem.

The user code would look something like:

peripherals = adafruit_fruitjam.peripherals.Peripherals()
peripherals.audio = I2SOut(...)
peripherals.play_file(...)

@relic-se
Copy link
Contributor Author

relic-se commented Sep 5, 2025

As for the DAC, I could see us adding in an argument for the busio.I2S object, but I don't think it makes sense to pass the whole TLV320DAC3100 object. Alternatively, we could do a similar thing for a setter.

@RetiredWizard
Copy link

RetiredWizard commented Sep 5, 2025

As for the DAC, I could see us adding in an argument for the busio.I2S object, but I don't think it makes sense to pass the whole TLV320DAC3100 object. Alternatively, we could do a similar thing for a setter.

I had noticed an application that used a different I2C bus to communicate with the TLV320 breakout board which is why I considered passing the DAC object. I'm not really even sure it wasn't just an alternate name for the board.I2C but it got me thinking that it was possible someone might wire up a different bus.

If we passed in the I2C object to be used though, then a different bus could be used. In addition, if there was an alternate DAC being used (the ES8311 also uses I2C 0x18 so it would be incorrectly identified as the TLV320) an invalid I2C bus or one that wasn't connected could be passed in to disable the TLV320 allowing it to be handled outside the library.

EDIT: 😁 I guess that's essentially your setter approach though....

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Sep 5, 2025

This version of the library seems to be causing the boot animation (or perhaps more broadly initializing adafruit_fruitjam.peripherals.Peripherals?) to get stuck when it runs on a Fruit Jam device (tested on 10.0.beta-3).

I've started tracing to figure out where it is getting stalled but not managed to find the bottom of the rabbit hole yet. It seems like the DAC init never completes when using this version of the library edited to add a few print statements to check where it's at:

>>> import boot_animation
before
after
tlv320_present True
before fj periphs
dac_present True
before tlv init()
...  # never prints anything else even though there is a print after tlv init()

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

I think it's missing an i2c unlock.

@relic-se
Copy link
Contributor Author

relic-se commented Sep 5, 2025

If we passed in the I2C object to be used though, then a different bus could be used. In addition, if there was an alternate DAC being used (the ES8311 also uses I2C 0x18 so it would be incorrectly identified as the TLV320) an invalid I2C bus or one that wasn't connected could be passed in to disable the TLV320 allowing it to be handled outside the library.

@RetiredWizard I've got the setters going and have the i2c bus parameter to disable initialization. I think that takes care of it, but for anything deeper, I may need a direct use-case with desired code examples, because it's starting to get over my head.

Copy link

@RetiredWizard RetiredWizard left a comment

Choose a reason for hiding this comment

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

For what it's worth, here are some notes on my read through. If I have time later tonight, I'll try and get the updates from this PR installed locally so I can do better testing.

@relic-se
Copy link
Contributor Author

relic-se commented Sep 8, 2025

Thanks for the review, @RetiredWizard & @FoamyGuy! I think I've got this ready to go now, but please let me know if there are any additional changes that need to be made.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Thank you!

This looks good to me. Tested successfully with the boot animation on Fruit Jam.

@FoamyGuy FoamyGuy merged commit 57fc5e8 into adafruit:main Sep 8, 2025
1 check passed
@relic-se relic-se deleted the dac-settings branch September 8, 2025 19:47
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 9, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 3.5.4 from 3.5.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#83 from squaregoldfish/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_VEML7700 to 2.1.5 from 2.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_VEML7700#37 from anecdata/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 7.3.0 from 7.2.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#186 from wizhannah/W6300

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI to 1.0.20 from 1.0.19:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_MIDI#15 from spridget/patch-2

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout to 3.1.1 from 3.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#105 from shubham0x13/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_FruitJam to 1.4.0 from 1.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#21 from relic-se/optional-buttons
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#20 from relic-se/dac-settings
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#15 from FoamyGuy/play_mp3_file
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.

3 participants