From 2a5282ee2f534e4250dc0a8c53bf3ca647d7bdf9 Mon Sep 17 00:00:00 2001 From: Banst Date: Fri, 18 Aug 2023 18:46:18 +0200 Subject: [PATCH] feat: bootsrap code [#2] --- .clang-tidy | 366 ++++++++++++++++++++++++++++++++++ .github/workflows/push.yml | 8 + .github/workflows/release.yml | 2 + .gitignore | 57 ++++++ Makefile | 16 +- core | 0 include/app.h | 113 ++++++----- include/app_defs.h | 77 ++++--- include/colors.h | 18 ++ include/layout.h | 27 +++ src/app.c | 184 +++-------------- src/layout.c | 14 ++ tools/simulator.c | 1 + 13 files changed, 637 insertions(+), 246 deletions(-) create mode 100644 .clang-tidy create mode 100644 core create mode 100644 include/colors.h create mode 100644 include/layout.h create mode 100644 src/layout.c diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..e87b744 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,366 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-altera-unroll-loops,-modernize-macro-to-enum' +WarningsAsErrors: '' +HeaderFilterRegex: '.*' +AnalyzeTemporaryDtors: false +FormatStyle: 'llvm' +User: banst +CheckOptions: + hicpp-move-const-arg.CheckMoveToConstRef: 'true' + readability-suspicious-call-argument.PrefixSimilarAbove: '30' + cppcoreguidelines-no-malloc.Reallocations: '::realloc' + portability-simd-intrinsics.Std: '' + cppcoreguidelines-owning-memory.LegacyResourceConsumers: '::free;::realloc;::freopen;::fclose' + modernize-use-auto.MinTypeNameLength: '5' + bugprone-reserved-identifier.Invert: 'false' + bugprone-narrowing-conversions.PedanticMode: 'false' + altera-struct-pack-align.MaxConfiguredAlignment: '128' + bugprone-unused-return-value.CheckedFunctions: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty;::std::back_inserter;::std::distance;::std::find;::std::find_if;::std::inserter;::std::lower_bound;::std::make_pair;::std::map::count;::std::map::find;::std::map::lower_bound;::std::multimap::equal_range;::std::multimap::upper_bound;::std::set::count;::std::set::find;::std::setfill;::std::setprecision;::std::setw;::std::upper_bound;::std::vector::at;::bsearch;::ferror;::feof;::isalnum;::isalpha;::isblank;::iscntrl;::isdigit;::isgraph;::islower;::isprint;::ispunct;::isspace;::isupper;::iswalnum;::iswprint;::iswspace;::isxdigit;::memchr;::memcmp;::strcmp;::strcoll;::strncmp;::strpbrk;::strrchr;::strspn;::strstr;::wcscmp;::access;::bind;::connect;::difftime;::dlsym;::fnmatch;::getaddrinfo;::getopt;::htonl;::htons;::iconv_open;::inet_addr;::isascii;::isatty;::mmap;::newlocale;::openat;::pathconf;::pthread_equal;::pthread_getspecific;::pthread_mutex_trylock;::readdir;::readlink;::recvmsg;::regexec;::scandir;::semget;::setjmp;::shm_open;::shmget;::sigismember;::strcasecmp;::strsignal;::ttyname' + readability-magic-numbers.IgnoredIntegerValues: '1;2;3;4;' + cert-dcl51-cpp.AggressiveDependentMemberLookup: 'false' + hicpp-use-auto.MinTypeNameLength: '5' + readability-inconsistent-declaration-parameter-name.Strict: 'false' + hicpp-use-override.IgnoreDestructors: 'false' + cppcoreguidelines-macro-usage.CheckCapsOnly: 'false' + readability-suspicious-call-argument.DiceDissimilarBelow: '60' + cert-dcl37-c.AllowedIdentifiers: '' + cert-dcl16-c.IgnoreMacros: 'true' + hicpp-use-emplace.SmartPointers: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr' + bugprone-assert-side-effect.IgnoredFunctions: __builtin_expect + hicpp-member-init.IgnoreArrays: 'false' + openmp-exception-escape.IgnoredExceptions: '' + readability-suspicious-call-argument.Equality: 'true' + hicpp-use-override.AllowOverrideAndFinal: 'false' + misc-uniqueptr-reset-release.IncludeStyle: llvm + abseil-string-find-str-contains.StringLikeClasses: '::std::basic_string;::std::basic_string_view;::absl::string_view' + readability-const-return-type.IgnoreMacros: 'true' + hicpp-signed-bitwise.IgnorePositiveIntegerLiterals: 'false' + bugprone-easily-swappable-parameters.QualifiersMix: 'false' + cert-err09-cpp.WarnOnLargeObjects: 'false' + bugprone-suspicious-string-compare.WarnOnImplicitComparison: 'true' + bugprone-argument-comment.CommentNullPtrs: '0' + android-comparison-in-temp-failure-retry.RetryMacros: TEMP_FAILURE_RETRY + cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion: 'true' + hicpp-use-equals-delete.IgnoreMacros: 'true' + cppcoreguidelines-init-variables.IncludeStyle: llvm + modernize-use-nodiscard.ReplacementString: '[[nodiscard]]' + modernize-loop-convert.MakeReverseRangeHeader: '' + readability-avoid-const-params-in-decls.IgnoreMacros: 'true' + readability-suspicious-call-argument.SuffixSimilarAbove: '30' + misc-definitions-in-headers.HeaderFileExtensions: ';h;hh;hpp;hxx' + hicpp-uppercase-literal-suffix.NewSuffixes: '' + modernize-use-emplace.ContainersWithPush: '::std::stack;::std::queue;::std::priority_queue' + cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'true' + bugprone-easily-swappable-parameters.IgnoredParameterNames: '"";iterator;Iterator;begin;Begin;end;End;first;First;last;Last;lhs;LHS;rhs;RHS' + modernize-loop-convert.UseCxx20ReverseRanges: 'true' + cppcoreguidelines-prefer-member-initializer.UseAssignment: 'false' + hicpp-function-size.VariableThreshold: '4294967295' + cert-oop57-cpp.MemSetNames: '' + hicpp-no-malloc.Deallocations: '::free' + performance-type-promotion-in-math-fn.IncludeStyle: llvm + google-readability-function-size.LineThreshold: '4294967295' + readability-function-cognitive-complexity.DescribeBasicIncrements: 'true' + bugprone-suspicious-include.ImplementationFileExtensions: 'c;cc;cpp;cxx' + hicpp-use-emplace.ContainersWithPushFront: '::std::forward_list;::std::list;::std::deque' + modernize-loop-convert.MakeReverseRangeFunction: '' + readability-inconsistent-declaration-parameter-name.IgnoreMacros: 'true' + bugprone-suspicious-missing-comma.SizeThreshold: '5' + readability-identifier-naming.IgnoreFailedSplit: 'false' + hicpp-multiway-paths-covered.WarnOnMissingElse: 'false' + readability-qualified-auto.AddConstToQualified: 'true' + bugprone-sizeof-expression.WarnOnSizeOfThis: 'true' + bugprone-string-constructor.WarnOnLargeLength: 'true' + cppcoreguidelines-explicit-virtual-functions.OverrideSpelling: override + hicpp-no-malloc.Allocations: '::malloc;::calloc' + hicpp-use-noexcept.UseNoexceptFalse: 'true' + abseil-string-find-startswith.IncludeStyle: llvm + google-global-names-in-headers.HeaderFileExtensions: ';h;hh;hpp;hxx' + readability-uppercase-literal-suffix.IgnoreMacros: 'true' + modernize-make-shared.IgnoreMacros: 'true' + modernize-use-emplace.ContainersWithPushFront: '::std::forward_list;::std::list;::std::deque' + misc-const-correctness.TransformValues: 'true' + cert-dcl59-cpp.HeaderFileExtensions: ';h;hh;hpp;hxx' + bugprone-suspicious-enum-usage.StrictMode: 'false' + performance-unnecessary-copy-initialization.AllowedTypes: '' + bugprone-suspicious-missing-comma.MaxConcatenatedTokens: '5' + modernize-use-transparent-functors.SafeMode: 'false' + readability-suspicious-call-argument.Levenshtein: 'true' + misc-throw-by-value-catch-by-reference.CheckThrowTemporaries: 'true' + bugprone-not-null-terminated-result.WantToUseSafeFunctions: 'true' + bugprone-string-constructor.LargeLengthThreshold: '8388608' + bugprone-dynamic-static-initializers.HeaderFileExtensions: ';h;hh;hpp;hxx' + readability-simplify-boolean-expr.ChainedConditionalAssignment: 'false' + cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues: 'false' + cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false' + cert-err09-cpp.CheckThrowTemporaries: 'true' + performance-inefficient-vector-operation.EnableProto: 'false' + bugprone-exception-escape.FunctionsThatShouldNotThrow: '' + modernize-loop-convert.MaxCopySize: '16' + readability-suspicious-call-argument.PrefixDissimilarBelow: '25' + readability-function-size.LineThreshold: '4294967295' + bugprone-easily-swappable-parameters.MinimumLength: '2' + portability-simd-intrinsics.Suggest: 'false' + hicpp-deprecated-headers.CheckHeaderFile: 'false' + modernize-use-override.IgnoreDestructors: 'false' + cppcoreguidelines-pro-bounds-constant-array-index.GslHeader: '' + modernize-make-shared.MakeSmartPtrFunctionHeader: '' + modernize-make-shared.MakeSmartPtrFunction: 'std::make_shared' + misc-non-private-member-variables-in-classes.IgnorePublicMemberVariables: 'false' + bugprone-sizeof-expression.WarnOnSizeOfConstant: 'true' + readability-redundant-string-init.StringNames: '::std::basic_string_view;::std::basic_string' + modernize-make-unique.IgnoreDefaultInitialization: 'true' + modernize-use-emplace.ContainersWithPushBack: '::std::vector;::std::list;::std::deque' + readability-magic-numbers.IgnoreBitFieldsWidths: 'true' + modernize-make-unique.IncludeStyle: llvm + modernize-use-override.OverrideSpelling: override + google-readability-function-size.NestingThreshold: '4294967295' + google-build-namespaces.HeaderFileExtensions: ';h;hh;hpp;hxx' + readability-suspicious-call-argument.LevenshteinDissimilarBelow: '50' + bugprone-argument-comment.CommentStringLiterals: '0' + concurrency-mt-unsafe.FunctionSet: any + readability-identifier-length.IgnoredExceptionVariableNames: '^[e]$' + google-readability-braces-around-statements.ShortStatementLines: '1' + bugprone-reserved-identifier.AllowedIdentifiers: '' + cppcoreguidelines-pro-type-member-init.IgnoreArrays: 'false' + readability-else-after-return.WarnOnUnfixable: 'true' + cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues: '1.0;100.0;' + modernize-use-emplace.IgnoreImplicitConstructors: 'false' + cppcoreguidelines-macro-usage.IgnoreCommandLineMacros: 'true' + readability-suspicious-call-argument.Substring: 'true' + modernize-use-equals-delete.IgnoreMacros: 'true' + objc-forbidden-subclassing.ForbiddenSuperClassNames: 'ABNewPersonViewController;ABPeoplePickerNavigationController;ABPersonViewController;ABUnknownPersonViewController;NSHashTable;NSMapTable;NSPointerArray;NSPointerFunctions;NSTimer;UIActionSheet;UIAlertView;UIImagePickerController;UITextInputMode;UIWebView' + readability-identifier-length.IgnoredVariableNames: '' + readability-magic-numbers.IgnoreAllFloatingPointValues: 'false' + cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle: llvm + hicpp-use-auto.RemoveStars: 'false' + readability-suspicious-call-argument.Abbreviations: 'arr=array;cnt=count;idx=index;src=source;stmt=statement;cpy=copy;dest=destination;dist=distancedst=distance;ptr=pointer;wdth=width;str=string;ln=line;srv=server;attr=attribute;ref=reference;buf=buffer;col=column;nr=number;vec=vector;len=length;elem=element;val=value;i=index;var=variable;hght=height;cl=client;num=number;pos=position;lst=list;addr=address' + bugprone-misplaced-widening-cast.CheckImplicitCasts: 'false' + readability-uppercase-literal-suffix.NewSuffixes: '' + modernize-loop-convert.MinConfidence: reasonable + performance-unnecessary-value-param.AllowedTypes: '' + readability-uniqueptr-delete-release.PreferResetCall: 'false' + readability-identifier-length.MinimumExceptionNameLength: '2' + misc-definitions-in-headers.UseHeaderFileExtension: 'true' + google-readability-namespace-comments.SpacesBeforeComments: '2' + cppcoreguidelines-avoid-magic-numbers.IgnoreBitFieldsWidths: 'true' + cert-err61-cpp.CheckThrowTemporaries: 'true' + cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues: '1;2;3;4;' + cppcoreguidelines-no-malloc.Allocations: '::malloc;::calloc' + cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues: 'false' + bugprone-narrowing-conversions.IgnoreConversionFromTypes: '' + readability-function-size.BranchThreshold: '4294967295' + bugprone-suspicious-missing-comma.RatioThreshold: '0.200000' + hicpp-function-size.LineThreshold: '4294967295' + readability-implicit-bool-conversion.AllowIntegerConditions: 'false' + readability-identifier-length.IgnoredParameterNames: '^[n]$' + readability-function-size.StatementThreshold: '800' + hicpp-use-noexcept.ReplacementString: '' + readability-identifier-naming.IgnoreMainLikeFunctions: 'false' + cppcoreguidelines-init-variables.MathHeader: '' + google-runtime-int.SignedTypePrefix: int + google-readability-function-size.StatementThreshold: '800' + cert-msc51-cpp.DisallowedSeedTypes: 'time_t,std::time_t' + hicpp-use-emplace.TupleMakeFunctions: '::std::make_pair;::std::make_tuple' + bugprone-reserved-identifier.AggressiveDependentMemberLookup: 'false' + readability-suspicious-call-argument.DiceSimilarAbove: '70' + modernize-use-equals-default.IgnoreMacros: 'true' + readability-suspicious-call-argument.Abbreviation: 'true' + cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: 'false' + cert-dcl37-c.AggressiveDependentMemberLookup: 'false' + readability-identifier-length.MinimumLoopCounterNameLength: '2' + abseil-string-find-str-contains.AbseilStringsMatchHeader: 'absl/strings/match.h' + bugprone-dangling-handle.HandleClasses: 'std::basic_string_view;std::experimental::basic_string_view' + cert-msc54-cpp.AsyncSafeFunctionSet: POSIX + modernize-use-emplace.SmartPointers: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr' + readability-magic-numbers.IgnorePowersOf2IntegerValues: 'false' + misc-const-correctness.TransformPointersAsValues: 'false' + readability-suspicious-call-argument.JaroWinklerSimilarAbove: '85' + misc-unused-parameters.StrictMode: 'false' + cppcoreguidelines-no-malloc.Deallocations: '::free' + readability-simplify-subscript-expr.Types: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array' + performance-unnecessary-copy-initialization.ExcludedContainerTypes: '' + modernize-replace-auto-ptr.IncludeStyle: llvm + performance-move-const-arg.CheckTriviallyCopyableMove: 'true' + misc-const-correctness.TransformReferences: 'true' + hicpp-move-const-arg.CheckTriviallyCopyableMove: 'true' + readability-function-size.VariableThreshold: '4294967295' + readability-static-accessed-through-instance.NameSpecifierNestingThreshold: '3' + cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU' + misc-const-correctness.AnalyzeValues: 'true' + readability-identifier-naming.GetConfigPerFile: 'true' + bugprone-narrowing-conversions.WarnOnFloatingPointNarrowingConversion: 'true' + cert-sig30-c.AsyncSafeFunctionSet: POSIX + hicpp-member-init.UseAssignment: 'false' + modernize-use-default-member-init.UseAssignment: 'false' + readability-simplify-boolean-expr.SimplifyDeMorgan: 'true' + readability-function-size.NestingThreshold: '4294967295' + google-readability-function-size.BranchThreshold: '4294967295' + bugprone-sizeof-expression.WarnOnSizeOfPointerToAggregate: 'true' + llvm-namespace-comment.ShortNamespaceLines: '1' + llvm-namespace-comment.SpacesBeforeComments: '1' + modernize-use-override.AllowOverrideAndFinal: 'false' + cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes: '' + readability-function-size.ParameterThreshold: '4294967295' + hicpp-function-size.NestingThreshold: '4294967295' + modernize-pass-by-value.ValuesOnly: 'false' + readability-function-cognitive-complexity.IgnoreMacros: 'false' + modernize-loop-convert.IncludeStyle: llvm + cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false' + bugprone-narrowing-conversions.WarnWithinTemplateInstantiation: 'false' + cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;' + bugprone-suspicious-string-compare.WarnOnLogicalNotComparison: 'false' + hicpp-braces-around-statements.ShortStatementLines: '0' + cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal: 'false' + google-readability-function-size.ParameterThreshold: '4294967295' + readability-redundant-smartptr-get.IgnoreMacros: 'true' + readability-identifier-naming.AggressiveDependentMemberLookup: 'false' + cert-err61-cpp.WarnOnLargeObjects: 'false' + misc-const-correctness.WarnPointersAsValues: 'false' + readability-identifier-length.MinimumParameterNameLength: '3' + modernize-use-emplace.TupleTypes: '::std::pair;::std::tuple' + hicpp-use-emplace.IgnoreImplicitConstructors: 'false' + modernize-use-emplace.TupleMakeFunctions: '::std::make_pair;::std::make_tuple' + bugprone-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion: 'true' + cppcoreguidelines-owning-memory.LegacyResourceProducers: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile' + bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 'true' + bugprone-argument-comment.StrictMode: '0' + hicpp-uppercase-literal-suffix.IgnoreMacros: 'true' + misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'false' + modernize-replace-random-shuffle.IncludeStyle: llvm + modernize-use-bool-literals.IgnoreMacros: 'true' + bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: '1' + bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField: 'true' + google-readability-namespace-comments.ShortNamespaceLines: '10' + readability-suspicious-call-argument.JaroWinklerDissimilarBelow: '75' + bugprone-suspicious-string-compare.StringCompareLikeFunctions: '' + modernize-avoid-bind.PermissiveParameterList: 'false' + readability-suspicious-call-argument.Suffix: 'true' + modernize-use-override.FinalSpelling: final + hicpp-use-equals-default.IgnoreMacros: 'true' + modernize-use-noexcept.ReplacementString: '' + hicpp-use-override.OverrideSpelling: override + modernize-use-using.IgnoreMacros: 'true' + hicpp-use-override.FinalSpelling: final + cppcoreguidelines-explicit-virtual-functions.FinalSpelling: final + readability-suspicious-call-argument.MinimumIdentifierNameLength: '3' + bugprone-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'true' + modernize-loop-convert.NamingStyle: CamelCase + cppcoreguidelines-pro-type-member-init.UseAssignment: 'false' + bugprone-suspicious-include.HeaderFileExtensions: ';h;hh;hpp;hxx' + hicpp-function-size.StatementThreshold: '800' + readability-suspicious-call-argument.SubstringDissimilarBelow: '40' + hicpp-no-malloc.Reallocations: '::realloc' + bugprone-stringview-nullptr.IncludeStyle: llvm + performance-for-range-copy.WarnOnAllAutoCopies: 'false' + google-runtime-int.UnsignedTypePrefix: uint + performance-no-automatic-move.AllowedTypes: '' + modernize-pass-by-value.IncludeStyle: llvm + bugprone-argument-comment.CommentIntegerLiterals: '0' + bugprone-argument-comment.CommentFloatLiterals: '0' + bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit: '16' + abseil-string-find-startswith.AbseilStringsMatchHeader: 'absl/strings/match.h' + readability-simplify-boolean-expr.ChainedConditionalReturn: 'false' + readability-else-after-return.WarnOnConditionVariables: 'true' + modernize-use-nullptr.NullMacros: 'NULL' + readability-suspicious-call-argument.SuffixDissimilarBelow: '25' + bugprone-argument-comment.CommentCharacterLiterals: '0' + cppcoreguidelines-macro-usage.AllowedRegexp: '^DEBUG_*' + llvm-header-guard.HeaderFileExtensions: ';h;hh;hpp;hxx' + readability-suspicious-call-argument.LevenshteinSimilarAbove: '66' + cppcoreguidelines-narrowing-conversions.PedanticMode: 'false' + modernize-make-shared.IgnoreDefaultInitialization: 'true' + readability-suspicious-call-argument.JaroWinkler: 'true' + bugprone-implicit-widening-of-multiplication-result.UseCXXHeadersInCppSources: 'true' + modernize-make-shared.IncludeStyle: llvm + readability-suspicious-call-argument.Prefix: 'true' + hicpp-special-member-functions.AllowMissingMoveFunctions: 'false' + cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions: 'false' + bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources: 'true' + bugprone-signed-char-misuse.CharTypdefsToIgnore: '' + cert-dcl51-cpp.Invert: 'false' + hicpp-special-member-functions.AllowSoleDefaultDtor: 'false' + modernize-deprecated-headers.CheckHeaderFile: 'false' + hicpp-use-emplace.EmplacyFunctions: 'vector::emplace_back;vector::emplace;deque::emplace;deque::emplace_front;deque::emplace_back;forward_list::emplace_after;forward_list::emplace_front;list::emplace;list::emplace_back;list::emplace_front;set::emplace;set::emplace_hint;map::emplace;map::emplace_hint;multiset::emplace;multiset::emplace_hint;multimap::emplace;multimap::emplace_hint;unordered_set::emplace;unordered_set::emplace_hint;unordered_map::emplace;unordered_map::emplace_hint;unordered_multiset::emplace;unordered_multiset::emplace_hint;unordered_multimap::emplace;unordered_multimap::emplace_hint;stack::emplace;queue::emplace;priority_queue::emplace' + cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors: 'false' + modernize-make-unique.IgnoreMacros: 'true' + performance-for-range-copy.AllowedTypes: '' + hicpp-function-size.BranchThreshold: '4294967295' + misc-const-correctness.AnalyzeReferences: 'true' + bugprone-unchecked-optional-access.IgnoreSmartPointerDereference: 'false' + bugprone-argument-comment.CommentBoolLiterals: '0' + readability-braces-around-statements.ShortStatementLines: '0' + bugprone-argument-comment.CommentUserDefinedLiterals: '0' + hicpp-use-emplace.ContainersWithPushBack: '::std::vector;::std::list;::std::deque' + abseil-string-find-startswith.StringLikeClasses: '::std::basic_string' + hicpp-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: 'false' + performance-inefficient-string-concatenation.StrictMode: 'false' + readability-redundant-declaration.IgnoreMacros: 'true' + readability-magic-numbers.IgnoredFloatingPointValues: '1.0;100.0;' + bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: 'bool;Bool;_Bool;it;It;iterator;Iterator;inputit;InputIt;forwardit;ForwardIt;bidirit;BidirIt;constiterator;const_iterator;Const_Iterator;Constiterator;ConstIterator;RandomIt;randomit;random_iterator;ReverseIt;reverse_iterator;reverse_const_iterator;ConstReverseIterator;Const_Reverse_Iterator;const_reverse_iterator;Constreverseiterator;constreverseiterator' + modernize-make-unique.MakeSmartPtrFunction: 'std::make_unique' + google-runtime-int.TypeSuffix: '' + hicpp-function-size.ParameterThreshold: '4294967295' + cert-dcl51-cpp.AllowedIdentifiers: '' + abseil-cleanup-ctad.IncludeStyle: llvm + cert-oop57-cpp.MemCpyNames: '' + modernize-make-unique.MakeSmartPtrFunctionHeader: '' + bugprone-signal-handler.AsyncSafeFunctionSet: POSIX + bugprone-easily-swappable-parameters.ModelImplicitConversions: 'true' + readability-suspicious-call-argument.SubstringSimilarAbove: '50' + cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation: 'false' + portability-restrict-system-includes.Includes: '*' + performance-move-const-arg.CheckMoveToConstRef: 'true' + readability-identifier-length.MinimumVariableNameLength: '3' + modernize-use-emplace.EmplacyFunctions: 'vector::emplace_back;vector::emplace;deque::emplace;deque::emplace_front;deque::emplace_back;forward_list::emplace_after;forward_list::emplace_front;list::emplace;list::emplace_back;list::emplace_front;set::emplace;set::emplace_hint;map::emplace;map::emplace_hint;multiset::emplace;multiset::emplace_hint;multimap::emplace;multimap::emplace_hint;unordered_set::emplace;unordered_set::emplace_hint;unordered_map::emplace;unordered_map::emplace_hint;unordered_multiset::emplace;unordered_multiset::emplace_hint;unordered_multimap::emplace;unordered_multimap::emplace_hint;stack::emplace;queue::emplace;priority_queue::emplace' + zircon-temporary-objects.Names: '' + cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth: 'true' + hicpp-use-emplace.TupleTypes: '::std::pair;::std::tuple' + cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables: 'false' + fuchsia-header-anon-namespaces.HeaderFileExtensions: ';h;hh;hpp;hxx' + cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: 'false' + cert-oop57-cpp.MemCmpNames: '' + modernize-use-noexcept.UseNoexceptFalse: 'true' + readability-function-cognitive-complexity.Threshold: '25' + cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true' + readability-simplify-boolean-expr.SimplifyDeMorganRelaxed: 'false' + bugprone-narrowing-conversions.WarnOnEquivalentBitWidth: 'true' + bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression: 'false' + performance-faster-string-find.StringLikeClasses: '::std::basic_string;::std::basic_string_view' + cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion: 'true' + google-readability-function-size.VariableThreshold: '4294967295' + bugprone-assert-side-effect.CheckFunctionCalls: 'false' + bugprone-string-constructor.StringNames: '::std::basic_string;::std::basic_string_view' + bugprone-assert-side-effect.AssertMacros: assert,NSAssert,NSCAssert + bugprone-exception-escape.IgnoredExceptions: '' + bugprone-signed-char-misuse.DiagnoseSignedUnsignedCharComparisons: 'true' + altera-unroll-loops.MaxLoopIterations: '100' + llvm-qualified-auto.AddConstToQualified: 'false' + hicpp-use-emplace.ContainersWithPush: '::std::stack;::std::queue;::std::priority_queue' + modernize-use-default-member-init.IgnoreMacros: 'true' + cert-str34-c.CharTypdefsToIgnore: '' + misc-use-anonymous-namespace.HeaderFileExtensions: ';h;hh;hpp;hxx' + llvm-else-after-return.WarnOnConditionVariables: 'false' + bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant: 'true' + bugprone-argument-comment.IgnoreSingleArgument: '0' + modernize-raw-string-literal.DelimiterStem: lit + readability-suspicious-call-argument.Dice: 'true' + misc-throw-by-value-catch-by-reference.WarnOnLargeObjects: 'false' + readability-identifier-length.IgnoredLoopCounterNames: '^[ijk_]$' + cert-dcl37-c.Invert: 'false' + altera-single-work-item-barrier.AOCVersion: '1600' + cppcoreguidelines-avoid-do-while.IgnoreMacros: 'false' + modernize-raw-string-literal.ReplaceShorterLiterals: 'false' + readability-implicit-bool-conversion.AllowPointerConditions: 'false' + performance-inefficient-vector-operation.VectorLikeClasses: '::std::vector' + modernize-use-auto.RemoveStars: 'false' + abseil-string-find-str-contains.IncludeStyle: llvm + bugprone-implicit-widening-of-multiplication-result.IncludeStyle: llvm + llvmlibc-restrict-system-libc-headers.Includes: '-*' + hicpp-use-nullptr.NullMacros: '' + readability-redundant-member-init.IgnoreBaseInCopyConstructors: 'false' + modernize-replace-disallow-copy-and-assign-macro.MacroName: DISALLOW_COPY_AND_ASSIGN + performance-unnecessary-value-param.IncludeStyle: llvm + llvm-else-after-return.WarnOnUnfixable: 'false' + cert-msc32-c.DisallowedSeedTypes: 'time_t,std::time_t' +... + diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7eed618..a68fde2 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -2,6 +2,8 @@ name: Build and Test on: push: + branches: + - '**' tags-ignore: - v** @@ -10,8 +12,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + submodules: true - uses: carlosperate/arm-none-eabi-gcc-action@v1 - name: build run: make - name: test run: test -f build/polyboard.syx + - name: lint + run: make lint + - name: tidy + run: make tidy diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb4bfd3..ecf93fd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + submodules: true - uses: carlosperate/arm-none-eabi-gcc-action@v1 - name: build run: make diff --git a/.gitignore b/.gitignore index 3a8f6da..56a9508 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,60 @@ tools/osx/simulator.xcodeproj/xcuserdata/davehodder.xcuserdatad/xcschemes/xcsche *.xcbkptlist tools/osx/simulator.xcodeproj/xcuserdata +# Created by https://www.toptal.com/developers/gitignore/api/vim,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=vim,macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +# End of https://www.toptal.com/developers/gitignore/api/vim,macos diff --git a/Makefile b/Makefile index c205bf8..5ed7711 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ BUILDDIR = build TOOLS = tools -SOURCES += src/app.c +SOURCES := $(wildcard src/*.c) +HEADERS := $(wildcard include/*.h) INCLUDES += -Iinclude -I @@ -23,6 +24,7 @@ HOST_GCC = gcc CC = arm-none-eabi-gcc LD = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy +CODE_STYLE = llvm CFLAGS = -Os -Wall -I.\ -D_STM32F103RBT6_ -D_STM3x_ -D_STM32x_ -mthumb -mcpu=cortex-m3 \ @@ -63,5 +65,17 @@ $(BUILDDIR)/%.o: %.c mkdir -p $(dir $@) $(CC) -c $(CFLAGS) -MMD -o $@ $< +fmt: $(SOURCES) $(HEADERS) + clang-format --style=$(CODE_STYLE) -i $^ +.PHONY: fmt + +tidy: $(SOURCES) $(HEADERS) + clang-tidy $^ -- -Iinclude +.PHONY: tidy + +lint: $(SOURCES) $(HEADERS) + clang-format --style=$(CODE_STYLE) -Werror --dry-run $^ +.PHONY: lint + clean: rm -rf $(BUILDDIR) diff --git a/core b/core new file mode 100644 index 0000000..e69de29 diff --git a/include/app.h b/include/app.h index 6752b62..c4a8fec 100644 --- a/include/app.h +++ b/include/app.h @@ -1,25 +1,25 @@ -#ifndef LAUNCHPAD_APP_H -#define LAUNCHPAD_APP_H +#ifndef APP_H +#define APP_H /****************************************************************************** - + Copyright (c) 2015, Focusrite Audio Engineering Ltd. All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + * Neither the name of Focusrite Audio Engineering Ltd., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -30,9 +30,11 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + *****************************************************************************/ +// NOLINTBEGIN + // ____________________________________________________________________________ // // Don't modify this file! This declares the binary interface to the library, @@ -44,13 +46,13 @@ /****************************************************************************** Button indexing is as follows - numbers in brackets do not correspond to real buttons, but can be harmessly sent in hal_set_led. - + (90)91 92 93 94 95 96 97 98 (99) ....... 20 21 22 23 24 25 26 27 28 29 10 11 12 13 14 15 16 17 18 19 (0) 1 2 3 4 5 6 7 8 (9) - + *****************************************************************************/ // ____________________________________________________________________________ @@ -62,8 +64,10 @@ * Set an LED's RGB value. This function is safe to call from any * of the app functions below, at any time. * - * @param type - TYPEPAD to address any pad or button, TYPESETUP to address the Setup button - * @param index - The index of the button. The buttons are indexed from the bottom left as detailed above. + * @param type - TYPEPAD to address any pad or button, TYPESETUP to address the + * Setup button + * @param index - The index of the button. The buttons are indexed from the + * bottom left as detailed above. * @param red - red colour value, in [0, MAXLED] * @param green - green colour value, in [0, MAXLED] * @param blue - blue colour value, in [0, MAXLED] @@ -72,10 +76,11 @@ void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue); /** * Read the RGB value of an LED. This function is safe to call from any - * of the app functions below, at any time. Result is undefined if an invalid address is passed - * for any of the red, green or blue components. + * of the app functions below, at any time. Result is undefined if an invalid + * address is passed for any of the red, green or blue components. * - * @param type - TYPEPAD to address any pad or button, TYPESETUP to address the Setup LED + * @param type - TYPEPAD to address any pad or button, TYPESETUP to address the + * Setup LED * @param index - The index of the button, as above * @param red - address to read red colour value, in [0, MAXLED]. * @param green - address to read green colour value, in [0, MAXLED] @@ -85,13 +90,15 @@ void hal_read_led(u8 type, u8 index, u8 *red, u8 *green, u8 *blue); /** * Send a MIDI message to either USB port or to the DIN output. - * - * @param port - which port to send the message to - can be USBSTANDALONE, USBMIDI or DINMIDI. + * + * @param port - which port to send the message to - can be USBSTANDALONE, + * USBMIDI or DINMIDI. * @param status - MIDI status byte * @param data1 - first MIDI data byte * @param data2 - second MIDI data byte * - * There is little error checking in this code - if you send invalid MIDI, the results are undefined! + * There is little error checking in this code - if you send invalid MIDI, the + * results are undefined! */ void hal_send_midi(u8 port, u8 status, u8 data1, u8 data2); @@ -99,11 +106,12 @@ void hal_send_midi(u8 port, u8 status, u8 data1, u8 data2); * Send system exclusive to USB or DIN. Messages must be correctly formatted * (F0 ... F7) and must not exceed 320 bytes. * - * @param port - which port to send the message to - can be USBSTANDALONE, USBMIDI or DINMIDI. + * @param port - which port to send the message to - can be USBSTANDALONE, + * USBMIDI or DINMIDI. * @param data - pointer to array containing sysex data. Can be on the stack. * @param length - must not exceed 320 bytes, behaviour undefined if it does. */ -void hal_send_sysex(u8 port, const u8* data, u16 length); +void hal_send_sysex(u8 port, const u8 *data, u16 length); /** * Read some data from flash. @@ -137,7 +145,7 @@ void hal_read_flash(u32 offset, u8 *data, u32 length); * * Attempts to write beyond the end of the block will fail silently */ -void hal_write_flash(u32 offset,const u8 *data, u32 length); +void hal_write_flash(u32 offset, const u8 *data, u32 length); /** * Retrieve the device ID bootloader option @@ -152,8 +160,9 @@ u8 hal_read_device_id(); /** * Retrieve the "layout text" bootloader option * - * This setting determines whether the factory firmware will scroll text on changing - * layouts. This may be useful as a preference for open firmware apps as well. + * This setting determines whether the factory firmware will scroll text on + * changing layouts. This may be useful as a preference for open firmware apps + * as well. * * @result 1 to scroll text on layout changes, 0 not to. */ @@ -167,10 +176,10 @@ u8 hal_read_layout_text(); /** * Called on startup, this is a good place to do any initialisation. * - * @param adc_buffer - this is a pointer to the raw ADC frame buffer. The - * data is 12 bit unsigned. Note the indexing is strange - - * translate ADC indices to LED/button indices using the - * ADC_MAP table declared in app_defs.h. + * @param adc_buffer - this is a pointer to the raw ADC frame buffer. + * The data is 12 bit unsigned. Note the indexing + *is strange - translate ADC indices to LED/button indices using the ADC_MAP + *table declared in app_defs.h. */ void app_init(const u16 *adc_buffer); @@ -185,7 +194,8 @@ void app_timer_event(); /** * Called when a MIDI message is received from USB or DIN. * - * @param port - the port the message was received from - USBSTANDALONE, USBMIDI or DINMIDI. + * @param port - the port the message was received from - USBSTANDALONE, USBMIDI + * or DINMIDI. * @param status - MIDI status byte * @param data1 - first MIDI data byte * @param data2 - second MIDI data byte @@ -193,44 +203,53 @@ void app_timer_event(); void app_midi_event(u8 port, u8 status, u8 d1, u8 d2); /** - * As above, but for system exclusive messages. Low level hardware buffering sets - * a maximum message size of 320 bytes, messages larger than this will not work. - * - * @param port - the port the message was received from - USBSTANDALONE, USBMIDI or DINMIDI. - * @param data - pointer to array containing sysex data. Only valid in the scope of this callback. + * As above, but for system exclusive messages. Low level hardware buffering + * sets a maximum message size of 320 bytes, messages larger than this will not + * work. + * + * @param port - the port the message was received from - USBSTANDALONE, USBMIDI + * or DINMIDI. + * @param data - pointer to array containing sysex data. Only valid in the + * scope of this callback. * @param length - the amount of data received. */ -void app_sysex_event(u8 port, u8 * data, u16 count); +void app_sysex_event(u8 port, u8 *data, u16 count); /** - * Called when a MIDI DIN breakout cable is connected or disconnected. Note that - * you can still write MIDI events to the DIN ports even if no cable is connected. + * Called when a MIDI DIN breakout cable is connected or disconnected. Note + * that you can still write MIDI events to the DIN ports even if no cable is + * connected. * - * @param type - which cable was connected/disconnected - MIDI_IN_CABLE or MIDI_OUT_CABLE. + * @param type - which cable was connected/disconnected - MIDI_IN_CABLE or + * MIDI_OUT_CABLE. * @param value - 0 = disconnected, nonzero = connected. */ void app_cable_event(u8 type, u8 value); /** - * Called when the user presses or releases any button or pad on the control surface. + * Called when the user presses or releases any button or pad on the control + * surface. * - * @param type - TYPEPAD for normal pads or buttons, TYPESETUP for the Setup button - * @param index - The index of the button, as detailed at the start of this file. + * @param type - TYPEPAD for normal pads or buttons, TYPESETUP for the Setup + * button + * @param index - The index of the button, as detailed at the start of this + * file. * @param value - 0 for release, nonzero for press. */ void app_surface_event(u8 type, u8 index, u8 value); /** - * Called when the low level pad scanning reports an aftertouch (pad pressure) event. - * A pad press event will always come first. Note that the factory firmware sets a - * threshold to prevent excessive aftertouch after the initial hit, at the expense of - * dynamic range. This firmware does not - the full range of the pad is transmitted, - * with the side effect that aftertouch onset is more rapid. + * Called when the low level pad scanning reports an aftertouch (pad pressure) + * event. A pad press event will always come first. Note that the factory + * firmware sets a threshold to prevent excessive aftertouch after the initial + * hit, at the expense of dynamic range. This firmware does not - the full + * range of the pad is transmitted, with the side effect that aftertouch onset + * is more rapid. * * @param index - The index of the pad, as detailed at the start of this file. * @param value - the aftertouch value in [0, 127] */ void app_aftertouch_event(u8 index, u8 value); - +// NOLINTEND #endif diff --git a/include/app_defs.h b/include/app_defs.h index d9b4311..d261c2c 100644 --- a/include/app_defs.h +++ b/include/app_defs.h @@ -1,26 +1,26 @@ -#ifndef APP_TYPES_H -#define APP_TYPES_H +#ifndef APP_DEFS_H +#define APP_DEFS_H /****************************************************************************** - + Copyright (c) 2015, Focusrite Audio Engineering Ltd. All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + * Neither the name of Focusrite Audio Engineering Ltd., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -31,7 +31,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + *****************************************************************************/ // ____________________________________________________________________________ @@ -43,39 +43,39 @@ // Types // ____________________________________________________________________________ -typedef signed long s32; +typedef signed long s32; typedef signed short s16; -typedef signed char s8; +typedef signed char s8; -typedef unsigned long u32; +typedef unsigned long u32; typedef unsigned short u16; -typedef unsigned char u8; +typedef unsigned char u8; // ____________________________________________________________________________ // // App structure // ____________________________________________________________________________ -#define TYPEPAD 0 -#define TYPESETUP 1 +#define TYPEPAD 0 +#define TYPESETUP 1 -#define MAXLED 63 +#define MAXLED 63 // ____________________________________________________________________________ // // Useful MIDI constants // ____________________________________________________________________________ -#define NOTEON 0x90 -#define NOTEOFF 0x80 -#define POLYAFTERTOUCH 0xA0 -#define CC 0xB0 -#define CHANNELAFTERTOUCH 0xD0 -#define SONGPOSITIONPOINTER 0xF2 -#define MIDITIMINGCLOCK 0xF8 -#define MIDISTART 0xFA -#define MIDICONTINUE 0xFB -#define MIDISTOP 0xFC +#define NOTEON 0x90 +#define NOTEOFF 0x80 +#define POLYAFTERTOUCH 0xA0 +#define CC 0xB0 +#define CHANNELAFTERTOUCH 0xD0 +#define SONGPOSITIONPOINTER 0xF2 +#define MIDITIMINGCLOCK 0xF8 +#define MIDISTART 0xFA +#define MIDICONTINUE 0xFB +#define MIDISTOP 0xFC // ____________________________________________________________________________ // @@ -83,21 +83,21 @@ typedef unsigned char u8; // ____________________________________________________________________________ // USB MIDI: "Standalone" port -#define USBSTANDALONE 0 +#define USBSTANDALONE 0 // USB MIDI: "MIDI" port -#define USBMIDI 1 +#define USBMIDI 1 // MIDI DIN port -#define DINMIDI 2 +#define DINMIDI 2 // ____________________________________________________________________________ // // MIDI Jack Socket Switch IDs // ____________________________________________________________________________ -#define MIDI_IN_CABLE 0 -#define MIDI_OUT_CABLE 1 +#define MIDI_IN_CABLE 0 +#define MIDI_OUT_CABLE 1 // ____________________________________________________________________________ // @@ -115,16 +115,11 @@ typedef unsigned char u8; #define PAD_COUNT 64 -static const u8 ADC_MAP[PAD_COUNT] = -{ - 11, 51, 12, 52, 13, 53, 14, 54, - 15, 55, 16, 56, 17 ,57, 18, 58, - 21, 61, 22, 62, 23, 63, 24, 64, - 25, 65, 26, 66, 27, 67, 28, 68, - 31, 71, 32, 72, 33, 73, 34, 74, - 35, 75, 36, 76, 37, 77, 38, 78, - 41, 81, 42, 82, 43, 83, 44, 84, - 45, 85, 46, 86, 47, 87, 48, 88, +static const u8 ADC_MAP[PAD_COUNT] = { + 11, 51, 12, 52, 13, 53, 14, 54, 15, 55, 16, 56, 17, 57, 18, 58, + 21, 61, 22, 62, 23, 63, 24, 64, 25, 65, 26, 66, 27, 67, 28, 68, + 31, 71, 32, 72, 33, 73, 34, 74, 35, 75, 36, 76, 37, 77, 38, 78, + 41, 81, 42, 82, 43, 83, 44, 84, 45, 85, 46, 86, 47, 87, 48, 88, }; // ____________________________________________________________________________ diff --git a/include/colors.h b/include/colors.h new file mode 100644 index 0000000..9356859 --- /dev/null +++ b/include/colors.h @@ -0,0 +1,18 @@ +#ifndef COLORS_H +#define COLORS_H + +// Predefined colors +#define COLOR_BLACK 0x000000U +#define COLOR_WHITE 0xFFFFFFU +#define COLOR_RED 0xFF0000U +#define COLOR_GREEN 0x00FF00U +#define COLOR_BLUE 0x0000FFU +#define COLOR_MAGENTA 0xFF00FFU +#define COLOR_TEAL 0x00E6FFU + +// Shifts to extract color components +#define COLOR_RED_SHIFT 16U +#define COLOR_GREEN_SHIFT 8U +#define COLOR_BLUE_SHIFT 0U + +#endif // COLORS_H diff --git a/include/layout.h b/include/layout.h new file mode 100644 index 0000000..56c4d0d --- /dev/null +++ b/include/layout.h @@ -0,0 +1,27 @@ +#ifndef LAYOUT_H +#define LAYOUT_H + +#include "app.h" +#include "app_defs.h" +#include "colors.h" + +#define GRID_SIZE 100 + +static const u32 GRID_LOGO[GRID_SIZE] = { + [25] = COLOR_MAGENTA, [26] = COLOR_MAGENTA, [35] = COLOR_MAGENTA, + [37] = COLOR_MAGENTA, [46] = COLOR_MAGENTA, [47] = COLOR_MAGENTA, + [57] = COLOR_MAGENTA, + + [42] = COLOR_TEAL, [52] = COLOR_TEAL, [53] = COLOR_TEAL, + [62] = COLOR_TEAL, [64] = COLOR_TEAL, [73] = COLOR_TEAL, + [74] = COLOR_TEAL, +}; + +/** + * Renders the full grid + * + * @param layout The layout to render. + */ +void render_grid(const u32 layout[GRID_SIZE]); + +#endif // LAYOUT_H diff --git a/src/app.c b/src/app.c index 4ce908e..6ee85f2 100644 --- a/src/app.c +++ b/src/app.c @@ -1,22 +1,22 @@ /****************************************************************************** - + Copyright (c) 2015, Focusrite Audio Engineering Ltd. All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + * Neither the name of Focusrite Audio Engineering Ltd., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -27,7 +27,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + *****************************************************************************/ //______________________________________________________________________________ @@ -36,173 +36,43 @@ //______________________________________________________________________________ #include "app.h" +#include "layout.h" -//______________________________________________________________________________ -// -// This is where the fun is! Add your code to the callbacks below to define how -// your app behaves. -// -// In this example, we either render the raw ADC data as LED rainbows or store -// and recall the pad state from flash. -//______________________________________________________________________________ - -// store ADC frame pointer -static const u16 *g_ADC = 0; - -// buffer to store pad states for flash save -#define BUTTON_COUNT 100 - -u8 g_Buttons[BUTTON_COUNT] = {0}; +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) +void app_surface_event(u8 type, u8 index, u8 value) {} //______________________________________________________________________________ -void app_surface_event(u8 type, u8 index, u8 value) -{ - switch (type) - { - case TYPEPAD: - { - // toggle it and store it off, so we can save to flash if we want to - if (value) - { - g_Buttons[index] = MAXLED * !g_Buttons[index]; - } - - // example - light / extinguish pad LEDs - hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]); - - // example - send MIDI - hal_send_midi(DINMIDI, NOTEON | 0, index, value); - - } - break; - - case TYPESETUP: - { - if (value) - { - // save button states to flash (reload them by power cycling the hardware!) - hal_write_flash(0, g_Buttons, BUTTON_COUNT); - } - } - break; - } -} +// NOLINTNEXTLINE +void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) {} //______________________________________________________________________________ -void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) -{ - // example - MIDI interface functionality for USB "MIDI" port -> DIN port - if (port == USBMIDI) - { - hal_send_midi(DINMIDI, status, d1, d2); - } - - // // example -MIDI interface functionality for DIN -> USB "MIDI" port port - if (port == DINMIDI) - { - hal_send_midi(USBMIDI, status, d1, d2); - } -} +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) +void app_sysex_event(u8 port, u8 *data, u16 count) {} //______________________________________________________________________________ -void app_sysex_event(u8 port, u8 * data, u16 count) -{ - // example - respond to UDI messages? -} +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) +void app_aftertouch_event(u8 index, u8 value) {} //______________________________________________________________________________ -void app_aftertouch_event(u8 index, u8 value) -{ - // example - send poly aftertouch to MIDI ports - hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); - - +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) +void app_cable_event(u8 type, u8 value) { + // example - light the Setup LED to indicate cable connections + if (type == MIDI_IN_CABLE) { + hal_plot_led(TYPESETUP, 0, 0, value, 0); // green + } else if (type == MIDI_OUT_CABLE) { + hal_plot_led(TYPESETUP, 0, value, 0, 0); // red + } } //______________________________________________________________________________ -void app_cable_event(u8 type, u8 value) -{ - // example - light the Setup LED to indicate cable connections - if (type == MIDI_IN_CABLE) - { - hal_plot_led(TYPESETUP, 0, 0, value, 0); // green - } - else if (type == MIDI_OUT_CABLE) - { - hal_plot_led(TYPESETUP, 0, value, 0, 0); // red - } -} +void app_timer_event() {} //______________________________________________________________________________ -void app_timer_event() -{ - // example - send MIDI clock at 125bpm -#define TICK_MS 20 - - static u8 ms = TICK_MS; - - if (++ms >= TICK_MS) - { - ms = 0; - - // send a clock pulse up the USB - hal_send_midi(USBSTANDALONE, MIDITIMINGCLOCK, 0, 0); - } - - // alternative example - show raw ADC data as LEDs - for (int i=0; i < PAD_COUNT; ++i) - { - // raw adc values are 12 bit, but LEDs are 6 bit. - // Let's saturate into r;g;b for a rainbow effect to show pressure - u16 r = 0; - u16 g = 0; - u16 b = 0; - - u16 x = (3 * MAXLED * g_ADC[i]) >> 12; - - if (x < MAXLED) - { - r = x; - } - else if (x >= MAXLED && x < (2*MAXLED)) - { - r = 2*MAXLED - x; - g = x - MAXLED; - } - else - { - g = 3*MAXLED - x; - b = x - 2*MAXLED; - } - - hal_plot_led(TYPEPAD, ADC_MAP[i], r, g, b); - } -} - -//______________________________________________________________________________ - -void app_init(const u16 *adc_raw) -{ - // example - load button states from flash - hal_read_flash(0, g_Buttons, BUTTON_COUNT); - - // example - light the LEDs to say hello! - for (int i=0; i < 10; ++i) - { - for (int j=0; j < 10; ++j) - { - u8 b = g_Buttons[j*10 + i]; - - hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b); - } - } - - // store off the raw ADC frame pointer for later use - g_ADC = adc_raw; -} +// NOLINTNEXTLINE(misc-unused-parameters) +void app_init(const u16 *adc_raw) { render_grid(GRID_LOGO); } diff --git a/src/layout.c b/src/layout.c new file mode 100644 index 0000000..5e98889 --- /dev/null +++ b/src/layout.c @@ -0,0 +1,14 @@ +#include "layout.h" + +void render_grid(const u32 layout[GRID_SIZE]) { + u8 red = 0; + u8 green = 0; + u8 blue = 0; + + for (int i = 0; i < GRID_SIZE; i++) { + red = (layout[i] & COLOR_RED) >> COLOR_RED_SHIFT; + green = (layout[i] & COLOR_GREEN) >> COLOR_GREEN_SHIFT; + blue = (layout[i] & COLOR_BLUE) >> COLOR_BLUE_SHIFT; + hal_plot_led(TYPEPAD, i, red, green, blue); + } +} diff --git a/tools/simulator.c b/tools/simulator.c index cec1ede..16b721a 100644 --- a/tools/simulator.c +++ b/tools/simulator.c @@ -42,6 +42,7 @@ void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue) { // wire this up to MIDI out...? + printf("...hsl_plot_led(%d, %d, 0x%2.2x, 0x%2.2x, 0x%2.2x);\n", type, index, red, green, blue); } void hal_read_led(u8 type, u8 index, u8 *red, u8 *green, u8 *blue)