2018-06-22 22:21:20 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-21 19:41:16 +08:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include <QAction>
|
2018-06-21 21:41:40 +08:00
|
|
|
#include <QFileDialog>
|
2018-07-21 17:24:29 +08:00
|
|
|
#include <QFileInfo>
|
2018-06-21 19:41:16 +08:00
|
|
|
#include <QIcon>
|
2018-06-23 22:03:22 +08:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QLineEdit>
|
2018-08-09 00:17:34 +08:00
|
|
|
#include <fstream>
|
2018-06-21 19:55:36 +08:00
|
|
|
#include "bitstream.h"
|
|
|
|
#include "design_utils.h"
|
2018-06-21 19:41:16 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "pcf.h"
|
|
|
|
|
2018-06-22 19:10:27 +08:00
|
|
|
static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2019-06-14 21:18:35 +08:00
|
|
|
MainWindow::MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent)
|
|
|
|
: BaseMainWindow(std::move(context), handler, parent)
|
2018-06-21 19:41:16 +08:00
|
|
|
{
|
2018-06-22 19:10:27 +08:00
|
|
|
initMainResource();
|
|
|
|
|
2018-06-26 21:47:22 +08:00
|
|
|
std::string title = "nextpnr-ice40 - [EMPTY]";
|
2018-06-21 19:41:16 +08:00
|
|
|
setWindowTitle(title.c_str());
|
|
|
|
|
2018-08-03 16:53:38 +08:00
|
|
|
connect(this, &BaseMainWindow::contextChanged, this, &MainWindow::newContext);
|
2018-06-26 21:47:22 +08:00
|
|
|
|
2018-06-22 18:11:22 +08:00
|
|
|
createMenu();
|
2018-06-21 19:41:16 +08:00
|
|
|
}
|
|
|
|
|
2018-08-03 00:50:08 +08:00
|
|
|
MainWindow::~MainWindow() {}
|
2018-06-21 19:41:16 +08:00
|
|
|
|
|
|
|
void MainWindow::createMenu()
|
2018-08-03 01:25:20 +08:00
|
|
|
{
|
|
|
|
// Add arch specific actions
|
2018-07-15 21:12:31 +08:00
|
|
|
actionLoadPCF = new QAction("Open PCF", this);
|
2018-07-14 23:58:58 +08:00
|
|
|
actionLoadPCF->setIcon(QIcon(":/icons/resources/open_pcf.png"));
|
2018-06-23 22:55:13 +08:00
|
|
|
actionLoadPCF->setStatusTip("Open PCF file");
|
|
|
|
actionLoadPCF->setEnabled(false);
|
2018-08-03 16:53:38 +08:00
|
|
|
connect(actionLoadPCF, &QAction::triggered, this, &MainWindow::open_pcf);
|
2018-06-23 22:55:13 +08:00
|
|
|
|
2018-07-15 21:12:31 +08:00
|
|
|
actionSaveAsc = new QAction("Save ASC", this);
|
2018-07-14 23:58:58 +08:00
|
|
|
actionSaveAsc->setIcon(QIcon(":/icons/resources/save_asc.png"));
|
2018-06-26 19:49:32 +08:00
|
|
|
actionSaveAsc->setStatusTip("Save ASC file");
|
|
|
|
actionSaveAsc->setEnabled(false);
|
2018-08-03 16:53:38 +08:00
|
|
|
connect(actionSaveAsc, &QAction::triggered, this, &MainWindow::save_asc);
|
2018-06-26 19:49:32 +08:00
|
|
|
|
2018-08-03 01:21:25 +08:00
|
|
|
// Add actions in menus
|
|
|
|
mainActionBar->addSeparator();
|
|
|
|
mainActionBar->addAction(actionLoadPCF);
|
|
|
|
mainActionBar->addAction(actionSaveAsc);
|
2018-08-03 01:25:20 +08:00
|
|
|
|
2018-08-03 00:50:08 +08:00
|
|
|
menuDesign->addSeparator();
|
|
|
|
menuDesign->addAction(actionLoadPCF);
|
|
|
|
menuDesign->addAction(actionSaveAsc);
|
2018-06-21 19:41:16 +08:00
|
|
|
}
|
2018-06-21 21:41:40 +08:00
|
|
|
|
2018-07-07 19:23:45 +08:00
|
|
|
void MainWindow::new_proj()
|
|
|
|
{
|
|
|
|
QMap<QString, int> arch;
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::LP384))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40LP384", ArchArgs::LP384);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::LP1K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40LP1K", ArchArgs::LP1K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::HX1K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40HX1K", ArchArgs::HX1K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::U1K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE5LP1K", ArchArgs::U1K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::U2K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE5LP2K", ArchArgs::U2K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::U4K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE5LP4K", ArchArgs::U4K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::UP3K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40UP3K", ArchArgs::UP3K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::UP5K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40UP5K", ArchArgs::UP5K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::LP4K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40LP4K", ArchArgs::LP4K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::LP8K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40LP8K", ArchArgs::LP8K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::HX4K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40HX4K", ArchArgs::HX4K);
|
2021-02-03 18:21:45 +08:00
|
|
|
if (Arch::is_available(ArchArgs::HX8K))
|
2020-07-08 20:16:00 +08:00
|
|
|
arch.insert("Lattice iCE40HX8K", ArchArgs::HX8K);
|
2020-06-25 23:11:47 +08:00
|
|
|
|
2018-07-07 19:23:45 +08:00
|
|
|
bool ok;
|
|
|
|
QString item = QInputDialog::getItem(this, "Select new context", "Chip:", arch.keys(), 0, false, &ok);
|
|
|
|
if (ok && !item.isEmpty()) {
|
2019-06-14 21:18:35 +08:00
|
|
|
ArchArgs chipArgs;
|
2018-07-07 19:23:45 +08:00
|
|
|
chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(item);
|
|
|
|
|
2020-06-25 23:11:47 +08:00
|
|
|
QStringList packages;
|
2021-02-03 18:21:45 +08:00
|
|
|
for (auto package : Arch::get_supported_packages(chipArgs.type))
|
2020-06-25 23:11:47 +08:00
|
|
|
packages.append(QLatin1String(package.data(), package.size()));
|
|
|
|
QString package = QInputDialog::getItem(this, "Select package", "Package:", packages, 0, false, &ok);
|
2018-07-07 19:23:45 +08:00
|
|
|
|
2018-07-22 06:50:49 +08:00
|
|
|
if (ok && !item.isEmpty()) {
|
2020-09-04 23:14:30 +08:00
|
|
|
handler->clear();
|
2018-07-21 18:15:50 +08:00
|
|
|
currentProj = "";
|
2018-07-21 18:22:41 +08:00
|
|
|
disableActions();
|
2018-07-07 19:23:45 +08:00
|
|
|
chipArgs.package = package.toStdString().c_str();
|
2018-07-13 15:14:48 +08:00
|
|
|
ctx = std::unique_ptr<Context>(new Context(chipArgs));
|
2018-07-13 18:02:49 +08:00
|
|
|
actionLoadJSON->setEnabled(true);
|
2018-07-07 19:23:45 +08:00
|
|
|
|
2018-07-13 15:14:48 +08:00
|
|
|
Q_EMIT contextChanged(ctx.get());
|
2018-07-07 19:23:45 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-26 20:17:17 +08:00
|
|
|
}
|
|
|
|
|
2018-07-13 15:14:48 +08:00
|
|
|
void MainWindow::load_pcf(std::string filename)
|
|
|
|
{
|
|
|
|
disableActions();
|
2018-08-03 01:25:20 +08:00
|
|
|
std::ifstream f(filename);
|
2018-08-09 02:14:18 +08:00
|
|
|
if (apply_pcf(ctx.get(), filename, f)) {
|
2018-08-03 00:10:01 +08:00
|
|
|
log("Loading PCF successful.\n");
|
|
|
|
actionPack->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
actionLoadPCF->setEnabled(true);
|
|
|
|
log("Loading PCF failed.\n");
|
|
|
|
}
|
2018-07-13 15:14:48 +08:00
|
|
|
}
|
|
|
|
|
2018-06-26 21:47:22 +08:00
|
|
|
void MainWindow::newContext(Context *ctx)
|
|
|
|
{
|
2019-06-14 21:18:35 +08:00
|
|
|
std::string title = "nextpnr-ice40 - " + ctx->getChipName() + " ( " + ctx->archArgs().package + " )";
|
2018-06-26 21:47:22 +08:00
|
|
|
setWindowTitle(title.c_str());
|
|
|
|
}
|
|
|
|
|
2018-06-23 22:55:13 +08:00
|
|
|
void MainWindow::open_pcf()
|
|
|
|
{
|
2018-06-26 19:49:32 +08:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, QString("Open PCF"), QString(), QString("*.pcf"));
|
2018-06-23 22:55:13 +08:00
|
|
|
if (!fileName.isEmpty()) {
|
2018-07-13 15:14:48 +08:00
|
|
|
load_pcf(fileName.toStdString());
|
2018-06-23 22:55:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 19:49:32 +08:00
|
|
|
void MainWindow::save_asc()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, QString("Save ASC"), QString(), QString("*.asc"));
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
std::string fn = fileName.toStdString();
|
|
|
|
disableActions();
|
2018-08-03 00:10:01 +08:00
|
|
|
std::ofstream f(fn);
|
|
|
|
write_asc(ctx.get(), f);
|
|
|
|
log("Saving ASC successful.\n");
|
2018-06-26 19:49:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:50:08 +08:00
|
|
|
void MainWindow::onDisableActions()
|
2018-06-22 21:35:07 +08:00
|
|
|
{
|
2018-06-23 22:55:13 +08:00
|
|
|
actionLoadPCF->setEnabled(false);
|
2018-06-26 19:49:32 +08:00
|
|
|
actionSaveAsc->setEnabled(false);
|
2018-06-22 21:35:07 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 00:19:25 +08:00
|
|
|
void MainWindow::onUpdateActions()
|
|
|
|
{
|
|
|
|
if (ctx->settings.find(ctx->id("pack")) == ctx->settings.end())
|
2019-06-14 17:14:18 +08:00
|
|
|
actionLoadPCF->setEnabled(true);
|
2019-06-26 00:19:25 +08:00
|
|
|
if (ctx->settings.find(ctx->id("route")) != ctx->settings.end())
|
2019-06-14 17:14:18 +08:00
|
|
|
actionSaveAsc->setEnabled(true);
|
|
|
|
}
|
2018-08-09 03:15:54 +08:00
|
|
|
|
2018-07-12 00:04:09 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|