Rename the ADC constructor to new, make it infallible (#1133)
* Rename the ADC constructor to `new`, make it infallible * Update `CHANGELOG.md`
This commit is contained in:
parent
f36e2e72d6
commit
a586cb311e
@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- `ADC` and `DAC` drivers now take virtual peripherals in their constructors, instead of splitting `APB_SARADC`/`SENS` (#1100)
|
- `ADC` and `DAC` drivers now take virtual peripherals in their constructors, instead of splitting `APB_SARADC`/`SENS` (#1100)
|
||||||
- The `DAC` driver's constructor is now `new` instead of `dac`, to be more consistent with other APIs (#1100)
|
- The `DAC` driver's constructor is now `new` instead of `dac`, to be more consistent with other APIs (#1100)
|
||||||
- The DMA peripheral is now called `Dma` for devices with both PDMA and GDMA controllers (#1125)
|
- The DMA peripheral is now called `Dma` for devices with both PDMA and GDMA controllers (#1125)
|
||||||
|
- The `ADC` driver's constructor is now `new` instead of `adc`, to be more consistent with other APIs (#1133)
|
||||||
|
|
||||||
## [0.15.0] - 2024-01-19
|
## [0.15.0] - 2024-01-19
|
||||||
|
|
||||||
|
|||||||
@ -256,10 +256,10 @@ impl<'d, ADCI> ADC<'d, ADCI>
|
|||||||
where
|
where
|
||||||
ADCI: RegisterAccess,
|
ADCI: RegisterAccess,
|
||||||
{
|
{
|
||||||
pub fn adc(
|
pub fn new(
|
||||||
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
|
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
|
||||||
config: AdcConfig<ADCI>,
|
config: AdcConfig<ADCI>,
|
||||||
) -> Result<Self, ()> {
|
) -> Self {
|
||||||
let sensors = unsafe { &*SENS::ptr() };
|
let sensors = unsafe { &*SENS::ptr() };
|
||||||
|
|
||||||
// Set reading and sampling resolution
|
// Set reading and sampling resolution
|
||||||
@ -322,13 +322,11 @@ where
|
|||||||
.sar_read_ctrl2()
|
.sar_read_ctrl2()
|
||||||
.modify(|_, w| w.sar2_data_inv().set_bit());
|
.modify(|_, w| w.sar2_data_inv().set_bit());
|
||||||
|
|
||||||
let adc = ADC {
|
ADC {
|
||||||
_adc: adc_instance.into_ref(),
|
_adc: adc_instance.into_ref(),
|
||||||
attenuations: config.attenuations,
|
attenuations: config.attenuations,
|
||||||
active_channel: None,
|
active_channel: None,
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(adc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! let mut adc1_config = AdcConfig::new();
|
//! let mut adc1_config = AdcConfig::new();
|
||||||
//! let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
//! let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
//! let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
//! let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
||||||
//!
|
//!
|
||||||
//! let mut delay = Delay::new(&clocks);
|
//! let mut delay = Delay::new(&clocks);
|
||||||
|
|||||||
@ -490,14 +490,13 @@ impl<'d, ADCI> ADC<'d, ADCI>
|
|||||||
where
|
where
|
||||||
ADCI: RegisterAccess + 'd,
|
ADCI: RegisterAccess + 'd,
|
||||||
{
|
{
|
||||||
pub fn adc(
|
pub fn new(
|
||||||
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
|
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
|
||||||
config: AdcConfig<ADCI>,
|
config: AdcConfig<ADCI>,
|
||||||
) -> Result<Self, ()> {
|
) -> Self {
|
||||||
PeripheralClockControl::enable(Peripheral::ApbSarAdc);
|
PeripheralClockControl::enable(Peripheral::ApbSarAdc);
|
||||||
|
|
||||||
let sar_adc = unsafe { &*APB_SARADC::PTR };
|
unsafe { &*APB_SARADC::PTR }.ctrl().modify(|_, w| unsafe {
|
||||||
sar_adc.ctrl().modify(|_, w| unsafe {
|
|
||||||
w.saradc_start_force()
|
w.saradc_start_force()
|
||||||
.set_bit()
|
.set_bit()
|
||||||
.saradc_start()
|
.saradc_start()
|
||||||
@ -507,13 +506,12 @@ where
|
|||||||
.saradc_xpd_sar_force()
|
.saradc_xpd_sar_force()
|
||||||
.bits(0b11)
|
.bits(0b11)
|
||||||
});
|
});
|
||||||
let adc = ADC {
|
|
||||||
|
ADC {
|
||||||
_adc: adc_instance.into_ref(),
|
_adc: adc_instance.into_ref(),
|
||||||
attenuations: config.attenuations,
|
attenuations: config.attenuations,
|
||||||
active_channel: None,
|
active_channel: None,
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(adc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -524,10 +524,10 @@ impl<'d, ADCI> ADC<'d, ADCI>
|
|||||||
where
|
where
|
||||||
ADCI: RegisterAccess,
|
ADCI: RegisterAccess,
|
||||||
{
|
{
|
||||||
pub fn adc(
|
pub fn new(
|
||||||
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
|
adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd,
|
||||||
config: AdcConfig<ADCI>,
|
config: AdcConfig<ADCI>,
|
||||||
) -> Result<Self, ()> {
|
) -> Self {
|
||||||
let sensors = unsafe { &*SENS::ptr() };
|
let sensors = unsafe { &*SENS::ptr() };
|
||||||
|
|
||||||
// Set attenuation for pins
|
// Set attenuation for pins
|
||||||
@ -592,13 +592,11 @@ where
|
|||||||
.sar_amp_ctrl2()
|
.sar_amp_ctrl2()
|
||||||
.modify(|_, w| unsafe { w.sar_amp_wait3().bits(1) });
|
.modify(|_, w| unsafe { w.sar_amp_wait3().bits(1) });
|
||||||
|
|
||||||
let adc = ADC {
|
ADC {
|
||||||
_adc: adc_instance.into_ref(),
|
_adc: adc_instance.into_ref(),
|
||||||
attenuations: config.attenuations,
|
attenuations: config.attenuations,
|
||||||
active_channel: None,
|
active_channel: None,
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(adc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ fn main() -> ! {
|
|||||||
let mut adc2_config = AdcConfig::new();
|
let mut adc2_config = AdcConfig::new();
|
||||||
let mut pin25 =
|
let mut pin25 =
|
||||||
adc2_config.enable_pin(io.pins.gpio25.into_analog(), Attenuation::Attenuation11dB);
|
adc2_config.enable_pin(io.pins.gpio25.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc2 = ADC::<ADC2>::adc(peripherals.ADC2, adc2_config).unwrap();
|
let mut adc2 = ADC::<ADC2>::new(peripherals.ADC2, adc2_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ fn main() -> ! {
|
|||||||
// Create ADC instances
|
// Create ADC instances
|
||||||
let mut adc1_config = AdcConfig::new();
|
let mut adc1_config = AdcConfig::new();
|
||||||
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ fn main() -> ! {
|
|||||||
io.pins.gpio2.into_analog(),
|
io.pins.gpio2.into_analog(),
|
||||||
Attenuation::Attenuation11dB,
|
Attenuation::Attenuation11dB,
|
||||||
);
|
);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ fn main() -> ! {
|
|||||||
// Create ADC instances
|
// Create ADC instances
|
||||||
let mut adc1_config = AdcConfig::new();
|
let mut adc1_config = AdcConfig::new();
|
||||||
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ fn main() -> ! {
|
|||||||
io.pins.gpio2.into_analog(),
|
io.pins.gpio2.into_analog(),
|
||||||
Attenuation::Attenuation11dB,
|
Attenuation::Attenuation11dB,
|
||||||
);
|
);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ fn main() -> ! {
|
|||||||
// Create ADC instances
|
// Create ADC instances
|
||||||
let mut adc1_config = AdcConfig::new();
|
let mut adc1_config = AdcConfig::new();
|
||||||
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ fn main() -> ! {
|
|||||||
io.pins.gpio2.into_analog(),
|
io.pins.gpio2.into_analog(),
|
||||||
Attenuation::Attenuation11dB,
|
Attenuation::Attenuation11dB,
|
||||||
);
|
);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ fn main() -> ! {
|
|||||||
// Create ADC instances
|
// Create ADC instances
|
||||||
let mut adc1_config = AdcConfig::new();
|
let mut adc1_config = AdcConfig::new();
|
||||||
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ fn main() -> ! {
|
|||||||
let mut adc1_config = AdcConfig::new();
|
let mut adc1_config = AdcConfig::new();
|
||||||
let mut pin3 =
|
let mut pin3 =
|
||||||
adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB);
|
adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ fn main() -> ! {
|
|||||||
let mut adc1_config = AdcConfig::new();
|
let mut adc1_config = AdcConfig::new();
|
||||||
let mut pin3 =
|
let mut pin3 =
|
||||||
adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB);
|
adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ fn main() -> ! {
|
|||||||
io.pins.gpio3.into_analog(),
|
io.pins.gpio3.into_analog(),
|
||||||
Attenuation::Attenuation11dB,
|
Attenuation::Attenuation11dB,
|
||||||
);
|
);
|
||||||
let mut adc1 = ADC::<ADC1>::adc(peripherals.ADC1, adc1_config).unwrap();
|
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
|
||||||
|
|
||||||
let mut delay = Delay::new(&clocks);
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user