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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
 * Calibration parameters, stored in the EEPROM device
 */
pub use crate::rp::rp_calib_params_t as Params;

/**
 * Returns calibration settings.
 *
 * These calibration settings are populated only once from EEPROM at `init()`.
 *
 * Each `settings()` call returns the same cached setting values.
 */
pub fn settings() -> Params
{
    unsafe {
        crate::rp::rp_GetCalibrationSettings()
    }
}

/**
 * Calibrates input channel offset. This input channel must be grounded to
 * calibrate properly.
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn calibrate_front_end_offset(channel: super::Channel, gain: super::pin::State) -> crate::Result<Params>
{
    let mut params = Default::default();

    match handle_unsafe!(
        crate::rp::rp_CalibrateFrontEndOffset(channel, gain, &mut params)
    ) {
        Ok(_) => Ok(params),
        Err(err) => Err(err),
    }
}

/**
 * Calibrates input channel low voltage scale. Jumpers must be set to LV.
 *
 * This input channel must be connected to stable positive source.
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn calibrate_front_end_scale_lv(channel: super::Channel, referential_voltage: f32) -> crate::Result<Params>
{
    let mut params = Default::default();

    match handle_unsafe!(
        crate::rp::rp_CalibrateFrontEndScaleLV(channel, referential_voltage, &mut params)
    ) {
        Ok(_) => Ok(params),
        Err(err) => Err(err),
    }
}

/**
 * Calibrates input channel high voltage scale. Jumpers must be set to HV.
 *
 * This input channel must be connected to stable positive source.
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn calibrate_front_end_scale_hv(channel: super::Channel, referential_voltage: f32) -> crate::Result<Params>
{
    let mut params = Default::default();

    match handle_unsafe!(
        crate::rp::rp_CalibrateFrontEndScaleHV(channel, referential_voltage, &mut params)
    ) {
        Ok(_) => Ok(params),
        Err(err) => Err(err),
    }
}

/**
 * Calibrates output channel offset.
 *
 * This input channel must be connected to calibrated input channel with came
 * number (CH1 to CH1 and CH2 to CH2).
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn calibrate_back_end_offset(channel: super::Channel) -> crate::Result<()>
{
    handle_unsafe!(
        crate::rp::rp_CalibrateBackEndOffset(channel)
    )
}

/**
 * Calibrates output channel voltage scale.
 *
 * This input channel must be connected to calibrated input channel with came
 * number (CH1 to CH1 and CH2 to CH2).
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn calibrate_back_end_scale(channel: super::Channel) -> crate::Result<()>
{
    handle_unsafe!(
        crate::rp::rp_CalibrateBackEndScale(channel)
    )
}

/**
 * Calibrates output channel.
 *
 * This input channel must be connected to calibrated input channel with came
 * number (CH1 to CH1 and CH2 to CH2).
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn calibrate_back_end(channel: super::Channel, params: *mut Params) -> crate::Result<()>
{
    handle_unsafe!(
        crate::rp::rp_CalibrateBackEnd(channel, params)
    )
}

/**
 * Set default calibration values.
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn reset() -> crate::Result<()>
{
    handle_unsafe!(
        crate::rp::rp_CalibrationReset()
    )
}

/**
 * Set saved calibration values in case of roll-back calibration.
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn set_cached_params() -> crate::Result<()>
{
    handle_unsafe!(
        crate::rp::rp_CalibrationSetCachedParams()
    )
}

/**
 * Write calibration values.
 *
 * Calibration data is written to EPROM and repopulated so that `settings()`
 * works properly.
 */
pub fn write_params(params: Params) -> crate::Result<()>
{
    handle_unsafe!(
        crate::rp::rp_CalibrationWriteParams(params)
    )
}