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

GPIO cleanup #2384

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions esp-hal/src/gpio/interconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl InputSignal {
/// - invert: Configures whether or not to invert the input value
/// - input: The GPIO number to connect to the input signal
fn connect(&self, signal: usize, invert: bool, input: u8) {
unsafe { &*GPIO::PTR }
unsafe { GPIO::steal() }
.func_in_sel_cfg(signal - FUNC_IN_SEL_OFFSET)
.modify(|_, w| unsafe {
w.sel()
Expand Down Expand Up @@ -122,10 +122,9 @@ impl PeripheralInput for InputSignal {
GPIO_FUNCTION
} else {
self.input_signals(private::Internal)
.into_iter()
.position(|s| s == Some(signal))
.ok_or(())
.and_then(AlternateFunction::try_from)
.iter()
.find(|(_af, s)| *s == signal)
.map(|(af, _)| *af)
.unwrap_or(GPIO_FUNCTION)
};

Expand Down Expand Up @@ -153,12 +152,12 @@ impl PeripheralInput for InputSignal {
self.pin
.set_alternate_function(GPIO_FUNCTION, private::Internal);

unsafe { &*GPIO::PTR }
unsafe { GPIO::steal() }
.func_in_sel_cfg(signal as usize - FUNC_IN_SEL_OFFSET)
.modify(|_, w| w.sel().clear_bit());
}

fn input_signals(&self, _: private::Internal) -> [Option<gpio::InputSignal>; 6] {
fn input_signals(&self, _: private::Internal) -> &[(AlternateFunction, gpio::InputSignal)] {
PeripheralInput::input_signals(&self.pin, private::Internal)
}

Expand Down Expand Up @@ -239,7 +238,7 @@ impl OutputSignal {
enable_from_gpio: bool,
output: u8,
) {
unsafe { &*GPIO::PTR }
unsafe { GPIO::steal() }
.func_out_sel_cfg(output as usize)
.modify(|_, w| unsafe {
w.out_sel()
Expand Down Expand Up @@ -269,10 +268,9 @@ impl PeripheralOutput for OutputSignal {
GPIO_FUNCTION
} else {
self.output_signals(private::Internal)
.into_iter()
.position(|s| s == Some(signal))
.ok_or(())
.and_then(AlternateFunction::try_from)
.iter()
.find(|(_af, s)| *s == signal)
.map(|(af, _)| *af)
.unwrap_or(GPIO_FUNCTION)
};

Expand Down Expand Up @@ -306,12 +304,12 @@ impl PeripheralOutput for OutputSignal {
self.pin
.set_alternate_function(GPIO_FUNCTION, private::Internal);

unsafe { &*GPIO::PTR }
unsafe { GPIO::steal() }
.func_in_sel_cfg(signal as usize - FUNC_IN_SEL_OFFSET)
.modify(|_, w| w.sel().clear_bit());
}

fn output_signals(&self, _: private::Internal) -> [Option<gpio::OutputSignal>; 6] {
fn output_signals(&self, _: private::Internal) -> &[(AlternateFunction, gpio::OutputSignal)] {
PeripheralOutput::output_signals(&self.pin, private::Internal)
}

Expand Down Expand Up @@ -405,7 +403,7 @@ impl PeripheralInput for AnyInputSignal {
} {
fn init_input(&self, pull: Pull, _internal: private::Internal);
fn is_input_high(&self, _internal: private::Internal) -> bool;
fn input_signals(&self, _internal: private::Internal) -> [Option<gpio::InputSignal>; 6];
fn input_signals(&self, _internal: private::Internal) -> &[(AlternateFunction, gpio::InputSignal)];
}

to match &mut self.0 {
Expand Down
Loading