Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Conversation

jannic
Copy link

@jannic jannic commented May 5, 2022

According to https://docs.rs/embedded-hal/latest/embedded_hal/digital/v2/trait.StatefulOutputPin.html,
the functions in StatefulOutputPin should not read the actual electrical
value of the pin, but the current state of the output driver.

The fe310 manual states: "Reading the output_val register returns the
written value. Reading the input_val register returns the actual value
of the pin gated by input_en."

So the right thing to do here is to read the corresponding bit in the
output register.

NOTE: I don't have hardware to actually test this fix.

According to https://docs.rs/embedded-hal/latest/embedded_hal/digital/v2/trait.StatefulOutputPin.html,
the functions in StatefulOutputPin should not read the actual electrical
value of the pin, but the current state of the output driver.

The fe310 manual states: "Reading the output_val register returns the
written value. Reading the input_val register returns the actual value
of the pin gated by input_en."

So the right thing to do here is to read the corresponding bit in the
output register.
@almindor
Copy link
Collaborator

almindor commented May 5, 2022

NOTE: I don't have hardware to actually test this fix.

Sadly currently neither do I since I burned my redv :(

@yusefkarim
Copy link

yusefkarim commented Nov 26, 2023

I tested this on my RED-V, works fine 👍 .

An aside: I was wondering, whether if in the output functions (into_output, into_inverted_output, into_output_drive, and into_inverted_output_drive) we should also be clearing the input_en enable bit (e.g., adding the line $GPIOX::set_input_en(Self::INDEX, false);) in all the aforementioned functions?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants