Skip to content

Commit

Permalink
quartus pgm settings
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Mar 22, 2024
1 parent 424088d commit fbdded7
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/OneWare.Quartus/OneWare.Quartus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OneWare.Essentials" Version="0.4.6" Private="false" ExcludeAssets="runtime;Native"/>
<PackageReference Include="OneWare.UniversalFpgaProjectSystem" Version="0.16.8" Private="false" ExcludeAssets="runtime;Native"/>
<PackageReference Include="OneWare.Essentials" Version="0.4.7" Private="false" ExcludeAssets="runtime;Native"/>
<PackageReference Include="OneWare.UniversalFpgaProjectSystem" Version="0.17" Private="false" ExcludeAssets="runtime;Native"/>
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/OneWare.Quartus/QuartusLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public async Task DownloadAsync(UniversalFpgaProjectRoot project)
return;
}

var shortTermMode = properties.GetValueOrDefault("QuartusProgrammer_ShortTermMode") ?? "JTAG";
var shortTermOperation = properties.GetValueOrDefault("QuartusProgrammer_ShortTermOperation") ?? "P";
var shortTermMode = properties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Mode") ?? "JTAG";
var shortTermOperation = properties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Operation") ?? "P";
var shortTermArgs = properties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Arguments")?.Split(' ') ?? [];

List<string> pgmArgs = ["-c", cableName, "-m", shortTermMode];
pgmArgs.AddRange(shortTermArgs);
pgmArgs.AddRange(["-o", $"p;{sofFile}"]);
pgmArgs.AddRange(["-o", $"{shortTermOperation};{sofFile}"]);

await childProcessService.ExecuteShellAsync("quartus_pgm", pgmArgs,
project.FullPath, "Running Quartus programmer (Short-Term)...", AppState.Loading, true);
Expand Down Expand Up @@ -115,8 +115,8 @@ await childProcessService.ExecuteShellAsync("quartus_pgm", pgmArgs,
programFile = convertedFilePath;
}

var longTermMode = properties.GetValueOrDefault("QuartusProgrammer_LongTermMode") ?? "JTAG";
var longTermOperation = properties.GetValueOrDefault("QuartusProgrammer_LongTermOperation") ?? "P";
var longTermMode = properties.GetValueOrDefault("QuartusProgrammer_LongTerm_Mode") ?? "JTAG";
var longTermOperation = properties.GetValueOrDefault("QuartusProgrammer_LongTerm_Operation") ?? "P";
var longTermArgs = properties.GetValueOrDefault("QuartusProgrammer_LongTerm_Arguments")?.Split(' ') ?? [];

List<string> pgmArgs = ["-c", cableName, "-m", longTermMode];
Expand Down
8 changes: 8 additions & 0 deletions src/OneWare.Quartus/QuartusModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void OnInitialized(IContainerProvider containerProvider)
{
DataContext = containerProvider.Resolve<QuartusCompileWindowExtensionViewModel>()
}));
containerProvider.Resolve<IWindowService>().RegisterUiExtension("UniversalFpgaToolBar_DownloaderConfigurationExtension", new UiExtension(x =>
{
if (x is not UniversalFpgaProjectRoot cm) return null;
return new QuartusLoaderWindowExtensionView()
{
DataContext = containerProvider.Resolve<QuartusLoaderWindowExtensionViewModel>((typeof(UniversalFpgaProjectRoot), cm))
};
}));
containerProvider.Resolve<FpgaService>().RegisterToolchain<QuartusToolchain>();
containerProvider.Resolve<FpgaService>().RegisterLoader<QuartusLoader>();

Expand Down
10 changes: 8 additions & 2 deletions src/OneWare.Quartus/QuartusToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OneWare.Quartus.Helper;
using OneWare.Quartus.Services;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Parser;
using OneWare.UniversalFpgaProjectSystem.Services;

namespace OneWare.Quartus;
Expand Down Expand Up @@ -66,15 +67,20 @@ public Task<bool> CompileAsync(UniversalFpgaProjectRoot project, FpgaModel fpga)
{
var topEntity = project.TopEntity?.Header ?? throw new Exception("No TopEntity set!");
topEntity = Path.GetFileNameWithoutExtension(topEntity);

var properties = FpgaSettingsParser.LoadSettings(project, fpga.Fpga.Name);

var qsfPath = QsfHelper.GetQsfPath(project);
var qsf = QsfHelper.ReadQsf(qsfPath);

var family = properties.GetValueOrDefault("QuartusToolchain_Family") ?? throw new Exception("No Family set!");
var device = properties.GetValueOrDefault("QuartusToolchain_Device") ?? throw new Exception("No Device set!");

//Add Family
qsf.SetGlobalAssignment("FAMILY", fpga.Fpga.Family);
qsf.SetGlobalAssignment("FAMILY", family);

//Add Device
qsf.SetGlobalAssignment("DEVICE", fpga.Fpga.Model);
qsf.SetGlobalAssignment("DEVICE", device);

//Add toplevel
qsf.SetGlobalAssignment("TOP_LEVEL_ENTITY", topEntity);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
using DynamicData;
using ImTools;
using OneWare.Essentials.Controls;
using OneWare.Essentials.Controls;
using OneWare.Essentials.ViewModels;
using OneWare.ProjectSystem.Models;
using OneWare.Quartus.Helper;
using OneWare.Settings;
using OneWare.Settings.ViewModels;
using OneWare.Settings.ViewModels.SettingTypes;
using OneWare.UniversalFpgaProjectSystem.Models;

namespace OneWare.Quartus.ViewModels;

public class QuartusCompileSettingsViewModel : FlexibleWindowViewModelBase
{
private string _qsfPath;
private QsfFile _qsfFile;
private readonly string _qsfPath;
private readonly QsfFile _qsfFile;

public SettingsCollectionViewModel SettingsCollection { get; } = new("Quartus Settings")
{
ShowTitle = false
};

private List<IQsfSetting> _settings = [];
private readonly List<IQsfSetting> _settings = [];

public QuartusCompileSettingsViewModel(UniversalFpgaProjectRoot fpgaProjectRoot)
{
Expand Down
124 changes: 124 additions & 0 deletions src/OneWare.Quartus/ViewModels/QuartusLoaderSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using DynamicData;
using OneWare.Essentials.Controls;
using OneWare.Essentials.ViewModels;
using OneWare.Settings;
using OneWare.Settings.ViewModels;
using OneWare.Settings.ViewModels.SettingTypes;
using OneWare.UniversalFpgaProjectSystem.Fpga;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Parser;

namespace OneWare.Quartus.ViewModels;

public class QuartusLoaderSettingsViewModel : FlexibleWindowViewModelBase
{
private readonly UniversalFpgaProjectRoot _projectRoot;
private readonly Dictionary<string, string> _settings;
private readonly IFpga _fpga;
private readonly ComboBoxSetting _shortTermModeSetting;
private readonly TitledSetting _shortTermOperationSetting;
private readonly TitledSetting _shortTermArgumentsSetting;
private readonly ComboBoxSetting _longTermModeSetting;
private readonly TitledSetting _longTermOperationSetting;
private readonly ComboBoxSetting _longTermFormatSetting;
private readonly TitledSetting _longTermCpfArgumentsSetting;
private readonly TitledSetting _longTermArgumentsSetting;

public SettingsCollectionViewModel SettingsCollection { get; } = new("Quartus Loader Settings")
{
ShowTitle = false
};

public QuartusLoaderSettingsViewModel(UniversalFpgaProjectRoot projectRoot, IFpga fpga)
{
_projectRoot = projectRoot;
_fpga = fpga;

Title = "Quartus Loader Settings";
Id = "Quartus Loader Settings";

var defaultProperties = fpga.Properties;
_settings = FpgaSettingsParser.LoadSettings(projectRoot, fpga.Name);

_shortTermModeSetting = new ComboBoxSetting("Short Term Mode", "Mode to use for Short Term Programming",
defaultProperties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Mode") ?? "", ["JTAG", "CJTAG", "AS", "PS"]);

_shortTermOperationSetting = new TitledSetting("Short Term Operation", "Operation to use for Short Term Programming",
defaultProperties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Operation") ?? "");

_shortTermArgumentsSetting = new TitledSetting("Short Term Additional Arguments", "Additional Arguments to use for Short Term Programming",
defaultProperties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Arguments") ?? "");

_longTermModeSetting = new ComboBoxSetting("Long Term Mode", "Mode to use for Long Term Programming",
defaultProperties.GetValueOrDefault("QuartusProgrammer_LongTerm_Mode") ?? "", ["JTAG", "CJTAG", "AS", "PS"]);

_longTermOperationSetting = new TitledSetting("Long Term Operation", "Operation to use for Long Term Programming",
defaultProperties.GetValueOrDefault("QuartusProgrammer_LongTerm_Operation") ?? "");

_longTermFormatSetting = new ComboBoxSetting("Long Term Format", "Programming Format to use",
defaultProperties.GetValueOrDefault("QuartusProgrammer_LongTerm_Format") ?? "", ["POF", "JIC"]);

_longTermCpfArgumentsSetting = new TitledSetting("Long Term Cpf Arguments", "If format is different from POF, these arguments will be used to convert .sof to given format",
defaultProperties.GetValueOrDefault("QuartusProgrammer_LongTerm_CpfArguments") ?? "");

_longTermArgumentsSetting = new TitledSetting("Long Term Additional Arguments", "Additional Arguments to use for Long Term Programming",
defaultProperties.GetValueOrDefault("QuartusProgrammer_LongTerm_Arguments") ?? "");

if (_settings.TryGetValue("QuartusProgrammer_ShortTerm_Mode", out var qPstMode))
_shortTermModeSetting.Value = qPstMode;

if (_settings.TryGetValue("QuartusProgrammer_ShortTerm_Operation", out var qPstOperation))
_shortTermOperationSetting.Value = qPstOperation;

if (_settings.TryGetValue("QuartusProgrammer_ShortTerm_Arguments", out var qPstArguments))
_shortTermArgumentsSetting.Value = qPstArguments;

if (_settings.TryGetValue("QuartusProgrammer_LongTerm_Mode", out var qPltMode))
_longTermModeSetting.Value = qPltMode;

if (_settings.TryGetValue("QuartusProgrammer_LongTerm_Operation", out var qPltOperation))
_longTermOperationSetting.Value = qPltOperation;

if (_settings.TryGetValue("QuartusProgrammer_LongTerm_Format", out var qPltFormat))
_longTermFormatSetting.Value = qPltFormat;

if (_settings.TryGetValue("QuartusProgrammer_LongTerm_CpfArguments", out var qPltCpfArguments))
_longTermCpfArgumentsSetting.Value = qPltCpfArguments;

if (_settings.TryGetValue("QuartusProgrammer_LongTerm_Arguments", out var qPltArguments))
_longTermArgumentsSetting.Value = qPltArguments;

SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_shortTermModeSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_shortTermOperationSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_shortTermArgumentsSetting));
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_longTermModeSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_longTermOperationSetting));
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_longTermFormatSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_longTermCpfArgumentsSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_longTermArgumentsSetting));
}

public void Save(FlexibleWindow flexibleWindow)
{
_settings["QuartusProgrammer_ShortTerm_Mode"] = _shortTermModeSetting.Value.ToString()!;
_settings["QuartusProgrammer_ShortTerm_Operation"] = _shortTermOperationSetting.Value.ToString()!;
_settings["QuartusProgrammer_ShortTerm_Arguments"] = _shortTermArgumentsSetting.Value.ToString()!;
_settings["QuartusProgrammer_LongTerm_Mode"] = _longTermModeSetting.Value.ToString()!;
_settings["QuartusProgrammer_LongTerm_Operation"] = _longTermOperationSetting.Value.ToString()!;
_settings["QuartusProgrammer_LongTerm_Format"] = _longTermFormatSetting.Value.ToString()!;
_settings["QuartusProgrammer_LongTerm_CpfArguments"] = _longTermCpfArgumentsSetting.Value.ToString()!;
_settings["QuartusProgrammer_LongTerm_Arguments"] = _longTermArgumentsSetting.Value.ToString()!;

FpgaSettingsParser.SaveSettings(_projectRoot, _fpga.Name, _settings);

Close(flexibleWindow);
}

public void Reset()
{
foreach (var setting in SettingsCollection.SettingModels)
{
setting.Setting.Value = setting.Setting.DefaultValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Avalonia.Controls;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using OneWare.Essentials.Services;
using OneWare.Quartus.Views;
using OneWare.UniversalFpgaProjectSystem.Fpga;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Services;
using Prism.Ioc;

namespace OneWare.Quartus.ViewModels;

public class QuartusLoaderWindowExtensionViewModel : ObservableObject
{
private readonly IWindowService _windowService;
private readonly UniversalFpgaProjectRoot _projectRoot;
private readonly IFpga? _fpga;

public bool IsVisible { get; }

public bool IsEnabled { get; }

public QuartusLoaderWindowExtensionViewModel(UniversalFpgaProjectRoot projectRoot, IWindowService windowService, FpgaService fpgaService)
{
_windowService = windowService;
_projectRoot = projectRoot;

_fpga = fpgaService.Fpgas.FirstOrDefault(x => x.Name == projectRoot.GetProjectProperty("Fpga"));

IsVisible = projectRoot.Loader is QuartusLoader;
IsEnabled = _fpga != null;
}

public async Task OpenSettingsAsync(Control control)
{
if (_fpga == null) return;

var ownerWindow = TopLevel.GetTopLevel(control) as Window;
await Dispatcher.UIThread.InvokeAsync(async () =>
{
try
{
await _windowService.ShowDialogAsync(new QuartusLoaderSettingsView()
{ DataContext = new QuartusLoaderSettingsViewModel(_projectRoot, _fpga) }, ownerWindow);
}
catch (Exception e)
{
ContainerLocator.Container.Resolve<ILogger>().Error(e.Message, e);
}
});
}
}
32 changes: 32 additions & 0 deletions src/OneWare.Quartus/Views/QuartusLoaderSettingsView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<controls:FlexibleWindow xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:OneWare.Essentials.Controls;assembly=OneWare.Essentials"
xmlns:behaviours="clr-namespace:OneWare.Essentials.Behaviours;assembly=OneWare.Essentials"
xmlns:viewModels="clr-namespace:OneWare.Quartus.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" PrefHeight="370" PrefWidth="400"
CustomIcon="{DynamicResource Material.SettingsOutline}"
Icon="avares://OneWare.Core/Assets/Images/Icons/Settings_White.png"
x:Class="OneWare.Quartus.Views.QuartusLoaderSettingsView" Name="QuartusLoaderSettingsViewView"
WindowStartupLocation="CenterOwner" Title="Quartus Loader Settings" x:DataType="viewModels:QuartusLoaderSettingsViewModel">
<Interaction.Behaviors>
<behaviours:CommandOnEnterBehaviour Command="{Binding Save}"
CommandParameter="{Binding #QuartusLoaderSettingsViewView}" />
</Interaction.Behaviors>
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" Margin="8" Classes="WindowButtons" HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Button Command="{Binding Reset}" ToolTip.Tip="Reset to Device Default">
<TextBlock Text="Reset" />
</Button>
<Button Background="{DynamicResource HighlightBrush}" Command="{Binding Save}"
CommandParameter="{Binding #QuartusLoaderSettingsViewView}">
<TextBlock Text="Save" />
</Button>
</StackPanel>
<ScrollViewer DockPanel.Dock="Top" >
<ContentControl Padding="4" Content="{Binding SettingsCollection}"/>
</ScrollViewer>
</DockPanel>
</controls:FlexibleWindow>
11 changes: 11 additions & 0 deletions src/OneWare.Quartus/Views/QuartusLoaderSettingsView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OneWare.Essentials.Controls;

namespace OneWare.Quartus.Views;

public partial class QuartusLoaderSettingsView : FlexibleWindow
{
public QuartusLoaderSettingsView()
{
InitializeComponent();
}
}
15 changes: 15 additions & 0 deletions src/OneWare.Quartus/Views/QuartusLoaderWindowExtensionView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels1="clr-namespace:OneWare.Quartus.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" IsVisible="{Binding IsVisible}"
x:Class="OneWare.Quartus.Views.QuartusLoaderWindowExtensionView" x:DataType="viewModels1:QuartusLoaderWindowExtensionViewModel">
<MenuItem Header="Quartus Loader Settings"
Command="{Binding OpenSettingsAsync}"
IsEnabled="{Binding IsEnabled}">
<MenuItem.Icon>
<Image Source="{DynamicResource Material.SettingsOutline}"/>
</MenuItem.Icon>
</MenuItem>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace OneWare.Quartus.Views;

public partial class QuartusLoaderWindowExtensionView : UserControl
{
public QuartusLoaderWindowExtensionView()
{
InitializeComponent();
}
}
8 changes: 4 additions & 4 deletions src/OneWare.Quartus/oneware.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"Dependencies": [
{
"Name": "OneWare.Essentials",
"MinVersion": "0.4.6.0",
"MaxVersion": "0.4.6.0"
"MinVersion": "0.4.7.0",
"MaxVersion": "0.4.7.0"
},
{
"Name": "OneWare.UniversalFpgaProjectSystem",
"MinVersion": "0.16.8.0",
"MaxVersion": "0.16.8.0"
"MinVersion": "0.17.0.0",
"MaxVersion": "0.17.0.0"
}
]
}

0 comments on commit fbdded7

Please sign in to comment.