|
| 1 | +use num_derive::{ToPrimitive, FromPrimitive}; |
| 2 | + |
| 3 | +#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)] |
| 4 | +pub enum PicoWaveType { |
| 5 | + Sine = 0, |
| 6 | + Square = 1, |
| 7 | + Triangle = 2, |
| 8 | + RampUp = 3, |
| 9 | + RampDown = 4, |
| 10 | + Sinc = 5, |
| 11 | + Gaussian = 6, |
| 12 | + HalfSine = 7, |
| 13 | + DCVoltage = 8, |
| 14 | +} |
| 15 | + |
| 16 | +impl Default for PicoWaveType { |
| 17 | + fn default() -> Self { |
| 18 | + PicoWaveType::Sine |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)] |
| 23 | +pub enum PicoSweepType { |
| 24 | + Up = 0, |
| 25 | + Down = 1, |
| 26 | + UpDown = 2, |
| 27 | + DownUp = 3, |
| 28 | +} |
| 29 | + |
| 30 | +impl Default for PicoSweepType { |
| 31 | + fn default() -> Self { |
| 32 | + PicoSweepType::Up |
| 33 | + } |
| 34 | +} |
| 35 | + |
1 | 36 | #[derive(Debug, Clone)]
|
2 | 37 | pub struct SigGenArbitraryMinMaxValues {
|
3 | 38 | pub min_value: i16,
|
4 | 39 | pub max_value: i16,
|
5 | 40 | pub min_size: u32,
|
6 | 41 | pub max_size: u32,
|
7 | 42 | }
|
| 43 | + |
| 44 | +// Rust addition: encode the potential values of sweeps and shots, to avoid invalid states |
| 45 | +// like >0 & >0 |
| 46 | +#[derive(Debug, Clone)] |
| 47 | +pub enum SweepShotCount { |
| 48 | + None, |
| 49 | + Sweeps(u32), |
| 50 | + Shots(u32), |
| 51 | + ContinuousSweeps, |
| 52 | + ContinuousShots, |
| 53 | +} |
| 54 | + |
| 55 | +impl Default for SweepShotCount { |
| 56 | + fn default() -> Self { |
| 57 | + SweepShotCount::None |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +// TODO: this value is copied from sys/src/ps2000a - should we import it here? |
| 62 | +// should there be a crate for identical symbols? |
| 63 | +// should build.rs check for identity? |
| 64 | +const COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN: u32 = 4294967295; |
| 65 | + |
| 66 | +impl SweepShotCount { |
| 67 | + pub fn to_sweeps(&self) -> u32 { |
| 68 | + match self { |
| 69 | + SweepShotCount::Sweeps(sweeps) => *sweeps, |
| 70 | + SweepShotCount::ContinuousSweeps => COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN, |
| 71 | + _ => 0, |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + pub fn to_shots(&self) -> u32 { |
| 76 | + match self { |
| 77 | + SweepShotCount::Shots(shots) => *shots, |
| 78 | + SweepShotCount::ContinuousShots => COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN, |
| 79 | + _ => 0, |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)] |
| 85 | +pub enum PicoExtraOperations { |
| 86 | + /// <summary> |
| 87 | + /// Normal signal generator operation specified by wavetype. |
| 88 | + /// </summary> |
| 89 | + Off = 0, |
| 90 | + /// <summary> |
| 91 | + /// The signal generator produces white noise and ignores all settings except pkToPk and offsetVoltage. |
| 92 | + /// </summary> |
| 93 | + WhiteNoise = 1, |
| 94 | + /// <summary> |
| 95 | + /// produces a pseudorandom random binary sequence with a bit rate |
| 96 | + /// specified by the start and stop frequency. |
| 97 | + /// </summary> |
| 98 | + PRBS = 2, // Pseudo-Random Bit Stream |
| 99 | +} |
| 100 | + |
| 101 | +impl Default for PicoExtraOperations { |
| 102 | + fn default() -> Self { |
| 103 | + PicoExtraOperations::Off |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +/// <summary> |
| 108 | +/// AWG index modes |
| 109 | +/// </summary> |
| 110 | +#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)] |
| 111 | +pub enum PicoIndexMode { |
| 112 | + /// <summary> |
| 113 | + /// The generator outputs the raw contents of the buffer repeatedly . |
| 114 | + /// </summary> |
| 115 | + Single = 0, |
| 116 | + /// <summary> |
| 117 | + /// The generator outputs the contents of the buffer from beginning to end, and then does a second pass in the reverse |
| 118 | + /// direction through the buffer |
| 119 | + /// </summary> |
| 120 | + Dual = 1, |
| 121 | + /// <summary> |
| 122 | + /// This is similiar to the Dual but passes through the buffer four time inverting, and inverting reversed |
| 123 | + /// </summary> |
| 124 | + Quad = 2, |
| 125 | +} |
| 126 | + |
| 127 | +/// <summary> |
| 128 | +/// The type of trigger that will be applied to the signal generator |
| 129 | +/// </summary> |
| 130 | +#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)] |
| 131 | +pub enum PicoSigGenTrigType { |
| 132 | + /// <summary> |
| 133 | + /// Trigger on rising edge |
| 134 | + /// </summary> |
| 135 | + Rising = 0, |
| 136 | + /// <summary> |
| 137 | + /// Trigger on falling edge |
| 138 | + /// </summary> |
| 139 | + Falling = 1, |
| 140 | + /// <summary> |
| 141 | + /// Run while trigger is high |
| 142 | + /// </summary> |
| 143 | + GateHigh = 2, |
| 144 | + /// <summary> |
| 145 | + /// Run while trigger is low |
| 146 | + /// </summary> |
| 147 | + GateLow = 3, |
| 148 | +} |
| 149 | + |
| 150 | +impl Default for PicoSigGenTrigType { |
| 151 | + fn default() -> Self { |
| 152 | + PicoSigGenTrigType::Rising |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +/// <summary> |
| 157 | +/// The source that will trigger the signal generator |
| 158 | +/// </summary> |
| 159 | +#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive, PartialEq)] |
| 160 | +pub enum PicoSigGenTrigSource { |
| 161 | + /// <summary> |
| 162 | + /// Run without waiting for trigger |
| 163 | + /// </summary> |
| 164 | + None = 0, |
| 165 | + /// <summary> |
| 166 | + /// Use scope trigger |
| 167 | + /// </summary |
| 168 | + ScopeTrig = 1, |
| 169 | + /// <summary> |
| 170 | + /// Use AUXIO input |
| 171 | + /// </summary> |
| 172 | + AuxIn = 2, |
| 173 | + /// <summary> |
| 174 | + /// Use external input |
| 175 | + /// </summary> |
| 176 | + ExtIn = 3, |
| 177 | + /// <summary> |
| 178 | + /// Wait for software trigger |
| 179 | + /// </summary> |
| 180 | + SoftTrig = 4, |
| 181 | +} |
| 182 | + |
| 183 | +impl Default for PicoSigGenTrigSource { |
| 184 | + fn default() -> Self { |
| 185 | + PicoSigGenTrigSource::None |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | +#[derive(Default, Debug)] |
| 190 | +pub struct SetSigGenBuiltInV2Properties { |
| 191 | + pub offset_voltage: i32, /* microvolts */ |
| 192 | + pub pk_to_pk: u32, /* microvolts */ |
| 193 | + pub wave_type: PicoWaveType, |
| 194 | + pub start_frequency: f64, /* Hertz */ |
| 195 | + pub stop_frequency: f64, /* Hertz */ |
| 196 | + pub increment: f64, /* delta frequency jumps in Hertz */ |
| 197 | + pub dwell_time: f64, /* amount to stay at each frequency in seconds */ |
| 198 | + pub sweep_type: PicoSweepType, |
| 199 | + pub extra_operations: PicoExtraOperations, |
| 200 | + pub sweeps_shots: SweepShotCount, |
| 201 | + pub trig_type: PicoSigGenTrigType, |
| 202 | + pub trig_source: PicoSigGenTrigSource, |
| 203 | + pub ext_in_threshold: i16, |
| 204 | +} |
0 commit comments