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

Skip to content

Conversation

@mattytrentini
Copy link
Contributor

@mattytrentini mattytrentini commented Sep 2, 2025

Summary

As described in #7915, machine module needed a DAC entry.

This turned out to be a simple doc item but was surprisingly challenging to summarise the different DAC implementations.

Testing

Tested by building the docs locally; looks reasonable.

Trade-offs and Alternatives

It is tempting to overhaul the DAC interface to make it more complete and remove some of the differences between ports.

For example, we could settle on using, say, a 16 bit range for all ports and interpolate with however many bits are available. Something like a DAC.bits() method could return the port-specific number of bits so the user could determine the actual resolution available. The docs would not need to call out the port-specific ranges. Also, init and deinit are not standard, they probably should be.

So, rather than overhaul the interface (and introduce breaking changes), I thought it best to document the current state and then, later, make the changes and update the docs.

Constructors
------------

.. class:: DAC(pin)
Copy link
Contributor

@robert-hh robert-hh Sep 2, 2025

Choose a reason for hiding this comment

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

At the SAMD port with fixed pins the argument of the constructor is an ID, not a Pin: 0 for SAMD21 and 0 or 1 for SAMD51. That could be changed, but maybe together with the other suggested changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooof, ok, thanks. I can see why you did it that way but it's amazing how - across just three ports - a single method can differ so much! 😉

@robert-hh
Copy link
Contributor

robert-hh commented Sep 2, 2025

Thank you for the effort. Minor comments:

  • There is support for pyb.DAC in the STM32 port. Maybe you could mention it.
  • Given that there is not any more that creating the DAC instance, DAC.init() would not have any functionality. And a DAC.deinit() would only be needed if the DAC implementation would allocate resources which may be used by other modules. I did not see that.

@dpgeorge dpgeorge added this to the release-1.27.0 milestone Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants