diff --git a/include/libm2k/digital/m2kdigital.hpp b/include/libm2k/digital/m2kdigital.hpp index 2da6e46c0..2f6ba915c 100644 --- a/include/libm2k/digital/m2kdigital.hpp +++ b/include/libm2k/digital/m2kdigital.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -352,6 +353,13 @@ class LIBM2K_API M2kDigital virtual libm2k::M2kHardwareTrigger* getTrigger() = 0; + /** + * @brief Get the hardware trigger out handler + * @return the trigger object + */ + virtual libm2k::M2kOutHardwareTrigger* getOutTrigger() = 0; + + /** * @brief Set the kernel buffers for input to a specific value * @param count the number of kernel buffers diff --git a/src/digital/m2kdigital_impl.cpp b/src/digital/m2kdigital_impl.cpp index 243baa334..0f558db89 100644 --- a/src/digital/m2kdigital_impl.cpp +++ b/src/digital/m2kdigital_impl.cpp @@ -38,7 +38,7 @@ std::vector M2kDigitalImpl::m_output_mode = { "push-pull", }; -M2kDigitalImpl::M2kDigitalImpl(struct iio_context *ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger) +M2kDigitalImpl::M2kDigitalImpl(struct iio_context *ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger, M2kOutHardwareTrigger *trigger_out) { __try { m_dev_generic = make_shared(ctx, logic_dev); @@ -48,6 +48,7 @@ M2kDigitalImpl::M2kDigitalImpl(struct iio_context *ctx, std::string logic_dev, b } m_trigger = trigger; + m_trigger_out = trigger_out; m_dev_name_write = logic_dev + "-tx"; m_dev_name_read = logic_dev + "-rx"; @@ -347,6 +348,14 @@ M2kHardwareTrigger* M2kDigitalImpl::getTrigger() return m_trigger; } +M2kOutHardwareTrigger* M2kDigitalImpl::getOutTrigger() +{ + if (!m_trigger_out) { + throw_exception(EXC_INVALID_PARAMETER, "Digital TX trigger is not available"); + } + return m_trigger_out; +} + void M2kDigitalImpl::setOutputMode(DIO_CHANNEL chn, DIO_MODE mode) { std::string output_mode = m_output_mode[mode]; diff --git a/src/digital/m2kdigital_impl.hpp b/src/digital/m2kdigital_impl.hpp index 6d5ae5020..837fbd6e4 100644 --- a/src/digital/m2kdigital_impl.hpp +++ b/src/digital/m2kdigital_impl.hpp @@ -38,7 +38,7 @@ namespace digital { class M2kDigitalImpl : public M2kDigital { public: - M2kDigitalImpl(struct iio_context* ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger); + M2kDigitalImpl(struct iio_context* ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger, M2kOutHardwareTrigger *trigger_out); virtual ~M2kDigitalImpl(); void reset(); @@ -85,6 +85,7 @@ class M2kDigitalImpl : public M2kDigital void setCyclic(bool cyclic); libm2k::M2kHardwareTrigger* getTrigger(); + libm2k::M2kOutHardwareTrigger* getOutTrigger() override; void setKernelBuffersCountIn(unsigned int count); void setKernelBuffersCountOut(unsigned int count); @@ -108,6 +109,7 @@ class M2kDigitalImpl : public M2kDigital std::vector m_tx_channels_enabled; std::vector m_rx_channels_enabled; libm2k::M2kHardwareTrigger *m_trigger; + libm2k::M2kOutHardwareTrigger *m_trigger_out; static std::vector m_output_mode; void syncDevice(); diff --git a/src/m2k_impl.cpp b/src/m2k_impl.cpp index 6f529aa56..70d225529 100644 --- a/src/m2k_impl.cpp +++ b/src/m2k_impl.cpp @@ -25,6 +25,7 @@ #include "analog/m2kpowersupply_impl.hpp" #include "m2khardwaretrigger_impl.hpp" #include "m2khardwaretrigger_v0.24_impl.hpp" +#include "m2kouthardwaretrigger_impl.hpp" #include "m2kcalibration_impl.hpp" #include #include "utils/channel.hpp" @@ -66,13 +67,17 @@ M2kImpl::M2kImpl(std::string uri, iio_context* ctx, std::string name, bool sync) m_firmware_version = getFirmwareVersion(); - int diff = Utils::compareVersions(m_firmware_version, "v0.24"); - if (diff < 0) { //m_firmware_version < 0.24 + int diff_v024 = Utils::compareVersions(m_firmware_version, "v0.24"); + if (diff_v024 < 0) { //m_firmware_version < 0.24 m_trigger = new M2kHardwareTriggerImpl(ctx); } else { m_trigger = new M2kHardwareTriggerV024Impl(ctx); } - + // TODO replace v0.25 -> v0.26 and change the comp condition + int diff_v026 = Utils::compareVersions(m_firmware_version, "v0.25"); + if (diff_v026 < 0) { + m_trigger_out = new M2kOutHardwareTriggerImpl(ctx); + } if (!m_trigger) { throw_exception(EXC_INVALID_PARAMETER, "Can't instantiate M2K board; M2K trigger is invalid."); } @@ -187,7 +192,7 @@ void M2kImpl::scanAllPowerSupply() void M2kImpl::scanAllDigital() { - libm2k::digital::M2kDigital* logic = new libm2k::digital::M2kDigitalImpl(m_context, "m2k-logic-analyzer", m_sync, m_trigger); + libm2k::digital::M2kDigital* logic = new libm2k::digital::M2kDigitalImpl(m_context, "m2k-logic-analyzer", m_sync, m_trigger, m_trigger_out); m_instancesDigital.push_back(logic); } diff --git a/src/m2k_impl.hpp b/src/m2k_impl.hpp index 4196e7070..d86607dba 100644 --- a/src/m2k_impl.hpp +++ b/src/m2k_impl.hpp @@ -27,6 +27,7 @@ namespace libm2k { class M2kHardwareTrigger; +class M2kOutHardwareTrigger; class M2kCalibration; namespace context { @@ -73,6 +74,7 @@ class M2kImpl : public M2k, public ContextImpl private: M2kCalibration* m_calibration; libm2k::M2kHardwareTrigger *m_trigger; + libm2k::M2kOutHardwareTrigger *m_trigger_out; std::vector m_instancesAnalogOut; std::vector m_instancesAnalogIn; std::vector m_instancesPowerSupply;