diff --git a/CMakeLists.txt b/CMakeLists.txt index 8861073..e8f8cda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,15 @@ option(EMBLINK_STUDIO_BUILD_TESTS "Build the Qt tests" ON) find_package(Qt6 6.8 REQUIRED COMPONENTS Core Gui Widgets LinguistTools) qt_standard_project_setup() -# The Python that runs the core during development (spec section 11, question 4). +# The Python that runs the core during development (spec section 11, question 4): the core's own +# environment when it exists (docs/development.md makes it in core/.venv), so the core runs with +# its dependencies, PyYAML for the RTOS's generator among them; any Python 3.11+ otherwise. +foreach(candidate "${PROJECT_SOURCE_DIR}/core/.venv/bin/python" + "${PROJECT_SOURCE_DIR}/core/.venv/Scripts/python.exe") + if(NOT DEFINED Python3_EXECUTABLE AND EXISTS "${candidate}") + set(Python3_EXECUTABLE "${candidate}") + endif() +endforeach() find_package(Python3 3.11 REQUIRED COMPONENTS Interpreter) if(EMBLINK_STUDIO_BUILD_TESTS) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index e81a3eb..c589148 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -11,6 +11,7 @@ qt_add_library(emblink_studio_corelink STATIC src/framing.cpp src/framing.h src/coreclient.cpp src/coreclient.h + src/session.cpp src/session.h ) target_include_directories(emblink_studio_corelink PUBLIC src) target_link_libraries(emblink_studio_corelink PUBLIC Qt6::Core) @@ -34,6 +35,8 @@ qt_add_library(emblink_studio_ui STATIC src/segmentedcontrol.cpp src/segmentedcontrol.h src/language.cpp src/language.h src/settingsdialog.cpp src/settingsdialog.h + src/boardview.cpp src/boardview.h + src/problemsview.cpp src/problemsview.h ) target_include_directories(emblink_studio_ui PUBLIC src) target_link_libraries(emblink_studio_ui PUBLIC Qt6::Widgets) @@ -75,7 +78,7 @@ set_target_properties(emblinkstudio PROPERTIES # source. `cmake --build --preset dev --target update_translations` refreshes the .ts files # from the sources; translate them in Qt Linguist. They are compiled into the frame library. qt_add_translations(TARGETS emblink_studio_ui - SOURCE_TARGETS emblinkstudio emblink_studio_ui + SOURCE_TARGETS emblinkstudio emblink_studio_ui emblink_studio_corelink TS_FILES i18n/emblinkstudio_fr.ts i18n/emblinkstudio_zh_CN.ts RESOURCE_PREFIX /i18n LUPDATE_OPTIONS -no-obsolete -locations none @@ -101,8 +104,14 @@ if(EMBLINK_STUDIO_BUILD_TESTS) endforeach() # qt_standard_project_setup() makes executables GUI programs on Windows and bundles on # macOS; a test is a console program, so its output reaches CTest on every system. + qt_add_executable(tst_session tests/tst_session.cpp) + target_link_libraries(tst_session PRIVATE emblink_studio_corelink emblink_studio_ui Qt6::Test) + target_compile_definitions(tst_session PRIVATE + EMBLINK_STUDIO_FAKE_HWGEN="${PROJECT_SOURCE_DIR}/core/tests/fake_hwgen.py") + add_test(NAME tst_session COMMAND tst_session) + set_target_properties(tst_framing tst_coreclient tst_workbench tst_theme tst_segmentedcontrol - tst_language PROPERTIES WIN32_EXECUTABLE OFF MACOSX_BUNDLE OFF) + tst_language tst_session PROPERTIES WIN32_EXECUTABLE OFF MACOSX_BUNDLE OFF) target_compile_definitions(tst_theme PRIVATE EMBLINK_STUDIO_TOKENS="${PROJECT_SOURCE_DIR}/docs/design/tokens.json") endif() diff --git a/app/i18n/emblinkstudio_fr.ts b/app/i18n/emblinkstudio_fr.ts index e58b6b9..795a0af 100644 --- a/app/i18n/emblinkstudio_fr.ts +++ b/app/i18n/emblinkstudio_fr.ts @@ -1,6 +1,168 @@ + + emblinkstudio::BoardView + + Open a board of an EmbLinkRTOS checkout to see its model. + Ouvrez une carte d’une copie locale d’EmbLinkRTOS pour voir son modèle. + + + %1 has no generated model yet. Generate it to see its chip, clocks, memory and pins. + %1 n’a pas encore de modèle généré. Générez-le pour voir sa puce, ses horloges, sa mémoire et ses broches. + + + Chip + Puce + + + Part + Référence + + + Core + Cœur + + + FPU + FPU + + + Package + Boîtier + + + CPU clock + Horloge du CPU + + + Debug + Débogage + + + Revision + Révision + + + Description + Description + + + Curated + Vérifiée + + + Not curated yet + Pas encore vérifiée + + + Console + Console + + + %1 at %2 baud + %1 à %2 bauds + + + LED %1 + LED %1 + + + Button %1 + Bouton %1 + + + Debug probe + Sonde de débogage + + + Board + Carte + + + Source + Source + + + PLL output (VCO) + Sortie de la PLL (VCO) + + + CPU + CPU + + + Bus %1 + Bus %1 + + + Flash wait states + États d’attente de la flash + + + Clocks + Horloges + + + %1 at %2 + %1 à %2 + + + Partition %1 + Partition %1 + + + Memory + Mémoire + + + Pins in use + Broches utilisées + + + Devices + Dispositifs + + + + emblinkstudio::CoreClient + + Could not start EmbLink Studio Core (%1): %2 + Impossible de démarrer EmbLink Studio Core (%1) : %2 + + + EmbLink Studio Core speaks protocol %1; this EmbLink Studio needs %2.x. + EmbLink Studio Core parle le protocole %1 ; cet EmbLink Studio a besoin de %2.x. + + + (none) + (aucun) + + + EmbLink Studio Core refused to initialize (%1): %2 + EmbLink Studio Core a refusé de s’initialiser (%1) : %2 + + + EmbLink Studio Core sent a malformed frame: %1 + EmbLink Studio Core a envoyé une trame mal formée : %1 + + + dropped a frame that is not JSON: %1 + trame ignorée, ce n’est pas du JSON : %1 + + + a response with no matching request: id %1 + une réponse sans requête correspondante : id %1 + + + error %1: %2 + erreur %1 : %2 + + + EmbLink Studio Core exited (code %1) before it initialized. + EmbLink Studio Core s’est arrêté (code %1) avant son initialisation. + + emblinkstudio::MainWindow @@ -15,10 +177,6 @@ EmbLink Studio EmbLink Studio - - No project open - Aucun projet ouvert - Configure Configurer @@ -47,6 +205,18 @@ Core log Journal du Core + + No board open + Aucune carte ouverte + + + Board + Carte + + + Problems + Problèmes + &Restart the core &Redémarrer le Core @@ -55,6 +225,30 @@ &File &Fichier + + &Open Board... + &Ouvrir une carte... + + + Open &Recent + Ouvrir un élément &récent + + + &Close Board + &Fermer la carte + + + &Board + &Carte + + + &Validate + &Valider + + + &Generate + &Générer + &Settings... &Réglages... @@ -87,6 +281,30 @@ &About EmbLink Studio À &propos d’EmbLink Studio + + Open a board of an EmbLinkRTOS checkout, such as boards/st/nucleo_f446re + Ouvrir une carte d’une copie locale d’EmbLinkRTOS, par exemple boards/st/nucleo_f446re + + + No recent boards + Aucune carte récente + + + Trust this checkout? + Faire confiance à cette copie locale ? + + + Validating and generating run the generator of the EmbLinkRTOS checkout at %1, which is code from that checkout. + Valider et générer exécutent le générateur de la copie locale d’EmbLinkRTOS située dans %1, c’est-à-dire du code provenant de cette copie. + + + Trust it only if you know where it comes from. EmbLink Studio remembers your answer for this checkout. + Ne lui faites confiance que si vous savez d’où elle vient. EmbLink Studio retient votre réponse pour cette copie. + + + Trust and Continue + Faire confiance et continuer + Starting EmbLink Studio Core... Démarrage d’EmbLink Studio Core... @@ -132,6 +350,58 @@ Nom de cette disposition, par exemple Débogage : + + emblinkstudio::ProblemsView + + Validate + Valider + + + Problem + Problème + + + Where + Emplacement + + + Open a board to see what the generator says about it. + Ouvrez une carte pour voir ce qu’en dit le générateur. + + + Not validated yet. + Pas encore validée. + + + No problems: the generator accepts this board. + Aucun problème : le générateur accepte cette carte. + + + Valid, with %n warning(s). + + Valide, avec %n avertissement. + Valide, avec %n avertissements. + + + + %n error(s) + + %n erreur + %n erreurs + + + + %n warning(s) + + %n avertissement + %n avertissements + + + + The generator refuses this board as it is. + Le générateur refuse cette carte en l’état. + + emblinkstudio::SettingsDialog diff --git a/app/i18n/emblinkstudio_zh_CN.ts b/app/i18n/emblinkstudio_zh_CN.ts index 51cca50..587f951 100644 --- a/app/i18n/emblinkstudio_zh_CN.ts +++ b/app/i18n/emblinkstudio_zh_CN.ts @@ -1,6 +1,168 @@ + + emblinkstudio::BoardView + + Open a board of an EmbLinkRTOS checkout to see its model. + 打开 EmbLinkRTOS 本地仓库中的开发板以查看其模型。 + + + %1 has no generated model yet. Generate it to see its chip, clocks, memory and pins. + %1 还没有生成的模型。生成后即可查看其芯片、时钟、内存和引脚。 + + + Chip + 芯片 + + + Part + 型号 + + + Core + 内核 + + + FPU + FPU + + + Package + 封装 + + + CPU clock + CPU 时钟 + + + Debug + 调试 + + + Revision + 版本 + + + Description + 描述 + + + Curated + 已审核 + + + Not curated yet + 尚未审核 + + + Console + 控制台 + + + %1 at %2 baud + %1,%2 波特 + + + LED %1 + LED %1 + + + Button %1 + 按键 %1 + + + Debug probe + 调试探针 + + + Board + 开发板 + + + Source + 时钟源 + + + PLL output (VCO) + PLL 输出(VCO) + + + CPU + CPU + + + Bus %1 + 总线 %1 + + + Flash wait states + 闪存等待周期 + + + Clocks + 时钟 + + + %1 at %2 + %1,位于 %2 + + + Partition %1 + 分区 %1 + + + Memory + 内存 + + + Pins in use + 已用引脚 + + + Devices + 设备 + + + + emblinkstudio::CoreClient + + Could not start EmbLink Studio Core (%1): %2 + 无法启动 EmbLink Studio Core(%1):%2 + + + EmbLink Studio Core speaks protocol %1; this EmbLink Studio needs %2.x. + EmbLink Studio Core 使用协议 %1;此 EmbLink Studio 需要 %2.x。 + + + (none) + (无) + + + EmbLink Studio Core refused to initialize (%1): %2 + EmbLink Studio Core 拒绝初始化(%1):%2 + + + EmbLink Studio Core sent a malformed frame: %1 + EmbLink Studio Core 发送了格式错误的帧:%1 + + + dropped a frame that is not JSON: %1 + 已丢弃非 JSON 帧:%1 + + + a response with no matching request: id %1 + 没有对应请求的响应:id %1 + + + error %1: %2 + 错误 %1:%2 + + + EmbLink Studio Core exited (code %1) before it initialized. + EmbLink Studio Core 在初始化之前退出(代码 %1)。 + + emblinkstudio::MainWindow @@ -15,10 +177,6 @@ EmbLink Studio EmbLink Studio - - No project open - 未打开项目 - Configure 配置 @@ -47,6 +205,18 @@ Core log Core 日志 + + No board open + 未打开开发板 + + + Board + 开发板 + + + Problems + 问题 + &Restart the core 重新启动 Core(&R) @@ -55,6 +225,30 @@ &File 文件(&F) + + &Open Board... + 打开开发板(&O)... + + + Open &Recent + 最近打开(&R) + + + &Close Board + 关闭开发板(&C) + + + &Board + 开发板(&B) + + + &Validate + 校验(&V) + + + &Generate + 生成(&G) + &Settings... 设置(&S)... @@ -87,6 +281,30 @@ &About EmbLink Studio 关于 EmbLink Studio(&A) + + Open a board of an EmbLinkRTOS checkout, such as boards/st/nucleo_f446re + 打开 EmbLinkRTOS 本地仓库中的开发板,例如 boards/st/nucleo_f446re + + + No recent boards + 没有最近的开发板 + + + Trust this checkout? + 信任此本地仓库? + + + Validating and generating run the generator of the EmbLinkRTOS checkout at %1, which is code from that checkout. + 校验和生成会运行位于 %1 的 EmbLinkRTOS 本地仓库中的生成器,也就是来自该仓库的代码。 + + + Trust it only if you know where it comes from. EmbLink Studio remembers your answer for this checkout. + 仅在你了解其来源时才信任它。EmbLink Studio 会记住你对此仓库的选择。 + + + Trust and Continue + 信任并继续 + Starting EmbLink Studio Core... 正在启动 EmbLink Studio Core... @@ -132,6 +350,55 @@ 此布局的名称,例如“调试”: + + emblinkstudio::ProblemsView + + Validate + 校验 + + + Problem + 问题 + + + Where + 位置 + + + Open a board to see what the generator says about it. + 打开开发板以查看生成器的结论。 + + + Not validated yet. + 尚未校验。 + + + No problems: the generator accepts this board. + 没有问题:生成器接受此开发板。 + + + Valid, with %n warning(s). + + 有效,有 %n 个警告。 + + + + %n error(s) + + %n 个错误 + + + + %n warning(s) + + %n 个警告 + + + + The generator refuses this board as it is. + 生成器不接受此开发板的当前配置。 + + emblinkstudio::SettingsDialog diff --git a/app/src/boardview.cpp b/app/src/boardview.cpp new file mode 100644 index 0000000..c36c2d4 --- /dev/null +++ b/app/src/boardview.cpp @@ -0,0 +1,311 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file boardview.cpp + * @brief Implementation of BoardView: the groups and rows, built from hw.json's sections. + * + * @details + * render() rebuilds the content from the last model and runs again on a language + * change. A value missing from the model shows as a dash rather than a guess. Technical + * values (pins, addresses, names in the description) are set in the code font, which + * is never translated. + * + * @see boardview.h + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#include "boardview.h" +#include "theme.h" + +#include +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +namespace +{ + +QString dash() +{ + return QStringLiteral("—"); +} + +QString text(const QJsonValue &v) +{ + if (v.isString()) + return v.toString(); + if (v.isDouble()) + return QLocale().toString(v.toDouble(), 'g', 12); + if (v.isBool()) + return v.toBool() ? QStringLiteral("✓") : dash(); + return dash(); +} + +QString hex(double value) +{ + return QStringLiteral("0x%1") + .arg(qulonglong(value), 8, 16, QLatin1Char('0')) + .toUpper() + .replace(QStringLiteral("0X"), QStringLiteral("0x")); +} + +} // namespace + +QString formatHz(double hz) +{ + const QLocale locale; + if (hz >= 1e6) + return locale.toString(hz / 1e6, 'g', 6) + QStringLiteral(" MHz"); + if (hz >= 1e3) + return locale.toString(hz / 1e3, 'g', 6) + QStringLiteral(" kHz"); + return locale.toString(hz, 'g', 6) + QStringLiteral(" Hz"); +} + +QString formatBytes(double bytes) +{ + const QLocale locale; + if (bytes >= 1024.0 * 1024.0) + return locale.toString(bytes / (1024.0 * 1024.0), 'g', 4) + QStringLiteral(" MB"); + if (bytes >= 1024.0) + return locale.toString(bytes / 1024.0, 'g', 4) + QStringLiteral(" KB"); + return locale.toString(bytes, 'g', 6) + QStringLiteral(" B"); +} + +BoardView::BoardView(QWidget *parent) : QScrollArea(parent) +{ + setObjectName(QStringLiteral("viewContent")); + setAttribute(Qt::WA_StyledBackground, true); + setWidgetResizable(true); + setFrameShape(QFrame::NoFrame); + m_content = new QWidget(this); + m_content->setObjectName(QStringLiteral("viewContent")); + m_content->setAttribute(Qt::WA_StyledBackground, true); + m_layout = new QVBoxLayout(m_content); + m_layout->setContentsMargins(18, 16, 18, 20); + m_layout->setSpacing(6); + setWidget(m_content); + render(); +} + +void BoardView::setModel(const QJsonObject &status, const QJsonObject &describe, + const QJsonObject &clocks, const QJsonObject &memory, + const QJsonObject &pins) +{ + m_status = status; + m_describe = describe; + m_clocks = clocks; + m_memory = memory; + m_pins = pins; + render(); +} + +QString BoardView::value(const QString &group, const QString &label) const +{ + return m_values.value(group + QLatin1Char('/') + label); +} + +void BoardView::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + render(); + QScrollArea::changeEvent(event); +} + +void BoardView::addGroup(const QString &title, const QList> &rows) +{ + if (rows.isEmpty()) + return; + const Theme &theme = Theme::current(); + m_groupTitles.append(title); + + auto *caption = new QLabel(title, m_content); + caption->setProperty("role", QStringLiteral("caption")); + caption->setFont(theme.font(QStringLiteral("caption"))); + caption->setContentsMargins(4, 12, 0, 4); + m_layout->addWidget(caption); + + auto *group = new QFrame(m_content); + group->setProperty("role", QStringLiteral("group")); + auto *column = new QVBoxLayout(group); + column->setContentsMargins(0, 0, 0, 0); + column->setSpacing(0); + for (int i = 0; i < rows.size(); ++i) { + auto *row = new QWidget(group); + row->setProperty("role", QStringLiteral("row")); + row->setProperty("first", i == 0); + row->setAttribute(Qt::WA_StyledBackground, true); + auto *line = new QHBoxLayout(row); + line->setContentsMargins(12, 8, 12, 8); + auto *label = new QLabel(rows.at(i).first, row); + label->setFont(theme.font(QStringLiteral("bodySmall"))); + auto *value = new QLabel(rows.at(i).second, row); + value->setFont(theme.font(QStringLiteral("codeMeta"))); + value->setProperty("role", QStringLiteral("secondary")); + value->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + value->setTextInteractionFlags(Qt::TextSelectableByMouse); + value->setWordWrap(true); + line->addWidget(label); + line->addStretch(); + line->addWidget(value, 1); + column->addWidget(row); + m_values.insert(title + QLatin1Char('/') + rows.at(i).first, rows.at(i).second); + } + m_layout->addWidget(group); +} + +void BoardView::render() +{ + while (QLayoutItem *item = m_layout->takeAt(0)) { + delete item->widget(); + delete item; + } + m_groupTitles.clear(); + m_values.clear(); + const Theme &theme = Theme::current(); + + const QJsonObject board = m_describe.value(QStringLiteral("board")).toObject(); + const QJsonObject soc = m_describe.value(QStringLiteral("soc")).toObject(); + if (m_describe.isEmpty()) { + auto *empty = new QLabel(m_content); + empty->setProperty("role", QStringLiteral("secondary")); + empty->setWordWrap(true); + empty->setText(m_status.isEmpty() + ? tr("Open a board of an EmbLinkRTOS checkout to see its model.") + : tr("%1 has no generated model yet. Generate it to see its chip, " + "clocks, memory and pins.") + .arg(m_status.value(QStringLiteral("id")).toString())); + m_layout->addWidget(empty); + m_layout->addStretch(); + return; + } + + const QJsonObject cpu = soc.value(QStringLiteral("cpu")).toObject(); + auto *title = new QLabel(text(board.value(QStringLiteral("name"))), m_content); + title->setFont(theme.font(QStringLiteral("title2"))); + m_layout->addWidget(title); + QStringList facts{text(soc.value(QStringLiteral("part"))), + text(cpu.value(QStringLiteral("core"))), + text(soc.value(QStringLiteral("package"))).toUpper()}; + auto *sub = new QLabel(facts.join(QStringLiteral(" · ")), m_content); + sub->setProperty("role", QStringLiteral("secondary")); + sub->setFont(theme.font(QStringLiteral("small"))); + m_layout->addWidget(sub); + if (!board.value(QStringLiteral("doc")).toString().isEmpty()) { + auto *doc = new QLabel(board.value(QStringLiteral("doc")).toString(), m_content); + doc->setWordWrap(true); + doc->setProperty("role", QStringLiteral("quiet")); + doc->setFont(theme.font(QStringLiteral("small"))); + doc->setContentsMargins(0, 6, 0, 0); + m_layout->addWidget(doc); + } + + const QJsonObject resolved = m_clocks.value(QStringLiteral("resolved")).toObject(); + const double cpuHz = resolved.value(QStringLiteral("cpu_hz")).toDouble(); + QStringList debug; + const QJsonObject debugCaps = soc.value(QStringLiteral("debug")).toObject(); + for (auto it = debugCaps.begin(); it != debugCaps.end(); ++it) + if (it->toBool()) + debug.append(it.key().toUpper()); + addGroup(tr("Chip"), + {{tr("Part"), text(soc.value(QStringLiteral("part")))}, + {tr("Core"), text(cpu.value(QStringLiteral("core")))}, + {tr("FPU"), text(cpu.value(QStringLiteral("fpu")))}, + {tr("Package"), text(soc.value(QStringLiteral("package"))).toUpper()}, + {tr("CPU clock"), cpuHz > 0 ? formatHz(cpuHz) : dash()}, + {tr("Debug"), debug.isEmpty() ? dash() : debug.join(QStringLiteral(", "))}}); + + QList> boardRows{ + {tr("Revision"), text(board.value(QStringLiteral("revision")))}, + {tr("Description"), + board.value(QStringLiteral("curated")).toBool() ? tr("Curated") : tr("Not curated yet")}}; + const QJsonObject console = board.value(QStringLiteral("console")).toObject(); + if (!console.isEmpty()) + boardRows.append( + {tr("Console"), + tr("%1 at %2 baud") + .arg(console.value(QStringLiteral("device")).toString(), + QLocale().toString(console.value(QStringLiteral("baud")).toInt()))}); + for (const QJsonValue &led : board.value(QStringLiteral("leds")).toArray()) + boardRows.append({tr("LED %1").arg(led.toObject().value(QStringLiteral("name")).toString()), + led.toObject().value(QStringLiteral("gpio")).toString()}); + for (const QJsonValue &button : board.value(QStringLiteral("buttons")).toArray()) + boardRows.append( + {tr("Button %1").arg(button.toObject().value(QStringLiteral("name")).toString()), + button.toObject().value(QStringLiteral("gpio")).toString()}); + const QJsonObject probe = board.value(QStringLiteral("debug_probe")).toObject(); + if (!probe.isEmpty()) { + QStringList ways; + for (auto it = probe.begin(); it != probe.end(); ++it) + ways.append(it.key() + QStringLiteral(" ") + text(it.value())); + boardRows.append({tr("Debug probe"), ways.join(QStringLiteral("\n"))}); + } + addGroup(tr("Board"), boardRows); + + QList> clockRows; + if (resolved.contains(QStringLiteral("source"))) + clockRows.append( + {tr("Source"), resolved.value(QStringLiteral("source")).toString() + + QStringLiteral(" · ") + + formatHz(resolved.value(QStringLiteral("source_hz")).toDouble())}); + const QJsonObject pll = resolved.value(QStringLiteral("pll")).toObject(); + if (pll.contains(QStringLiteral("vco_hz"))) + clockRows.append( + {tr("PLL output (VCO)"), formatHz(pll.value(QStringLiteral("vco_hz")).toDouble())}); + if (cpuHz > 0) + clockRows.append({tr("CPU"), formatHz(cpuHz)}); + const QJsonObject buses = resolved.value(QStringLiteral("bus_hz")).toObject(); + for (auto it = buses.begin(); it != buses.end(); ++it) + clockRows.append({tr("Bus %1").arg(it.key().toUpper()), formatHz(it->toDouble())}); + if (resolved.contains(QStringLiteral("flash_wait_states"))) + clockRows.append( + {tr("Flash wait states"), text(resolved.value(QStringLiteral("flash_wait_states")))}); + addGroup(tr("Clocks"), clockRows); + + QList> memoryRows; + for (const QJsonValue &v : m_memory.value(QStringLiteral("regions")).toArray()) { + const QJsonObject region = v.toObject(); + memoryRows.append({region.value(QStringLiteral("name")).toString(), + tr("%1 at %2") + .arg(formatBytes(region.value(QStringLiteral("size")).toDouble()), + hex(region.value(QStringLiteral("base")).toDouble()))}); + } + for (const QJsonValue &v : m_memory.value(QStringLiteral("partitions")).toArray()) { + const QJsonObject part = v.toObject(); + memoryRows.append({tr("Partition %1").arg(part.value(QStringLiteral("name")).toString()), + tr("%1 at %2") + .arg(formatBytes(part.value(QStringLiteral("size")).toDouble()), + hex(part.value(QStringLiteral("base")).toDouble()))}); + } + addGroup(tr("Memory"), memoryRows); + + QList> pinRows; + for (const QJsonValue &v : m_pins.value(QStringLiteral("assigned")).toArray()) { + const QJsonObject pin = v.toObject(); + const QString signal = pin.value(QStringLiteral("signal")).toString(); + pinRows.append({pin.value(QStringLiteral("pin")).toString(), + (signal.isEmpty() ? pin.value(QStringLiteral("mode")).toString() : signal) + + QStringLiteral(" · ") + pin.value(QStringLiteral("owner")).toString()}); + } + addGroup(tr("Pins in use"), pinRows); + + QList> deviceRows; + for (const QJsonValue &v : m_describe.value(QStringLiteral("devices")).toArray()) { + const QJsonObject device = v.toObject(); + deviceRows.append({device.value(QStringLiteral("name")).toString(), + device.value(QStringLiteral("class")).toString()}); + } + addGroup(tr("Devices"), deviceRows); + m_layout->addStretch(); +} + +} // namespace emblinkstudio diff --git a/app/src/boardview.h b/app/src/boardview.h new file mode 100644 index 0000000..8ffa877 --- /dev/null +++ b/app/src/boardview.h @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file boardview.h + * @brief BoardView: the open board's model, read-only (stage S1). + * + * @details + * Shows what the generator resolved for the board (board.describe, clocks, memory, + * pins): the chip, the board's console, LEDs and buttons, the clock tree's frequencies, + * the memory regions, the devices and the pins in use. Each group is a rounded group + * of rows, as System Settings lays them out (design brief section 4f). Every value is + * the core's; the view only formats it for reading (180 MHz, 512 KB), in the + * interface's language. The drawn Board, Pin map and Clock tree views of stage S2 + * replace it. + * + * @see session.h; spec section 7 (Board view) + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#pragma once + +#include +#include +#include +#include + +class QLabel; +class QVBoxLayout; + +namespace emblinkstudio +{ + +class BoardView : public QScrollArea +{ + Q_OBJECT + + public: + explicit BoardView(QWidget *parent = nullptr); + + // An empty describe shows the empty state: no board, or a board not generated yet. + void setModel(const QJsonObject &status, const QJsonObject &describe, const QJsonObject &clocks, + const QJsonObject &memory, const QJsonObject &pins); + + // The groups shown, by title, for tests: "CHIP", "BOARD", "CLOCKS", ... + QStringList groupTitles() const + { + return m_groupTitles; + } + // A row's value, for tests: value("CHIP", tr("Part")). + QString value(const QString &group, const QString &label) const; + + protected: + void changeEvent(QEvent *event) override; + + private: + void render(); + void addGroup(const QString &title, const QList> &rows); + + QWidget *m_content = nullptr; + QVBoxLayout *m_layout = nullptr; + QJsonObject m_status; + QJsonObject m_describe; + QJsonObject m_clocks; + QJsonObject m_memory; + QJsonObject m_pins; + QStringList m_groupTitles; + QHash m_values; +}; + +// "180 MHz", "8 MHz", "32.768 kHz": a frequency in the interface's language. +QString formatHz(double hz); +// "512 KB", "16 KB", "1.5 MB". +QString formatBytes(double bytes); + +} // namespace emblinkstudio diff --git a/app/src/main.cpp b/app/src/main.cpp index c13b3b8..97833e0 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -18,6 +18,7 @@ * Options, for development and for the pictures in progress-screenshots/: * --language use this language for this run, without saving it * --stage open on this stage + * --open open this board of an EmbLinkRTOS checkout * --screenshot save a picture of the window to , then quit * * @see mainwindow.h, theme.h, language.h @@ -53,7 +54,11 @@ int main(int argc, char *argv[]) QStringLiteral("screenshot"), QStringLiteral("Save a picture of the window to , then quit."), QStringLiteral("file")); - parser.addOptions({languageOption, stageOption, screenshotOption}); + const QCommandLineOption openOption( + QStringLiteral("open"), + QStringLiteral("Open , a board directory of an EmbLinkRTOS checkout."), + QStringLiteral("board")); + parser.addOptions({languageOption, stageOption, openOption, screenshotOption}); parser.process(app); emblinkstudio::Language language(&app); @@ -74,12 +79,14 @@ int main(int argc, char *argv[]) emblinkstudio::MainWindow window(&language); if (parser.isSet(stageOption)) window.setStage(parser.value(stageOption)); + if (parser.isSet(openOption)) + window.openBoard(parser.value(openOption)); window.show(); if (parser.isSet(screenshotOption)) { const QString file = parser.value(screenshotOption); - // Long enough for the core to answer and the stage switch to settle. - QTimer::singleShot(1500, &window, [&window, &app, file] { + // Long enough for the core to open and validate a board, and the stage switch to settle. + QTimer::singleShot(3000, &window, [&window, &app, file] { if (!window.grab().save(file)) qWarning("Cannot save %s", qPrintable(file)); app.exit(0); diff --git a/app/src/mainwindow.cpp b/app/src/mainwindow.cpp index 3a56d2e..9aaf60f 100644 --- a/app/src/mainwindow.cpp +++ b/app/src/mainwindow.cpp @@ -27,9 +27,12 @@ * @date 2026-11-11 (created) */ +#include "boardview.h" #include "language.h" #include "mainwindow.h" +#include "problemsview.h" #include "segmentedcontrol.h" +#include "session.h" #include "settingsdialog.h" #include "theme.h" #include "workbench.h" @@ -37,19 +40,25 @@ #include #include #include +#include #include #include +#include #include +#include #include #include #include #include +#include #include #include #include #include #include +#include #include +#include namespace emblinkstudio { @@ -103,9 +112,20 @@ MainWindow::MainWindow(Language *language, QWidget *parent) m_log->setMaximumBlockCount(5000); m_log->setFont(theme.font(QStringLiteral("code"))); + m_session = new Session(&m_core, this); + m_boardView = new BoardView; + m_problems = new ProblemsView; + // The ids name the views in saved layouts: keep them stable. - m_workbench->addView(QStringLiteral("core"), QString(), coreView, ads::CenterDockWidgetArea); - m_workbench->addView(QStringLiteral("coreLog"), QString(), m_log, ads::BottomDockWidgetArea); + m_workbench->addView(QStringLiteral("board"), QString(), m_boardView, + ads::CenterDockWidgetArea); + ads::CDockWidget *problems = m_workbench->addView(QStringLiteral("problems"), QString(), + m_problems, ads::BottomDockWidgetArea); + m_workbench->addView(QStringLiteral("coreLog"), QString(), m_log, ads::BottomDockWidgetArea, + problems); + m_workbench->addView(QStringLiteral("core"), QString(), coreView, ads::BottomDockWidgetArea, + problems); + problems->setAsCurrentTab(); m_workbench->captureDefaultLayout(); buildStageBar(); @@ -121,6 +141,29 @@ MainWindow::MainWindow(Language *language, QWidget *parent) if (m_workbench->stage().isEmpty()) m_workbench->setStage(stageIds().first()); + connect(m_session, &Session::statusChanged, this, &MainWindow::retranslate); + connect(m_session, &Session::modelChanged, this, &MainWindow::showModel); + connect(m_session, &Session::diagnosticsChanged, this, [this] { + m_problems->setDiagnostics(m_session->diagnostics(), m_session->isOpen(), + m_session->hasVerdict(), m_session->isValid()); + }); + connect(m_session, &Session::busyChanged, m_problems, &ProblemsView::setBusy); + connect(m_session, &Session::opened, this, [this] { + rememberBoard(m_session->status().value(QStringLiteral("path")).toString()); + }); + connect(m_session, &Session::trustNeeded, this, + [this](const QString &checkout, Session::Action action) { + askTrust(checkout, int(action)); + }); + connect(m_session, &Session::failed, this, [this](const QString &message) { + QMessageBox::warning(this, tr("EmbLink Studio"), message); + }); + connect(m_problems, &ProblemsView::validateRequested, m_session, &Session::validate); + connect(m_problems, &ProblemsView::openRequested, this, [](const QString &file, int) { + // No editor yet (stage S8): the person's own editor opens the file. + QDesktopServices::openUrl(QUrl::fromLocalFile(file)); + }); + connect(m_restart, &QPushButton::clicked, this, &MainWindow::startCore); connect(&m_core, &CoreClient::logLine, m_log, &QPlainTextEdit::appendPlainText); connect(&m_core, &CoreClient::ready, this, [this](const QJsonObject &info) { @@ -131,6 +174,11 @@ MainWindow::MainWindow(Language *language, QWidget *parent) setStatus( [=] { return tr("Connected to %1 %2, protocol %3.").arg(name, version, protocol); }, CoreState::Connected); + // After a restart, the board that was open opens again; at start, the one asked for. + if (!m_pendingOpen.isEmpty()) + m_session->open(std::exchange(m_pendingOpen, QString())); + else + m_session->reopen(); }); connect(&m_core, &CoreClient::failed, this, [this](const QString &message) { setStatus([=] { return message; }, CoreState::Stopped); @@ -193,6 +241,12 @@ void MainWindow::buildStageBar() void MainWindow::buildMenus() { m_fileMenu = menuBar()->addMenu(QString()); + m_openAction = m_fileMenu->addAction(QString(), this, &MainWindow::chooseBoard); + m_openAction->setShortcut(QKeySequence::Open); + m_recentMenu = m_fileMenu->addMenu(QString()); + connect(m_recentMenu, &QMenu::aboutToShow, this, &MainWindow::fillRecentMenu); + m_closeAction = m_fileMenu->addAction(QString(), m_session, &Session::close); + m_fileMenu->addSeparator(); m_settingsAction = m_fileMenu->addAction(QString(), this, &MainWindow::showSettings); m_settingsAction->setShortcut(QKeySequence::Preferences); m_settingsAction->setMenuRole(QAction::PreferencesRole); @@ -217,6 +271,12 @@ void MainWindow::buildMenus() m_saveLayoutAction = m_viewMenu->addAction(QString(), this, &MainWindow::saveLayoutAs); m_resetLayoutAction = m_viewMenu->addAction(QString(), m_workbench, &Workbench::resetLayout); + m_boardMenu = menuBar()->addMenu(QString()); + m_validateAction = m_boardMenu->addAction(QString(), m_session, &Session::validate); + m_generateAction = m_boardMenu->addAction(QString(), m_session, &Session::generate); + // ⌥⌘G (design brief section 4g); Ctrl+Alt+G elsewhere. + m_generateAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_G)); + m_helpMenu = menuBar()->addMenu(QString()); m_aboutAction = m_helpMenu->addAction(QString(), this, &MainWindow::showAbout); m_aboutAction->setMenuRole(QAction::AboutRole); @@ -225,7 +285,10 @@ void MainWindow::buildMenus() void MainWindow::retranslate() { setWindowTitle(tr("EmbLink Studio")); - m_project->setText(tr("No project open")); + const QJsonObject status = m_session->status(); + m_project->setText(m_session->isOpen() ? status.value(QStringLiteral("id")).toString() + : tr("No board open")); + m_project->setToolTip(status.value(QStringLiteral("path")).toString()); const QStringList stages{tr("Configure"), tr("Code"), tr("Debug"), tr("Verify")}; for (int i = 0; i < int(stages.size()); ++i) { m_stages->setSegmentText(i, stages.at(i)); @@ -234,13 +297,24 @@ void MainWindow::retranslate() m_stages->setAccessibleName(tr("Stage")); const QList views = m_workbench->views(); - views.at(0)->setWindowTitle(tr("Core")); - views.at(1)->setWindowTitle(tr("Core log")); + views.at(0)->setWindowTitle(tr("Board")); + views.at(1)->setWindowTitle(tr("Problems")); + views.at(2)->setWindowTitle(tr("Core log")); + views.at(3)->setWindowTitle(tr("Core")); for (ads::CDockWidget *v : views) v->toggleViewAction()->setText(v->windowTitle()); m_restart->setText(tr("&Restart the core")); m_fileMenu->setTitle(tr("&File")); + m_openAction->setText(tr("&Open Board...")); + m_recentMenu->setTitle(tr("Open &Recent")); + m_closeAction->setText(tr("&Close Board")); + m_closeAction->setEnabled(m_session->isOpen()); + m_boardMenu->setTitle(tr("&Board")); + m_validateAction->setText(tr("&Validate")); + m_generateAction->setText(tr("&Generate")); + m_validateAction->setEnabled(m_session->isOpen()); + m_generateAction->setEnabled(m_session->isOpen()); m_settingsAction->setText(tr("&Settings...")); m_quitAction->setText(tr("&Quit")); m_viewMenu->setTitle(tr("&View")); @@ -272,6 +346,75 @@ QString MainWindow::stage() const return m_workbench->stage(); } +void MainWindow::openBoard(const QString &path) +{ + if (m_core.isReady()) + m_session->open(path); + else + m_pendingOpen = path; +} + +void MainWindow::chooseBoard() +{ + QSettings settings; + const QStringList recent = settings.value(QStringLiteral("recentBoards")).toStringList(); + const QString start = recent.isEmpty() ? QDir::homePath() : recent.first(); + const QString dir = QFileDialog::getExistingDirectory( + this, tr("Open a board of an EmbLinkRTOS checkout, such as boards/st/nucleo_f446re"), + start); + if (!dir.isEmpty()) + openBoard(dir); +} + +void MainWindow::rememberBoard(const QString &path) +{ + if (path.isEmpty()) + return; + QSettings settings; + QStringList recent = settings.value(QStringLiteral("recentBoards")).toStringList(); + recent.removeAll(path); + recent.prepend(path); + while (recent.size() > 8) + recent.removeLast(); + settings.setValue(QStringLiteral("recentBoards"), recent); +} + +void MainWindow::fillRecentMenu() +{ + m_recentMenu->clear(); + const QStringList recent = QSettings().value(QStringLiteral("recentBoards")).toStringList(); + if (recent.isEmpty()) { + m_recentMenu->addAction(tr("No recent boards"))->setEnabled(false); + return; + } + for (const QString &path : recent) + m_recentMenu->addAction(QDir::toNativeSeparators(path), this, + [this, path] { openBoard(path); }); +} + +void MainWindow::askTrust(const QString &checkout, int action) +{ + QMessageBox box(QMessageBox::Question, tr("Trust this checkout?"), + tr("Validating and generating run the generator of the EmbLinkRTOS checkout " + "at %1, which is code from that checkout.") + .arg(QDir::toNativeSeparators(checkout)), + QMessageBox::NoButton, this); + box.setInformativeText(tr("Trust it only if you know where it comes from. EmbLink Studio " + "remembers your answer for this checkout.")); + QPushButton *trust = box.addButton(tr("Trust and Continue"), QMessageBox::AcceptRole); + box.addButton(QMessageBox::Cancel); + box.setDefaultButton(trust); + box.exec(); + if (box.clickedButton() == trust) + m_session->trustAndRun(Session::Action(action)); +} + +void MainWindow::showModel() +{ + m_boardView->setModel(m_session->status(), m_session->describe(), m_session->clocks(), + m_session->memory(), m_session->pins()); +} + void MainWindow::startCore() { setStatus([] { return tr("Starting EmbLink Studio Core..."); }, CoreState::Starting); diff --git a/app/src/mainwindow.h b/app/src/mainwindow.h index 3f6d400..f4b65b3 100644 --- a/app/src/mainwindow.h +++ b/app/src/mainwindow.h @@ -15,9 +15,12 @@ * (Ctrl elsewhere); and below it the Workbench, where every view is a card. Each stage * keeps its own layout. * - * The views so far show whether EmbLink Studio Core is connected, with a restart when - * the core fails or stops unexpectedly, and the core's log. The window owns the - * CoreClient for the life of the application. + * The views so far: Board, the open board's model; Problems, the generator's + * diagnostics, each linked to its file; Core, whether EmbLink Studio Core is connected, + * with a restart when it fails or stops; and the core's log. The window owns the + * CoreClient and the Session (the open board) for the life of the application. Open + * Board (⌘O) opens a board of an EmbLinkRTOS checkout; the Board menu validates and + * generates it, asking first to trust the checkout when the core needs it. * * Every visible text is set in retranslate(), which runs again when the interface * language changes, so the window follows a change made in Settings at once. @@ -46,8 +49,11 @@ class QToolBar; namespace emblinkstudio { +class BoardView; class Language; +class ProblemsView; class SegmentedControl; +class Session; class Workbench; class MainWindow : public QMainWindow @@ -61,6 +67,12 @@ class MainWindow : public QMainWindow static QStringList stageIds(); void setStage(const QString &id); QString stage() const; + // Opens a board directory of an EmbLinkRTOS checkout, once the core is ready. + void openBoard(const QString &path); + Session *session() const + { + return m_session; + } protected: void closeEvent(QCloseEvent *event) override; @@ -82,6 +94,11 @@ class MainWindow : public QMainWindow void setStatus(std::function text, CoreState state); void fillLayoutsMenu(); void saveLayoutAs(); + void chooseBoard(); + void fillRecentMenu(); + void rememberBoard(const QString &path); + void askTrust(const QString &checkout, int action); + void showModel(); Language *m_language = nullptr; CoreClient m_core; @@ -95,7 +112,13 @@ class MainWindow : public QMainWindow QMenu *m_fileMenu = nullptr; QMenu *m_viewMenu = nullptr; QMenu *m_helpMenu = nullptr; + QMenu *m_boardMenu = nullptr; + QMenu *m_recentMenu = nullptr; QMenu *m_layouts = nullptr; + QAction *m_openAction = nullptr; + QAction *m_closeAction = nullptr; + QAction *m_validateAction = nullptr; + QAction *m_generateAction = nullptr; QAction *m_settingsAction = nullptr; QAction *m_quitAction = nullptr; QAction *m_saveLayoutAction = nullptr; @@ -106,6 +129,10 @@ class MainWindow : public QMainWindow QLabel *m_status = nullptr; QPushButton *m_restart = nullptr; QPlainTextEdit *m_log = nullptr; + Session *m_session = nullptr; + BoardView *m_boardView = nullptr; + ProblemsView *m_problems = nullptr; + QString m_pendingOpen; std::function m_statusText; CoreState m_coreState = CoreState::Starting; }; diff --git a/app/src/problemsview.cpp b/app/src/problemsview.cpp new file mode 100644 index 0000000..0ea2862 --- /dev/null +++ b/app/src/problemsview.cpp @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file problemsview.cpp + * @brief Implementation of ProblemsView: the summary, the list, opening a problem's file. + * + * @details + * Each row is a dot in the state's colour (danger for an error, warning for a + * warning), the message, and the place as "board.yaml:25 · pins.usart2.tx", the full + * path in its tooltip. Errors come before warnings; within each, the generator's order + * is kept. Counts use Qt's plural forms, so each language says them its own way. + * + * @see problemsview.h + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#include "problemsview.h" +#include "theme.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +namespace +{ + +constexpr int kFileRole = Qt::UserRole; +constexpr int kLineRole = Qt::UserRole + 1; + +QIcon dot(const QColor &color) +{ + QPixmap pixmap(14, 14); + pixmap.fill(Qt::transparent); + QPainter p(&pixmap); + p.setRenderHint(QPainter::Antialiasing); + p.setPen(Qt::NoPen); + p.setBrush(color); + p.drawEllipse(QRectF(3.5, 3.5, 7, 7)); + return QIcon(pixmap); +} + +} // namespace + +ProblemsView::ProblemsView(QWidget *parent) : QWidget(parent) +{ + setObjectName(QStringLiteral("viewContent")); + setAttribute(Qt::WA_StyledBackground, true); + const Theme &theme = Theme::current(); + + auto *layout = new QVBoxLayout(this); + layout->setContentsMargins(12, 10, 12, 8); + layout->setSpacing(8); + auto *header = new QHBoxLayout; + m_summary = new QLabel(this); + m_summary->setFont(theme.font(QStringLiteral("bodySmall"))); + m_summary->setWordWrap(true); + m_validate = new QPushButton(this); + header->addWidget(m_summary, 1); + header->addWidget(m_validate); + layout->addLayout(header); + + m_list = new QTreeWidget(this); + m_list->setObjectName(QStringLiteral("problems")); + m_list->setColumnCount(2); + m_list->setRootIsDecorated(false); + m_list->setUniformRowHeights(true); + m_list->setAlternatingRowColors(false); + m_list->header()->setStretchLastSection(false); + m_list->header()->setSectionResizeMode(0, QHeaderView::Stretch); + m_list->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); + m_list->setFont(theme.font(QStringLiteral("bodySmall"))); + layout->addWidget(m_list, 1); + layout->addStretch(); // keeps the summary at the top while the list is hidden + + connect(m_validate, &QPushButton::clicked, this, &ProblemsView::validateRequested); + connect(m_list, &QTreeWidget::itemActivated, this, + [this](QTreeWidgetItem *item) { activate(item); }); + render(); +} + +void ProblemsView::setDiagnostics(const QJsonArray &diagnostics, bool open, bool hasVerdict, + bool valid) +{ + m_diagnostics = diagnostics; + m_open = open; + m_hasVerdict = hasVerdict; + m_valid = valid; + render(); +} + +void ProblemsView::setBusy(bool busy) +{ + m_busy = busy; + m_validate->setEnabled(m_open && !busy); +} + +QString ProblemsView::summary() const +{ + return m_summary->text(); +} + +int ProblemsView::rowCount() const +{ + return m_list->topLevelItemCount(); +} + +void ProblemsView::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + render(); + QWidget::changeEvent(event); +} + +void ProblemsView::activate(QTreeWidgetItem *item) +{ + const QString file = item->data(0, kFileRole).toString(); + if (!file.isEmpty()) + emit openRequested(file, item->data(0, kLineRole).toInt()); +} + +void ProblemsView::render() +{ + const Theme &theme = Theme::current(); + m_validate->setText(tr("Validate")); + m_validate->setEnabled(m_open && !m_busy); + m_list->setHeaderLabels({tr("Problem"), tr("Where")}); + m_list->clear(); + + int errors = 0; + int warnings = 0; + QList errorRows; + QList warningRows; + for (const QJsonValue &v : std::as_const(m_diagnostics)) { + const QJsonObject d = v.toObject(); + const bool error = d.value(QStringLiteral("severity")).toString() == + QStringLiteral("error"); + (error ? errors : warnings)++; + const QString file = d.value(QStringLiteral("file")).toString(); + const int line = d.value(QStringLiteral("line")).toInt(); + QString where; + if (!file.isEmpty()) + where = QFileInfo(file).fileName() + + (line > 0 ? QStringLiteral(":%1").arg(line) : QString()); + const QString path = d.value(QStringLiteral("path")).toString(); + if (!path.isEmpty()) + where += (where.isEmpty() ? QString() : QStringLiteral(" · ")) + path; + auto *item = new QTreeWidgetItem({d.value(QStringLiteral("message")).toString(), where}); + item->setIcon(0, dot(theme.color(error ? QStringLiteral("state.danger.base") + : QStringLiteral("state.warning.base")))); + item->setData(0, kFileRole, file); + item->setData(0, kLineRole, line); + item->setToolTip(0, d.value(QStringLiteral("message")).toString()); + item->setToolTip(1, file.isEmpty() ? where : file + QStringLiteral(":%1").arg(line)); + item->setFont(1, theme.font(QStringLiteral("codeMeta"))); + item->setForeground(1, theme.color(QStringLiteral("text.tertiary"))); + (error ? errorRows : warningRows).append(item); + } + m_list->addTopLevelItems(errorRows + warningRows); + m_list->setVisible(!m_diagnostics.isEmpty()); + + if (!m_open) + m_summary->setText(tr("Open a board to see what the generator says about it.")); + else if (!m_hasVerdict) + m_summary->setText(tr("Not validated yet.")); + else if (errors == 0 && warnings == 0) + m_summary->setText(tr("No problems: the generator accepts this board.")); + else if (errors == 0) + m_summary->setText(tr("Valid, with %n warning(s).", nullptr, warnings)); + else + m_summary->setText( + tr("%n error(s)", nullptr, errors) + + (warnings ? QStringLiteral(", ") + tr("%n warning(s)", nullptr, warnings) : QString()) + + QStringLiteral(". ") + tr("The generator refuses this board as it is.")); +} + +} // namespace emblinkstudio diff --git a/app/src/problemsview.h b/app/src/problemsview.h new file mode 100644 index 0000000..bec64e3 --- /dev/null +++ b/app/src/problemsview.h @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file problemsview.h + * @brief ProblemsView: every diagnostic, each linked to its file and line (spec section 7). + * + * @details + * Lists the generator's diagnostics for the open board, errors first, each with its + * message and its place: the file, the line and the node's path in the YAML. A + * double-click (or Return) asks to open the file at that line. The summary above the + * list says whether the board has been validated and what the generator found; the + * Validate button asks the generator again. + * + * @see session.h; protocol/project.validate.result.schema.json + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#pragma once + +#include +#include + +class QLabel; +class QPushButton; +class QTreeWidget; +class QTreeWidgetItem; + +namespace emblinkstudio +{ + +class ProblemsView : public QWidget +{ + Q_OBJECT + + public: + explicit ProblemsView(QWidget *parent = nullptr); + + void setDiagnostics(const QJsonArray &diagnostics, bool open, bool hasVerdict, bool valid); + void setBusy(bool busy); + + QString summary() const; + int rowCount() const; + QTreeWidget *list() const + { + return m_list; + } + + signals: + void validateRequested(); + void openRequested(const QString &file, int line); + + protected: + void changeEvent(QEvent *event) override; + + private: + void render(); + void activate(QTreeWidgetItem *item); + + QLabel *m_summary = nullptr; + QPushButton *m_validate = nullptr; + QTreeWidget *m_list = nullptr; + QJsonArray m_diagnostics; + bool m_open = false; + bool m_hasVerdict = false; + bool m_valid = false; + bool m_busy = false; +}; + +} // namespace emblinkstudio diff --git a/app/src/session.cpp b/app/src/session.cpp new file mode 100644 index 0000000..fb651a9 --- /dev/null +++ b/app/src/session.cpp @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file session.cpp + * @brief Implementation of Session: the requests behind opening, validating and generating. + * + * @details + * Every request carries the session's generation; an answer that arrives after the + * board was closed or another opened is ignored. The busy count rises with each request + * and falls with its answer, so the window can show that the core is working. Errors + * other than untrusted become failed(), with the core's message, which is written for + * the person. + * + * @see session.h + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#include "coreclient.h" +#include "session.h" + +namespace emblinkstudio +{ + +Session::Session(CoreClient *core, QObject *parent) : QObject(parent), m_core(core) +{ +} + +void Session::call(const QString &method, const QJsonValue ¶ms, + std::function onResult) +{ + const int generation = m_generation; + if (m_busy++ == 0) + emit busyChanged(true); + auto done = [this] { + if (--m_busy == 0) + emit busyChanged(false); + }; + m_core->request( + method, params, + [this, generation, onResult, done](const QJsonValue &result) { + done(); + if (generation == m_generation) + onResult(result); + }, + [this, generation, done](int code, const QString &message, const QJsonValue &data) { + done(); + if (generation != m_generation) + return; + Q_UNUSED(code); + Q_UNUSED(data); + emit failed(message); + }); +} + +void Session::clear() +{ + m_status = {}; + m_describe = {}; + m_pins = {}; + m_clocks = {}; + m_memory = {}; + m_diagnostics = {}; + m_hasVerdict = false; + m_valid = false; +} + +void Session::open(const QString &path) +{ + ++m_generation; + const bool wasOpen = isOpen(); + clear(); + if (wasOpen) + emit closed(); + m_path = path; + call(QStringLiteral("project.open"), QJsonObject{{QStringLiteral("path"), path}}, + [this](const QJsonValue &result) { + m_status = result.toObject(); + emit opened(); + emit statusChanged(); + emit diagnosticsChanged(); + fetchModel(); + // A trusted checkout is validated at once, so the problems are there on opening. + if (m_status.value(QStringLiteral("trusted")).toBool()) + run(Action::Validate); + }); +} + +void Session::reopen() +{ + if (!m_path.isEmpty()) + open(m_path); +} + +void Session::close() +{ + ++m_generation; + const bool wasOpen = isOpen(); + clear(); + m_path.clear(); + m_core->request(QStringLiteral("project.close"), QJsonValue(), [](const QJsonValue &) {}); + if (wasOpen) { + emit closed(); + emit statusChanged(); + emit modelChanged(); + emit diagnosticsChanged(); + } +} + +void Session::fetchStatus() +{ + call(QStringLiteral("project.status"), QJsonValue(), [this](const QJsonValue &result) { + m_status = result.toObject(); + emit statusChanged(); + }); +} + +void Session::fetchModel() +{ + if (!m_status.value(QStringLiteral("generated")).toBool()) { + m_describe = m_pins = m_clocks = m_memory = {}; + emit modelChanged(); + return; + } + // Four answers; the views are told once, when the last arrives. + auto remaining = std::make_shared(4); + auto arrived = [this, remaining](QJsonObject &slot) { + return [this, remaining, &slot](const QJsonValue &result) { + slot = result.toObject(); + if (--*remaining == 0) + emit modelChanged(); + }; + }; + call(QStringLiteral("board.describe"), QJsonValue(), arrived(m_describe)); + call(QStringLiteral("board.pins"), QJsonValue(), arrived(m_pins)); + call(QStringLiteral("board.clocks"), QJsonValue(), arrived(m_clocks)); + call(QStringLiteral("board.memory"), QJsonValue(), arrived(m_memory)); +} + +void Session::setVerdict(const QJsonObject &result) +{ + m_diagnostics = result.value(QStringLiteral("diagnostics")).toArray(); + m_hasVerdict = true; + m_valid = result.contains(QStringLiteral("valid")) + ? result.value(QStringLiteral("valid")).toBool() + : result.value(QStringLiteral("errors")).toInt() == 0; + emit diagnosticsChanged(); +} + +void Session::validate() +{ + run(Action::Validate); +} + +void Session::generate() +{ + run(Action::Generate); +} + +void Session::run(Action action) +{ + if (!isOpen()) + return; + const QString method = action == Action::Validate ? QStringLiteral("project.validate") + : QStringLiteral("generate.run"); + const int generation = m_generation; + if (m_busy++ == 0) + emit busyChanged(true); + auto done = [this] { + if (--m_busy == 0) + emit busyChanged(false); + }; + m_core->request( + method, QJsonValue(), + [this, generation, action, done](const QJsonValue &result) { + done(); + if (generation != m_generation) + return; + setVerdict(result.toObject()); + if (action == Action::Generate && + result.toObject().value(QStringLiteral("written")).toBool()) { + fetchStatus(); + m_status.insert(QStringLiteral("generated"), true); + fetchModel(); + } + }, + [this, generation, action, done](int code, const QString &message, const QJsonValue &data) { + done(); + if (generation != m_generation) + return; + if (code == Untrusted) { + emit trustNeeded(data.toObject().value(QStringLiteral("path")).toString(), action); + return; + } + emit failed(message); + }); +} + +void Session::trustAndRun(Action action) +{ + call(QStringLiteral("project.trust"), QJsonValue(), [this, action](const QJsonValue &result) { + m_status = result.toObject(); + emit statusChanged(); + run(action); + }); +} + +} // namespace emblinkstudio diff --git a/app/src/session.h b/app/src/session.h new file mode 100644 index 0000000..cac78ff --- /dev/null +++ b/app/src/session.h @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file session.h + * @brief Session: the board the desktop has open, as the core knows it (stage S1). + * + * @details + * The desktop keeps no knowledge of its own (spec section 4): the Session asks the + * core and holds the answers for the views. Opening a board fetches its status and, + * when it is generated, its model (board.describe, pins, clocks, memory), and validates + * it when its checkout is trusted. validate() and generate() run the checkout's + * generator; when the core answers untrusted, the Session emits trustNeeded() and the + * window asks the person, who can trust and run the action in one step with + * trustAndRun(). After a generate, the model and the problems are fetched again. + * + * When the core restarts, reopen() opens the same board again, so a crash loses + * nothing (spec section 4, process model). + * + * @see coreclient.h; protocol/project.*.schema.json, protocol/board.*.schema.json + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +class CoreClient; + +class Session : public QObject +{ + Q_OBJECT + + public: + // The core's error codes the Session acts on (spec section 5, Errors). + enum ErrorCode { + NoProject = 1002, + Untrusted = 1003 + }; + enum class Action { + Validate, + Generate + }; + Q_ENUM(Action) + + explicit Session(CoreClient *core, QObject *parent = nullptr); + + void open(const QString &path); + // Opens the last board again, after the core restarted; nothing if none was open. + void reopen(); + void close(); + void validate(); + void generate(); + // Trusts the board's checkout, then runs `action`. + void trustAndRun(Action action); + + bool isOpen() const + { + return !m_status.isEmpty(); + } + QString path() const + { + return m_path; + } + bool isBusy() const + { + return m_busy > 0; + } + // project.status: kind, path, id, name, rtos, trusted, generated, board (summary). + QJsonObject status() const + { + return m_status; + } + QJsonObject describe() const + { + return m_describe; + } + QJsonObject pins() const + { + return m_pins; + } + QJsonObject clocks() const + { + return m_clocks; + } + QJsonObject memory() const + { + return m_memory; + } + QJsonArray diagnostics() const + { + return m_diagnostics; + } + // Whether the generator has given its verdict since the board was opened. + bool hasVerdict() const + { + return m_hasVerdict; + } + bool isValid() const + { + return m_valid; + } + + signals: + void opened(); + void closed(); + void statusChanged(); + void modelChanged(); + void diagnosticsChanged(); + void busyChanged(bool busy); + // The generator needs the checkout trusted before `action` (spec section 9). + void trustNeeded(const QString &checkout, emblinkstudio::Session::Action action); + // A message for the person: the core refused or a tool failed. + void failed(const QString &message); + + private: + void run(Action action); + void fetchStatus(); + void fetchModel(); + void setVerdict(const QJsonObject &result); + void call(const QString &method, const QJsonValue ¶ms, + std::function onResult); + void clear(); + + CoreClient *m_core = nullptr; + QString m_path; + QJsonObject m_status; + QJsonObject m_describe; + QJsonObject m_pins; + QJsonObject m_clocks; + QJsonObject m_memory; + QJsonArray m_diagnostics; + bool m_hasVerdict = false; + bool m_valid = false; + int m_busy = 0; + // Bumped on every open and close, so an answer about a board no longer open is dropped. + int m_generation = 0; +}; + +} // namespace emblinkstudio diff --git a/app/src/theme.cpp b/app/src/theme.cpp index 3da502f..0c7d641 100644 --- a/app/src/theme.cpp +++ b/app/src/theme.cpp @@ -308,6 +308,16 @@ QString Theme::styleSheet() const s += QStringLiteral("QFrame[role=\"group\"] { background: %1; border: 0; border-radius: %2px; " "}\n") .arg(over("fill.group", card), n("radius.group")); + s += QStringLiteral("QWidget[role=\"row\"] { background: transparent; border: 0; " + "border-top: 1px solid %1; }\n" + "QWidget[role=\"row\"][first=\"true\"] { border-top: 0; }\n") + .arg(c("line.hairline")); + s += QStringLiteral("QTreeWidget#problems { background: transparent; border: 0; }\n" + "QTreeWidget#problems::item { padding: 4px 2px; border-radius: 6px; }\n" + "QTreeWidget#problems::item:selected { background: %1; color: %2; }\n" + "QTreeWidget#problems QHeaderView::section { background: transparent; " + "color: %3; border: 0; padding: 2px 4px; }\n") + .arg(c("fill.selected"), c("text.strong"), c("text.quiet")); s += QStringLiteral("QMenu { background: %1; border: 1px solid %2; border-radius: %3px; " "padding: 6px; }\n" "QMenu::item { padding: 5px 14px; border-radius: 6px; }\n" diff --git a/app/src/workbench.h b/app/src/workbench.h index 6be0d24..142de21 100644 --- a/app/src/workbench.h +++ b/app/src/workbench.h @@ -89,7 +89,7 @@ class Workbench : public QObject } // Bumped when a change to the views would make old saved layouts misleading. - static constexpr int kLayoutVersion = 1; + static constexpr int kLayoutVersion = 2; // 2: Board and Problems join the views signals: void namedLayoutsChanged(); diff --git a/app/tests/tst_session.cpp b/app/tests/tst_session.cpp new file mode 100644 index 0000000..5197773 --- /dev/null +++ b/app/tests/tst_session.cpp @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file tst_session.cpp + * @brief Qt Test suite for Session and its views, against the real core (stage S1). + * + * @details + * Runs EmbLink Studio Core as the application does, on a temporary EmbLinkRTOS + * checkout whose generator is the core's test stand-in (core/tests/fake_hwgen.py), with + * the core's settings in a temporary directory. Checks that a board opens; that the + * generator waits for trust, and that trusting runs it; that generating brings the + * model, which the Board view shows; that validation's errors reach the Problems view + * with their place; that a board opens again after the core restarts; and that a + * refusal reaches the person as a message. + * + * @see session.h, boardview.h, problemsview.h + * @author Junior Deogracias + * @date 2026-11-12 (created) + */ + +#include "boardview.h" +#include "coreclient.h" +#include "problemsview.h" +#include "session.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +using emblinkstudio::BoardView; +using emblinkstudio::CoreClient; +using emblinkstudio::ProblemsView; +using emblinkstudio::Session; + +namespace +{ + +constexpr int kTimeoutMs = 20000; + +const char kBoard[] = "schema_version: 0\n" + "kind: board\n" + "name: demo\n" + "vendor: acme\n" + "clocks:\n" + " cpu_hz: 48000000\n"; + +bool write(const QString &path, const QByteArray &text) +{ + QDir().mkpath(QFileInfo(path).path()); + QFile file(path); + return file.open(QIODevice::WriteOnly) && file.write(text) == text.size(); +} + +// A checkout with the fake generator and one board, acme/demo, not generated yet. +struct Checkout { + QTemporaryDir dir; + QString root() const + { + return dir.filePath(QStringLiteral("rtos")); + } + QString board() const + { + return root() + QStringLiteral("/boards/acme/demo"); + } + bool make(const QByteArray &boardYaml = kBoard) + { + QFile fake(QStringLiteral(EMBLINK_STUDIO_FAKE_HWGEN)); + return dir.isValid() && fake.open(QIODevice::ReadOnly) && + write(root() + QStringLiteral("/hw/gen/emb-hwgen.py"), fake.readAll()) && + write(root() + QStringLiteral("/hw/gen/emb_hwgen/__init__.py"), + "VERSION = \"0.1.0\"\nSCHEMA_VERSION = 0\n") && + write(board() + QStringLiteral("/board.yaml"), boardYaml); + } +}; + +CoreClient::Launch launch(const QTemporaryDir &config) +{ + CoreClient::Launch l = CoreClient::defaultLaunch(); + l.environment.insert(QStringLiteral("EMBLINK_STUDIO_CONFIG_DIR"), config.path()); + return l; +} + +bool startCore(CoreClient &core, const QTemporaryDir &config) +{ + QSignalSpy ready(&core, &CoreClient::ready); + core.start(launch(config)); + return ready.wait(kTimeoutMs); +} + +} // namespace + +class TestSession : public QObject +{ + Q_OBJECT + + private slots: + void initTestCase() + { + QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); + } + + void formatting() + { + QCOMPARE(emblinkstudio::formatHz(180000000), QStringLiteral("180 MHz")); + QCOMPARE(emblinkstudio::formatHz(32768), QStringLiteral("32.768 kHz")); + QCOMPARE(emblinkstudio::formatBytes(524288), QStringLiteral("512 KB")); + QCOMPARE(emblinkstudio::formatBytes(16384), QStringLiteral("16 KB")); + } + + void generatingWaitsForTrustThenShowsTheModel() + { + Checkout checkout; + QVERIFY(checkout.make()); + QTemporaryDir config; + CoreClient core; + QVERIFY(startCore(core, config)); + Session session(&core); + + QSignalSpy opened(&session, &Session::opened); + session.open(checkout.board()); + QVERIFY(opened.wait(kTimeoutMs)); + QCOMPARE(session.status().value(QStringLiteral("id")).toString(), + QStringLiteral("acme/demo")); + QVERIFY(!session.status().value(QStringLiteral("generated")).toBool()); + QVERIFY(!session.status().value(QStringLiteral("trusted")).toBool()); + QVERIFY(session.describe().isEmpty()); + + QSignalSpy trust(&session, &Session::trustNeeded); + session.generate(); + QVERIFY(trust.wait(kTimeoutMs)); + QCOMPARE(trust.first().at(1).value(), Session::Action::Generate); + QVERIFY(trust.first().at(0).toString().endsWith(QStringLiteral("rtos"))); + + QSignalSpy model(&session, &Session::modelChanged); + session.trustAndRun(Session::Action::Generate); + QVERIFY(model.wait(kTimeoutMs)); + QVERIFY(session.status().value(QStringLiteral("trusted")).toBool()); + QCOMPARE(session.describe() + .value(QStringLiteral("board")) + .toObject() + .value(QStringLiteral("name")) + .toString(), + QStringLiteral("demo")); + QCOMPARE(session.clocks() + .value(QStringLiteral("resolved")) + .toObject() + .value(QStringLiteral("cpu_hz")) + .toDouble(), + 48000000.0); + QVERIFY(session.hasVerdict()); + QVERIFY(session.isValid()); + + BoardView view; + view.setModel(session.status(), session.describe(), session.clocks(), session.memory(), + session.pins()); + QVERIFY(view.groupTitles().contains(QStringLiteral("Chip"))); + QCOMPARE(view.value(QStringLiteral("Chip"), QStringLiteral("Part")), + QStringLiteral("ACME1")); + QCOMPARE(view.value(QStringLiteral("Clocks"), QStringLiteral("CPU")), + QStringLiteral("48 MHz")); + QCOMPARE(view.value(QStringLiteral("Pins in use"), QStringLiteral("PA0")), + QStringLiteral("uart0_tx · pins.uart0.tx")); + core.stop(); + } + + void errorsReachTheProblemsViewWithTheirPlace() + { + Checkout checkout; + QVERIFY(checkout.make(QByteArray(kBoard) + + "pins: {} # error: pins.uart0.tx: PA9 cannot carry uart0_tx\n")); + QTemporaryDir config; + CoreClient core; + QVERIFY(startCore(core, config)); + Session session(&core); + QSignalSpy opened(&session, &Session::opened); + session.open(checkout.board()); + QVERIFY(opened.wait(kTimeoutMs)); + + QSignalSpy diagnostics(&session, &Session::diagnosticsChanged); + diagnostics.clear(); + session.trustAndRun(Session::Action::Validate); + QVERIFY(diagnostics.wait(kTimeoutMs)); + QVERIFY(session.hasVerdict()); + QVERIFY(!session.isValid()); + QCOMPARE(session.diagnostics().size(), 1); + const QJsonObject d = session.diagnostics().first().toObject(); + QCOMPARE(d.value(QStringLiteral("line")).toInt(), 7); + QCOMPARE(d.value(QStringLiteral("path")).toString(), QStringLiteral("pins.uart0.tx")); + + ProblemsView view; + QSignalSpy open(&view, &ProblemsView::openRequested); + view.setDiagnostics(session.diagnostics(), true, session.hasVerdict(), session.isValid()); + QCOMPARE(view.rowCount(), 1); + QVERIFY2(view.summary().startsWith(QStringLiteral("1 error")), qPrintable(view.summary())); + QCOMPARE(view.list()->topLevelItem(0)->text(1), + QStringLiteral("board.yaml:7 · pins.uart0.tx")); + emit view.list()->itemActivated(view.list()->topLevelItem(0), 0); + QCOMPARE(open.count(), 1); + QVERIFY(open.first().at(0).toString().endsWith(QStringLiteral("board.yaml"))); + QCOMPARE(open.first().at(1).toInt(), 7); + core.stop(); + } + + void theBoardOpensAgainAfterTheCoreRestarts() + { + Checkout checkout; + QVERIFY(checkout.make()); + QTemporaryDir config; + CoreClient core; + QVERIFY(startCore(core, config)); + Session session(&core); + QSignalSpy opened(&session, &Session::opened); + session.open(checkout.board()); + QVERIFY(opened.wait(kTimeoutMs)); + + core.stop(); + QVERIFY(startCore(core, config)); + session.reopen(); + QVERIFY(opened.wait(kTimeoutMs)); + QCOMPARE(opened.count(), 2); + QCOMPARE(session.status().value(QStringLiteral("id")).toString(), + QStringLiteral("acme/demo")); + core.stop(); + } + + void aRefusalReachesThePerson() + { + QTemporaryDir config; + QTemporaryDir nowhere; + CoreClient core; + QVERIFY(startCore(core, config)); + Session session(&core); + QSignalSpy failed(&session, &Session::failed); + session.open(nowhere.path()); + QVERIFY(failed.wait(kTimeoutMs)); + QVERIFY2(failed.first().first().toString().contains(QStringLiteral("board.yaml")), + qPrintable(failed.first().first().toString())); + QVERIFY(!session.isOpen()); + + QSignalSpy closed(&session, &Session::closed); + session.close(); + QCOMPARE(closed.count(), 0); // nothing was open + core.stop(); + } +}; + +QTEST_MAIN(TestSession) +#include "tst_session.moc" diff --git a/docs/development.md b/docs/development.md index 2fe9c0a..b0953b5 100644 --- a/docs/development.md +++ b/docs/development.md @@ -33,11 +33,19 @@ core/.venv/bin/emblink-studio-core board list ~/EmbLinkRTOS # every met core/.venv/bin/emblink-studio-core project validate ~/EmbLinkRTOS/boards/st/nucleo_f446re ``` +Make `core/.venv` before the first `cmake --preset dev`: the build then runs the core with that Python, which +has the core's dependencies (PyYAML, for the RTOS's generator). Configured before it existed, run +`cmake --preset dev -DPython3_EXECUTABLE=$PWD/core/.venv/bin/python` once. + Run the application: `build/dev/app/EmbLinkStudio.app/Contents/MacOS/EmbLinkStudio` on macOS, `build/dev/app/EmbLinkStudio` elsewhere. It runs the core from `core/src` with the Python CMake found; set `EMBLINK_STUDIO_CORE` to an installed `emblink-studio-core` to use that instead. -Options for a run: `--language en|fr|zh_CN` uses that language without saving it, `--stage +Open a board with File › Open Board (⌘O): a board directory of an EmbLinkRTOS checkout, such as +`~/EmbLinkRTOS/boards/st/nucleo_f446re`. Validating and generating run the checkout's generator, so the +application asks once to trust the checkout. + +Options for a run: `--open ` opens that board, `--language en|fr|zh_CN` uses that language without saving it, `--stage configure|code|debug|verify` opens on that stage, and `--screenshot ` saves a picture of the window and quits. diff --git a/docs/specification.md b/docs/specification.md index adace92..a0efa8f 100644 --- a/docs/specification.md +++ b/docs/specification.md @@ -276,7 +276,7 @@ Ten stages, each ending in something usable and demonstrated. S0 is done: CI bui | Stage | Delivers | Accepted when | Needs from the RTOS | Status | | --- | --- | --- | --- | --- | | **S0 Setup** | The EmbLink Studio repository, its licence files and contributor agreement, CI on Windows, Linux and macOS, a Qt application that starts and talks to a stub core | CI builds and tests on all three systems; `initialize` and `shutdown` succeed; the notices list is generated | Nothing | Done | -| **S1 Core foundation** | `emblink-studio-core serve`, `project.open` and `validate`, `board.*` from `hw.json`, `generate.run` | Opening the RTOS's `nucleo_f446re` and `pico2_w` boards shows their model; validation reports the generator's errors with their locations | JSON diagnostics from `emb-hwgen`; a versioned `hw.json` | In progress | +| **S1 Core foundation** | `emblink-studio-core serve`, `project.open` and `validate`, `board.*` from `hw.json`, `generate.run` | Opening the RTOS's `nucleo_f446re` and `pico2_w` boards shows their model; validation reports the generator's errors with their locations | JSON diagnostics from `emb-hwgen`; a versioned `hw.json` | Done (2026-11-12) | | **S2 Read-only views** | Board, pin map, clock tree, devices, memory, RTOS, problems | For both boards, a golden test finds every value in the views equal to `hw.json` and to the generator's `board.md` and `build_report.md` | Existing outputs | Not started | | **S3 Editing** | `config.preview`, `apply`, `undo`; pins, devices and threads editable; live diagnostics | A pin conflict is refused with the generator's message; an edit's `git diff` touches only the lines it must; generation stays clean | `system.yaml` (E3) for threads | Not started | | **S4 Build, flash, console** | Toolchain discovery, CMake build, flash by OpenOCD and picotool, serial console | A project is created, built, flashed and seen running on the NUCLEO-F446RE and the Pico 2 W; in CI, on EmbSIM's `nucleo_f446re` | The CMake package (A91) | Not started |