Coder Social home page Coder Social logo

Comments (7)

stappersg avatar stappersg commented on September 6, 2024

from avr-hal.

Rahix avatar Rahix commented on September 6, 2024

@stappersg this is entirely besides the point. There are certainly usecases where a pin is used with the ADC and digital I/O at the same time.

from avr-hal.

Rahix avatar Rahix commented on September 6, 2024

Am I missing something? Is there a different way to read from a pin and get it back?

No, unfortunately you are not missing anything. We simply don't have this implemented yet. The problem is that we can't just reuse the .into_...() methods that are used to convert a pin between different digital I/O modes because they don't reset the ADC configuration. I am not sure how this can be best plumbed into our codebase. Maybe the easiest solution is simply a .into_digital() method on ADC pins which always just makes the pin a floating input - and then you can further convert the pin into any digital I/O as you please. What do you think?

from avr-hal.

QuinnFreedman avatar QuinnFreedman commented on September 6, 2024

Maybe the easiest solution is simply a .into_digital() method on ADC pins which always just makes the pin a floating input.

Could you just add another impl for Pin<mode::Analog, PIN> that implements all the into... methods and resets the ADC in each one? If that doesn't work, an into_digital method would also be fine by me. On a related note, it looks like an Adc::disable_pin method might be missing.

I am happy to work on a PR for this next week if you don't have the bandwidth to take it on.

from avr-hal.

QuinnFreedman avatar QuinnFreedman commented on September 6, 2024

@stappersg My current usecase is that I have several pullup inputs connected to buttons, but I want to read their floating value before setting them to pullup in order to seed my PRNG. But you could also have situations where you want to switch between input modes based on what is connected to your device, user configuration, etc.

from avr-hal.

stappersg avatar stappersg commented on September 6, 2024

from avr-hal.

Rahix avatar Rahix commented on September 6, 2024

Could you just add another impl for Pin<mode::Analog, PIN> that implements all the into... methods and resets the ADC in each one?

No, unfortunately, Rust doesn't allow multiple inherent impls on the same type to define methods of the same name, even if the generics don't overlap. That's why I suggested the into_digital() approach...

I am happy to work on a PR for this next week if you don't have the bandwidth to take it on.

I'd certainly welcome a PR :)

from avr-hal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.