Skip to content

Commit 8f0011c

Browse files
Teo PerisanuTeo Perisanu
authored andcommitted
M2kHardwareTrigger: Add trigger out for digital interface.
Add the digital device. Implement the functionalities based on the generic definitions. Signed-off-by: Teo Perisanu <[email protected]>
1 parent 6cf468e commit 8f0011c

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

include/libm2k/m2khardwaretrigger.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,48 @@ class LIBM2K_API M2kHardwareTrigger
404404
* @note Only available from firmware v0.24.
405405
*/
406406
virtual M2K_TRIGGER_SOURCE_DIGITAL getDigitalSource() const;
407+
408+
409+
/**
410+
* @brief Select which interface triggers the DigitalOut.
411+
* @param src: of type M2K_TRIGGER_OUT_SOURCE:\n
412+
* SRC_OUT_NONE - no trigger events
413+
* SRC_OUT_TRIGGER_IN - trigger events on the TI(trigger in) pin trigger the DigitalOut interface;\n
414+
* SRC_OUT_TRIGGER_OUT - trigger events on the TO(trigger out) pin trigger the DigitalOut interface;\n
415+
* SRC_OUT_ANALOG_IN - trigger events on the AnalogIn interface trigger the DigitalOut interface;\n
416+
* SRC_OUT_DIGITAL_IN - trigger events on the DigitalIn interface trigger the DigitalOut interface;\n
417+
* @note Only available from firmware v0.26.
418+
*/
419+
virtual void setDigitalOutSource(M2K_TRIGGER_OUT_SOURCE src) = 0;
420+
421+
422+
/**
423+
* @brief Retrieve the source of the DigitalOut interface trigger event.
424+
* @return M2K_TRIGGER_OUT_SOURCE :\n
425+
* SRC_OUT_NONE;\n
426+
* SRC_OUT_TRIGGER_IN;\n
427+
* SRC_OUT_TRIGGER_OUT;\n
428+
* SRC_OUT_ANALOG_IN;\n
429+
* SRC_OUT_DIGITAL_IN;\n
430+
* @note Only available from firmware v0.26.
431+
*/
432+
virtual M2K_TRIGGER_OUT_SOURCE getDigitalOutSource() const = 0;
433+
434+
435+
/**
436+
* @brief Set the trigger condition for the TI/TO in order to trigger the DigitalOut interface
437+
* @param cond the specific trigger condition
438+
*
439+
* @note to have any effect the digital out source must be set to TI or TO
440+
*/
441+
virtual void setDigitalOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) = 0;
442+
443+
444+
/**
445+
* @brief Get the trigger condition of the TI/TO pins that triggers the DigitalOut interface
446+
* @return the trigger condition
447+
*/
448+
virtual M2K_TRIGGER_CONDITION_DIGITAL getDigitalOutCondition() const = 0;
407449
};
408450
}
409451

src/m2khardwaretrigger_impl.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,3 +570,27 @@ void M2kHardwareTriggerImpl::setCalibParameters(unsigned int chnIdx, double scal
570570
m_scaling[chnIdx] = scaling;
571571
m_offset[chnIdx] = offset;
572572
}
573+
574+
void M2kHardwareTriggerImpl::setDigitalOutSource(M2K_TRIGGER_OUT_SOURCE src)
575+
{
576+
UNUSED(src);
577+
THROW_M2K_EXCEPTION("Invalid firmware version. Minimum required version: v0.26", libm2k::EXC_INVALID_FIRMWARE_VERSION);
578+
}
579+
580+
M2K_TRIGGER_OUT_SOURCE M2kHardwareTriggerImpl::getDigitalOutSource() const
581+
{
582+
THROW_M2K_EXCEPTION("Invalid firmware version. Minimum required version: v0.26", libm2k::EXC_INVALID_FIRMWARE_VERSION);
583+
return SRC_OUT_NONE;
584+
}
585+
586+
void M2kHardwareTriggerImpl::setDigitalOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond)
587+
{
588+
UNUSED(cond);
589+
THROW_M2K_EXCEPTION("Invalid firmware version. Minimum required version: v0.26", libm2k::EXC_INVALID_FIRMWARE_VERSION);
590+
}
591+
592+
M2K_TRIGGER_CONDITION_DIGITAL M2kHardwareTriggerImpl::getDigitalOutCondition() const
593+
{
594+
THROW_M2K_EXCEPTION("Invalid firmware version. Minimum required version: v0.26", libm2k::EXC_INVALID_FIRMWARE_VERSION);
595+
return NO_TRIGGER_DIGITAL;
596+
}

src/m2khardwaretrigger_impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class M2kHardwareTriggerImpl : public M2kHardwareTrigger
107107
M2K_TRIGGER_CONDITION_DIGITAL getDigitalCondition(DIO_CHANNEL chn);
108108
void setDigitalCondition(DIO_CHANNEL chn, M2K_TRIGGER_CONDITION_DIGITAL cond);
109109

110+
void setDigitalOutSource(M2K_TRIGGER_OUT_SOURCE src) override;
111+
M2K_TRIGGER_OUT_SOURCE getDigitalOutSource() const override;
112+
void setDigitalOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) override;
113+
M2K_TRIGGER_CONDITION_DIGITAL getDigitalOutCondition() const override;
110114
protected:
111115
struct iio_device *m_trigger_device;
112116
std::vector<Channel *> m_analog_channels;

src/m2khardwaretrigger_v0.26_impl.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,47 @@ std::vector<std::string> libm2k::M2kHardwareTriggerV026Impl::m_trigger_cond = {
4848
libm2k::M2kHardwareTriggerV026Impl::M2kHardwareTriggerV026Impl(struct iio_context *ctx, bool init) :
4949
M2kHardwareTriggerV024Impl(ctx)
5050
{
51+
bool hasTriggerSource;
52+
bool hasTriggerCondition;
53+
m_digital_trigger_device = make_shared<libm2k::utils::DeviceOut>(ctx, "m2k-logic-analyzer-tx");
54+
if (!m_digital_trigger_device) {
55+
THROW_M2K_EXCEPTION("No digital TX trigger available", libm2k::EXC_RUNTIME_ERROR);
56+
}
57+
hasTriggerSource = m_digital_trigger_device->hasGlobalAttribute(m_source_attr);
58+
hasTriggerCondition = m_digital_trigger_device->hasGlobalAttribute(m_condition_attr);
59+
if (!hasTriggerSource || !hasTriggerCondition) {
60+
THROW_M2K_EXCEPTION("Analog TX trigger is not available", libm2k::EXC_RUNTIME_ERROR);
61+
}
62+
5163
if (init) {
5264
reset();
5365
}
5466
}
5567

56-
void libm2k::M2kHardwareTriggerV026Impl::reset()
57-
{
68+
void libm2k::M2kHardwareTriggerV026Impl::reset() {
5869
M2kHardwareTriggerV024Impl::reset();
70+
setDigitalOutSource(SRC_OUT_NONE);
71+
setDigitalOutCondition(NO_TRIGGER_DIGITAL);
72+
}
73+
74+
void libm2k::M2kHardwareTriggerV026Impl::setDigitalOutSource(libm2k::M2K_TRIGGER_OUT_SOURCE src)
75+
{
76+
setTriggerOutSource(src, m_digital_trigger_device);
77+
}
78+
79+
libm2k::M2K_TRIGGER_OUT_SOURCE libm2k::M2kHardwareTriggerV026Impl::getDigitalOutSource() const
80+
{
81+
return getTriggerOutSource(m_digital_trigger_device);
82+
}
83+
84+
void libm2k::M2kHardwareTriggerV026Impl::setDigitalOutCondition(libm2k::M2K_TRIGGER_CONDITION_DIGITAL cond)
85+
{
86+
setTriggerOutCondition(cond, m_digital_trigger_device);
87+
}
88+
89+
libm2k::M2K_TRIGGER_CONDITION_DIGITAL libm2k::M2kHardwareTriggerV026Impl::getDigitalOutCondition() const
90+
{
91+
return getTriggerOutCondition(m_digital_trigger_device);
5992
}
6093

6194
void libm2k::M2kHardwareTriggerV026Impl::setTriggerOutSource(libm2k::M2K_TRIGGER_OUT_SOURCE src,

src/m2khardwaretrigger_v0.26_impl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ class M2kHardwareTriggerV026Impl : public M2kHardwareTriggerV024Impl {
3636

3737
void reset() override;
3838

39+
void setDigitalOutSource(M2K_TRIGGER_OUT_SOURCE src) override;
40+
41+
M2K_TRIGGER_OUT_SOURCE getDigitalOutSource() const override;
42+
43+
void setDigitalOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) override;
44+
45+
M2K_TRIGGER_CONDITION_DIGITAL getDigitalOutCondition() const override;
46+
3947
protected:
4048
void setTriggerOutSource(M2K_TRIGGER_OUT_SOURCE src, const std::shared_ptr<libm2k::utils::DeviceOut>& device);
4149
M2K_TRIGGER_OUT_SOURCE getTriggerOutSource(const std::shared_ptr<libm2k::utils::DeviceOut>& device) const;
4250
void setTriggerOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond, const std::shared_ptr<libm2k::utils::DeviceOut>& device);
4351
M2K_TRIGGER_CONDITION_DIGITAL getTriggerOutCondition(const std::shared_ptr<libm2k::utils::DeviceOut>& device) const;
4452

53+
std::shared_ptr<libm2k::utils::DeviceOut> m_digital_trigger_device;
54+
4555
static std::vector<std::string> m_trigger_source;
4656
static std::vector<std::string> m_trigger_cond;
4757

0 commit comments

Comments
 (0)