mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-27 04:10:25 +00:00
Working draft of VREFBUF driver
This commit is contained in:
parent
f2be66a5f9
commit
556ae0106b
@ -81,7 +81,7 @@ futures-util = { version = "0.3.30", default-features = false }
|
||||
sdio-host = "0.9.0"
|
||||
critical-section = "1.1"
|
||||
#stm32-metapac = { version = "16" }
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-cad609e02a866422ffdbb8e07be26311cfdd07d9" }
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f0ef9106642ed869e7cfbf82d891d364c98ebb43" }
|
||||
|
||||
vcell = "0.1.3"
|
||||
nb = "1.0.0"
|
||||
@ -110,7 +110,7 @@ proc-macro2 = "1.0.36"
|
||||
quote = "1.0.15"
|
||||
|
||||
#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]}
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-cad609e02a866422ffdbb8e07be26311cfdd07d9", default-features = false, features = ["metadata"] }
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f0ef9106642ed869e7cfbf82d891d364c98ebb43", default-features = false, features = ["metadata"] }
|
||||
|
||||
[features]
|
||||
default = ["rt"]
|
||||
|
@ -125,6 +125,8 @@ pub mod uid;
|
||||
pub mod usart;
|
||||
#[cfg(any(usb, otg))]
|
||||
pub mod usb;
|
||||
#[cfg(vrefbuf)]
|
||||
pub mod vrefbuf;
|
||||
#[cfg(iwdg)]
|
||||
pub mod wdg;
|
||||
#[cfg(xspi)]
|
||||
|
69
embassy-stm32/src/vrefbuf/mod.rs
Normal file
69
embassy-stm32/src/vrefbuf/mod.rs
Normal file
@ -0,0 +1,69 @@
|
||||
//! Voltage Reference Buffer (VREFBUF)
|
||||
// use core::ptr::{read_volatile, write_volatile};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use embassy_hal_internal::PeripheralType;
|
||||
use stm32_metapac::vrefbuf::vals::*;
|
||||
|
||||
use crate::pac::RCC;
|
||||
use crate::Peri;
|
||||
|
||||
/// Voltage Reference (VREFBUF) driver.
|
||||
pub struct VoltageReferenceBuffer<'d, T: Instance> {
|
||||
vrefbuf: PhantomData<&'d mut T>,
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> {
|
||||
/// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode.
|
||||
///
|
||||
/// [Self] has to be started with [Self::new()].
|
||||
pub fn new(_instance: Peri<'d, T>, voltage_scale: Vrs, impedance_mode: Hiz) -> Self {
|
||||
#[cfg(rcc_wba)]
|
||||
{
|
||||
RCC.apb7enr().modify(|w| w.set_vrefen(true));
|
||||
}
|
||||
#[cfg(any(rcc_u5, rcc_h50, rcc_h5))]
|
||||
{
|
||||
RCC.apb3enr().modify(|w| w.set_vrefen(true));
|
||||
}
|
||||
#[cfg(any(rcc_h7rs, rcc_h7rm0433, rcc_h7ab, rcc_h7))]
|
||||
{
|
||||
RCC.apb4enr().modify(|w| w.set_vrefen(true));
|
||||
}
|
||||
let vrefbuf = T::regs();
|
||||
vrefbuf.csr().modify(|w| {
|
||||
w.set_hiz(impedance_mode);
|
||||
w.set_envr(true);
|
||||
w.set_vrs(voltage_scale);
|
||||
});
|
||||
while vrefbuf.csr().read().vrr() != false {
|
||||
// wait...
|
||||
}
|
||||
trace!(
|
||||
"Vrefbuf configured with voltage scale {} and impedance mode {}",
|
||||
voltage_scale,
|
||||
impedance_mode
|
||||
);
|
||||
VoltageReferenceBuffer { vrefbuf: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
trait SealedInstance {
|
||||
fn regs() -> crate::pac::vrefbuf::Vrefbuf;
|
||||
}
|
||||
|
||||
/// VREFBUF instance trait.
|
||||
#[allow(private_bounds)]
|
||||
pub trait Instance: SealedInstance + PeripheralType {}
|
||||
|
||||
foreach_peripheral!(
|
||||
(vrefbuf, $inst:ident) => {
|
||||
impl SealedInstance for crate::peripherals::$inst {
|
||||
fn regs() -> crate::pac::vrefbuf::Vrefbuf {
|
||||
crate::pac::$inst
|
||||
}
|
||||
}
|
||||
|
||||
impl Instance for crate::peripherals::$inst {}
|
||||
};
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user