Skip to content

Commit 74a0ddb

Browse files
committed
move sig-gen types into sig-gen module, add property struct for sig-gen-builtin-v2
1 parent 4cd5631 commit 74a0ddb

File tree

5 files changed

+223
-255
lines changed

5 files changed

+223
-255
lines changed

common/src/enums.rs

Lines changed: 0 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -214,181 +214,3 @@ impl From<PicoInfo> for i16 {
214214
num_traits::ToPrimitive::to_i16(&value).expect("Non-valid info type")
215215
}
216216
}
217-
218-
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
219-
pub enum PicoWaveType {
220-
Sine = 0,
221-
Square = 1,
222-
Triangle = 2,
223-
RampUp = 3,
224-
RampDown = 4,
225-
Sinc = 5,
226-
Gaussian = 6,
227-
HalfSine = 7,
228-
DCVoltage = 8,
229-
}
230-
231-
impl Default for PicoWaveType {
232-
fn default() -> Self {
233-
PicoWaveType::Sine
234-
}
235-
}
236-
237-
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
238-
pub enum PicoSweepType {
239-
Up = 0,
240-
Down = 1,
241-
UpDown = 2,
242-
DownUp = 3,
243-
}
244-
245-
impl Default for PicoSweepType {
246-
fn default() -> Self {
247-
PicoSweepType::Up
248-
}
249-
}
250-
251-
// Rust addition: encode the potential values of sweeps and shots, to avoid invalid states
252-
// like >0 & >0
253-
#[derive(Debug, Clone)]
254-
pub enum SweepShotCount {
255-
None,
256-
Sweeps(u32),
257-
Shots(u32),
258-
ContinuousSweeps,
259-
ContinuousShots,
260-
}
261-
262-
impl Default for SweepShotCount {
263-
fn default() -> Self {
264-
SweepShotCount::None
265-
}
266-
}
267-
268-
// TODO: this value is copied from sys/src/ps2000a - should we import it here?
269-
// should there be a crate for identical symbols?
270-
// should build.rs check for identity?
271-
const COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN: u32 = 4294967295;
272-
273-
impl SweepShotCount {
274-
pub fn to_sweeps(&self) -> u32 {
275-
match self {
276-
SweepShotCount::Sweeps(sweeps) => *sweeps,
277-
SweepShotCount::ContinuousSweeps => COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN,
278-
_ => 0,
279-
}
280-
}
281-
282-
pub fn to_shots(&self) -> u32 {
283-
match self {
284-
SweepShotCount::Shots(shots) => *shots,
285-
SweepShotCount::ContinuousShots => COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN,
286-
_ => 0,
287-
}
288-
}
289-
}
290-
291-
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
292-
pub enum PicoExtraOperations {
293-
/// <summary>
294-
/// Normal signal generator operation specified by wavetype.
295-
/// </summary>
296-
Off = 0,
297-
/// <summary>
298-
/// The signal generator produces white noise and ignores all settings except pkToPk and offsetVoltage.
299-
/// </summary>
300-
WhiteNoise = 1,
301-
/// <summary>
302-
/// produces a pseudorandom random binary sequence with a bit rate
303-
/// specified by the start and stop frequency.
304-
/// </summary>
305-
PRBS = 2, // Pseudo-Random Bit Stream
306-
}
307-
308-
impl Default for PicoExtraOperations {
309-
fn default() -> Self {
310-
PicoExtraOperations::Off
311-
}
312-
}
313-
314-
/// <summary>
315-
/// AWG index modes
316-
/// </summary>
317-
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
318-
pub enum PicoIndexMode {
319-
/// <summary>
320-
/// The generator outputs the raw contents of the buffer repeatedly .
321-
/// </summary>
322-
Single = 0,
323-
/// <summary>
324-
/// The generator outputs the contents of the buffer from beginning to end, and then does a second pass in the reverse
325-
/// direction through the buffer
326-
/// </summary>
327-
Dual = 1,
328-
/// <summary>
329-
/// This is similiar to the Dual but passes through the buffer four time inverting, and inverting reversed
330-
/// </summary>
331-
Quad = 2,
332-
}
333-
334-
/// <summary>
335-
/// The type of trigger that will be applied to the signal generator
336-
/// </summary>
337-
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
338-
pub enum PicoSigGenTrigType {
339-
/// <summary>
340-
/// Trigger on rising edge
341-
/// </summary>
342-
Rising = 0,
343-
/// <summary>
344-
/// Trigger on falling edge
345-
/// </summary>
346-
Falling = 1,
347-
/// <summary>
348-
/// Run while trigger is high
349-
/// </summary>
350-
GateHigh = 2,
351-
/// <summary>
352-
/// Run while trigger is low
353-
/// </summary>
354-
GateLow = 3,
355-
}
356-
357-
impl Default for PicoSigGenTrigType {
358-
fn default() -> Self {
359-
PicoSigGenTrigType::Rising
360-
}
361-
}
362-
363-
/// <summary>
364-
/// The source that will trigger the signal generator
365-
/// </summary>
366-
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive, PartialEq)]
367-
pub enum PicoSigGenTrigSource {
368-
/// <summary>
369-
/// Run without waiting for trigger
370-
/// </summary>
371-
None = 0,
372-
/// <summary>
373-
/// Use scope trigger
374-
/// </summary
375-
ScopeTrig = 1,
376-
/// <summary>
377-
/// Use AUXIO input
378-
/// </summary>
379-
AuxIn = 2,
380-
/// <summary>
381-
/// Use external input
382-
/// </summary>
383-
ExtIn = 3,
384-
/// <summary>
385-
/// Wait for software trigger
386-
/// </summary>
387-
SoftTrig = 4,
388-
}
389-
390-
impl Default for PicoSigGenTrigSource {
391-
fn default() -> Self {
392-
PicoSigGenTrigSource::None
393-
}
394-
}

common/src/sig_gen.rs

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,204 @@
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+
136
#[derive(Debug, Clone)]
237
pub struct SigGenArbitraryMinMaxValues {
338
pub min_value: i16,
439
pub max_value: i16,
540
pub min_size: u32,
641
pub max_size: u32,
742
}
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

Comments
 (0)