mirror of
https://github.com/espressif/arduino-esp32
synced 2024-09-21 02:18:29 +00:00
refactor(style): Change some style options (#9526)
* refactor(style): Change some style options * refactor(style): Apply style changes
This commit is contained in:
parent
8cab8c9b31
commit
6bfcd6d9a9
188
.clang-format
188
.clang-format
@ -1,37 +1,69 @@
|
||||
# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
|
||||
# Clang format version: 18.1.3
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveMacros: None
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
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: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseColons: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowBreakBeforeNoexceptSpecifier: Never
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortCompoundRequirementOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: No
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BasedOnStyle: LLVM
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterCaseLabel: true
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
@ -46,33 +78,33 @@ BraceWrapping:
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAdjacentStringLiterals: true
|
||||
BreakAfterAttributes: Always
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakArrays: false
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeConceptDeclarations: false
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: ''
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 160
|
||||
CommentPragmas: ""
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
ContinuationIndentWidth: 2
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: true
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Leave
|
||||
EmptyLineBeforeAccessModifier: Leave
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
@ -81,38 +113,49 @@ IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
- Regex: ^"(llvm|llvm-c|clang|clang-c)/
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
- Regex: ^(<|"(gtest|gmock|isl|json)/)
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
- Regex: .*
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: ''
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IncludeIsMainRegex: ""
|
||||
IncludeIsMainSourceRegex: ""
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: Indent
|
||||
IndentExternBlock: NoIndent
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentRequires: true
|
||||
IndentRequiresClause: false
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
IndentWrappedFunctionNames: true
|
||||
InsertBraces: true
|
||||
InsertNewlineAtEOF: true
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigits: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigits: 0
|
||||
Hex: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtEOF: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
LambdaBodyIndentation: Signature
|
||||
Language: Cpp
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 100000
|
||||
LineEnding: LF
|
||||
MacroBlockBegin: ""
|
||||
MacroBlockEnd: ""
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
@ -121,26 +164,32 @@ ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PPIndentWidth: -1
|
||||
PackConstructorInitializers: BinPack
|
||||
PenaltyBreakAssignment: 1
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 1
|
||||
PenaltyBreakFirstLessLess: 1
|
||||
PenaltyBreakOpenParenthesis: 1
|
||||
PenaltyBreakString: 1
|
||||
PenaltyBreakTemplateDeclaration: 1
|
||||
PenaltyExcessCharacter: 1
|
||||
PenaltyIndentedWhitespace: 1
|
||||
PenaltyReturnTypeOnItsOwnLine: 1
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakScopeResolution: 500
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
QualifierAlignment: Leave
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: false
|
||||
RemoveBracesLLVM: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 0
|
||||
ShortNamespaceLines: 1
|
||||
SkipMacroDefinitionBody: false
|
||||
SortIncludes: Never
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: false
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
@ -150,28 +199,34 @@ SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
AfterOverloadedOperator: true
|
||||
AfterPlacementOperator: true
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: Leave
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 0
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
InConditionalStatements: false
|
||||
InCStyleCasts: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
StatementAttributeLikeMacros:
|
||||
@ -180,11 +235,12 @@ StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 2
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
BracedInitializerIndentWidth: 2
|
||||
|
@ -26,7 +26,7 @@ repos:
|
||||
exclude: ^.*\.(svd|SVD)$
|
||||
stages: [manual]
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: "v15.0.7"
|
||||
rev: "v18.1.3"
|
||||
hooks:
|
||||
- id: clang-format
|
||||
types_or: [c, c++]
|
||||
|
@ -102,7 +102,9 @@
|
||||
// avr-libc defines _NOP() since 1.6.2
|
||||
#ifndef _NOP
|
||||
#define _NOP() \
|
||||
do { __asm__ volatile("nop"); } while (0)
|
||||
do { \
|
||||
__asm__ volatile("nop"); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
@ -213,28 +215,32 @@ uint16_t makeWord(uint8_t h, uint8_t l);
|
||||
|
||||
size_t getArduinoLoopTaskStackSize(void);
|
||||
#define SET_LOOP_TASK_STACK_SIZE(sz) \
|
||||
size_t getArduinoLoopTaskStackSize() { return sz; }
|
||||
size_t getArduinoLoopTaskStackSize() { \
|
||||
return sz; \
|
||||
}
|
||||
|
||||
bool shouldPrintChipDebugReport(void);
|
||||
#define ENABLE_CHIP_DEBUG_REPORT \
|
||||
bool shouldPrintChipDebugReport(void) { return true; }
|
||||
bool shouldPrintChipDebugReport(void) { \
|
||||
return true; \
|
||||
}
|
||||
|
||||
// allows user to bypass esp_spiram_test()
|
||||
bool esp_psram_extram_test(void);
|
||||
#define BYPASS_SPIRAM_TEST(bypass) \
|
||||
bool testSPIRAM(void) { \
|
||||
if (bypass) return true; \
|
||||
else return esp_psram_extram_test(); \
|
||||
if (bypass) \
|
||||
return true; \
|
||||
else \
|
||||
return esp_psram_extram_test(); \
|
||||
}
|
||||
|
||||
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||
|
||||
extern "C" bool getLocalTime(struct tm *info, uint32_t ms = 5000);
|
||||
extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec,
|
||||
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
|
||||
extern "C" void configTzTime(const char* tz,
|
||||
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
|
||||
extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec, const char *server1, const char *server2 = nullptr, const char *server3 = nullptr);
|
||||
extern "C" void configTzTime(const char *tz, const char *server1, const char *server2 = nullptr, const char *server3 = nullptr);
|
||||
|
||||
void setToneChannel(uint8_t channel = 0);
|
||||
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
|
||||
protected:
|
||||
uint8_t *rawIPAddress(IPAddress &addr) {
|
||||
return addr.raw_address();
|
||||
|
@ -119,7 +119,6 @@ unsigned long long operator"" _GB(unsigned long long x) {
|
||||
return x * 1024 * 1024 * 1024;
|
||||
}
|
||||
|
||||
|
||||
EspClass ESP;
|
||||
|
||||
void EspClass::deepSleep(uint64_t time_us) {
|
||||
@ -177,7 +176,9 @@ uint32_t EspClass::getMaxAllocPsram(void) {
|
||||
static uint32_t sketchSize(sketchSize_t response) {
|
||||
esp_image_metadata_t data;
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
if (!running) return 0;
|
||||
if (!running) {
|
||||
return 0;
|
||||
}
|
||||
const esp_partition_pos_t running_pos = {
|
||||
.offset = running->address,
|
||||
.size = running->size,
|
||||
@ -260,39 +261,31 @@ const char *EspClass::getChipModel(void) {
|
||||
uint32_t pkg_ver = chip_ver & 0x7;
|
||||
switch (pkg_ver) {
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6:
|
||||
if (getChipRevision() == 3)
|
||||
if (getChipRevision() == 3) {
|
||||
return "ESP32-D0WDQ6-V3";
|
||||
else
|
||||
} else {
|
||||
return "ESP32-D0WDQ6";
|
||||
}
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5:
|
||||
if (getChipRevision() == 3)
|
||||
if (getChipRevision() == 3) {
|
||||
return "ESP32-D0WD-V3";
|
||||
else
|
||||
} else {
|
||||
return "ESP32-D0WD";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5:
|
||||
return "ESP32-D2WD";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2:
|
||||
return "ESP32-PICO-D2";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4:
|
||||
return "ESP32-PICO-D4";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302:
|
||||
return "ESP32-PICO-V3-02";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3:
|
||||
return "ESP32-D0WDR2-V3";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5: return "ESP32-D2WD";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2: return "ESP32-PICO-D2";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4: return "ESP32-PICO-D4";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302: return "ESP32-PICO-V3-02";
|
||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3: return "ESP32-D0WDR2-V3";
|
||||
default: return "Unknown";
|
||||
}
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_3_REG, EFUSE_PKG_VERSION);
|
||||
switch (pkg_ver) {
|
||||
case 0:
|
||||
return "ESP32-S2";
|
||||
case 1:
|
||||
return "ESP32-S2FH16";
|
||||
case 2:
|
||||
return "ESP32-S2FH32";
|
||||
default:
|
||||
return "ESP32-S2 (Unknown)";
|
||||
case 0: return "ESP32-S2";
|
||||
case 1: return "ESP32-S2FH16";
|
||||
case 2: return "ESP32-S2FH32";
|
||||
default: return "ESP32-S2 (Unknown)";
|
||||
}
|
||||
#else
|
||||
esp_chip_info_t chip_info;
|
||||
@ -414,7 +407,6 @@ uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#elif CONFIG_IDF_TARGET_ESP32C6
|
||||
/*
|
||||
FLASH_FREQUENCY = {
|
||||
@ -449,7 +441,6 @@ uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
/*
|
||||
FLASH_FREQUENCY = {
|
||||
@ -470,7 +461,6 @@ uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
FlashMode_t EspClass::magicFlashChipMode(uint8_t byte) {
|
||||
FlashMode_t mode = (FlashMode_t)byte;
|
||||
if (mode > FM_SLOW_READ) {
|
||||
|
@ -42,7 +42,6 @@ typedef enum {
|
||||
WDTO_8S = 8000 //!< WDTO_8S
|
||||
} WDTO_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
FM_QIO = 0x00,
|
||||
FM_QOUT = 0x01,
|
||||
|
@ -310,7 +310,8 @@ static int32_t msc_write(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_
|
||||
return 0;
|
||||
}
|
||||
} else if (msc_update_state == MSC_UPDATE_RUNNING) {
|
||||
if (msc_update_entry && msc_update_entry->file_size && msc_update_bytes_written < msc_update_entry->file_size && (msc_update_bytes_written + bufsize) >= msc_update_entry->file_size) {
|
||||
if (msc_update_entry && msc_update_entry->file_size && msc_update_bytes_written < msc_update_entry->file_size
|
||||
&& (msc_update_bytes_written + bufsize) >= msc_update_entry->file_size) {
|
||||
bufsize = msc_update_entry->file_size - msc_update_bytes_written;
|
||||
}
|
||||
if (msc_update_write(msc_ota_partition, ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) == ESP_OK) {
|
||||
@ -369,8 +370,7 @@ static void msc_task(void *pvParameters) {
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
FirmwareMSC::FirmwareMSC()
|
||||
: msc() {}
|
||||
FirmwareMSC::FirmwareMSC() : msc() {}
|
||||
|
||||
FirmwareMSC::~FirmwareMSC() {
|
||||
end();
|
||||
|
@ -21,7 +21,8 @@
|
||||
#include <HEXBuilder.h>
|
||||
|
||||
static uint8_t hex_char_to_byte(uint8_t c) {
|
||||
return (c >= 'a' && c <= 'f') ? (c - ((uint8_t)'a' - 0xa)) : (c >= 'A' && c <= 'F') ? (c - ((uint8_t)'A' - 0xA))
|
||||
return (c >= 'a' && c <= 'f') ? (c - ((uint8_t)'a' - 0xa))
|
||||
: (c >= 'A' && c <= 'F') ? (c - ((uint8_t)'A' - 0xA))
|
||||
: (c >= '0' && c <= '9') ? (c - (uint8_t)'0')
|
||||
: 0x10; // unknown char is 16
|
||||
}
|
||||
@ -35,16 +36,19 @@ size_t HEXBuilder::hex2bytes(unsigned char *out, size_t maxlen, const char *in)
|
||||
for (; *in; in++) {
|
||||
uint8_t c = hex_char_to_byte(*in);
|
||||
// Silently skip anything unknown.
|
||||
if (c > 15)
|
||||
if (c > 15) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len & 1) {
|
||||
if (len / 2 < maxlen)
|
||||
if (len / 2 < maxlen) {
|
||||
out[len / 2] |= c;
|
||||
}
|
||||
} else {
|
||||
if (len / 2 < maxlen)
|
||||
if (len / 2 < maxlen) {
|
||||
out[len / 2] = c << 4;
|
||||
}
|
||||
}
|
||||
len++;
|
||||
}
|
||||
return (len + 1) / 2;
|
||||
@ -62,7 +66,9 @@ size_t HEXBuilder::bytes2hex(char *out, size_t maxlen, const unsigned char *in,
|
||||
String HEXBuilder::bytes2hex(const unsigned char *in, size_t len) {
|
||||
size_t maxlen = len * 2 + 1;
|
||||
char *out = (char *)malloc(maxlen);
|
||||
if (!out) return String();
|
||||
if (!out) {
|
||||
return String();
|
||||
}
|
||||
bytes2hex(out, maxlen, in, len);
|
||||
String ret = String(out);
|
||||
free(out);
|
||||
|
@ -45,21 +45,19 @@ static uint32_t requested_tx_timeout_ms = 100;
|
||||
|
||||
static esp_event_loop_handle_t arduino_hw_cdc_event_loop_handle = NULL;
|
||||
|
||||
static esp_err_t arduino_hw_cdc_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, BaseType_t *task_unblocked) {
|
||||
static esp_err_t
|
||||
arduino_hw_cdc_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, BaseType_t *task_unblocked) {
|
||||
if (arduino_hw_cdc_event_loop_handle == NULL) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return esp_event_isr_post_to(arduino_hw_cdc_event_loop_handle, event_base, event_id, event_data, event_data_size, task_unblocked);
|
||||
}
|
||||
|
||||
static esp_err_t arduino_hw_cdc_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg) {
|
||||
static esp_err_t
|
||||
arduino_hw_cdc_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg) {
|
||||
if (!arduino_hw_cdc_event_loop_handle) {
|
||||
esp_event_loop_args_t event_task_args = {
|
||||
.queue_size = 5,
|
||||
.task_name = "arduino_hw_cdc_events",
|
||||
.task_priority = 5,
|
||||
.task_stack_size = 2048,
|
||||
.task_core_id = tskNO_AFFINITY
|
||||
.queue_size = 5, .task_name = "arduino_hw_cdc_events", .task_priority = 5, .task_stack_size = 2048, .task_core_id = tskNO_AFFINITY
|
||||
};
|
||||
if (esp_event_loop_create(&event_task_args, &arduino_hw_cdc_event_loop_handle) != ESP_OK) {
|
||||
log_e("esp_event_loop_create failed");
|
||||
@ -99,7 +97,9 @@ static void hw_cdc_isr_handler(void *arg) {
|
||||
usb_serial_jtag_ll_write_txfifo(queued_buff, queued_size);
|
||||
usb_serial_jtag_ll_txfifo_flush();
|
||||
vRingbufferReturnItemFromISR(tx_ring_buf, queued_buff, &xTaskWoken);
|
||||
if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
if (connected) {
|
||||
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
}
|
||||
//send event?
|
||||
//ets_printf("TX:%u\n", queued_size);
|
||||
event.tx.len = queued_size;
|
||||
@ -204,7 +204,9 @@ void HWCDC::onEvent(arduino_hw_cdc_event_t event, esp_event_handler_t callback)
|
||||
bool HWCDC::deinit(void *busptr) {
|
||||
// avoid any recursion issue with Peripheral Manager perimanSetPinBus() call
|
||||
static bool running = false;
|
||||
if (running) return true;
|
||||
if (running) {
|
||||
return true;
|
||||
}
|
||||
running = true;
|
||||
// Setting USB D+ D- pins
|
||||
bool retCode = true;
|
||||
@ -245,9 +247,13 @@ void HWCDC::begin(unsigned long baud) {
|
||||
|
||||
// Peripheral Manager setting for USB D+ D- pins
|
||||
uint8_t pin = USB_DM_GPIO_NUM;
|
||||
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *)this, -1, -1)) goto err;
|
||||
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *)this, -1, -1)) {
|
||||
goto err;
|
||||
}
|
||||
pin = USB_DP_GPIO_NUM;
|
||||
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *)this, -1, -1)) goto err;
|
||||
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *)this, -1, -1)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Configure PHY
|
||||
// USB_Serial_JTAG use internal PHY
|
||||
@ -333,7 +339,9 @@ int HWCDC::availableForWrite(void) {
|
||||
}
|
||||
|
||||
static void flushTXBuffer() {
|
||||
if (!tx_ring_buf) return;
|
||||
if (!tx_ring_buf) {
|
||||
return;
|
||||
}
|
||||
UBaseType_t uxItemsWaiting = 0;
|
||||
vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
|
||||
@ -373,7 +381,9 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size) {
|
||||
so_far += space;
|
||||
// Now trigger the ISR to read data from the ring buffer.
|
||||
usb_serial_jtag_ll_txfifo_flush();
|
||||
if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
if (connected) {
|
||||
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
}
|
||||
|
||||
while (to_send) {
|
||||
space = xRingbufferGetCurFreeSize(tx_ring_buf);
|
||||
@ -389,7 +399,9 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size) {
|
||||
to_send -= space;
|
||||
// Now trigger the ISR to read data from the ring buffer.
|
||||
usb_serial_jtag_ll_txfifo_flush();
|
||||
if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
if (connected) {
|
||||
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
// CDC is disconnected ==> flush all data from TX buffer
|
||||
@ -423,14 +435,18 @@ void HWCDC::flush(void) {
|
||||
if (uxItemsWaiting) {
|
||||
// Now trigger the ISR to read data from the ring buffer.
|
||||
usb_serial_jtag_ll_txfifo_flush();
|
||||
if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
if (connected) {
|
||||
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
|
||||
}
|
||||
}
|
||||
uint8_t tries = 3;
|
||||
while (tries && uxItemsWaiting) {
|
||||
delay(5);
|
||||
UBaseType_t lastUxItemsWaiting = uxItemsWaiting;
|
||||
vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
if (lastUxItemsWaiting == uxItemsWaiting) tries--;
|
||||
if (lastUxItemsWaiting == uxItemsWaiting) {
|
||||
tries--;
|
||||
}
|
||||
}
|
||||
if (tries == 0) { // CDC isn't connected anymore...
|
||||
connected = false;
|
||||
|
@ -59,18 +59,28 @@ void USBSerialEvent(void) {}
|
||||
|
||||
void serialEventRun(void) {
|
||||
#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event
|
||||
if (HWCDCSerial.available()) HWCDCSerialEvent();
|
||||
if (HWCDCSerial.available()) {
|
||||
HWCDCSerialEvent();
|
||||
}
|
||||
#endif
|
||||
#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event
|
||||
if (USBSerial.available()) USBSerialEvent();
|
||||
if (USBSerial.available()) {
|
||||
USBSerialEvent();
|
||||
}
|
||||
#endif
|
||||
// UART0 is default serialEvent()
|
||||
if (Serial0.available()) serialEvent();
|
||||
if (Serial0.available()) {
|
||||
serialEvent();
|
||||
}
|
||||
#if SOC_UART_NUM > 1
|
||||
if (Serial1.available()) serialEvent1();
|
||||
if (Serial1.available()) {
|
||||
serialEvent1();
|
||||
}
|
||||
#endif
|
||||
#if SOC_UART_NUM > 2
|
||||
if (Serial2.available()) serialEvent2();
|
||||
if (Serial2.available()) {
|
||||
serialEvent2();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -86,16 +96,8 @@ void serialEventRun(void) {
|
||||
#endif
|
||||
|
||||
HardwareSerial::HardwareSerial(uint8_t uart_nr)
|
||||
: _uart_nr(uart_nr),
|
||||
_uart(NULL),
|
||||
_rxBufferSize(256),
|
||||
_txBufferSize(0),
|
||||
_onReceiveCB(NULL),
|
||||
_onReceiveErrorCB(NULL),
|
||||
_onReceiveTimeout(false),
|
||||
_rxTimeout(2),
|
||||
_rxFIFOFull(0),
|
||||
_eventTask(NULL)
|
||||
: _uart_nr(uart_nr), _uart(NULL), _rxBufferSize(256), _txBufferSize(0), _onReceiveCB(NULL), _onReceiveErrorCB(NULL), _onReceiveTimeout(false), _rxTimeout(2),
|
||||
_rxFIFOFull(0), _eventTask(NULL)
|
||||
#if !CONFIG_DISABLE_HAL_LOCKS
|
||||
,
|
||||
_lock(NULL)
|
||||
@ -123,10 +125,12 @@ HardwareSerial::~HardwareSerial() {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void HardwareSerial::_createEventTask(void *args) {
|
||||
// Creating UART event Task
|
||||
xTaskCreateUniversal(_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask, ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE);
|
||||
xTaskCreateUniversal(
|
||||
_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask,
|
||||
ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE
|
||||
);
|
||||
if (_eventTask == NULL) {
|
||||
log_e(" -- UART%d Event Task not Created!", _uart_nr);
|
||||
}
|
||||
@ -189,7 +193,9 @@ bool HardwareSerial::setRxFIFOFull(uint8_t fifoBytes) {
|
||||
log_w("OnReceive is set to Timeout only, thus FIFO Full is now 120 bytes.");
|
||||
}
|
||||
bool retCode = uartSetRxFIFOFull(_uart, fifoBytes); // Set new timeout
|
||||
if (fifoBytes > 0 && fifoBytes < SOC_UART_FIFO_LEN - 1) _rxFIFOFull = fifoBytes;
|
||||
if (fifoBytes > 0 && fifoBytes < SOC_UART_FIFO_LEN - 1) {
|
||||
_rxFIFOFull = fifoBytes;
|
||||
}
|
||||
HSERIAL_MUTEX_UNLOCK();
|
||||
return retCode;
|
||||
}
|
||||
@ -202,7 +208,9 @@ bool HardwareSerial::setRxTimeout(uint8_t symbols_timeout) {
|
||||
// Zero disables timeout, thus, onReceive callback will only be called when RX FIFO reaches 120 bytes
|
||||
// Any non-zero value will activate onReceive callback based on UART baudrate with about 11 bits per symbol
|
||||
_rxTimeout = symbols_timeout;
|
||||
if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag
|
||||
if (!symbols_timeout) {
|
||||
_onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag
|
||||
}
|
||||
|
||||
bool retCode = uartSetRxTimeout(_uart, _rxTimeout); // Set new timeout
|
||||
|
||||
@ -233,8 +241,9 @@ void HardwareSerial::_uartEventTask(void *args) {
|
||||
hardwareSerial_error_t currentErr = UART_NO_ERROR;
|
||||
switch (event.type) {
|
||||
case UART_DATA:
|
||||
if (uart->_onReceiveCB && uart->available() > 0 && ((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout))
|
||||
if (uart->_onReceiveCB && uart->available() > 0 && ((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout)) {
|
||||
uart->_onReceiveCB();
|
||||
}
|
||||
break;
|
||||
case UART_FIFO_OVF:
|
||||
log_w("UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application.", uart->_uart_nr);
|
||||
@ -256,12 +265,12 @@ void HardwareSerial::_uartEventTask(void *args) {
|
||||
log_w("UART%d frame error.", uart->_uart_nr);
|
||||
currentErr = UART_FRAME_ERROR;
|
||||
break;
|
||||
default:
|
||||
log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type);
|
||||
break;
|
||||
default: log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type); break;
|
||||
}
|
||||
if (currentErr != UART_NO_ERROR) {
|
||||
if (uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(currentErr);
|
||||
if (uart->_onReceiveErrorCB) {
|
||||
uart->_onReceiveErrorCB(currentErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,6 @@ typedef enum {
|
||||
UART_PARITY_ERROR
|
||||
} hardwareSerial_error_t;
|
||||
|
||||
|
||||
#ifndef ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE
|
||||
#define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048
|
||||
#endif
|
||||
@ -250,7 +249,10 @@ public:
|
||||
// timeout_ms is used in baudrate detection (ESP32, ESP32S2 only)
|
||||
// invert will invert RX/TX polarity
|
||||
// rxfifo_full_thrhd if the UART Flow Control Threshold in the UART FIFO (max 127)
|
||||
void begin(unsigned long baud, uint32_t config = SERIAL_8N1, int8_t rxPin = -1, int8_t txPin = -1, bool invert = false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 112);
|
||||
void begin(
|
||||
unsigned long baud, uint32_t config = SERIAL_8N1, int8_t rxPin = -1, int8_t txPin = -1, bool invert = false, unsigned long timeout_ms = 20000UL,
|
||||
uint8_t rxfifo_full_thrhd = 112
|
||||
);
|
||||
void end(void);
|
||||
void updateBaudRate(unsigned long baud);
|
||||
int available(void);
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include "lwip/netif.h"
|
||||
#include "StreamString.h"
|
||||
|
||||
IPAddress::IPAddress()
|
||||
: IPAddress(IPv4) {}
|
||||
IPAddress::IPAddress() : IPAddress(IPv4) {}
|
||||
|
||||
IPAddress::IPAddress(IPType ip_type) {
|
||||
_type = ip_type;
|
||||
@ -41,7 +40,10 @@ IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_oc
|
||||
_address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = fourth_octet;
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z) {
|
||||
IPAddress::IPAddress(
|
||||
uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12,
|
||||
uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z
|
||||
) {
|
||||
_type = IPv6;
|
||||
_address.bytes[0] = o1;
|
||||
_address.bytes[1] = o2;
|
||||
@ -78,8 +80,7 @@ IPAddress::IPAddress(uint32_t address) {
|
||||
// in that order, will form the integer (uint32_t) 3460758158 .
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(const uint8_t* address)
|
||||
: IPAddress(IPv4, address) {}
|
||||
IPAddress::IPAddress(const uint8_t *address) : IPAddress(IPv4, address) {}
|
||||
|
||||
IPAddress::IPAddress(IPType ip_type, const uint8_t *address, uint8_t z) {
|
||||
_type = ip_type;
|
||||
@ -166,12 +167,14 @@ bool IPAddress::fromString6(const char* address) {
|
||||
while (*address) {
|
||||
char c = tolower(*address++);
|
||||
if (isalnum(c) && c <= 'f') {
|
||||
if (c >= 'a')
|
||||
if (c >= 'a') {
|
||||
c -= 'a' - '0' - 10;
|
||||
}
|
||||
acc = acc * 16 + (c - '0');
|
||||
if (acc > 0xffff)
|
||||
if (acc > 0xffff) {
|
||||
// Value out of range
|
||||
return false;
|
||||
}
|
||||
} else if (c == ':') {
|
||||
if (*address == ':') {
|
||||
if (double_colons >= 0) {
|
||||
@ -189,9 +192,10 @@ bool IPAddress::fromString6(const char* address) {
|
||||
// can't end with a single colon
|
||||
return false;
|
||||
}
|
||||
if (colons == 7)
|
||||
if (colons == 7) {
|
||||
// too many separators
|
||||
return false;
|
||||
}
|
||||
_address.bytes[colons * 2] = acc >> 8;
|
||||
_address.bytes[colons * 2 + 1] = acc & 0xff;
|
||||
colons++;
|
||||
@ -201,10 +205,11 @@ bool IPAddress::fromString6(const char* address) {
|
||||
while (*address != '\0') {
|
||||
address++;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
// Invalid char
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (double_colons == -1 && colons != 7) {
|
||||
// Too few separators
|
||||
@ -219,11 +224,13 @@ bool IPAddress::fromString6(const char* address) {
|
||||
colons++;
|
||||
|
||||
if (double_colons != -1) {
|
||||
for (int i = colons * 2 - double_colons * 2 - 1; i >= 0; i--)
|
||||
for (int i = colons * 2 - double_colons * 2 - 1; i >= 0; i--) {
|
||||
_address.bytes[16 - colons * 2 + double_colons * 2 + i] = _address.bytes[double_colons * 2 + i];
|
||||
for (int i = double_colons * 2; i < 16 - colons * 2 + double_colons * 2; i++)
|
||||
}
|
||||
for (int i = double_colons * 2; i < 16 - colons * 2 + double_colons * 2; i++) {
|
||||
_address.bytes[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_type = IPv6;
|
||||
return true;
|
||||
@ -259,8 +266,7 @@ IPAddress& IPAddress::operator=(const IPAddress& address) {
|
||||
}
|
||||
|
||||
bool IPAddress::operator==(const IPAddress &addr) const {
|
||||
return (addr._type == _type)
|
||||
&& (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0);
|
||||
return (addr._type == _type) && (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0);
|
||||
}
|
||||
|
||||
bool IPAddress::operator==(const uint8_t *addr) const {
|
||||
|
@ -59,7 +59,10 @@ public:
|
||||
IPAddress();
|
||||
IPAddress(IPType ip_type);
|
||||
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
|
||||
IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z = 0);
|
||||
IPAddress(
|
||||
uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12,
|
||||
uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z = 0
|
||||
);
|
||||
// IPv4; see implementation note
|
||||
IPAddress(uint32_t address);
|
||||
// Default IPv4
|
||||
|
@ -33,6 +33,7 @@ class MD5Builder : public HashBuilder {
|
||||
private:
|
||||
md5_context_t _ctx;
|
||||
uint8_t _buf[ESP_ROM_MD5_DIGEST_LEN];
|
||||
|
||||
public:
|
||||
void begin(void) override;
|
||||
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include <Print.h>
|
||||
|
||||
//Default constructor, blank mac address.
|
||||
MacAddress::MacAddress()
|
||||
: MacAddress(MAC6) {}
|
||||
MacAddress::MacAddress() : MacAddress(MAC6) {}
|
||||
|
||||
MacAddress::MacAddress(MACType mac_type) {
|
||||
_type = mac_type;
|
||||
@ -118,14 +117,12 @@ void MacAddress::toBytes(uint8_t *buf) {
|
||||
//MAC: Buffer must be at least 18 chars
|
||||
int MacAddress::toString(char *buf) {
|
||||
if (_type == MAC6) {
|
||||
return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
_mac.bytes[0], _mac.bytes[1], _mac.bytes[2],
|
||||
_mac.bytes[3], _mac.bytes[4], _mac.bytes[5]);
|
||||
return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], _mac.bytes[3], _mac.bytes[4], _mac.bytes[5]);
|
||||
} else {
|
||||
return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
_mac.bytes[0], _mac.bytes[1], _mac.bytes[2],
|
||||
_mac.bytes[3], _mac.bytes[4], _mac.bytes[5],
|
||||
_mac.bytes[6], _mac.bytes[7]);
|
||||
return sprintf(
|
||||
buf, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], _mac.bytes[3], _mac.bytes[4], _mac.bytes[5], _mac.bytes[6],
|
||||
_mac.bytes[7]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,14 +130,12 @@ String MacAddress::toString() const {
|
||||
uint8_t bytes = (_type == MAC6) ? 18 : 24;
|
||||
char buf[bytes];
|
||||
if (_type == MAC6) {
|
||||
snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
_mac.bytes[0], _mac.bytes[1], _mac.bytes[2],
|
||||
_mac.bytes[3], _mac.bytes[4], _mac.bytes[5]);
|
||||
snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X", _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], _mac.bytes[3], _mac.bytes[4], _mac.bytes[5]);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
_mac.bytes[0], _mac.bytes[1], _mac.bytes[2],
|
||||
_mac.bytes[3], _mac.bytes[4], _mac.bytes[5],
|
||||
_mac.bytes[6], _mac.bytes[7]);
|
||||
snprintf(
|
||||
buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], _mac.bytes[3], _mac.bytes[4], _mac.bytes[5],
|
||||
_mac.bytes[6], _mac.bytes[7]
|
||||
);
|
||||
}
|
||||
return String(buf);
|
||||
}
|
||||
|
@ -50,10 +50,8 @@ public:
|
||||
MacAddress(MACType mac_type, const uint8_t *macbytearray);
|
||||
|
||||
//Default MAC6
|
||||
MacAddress(uint64_t mac)
|
||||
: MacAddress(MAC6, mac) {}
|
||||
MacAddress(const uint8_t *macbytearray)
|
||||
: MacAddress(MAC6, macbytearray) {}
|
||||
MacAddress(uint64_t mac) : MacAddress(MAC6, mac) {}
|
||||
MacAddress(const uint8_t *macbytearray) : MacAddress(MAC6, macbytearray) {}
|
||||
|
||||
MacAddress(const char *macstr);
|
||||
MacAddress(const String &macstr);
|
||||
|
@ -38,14 +38,14 @@ private:
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
|
||||
protected:
|
||||
void setWriteError(int err = 1) {
|
||||
write_error = err;
|
||||
}
|
||||
|
||||
public:
|
||||
Print()
|
||||
: write_error(0) {
|
||||
}
|
||||
Print() : write_error(0) {}
|
||||
virtual ~Print() {}
|
||||
int getWriteError() {
|
||||
return write_error;
|
||||
@ -112,8 +112,7 @@ public:
|
||||
size_t println(struct tm *timeinfo, const char *format = NULL);
|
||||
size_t println(void);
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */
|
||||
}
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,12 +27,7 @@
|
||||
|
||||
#ifndef GET_UINT32_BE
|
||||
#define GET_UINT32_BE(n, b, i) \
|
||||
{ \
|
||||
(n) = ((uint32_t)(b)[(i)] << 24) \
|
||||
| ((uint32_t)(b)[(i) + 1] << 16) \
|
||||
| ((uint32_t)(b)[(i) + 2] << 8) \
|
||||
| ((uint32_t)(b)[(i) + 3]); \
|
||||
}
|
||||
{ (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); }
|
||||
#endif
|
||||
|
||||
#ifndef PUT_UINT32_BE
|
||||
@ -47,12 +42,8 @@
|
||||
|
||||
// Constants
|
||||
|
||||
static const uint8_t sha1_padding[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
static const uint8_t sha1_padding[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
// Private methods
|
||||
|
||||
@ -78,10 +69,7 @@ void SHA1Builder::process(const uint8_t* data) {
|
||||
|
||||
#define sha1_S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define sha1_R(t) \
|
||||
( \
|
||||
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ W[(t - 14) & 0x0F] ^ W[t & 0x0F], \
|
||||
(W[t & 0x0F] = sha1_S(temp, 1)))
|
||||
#define sha1_R(t) (temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ W[(t - 14) & 0x0F] ^ W[t & 0x0F], (W[t & 0x0F] = sha1_S(temp, 1)))
|
||||
|
||||
#define sha1_P(a, b, c, d, e, x) \
|
||||
{ \
|
||||
|
@ -116,37 +116,42 @@ int Stream::findMulti(struct Stream::MultiTarget *targets, int tCount) {
|
||||
// any zero length target string automatically matches and would make
|
||||
// a mess of the rest of the algorithm.
|
||||
for (struct MultiTarget *t = targets; t < targets + tCount; ++t) {
|
||||
if (t->len <= 0)
|
||||
if (t->len <= 0) {
|
||||
return t - targets;
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
if (c < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (struct MultiTarget *t = targets; t < targets + tCount; ++t) {
|
||||
// the simple case is if we match, deal with that first.
|
||||
if (c == t->str[t->index]) {
|
||||
if (++t->index == t->len)
|
||||
if (++t->index == t->len) {
|
||||
return t - targets;
|
||||
else
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// if not we need to walk back and see if we could have matched further
|
||||
// down the stream (ie '1112' doesn't match the first position in '11112'
|
||||
// but it will match the second position so we can't just reset the current
|
||||
// index to 0 when we find a mismatch.
|
||||
if (t->index == 0)
|
||||
if (t->index == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int origIndex = t->index;
|
||||
do {
|
||||
--t->index;
|
||||
// first check if current char works against the new current index
|
||||
if (c != t->str[t->index])
|
||||
if (c != t->str[t->index]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if it's the only char then we're good, nothing more to check
|
||||
if (t->index == 0) {
|
||||
@ -158,9 +163,10 @@ int Stream::findMulti(struct Stream::MultiTarget *targets, int tCount) {
|
||||
int diff = origIndex - t->index;
|
||||
size_t i;
|
||||
for (i = 0; i < t->index; ++i) {
|
||||
if (t->str[i] != t->str[i + diff])
|
||||
if (t->str[i] != t->str[i + diff]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we successfully got through the previous loop then our current
|
||||
// index is good.
|
||||
|
@ -48,8 +48,7 @@ public:
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
Stream()
|
||||
: _startMillis(0) {
|
||||
Stream() : _startMillis(0) {
|
||||
_timeout = 1000;
|
||||
}
|
||||
virtual ~Stream() {}
|
||||
|
@ -61,5 +61,4 @@ int StreamString::peek() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void StreamString::flush() {
|
||||
}
|
||||
void StreamString::flush() {}
|
||||
|
@ -35,5 +35,4 @@ public:
|
||||
void flush() override;
|
||||
};
|
||||
|
||||
|
||||
#endif /* STREAMSTRING_H_ */
|
||||
|
@ -60,8 +60,7 @@ static uint16_t load_dfu_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
#define DFU_ATTRS (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_CAN_UPLOAD | DFU_ATTR_MANIFESTATION_TOLERANT)
|
||||
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT");
|
||||
uint8_t descriptor[TUD_DFU_RT_DESC_LEN] = {
|
||||
// Interface number, string index, attributes, detach timeout, transfer size */
|
||||
uint8_t descriptor[TUD_DFU_RT_DESC_LEN] = {// Interface number, string index, attributes, detach timeout, transfer size */
|
||||
TUD_DFU_RT_DESCRIPTOR(*itf, str_index, DFU_ATTRS, 700, 64)
|
||||
};
|
||||
*itf += 1;
|
||||
@ -128,9 +127,12 @@ void tud_resume_cb(void) {
|
||||
}
|
||||
|
||||
ESPUSB::ESPUSB(size_t task_stack_size, uint8_t event_task_priority)
|
||||
: vid(USB_VID), pid(USB_PID), product_name(USB_PRODUCT), manufacturer_name(USB_MANUFACTURER), serial_number(USB_SERIAL), fw_version(0x0100), usb_version(0x0200) // at least 2.1 or 3.x for BOS & webUSB
|
||||
: vid(USB_VID), pid(USB_PID), product_name(USB_PRODUCT), manufacturer_name(USB_MANUFACTURER), serial_number(USB_SERIAL), fw_version(0x0100),
|
||||
usb_version(0x0200) // at least 2.1 or 3.x for BOS & webUSB
|
||||
,
|
||||
usb_class(TUSB_CLASS_MISC), usb_subclass(MISC_SUBCLASS_COMMON), usb_protocol(MISC_PROTOCOL_IAD), usb_attributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED), usb_power_ma(500), webusb_enabled(USB_WEBUSB_ENABLED), webusb_url(USB_WEBUSB_URL), _started(false), _task_stack_size(task_stack_size), _event_task_priority(event_task_priority) {
|
||||
usb_class(TUSB_CLASS_MISC), usb_subclass(MISC_SUBCLASS_COMMON), usb_protocol(MISC_PROTOCOL_IAD), usb_attributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED),
|
||||
usb_power_ma(500), webusb_enabled(USB_WEBUSB_ENABLED), webusb_url(USB_WEBUSB_URL), _started(false), _task_stack_size(task_stack_size),
|
||||
_event_task_priority(event_task_priority) {
|
||||
if (!arduino_usb_event_loop_handle) {
|
||||
esp_event_loop_args_t event_task_args = {
|
||||
.queue_size = 5,
|
||||
|
@ -118,6 +118,5 @@ private:
|
||||
|
||||
extern ESPUSB USB;
|
||||
|
||||
|
||||
#endif /* CONFIG_TINYUSB_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "USB.h"
|
||||
#if CONFIG_TINYUSB_CDC_ENABLED
|
||||
|
||||
|
||||
#include "esp32-hal-tinyusb.h"
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
@ -31,8 +30,7 @@ USBCDC *devices[MAX_USB_CDC_DEVICES] = { NULL, NULL };
|
||||
|
||||
static uint16_t load_cdc_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC");
|
||||
uint8_t descriptor[TUD_CDC_DESC_LEN] = {
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
uint8_t descriptor[TUD_CDC_DESC_LEN] = {// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(*itf, str_index, 0x85, 64, 0x03, 0x84, 64)
|
||||
};
|
||||
*itf += 2;
|
||||
@ -84,7 +82,8 @@ static void usb_unplugged_cb(void *arg, esp_event_base_t event_base, int32_t eve
|
||||
}
|
||||
|
||||
USBCDC::USBCDC(uint8_t itfn)
|
||||
: itf(itfn), bit_rate(0), stop_bits(0), parity(0), data_bits(0), dtr(false), rts(false), connected(false), reboot_enable(true), rx_queue(NULL), tx_lock(NULL), tx_timeout_ms(250) {
|
||||
: itf(itfn), bit_rate(0), stop_bits(0), parity(0), data_bits(0), dtr(false), rts(false), connected(false), reboot_enable(true), rx_queue(NULL), tx_lock(NULL),
|
||||
tx_timeout_ms(250) {
|
||||
tinyusb_enable_interface(USB_INTERFACE_CDC, TUD_CDC_DESC_LEN, load_cdc_descriptor);
|
||||
if (itf < MAX_USB_CDC_DEVICES) {
|
||||
arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, usb_unplugged_cb, this);
|
||||
@ -147,7 +146,9 @@ void USBCDC::begin(unsigned long baud) {
|
||||
tx_lock = xSemaphoreCreateMutex();
|
||||
}
|
||||
// if rx_queue was set before begin(), keep it
|
||||
if (!rx_queue) setRxBufferSize(256); //default if not preset
|
||||
if (!rx_queue) {
|
||||
setRxBufferSize(256); //default if not preset
|
||||
}
|
||||
devices[itf] = this;
|
||||
}
|
||||
|
||||
@ -175,10 +176,12 @@ void USBCDC::_onUnplugged(void) {
|
||||
}
|
||||
}
|
||||
|
||||
enum { CDC_LINE_IDLE,
|
||||
enum {
|
||||
CDC_LINE_IDLE,
|
||||
CDC_LINE_1,
|
||||
CDC_LINE_2,
|
||||
CDC_LINE_3 };
|
||||
CDC_LINE_3
|
||||
};
|
||||
void USBCDC::_onLineState(bool _dtr, bool _rts) {
|
||||
static uint8_t lineState = CDC_LINE_IDLE;
|
||||
|
||||
|
@ -140,6 +140,5 @@ protected:
|
||||
extern USBCDC USBSerial;
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* CONFIG_TINYUSB_CDC_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
|
@ -23,8 +23,7 @@ extern "C" uint16_t tusb_msc_load_descriptor(uint8_t* dst, uint8_t* itf) {
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MSC");
|
||||
uint8_t ep_num = tinyusb_get_free_duplex_endpoint();
|
||||
TU_VERIFY(ep_num != 0);
|
||||
uint8_t descriptor[TUD_MSC_DESC_LEN] = {
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
uint8_t descriptor[TUD_MSC_DESC_LEN] = {// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), 64)
|
||||
};
|
||||
*itf += 1;
|
||||
@ -165,7 +164,9 @@ int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, u
|
||||
}
|
||||
|
||||
// return resplen must not larger than bufsize
|
||||
if (resplen > bufsize) resplen = bufsize;
|
||||
if (resplen > bufsize) {
|
||||
resplen = bufsize;
|
||||
}
|
||||
|
||||
if (response && (resplen > 0)) {
|
||||
if (in_xfer) {
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
void onStartStop(msc_start_stop_cb cb);
|
||||
void onRead(msc_read_cb cb);
|
||||
void onWrite(msc_write_cb cb);
|
||||
|
||||
private:
|
||||
uint8_t _lun;
|
||||
};
|
||||
|
@ -84,6 +84,7 @@ public:
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
|
||||
protected:
|
||||
uint8_t *rawIPAddress(IPAddress &addr) {
|
||||
return addr.raw_address();
|
||||
|
@ -32,15 +32,17 @@
|
||||
|
||||
String::String(const char *cstr) {
|
||||
init();
|
||||
if (cstr)
|
||||
if (cstr) {
|
||||
copy(cstr, strlen(cstr));
|
||||
}
|
||||
}
|
||||
|
||||
String::String(const char *cstr, unsigned int length) {
|
||||
init();
|
||||
if (cstr)
|
||||
if (cstr) {
|
||||
copy(cstr, length);
|
||||
}
|
||||
}
|
||||
|
||||
String::String(const String &value) {
|
||||
init();
|
||||
@ -154,17 +156,20 @@ inline void String::init(void) {
|
||||
}
|
||||
|
||||
void String::invalidate(void) {
|
||||
if (!isSSO() && wbuffer())
|
||||
if (!isSSO() && wbuffer()) {
|
||||
free(wbuffer());
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
bool String::reserve(unsigned int size) {
|
||||
if (buffer() && capacity() >= size)
|
||||
if (buffer() && capacity() >= size) {
|
||||
return true;
|
||||
}
|
||||
if (changeBuffer(size)) {
|
||||
if (len() == 0)
|
||||
if (len() == 0) {
|
||||
wbuffer()[0] = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -262,34 +267,39 @@ void String::move(String &rhs) {
|
||||
#endif
|
||||
|
||||
String &String::operator=(const String &rhs) {
|
||||
if (this == &rhs)
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
if (rhs.buffer())
|
||||
}
|
||||
if (rhs.buffer()) {
|
||||
copy(rhs.buffer(), rhs.len());
|
||||
else
|
||||
} else {
|
||||
invalidate();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String &String::operator=(String &&rval) {
|
||||
if (this != &rval)
|
||||
if (this != &rval) {
|
||||
move(rval);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
String &String::operator=(StringSumHelper &&rval) {
|
||||
if (this != &rval)
|
||||
if (this != &rval) {
|
||||
move(rval);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
String &String::operator=(const char *cstr) {
|
||||
if (cstr)
|
||||
if (cstr) {
|
||||
copy(cstr, strlen(cstr));
|
||||
else
|
||||
} else {
|
||||
invalidate();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -302,12 +312,15 @@ bool String::concat(const String &s) {
|
||||
// realloc'ing the buffer and moving s.buffer in the method called
|
||||
if (&s == this) {
|
||||
unsigned int newlen = 2 * len();
|
||||
if (!s.buffer())
|
||||
if (!s.buffer()) {
|
||||
return false;
|
||||
if (s.len() == 0)
|
||||
}
|
||||
if (s.len() == 0) {
|
||||
return true;
|
||||
if (!reserve(newlen))
|
||||
}
|
||||
if (!reserve(newlen)) {
|
||||
return false;
|
||||
}
|
||||
memmove(wbuffer() + len(), buffer(), len());
|
||||
setLen(newlen);
|
||||
wbuffer()[len()] = 0;
|
||||
@ -319,25 +332,30 @@ bool String::concat(const String &s) {
|
||||
|
||||
bool String::concat(const char *cstr, unsigned int length) {
|
||||
unsigned int newlen = len() + length;
|
||||
if (!cstr)
|
||||
if (!cstr) {
|
||||
return false;
|
||||
if (length == 0)
|
||||
}
|
||||
if (length == 0) {
|
||||
return true;
|
||||
if (!reserve(newlen))
|
||||
}
|
||||
if (!reserve(newlen)) {
|
||||
return false;
|
||||
if (cstr >= wbuffer() && cstr < wbuffer() + len())
|
||||
}
|
||||
if (cstr >= wbuffer() && cstr < wbuffer() + len()) {
|
||||
// compatible with SSO in ram #6155 (case "x += x.c_str()")
|
||||
memmove(wbuffer() + len(), cstr, length + 1);
|
||||
else
|
||||
} else {
|
||||
// compatible with source in flash #6367
|
||||
memcpy_P(wbuffer() + len(), cstr, length + 1);
|
||||
}
|
||||
setLen(newlen);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool String::concat(const char *cstr) {
|
||||
if (!cstr)
|
||||
if (!cstr) {
|
||||
return false;
|
||||
}
|
||||
return concat(cstr, strlen(cstr));
|
||||
}
|
||||
|
||||
@ -406,85 +424,97 @@ bool String::concat(double num) {
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, const String &rhs) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(rhs.buffer(), rhs.len()))
|
||||
if (!a.concat(rhs.buffer(), rhs.len())) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, const char *cstr) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!cstr || !a.concat(cstr, strlen(cstr)))
|
||||
if (!cstr || !a.concat(cstr, strlen(cstr))) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, char c) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(c))
|
||||
if (!a.concat(c)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, unsigned char num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, int num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, unsigned int num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, long num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, float num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, double num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, long long num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long long num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
|
||||
if (!a.concat(num))
|
||||
if (!a.concat(num)) {
|
||||
a.invalidate();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@ -494,10 +524,12 @@ StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long long num) {
|
||||
|
||||
int String::compareTo(const String &s) const {
|
||||
if (!buffer() || !s.buffer()) {
|
||||
if (s.buffer() && s.len() > 0)
|
||||
if (s.buffer() && s.len() > 0) {
|
||||
return 0 - *(unsigned char *)s.buffer();
|
||||
if (buffer() && len() > 0)
|
||||
}
|
||||
if (buffer() && len() > 0) {
|
||||
return *(unsigned char *)buffer();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return strcmp(buffer(), s.buffer());
|
||||
@ -508,10 +540,12 @@ bool String::equals(const String &s2) const {
|
||||
}
|
||||
|
||||
bool String::equals(const char *cstr) const {
|
||||
if (len() == 0)
|
||||
if (len() == 0) {
|
||||
return (cstr == NULL || *cstr == 0);
|
||||
if (cstr == NULL)
|
||||
}
|
||||
if (cstr == NULL) {
|
||||
return buffer()[0] == 0;
|
||||
}
|
||||
return strcmp(buffer(), cstr) == 0;
|
||||
}
|
||||
|
||||
@ -532,39 +566,46 @@ bool String::operator>=(const String &rhs) const {
|
||||
}
|
||||
|
||||
bool String::equalsIgnoreCase(const String &s2) const {
|
||||
if (this == &s2)
|
||||
if (this == &s2) {
|
||||
return true;
|
||||
if (len() != s2.len())
|
||||
}
|
||||
if (len() != s2.len()) {
|
||||
return false;
|
||||
if (len() == 0)
|
||||
}
|
||||
if (len() == 0) {
|
||||
return true;
|
||||
}
|
||||
const char *p1 = buffer();
|
||||
const char *p2 = s2.buffer();
|
||||
while (*p1) {
|
||||
if (tolower(*p1++) != tolower(*p2++))
|
||||
if (tolower(*p1++) != tolower(*p2++)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned char String::equalsConstantTime(const String &s2) const {
|
||||
// To avoid possible time-based attacks present function
|
||||
// compares given strings in a constant time.
|
||||
if (len() != s2.len())
|
||||
if (len() != s2.len()) {
|
||||
return 0;
|
||||
}
|
||||
//at this point lengths are the same
|
||||
if (len() == 0)
|
||||
if (len() == 0) {
|
||||
return 1;
|
||||
}
|
||||
//at this point lengths are the same and non-zero
|
||||
const char *p1 = buffer();
|
||||
const char *p2 = s2.buffer();
|
||||
unsigned int equalchars = 0;
|
||||
unsigned int diffchars = 0;
|
||||
while (*p1) {
|
||||
if (*p1 == *p2)
|
||||
if (*p1 == *p2) {
|
||||
++equalchars;
|
||||
else
|
||||
} else {
|
||||
++diffchars;
|
||||
}
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
@ -575,20 +616,23 @@ unsigned char String::equalsConstantTime(const String &s2) const {
|
||||
}
|
||||
|
||||
bool String::startsWith(const String &s2) const {
|
||||
if (len() < s2.len())
|
||||
if (len() < s2.len()) {
|
||||
return false;
|
||||
}
|
||||
return startsWith(s2, 0);
|
||||
}
|
||||
|
||||
bool String::startsWith(const String &s2, unsigned int offset) const {
|
||||
if (offset > (unsigned)(len() - s2.len()) || !buffer() || !s2.buffer())
|
||||
if (offset > (unsigned)(len() - s2.len()) || !buffer() || !s2.buffer()) {
|
||||
return false;
|
||||
}
|
||||
return strncmp(&buffer()[offset], s2.buffer(), s2.len()) == 0;
|
||||
}
|
||||
|
||||
bool String::endsWith(const String &s2) const {
|
||||
if (len() < s2.len() || !buffer() || !s2.buffer())
|
||||
if (len() < s2.len() || !buffer() || !s2.buffer()) {
|
||||
return false;
|
||||
}
|
||||
return strcmp(&buffer()[len() - s2.len()], s2.buffer()) == 0;
|
||||
}
|
||||
|
||||
@ -601,9 +645,10 @@ char String::charAt(unsigned int loc) const {
|
||||
}
|
||||
|
||||
void String::setCharAt(unsigned int loc, char c) {
|
||||
if (loc < len())
|
||||
if (loc < len()) {
|
||||
wbuffer()[loc] = c;
|
||||
}
|
||||
}
|
||||
|
||||
char &String::operator[](unsigned int index) {
|
||||
static char dummy_writable_char;
|
||||
@ -615,21 +660,24 @@ char &String::operator[](unsigned int index) {
|
||||
}
|
||||
|
||||
char String::operator[](unsigned int index) const {
|
||||
if (index >= len() || !buffer())
|
||||
if (index >= len() || !buffer()) {
|
||||
return 0;
|
||||
}
|
||||
return buffer()[index];
|
||||
}
|
||||
|
||||
void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const {
|
||||
if (!bufsize || !buf)
|
||||
if (!bufsize || !buf) {
|
||||
return;
|
||||
}
|
||||
if (index >= len()) {
|
||||
buf[0] = 0;
|
||||
return;
|
||||
}
|
||||
unsigned int n = bufsize - 1;
|
||||
if (n > len() - index)
|
||||
if (n > len() - index) {
|
||||
n = len() - index;
|
||||
}
|
||||
strncpy((char *)buf, buffer() + index, n);
|
||||
buf[n] = 0;
|
||||
}
|
||||
@ -643,11 +691,13 @@ int String::indexOf(char c) const {
|
||||
}
|
||||
|
||||
int String::indexOf(char ch, unsigned int fromIndex) const {
|
||||
if (fromIndex >= len())
|
||||
if (fromIndex >= len()) {
|
||||
return -1;
|
||||
}
|
||||
const char *temp = strchr(buffer() + fromIndex, ch);
|
||||
if (temp == NULL)
|
||||
if (temp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return temp - buffer();
|
||||
}
|
||||
|
||||
@ -656,11 +706,13 @@ int String::indexOf(const String &s2) const {
|
||||
}
|
||||
|
||||
int String::indexOf(const String &s2, unsigned int fromIndex) const {
|
||||
if (fromIndex >= len())
|
||||
if (fromIndex >= len()) {
|
||||
return -1;
|
||||
}
|
||||
const char *found = strstr(buffer() + fromIndex, s2.buffer());
|
||||
if (found == NULL)
|
||||
if (found == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return found - buffer();
|
||||
}
|
||||
|
||||
@ -669,17 +721,20 @@ int String::lastIndexOf(char theChar) const {
|
||||
}
|
||||
|
||||
int String::lastIndexOf(char ch, unsigned int fromIndex) const {
|
||||
if (fromIndex >= len())
|
||||
if (fromIndex >= len()) {
|
||||
return -1;
|
||||
}
|
||||
char tempchar = buffer()[fromIndex + 1];
|
||||
wbuffer()[fromIndex + 1] = '\0';
|
||||
char *temp = strrchr(wbuffer(), ch);
|
||||
wbuffer()[fromIndex + 1] = tempchar;
|
||||
if (temp == NULL)
|
||||
if (temp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
const int rv = temp - buffer();
|
||||
if (rv >= len())
|
||||
if (rv >= len()) {
|
||||
return -1;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -688,18 +743,22 @@ int String::lastIndexOf(const String &s2) const {
|
||||
}
|
||||
|
||||
int String::lastIndexOf(const String &s2, unsigned int fromIndex) const {
|
||||
if (s2.len() == 0 || len() == 0 || s2.len() > len())
|
||||
if (s2.len() == 0 || len() == 0 || s2.len() > len()) {
|
||||
return -1;
|
||||
if (fromIndex >= len())
|
||||
}
|
||||
if (fromIndex >= len()) {
|
||||
fromIndex = len() - 1;
|
||||
}
|
||||
int found = -1;
|
||||
for (char *p = wbuffer(); p <= wbuffer() + fromIndex; p++) {
|
||||
p = strstr(p, s2.buffer());
|
||||
if (!p)
|
||||
if (!p) {
|
||||
break;
|
||||
if ((unsigned int)(p - wbuffer()) <= fromIndex)
|
||||
}
|
||||
if ((unsigned int)(p - wbuffer()) <= fromIndex) {
|
||||
found = p - buffer();
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
@ -710,10 +769,12 @@ String String::substring(unsigned int left, unsigned int right) const {
|
||||
left = temp;
|
||||
}
|
||||
String out;
|
||||
if (left >= len())
|
||||
if (left >= len()) {
|
||||
return out;
|
||||
if (right > len())
|
||||
}
|
||||
if (right > len()) {
|
||||
right = len();
|
||||
}
|
||||
out.copy(buffer() + left, right - left);
|
||||
return out;
|
||||
}
|
||||
@ -723,17 +784,20 @@ String String::substring(unsigned int left, unsigned int right) const {
|
||||
/*********************************************/
|
||||
|
||||
void String::replace(char find, char replace) {
|
||||
if (!buffer())
|
||||
if (!buffer()) {
|
||||
return;
|
||||
}
|
||||
for (char *p = wbuffer(); *p; p++) {
|
||||
if (*p == find)
|
||||
if (*p == find) {
|
||||
*p = replace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void String::replace(const String &find, const String &replace) {
|
||||
if (len() == 0 || find.len() == 0)
|
||||
if (len() == 0 || find.len() == 0) {
|
||||
return;
|
||||
}
|
||||
int diff = replace.len() - find.len();
|
||||
char *readFrom = wbuffer();
|
||||
char *foundAt;
|
||||
@ -762,8 +826,9 @@ void String::replace(const String &find, const String &replace) {
|
||||
readFrom = foundAt + find.len();
|
||||
size += diff;
|
||||
}
|
||||
if (size == len())
|
||||
if (size == len()) {
|
||||
return;
|
||||
}
|
||||
if (size > capacity() && !changeBuffer(size)) {
|
||||
log_w("String.Replace() Insufficient space to replace string");
|
||||
return;
|
||||
@ -806,33 +871,39 @@ void String::remove(unsigned int index, unsigned int count) {
|
||||
}
|
||||
|
||||
void String::toLowerCase(void) {
|
||||
if (!buffer())
|
||||
if (!buffer()) {
|
||||
return;
|
||||
}
|
||||
for (char *p = wbuffer(); *p; p++) {
|
||||
*p = tolower(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void String::toUpperCase(void) {
|
||||
if (!buffer())
|
||||
if (!buffer()) {
|
||||
return;
|
||||
}
|
||||
for (char *p = wbuffer(); *p; p++) {
|
||||
*p = toupper(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void String::trim(void) {
|
||||
if (!buffer() || len() == 0)
|
||||
if (!buffer() || len() == 0) {
|
||||
return;
|
||||
}
|
||||
char *begin = wbuffer();
|
||||
while (isspace(*begin))
|
||||
while (isspace(*begin)) {
|
||||
begin++;
|
||||
}
|
||||
char *end = wbuffer() + len() - 1;
|
||||
while (isspace(*end) && end >= begin)
|
||||
while (isspace(*end) && end >= begin) {
|
||||
end--;
|
||||
}
|
||||
unsigned int newlen = end + 1 - begin;
|
||||
if (begin > buffer())
|
||||
if (begin > buffer()) {
|
||||
memmove(wbuffer(), begin, newlen);
|
||||
}
|
||||
setLen(newlen);
|
||||
wbuffer()[newlen] = 0;
|
||||
}
|
||||
@ -842,20 +913,23 @@ void String::trim(void) {
|
||||
/*********************************************/
|
||||
|
||||
long String::toInt(void) const {
|
||||
if (buffer())
|
||||
if (buffer()) {
|
||||
return atol(buffer());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float String::toFloat(void) const {
|
||||
if (buffer())
|
||||
if (buffer()) {
|
||||
return atof(buffer());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
double String::toDouble(void) const {
|
||||
if (buffer())
|
||||
if (buffer()) {
|
||||
return atof(buffer());
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
// A pure abstract class forward used as a means to proide a unique pointer type
|
||||
// but really is never defined.
|
||||
class __FlashStringHelper;
|
||||
@ -47,8 +46,7 @@ class String {
|
||||
// complications of an operator bool(). for more information, see:
|
||||
// http://www.artima.com/cppsource/safebool.html
|
||||
typedef void (String::*StringIfHelperType)() const;
|
||||
void StringIfHelper() const {
|
||||
}
|
||||
void StringIfHelper() const {}
|
||||
|
||||
public:
|
||||
// constructors
|
||||
@ -59,12 +57,10 @@ public:
|
||||
String(const char *cstr = "");
|
||||
String(const char *cstr, unsigned int length);
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String(const uint8_t *cstr, unsigned int length)
|
||||
: String(reinterpret_cast<const char *>(cstr), length) {}
|
||||
String(const uint8_t *cstr, unsigned int length) : String(reinterpret_cast<const char *>(cstr), length) {}
|
||||
#endif
|
||||
String(const String &str);
|
||||
String(const __FlashStringHelper *str)
|
||||
: String(reinterpret_cast<const char *>(str)) {}
|
||||
String(const __FlashStringHelper *str) : String(reinterpret_cast<const char *>(str)) {}
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String(String &&rval);
|
||||
String(StringSumHelper &&rval);
|
||||
@ -322,16 +318,22 @@ protected:
|
||||
uint32_t len;
|
||||
};
|
||||
// This allows strings up up to 11 (10 + \0 termination) without any extra space.
|
||||
enum { SSOSIZE = sizeof(struct _ptr) + 4 - 1 }; // Characters to allocate space for SSO, must be 12 or more
|
||||
enum {
|
||||
SSOSIZE = sizeof(struct _ptr) + 4 - 1
|
||||
}; // Characters to allocate space for SSO, must be 12 or more
|
||||
struct _sso {
|
||||
char buff[SSOSIZE];
|
||||
unsigned char len : 7; // Ensure only one byte is allocated by GCC for the bitfields
|
||||
unsigned char isSSO : 1;
|
||||
} __attribute__((packed)); // Ensure that GCC doesn't expand the flag byte to a 32-bit word for alignment issues
|
||||
#ifdef BOARD_HAS_PSRAM
|
||||
enum { CAPACITY_MAX = 3145728 };
|
||||
enum {
|
||||
CAPACITY_MAX = 3145728
|
||||
};
|
||||
#else
|
||||
enum { CAPACITY_MAX = 65535 };
|
||||
enum {
|
||||
CAPACITY_MAX = 65535
|
||||
};
|
||||
#endif
|
||||
union {
|
||||
struct _ptr ptr;
|
||||
@ -362,10 +364,14 @@ protected:
|
||||
}
|
||||
}
|
||||
inline void setCapacity(int cap) {
|
||||
if (!isSSO()) ptr.cap = cap;
|
||||
if (!isSSO()) {
|
||||
ptr.cap = cap;
|
||||
}
|
||||
}
|
||||
inline void setBuffer(char *buff) {
|
||||
if (!isSSO()) ptr.buff = buff;
|
||||
if (!isSSO()) {
|
||||
ptr.buff = buff;
|
||||
}
|
||||
}
|
||||
// Buffer accessor functions
|
||||
inline const char *buffer() const {
|
||||
@ -392,42 +398,18 @@ protected:
|
||||
|
||||
class StringSumHelper : public String {
|
||||
public:
|
||||
StringSumHelper(const String &s)
|
||||
: String(s) {
|
||||
}
|
||||
StringSumHelper(const char *p)
|
||||
: String(p) {
|
||||
}
|
||||
StringSumHelper(char c)
|
||||
: String(c) {
|
||||
}
|
||||
StringSumHelper(unsigned char num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(int num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(unsigned int num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(long num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(unsigned long num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(float num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(double num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(long long num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(unsigned long long num)
|
||||
: String(num) {
|
||||
}
|
||||
StringSumHelper(const String &s) : String(s) {}
|
||||
StringSumHelper(const char *p) : String(p) {}
|
||||
StringSumHelper(char c) : String(c) {}
|
||||
StringSumHelper(unsigned char num) : String(num) {}
|
||||
StringSumHelper(int num) : String(num) {}
|
||||
StringSumHelper(unsigned int num) : String(num) {}
|
||||
StringSumHelper(long num) : String(num) {}
|
||||
StringSumHelper(unsigned long num) : String(num) {}
|
||||
StringSumHelper(float num) : String(num) {}
|
||||
StringSumHelper(double num) : String(num) {}
|
||||
StringSumHelper(long long num) : String(num) {}
|
||||
StringSumHelper(unsigned long long num) : String(num) {}
|
||||
};
|
||||
|
||||
inline StringSumHelper &operator+(const StringSumHelper &lhs, const __FlashStringHelper *rhs) {
|
||||
|
@ -5,8 +5,8 @@ class base64 {
|
||||
public:
|
||||
static String encode(const uint8_t *data, size_t length);
|
||||
static String encode(const String &text);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* CORE_BASE64_H_ */
|
||||
|
@ -30,12 +30,18 @@
|
||||
#define CBUF_MUTEX_CREATE() \
|
||||
if (_lock == NULL) { \
|
||||
_lock = xSemaphoreCreateMutex(); \
|
||||
if (_lock == NULL) { log_e("failed to create mutex"); } \
|
||||
if (_lock == NULL) { \
|
||||
log_e("failed to create mutex"); \
|
||||
} \
|
||||
}
|
||||
#define CBUF_MUTEX_LOCK() \
|
||||
if (_lock != NULL) { xSemaphoreTakeRecursive(_lock, portMAX_DELAY); }
|
||||
if (_lock != NULL) { \
|
||||
xSemaphoreTakeRecursive(_lock, portMAX_DELAY); \
|
||||
}
|
||||
#define CBUF_MUTEX_UNLOCK() \
|
||||
if (_lock != NULL) { xSemaphoreGiveRecursive(_lock); }
|
||||
if (_lock != NULL) { \
|
||||
xSemaphoreGiveRecursive(_lock); \
|
||||
}
|
||||
#define CBUF_MUTEX_DELETE() \
|
||||
if (_lock != NULL) { \
|
||||
SemaphoreHandle_t l = _lock; \
|
||||
@ -44,11 +50,7 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
cbuf::cbuf(size_t size)
|
||||
: next(NULL),
|
||||
has_peek(false),
|
||||
peek_byte(0),
|
||||
_buf(xRingbufferCreate(size, RINGBUF_TYPE_BYTEBUF)) {
|
||||
cbuf::cbuf(size_t size) : next(NULL), has_peek(false), peek_byte(0), _buf(xRingbufferCreate(size, RINGBUF_TYPE_BYTEBUF)) {
|
||||
if (_buf == NULL) {
|
||||
log_e("failed to allocate ring buffer");
|
||||
}
|
||||
@ -136,7 +138,9 @@ size_t cbuf::available() const {
|
||||
if (_buf != NULL) {
|
||||
vRingbufferGetInfo(_buf, NULL, NULL, NULL, NULL, (UBaseType_t *)&available);
|
||||
}
|
||||
if (has_peek) available++;
|
||||
if (has_peek) {
|
||||
available++;
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,9 @@ void printBeforeSetupInfo(void) {
|
||||
Serial.begin(0);
|
||||
Serial.setDebugOutput(true);
|
||||
uint8_t t = 0;
|
||||
while (!Serial && (t++ < 200)) delay(10); //wait up to 2 seconds for the IDE to connect
|
||||
while (!Serial && (t++ < 200)) {
|
||||
delay(10); //wait up to 2 seconds for the IDE to connect
|
||||
}
|
||||
#endif
|
||||
chip_report_printf("=========== Before Setup Start ===========\n");
|
||||
printChipInfo();
|
||||
|
@ -456,7 +456,6 @@ esp_err_t __analogContinuousInit(adc_channel_t *channel, uint8_t channel_num, ad
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
bool analogContinuous(uint8_t pins[], size_t pins_count, uint32_t conversions_per_pin, uint32_t sampling_freq_hz, void (*userFunc)(void)) {
|
||||
adc_channel_t channel[pins_count];
|
||||
adc_unit_t adc_unit;
|
||||
|
@ -126,7 +126,6 @@ extern "C" {
|
||||
* */
|
||||
void analogContinuousSetWidth(uint8_t bits);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -51,18 +51,10 @@ bool btStartMode(bt_mode mode) {
|
||||
esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
switch (mode) {
|
||||
case BT_MODE_BLE:
|
||||
esp_bt_mode = ESP_BT_MODE_BLE;
|
||||
break;
|
||||
case BT_MODE_CLASSIC_BT:
|
||||
esp_bt_mode = ESP_BT_MODE_CLASSIC_BT;
|
||||
break;
|
||||
case BT_MODE_BTDM:
|
||||
esp_bt_mode = ESP_BT_MODE_BTDM;
|
||||
break;
|
||||
default:
|
||||
esp_bt_mode = BT_MODE;
|
||||
break;
|
||||
case BT_MODE_BLE: esp_bt_mode = ESP_BT_MODE_BLE; break;
|
||||
case BT_MODE_CLASSIC_BT: esp_bt_mode = ESP_BT_MODE_CLASSIC_BT; break;
|
||||
case BT_MODE_BTDM: esp_bt_mode = ESP_BT_MODE_BTDM; break;
|
||||
default: esp_bt_mode = BT_MODE; break;
|
||||
}
|
||||
// esp_bt_controller_enable(MODE) This mode must be equal as the mode in “cfg” of esp_bt_controller_init().
|
||||
cfg.mode = esp_bt_mode;
|
||||
@ -107,8 +99,7 @@ bool btStop() {
|
||||
log_e("BT Disable failed");
|
||||
return false;
|
||||
}
|
||||
while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED)
|
||||
;
|
||||
while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
|
||||
}
|
||||
if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) {
|
||||
if (esp_bt_controller_deinit()) {
|
||||
|
@ -24,10 +24,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { BT_MODE_DEFAULT,
|
||||
typedef enum {
|
||||
BT_MODE_DEFAULT,
|
||||
BT_MODE_BLE,
|
||||
BT_MODE_CLASSIC_BT,
|
||||
BT_MODE_BTDM } bt_mode;
|
||||
BT_MODE_BTDM
|
||||
} bt_mode;
|
||||
|
||||
bool btStarted();
|
||||
bool btStart();
|
||||
|
@ -60,7 +60,6 @@ typedef struct apb_change_cb_s {
|
||||
apb_change_cb_t cb;
|
||||
} apb_change_t;
|
||||
|
||||
|
||||
static apb_change_t *apb_change_callbacks = NULL;
|
||||
static SemaphoreHandle_t apb_change_lock = NULL;
|
||||
|
||||
@ -80,13 +79,15 @@ static void triggerApbChangeCallback(apb_change_ev_t ev_type, uint32_t old_apb,
|
||||
xSemaphoreTake(apb_change_lock, portMAX_DELAY);
|
||||
apb_change_t *r = apb_change_callbacks;
|
||||
if (r != NULL) {
|
||||
if (ev_type == APB_BEFORE_CHANGE)
|
||||
if (ev_type == APB_BEFORE_CHANGE) {
|
||||
while (r != NULL) {
|
||||
r->cb(r->arg, ev_type, old_apb, new_apb);
|
||||
r = r->next;
|
||||
}
|
||||
else { // run backwards through chain
|
||||
while (r->next != NULL) r = r->next; // find first added
|
||||
} else { // run backwards through chain
|
||||
while (r->next != NULL) {
|
||||
r = r->next; // find first added
|
||||
}
|
||||
while (r != NULL) {
|
||||
r->cb(r->arg, ev_type, old_apb, new_apb);
|
||||
r = r->prev;
|
||||
@ -113,7 +114,9 @@ bool addApbChangeCallback(void* arg, apb_change_cb_t cb) {
|
||||
} else {
|
||||
apb_change_t *r = apb_change_callbacks;
|
||||
// look for duplicate callbacks
|
||||
while ((r != NULL) && !((r->cb == cb) && (r->arg == arg))) r = r->next;
|
||||
while ((r != NULL) && !((r->cb == cb) && (r->arg == arg))) {
|
||||
r = r->next;
|
||||
}
|
||||
if (r) {
|
||||
log_e("duplicate func=%8p arg=%8p", c->cb, c->arg);
|
||||
free(c);
|
||||
@ -134,18 +137,23 @@ bool removeApbChangeCallback(void* arg, apb_change_cb_t cb) {
|
||||
xSemaphoreTake(apb_change_lock, portMAX_DELAY);
|
||||
apb_change_t *r = apb_change_callbacks;
|
||||
// look for matching callback
|
||||
while ((r != NULL) && !((r->cb == cb) && (r->arg == arg))) r = r->next;
|
||||
while ((r != NULL) && !((r->cb == cb) && (r->arg == arg))) {
|
||||
r = r->next;
|
||||
}
|
||||
if (r == NULL) {
|
||||
log_e("not found func=%8p arg=%8p", cb, arg);
|
||||
xSemaphoreGive(apb_change_lock);
|
||||
return false;
|
||||
} else {
|
||||
// patch links
|
||||
if (r->prev) r->prev->next = r->next;
|
||||
else { // this is first link
|
||||
if (r->prev) {
|
||||
r->prev->next = r->next;
|
||||
} else { // this is first link
|
||||
apb_change_callbacks = r->next;
|
||||
}
|
||||
if (r->next) r->next->prev = r->prev;
|
||||
if (r->next) {
|
||||
r->next->prev = r->prev;
|
||||
}
|
||||
free(r);
|
||||
}
|
||||
xSemaphoreGive(apb_change_lock);
|
||||
@ -253,9 +261,17 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz) {
|
||||
triggerApbChangeCallback(APB_AFTER_CHANGE, capb, apb);
|
||||
}
|
||||
#ifdef SOC_CLK_APLL_SUPPORTED
|
||||
log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL) ? "PLL" : ((conf.source == RTC_CPU_FREQ_SRC_APLL) ? "APLL" : ((conf.source == RTC_CPU_FREQ_SRC_XTAL) ? "XTAL" : "8M")), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb);
|
||||
log_d(
|
||||
"%s: %u / %u = %u Mhz, APB: %u Hz",
|
||||
(conf.source == RTC_CPU_FREQ_SRC_PLL) ? "PLL"
|
||||
: ((conf.source == RTC_CPU_FREQ_SRC_APLL) ? "APLL" : ((conf.source == RTC_CPU_FREQ_SRC_XTAL) ? "XTAL" : "8M")),
|
||||
conf.source_freq_mhz, conf.div, conf.freq_mhz, apb
|
||||
);
|
||||
#else
|
||||
log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL) ? "PLL" : ((conf.source == RTC_CPU_FREQ_SRC_XTAL) ? "XTAL" : "17.5M"), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb);
|
||||
log_d(
|
||||
"%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL) ? "PLL" : ((conf.source == RTC_CPU_FREQ_SRC_XTAL) ? "XTAL" : "17.5M"),
|
||||
conf.source_freq_mhz, conf.div, conf.freq_mhz, apb
|
||||
);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -23,8 +23,10 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum { APB_BEFORE_CHANGE,
|
||||
APB_AFTER_CHANGE } apb_change_ev_t;
|
||||
typedef enum {
|
||||
APB_BEFORE_CHANGE,
|
||||
APB_AFTER_CHANGE
|
||||
} apb_change_ev_t;
|
||||
|
||||
typedef void (*apb_change_cb_t)(void *arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb);
|
||||
|
||||
|
@ -35,9 +35,7 @@ bool __dacWrite(uint8_t pin, uint8_t value) {
|
||||
return false;
|
||||
}
|
||||
dac_channel_t channel = (pin == DAC_CHAN0_GPIO_NUM) ? DAC_CHAN_0 : DAC_CHAN_1;
|
||||
dac_oneshot_config_t config = {
|
||||
.chan_id = channel
|
||||
};
|
||||
dac_oneshot_config_t config = {.chan_id = channel};
|
||||
err = dac_oneshot_new_channel(&config, &bus);
|
||||
if (err != ESP_OK) {
|
||||
log_e("dac_oneshot_new_channel failed with error: %d", err);
|
||||
|
@ -199,7 +199,9 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
|
||||
static bool interrupt_initialized = false;
|
||||
|
||||
// makes sure that pin -1 (255) will never work -- this follows Arduino standard
|
||||
if (pin >= SOC_GPIO_PIN_COUNT) return;
|
||||
if (pin >= SOC_GPIO_PIN_COUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!interrupt_initialized) {
|
||||
esp_err_t err = gpio_install_isr_service((int)ARDUINO_ISR_FLAG);
|
||||
@ -224,7 +226,6 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
|
||||
}
|
||||
gpio_isr_handler_add((gpio_num_t)pin, __onPinInterrupt, &__pinInterruptHandlers[pin]);
|
||||
|
||||
|
||||
//FIX interrupts on peripherals outputs (eg. LEDC,...)
|
||||
//Enable input in GPIO register
|
||||
gpio_hal_context_t gpiohal;
|
||||
@ -262,7 +263,6 @@ extern void disableInterrupt(uint8_t pin) {
|
||||
gpio_intr_disable((gpio_num_t)pin);
|
||||
}
|
||||
|
||||
|
||||
extern void pinMode(uint8_t pin, uint8_t mode) __attribute__((weak, alias("__pinMode")));
|
||||
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__((weak, alias("__digitalWrite")));
|
||||
extern int digitalRead(uint8_t pin) __attribute__((weak, alias("__digitalRead")));
|
||||
|
@ -64,13 +64,11 @@ extern "C" {
|
||||
#define ONLOW_WE 0x0C
|
||||
#define ONHIGH_WE 0x0D
|
||||
|
||||
|
||||
#define digitalPinIsValid(pin) GPIO_IS_VALID_GPIO(pin)
|
||||
#define digitalPinCanOutput(pin) GPIO_IS_VALID_OUTPUT_GPIO(pin)
|
||||
|
||||
#define digitalPinToRtcPin(pin) ((RTC_GPIO_IS_VALID_GPIO(pin)) ? rtc_io_number_get(pin) : -1)
|
||||
#define digitalPinToDacChannel(pin) (((pin) == DAC_CHANNEL_1_GPIO_NUM) ? 0 : ((pin) == DAC_CHANNEL_2_GPIO_NUM) ? 1 \
|
||||
: -1)
|
||||
#define digitalPinToDacChannel(pin) (((pin) == DAC_CHANNEL_1_GPIO_NUM) ? 0 : ((pin) == DAC_CHANNEL_2_GPIO_NUM) ? 1 : -1)
|
||||
|
||||
void pinMode(uint8_t pin, uint8_t mode);
|
||||
void digitalWrite(uint8_t pin, uint8_t val);
|
||||
|
@ -121,9 +121,13 @@ static i2c_slave_struct_t _i2c_bus_array[SOC_I2C_NUM] = {
|
||||
#define I2C_SLAVE_MUTEX_UNLOCK()
|
||||
#else
|
||||
#define I2C_SLAVE_MUTEX_LOCK() \
|
||||
if (i2c->lock) { xSemaphoreTake(i2c->lock, portMAX_DELAY); }
|
||||
if (i2c->lock) { \
|
||||
xSemaphoreTake(i2c->lock, portMAX_DELAY); \
|
||||
}
|
||||
#define I2C_SLAVE_MUTEX_UNLOCK() \
|
||||
if (i2c->lock) { xSemaphoreGive(i2c->lock); }
|
||||
if (i2c->lock) { \
|
||||
xSemaphoreGive(i2c->lock); \
|
||||
}
|
||||
#endif
|
||||
|
||||
//-------------------------------------- HAL_LL (Missing Functions) ------------------------------------------------
|
||||
@ -356,7 +360,8 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t
|
||||
i2c_ll_slave_enable_rx_it(i2c->dev);
|
||||
i2c_ll_set_stretch(i2c->dev, 0x3FF);
|
||||
i2c_ll_update(i2c->dev);
|
||||
if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_SLAVE_SDA, (void *)(i2c->num + 1), i2c->num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_SLAVE_SCL, (void *)(i2c->num + 1), i2c->num, -1)) {
|
||||
if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_SLAVE_SDA, (void *)(i2c->num + 1), i2c->num, -1)
|
||||
|| !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_SLAVE_SCL, (void *)(i2c->num + 1), i2c->num, -1)) {
|
||||
i2cSlaveDetachBus((void *)(i2c->num + 1));
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
@ -528,21 +533,15 @@ static void i2c_slave_delay_us(uint64_t us) {
|
||||
if (us) {
|
||||
uint64_t e = (m + us);
|
||||
if (m > e) { //overflow
|
||||
while ((uint64_t)esp_timer_get_time() > e)
|
||||
;
|
||||
while ((uint64_t)esp_timer_get_time() > e);
|
||||
}
|
||||
while ((uint64_t)esp_timer_get_time() < e)
|
||||
;
|
||||
while ((uint64_t)esp_timer_get_time() < e);
|
||||
}
|
||||
}
|
||||
|
||||
static void i2c_slave_gpio_mode(int8_t pin, gpio_mode_t mode) {
|
||||
gpio_config_t conf = {
|
||||
.pin_bit_mask = 1LL << pin,
|
||||
.mode = mode,
|
||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE
|
||||
.pin_bit_mask = 1LL << pin, .mode = mode, .pull_up_en = GPIO_PULLUP_ENABLE, .pull_down_en = GPIO_PULLDOWN_DISABLE, .intr_type = GPIO_INTR_DISABLE
|
||||
};
|
||||
gpio_config(&conf);
|
||||
}
|
||||
@ -735,8 +734,7 @@ static void i2c_slave_isr_handler(void *arg) {
|
||||
//reset TX data
|
||||
i2c_ll_txfifo_rst(i2c->dev);
|
||||
uint8_t d;
|
||||
while (xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t *const)&pxHigherPriorityTaskWoken) == pdTRUE)
|
||||
; //flush partial write
|
||||
while (xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t *const)&pxHigherPriorityTaskWoken) == pdTRUE); //flush partial write
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -794,10 +792,7 @@ static size_t i2c_slave_read_rx(i2c_slave_struct_t *i2c, uint8_t *data, size_t l
|
||||
}
|
||||
return (data) ? len : 0;
|
||||
#else
|
||||
size_t dlen = 0,
|
||||
to_read = len,
|
||||
so_far = 0,
|
||||
available = 0;
|
||||
size_t dlen = 0, to_read = len, so_far = 0, available = 0;
|
||||
uint8_t *rx_data = NULL;
|
||||
|
||||
vRingbufferGetInfo(i2c->rx_ring_buf, NULL, NULL, NULL, NULL, &available);
|
||||
|
@ -131,7 +131,8 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency) {
|
||||
bus[i2c_num].sda = sda;
|
||||
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2
|
||||
i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT);
|
||||
if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER_SDA, (void *)(i2c_num + 1), i2c_num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER_SCL, (void *)(i2c_num + 1), i2c_num, -1)) {
|
||||
if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER_SDA, (void *)(i2c_num + 1), i2c_num, -1)
|
||||
|| !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER_SCL, (void *)(i2c_num + 1), i2c_num, -1)) {
|
||||
i2cDetachBus((void *)(i2c_num + 1));
|
||||
return false;
|
||||
}
|
||||
@ -259,7 +260,9 @@ esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t *buff, size_t size,
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t i2cWriteReadNonStop(uint8_t i2c_num, uint16_t address, const uint8_t *wbuff, size_t wsize, uint8_t *rbuff, size_t rsize, uint32_t timeOutMillis, size_t *readCount) {
|
||||
esp_err_t i2cWriteReadNonStop(
|
||||
uint8_t i2c_num, uint16_t address, const uint8_t *wbuff, size_t wsize, uint8_t *rbuff, size_t rsize, uint32_t timeOutMillis, size_t *readCount
|
||||
) {
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
if (i2c_num >= SOC_I2C_NUM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
|
@ -34,7 +34,9 @@ extern "C" {
|
||||
esp_err_t i2cGetClock(uint8_t i2c_num, uint32_t *frequency);
|
||||
esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t *buff, size_t size, uint32_t timeOutMillis);
|
||||
esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t *buff, size_t size, uint32_t timeOutMillis, size_t *readCount);
|
||||
esp_err_t i2cWriteReadNonStop(uint8_t i2c_num, uint16_t address, const uint8_t* wbuff, size_t wsize, uint8_t* rbuff, size_t rsize, uint32_t timeOutMillis, size_t* readCount);
|
||||
esp_err_t i2cWriteReadNonStop(
|
||||
uint8_t i2c_num, uint16_t address, const uint8_t *wbuff, size_t wsize, uint8_t *rbuff, size_t rsize, uint32_t timeOutMillis, size_t *readCount
|
||||
);
|
||||
bool i2cIsInit(uint8_t i2c_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -86,13 +86,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
|
||||
|
||||
uint8_t group = (channel / 8), timer = ((channel / 2) % 4);
|
||||
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = group,
|
||||
.timer_num = timer,
|
||||
.duty_resolution = resolution,
|
||||
.freq_hz = freq,
|
||||
.clk_cfg = LEDC_DEFAULT_CLK
|
||||
};
|
||||
ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = resolution, .freq_hz = freq, .clk_cfg = LEDC_DEFAULT_CLK};
|
||||
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
|
||||
log_e("ledc setup failed!");
|
||||
return false;
|
||||
@ -101,13 +95,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
|
||||
uint32_t duty = ledc_get_duty(group, channel);
|
||||
|
||||
ledc_channel_config_t ledc_channel = {
|
||||
.speed_mode = group,
|
||||
.channel = (channel % 8),
|
||||
.timer_sel = timer,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.gpio_num = pin,
|
||||
.duty = duty,
|
||||
.hpoint = 0
|
||||
.speed_mode = group, .channel = (channel % 8), .timer_sel = timer, .intr_type = LEDC_INTR_DISABLE, .gpio_num = pin, .duty = duty, .hpoint = 0
|
||||
};
|
||||
ledc_channel_config(&ledc_channel);
|
||||
|
||||
@ -184,7 +172,6 @@ uint32_t ledcReadFreq(uint8_t pin) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) {
|
||||
ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC);
|
||||
if (bus != NULL) {
|
||||
@ -196,13 +183,7 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) {
|
||||
|
||||
uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4);
|
||||
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = group,
|
||||
.timer_num = timer,
|
||||
.duty_resolution = 10,
|
||||
.freq_hz = freq,
|
||||
.clk_cfg = LEDC_DEFAULT_CLK
|
||||
};
|
||||
ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = 10, .freq_hz = freq, .clk_cfg = LEDC_DEFAULT_CLK};
|
||||
|
||||
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
|
||||
log_e("ledcWriteTone configuration failed!");
|
||||
@ -218,8 +199,7 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) {
|
||||
}
|
||||
|
||||
uint32_t ledcWriteNote(uint8_t pin, note_t note, uint8_t octave) {
|
||||
const uint16_t noteFrequencyBase[12] = {
|
||||
// C C# D Eb E F F# G G# A Bb B
|
||||
const uint16_t noteFrequencyBase[12] = {// C C# D Eb E F F# G G# A Bb B
|
||||
4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902
|
||||
};
|
||||
|
||||
@ -254,13 +234,7 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) {
|
||||
}
|
||||
uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4);
|
||||
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = group,
|
||||
.timer_num = timer,
|
||||
.duty_resolution = resolution,
|
||||
.freq_hz = freq,
|
||||
.clk_cfg = LEDC_DEFAULT_CLK
|
||||
};
|
||||
ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = resolution, .freq_hz = freq, .clk_cfg = LEDC_DEFAULT_CLK};
|
||||
|
||||
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
|
||||
log_e("ledcChangeFrequency failed!");
|
||||
@ -336,9 +310,7 @@ static bool ledcFadeConfig(uint8_t pin, uint32_t start_duty, uint32_t target_dut
|
||||
bus->fn = (voidFuncPtr)userFunc;
|
||||
bus->arg = arg;
|
||||
|
||||
ledc_cbs_t callbacks = {
|
||||
.fade_cb = ledcFnWrapper
|
||||
};
|
||||
ledc_cbs_t callbacks = {.fade_cb = ledcFnWrapper};
|
||||
ledc_cb_register(group, channel, &callbacks, (void *)bus);
|
||||
|
||||
//Fixing if all bits in resolution is set = LEDC FULL ON
|
||||
@ -359,8 +331,7 @@ static bool ledcFadeConfig(uint8_t pin, uint32_t start_duty, uint32_t target_dut
|
||||
return false;
|
||||
}
|
||||
// Wait for LEDCs next PWM cycle to update duty (~ 1-2 ms)
|
||||
while (ledc_get_duty(group, channel) != start_duty)
|
||||
;
|
||||
while (ledc_get_duty(group, channel) != start_duty);
|
||||
|
||||
if (ledc_set_fade_time_and_start(group, channel, target_duty, max_fade_time_ms, LEDC_FADE_NO_WAIT) != ESP_OK) {
|
||||
log_e("ledc_set_fade_time_and_start failed");
|
||||
|
@ -80,14 +80,14 @@ extern "C" {
|
||||
#define ARDUHAL_LOG_COLOR_PRINT_END
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
const char *pathToFileName(const char *path);
|
||||
int log_printf(const char *fmt, ...);
|
||||
void log_print_buf(const uint8_t *b, size_t len);
|
||||
|
||||
#define ARDUHAL_SHORT_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_##letter format ARDUHAL_LOG_RESET_COLOR "\r\n"
|
||||
#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_##letter "[%6u][" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", (unsigned long)(esp_timer_get_time() / 1000ULL), pathToFileName(__FILE__), __LINE__, __FUNCTION__
|
||||
#define ARDUHAL_LOG_FORMAT(letter, format) \
|
||||
ARDUHAL_LOG_COLOR_##letter "[%6u][" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", (unsigned long)(esp_timer_get_time() / 1000ULL), \
|
||||
pathToFileName(__FILE__), __LINE__, __FUNCTION__
|
||||
|
||||
//esp_rom_printf(DRAM_STR("ST:%d\n"), frame_pos);
|
||||
|
||||
@ -103,11 +103,17 @@ extern "C" {
|
||||
} while (0)
|
||||
#else
|
||||
#define log_v(format, ...) \
|
||||
do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define isr_log_v(format, ...) \
|
||||
do { ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define log_buf_v(b, l) \
|
||||
do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE); } while (0)
|
||||
do { \
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE); \
|
||||
} while (0)
|
||||
#endif
|
||||
#else
|
||||
#define log_v(format, ...) \
|
||||
@ -133,11 +139,17 @@ extern "C" {
|
||||
} while (0)
|
||||
#else
|
||||
#define log_d(format, ...) \
|
||||
do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define isr_log_d(format, ...) \
|
||||
do { ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define log_buf_d(b, l) \
|
||||
do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG); } while (0)
|
||||
do { \
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG); \
|
||||
} while (0)
|
||||
#endif
|
||||
#else
|
||||
#define log_d(format, ...) \
|
||||
@ -163,11 +175,17 @@ extern "C" {
|
||||
} while (0)
|
||||
#else
|
||||
#define log_i(format, ...) \
|
||||
do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define isr_log_i(format, ...) \
|
||||
do { ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define log_buf_i(b, l) \
|
||||
do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO); } while (0)
|
||||
do { \
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO); \
|
||||
} while (0)
|
||||
#endif
|
||||
#else
|
||||
#define log_i(format, ...) \
|
||||
@ -193,11 +211,17 @@ extern "C" {
|
||||
} while (0)
|
||||
#else
|
||||
#define log_w(format, ...) \
|
||||
do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define isr_log_w(format, ...) \
|
||||
do { ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define log_buf_w(b, l) \
|
||||
do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN); } while (0)
|
||||
do { \
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN); \
|
||||
} while (0)
|
||||
#endif
|
||||
#else
|
||||
#define log_w(format, ...) \
|
||||
@ -223,11 +247,17 @@ extern "C" {
|
||||
} while (0)
|
||||
#else
|
||||
#define log_e(format, ...) \
|
||||
do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define isr_log_e(format, ...) \
|
||||
do { ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define log_buf_e(b, l) \
|
||||
do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); } while (0)
|
||||
do { \
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); \
|
||||
} while (0)
|
||||
#endif
|
||||
#else
|
||||
#define log_e(format, ...) \
|
||||
@ -253,11 +283,17 @@ extern "C" {
|
||||
} while (0)
|
||||
#else
|
||||
#define log_n(format, ...) \
|
||||
do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define isr_log_n(format, ...) \
|
||||
do { ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0)
|
||||
do { \
|
||||
ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define log_buf_n(b, l) \
|
||||
do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); } while (0)
|
||||
do { \
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); \
|
||||
} while (0)
|
||||
#endif
|
||||
#else
|
||||
#define log_n(format, ...) \
|
||||
|
@ -41,7 +41,6 @@
|
||||
#define GPIO_MATRIX_CONST_ONE_INPUT GPIO_FUNC_IN_HIGH
|
||||
#endif
|
||||
|
||||
|
||||
void ARDUINO_ISR_ATTR pinMatrixOutAttach(uint8_t pin, uint8_t function, bool invertOut, bool invertEnable) {
|
||||
gpio_matrix_out(pin, function, invertOut, invertEnable);
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
#ifndef _ESP32_HAL_MATRIX_H_
|
||||
#define _ESP32_HAL_MATRIX_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -176,13 +176,10 @@ void disableCore1WDT() {
|
||||
}
|
||||
#endif
|
||||
|
||||
BaseType_t xTaskCreateUniversal(TaskFunction_t pxTaskCode,
|
||||
const char *const pcName,
|
||||
const uint32_t usStackDepth,
|
||||
void *const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *const pxCreatedTask,
|
||||
const BaseType_t xCoreID) {
|
||||
BaseType_t xTaskCreateUniversal(
|
||||
TaskFunction_t pxTaskCode, const char *const pcName, const uint32_t usStackDepth, void *const pvParameters, UBaseType_t uxPriority,
|
||||
TaskHandle_t *const pxCreatedTask, const BaseType_t xCoreID
|
||||
) {
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
if (xCoreID >= 0 && xCoreID < 2) {
|
||||
return xTaskCreatePinnedToCore(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, xCoreID);
|
||||
|
@ -39,7 +39,6 @@ __attribute__((weak)) bool testSPIRAM(void) {
|
||||
return esp_psram_extram_test();
|
||||
}
|
||||
|
||||
|
||||
bool psramInit() {
|
||||
if (spiramDetected) {
|
||||
return true;
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "esp32-hal-rgb-led.h"
|
||||
|
||||
|
||||
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {
|
||||
#if SOC_RMT_SUPPORTED
|
||||
rmt_data_t led_data[24];
|
||||
|
@ -46,7 +46,6 @@ extern TaskHandle_t loopTaskHandle;
|
||||
#define RMT_MUTEX_UNLOCK(busptr) xSemaphoreGive(busptr->g_rmt_objlocks)
|
||||
#endif /* CONFIG_DISABLE_HAL_LOCKS */
|
||||
|
||||
|
||||
/**
|
||||
Typedefs for internal structures, enums
|
||||
*/
|
||||
@ -303,7 +302,10 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl
|
||||
}
|
||||
|
||||
log_v("GPIO: %d - Request: %d RMT Symbols - %s - Timeout: %d", pin, num_rmt_symbols, blocking ? "Blocking" : "Non-Blocking", timeout_ms);
|
||||
log_v("GPIO: %d - Currently in Loop Mode: [%s] | Asked to Loop: %s, LoopCancel: %s", pin, bus->rmt_ch_is_looping ? "YES" : "NO", loop ? "YES" : "NO", loopCancel ? "YES" : "NO");
|
||||
log_v(
|
||||
"GPIO: %d - Currently in Loop Mode: [%s] | Asked to Loop: %s, LoopCancel: %s", pin, bus->rmt_ch_is_looping ? "YES" : "NO", loop ? "YES" : "NO",
|
||||
loopCancel ? "YES" : "NO"
|
||||
);
|
||||
|
||||
if ((xEventGroupGetBits(bus->rmt_events) & RMT_FLAG_TX_DONE) == 0) {
|
||||
log_v("GPIO %d - RMT Write still pending to be completed.", pin);
|
||||
@ -348,8 +350,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl
|
||||
} else {
|
||||
if (blocking) {
|
||||
// wait for transmission confirmation | timeout
|
||||
retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_TX_DONE, pdFALSE /* do not clear on exit */,
|
||||
pdFALSE /* wait for all bits */, timeout_ms)
|
||||
retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_TX_DONE, pdFALSE /* do not clear on exit */, pdFALSE /* wait for all bits */, timeout_ms)
|
||||
& RMT_FLAG_TX_DONE)
|
||||
!= 0;
|
||||
}
|
||||
@ -387,8 +388,7 @@ static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool wa
|
||||
rmt_receive(bus->rmt_channel_h, data, *num_rmt_symbols * sizeof(rmt_data_t), &receive_config);
|
||||
// wait for data if requested
|
||||
if (waitForData) {
|
||||
retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_RX_DONE, pdFALSE /* do not clear on exit */,
|
||||
pdFALSE /* wait for all bits */, timeout_ms)
|
||||
retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_RX_DONE, pdFALSE /* do not clear on exit */, pdFALSE /* wait for all bits */, timeout_ms)
|
||||
& RMT_FLAG_RX_DONE)
|
||||
!= 0;
|
||||
}
|
||||
@ -397,7 +397,6 @@ static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool wa
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeout_ms) {
|
||||
return _rmtWrite(pin, data, num_rmt_symbols, true /*blocks*/, false /*looping*/, timeout_ms);
|
||||
}
|
||||
@ -451,7 +450,10 @@ bool rmtReceiveCompleted(int pin) {
|
||||
}
|
||||
|
||||
bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_size, uint32_t frequency_Hz) {
|
||||
log_v("GPIO %d - %s - MemSize[%d] - Freq=%dHz", pin, channel_direction == RMT_RX_MODE ? "RX MODE" : "TX MODE", mem_size * RMT_SYMBOLS_PER_CHANNEL_BLOCK, frequency_Hz);
|
||||
log_v(
|
||||
"GPIO %d - %s - MemSize[%d] - Freq=%dHz", pin, channel_direction == RMT_RX_MODE ? "RX MODE" : "TX MODE", mem_size * RMT_SYMBOLS_PER_CHANNEL_BLOCK,
|
||||
frequency_Hz
|
||||
);
|
||||
|
||||
// create common block mutex for protecting allocs from multiple threads allocating RMT channels
|
||||
if (!g_rmt_block_lock) {
|
||||
@ -588,8 +590,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
|
||||
rmt_enable(bus->rmt_channel_h); // starts/enables the channel
|
||||
|
||||
// Finally, allocate Peripheral Manager RMT bus and associate it to its GPIO
|
||||
peripheral_bus_type_t pinBusType =
|
||||
channel_direction == RMT_TX_MODE ? ESP32_BUS_TYPE_RMT_TX : ESP32_BUS_TYPE_RMT_RX;
|
||||
peripheral_bus_type_t pinBusType = channel_direction == RMT_TX_MODE ? ESP32_BUS_TYPE_RMT_TX : ESP32_BUS_TYPE_RMT_RX;
|
||||
if (!perimanSetPinBus(pin, pinBusType, (void *)bus, -1, -1)) {
|
||||
log_e("Can't allocate the GPIO %d in the Peripheral Manager.", pin);
|
||||
goto Err;
|
||||
|
@ -34,14 +34,7 @@ bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500
|
||||
log_e("Pin %u could not be detached.", pin);
|
||||
return false;
|
||||
}
|
||||
sdm_config_t config = {
|
||||
.gpio_num = (int)pin,
|
||||
.clk_src = SDM_CLK_SRC_DEFAULT,
|
||||
.sample_rate_hz = freq,
|
||||
.flags = {
|
||||
.invert_out = 0,
|
||||
.io_loop_back = 0 }
|
||||
};
|
||||
sdm_config_t config = {.gpio_num = (int)pin, .clk_src = SDM_CLK_SRC_DEFAULT, .sample_rate_hz = freq, .flags = {.invert_out = 0, .io_loop_back = 0}};
|
||||
esp_err_t err = sdm_new_channel(&config, &bus);
|
||||
if (err != ESP_OK) {
|
||||
log_e("sdm_new_channel failed with error: %d", err);
|
||||
|
@ -132,8 +132,7 @@ static spi_t _spi_bus_array[] = {
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1},
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1}
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
{ (volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1 },
|
||||
{ (volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1 }
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1}
|
||||
#elif CONFIG_IDF_TARGET_ESP32C2
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1}
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
@ -159,8 +158,7 @@ static spi_t _spi_bus_array[] = {
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1, -1, -1, -1, -1},
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2, -1, -1, -1, -1}
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
{ (volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1 },
|
||||
{ (volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1 }
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1}
|
||||
#elif CONFIG_IDF_TARGET_ESP32C2
|
||||
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1}
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
@ -371,7 +369,8 @@ void spiEnableSSPins(spi_t *spi, uint8_t ss_mask) {
|
||||
return;
|
||||
}
|
||||
SPI_MUTEX_LOCK();
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.val &= ~(ss_mask & SPI_SS_MASK_ALL);
|
||||
#else
|
||||
spi->dev->pin.val &= ~(ss_mask & SPI_SS_MASK_ALL);
|
||||
@ -384,7 +383,8 @@ void spiDisableSSPins(spi_t *spi, uint8_t ss_mask) {
|
||||
return;
|
||||
}
|
||||
SPI_MUTEX_LOCK();
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.val |= (ss_mask & SPI_SS_MASK_ALL);
|
||||
#else
|
||||
spi->dev->pin.val |= (ss_mask & SPI_SS_MASK_ALL);
|
||||
@ -417,7 +417,8 @@ void spiSSSet(spi_t *spi) {
|
||||
return;
|
||||
}
|
||||
SPI_MUTEX_LOCK();
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.cs_keep_active = 1;
|
||||
#else
|
||||
spi->dev->pin.cs_keep_active = 1;
|
||||
@ -430,7 +431,8 @@ void spiSSClear(spi_t *spi) {
|
||||
return;
|
||||
}
|
||||
SPI_MUTEX_LOCK();
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.cs_keep_active = 0;
|
||||
#else
|
||||
spi->dev->pin.cs_keep_active = 0;
|
||||
@ -458,7 +460,8 @@ uint8_t spiGetDataMode(spi_t *spi) {
|
||||
if (!spi) {
|
||||
return 0;
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
bool idleEdge = spi->dev->misc.ck_idle_edge;
|
||||
#else
|
||||
bool idleEdge = spi->dev->pin.ck_idle_edge;
|
||||
@ -483,7 +486,8 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) {
|
||||
SPI_MUTEX_LOCK();
|
||||
switch (dataMode) {
|
||||
case SPI_MODE1:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 0;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 0;
|
||||
@ -491,7 +495,8 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) {
|
||||
spi->dev->user.ck_out_edge = 1;
|
||||
break;
|
||||
case SPI_MODE2:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 1;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 1;
|
||||
@ -499,7 +504,8 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) {
|
||||
spi->dev->user.ck_out_edge = 1;
|
||||
break;
|
||||
case SPI_MODE3:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 1;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 1;
|
||||
@ -508,7 +514,8 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) {
|
||||
break;
|
||||
case SPI_MODE0:
|
||||
default:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 0;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 0;
|
||||
@ -545,8 +552,7 @@ static void _on_apb_change(void *arg, apb_change_ev_t ev_type, uint32_t old_apb,
|
||||
spi_t *spi = (spi_t *)arg;
|
||||
if (ev_type == APB_BEFORE_CHANGE) {
|
||||
SPI_MUTEX_LOCK();
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
} else {
|
||||
spi->dev->clock.val = spiFrequencyToClockDiv(old_apb / ((spi->dev->clock.clkdiv_pre + 1) * (spi->dev->clock.clkcnt_n + 1)));
|
||||
SPI_MUTEX_UNLOCK();
|
||||
@ -558,7 +564,8 @@ static void spiInitBus(spi_t *spi) {
|
||||
spi->dev->slave.trans_done = 0;
|
||||
#endif
|
||||
spi->dev->slave.val = 0;
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.val = 0;
|
||||
#else
|
||||
spi->dev->pin.val = 0;
|
||||
@ -684,8 +691,7 @@ void spiWaitReady(spi_t *spi) {
|
||||
if (!spi) {
|
||||
return;
|
||||
}
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32S2
|
||||
@ -720,12 +726,10 @@ void spiWrite(spi_t *spi, const uint32_t *data, uint8_t len) {
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
SPI_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
@ -749,12 +753,10 @@ void spiTransfer(spi_t *spi, uint32_t *data, uint8_t len) {
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
for (i = 0; i < len; i++) {
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data[i] = spi->dev->data_buf[i].val;
|
||||
@ -782,12 +784,10 @@ void spiWriteByte(spi_t *spi, uint8_t data) {
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
SPI_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
@ -805,12 +805,10 @@ uint8_t spiTransferByte(spi_t *spi, uint8_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val & 0xFF;
|
||||
#else
|
||||
@ -848,12 +846,10 @@ void spiWriteWord(spi_t *spi, uint16_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
SPI_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
@ -874,12 +870,10 @@ uint16_t spiTransferWord(spi_t *spi, uint16_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val;
|
||||
#else
|
||||
@ -911,12 +905,10 @@ void spiWriteLong(spi_t *spi, uint32_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
SPI_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
@ -937,12 +929,10 @@ uint32_t spiTransferLong(spi_t *spi, uint32_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val;
|
||||
#else
|
||||
@ -991,13 +981,11 @@ static void __spiTransferBytes(spi_t *spi, const uint8_t *data, uint8_t *out, ui
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
|
||||
if (out) {
|
||||
for (i = 0; i < words; i++) {
|
||||
@ -1073,7 +1061,8 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit
|
||||
spi->dev->clock.val = clockDiv;
|
||||
switch (dataMode) {
|
||||
case SPI_MODE1:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 0;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 0;
|
||||
@ -1081,7 +1070,8 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit
|
||||
spi->dev->user.ck_out_edge = 1;
|
||||
break;
|
||||
case SPI_MODE2:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 1;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 1;
|
||||
@ -1089,7 +1079,8 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit
|
||||
spi->dev->user.ck_out_edge = 1;
|
||||
break;
|
||||
case SPI_MODE3:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 1;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 1;
|
||||
@ -1098,7 +1089,8 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit
|
||||
break;
|
||||
case SPI_MODE0:
|
||||
default:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \
|
||||
|| CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->misc.ck_idle_edge = 0;
|
||||
#else
|
||||
spi->dev->pin.ck_idle_edge = 0;
|
||||
@ -1116,8 +1108,7 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit
|
||||
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
// Sync new config with hardware, fixes https://github.com/espressif/arduino-esp32/issues/9221
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1150,12 +1141,10 @@ void ARDUINO_ISR_ATTR spiWriteByteNL(spi_t *spi, uint8_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
}
|
||||
|
||||
uint8_t spiTransferByteNL(spi_t *spi, uint8_t data) {
|
||||
@ -1171,12 +1160,10 @@ uint8_t spiTransferByteNL(spi_t *spi, uint8_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val & 0xFF;
|
||||
#else
|
||||
@ -1203,12 +1190,10 @@ void ARDUINO_ISR_ATTR spiWriteShortNL(spi_t *spi, uint16_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
}
|
||||
|
||||
uint16_t spiTransferShortNL(spi_t *spi, uint16_t data) {
|
||||
@ -1227,12 +1212,10 @@ uint16_t spiTransferShortNL(spi_t *spi, uint16_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val & 0xFFFF;
|
||||
#else
|
||||
@ -1262,12 +1245,10 @@ void ARDUINO_ISR_ATTR spiWriteLongNL(spi_t *spi, uint32_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
}
|
||||
|
||||
uint32_t spiTransferLongNL(spi_t *spi, uint32_t data) {
|
||||
@ -1286,12 +1267,10 @@ uint32_t spiTransferLongNL(spi_t *spi, uint32_t data) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val;
|
||||
#else
|
||||
@ -1331,12 +1310,10 @@ void spiWriteNL(spi_t *spi, const void *data_in, uint32_t len) {
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
|
||||
data += c_longs;
|
||||
longs -= c_longs;
|
||||
@ -1381,12 +1358,10 @@ void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
if (result) {
|
||||
if (c_len & 3) {
|
||||
for (size_t i = 0; i < (c_longs - 1); i++) {
|
||||
@ -1457,12 +1432,10 @@ void spiTransferBitsNL(spi_t *spi, uint32_t data, uint32_t *out, uint8_t bits) {
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
data = spi->dev->data_buf[0].val;
|
||||
#else
|
||||
@ -1533,12 +1506,10 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t *spi, const void *data_in, uint32_t
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
spi->dev->cmd.update = 1;
|
||||
while (spi->dev->cmd.update)
|
||||
;
|
||||
while (spi->dev->cmd.update);
|
||||
#endif
|
||||
spi->dev->cmd.usr = 1;
|
||||
while (spi->dev->cmd.usr)
|
||||
;
|
||||
while (spi->dev->cmd.usr);
|
||||
|
||||
data += c_longs;
|
||||
longs -= c_longs;
|
||||
@ -1546,8 +1517,6 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t *spi, const void *data_in, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Clock Calculators
|
||||
*
|
||||
|
@ -102,7 +102,6 @@ extern "C" {
|
||||
uint8_t spiGetDataMode(spi_t *spi);
|
||||
uint8_t spiGetBitOrder(spi_t *spi);
|
||||
|
||||
|
||||
/*
|
||||
* Non transaction based lock methods (each locks and unlocks when called)
|
||||
* */
|
||||
|
@ -97,7 +97,9 @@ hw_timer_t *timerBegin(uint32_t frequency) {
|
||||
divider = counter_src_hz / frequency;
|
||||
if ((divider >= 2) && (divider <= 65536)) {
|
||||
break;
|
||||
} else divider = 0;
|
||||
} else {
|
||||
divider = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (divider == 0) {
|
||||
|
@ -102,9 +102,7 @@ static void configure_pins(usb_hal_context_t *usb) {
|
||||
}
|
||||
|
||||
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) {
|
||||
usb_hal_context_t hal = {
|
||||
.use_external_phy = config->external_phy
|
||||
};
|
||||
usb_hal_context_t hal = {.use_external_phy = config->external_phy};
|
||||
usb_hal_init(&hal);
|
||||
configure_pins(&hal);
|
||||
if (!tusb_init()) {
|
||||
@ -114,15 +112,6 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef char tusb_str_t[127];
|
||||
|
||||
static bool WEBUSB_ENABLED = false;
|
||||
@ -172,7 +161,6 @@ static char *tinyusb_string_descriptor[MAX_STRING_DESCRIPTORS] = {
|
||||
USB_DEVICE_SERIAL, // 3: Serials, should use chip ID
|
||||
};
|
||||
|
||||
|
||||
/* Microsoft OS 2.0 registry property descriptor
|
||||
Per MS requirements https://msdn.microsoft.com/en-us/library/windows/hardware/hh450799(v=vs.85).aspx
|
||||
device should create DeviceInterfaceGUIDs. It can be done by driver and
|
||||
@ -200,25 +188,23 @@ static uint8_t const tinyusb_ms_os_20_descriptor[] = {
|
||||
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08),
|
||||
|
||||
// MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
|
||||
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
|
||||
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, // sub-compatible
|
||||
|
||||
// MS OS 2.0 Registry property descriptor: length, type
|
||||
U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08 - 0x08 - 0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
|
||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
|
||||
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
|
||||
U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08 - 0x08 - 0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), U16_TO_U8S_LE(0x0007),
|
||||
U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
|
||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e',
|
||||
0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
|
||||
U16_TO_U8S_LE(0x0050), // wPropertyDataLength
|
||||
//bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”.
|
||||
'{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00,
|
||||
'0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00,
|
||||
'8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00,
|
||||
'8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
'{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-',
|
||||
0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C',
|
||||
0x00, 'A', 0x00, '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(tinyusb_ms_os_20_descriptor) == MS_OS_20_DESC_LEN, "Incorrect size");
|
||||
|
||||
|
||||
/*
|
||||
* BOS Descriptor (required for webUSB)
|
||||
* */
|
||||
@ -280,7 +266,6 @@ typedef union {
|
||||
|
||||
static tinyusb_endpoints_usage_t tinyusb_endpoints;
|
||||
|
||||
|
||||
/*
|
||||
* TinyUSB Callbacks
|
||||
* */
|
||||
@ -407,7 +392,6 @@ __attribute__((weak)) int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cm
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Private API
|
||||
* */
|
||||
@ -651,10 +635,7 @@ static void tinyusb_apply_device_config(tinyusb_device_config_t *config) {
|
||||
}
|
||||
|
||||
// Windows 10 will not recognize the CDC device if WebUSB is enabled and USB Class is not 2 (CDC)
|
||||
if (
|
||||
(tinyusb_loaded_interfaces_mask & BIT(USB_INTERFACE_CDC))
|
||||
&& config->webusb_enabled
|
||||
&& (config->usb_class != TUSB_CLASS_CDC)) {
|
||||
if ((tinyusb_loaded_interfaces_mask & BIT(USB_INTERFACE_CDC)) && config->webusb_enabled && (config->usb_class != TUSB_CLASS_CDC)) {
|
||||
config->usb_class = TUSB_CLASS_CDC;
|
||||
config->usb_protocol = 0x00;
|
||||
}
|
||||
@ -676,7 +657,9 @@ static void tinyusb_apply_device_config(tinyusb_device_config_t *config) {
|
||||
// This top level thread processes all usb events and invokes callbacks
|
||||
static void usb_device_task(void *param) {
|
||||
(void)param;
|
||||
while (1) tud_task(); // RTOS forever loop
|
||||
while (1) {
|
||||
tud_task(); // RTOS forever loop
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -52,20 +52,10 @@ extern "C" {
|
||||
|
||||
#define TINYUSB_CONFIG_DEFAULT() \
|
||||
{ \
|
||||
.vid = USB_ESPRESSIF_VID, \
|
||||
.pid = 0x0002, \
|
||||
.product_name = CONFIG_TINYUSB_DESC_PRODUCT_STRING, \
|
||||
.manufacturer_name = CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, \
|
||||
.serial_number = CONFIG_TINYUSB_DESC_SERIAL_STRING, \
|
||||
.fw_version = CONFIG_TINYUSB_DESC_BCDDEVICE, \
|
||||
.usb_version = 0x0200, \
|
||||
.usb_class = TUSB_CLASS_MISC, \
|
||||
.usb_subclass = MISC_SUBCLASS_COMMON, \
|
||||
.usb_protocol = MISC_PROTOCOL_IAD, \
|
||||
.usb_attributes = TUSB_DESC_CONFIG_ATT_SELF_POWERED, \
|
||||
.usb_power_ma = 500, \
|
||||
.webusb_enabled = false, \
|
||||
.webusb_url = "espressif.github.io/arduino-esp32/webusb.html" \
|
||||
.vid = USB_ESPRESSIF_VID, .pid = 0x0002, .product_name = CONFIG_TINYUSB_DESC_PRODUCT_STRING, .manufacturer_name = CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, \
|
||||
.serial_number = CONFIG_TINYUSB_DESC_SERIAL_STRING, .fw_version = CONFIG_TINYUSB_DESC_BCDDEVICE, .usb_version = 0x0200, .usb_class = TUSB_CLASS_MISC, \
|
||||
.usb_subclass = MISC_SUBCLASS_COMMON, .usb_protocol = MISC_PROTOCOL_IAD, .usb_attributes = TUSB_DESC_CONFIG_ATT_SELF_POWERED, .usb_power_ma = 500, \
|
||||
.webusb_enabled = false, .webusb_url = "espressif.github.io/arduino-esp32/webusb.html" \
|
||||
}
|
||||
|
||||
esp_err_t tinyusb_init(tinyusb_device_config_t *config);
|
||||
|
@ -90,8 +90,6 @@ static void ARDUINO_ISR_ATTR __touchISR(void *arg) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void __touchSetCycles(uint16_t measure, uint16_t sleep) {
|
||||
__touchSleepCycles = sleep;
|
||||
__touchMeasureCycles = measure;
|
||||
@ -268,7 +266,6 @@ static void __touchDettachInterrupt(uint8_t pin) {
|
||||
__touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as detaching
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
External Public Touch API Functions
|
||||
*/
|
||||
|
@ -75,7 +75,6 @@ typedef uint32_t touch_value_t;
|
||||
void touchInterruptSetThresholdDirection(bool mustbeLower);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Specific functions to ESP32-S2 and ESP32-S3
|
||||
* Returns true when the latest ISR status for the Touchpad is that it is touched (Active)
|
||||
|
@ -72,10 +72,12 @@ static uart_t _uart_bus_array[] = {
|
||||
#else
|
||||
|
||||
#define UART_MUTEX_LOCK() \
|
||||
if (uart->lock != NULL) do { \
|
||||
if (uart->lock != NULL) \
|
||||
do { \
|
||||
} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS)
|
||||
#define UART_MUTEX_UNLOCK() \
|
||||
if (uart->lock != NULL) xSemaphoreGive(uart->lock)
|
||||
if (uart->lock != NULL) \
|
||||
xSemaphoreGive(uart->lock)
|
||||
|
||||
static uart_t _uart_bus_array[] = {
|
||||
{NULL, 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0},
|
||||
@ -162,7 +164,6 @@ static bool _uartDetachBus_TX(void* busptr) {
|
||||
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, bus->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
static bool _uartDetachBus_CTS(void *busptr) {
|
||||
// sanity check - it should never happen
|
||||
assert(busptr && "_uartDetachBus_CTS bus NULL pointer.");
|
||||
@ -189,16 +190,19 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||
//log_v("attaching UART%d pins: prev,new RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num,
|
||||
// uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10);
|
||||
|
||||
|
||||
bool retCode = true;
|
||||
if (rxPin >= 0) {
|
||||
// forces a clean detaching from a previous peripheral
|
||||
if (perimanGetPinBusType(rxPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rxPin);
|
||||
if (perimanGetPinBusType(rxPin) != ESP32_BUS_TYPE_INIT) {
|
||||
perimanClearPinBus(rxPin);
|
||||
}
|
||||
// connect RX Pad
|
||||
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
if (ret) {
|
||||
ret &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART_RX, (void *)uart, uart_num, -1);
|
||||
if (ret) uart->_rxPin = rxPin;
|
||||
if (ret) {
|
||||
uart->_rxPin = rxPin;
|
||||
}
|
||||
}
|
||||
if (!ret) {
|
||||
log_e("UART%d failed to attach RX pin %d", uart_num, rxPin);
|
||||
@ -207,12 +211,16 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||
}
|
||||
if (txPin >= 0) {
|
||||
// forces a clean detaching from a previous peripheral
|
||||
if (perimanGetPinBusType(txPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(txPin);
|
||||
if (perimanGetPinBusType(txPin) != ESP32_BUS_TYPE_INIT) {
|
||||
perimanClearPinBus(txPin);
|
||||
}
|
||||
// connect TX Pad
|
||||
bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
if (ret) {
|
||||
ret &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART_TX, (void *)uart, uart_num, -1);
|
||||
if (ret) uart->_txPin = txPin;
|
||||
if (ret) {
|
||||
uart->_txPin = txPin;
|
||||
}
|
||||
}
|
||||
if (!ret) {
|
||||
log_e("UART%d failed to attach TX pin %d", uart_num, txPin);
|
||||
@ -221,12 +229,16 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||
}
|
||||
if (ctsPin >= 0) {
|
||||
// forces a clean detaching from a previous peripheral
|
||||
if (perimanGetPinBusType(ctsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(ctsPin);
|
||||
if (perimanGetPinBusType(ctsPin) != ESP32_BUS_TYPE_INIT) {
|
||||
perimanClearPinBus(ctsPin);
|
||||
}
|
||||
// connect CTS Pad
|
||||
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin);
|
||||
if (ret) {
|
||||
ret &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART_CTS, (void *)uart, uart_num, -1);
|
||||
if (ret) uart->_ctsPin = ctsPin;
|
||||
if (ret) {
|
||||
uart->_ctsPin = ctsPin;
|
||||
}
|
||||
}
|
||||
if (!ret) {
|
||||
log_e("UART%d failed to attach CTS pin %d", uart_num, ctsPin);
|
||||
@ -235,12 +247,16 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
|
||||
}
|
||||
if (rtsPin >= 0) {
|
||||
// forces a clean detaching from a previous peripheral
|
||||
if (perimanGetPinBusType(rtsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rtsPin);
|
||||
if (perimanGetPinBusType(rtsPin) != ESP32_BUS_TYPE_INIT) {
|
||||
perimanClearPinBus(rtsPin);
|
||||
}
|
||||
// connect RTS Pad
|
||||
bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE);
|
||||
if (ret) {
|
||||
ret &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART_RTS, (void *)uart, uart_num, -1);
|
||||
if (ret) uart->_rtsPin = rtsPin;
|
||||
if (ret) {
|
||||
uart->_rtsPin = rtsPin;
|
||||
}
|
||||
}
|
||||
if (!ret) {
|
||||
log_e("UART%d failed to attach RTS pin %d", uart_num, rtsPin);
|
||||
@ -358,7 +374,10 @@ bool uartSetHwFlowCtrlMode(uart_t* uart, uart_hw_flowcontrol_t mode, uint8_t thr
|
||||
}
|
||||
|
||||
// This helper function will return true if a new IDF UART driver needs to be restarted and false if the current one can continue its execution
|
||||
bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) {
|
||||
bool _testUartBegin(
|
||||
uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted,
|
||||
uint8_t rxfifo_full_thrhd
|
||||
) {
|
||||
if (uart_nr >= SOC_UART_NUM) {
|
||||
return false; // no new driver has to be installed
|
||||
}
|
||||
@ -366,7 +385,8 @@ bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t
|
||||
// verify if is necessary to restart the UART driver
|
||||
if (uart_is_driver_installed(uart_nr)) {
|
||||
// some parameters can't be changed unless we end the UART driver
|
||||
if (uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted || uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) {
|
||||
if (uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted
|
||||
|| uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) {
|
||||
return true; // the current IDF UART driver must be terminated and a new driver shall be installed
|
||||
} else {
|
||||
return false; // The current IDF UART driver can continue its execution
|
||||
@ -376,7 +396,10 @@ bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t
|
||||
}
|
||||
}
|
||||
|
||||
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) {
|
||||
uart_t *uartBegin(
|
||||
uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted,
|
||||
uint8_t rxfifo_full_thrhd
|
||||
) {
|
||||
if (uart_nr >= SOC_UART_NUM) {
|
||||
log_e("UART number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1);
|
||||
return NULL; // no new driver was installed
|
||||
@ -397,7 +420,8 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
||||
if (uart_is_driver_installed(uart_nr)) {
|
||||
log_v("UART%d Driver already installed.", uart_nr);
|
||||
// some parameters can't be changed unless we end the UART driver
|
||||
if (uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted || uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) {
|
||||
if (uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted
|
||||
|| uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) {
|
||||
log_v("UART%d changing buffer sizes or inverted signal or rxfifo_full_thrhd. IDF driver will be restarted", uart_nr);
|
||||
uartEnd(uart_nr);
|
||||
} else {
|
||||
@ -429,8 +453,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
||||
log_e("UART%d changing parity failed.", uart_nr);
|
||||
retCode = false;
|
||||
} else {
|
||||
log_v("UART%d changed parity to %s", uart_nr, parity == 0 ? "NONE" : parity == 2 ? "EVEN"
|
||||
: "ODD");
|
||||
log_v("UART%d changed parity to %s", uart_nr, parity == 0 ? "NONE" : parity == 2 ? "EVEN" : "ODD");
|
||||
}
|
||||
}
|
||||
if (retCode && (uart->_config & 0xc30) >> 4 != stop_bits) {
|
||||
@ -441,7 +464,9 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
||||
log_v("UART%d changed stop bits to %d", uart_nr, stop_bits == 3 ? 2 : 1);
|
||||
}
|
||||
}
|
||||
if (retCode) uart->_config = config;
|
||||
if (retCode) {
|
||||
uart->_config = config;
|
||||
}
|
||||
if (retCode && rxPin > 0 && uart->_rxPin != rxPin) {
|
||||
retCode &= _uartDetachPins(uart_nr, uart->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
retCode &= _uartAttachPins(uart_nr, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
@ -484,7 +509,9 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
||||
UART_MUTEX_LOCK();
|
||||
bool retCode = ESP_OK == uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0);
|
||||
|
||||
if (retCode) retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config);
|
||||
if (retCode) {
|
||||
retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config);
|
||||
}
|
||||
|
||||
// Is it right or the idea is to swap rx and tx pins?
|
||||
if (retCode && inverted) {
|
||||
@ -505,7 +532,9 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
||||
UART_MUTEX_UNLOCK();
|
||||
|
||||
// uartSetPins detaches previous pins if new ones are used over a previous begin()
|
||||
if (retCode) retCode &= uartSetPins(uart_nr, rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
if (retCode) {
|
||||
retCode &= uartSetPins(uart_nr, rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
}
|
||||
if (!retCode) {
|
||||
uartEnd(uart_nr);
|
||||
uart = NULL;
|
||||
@ -536,7 +565,6 @@ void uartSetFastReading(uart_t* uart) {
|
||||
UART_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
|
||||
bool uartSetRxTimeout(uart_t *uart, uint8_t numSymbTimeout) {
|
||||
if (uart == NULL) {
|
||||
return false;
|
||||
@ -559,7 +587,6 @@ bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull) {
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
void uartEnd(uint8_t uart_num) {
|
||||
if (uart_num >= SOC_UART_NUM) {
|
||||
log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1);
|
||||
@ -576,10 +603,10 @@ void uartEnd(uint8_t uart_num) {
|
||||
UART_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
|
||||
void uartSetRxInvert(uart_t *uart, bool invert) {
|
||||
if (uart == NULL)
|
||||
if (uart == NULL) {
|
||||
return;
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
// POTENTIAL ISSUE :: original code only set/reset rxd_inv bit
|
||||
// IDF or LL set/reset the whole inv_mask!
|
||||
@ -592,14 +619,14 @@ void uartSetRxInvert(uart_t* uart, bool invert) {
|
||||
// this implementation is better over IDF API because it only affects RXD
|
||||
// this is supported in ESP32, ESP32-S2 and ESP32-C3
|
||||
uart_dev_t *hw = UART_LL_GET_HW(uart->num);
|
||||
if (invert)
|
||||
if (invert) {
|
||||
hw->conf0.rxd_inv = 1;
|
||||
else
|
||||
} else {
|
||||
hw->conf0.rxd_inv = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint32_t uartAvailable(uart_t *uart) {
|
||||
|
||||
if (uart == NULL) {
|
||||
@ -609,12 +636,13 @@ uint32_t uartAvailable(uart_t* uart) {
|
||||
UART_MUTEX_LOCK();
|
||||
size_t available;
|
||||
uart_get_buffered_data_len(uart->num, &available);
|
||||
if (uart->has_peek) available++;
|
||||
if (uart->has_peek) {
|
||||
available++;
|
||||
}
|
||||
UART_MUTEX_UNLOCK();
|
||||
return available;
|
||||
}
|
||||
|
||||
|
||||
uint32_t uartAvailableForWrite(uart_t *uart) {
|
||||
if (uart == NULL) {
|
||||
return 0;
|
||||
@ -647,11 +675,12 @@ size_t uartReadBytes(uart_t* uart, uint8_t* buffer, size_t size, uint32_t timeou
|
||||
|
||||
if (size > 0) {
|
||||
int len = uart_read_bytes(uart->num, buffer, size, pdMS_TO_TICKS(timeout_ms));
|
||||
if (len < 0) len = 0; // error reading UART
|
||||
if (len < 0) {
|
||||
len = 0; // error reading UART
|
||||
}
|
||||
bytes_read += len;
|
||||
}
|
||||
|
||||
|
||||
UART_MUTEX_UNLOCK();
|
||||
return bytes_read;
|
||||
}
|
||||
@ -680,7 +709,6 @@ uint8_t uartRead(uart_t* uart) {
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
uint8_t uartPeek(uart_t *uart) {
|
||||
if (uart == NULL) {
|
||||
return 0;
|
||||
@ -733,8 +761,7 @@ void uartFlushTxOnly(uart_t* uart, bool txOnly) {
|
||||
}
|
||||
|
||||
UART_MUTEX_LOCK();
|
||||
while (!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num)))
|
||||
;
|
||||
while (!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num)));
|
||||
|
||||
if (!txOnly) {
|
||||
ESP_ERROR_CHECK(uart_flush_input(uart->num));
|
||||
@ -772,45 +799,34 @@ uint32_t uartGetBaudRate(uart_t* uart) {
|
||||
}
|
||||
|
||||
static void ARDUINO_ISR_ATTR uart0_write_char(char c) {
|
||||
while (uart_ll_get_txfifo_len(&UART0) == 0)
|
||||
;
|
||||
while (uart_ll_get_txfifo_len(&UART0) == 0);
|
||||
uart_ll_write_txfifo(&UART0, (const uint8_t *)&c, 1);
|
||||
}
|
||||
|
||||
#if SOC_UART_NUM > 1
|
||||
static void ARDUINO_ISR_ATTR uart1_write_char(char c) {
|
||||
while (uart_ll_get_txfifo_len(&UART1) == 0)
|
||||
;
|
||||
while (uart_ll_get_txfifo_len(&UART1) == 0);
|
||||
uart_ll_write_txfifo(&UART1, (const uint8_t *)&c, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SOC_UART_NUM > 2
|
||||
static void ARDUINO_ISR_ATTR uart2_write_char(char c) {
|
||||
while (uart_ll_get_txfifo_len(&UART2) == 0)
|
||||
;
|
||||
while (uart_ll_get_txfifo_len(&UART2) == 0);
|
||||
uart_ll_write_txfifo(&UART2, (const uint8_t *)&c, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_install_putc() {
|
||||
switch (s_uart_debug_nr) {
|
||||
case 0:
|
||||
ets_install_putc1((void (*)(char)) & uart0_write_char);
|
||||
break;
|
||||
case 0: ets_install_putc1((void (*)(char)) & uart0_write_char); break;
|
||||
#if SOC_UART_NUM > 1
|
||||
case 1:
|
||||
ets_install_putc1((void (*)(char)) & uart1_write_char);
|
||||
break;
|
||||
case 1: ets_install_putc1((void (*)(char)) & uart1_write_char); break;
|
||||
#endif
|
||||
#if SOC_UART_NUM > 2
|
||||
case 2:
|
||||
ets_install_putc1((void (*)(char)) & uart2_write_char);
|
||||
break;
|
||||
case 2: ets_install_putc1((void (*)(char)) & uart2_write_char); break;
|
||||
#endif
|
||||
default:
|
||||
ets_install_putc1(NULL);
|
||||
break;
|
||||
default: ets_install_putc1(NULL); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -883,9 +899,9 @@ int log_printfv(const char* format, va_list arg) {
|
||||
free(temp);
|
||||
}
|
||||
// flushes TX - make sure that the log message is completely sent.
|
||||
if (s_uart_debug_nr != -1)
|
||||
while (!uart_ll_is_tx_idle(UART_LL_GET_HW(s_uart_debug_nr)))
|
||||
;
|
||||
if (s_uart_debug_nr != -1) {
|
||||
while (!uart_ll_is_tx_idle(UART_LL_GET_HW(s_uart_debug_nr)));
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -898,7 +914,6 @@ int log_printf(const char* format, ...) {
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
static void log_print_buf_line(const uint8_t *b, size_t len, size_t total_len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
log_printf("%s0x%02x,", i ? " " : "", b[i]);
|
||||
@ -943,7 +958,9 @@ unsigned long uartBaudrateDetect(uart_t* uart, bool flg) {
|
||||
uart_dev_t *hw = UART_LL_GET_HW(uart->num);
|
||||
|
||||
while (hw->rxd_cnt.edge_cnt < 30) { // UART_PULSE_NUM(uart_num)
|
||||
if (flg) return 0;
|
||||
if (flg) {
|
||||
return 0;
|
||||
}
|
||||
ets_delay_us(1000);
|
||||
}
|
||||
|
||||
@ -958,7 +975,6 @@ unsigned long uartBaudrateDetect(uart_t* uart, bool flg) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* To start detection of baud rate with the uart the auto_baud.en bit needs to be cleared and set. The bit period is
|
||||
* detected calling uartBadrateDetect(). The raw baudrate is computed using the UART_CLK_FREQ. The raw baudrate is
|
||||
@ -1036,7 +1052,8 @@ unsigned long uartDetectBaudrate(uart_t* uart) {
|
||||
|
||||
//log_i("APB_FREQ = %d\nraw baudrate detected = %d", getApbFrequency(), baudrate);
|
||||
|
||||
static const unsigned long default_rates[] = { 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400 };
|
||||
static const unsigned long default_rates[] = {300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600,
|
||||
74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400};
|
||||
|
||||
size_t i;
|
||||
for (i = 1; i < sizeof(default_rates) / sizeof(default_rates[0]) - 1; i++) // find the nearest real baudrate
|
||||
@ -1080,7 +1097,9 @@ unsigned long uartDetectBaudrate(uart_t* uart) {
|
||||
This creates a loop that lets us receive anything we send on the UART without external wires.
|
||||
*/
|
||||
void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) {
|
||||
if (uartNum > SOC_UART_NUM - 1 || !GPIO_IS_VALID_GPIO(rxPin)) return;
|
||||
if (uartNum > SOC_UART_NUM - 1 || !GPIO_IS_VALID_GPIO(rxPin)) {
|
||||
return;
|
||||
}
|
||||
esp_rom_gpio_connect_out_signal(rxPin, UART_TX_SIGNAL(uartNum), false, false);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,14 @@ extern "C" {
|
||||
struct uart_struct_t;
|
||||
typedef struct uart_struct_t uart_t;
|
||||
|
||||
bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd);
|
||||
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd);
|
||||
bool _testUartBegin(
|
||||
uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted,
|
||||
uint8_t rxfifo_full_thrhd
|
||||
);
|
||||
uart_t *uartBegin(
|
||||
uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted,
|
||||
uint8_t rxfifo_full_thrhd
|
||||
);
|
||||
void uartEnd(uint8_t uart_num);
|
||||
|
||||
// This is used to retrieve the Event Queue pointer from a UART IDF Driver in order to allow user to deal with its events
|
||||
@ -74,7 +80,6 @@ extern "C" {
|
||||
int8_t uart_get_TxPin(uint8_t uart_num);
|
||||
void uart_init_PeriMan(void);
|
||||
|
||||
|
||||
// Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins
|
||||
// UART_HW_FLOWCTRL_DISABLE = 0x0 disable hardware flow control
|
||||
// UART_HW_FLOWCTRL_RTS = 0x1 enable RX hardware flow control (rts)
|
||||
@ -110,7 +115,6 @@ extern "C" {
|
||||
// Sends a buffer and at the end of the stream, it generates BREAK in the line
|
||||
int uart_send_msg_with_break(uint8_t uartNum, uint8_t *msg, size_t msgSize);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -116,13 +116,10 @@ extern "C" {
|
||||
|
||||
//if xCoreID < 0 or CPU is unicore, it will use xTaskCreate, else xTaskCreatePinnedToCore
|
||||
//allows to easily handle all possible situations without repetitive code
|
||||
BaseType_t xTaskCreateUniversal(TaskFunction_t pxTaskCode,
|
||||
const char* const pcName,
|
||||
const uint32_t usStackDepth,
|
||||
void* const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t* const pxCreatedTask,
|
||||
const BaseType_t xCoreID);
|
||||
BaseType_t xTaskCreateUniversal(
|
||||
TaskFunction_t pxTaskCode, const char *const pcName, const uint32_t usStackDepth, void *const pvParameters, UBaseType_t uxPriority,
|
||||
TaskHandle_t *const pxCreatedTask, const BaseType_t xCoreID
|
||||
);
|
||||
|
||||
unsigned long micros();
|
||||
unsigned long millis();
|
||||
|
@ -20,5 +20,4 @@
|
||||
#define ICACHE_FLASH_ATTR
|
||||
#define ICACHE_RAM_ATTR ARDUINO_ISR_ATTR
|
||||
|
||||
|
||||
#endif /* _ESP8266_COMPAT_H_ */
|
||||
|
@ -37,9 +37,7 @@ extern "C" {
|
||||
*
|
||||
* To be used in comparisons, such as ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
|
||||
*/
|
||||
#define ESP_ARDUINO_VERSION ESP_ARDUINO_VERSION_VAL(ESP_ARDUINO_VERSION_MAJOR, \
|
||||
ESP_ARDUINO_VERSION_MINOR, \
|
||||
ESP_ARDUINO_VERSION_PATCH)
|
||||
#define ESP_ARDUINO_VERSION ESP_ARDUINO_VERSION_VAL(ESP_ARDUINO_VERSION_MAJOR, ESP_ARDUINO_VERSION_MINOR, ESP_ARDUINO_VERSION_PATCH)
|
||||
|
||||
/**
|
||||
* Current ARDUINO version, as string
|
||||
|
@ -111,7 +111,9 @@ void fat_set_table_index(uint8_t *table, uint16_t index, uint16_t value, bool fa
|
||||
}
|
||||
}
|
||||
|
||||
fat_boot_sector_t *fat_add_boot_sector(uint8_t *dst, uint16_t sector_num, uint16_t table_sectors, const char *file_system_type, const char *volume_label, uint32_t serial_number) {
|
||||
fat_boot_sector_t *fat_add_boot_sector(
|
||||
uint8_t *dst, uint16_t sector_num, uint16_t table_sectors, const char *file_system_type, const char *volume_label, uint32_t serial_number
|
||||
) {
|
||||
fat_boot_sector_t *boot = (fat_boot_sector_t *)dst;
|
||||
boot->jump_instruction[0] = 0xEB;
|
||||
boot->jump_instruction[1] = 0x3C;
|
||||
@ -149,7 +151,9 @@ fat_dir_entry_t *fat_add_label(uint8_t *dst, const char *volume_label) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
fat_dir_entry_t *fat_add_root_file(uint8_t *dst, uint8_t index, const char *file_name, const char *file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16) {
|
||||
fat_dir_entry_t *fat_add_root_file(
|
||||
uint8_t *dst, uint8_t index, const char *file_name, const char *file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16
|
||||
) {
|
||||
fat_boot_sector_t *boot = (fat_boot_sector_t *)dst;
|
||||
uint8_t *table = dst + DISK_SECTOR_SIZE;
|
||||
fat_dir_entry_t *entry = (fat_dir_entry_t *)(dst + ((boot->sectors_per_alloc_table + 1) * DISK_SECTOR_SIZE) + (index * sizeof(fat_dir_entry_t)));
|
||||
|
@ -131,9 +131,13 @@ extern "C" {
|
||||
uint16_t fat_sectors_per_alloc_table(uint32_t sector_num, bool fat16);
|
||||
uint8_t *fat_add_table(uint8_t *dst, fat_boot_sector_t *boot, bool fat16);
|
||||
void fat_set_table_index(uint8_t *table, uint16_t index, uint16_t value, bool fat16);
|
||||
fat_boot_sector_t *fat_add_boot_sector(uint8_t *dst, uint16_t sector_num, uint16_t table_sectors, const char *file_system_type, const char *volume_label, uint32_t serial_number);
|
||||
fat_boot_sector_t *fat_add_boot_sector(
|
||||
uint8_t *dst, uint16_t sector_num, uint16_t table_sectors, const char *file_system_type, const char *volume_label, uint32_t serial_number
|
||||
);
|
||||
fat_dir_entry_t *fat_add_label(uint8_t *dst, const char *volume_label);
|
||||
fat_dir_entry_t *fat_add_root_file(uint8_t *dst, uint8_t index, const char *file_name, const char *file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16);
|
||||
fat_dir_entry_t *fat_add_root_file(
|
||||
uint8_t *dst, uint8_t index, const char *file_name, const char *file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16
|
||||
);
|
||||
uint8_t fat_lfn_checksum(const uint8_t *short_filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -50,7 +50,8 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
|
||||
#define i2cInit(i2c_num, sda, scl, clk_speed) i2cInit(i2c_num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), clk_speed)
|
||||
|
||||
// cores/esp32/esp32-hal-i2c-slave.h
|
||||
#define i2cSlaveInit(num, sda, scl, slaveID, frequency, rx_len, tx_len) i2cSlaveInit(num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), slaveID, frequency, rx_len, tx_len)
|
||||
#define i2cSlaveInit(num, sda, scl, slaveID, frequency, rx_len, tx_len) \
|
||||
i2cSlaveInit(num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), slaveID, frequency, rx_len, tx_len)
|
||||
|
||||
// cores/esp32/esp32-hal-ledc.h
|
||||
#define ledcAttach(pin, freq, resolution) ledcAttach(digitalPinToGPIONumber(pin), freq, resolution)
|
||||
@ -65,8 +66,10 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
|
||||
#define ledcOutputInvert(pin, out_invert) ledcOutputInvert(digitalPinToGPIONumber(pin), out_invert)
|
||||
|
||||
#define ledcFade(pin, start_duty, target_duty, max_fade_time_ms) ledcFade(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms)
|
||||
#define ledcFadeWithInterrupt(pin, start_duty, target_duty, max_fade_time_ms, userFunc) ledcFadeWithInterrupt(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc)
|
||||
#define ledcFadeWithInterruptArg(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg) ledcFadeWithInterruptArg(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc, arg)
|
||||
#define ledcFadeWithInterrupt(pin, start_duty, target_duty, max_fade_time_ms, userFunc) \
|
||||
ledcFadeWithInterrupt(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc)
|
||||
#define ledcFadeWithInterruptArg(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg) \
|
||||
ledcFadeWithInterruptArg(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc, arg)
|
||||
|
||||
// cores/esp32/esp32-hal-matrix.h
|
||||
#define pinMatrixInAttach(pin, signal, inverted) pinMatrixInAttach(digitalPinToGPIONumber(pin), signal, inverted)
|
||||
@ -87,7 +90,8 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
|
||||
#define rmtReadAsync(pin, data, num_rmt_symbols) rmtReadAsync(digitalPinToGPIONumber(pin), data, num_rmt_symbols)
|
||||
#define rmtReceiveCompleted(pin) rmtReceiveCompleted(digitalPinToGPIONumber(pin))
|
||||
#define rmtSetRxMaxThreshold(pin, idle_thres_ticks) rmtSetRxMaxThreshold(digitalPinToGPIONumber(pin), idle_thres_ticks)
|
||||
#define rmtSetCarrier(pin, carrier_en, carrier_level, frequency_Hz, duty_percent) rmtSetCarrier(digitalPinToGPIONumber(pin), carrier_en, carrier_level, frequency_Hz, duty_percent)
|
||||
#define rmtSetCarrier(pin, carrier_en, carrier_level, frequency_Hz, duty_percent) \
|
||||
rmtSetCarrier(digitalPinToGPIONumber(pin), carrier_en, carrier_level, frequency_Hz, duty_percent)
|
||||
#define rmtSetRxMinThreshold(pin, filter_pulse_ticks) rmtSetRxMinThreshold(digitalPinToGPIONumber(pin), filter_pulse_ticks)
|
||||
#define rmtDeinit(pin) rmtDeinit(digitalPinToGPIONumber(pin))
|
||||
|
||||
@ -112,7 +116,9 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
|
||||
|
||||
// cores/esp32/esp32-hal-uart.h
|
||||
#define uartBegin(uart_nr, baudrate, config, rxPin, txPin, rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd) \
|
||||
uartBegin(uart_nr, baudrate, config, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd)
|
||||
uartBegin( \
|
||||
uart_nr, baudrate, config, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd \
|
||||
)
|
||||
#define uartSetPins(uart, rxPin, txPin, ctsPin, rtsPin) \
|
||||
uartSetPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin))
|
||||
#define uartDetachPins(uart, rxPin, txPin, ctsPin, rtsPin) \
|
||||
|
@ -9,10 +9,14 @@ For details, see http://sourceforge.net/projects/libb64
|
||||
#include <stdint.h>
|
||||
|
||||
static int base64_decode_value_signed(int8_t value_in) {
|
||||
static const int8_t decoding[] = { 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
|
||||
static const int8_t decoding[] = {62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 3, 4,
|
||||
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1,
|
||||
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
|
||||
static const int8_t decoding_size = sizeof(decoding);
|
||||
value_in -= 43;
|
||||
if (value_in < 0 || value_in >= decoding_size) return -1;
|
||||
if (value_in < 0 || value_in >= decoding_size) {
|
||||
return -1;
|
||||
}
|
||||
return decoding[(int)value_in];
|
||||
}
|
||||
|
||||
@ -85,7 +89,9 @@ static int base64_decode_chars_signed(const int8_t* code_in, const int length_in
|
||||
base64_decodestate _state;
|
||||
base64_init_decodestate(&_state);
|
||||
int len = base64_decode_block_signed(code_in, length_in, plaintext_out, &_state);
|
||||
if (len > 0) plaintext_out[len] = 0;
|
||||
if (len > 0) {
|
||||
plaintext_out[len] = 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,7 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in) {
|
||||
*codechar++ = base64_encode_value(state_in->result);
|
||||
*codechar++ = '=';
|
||||
break;
|
||||
case step_A:
|
||||
break;
|
||||
case step_A: break;
|
||||
}
|
||||
*codechar = 0x00;
|
||||
|
||||
|
@ -71,7 +71,9 @@ void loopTask(void *pvParameters) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
loop();
|
||||
if (serialEventRun) serialEventRun();
|
||||
if (serialEventRun) {
|
||||
serialEventRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,19 +36,23 @@ typedef unsigned long prog_uint32_t;
|
||||
#define _SFR_BYTE(n) (n)
|
||||
|
||||
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||
#define pgm_read_word(addr) ({ \
|
||||
#define pgm_read_word(addr) \
|
||||
({ \
|
||||
typeof(addr) _addr = (addr); \
|
||||
*(const unsigned short *)(_addr); \
|
||||
})
|
||||
#define pgm_read_dword(addr) ({ \
|
||||
#define pgm_read_dword(addr) \
|
||||
({ \
|
||||
typeof(addr) _addr = (addr); \
|
||||
*(const unsigned long *)(_addr); \
|
||||
})
|
||||
#define pgm_read_float(addr) ({ \
|
||||
#define pgm_read_float(addr) \
|
||||
({ \
|
||||
typeof(addr) _addr = (addr); \
|
||||
*(const float *)(_addr); \
|
||||
})
|
||||
#define pgm_read_ptr(addr) ({ \
|
||||
#define pgm_read_ptr(addr) \
|
||||
({ \
|
||||
typeof(addr) _addr = (addr); \
|
||||
*(void *const *)(_addr); \
|
||||
})
|
||||
|
@ -59,8 +59,9 @@ char* ltoa(long value, char* result, int base) {
|
||||
} while (quotient);
|
||||
|
||||
// Apply negative sign
|
||||
if (value < 0)
|
||||
if (value < 0) {
|
||||
*out++ = '-';
|
||||
}
|
||||
|
||||
reverse(result, out);
|
||||
*out = 0;
|
||||
@ -84,8 +85,9 @@ char* lltoa(long long val, char* result, int base) {
|
||||
} while (quotient);
|
||||
|
||||
// Apply negative sign
|
||||
if (val < 0)
|
||||
if (val < 0) {
|
||||
*out++ = '-';
|
||||
}
|
||||
|
||||
reverse(result, out);
|
||||
*out = 0;
|
||||
@ -163,8 +165,9 @@ char* dtostrf(double number, signed int width, unsigned int prec, char* s) {
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
// I optimized out most of the divisions
|
||||
double rounding = 2.0;
|
||||
for (unsigned int i = 0; i < prec; ++i)
|
||||
for (unsigned int i = 0; i < prec; ++i) {
|
||||
rounding *= 10.0;
|
||||
}
|
||||
rounding = 1.0 / rounding;
|
||||
|
||||
number += rounding;
|
||||
@ -186,14 +189,18 @@ char* dtostrf(double number, signed int width, unsigned int prec, char* s) {
|
||||
}
|
||||
|
||||
// Handle negative sign
|
||||
if (negative) *out++ = '-';
|
||||
if (negative) {
|
||||
*out++ = '-';
|
||||
}
|
||||
|
||||
// Print the digits, and if necessary, the decimal point
|
||||
digitcount += prec;
|
||||
int8_t digit = 0;
|
||||
while (digitcount-- > 0) {
|
||||
digit = (int8_t)number;
|
||||
if (digit > 9) digit = 9; // insurance
|
||||
if (digit > 9) {
|
||||
digit = 9; // insurance
|
||||
}
|
||||
*out++ = (char)('0' | digit);
|
||||
if ((digitcount == prec) && (prec > 0)) {
|
||||
*out++ = '.';
|
||||
|
@ -49,5 +49,4 @@ extern "C" {
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -26,10 +26,11 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
//digitalWrite(clockPin, HIGH);
|
||||
if (bitOrder == LSBFIRST)
|
||||
if (bitOrder == LSBFIRST) {
|
||||
value |= digitalRead(dataPin) << i;
|
||||
else
|
||||
} else {
|
||||
value |= digitalRead(dataPin) << (7 - i);
|
||||
}
|
||||
digitalWrite(clockPin, HIGH);
|
||||
digitalWrite(clockPin, LOW);
|
||||
}
|
||||
@ -40,10 +41,11 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (bitOrder == LSBFIRST)
|
||||
if (bitOrder == LSBFIRST) {
|
||||
digitalWrite(dataPin, !!(val & (1 << i)));
|
||||
else
|
||||
} else {
|
||||
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
|
||||
}
|
||||
|
||||
digitalWrite(clockPin, HIGH);
|
||||
digitalWrite(clockPin, LOW);
|
||||
|
@ -33,10 +33,11 @@ void setup() {
|
||||
ArduinoOTA
|
||||
.onStart([]() {
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
if (ArduinoOTA.getCommand() == U_FLASH) {
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
} else { // U_SPIFFS
|
||||
type = "filesystem";
|
||||
}
|
||||
|
||||
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||
Serial.println("Start updating " + type);
|
||||
@ -49,11 +50,17 @@ void setup() {
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
if (error == OTA_AUTH_ERROR) {
|
||||
Serial.println("Auth Failed");
|
||||
} else if (error == OTA_BEGIN_ERROR) {
|
||||
Serial.println("Begin Failed");
|
||||
} else if (error == OTA_CONNECT_ERROR) {
|
||||
Serial.println("Connect Failed");
|
||||
} else if (error == OTA_RECEIVE_ERROR) {
|
||||
Serial.println("Receive Failed");
|
||||
} else if (error == OTA_END_ERROR) {
|
||||
Serial.println("End Failed");
|
||||
}
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
|
@ -8,12 +8,11 @@
|
||||
#include "MD5Builder.h"
|
||||
#include "Update.h"
|
||||
|
||||
|
||||
// #define OTA_DEBUG Serial
|
||||
|
||||
ArduinoOTAClass::ArduinoOTAClass()
|
||||
: _port(0), _initialized(false), _rebootOnSuccess(true), _mdnsEnabled(true), _state(OTA_IDLE), _size(0), _cmd(0), _ota_port(0), _ota_timeout(1000), _start_callback(NULL), _end_callback(NULL), _error_callback(NULL), _progress_callback(NULL) {
|
||||
}
|
||||
: _port(0), _initialized(false), _rebootOnSuccess(true), _mdnsEnabled(true), _state(OTA_IDLE), _size(0), _cmd(0), _ota_port(0), _ota_timeout(1000),
|
||||
_start_callback(NULL), _end_callback(NULL), _error_callback(NULL), _progress_callback(NULL) {}
|
||||
|
||||
ArduinoOTAClass::~ArduinoOTAClass() {
|
||||
_udp_ota.stop();
|
||||
@ -111,7 +110,6 @@ void ArduinoOTAClass::begin() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!_hostname.length()) {
|
||||
char tmp[20];
|
||||
uint8_t mac[6];
|
||||
@ -132,7 +130,9 @@ int ArduinoOTAClass::parseInt() {
|
||||
char data[INT_BUFFER_SIZE];
|
||||
uint8_t index = 0;
|
||||
char value;
|
||||
while (_udp_ota.peek() == ' ') _udp_ota.read();
|
||||
while (_udp_ota.peek() == ' ') {
|
||||
_udp_ota.read();
|
||||
}
|
||||
while (index < INT_BUFFER_SIZE - 1) {
|
||||
value = _udp_ota.peek();
|
||||
if (value < '0' || value > '9') {
|
||||
@ -160,8 +160,9 @@ String ArduinoOTAClass::readStringUntil(char end) {
|
||||
void ArduinoOTAClass::_onRx() {
|
||||
if (_state == OTA_IDLE) {
|
||||
int cmd = parseInt();
|
||||
if (cmd != U_FLASH && cmd != U_SPIFFS)
|
||||
if (cmd != U_FLASH && cmd != U_SPIFFS) {
|
||||
return;
|
||||
}
|
||||
_cmd = cmd;
|
||||
_ota_port = parseInt();
|
||||
_size = parseInt();
|
||||
@ -226,7 +227,9 @@ void ArduinoOTAClass::_onRx() {
|
||||
_udp_ota.print("Authentication Failed");
|
||||
log_w("Authentication Failed");
|
||||
_udp_ota.endPacket();
|
||||
if (_error_callback) _error_callback(OTA_AUTH_ERROR);
|
||||
if (_error_callback) {
|
||||
_error_callback(OTA_AUTH_ERROR);
|
||||
}
|
||||
_state = OTA_IDLE;
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ void setup() {
|
||||
Serial.println("UDP connected");
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast"
|
||||
: "Unicast");
|
||||
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
Serial.print(", From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
|
@ -21,8 +21,7 @@ void setup() {
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast"
|
||||
: "Unicast");
|
||||
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
Serial.print(", From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
|
@ -21,8 +21,7 @@ void setup() {
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast"
|
||||
: "Unicast");
|
||||
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
Serial.print(", From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
|
@ -15,9 +15,7 @@ extern "C" {
|
||||
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
|
||||
static const char *netif_ifkeys[TCPIP_ADAPTER_IF_MAX] = {
|
||||
"WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF", "PPP_DEF"
|
||||
};
|
||||
static const char *netif_ifkeys[TCPIP_ADAPTER_IF_MAX] = {"WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF", "PPP_DEF"};
|
||||
|
||||
static esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void **netif) {
|
||||
*netif = NULL;
|
||||
@ -172,7 +170,9 @@ static bool _udp_task_start() {
|
||||
}
|
||||
}
|
||||
if (!_udp_task_handle) {
|
||||
xTaskCreateUniversal(_udp_task, "async_udp", 4096, NULL, CONFIG_ARDUINO_UDP_TASK_PRIORITY, (TaskHandle_t *)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE);
|
||||
xTaskCreateUniversal(
|
||||
_udp_task, "async_udp", 4096, NULL, CONFIG_ARDUINO_UDP_TASK_PRIORITY, (TaskHandle_t *)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE
|
||||
);
|
||||
if (!_udp_task_handle) {
|
||||
return false;
|
||||
}
|
||||
@ -232,12 +232,9 @@ static bool _udp_task_stop(){
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define UDP_MUTEX_LOCK() //xSemaphoreTake(_lock, portMAX_DELAY)
|
||||
#define UDP_MUTEX_UNLOCK() //xSemaphoreGive(_lock)
|
||||
|
||||
|
||||
AsyncUDPMessage::AsyncUDPMessage(size_t size) {
|
||||
_index = 0;
|
||||
if (size > CONFIG_TCP_MSS) {
|
||||
@ -762,7 +759,6 @@ size_t AsyncUDP::broadcast(const char *data) {
|
||||
return broadcast((uint8_t *)data, strlen(data));
|
||||
}
|
||||
|
||||
|
||||
size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if) {
|
||||
if (!message) {
|
||||
return 0;
|
||||
|
@ -36,6 +36,7 @@ protected:
|
||||
uint8_t *_buffer;
|
||||
size_t _index;
|
||||
size_t _size;
|
||||
|
||||
public:
|
||||
AsyncUDPMessage(size_t size = CONFIG_TCP_MSS);
|
||||
virtual ~AsyncUDPMessage();
|
||||
@ -63,6 +64,7 @@ protected:
|
||||
uint8_t *_data;
|
||||
size_t _len;
|
||||
size_t _index;
|
||||
|
||||
public:
|
||||
AsyncUDPPacket(AsyncUDPPacket &packet);
|
||||
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif);
|
||||
|
@ -81,39 +81,21 @@ esp_ble_gap_ext_adv_params_t ext_adv_params_coded = {
|
||||
.scan_req_notif = false,
|
||||
};
|
||||
|
||||
static uint8_t raw_adv_data_1m[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', '1', 'M', 0X0
|
||||
};
|
||||
static uint8_t raw_adv_data_1m[] = {0x02, 0x01, 0x06, 0x02, 0x0a, 0xeb, 0x12, 0x09, 'E', 'S', 'P', '_', 'M',
|
||||
'U', 'L', 'T', 'I', '_', 'A', 'D', 'V', '_', '1', 'M', 0X0};
|
||||
|
||||
static uint8_t raw_scan_rsp_data_2m[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', '2', 'M', 0X0
|
||||
};
|
||||
static uint8_t raw_scan_rsp_data_2m[] = {0x02, 0x01, 0x06, 0x02, 0x0a, 0xeb, 0x12, 0x09, 'E', 'S', 'P', '_', 'M',
|
||||
'U', 'L', 'T', 'I', '_', 'A', 'D', 'V', '_', '2', 'M', 0X0};
|
||||
|
||||
static uint8_t legacy_adv_data[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x15, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', 'C', 'O', 'D', 'E', 'D', 0X0
|
||||
};
|
||||
static uint8_t legacy_adv_data[] = {0x02, 0x01, 0x06, 0x02, 0x0a, 0xeb, 0x15, 0x09, 'E', 'S', 'P', '_', 'M', 'U',
|
||||
'L', 'T', 'I', '_', 'A', 'D', 'V', '_', 'C', 'O', 'D', 'E', 'D', 0X0};
|
||||
|
||||
static uint8_t legacy_scan_rsp_data[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x16, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', 'L', 'E', 'G', 'A', 'C', 'Y', 0X0
|
||||
};
|
||||
|
||||
static uint8_t raw_scan_rsp_data_coded[] = {
|
||||
0x37, 0x09, 'V', 'E', 'R', 'Y', '_', 'L', 'O', 'N', 'G', '_', 'D', 'E', 'V', 'I', 'C', 'E', '_', 'N', 'A', 'M', 'E', '_',
|
||||
'S', 'E', 'N', 'T', '_', 'U', 'S', 'I', 'N', 'G', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V', 'E', 'R', 'T', 'I', 'S', 'I', 'N', 'G', 0X0
|
||||
};
|
||||
static uint8_t legacy_scan_rsp_data[] = {0x02, 0x01, 0x06, 0x02, 0x0a, 0xeb, 0x16, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L',
|
||||
'T', 'I', '_', 'A', 'D', 'V', '_', 'L', 'E', 'G', 'A', 'C', 'Y', 0X0};
|
||||
|
||||
static uint8_t raw_scan_rsp_data_coded[] = {0x37, 0x09, 'V', 'E', 'R', 'Y', '_', 'L', 'O', 'N', 'G', '_', 'D', 'E', 'V', 'I', 'C', 'E', '_',
|
||||
'N', 'A', 'M', 'E', '_', 'S', 'E', 'N', 'T', '_', 'U', 'S', 'I', 'N', 'G', '_', 'E', 'X', 'T',
|
||||
'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V', 'E', 'R', 'T', 'I', 'S', 'I', 'N', 'G', 0X0};
|
||||
|
||||
uint8_t addr_1m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x01};
|
||||
uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02};
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEAdvertising.h>
|
||||
|
||||
|
||||
esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
|
||||
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED,
|
||||
.interval_min = 0x40,
|
||||
@ -29,12 +28,8 @@ esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
|
||||
.scan_req_notif = false,
|
||||
};
|
||||
|
||||
static uint8_t raw_scan_rsp_data_2m[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', '2', 'M', 0X0
|
||||
};
|
||||
static uint8_t raw_scan_rsp_data_2m[] = {0x02, 0x01, 0x06, 0x02, 0x0a, 0xeb, 0x12, 0x09, 'E', 'S', 'P', '_', 'M',
|
||||
'U', 'L', 'T', 'I', '_', 'A', 'D', 'V', '_', '2', 'M', 0X0};
|
||||
|
||||
static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
|
||||
.interval_min = 0x320, // 1000 ms interval
|
||||
@ -42,14 +37,8 @@ static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
|
||||
.properties = 0, // Do not include TX power
|
||||
};
|
||||
|
||||
static uint8_t periodic_adv_raw_data[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x03, 0x03, 0xab, 0xcd,
|
||||
0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I',
|
||||
'C', '_', 'A', 'D', 'V'
|
||||
};
|
||||
|
||||
static uint8_t periodic_adv_raw_data[] = {0x02, 0x01, 0x06, 0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd, 0x11, 0x09, 'E', 'S',
|
||||
'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', 'C', '_', 'A', 'D', 'V'};
|
||||
|
||||
uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02};
|
||||
|
||||
|
@ -63,17 +63,11 @@ class MyPeriodicScan : public BLEPeriodicScanCallbacks {
|
||||
void onSync(esp_ble_periodic_adv_sync_estab_param_t params) {
|
||||
log_i("ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT, status %d", params.status);
|
||||
// esp_log_buffer_hex("sync addr", param->periodic_adv_sync_estab.adv_addr, 6);
|
||||
log_i("sync handle %d sid %d perioic adv interval %d adv phy %d", params.sync_handle,
|
||||
params.sid,
|
||||
params.period_adv_interval,
|
||||
params.adv_phy);
|
||||
log_i("sync handle %d sid %d perioic adv interval %d adv phy %d", params.sync_handle, params.sid, params.period_adv_interval, params.adv_phy);
|
||||
}
|
||||
|
||||
void onReport(esp_ble_gap_periodic_adv_report_t params) {
|
||||
log_i("periodic adv report, sync handle %d data status %d data len %d rssi %d", params.sync_handle,
|
||||
params.data_status,
|
||||
params.data_length,
|
||||
params.rssi);
|
||||
log_i("periodic adv report, sync handle %d data status %d data len %d rssi %d", params.sync_handle, params.data_status, params.data_length, params.rssi);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,10 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
BLEBeacon oBeacon = BLEBeacon();
|
||||
oBeacon.setData(strManufacturerData);
|
||||
Serial.printf("iBeacon Frame\n");
|
||||
Serial.printf("ID: %04X Major: %d Minor: %d UUID: %s Power: %d\n", oBeacon.getManufacturerId(), ENDIAN_CHANGE_U16(oBeacon.getMajor()), ENDIAN_CHANGE_U16(oBeacon.getMinor()), oBeacon.getProximityUUID().toString().c_str(), oBeacon.getSignalPower());
|
||||
Serial.printf(
|
||||
"ID: %04X Major: %d Minor: %d UUID: %s Power: %d\n", oBeacon.getManufacturerId(), ENDIAN_CHANGE_U16(oBeacon.getMajor()),
|
||||
ENDIAN_CHANGE_U16(oBeacon.getMinor()), oBeacon.getProximityUUID().toString().c_str(), oBeacon.getSignalPower()
|
||||
);
|
||||
} else {
|
||||
Serial.println("Found another manufacturers beacon!");
|
||||
Serial.printf("strManufacturerData: %d ", strManufacturerData.length());
|
||||
|
@ -19,11 +19,7 @@ static boolean doScan = false;
|
||||
static BLERemoteCharacteristic *pRemoteCharacteristic;
|
||||
static BLEAdvertisedDevice *myDevice;
|
||||
|
||||
static void notifyCallback(
|
||||
BLERemoteCharacteristic* pBLERemoteCharacteristic,
|
||||
uint8_t* pData,
|
||||
size_t length,
|
||||
bool isNotify) {
|
||||
static void notifyCallback(BLERemoteCharacteristic *pBLERemoteCharacteristic, uint8_t *pData, size_t length, bool isNotify) {
|
||||
Serial.print("Notify callback for characteristic ");
|
||||
Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str());
|
||||
Serial.print(" of data length ");
|
||||
@ -34,8 +30,7 @@ static void notifyCallback(
|
||||
}
|
||||
|
||||
class MyClientCallback : public BLEClientCallbacks {
|
||||
void onConnect(BLEClient* pclient) {
|
||||
}
|
||||
void onConnect(BLEClient *pclient) {}
|
||||
|
||||
void onDisconnect(BLEClient *pclient) {
|
||||
connected = false;
|
||||
@ -67,7 +62,6 @@ bool connectToServer() {
|
||||
}
|
||||
Serial.println(" - Found our service");
|
||||
|
||||
|
||||
// Obtain a reference to the characteristic in the service of the remote BLE server.
|
||||
pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
|
||||
if (pRemoteCharacteristic == nullptr) {
|
||||
@ -85,8 +79,9 @@ bool connectToServer() {
|
||||
Serial.println(value.c_str());
|
||||
}
|
||||
|
||||
if (pRemoteCharacteristic->canNotify())
|
||||
if (pRemoteCharacteristic->canNotify()) {
|
||||
pRemoteCharacteristic->registerForNotify(notifyCallback);
|
||||
}
|
||||
|
||||
connected = true;
|
||||
return true;
|
||||
@ -114,7 +109,6 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
} // onResult
|
||||
}; // MyAdvertisedDeviceCallbacks
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting Arduino BLE Client application...");
|
||||
@ -131,7 +125,6 @@ void setup() {
|
||||
pBLEScan->start(5, false);
|
||||
} // End of setup.
|
||||
|
||||
|
||||
// This is the Arduino main loop function.
|
||||
void loop() {
|
||||
|
||||
|
@ -89,5 +89,4 @@ void setup() {
|
||||
esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
@ -102,5 +102,4 @@ void setup() {
|
||||
esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
@ -36,7 +36,6 @@ uint32_t value = 0;
|
||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||
|
||||
|
||||
class MyServerCallbacks : public BLEServerCallbacks {
|
||||
void onConnect(BLEServer *pServer) {
|
||||
deviceConnected = true;
|
||||
@ -47,8 +46,6 @@ class MyServerCallbacks : public BLEServerCallbacks {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
@ -65,7 +62,8 @@ void setup() {
|
||||
// Create a BLE Characteristic
|
||||
pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE);
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE
|
||||
);
|
||||
|
||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
|
||||
// Create a BLE Descriptor
|
||||
|
@ -21,9 +21,8 @@ void setup() {
|
||||
BLEDevice::init("Long name works now");
|
||||
BLEServer *pServer = BLEDevice::createServer();
|
||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
|
||||
BLECharacteristic *pCharacteristic =
|
||||
pService->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
|
||||
|
||||
pCharacteristic->setValue("Hello World says Neil");
|
||||
pService->start();
|
||||
|
@ -36,7 +36,6 @@ uint32_t value = 0;
|
||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||
|
||||
|
||||
class MyServerCallbacks : public BLEServerCallbacks {
|
||||
void onConnect(BLEServer *pServer) {
|
||||
deviceConnected = true;
|
||||
@ -48,8 +47,6 @@ class MyServerCallbacks : public BLEServerCallbacks {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
@ -66,7 +63,8 @@ void setup() {
|
||||
// Create a BLE Characteristic
|
||||
pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE);
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE
|
||||
);
|
||||
|
||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
|
||||
// Create a BLE Descriptor
|
||||
|
@ -37,7 +37,6 @@ uint8_t txValue = 0;
|
||||
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||
|
||||
|
||||
class MyServerCallbacks : public BLEServerCallbacks {
|
||||
void onConnect(BLEServer *pServer) {
|
||||
deviceConnected = true;
|
||||
@ -55,8 +54,9 @@ class MyCallbacks : public BLECharacteristicCallbacks {
|
||||
if (rxValue.length() > 0) {
|
||||
Serial.println("*********");
|
||||
Serial.print("Received Value: ");
|
||||
for (int i = 0; i < rxValue.length(); i++)
|
||||
for (int i = 0; i < rxValue.length(); i++) {
|
||||
Serial.print(rxValue[i]);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.println("*********");
|
||||
@ -64,7 +64,6 @@ class MyCallbacks : public BLECharacteristicCallbacks {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
@ -79,15 +78,11 @@ void setup() {
|
||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||
|
||||
// Create a BLE Characteristic
|
||||
pTxCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID_TX,
|
||||
BLECharacteristic::PROPERTY_NOTIFY);
|
||||
pTxCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);
|
||||
|
||||
pTxCharacteristic->addDescriptor(new BLE2902());
|
||||
|
||||
BLECharacteristic *pRxCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID_RX,
|
||||
BLECharacteristic::PROPERTY_WRITE);
|
||||
BLECharacteristic *pRxCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE);
|
||||
|
||||
pRxCharacteristic->setCallbacks(new MyCallbacks());
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||
|
||||
|
||||
class MyCallbacks : public BLECharacteristicCallbacks {
|
||||
void onWrite(BLECharacteristic *pCharacteristic) {
|
||||
String value = pCharacteristic->getValue();
|
||||
@ -21,8 +20,9 @@ class MyCallbacks : public BLECharacteristicCallbacks {
|
||||
if (value.length() > 0) {
|
||||
Serial.println("*********");
|
||||
Serial.print("New value: ");
|
||||
for (int i = 0; i < value.length(); i++)
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
Serial.print(value[i]);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.println("*********");
|
||||
@ -44,9 +44,8 @@ void setup() {
|
||||
|
||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||
|
||||
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
|
||||
BLECharacteristic *pCharacteristic =
|
||||
pService->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
|
||||
|
||||
pCharacteristic->setCallbacks(new MyCallbacks());
|
||||
|
||||
|
@ -63,7 +63,6 @@ class MyCallbacks : public BLECharacteristicCallbacks {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void init_service() {
|
||||
BLEAdvertising *pAdvertising;
|
||||
pAdvertising = pServer->getAdvertising();
|
||||
@ -74,8 +73,8 @@ void init_service() {
|
||||
|
||||
// Create a BLE Characteristic
|
||||
pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY);
|
||||
CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY
|
||||
);
|
||||
pCharacteristic->setCallbacks(new MyCallbacks());
|
||||
pCharacteristic->addDescriptor(new BLE2902());
|
||||
|
||||
|
@ -17,13 +17,11 @@
|
||||
|
||||
#include "BLE2902.h"
|
||||
|
||||
BLE2902::BLE2902()
|
||||
: BLEDescriptor(BLEUUID((uint16_t)0x2902)) {
|
||||
BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t)0x2902)) {
|
||||
uint8_t data[2] = {0, 0};
|
||||
setValue(data, 2);
|
||||
} // BLE2902
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the notifications value.
|
||||
* @return The notifications value. True if notifications are enabled and false if not.
|
||||
@ -32,7 +30,6 @@ bool BLE2902::getNotifications() {
|
||||
return (getValue()[0] & (1 << 0)) != 0;
|
||||
} // getNotifications
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the indications value.
|
||||
* @return The indications value. True if indications are enabled and false if not.
|
||||
@ -41,27 +38,31 @@ bool BLE2902::getIndications() {
|
||||
return (getValue()[0] & (1 << 1)) != 0;
|
||||
} // getIndications
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the indications flag.
|
||||
* @param [in] flag The indications flag.
|
||||
*/
|
||||
void BLE2902::setIndications(bool flag) {
|
||||
uint8_t *pValue = getValue();
|
||||
if (flag) pValue[0] |= 1 << 1;
|
||||
else pValue[0] &= ~(1 << 1);
|
||||
if (flag) {
|
||||
pValue[0] |= 1 << 1;
|
||||
} else {
|
||||
pValue[0] &= ~(1 << 1);
|
||||
}
|
||||
setValue(pValue, 2);
|
||||
} // setIndications
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the notifications flag.
|
||||
* @param [in] flag The notifications flag.
|
||||
*/
|
||||
void BLE2902::setNotifications(bool flag) {
|
||||
uint8_t *pValue = getValue();
|
||||
if (flag) pValue[0] |= 1 << 0;
|
||||
else pValue[0] &= ~(1 << 0);
|
||||
if (flag) {
|
||||
pValue[0] |= 1 << 0;
|
||||
} else {
|
||||
pValue[0] &= ~(1 << 0);
|
||||
}
|
||||
setValue(pValue, 2);
|
||||
} // setNotifications
|
||||
|
||||
|
@ -17,9 +17,7 @@
|
||||
|
||||
#include "BLE2904.h"
|
||||
|
||||
|
||||
BLE2904::BLE2904()
|
||||
: BLEDescriptor(BLEUUID((uint16_t)0x2904)) {
|
||||
BLE2904::BLE2904() : BLEDescriptor(BLEUUID((uint16_t)0x2904)) {
|
||||
m_data.m_format = 0;
|
||||
m_data.m_exponent = 0;
|
||||
m_data.m_namespace = 1; // 1 = Bluetooth SIG Assigned Numbers
|
||||
@ -28,7 +26,6 @@ BLE2904::BLE2904()
|
||||
setValue((uint8_t *)&m_data, sizeof(m_data));
|
||||
} // BLE2902
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the description.
|
||||
*/
|
||||
@ -37,7 +34,6 @@ void BLE2904::setDescription(uint16_t description) {
|
||||
setValue((uint8_t *)&m_data, sizeof(m_data));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the exponent.
|
||||
*/
|
||||
@ -46,7 +42,6 @@ void BLE2904::setExponent(int8_t exponent) {
|
||||
setValue((uint8_t *)&m_data, sizeof(m_data));
|
||||
} // setExponent
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the format.
|
||||
*/
|
||||
@ -55,7 +50,6 @@ void BLE2904::setFormat(uint8_t format) {
|
||||
setValue((uint8_t *)&m_data, sizeof(m_data));
|
||||
} // setFormat
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the namespace.
|
||||
*/
|
||||
@ -64,7 +58,6 @@ void BLE2904::setNamespace(uint8_t namespace_value) {
|
||||
setValue((uint8_t *)&m_data, sizeof(m_data));
|
||||
} // setNamespace
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the units for this value. It should be one of the encoded values defined here:
|
||||
* https://www.bluetooth.com/specifications/assigned-numbers/units
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "esp32-hal-log.h"
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create an address from the native ESP32 representation.
|
||||
* @param [in] address The native representation.
|
||||
@ -30,7 +29,6 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
|
||||
memcpy(m_address, address, ESP_BD_ADDR_LEN);
|
||||
} // BLEAddress
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create an address from a hex string
|
||||
*
|
||||
@ -43,7 +41,9 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
|
||||
* @param [in] stringAddress The hex representation of the address.
|
||||
*/
|
||||
BLEAddress::BLEAddress(String stringAddress) {
|
||||
if (stringAddress.length() != 17) return;
|
||||
if (stringAddress.length() != 17) {
|
||||
return;
|
||||
}
|
||||
|
||||
int data[6];
|
||||
sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
|
||||
@ -55,7 +55,6 @@ BLEAddress::BLEAddress(String stringAddress) {
|
||||
m_address[5] = (uint8_t)data[5];
|
||||
} // BLEAddress
|
||||
|
||||
|
||||
/**
|
||||
* @brief Determine if this address equals another.
|
||||
* @param [in] otherAddress The other address to compare against.
|
||||
@ -97,7 +96,6 @@ esp_bd_addr_t* BLEAddress::getNative() {
|
||||
return &m_address;
|
||||
} // getNative
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convert a BLE address to a string.
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user