1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! DAC trim for VCTCXO frequency adjustment.
//!
//! The DAC161S055 is a 16-bit voltage-output DAC that generates the tuning
//! voltage for the on-board VCTCXO. Writing a new DAC code shifts the
//! VCTCXO frequency, allowing fine frequency correction. The value ranges
//! from 0x0000 (minimum voltage) to 0xFFFF (maximum voltage).
use crate::bladerf1::board::RfLinkSession;
use crate::error::Result;
use crate::maybe_future::Op;
use nusb::MaybeFuture;
impl RfLinkSession<'_> {
/// Writes a 16-bit trim value to the DAC161S055 to adjust the VCTCXO frequency.
///
/// The DAC output voltage shifts the VCTCXO oscillation frequency, enabling
/// fine frequency calibration. The value 0x0000 produces the minimum output
/// voltage and 0xFFFF produces the maximum.
///
/// Returns `Error::BoardState` if the board is not initialized.
pub fn set_dac_trim(&mut self, value: u16) -> impl MaybeFuture<Output = Result<()>> {
Op::new(async move {
self.require_initialized().await?;
self.dac().write(value).await
})
}
/// Returns the current 16-bit DAC trim value.
///
/// Reads the DAC161S055 output register to determine the active VCTCXO
/// tuning setting.
///
/// Returns `Error::BoardState` if the board is not initialized.
pub fn get_dac_trim(&mut self) -> impl MaybeFuture<Output = Result<u16>> {
Op::new(async move {
self.require_initialized().await?;
self.dac().read().await
})
}
}