tof_control/rb_control/
rb_mode.rs

1use crate::helper::rb_type::RBError;
2use crate::rb_control::{rb_dac, rb_input, rb_gpioe};
3
4pub fn select_noi_mode() -> Result<(), RBError> {
5    rb_dac::dac_noi_mode()?;
6    rb_input::disable_rf_input()?;
7
8    Ok(())
9}
10
11pub fn select_vcal_mode() -> Result<(), RBError> {
12    rb_dac::dac_vcal_mode()?;
13    rb_input::disable_rf_input()?;
14
15    Ok(())
16}
17
18pub fn select_tcal_mode() -> Result<(), RBError> {
19    rb_dac::dac_tcal_mode()?;
20    rb_input::enable_tca_input()?;
21
22    Ok(())
23}
24
25pub fn select_sma_mode() -> Result<(), RBError> {
26    rb_dac::dac_sma_mode()?;
27    rb_input::enable_sma_input()?;
28
29    Ok(())
30}
31
32pub fn read_input_mode() -> Result<String, RBError> {
33    
34    let mut rf_input_ports: [u8; 9] = Default::default();
35    for i in 0..9 {
36        let rf_input_port = rb_gpioe::read_rf_input_port(i+1 as u8)?;
37        rf_input_ports[i as usize] = rf_input_port;
38    }
39
40    let input_mode: &str;
41    match rf_input_ports {
42        [0, 0, 0, 0, 0, 0, 0, 0, 0] => {
43            input_mode = "SMA";
44        }
45        [1, 1, 1, 1, 1, 1, 1, 1, 1] => {
46            input_mode = "TCAL";
47        }
48        [3, 3, 3, 3, 3, 3, 3, 3, 3] => {
49            input_mode = "NOI";
50        }
51        _ => {
52            input_mode = "Input Mode Error";
53        }
54    }
55
56    Ok(input_mode.to_string())
57}