Merge pull request #2013 from xoviat/opamp
stm32: update metapac and fix opamp ch
This commit is contained in:
commit
42176b1a3a
@ -59,7 +59,7 @@ sdio-host = "0.5.0"
|
|||||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
||||||
critical-section = "1.1"
|
critical-section = "1.1"
|
||||||
atomic-polyfill = "1.0.1"
|
atomic-polyfill = "1.0.1"
|
||||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-06d13dfd245cc9bf86fd88c35b401bdb84c079c4" }
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-172c5ea18824d7cd38decb210e4af441fa3816cb" }
|
||||||
vcell = "0.1.3"
|
vcell = "0.1.3"
|
||||||
bxcan = "0.7.0"
|
bxcan = "0.7.0"
|
||||||
nb = "1.0.0"
|
nb = "1.0.0"
|
||||||
@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] }
|
|||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
proc-macro2 = "1.0.36"
|
proc-macro2 = "1.0.36"
|
||||||
quote = "1.0.15"
|
quote = "1.0.15"
|
||||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-06d13dfd245cc9bf86fd88c35b401bdb84c079c4", default-features = false, features = ["metadata"]}
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-172c5ea18824d7cd38decb210e4af441fa3816cb", default-features = false, features = ["metadata"]}
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -4,7 +4,15 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
|
|||||||
|
|
||||||
use crate::Peripheral;
|
use crate::Peripheral;
|
||||||
|
|
||||||
#[cfg(opamp_f3)]
|
#[derive(Clone, Copy)]
|
||||||
|
pub enum OpAmpGain {
|
||||||
|
Mul1,
|
||||||
|
Mul2,
|
||||||
|
Mul4,
|
||||||
|
Mul8,
|
||||||
|
Mul16,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct OpAmpOutput<'d, 'p, T: Instance, P: NonInvertingPin<T>> {
|
pub struct OpAmpOutput<'d, 'p, T: Instance, P: NonInvertingPin<T>> {
|
||||||
_inner: &'d OpAmp<'d, T>,
|
_inner: &'d OpAmp<'d, T>,
|
||||||
_input: &'p mut P,
|
_input: &'p mut P,
|
||||||
@ -35,14 +43,32 @@ impl<'d, T: Instance> OpAmp<'d, T> {
|
|||||||
Self { _inner: opamp }
|
Self { _inner: opamp }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(opamp_f3)]
|
pub fn buffer_for<'a, 'b, P>(&'a mut self, pin: &'b mut P, gain: OpAmpGain) -> OpAmpOutput<'a, 'b, T, P>
|
||||||
pub fn buffer_for<'a, 'b, P>(&'a mut self, pin: &'b mut P) -> OpAmpOutput<'a, 'b, T, P>
|
|
||||||
where
|
where
|
||||||
P: NonInvertingPin<T>,
|
P: NonInvertingPin<T>,
|
||||||
{
|
{
|
||||||
|
let (vm_sel, pga_gain) = match gain {
|
||||||
|
OpAmpGain::Mul1 => (0b11, 0b00),
|
||||||
|
OpAmpGain::Mul2 => (0b10, 0b00),
|
||||||
|
OpAmpGain::Mul4 => (0b10, 0b01),
|
||||||
|
OpAmpGain::Mul8 => (0b10, 0b10),
|
||||||
|
OpAmpGain::Mul16 => (0b10, 0b11),
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(opamp_f3)]
|
#[cfg(opamp_f3)]
|
||||||
T::regs().opampcsr().modify(|w| {
|
T::regs().opampcsr().modify(|w| {
|
||||||
w.set_vp_sel(pin.channel());
|
w.set_vp_sel(pin.channel());
|
||||||
|
w.set_vm_sel(vm_sel);
|
||||||
|
w.set_pga_gain(pga_gain);
|
||||||
|
});
|
||||||
|
|
||||||
|
#[cfg(opamp_g4)]
|
||||||
|
T::regs().opamp_csr().modify(|w| {
|
||||||
|
use crate::pac::opamp::vals::*;
|
||||||
|
|
||||||
|
w.set_vp_sel(OpampCsrVpSel::from_bits(pin.channel()));
|
||||||
|
w.set_vm_sel(OpampCsrVmSel::from_bits(vm_sel));
|
||||||
|
w.set_pga_gain(OpampCsrPgaGain::from_bits(pga_gain));
|
||||||
});
|
});
|
||||||
|
|
||||||
OpAmpOutput {
|
OpAmpOutput {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use defmt::info;
|
use defmt::info;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::adc::{Adc, SampleTime};
|
use embassy_stm32::adc::{Adc, SampleTime};
|
||||||
use embassy_stm32::opamp::OpAmp;
|
use embassy_stm32::opamp::{OpAmp, OpAmpGain};
|
||||||
use embassy_stm32::peripherals::ADC2;
|
use embassy_stm32::peripherals::ADC2;
|
||||||
use embassy_stm32::rcc::AdcClockSource;
|
use embassy_stm32::rcc::AdcClockSource;
|
||||||
use embassy_stm32::time::mhz;
|
use embassy_stm32::time::mhz;
|
||||||
@ -39,7 +39,7 @@ async fn main(_spawner: Spawner) -> ! {
|
|||||||
|
|
||||||
let mut vrefint = adc.enable_vref(&mut Delay);
|
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||||
let mut temperature = adc.enable_temperature();
|
let mut temperature = adc.enable_temperature();
|
||||||
let mut buffer = opamp.buffer_for(&mut p.PA7);
|
let mut buffer = opamp.buffer_for(&mut p.PA7, OpAmpGain::Mul1);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let vref = adc.read(&mut vrefint).await;
|
let vref = adc.read(&mut vrefint).await;
|
||||||
|
Loading…
Reference in New Issue
Block a user