feat: 移植 lwprintf
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
"srcDirs": [
|
"srcDirs": [
|
||||||
".eide/deps",
|
".eide/deps",
|
||||||
"3rd-part",
|
"3rd-part",
|
||||||
"libraries/device"
|
"libraries/device",
|
||||||
|
"middlewares"
|
||||||
],
|
],
|
||||||
"virtualFolder": {
|
"virtualFolder": {
|
||||||
"name": "<virtual_root>",
|
"name": "<virtual_root>",
|
||||||
@@ -74,6 +75,9 @@
|
|||||||
{
|
{
|
||||||
"path": "project/src/at32f403a_407_wk_config.c"
|
"path": "project/src/at32f403a_407_wk_config.c"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "project/src/by_debug.c"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "project/src/main.c"
|
"path": "project/src/main.c"
|
||||||
}
|
}
|
||||||
@@ -131,9 +135,9 @@
|
|||||||
"libraries/cmsis/cm4/device_support",
|
"libraries/cmsis/cm4/device_support",
|
||||||
"project/inc",
|
"project/inc",
|
||||||
".cmsis/include",
|
".cmsis/include",
|
||||||
"project/MDK_V5/RTE/_BC1C",
|
|
||||||
".eide/deps",
|
".eide/deps",
|
||||||
"3rd-part/dwt_delay"
|
"3rd-part/dwt_delay",
|
||||||
|
"3rd-part/lwprintf"
|
||||||
],
|
],
|
||||||
"libList": [],
|
"libList": [],
|
||||||
"sourceDirList": [],
|
"sourceDirList": [],
|
||||||
|
|||||||
400
3rd-part/lwprintf/.gitignore
vendored
Normal file
400
3rd-part/lwprintf/.gitignore
vendored
Normal file
@@ -0,0 +1,400 @@
|
|||||||
|
#Build Keil files
|
||||||
|
*.rar
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
*.crf
|
||||||
|
*.htm
|
||||||
|
*.dep
|
||||||
|
*.map
|
||||||
|
*.bak
|
||||||
|
*.axf
|
||||||
|
*.lnp
|
||||||
|
*.lst
|
||||||
|
*.ini
|
||||||
|
*.scvd
|
||||||
|
*.iex
|
||||||
|
*.sct
|
||||||
|
*.MajerleT
|
||||||
|
*.tjuln
|
||||||
|
*.tilen
|
||||||
|
*.dbgconf
|
||||||
|
*.uvguix
|
||||||
|
*.uvoptx
|
||||||
|
*.__i
|
||||||
|
*.i
|
||||||
|
*.txt
|
||||||
|
!docs/*.txt
|
||||||
|
!CMakeLists.txt
|
||||||
|
RTE/
|
||||||
|
|
||||||
|
*debug
|
||||||
|
|
||||||
|
# IAR Settings
|
||||||
|
**/settings/*.crun
|
||||||
|
**/settings/*.dbgdt
|
||||||
|
**/settings/*.cspy
|
||||||
|
**/settings/*.cspy.*
|
||||||
|
**/settings/*.xcl
|
||||||
|
**/settings/*.dni
|
||||||
|
**/settings/*.wsdt
|
||||||
|
**/settings/*.wspos
|
||||||
|
|
||||||
|
# IAR Debug Exe
|
||||||
|
**/Exe/*.sim
|
||||||
|
|
||||||
|
# IAR Debug Obj
|
||||||
|
**/Obj/*.pbd
|
||||||
|
**/Obj/*.pbd.*
|
||||||
|
**/Obj/*.pbi
|
||||||
|
**/Obj/*.pbi.*
|
||||||
|
|
||||||
|
*.TMP
|
||||||
|
/docs_src/x_Doxyfile.doxy
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
[Dd]ebug*/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
_build/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUNIT
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
**/Properties/launchSettings.json
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_i.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
*.out
|
||||||
|
*.sim
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding add-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
.idea/
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
|
# CodeRush
|
||||||
|
.cr/
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
log_file.txt
|
||||||
|
.metadata/
|
||||||
|
.mxproject
|
||||||
|
.settings/
|
||||||
|
project.ioc
|
||||||
|
mx.scratch
|
||||||
|
*.tilen majerle
|
||||||
|
|
||||||
|
|
||||||
|
# Altium
|
||||||
|
Project outputs*
|
||||||
|
History/
|
||||||
|
*.SchDocPreview
|
||||||
|
*.$$$Preview
|
||||||
|
|
||||||
|
# VSCode projects
|
||||||
|
project_vscode_compiled.exe
|
||||||
6
3rd-part/lwprintf/AUTHORS
Normal file
6
3rd-part/lwprintf/AUTHORS
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Tilen Majerle <tilen.majerle@gmail.com>
|
||||||
|
Tilen Majerle <tilen@majerle.eu>
|
||||||
|
Okarss <104319900+Okarss@users.noreply.github.com>
|
||||||
|
Dmitry Karasev <karasevsdmitry@yandex.ru>
|
||||||
|
Brian <bayuan@purdue.edu>
|
||||||
|
Peter Maxwell Warasila <madmaxwell@soundcomesout.com>
|
||||||
41
3rd-part/lwprintf/CHANGELOG.md
Normal file
41
3rd-part/lwprintf/CHANGELOG.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## Develop
|
||||||
|
|
||||||
|
- Add `lwprintf_debug` and `lwprintf_debug_cond` functions
|
||||||
|
|
||||||
|
## v1.0.5
|
||||||
|
|
||||||
|
- Fix building the library with `LWPRINTF_CFG_OS=1` and `LWPRINTF_CFG_OS_MANUAL_PROTECT=0` options
|
||||||
|
|
||||||
|
## v1.0.4
|
||||||
|
|
||||||
|
- Fix calculation for NULL terminated string and precision with 0 as an input
|
||||||
|
- Split CMakeLists.txt files between library and executable
|
||||||
|
- Fix missing break in switch statement
|
||||||
|
- Add support for manual mutual-exclusion setup in OS mode
|
||||||
|
- Change license year to 2022
|
||||||
|
- Update code style with astyle
|
||||||
|
- Add `.clang-format` draft
|
||||||
|
- Fix protection functions for when print mode is not used
|
||||||
|
|
||||||
|
## v1.0.3
|
||||||
|
|
||||||
|
- CMSIS-OS improvements for Kernel aware debuggers
|
||||||
|
|
||||||
|
## v1.0.2
|
||||||
|
|
||||||
|
- Fixed `float` output when engineering mode is disabled
|
||||||
|
|
||||||
|
## v1.0.1
|
||||||
|
|
||||||
|
- Fixed compiler error when engineering mode disabled but float enabled
|
||||||
|
- Properly handled `zero` float inputs
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
- First stable release
|
||||||
|
- Embedded systems optimized library
|
||||||
|
- Apply all modifiers except `%a`
|
||||||
|
- Extensive docs available
|
||||||
|
- Operating system ready with CMSIS-OS template
|
||||||
21
3rd-part/lwprintf/LICENSE
Normal file
21
3rd-part/lwprintf/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
29
3rd-part/lwprintf/README.md
Normal file
29
3rd-part/lwprintf/README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Lightweight printf stdio manager
|
||||||
|
|
||||||
|
<h3>Read first: <a href="http://docs.majerle.eu/projects/lwprintf/">Documentation</a></h3>
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Written in C (C11), compatible with ``size_t`` and ``uintmax_t`` types for some specifiers
|
||||||
|
* Implements output functions compatible with ``printf``, ``vprintf``, ``snprintf``, ``sprintf`` and ``vsnprintf``
|
||||||
|
* Low-memory footprint, suitable for embedded systems
|
||||||
|
* Reentrant access to all API functions
|
||||||
|
* Operating-system ready
|
||||||
|
* Requires single output function to be implemented by user for ``printf``-like API calls
|
||||||
|
* With optional functions for operating systems to protect multiple threads printing to the same output stream
|
||||||
|
* Allows multiple output stream functions (unlike standard ``printf`` which supports only one) to separate parts of application
|
||||||
|
* Added additional specifiers vs original features
|
||||||
|
* User friendly MIT license
|
||||||
|
|
||||||
|
## Contribute
|
||||||
|
|
||||||
|
Fresh contributions are always welcome. Simple instructions to proceed:
|
||||||
|
|
||||||
|
1. Fork Github repository
|
||||||
|
2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project
|
||||||
|
3. Create a pull request to develop branch with new features or bug fixes
|
||||||
|
|
||||||
|
Alternatively you may:
|
||||||
|
|
||||||
|
1. Report a bug
|
||||||
|
2. Ask for a feature request
|
||||||
1274
3rd-part/lwprintf/lwprintf.c
Normal file
1274
3rd-part/lwprintf/lwprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
313
3rd-part/lwprintf/lwprintf.h
Normal file
313
3rd-part/lwprintf/lwprintf.h
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
/**
|
||||||
|
* \file lwprintf.h
|
||||||
|
* \brief Lightweight stdio manager
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is part of LwPRINTF - Lightweight stdio manager library.
|
||||||
|
*
|
||||||
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
|
* Version: v1.0.5
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_HDR_H
|
||||||
|
#define LWPRINTF_HDR_H
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "lwprintf_opt.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup LWPRINTF Lightweight stdio manager
|
||||||
|
* \brief Lightweight stdio manager
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Unused variable macro
|
||||||
|
* \param[in] x: Unused variable
|
||||||
|
*/
|
||||||
|
#define LWPRINTF_UNUSED(x) ((void)(x))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Calculate size of statically allocated array
|
||||||
|
* \param[in] x: Input array
|
||||||
|
* \return Number of array elements
|
||||||
|
*/
|
||||||
|
#define LWPRINTF_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Forward declaration for LwPRINTF instance
|
||||||
|
*/
|
||||||
|
struct lwprintf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Callback function for character output
|
||||||
|
* \param[in] ch: Character to print
|
||||||
|
* \param[in] lwobj: LwPRINTF instance
|
||||||
|
* \return `ch` on success, `0` to terminate further string processing
|
||||||
|
*/
|
||||||
|
typedef int (*lwprintf_output_fn)(int ch, struct lwprintf* lwobj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief LwPRINTF instance
|
||||||
|
*/
|
||||||
|
typedef struct lwprintf {
|
||||||
|
lwprintf_output_fn out_fn; /*!< Output function for direct print operations */
|
||||||
|
#if LWPRINTF_CFG_OS || __DOXYGEN__
|
||||||
|
LWPRINTF_CFG_OS_MUTEX_HANDLE mutex; /*!< OS mutex handle */
|
||||||
|
#endif /* LWPRINTF_CFG_OS || __DOXYGEN__ */
|
||||||
|
} lwprintf_t;
|
||||||
|
|
||||||
|
uint8_t lwprintf_init_ex(lwprintf_t* lwobj, lwprintf_output_fn out_fn);
|
||||||
|
int lwprintf_vprintf_ex(lwprintf_t* const lwobj, const char* format, va_list arg);
|
||||||
|
int lwprintf_printf_ex(lwprintf_t* const lwobj, const char* format, ...);
|
||||||
|
int lwprintf_vsnprintf_ex(lwprintf_t* const lwobj, char* s, size_t n, const char* format, va_list arg);
|
||||||
|
int lwprintf_snprintf_ex(lwprintf_t* const lwobj, char* s, size_t n, const char* format, ...);
|
||||||
|
uint8_t lwprintf_protect_ex(lwprintf_t* const lwobj);
|
||||||
|
uint8_t lwprintf_unprotect_ex(lwprintf_t* const lwobj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer
|
||||||
|
* \param[in,out] lwobj: LwPRINTF instance. Set to `NULL` to use default instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_sprintf_ex(lwobj, s, format, ...) lwprintf_snprintf_ex((lwobj), (s), SIZE_MAX, (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Initialize default LwPRINTF instance
|
||||||
|
* \param[in] out_fn: Output function used for print operation
|
||||||
|
* \return `1` on success, `0` otherwise
|
||||||
|
* \sa lwprintf_init_ex
|
||||||
|
*/
|
||||||
|
#define lwprintf_init(out_fn) lwprintf_init_ex(NULL, (out_fn))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Print formatted data from variable argument list to the output with default LwPRINTF instance
|
||||||
|
* \param[in] format: C string that contains the text to be written to output
|
||||||
|
* \param[in] arg: A value identifying a variable arguments list initialized with `va_start`.
|
||||||
|
* `va_list` is a special type defined in `<cstdarg>`.
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_vprintf(format, arg) lwprintf_vprintf_ex(NULL, (format), (arg))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Print formatted data to the output with default LwPRINTF instance
|
||||||
|
* \param[in] format: C string that contains the text to be written to output
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_printf(format, ...) lwprintf_printf_ex(NULL, (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] n: Maximum number of bytes to be used in the buffer.
|
||||||
|
* The generated string has a length of at most `n - 1`,
|
||||||
|
* leaving space for the additional terminating null character
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] arg: A value identifying a variable arguments list initialized with `va_start`.
|
||||||
|
* `va_list` is a special type defined in `<cstdarg>`.
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_vsnprintf(s, n, format, arg) lwprintf_vsnprintf_ex(NULL, (s), (n), (format), (arg))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] n: Maximum number of bytes to be used in the buffer.
|
||||||
|
* The generated string has a length of at most `n - 1`,
|
||||||
|
* leaving space for the additional terminating null character
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written if `n` had been sufficiently large,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_snprintf(s, n, format, ...) lwprintf_snprintf_ex(NULL, (s), (n), (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
|
||||||
|
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
|
||||||
|
* The buffer should have a size of at least `n` characters
|
||||||
|
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
|
||||||
|
* \param[in] ...: Optional arguments for format string
|
||||||
|
* \return The number of characters that would have been written,
|
||||||
|
* not counting the terminating null character.
|
||||||
|
*/
|
||||||
|
#define lwprintf_sprintf(s, format, ...) lwprintf_sprintf_ex(NULL, (s), (format), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Manually enable mutual exclusion
|
||||||
|
* \return `1` if protected, `0` otherwise
|
||||||
|
*/
|
||||||
|
#define lwprintf_protect() lwprintf_protect_ex(NULL)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Manually disable mutual exclusion
|
||||||
|
* \return `1` if protected, `0` otherwise
|
||||||
|
*/
|
||||||
|
#define lwprintf_unprotect() lwprintf_unprotect_ex(NULL)
|
||||||
|
|
||||||
|
#if LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_printf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_printf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwprintf lwprintf_printf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwvprintf lwprintf_vprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vsnprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vsnprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwvsnprintf lwprintf_vsnprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_snprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_snprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwsnprintf lwprintf_snprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_sprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_sprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
|
||||||
|
*/
|
||||||
|
#define lwsprintf lwprintf_sprintf
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__ */
|
||||||
|
|
||||||
|
#if LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_printf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_printf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define printf lwprintf_printf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define vprintf lwprintf_vprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_vsnprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_vsnprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define vsnprintf lwprintf_vsnprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_snprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_snprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define snprintf lwprintf_snprintf
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \copydoc lwprintf_sprintf
|
||||||
|
* \note This function is equivalent to \ref lwprintf_sprintf
|
||||||
|
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
|
||||||
|
*/
|
||||||
|
#define sprintf lwprintf_sprintf
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__ */
|
||||||
|
|
||||||
|
/* Debug module */
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
/**
|
||||||
|
* \brief Debug output function
|
||||||
|
*
|
||||||
|
* Its purpose is to have a debug printout to the defined output,
|
||||||
|
* which will get disabled for the release build (when NDEBUG is defined).
|
||||||
|
*
|
||||||
|
* \note It calls \ref lwprintf_printf to execute the print
|
||||||
|
* \note Defined as empty when \ref NDEBUG is enabled
|
||||||
|
* \param[in] fmt: Format text
|
||||||
|
* \param[in] ...: Optional formatting parameters
|
||||||
|
*/
|
||||||
|
#define lwprintf_debug(fmt, ...) lwprintf_printf((fmt), ##__VA_ARGS__)
|
||||||
|
/**
|
||||||
|
* \brief Conditional debug output
|
||||||
|
*
|
||||||
|
* It prints the formatted text only if condition is true
|
||||||
|
*
|
||||||
|
* Its purpose is to have a debug printout to the defined output,
|
||||||
|
* which will get disabled for the release build (when NDEBUG is defined).
|
||||||
|
*
|
||||||
|
* \note It calls \ref lwprintf_debug to execute the print
|
||||||
|
* \note Defined as empty when \ref NDEBUG is enabled
|
||||||
|
* \param[in] cond: Condition to check before outputing the message
|
||||||
|
* \param[in] fmt: Format text
|
||||||
|
* \param[in] ...: Optional formatting parameters
|
||||||
|
*/
|
||||||
|
#define lwprintf_debug_cond(cond, fmt, ...) \
|
||||||
|
do { \
|
||||||
|
if ((cond)) { \
|
||||||
|
lwprintf_debug((fmt), ##__VA_ARGS__) \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define lwprintf_debug(fmt, ...) ((void)0)
|
||||||
|
#define lwprintf_debug_cond(cond, fmt, ...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_HDR_H */
|
||||||
191
3rd-part/lwprintf/lwprintf_opt.h
Normal file
191
3rd-part/lwprintf/lwprintf_opt.h
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
/**
|
||||||
|
* \file lwprintf_opt.h
|
||||||
|
* \brief LwPRINTF options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is part of LwPRINTF - Lightweight stdio manager library.
|
||||||
|
*
|
||||||
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
|
* Version: v1.0.5
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_OPT_HDR_H
|
||||||
|
#define LWPRINTF_OPT_HDR_H
|
||||||
|
|
||||||
|
/* Uncomment to ignore user options (or set macro in compiler flags) */
|
||||||
|
/* #define LWPRINTF_IGNORE_USER_OPTS */
|
||||||
|
|
||||||
|
/* Include application options */
|
||||||
|
#ifndef LWPRINTF_IGNORE_USER_OPTS
|
||||||
|
#include "lwprintf_opts.h"
|
||||||
|
#endif /* LWPRINTF_IGNORE_USER_OPTS */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup LWPRINTF_OPT Configuration
|
||||||
|
* \brief LwPRINTF options
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` operating system support in the library
|
||||||
|
*
|
||||||
|
* \note When `LWPRINTF_CFG_OS` is enabled, user must implement functions in \ref LWPRINTF_SYS group.
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_OS
|
||||||
|
#define LWPRINTF_CFG_OS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Mutex handle type
|
||||||
|
*
|
||||||
|
* \note This value must be set in case \ref LWPRINTF_CFG_OS is set to `1`.
|
||||||
|
* If data type is not known to compiler, include header file with
|
||||||
|
* definition before you define handle type
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_OS_MUTEX_HANDLE
|
||||||
|
#define LWPRINTF_CFG_OS_MUTEX_HANDLE void*
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` manual mutex lock.
|
||||||
|
*
|
||||||
|
* When this feature is enabled, together with \ref LWPRINTF_CFG_OS, behavior is as following:
|
||||||
|
* - System mutex is kept created during init phase
|
||||||
|
* - Calls to direct printing functions are not thread-safe by default anymore
|
||||||
|
* - Calls to sprintf (buffer functions) are kept thread-safe
|
||||||
|
* - User must manually call \ref lwprintf_protect or \ref lwprintf_protect_ex functions to protect direct printing operation
|
||||||
|
* - User must manually call \ref lwprintf_unprotect or \ref lwprintf_unprotect_ex functions to exit protected area
|
||||||
|
*
|
||||||
|
* \note If you prefer to completely disable locking mechanism with this library,
|
||||||
|
* turn off \ref LWPRINTF_CFG_OS and fully manually handle mutual exclusion for non-reentrant functions
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_OS_MANUAL_PROTECT
|
||||||
|
#define LWPRINTF_CFG_OS_MANUAL_PROTECT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `long long int` type, signed or unsigned.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_LONG_LONG
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_LONG_LONG 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for any specifier accepting any kind of integer types.
|
||||||
|
* This is enabling `%d, %b, %u, %o, %i, %x` specifiers
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_INT
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_INT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support `%p` pointer print type
|
||||||
|
*
|
||||||
|
* When enabled, architecture must support `uintptr_t` type, normally available with C11 standard
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_POINTER
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_POINTER 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support `%f` float type
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_FLOAT
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_FLOAT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `%e` engineering output type for float numbers
|
||||||
|
*
|
||||||
|
* \note \ref LWPRINTF_CFG_SUPPORT_TYPE_FLOAT has to be enabled to use this feature
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `%s` for string output
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_STRING
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_STRING 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` support for `%k` for hex byte array output
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY
|
||||||
|
#define LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Specifies default number of precision for floating number
|
||||||
|
*
|
||||||
|
* Represents number of digits to be used after comma if no precision
|
||||||
|
* is set with specifier itself
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION
|
||||||
|
#define LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` optional short names for LwPRINTF API functions.
|
||||||
|
*
|
||||||
|
* It adds functions for default instance: `lwprintf`, `lwsnprintf` and others
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_ENABLE_SHORTNAMES
|
||||||
|
#define LWPRINTF_CFG_ENABLE_SHORTNAMES 1
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables `1` or disables `0` C standard API names
|
||||||
|
*
|
||||||
|
* Disabled by default not to interfere with compiler implementation.
|
||||||
|
* Application may need to remove standard C STDIO library from linkage
|
||||||
|
* to be able to properly compile LwPRINTF with this option enabled
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_CFG_ENABLE_STD_NAMES
|
||||||
|
#define LWPRINTF_CFG_ENABLE_STD_NAMES 0
|
||||||
|
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_OPT_HDR_H */
|
||||||
44
3rd-part/lwprintf/lwprintf_opts.h
Normal file
44
3rd-part/lwprintf/lwprintf_opts.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* \file lwprintf_opts_template.h
|
||||||
|
* \brief LwPRINTF configuration file
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Tilen MAJERLE
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* This file is part of LwPRINTF - Lightweight stdio manager library.
|
||||||
|
*
|
||||||
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
|
* Version: v1.0.5
|
||||||
|
*/
|
||||||
|
#ifndef LWPRINTF_OPTS_HDR_H
|
||||||
|
#define LWPRINTF_OPTS_HDR_H
|
||||||
|
|
||||||
|
/* Rename this file to "lwprintf_opts.h" for your application */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open "include/lwprintf/lwprintf_opt.h" and
|
||||||
|
* copy & replace here settings you want to change values
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* LWPRINTF_OPTS_HDR_H */
|
||||||
@@ -25,7 +25,12 @@
|
|||||||
"editor.tabSize": 4,
|
"editor.tabSize": 4,
|
||||||
"editor.autoIndent": "advanced"
|
"editor.autoIndent": "advanced"
|
||||||
},
|
},
|
||||||
"EIDE.OpenOCD.ExePath": "D:/Program Files (x86)/at32_OpenOCD_V2.0.2/bin/openocd.exe"
|
"EIDE.OpenOCD.ExePath": "D:/Program Files (x86)/at32_OpenOCD_V2.0.2/bin/openocd.exe",
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"activityBar.background": "#4B2301",
|
||||||
|
"titleBar.activeBackground": "#693002",
|
||||||
|
"titleBar.activeForeground": "#FFF9F4"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"extensions": {
|
"extensions": {
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
|
|||||||
11
project/inc/by_debug.h
Normal file
11
project/inc/by_debug.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef _BY_DEBUG_H__
|
||||||
|
#define _BY_DEBUG_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "lwprintf.h"
|
||||||
|
|
||||||
|
#define BY_DEBUG_USART_INDEX (USART1)
|
||||||
|
|
||||||
|
void by_debug_init(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
23
project/src/by_debug.c
Normal file
23
project/src/by_debug.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "by_debug.h"
|
||||||
|
|
||||||
|
#include "at32f403a_407.h"
|
||||||
|
#include "lwprintf.h"
|
||||||
|
|
||||||
|
int lwprintf_out(int ch, lwprintf_t *lwp)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* May use printf to output it for test */
|
||||||
|
|
||||||
|
if (ch != '\0') {
|
||||||
|
while (usart_flag_get(BY_DEBUG_USART_INDEX, USART_TDC_FLAG) == RESET)
|
||||||
|
;
|
||||||
|
usart_data_transmit(BY_DEBUG_USART_INDEX, (char)ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_debug_init(void)
|
||||||
|
{
|
||||||
|
lwprintf_init(lwprintf_out);
|
||||||
|
}
|
||||||
@@ -26,10 +26,11 @@
|
|||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "at32f403a_407_wk_config.h"
|
#include "at32f403a_407_wk_config.h"
|
||||||
#include "dwt_delay.h"
|
|
||||||
/* private includes ----------------------------------------------------------*/
|
/* private includes ----------------------------------------------------------*/
|
||||||
/* add user code begin private includes */
|
/* add user code begin private includes */
|
||||||
|
#include "dwt_delay.h"
|
||||||
|
|
||||||
|
#include "by_debug.h"
|
||||||
/* add user code end private includes */
|
/* add user code end private includes */
|
||||||
|
|
||||||
/* private typedef -----------------------------------------------------------*/
|
/* private typedef -----------------------------------------------------------*/
|
||||||
@@ -126,13 +127,13 @@ int main(void)
|
|||||||
|
|
||||||
/* add user code begin 2 */
|
/* add user code begin 2 */
|
||||||
DWT_Init();
|
DWT_Init();
|
||||||
|
by_debug_init();
|
||||||
/* add user code end 2 */
|
/* add user code end 2 */
|
||||||
// i2c_start_generate(I2C1);
|
|
||||||
// i2c_7bit_address_send(I2C1, 0x68, I2C_DIRECTION_TRANSMIT);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* add user code begin 3 */
|
/* add user code begin 3 */
|
||||||
// usart_data_transmit(USART1, 0xEF);
|
// DWT_Delay(1000000);
|
||||||
/* add user code end 3 */
|
/* add user code end 3 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user