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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Sample rate control for BladeRF1.
//!
//! Configures the Si5338 MultiSynth clocks to produce the desired sample rate.
//! The Si5338 supports arbitrary rational rates via `RationalRate`, allowing
//! precise frequency synthesis beyond integer sample rates.
use crate::bladerf1::board::RfLinkSession;
use crate::bladerf1::hardware::si5338::{self, Si5338};
use crate::channel::Channel;
use crate::error::Result;
use crate::maybe_future::Op;
use crate::range::Range;
use nusb::MaybeFuture;
impl RfLinkSession<'_> {
/// Sets the sample rate for the given channel in samples per second.
///
/// Programs the Si5338 MultiSynth clock to the desired integer rate.
/// Returns the actual rate applied, which may differ if rounding is needed.
///
/// Returns `Error::NotInitialized` if the board has not been initialized.
pub fn set_sample_rate(
&mut self,
channel: Channel,
rate: u32,
) -> impl MaybeFuture<Output = Result<u32>> {
Op::new(async move {
self.require_initialized().await?;
self.si().set_sample_rate(channel, rate).await
})
}
/// Returns the current sample rate for the given channel in samples per second.
///
/// Returns `Error::NotInitialized` if the board has not been initialized.
pub fn get_sample_rate(&mut self, channel: Channel) -> impl MaybeFuture<Output = Result<u32>> {
Op::new(async move {
self.require_initialized().await?;
self.si().get_sample_rate(channel).await
})
}
/// Returns the supported sample rate range in samples per second.
pub fn get_sample_rate_range() -> Range {
Si5338::get_sample_rate_range()
}
/// Sets the sample rate for the given channel using a rational number.
///
/// The `RationalRate` provides exact clock configuration via numerator,
/// denominator, and post-divider for the Si5338 MultiSynth, enabling
/// precise non-integer sample rates. The input rate is normalized and
/// updated with the actual applied values.
///
/// Returns the actual `RationalRate` applied by the hardware.
///
/// Returns `Error::NotInitialized` if the board has not been initialized.
pub fn set_rational_sample_rate(
&mut self,
channel: Channel,
rate: &mut si5338::RationalRate,
) -> impl MaybeFuture<Output = Result<si5338::RationalRate>> {
Op::new(async move {
self.require_initialized().await?;
self.si().set_rational_sample_rate(channel, rate).await
})
}
/// Returns the current rational sample rate configuration for the given channel.
///
/// Reads the Si5338 MultiSynth registers and returns the actual rate as
/// a `RationalRate` (numerator, denominator, post-divider).
///
/// Returns `Error::NotInitialized` if the board has not been initialized.
pub fn get_rational_sample_rate(
&mut self,
channel: Channel,
) -> impl MaybeFuture<Output = Result<si5338::RationalRate>> {
Op::new(async move {
self.require_initialized().await?;
self.si().get_rational_sample_rate(channel).await
})
}
}