diff --git a/modular-psu-firmware.eez-project b/modular-psu-firmware.eez-project index b6630d30b..212821dd9 100644 --- a/modular-psu-firmware.eez-project +++ b/modular-psu-firmware.eez-project @@ -75359,12 +75359,16 @@ "value": "5" }, { - "name": "TINP", + "name": "SYSTrig", "value": "6" }, { "name": "TOUT", "value": "7" + }, + { + "name": "DLOGTrig", + "value": "8" } ] }, diff --git a/src/eez/modules/psu/dlog_record.cpp b/src/eez/modules/psu/dlog_record.cpp index ee7ab5d1a..c6c9437ae 100644 --- a/src/eez/modules/psu/dlog_record.cpp +++ b/src/eez/modules/psu/dlog_record.cpp @@ -16,23 +16,25 @@ * along with this program. If not, see . */ -#include -#include - #include #include +#include #include #include #include -#include #include -#include +#include #include #include + +#include + #include +#include + #include namespace eez { @@ -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) { @@ -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 ¶meters, bool doNotCheckFilePath, bool forTraceUsage) { diff --git a/src/eez/modules/psu/dlog_record.h b/src/eez/modules/psu/dlog_record.h index b4844c6d9..6189cbf0e 100644 --- a/src/eez/modules/psu/dlog_record.h +++ b/src/eez/modules/psu/dlog_record.h @@ -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 ¶meters, bool doNotCheckFilePath, bool forTraceUsage); int initiate(); diff --git a/src/eez/modules/psu/gui/data.cpp b/src/eez/modules/psu/gui/data.cpp index 0679b0403..2a3339ac3 100644 --- a/src/eez/modules/psu/gui/data.cpp +++ b/src/eez/modules/psu/gui/data.cpp @@ -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 } }; @@ -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(); } } @@ -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 { @@ -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 { @@ -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 { diff --git a/src/eez/modules/psu/gui/data.h b/src/eez/modules/psu/gui/data.h index bdca250bd..c97c5627c 100644 --- a/src/eez/modules/psu/gui/data.h +++ b/src/eez/modules/psu/gui/data.h @@ -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) \ diff --git a/src/eez/modules/psu/gui/page_sys_settings.cpp b/src/eez/modules/psu/gui/page_sys_settings.cpp index 2a873e7e8..44273db17 100644 --- a/src/eez/modules/psu/gui/page_sys_settings.cpp +++ b/src/eez/modules/psu/gui/page_sys_settings.cpp @@ -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) { @@ -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() { @@ -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!"); @@ -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); @@ -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() { @@ -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]); diff --git a/src/eez/modules/psu/io_pins.cpp b/src/eez/modules/psu/io_pins.cpp index 6f725f7d8..d08cb4bb9 100644 --- a/src/eez/modules/psu/io_pins.cpp +++ b/src/eez/modules/psu/io_pins.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #if defined EEZ_PLATFORM_STM32 #include @@ -45,6 +46,8 @@ namespace eez { namespace psu { namespace io_pins { +IOPin g_ioPins[4]; + static struct { unsigned outputFault : 2; unsigned outputEnabled : 2; @@ -144,7 +147,7 @@ void initInputPin(int pin) { if (!bp3c::flash_slave::g_bootloaderMode || pin != 0) { GPIO_InitTypeDef GPIO_InitStruct = { 0 }; - const persist_conf::IOPin &ioPin = persist_conf::devConf.ioPins[pin]; + const IOPin &ioPin = g_ioPins[pin]; GPIO_InitStruct.Pin = pin == 0 ? UART_RX_DIN1_Pin : DIN2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; @@ -266,7 +269,7 @@ void initOutputPin(int pin) { } #endif } else if (pin == DOUT2) { - const persist_conf::IOPin &ioPin = persist_conf::devConf.ioPins[pin]; + const IOPin &ioPin = g_ioPins[pin]; if (ioPin.function == io_pins::FUNCTION_PWM) { updatePwmFrequency(pin); } else { @@ -281,11 +284,11 @@ void init() { void tick(uint32_t tickCount) { // execute input pins function - const persist_conf::IOPin &inputPin1 = persist_conf::devConf.ioPins[0]; + const IOPin &inputPin1 = g_ioPins[0]; int inputPin1Value = ioPinRead(EXT_TRIG1); bool inputPin1State = (inputPin1Value && inputPin1.polarity == io_pins::POLARITY_POSITIVE) || (!inputPin1Value && inputPin1.polarity == io_pins::POLARITY_NEGATIVE); - const persist_conf::IOPin &inputPin2 = persist_conf::devConf.ioPins[1]; + const IOPin &inputPin2 = g_ioPins[1]; int inputPin2Value = ioPinRead(EXT_TRIG2); bool inputPin2State = (inputPin2Value && inputPin2.polarity == io_pins::POLARITY_POSITIVE) || (!inputPin2Value && inputPin2.polarity == io_pins::POLARITY_NEGATIVE); @@ -306,11 +309,11 @@ void tick(uint32_t tickCount) { Channel::onInhibitedChanged(inhibited); } - if (inputPin1.function == io_pins::FUNCTION_TINPUT && inputPin1State && !g_pinState[0]) { + if ((inputPin1.function == io_pins::FUNCTION_SYSTRIG || inputPin1.function == io_pins::FUNCTION_DLOGTRIG) && inputPin1State && !g_pinState[0]) { trigger::generateTrigger(trigger::SOURCE_PIN1); } - if (inputPin2.function == io_pins::FUNCTION_TINPUT && inputPin2State && !g_pinState[1]) { + if ((inputPin2.function == io_pins::FUNCTION_SYSTRIG || inputPin2.function == io_pins::FUNCTION_DLOGTRIG) && inputPin2State && !g_pinState[1]) { trigger::generateTrigger(trigger::SOURCE_PIN2); } @@ -322,7 +325,7 @@ void tick(uint32_t tickCount) { int32_t diff = tickCount - g_toutputPulseStartTickCount; if (diff > CONF_TOUTPUT_PULSE_WIDTH_MS * 1000L) { for (int pin = 2; pin < NUM_IO_PINS; ++pin) { - const persist_conf::IOPin &outputPin = persist_conf::devConf.ioPins[pin]; + const IOPin &outputPin = g_ioPins[pin]; if (outputPin.function == io_pins::FUNCTION_TOUTPUT) { setPinState(pin, false); } @@ -336,7 +339,7 @@ void tick(uint32_t tickCount) { // execute output pins function for (int pin = 2; pin < NUM_IO_PINS; ++pin) { - const persist_conf::IOPin &outputPin = persist_conf::devConf.ioPins[pin]; + const IOPin &outputPin = g_ioPins[pin]; if (outputPin.function == io_pins::FUNCTION_FAULT) { if (trippedState == UNKNOWN) { @@ -373,7 +376,7 @@ void tick(uint32_t tickCount) { void onTrigger() { // start trigger output pulse for (int pin = 2; pin < NUM_IO_PINS; ++pin) { - const persist_conf::IOPin &outputPin = persist_conf::devConf.ioPins[pin]; + const IOPin &outputPin = g_ioPins[pin]; if (outputPin.function == io_pins::FUNCTION_TOUTPUT) { setPinState(pin, true); g_lastState.toutputPulse = 1; @@ -390,7 +393,7 @@ void refresh() { } else { initOutputPin(pin); - const persist_conf::IOPin &ioPin = persist_conf::devConf.ioPins[pin]; + const IOPin &ioPin = g_ioPins[pin]; if (ioPin.function == io_pins::FUNCTION_NONE) { setPinState(pin, false); } else if (ioPin.function == io_pins::FUNCTION_OUTPUT) { @@ -416,11 +419,64 @@ bool isInhibited() { return g_lastState.inhibited; } +void setPinPolarity(int pin, unsigned polarity) { + g_ioPins[pin].polarity = polarity; + refresh(); +} + +void setPinFunction(int pin, unsigned function) { + g_ioPins[pin].function = function; + + if (pin == 0 || pin == 1) { + int otherPin = pin == 0 ? 1 : 0; + + if (function == io_pins::FUNCTION_SYSTRIG) { + if (g_ioPins[otherPin].function == io_pins::FUNCTION_SYSTRIG) { + g_ioPins[otherPin].function = io_pins::FUNCTION_NONE; + } + + trigger::Source triggerSource = pin == 0 ? trigger::SOURCE_PIN1 : trigger::SOURCE_PIN2; + + if (dlog_record::g_parameters.triggerSource == triggerSource) { + dlog_record::setTriggerSource(trigger::SOURCE_IMMEDIATE); + } + + if (trigger::g_triggerSource != triggerSource) { + trigger::setSource(triggerSource); + } + } else if (function == io_pins::FUNCTION_DLOGTRIG) { + if (g_ioPins[otherPin].function == io_pins::FUNCTION_DLOGTRIG) { + g_ioPins[otherPin].function = io_pins::FUNCTION_NONE; + } + + trigger::Source triggerSource = pin == 0 ? trigger::SOURCE_PIN1 : trigger::SOURCE_PIN2; + + if (trigger::g_triggerSource == triggerSource) { + trigger::setSource(trigger::SOURCE_IMMEDIATE); + } + + if (dlog_record::g_parameters.triggerSource != triggerSource) { + dlog_record::setTriggerSource(triggerSource); + } + } else { + if (pin == 0 && dlog_record::g_parameters.triggerSource == trigger::SOURCE_PIN1 || pin == 1 && dlog_record::g_parameters.triggerSource == trigger::SOURCE_PIN2) { + dlog_record::setTriggerSource(trigger::SOURCE_IMMEDIATE); + } + + if (pin == 0 && trigger::g_triggerSource == trigger::SOURCE_PIN1 || pin == 1 && trigger::g_triggerSource == trigger::SOURCE_PIN2) { + trigger::setSource(trigger::SOURCE_IMMEDIATE); + } + } + } + + io_pins::refresh(); +} + void setPinState(int pin, bool state) { if (pin >= 2) { g_pinState[pin] = state; - if (persist_conf::devConf.ioPins[pin].polarity == io_pins::POLARITY_NEGATIVE) { + if (g_ioPins[pin].polarity == io_pins::POLARITY_NEGATIVE) { state = !state; } @@ -433,12 +489,12 @@ bool getPinState(int pin) { bool state; if (pin == 0) { state = ioPinRead(EXT_TRIG1) ? true : false; - if (persist_conf::devConf.ioPins[0].polarity == io_pins::POLARITY_NEGATIVE) { + if (g_ioPins[0].polarity == io_pins::POLARITY_NEGATIVE) { state = !state; } } else { state = ioPinRead(EXT_TRIG2) ? true : false; - if (persist_conf::devConf.ioPins[1].polarity == io_pins::POLARITY_NEGATIVE) { + if (g_ioPins[1].polarity == io_pins::POLARITY_NEGATIVE) { state = !state; } } diff --git a/src/eez/modules/psu/io_pins.h b/src/eez/modules/psu/io_pins.h index 0bc8f9216..83a703a5c 100644 --- a/src/eez/modules/psu/io_pins.h +++ b/src/eez/modules/psu/io_pins.h @@ -40,11 +40,19 @@ enum Function { FUNCTION_FAULT, FUNCTION_INHIBIT, FUNCTION_ON_COUPLE, - FUNCTION_TINPUT, + FUNCTION_SYSTRIG, FUNCTION_TOUTPUT, - FUNCTION_PWM + FUNCTION_PWM, + FUNCTION_DLOGTRIG }; +struct IOPin { + unsigned polarity : 1; + unsigned function : 7; +}; + +extern IOPin g_ioPins[4]; + void init(); void tick(uint32_t tickCount); void onTrigger(); @@ -53,6 +61,9 @@ void refresh(); // When PSU is in inhibited state all outputs are disabled and execution of LIST on channels is stopped. bool isInhibited(); +void setPinPolarity(int pin, unsigned polarity); +void setPinFunction(int pin, unsigned function); + void setPinState(int pin, bool state); bool getPinState(int pin); diff --git a/src/eez/modules/psu/persist_conf.cpp b/src/eez/modules/psu/persist_conf.cpp index 35ee9fcfd..71e0a9214 100644 --- a/src/eez/modules/psu/persist_conf.cpp +++ b/src/eez/modules/psu/persist_conf.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -44,9 +45,7 @@ using namespace eez::mcu::display; #endif #include -#include #include -#include #include @@ -89,7 +88,7 @@ static DevConfBlock g_devConfBlocks[] = { { offsetof(DeviceConfiguration, dateYear), 1, false, 0, 0, 0 }, { offsetof(DeviceConfiguration, profileAutoRecallLocation), 1, false, 0, 0, 0 }, { offsetof(DeviceConfiguration, startOfBlock4), 1, false, 0, 0, 0 }, - { offsetof(DeviceConfiguration, triggerSource), 1, false, 0, 0, 0 }, + { offsetof(DeviceConfiguration, reserved51), 1, false, 0, 0, 0 }, { offsetof(DeviceConfiguration, ytGraphUpdateMethod), 1, false, 0, 0, 0 }, { offsetof(DeviceConfiguration, userSwitchAction), 1, false, 0, 60 * 1000, 0 }, { offsetof(DeviceConfiguration, ethernetHostName), 1, false, 0, 0, 0 }, @@ -162,10 +161,6 @@ void initDefaultDevConf() { g_defaultDevConf.encoderMovingSpeedUp = mcu::encoder::DEFAULT_MOVING_UP_SPEED; // block 5 - g_defaultDevConf.triggerContinuousInitializationEnabled = 0; - - g_defaultDevConf.triggerSource = trigger::SOURCE_IMMEDIATE; - g_defaultDevConf.triggerDelay = 0; // block 6 g_defaultDevConf.displayState = 1; @@ -1205,38 +1200,10 @@ void setDateTimeFormat(unsigned dateTimeFormat) { g_devConf.dateTimeFormat = dateTimeFormat; } -void setIoPinPolarity(int pin, unsigned polarity) { - g_devConf.ioPins[pin].polarity = polarity; - io_pins::refresh(); -} - -void setIoPinFunction(int pin, unsigned function) { - g_devConf.ioPins[pin].function = function; - io_pins::refresh(); -} - void setSelectedThemeIndex(uint8_t selectedThemeIndex) { g_devConf.selectedThemeIndex = selectedThemeIndex; } -void resetTrigger() { - g_devConf.triggerDelay = trigger::DELAY_DEFAULT; - g_devConf.triggerSource = trigger::SOURCE_IMMEDIATE; - g_devConf.triggerContinuousInitializationEnabled = 0; -} - -void setTriggerContinuousInitializationEnabled(unsigned triggerContinuousInitializationEnabled) { - g_devConf.triggerContinuousInitializationEnabled = triggerContinuousInitializationEnabled; -} - -void setTriggerDelay(float triggerDelay) { - g_devConf.triggerDelay = triggerDelay; -} - -void setTriggerSource(uint8_t triggerSource) { - g_devConf.triggerSource = triggerSource; -} - void setSkipChannelCalibrations(unsigned skipChannelCalibrations) { g_devConf.skipChannelCalibrations = skipChannelCalibrations; } diff --git a/src/eez/modules/psu/persist_conf.h b/src/eez/modules/psu/persist_conf.h index b5891ba1a..17aee185d 100644 --- a/src/eez/modules/psu/persist_conf.h +++ b/src/eez/modules/psu/persist_conf.h @@ -52,11 +52,6 @@ struct BlockHeader { uint16_t version; }; -struct IOPin { - unsigned polarity : 1; - unsigned function : 7; -}; - enum UserSwitchAction { USER_SWITCH_ACTION_NONE, USER_SWITCH_ACTION_ENCODER_STEP, @@ -156,12 +151,15 @@ struct DeviceConfiguration { unsigned isClickSoundEnabled : 1; // block 5 - uint8_t triggerSource; - float triggerDelay; + uint8_t reserved51; // was triggerSource + float reserved52; // was triggerDelay - IOPin ioPins[4]; + struct { + unsigned reserved1 : 1; + unsigned reserved2 : 7; + } reserved53[4]; // was ioPins - unsigned triggerContinuousInitializationEnabled : 1; + unsigned reserved54 : 1; // was triggerContinuousInitializationEnabled unsigned isFrontPanelLocked : 1; @@ -321,16 +319,8 @@ void setTimeZone(int16_t time_zone); void setDstRule(uint8_t dstRule); void setDateTimeFormat(unsigned dstRule); -void setIoPinPolarity(int pin, unsigned polarity); -void setIoPinFunction(int pin, unsigned function); - void setSelectedThemeIndex(uint8_t selectedThemeIndex); -void resetTrigger(); -void setTriggerContinuousInitializationEnabled(unsigned triggerContinuousInitializationEnabled); -void setTriggerDelay(float triggerDelay); -void setTriggerSource(uint8_t triggerSource); - void setSkipChannelCalibrations(unsigned skipChannelCalibrations); void setSkipDateTimeSetup(unsigned skipDateTimeSetup); void setSkipEthernetSetup(unsigned skipEthernetSetup); diff --git a/src/eez/modules/psu/profile.cpp b/src/eez/modules/psu/profile.cpp index 37aab05e3..ca0bc0bd3 100644 --- a/src/eez/modules/psu/profile.cpp +++ b/src/eez/modules/psu/profile.cpp @@ -677,6 +677,12 @@ static void saveState(Parameters &profile, List *lists) { } } + profile.flags.triggerContinuousInitializationEnabled = trigger::g_triggerContinuousInitializationEnabled; + profile.triggerSource = trigger::g_triggerSource; + profile.triggerDelay = trigger::g_triggerDelay; + + memcpy(profile.ioPins, io_pins::g_ioPins, sizeof(profile.ioPins)); + profile.flags.isValid = true; } @@ -806,6 +812,13 @@ static bool recallState(Parameters &profile, List *lists, int recallOptions, int Channel::updateAllChannels(); + trigger::g_triggerContinuousInitializationEnabled = profile.flags.triggerContinuousInitializationEnabled; + trigger::g_triggerSource = (trigger::Source)profile.triggerSource; + trigger::g_triggerDelay = profile.triggerDelay; + + memcpy(io_pins::g_ioPins, profile.ioPins, sizeof(profile.ioPins)); + io_pins::refresh(); + return true; } @@ -1085,6 +1098,17 @@ static bool profileWrite(WriteContext &ctx, const Parameters ¶meters, List * #endif } + ctx.group("trigger"); + WRITE_PROPERTY("continuousInitializationEnabled", parameters.flags.triggerContinuousInitializationEnabled); + WRITE_PROPERTY("source", parameters.triggerSource); + WRITE_PROPERTY("delay", parameters.triggerDelay); + + for (int i = 0; i < 4; ++i) { + ctx.group("io_pin", i + 1); + WRITE_PROPERTY("function", parameters.ioPins[i].function); + WRITE_PROPERTY("polarity", parameters.ioPins[i].polarity); + } + return true; } @@ -1462,6 +1486,22 @@ static bool profileReadCallback(ReadContext &ctx, Parameters ¶meters, List * READ_PROPERTY(state, tempSensorProt.state); } + if (ctx.matchGroup("trigger")) { + READ_FLAG(continuousInitializationEnabled, parameters.flags.triggerContinuousInitializationEnabled); + READ_PROPERTY(source, parameters.triggerSource); + READ_PROPERTY(delay, parameters.triggerDelay); + } + + int ioPinIndex; + if (ctx.matchGroup("io_pin", ioPinIndex)) { + --ioPinIndex; + + auto &ioPin = parameters.ioPins[ioPinIndex]; + + READ_FLAG(function, ioPin.function); + READ_FLAG(polarity, ioPin.polarity); + } + return false; } diff --git a/src/eez/modules/psu/profile.h b/src/eez/modules/psu/profile.h index 4dc317fb9..644f3e7d8 100644 --- a/src/eez/modules/psu/profile.h +++ b/src/eez/modules/psu/profile.h @@ -19,6 +19,7 @@ #pragma once #include +#include #define PROFILE_EXT ".profile" @@ -85,7 +86,8 @@ struct ProfileFlags { unsigned isValid: 1; unsigned powerIsUp: 1; unsigned couplingType : 3; - unsigned reserverd : 11; + unsigned triggerContinuousInitializationEnabled: 1; + unsigned reserverd : 10; }; enum LoadStatus { @@ -101,6 +103,9 @@ struct Parameters { char name[PROFILE_NAME_MAX_LENGTH + 1]; ChannelParameters channels[CH_MAX]; temperature::ProtectionConfiguration tempProt[temp_sensor::MAX_NUM_TEMP_SENSORS]; + uint16_t triggerSource; + float triggerDelay; + io_pins::IOPin ioPins[4]; }; void init(); diff --git a/src/eez/modules/psu/scpi/syst.cpp b/src/eez/modules/psu/scpi/syst.cpp index 860f801ed..fe1b6eb5f 100644 --- a/src/eez/modules/psu/scpi/syst.cpp +++ b/src/eez/modules/psu/scpi/syst.cpp @@ -1252,7 +1252,7 @@ scpi_result_t scpi_cmd_systemDigitalInputDataQ(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_INPUT) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_INPUT) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } @@ -1275,7 +1275,7 @@ scpi_result_t scpi_cmd_systemDigitalOutputData(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_OUTPUT) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_OUTPUT) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } @@ -1303,7 +1303,7 @@ scpi_result_t scpi_cmd_systemDigitalOutputDataQ(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_OUTPUT) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_OUTPUT) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } @@ -1319,9 +1319,10 @@ static scpi_choice_def_t functionChoice[] = { { "NONE", io_pins::FUNCTION_NONE } { "FAULt", io_pins::FUNCTION_FAULT }, { "INHibit", io_pins::FUNCTION_INHIBIT }, { "ONCouple", io_pins::FUNCTION_ON_COUPLE }, - { "TINPut", io_pins::FUNCTION_TINPUT }, + { "SYSTrig", io_pins::FUNCTION_SYSTRIG }, { "TOUTput", io_pins::FUNCTION_TOUTPUT }, { "PWM", io_pins::FUNCTION_PWM }, + { "DLOGTrig", io_pins::FUNCTION_DLOGTRIG }, SCPI_CHOICE_LIST_END }; scpi_result_t scpi_cmd_systemDigitalPinFunction(scpi_t *context) { @@ -1340,21 +1341,31 @@ scpi_result_t scpi_cmd_systemDigitalPinFunction(scpi_t *context) { pin--; if (pin < 2) { - if (function != io_pins::FUNCTION_NONE && function != io_pins::FUNCTION_INPUT && - function != io_pins::FUNCTION_INHIBIT && function != io_pins::FUNCTION_TINPUT) { + if ( + function != io_pins::FUNCTION_NONE && + function != io_pins::FUNCTION_INPUT && + function != io_pins::FUNCTION_INHIBIT && + function != io_pins::FUNCTION_SYSTRIG && + function != io_pins::FUNCTION_DLOGTRIG + ) { SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } } else { - if (function != io_pins::FUNCTION_NONE && function != io_pins::FUNCTION_OUTPUT && - function != io_pins::FUNCTION_FAULT && function != io_pins::FUNCTION_ON_COUPLE && - function != io_pins::FUNCTION_TOUTPUT && !(pin == DOUT2 && function == io_pins::FUNCTION_PWM)) { + if ( + function != io_pins::FUNCTION_NONE && + function != io_pins::FUNCTION_OUTPUT && + function != io_pins::FUNCTION_FAULT && + function != io_pins::FUNCTION_ON_COUPLE && + function != io_pins::FUNCTION_TOUTPUT && + !(pin == DOUT2 && function == io_pins::FUNCTION_PWM) + ) { SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } } - persist_conf::setIoPinFunction(pin, function); + io_pins::setPinFunction(pin, function); return SCPI_RES_OK; } @@ -1369,7 +1380,7 @@ scpi_result_t scpi_cmd_systemDigitalPinFunctionQ(scpi_t *context) { pin--; - resultChoiceName(context, functionChoice, persist_conf::devConf.ioPins[pin].function); + resultChoiceName(context, functionChoice, io_pins::g_ioPins[pin].function); return SCPI_RES_OK; } @@ -1393,7 +1404,7 @@ scpi_result_t scpi_cmd_systemDigitalPinPolarity(scpi_t *context) { return SCPI_RES_ERR; } - persist_conf::setIoPinPolarity(pin, polarity); + io_pins::setPinPolarity(pin, polarity); return SCPI_RES_OK; } @@ -1408,7 +1419,7 @@ scpi_result_t scpi_cmd_systemDigitalPinPolarityQ(scpi_t *context) { pin--; - resultChoiceName(context, polarityChoice, persist_conf::devConf.ioPins[pin].polarity); + resultChoiceName(context, polarityChoice, io_pins::g_ioPins[pin].polarity); return SCPI_RES_OK; } @@ -1426,7 +1437,7 @@ scpi_result_t scpi_cmd_systemDigitalOutputPwmFrequency(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_PWM) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_PWM) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } @@ -1480,7 +1491,7 @@ scpi_result_t scpi_cmd_systemDigitalOutputPwmFrequencyQ(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_PWM) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_PWM) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } @@ -1503,7 +1514,7 @@ scpi_result_t scpi_cmd_systemDigitalOutputPwmDuty(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_PWM) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_PWM) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } @@ -1557,7 +1568,7 @@ scpi_result_t scpi_cmd_systemDigitalOutputPwmDutyQ(scpi_t *context) { pin--; - if (persist_conf::devConf.ioPins[pin].function != io_pins::FUNCTION_PWM) { + if (io_pins::g_ioPins[pin].function != io_pins::FUNCTION_PWM) { SCPI_ErrorPush(context, SCPI_ERROR_DIGITAL_PIN_FUNCTION_MISMATCH); return SCPI_RES_ERR; } diff --git a/src/eez/modules/psu/scpi/trigger.cpp b/src/eez/modules/psu/scpi/trigger.cpp index 1c8e10b0d..ae9b93883 100644 --- a/src/eez/modules/psu/scpi/trigger.cpp +++ b/src/eez/modules/psu/scpi/trigger.cpp @@ -63,7 +63,7 @@ scpi_result_t scpi_cmd_triggerSequenceDelay(scpi_t *context) { } scpi_result_t scpi_cmd_triggerSequenceDelayQ(scpi_t *context) { - SCPI_ResultFloat(context, trigger::getDelay()); + SCPI_ResultFloat(context, trigger::g_triggerDelay); return SCPI_RES_OK; } @@ -75,19 +75,11 @@ scpi_result_t scpi_cmd_triggerSequenceSource(scpi_t *context) { trigger::setSource((trigger::Source)source); - if (source == trigger::SOURCE_PIN1) { - persist_conf::setIoPinFunction(0, io_pins::FUNCTION_TINPUT); - } - - if (source == trigger::SOURCE_PIN2) { - persist_conf::setIoPinFunction(1, io_pins::FUNCTION_TINPUT); - } - return SCPI_RES_OK; } scpi_result_t scpi_cmd_triggerSequenceSourceQ(scpi_t *context) { - resultChoiceName(context, sourceChoice, trigger::getSource()); + resultChoiceName(context, sourceChoice, trigger::g_triggerSource); return SCPI_RES_OK; } @@ -159,7 +151,7 @@ scpi_result_t scpi_cmd_initiateContinuous(scpi_t *context) { } scpi_result_t scpi_cmd_initiateContinuousQ(scpi_t *context) { - SCPI_ResultBool(context, trigger::isContinuousInitializationEnabled() ? 1 : 0); + SCPI_ResultBool(context, trigger::g_triggerContinuousInitializationEnabled); return SCPI_RES_OK; } @@ -193,15 +185,7 @@ scpi_result_t scpi_cmd_triggerDlogSource(scpi_t *context) { return SCPI_RES_ERR; } - dlog_record::g_parameters.triggerSource = (trigger::Source)source; - - if (source == trigger::SOURCE_PIN1) { - persist_conf::setIoPinFunction(0, io_pins::FUNCTION_TINPUT); - } - - if (source == trigger::SOURCE_PIN2) { - persist_conf::setIoPinFunction(1, io_pins::FUNCTION_TINPUT); - } + dlog_record::setTriggerSource((trigger::Source)source); return SCPI_RES_OK; } diff --git a/src/eez/modules/psu/trigger.cpp b/src/eez/modules/psu/trigger.cpp index 81c7d81ab..2837516ad 100644 --- a/src/eez/modules/psu/trigger.cpp +++ b/src/eez/modules/psu/trigger.cpp @@ -34,6 +34,10 @@ namespace eez { namespace psu { namespace trigger { +Source g_triggerSource; +float g_triggerDelay; +bool g_triggerContinuousInitializationEnabled; + enum State { STATE_IDLE, STATE_INITIATED, STATE_TRIGGERED, STATE_EXECUTING }; static State g_state; static uint32_t g_triggeredTime; @@ -61,7 +65,9 @@ void setState(State newState) { } void reset() { - persist_conf::resetTrigger(); + g_triggerDelay = trigger::DELAY_DEFAULT; + setSource(trigger::SOURCE_IMMEDIATE); + g_triggerContinuousInitializationEnabled = 0; setState(STATE_IDLE); } @@ -69,35 +75,43 @@ void reset() { void init() { setState(STATE_IDLE); - if (isContinuousInitializationEnabled()) { + if (g_triggerContinuousInitializationEnabled) { initiate(); } } void setDelay(float delay) { - persist_conf::setTriggerDelay(delay); -} - -float getDelay() { - return persist_conf::devConf.triggerDelay; + g_triggerDelay = delay; } -void setSource(Source source) { - persist_conf::setTriggerSource(source); -} +void setSource(Source triggerSource) { + g_triggerSource = triggerSource; -Source getSource() { - return (Source)persist_conf::devConf.triggerSource; + if (triggerSource == trigger::SOURCE_PIN1) { + if (io_pins::g_ioPins[0].function != io_pins::FUNCTION_SYSTRIG) { + io_pins::setPinFunction(0, io_pins::FUNCTION_SYSTRIG); + } + } else if (triggerSource == trigger::SOURCE_PIN2) { + if (io_pins::g_ioPins[1].function != io_pins::FUNCTION_SYSTRIG) { + io_pins::setPinFunction(1, io_pins::FUNCTION_SYSTRIG); + } + } else { + if (io_pins::g_ioPins[0].function == io_pins::FUNCTION_SYSTRIG) { + io_pins::setPinFunction(0, io_pins::FUNCTION_NONE); + } else if (io_pins::g_ioPins[1].function == io_pins::FUNCTION_SYSTRIG) { + io_pins::setPinFunction(1, io_pins::FUNCTION_NONE); + } + } } void check(uint32_t currentTime) { - if (currentTime - g_triggeredTime > persist_conf::devConf.triggerDelay * 1000L) { + if (currentTime - g_triggeredTime > g_triggerDelay * 1000L) { startImmediately(); } } int generateTrigger(Source source, bool checkImmediatelly) { - bool seqTriggered = persist_conf::devConf.triggerSource == source && g_state == STATE_INITIATED; + bool seqTriggered = g_triggerSource == source && g_state == STATE_INITIATED; bool dlogTriggered = dlog_record::g_parameters.triggerSource == source && dlog_record::isInitiated(); @@ -132,7 +146,7 @@ bool isTriggerFinishedOnAllChannels() { } void triggerFinished() { - if (persist_conf::devConf.triggerContinuousInitializationEnabled) { + if (g_triggerContinuousInitializationEnabled) { setState(STATE_INITIATED); } else { setState(STATE_IDLE); @@ -337,7 +351,7 @@ int initiate() { setState(STATE_INITIATED); - if (persist_conf::devConf.triggerSource == SOURCE_IMMEDIATE) { + if (g_triggerSource == SOURCE_IMMEDIATE) { return trigger::generateTrigger(trigger::SOURCE_IMMEDIATE); } @@ -345,7 +359,7 @@ int initiate() { } int enableInitiateContinuous(bool enable) { - persist_conf::setTriggerContinuousInitializationEnabled(enable); + g_triggerContinuousInitializationEnabled = enable; if (enable) { return initiate(); } else { @@ -353,10 +367,6 @@ int enableInitiateContinuous(bool enable) { } } -bool isContinuousInitializationEnabled() { - return persist_conf::devConf.triggerContinuousInitializationEnabled; -} - bool isIdle() { return g_state == STATE_IDLE; } diff --git a/src/eez/modules/psu/trigger.h b/src/eez/modules/psu/trigger.h index 232cb1c32..a5c369b7c 100644 --- a/src/eez/modules/psu/trigger.h +++ b/src/eez/modules/psu/trigger.h @@ -34,14 +34,16 @@ enum Source { SOURCE_PIN2 }; +extern Source g_triggerSource; +extern float g_triggerDelay; +extern bool g_triggerContinuousInitializationEnabled; + void init(); void reset(); void setDelay(float delay); -float getDelay(); void setSource(Source source); -Source getSource(); void setVoltage(Channel &channel, float value); float getVoltage(Channel &channel); @@ -54,7 +56,6 @@ int startImmediately(); void startImmediatelyInPsuThread(); int initiate(); int enableInitiateContinuous(bool enable); -bool isContinuousInitializationEnabled(); void setTriggerFinished(Channel &channel); bool isIdle(); bool isInitiated();