Skip to content

Commit

Permalink
M2kImpl: add trigger deinit on context close
Browse files Browse the repository at this point in the history
- This change ensures that the IIO attributes of the trigger are properly
reset when the context is closed. As a result, the interfaces remains in
a usable state, and any previously configured triggers are set to
a condition that always triggers.

Signed-off-by: Adrian Stanea <[email protected]>
  • Loading branch information
Adrian-Stanea committed Aug 30, 2024
1 parent 71ae6ee commit 5b20a29
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/m2k_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ void M2kImpl::deinitialize()
if (aout_impl) {
aout_impl->deinitialize();
}

auto trigger_impl = dynamic_cast<M2kHardwareTriggerImpl*>(m_trigger);
if (trigger_impl) {
trigger_impl->deinitialize();
}
}

void M2kImpl::reset()
Expand Down
12 changes: 11 additions & 1 deletion src/m2khardwaretrigger_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ void M2kHardwareTriggerImpl::M2kHardwareTriggerImpl::reset()
setDigitalExternalCondition(NO_TRIGGER_DIGITAL);
}

void libm2k::M2kHardwareTriggerImpl::deinitialize()
{
for (unsigned int i = 0; i < m_analog_channels.size(); i++) {
setAnalogMode(i, ALWAYS);
}
for (unsigned int i = 0; i < m_digital_channels.size(); i++) {
setDigitalCondition(i, NO_TRIGGER_DIGITAL);
}
}

bool M2kHardwareTriggerImpl::hasExternalTriggerOut() const
{
return m_logic_channels.at(1)->hasAttribute("out_select");
Expand Down Expand Up @@ -622,4 +632,4 @@ M2K_TRIGGER_STATUS_ANALOG_OUT M2kHardwareTriggerImpl::getAnalogOutTriggerStatus(
"the current board; Check the firmware version.",
libm2k::EXC_INVALID_FIRMWARE_VERSION);
return DISABLED;
}
}
1 change: 1 addition & 0 deletions src/m2khardwaretrigger_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class M2kHardwareTriggerImpl : public M2kHardwareTrigger
virtual ~M2kHardwareTriggerImpl() override;

void reset() override;
virtual void deinitialize();

int getAnalogLevelRaw(unsigned int chnIdx) override;
void setAnalogLevelRaw(unsigned int chnIdx, int level) override;
Expand Down
5 changes: 5 additions & 0 deletions src/m2khardwaretrigger_v0.24_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ void M2kHardwareTriggerV024Impl::reset()
setDigitalSource(SRC_NONE);
}

void libm2k::M2kHardwareTriggerV024Impl::deinitialize()
{
M2kHardwareTriggerImpl::deinitialize();
}

void M2kHardwareTriggerV024Impl::setAnalogExternalOutSelect(M2K_TRIGGER_OUT_SELECT out_select)
{
unsigned int TRIGGER_OUT_PIN = 1;
Expand Down
1 change: 1 addition & 0 deletions src/m2khardwaretrigger_v0.24_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class M2kHardwareTriggerV024Impl : public M2kHardwareTriggerImpl
virtual ~M2kHardwareTriggerV024Impl();

void reset();
void deinitialize() override;

void setAnalogExternalOutSelect(M2K_TRIGGER_OUT_SELECT output_select);
M2K_TRIGGER_OUT_SELECT getAnalogExternalOutSelect();
Expand Down
6 changes: 6 additions & 0 deletions src/m2khardwaretrigger_v0.33_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ void M2kHardwareTriggerV033Impl::reset()
setAnalogOutTriggerStatus(DISABLED);
}

void libm2k::M2kHardwareTriggerV033Impl::deinitialize()
{
M2kHardwareTriggerV024Impl::deinitialize();
setAnalogOutTriggerStatus(DISABLED);
}

void M2kHardwareTriggerV033Impl::setAnalogOutTriggerSource(M2K_TRIGGER_SOURCE_OUT src)
{
if (src < 0 || src >= m_trigger_source_out.size())
Expand Down
1 change: 1 addition & 0 deletions src/m2khardwaretrigger_v0.33_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class M2kHardwareTriggerV033Impl : public M2kHardwareTriggerV024Impl
virtual ~M2kHardwareTriggerV033Impl();

void reset();
void deinitialize() override;

void setAnalogOutTriggerSource(M2K_TRIGGER_SOURCE_OUT src);
M2K_TRIGGER_SOURCE_OUT getAnalogOutTriggerSource() const;
Expand Down

0 comments on commit 5b20a29

Please sign in to comment.