diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..51b67cee --- /dev/null +++ b/.clang-format @@ -0,0 +1,244 @@ +## use pip install clang-format==18.1.3 +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE \ No newline at end of file diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index a04a1621..d3e127a0 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -27,7 +27,9 @@ jobs: run: python3 ci/build_platform.py main_platforms - name: clang - run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . + run: | + clang-format --version + python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . - name: doxygen env: diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index 870979b3..3452d0d0 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -352,6 +352,81 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, } #endif // end !ESP8266 +#if defined(ARDUINO_ARDUINO_NESSO_N1) +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + int8_t cs, ExpanderPin *dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(-1) { + hwspi._spi = spiClass; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _dcExp = dc; + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + int8_t cs, int8_t dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(dc) { + hwspi._spi = spiClass; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + ExpanderPin *cs, ExpanderPin *dc, + ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(-1), _dc(-1) { + hwspi._spi = spiClass; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _csExp = cs; + _dcExp = dc; + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, + ExpanderPin *dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(-1) { + hwspi._spi = &SPI; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _dcExp = dc; + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, + ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(dc) { + hwspi._spi = &SPI; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, ExpanderPin *cs, + ExpanderPin *dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(-1), _dc(-1) { + hwspi._spi = &SPI; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _csExp = cs; + _dcExp = dc; + _rstExp = rst; +} +#endif + /*! @brief Adafruit_SPITFT constructor for parallel display connection. @param w Display width in pixels at default rotation (0). @@ -543,8 +618,23 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { pinMode(_cs, OUTPUT); digitalWrite(_cs, HIGH); // Deselect } - pinMode(_dc, OUTPUT); - digitalWrite(_dc, HIGH); // Data mode +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_csExp) { + pinMode(*_csExp, OUTPUT); + digitalWrite(*_csExp, HIGH); + } +#endif + + if (_dc >= 0) { + pinMode(_dc, OUTPUT); + digitalWrite(_dc, HIGH); // Data mode + } +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_dcExp) { + pinMode(*_dcExp, OUTPUT); + digitalWrite(*_dcExp, HIGH); + } +#endif if (connection == TFT_HARD_SPI) { @@ -657,6 +747,17 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { digitalWrite(_rst, HIGH); delay(200); } +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_rstExp) { + pinMode(*_rstExp, OUTPUT); + digitalWrite(*_rstExp, HIGH); + delay(100); + digitalWrite(*_rstExp, LOW); + delay(100); + digitalWrite(*_rstExp, HIGH); + delay(200); + } +#endif #if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) && diff --git a/Adafruit_SPITFT.h b/Adafruit_SPITFT.h index 7d0843e6..9fa5c68b 100644 --- a/Adafruit_SPITFT.h +++ b/Adafruit_SPITFT.h @@ -26,6 +26,10 @@ #include "Adafruit_GFX.h" #include +// #if defined(ARDUINO_ARDUINO_NESSO_N1) +// class ExpanderPin; +// #endif + // HARDWARE CONFIG --------------------------------------------------------- #if defined(__AVR__) @@ -157,6 +161,23 @@ class Adafruit_SPITFT : public Adafruit_GFX { int8_t dc, int8_t rst = -1); #endif // end !ESP8266 +#if defined(ARDUINO_ARDUINO_NESSO_N1) + // Hardware SPI constructor using default or an arbitrary SPI peripheral + // and ExpanderPin for cs, dc, rst + Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs, + ExpanderPin *dc, ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs, + int8_t dc, ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, ExpanderPin *cs, + ExpanderPin *dc, ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, ExpanderPin *dc, + ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, + ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, ExpanderPin *cs, ExpanderPin *dc, + ExpanderPin *rst = NULL); +#endif + // Parallel constructor: expects width & height (rotation 0), flag // indicating whether 16-bit (true) or 8-bit (false) interface, 3 signal // pins (d0, wr, dc), 3 optional pins (cs, rst, rd). 16-bit parallel @@ -300,6 +321,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { connection is parallel. */ void SPI_CS_HIGH(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_csExp) { + digitalWrite(*_csExp, HIGH); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -322,6 +349,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { connection is parallel. */ void SPI_CS_LOW(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_csExp) { + digitalWrite(*_csExp, LOW); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -341,6 +374,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { @brief Set the data/command line HIGH (data mode). */ void SPI_DC_HIGH(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_dcExp) { + digitalWrite(*_dcExp, HIGH); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -360,6 +399,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { @brief Set the data/command line LOW (command mode). */ void SPI_DC_LOW(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_dcExp) { + digitalWrite(*_dcExp, LOW); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -528,6 +573,11 @@ class Adafruit_SPITFT : public Adafruit_GFX { int8_t _rst; ///< Reset pin # (or -1) int8_t _cs; ///< Chip select pin # (or -1) int8_t _dc; ///< Data/command pin # +#if defined(ARDUINO_ARDUINO_NESSO_N1) + ExpanderPin *_rstExp = NULL; + ExpanderPin *_csExp = NULL; + ExpanderPin *_dcExp = NULL; +#endif int16_t _xstart = 0; ///< Internal framebuffer X offset int16_t _ystart = 0; ///< Internal framebuffer Y offset