Skip to content
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

Peripheral interconnect redo, vol 2 (split()) #2418

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented Oct 28, 2024

This PR replaces the previous getters with a split function. This will allow eventually resolving #2273 by introducing different variants for when the GPIO is split, vs when the GPIO is passed wholly to a peripheral. This also allows us to remove a few hacks around input/output initialization - if a pin was split, enable_output shouldn't disable input, for example.

Pin drivers retain their getters and instead convert into signals that (will) force GPIO matrix use.

esp-hal/src/gpio/mod.rs Show resolved Hide resolved
esp-hal/src/gpio/mod.rs Show resolved Hide resolved
hil-test/tests/spi_slave.rs Show resolved Hide resolved
@bugadani bugadani force-pushed the interconnect branch 5 times, most recently from 8b14709 to 71d9427 Compare October 28, 2024 11:14
esp-hal/src/gpio/mod.rs Outdated Show resolved Hide resolved
@bugadani bugadani marked this pull request as draft October 29, 2024 14:32
@bugadani bugadani marked this pull request as ready for review October 29, 2024 15:01

/// Returns a peripheral [input][interconnect::InputSignal] connected to
/// this pin.
impl<P> Input<'_, P>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment on spi_slave test.

let cs = cs_gpio.peripheral_input();
let sclk = sclk_gpio.peripheral_input();
let mosi = mosi_gpio.peripheral_input();
// let miso = unsafe { miso_gpio.clone_unchecked() }.into_peripheral_output();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm considering my options here. This unsafe clone can be replaced by a Flex::split_peripheral_output() -> (interconnect::OutputSignal, Input) (and same method on Output and OutputOpenDrain), but then we can't have split and into_peripheral_output on Input. I'm not sure which one is better, working with Flex is somewhat low level - but so is splitting off an output signal and keeping a GPIO input.

@bugadani

This comment was marked as resolved.

@bugadani bugadani marked this pull request as draft October 29, 2024 16:02
@bugadani bugadani force-pushed the interconnect branch 3 times, most recently from 52f4fb0 to 71d9427 Compare October 29, 2024 16:37
@bugadani bugadani marked this pull request as ready for review October 29, 2024 16:58
@bugadani bugadani force-pushed the interconnect branch 3 times, most recently from 4d59d75 to 16b376a Compare October 30, 2024 18:37
@bugadani bugadani changed the title Peripheral interconnect redo, vol 2 Peripheral interconnect redo, vol 2 (split()) Oct 31, 2024
@MabezDev
Copy link
Member

Perhaps a naive question, what's the point of the owned split if the signals are still clonable?

@bugadani
Copy link
Contributor Author

What is "owned split"?

@bugadani
Copy link
Contributor Author

Ah this PR is a preparation for #2419. After #2419 there will be a difference between passing a pin to a peripheral (may bypass the GPIO matrix) and passing a signal to a peripheral (forces use of the GPIO matrix). We can't provide a non-splitting way to obtain signals, because GPIO matrix usage won't be unambiguous.

@MabezDev
Copy link
Member

Ah okay I think I answered my own question actually. This PR stops someone using a GPIO pin's signal for something and then doing something with the pin itself which might end up overwriting some signal-related operations?

@bugadani
Copy link
Contributor Author

The only intended change is that peripherals won't try to force their specific alternate function on a GPIO, but instead always go through the GPIO matrix.

The side-effect is that "split-then-create-a-gpio-driver" use cases will need to be flipped to "create-driver-then-split-off-signal".

There shouldn't be any reduction in flexibility I hope.

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

LGTM, one note about the migration guide entry.

esp-hal/MIGRATING-0.21.md Show resolved Hide resolved
@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2024

Not really related but I'm wondering if we should briefly explain things like signals and alternate functions in the GPIO module docs

@bugadani
Copy link
Contributor Author

bugadani commented Nov 1, 2024

Definitely, although I'd leave it to upcoming documentation work (or just the next PR)

@bugadani
Copy link
Contributor Author

bugadani commented Nov 4, 2024

Not really related but I'm wondering if we should briefly explain things like signals and alternate functions in the GPIO module docs

I've tweaked the docs in #2419 a bit but as we don't exactly advertise alternate functions I think it's fine to keep their docs where they are.

Copy link
Contributor

@JurajSadel JurajSadel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@bugadani bugadani added this pull request to the merge queue Nov 4, 2024
Merged via the queue into esp-rs:main with commit 0c86740 Nov 4, 2024
28 checks passed
@bugadani bugadani deleted the interconnect branch November 4, 2024 11:48
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.

5 participants