Skip to content

Commit

Permalink
fix fpgaservice
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 13, 2023
1 parent ac3d268 commit a12bcd5
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 75 deletions.
9 changes: 9 additions & 0 deletions src/OneWare.Core/Styles/Icons.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">



<DrawingImage x:Key="BoxIcons.RegularLogOutCircle">
<GeometryDrawing Brush="{StaticResource IconColor}" Geometry="M-3.433E-009,7.2 L4,10.4 L4,8 L11.2,8 L11.2,6.4 L4,6.4 L4,4 z M8.8,1.887E-05 C8.794,1.190E-007 8.787,1.190E-007 8.78,1.190E-007 C6.798,1.190E-007 5.005,0.8064 3.71,2.109 L3.709,2.109 L4.84,3.24 C5.898,2.183 7.304,1.6 8.8,1.6 C10.3,1.6 11.7,2.183 12.76,3.24 C13.82,4.298 14.4,5.704 14.4,7.2 C14.4,8.696 13.82,10.1 12.76,11.16 C11.7,12.22 10.3,12.8 8.8,12.8 C7.304,12.8 5.898,12.22 4.84,11.16 L3.709,12.29 C5.068,13.65 6.876,14.4 8.8,14.4 C10.72,14.4 12.53,13.65 13.89,12.29 C15.25,10.93 16,9.124 16,7.2 C16,5.276 15.25,3.468 13.89,2.109 C12.6,0.8064 10.8,1.190E-007 8.82,1.190E-007 C8.813,1.190E-007 8.806,1.887E-05 8.799,3.762E-05 L8.8,3.762E-05 z" />
</DrawingImage>
<DrawingImage x:Key="BoxIcons.RegularLogInCircle">
<GeometryDrawing Brush="{StaticResource IconColor}" Geometry="M7.199,10.4 L11.2,7.2 L7.199,4 L7.199,6.4 L-2.060E-008,6.4 L-2.060E-008,8 L7.199,8 z M8.8,1.887E-05 C8.794,1.190E-007 8.787,1.190E-007 8.78,1.190E-007 C6.798,1.190E-007 5.005,0.8064 3.71,2.109 L3.709,2.109 L4.84,3.24 C5.898,2.183 7.304,1.6 8.8,1.6 C10.3,1.6 11.7,2.183 12.76,3.24 C13.82,4.298 14.4,5.704 14.4,7.2 C14.4,8.696 13.82,10.1 12.76,11.16 C11.7,12.22 10.3,12.8 8.8,12.8 C7.304,12.8 5.898,12.22 4.84,11.16 L3.709,12.29 C5.068,13.65 6.876,14.4 8.8,14.4 C10.72,14.4 12.53,13.65 13.89,12.29 C15.25,10.93 16,9.124 16,7.2 C16,5.276 15.25,3.468 13.89,2.109 C12.6,0.8064 10.8,1.190E-007 8.82,1.190E-007 C8.813,1.190E-007 8.806,1.887E-05 8.799,3.762E-05 L8.8,3.762E-05 z" />
</DrawingImage>

<DrawingImage x:Key="BoxIcons.RegularCheck">
<GeometryDrawing Brush="{StaticResource IconColor}"
Geometry="M5.225,9.205 L1.57,5.55 L-1.747E-007,7.12 L5.225,12.34 L16,1.57 L14.43,-1.651E-007 z" />
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.IceBreaker/IceBreakerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public void RegisterTypes(IContainerRegistry containerRegistry)

public void OnInitialized(IContainerProvider containerProvider)
{
containerProvider.Resolve<FpgaService>().AddFpga(new IceBreakerV10EViewModel());
containerProvider.Resolve<FpgaService>().AddFpga<IceBreakerV10EViewModel>();
}
}
49 changes: 48 additions & 1 deletion src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public NodeModel? SelectedNode

public RelayCommand DisconnectCommand { get; }

private string _searchTextPins = string.Empty;

public string SearchTextPins
{
get => _searchTextPins;
set => SetProperty(ref _searchTextPins, value);
}

private string _searchTextNodes = string.Empty;

public string SearchTextNodes
{
get => _searchTextNodes;
set => SetProperty(ref _searchTextNodes, value);
}

public FpgaModelBase()
{
ConnectCommand = new RelayCommand(Connect, () => SelectedNode is not null && SelectedPin is not null);
Expand All @@ -63,18 +79,49 @@ public FpgaModelBase()
ConnectCommand.NotifyCanExecuteChanged();
DisconnectCommand.NotifyCanExecuteChanged();
});

this.WhenValueChanged(x => x.SearchTextPins).Subscribe(SearchPins);
this.WhenValueChanged(x => x.SearchTextNodes).Subscribe(SearchNodes);

}

private void SearchPins(string? search)
{
if (string.IsNullOrWhiteSpace(search))
{
SelectedPin = null;
return;
}

SelectedPin = VisiblePins.FirstOrDefault(x => x.Name.Contains(search, StringComparison.OrdinalIgnoreCase)
|| x.Description.Contains(search, StringComparison.OrdinalIgnoreCase));
}

private void SearchNodes(string? search)
{
if (string.IsNullOrWhiteSpace(search))
{
SelectedNode = null;
return;
}

SelectedNode = VisibleNodes.FirstOrDefault(x => x.Name.Contains(search, StringComparison.OrdinalIgnoreCase));
}

private void Connect()
{
SelectedPin!.Connection = SelectedNode;
if (SelectedPin is null || SelectedNode is null) return;
SelectedPin.Connection = SelectedNode;
SelectedNode.Connection = SelectedPin;
ConnectCommand.NotifyCanExecuteChanged();
DisconnectCommand.NotifyCanExecuteChanged();
}

private void Disconnect()
{
if (SelectedPin is null || SelectedNode is null) return;
SelectedPin!.Connection = null;
SelectedNode!.Connection = null;
ConnectCommand.NotifyCanExecuteChanged();
DisconnectCommand.NotifyCanExecuteChanged();
}
Expand Down
22 changes: 19 additions & 3 deletions src/OneWare.UniversalFpgaProjectSystem/Models/NodeModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
namespace OneWare.UniversalFpgaProjectSystem.Models;
using CommunityToolkit.Mvvm.ComponentModel;

public class NodeModel
namespace OneWare.UniversalFpgaProjectSystem.Models;

public class NodeModel : ObservableObject
{
public string Name { get; }

public string Direction { get; }


private FpgaPinModel? _connection;
public FpgaPinModel? Connection
{
get => _connection;
set
{
this.SetProperty(ref _connection, value);
}
}

public NodeModel(string name)
public NodeModel(string name, string direction)
{
Name = name;
Direction = direction;
}

public override string ToString()
Expand Down
14 changes: 11 additions & 3 deletions src/OneWare.UniversalFpgaProjectSystem/Services/FpgaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ namespace OneWare.UniversalFpgaProjectSystem.Services;

public class FpgaService
{
public ObservableCollection<FpgaModelBase> FpgaModels { get; } = new();
public ObservableCollection<Type> FpgaModels { get; } = new();

public void AddFpga(FpgaModelBase fpgaModelBase)
public void AddFpga<T>() where T : FpgaModelBase
{
FpgaModels.Add(fpgaModelBase);
FpgaModels.Add(typeof(T));
}

public IEnumerable<FpgaModelBase> GetFpgas()
{
foreach (var t in FpgaModels)
{
yield return Activator.CreateInstance(t) as FpgaModelBase;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UniversalFpgaProjectCompileViewModel : ObservableObject
private readonly UniversalFpgaProjectRoot _project;
public string Title => "Connect and Compile - " + _project.Header;

public ObservableCollection<FpgaModelBase> FpgaModels { get; }
public List<FpgaModelBase> FpgaModels { get; }

private FpgaModelBase? _selectedFpga;
public FpgaModelBase? SelectedFpga
Expand All @@ -34,7 +34,7 @@ public UniversalFpgaProjectCompileViewModel(FpgaService fpgaService, NodeProvide
{
_project = project;

FpgaModels = fpgaService.FpgaModels;
FpgaModels = fpgaService.GetFpgas().ToList();

SelectedFpga = FpgaModels.FirstOrDefault();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
x:DataType="viewModels:UniversalFpgaProjectCompileViewModel"
Name="UniversalFpgaProjectCompileViewView">
<Interaction.Behaviors>
<behaviours:CommandOnEnterBehaviour Command="{Binding SaveAsync}"
CommandParameter="{Binding #UniversalFpgaProjectCompileViewView}" />
<behaviours:CommandOnEnterBehaviour Command="{Binding SelectedFpga.ConnectCommand, FallbackValue={x:Null}}"/>
</Interaction.Behaviors>

<Grid RowDefinitions="*, Auto">
Expand All @@ -41,30 +40,32 @@
IsVisible="{Binding Converter={x:Static converters:SharedConverters.ViewFoundConverter}}"
Content="{Binding }" />

<Grid ColumnDefinitions="*, 100, *" RowDefinitions="Auto, *" DockPanel.Dock="Top">
<TextBlock Text="Nodes"></TextBlock>
<Grid ColumnDefinitions="*, 70, *" RowDefinitions="20, *" DockPanel.Dock="Top">

<TextBlock Grid.Row="0" Grid.Column="0" Text="Pins:"></TextBlock>
<Border Grid.Column="0" Grid.Row="1" Background="{DynamicResource ThemeControlLowBrush}" BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}">
<DockPanel Background="{DynamicResource ThemeControlLowBrush}">
<controls:SearchBox DockPanel.Dock="Top" VerticalAlignment="Center"
Background="{DynamicResource ThemeBackgroundBrush}"
VerticalContentAlignment="Center" />
<ListBox AutoScrollToSelectedItem="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
BorderThickness="0,1,0,0" BorderBrush="{DynamicResource ThemeBorderLowBrush}"
Name="SignalList" ItemsSource="{Binding VisibleNodes}"
SelectedItem="{Binding Path=SelectedNode, Mode=TwoWay}" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding Name}" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
<DockPanel Background="{DynamicResource ThemeControlLowBrush}">
<controls:SearchBox DockPanel.Dock="Top" VerticalAlignment="Center"
Background="{DynamicResource ThemeBackgroundBrush}"
SearchText="{Binding SearchTextPins}"
VerticalContentAlignment="Center" SearchButtonVisible="False" />
<DataGrid Name="VisiblePinDataGrid" CanUserSortColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="True"
Background="{DynamicResource ThemeControlLowBrush}"
RowBackground="Transparent" IsReadOnly="True"
ItemsSource="{Binding VisiblePins}"
SelectedItem="{Binding SelectedPin}"
BorderThickness="0"
VerticalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Pin" Width="*" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Description" Width="*" Binding="{Binding Description}"/>
<DataGridTextColumn Header="Node" Width="*" Binding="{Binding Connection.Name, FallbackValue={}}"/>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</Border>

<Border Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Background="{DynamicResource ThemeBackgroundBrush}">
<Border Grid.Column="1" Grid.Row="1" Background="{DynamicResource ThemeBackgroundBrush}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Spacing="15">
<Button Command="{Binding ConnectCommand}" Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Image Source="{DynamicResource VSImageLib2019.Plugged_16x}" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
Expand All @@ -74,29 +75,29 @@
</Button>
</StackPanel>
</Border>

<TextBlock Grid.Row="0" Grid.Column="2" Text="Pins"></TextBlock>
<TextBlock Grid.Row="0" Grid.Column="2" Text="Nodes:"></TextBlock>
<Border Grid.Column="2" Grid.Row="1" Background="{DynamicResource ThemeControlLowBrush}" BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}">
<DockPanel Background="{DynamicResource ThemeControlLowBrush}">
<controls:SearchBox DockPanel.Dock="Top" VerticalAlignment="Center"
Background="{DynamicResource ThemeBackgroundBrush}"
VerticalContentAlignment="Center" />
<ListBox AutoScrollToSelectedItem="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
BorderThickness="0,1,0,0" BorderBrush="{DynamicResource ThemeBorderLowBrush}"
Name="PinList" ItemsSource="{Binding VisiblePins}"
SelectedItem="{Binding Path=SelectedPin, Mode=TwoWay}" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Connection}" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
VerticalContentAlignment="Center" SearchButtonVisible="False" SearchText="{Binding SearchTextNodes}"/>
<DataGrid CanUserSortColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="True"
Background="{DynamicResource ThemeControlLowBrush}"
RowBackground="Transparent" IsReadOnly="True"
ItemsSource="{Binding VisibleNodes}"
SelectedItem="{Binding SelectedNode}"
BorderThickness="0"
VerticalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Node" Width="*" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Direction" Width="*" Binding="{Binding Direction}"/>
<DataGridTextColumn Header="Pin" Width="*" Binding="{Binding Connection.Name, FallbackValue={}}"/>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</Border>

</Grid>
</DockPanel>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OneWare.Shared.Controls;
using DynamicData.Binding;
using OneWare.Shared.Controls;

namespace OneWare.UniversalFpgaProjectSystem.Views;

Expand All @@ -7,5 +8,10 @@ public partial class UniversalFpgaProjectCompileView : FlexibleWindow
public UniversalFpgaProjectCompileView()
{
InitializeComponent();

VisiblePinDataGrid.WhenValueChanged(x => x.SelectedItem).Subscribe(x =>
{
if(x is not null) VisiblePinDataGrid.ScrollIntoView(x, null);
});
}
}
60 changes: 36 additions & 24 deletions src/OneWare.Vhdl/Parsing/VhdlNodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,46 @@ public class VhdlNodeProvider : INodeProvider
public IEnumerable<NodeModel> ExtractNodes(IProjectFile file)
{
var fileLines = File.ReadAllLines(file.FullPath);

bool inEntity = false;
foreach (var line in fileLines)
{
// Check for entity start
if (Regex.IsMatch(line, @"\bentity\b", RegexOptions.IgnoreCase))
{
inEntity = true;
continue;
}
return ExtractEntityPorts(fileLines);
}

// Check for entity end
if (inEntity && Regex.IsMatch(line, @"\bend entity\b", RegexOptions.IgnoreCase))
{
inEntity = false;
continue;
}
public static IEnumerable<NodeModel> ExtractEntityPorts(IEnumerable<string> vhdlLines)
{
bool inPortSection = false;
var portPattern = @"\b(\w+)\s+:\s+(in|out|inout|buffer)\s+(\w+)(?:\((\d+)\s+downto\s+(\d+)\))?(?:\s+:=\s+[^;]+)?";

foreach (var line in vhdlLines)
{
if (line.Trim().StartsWith("port (", StringComparison.OrdinalIgnoreCase)) inPortSection = true;
if (line.Trim().StartsWith(");", StringComparison.OrdinalIgnoreCase)) inPortSection = false;

// Extract inputs and outputs
if (inEntity)
if (inPortSection)
{
MatchCollection matches = Regex.Matches(line, @"\b(\w+)\s*:\s*(in|out)\s*\w+", RegexOptions.IgnoreCase);
foreach (Match match in matches)
var match = Regex.Match(line, portPattern, RegexOptions.IgnoreCase);
if (match.Success)
{
string portName = match.Groups[1].Value;
string direction = match.Groups[2].Value;

yield return new NodeModel(portName);
var portName = match.Groups[1].Value;
var direction = match.Groups[2].Value;
var portType = match.Groups[3].Value;
var upperBound = match.Groups[4].Value;
var lowerBound = match.Groups[5].Value;

if (!string.IsNullOrEmpty(upperBound) && !string.IsNullOrEmpty(lowerBound))
{
// Expand std_logic_vector into individual ports
int upper = int.Parse(upperBound);
int lower = int.Parse(lowerBound);

for (var i = upper; i >= lower; i--)
{
yield return new NodeModel($"{portName}[{i}]", direction); //$"{portName}({i}) : {direction} {portType}";
}
}
else
{
// Single port
yield return new NodeModel(portName, direction); // $"{portName} : {direction} {portType}";
}
}
}
}
Expand Down

0 comments on commit a12bcd5

Please sign in to comment.