Skip to content

Commit 24f8458

Browse files
authored
Remove DerefMut from PeripheralRef (#3017)
1 parent f247b40 commit 24f8458

File tree

17 files changed

+185
-208
lines changed

17 files changed

+185
-208
lines changed

esp-hal/src/gpio/interconnect.rs

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub(crate) fn connect_input_signal(
155155
}
156156

157157
fn connect_pin_to_input_signal(
158-
pin: &mut AnyPin,
158+
pin: &AnyPin,
159159
signal: gpio::InputSignal,
160160
is_inverted: bool,
161161
force_gpio: bool,
@@ -176,7 +176,7 @@ fn connect_pin_to_input_signal(
176176
}
177177

178178
fn connect_peripheral_to_output(
179-
pin: &mut AnyPin,
179+
pin: &AnyPin,
180180
signal: gpio::OutputSignal,
181181
is_inverted: bool,
182182
force_gpio: bool,
@@ -217,7 +217,7 @@ fn connect_peripheral_to_output(
217217
});
218218
}
219219

220-
fn disconnect_peripheral_output_from_pin(pin: &mut AnyPin, signal: gpio::OutputSignal) {
220+
fn disconnect_peripheral_output_from_pin(pin: &AnyPin, signal: gpio::OutputSignal) {
221221
pin.set_alternate_function(GPIO_FUNCTION);
222222

223223
GPIO::regs()
@@ -307,8 +307,8 @@ impl InputSignal {
307307
/// Since there can only be one input signal connected to a peripheral at a
308308
/// time, this function will disconnect any previously connected input
309309
/// signals.
310-
fn connect_input_to_peripheral(&mut self, signal: gpio::InputSignal) {
311-
connect_pin_to_input_signal(&mut self.pin, signal, self.is_inverted, true);
310+
fn connect_input_to_peripheral(&self, signal: gpio::InputSignal) {
311+
connect_pin_to_input_signal(&self.pin, signal, self.is_inverted, true);
312312
}
313313

314314
delegate::delegate! {
@@ -318,7 +318,7 @@ impl InputSignal {
318318
pub fn input_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::InputSignal)];
319319
pub fn init_input(&self, pull: Pull);
320320
pub fn is_input_high(&self) -> bool;
321-
pub fn enable_input(&mut self, on: bool);
321+
pub fn enable_input(&self, on: bool);
322322
}
323323
}
324324
}
@@ -346,8 +346,8 @@ impl DirectInputSignal {
346346
/// Since there can only be one input signal connected to a peripheral at a
347347
/// time, this function will disconnect any previously connected input
348348
/// signals.
349-
fn connect_input_to_peripheral(&mut self, signal: gpio::InputSignal) {
350-
connect_pin_to_input_signal(&mut self.pin, signal, false, false);
349+
fn connect_input_to_peripheral(&self, signal: gpio::InputSignal) {
350+
connect_pin_to_input_signal(&self.pin, signal, false, false);
351351
}
352352

353353
delegate::delegate! {
@@ -356,7 +356,7 @@ impl DirectInputSignal {
356356
fn input_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::InputSignal)];
357357
fn init_input(&self, pull: Pull);
358358
fn is_input_high(&self) -> bool;
359-
fn enable_input(&mut self, on: bool);
359+
fn enable_input(&self, on: bool);
360360
}
361361
}
362362
}
@@ -428,17 +428,17 @@ impl OutputSignal {
428428
}
429429

430430
/// Connect the pin to a peripheral output signal.
431-
fn connect_peripheral_to_output(&mut self, signal: gpio::OutputSignal) {
432-
connect_peripheral_to_output(&mut self.pin, signal, self.is_inverted, true, true, false);
431+
fn connect_peripheral_to_output(&self, signal: gpio::OutputSignal) {
432+
connect_peripheral_to_output(&self.pin, signal, self.is_inverted, true, true, false);
433433
}
434434

435435
/// Remove this output pin from a connected [signal](`gpio::OutputSignal`).
436436
///
437437
/// Clears the entry in the GPIO matrix / Io mux that associates this output
438438
/// pin with a previously connected [signal](`gpio::OutputSignal`). Any
439439
/// other outputs connected to the peripheral remain intact.
440-
fn disconnect_from_peripheral_output(&mut self, signal: gpio::OutputSignal) {
441-
disconnect_peripheral_output_from_pin(&mut self.pin, signal);
440+
fn disconnect_from_peripheral_output(&self, signal: gpio::OutputSignal) {
441+
disconnect_peripheral_output_from_pin(&self.pin, signal);
442442
}
443443

444444
delegate::delegate! {
@@ -448,15 +448,15 @@ impl OutputSignal {
448448
pub fn input_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::InputSignal)];
449449
pub fn init_input(&self, pull: Pull);
450450
pub fn is_input_high(&self) -> bool;
451-
pub fn enable_input(&mut self, on: bool);
451+
pub fn enable_input(&self, on: bool);
452452

453453
pub fn output_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::OutputSignal)];
454-
pub fn set_to_open_drain_output(&mut self);
455-
pub fn set_to_push_pull_output(&mut self);
456-
pub fn enable_output(&mut self, on: bool);
457-
pub fn set_output_high(&mut self, on: bool);
458-
pub fn set_drive_strength(&mut self, strength: gpio::DriveStrength);
459-
pub fn enable_open_drain(&mut self, on: bool);
454+
pub fn set_to_open_drain_output(&self);
455+
pub fn set_to_push_pull_output(&self);
456+
pub fn enable_output(&self, on: bool);
457+
pub fn set_output_high(&self, on: bool);
458+
pub fn set_drive_strength(&self, strength: gpio::DriveStrength);
459+
pub fn enable_open_drain(&self, on: bool);
460460
pub fn is_set_high(&self) -> bool;
461461
}
462462
}
@@ -475,17 +475,17 @@ impl DirectOutputSignal {
475475
}
476476

477477
/// Connect the pin to a peripheral output signal.
478-
fn connect_peripheral_to_output(&mut self, signal: gpio::OutputSignal) {
479-
connect_peripheral_to_output(&mut self.pin, signal, false, false, true, false);
478+
fn connect_peripheral_to_output(&self, signal: gpio::OutputSignal) {
479+
connect_peripheral_to_output(&self.pin, signal, false, false, true, false);
480480
}
481481

482482
/// Remove this output pin from a connected [signal](`gpio::OutputSignal`).
483483
///
484484
/// Clears the entry in the GPIO matrix / Io mux that associates this output
485485
/// pin with a previously connected [signal](`gpio::OutputSignal`). Any
486486
/// other outputs connected to the peripheral remain intact.
487-
fn disconnect_from_peripheral_output(&mut self, signal: gpio::OutputSignal) {
488-
disconnect_peripheral_output_from_pin(&mut self.pin, signal);
487+
fn disconnect_from_peripheral_output(&self, signal: gpio::OutputSignal) {
488+
disconnect_peripheral_output_from_pin(&self.pin, signal);
489489
}
490490

491491
delegate::delegate! {
@@ -494,15 +494,15 @@ impl DirectOutputSignal {
494494
fn input_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::InputSignal)];
495495
fn init_input(&self, pull: Pull);
496496
fn is_input_high(&self) -> bool;
497-
fn enable_input(&mut self, on: bool);
497+
fn enable_input(&self, on: bool);
498498

499499
fn output_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::OutputSignal)];
500-
fn set_to_open_drain_output(&mut self);
501-
fn set_to_push_pull_output(&mut self);
502-
fn enable_output(&mut self, on: bool);
503-
fn set_output_high(&mut self, on: bool);
504-
fn set_drive_strength(&mut self, strength: gpio::DriveStrength);
505-
fn enable_open_drain(&mut self, on: bool);
500+
fn set_to_open_drain_output(&self);
501+
fn set_to_push_pull_output(&self);
502+
fn enable_output(&self, on: bool);
503+
fn set_output_high(&self, on: bool);
504+
fn set_drive_strength(&self, strength: gpio::DriveStrength);
505+
fn enable_open_drain(&self, on: bool);
506506
fn is_set_high(&self) -> bool;
507507
}
508508
}
@@ -605,18 +605,10 @@ impl InputConnection {
605605
pub fn init_input(&self, pull: Pull);
606606
pub fn is_input_high(&self) -> bool;
607607
pub fn input_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::InputSignal)];
608-
}
609-
610-
#[instability::unstable]
611-
to match &mut self.0 {
612-
InputConnectionInner::Input(pin) => pin,
613-
InputConnectionInner::DirectInput(pin) => pin,
614-
InputConnectionInner::Constant(level) => level,
615-
} {
616-
pub fn enable_input(&mut self, on: bool);
608+
pub fn enable_input(&self, on: bool);
617609

618610
// This doesn't need to be public, the intended way is `connect_to` and `disconnect_from`
619-
fn connect_input_to_peripheral(&mut self, signal: gpio::InputSignal);
611+
fn connect_input_to_peripheral(&self, signal: gpio::InputSignal);
620612
}
621613
}
622614
}
@@ -702,27 +694,20 @@ impl OutputConnection {
702694

703695
pub fn is_set_high(&self) -> bool;
704696
pub fn output_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, gpio::OutputSignal)];
705-
}
706-
#[instability::unstable]
707-
to match &mut self.0 {
708-
OutputConnectionInner::Output(pin) => pin,
709-
OutputConnectionInner::DirectOutput(pin) => pin,
710-
OutputConnectionInner::Constant(level) => level,
711-
} {
712-
pub fn pull_direction(&mut self, pull: Pull);
713-
pub fn init_input(&mut self, pull: Pull);
714-
pub fn enable_input(&mut self, on: bool);
697+
pub fn pull_direction(&self, pull: Pull);
698+
pub fn init_input(&self, pull: Pull);
699+
pub fn enable_input(&self, on: bool);
715700

716-
pub fn set_to_open_drain_output(&mut self);
717-
pub fn set_to_push_pull_output(&mut self);
718-
pub fn enable_output(&mut self, on: bool);
719-
pub fn set_output_high(&mut self, on: bool);
720-
pub fn set_drive_strength(&mut self, strength: gpio::DriveStrength);
721-
pub fn enable_open_drain(&mut self, on: bool);
701+
pub fn set_to_open_drain_output(&self);
702+
pub fn set_to_push_pull_output(&self);
703+
pub fn enable_output(&self, on: bool);
704+
pub fn set_output_high(&self, on: bool);
705+
pub fn set_drive_strength(&self, strength: gpio::DriveStrength);
706+
pub fn enable_open_drain(&self, on: bool);
722707

723708
// These don't need to be public, the intended way is `connect_to` and `disconnect_from`
724-
fn connect_peripheral_to_output(&mut self, signal: gpio::OutputSignal);
725-
fn disconnect_from_peripheral_output(&mut self, signal: gpio::OutputSignal);
709+
fn connect_peripheral_to_output(&self, signal: gpio::OutputSignal);
710+
fn disconnect_from_peripheral_output(&self, signal: gpio::OutputSignal);
726711
}
727712
}
728713

esp-hal/src/gpio/lp_io.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ macro_rules! lp_gpio {
200200
) => {
201201
$(
202202
impl $crate::gpio::RtcPin for GpioPin<$gpionum> {
203-
unsafe fn apply_wakeup(&mut self, wakeup: bool, level: u8) {
203+
unsafe fn apply_wakeup(&self, wakeup: bool, level: u8) {
204204
let lp_io = $crate::peripherals::LP_IO::regs();
205205
lp_io.pin($gpionum).modify(|_, w| {
206206
w.wakeup_enable().bit(wakeup).int_type().bits(level)
207207
});
208208
}
209209

210-
fn rtcio_pad_hold(&mut self, enable: bool) {
210+
fn rtcio_pad_hold(&self, enable: bool) {
211211
let mask = 1 << $gpionum;
212212
unsafe {
213213
let lp_aon = $crate::peripherals::LP_AON::regs();
@@ -224,7 +224,7 @@ macro_rules! lp_gpio {
224224

225225
/// Set the LP properties of the pin. If `mux` is true then then pin is
226226
/// routed to LP_IO, when false it is routed to IO_MUX.
227-
fn rtc_set_config(&mut self, input_enable: bool, mux: bool, func: $crate::gpio::RtcFunction) {
227+
fn rtc_set_config(&self, input_enable: bool, mux: bool, func: $crate::gpio::RtcFunction) {
228228
let mask = 1 << $gpionum;
229229
unsafe {
230230
let lp_aon = $crate::peripherals::LP_AON::regs();
@@ -251,12 +251,12 @@ macro_rules! lp_gpio {
251251
}
252252

253253
impl $crate::gpio::RtcPinWithResistors for GpioPin<$gpionum> {
254-
fn rtcio_pullup(&mut self, enable: bool) {
254+
fn rtcio_pullup(&self, enable: bool) {
255255
let lp_io = $crate::peripherals::LP_IO::regs();
256256
lp_io.gpio($gpionum).modify(|_, w| w.fun_wpu().bit(enable));
257257
}
258258

259-
fn rtcio_pulldown(&mut self, enable: bool) {
259+
fn rtcio_pulldown(&self, enable: bool) {
260260
let lp_io = $crate::peripherals::LP_IO::regs();
261261
lp_io.gpio($gpionum).modify(|_, w| w.fun_wpd().bit(enable));
262262
}

0 commit comments

Comments
 (0)