├── .editorconfig ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ └── feature_request.yml ├── actions │ ├── build │ │ └── action.yml │ ├── build_and_test │ │ └── action.yml │ └── test │ │ └── action.yml ├── release.yml └── workflows │ └── push_and_pr.yml ├── .gitignore ├── Apps └── CSP.Apps.Dev │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── CSP.Apps.Dev.csproj │ ├── CSPModule.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── RegionAdapter │ └── DockingManager │ │ ├── DocumentRegionActiveAwareBehavior .cs │ │ └── RegionAdapter.cs │ ├── Resources │ ├── Images │ │ ├── csp-logo.ico │ │ └── csp-logo.svg │ ├── Syncfusion.PropertyGrid.Wpf.zh-Hans.resx │ └── Syncfusion.Tools.Wpf.zh-Hans.resx │ ├── ViewModels │ ├── HomeViewModel.cs │ ├── MainViewModel.cs │ └── Windows │ │ ├── OutputViewModel.cs │ │ ├── PropertyViewModel.cs │ │ └── SolutionExplorerViewModel.cs │ └── Views │ ├── HomeView.xaml │ ├── HomeView.xaml.cs │ ├── MainView.xaml │ ├── MainView.xaml.cs │ └── Windows │ ├── DialogWindowView.xaml │ ├── DialogWindowView.xaml.cs │ ├── OutputView.xaml │ ├── OutputView.xaml.cs │ ├── PropertyView.xaml │ ├── PropertyView.xaml.cs │ ├── SolutionExplorerView.xaml │ └── SolutionExplorerView.xaml.cs ├── Components └── CSP.Components │ ├── CSP.Components.csproj │ ├── DockControl.cs │ └── ValuePropertyGrid │ ├── BooleanEditor.cs │ ├── DictionaryEditor.cs │ ├── IntEditor.cs │ └── StringEditor.cs ├── Database ├── CSP.Database.Tests │ ├── CSP.Database.Tests.csproj │ ├── MDKHelperTests.cs │ └── test │ │ └── STM32F401RE.uvprojx └── CSP.Database │ ├── CSP.Database.csproj │ ├── Components │ └── ValuePropertyGridComboEditor.cs │ ├── MCUHelper.cs │ ├── MCUInstance.cs │ ├── MDKHelper.cs │ ├── MDKInstance.cs │ └── Models │ ├── MCU │ ├── IPModel.cs │ ├── MCUModel.cs │ ├── MapModel.cs │ └── RepositoryModel.cs │ └── MDK │ └── UvprojxModel.cs ├── Directory.Build.props ├── Events └── CSP.Events │ ├── CSP.Events.csproj │ ├── ClosingEvent.cs │ ├── CustomEditorEvent.cs │ ├── GenerateEvent.cs │ ├── PropertyEvent.cs │ ├── RenderedEvent.cs │ ├── SaveEvent.cs │ └── SolutionExplorerEvent.cs ├── Extras └── CSP.Extras.BeforeBuild │ ├── AppStartup.cs │ ├── CSP.Extras.BeforeBuild.csproj │ └── Tool │ └── Resources │ └── Icon.cs ├── LICENSE.md ├── Models ├── CSP.Models.Interfaces │ ├── CSP.Models.Interfaces.csproj │ └── IDialogWindowParameters.cs └── CSP.Models │ ├── CSP.Models.csproj │ └── MCUModel.cs ├── Modules ├── CSP.Modules.Dialogs.NewMCU.Tests │ ├── CSP.Modules.Dialogs.NewMCU.Tests.csproj │ └── Models │ │ └── RepositoryAndMCUModelTests.cs ├── CSP.Modules.Dialogs.NewMCU │ ├── CSP.Modules.Dialogs.NewMCU.csproj │ ├── Models │ │ ├── DocumentModel.cs │ │ └── RepositoryModel.cs │ ├── NewMCUModule.cs │ ├── Resources │ │ └── Images │ │ │ ├── LQFP144.png │ │ │ ├── LQFP48.png │ │ │ └── LQFP64.png │ ├── ViewModels │ │ └── MCUSelectorViewModel.cs │ └── Views │ │ ├── Components │ │ ├── MCUBox.xaml │ │ ├── MCUBox.xaml.cs │ │ ├── MCUFilterBox.xaml │ │ └── MCUFilterBox.xaml.cs │ │ ├── MCUSelectorView.xaml │ │ └── MCUSelectorView.xaml.cs ├── CSP.Modules.Pages.MCU.Tests │ ├── CSP.Modules.Pages.MCU.Tests.csproj │ └── Services │ │ └── Generate │ │ ├── GPIOIncTests.cs │ │ └── GPIOSrcTests.cs └── CSP.Modules.Pages.MCU │ ├── CSP.Modules.Pages.MCU.csproj │ ├── Components │ └── LQFP │ │ ├── Pin.xaml │ │ ├── Pin.xaml.cs │ │ ├── PinBase.cs │ │ ├── PinBottom.xaml │ │ ├── PinBottom.xaml.cs │ │ ├── PinLeft.xaml │ │ ├── PinLeft.xaml.cs │ │ ├── PinRight.xaml │ │ ├── PinRight.xaml.cs │ │ ├── PinTop.xaml │ │ └── PinTop.xaml.cs │ ├── Enums │ └── DirectionEnum.cs │ ├── MCUModule.cs │ ├── Models │ ├── Description │ │ ├── ClockModel.cs │ │ ├── IPModel.cs │ │ ├── MapModel.cs │ │ └── PinoutModel.cs │ └── PinModel.cs │ ├── Resources │ ├── Copyright.txt │ ├── Files.Designer.cs │ ├── Files.resx │ ├── HeaderEnd.txt │ ├── HeaderStart.txt │ └── Themes │ │ └── ButtonPinMaterialLightThemes.xaml │ ├── Services │ └── Generate │ │ ├── GPIOInc.cs │ │ ├── GPIOSrc.cs │ │ ├── GenerateBase.cs │ │ ├── GenerateService.cs │ │ ├── IncBase.cs │ │ ├── Models │ │ ├── ExternModel.cs │ │ ├── FunctionDeclarationModel.cs │ │ ├── FunctionModel.cs │ │ ├── IncModel.cs │ │ ├── MacroModel.cs │ │ └── VariableModel.cs │ │ └── SrcBase.cs │ ├── Tools │ ├── DescriptionHelper.cs │ └── DescriptionInstance.cs │ ├── ViewModels │ ├── ClockTreeViewModel.cs │ ├── Components │ │ ├── Config │ │ │ ├── ClockViewModel.cs │ │ │ └── GPIOViewModel.cs │ │ └── Package │ │ │ ├── LQFP144ViewModel.cs │ │ │ ├── LQFP48ViewModel.cs │ │ │ └── LQFP64ViewModel.cs │ └── ConfigViewModel.cs │ └── Views │ ├── ClockTreeView.xaml │ ├── ClockTreeView.xaml.cs │ ├── Components │ ├── Config │ │ ├── ClockView.xaml │ │ ├── ClockView.xaml.cs │ │ ├── GPIOView.xaml │ │ └── GPIOView.xaml.cs │ └── Package │ │ ├── LQFP144View.xaml │ │ ├── LQFP144View.xaml.cs │ │ ├── LQFP48View.xaml │ │ ├── LQFP48View.xaml.cs │ │ ├── LQFP64View.xaml │ │ └── LQFP64View.xaml.cs │ ├── ConfigView.xaml │ ├── ConfigView.xaml.cs │ └── Windows │ ├── PropertyTableView.xaml │ └── PropertyTableView.xaml.cs ├── README.md ├── Resources ├── CSP.Resources.Tests │ ├── CSP.Resources.Tests.csproj │ └── IniFileTests.cs └── CSP.Resources │ ├── CSP.Resources.csproj │ ├── Icon.cs │ ├── Icon │ ├── BlockEight.png │ ├── BlockFive.png │ ├── BlockFour.png │ ├── BlockNine.png │ ├── BlockOne.png │ ├── BlockSeven.png │ ├── BlockSix.png │ ├── BlockTen.png │ ├── BlockThree.png │ ├── BlockTwo.png │ ├── BlocksAndArrows.png │ ├── C.png │ ├── CSharp.png │ ├── Chip.png │ ├── Error.png │ ├── Git.png │ ├── Information.png │ ├── Json.png │ ├── Lib.png │ ├── Log.png │ ├── New.png │ ├── PPT.png │ ├── Pdf.png │ ├── Pin.png │ ├── PlayOne.png │ ├── Setting.png │ ├── System.png │ ├── Time.png │ ├── Timer.png │ ├── Warning.png │ ├── Xml.png │ └── YellowFolder.png │ ├── IconInstance.cs │ ├── IniFile.cs │ ├── IniFileInstance.cs │ ├── Path.Designer.cs │ └── Path.resx ├── Services ├── CSP.Services.Tests │ └── CSP.Services.Tests.csproj └── CSP.Services │ ├── CSP.Services.csproj │ ├── Models │ └── ProjectModel.cs │ ├── ProjectHelper.cs │ └── ProjectInstance.cs ├── Utils ├── CSP.Utils.Tests │ └── CSP.Utils.Tests.csproj └── CSP.Utils │ ├── BindableBaseUtil.cs │ ├── CSP.Utils.csproj │ ├── DebugUtil.cs │ ├── DialogUtil.cs │ ├── Extensions │ ├── ByteArrayExtension.cs │ └── StringExtension.cs │ ├── MessageBoxUtil.cs │ ├── ObservableDictionary.cs │ ├── RegionUtil.cs │ ├── ThemesUtil.cs │ └── Util.cs └── csp.sln /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # 贡献指南 2 | 3 | 欢迎对这个项目进行 PR,但在贡献之前,请记住我在下面的想法。如果可能,请进行所有的单元测试。如果您不确定是否参与,请询问(在 [QQ群: 444093737](https://jq.qq.com/?_wv=1027&k=CWt7TZln) 中打个招呼)。 4 | 5 | ## 这个仓库的目的: 6 | 7 | 此软件的目的是兼容国产的 MCU 与 SOC 系列,目前国产公司的芯片开发环境一言难尽,甚至连数据手册都不愿意公开。在一颗 STM32 卖的比我电脑 CPU 还贵的时代,这是我不愿意看到的。尽管,大家可能会想:“国产 MCU,大都是都是为了抢占 STM32 的市场,他们的代码甚至可以直接兼容 HAL 库,为什么我不直接用cube呢?”。对此,我想说,此软件的目的绝不只有简单芯片基础配置功能:支持国产操作系统RTT,能够直接进行RTT的移植,一键创建线程等功能。加入外设芯片软件包,一些通用外设芯片,例如 Flash、IMU、EEPROM 等,可以一键移植。对于一些较为封闭的厂商芯片,也可以将代码打包成库,供大家进行选型以及参考。总的来说,我个人认为这并不是无用功。 8 | 9 | ## 代码标准: 10 | 11 | 我使用标准 Visual Studio 设置进行代码编写,使用 Resharper,并采用(大部分)ReSharper 的建议。我希望代码看起来非常相似。 12 | 13 | API 为王。如果向该仓库的公共接口(控件、助手等)添加任何内容,请注意命名和使用。如果我接受您的 PR 但稍微重命名,请不要生气。 14 | 15 | ## 提交 PR: 16 | 17 | 可能越小越好(在您的更改性质的合理范围内);至少将单个功能保留到单个分支/ PR。 -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug汇报 2 | description: 汇报一个 BUG 3 | labels: ["bug", "evaluation required"] 4 | title: '[Bug]: ' 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | 感谢您花时间填写此 Bug 报告! 10 | 为了方便进行 Bug 定位,我们需要知道如何重现该 Bug。 11 | 12 | - type: textarea 13 | id: bug-explanation 14 | attributes: 15 | label: 错误说明 16 | description: | 17 | - 告诉我们问题出在哪里。 18 | - 解释重现错误的不同步骤。 19 | - 有必要的话可以提供一个最小且可重现的示例。 20 | 21 | 您可以附上一些屏幕截图或/和视频以更好地说明问题。 22 | placeholder: 在此键入... 23 | validations: 24 | required: true 25 | 26 | - type: input 27 | id: version 28 | attributes: 29 | label: 版本 30 | description: 您运行的是哪个版本? 31 | placeholder: "示例: 1.0.0" 32 | validations: 33 | required: true 34 | 35 | - type: input 36 | id: system 37 | attributes: 38 | label: 系统 39 | description: 您运行的是哪个系统? 40 | placeholder: "示例: windows-10 x64" 41 | validations: 42 | required: true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Github 讨论组 4 | url: https://github.com/xqyjlj/csp/discussions 5 | about: 一些使用问题请到 Discussion 提问。 6 | 7 | - name: csp 主页导航 8 | url: https://xqyjlj.github.io/2022/08/20/CSP%E4%B8%BB%E9%A1%B5%E5%AF%BC%E8%88%AA/ 9 | about: 有关 csp 的简介与部分使用教程 10 | 11 | - name: QQ 群 12 | url: https://jq.qq.com/?_wv=1027&k=CWt7TZln 13 | about: "群号 444093737" 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: 功能需求 2 | description: 描述一个功能需求 3 | labels: ["enhancement"] 4 | title: '[Feature]: ' 5 | 6 | body: 7 | - type: textarea 8 | id: feature-request 9 | attributes: 10 | label: 想要的功能 11 | description: 请描述你所需要的新功能 12 | validations: 13 | required: true -------------------------------------------------------------------------------- /.github/actions/build/action.yml: -------------------------------------------------------------------------------- 1 | name: "build" 2 | description: "build the solution" 3 | inputs: 4 | solution: 5 | description: "The relative path to the solution file" 6 | required: true 7 | buildConfiguration: 8 | description: "The configuration to use when building" 9 | required: true 10 | runs: 11 | using: "composite" 12 | steps: 13 | - name: Setup .NET 14 | uses: actions/setup-dotnet@v2 15 | with: 16 | dotnet-version: | 17 | 6.x 18 | 19 | - name: restore dependencies 20 | shell: pwsh 21 | run: dotnet restore ${{ inputs.solution }} 22 | 23 | - name: build 24 | shell: pwsh 25 | run: dotnet build ${{ inputs.solution }} --configuration ${{ inputs.buildConfiguration }} --no-restore -p:Platform="Any CPU" -p:TreatWarningsAsErrors=True 26 | 27 | - name: msbuild 28 | shell: pwsh 29 | run: dotnet msbuild -property:Configuration=${{ inputs.buildConfiguration }} 30 | 31 | - name: upload artifact 32 | uses: actions/upload-artifact@v2 33 | with: 34 | name: csp-${{ github.run_number }} 35 | path: ${{ github.workspace }}/Apps/CSP.Apps.Dev/bin/${{ inputs.buildConfiguration }}/net6.0-windows 36 | -------------------------------------------------------------------------------- /.github/actions/build_and_test/action.yml: -------------------------------------------------------------------------------- 1 | name: "build_and_test" 2 | description: "build and test the solution" 3 | inputs: 4 | solution: 5 | description: "The relative path to the solution file" 6 | required: true 7 | buildConfiguration: 8 | description: "The configuration to use when building" 9 | required: true 10 | runs: 11 | using: "composite" 12 | steps: 13 | - name: Setup .NET 14 | uses: actions/setup-dotnet@v2 15 | with: 16 | dotnet-version: | 17 | 6.x 18 | 19 | - name: download repository 20 | uses: actions/checkout@v3 21 | with: 22 | repository: xqyjlj/csp_hal_apm32f1 23 | path: .repository/csp_hal_apm32f1 24 | 25 | - name: restore dependencies 26 | shell: pwsh 27 | run: dotnet restore ${{ inputs.solution }} 28 | 29 | - name: build 30 | shell: pwsh 31 | run: dotnet build ${{ inputs.solution }} --configuration ${{ inputs.buildConfiguration }} --no-restore -p:Platform="Any CPU" -p:TreatWarningsAsErrors=True 32 | 33 | - name: msbuild 34 | shell: pwsh 35 | run: dotnet msbuild -property:Configuration=${{ inputs.buildConfiguration }} 36 | 37 | - name: test 38 | shell: pwsh 39 | run: dotnet test ${{ inputs.solution }} --configuration ${{ inputs.buildConfiguration }} --no-build --verbosity normal --blame-crash 40 | 41 | - name: upload artifact 42 | uses: actions/upload-artifact@v2 43 | with: 44 | name: csp-${{ github.run_number }} 45 | path: ${{ github.workspace }}/Apps/CSP.Apps.Dev/bin/${{ inputs.buildConfiguration }}/net6.0-windows 46 | -------------------------------------------------------------------------------- /.github/actions/test/action.yml: -------------------------------------------------------------------------------- 1 | name: "test" 2 | description: "test the solution" 3 | inputs: 4 | solution: 5 | description: "The relative path to the solution file" 6 | required: true 7 | buildConfiguration: 8 | description: "The configuration to use when building" 9 | required: true 10 | runs: 11 | using: "composite" 12 | steps: 13 | - name: Setup .NET 14 | uses: actions/setup-dotnet@v2 15 | with: 16 | dotnet-version: | 17 | 6.x 18 | 19 | - name: restore dependencies 20 | shell: pwsh 21 | run: dotnet restore ${{ inputs.solution }} 22 | 23 | - name: msbuild 24 | shell: pwsh 25 | run: dotnet msbuild -property:Configuration=${{ inputs.buildConfiguration }} 26 | 27 | - name: test 28 | shell: pwsh 29 | run: dotnet test ${{ inputs.solution }} --configuration ${{ inputs.buildConfiguration }} --verbosity normal --blame-crash 30 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | # .github/release.yml 2 | 3 | changelog: 4 | exclude: 5 | labels: 6 | - ignore-for-release 7 | categories: 8 | - title: Key Changes 9 | labels: 10 | - release notes 11 | - title: Breaking Changes 12 | labels: 13 | - breaking change 14 | - visual breaking change 15 | -------------------------------------------------------------------------------- /.github/workflows/push_and_pr.yml: -------------------------------------------------------------------------------- 1 | # .github/workflows/push_and_pr.yml 2 | 3 | name: push and pull_request verification 4 | on: [push, pull_request] 5 | 6 | env: 7 | solution: csp.sln 8 | buildConfiguration: Release 9 | 10 | jobs: 11 | build_and_test: 12 | runs-on: windows-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | 16 | - uses: actions/checkout@v3 17 | with: 18 | repository: xqyjlj/csp_mcu_db 19 | path: Apps/CSP.Apps.Dev/bin/${{ env.buildConfiguration }}/net6.0-windows/Database/MCU 20 | 21 | - uses: actions/checkout@v3 22 | with: 23 | repository: xqyjlj/csp_hal_apm32f1 24 | path: Apps/CSP.Apps.Dev/bin/${{ env.buildConfiguration }}/net6.0-windows/Repository/csp_hal_apm32f1-latest 25 | 26 | - name: build_and_test 27 | uses: ./.github/actions/build_and_test 28 | timeout-minutes: 20 29 | with: 30 | solution: ${{ env.solution }} 31 | buildConfiguration: ${{ env.buildConfiguration }} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # VS Code 5 | *.vscode/ 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | .buildResources/ 14 | 15 | # User-specific files (MonoDevelop/Xamarin Studio) 16 | *.userprefs 17 | 18 | # Build results 19 | [Dd]ebug/ 20 | [Dd]ebugPublic/ 21 | [Rr]elease/ 22 | [Rr]eleases/ 23 | x64/ 24 | x86/ 25 | build/ 26 | bld/ 27 | [Bb]in/ 28 | [Oo]bj/ 29 | 30 | # Visual Studo 2015 cache/options directory 31 | .vs/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opensdf 79 | *.sdf 80 | *.cachefile 81 | 82 | # Visual Studio profiler 83 | *.psess 84 | *.vsp 85 | *.vspx 86 | 87 | # TFS 2012 Local Workspace 88 | $tf/ 89 | 90 | # Guidance Automation Toolkit 91 | *.gpState 92 | 93 | # ReSharper is a .NET coding add-in 94 | _ReSharper*/ 95 | *.[Rr]e[Ss]harper 96 | *.DotSettings.user 97 | *.DotSettings 98 | 99 | # JustCode is a .NET coding addin-in 100 | .JustCode 101 | 102 | # TeamCity is a build add-in 103 | _TeamCity* 104 | 105 | # DotCover is a Code Coverage Tool 106 | *.dotCover 107 | 108 | # NCrunch 109 | _NCrunch_* 110 | .*crunch*.local.xml 111 | 112 | # MightyMoose 113 | *.mm.* 114 | AutoTest.Net/ 115 | 116 | # Web workbench (sass) 117 | .sass-cache/ 118 | 119 | # Installshield output folder 120 | [Ee]xpress/ 121 | 122 | # DocProject is a documentation generator add-in 123 | DocProject/buildhelp/ 124 | DocProject/Help/*.HxT 125 | DocProject/Help/*.HxC 126 | DocProject/Help/*.hhc 127 | DocProject/Help/*.hhk 128 | DocProject/Help/*.hhp 129 | DocProject/Help/Html2 130 | DocProject/Help/html 131 | 132 | # Click-Once directory 133 | publish/ 134 | 135 | # Publish Web Output 136 | *.[Pp]ublish.xml 137 | *.azurePubxml 138 | # TODO: Comment the next line if you want to checkin your web deploy settings 139 | # but database connection strings (with potential passwords) will be unencrypted 140 | *.pubxml 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Others 160 | *.[Cc]ache 161 | ClientBin/ 162 | [Ss]tyle[Cc]op.* 163 | ~$* 164 | *~ 165 | *.dbmdl 166 | *.dbproj.schemaview 167 | *.pfx 168 | *.publishsettings 169 | node_modules/ 170 | bower_components/ 171 | 172 | # RIA/Silverlight projects 173 | Generated_Code/ 174 | 175 | # Backup & report files from converting an old project file 176 | # to a newer Visual Studio version. Backup files are not needed, 177 | # because we have git ;-) 178 | _UpgradeReport_Files/ 179 | Backup*/ 180 | UpgradeLog*.XML 181 | UpgradeLog*.htm 182 | 183 | # SQL Server files 184 | *.mdf 185 | *.ldf 186 | 187 | # Business Intelligence projects 188 | *.rdl.data 189 | *.bim.layout 190 | *.bim_*.settings 191 | 192 | # Microsoft Fakes 193 | FakesAssemblies/ 194 | 195 | # Node.js Tools for Visual Studio 196 | .ntvs_analysis.dat 197 | 198 | # Visual Studio 6 build log 199 | *.plg 200 | 201 | # Visual Studio 6 workspace options file 202 | *.opt 203 | 204 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/App.xaml: -------------------------------------------------------------------------------- 1 | 8 | 9 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Apps.Dev.Views; 2 | using CSP.Resources; 3 | using Prism.Ioc; 4 | using Prism.Modularity; 5 | using Prism.Regions; 6 | using Serilog; 7 | using Syncfusion.Windows.Tools.Controls; 8 | using System.IO; 9 | using System.Text; 10 | using System.Windows; 11 | 12 | namespace CSP.Apps.Dev 13 | { 14 | public partial class App 15 | { 16 | protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { 17 | base.ConfigureModuleCatalog(moduleCatalog); 18 | 19 | moduleCatalog.AddModule(); 20 | 21 | moduleCatalog.AddModule(); 22 | 23 | moduleCatalog.AddModule(); 24 | } 25 | 26 | protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings) { 27 | base.ConfigureRegionAdapterMappings(regionAdapterMappings); 28 | regionAdapterMappings.RegisterMapping(typeof(DockingManager), Container.Resolve()); 29 | } 30 | 31 | protected override Window CreateShell() { 32 | return Container.Resolve(); 33 | } 34 | 35 | protected override void RegisterTypes(IContainerRegistry containerRegistry) { 36 | } 37 | 38 | private void OnAppExit(object sender, ExitEventArgs e) { 39 | IniFile.Save(); 40 | Log.CloseAndFlush(); 41 | } 42 | 43 | private void OnAppStartup(object sender, StartupEventArgs e) { 44 | Log.Logger = new LoggerConfiguration() 45 | .MinimumLevel.Verbose() 46 | .WriteTo.Debug() 47 | .WriteTo.File(IniFile.PathLogFile,//文件保存路径 48 | outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}",//输出日期格式 49 | rollingInterval: RollingInterval.Day,//日志按日保存 50 | rollOnFileSizeLimit: true, // 限制单个文件的最大长度 51 | encoding: Encoding.UTF8, // 文件字符编码 52 | retainedFileCountLimit: 10, // 最大保存文件数 53 | fileSizeLimitBytes: 10 * 1024) // 最大单个文件长度 54 | .CreateLogger(); 55 | 56 | #if DEBUG 57 | var solutionDir = File.ReadAllLines("./SolutionDir.txt")[0]; 58 | IniFile.PathMCUDb = $"{solutionDir}../csp_mcu_db"; 59 | IniFile.PathRepository = $"{solutionDir}.."; 60 | #endif 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/CSP.Apps.Dev.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | true 7 | xqyjlj 8 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 9 | Resources\Images\csp-logo.ico 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/CSPModule.cs: -------------------------------------------------------------------------------- 1 | using CSP.Apps.Dev.Views; 2 | using CSP.Apps.Dev.Views.Windows; 3 | using CSP.Utils; 4 | using Prism.Ioc; 5 | using Prism.Modularity; 6 | using Prism.Regions; 7 | 8 | namespace CSP.Apps.Dev 9 | { 10 | public class CSPModule : IModule 11 | { 12 | public void OnInitialized(IContainerProvider containerProvider) { 13 | var regionManager = containerProvider.Resolve(); 14 | RegionUtil.RegisterViewWithRegion(regionManager, "Region.Window.Document", typeof(OutputView)); 15 | RegionUtil.RegisterViewWithRegion(regionManager, "Region.Window.Document", typeof(SolutionExplorerView)); 16 | RegionUtil.RegisterViewWithRegion(regionManager, "Region.Window.Document", typeof(PropertyView)); 17 | } 18 | 19 | public void RegisterTypes(IContainerRegistry containerRegistry) { 20 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.Home"); 21 | DialogUtil.RegisterDialogWindow(containerRegistry, "DialogWindow"); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/RegionAdapter/DockingManager/DocumentRegionActiveAwareBehavior .cs: -------------------------------------------------------------------------------- 1 | using Prism.Regions; 2 | using Prism.Regions.Behaviors; 3 | using Syncfusion.Windows.Tools.Controls; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | 7 | namespace CSP.Apps.Dev.RegionAdapter.DockingManager 8 | { 9 | public class DocumentRegionActiveAwareBehavior : RegionBehavior, IHostAwareRegionBehavior 10 | { 11 | public const string BehaviorKey = "DocumentRegionActiveAwareBehavior"; 12 | private DependencyObject _hostControl; 13 | 14 | public DependencyObject HostControl { 15 | get => _hostControl; 16 | set => _hostControl = value as Syncfusion.Windows.Tools.Controls.DockingManager; 17 | } 18 | 19 | protected override void OnAttach() { 20 | if (HostControl is Syncfusion.Windows.Tools.Controls.DockingManager { DocContainer: DocumentContainer docContainer }) { 21 | docContainer.AddTabDocumentAtLast = true; 22 | docContainer.ActiveDocumentChanged += DocumentRegionActiveAwareBehavior_ActiveDocumentChanged; 23 | } 24 | } 25 | 26 | private void DocumentRegionActiveAwareBehavior_ActiveDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { 27 | if (e.OldValue != null) { 28 | var item = e.OldValue; 29 | 30 | //are we dealing with a ContentPane directly 31 | if (Region.Views.Contains(item) && Region.ActiveViews.Contains(item)) { 32 | Region.Deactivate(item); 33 | } 34 | else { 35 | //now check to see if we have any views that were injected 36 | if (item is ContentControl contentControl) { 37 | var injectedView = contentControl.Content; 38 | if (Region.Views.Contains(injectedView) && Region.ActiveViews.Contains(injectedView)) 39 | Region.Deactivate(injectedView); 40 | } 41 | } 42 | } 43 | 44 | if (e.NewValue != null) { 45 | var item = e.NewValue; 46 | 47 | //are we dealing with a ContentPane directly 48 | if (Region.Views.Contains(item) && !this.Region.ActiveViews.Contains(item)) { 49 | Region.Activate(item); 50 | } 51 | else { 52 | //now check to see if we have any views that were injected 53 | if (item is ContentControl contentControl) { 54 | var injectedView = contentControl.Content; 55 | if (Region.Views.Contains(injectedView) && !this.Region.ActiveViews.Contains(injectedView)) 56 | Region.Activate(injectedView); 57 | } 58 | } 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/RegionAdapter/DockingManager/RegionAdapter.cs: -------------------------------------------------------------------------------- 1 | using Prism.Regions; 2 | using System.Collections.Specialized; 3 | using System.Windows; 4 | 5 | namespace CSP.Apps.Dev.RegionAdapter.DockingManager 6 | { 7 | public class RegionAdapter : RegionAdapterBase 8 | { 9 | public RegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory) { 10 | } 11 | 12 | protected override void Adapt(IRegion region, Syncfusion.Windows.Tools.Controls.DockingManager regionTarget) { 13 | region.Views.CollectionChanged += (_, e) => { 14 | if (e.Action == NotifyCollectionChangedAction.Add) { 15 | if (e.NewItems != null) { 16 | foreach (FrameworkElement element in e.NewItems) { 17 | if (!regionTarget.Children.Contains(element)) { 18 | regionTarget.BeginInit(); 19 | regionTarget.Children.Add(element); 20 | regionTarget.EndInit(); 21 | } 22 | } 23 | } 24 | } 25 | }; 26 | } 27 | 28 | protected override void AttachBehaviors(IRegion region, Syncfusion.Windows.Tools.Controls.DockingManager regionTarget) { 29 | base.AttachBehaviors(region, regionTarget); 30 | if (!region.Behaviors.ContainsKey(DocumentRegionActiveAwareBehavior.BehaviorKey)) { 31 | region.Behaviors.Add(DocumentRegionActiveAwareBehavior.BehaviorKey, new DocumentRegionActiveAwareBehavior { HostControl = regionTarget }); 32 | } 33 | } 34 | 35 | protected override IRegion CreateRegion() { 36 | return new SingleActiveRegion(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Resources/Images/csp-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Apps/CSP.Apps.Dev/Resources/Images/csp-logo.ico -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Resources/Images/csp-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/ViewModels/HomeViewModel.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | using Prism.Regions; 3 | 4 | namespace CSP.Apps.Dev.ViewModels 5 | { 6 | public class HomeViewModel : BindableBase, INavigationAware 7 | { 8 | #region INavigationAware 9 | 10 | public bool IsNavigationTarget(NavigationContext navigationContext) { 11 | return true; 12 | } 13 | 14 | public void OnNavigatedFrom(NavigationContext navigationContext) { 15 | } 16 | 17 | public void OnNavigatedTo(NavigationContext navigationContext) { 18 | } 19 | 20 | #endregion INavigationAware 21 | } 22 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/ViewModels/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Events; 2 | using CSP.Utils; 3 | using Prism.Commands; 4 | using Prism.Events; 5 | using Prism.Mvvm; 6 | using Prism.Regions; 7 | using Prism.Services.Dialogs; 8 | 9 | namespace CSP.Apps.Dev.ViewModels 10 | { 11 | public class MainViewModel : BindableBase 12 | { 13 | private readonly IDialogService _dialogService; 14 | private readonly IEventAggregator _eventAggregator; 15 | private readonly IRegionManager _regionManager; 16 | 17 | public MainViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogService) { 18 | _regionManager = regionManager; 19 | _eventAggregator = eventAggregator; 20 | _dialogService = dialogService; 21 | } 22 | 23 | public DelegateCommand OnBuild { 24 | get { 25 | return new DelegateCommand(() => { 26 | }); 27 | } 28 | } 29 | 30 | public DelegateCommand OnGenerate { 31 | get { 32 | return new DelegateCommand(() => { 33 | _eventAggregator.GetEvent().Publish("Events.Generate"); 34 | }); 35 | } 36 | } 37 | 38 | public DelegateCommand OnNewMCU { 39 | get { 40 | return new DelegateCommand(() => { 41 | DialogUtil.ShowModalDialog(_dialogService, "Dialog.NewMCU", null, (IDialogResult result) => { 42 | }, "DialogWindow"); 43 | }); 44 | } 45 | } 46 | 47 | public DelegateCommand OnSave { 48 | get { 49 | return new DelegateCommand(() => { 50 | _eventAggregator.GetEvent().Publish("Events.Save"); 51 | }); 52 | } 53 | } 54 | 55 | public DelegateCommand OnWindowClosing { 56 | get { 57 | return new DelegateCommand(() => { 58 | _eventAggregator.GetEvent().Publish("Events.Closing.Window"); 59 | }); 60 | } 61 | } 62 | 63 | public DelegateCommand OnWindowRendered { 64 | get { 65 | return new DelegateCommand(() => { 66 | _eventAggregator.GetEvent().Publish("Events.Rendered.Window"); 67 | 68 | RegionUtil.RequestNavigate(_regionManager, "Region.Window.Document", "Page.Home"); 69 | RegionUtil.RequestNavigate(_regionManager, "Region.Window.Document", "Page.MCU.Config"); 70 | }); 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/ViewModels/Windows/OutputViewModel.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | 3 | namespace CSP.Apps.Dev.ViewModels.Windows 4 | { 5 | public class OutputViewModel : BindableBase 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/ViewModels/Windows/PropertyViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Components.ValuePropertyGrid; 2 | using CSP.Events; 3 | using Prism.Events; 4 | using Prism.Mvvm; 5 | using Syncfusion.Windows.PropertyGrid; 6 | 7 | namespace CSP.Apps.Dev.ViewModels.Windows 8 | { 9 | public class PropertyViewModel : BindableBase 10 | { 11 | private readonly IEventAggregator _eventAggregator; 12 | 13 | public PropertyViewModel(IEventAggregator eventAggregator) { 14 | _eventAggregator = eventAggregator; 15 | 16 | eventAggregator.GetEvent().Subscribe(name => { 17 | AddCustomEditor(); 18 | }); 19 | } 20 | 21 | private void AddCustomEditor() { 22 | CustomEditor editor = new() { 23 | Editor = new DictionaryEditor(), 24 | HasPropertyType = true, 25 | PropertyType = typeof(DictionaryEditorModel) 26 | }; 27 | _eventAggregator.GetEvent().Publish(editor); 28 | 29 | editor = new CustomEditor { 30 | Editor = new StringEditor(), 31 | HasPropertyType = true, 32 | PropertyType = typeof(StringEditorModel) 33 | }; 34 | _eventAggregator.GetEvent().Publish(editor); 35 | 36 | editor = new CustomEditor { 37 | Editor = new BooleanEditor(), 38 | HasPropertyType = true, 39 | PropertyType = typeof(BooleanEditorModel) 40 | }; 41 | _eventAggregator.GetEvent().Publish(editor); 42 | 43 | editor = new CustomEditor { 44 | Editor = new IntEditor(), 45 | HasPropertyType = true, 46 | PropertyType = typeof(IntEditorModel) 47 | }; 48 | _eventAggregator.GetEvent().Publish(editor); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/ViewModels/Windows/SolutionExplorerViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Events; 2 | using CSP.Resources; 3 | using Prism.Events; 4 | using Prism.Mvvm; 5 | using Prism.Regions; 6 | using System.Collections.Generic; 7 | using System.Collections.ObjectModel; 8 | using System.IO; 9 | 10 | namespace CSP.Apps.Dev.ViewModels.Windows 11 | { 12 | public class SolutionExplorerViewModel : BindableBase, INavigationAware 13 | { 14 | #region INavigationAware 15 | 16 | public bool IsNavigationTarget(NavigationContext navigationContext) { 17 | return true; 18 | } 19 | 20 | public void OnNavigatedFrom(NavigationContext navigationContext) { 21 | } 22 | 23 | public void OnNavigatedTo(NavigationContext navigationContext) { 24 | } 25 | 26 | #endregion INavigationAware 27 | 28 | private ObservableCollection _directories = new(); 29 | 30 | public SolutionExplorerViewModel(IEventAggregator eventAggregator) { 31 | eventAggregator.GetEvent().Subscribe(OnSolutionExplorerReceive); 32 | 33 | var rootNode1 = new SolutionExplorerEvent.Model("解决方案") { Image = Icon.YellowFolder }; 34 | 35 | InitDirectories("./", rootNode1); 36 | Directories.Add(rootNode1); 37 | } 38 | 39 | public ObservableCollection Directories { 40 | get => _directories; 41 | set => SetProperty(ref _directories, value); 42 | } 43 | 44 | private static void InitDirectories(string path, SolutionExplorerEvent.Model fileInfo) { 45 | DirectoryInfo d = new(path); 46 | FileSystemInfo[] fsInfos = d.GetFileSystemInfos(); 47 | var directories = new List(); 48 | var files = new List(); 49 | 50 | foreach (FileSystemInfo fsInfo in fsInfos) { 51 | if (fsInfo is DirectoryInfo) //判断是否为文件夹 52 | { 53 | directories.Add(fsInfo); 54 | } 55 | else { 56 | files.Add(fsInfo); 57 | } 58 | } 59 | 60 | foreach (var directory in directories) { 61 | var info = new SolutionExplorerEvent.Model(directory.FullName); 62 | InitDirectories(directory.FullName, info);//递归调用 63 | fileInfo.Children.Add(info); 64 | } 65 | 66 | foreach (var file in files) { 67 | var info = new SolutionExplorerEvent.Model(file.FullName); 68 | fileInfo.Children.Add(info); 69 | } 70 | } 71 | 72 | private void OnSolutionExplorerReceive(IEnumerable infos) { 73 | foreach (var info in infos) { 74 | Directories[0].Children.Insert(0, info); 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/HomeView.xaml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 欢迎使用 CSP 25 | 26 | 27 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/HomeView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Apps.Dev.Views 2 | { 3 | public partial class HomeView 4 | { 5 | public HomeView() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/MainView.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using System.Globalization; 3 | 4 | namespace CSP.Apps.Dev.Views 5 | { 6 | public partial class MainView 7 | { 8 | public MainView() { 9 | System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-Hans"); 10 | ThemesUtil.SetThemes(this, "Office2019Colorful"); 11 | InitializeComponent(); 12 | } 13 | 14 | // private void OnDockingManagerMainChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 15 | // { 16 | // MenuView.Items.Clear(); 17 | // MenuView.Items.Add(new MenuItem { Header = "打开方式(_N)" }); 18 | // MenuView.Items.Add(new Separator()); 19 | // foreach (var child in DockingManagerMain.Children) 20 | // { 21 | // if (child is not DockControlModel dock) 22 | // return; 23 | // 24 | // var headerObj = DockingManager.GetHeader(dock); 25 | // 26 | // if (headerObj is not string header) 27 | // return; 28 | // 29 | // if (dock.Key >= 'A' && dock.Key <= 'Z') 30 | // { 31 | // header = $"{header}(_{dock.Key})"; 32 | // } 33 | // 34 | // MenuView.Items.Add(new MenuItem { Header = header, Icon = dock.Icon }); 35 | // } 36 | // } 37 | } 38 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/DialogWindowView.xaml: -------------------------------------------------------------------------------- 1 | 18 | 19 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/DialogWindowView.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using Prism.Services.Dialogs; 3 | 4 | namespace CSP.Apps.Dev.Views.Windows 5 | { 6 | public partial class DialogWindowView : IDialogWindow 7 | { 8 | public DialogWindowView() { 9 | ThemesUtil.SetThemes(this, "Office2019Colorful"); 10 | 11 | InitializeComponent(); 12 | } 13 | 14 | public IDialogResult Result { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/OutputView.xaml: -------------------------------------------------------------------------------- 1 | 19 | 20 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/OutputView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Apps.Dev.Views.Windows 2 | { 3 | public partial class OutputView 4 | { 5 | public OutputView() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/PropertyView.xaml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 28 | 29 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/PropertyView.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Events; 2 | using Prism.Events; 3 | using Prism.Ioc; 4 | using Syncfusion.Windows.PropertyGrid; 5 | 6 | namespace CSP.Apps.Dev.Views.Windows 7 | { 8 | public partial class PropertyView 9 | { 10 | public PropertyView() { 11 | InitializeComponent(); 12 | 13 | var containerExtension = ContainerLocator.Current; 14 | var eventAggregator = containerExtension.Resolve(); 15 | eventAggregator.GetEvent().Subscribe(OnPropertyReceive); 16 | eventAggregator.GetEvent().Subscribe(OnCustomEditorReceive); 17 | } 18 | 19 | private void OnCustomEditorReceive(CustomEditor editor) { 20 | Property.CustomEditorCollection.Add(editor); 21 | } 22 | 23 | private void OnPropertyReceive(object property) { 24 | Property.SelectedObject = property; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/SolutionExplorerView.xaml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 43 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Apps/CSP.Apps.Dev/Views/Windows/SolutionExplorerView.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Events; 2 | using System.Windows.Input; 3 | 4 | namespace CSP.Apps.Dev.Views.Windows 5 | { 6 | public partial class SolutionExplorerView 7 | { 8 | public SolutionExplorerView() { 9 | InitializeComponent(); 10 | } 11 | 12 | private void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { 13 | var item = TreeView.SelectedItem; 14 | 15 | if (item is not SolutionExplorerEvent.Model value) 16 | return; 17 | 18 | value.CallBack?.Invoke(value.Name); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Components/CSP.Components/CSP.Components.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Components/CSP.Components/DockControl.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace CSP.Components 5 | { 6 | public class DockControl : UserControl 7 | { 8 | public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", 9 | typeof(Image), 10 | typeof(DockControl), 11 | new FrameworkPropertyMetadata(null, OnIconChanged) { BindsTwoWayByDefault = true }); 12 | 13 | public static readonly DependencyProperty KeyProperty = DependencyProperty.Register("Key", 14 | typeof(char), 15 | typeof(DockControl), 16 | new FrameworkPropertyMetadata('a', OnKeyChanged) { BindsTwoWayByDefault = true }); 17 | 18 | public DockControl() { 19 | } 20 | 21 | public Image Icon { 22 | get => (Image)GetValue(IconProperty); 23 | set => SetValue(IconProperty, value); 24 | } 25 | 26 | public char Key { 27 | get => (char)GetValue(KeyProperty); 28 | set => SetValue(KeyProperty, value); 29 | } 30 | 31 | private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { 32 | } 33 | 34 | private static void OnKeyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Components/CSP.Components/ValuePropertyGrid/BooleanEditor.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | using Syncfusion.Windows.PropertyGrid; 3 | using System.ComponentModel; 4 | using System.Reflection; 5 | using System.Windows.Controls; 6 | using System.Windows.Data; 7 | 8 | namespace CSP.Components.ValuePropertyGrid 9 | { 10 | public class BooleanEditor : BaseTypeEditor 11 | { 12 | private CheckBox _checkBox; 13 | 14 | public override void Attach(PropertyViewItem property, PropertyItem info) { 15 | if (info.Value is not BooleanEditorModel) 16 | return; 17 | 18 | var binding = new Binding("Value.Boolean") { 19 | Mode = BindingMode.TwoWay, 20 | Source = info, 21 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 22 | }; 23 | BindingOperations.SetBinding(_checkBox, CheckBox.IsCheckedProperty, binding); 24 | 25 | binding = new Binding("Value.Boolean") { 26 | Mode = BindingMode.TwoWay, 27 | Source = info, 28 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 29 | }; 30 | BindingOperations.SetBinding(_checkBox, CheckBox.ToolTipProperty, binding); 31 | 32 | _checkBox.IsEnabled = !info.IsReadOnly; 33 | } 34 | 35 | public override object Create(PropertyInfo propertyInfo) { 36 | return CreateEditor(); 37 | } 38 | 39 | public override object Create(PropertyDescriptor propertyDescriptor) { 40 | return CreateEditor(); 41 | } 42 | 43 | public override void Detach(PropertyViewItem property) { 44 | _checkBox = null; 45 | } 46 | 47 | private CheckBox CreateEditor() { 48 | _checkBox = new CheckBox(); 49 | return _checkBox; 50 | } 51 | } 52 | 53 | public class BooleanEditorModel : BindableBase 54 | { 55 | private bool _boolean; 56 | 57 | public bool Boolean { 58 | get => _boolean; 59 | set => SetProperty(ref _boolean, value); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Components/CSP.Components/ValuePropertyGrid/DictionaryEditor.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using CSP.Utils.Extensions; 3 | using Syncfusion.Windows.PropertyGrid; 4 | using System.ComponentModel; 5 | using System.Reflection; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | 9 | namespace CSP.Components.ValuePropertyGrid 10 | { 11 | public class DictionaryEditor : BaseTypeEditor 12 | { 13 | private ComboBox _comboBox; 14 | 15 | public override void Attach(PropertyViewItem property, PropertyItem info) { 16 | if (info.Value is not DictionaryEditorModel value) 17 | return; 18 | 19 | var binding = new Binding("Value.Source") { 20 | Mode = BindingMode.TwoWay, 21 | Source = info, 22 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 23 | }; 24 | BindingOperations.SetBinding(_comboBox, ComboBox.ItemsSourceProperty, binding); 25 | 26 | binding = new Binding("Value.Value") { 27 | Mode = BindingMode.TwoWay, 28 | Source = info, 29 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 30 | }; 31 | BindingOperations.SetBinding(_comboBox, ComboBox.SelectedValueProperty, binding); 32 | 33 | binding = new Binding("Value.Value") { 34 | Mode = BindingMode.TwoWay, 35 | Source = info, 36 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 37 | }; 38 | BindingOperations.SetBinding(_comboBox, ComboBox.ToolTipProperty, binding); 39 | 40 | _comboBox.DisplayMemberPath = "Value"; 41 | _comboBox.SelectedValuePath = "Key"; 42 | 43 | if (value.Value.IsNullOrEmpty()) { 44 | _comboBox.SelectedIndex = 0; 45 | } 46 | else { 47 | _comboBox.SelectedValue = value.Value; 48 | } 49 | } 50 | 51 | public override object Create(PropertyInfo propertyInfo) { 52 | return CreateEditor(); 53 | } 54 | 55 | public override object Create(PropertyDescriptor propertyDescriptor) { 56 | return CreateEditor(); 57 | } 58 | 59 | public override void Detach(PropertyViewItem property) { 60 | _comboBox = null; 61 | } 62 | 63 | private ComboBox CreateEditor() { 64 | _comboBox = new ComboBox(); 65 | return _comboBox; 66 | } 67 | } 68 | 69 | public class DictionaryEditorModel : BindableBaseUtil 70 | { 71 | private string _value; 72 | 73 | public ObservableDictionary Source { get; init; } = new(); 74 | 75 | public string Value { 76 | get => _value; 77 | set => SetProperty(ref _value, value); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /Components/CSP.Components/ValuePropertyGrid/IntEditor.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | using Syncfusion.Windows.PropertyGrid; 3 | using Syncfusion.Windows.Shared; 4 | using System.ComponentModel; 5 | using System.Reflection; 6 | using System.Windows.Data; 7 | 8 | namespace CSP.Components.ValuePropertyGrid 9 | { 10 | public class IntEditor : BaseTypeEditor 11 | { 12 | private IntegerTextBox _integerTextBox; 13 | 14 | public override void Attach(PropertyViewItem property, PropertyItem info) { 15 | if (info.Value is not IntEditorModel) 16 | return; 17 | 18 | var binding = new Binding("Value.Boolean") { 19 | Mode = BindingMode.TwoWay, 20 | Source = info, 21 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 22 | }; 23 | BindingOperations.SetBinding(_integerTextBox, IntegerTextBox.ValueProperty, binding); 24 | 25 | binding = new Binding("Value.Boolean") { 26 | Mode = BindingMode.TwoWay, 27 | Source = info, 28 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 29 | }; 30 | BindingOperations.SetBinding(_integerTextBox, IntegerTextBox.ToolTipProperty, binding); 31 | 32 | _integerTextBox.IsReadOnly = info.IsReadOnly; 33 | } 34 | 35 | public override object Create(PropertyInfo propertyInfo) { 36 | return CreateEditor(); 37 | } 38 | 39 | public override object Create(PropertyDescriptor propertyDescriptor) { 40 | return CreateEditor(); 41 | } 42 | 43 | public override void Detach(PropertyViewItem property) { 44 | _integerTextBox = null; 45 | } 46 | 47 | private IntegerTextBox CreateEditor() { 48 | _integerTextBox = new IntegerTextBox(); 49 | return _integerTextBox; 50 | } 51 | } 52 | 53 | public class IntEditorModel : BindableBase 54 | { 55 | private int _int; 56 | 57 | public int Int { 58 | get => _int; 59 | set => SetProperty(ref _int, value); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Components/CSP.Components/ValuePropertyGrid/StringEditor.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | using Syncfusion.Windows.PropertyGrid; 3 | using System.ComponentModel; 4 | using System.Reflection; 5 | using System.Windows.Controls; 6 | using System.Windows.Data; 7 | 8 | namespace CSP.Components.ValuePropertyGrid 9 | { 10 | public class StringEditor : BaseTypeEditor 11 | { 12 | private TextBox _textBox; 13 | 14 | public override void Attach(PropertyViewItem property, PropertyItem info) { 15 | if (info.Value is not StringEditorModel) 16 | return; 17 | 18 | var binding = new Binding("Value.String") { 19 | Mode = BindingMode.TwoWay, 20 | Source = info, 21 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 22 | }; 23 | BindingOperations.SetBinding(_textBox, TextBox.TextProperty, binding); 24 | 25 | binding = new Binding("Value.String") { 26 | Mode = BindingMode.TwoWay, 27 | Source = info, 28 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 29 | }; 30 | BindingOperations.SetBinding(_textBox, TextBox.ToolTipProperty, binding); 31 | 32 | _textBox.IsReadOnly = info.IsReadOnly; 33 | } 34 | 35 | public override object Create(PropertyInfo propertyInfo) { 36 | return CreateEditor(); 37 | } 38 | 39 | public override object Create(PropertyDescriptor propertyDescriptor) { 40 | return CreateEditor(); 41 | } 42 | 43 | public override void Detach(PropertyViewItem property) { 44 | _textBox = null; 45 | } 46 | 47 | private TextBox CreateEditor() { 48 | _textBox = new TextBox(); 49 | return _textBox; 50 | } 51 | } 52 | 53 | public class StringEditorModel : BindableBase 54 | { 55 | private string _string = string.Empty; 56 | 57 | public string String { 58 | get => _string; 59 | set => SetProperty(ref _string, value); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Database/CSP.Database.Tests/CSP.Database.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Database/CSP.Database.Tests/MDKHelperTests.cs: -------------------------------------------------------------------------------- 1 | using CSP.Resources; 2 | using System; 3 | using System.IO; 4 | using Xunit; 5 | using Xunit.Abstractions; 6 | 7 | namespace CSP.Database.Tests 8 | { 9 | public class MDKHelperTests : IDisposable 10 | { 11 | private readonly ITestOutputHelper _testOutputHelper; 12 | 13 | public MDKHelperTests(ITestOutputHelper testOutputHelper) { 14 | _testOutputHelper = testOutputHelper; 15 | } 16 | 17 | public void Dispose() { 18 | IniFile.Save(); 19 | } 20 | 21 | [Fact] 22 | public void Load() { 23 | var solutionDir = File.ReadAllLines("./SolutionDir.txt")[0]; 24 | var path = $"{solutionDir}/Database/CSP.Database.Tests/test/STM32F401RE.uvprojx"; 25 | var model = MDKHelper.Load(path); 26 | 27 | Assert.False(model == null); 28 | Assert.False(model.Targets == null); 29 | Assert.False(model.Targets.Length == 0); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Database/CSP.Database/CSP.Database.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Database/CSP.Database/Components/ValuePropertyGridComboEditor.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils.Extensions; 2 | using Syncfusion.Windows.PropertyGrid; 3 | using System.ComponentModel; 4 | using System.Reflection; 5 | using System.Windows.Controls; 6 | using System.Windows.Data; 7 | 8 | namespace CSP.Database.Components 9 | { 10 | public class ValuePropertyGridComboEditor : BaseTypeEditor 11 | { 12 | private ComboBox _comboBox; 13 | 14 | public override void Attach(PropertyViewItem property, PropertyItem info) { 15 | if (info.Value is not Models.MCU.MapModel.GroupModel.ValuePropertyGridComboEditorModel value) 16 | return; 17 | 18 | var binding = new Binding("Value.Source") { 19 | Mode = BindingMode.TwoWay, 20 | Source = info, 21 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 22 | }; 23 | BindingOperations.SetBinding(_comboBox, ComboBox.ItemsSourceProperty, binding); 24 | 25 | binding = new Binding("Value.Value") { 26 | Mode = BindingMode.TwoWay, 27 | Source = info, 28 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 29 | }; 30 | BindingOperations.SetBinding(_comboBox, ComboBox.SelectedValueProperty, binding); 31 | 32 | binding = new Binding("Value.Value") { 33 | Mode = BindingMode.TwoWay, 34 | Source = info, 35 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 36 | }; 37 | BindingOperations.SetBinding(_comboBox, ComboBox.ToolTipProperty, binding); 38 | 39 | _comboBox.DisplayMemberPath = "Value"; 40 | _comboBox.SelectedValuePath = "Key"; 41 | 42 | if (value.Value.IsNullOrEmpty()) { 43 | _comboBox.SelectedIndex = 0; 44 | } 45 | else { 46 | _comboBox.SelectedValue = value.Value; 47 | } 48 | } 49 | 50 | public override object Create(PropertyInfo propertyInfo) { 51 | return CreateEditor(); 52 | } 53 | 54 | public override object Create(PropertyDescriptor propertyDescriptor) { 55 | return CreateEditor(); 56 | } 57 | 58 | public override void Detach(PropertyViewItem property) { 59 | _comboBox = null; 60 | } 61 | 62 | private ComboBox CreateEditor() { 63 | _comboBox = new ComboBox(); 64 | return _comboBox; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Database/CSP.Database/MCUHelper.cs: -------------------------------------------------------------------------------- 1 | using CSP.Database.Models.MCU; 2 | 3 | namespace CSP.Database 4 | { 5 | public static class MCUHelper 6 | { 7 | private static readonly MCUInstance Instance = MCUInstance.Instance; 8 | 9 | public static string Company { get => Instance.Company; } 10 | public static IPModel IP { get => Instance.IP; } 11 | public static MCUModel MCU { get => Instance.MCU; } 12 | public static string Name { get => Instance.Name; } 13 | public static RepositoryModel Repository { get => Instance.Repository; } 14 | 15 | public static void GenerateMap(string source, string dest) { 16 | var model = MapModel.Transform(source); 17 | MapModel.Create(dest, model); 18 | } 19 | 20 | public static MapModel GetMap(string name) { 21 | return Instance.GetMap(name); 22 | } 23 | 24 | public static void LoadMcu(string company, string name) { 25 | Instance.LoadMCU(company, name); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Database/CSP.Database/MCUInstance.cs: -------------------------------------------------------------------------------- 1 | using CSP.Database.Models.MCU; 2 | using CSP.Resources; 3 | using CSP.Utils; 4 | using CSP.Utils.Extensions; 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | namespace CSP.Database 9 | { 10 | internal class MCUInstance 11 | { 12 | private static readonly Lazy Lazy = new(static () => new MCUInstance()); 13 | private static readonly string[] MapNames = { "GPIO" }; 14 | private readonly Dictionary _maps = new(); 15 | private IPModel _ip; 16 | private MCUModel _mcu; 17 | private RepositoryModel _repository; 18 | 19 | private MCUInstance() { 20 | } 21 | 22 | public static MCUInstance Instance => Lazy.Value; 23 | public string Company { get; private set; } 24 | 25 | public IPModel IP { 26 | get => _ip; 27 | private set { 28 | _ip = value; 29 | UpdatePinFunctionMode(); 30 | } 31 | } 32 | 33 | public MCUModel MCU { 34 | get => _mcu; 35 | private set { 36 | _mcu = value; 37 | UpdatePinFunctionMode(); 38 | } 39 | } 40 | 41 | public string Name { get; private set; } 42 | 43 | public RepositoryModel Repository => _repository ??= RepositoryModel.Load($"{IniFile.PathMCUDb}/Repository.xml"); 44 | 45 | public MapModel GetMap(string name) { 46 | return _maps.ContainsKey(name) ? _maps[name] : null; 47 | } 48 | 49 | public void LoadMCU(string company, string name) { 50 | DebugUtil.Assert(!company.IsNullOrEmpty(), new ArgumentNullException(nameof(company))); 51 | DebugUtil.Assert(!name.IsNullOrEmpty(), new ArgumentNullException(nameof(name))); 52 | 53 | Company = company; 54 | Name = name; 55 | 56 | var path = $"{IniFile.PathMCUDb}/Company/{company}/MCU/{name}.xml"; 57 | MCU = MCUModel.Load(path); 58 | 59 | DebugUtil.Assert(MCU != null, new ArgumentNullException(nameof(MCU)), $"MCU \"{name}\" 读取失败"); 60 | 61 | LoadIP(); 62 | LoadMaps(); 63 | } 64 | 65 | private void LoadIP() { 66 | var path = $"{IniFile.PathMCUDb}/Company/{Company}/IP/{Name}-IP.xml"; 67 | IP = IPModel.Load(path); 68 | 69 | DebugUtil.Assert(IP != null, new ArgumentNullException(nameof(IP)), $"MCU \"{Name}\" 读取失败"); 70 | } 71 | 72 | private void LoadMaps() { 73 | _maps.Clear(); 74 | foreach (var name in MapNames) { 75 | _maps.Add(name, MapModel.Load($"{IniFile.PathMCUDb}/Company/{Company}/Map/{MCU.Line}/{name}.xml")); 76 | } 77 | } 78 | 79 | private void UpdatePinFunctionMode() { 80 | if (MCU == null || IP == null) 81 | return; 82 | 83 | foreach (var pin in MCU.Pins) { 84 | if (pin.Functions == null) 85 | continue; 86 | 87 | // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator 88 | foreach (var function in pin.Functions) { 89 | if (!function.Value.ModeName.IsNullOrEmpty() && IP.GPIO.Modes.ContainsKey(function.Value.ModeName)) { 90 | function.Value.Mode = IP.GPIO.Modes[function.Value.ModeName]; 91 | } 92 | } 93 | } 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /Database/CSP.Database/MDKHelper.cs: -------------------------------------------------------------------------------- 1 | using CSP.Database.Models.MDK; 2 | 3 | namespace CSP.Database 4 | { 5 | public static class MDKHelper 6 | { 7 | private static readonly MDKInstance Instance = MDKInstance.Instance; 8 | 9 | private static UvprojxModel Uvprojx { get => Instance.Uvprojx; } 10 | 11 | public static UvprojxModel Load(string path) => Instance.Load(path); 12 | } 13 | } -------------------------------------------------------------------------------- /Database/CSP.Database/MDKInstance.cs: -------------------------------------------------------------------------------- 1 | using CSP.Database.Models.MDK; 2 | using System; 3 | 4 | namespace CSP.Database 5 | { 6 | internal class MDKInstance 7 | { 8 | public UvprojxModel Uvprojx; 9 | private static readonly Lazy Lazy = new(static () => new MDKInstance()); 10 | 11 | private MDKInstance() { 12 | } 13 | 14 | public static MDKInstance Instance => Lazy.Value; 15 | 16 | public UvprojxModel Load(string path) { 17 | Uvprojx = UvprojxModel.Load(path); 18 | return Uvprojx; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Database/CSP.Database/Models/MCU/IPModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using CSP.Utils.Extensions; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Windows; 7 | using System.Xml.Serialization; 8 | 9 | // ReSharper disable UnusedAutoPropertyAccessor.Global 10 | 11 | namespace CSP.Database.Models.MCU 12 | { 13 | [XmlRoot("IP", IsNullable = false)] 14 | public class IPModel 15 | { 16 | public IpGpioModel GPIO { get; set; } 17 | 18 | internal static IPModel Load(string path) { 19 | DebugUtil.Assert(!path.IsNullOrEmpty(), new ArgumentNullException(nameof(path))); 20 | 21 | if (!File.Exists(path)) 22 | return null; 23 | 24 | var deserializer = new XmlSerializer(typeof(IPModel)); 25 | var reader = new StreamReader(path); 26 | 27 | IPModel rtn; 28 | try { 29 | rtn = (IPModel)deserializer.Deserialize(reader); 30 | } 31 | catch (InvalidOperationException e) { 32 | MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); 33 | return null; 34 | } 35 | 36 | DebugUtil.Assert(rtn != null, new ArgumentNullException(nameof(rtn)), "XML反序列化失败"); 37 | if (rtn == null) 38 | return null; 39 | 40 | //给辅助变量赋值,将变量转化为字典形式 41 | foreach (var mode in rtn.GPIO.ModesTemp) { 42 | foreach (var parameter in mode.ParametersTemp) { 43 | mode.Parameters.Add(parameter.Group, parameter); 44 | } 45 | 46 | rtn.GPIO.Modes.Add(mode.Name, mode); 47 | } 48 | 49 | return rtn; 50 | } 51 | 52 | public class IpGpioModel 53 | { 54 | [XmlIgnore] 55 | public Dictionary Modes { get; } = new(); 56 | 57 | [XmlArray("Modes")] 58 | [XmlArrayItem("Mode")] 59 | public IpGpioModeModel[] ModesTemp { get; set; } 60 | 61 | public class IpGpioModeModel 62 | { 63 | [XmlAttribute] 64 | public string Name { get; set; } 65 | 66 | [XmlIgnore] 67 | public Dictionary Parameters { get; } = new(); 68 | 69 | [XmlArray("Parameters")] 70 | [XmlArrayItem("Parameter")] 71 | public IpGpioModeParameterModel[] ParametersTemp { get; set; } 72 | 73 | [XmlAttribute] 74 | public string Type { get; set; } 75 | 76 | public class IpGpioModeParameterModel 77 | { 78 | [XmlAttribute] 79 | public string Group { get; set; } 80 | 81 | [XmlArray("Values")] 82 | [XmlArrayItem("Value")] 83 | public string[] Values { get; set; } 84 | } 85 | } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AnyCPU;x86;x64 5 | 10.0 6 | 1701;1702;0067 7 | 8 | 9 | 10 | $(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | none 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Events/CSP.Events/CSP.Events.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Events/CSP.Events/ClosingEvent.cs: -------------------------------------------------------------------------------- 1 | using Prism.Events; 2 | 3 | namespace CSP.Events 4 | { 5 | public class ClosingEvent : PubSubEvent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Events/CSP.Events/CustomEditorEvent.cs: -------------------------------------------------------------------------------- 1 | using Prism.Events; 2 | using Syncfusion.Windows.PropertyGrid; 3 | 4 | namespace CSP.Events 5 | { 6 | public class CustomEditorEvent : PubSubEvent 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Events/CSP.Events/GenerateEvent.cs: -------------------------------------------------------------------------------- 1 | using Prism.Events; 2 | 3 | namespace CSP.Events 4 | { 5 | public class GenerateEvent : PubSubEvent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Events/CSP.Events/RenderedEvent.cs: -------------------------------------------------------------------------------- 1 | using Prism.Events; 2 | 3 | namespace CSP.Events 4 | { 5 | public class RenderedEvent : PubSubEvent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Events/CSP.Events/SaveEvent.cs: -------------------------------------------------------------------------------- 1 | using Prism.Events; 2 | 3 | namespace CSP.Events 4 | { 5 | public class SaveEvent : PubSubEvent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Events/CSP.Events/SolutionExplorerEvent.cs: -------------------------------------------------------------------------------- 1 | using CSP.Resources; 2 | using CSP.Utils.Extensions; 3 | using Prism.Events; 4 | using Prism.Mvvm; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Collections.ObjectModel; 8 | using System.IO; 9 | using System.Windows.Media.Imaging; 10 | 11 | namespace CSP.Events 12 | { 13 | public class SolutionExplorerEvent : PubSubEvent> 14 | { 15 | public class Model : BindableBase 16 | { 17 | public Action CallBack; 18 | private ObservableCollection _children; 19 | 20 | private BitmapImage _image; 21 | private string _name; 22 | private string _path; 23 | 24 | public Model() { 25 | } 26 | 27 | public Model(string path) { 28 | if (path.IsNullOrEmpty()) 29 | throw new ArgumentNullException(nameof(path)); 30 | 31 | Children = new ObservableCollection(); 32 | 33 | var info = new FileInfo(path); 34 | 35 | if ((info.Attributes & FileAttributes.Directory) != 0) { 36 | Image = Icon.YellowFolder; 37 | } 38 | else { 39 | Image = System.IO.Path.GetExtension(info.Name).ToLower() switch { 40 | ".c" => Icon.C, 41 | ".dll" => Icon.Setting, 42 | ".log" => Icon.Log, 43 | ".xml" => Icon.Xml, 44 | ".json" => Icon.Json, 45 | ".lib" => Icon.Lib, 46 | ".cs" => Icon.CSharp, 47 | ".config" => Icon.Log, 48 | _ => Icon.C 49 | }; 50 | } 51 | 52 | Name = info.Name; 53 | } 54 | 55 | public ObservableCollection Children { 56 | get => _children; 57 | set => SetProperty(ref _children, value); 58 | } 59 | 60 | public BitmapImage Image { 61 | get => _image; 62 | set => SetProperty(ref _image, value); 63 | } 64 | 65 | public string Name { 66 | get => _name; 67 | set => SetProperty(ref _name, value); 68 | } 69 | 70 | public string Path { 71 | get => _path; 72 | set => SetProperty(ref _path, value); 73 | } 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /Extras/CSP.Extras.BeforeBuild/AppStartup.cs: -------------------------------------------------------------------------------- 1 | using CSP.Extras.BeforeBuild.Tool.Resources; 2 | 3 | namespace CSP.Extras.BeforeBuild 4 | { 5 | internal static class AppStartup 6 | { 7 | private static void Main(string[] args) { 8 | Icon.Init(); 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Extras/CSP.Extras.BeforeBuild/CSP.Extras.BeforeBuild.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0-windows 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Extras/CSP.Extras.BeforeBuild/Tool/Resources/Icon.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace CSP.Extras.BeforeBuild.Tool.Resources 4 | { 5 | internal static class Icon 6 | { 7 | private const string IconDataTemplate = 8 | @" 9 | public static BitmapImage $Data{ 10 | get => Instance.$Data; 11 | } 12 | "; 13 | 14 | private const string IconInstanceDataTemplate = " internal readonly BitmapImage $Data = new(new Uri(@\"pack://application:,,,/CSP.Resources;component/Icon/$Data.png\"));\r\n"; 15 | 16 | private const string IconInstanceTemplate = 17 | @"using System; 18 | using System.Windows.Media.Imaging; 19 | 20 | namespace CSP.Resources 21 | { 22 | internal class IconInstance 23 | { 24 | $Data } 25 | }"; 26 | 27 | private const string IconTemplate = 28 | @"using System.Windows.Media.Imaging; 29 | 30 | namespace CSP.Resources 31 | { 32 | public static class Icon 33 | { 34 | private static readonly IconInstance Instance = new(); 35 | $Data 36 | } 37 | }"; 38 | 39 | public static void Init() { 40 | var solutionDir = File.ReadAllLines("./SolutionDir.txt")[0]; 41 | var resourcesIconPath = $"{solutionDir}Resources/CSP.Resources/Icon.cs"; 42 | var resourcesIconInstancePath = $"{solutionDir}Resources/CSP.Resources/IconInstance.cs"; 43 | var resourcesIconDir = $"{solutionDir}Resources/CSP.Resources/Icon"; 44 | 45 | var iconInstanceData = ""; 46 | var iconData = ""; 47 | 48 | DirectoryInfo d = new(resourcesIconDir); 49 | FileSystemInfo[] fsInfos = d.GetFileSystemInfos(); 50 | foreach (var fsInfo in fsInfos) { 51 | if (fsInfo is not DirectoryInfo) { 52 | var name = fsInfo.Name.Replace(".png", ""); 53 | iconInstanceData += IconInstanceDataTemplate.Replace("$Data", name); 54 | iconData += IconDataTemplate.Replace("$Data", name); 55 | } 56 | } 57 | 58 | // Console.WriteLine($"write IconInstance: \n {iconInstanceData}"); 59 | // Console.WriteLine($"write Icon: \n {iconData}"); 60 | 61 | var iconInstance = IconInstanceTemplate.Replace("$Data", iconInstanceData); 62 | var icon = IconTemplate.Replace("$Data", iconData); 63 | 64 | File.WriteAllText(resourcesIconPath, icon); 65 | File.WriteAllText(resourcesIconInstancePath, iconInstance); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | | 组件 | 证书 | 版权 | 2 | | ---- | ------------------------------- | ------ | 3 | | csp | GNU General Public License v3.0 | xqyjlj | 4 | 5 | 其余Nuget包,待脚本更新后会自动声明到本文件,目前暂时只能用Nuget还原查看 6 | -------------------------------------------------------------------------------- /Models/CSP.Models.Interfaces/CSP.Models.Interfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Models/CSP.Models.Interfaces/IDialogWindowParameters.cs: -------------------------------------------------------------------------------- 1 | using Prism.Services.Dialogs; 2 | using System.Windows; 3 | 4 | namespace CSP.Models.Interfaces 5 | { 6 | public interface IDialogWindowParameters : IDialogAware 7 | { 8 | public double Height { get; } 9 | public double MinHeight { get; } 10 | public double MinWidth { get; } 11 | public bool ShowInTaskbar { get; } 12 | public SizeToContent SizeToContent { get; } 13 | public double Width { get; } 14 | public WindowState WindowState { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Models/CSP.Models/CSP.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Models/CSP.Models/MCUModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using CSP.Utils.Extensions; 3 | using System; 4 | using System.IO; 5 | using System.Windows; 6 | using System.Xml.Serialization; 7 | 8 | namespace CSP.Models 9 | { 10 | [XmlRoot("MCU", IsNullable = false)] 11 | public class MCUModel 12 | { 13 | [XmlArray("Applications")] 14 | [XmlArrayItem("Document")] 15 | public DocumentModel[] Applications { get; set; } 16 | 17 | [XmlAttribute] 18 | public string ClockTree { get; set; } 19 | 20 | [XmlAttribute] 21 | public string Company { get; set; } 22 | 23 | public string CompanyUrl { get; set; } 24 | 25 | [XmlArray("DataSheets")] 26 | [XmlArrayItem("Document")] 27 | public DocumentModel[] DataSheets { get; set; } 28 | 29 | [XmlArray("Errata")] 30 | [XmlArrayItem("Document")] 31 | public DocumentModel[] Errata { get; set; } 32 | 33 | public HALModel HAL { get; set; } 34 | 35 | [XmlAttribute] 36 | public bool HasPowerPad { get; set; } 37 | 38 | public string Illustrate { get; set; } 39 | 40 | public string Introduction { get; set; } 41 | 42 | [XmlAttribute] 43 | public string IoType { get; set; } 44 | 45 | [XmlAttribute] 46 | public string Line { get; set; } 47 | 48 | [XmlArray("Modules")] 49 | [XmlArrayItem("Module")] 50 | public ModuleModel[] Modules { get; set; } 51 | 52 | [XmlAttribute] 53 | public string Name { get; set; } 54 | 55 | [XmlAttribute] 56 | public string Package { get; set; } 57 | 58 | [XmlAttribute] 59 | public float Price { get; set; } 60 | 61 | [XmlArray("Programs")] 62 | [XmlArrayItem("Document")] 63 | public DocumentModel[] Programs { get; set; } 64 | 65 | [XmlArray("References")] 66 | [XmlArrayItem("Document")] 67 | public DocumentModel[] References { get; set; } 68 | 69 | public string RepositoryUrl { get; set; } 70 | 71 | [XmlAttribute] 72 | public string Series { get; set; } 73 | 74 | public string Url { get; set; } 75 | 76 | public static MCUModel Load(string path) { 77 | DebugUtil.Assert(!path.IsNullOrEmpty(), new ArgumentNullException(nameof(path)), "path不能为空"); 78 | DebugUtil.Assert(File.Exists(path), new FileNotFoundException(nameof(path)), $"{path}: 不存在"); 79 | 80 | if (path == null) return null; 81 | if (!File.Exists(path)) return null; 82 | 83 | var deserializer = new XmlSerializer(typeof(MCUModel)); 84 | var reader = new StreamReader(path); 85 | 86 | MCUModel rtn; 87 | try { 88 | rtn = (MCUModel)deserializer.Deserialize(reader); 89 | } 90 | catch (InvalidOperationException e) { 91 | MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); 92 | return null; 93 | } 94 | 95 | DebugUtil.Assert(rtn != null, new ArgumentNullException(nameof(rtn)), "XML反序列化失败"); 96 | return rtn; 97 | } 98 | 99 | public class DocumentModel 100 | { 101 | [XmlAttribute] 102 | public string Name { get; set; } 103 | 104 | public string Url { get; set; } 105 | } 106 | 107 | public class HALModel 108 | { 109 | [XmlAttribute] 110 | public string Name { get; set; } 111 | 112 | [XmlAttribute] 113 | public string Version { get; set; } 114 | } 115 | 116 | public class ModuleModel 117 | { 118 | [XmlArray("Categories")] 119 | [XmlArrayItem("Category")] 120 | public CategoryModel[] Categories { get; set; } 121 | 122 | [XmlAttribute] 123 | public string Name { get; set; } 124 | 125 | public class CategoryModel 126 | { 127 | [XmlAttribute] 128 | public string Name { get; set; } 129 | } 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU.Tests/CSP.Modules.Dialogs.NewMCU.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/CSP.Modules.Dialogs.NewMCU.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/Models/DocumentModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Resources; 2 | using CSP.Utils.Extensions; 3 | using Prism.Mvvm; 4 | using System; 5 | using System.Collections.ObjectModel; 6 | using System.Windows.Media.Imaging; 7 | 8 | namespace CSP.Modules.Dialogs.NewMCU.Models 9 | { 10 | public class DocumentModel : BindableBase 11 | { 12 | private ObservableCollection _children; 13 | 14 | private BitmapImage _image; 15 | private bool _isExpanded; 16 | private string _name; 17 | private string _url; 18 | 19 | public DocumentModel() { 20 | } 21 | 22 | public DocumentModel(string name) { 23 | if (name.IsNullOrEmpty()) 24 | throw new ArgumentNullException(nameof(name)); 25 | 26 | Children = new ObservableCollection(); 27 | 28 | Image = Icon.YellowFolder; 29 | Name = name; 30 | } 31 | 32 | public DocumentModel(string name, string url) { 33 | if (url.IsNullOrEmpty()) 34 | throw new ArgumentNullException(nameof(url)); 35 | 36 | Children = new ObservableCollection(); 37 | 38 | Image = url.ToLower().EndsWith(".pdf") ? Icon.Pdf : Icon.Lib; 39 | Name = name; 40 | Url = url; 41 | } 42 | 43 | public ObservableCollection Children { 44 | get => _children; 45 | set => SetProperty(ref _children, value); 46 | } 47 | 48 | public BitmapImage Image { 49 | get => _image; 50 | set => SetProperty(ref _image, value); 51 | } 52 | 53 | public bool IsExpanded { 54 | get => _isExpanded; 55 | 56 | set => SetProperty(ref _isExpanded, value); 57 | } 58 | 59 | public string Name { 60 | get => _name; 61 | set => SetProperty(ref _name, value); 62 | } 63 | 64 | public string Url { 65 | get => _url; 66 | set => SetProperty(ref _url, value); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/NewMCUModule.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Dialogs.NewMCU.ViewModels; 2 | using CSP.Modules.Dialogs.NewMCU.Views; 3 | using CSP.Utils; 4 | using Prism.Ioc; 5 | using Prism.Modularity; 6 | 7 | namespace CSP.Modules.Dialogs.NewMCU 8 | { 9 | public class NewMCUModule : IModule 10 | { 11 | public void OnInitialized(IContainerProvider containerProvider) { 12 | } 13 | 14 | public void RegisterTypes(IContainerRegistry containerRegistry) { 15 | DialogUtil.RegisterDialog(containerRegistry, "Dialog.NewMCU"); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/Resources/Images/LQFP144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Modules/CSP.Modules.Dialogs.NewMCU/Resources/Images/LQFP144.png -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/Resources/Images/LQFP48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Modules/CSP.Modules.Dialogs.NewMCU/Resources/Images/LQFP48.png -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/Resources/Images/LQFP64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Modules/CSP.Modules.Dialogs.NewMCU/Resources/Images/LQFP64.png -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/Views/Components/MCUBox.xaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Dialogs.NewMCU/Views/MCUSelectorView.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Dialogs.NewMCU.Models; 2 | using CSP.Utils; 3 | using CSP.Utils.Extensions; 4 | using Syncfusion.UI.Xaml.TreeView; 5 | 6 | namespace CSP.Modules.Dialogs.NewMCU.Views 7 | { 8 | public partial class MCUSelectorView 9 | { 10 | public MCUSelectorView() { 11 | InitializeComponent(); 12 | } 13 | 14 | private void OnSelectionChanged(object sender, ItemSelectionChangedEventArgs e) { 15 | var item = TreeView.SelectedItem; 16 | 17 | if (item is not DocumentModel value) 18 | return; 19 | 20 | if (!value.Url.IsNullOrEmpty()) 21 | Util.OpenUrl(value.Url); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU.Tests/CSP.Modules.Pages.MCU.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU.Tests/Services/Generate/GPIOIncTests.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Services.Generate; 2 | using System.IO; 3 | using Xunit; 4 | using Xunit.Abstractions; 5 | 6 | namespace CSP.Modules.Pages.MCU.Tests.Services.Generate 7 | { 8 | public class GPIOIncTests 9 | { 10 | private readonly ITestOutputHelper _testOutputHelper; 11 | 12 | public GPIOIncTests(ITestOutputHelper testOutputHelper) { 13 | _testOutputHelper = testOutputHelper; 14 | } 15 | 16 | [Fact] 17 | public void Test() { 18 | var gpioInc = new GPIOInc(); 19 | var inc = gpioInc.Generate(); 20 | 21 | const string path = "./csp/inc"; 22 | 23 | if (!Directory.Exists(path)) 24 | Directory.CreateDirectory(path); 25 | 26 | var sw = new StreamWriter($"{path}/csp_gpio.h", false); 27 | sw.Write(inc); 28 | sw.Close(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU.Tests/Services/Generate/GPIOSrcTests.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Services.Generate; 2 | using CSP.Modules.Pages.MCU.Services.Generate.Models; 3 | using System.IO; 4 | using Xunit; 5 | using Xunit.Abstractions; 6 | 7 | // ReSharper disable StringLiteralTypo 8 | 9 | namespace CSP.Modules.Pages.MCU.Tests.Services.Generate 10 | { 11 | public class GPIOSrcTests 12 | { 13 | private readonly ITestOutputHelper _testOutputHelper; 14 | 15 | public GPIOSrcTests(ITestOutputHelper testOutputHelper) { 16 | _testOutputHelper = testOutputHelper; 17 | } 18 | 19 | [Fact] 20 | public void Test() { 21 | var gpioSrc = new GPIOSrc(); 22 | 23 | var ext = new ExternModel() { 24 | Name = "PA0", 25 | Type = "md_gpio_obj_t" 26 | }; 27 | gpioSrc.AddExtern(ext); 28 | 29 | ext = new ExternModel() { 30 | Name = "PA1", 31 | Type = "md_gpio_obj_t" 32 | }; 33 | gpioSrc.AddExtern(ext); 34 | 35 | var variable = new VariableModel() { 36 | Name = "PA0", 37 | IsStatic = false, 38 | Type = "md_gpio_obj_t", 39 | Value = "{GPIOA, GPIO_PIN_0, EXTI0_1_IRQn}" 40 | }; 41 | gpioSrc.AddVariable(variable); 42 | 43 | variable = new VariableModel() { 44 | Name = "PA1", 45 | IsStatic = false, 46 | Type = "md_gpio_obj_t", 47 | Value = "{GPIOA, GPIO_PIN_1, EXTI0_1_IRQn}" 48 | }; 49 | gpioSrc.AddVariable(variable); 50 | 51 | var function = new FunctionModel { 52 | Name = "ms_gpio_init", 53 | Type = "void" 54 | }; 55 | function.Parameters.Add(new FunctionModel.ParameterModel() { 56 | Name = "", 57 | Type = "void" 58 | }); 59 | 60 | var functionUse = new FunctionModel.FunctionUseModel { 61 | Name = "md_gpio_set_mode" 62 | }; 63 | functionUse.Parameters.Add("&PA0"); 64 | functionUse.Parameters.Add("MD_GPIO_MODE_OUTPUT_PP"); 65 | functionUse.Parameters.Add("MD_GPIO_SPEED_LOW"); 66 | functionUse.Parameters.Add("MD_GPIO_PULL_DOWN"); 67 | function.FunctionUses.Add(functionUse); 68 | 69 | functionUse = new FunctionModel.FunctionUseModel { 70 | Name = "md_gpio_set_mode" 71 | }; 72 | 73 | functionUse.Parameters.Add("&PA1"); 74 | functionUse.Parameters.Add("MD_GPIO_MODE_OUTPUT_PP"); 75 | functionUse.Parameters.Add("MD_GPIO_SPEED_LOW"); 76 | functionUse.Parameters.Add("MD_GPIO_PULL_DOWN"); 77 | function.FunctionUses.Add(functionUse); 78 | 79 | gpioSrc.AddFunction(function); 80 | 81 | var src = gpioSrc.Generate(); 82 | 83 | const string path = "./csp/src"; 84 | 85 | if (!Directory.Exists(path)) 86 | Directory.CreateDirectory(path); 87 | 88 | var sw = new StreamWriter($"{path}/csp_gpio.c", false); 89 | sw.Write(src); 90 | sw.Close(); 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/CSP.Modules.Pages.MCU.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | True 31 | True 32 | Files.resx 33 | 34 | 35 | 36 | 37 | 38 | ResXFileCodeGenerator 39 | Files.Designer.cs 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/Pin.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/Pin.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Enums; 2 | using System.Windows; 3 | 4 | namespace CSP.Modules.Pages.MCU.Components.LQFP 5 | { 6 | public partial class Pin 7 | { 8 | public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register("Direction", 9 | typeof(DirectionEnum), 10 | typeof(Pin), 11 | new FrameworkPropertyMetadata(DirectionEnum.Top, OnDirectionChanged) { BindsTwoWayByDefault = true }); 12 | 13 | public Pin() { 14 | InitializeComponent(); 15 | } 16 | 17 | public DirectionEnum Direction { 18 | get => (DirectionEnum)GetValue(DirectionProperty); 19 | set => SetValue(DirectionProperty, value); 20 | } 21 | 22 | private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { 23 | if (d is not Pin pin) 24 | return; 25 | if (e.NewValue is not DirectionEnum direction) 26 | return; 27 | 28 | pin.ContentTemplate = pin.Resources[$"Pin{direction.ToString()}"] as DataTemplate; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinBottom.xaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 32 | 36 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinBottom.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Components.LQFP 2 | { 3 | public partial class PinBottom 4 | { 5 | public PinBottom() { 6 | InitializeComponent(); 7 | PinName = ButtonPin; 8 | PinNote = TextBlockNote; 9 | RightContextMenu = ButtonPinContextMenu; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinLeft.xaml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 26 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinLeft.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Components.LQFP 2 | { 3 | public partial class PinLeft 4 | { 5 | public PinLeft() { 6 | InitializeComponent(); 7 | PinName = ButtonPin; 8 | PinNote = TextBlockNote; 9 | RightContextMenu = ButtonPinContextMenu; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinRight.xaml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 26 | 27 | 28 | 29 | 30 | 31 | 40 | 41 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinRight.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Components.LQFP 2 | { 3 | public partial class PinRight 4 | { 5 | public PinRight() { 6 | InitializeComponent(); 7 | PinName = ButtonPin; 8 | PinNote = TextBlockNote; 9 | RightContextMenu = ButtonPinContextMenu; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinTop.xaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 27 | 36 | 37 | 38 | 39 | 40 | 41 | 50 | 51 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Components/LQFP/PinTop.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Components.LQFP 2 | { 3 | public partial class PinTop 4 | { 5 | public PinTop() { 6 | InitializeComponent(); 7 | PinName = ButtonPin; 8 | PinNote = TextBlockNote; 9 | RightContextMenu = ButtonPinContextMenu; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Enums/DirectionEnum.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Enums 2 | { 3 | public enum DirectionEnum 4 | { 5 | Top, 6 | Left, 7 | Right, 8 | Bottom 9 | } 10 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/MCUModule.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Views; 2 | using CSP.Modules.Pages.MCU.Views.Components.Config; 3 | using CSP.Modules.Pages.MCU.Views.Components.Package; 4 | using CSP.Modules.Pages.MCU.Views.Windows; 5 | using CSP.Utils; 6 | using Prism.Ioc; 7 | using Prism.Modularity; 8 | using Prism.Regions; 9 | 10 | namespace CSP.Modules.Pages.MCU 11 | { 12 | public class MCUModule : IModule 13 | { 14 | public void OnInitialized(IContainerProvider containerProvider) { 15 | var regionManager = containerProvider.Resolve(); 16 | 17 | RegionUtil.RegisterViewWithRegion(regionManager, "Region.Window.Document", typeof(PropertyTableView)); 18 | } 19 | 20 | public void RegisterTypes(IContainerRegistry containerRegistry) { 21 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.MCU.Config"); 22 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.MCU.Config.PropertyTableView.GPIO"); 23 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.MCU.Config.PropertyTableView.Clock"); 24 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.MCU.Package.LQFP48"); 25 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.MCU.Package.LQFP64"); 26 | RegionUtil.RegisterForNavigation(containerRegistry, "Page.MCU.Package.LQFP144"); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Models/Description/IPModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using CSP.Utils.Extensions; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Windows; 7 | using System.Xml.Serialization; 8 | 9 | namespace CSP.Modules.Pages.MCU.Models.Description 10 | { 11 | [XmlRoot("IP", IsNullable = false)] 12 | public class IPModel 13 | { 14 | [XmlIgnore] 15 | public Dictionary ModeMap { get; } = new(); 16 | 17 | [XmlArray("Modes")] 18 | [XmlArrayItem("Mode")] 19 | public ModeModel[] Modes { get; set; } 20 | 21 | internal static IPModel Load(string path) { 22 | DebugUtil.Assert(!path.IsNullOrEmpty(), new ArgumentNullException(nameof(path)), "path不能为空"); 23 | DebugUtil.Assert(File.Exists(path), new FileNotFoundException(nameof(path)), $"{path}: 不存在"); 24 | 25 | if (path == null) return null; 26 | if (!File.Exists(path)) return null; 27 | 28 | var deserializer = new XmlSerializer(typeof(IPModel)); 29 | var reader = new StreamReader(path); 30 | 31 | IPModel rtn; 32 | try { 33 | rtn = (IPModel)deserializer.Deserialize(reader); 34 | } 35 | catch (InvalidOperationException e) { 36 | MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); 37 | return null; 38 | } 39 | 40 | DebugUtil.Assert(rtn != null, new ArgumentNullException(nameof(rtn)), "XML反序列化失败"); 41 | if (rtn == null) 42 | return null; 43 | 44 | //给辅助变量赋值,将变量转化为字典形式 45 | foreach (var mode in rtn.Modes) { 46 | foreach (var parameter in mode.Parameters) { 47 | mode.ParameterMap.Add(parameter.Group, parameter); 48 | } 49 | 50 | rtn.ModeMap.Add(mode.Name, mode); 51 | } 52 | 53 | return rtn; 54 | } 55 | 56 | public class ModeModel 57 | { 58 | [XmlAttribute] 59 | public string Name { get; set; } 60 | 61 | [XmlIgnore] 62 | public Dictionary ParameterMap { get; } = new(); 63 | 64 | [XmlArray("Parameters")] 65 | [XmlArrayItem("Parameter")] 66 | public ParameterModel[] Parameters { get; set; } 67 | 68 | [XmlAttribute] 69 | public string Type { get; set; } 70 | 71 | public class ParameterModel 72 | { 73 | [XmlAttribute] 74 | public string Group { get; set; } 75 | 76 | [XmlArray("Values")] 77 | [XmlArrayItem("Value")] 78 | public string[] Values { get; set; } 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Models/Description/PinoutModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using CSP.Utils.Extensions; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Windows; 7 | using System.Xml.Serialization; 8 | 9 | namespace CSP.Modules.Pages.MCU.Models.Description 10 | { 11 | [XmlRoot("Pinout", IsNullable = false)] 12 | public class PinoutModel 13 | { 14 | [XmlArray("Pins")] 15 | [XmlArrayItem("Pin")] 16 | public PinModel[] Pins { get; set; } 17 | 18 | internal static PinoutModel Load(string path) { 19 | DebugUtil.Assert(!path.IsNullOrEmpty(), new ArgumentNullException(nameof(path)), "path不能为空"); 20 | DebugUtil.Assert(File.Exists(path), new FileNotFoundException(nameof(path)), $"{path}: 不存在"); 21 | 22 | if (path == null) return null; 23 | if (!File.Exists(path)) return null; 24 | 25 | var deserializer = new XmlSerializer(typeof(PinoutModel)); 26 | var reader = new StreamReader(path); 27 | 28 | PinoutModel rtn; 29 | try { 30 | rtn = (PinoutModel)deserializer.Deserialize(reader); 31 | } 32 | catch (InvalidOperationException e) { 33 | MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); 34 | return null; 35 | } 36 | 37 | DebugUtil.Assert(rtn != null, new ArgumentNullException(nameof(rtn)), "XML反序列化失败"); 38 | if (rtn == null) 39 | return null; 40 | 41 | //给辅助变量赋值,将变量转化为字典形式 42 | foreach (var pin in rtn.Pins) { 43 | if (pin.Functions != null) { 44 | foreach (var functions in pin.Functions) { 45 | pin.FunctionMap.Add(functions.Name, functions); 46 | } 47 | } 48 | } 49 | 50 | return rtn; 51 | } 52 | 53 | public class PinModel 54 | { 55 | [XmlIgnore] 56 | public Dictionary FunctionMap { get; } = new(); 57 | 58 | [XmlArray("Functions")] 59 | [XmlArrayItem("Function")] 60 | public FunctionModel[] Functions { get; set; } 61 | 62 | [XmlAttribute] 63 | public string Name { get; set; } 64 | 65 | [XmlAttribute] 66 | public int Position { get; set; } 67 | 68 | [XmlAttribute] 69 | public string Type { get; set; } 70 | 71 | public class FunctionModel 72 | { 73 | [XmlAttribute("Mode")] 74 | public string Mode { get; set; } 75 | 76 | [XmlAttribute] 77 | public string Name { get; set; } 78 | 79 | [XmlAttribute] 80 | public string Type { get; set; } 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Models/PinModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Components.ValuePropertyGrid; 2 | using CSP.Events; 3 | using CSP.Utils; 4 | using Prism.Mvvm; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.ComponentModel; 8 | using System.ComponentModel.DataAnnotations; 9 | using System.Xml.Serialization; 10 | 11 | namespace CSP.Modules.Pages.MCU.Models 12 | { 13 | public class PinModel : BindableBase 14 | { 15 | [ReadOnly(true)] 16 | [Display(Name = "功能", Description = "Pin 功能", GroupName = "系统")] 17 | [XmlAttribute] 18 | public StringEditorModel Function { get; set; } = new(); 19 | 20 | [ReadOnly(false)] 21 | [Display(Name = "锁定", Description = "锁定", GroupName = "基础")] 22 | [XmlAttribute] 23 | public BooleanEditorModel IsLocked { get; set; } = new(); 24 | 25 | [ReadOnly(false)] 26 | [Display(Name = "标签", Description = "Pin 标签, 用于宏定义", GroupName = "基础")] 27 | [XmlAttribute] 28 | public StringEditorModel Label { get; set; } = new(); 29 | 30 | [ReadOnly(true)] 31 | [Display(Name = "名称", Description = "Pin 名称", GroupName = "基础")] 32 | [XmlAttribute] 33 | public StringEditorModel Name { get; set; } = new(); 34 | 35 | [ReadOnly(true)] 36 | [Display(Name = "引脚序号", Description = "Pin 引脚序号", GroupName = "基础")] 37 | [XmlAttribute] 38 | public StringEditorModel Position { get; set; } = new(); 39 | 40 | public PropertyDetails Property { get; } = new(); 41 | 42 | public ObservableDictionary> GetAttributes() { 43 | var rtn = new ObservableDictionary>(); 44 | var infos = typeof(PinModel).GetProperties(); 45 | foreach (var info in infos) { 46 | var attrs = info.GetCustomAttributes(false); 47 | if (attrs.Length > 0) { 48 | var attributes = new ObservableDictionary(); 49 | foreach (var attr in attrs) { 50 | switch (attr) { 51 | case DisplayAttribute displayAttribute: { 52 | if (displayAttribute.Name != null) { 53 | attributes.Add("DisplayName", new DisplayNameAttribute(displayAttribute.Name)); 54 | } 55 | if (displayAttribute.Description != null) { 56 | attributes.Add("Description", new DescriptionAttribute(displayAttribute.Description)); 57 | } 58 | if (displayAttribute.GroupName != null) { 59 | attributes.Add("Category", new CategoryAttribute(displayAttribute.GroupName)); 60 | } 61 | break; 62 | } 63 | case ReadOnlyAttribute readOnlyAttribute: { 64 | attributes.Add("ReadOnly", new ReadOnlyAttribute(readOnlyAttribute.IsReadOnly)); 65 | break; 66 | } 67 | } 68 | } 69 | rtn.Add(info.Name, attributes); 70 | } 71 | } 72 | 73 | return rtn; 74 | } 75 | 76 | public ObservableDictionary GetDetails() { 77 | var rtn = new ObservableDictionary { 78 | {"Function", Function}, 79 | {"IsLocked", IsLocked}, 80 | {"Label", Label}, 81 | {"Name", Name}, 82 | {"Position", Position}, 83 | }; 84 | 85 | return rtn; 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Resources/Copyright.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ${file} 3 | * @brief ${brief} 4 | * @author ${author} 5 | * @version 0.0 6 | * @date ${year}-${month}-${day} ${hour}:${minute}:${second} 7 | * @copyright Copyright © 2021-${year} misfra team 8 | * @SPDX-License-Identifier: Apache-2.0 9 | * 10 | * ************************************************************************************ 11 | * @par ChangeLog: 12 | * 13 | * Date Version Author Description 14 | * ${year}-${month}-${day} 0.0 ${author} generate by misfra stduio 15 | * 16 | * ************************************************************************************ 17 | */ -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Resources/HeaderEnd.txt: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | } 3 | #endif 4 | 5 | #endif -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Resources/HeaderStart.txt: -------------------------------------------------------------------------------- 1 | #ifndef __${file} 2 | #define __${file} 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/GPIOInc.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Models.Description; 2 | using CSP.Modules.Pages.MCU.Services.Generate.Models; 3 | 4 | namespace CSP.Modules.Pages.MCU.Services.Generate 5 | { 6 | public class GPIOInc : IncBase 7 | { 8 | public GPIOInc(PinoutModel mcu = null, string path = null) : base(path) { 9 | File = "gpio.h"; 10 | Brief = "This file provides code for the configuration of all used GPIO."; 11 | 12 | AddInclude(new IncModel() { 13 | IsSys = false, 14 | Name = "chal/gpio.h" 15 | }); 16 | 17 | var functionDeclaration = new FunctionDeclarationModel { 18 | Name = "csp_gpio_init", 19 | Type = "void" 20 | }; 21 | functionDeclaration.Parameters.Add(new FunctionDeclarationModel.ParameterModel() { 22 | Name = "", 23 | Type = "void" 24 | }); 25 | AddFunctionDeclaration(functionDeclaration); 26 | 27 | if (mcu == null) 28 | return; 29 | 30 | // foreach (var pin in mcu.Pins) { 31 | // if (pin.BaseProperty.IsLocked) { 32 | // if (!pin.BaseProperty.Label.IsNullOrEmpty()) { 33 | // var macro = new MacroModel { 34 | // Name = pin.BaseProperty.Label, 35 | // String = pin.BaseProperty.Name 36 | // }; 37 | // AddMacro(macro); 38 | // } 39 | // } 40 | // } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/GenerateService.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Models.Description; 2 | using System; 3 | using System.IO; 4 | 5 | namespace CSP.Modules.Pages.MCU.Services.Generate 6 | { 7 | public class GenerateService 8 | { 9 | public static void Generate(PinoutModel mcu, string path) { 10 | if (mcu == null) 11 | throw new ArgumentNullException(nameof(mcu)); 12 | 13 | var pathInc = $"{path}/csp/inc/csp"; 14 | var pathSrc = $"{path}/csp/src"; 15 | 16 | if (!Directory.Exists(pathInc)) 17 | Directory.CreateDirectory(pathInc); 18 | if (!Directory.Exists(pathSrc)) 19 | Directory.CreateDirectory(pathSrc); 20 | 21 | // foreach (var module in mcu.Modules) { 22 | // foreach (var category in module.Categories) { 23 | // switch (category.Name.ToUpper()) { 24 | // case "GPIO": { 25 | // GenerateGPIO(mcu, path); 26 | // } 27 | // break; 28 | // } 29 | // } 30 | // } 31 | } 32 | 33 | public static void GenerateGPIO(PinoutModel mcu, string path) { 34 | if (mcu == null) 35 | throw new ArgumentNullException(nameof(mcu)); 36 | 37 | var pathInc = $"{path}/csp/inc/csp/gpio.h"; 38 | var pathSrc = $"{path}/csp/src/csp_gpio.c"; 39 | 40 | var gpioInc = new GPIOInc(mcu); 41 | var inc = gpioInc.Generate(); 42 | 43 | var sw = new StreamWriter($"{pathInc}", false); 44 | sw.Write(inc); 45 | sw.Close(); 46 | 47 | var gpioSrc = new GPIOSrc(mcu); 48 | var src = gpioSrc.Generate(); 49 | 50 | sw = new StreamWriter($"{pathSrc}", false); 51 | sw.Write(src); 52 | sw.Close(); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/IncBase.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Services.Generate 2 | { 3 | public class IncBase : GenerateBase 4 | { 5 | protected IncBase(string path = null) : base(path) { 6 | } 7 | 8 | public string Generate() { 9 | var content = ""; 10 | 11 | content += RegionCopyright; 12 | content += Copyright; 13 | content += EndregionCopyright; 14 | content += "\n\n"; 15 | 16 | content += Resources.Files.HeaderStart.Replace("${file}", $"CSP_{File}".ToUpper().Replace(".", "_") + "__"); 17 | content += "\n\n"; 18 | 19 | #region includes 20 | 21 | content += RegionIncludes; 22 | content += GenerateIncludes(); 23 | content += EndregionIncludes; 24 | content += "\n\n"; 25 | 26 | content += RegionUserIncludes; 27 | content += UserIncludes; 28 | content += EndregionUserIncludes; 29 | content += "\n\n"; 30 | 31 | #endregion includes 32 | 33 | #region macros 34 | 35 | content += RegionMacros; 36 | content += GenerateMacros(); 37 | content += EndregionMacros; 38 | content += "\n\n"; 39 | 40 | content += RegionUserMacros; 41 | content += UserMacros; 42 | content += EndregionUserMacros; 43 | content += "\n\n"; 44 | 45 | #endregion macros 46 | 47 | #region externs 48 | 49 | content += RegionExterns; 50 | content += GenerateExterns(); 51 | content += EndregionExterns; 52 | content += "\n\n"; 53 | 54 | content += RegionUserExterns; 55 | content += UserExterns; 56 | content += EndregionUserExterns; 57 | content += "\n\n"; 58 | 59 | #endregion externs 60 | 61 | #region function_declarations 62 | 63 | content += RegionFunctionDeclarations; 64 | content += GenerateFunctionDeclarations(); 65 | content += EndregionFunctionDeclarations; 66 | content += "\n\n"; 67 | 68 | content += RegionUserFunctionDeclarations; 69 | content += UserFunctionDeclarations; 70 | content += EndregionFunctionDeclarations; 71 | content += "\n\n"; 72 | 73 | #endregion function_declarations 74 | 75 | content += Resources.Files.HeaderEnd; 76 | content += "\n"; 77 | 78 | return content; 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/Models/ExternModel.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Services.Generate.Models 2 | { 3 | public class ExternModel 4 | { 5 | public string Name { get; set; } 6 | 7 | public string Type { get; set; } 8 | 9 | public override string ToString() { 10 | return $"extern {Type} {Name};"; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/Models/FunctionDeclarationModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils.Extensions; 2 | using System.Collections.Generic; 3 | 4 | namespace CSP.Modules.Pages.MCU.Services.Generate.Models 5 | { 6 | public class FunctionDeclarationModel 7 | { 8 | public string Name { get; set; } 9 | 10 | public List Parameters { get; } = new(); 11 | 12 | public string Type { get; set; } 13 | 14 | public override string ToString() { 15 | var parameter = ""; 16 | 17 | var count = Parameters.Count; 18 | for (var i = 0; i < count; i++) { 19 | if (count == 1) { 20 | if (Parameters[0].Name.IsNullOrEmpty()) { 21 | parameter += $"{Parameters[0].Type}"; 22 | } 23 | else { 24 | parameter += $"{Parameters[0].Type} {Parameters[0].Name}"; 25 | } 26 | } 27 | else { 28 | if (i == count - 1) { 29 | parameter += $"{Parameters[i].Type} {Parameters[i].Name}"; 30 | } 31 | else { 32 | parameter += $"{Parameters[i].Type} {Parameters[i].Name}, "; 33 | } 34 | } 35 | } 36 | 37 | var rtn = $"{Type} {Name}({parameter});"; 38 | 39 | return rtn; 40 | } 41 | 42 | public class ParameterModel 43 | { 44 | public string Name { get; set; } 45 | public string Type { get; set; } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/Models/FunctionModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils.Extensions; 2 | using System.Collections.Generic; 3 | 4 | namespace CSP.Modules.Pages.MCU.Services.Generate.Models 5 | { 6 | public class FunctionModel 7 | { 8 | public List FunctionUses { get; } = new(); 9 | 10 | public string Name { get; set; } 11 | 12 | public List Parameters { get; } = new(); 13 | 14 | public string Type { get; set; } 15 | 16 | public override string ToString() { 17 | var parameter = ""; 18 | 19 | var count = Parameters.Count; 20 | for (var i = 0; i < count; i++) { 21 | if (count == 1) { 22 | if (Parameters[0].Name.IsNullOrEmpty()) { 23 | parameter += $"{Parameters[0].Type}"; 24 | } 25 | else { 26 | parameter += $"{Parameters[0].Type} {Parameters[0].Name}"; 27 | } 28 | } 29 | else { 30 | if (i == count - 1) { 31 | parameter += $"{Parameters[i].Type} {Parameters[i].Name}"; 32 | } 33 | else { 34 | parameter += $"{Parameters[i].Type} {Parameters[i].Name}, "; 35 | } 36 | } 37 | } 38 | 39 | var rtn = $"{Type} {Name}({parameter})\n"; 40 | rtn += "{\n"; 41 | 42 | foreach (var function in FunctionUses) { 43 | rtn += $" {function}"; 44 | } 45 | 46 | switch (Type) { 47 | case "int": 48 | rtn += "\n return RT_EOK;\n"; 49 | break; 50 | } 51 | 52 | rtn += "}"; 53 | return rtn; 54 | } 55 | 56 | public class FunctionUseModel 57 | { 58 | public string Name { get; set; } 59 | public List Parameters { get; } = new(); 60 | 61 | public override string ToString() { 62 | var parameter = ""; 63 | 64 | if (Name.IsNullOrEmpty()) 65 | return "\n"; 66 | 67 | var count = Parameters.Count; 68 | for (var i = 0; i < count; i++) { 69 | if (count == 1) { 70 | parameter += $"{Parameters[0]}"; 71 | } 72 | else { 73 | if (i == count - 1) { 74 | parameter += $"{Parameters[i]}"; 75 | } 76 | else { 77 | parameter += $"{Parameters[i]}, "; 78 | } 79 | } 80 | } 81 | 82 | var rtn = $"{Name}({parameter});\n"; 83 | return rtn; 84 | } 85 | } 86 | 87 | public class ParameterModel 88 | { 89 | public string Name { get; set; } 90 | public string Type { get; set; } 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/Models/IncModel.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Services.Generate.Models 2 | { 3 | public class IncModel 4 | { 5 | public bool IsSys { get; set; } 6 | public string Name { get; set; } 7 | 8 | public override string ToString() { 9 | return IsSys ? $"#include <{Name}>" : $"#include \"{Name}\""; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/Models/MacroModel.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Services.Generate.Models 2 | { 3 | public class MacroModel 4 | { 5 | public string Name { get; set; } 6 | 7 | public string Value { get; set; } 8 | 9 | public override string ToString() { 10 | return $"#define {Name} {Value}"; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Services/Generate/Models/VariableModel.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Services.Generate.Models 2 | { 3 | public class VariableModel 4 | { 5 | public bool IsStatic { get; set; } 6 | public string Name { get; set; } 7 | public string Type { get; set; } 8 | public string Value { get; set; } 9 | 10 | public override string ToString() { 11 | var sta = IsStatic ? "static " : ""; 12 | var rtn = $"{sta}{Type} {Name} = {Value};"; 13 | return rtn; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Tools/DescriptionHelper.cs: -------------------------------------------------------------------------------- 1 | using CSP.Components.ValuePropertyGrid; 2 | using CSP.Events; 3 | using CSP.Models; 4 | using CSP.Modules.Pages.MCU.Models; 5 | using CSP.Modules.Pages.MCU.Models.Description; 6 | using CSP.Resources; 7 | using CSP.Utils; 8 | using CSP.Utils.Extensions; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Collections.ObjectModel; 12 | 13 | namespace CSP.Modules.Pages.MCU.Tools 14 | { 15 | public static class DescriptionHelper 16 | { 17 | private static readonly DescriptionInstance Instance = DescriptionInstance.Instance; 18 | 19 | public static ClockModel Clock { get => Instance.Clock; } 20 | 21 | public static string Company { get => Instance.Company; } 22 | 23 | public static ObservableDictionary Defines { get => Instance.Defines; } 24 | 25 | public static MCUModel MCU { get => Instance.MCU; } 26 | 27 | public static string Name { get => Instance.Name; } 28 | 29 | public static PinoutModel Pinout { get => Instance.Pinout; } 30 | 31 | public static ObservableDictionary Properties { get => Instance.Properties; } 32 | 33 | public static string RepositoryPath { get => Instance.RepositoryPath; } 34 | 35 | public static IPModel GetIP(string name) { 36 | return Instance.GetIP(name.ToUpper()); 37 | } 38 | 39 | public static MapModel GetMap(string name) { 40 | return Instance.GetMap(name.ToUpper()); 41 | } 42 | 43 | public static PinModel GetPinProperty(string name) { 44 | return Instance.GetPinProperty(name); 45 | } 46 | 47 | public static bool Load(MCUModel mcu) { 48 | DebugUtil.Assert(mcu != null, new ArgumentNullException(nameof(mcu)), "MCU不能为空"); 49 | if (mcu == null) 50 | return false; 51 | 52 | Instance.MCU = mcu; 53 | 54 | return true; 55 | } 56 | 57 | public static bool Load(string company, string name) { 58 | DebugUtil.Assert(!company.IsNullOrEmpty(), new ArgumentNullException(nameof(company)), "company不能为空"); 59 | DebugUtil.Assert(!name.IsNullOrEmpty(), new ArgumentNullException(nameof(name)), "name不能为空"); 60 | if (company == null || name == null) 61 | return false; 62 | 63 | return Load(MCUModel.Load($"{IniFile.PathMCUDb}/{company}/{name}.xml")); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/ViewModels/Components/Config/ClockViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Components.ValuePropertyGrid; 2 | using CSP.Events; 3 | using CSP.Modules.Pages.MCU.Tools; 4 | using CSP.Utils; 5 | using Prism.Events; 6 | using Prism.Mvvm; 7 | using Prism.Regions; 8 | 9 | namespace CSP.Modules.Pages.MCU.ViewModels.Components.Config 10 | { 11 | public class ClockViewModel : BindableBase, INavigationAware 12 | { 13 | #region INavigationAware 14 | 15 | public bool IsNavigationTarget(NavigationContext navigationContext) { 16 | return false; 17 | } 18 | 19 | public void OnNavigatedFrom(NavigationContext navigationContext) { 20 | } 21 | 22 | public void OnNavigatedTo(NavigationContext navigationContext) { 23 | _eventAggregator.GetEvent().Publish(null); 24 | if (DescriptionHelper.Properties.ContainsKey("Clock")) { 25 | var properties = DescriptionHelper.Properties["Clock"]; 26 | _eventAggregator.GetEvent().Publish(properties); 27 | } 28 | } 29 | 30 | #endregion INavigationAware 31 | 32 | private readonly IEventAggregator _eventAggregator; 33 | 34 | public ClockViewModel(IEventAggregator eventAggregator) { 35 | _eventAggregator = eventAggregator; 36 | 37 | if (!DescriptionHelper.Properties.ContainsKey("Clock")) { 38 | DescriptionHelper.Properties.Add("Clock", CreateClockPropertyDetails()); 39 | } 40 | } 41 | 42 | public static PropertyDetails CreateClockPropertyDetails() { 43 | var property = new PropertyDetails(); 44 | var clockMap = DescriptionHelper.GetMap("Clock"); 45 | var clockIP = DescriptionHelper.GetIP("Clock"); 46 | foreach (var mode in clockIP.ModeMap) { 47 | foreach (var parameter in clockIP.ModeMap[mode.Key].ParameterMap) { 48 | var map = new ObservableDictionary(); 49 | 50 | foreach (var value in parameter.Value.Values) { 51 | if (clockMap.Total.ContainsKey(value)) { 52 | map.Add(value, clockMap.Total[value]); 53 | } 54 | } 55 | 56 | var model = new DictionaryEditorModel { 57 | Source = map 58 | }; 59 | model.PropertyValueChanged += (sender, e) => { 60 | if (sender is not DictionaryEditorModel) 61 | return; 62 | 63 | switch (e.PropertyName) { 64 | case "Value": { 65 | break; 66 | } 67 | } 68 | }; 69 | property.Details.Add(parameter.Key, model); 70 | property.Attributes.Add(parameter.Key, clockMap.Attributes[parameter.Key]); 71 | } 72 | } 73 | 74 | return property; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/ViewModels/Components/Package/LQFP144ViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Models.Description; 2 | using CSP.Modules.Pages.MCU.Tools; 3 | using CSP.Utils; 4 | using Prism.Mvvm; 5 | 6 | namespace CSP.Modules.Pages.MCU.ViewModels.Components.Package 7 | { 8 | public class LQFP144ViewModel : BindableBase 9 | { 10 | public LQFP144ViewModel() { 11 | if (Pins.Length != 144) { 12 | MessageBoxUtil.Error($"读取引脚数据失败,LQFP144的引脚列表长度不为144,读取结果为{Pins.Length}"); 13 | } 14 | } 15 | 16 | public string Company { get => DescriptionHelper.Company; } 17 | public string Name { get => DescriptionHelper.Name; } 18 | public PinoutModel.PinModel[] Pins { get => DescriptionHelper.Pinout.Pins; } 19 | } 20 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/ViewModels/Components/Package/LQFP48ViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Models.Description; 2 | using CSP.Modules.Pages.MCU.Tools; 3 | using CSP.Utils; 4 | using Prism.Mvvm; 5 | 6 | namespace CSP.Modules.Pages.MCU.ViewModels.Components.Package 7 | { 8 | public class LQFP48ViewModel : BindableBase 9 | { 10 | public LQFP48ViewModel() { 11 | if (Pins.Length != 48) { 12 | MessageBoxUtil.Error($"读取引脚数据失败,LQFP48的引脚列表长度不为48,读取结果为{Pins.Length}"); 13 | } 14 | } 15 | 16 | public string Company { get => DescriptionHelper.Company; } 17 | public string Name { get => DescriptionHelper.Name; } 18 | public PinoutModel.PinModel[] Pins { get => DescriptionHelper.Pinout.Pins; } 19 | } 20 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/ViewModels/Components/Package/LQFP64ViewModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Modules.Pages.MCU.Models.Description; 2 | using CSP.Modules.Pages.MCU.Tools; 3 | using CSP.Utils; 4 | using Prism.Mvvm; 5 | 6 | namespace CSP.Modules.Pages.MCU.ViewModels.Components.Package 7 | { 8 | public class LQFP64ViewModel : BindableBase 9 | { 10 | public LQFP64ViewModel() { 11 | if (Pins.Length != 64) { 12 | MessageBoxUtil.Error($"读取引脚数据失败,LQFP64的引脚列表长度不为64,读取结果为{Pins.Length}"); 13 | } 14 | } 15 | 16 | public string Company { get => DescriptionHelper.Company; } 17 | public string Name { get => DescriptionHelper.Name; } 18 | public PinoutModel.PinModel[] Pins { get => DescriptionHelper.Pinout.Pins; } 19 | } 20 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/ClockTreeView.xaml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/ClockTreeView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views 2 | { 3 | public partial class ClockTreeView 4 | { 5 | public ClockTreeView() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Config/ClockView.xaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Config/ClockView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views.Components.Config 2 | { 3 | public partial class ClockView 4 | { 5 | public ClockView() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Config/GPIOView.xaml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Config/GPIOView.xaml.cs: -------------------------------------------------------------------------------- 1 | using CSP.Events; 2 | using Syncfusion.UI.Xaml.TreeView; 3 | 4 | namespace CSP.Modules.Pages.MCU.Views.Components.Config 5 | { 6 | public partial class GPIOView 7 | { 8 | public GPIOView() { 9 | InitializeComponent(); 10 | } 11 | 12 | private void OnSelectionChanged(object sender, ItemSelectionChangedEventArgs e) { 13 | var item = TreeView.SelectedItem; 14 | if (item is not SolutionExplorerEvent.Model value) 15 | return; 16 | 17 | value.CallBack?.Invoke(value.Name); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Package/LQFP144View.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views.Components.Package 2 | { 3 | public partial class LQFP144View 4 | { 5 | public LQFP144View() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Package/LQFP48View.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views.Components.Package 2 | { 3 | public partial class LQFP48View 4 | { 5 | public LQFP48View() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Components/Package/LQFP64View.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views.Components.Package 2 | { 3 | public partial class LQFP64View 4 | { 5 | public LQFP64View() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/ConfigView.xaml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/ConfigView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views 2 | { 3 | public partial class ConfigView 4 | { 5 | public ConfigView() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Windows/PropertyTableView.xaml: -------------------------------------------------------------------------------- 1 | 17 | 18 | -------------------------------------------------------------------------------- /Modules/CSP.Modules.Pages.MCU/Views/Windows/PropertyTableView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Modules.Pages.MCU.Views.Windows 2 | { 3 | public partial class PropertyTableView 4 | { 5 | public PropertyTableView() { 6 | InitializeComponent(); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 为了更好的方便大家的贡献,此仓库已迁移至https://github.com/csplink -------------------------------------------------------------------------------- /Resources/CSP.Resources.Tests/CSP.Resources.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Resources/CSP.Resources.Tests/IniFileTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using Xunit.Abstractions; 4 | 5 | namespace CSP.Resources.Tests 6 | { 7 | public class IniFileTests : IDisposable 8 | { 9 | private readonly ITestOutputHelper _testOutputHelper; 10 | 11 | public IniFileTests(ITestOutputHelper testOutputHelper) { 12 | _testOutputHelper = testOutputHelper; 13 | } 14 | 15 | public void Dispose() { 16 | IniFile.Save(); 17 | } 18 | 19 | [Fact] 20 | public void Test() { 21 | IniFile.PathMCUDb = "./"; 22 | Assert.False(IniFile.PathMCUDb != "./"); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Resources/CSP.Resources/CSP.Resources.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | True 52 | True 53 | Path.resx 54 | 55 | 56 | 57 | 58 | 59 | ResXFileCodeGenerator 60 | path.Designer.cs 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Media.Imaging; 2 | 3 | namespace CSP.Resources 4 | { 5 | public static class Icon 6 | { 7 | private static readonly IconInstance Instance = new(); 8 | 9 | public static BitmapImage BlockEight { 10 | get => Instance.BlockEight; 11 | } 12 | 13 | public static BitmapImage BlockFive { 14 | get => Instance.BlockFive; 15 | } 16 | 17 | public static BitmapImage BlockFour { 18 | get => Instance.BlockFour; 19 | } 20 | 21 | public static BitmapImage BlockNine { 22 | get => Instance.BlockNine; 23 | } 24 | 25 | public static BitmapImage BlockOne { 26 | get => Instance.BlockOne; 27 | } 28 | 29 | public static BitmapImage BlocksAndArrows { 30 | get => Instance.BlocksAndArrows; 31 | } 32 | 33 | public static BitmapImage BlockSeven { 34 | get => Instance.BlockSeven; 35 | } 36 | 37 | public static BitmapImage BlockSix { 38 | get => Instance.BlockSix; 39 | } 40 | 41 | public static BitmapImage BlockTen { 42 | get => Instance.BlockTen; 43 | } 44 | 45 | public static BitmapImage BlockThree { 46 | get => Instance.BlockThree; 47 | } 48 | 49 | public static BitmapImage BlockTwo { 50 | get => Instance.BlockTwo; 51 | } 52 | 53 | public static BitmapImage C { 54 | get => Instance.C; 55 | } 56 | 57 | public static BitmapImage Chip { 58 | get => Instance.Chip; 59 | } 60 | 61 | public static BitmapImage CSharp { 62 | get => Instance.CSharp; 63 | } 64 | 65 | public static BitmapImage Error { 66 | get => Instance.Error; 67 | } 68 | 69 | public static BitmapImage Git { 70 | get => Instance.Git; 71 | } 72 | 73 | public static BitmapImage Information { 74 | get => Instance.Information; 75 | } 76 | 77 | public static BitmapImage Json { 78 | get => Instance.Json; 79 | } 80 | 81 | public static BitmapImage Lib { 82 | get => Instance.Lib; 83 | } 84 | 85 | public static BitmapImage Log { 86 | get => Instance.Log; 87 | } 88 | 89 | public static BitmapImage New { 90 | get => Instance.New; 91 | } 92 | 93 | public static BitmapImage Pdf { 94 | get => Instance.Pdf; 95 | } 96 | 97 | public static BitmapImage Pin { 98 | get => Instance.Pin; 99 | } 100 | 101 | public static BitmapImage PlayOne { 102 | get => Instance.PlayOne; 103 | } 104 | 105 | public static BitmapImage PPT { 106 | get => Instance.PPT; 107 | } 108 | 109 | public static BitmapImage Setting { 110 | get => Instance.Setting; 111 | } 112 | 113 | public static BitmapImage System { 114 | get => Instance.System; 115 | } 116 | 117 | public static BitmapImage Time { 118 | get => Instance.Time; 119 | } 120 | 121 | public static BitmapImage Timer { 122 | get => Instance.Timer; 123 | } 124 | 125 | public static BitmapImage Warning { 126 | get => Instance.Warning; 127 | } 128 | 129 | public static BitmapImage Xml { 130 | get => Instance.Xml; 131 | } 132 | 133 | public static BitmapImage YellowFolder { 134 | get => Instance.YellowFolder; 135 | } 136 | } 137 | } -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockEight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockEight.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockFive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockFive.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockFour.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockFour.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockNine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockNine.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockOne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockOne.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockSeven.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockSeven.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockSix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockSix.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockTen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockTen.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockThree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockThree.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlockTwo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlockTwo.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/BlocksAndArrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/BlocksAndArrows.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/C.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/CSharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/CSharp.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Chip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Chip.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Error.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Git.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Git.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Information.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Json.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Lib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Lib.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Log.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/New.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/New.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/PPT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/PPT.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Pdf.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Pin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Pin.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/PlayOne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/PlayOne.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Setting.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/System.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/System.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Time.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Timer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Timer.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Warning.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/Xml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/Xml.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/Icon/YellowFolder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqyjlj/csp/3061c73008a813b49e00772cd3156f20378d977b/Resources/CSP.Resources/Icon/YellowFolder.png -------------------------------------------------------------------------------- /Resources/CSP.Resources/IconInstance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Media.Imaging; 3 | 4 | namespace CSP.Resources 5 | { 6 | internal class IconInstance 7 | { 8 | internal readonly BitmapImage BlockEight = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockEight.png")); 9 | internal readonly BitmapImage BlockFive = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockFive.png")); 10 | internal readonly BitmapImage BlockFour = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockFour.png")); 11 | internal readonly BitmapImage BlockNine = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockNine.png")); 12 | internal readonly BitmapImage BlockOne = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockOne.png")); 13 | internal readonly BitmapImage BlocksAndArrows = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlocksAndArrows.png")); 14 | internal readonly BitmapImage BlockSeven = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockSeven.png")); 15 | internal readonly BitmapImage BlockSix = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockSix.png")); 16 | internal readonly BitmapImage BlockTen = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockTen.png")); 17 | internal readonly BitmapImage BlockThree = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockThree.png")); 18 | internal readonly BitmapImage BlockTwo = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/BlockTwo.png")); 19 | internal readonly BitmapImage C = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/C.png")); 20 | internal readonly BitmapImage Chip = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Chip.png")); 21 | internal readonly BitmapImage CSharp = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/CSharp.png")); 22 | internal readonly BitmapImage Error = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Error.png")); 23 | internal readonly BitmapImage Git = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Git.png")); 24 | internal readonly BitmapImage Information = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Information.png")); 25 | internal readonly BitmapImage Json = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Json.png")); 26 | internal readonly BitmapImage Lib = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Lib.png")); 27 | internal readonly BitmapImage Log = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Log.png")); 28 | internal readonly BitmapImage New = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/New.png")); 29 | internal readonly BitmapImage Pdf = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Pdf.png")); 30 | internal readonly BitmapImage Pin = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Pin.png")); 31 | internal readonly BitmapImage PlayOne = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/PlayOne.png")); 32 | internal readonly BitmapImage PPT = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/PPT.png")); 33 | internal readonly BitmapImage Setting = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Setting.png")); 34 | internal readonly BitmapImage System = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/System.png")); 35 | internal readonly BitmapImage Time = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Time.png")); 36 | internal readonly BitmapImage Timer = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Timer.png")); 37 | internal readonly BitmapImage Warning = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Warning.png")); 38 | internal readonly BitmapImage Xml = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/Xml.png")); 39 | internal readonly BitmapImage YellowFolder = new(new Uri(@"pack://application:,,,/CSP.Resources;component/Icon/YellowFolder.png")); 40 | } 41 | } -------------------------------------------------------------------------------- /Resources/CSP.Resources/IniFile.cs: -------------------------------------------------------------------------------- 1 | namespace CSP.Resources 2 | { 3 | public static class IniFile 4 | { 5 | private static readonly IniFileInstance Ini = new(); 6 | 7 | public static string PathGit { 8 | get => Ini.ReadKey("Path", "Git", Path.Git); 9 | set => Ini.AddKey("Path", "Git", value); 10 | } 11 | 12 | public static string PathLogFile { 13 | get => Ini.ReadKey("Path", "LogFile", Path.LogFile); 14 | set => Ini.AddKey("Path", "LogFile", value); 15 | } 16 | 17 | public static string PathMCUDb { 18 | get => Ini.ReadKey("Path", "MCUDb", Path.MCUDb); 19 | set => Ini.AddKey("Path", "MCUDb", value); 20 | } 21 | 22 | public static string PathMCUDbUrl { 23 | get => Ini.ReadKey("Path", "MCUDbUrl", Path.MCUDbUrl); 24 | set => Ini.AddKey("Path", "MCUDbUrl", value); 25 | } 26 | 27 | public static string PathRepository { 28 | get => Ini.ReadKey("Path", "Repository", Path.Repository); 29 | set => Ini.AddKey("Path", "Repository", value); 30 | } 31 | 32 | public static void Save() { 33 | Ini.Save(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Resources/CSP.Resources/IniFileInstance.cs: -------------------------------------------------------------------------------- 1 | using IniParser; 2 | using IniParser.Model; 3 | using System.IO; 4 | 5 | namespace CSP.Resources 6 | { 7 | public class IniFileInstance 8 | { 9 | private const string IniPath = "./CSP.ini"; 10 | private readonly IniData _ini = new(); 11 | private readonly FileIniDataParser _parser = new(); 12 | 13 | public IniFileInstance() { 14 | if (!File.Exists(IniPath)) { 15 | InitData(); 16 | } 17 | else { 18 | _ini = _parser.ReadFile(IniPath); 19 | } 20 | } 21 | 22 | public void Save() { 23 | _parser.WriteFile(IniPath, _ini); 24 | } 25 | 26 | internal void AddKey(string section, string key, string value) { 27 | if (!_ini.Sections.ContainsSection(section)) { 28 | _ini.Sections.AddSection("Path"); 29 | } 30 | 31 | if (_ini[section].ContainsKey(key)) { 32 | _ini[section][key] = value; 33 | } 34 | else { 35 | _ini[section].AddKey(key, value); 36 | } 37 | } 38 | 39 | internal string ReadKey(string section, string key, string defaultValue) { 40 | if (!_ini.Sections.ContainsSection(section)) { 41 | AddKey(section, key, defaultValue); 42 | return defaultValue; 43 | } 44 | 45 | if (!_ini[section].ContainsKey(key)) { 46 | AddKey(section, key, defaultValue); 47 | return defaultValue; 48 | } 49 | 50 | return _ini[section][key]; 51 | } 52 | 53 | private void InitData() { 54 | AddKey("Path", "Git", Path.Git); 55 | AddKey("Path", "MCUDb", Path.MCUDb); 56 | AddKey("Path", "MCUDbUrl", Path.MCUDbUrl); 57 | AddKey("Path", "LogFile", Path.LogFile); 58 | AddKey("Path", "Repository", Path.Repository); 59 | 60 | Save(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Resources/CSP.Resources/Path.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CSP.Resources { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Path { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Path() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CSP.Resources.Path", typeof(Path).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找类似 ./tools/mingit 的本地化字符串。 65 | /// 66 | internal static string Git { 67 | get { 68 | return ResourceManager.GetString("Git", resourceCulture); 69 | } 70 | } 71 | 72 | /// 73 | /// 查找类似 logs/csp.log 的本地化字符串。 74 | /// 75 | internal static string LogFile { 76 | get { 77 | return ResourceManager.GetString("LogFile", resourceCulture); 78 | } 79 | } 80 | 81 | /// 82 | /// 查找类似 ./Database/MCU 的本地化字符串。 83 | /// 84 | internal static string MCUDb { 85 | get { 86 | return ResourceManager.GetString("MCUDb", resourceCulture); 87 | } 88 | } 89 | 90 | /// 91 | /// 查找类似 https://gitee.com/misfra/misfra_mcu_db 的本地化字符串。 92 | /// 93 | internal static string MCUDbUrl { 94 | get { 95 | return ResourceManager.GetString("MCUDbUrl", resourceCulture); 96 | } 97 | } 98 | 99 | /// 100 | /// 查找类似 ./Repository 的本地化字符串。 101 | /// 102 | internal static string Repository { 103 | get { 104 | return ResourceManager.GetString("Repository", resourceCulture); 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Services/CSP.Services.Tests/CSP.Services.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Services/CSP.Services/CSP.Services.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Services/CSP.Services/Models/ProjectModel.cs: -------------------------------------------------------------------------------- 1 | using CSP.Utils; 2 | using Prism.Mvvm; 3 | using System; 4 | using System.IO; 5 | using System.Windows; 6 | using System.Xml.Serialization; 7 | 8 | namespace CSP.Services.Models 9 | { 10 | [XmlRoot("Project", IsNullable = false)] 11 | public class ProjectModel : BindableBase 12 | { 13 | [XmlElement(ElementName = "Header")] 14 | public string Header { get; set; } 15 | 16 | [XmlElement("Target")] 17 | public TargetModel Target { get; set; } 18 | 19 | [XmlElement(ElementName = "Version")] 20 | public string Version { get; set; } 21 | 22 | internal static void Create(string path, ProjectModel model) { 23 | DebugUtil.Assert(path != null, new ArgumentNullException(nameof(path))); 24 | DebugUtil.Assert(model != null, new ArgumentNullException(nameof(model))); 25 | 26 | var dir = Path.GetDirectoryName(path); 27 | if (!Directory.Exists(dir)) 28 | if (dir != null) 29 | Directory.CreateDirectory(dir); 30 | 31 | var serializer = new XmlSerializer(typeof(ProjectModel)); 32 | // ReSharper disable once AssignNullToNotNullAttribute 33 | Stream fs = new FileStream(path, FileMode.Create); 34 | var writer = new StreamWriter(fs); 35 | 36 | // var ns = new XmlSerializerNamespaces(); 37 | // ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); 38 | // serializer.Serialize(writer, prj, ns); 39 | 40 | serializer.Serialize(writer, model); 41 | writer.Close(); 42 | } 43 | 44 | internal static ProjectModel Load(string path) { 45 | DebugUtil.Assert(path != null, new ArgumentNullException(nameof(path))); 46 | 47 | if (!File.Exists(path)) return null; 48 | 49 | var deserializer = new XmlSerializer(typeof(ProjectModel)); 50 | var reader = new StreamReader(path); 51 | 52 | ProjectModel rtn; 53 | try { 54 | rtn = (ProjectModel)deserializer.Deserialize(reader); 55 | } 56 | catch (InvalidOperationException e) { 57 | MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); 58 | return null; 59 | } 60 | 61 | DebugUtil.Assert(rtn != null, new ArgumentNullException(nameof(rtn)), "XML反序列化失败"); 62 | 63 | return rtn; 64 | } 65 | 66 | public class TargetModel : BindableBase 67 | { 68 | [XmlElement("MCU")] 69 | public MCUModel MCU { get; set; } 70 | 71 | [XmlAttribute("Name")] 72 | public string Name { get; set; } 73 | 74 | [XmlAttribute("Type")] 75 | public string Type { get; set; } 76 | 77 | public class MCUModel : BindableBase 78 | { 79 | [XmlAttribute("Company")] 80 | public string Company { get; set; } 81 | 82 | [XmlAttribute("Name")] 83 | public string Name { get; set; } 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /Services/CSP.Services/ProjectHelper.cs: -------------------------------------------------------------------------------- 1 | using CSP.Services.Models; 2 | using CSP.Utils; 3 | using System; 4 | 5 | namespace CSP.Services 6 | { 7 | public static class ProjectHelper 8 | { 9 | private static readonly ProjectInstance Instance = ProjectInstance.Instance; 10 | public static string Name { get; set; } 11 | public static string Path { get; set; } 12 | public static ProjectModel Project { get; set; } 13 | 14 | public static void Create(string path, ProjectModel model) { 15 | DebugUtil.Assert(path != null, new ArgumentNullException(nameof(path))); 16 | DebugUtil.Assert(model != null, new ArgumentNullException(nameof(model))); 17 | 18 | Path = path; 19 | Name = System.IO.Path.GetFileNameWithoutExtension(path); 20 | ProjectModel.Create(path, model); 21 | Project = model; 22 | } 23 | 24 | public static void Create(string path) { 25 | Create(path, Project); 26 | } 27 | 28 | public static ProjectModel Load(string path) { 29 | DebugUtil.Assert(path != null, new ArgumentNullException(nameof(path))); 30 | 31 | Path = path; 32 | Name = System.IO.Path.GetFileNameWithoutExtension(path); 33 | Project = ProjectModel.Load(path); 34 | return Project; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Services/CSP.Services/ProjectInstance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSP.Services 4 | { 5 | internal class ProjectInstance 6 | { 7 | private static readonly Lazy Lazy = new(static () => new ProjectInstance()); 8 | 9 | private ProjectInstance() { 10 | } 11 | 12 | public static ProjectInstance Instance => Lazy.Value; 13 | } 14 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils.Tests/CSP.Utils.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Utils/CSP.Utils/BindableBaseUtil.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace CSP.Utils 8 | { 9 | public delegate void PropertyValueChangedEventHandler(object sender, PropertyValueChangedEventArgs e); 10 | 11 | public abstract class BindableBaseUtil : BindableBase 12 | { 13 | public new event PropertyChangedEventHandler PropertyChanged; 14 | 15 | public event PropertyValueChangedEventHandler PropertyValueChanged; 16 | 17 | protected override void OnPropertyChanged(PropertyChangedEventArgs args) { 18 | PropertyChanged?.Invoke(this, args); 19 | } 20 | 21 | protected new void RaisePropertyChanged([CallerMemberName] string propertyName = null) { 22 | OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); 23 | } 24 | 25 | protected override bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) { 26 | if (EqualityComparer.Default.Equals(storage, value)) return false; 27 | PropertyValueChanged?.Invoke(this, new PropertyValueChangedEventArgs(propertyName, storage, value)); 28 | storage = value; 29 | RaisePropertyChanged(propertyName); 30 | 31 | return true; 32 | } 33 | 34 | protected override bool SetProperty(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null) { 35 | if (EqualityComparer.Default.Equals(storage, value)) return false; 36 | PropertyValueChanged?.Invoke(this, new PropertyValueChangedEventArgs(propertyName, storage, value)); 37 | storage = value; 38 | onChanged?.Invoke(); 39 | RaisePropertyChanged(propertyName); 40 | 41 | return true; 42 | } 43 | } 44 | 45 | public class PropertyValueChangedEventArgs : PropertyChangedEventArgs 46 | { 47 | public PropertyValueChangedEventArgs(string propertyName) : base(propertyName) { 48 | } 49 | 50 | public PropertyValueChangedEventArgs(string propertyName, object oldValue, object newValue) : base(propertyName) { 51 | NewValue = newValue; 52 | OldValue = oldValue; 53 | } 54 | 55 | public virtual object NewValue { get; } 56 | 57 | public virtual object OldValue { get; } 58 | } 59 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/CSP.Utils.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | true 6 | xqyjlj 7 | copyright © 2021-2022 xqyjlj<xqyjlj@126.com> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Utils/CSP.Utils/DebugUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSP.Utils 4 | { 5 | public static class DebugUtil 6 | { 7 | public static void Assert(bool condition, Exception exception, string message = "") { 8 | #if DEBUG 9 | System.Diagnostics.Debug.Assert(condition, message, exception.ToString()); 10 | #else 11 | if(!condition) 12 | { 13 | Serilog.Log.Error(exception, message); 14 | } 15 | #endif 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/DialogUtil.cs: -------------------------------------------------------------------------------- 1 | using CSP.Models.Interfaces; 2 | using CSP.Utils.Extensions; 3 | using Prism.Ioc; 4 | using Prism.Services.Dialogs; 5 | using Serilog; 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | namespace CSP.Utils 10 | { 11 | public static class DialogUtil 12 | { 13 | public static readonly List DialogNames = new(); 14 | public static readonly List DialogWindowNames = new(); 15 | 16 | public static void RegisterDialog(IContainerRegistry containerRegistry, string name = null) where TViewModel : IDialogWindowParameters { 17 | containerRegistry.RegisterDialog(name); 18 | 19 | AddDialogName(name); 20 | } 21 | 22 | public static void RegisterDialogWindow(IContainerRegistry containerRegistry, string name = null) where TWindow : IDialogWindow { 23 | containerRegistry.RegisterDialogWindow(name); 24 | 25 | AddDialogWindowName(name); 26 | } 27 | 28 | public static void ShowModalDialog(IDialogService dialogService, string name, IDialogParameters parameters = null, Action callback = null, string windowName = null) { 29 | Log.Information($"打开模态对话框 \"{name}\" + \"{windowName}\""); 30 | 31 | if (!windowName.IsNullOrEmpty()) { 32 | if (!DialogWindowNames.Contains(windowName)) { 33 | var message = $"无Dialog Window \"{windowName}\""; 34 | MessageBoxUtil.Error(message); 35 | } 36 | } 37 | 38 | if (DialogNames.Contains(name)) { 39 | dialogService.ShowDialog(name, parameters, callback, windowName); 40 | } 41 | else { 42 | var message = $"尝试打开模态对话框 \"{name}\" 失败"; 43 | MessageBoxUtil.Error(message); 44 | } 45 | } 46 | 47 | public static void ShowNonModalDialog(IDialogService dialogService, string name, IDialogParameters parameters = null, Action callback = null, string windowName = null) { 48 | Log.Information($"打开非模态对话框 \"{name}\" + \"{windowName}\""); 49 | 50 | if (!windowName.IsNullOrEmpty()) { 51 | if (!DialogWindowNames.Contains(windowName)) { 52 | var message = $"无Dialog Window \"{windowName}\""; 53 | MessageBoxUtil.Error(message); 54 | } 55 | } 56 | 57 | if (DialogNames.Contains(name)) { 58 | dialogService.Show(name, parameters, callback, windowName); 59 | } 60 | else { 61 | var message = $"尝试打开非模态对话框 \"{name}\" 失败"; 62 | MessageBoxUtil.Error(message); 63 | } 64 | } 65 | 66 | private static void AddDialogName(string name) { 67 | DialogNames.Add(name); 68 | } 69 | 70 | private static void AddDialogWindowName(string name) { 71 | DialogWindowNames.Add(name); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/Extensions/ByteArrayExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace CSP.Utils.Extensions 5 | { 6 | public static class ByteArrayExtension 7 | { 8 | public static string FromHexToString(this byte[] bytes) { 9 | var builder = new StringBuilder(); 10 | 11 | foreach (var t in bytes) 12 | builder.Append($"{t:X2} "); 13 | 14 | return builder.ToString().Trim(); 15 | } 16 | 17 | public static string FromTextToString(this byte[] bytes, Encoding encoding) { 18 | if (bytes == null) 19 | throw new ArgumentNullException(nameof(bytes)); 20 | if (encoding == null) 21 | throw new ArgumentNullException(nameof(encoding)); 22 | 23 | return encoding.GetString(bytes); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/Extensions/StringExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CSP.Utils.Extensions 7 | { 8 | public static class StringExtension 9 | { 10 | public static byte[] FromHexToByteArray(this string str) { 11 | if (str == null) 12 | throw new ArgumentNullException(nameof(str)); 13 | 14 | var chars = str.Replace(" ", "").Split(2); 15 | var returnBytes = new byte[chars.Length]; 16 | 17 | //逐个字符变为16进制字节数据 18 | for (var i = 0; i < chars.Length; i++) 19 | returnBytes[i] = Convert.ToByte(chars[i], 16); 20 | 21 | return returnBytes; 22 | } 23 | 24 | public static string FromHexToText(this string str, Encoding encoding) { 25 | if (str == null) 26 | throw new ArgumentNullException(nameof(str)); 27 | if (encoding == null) 28 | throw new ArgumentNullException(nameof(encoding)); 29 | 30 | var bytes = str.FromHexToByteArray(); 31 | return encoding.GetString(bytes); 32 | } 33 | 34 | public static byte[] FromTextToByteArray(this string str, Encoding encoding) { 35 | if (str == null) 36 | throw new ArgumentNullException(nameof(str)); 37 | if (encoding == null) 38 | throw new ArgumentNullException(nameof(encoding)); 39 | 40 | return encoding.GetBytes(str); 41 | } 42 | 43 | public static string FromTextToHex(this string str, Encoding encoding) { 44 | if (str == null) 45 | throw new ArgumentNullException(nameof(str)); 46 | if (encoding == null) 47 | throw new ArgumentNullException(nameof(encoding)); 48 | 49 | return BitConverter.ToString(encoding.GetBytes(str)).Replace("-", " "); 50 | } 51 | 52 | public static bool IsLegalHex(this string str) { 53 | if (str == null) 54 | throw new ArgumentNullException(nameof(str)); 55 | 56 | IList hexSet = new List 57 | { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f' }; 58 | 59 | return str.All(item => hexSet.Contains(item)); 60 | } 61 | 62 | public static bool IsNullOrEmpty(this string s) { 63 | return string.IsNullOrEmpty(s); 64 | } 65 | 66 | /// 67 | /// 按指定长度分割字符串 68 | /// 69 | /// 70 | /// 原字符串 71 | /// 72 | /// 73 | /// 分割长度 74 | /// 75 | /// 76 | /// 被分割后的字符串 77 | /// 78 | public static string[] Split(this string str, int count) { 79 | if (str == null) 80 | throw new ArgumentNullException(nameof(str)); 81 | 82 | List list = new(); 83 | 84 | for (var i = 0; i < str.Length; i += count) 85 | list.Add((str.Length - i) > count ? str.Substring(i, count) : str.Substring(i)); 86 | 87 | return list.ToArray(); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/MessageBoxUtil.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System.Windows; 3 | 4 | namespace CSP.Utils 5 | { 6 | public static class MessageBoxUtil 7 | { 8 | public static void Error(string message) { 9 | Log.Error(message); 10 | MessageBox.Show(message, "错误", MessageBoxButton.YesNo, MessageBoxImage.Error); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/RegionUtil.cs: -------------------------------------------------------------------------------- 1 | using Prism.Ioc; 2 | using Prism.Regions; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace CSP.Utils 8 | { 9 | public static class RegionUtil 10 | { 11 | private static readonly List Names = new(); 12 | 13 | public static IEnumerable Views => Names; 14 | 15 | public static void RegisterForNavigation(IContainerRegistry containerRegistry, string viewName) { 16 | containerRegistry.RegisterForNavigation(viewName); 17 | 18 | AddView(viewName); 19 | } 20 | 21 | public static void RegisterViewWithRegion(IRegionManager regionManager, string regionName, Type viewType) { 22 | regionManager.RegisterViewWithRegion(regionName, viewType); 23 | } 24 | 25 | public static void RequestNavigate(IRegionManager regionManager, string regionName, string viewName) { 26 | if (regionManager.Regions.ContainsRegionWithName(regionName) && Views.Contains(viewName)) { 27 | regionManager.RequestNavigate(regionName, viewName); 28 | } 29 | } 30 | 31 | public static void RequestNavigate(IRegionManager regionManager, string regionName, string viewName, NavigationParameters navigationParameters) { 32 | if (regionManager.Regions.ContainsRegionWithName(regionName) && Views.Contains(viewName)) { 33 | regionManager.RequestNavigate(regionName, viewName, navigationParameters); 34 | } 35 | } 36 | 37 | private static void AddView(string name) { 38 | Names.Add(name); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/ThemesUtil.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.SfSkinManager; 2 | using Syncfusion.Themes.Office2019Colorful.WPF; 3 | using System.Windows; 4 | using System.Windows.Media; 5 | 6 | namespace CSP.Utils 7 | { 8 | public static class ThemesUtil 9 | { 10 | public static void SetThemes(DependencyObject window, string theme) { 11 | Office2019ColorfulThemeSettings themeSettings = new() { 12 | FontFamily = new FontFamily("Segoe UI, 微软雅黑"), 13 | BodyAltFontSize = 12 14 | }; 15 | SfSkinManager.RegisterThemeSettings(theme, themeSettings); 16 | SfSkinManager.SetTheme(window, new Theme { ThemeName = theme }); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Utils/CSP.Utils/Util.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace CSP.Utils 4 | { 5 | public class Util 6 | { 7 | public static void OpenUrl(string url) { 8 | Process p = new(); 9 | p.StartInfo.FileName = "cmd.exe"; 10 | p.StartInfo.UseShellExecute = false; 11 | p.StartInfo.RedirectStandardInput = true; 12 | p.StartInfo.RedirectStandardOutput = false; 13 | p.StartInfo.RedirectStandardError = true; 14 | p.StartInfo.CreateNoWindow = true; 15 | p.Start(); 16 | 17 | p.StandardInput.WriteLine("start " + url + "&exit"); 18 | p.StandardInput.AutoFlush = true; 19 | p.WaitForExit(); 20 | p.Close(); 21 | } 22 | } 23 | } --------------------------------------------------------------------------------