aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2022-12-31 15:23:31 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2022-12-31 15:23:31 +0100
commitc08d47f914da5a0f9b505dee72c4a3a6969d878d (patch)
treea6b9d05b2ceab4ab1ff8b06baf761c69526e7c48
parentba3778a9d75a177ef51b99c3d641d399ffce4bd2 (diff)
downloadfl2k_ampliphase-c08d47f914da5a0f9b505dee72c4a3a6969d878d.tar.gz
fl2k_ampliphase-c08d47f914da5a0f9b505dee72c4a3a6969d878d.tar.bz2
fl2k_ampliphase-c08d47f914da5a0f9b505dee72c4a3a6969d878d.zip
Add more fl2k functions, callback still missing
-rw-r--r--src/fl2k.rs21
-rw-r--r--src/main.rs3
2 files changed, 20 insertions, 4 deletions
diff --git a/src/fl2k.rs b/src/fl2k.rs
index cfc2778..8bfc0ec 100644
--- a/src/fl2k.rs
+++ b/src/fl2k.rs
@@ -1,5 +1,5 @@
use std::ffi::c_int;
-use fl2k_ampliphase::{fl2k_dev_t, fl2k_get_device_count, fl2k_open, fl2k_close, fl2k_stop_tx};
+use fl2k_ampliphase::{fl2k_dev_t, fl2k_get_device_count, fl2k_open, fl2k_close, fl2k_stop_tx, fl2k_set_sample_rate, fl2k_get_sample_rate, fl2k_tx_cb_t, fl2k_start_tx};
#[derive(Debug)]
pub enum FL2KError {
@@ -41,12 +41,27 @@ impl FL2K {
}
}
+
+ pub fn set_sample_rate(&mut self, sample_rate : u32) -> Result<(), FL2KError> {
+ handle_return_value( unsafe { fl2k_set_sample_rate(self.device, sample_rate) })
+ }
+
+ pub fn get_sample_rate(&mut self) -> Result<u32, FL2KError> {
+ let sr = unsafe { fl2k_get_sample_rate(self.device) };
+ if sr == 0 { Err(FL2KError::Unknown(0)) } else { Ok(sr) }
+ }
+
+ pub fn start_tx(&mut self, callback : fl2k_tx_cb_t, buf_num: u32) -> Result<(), FL2KError> {
+ let r = unsafe { fl2k_start_tx(self.device, callback, std::ptr::null_mut(), 0) };
+ handle_return_value(r)
+ }
+
pub fn stop_tx(&self) -> Result<(), FL2KError> {
- handle_return_value( unsafe { fl2k_stop_tx(self.device) } )?;
- Ok(())
+ handle_return_value( unsafe { fl2k_stop_tx(self.device) } )
}
}
+
impl Drop for FL2K {
fn drop(&mut self) {
match unsafe {
diff --git a/src/main.rs b/src/main.rs
index a415e9f..c04740f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -331,7 +331,8 @@ fn main() {
// Main thread, output to file/device
match output {
Output::FL2K => {
- let fl2k = fl2k::FL2K::open(device_index);
+ let fl2k = fl2k::FL2K::open(device_index).expect("fl2k open");
+ // TODO fl2k.start_tx(|| {}, 0).expect("fl2k start_tx");
}
Output::Debug => {
let out_file = File::create("debug-out.i8").expect("create file");