Skip to content

Commit

Permalink
@19
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jun 14, 2021
1 parent 1caad20 commit 14aff78
Show file tree
Hide file tree
Showing 14 changed files with 371 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/eez/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,15 +953,19 @@ void action_io_pin_select_uart_mode() {
}

void action_io_pin_select_uart_baud() {
((SysSettingsIOPinsPage *)getActivePage())->selectUartBaudRate();
}

void action_io_pin_select_uart_data_bits() {
((SysSettingsIOPinsPage *)getActivePage())->selectUartDataBits();
}

void action_io_pin_select_uart_parity() {
((SysSettingsIOPinsPage *)getActivePage())->selectUartParity();
}

void action_io_pin_select_uart_stop_bits() {
((SysSettingsIOPinsPage *)getActivePage())->selectUartStopBits();
}

void action_ntp_toggle() {
Expand Down
7 changes: 4 additions & 3 deletions src/eez/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,10 @@ void updateSpiIrqPin(int slotIndex) {
}
}

/* EXTI interrupt init*/
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
#if defined(EEZ_PLATFORM_STM32)
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
#endif
}

} // namespace eez
61 changes: 55 additions & 6 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <eez/hmi.h>
#include <eez/uart.h>
#include <eez/usb.h>
#include <eez/function_generator.h>

#include <eez/fs_driver.h>

Expand Down Expand Up @@ -313,6 +314,36 @@ EnumItem g_enumDefinition_UART_MODE[] = {
{ 0, 0 }
};

EnumItem g_enumDefinition_UART_BAUD_RATE[] = {
{ 0, "9600" },
{ 1, "14400" },
{ 2, "19200" },
{ 3, "38400" },
{ 4, "57600" },
{ 5, "115200" },
{ 0, 0 }
};

EnumItem g_enumDefinition_UART_DATA_BITS[] = {
{ 6, "6" },
{ 7, "7" },
{ 8, "8" },
{ 0, 0 }
};

EnumItem g_enumDefinition_UART_STOP_BITS[] = {
{ 1, "1" },
{ 2, "2" },
{ 0, 0 }
};

EnumItem g_enumDefinition_UART_PARITY[] = {
{ 0, "None" },
{ 1, "Even" },
{ 2, "Odd" },
{ 0, 0 }
};

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

Value MakeValue(float value, Unit unit) {
Expand Down Expand Up @@ -4643,7 +4674,7 @@ void data_io_pin_uart_baud(DataOperationEnum operation, Cursor cursor, Value &va
if (operation == DATA_OPERATION_GET) {
SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getPage(PAGE_ID_SYS_SETTINGS_IO);
if (page) {
value = "115200";
value = (int)page->m_uartBaudRate;
}
}
}
Expand All @@ -4652,7 +4683,7 @@ void data_io_pin_uart_data_bits(DataOperationEnum operation, Cursor cursor, Valu
if (operation == DATA_OPERATION_GET) {
SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getPage(PAGE_ID_SYS_SETTINGS_IO);
if (page) {
value = "8";
value = (int)page->m_uartDataBits;
}
}
}
Expand All @@ -4661,7 +4692,7 @@ void data_io_pin_uart_parity(DataOperationEnum operation, Cursor cursor, Value &
if (operation == DATA_OPERATION_GET) {
SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getPage(PAGE_ID_SYS_SETTINGS_IO);
if (page) {
value = "Event";
value = page->m_uartParity == 0 ? "None" : page->m_uartParity == 1 ? "Even" : "Odd";
}
}
}
Expand All @@ -4670,7 +4701,7 @@ void data_io_pin_uart_stop_bits(DataOperationEnum operation, Cursor cursor, Valu
if (operation == DATA_OPERATION_GET) {
SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getPage(PAGE_ID_SYS_SETTINGS_IO);
if (page) {
value = "1";
value = (int)page->m_uartStopBits;
}
}
}
Expand Down Expand Up @@ -4833,6 +4864,7 @@ void data_overlay(DataOperationEnum operation, Cursor cursor, Value &value) {
RAMP_GRID_WIDGET,
DLOG_INFO_WIDGET,
SCRIPT_INFO_WIDGET,
FUNCTION_GENERATOR_WIDGET,
NUM_WIDGETS
};

Expand All @@ -4848,9 +4880,10 @@ void data_overlay(DataOperationEnum operation, Cursor cursor, Value &value) {
bool areRampCountersVisible = ramp::g_numChannelsWithVisibleCounters > 0;
bool isDlogVisible = !dlog_record::isIdle();
bool isScriptVisible = !mp::isIdle();
bool isFunctionGeneratorVisible = function_generator::isActive();

int state = 0;
if (areListCountersVisible || areRampCountersVisible || isDlogVisible || isScriptVisible) {
if (areListCountersVisible || areRampCountersVisible || isDlogVisible || isScriptVisible || isFunctionGeneratorVisible) {
state = 0;

if (list::g_numChannelsWithVisibleCounters > 0) {
Expand Down Expand Up @@ -4884,6 +4917,10 @@ void data_overlay(DataOperationEnum operation, Cursor cursor, Value &value) {
if (isScriptVisible) {
state |= 0x4000;
}

if (isFunctionGeneratorVisible) {
state |= 0x10000;
}
}

if (overlay.state != state) {
Expand All @@ -4899,9 +4936,10 @@ void data_overlay(DataOperationEnum operation, Cursor cursor, Value &value) {
const Widget *rampGridWidget = GET_WIDGET_LIST_ELEMENT(containerWidget->widgets, RAMP_GRID_WIDGET);
const Widget *dlogInfoWidget = GET_WIDGET_LIST_ELEMENT(containerWidget->widgets, DLOG_INFO_WIDGET);
const Widget *scriptInfoWidget = GET_WIDGET_LIST_ELEMENT(containerWidget->widgets, SCRIPT_INFO_WIDGET);
const Widget *functionGeneratorWidget = GET_WIDGET_LIST_ELEMENT(containerWidget->widgets, FUNCTION_GENERATOR_WIDGET);

overlay.width = widgetCursor.widget->w;
if (list::g_numChannelsWithVisibleCounters <= 1 && ramp::g_numChannelsWithVisibleCounters <= 1 && !isDlogVisible && !isScriptVisible) {
if (list::g_numChannelsWithVisibleCounters <= 1 && ramp::g_numChannelsWithVisibleCounters <= 1 && !isDlogVisible && !isScriptVisible && !isFunctionGeneratorVisible) {
overlay.width -= listGridWidget->w / 2;
}

Expand Down Expand Up @@ -4989,6 +5027,17 @@ void data_overlay(DataOperationEnum operation, Cursor cursor, Value &value) {
overlay.height -= scriptInfoWidget->h;
}

if (isFunctionGeneratorVisible) {
widgetOverrides[FUNCTION_GENERATOR_WIDGET].isVisible = true;
widgetOverrides[FUNCTION_GENERATOR_WIDGET].x = functionGeneratorWidget->x;
widgetOverrides[FUNCTION_GENERATOR_WIDGET].y = overlay.height - (widgetCursor.widget->h - functionGeneratorWidget->y);
widgetOverrides[FUNCTION_GENERATOR_WIDGET].w = functionGeneratorWidget->w;
widgetOverrides[FUNCTION_GENERATOR_WIDGET].h = functionGeneratorWidget->h;
} else {
widgetOverrides[FUNCTION_GENERATOR_WIDGET].isVisible = false;
overlay.height -= functionGeneratorWidget->h;
}

overlay.x = 480 - overlay.width;
overlay.y = 240 - overlay.height;
}
Expand Down
6 changes: 5 additions & 1 deletion src/eez/modules/psu/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ namespace gui {
ENUM_DEFINITION(CALIBRATION_VALUE_TYPE) \
ENUM_DEFINITION(USB_MODE) \
ENUM_DEFINITION(USB_DEVICE_CLASS) \
ENUM_DEFINITION(UART_MODE)
ENUM_DEFINITION(UART_MODE) \
ENUM_DEFINITION(UART_BAUD_RATE) \
ENUM_DEFINITION(UART_DATA_BITS) \
ENUM_DEFINITION(UART_STOP_BITS) \
ENUM_DEFINITION(UART_PARITY)

#define ENUM_DEFINITION(NAME) ENUM_DEFINITION_##NAME,
enum EnumDefinition {
Expand Down
91 changes: 89 additions & 2 deletions src/eez/modules/psu/gui/page_sys_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ void SysSettingsIOPinsPage::pageAlloc() {
}

m_uartMode = m_uartModeOrig = io_pins::g_uartMode;

m_uartBaudRate = m_uartBaudRateOrig = io_pins::g_uartBaudRate;
m_uartDataBits = m_uartDataBitsOrig = io_pins::g_uartDataBits;
m_uartStopBits = m_uartStopBitsOrig = io_pins::g_uartStopBits;
m_uartParity = m_uartParityOrig = io_pins::g_uartParity;
}

void SysSettingsIOPinsPage::togglePolarity() {
Expand Down Expand Up @@ -925,6 +930,76 @@ void SysSettingsIOPinsPage::selectUartMode() {
pushSelectFromEnumPage(ENUM_DEFINITION_UART_MODE, m_uartMode, 0, onUartModeSet);
}

void SysSettingsIOPinsPage::onUartBaudRateSet(uint16_t value) {
popPage();

SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getActivePage();
if (value == 1) {
page->m_uartBaudRate = 14400;
} else if (value == 2) {
page->m_uartBaudRate = 19200;
} else if (value == 3) {
page->m_uartBaudRate = 38400;
} else if (value == 4) {
page->m_uartBaudRate = 57600;
} else if (value == 5) {
page->m_uartBaudRate = 115200;
} else {
page->m_uartBaudRate = 9600;
}
}

void SysSettingsIOPinsPage::selectUartBaudRate() {
uint16_t value;
if (m_uartBaudRate == 14400) {
value = 1;
} else if (m_uartBaudRate == 19200) {
value = 2;
} else if (m_uartBaudRate == 38400) {
value = 3;
} else if (m_uartBaudRate == 57600) {
value = 4;
} else if (m_uartBaudRate == 115200) {
value = 5;
} else {
value = 0;
}
pushSelectFromEnumPage(ENUM_DEFINITION_UART_BAUD_RATE, value, 0, onUartBaudRateSet);
}

void SysSettingsIOPinsPage::onUartDataBitsSet(uint16_t value) {
popPage();

SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getActivePage();
page->m_uartDataBits = value;
}

void SysSettingsIOPinsPage::selectUartDataBits() {
pushSelectFromEnumPage(ENUM_DEFINITION_UART_DATA_BITS, m_uartDataBits, 0, onUartDataBitsSet);
}

void SysSettingsIOPinsPage::onUartParitySet(uint16_t value) {
popPage();

SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getActivePage();
page->m_uartParity = value;
}

void SysSettingsIOPinsPage::selectUartParity() {
pushSelectFromEnumPage(ENUM_DEFINITION_UART_PARITY, m_uartParity, 0, onUartParitySet);
}

void SysSettingsIOPinsPage::onUartStopBitsSet(uint16_t value) {
popPage();

SysSettingsIOPinsPage *page = (SysSettingsIOPinsPage *)getActivePage();
page->m_uartStopBits = value;
}

void SysSettingsIOPinsPage::selectUartStopBits() {
pushSelectFromEnumPage(ENUM_DEFINITION_UART_STOP_BITS, m_uartStopBits, 0, onUartStopBitsSet);
}

int SysSettingsIOPinsPage::getDirty() {
for (int i = 0; i < NUM_IO_PINS; ++i) {
if (m_polarityOrig[i] != m_polarity[i] || m_functionOrig[i] != m_function[i]) {
Expand All @@ -936,7 +1011,7 @@ int SysSettingsIOPinsPage::getDirty() {
}
}
}
if (m_uartMode != m_uartModeOrig) {
if (m_uartMode != m_uartModeOrig || m_uartBaudRate != m_uartBaudRateOrig || m_uartDataBits != m_uartDataBitsOrig || m_uartStopBits != m_uartStopBitsOrig || m_uartParity != m_uartParityOrig) {
return true;
}
return false;
Expand All @@ -945,20 +1020,32 @@ int SysSettingsIOPinsPage::getDirty() {
void SysSettingsIOPinsPage::set() {
if (getDirty()) {
io_pins::g_uartMode = m_uartMode;
io_pins::g_uartBaudRate = m_uartBaudRate;
io_pins::g_uartDataBits = m_uartDataBits;
io_pins::g_uartStopBits = m_uartStopBits;
io_pins::g_uartParity = m_uartParity;

bool uartReinitialized = false;

for (int i = 0; i < NUM_IO_PINS; 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]);
uartReinitialized = true;
}
if (g_pwmDutyOrig[i - DOUT1] != g_pwmDuty[i - DOUT1]) {
io_pins::setPwmDuty(i, g_pwmDuty[i - DOUT1]);
uartReinitialized = true;
}
}
}


if (!uartReinitialized) {
uart::reinit();
}

pageAlloc();
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/eez/modules/psu/gui/page_sys_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,23 @@ class SysSettingsIOPinsPage : public SetPage {
void setPwmDuty(int pin, float duty);
float getPwmDuty(int pin);

void selectUartMode();
void selectUartMode();
void selectUartBaudRate();
void selectUartDataBits();
void selectUartStopBits();
void selectUartParity();

int getDirty();
void set();

io_pins::Polarity m_polarity[NUM_IO_PINS];
io_pins::Function m_function[NUM_IO_PINS];

uart::UartMode m_uartMode;
uart::UartMode m_uartMode;
uint32_t m_uartBaudRate;
uint32_t m_uartDataBits;
uint32_t m_uartStopBits;
uint32_t m_uartParity;

private:
int pinNumber;
Expand All @@ -339,10 +347,18 @@ class SysSettingsIOPinsPage : public SetPage {
float g_pwmDutyOrig[NUM_IO_PINS - DOUT1];
float g_pwmDuty[NUM_IO_PINS - DOUT1];

uart::UartMode m_uartModeOrig;
uart::UartMode m_uartModeOrig;
uint32_t m_uartBaudRateOrig;
uint32_t m_uartDataBitsOrig;
uint32_t m_uartStopBitsOrig;
uint32_t m_uartParityOrig;

static void onFunctionSet(uint16_t value);
static void onUartModeSet(uint16_t value);
static void onUartModeSet(uint16_t value);
static void onUartBaudRateSet(uint16_t value);
static void onUartDataBitsSet(uint16_t value);
static void onUartStopBitsSet(uint16_t value);
static void onUartParitySet(uint16_t value);
};

class SysSettingsTrackingPage : public SetPage {
Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/psu/io_pins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ static uint32_t g_pwmPeriodInt[NUM_IO_PINS - DOUT1];
static bool g_pwmStarted;

uart::UartMode g_uartMode;
uint32_t g_uartBaudRate = 115200;
uint32_t g_uartDataBits = 8;
uint32_t g_uartStopBits = 1;
uint32_t g_uartParity = 1;

#if defined EEZ_PLATFORM_STM32
static float g_pwmStartedFrequency;
Expand Down
Loading

0 comments on commit 14aff78

Please sign in to comment.