-
Notifications
You must be signed in to change notification settings - Fork 221
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
Implement open drain output #263
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for picking this back up! I've got two comments, apart from that it looks good to go.
Co-authored-by: Rahix <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! Just to make sure: Did you test that it behaves correctly on real hardware? If not, I can take care of it in the coming days.
I haven't yet, but I can do a test sometime today |
I tested it with this modified uno-blink example: Measured the resistance to ground and the voltage (with a pullup) and it seems to work as expected. #![no_std]
#![no_main]
use panic_halt as _;
#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut led = pins.d12.into_opendrain_high();
loop {
led.set_high();
arduino_hal::delay_ms(500);
led.set_low();
arduino_hal::delay_ms(500);
led.set_high();
arduino_hal::delay_ms(500);
led.set_low();
arduino_hal::delay_ms(1000);
}
} |
One thing I noticed is that there isn't a |
We should want that the hardware provides. If the open drain output can not be read back, don't do it, do not fake toggle for something that can not be toggled. (My definition of toggle is an atomic read level and write invert level back, something that will work for a push-pull-output-pin. (But we are dealing with open drain outpt.)) |
@stappersg Glancing at the ATmega328P datasheet, the bits of DDRx registers are labeled R/W, so I'm pretty sure we can determine the state of open-drain pins, and I'd assume that's also a feature on other models. So that's some justification for a And there is precedent for a read-modify-write implementation for |
Sure, this would also be nice. But I suggest adding it in a separate MR...
Careful! This is especially important for open-drain outputs. After a |
Oh, thanks, I should have looked more closely, it does use |
Based on #217 as it has been inactive. I've rebased it on the latest
main
and addressed the comments in the original pull request.