Skip to content

Commit

Permalink
Rename private function Adc::read to Adc::inner_read
Browse files Browse the repository at this point in the history
The name conflicts with the public trait method OneShot::read.
This isn't an issue with correct programs, as rustc just uses the
visible function when called from other crates.

But if you forget importing OneShot, you get a confusing error message:

```
error[E0624]: method `read` is private
   --> rp2040-hal/examples/adc.rs:116:45
    |
116 |         let temp_sens_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap();
    |                                             ^^^^ private method
    |
   ::: /home/jan/rp2040/rp-rs/rp-hal/rp2040-hal/src/adc.rs:302:5
    |
302 |     fn read(&mut self, chan: u8) -> u16 {
    |     ----------------------------------- private method defined here
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
15  + use cortex_m::prelude::_embedded_hal_adc_OneShot;
    |
```

Note that the references method in line 302 is not the one that should
be called, and also has different parameters.

(This was noticed in rp-rs/rp-hal-boards#42)
  • Loading branch information
jannic committed Sep 26, 2023
1 parent 43ddad5 commit 65f2385
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rp2040-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl Adc {
}
}

fn read(&mut self, chan: u8) -> u16 {
fn inner_read(&mut self, chan: u8) -> u16 {
while !self.device.cs.read().ready().bit_is_set() {
cortex_m::asm::nop();
}
Expand Down Expand Up @@ -327,7 +327,7 @@ where
fn read(&mut self, _pin: &mut SRC) -> nb::Result<WORD, Self::Error> {
let chan = SRC::channel();

Ok(self.read(chan).into())
Ok(self.inner_read(chan).into())
}
}

Expand All @@ -351,7 +351,7 @@ where
return Err(nb::Error::Other(InvalidPinError));
};

Ok(self.read(chan).into())
Ok(self.inner_read(chan).into())
}
}

Expand Down

0 comments on commit 65f2385

Please sign in to comment.