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
//! 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;
use crate::channel::Channel;
use crate::error::Result;
use crate::range::{Range, RangeItem};
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) -> Result<u32> {
self.require_initialized()?;
self.si().set_sample_rate(channel, rate)
}
/// 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) -> Result<u32> {
self.require_initialized()?;
self.si().get_sample_rate(channel)
}
/// Returns the supported sample rate range in samples per second.
pub fn get_sample_rate_range() -> Range {
Range::new(vec![RangeItem::Step(
si5338::BLADERF_SAMPLERATE_MIN as f64,
si5338::BLADERF_SAMPLERATE_REC_MAX as f64,
1f64,
1f64,
)])
}
/// 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,
) -> Result<si5338::RationalRate> {
self.require_initialized()?;
self.si().set_rational_sample_rate(channel, rate)
}
/// 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) -> Result<si5338::RationalRate> {
self.require_initialized()?;
self.si().get_rational_sample_rate(channel)
}
}