Skip to content

Commit

Permalink
trigger and io_pins sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed May 6, 2020
1 parent 48bc67a commit 412a0d6
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 158 deletions.
6 changes: 5 additions & 1 deletion modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -75359,12 +75359,16 @@
"value": "5"
},
{
"name": "TINP",
"name": "SYSTrig",
"value": "6"
},
{
"name": "TOUT",
"value": "7"
},
{
"name": "DLOGTrig",
"value": "8"
}
]
},
Expand Down
37 changes: 31 additions & 6 deletions src/eez/modules/psu/dlog_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <eez/modules/psu/psu.h>
#include <eez/libs/sd_fat/sd_fat.h>

#include <math.h>

#include <eez/index.h>
#include <eez/system.h>

#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/channel_dispatcher.h>
#include <eez/modules/psu/datetime.h>
#include <eez/modules/psu/scpi/psu.h>
#include <eez/modules/psu/sd_card.h>
#include <eez/system.h>
#include <eez/modules/psu/io_pins.h>
#include <eez/modules/psu/dlog_record.h>
#include <eez/modules/psu/event_queue.h>

#include <eez/modules/psu/scpi/psu.h>

#include <eez/gui/widgets/yt_graph.h>

#include <eez/libs/sd_fat/sd_fat.h>

#include <eez/memory.h>

namespace eez {
Expand Down Expand Up @@ -609,7 +611,7 @@ static void resetParameters() {
memset(&g_parameters, 0, sizeof(g_parameters));
g_parameters.period = PERIOD_DEFAULT;
g_parameters.time = TIME_DEFAULT;
g_parameters.triggerSource = trigger::SOURCE_IMMEDIATE;
setTriggerSource(trigger::SOURCE_IMMEDIATE);
}

static void doFinish(bool afterError) {
Expand All @@ -621,6 +623,29 @@ static void doFinish(bool afterError) {
setState(STATE_IDLE);
}


////////////////////////////////////////////////////////////////////////////////

void setTriggerSource(trigger::Source source) {
g_parameters.triggerSource = source;

if (source == trigger::SOURCE_PIN1) {
if (io_pins::g_ioPins[0].function != io_pins::FUNCTION_DLOGTRIG) {
io_pins::setPinFunction(0, io_pins::FUNCTION_DLOGTRIG);
}
} else if (source == trigger::SOURCE_PIN2) {
if (io_pins::g_ioPins[1].function != io_pins::FUNCTION_DLOGTRIG) {
io_pins::setPinFunction(1, io_pins::FUNCTION_DLOGTRIG);
}
} else {
if (io_pins::g_ioPins[0].function == io_pins::FUNCTION_DLOGTRIG) {
io_pins::setPinFunction(0, io_pins::FUNCTION_NONE);
} else if (io_pins::g_ioPins[1].function == io_pins::FUNCTION_DLOGTRIG) {
io_pins::setPinFunction(1, io_pins::FUNCTION_NONE);
}
}
}

////////////////////////////////////////////////////////////////////////////////

int checkDlogParameters(dlog_view::Parameters &parameters, bool doNotCheckFilePath, bool forTraceUsage) {
Expand Down
2 changes: 2 additions & 0 deletions src/eez/modules/psu/dlog_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ inline bool isExecuting() { return g_state == STATE_EXECUTING; }
inline bool isTraceExecuting() { return g_state == STATE_EXECUTING && g_traceInitiated; }
inline bool isInStateTransition() { return g_inStateTransition; }

void setTriggerSource(trigger::Source source);

int checkDlogParameters(dlog_view::Parameters &parameters, bool doNotCheckFilePath, bool forTraceUsage);

int initiate();
Expand Down
23 changes: 16 additions & 7 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ EnumItem g_enumDefinition_IO_PINS_INPUT_FUNCTION[] = {
{ io_pins::FUNCTION_NONE, "None" },
{ io_pins::FUNCTION_INPUT, "Input" },
{ io_pins::FUNCTION_INHIBIT, "Inhibit" },
{ io_pins::FUNCTION_TINPUT, "Trigger input", "Tinput" },
{ io_pins::FUNCTION_SYSTRIG, "System trigger", "SysTrig" },
{ 0, 0 }
};

EnumItem g_enumDefinition_IO_PINS_INPUT_FUNCTION_WITH_DLOG_TRIGGER[] = {
{ io_pins::FUNCTION_NONE, "None" },
{ io_pins::FUNCTION_INPUT, "Input" },
{ io_pins::FUNCTION_INHIBIT, "Inhibit" },
{ io_pins::FUNCTION_SYSTRIG, "System trigger", "SysTrig" },
{ io_pins::FUNCTION_DLOGTRIG, "DLOG trigger", "DlogTrig" },
{ 0, 0 }
};

Expand Down Expand Up @@ -4279,7 +4288,7 @@ void data_trigger_is_initiated(DataOperationEnum operation, Cursor cursor, Value

void data_trigger_is_manual(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
value = trigger::getSource() == trigger::SOURCE_MANUAL && !trigger::isTriggered();
value = trigger::g_triggerSource == trigger::SOURCE_MANUAL && !trigger::isTriggered();
}
}

Expand Down Expand Up @@ -4353,8 +4362,8 @@ void data_io_pins_inhibit_state(DataOperationEnum operation, Cursor cursor, Valu
if (io_pins::isInhibited()) {
value = 1;
} else {
const persist_conf::IOPin &inputPin1 = persist_conf::devConf.ioPins[0];
const persist_conf::IOPin &inputPin2 = persist_conf::devConf.ioPins[1];
const io_pins::IOPin &inputPin1 = io_pins::g_ioPins[0];
const io_pins::IOPin &inputPin2 = io_pins::g_ioPins[1];
if (inputPin1.function == io_pins::FUNCTION_INHIBIT || inputPin2.function == io_pins::FUNCTION_INHIBIT) {
value = 0;
} else {
Expand Down Expand Up @@ -4399,7 +4408,7 @@ void data_io_pin_function_name(DataOperationEnum operation, Cursor cursor, Value
SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getPage(PAGE_ID_SYS_SETTINGS_IO);
if (page) {
if (cursor < DOUT1) {
value = MakeEnumDefinitionValue(page->m_function[cursor], ENUM_DEFINITION_IO_PINS_INPUT_FUNCTION);
value = MakeEnumDefinitionValue(page->m_function[cursor], ENUM_DEFINITION_IO_PINS_INPUT_FUNCTION_WITH_DLOG_TRIGGER);
} else if (cursor == DOUT2) {
value = MakeEnumDefinitionValue(page->m_function[cursor], ENUM_DEFINITION_IO_PINS_OUTPUT2_FUNCTION);
} else {
Expand All @@ -4419,11 +4428,11 @@ void data_io_pin_state(DataOperationEnum operation, Cursor cursor, Value &value)
} else {
int state = io_pins::getPinState(cursor);

if (page->m_polarity[pin] != persist_conf::devConf.ioPins[pin].polarity) {
if (page->m_polarity[pin] != io_pins::g_ioPins[pin].polarity) {
state = state ? 0 : 1;
}

if (pin >= 2 && page->m_function[pin] == io_pins::FUNCTION_OUTPUT && persist_conf::devConf.ioPins[pin].function == io_pins::FUNCTION_OUTPUT) {
if (pin >= 2 && page->m_function[pin] == io_pins::FUNCTION_OUTPUT && io_pins::g_ioPins[pin].function == io_pins::FUNCTION_OUTPUT) {
if (state) {
value = 3; // Active_Changeable
} else {
Expand Down
1 change: 1 addition & 0 deletions src/eez/modules/psu/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace gui {
ENUM_DEFINITION(CHANNEL_TRIGGER_ON_LIST_STOP) \
ENUM_DEFINITION(IO_PINS_POLARITY) \
ENUM_DEFINITION(IO_PINS_INPUT_FUNCTION) \
ENUM_DEFINITION(IO_PINS_INPUT_FUNCTION_WITH_DLOG_TRIGGER) \
ENUM_DEFINITION(IO_PINS_OUTPUT_FUNCTION) \
ENUM_DEFINITION(IO_PINS_OUTPUT2_FUNCTION) \
ENUM_DEFINITION(DST_RULE) \
Expand Down
29 changes: 14 additions & 15 deletions src/eez/modules/psu/gui/page_sys_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,9 @@ void SysSettingsEncoderPage::set() {
////////////////////////////////////////////////////////////////////////////////

void SysSettingsTriggerPage::pageAlloc() {
m_sourceOrig = m_source = trigger::getSource();
m_delayOrig = m_delay = trigger::getDelay();
m_initiateContinuouslyOrig = m_initiateContinuously =
trigger::isContinuousInitializationEnabled();
m_sourceOrig = m_source = trigger::g_triggerSource;
m_delayOrig = m_delay = trigger::g_triggerDelay;
m_initiateContinuouslyOrig = m_initiateContinuously = trigger::g_triggerContinuousInitializationEnabled;
}

void SysSettingsTriggerPage::onTriggerSourceSet(uint16_t value) {
Expand Down Expand Up @@ -791,7 +790,7 @@ void SysSettingsTriggerPage::editDelay() {
options.flags.signButtonEnabled = true;
options.flags.dotButtonEnabled = true;

NumericKeypad::start(0, MakeValue(trigger::getDelay(), UNIT_SECOND), options, onDelaySet, 0, 0);
NumericKeypad::start(0, MakeValue(trigger::g_triggerDelay, UNIT_SECOND), options, onDelaySet, 0, 0);
}

void SysSettingsTriggerPage::toggleInitiateContinuously() {
Expand All @@ -809,12 +808,6 @@ void SysSettingsTriggerPage::set() {
trigger::setDelay(m_delay);
trigger::enableInitiateContinuous(m_initiateContinuously);

if (m_source == trigger::SOURCE_PIN1) {
persist_conf::setIoPinFunction(0, io_pins::FUNCTION_TINPUT);
} else if (m_source == trigger::SOURCE_PIN2) {
persist_conf::setIoPinFunction(1, io_pins::FUNCTION_TINPUT);
}

popPage();

// infoMessage("Trigger settings saved!");
Expand All @@ -825,8 +818,8 @@ void SysSettingsTriggerPage::set() {

void SysSettingsIOPinsPage::pageAlloc() {
for (int i = 0; i < NUM_IO_PINS; i++) {
m_polarityOrig[i] = m_polarity[i] = (io_pins::Polarity)persist_conf::devConf.ioPins[i].polarity;
m_functionOrig[i] = m_function[i] = (io_pins::Function)persist_conf::devConf.ioPins[i].function;
m_polarityOrig[i] = m_polarity[i] = (io_pins::Polarity)io_pins::g_ioPins[i].polarity;
m_functionOrig[i] = m_function[i] = (io_pins::Function)io_pins::g_ioPins[i].function;
if (i >= DOUT1) {
g_pwmFrequencyOrig[i - DOUT1] = g_pwmFrequency[i - DOUT1] = io_pins::getPwmFrequency(i);
g_pwmDutyOrig[i - DOUT1] = g_pwmDuty[i - DOUT1] = io_pins::getPwmDuty(i);
Expand All @@ -844,6 +837,12 @@ void SysSettingsIOPinsPage::onFunctionSet(uint16_t value) {
popPage();
SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getActivePage();
page->m_function[page->pinNumber] = (io_pins::Function)value;
if (value == io_pins::FUNCTION_SYSTRIG) {
int otherPin = page->pinNumber == 0 ? 1 : 0;
if (page->m_function[otherPin] == io_pins::FUNCTION_SYSTRIG) {
page->m_function[otherPin] = io_pins::FUNCTION_NONE;
}
}
}

void SysSettingsIOPinsPage::selectFunction() {
Expand Down Expand Up @@ -890,8 +889,8 @@ int SysSettingsIOPinsPage::getDirty() {
void SysSettingsIOPinsPage::set() {
if (getDirty()) {
for (int i = 0; i < NUM_IO_PINS; i++) {
persist_conf::setIoPinPolarity(i, m_polarity[i]);
persist_conf::setIoPinFunction(i, m_function[i]);
io_pins::setPinPolarity(i, m_polarity[i]);
io_pins::setPinFunction(i, m_function[i]);
if (i >= DOUT1) {
if (g_pwmFrequencyOrig[i - DOUT1] != g_pwmFrequency[i - DOUT1]) {
io_pins::setPwmFrequency(i, g_pwmFrequency[i - DOUT1]);
Expand Down
Loading

0 comments on commit 412a0d6

Please sign in to comment.