871: nrf/saadc: add type-erased AnyInput. r=Dirbaio a=Dirbaio 872: nrf/usb: prevent user code from constructing a PowerUsb directly. r=Dirbaio a=Dirbaio PowerUsb must be constructed through `new()` so that it sets up the IRQ. It must have at least one private field, otherwise user code can construct it directly with `PowerUsb{}`. Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
b916a912df
2 changed files with 30 additions and 3 deletions
|
@ -119,6 +119,25 @@ impl sealed::Input for VddhDiv5Input {
|
||||||
#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
|
#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
|
||||||
impl Input for VddhDiv5Input {}
|
impl Input for VddhDiv5Input {}
|
||||||
|
|
||||||
|
pub struct AnyInput {
|
||||||
|
channel: InputChannel,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Unborrow for AnyInput {
|
||||||
|
type Target = AnyInput;
|
||||||
|
unsafe fn unborrow(self) -> Self::Target {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sealed::Input for AnyInput {
|
||||||
|
fn channel(&self) -> InputChannel {
|
||||||
|
self.channel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Input for AnyInput {}
|
||||||
|
|
||||||
impl<'d> ChannelConfig<'d> {
|
impl<'d> ChannelConfig<'d> {
|
||||||
/// Default configuration for single ended channel sampling.
|
/// Default configuration for single ended channel sampling.
|
||||||
pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self {
|
pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self {
|
||||||
|
@ -670,7 +689,13 @@ pub(crate) mod sealed {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
|
/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
|
||||||
pub trait Input: sealed::Input + Unborrow<Target = Self> {}
|
pub trait Input: sealed::Input + Unborrow<Target = Self> + Sized {
|
||||||
|
fn degrade_saadc(self) -> AnyInput {
|
||||||
|
AnyInput {
|
||||||
|
channel: self.channel(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! impl_saadc_input {
|
macro_rules! impl_saadc_input {
|
||||||
($pin:ident, $ch:ident) => {
|
($pin:ident, $ch:ident) => {
|
||||||
|
|
|
@ -47,7 +47,9 @@ pub struct Driver<'d, T: Instance, P: UsbSupply> {
|
||||||
/// Uses the POWER peripheral to detect when power is available
|
/// Uses the POWER peripheral to detect when power is available
|
||||||
/// for USB. Unsuitable for usage with the nRF softdevice.
|
/// for USB. Unsuitable for usage with the nRF softdevice.
|
||||||
#[cfg(not(feature = "_nrf5340-app"))]
|
#[cfg(not(feature = "_nrf5340-app"))]
|
||||||
pub struct PowerUsb {}
|
pub struct PowerUsb {
|
||||||
|
_private: (),
|
||||||
|
}
|
||||||
|
|
||||||
/// Can be used to signal that power is available. Particularly suited for
|
/// Can be used to signal that power is available. Particularly suited for
|
||||||
/// use with the nRF softdevice.
|
/// use with the nRF softdevice.
|
||||||
|
@ -70,7 +72,7 @@ impl PowerUsb {
|
||||||
regs.intenset
|
regs.intenset
|
||||||
.write(|w| w.usbdetected().set().usbremoved().set().usbpwrrdy().set());
|
.write(|w| w.usbdetected().set().usbremoved().set().usbpwrrdy().set());
|
||||||
|
|
||||||
Self {}
|
Self { _private: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "_nrf5340-app"))]
|
#[cfg(not(feature = "_nrf5340-app"))]
|
||||||
|
|
Loading…
Reference in a new issue