mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-06-26 02:11:34 +02:00
Compare commits
27 Commits
1.0.6
...
idf-releas
Author | SHA1 | Date | |
---|---|---|---|
d011dd7ef5 | |||
475208e535 | |||
2bf655b658 | |||
2fbbae762b | |||
d2761a9eab | |||
8c8d8610f4 | |||
c2da05050e | |||
3746ef9df9 | |||
92eb1a2264 | |||
b47b0dc966 | |||
2271c7726d | |||
9afee31462 | |||
f15a6ac205 | |||
176077b133 | |||
60f20a7869 | |||
8817e536fd | |||
d1e3122d87 | |||
856e596c79 | |||
2a88f72c4e | |||
354e485c4b | |||
5d9a22eb3a | |||
1c4966566c | |||
4bb60f68da | |||
a9fa894f0d | |||
251d5ef92b | |||
41ba143063 | |||
8c723be135 |
@ -23,9 +23,9 @@ if [ ! -d "$ARDUINO_ESP32_PATH" ]; then
|
|||||||
git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1
|
git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Updating Submodules ..."
|
#echo "Updating Submodules ..."
|
||||||
cd esp32
|
cd esp32
|
||||||
git submodule update --init --recursive > /dev/null 2>&1
|
#git submodule update --init --recursive > /dev/null 2>&1
|
||||||
|
|
||||||
echo "Installing Platform Tools ..."
|
echo "Installing Platform Tools ..."
|
||||||
cd tools && python get.py
|
cd tools && python get.py
|
||||||
|
12
.github/scripts/install-arduino-ide.sh
vendored
12
.github/scripts/install-arduino-ide.sh
vendored
@ -48,22 +48,16 @@ else
|
|||||||
export ARDUINO_USR_PATH="$HOME/Arduino"
|
export ARDUINO_USR_PATH="$HOME/Arduino"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Updated as of Nov 3rd 2020
|
|
||||||
ARDUINO_IDE_URL="https://github.com/espressif/arduino-esp32/releases/download/1.0.4/arduino-nightly-"
|
|
||||||
|
|
||||||
# Currently not working
|
|
||||||
#ARDUINO_IDE_URL="https://www.arduino.cc/download.php?f=/arduino-nightly-"
|
|
||||||
|
|
||||||
if [ ! -d "$ARDUINO_IDE_PATH" ]; then
|
if [ ! -d "$ARDUINO_IDE_PATH" ]; then
|
||||||
echo "Installing Arduino IDE on $OS_NAME ..."
|
echo "Installing Arduino IDE on $OS_NAME ..."
|
||||||
echo "Downloading '$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT' ..."
|
echo "Downloading 'arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT' ..."
|
||||||
if [ "$OS_IS_LINUX" == "1" ]; then
|
if [ "$OS_IS_LINUX" == "1" ]; then
|
||||||
wget -O "arduino.$ARCHIVE_FORMAT" "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
|
wget -O "arduino.$ARCHIVE_FORMAT" "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
|
||||||
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
|
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
|
||||||
tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null
|
tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null
|
||||||
mv arduino-nightly "$ARDUINO_IDE_PATH"
|
mv arduino-nightly "$ARDUINO_IDE_PATH"
|
||||||
else
|
else
|
||||||
curl -o "arduino.$ARCHIVE_FORMAT" -L "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
|
curl -o "arduino.$ARCHIVE_FORMAT" -L "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
|
||||||
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
|
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
|
||||||
unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
|
unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
|
||||||
if [ "$OS_IS_MACOS" == "1" ]; then
|
if [ "$OS_IS_MACOS" == "1" ]; then
|
||||||
|
11
.github/scripts/install-platformio-esp32.sh
vendored
11
.github/scripts/install-platformio-esp32.sh
vendored
@ -9,17 +9,22 @@ echo "Installing PlatformIO ..."
|
|||||||
pip install -U https://github.com/platformio/platformio/archive/develop.zip > /dev/null 2>&1
|
pip install -U https://github.com/platformio/platformio/archive/develop.zip > /dev/null 2>&1
|
||||||
|
|
||||||
echo "Installing Platform ESP32 ..."
|
echo "Installing Platform ESP32 ..."
|
||||||
python -m platformio platform install https://github.com/platformio/platform-espressif32.git > /dev/null 2>&1
|
python -m platformio platform install https://github.com/platformio/platform-espressif32.git#feature/stage > /dev/null 2>&1
|
||||||
|
|
||||||
echo "Replacing the framework version ..."
|
echo "Replacing the framework version ..."
|
||||||
python -c "import json; import os; fp=open(os.path.expanduser('~/.platformio/platforms/espressif32/platform.json'), 'r+'); data=json.load(fp); data['packages']['framework-arduinoespressif32']['version'] = '*'; del data['packages']['framework-arduinoespressif32']['owner']; fp.seek(0); fp.truncate(); json.dump(data, fp); fp.close()"
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
sed 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json" > "platform.json"
|
||||||
|
mv -f "platform.json" "$HOME/.platformio/platforms/espressif32/platform.json"
|
||||||
|
else
|
||||||
|
sed -i 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then
|
if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then
|
||||||
echo "Linking Core..."
|
echo "Linking Core..."
|
||||||
ln -s $GITHUB_WORKSPACE "$PLATFORMIO_ESP32_PATH"
|
ln -s $GITHUB_WORKSPACE "$PLATFORMIO_ESP32_PATH"
|
||||||
else
|
else
|
||||||
echo "Cloning Core Repository ..."
|
echo "Cloning Core Repository ..."
|
||||||
git clone --recursive https://github.com/espressif/arduino-esp32.git "$PLATFORMIO_ESP32_PATH" > /dev/null 2>&1
|
git clone https://github.com/espressif/arduino-esp32.git "$PLATFORMIO_ESP32_PATH" > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "PlatformIO for ESP32 has been installed"
|
echo "PlatformIO for ESP32 has been installed"
|
||||||
|
6
.github/scripts/on-pages.sh
vendored
6
.github/scripts/on-pages.sh
vendored
@ -87,15 +87,9 @@ function git_safe_upload_to_pages(){
|
|||||||
|
|
||||||
EVENT_JSON=`cat $GITHUB_EVENT_PATH`
|
EVENT_JSON=`cat $GITHUB_EVENT_PATH`
|
||||||
|
|
||||||
echo "GITHUB_EVENT_PATH: $GITHUB_EVENT_PATH"
|
|
||||||
echo "EVENT_JSON: $EVENT_JSON"
|
|
||||||
|
|
||||||
pages_added=`echo "$EVENT_JSON" | jq -r '.commits[].added[]'`
|
pages_added=`echo "$EVENT_JSON" | jq -r '.commits[].added[]'`
|
||||||
echo "added: $pages_added"
|
|
||||||
pages_modified=`echo "$EVENT_JSON" | jq -r '.commits[].modified[]'`
|
pages_modified=`echo "$EVENT_JSON" | jq -r '.commits[].modified[]'`
|
||||||
echo "modified: $pages_modified"
|
|
||||||
pages_removed=`echo "$EVENT_JSON" | jq -r '.commits[].removed[]'`
|
pages_removed=`echo "$EVENT_JSON" | jq -r '.commits[].removed[]'`
|
||||||
echo "removed: $pages_removed"
|
|
||||||
|
|
||||||
for page in $pages_added; do
|
for page in $pages_added; do
|
||||||
if [[ $page != "README.md" && $page != "docs/"* ]]; then
|
if [[ $page != "README.md" && $page != "docs/"* ]]; then
|
||||||
|
7
.github/scripts/on-push.sh
vendored
7
.github/scripts/on-push.sh
vendored
@ -30,8 +30,8 @@ elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then
|
|||||||
BUILD_PIO=1
|
BUILD_PIO=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Updating submodules ..."
|
#echo "Updating submodules ..."
|
||||||
git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
|
#git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
|
||||||
|
|
||||||
if [ "$BUILD_PIO" -eq 0 ]; then
|
if [ "$BUILD_PIO" -eq 0 ]; then
|
||||||
# ArduinoIDE Test
|
# ArduinoIDE Test
|
||||||
@ -41,14 +41,12 @@ if [ "$BUILD_PIO" -eq 0 ]; then
|
|||||||
if [ "$OS_IS_WINDOWS" == "1" ]; then
|
if [ "$OS_IS_WINDOWS" == "1" ]; then
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \
|
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
|
||||||
elif [ "$OS_IS_MACOS" == "1" ]; then
|
elif [ "$OS_IS_MACOS" == "1" ]; then
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \
|
|
||||||
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
|
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
|
||||||
else
|
else
|
||||||
# CMake Test
|
# CMake Test
|
||||||
@ -65,7 +63,6 @@ else
|
|||||||
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
|
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
|
||||||
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
|
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
|
||||||
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
|
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
|
||||||
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \
|
|
||||||
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
|
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
|
||||||
#build_pio_sketches esp32dev "$PLATFORMIO_ESP32_PATH/libraries"
|
#build_pio_sketches esp32dev "$PLATFORMIO_ESP32_PATH/libraries"
|
||||||
fi
|
fi
|
||||||
|
91
.github/scripts/on-release.sh
vendored
91
.github/scripts/on-release.sh
vendored
@ -171,19 +171,18 @@ mkdir -p "$PKG_DIR/tools"
|
|||||||
|
|
||||||
# Copy all core files to the package folder
|
# Copy all core files to the package folder
|
||||||
echo "Copying files for packaging ..."
|
echo "Copying files for packaging ..."
|
||||||
cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/"
|
cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/"
|
||||||
cp -f "$GITHUB_WORKSPACE/programmers.txt" "$PKG_DIR/"
|
cp -f "$GITHUB_WORKSPACE/programmers.txt" "$PKG_DIR/"
|
||||||
cp -Rf "$GITHUB_WORKSPACE/cores" "$PKG_DIR/"
|
cp -Rf "$GITHUB_WORKSPACE/cores" "$PKG_DIR/"
|
||||||
cp -Rf "$GITHUB_WORKSPACE/libraries" "$PKG_DIR/"
|
cp -Rf "$GITHUB_WORKSPACE/libraries" "$PKG_DIR/"
|
||||||
cp -Rf "$GITHUB_WORKSPACE/variants" "$PKG_DIR/"
|
cp -Rf "$GITHUB_WORKSPACE/variants" "$PKG_DIR/"
|
||||||
cp -f "$GITHUB_WORKSPACE/tools/espota.exe" "$PKG_DIR/tools/"
|
cp -f "$GITHUB_WORKSPACE/tools/espota.exe" "$PKG_DIR/tools/"
|
||||||
cp -f "$GITHUB_WORKSPACE/tools/espota.py" "$PKG_DIR/tools/"
|
cp -f "$GITHUB_WORKSPACE/tools/espota.py" "$PKG_DIR/tools/"
|
||||||
cp -f "$GITHUB_WORKSPACE/tools/esptool.py" "$PKG_DIR/tools/"
|
cp -f "$GITHUB_WORKSPACE/tools/esptool.py" "$PKG_DIR/tools/"
|
||||||
cp -f "$GITHUB_WORKSPACE/tools/gen_esp32part.py" "$PKG_DIR/tools/"
|
cp -f "$GITHUB_WORKSPACE/tools/gen_esp32part.py" "$PKG_DIR/tools/"
|
||||||
cp -f "$GITHUB_WORKSPACE/tools/gen_esp32part.exe" "$PKG_DIR/tools/"
|
cp -f "$GITHUB_WORKSPACE/tools/gen_esp32part.exe" "$PKG_DIR/tools/"
|
||||||
cp -Rf "$GITHUB_WORKSPACE/tools/partitions" "$PKG_DIR/tools/"
|
cp -Rf "$GITHUB_WORKSPACE/tools/partitions" "$PKG_DIR/tools/"
|
||||||
cp -Rf "$GITHUB_WORKSPACE/tools/sdk" "$PKG_DIR/tools/"
|
cp -Rf "$GITHUB_WORKSPACE/tools/sdk" "$PKG_DIR/tools/"
|
||||||
cp -f "$GITHUB_WORKSPACE/tools/platformio-build.py" "$PKG_DIR/tools/"
|
|
||||||
|
|
||||||
# Remove unnecessary files in the package folder
|
# Remove unnecessary files in the package folder
|
||||||
echo "Cleaning up folders ..."
|
echo "Cleaning up folders ..."
|
||||||
@ -255,30 +254,17 @@ releasesJson=`curl -sH "Authorization: token $GITHUB_TOKEN" "https://api.github.
|
|||||||
if [ $? -ne 0 ]; then echo "ERROR: Get Releases Failed! ($?)"; exit 1; fi
|
if [ $? -ne 0 ]; then echo "ERROR: Get Releases Failed! ($?)"; exit 1; fi
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
prev_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false)) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
|
prev_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false and .prerelease == false)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name')
|
||||||
prev_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false)) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
|
prev_any_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name')
|
||||||
prev_branch_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
|
|
||||||
prev_branch_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
|
|
||||||
shopt -s nocasematch
|
shopt -s nocasematch
|
||||||
if [ "$prev_release" == "$RELEASE_TAG" ]; then
|
|
||||||
prev_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false)) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
|
|
||||||
fi
|
|
||||||
if [ "$prev_any_release" == "$RELEASE_TAG" ]; then
|
if [ "$prev_any_release" == "$RELEASE_TAG" ]; then
|
||||||
prev_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false)) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
|
prev_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false and .prerelease == false)) | sort_by(.created_at | - fromdateiso8601) | .[1].tag_name')
|
||||||
fi
|
prev_any_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false)) | sort_by(.created_at | - fromdateiso8601) | .[1].tag_name')
|
||||||
if [ "$prev_branch_release" == "$RELEASE_TAG" ]; then
|
|
||||||
prev_branch_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
|
|
||||||
fi
|
|
||||||
if [ "$prev_branch_any_release" == "$RELEASE_TAG" ]; then
|
|
||||||
prev_branch_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
|
|
||||||
fi
|
fi
|
||||||
|
COMMITS_SINCE_RELEASE="$prev_any_release"
|
||||||
shopt -u nocasematch
|
shopt -u nocasematch
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "Previous Release: $prev_release"
|
|
||||||
echo "Previous (any)release: $prev_any_release"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Merge package JSONs with previous releases
|
# Merge package JSONs with previous releases
|
||||||
if [ ! -z "$prev_any_release" ] && [ "$prev_any_release" != "null" ]; then
|
if [ ! -z "$prev_any_release" ] && [ "$prev_any_release" != "null" ]; then
|
||||||
echo "Merging with JSON from $prev_any_release ..."
|
echo "Merging with JSON from $prev_any_release ..."
|
||||||
@ -286,12 +272,17 @@ if [ ! -z "$prev_any_release" ] && [ "$prev_any_release" != "null" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$RELEASE_PRE" == "false" ]; then
|
if [ "$RELEASE_PRE" == "false" ]; then
|
||||||
|
COMMITS_SINCE_RELEASE="$prev_release"
|
||||||
if [ ! -z "$prev_release" ] && [ "$prev_release" != "null" ]; then
|
if [ ! -z "$prev_release" ] && [ "$prev_release" != "null" ]; then
|
||||||
echo "Merging with JSON from $prev_release ..."
|
echo "Merging with JSON from $prev_release ..."
|
||||||
merge_package_json "$prev_release/$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL"
|
merge_package_json "$prev_release/$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Previous Release: $prev_release"
|
||||||
|
echo "Previous (any)release: $prev_any_release"
|
||||||
|
echo
|
||||||
|
|
||||||
# Upload package JSONs
|
# Upload package JSONs
|
||||||
echo "Uploading $PACKAGE_JSON_DEV ..."
|
echo "Uploading $PACKAGE_JSON_DEV ..."
|
||||||
echo "Download URL: "`git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV"`
|
echo "Download URL: "`git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV"`
|
||||||
@ -336,35 +327,21 @@ if [ $arrLen > 3 ] && [ "${msgArray[0]:0:3}" == "tag" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Append Commit Messages
|
# Append Commit Messages
|
||||||
echo
|
|
||||||
echo "Previous Branch Release: $prev_branch_release"
|
|
||||||
echo "Previous Branch (any)release: $prev_branch_any_release"
|
|
||||||
echo
|
|
||||||
commitFile="$OUTPUT_DIR/commits.txt"
|
|
||||||
COMMITS_SINCE_RELEASE="$prev_branch_any_release"
|
|
||||||
if [ "$RELEASE_PRE" == "false" ]; then
|
|
||||||
COMMITS_SINCE_RELEASE="$prev_branch_release"
|
|
||||||
fi
|
|
||||||
if [ ! -z "$COMMITS_SINCE_RELEASE" ] && [ "$COMMITS_SINCE_RELEASE" != "null" ]; then
|
if [ ! -z "$COMMITS_SINCE_RELEASE" ] && [ "$COMMITS_SINCE_RELEASE" != "null" ]; then
|
||||||
echo "Getting commits since $COMMITS_SINCE_RELEASE ..."
|
echo "Getting commits since $COMMITS_SINCE_RELEASE ..."
|
||||||
git -C "$GITHUB_WORKSPACE" log --oneline -n 500 "$COMMITS_SINCE_RELEASE..HEAD" > "$commitFile"
|
commitFile=$OUTPUT_DIR/commits.txt
|
||||||
elif [ "$RELEASE_BRANCH" != "master" ]; then
|
git -C "$GITHUB_WORKSPACE" log --oneline $COMMITS_SINCE_RELEASE.. > "$OUTPUT_DIR/commits.txt"
|
||||||
echo "Getting all commits on branch '$RELEASE_BRANCH' ..."
|
releaseNotes+=$'\r\n##### Commits\r\n'
|
||||||
git -C "$GITHUB_WORKSPACE" log --oneline -n 500 --cherry-pick --left-only --no-merges HEAD...origin/master > "$commitFile"
|
IFS=$'\n'
|
||||||
else
|
for next in `cat $commitFile`
|
||||||
echo "Getting all commits on master ..."
|
do
|
||||||
git -C "$GITHUB_WORKSPACE" log --oneline -n 500 --no-merges > "$commitFile"
|
IFS=' ' read -r commitId commitMsg <<< "$next"
|
||||||
|
commitLine="- [$commitId](https://github.com/$GITHUB_REPOSITORY/commit/$commitId) $commitMsg"
|
||||||
|
releaseNotes+="$commitLine"
|
||||||
|
releaseNotes+=$'\r\n'
|
||||||
|
done
|
||||||
|
rm -f $commitFile
|
||||||
fi
|
fi
|
||||||
releaseNotes+=$'\r\n##### Commits\r\n'
|
|
||||||
IFS=$'\n'
|
|
||||||
for next in `cat $commitFile`
|
|
||||||
do
|
|
||||||
IFS=' ' read -r commitId commitMsg <<< "$next"
|
|
||||||
commitLine="- [$commitId](https://github.com/$GITHUB_REPOSITORY/commit/$commitId) $commitMsg"
|
|
||||||
releaseNotes+="$commitLine"
|
|
||||||
releaseNotes+=$'\r\n'
|
|
||||||
done
|
|
||||||
rm -f $commitFile
|
|
||||||
|
|
||||||
# Prepend the original release body
|
# Prepend the original release body
|
||||||
if [ "${RELEASE_BODY: -1}" == $'\r' ]; then
|
if [ "${RELEASE_BODY: -1}" == $'\r' ]; then
|
||||||
|
11
.github/stale.yml
vendored
11
.github/stale.yml
vendored
@ -12,9 +12,12 @@ onlyLabels: []
|
|||||||
|
|
||||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||||
exemptLabels:
|
exemptLabels:
|
||||||
- "Type: For reference"
|
- pinned
|
||||||
- "Type: To be implemented"
|
- security
|
||||||
- "Type: Feature request"
|
- "to be implemented"
|
||||||
|
- "for reference"
|
||||||
|
- "move to PR"
|
||||||
|
- "enhancement"
|
||||||
|
|
||||||
# Set to true to ignore issues in a project (defaults to false)
|
# Set to true to ignore issues in a project (defaults to false)
|
||||||
exemptProjects: false
|
exemptProjects: false
|
||||||
@ -26,7 +29,7 @@ exemptMilestones: false
|
|||||||
exemptAssignees: false
|
exemptAssignees: false
|
||||||
|
|
||||||
# Label to use when marking as stale
|
# Label to use when marking as stale
|
||||||
staleLabel: Status: Stale
|
staleLabel: stale
|
||||||
|
|
||||||
# Comment to post when marking as stale. Set to `false` to disable
|
# Comment to post when marking as stale. Set to `false` to disable
|
||||||
markComment: >
|
markComment: >
|
||||||
|
3
.github/workflows/gh-pages.yml
vendored
3
.github/workflows/gh-pages.yml
vendored
@ -4,12 +4,9 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- pages
|
|
||||||
paths:
|
paths:
|
||||||
- 'README.md'
|
- 'README.md'
|
||||||
- 'docs/**'
|
- 'docs/**'
|
||||||
- '.github/scripts/on-pages.sh'
|
|
||||||
- '.github/workflows/gh-pages.yml'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -11,8 +11,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v1
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version: '3.x'
|
||||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,10 +1,9 @@
|
|||||||
tools/xtensa-esp32-elf
|
tools/xtensa-esp32-elf
|
||||||
tools/xtensa-esp32s2-elf
|
|
||||||
tools/dist
|
tools/dist
|
||||||
tools/esptool
|
tools/esptool
|
||||||
tools/esptool.exe
|
tools/esptool.exe
|
||||||
tools/mkspiffs
|
tools/mkspiffs/mkspiffs
|
||||||
tools/mklittlefs
|
tools/mkspiffs/mkspiffs.exe
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
#Ignore files built by Visual Studio/Visual Micro
|
#Ignore files built by Visual Studio/Visual Micro
|
||||||
@ -13,4 +12,3 @@ tools/mklittlefs
|
|||||||
.vs/
|
.vs/
|
||||||
__vm/
|
__vm/
|
||||||
*.vcxproj*
|
*.vcxproj*
|
||||||
.vscode/
|
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "libraries/AzureIoT"]
|
|
||||||
path = libraries/AzureIoT
|
|
||||||
url = https://github.com/VSChina/ESP32_AzureIoT_Arduino
|
|
||||||
|
@ -7,7 +7,6 @@ set(CORE_SRCS
|
|||||||
cores/esp32/esp32-hal-dac.c
|
cores/esp32/esp32-hal-dac.c
|
||||||
cores/esp32/esp32-hal-gpio.c
|
cores/esp32/esp32-hal-gpio.c
|
||||||
cores/esp32/esp32-hal-i2c.c
|
cores/esp32/esp32-hal-i2c.c
|
||||||
cores/esp32/esp32-hal-log.c
|
|
||||||
cores/esp32/esp32-hal-ledc.c
|
cores/esp32/esp32-hal-ledc.c
|
||||||
cores/esp32/esp32-hal-matrix.c
|
cores/esp32/esp32-hal-matrix.c
|
||||||
cores/esp32/esp32-hal-misc.c
|
cores/esp32/esp32-hal-misc.c
|
||||||
@ -61,7 +60,6 @@ set(LIBRARY_SRCS
|
|||||||
libraries/SPI/src/SPI.cpp
|
libraries/SPI/src/SPI.cpp
|
||||||
libraries/Ticker/src/Ticker.cpp
|
libraries/Ticker/src/Ticker.cpp
|
||||||
libraries/Update/src/Updater.cpp
|
libraries/Update/src/Updater.cpp
|
||||||
libraries/Update/src/HttpsOTAUpdate.cpp
|
|
||||||
libraries/WebServer/src/WebServer.cpp
|
libraries/WebServer/src/WebServer.cpp
|
||||||
libraries/WebServer/src/Parsing.cpp
|
libraries/WebServer/src/Parsing.cpp
|
||||||
libraries/WebServer/src/detail/mimetable.cpp
|
libraries/WebServer/src/detail/mimetable.cpp
|
||||||
@ -77,70 +75,9 @@ set(LIBRARY_SRCS
|
|||||||
libraries/WiFi/src/WiFiServer.cpp
|
libraries/WiFi/src/WiFiServer.cpp
|
||||||
libraries/WiFi/src/WiFiSTA.cpp
|
libraries/WiFi/src/WiFiSTA.cpp
|
||||||
libraries/WiFi/src/WiFiUdp.cpp
|
libraries/WiFi/src/WiFiUdp.cpp
|
||||||
libraries/WiFiProv/src/WiFiProv.cpp
|
|
||||||
libraries/Wire/src/Wire.cpp
|
libraries/Wire/src/Wire.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(AZURE_SRCS
|
|
||||||
libraries/AzureIoT/src/az_iot/azureiotcerts.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/agenttime.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/dns_async.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/lock.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/threadapi.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/tickcounter.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/lwip/sntp_lwip.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/socket_async.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/src/platform_openssl_compact.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/src/tlsio_openssl_compact.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/pal/tlsio_options.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/base64.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/buffer.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/connection_string_parser.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/consolelogger.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/constbuffer.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/constmap.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/crt_abstractions.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/doublylinkedlist.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/gballoc.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/gb_stdio.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/gb_time.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/hmac.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/hmacsha256.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/httpapiex.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/httpapiexsas.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/httpheaders.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/http_proxy_io.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/map.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/optionhandler.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/sastoken.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/sha1.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/sha224.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/sha384-512.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/singlylinkedlist.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/strings.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/string_tokenizer.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/urlencode.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/usha.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/vector.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/xio.c
|
|
||||||
libraries/AzureIoT/src/az_iot/c-utility/src/xlogging.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/blob.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_authorization.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_ll.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_retry_control.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_message.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransportmqtt.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport_mqtt_common.c
|
|
||||||
libraries/AzureIoT/src/az_iot/iothub_client/src/version.c
|
|
||||||
libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_client.c
|
|
||||||
libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_codec.c
|
|
||||||
libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_message.c
|
|
||||||
libraries/AzureIoT/src/AzureIotHub.cpp
|
|
||||||
libraries/AzureIoT/src/Esp32MQTTClient.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(BLE_SRCS
|
set(BLE_SRCS
|
||||||
libraries/BLE/src/BLE2902.cpp
|
libraries/BLE/src/BLE2902.cpp
|
||||||
libraries/BLE/src/BLE2904.cpp
|
libraries/BLE/src/BLE2904.cpp
|
||||||
@ -173,14 +110,13 @@ set(BLE_SRCS
|
|||||||
libraries/BLE/src/GeneralUtils.cpp
|
libraries/BLE/src/GeneralUtils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(COMPONENT_SRCS ${CORE_SRCS} ${LIBRARY_SRCS} ${AZURE_SRCS} ${BLE_SRCS})
|
set(COMPONENT_SRCS ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS})
|
||||||
|
|
||||||
set(COMPONENT_ADD_INCLUDEDIRS
|
set(COMPONENT_ADD_INCLUDEDIRS
|
||||||
variants/esp32/
|
variants/esp32/
|
||||||
cores/esp32/
|
cores/esp32/
|
||||||
libraries/ArduinoOTA/src
|
libraries/ArduinoOTA/src
|
||||||
libraries/AsyncUDP/src
|
libraries/AsyncUDP/src
|
||||||
libraries/AzureIoT/src
|
|
||||||
libraries/BLE/src
|
libraries/BLE/src
|
||||||
libraries/BluetoothSerial/src
|
libraries/BluetoothSerial/src
|
||||||
libraries/DNSServer/src
|
libraries/DNSServer/src
|
||||||
@ -203,18 +139,12 @@ set(COMPONENT_ADD_INCLUDEDIRS
|
|||||||
libraries/WebServer/src
|
libraries/WebServer/src
|
||||||
libraries/WiFiClientSecure/src
|
libraries/WiFiClientSecure/src
|
||||||
libraries/WiFi/src
|
libraries/WiFi/src
|
||||||
libraries/WiFiProv/src
|
|
||||||
libraries/Wire/src
|
libraries/Wire/src
|
||||||
)
|
)
|
||||||
|
|
||||||
set(COMPONENT_PRIV_INCLUDEDIRS cores/esp32/libb64)
|
set(COMPONENT_PRIV_INCLUDEDIRS cores/esp32/libb64)
|
||||||
|
|
||||||
set(COMPONENT_REQUIRES spi_flash mbedtls mdns ethernet esp_adc_cal wifi_provisioning)
|
set(COMPONENT_REQUIRES spi_flash mbedtls mdns esp_adc_cal)
|
||||||
set(COMPONENT_PRIV_REQUIRES fatfs nvs_flash app_update spiffs bootloader_support openssl bt esp_http_client esp_https_ota)
|
set(COMPONENT_PRIV_REQUIRES fatfs nvs_flash app_update spiffs bootloader_support openssl bt)
|
||||||
|
|
||||||
register_component()
|
register_component()
|
||||||
|
|
||||||
set_source_files_properties(libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport_mqtt_common.c
|
|
||||||
PROPERTIES COMPILE_FLAGS
|
|
||||||
-Wno-maybe-uninitialized
|
|
||||||
)
|
|
||||||
|
@ -40,12 +40,6 @@ config ARDUINO_RUNNING_CORE
|
|||||||
default 1 if ARDUINO_RUN_CORE1
|
default 1 if ARDUINO_RUN_CORE1
|
||||||
default -1 if ARDUINO_RUN_NO_AFFINITY
|
default -1 if ARDUINO_RUN_NO_AFFINITY
|
||||||
|
|
||||||
config ARDUINO_LOOP_STACK_SIZE
|
|
||||||
int "Loop thread stack size"
|
|
||||||
default 8192
|
|
||||||
help
|
|
||||||
Amount of stack available for the Arduino task.
|
|
||||||
|
|
||||||
choice ARDUINO_EVENT_RUNNING_CORE
|
choice ARDUINO_EVENT_RUNNING_CORE
|
||||||
bool "Core on which Arduino's event handler is running"
|
bool "Core on which Arduino's event handler is running"
|
||||||
default ARDUINO_EVENT_RUN_CORE1
|
default ARDUINO_EVENT_RUN_CORE1
|
||||||
@ -82,18 +76,13 @@ choice ARDUINO_UDP_RUNNING_CORE
|
|||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config ARDUINO_UDP_TASK_PRIORITY
|
|
||||||
int "Priority of the UDP task"
|
|
||||||
default 3
|
|
||||||
help
|
|
||||||
Select at what priority you want the UDP task to run.
|
|
||||||
|
|
||||||
config ARDUINO_UDP_RUNNING_CORE
|
config ARDUINO_UDP_RUNNING_CORE
|
||||||
int
|
int
|
||||||
default 0 if ARDUINO_UDP_RUN_CORE0
|
default 0 if ARDUINO_UDP_RUN_CORE0
|
||||||
default 1 if ARDUINO_UDP_RUN_CORE1
|
default 1 if ARDUINO_UDP_RUN_CORE1
|
||||||
default -1 if ARDUINO_UDP_RUN_NO_AFFINITY
|
default -1 if ARDUINO_UDP_RUN_NO_AFFINITY
|
||||||
|
|
||||||
|
|
||||||
config DISABLE_HAL_LOCKS
|
config DISABLE_HAL_LOCKS
|
||||||
bool "Disable mutex locks for HAL"
|
bool "Disable mutex locks for HAL"
|
||||||
default "n"
|
default "n"
|
||||||
|
@ -11,11 +11,9 @@
|
|||||||
- [ESP32Dev Board PINMAP](#esp32dev-board-pinmap)
|
- [ESP32Dev Board PINMAP](#esp32dev-board-pinmap)
|
||||||
|
|
||||||
### Development Status
|
### Development Status
|
||||||
|
[Latest stable release  ](https://github.com/espressif/arduino-esp32/releases/latest/) 
|
||||||
|
|
||||||
Latest Stable Release [](https://github.com/espressif/arduino-esp32/releases/latest/) [](https://github.com/espressif/arduino-esp32/releases/latest/) [](https://github.com/espressif/arduino-esp32/releases/latest/)
|
[Latest development release  ](https://github.com/espressif/arduino-esp32/releases/latest/) 
|
||||||
|
|
||||||
Latest Development Release [](https://github.com/espressif/arduino-esp32/releases/latest/) [](https://github.com/espressif/arduino-esp32/releases/latest/) [](https://github.com/espressif/arduino-esp32/releases/latest/)
|
|
||||||
|
|
||||||
|
|
||||||
### Installation Instructions
|
### Installation Instructions
|
||||||
- Using Arduino IDE Boards Manager (preferred)
|
- Using Arduino IDE Boards Manager (preferred)
|
||||||
|
2051
boards.txt
2051
boards.txt
File diff suppressed because it is too large
Load Diff
@ -78,7 +78,7 @@
|
|||||||
#define interrupts() sei()
|
#define interrupts() sei()
|
||||||
#define noInterrupts() cli()
|
#define noInterrupts() cli()
|
||||||
|
|
||||||
#define clockCyclesPerMicrosecond() ( (long int)getCpuFrequencyMhz() )
|
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||||
|
|
||||||
@ -88,7 +88,7 @@
|
|||||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||||
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
|
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||||
|
|
||||||
// avr-libc defines _NOP() since 1.6.2
|
// avr-libc defines _NOP() since 1.6.2
|
||||||
#ifndef _NOP
|
#ifndef _NOP
|
||||||
@ -118,7 +118,9 @@ typedef unsigned int word;
|
|||||||
void setup(void);
|
void setup(void);
|
||||||
void loop(void);
|
void loop(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
long random(long, long);
|
long random(long, long);
|
||||||
|
#endif
|
||||||
void randomSeed(unsigned long);
|
void randomSeed(unsigned long);
|
||||||
long map(long, long, long, long, long);
|
long map(long, long, long, long, long);
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "Esp.h"
|
#include "Esp.h"
|
||||||
#include "rom/spi_flash.h"
|
|
||||||
#include "esp_sleep.h"
|
#include "esp_sleep.h"
|
||||||
#include "esp_spi_flash.h"
|
#include "esp_spi_flash.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -32,6 +31,17 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#include <MD5Builder.h>
|
#include <MD5Builder.h>
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/spi_flash.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/spi_flash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User-defined Literals
|
* User-defined Literals
|
||||||
* usage:
|
* usage:
|
||||||
@ -218,33 +228,6 @@ uint8_t EspClass::getChipRevision(void)
|
|||||||
return chip_info.revision;
|
return chip_info.revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * EspClass::getChipModel(void)
|
|
||||||
{
|
|
||||||
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
|
|
||||||
uint32_t pkg_ver = chip_ver & 0x7;
|
|
||||||
switch (pkg_ver) {
|
|
||||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 :
|
|
||||||
return "ESP32-D0WDQ6";
|
|
||||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 :
|
|
||||||
return "ESP32-D0WDQ5";
|
|
||||||
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 :
|
|
||||||
return "ESP32-D2WDQ5";
|
|
||||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 :
|
|
||||||
return "ESP32-PICO-D2";
|
|
||||||
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 :
|
|
||||||
return "ESP32-PICO-D4";
|
|
||||||
default:
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t EspClass::getChipCores(void)
|
|
||||||
{
|
|
||||||
esp_chip_info_t chip_info;
|
|
||||||
esp_chip_info(&chip_info);
|
|
||||||
return chip_info.cores;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * EspClass::getSdkVersion(void)
|
const char * EspClass::getSdkVersion(void)
|
||||||
{
|
{
|
||||||
return esp_get_idf_version();
|
return esp_get_idf_version();
|
||||||
@ -336,20 +319,6 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size)
|
|||||||
return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
|
return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size)
|
|
||||||
{
|
|
||||||
return esp_partition_erase_range(partition, offset, size) == ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size)
|
|
||||||
{
|
|
||||||
return esp_partition_write(partition, offset, data, size) == ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size)
|
|
||||||
{
|
|
||||||
return esp_partition_read(partition, offset, data, size) == ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t EspClass::getEfuseMac(void)
|
uint64_t EspClass::getEfuseMac(void)
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#define ESP_H
|
#define ESP_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <esp_partition.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AVR macros for WDT managment
|
* AVR macros for WDT managment
|
||||||
@ -76,8 +75,6 @@ public:
|
|||||||
uint32_t getMaxAllocPsram();
|
uint32_t getMaxAllocPsram();
|
||||||
|
|
||||||
uint8_t getChipRevision();
|
uint8_t getChipRevision();
|
||||||
const char * getChipModel();
|
|
||||||
uint8_t getChipCores();
|
|
||||||
uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); }
|
uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); }
|
||||||
inline uint32_t getCycleCount() __attribute__((always_inline));
|
inline uint32_t getCycleCount() __attribute__((always_inline));
|
||||||
const char * getSdkVersion();
|
const char * getSdkVersion();
|
||||||
@ -100,10 +97,6 @@ public:
|
|||||||
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
|
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
|
||||||
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
|
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
|
||||||
|
|
||||||
bool partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size);
|
|
||||||
bool partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size);
|
|
||||||
bool partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size);
|
|
||||||
|
|
||||||
uint64_t getEfuseMac();
|
uint64_t getEfuseMac();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -53,8 +53,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
|
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
|
||||||
_tx_pin = txPin;
|
|
||||||
_rx_pin = rxPin;
|
|
||||||
|
|
||||||
if(!baud) {
|
if(!baud) {
|
||||||
uartStartDetectBaudrate(_uart);
|
uartStartDetectBaudrate(_uart);
|
||||||
@ -72,8 +70,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
|
|||||||
} else {
|
} else {
|
||||||
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
|
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
|
||||||
_uart = NULL;
|
_uart = NULL;
|
||||||
_tx_pin = 255;
|
|
||||||
_rx_pin = 255;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,8 +84,7 @@ void HardwareSerial::end()
|
|||||||
if(uartGetDebug() == _uart_nr) {
|
if(uartGetDebug() == _uart_nr) {
|
||||||
uartSetDebug(0);
|
uartSetDebug(0);
|
||||||
}
|
}
|
||||||
log_v("pins %d %d",_tx_pin, _rx_pin);
|
uartEnd(_uart);
|
||||||
uartEnd(_uart, _tx_pin, _rx_pin);
|
|
||||||
_uart = 0;
|
_uart = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +179,3 @@ HardwareSerial::operator bool() const
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::setRxInvert(bool invert)
|
|
||||||
{
|
|
||||||
uartSetRxInvert(_uart, invert);
|
|
||||||
}
|
|
||||||
|
@ -100,14 +100,10 @@ public:
|
|||||||
|
|
||||||
size_t setRxBufferSize(size_t);
|
size_t setRxBufferSize(size_t);
|
||||||
void setDebugOutput(bool);
|
void setDebugOutput(bool);
|
||||||
|
|
||||||
void setRxInvert(bool);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _uart_nr;
|
int _uart_nr;
|
||||||
uart_t* _uart;
|
uart_t* _uart;
|
||||||
uint8_t _tx_pin;
|
|
||||||
uint8_t _rx_pin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void serialEventRun(void) __attribute__((weak));
|
extern void serialEventRun(void) __attribute__((weak));
|
||||||
|
@ -21,7 +21,17 @@
|
|||||||
|
|
||||||
#include <WString.h>
|
#include <WString.h>
|
||||||
#include <Stream.h>
|
#include <Stream.h>
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/md5_hash.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
#include "rom/md5_hash.h"
|
#include "rom/md5_hash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
class MD5Builder
|
class MD5Builder
|
||||||
{
|
{
|
||||||
|
@ -110,37 +110,24 @@ size_t Print::print(unsigned int n, int base)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long n, int base)
|
size_t Print::print(long n, int base)
|
||||||
{
|
|
||||||
int t = 0;
|
|
||||||
if (base == 10 && n < 0) {
|
|
||||||
t = print('-');
|
|
||||||
n = -n;
|
|
||||||
}
|
|
||||||
return printNumber(static_cast<unsigned long>(n), base) + t;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
|
||||||
{
|
{
|
||||||
if(base == 0) {
|
if(base == 0) {
|
||||||
return write(n);
|
return write(n);
|
||||||
|
} else if(base == 10) {
|
||||||
|
if(n < 0) {
|
||||||
|
int t = print('-');
|
||||||
|
n = -n;
|
||||||
|
return printNumber(n, 10) + t;
|
||||||
|
}
|
||||||
|
return printNumber(n, 10);
|
||||||
} else {
|
} else {
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
int t = 0;
|
if(base == 0) {
|
||||||
if (base == 10 && n < 0) {
|
|
||||||
t = print('-');
|
|
||||||
n = -n;
|
|
||||||
}
|
|
||||||
return printNumber(static_cast<unsigned long long>(n), base) + t;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
|
||||||
{
|
|
||||||
if (base == 0) {
|
|
||||||
return write(n);
|
return write(n);
|
||||||
} else {
|
} else {
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
@ -239,20 +226,6 @@ size_t Print::println(unsigned long num, int base)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
|
||||||
{
|
|
||||||
size_t n = print(num, base);
|
|
||||||
n += println();
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
|
||||||
{
|
|
||||||
size_t n = print(num, base);
|
|
||||||
n += println();
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
@ -278,7 +251,7 @@ size_t Print::println(struct tm * timeinfo, const char * format)
|
|||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
@ -289,34 +262,11 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char c = n % base;
|
unsigned long m = n;
|
||||||
n /= base;
|
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
|
||||||
} while (n);
|
|
||||||
|
|
||||||
return write(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long long n, uint8_t base)
|
|
||||||
{
|
|
||||||
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
|
|
||||||
char* str = &buf[sizeof(buf) - 1];
|
|
||||||
|
|
||||||
*str = '\0';
|
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
|
||||||
if (base < 2) {
|
|
||||||
base = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
auto m = n;
|
|
||||||
n /= base;
|
n /= base;
|
||||||
char c = m - base * n;
|
char c = m - base * n;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while(n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ class Print
|
|||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printNumber(unsigned long long, uint8_t);
|
|
||||||
size_t printFloat(double, uint8_t);
|
size_t printFloat(double, uint8_t);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
@ -73,11 +72,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
|
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
|
|
||||||
// add availableForWrite to make compatible with Arduino Print.h
|
|
||||||
// default to zero, meaning "a single write may block"
|
|
||||||
// should be overriden by subclasses with buffering
|
|
||||||
virtual int availableForWrite() { return 0; }
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
@ -87,8 +81,6 @@ public:
|
|||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
|
||||||
size_t print(unsigned long long, int = DEC);
|
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
size_t print(struct tm * timeinfo, const char * format = NULL);
|
size_t print(struct tm * timeinfo, const char * format = NULL);
|
||||||
@ -102,8 +94,6 @@ public:
|
|||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
|
||||||
size_t println(unsigned long long, int = DEC);
|
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(struct tm * timeinfo, const char * format = NULL);
|
size_t println(struct tm * timeinfo, const char * format = NULL);
|
||||||
|
@ -87,22 +87,22 @@ unsigned long Stream::getTimeout(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find returns true if the target string is found
|
// find returns true if the target string is found
|
||||||
bool Stream::find(const char *target)
|
bool Stream::find(const char *target)
|
||||||
{
|
{
|
||||||
return findUntil(target, strlen(target), NULL, 0);
|
return findUntil(target, (char*) "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// reads data from the stream until the target string of given length is found
|
// reads data from the stream until the target string of given length is found
|
||||||
// returns true if target string is found, false if timed out
|
// returns true if target string is found, false if timed out
|
||||||
bool Stream::find(const char *target, size_t length)
|
bool Stream::find(const char *target, size_t length)
|
||||||
{
|
{
|
||||||
return findUntil(target, length, NULL, 0);
|
return findUntil(target, length, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// as find but search ends if the terminator string is found
|
// as find but search ends if the terminator string is found
|
||||||
bool Stream::findUntil(const char *target, const char *terminator)
|
bool Stream::findUntil(const char *target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target, strlen(target), terminator, strlen(terminator));
|
return findUntil(target, strlen(target), terminator, strlen(terminator));
|
||||||
}
|
}
|
||||||
|
|
||||||
// reads data from the stream until the target string of the given length is found
|
// reads data from the stream until the target string of the given length is found
|
||||||
@ -110,78 +110,35 @@ bool Stream::findUntil(const char *target, const char *terminator)
|
|||||||
// returns true if target string is found, false if terminated or timed out
|
// returns true if target string is found, false if terminated or timed out
|
||||||
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
||||||
{
|
{
|
||||||
if (terminator == NULL) {
|
size_t index = 0; // maximum target string length is 64k bytes!
|
||||||
MultiTarget t[1] = {{target, targetLen, 0}};
|
size_t termIndex = 0;
|
||||||
return findMulti(t, 1) == 0 ? true : false;
|
int c;
|
||||||
} else {
|
|
||||||
MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}};
|
|
||||||
return findMulti(t, 2) == 0 ? true : false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
|
if(*target == 0) {
|
||||||
// any zero length target string automatically matches and would make
|
return true; // return true if target is a null string
|
||||||
// a mess of the rest of the algorithm.
|
|
||||||
for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
|
|
||||||
if (t->len <= 0)
|
|
||||||
return t - targets;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
int c = timedRead();
|
|
||||||
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)
|
|
||||||
return t - targets;
|
|
||||||
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)
|
|
||||||
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])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// if it's the only char then we're good, nothing more to check
|
|
||||||
if (t->index == 0) {
|
|
||||||
t->index++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise we need to check the rest of the found string
|
|
||||||
int diff = origIndex - t->index;
|
|
||||||
size_t i;
|
|
||||||
for (i = 0; i < t->index; ++i) {
|
|
||||||
if (t->str[i] != t->str[i + diff])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we successfully got through the previous loop then our current
|
|
||||||
// index is good.
|
|
||||||
if (i == t->index) {
|
|
||||||
t->index++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise we just try the next index
|
|
||||||
} while (t->index);
|
|
||||||
}
|
}
|
||||||
}
|
while((c = timedRead()) > 0) {
|
||||||
// unreachable
|
|
||||||
return -1;
|
if(c != target[index]) {
|
||||||
|
index = 0; // reset index if any char does not match
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c == target[index]) {
|
||||||
|
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||||
|
if(++index >= targetLen) { // return true if all chars in the target match
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(termLen > 0 && c == terminator[termIndex]) {
|
||||||
|
if(++termIndex >= termLen) {
|
||||||
|
return false; // return false if terminate string found before target string
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
termIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the first valid (long) integer value from the current position.
|
// returns the first valid (long) integer value from the current position.
|
||||||
|
@ -60,7 +60,6 @@ public:
|
|||||||
|
|
||||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||||
unsigned long getTimeout(void);
|
unsigned long getTimeout(void);
|
||||||
|
|
||||||
bool find(const char *target); // reads data from the stream until the target string is found
|
bool find(const char *target); // reads data from the stream until the target string is found
|
||||||
bool find(uint8_t *target)
|
bool find(uint8_t *target)
|
||||||
{
|
{
|
||||||
@ -124,17 +123,6 @@ protected:
|
|||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
|
|
||||||
float parseFloat(char skipChar); // as above but the given skipChar is ignored
|
float parseFloat(char skipChar); // as above but the given skipChar is ignored
|
||||||
|
|
||||||
struct MultiTarget {
|
|
||||||
const char *str; // string you're searching for
|
|
||||||
size_t len; // length of string you're searching for
|
|
||||||
size_t index; // index used by the search routine.
|
|
||||||
};
|
|
||||||
|
|
||||||
// This allows you to search for an arbitrary number of strings.
|
|
||||||
// Returns index of the target that is found first or -1 if timeout occurs.
|
|
||||||
int findMulti(struct MultiTarget *targets, int tCount);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,7 +43,6 @@ class UDP: public Stream
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||||
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
|
||||||
virtual void stop() =0; // Finish with the UDP socket
|
virtual void stop() =0; // Finish with the UDP socket
|
||||||
|
|
||||||
// Sending UDP packets
|
// Sending UDP packets
|
||||||
|
@ -27,7 +27,6 @@ extern "C" {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
}
|
}
|
||||||
#include "esp32-hal-log.h"
|
|
||||||
|
|
||||||
void randomSeed(unsigned long seed)
|
void randomSeed(unsigned long seed)
|
||||||
{
|
{
|
||||||
@ -45,7 +44,7 @@ long random(long howbig)
|
|||||||
uint32_t t = -howbig;
|
uint32_t t = -howbig;
|
||||||
if (t >= howbig) {
|
if (t >= howbig) {
|
||||||
t -= howbig;
|
t -= howbig;
|
||||||
if (t >= howbig)
|
if (t >= howbig)
|
||||||
t %= howbig;
|
t %= howbig;
|
||||||
}
|
}
|
||||||
while (l < t) {
|
while (l < t) {
|
||||||
@ -67,14 +66,11 @@ long random(long howsmall, long howbig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||||
const long dividend = out_max - out_min;
|
long divisor = (in_max - in_min);
|
||||||
const long divisor = in_max - in_min;
|
|
||||||
const long delta = x - in_min;
|
|
||||||
if(divisor == 0){
|
if(divisor == 0){
|
||||||
log_e("Invalid map input range, min == max");
|
|
||||||
return -1; //AVR returns -1, SAM returns 0
|
return -1; //AVR returns -1, SAM returns 0
|
||||||
}
|
}
|
||||||
return (delta * dividend + (divisor / 2)) / divisor + out_min;
|
return (x - in_min) * (out_max - out_min) / divisor + out_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int makeWord(unsigned int w)
|
unsigned int makeWord(unsigned int w)
|
||||||
|
@ -130,9 +130,9 @@ String::~String() {
|
|||||||
|
|
||||||
inline void String::init(void) {
|
inline void String::init(void) {
|
||||||
setSSO(false);
|
setSSO(false);
|
||||||
setBuffer(nullptr);
|
|
||||||
setCapacity(0);
|
setCapacity(0);
|
||||||
setLen(0);
|
setLen(0);
|
||||||
|
setBuffer(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::invalidate(void) {
|
void String::invalidate(void) {
|
||||||
@ -159,7 +159,7 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
|
|||||||
// Already using SSO, nothing to do
|
// Already using SSO, nothing to do
|
||||||
uint16_t oldLen = len();
|
uint16_t oldLen = len();
|
||||||
setSSO(true);
|
setSSO(true);
|
||||||
setLen(oldLen);
|
setLen(oldLen);
|
||||||
return 1;
|
return 1;
|
||||||
} else { // if bufptr && !isSSO()
|
} else { // if bufptr && !isSSO()
|
||||||
// Using bufptr, need to shrink into sso.buff
|
// Using bufptr, need to shrink into sso.buff
|
||||||
@ -168,8 +168,8 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
|
|||||||
free(wbuffer());
|
free(wbuffer());
|
||||||
uint16_t oldLen = len();
|
uint16_t oldLen = len();
|
||||||
setSSO(true);
|
setSSO(true);
|
||||||
|
setLen(oldLen);
|
||||||
memcpy(wbuffer(), temp, maxStrLen);
|
memcpy(wbuffer(), temp, maxStrLen);
|
||||||
setLen(oldLen);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,8 +193,8 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
|
|||||||
}
|
}
|
||||||
setSSO(false);
|
setSSO(false);
|
||||||
setCapacity(newSize - 1);
|
setCapacity(newSize - 1);
|
||||||
setBuffer(newbuffer);
|
|
||||||
setLen(oldLen); // Needed in case of SSO where len() never existed
|
setLen(oldLen); // Needed in case of SSO where len() never existed
|
||||||
|
setBuffer(newbuffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -209,8 +209,8 @@ String & String::copy(const char *cstr, unsigned int length) {
|
|||||||
invalidate();
|
invalidate();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
memmove(wbuffer(), cstr, length + 1);
|
|
||||||
setLen(length);
|
setLen(length);
|
||||||
|
memmove(wbuffer(), cstr, length + 1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,8 +219,8 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
|
|||||||
invalidate();
|
invalidate();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
memcpy_P(wbuffer(), (PGM_P)pstr, length + 1); // We know wbuffer() cannot ever be in PROGMEM, so memcpy safe here
|
|
||||||
setLen(length);
|
setLen(length);
|
||||||
|
memcpy_P(wbuffer(), (PGM_P)pstr, length + 1); // We know wbuffer() cannot ever be in PROGMEM, so memcpy safe here
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +250,8 @@ void String::move(String &rhs) {
|
|||||||
setLen(rhs.len());
|
setLen(rhs.len());
|
||||||
rhs.setSSO(false);
|
rhs.setSSO(false);
|
||||||
rhs.setCapacity(0);
|
rhs.setCapacity(0);
|
||||||
rhs.setBuffer(nullptr);
|
|
||||||
rhs.setLen(0);
|
rhs.setLen(0);
|
||||||
|
rhs.setBuffer(nullptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -744,7 +744,6 @@ void String::replace(const String& find, const String& replace) {
|
|||||||
}
|
}
|
||||||
} else if(diff < 0) {
|
} else if(diff < 0) {
|
||||||
char *writeTo = wbuffer();
|
char *writeTo = wbuffer();
|
||||||
unsigned int l = len();
|
|
||||||
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
|
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
|
||||||
unsigned int n = foundAt - readFrom;
|
unsigned int n = foundAt - readFrom;
|
||||||
memmove(writeTo, readFrom, n);
|
memmove(writeTo, readFrom, n);
|
||||||
@ -752,10 +751,9 @@ void String::replace(const String& find, const String& replace) {
|
|||||||
memmove(writeTo, replace.buffer(), replace.len());
|
memmove(writeTo, replace.buffer(), replace.len());
|
||||||
writeTo += replace.len();
|
writeTo += replace.len();
|
||||||
readFrom = foundAt + find.len();
|
readFrom = foundAt + find.len();
|
||||||
l += diff;
|
setLen(len() + diff);
|
||||||
}
|
}
|
||||||
memmove(writeTo, readFrom, strlen(readFrom)+1);
|
memmove(writeTo, readFrom, strlen(readFrom)+1);
|
||||||
setLen(l);
|
|
||||||
} else {
|
} else {
|
||||||
unsigned int size = len(); // compute size needed for result
|
unsigned int size = len(); // compute size needed for result
|
||||||
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
|
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
|
||||||
@ -770,7 +768,7 @@ void String::replace(const String& find, const String& replace) {
|
|||||||
while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
|
while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
|
||||||
readFrom = wbuffer() + index + find.len();
|
readFrom = wbuffer() + index + find.len();
|
||||||
memmove(readFrom + diff, readFrom, len() - (readFrom - buffer()));
|
memmove(readFrom + diff, readFrom, len() - (readFrom - buffer()));
|
||||||
int newLen = len() + diff;
|
int newLen = len() + diff;
|
||||||
memmove(wbuffer() + index, replace.buffer(), replace.len());
|
memmove(wbuffer() + index, replace.buffer(), replace.len());
|
||||||
setLen(newLen);
|
setLen(newLen);
|
||||||
wbuffer()[newLen] = 0;
|
wbuffer()[newLen] = 0;
|
||||||
@ -798,8 +796,8 @@ void String::remove(unsigned int index, unsigned int count) {
|
|||||||
}
|
}
|
||||||
char *writeTo = wbuffer() + index;
|
char *writeTo = wbuffer() + index;
|
||||||
unsigned int newlen = len() - count;
|
unsigned int newlen = len() - count;
|
||||||
memmove(writeTo, wbuffer() + index + count, newlen - index);
|
|
||||||
setLen(newlen);
|
setLen(newlen);
|
||||||
|
memmove(writeTo, wbuffer() + index + count, newlen - index);
|
||||||
wbuffer()[newlen] = 0;
|
wbuffer()[newlen] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -829,9 +827,9 @@ void String::trim(void) {
|
|||||||
while(isspace(*end) && end >= begin)
|
while(isspace(*end) && end >= begin)
|
||||||
end--;
|
end--;
|
||||||
unsigned int newlen = end + 1 - begin;
|
unsigned int newlen = end + 1 - begin;
|
||||||
|
setLen(newlen);
|
||||||
if(begin > buffer())
|
if(begin > buffer())
|
||||||
memmove(wbuffer(), begin, newlen);
|
memmove(wbuffer(), begin, newlen);
|
||||||
setLen(newlen);
|
|
||||||
wbuffer()[newlen] = 0;
|
wbuffer()[newlen] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,19 +301,9 @@ class String {
|
|||||||
inline unsigned int len() const { return isSSO() ? sso.len : ptr.len; }
|
inline unsigned int len() const { return isSSO() ? sso.len : ptr.len; }
|
||||||
inline unsigned int capacity() const { return isSSO() ? (unsigned int)SSOSIZE - 1 : ptr.cap; } // Size of max string not including terminal NUL
|
inline unsigned int capacity() const { return isSSO() ? (unsigned int)SSOSIZE - 1 : ptr.cap; } // Size of max string not including terminal NUL
|
||||||
inline void setSSO(bool set) { sso.isSSO = set; }
|
inline void setSSO(bool set) { sso.isSSO = set; }
|
||||||
inline void setLen(int len) {
|
inline void setLen(int len) { if (isSSO()) sso.len = len; else ptr.len = len; }
|
||||||
if (isSSO()) {
|
|
||||||
sso.len = len;
|
|
||||||
sso.buff[len] = 0;
|
|
||||||
} else {
|
|
||||||
ptr.len = len;
|
|
||||||
if (ptr.buff) {
|
|
||||||
ptr.buff[len] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inline void setCapacity(int cap) { if (!isSSO()) ptr.cap = cap; }
|
inline void setCapacity(int cap) { if (!isSSO()) ptr.cap = cap; }
|
||||||
inline void setBuffer(char *buff) { if (!isSSO()) ptr.buff = buff; }
|
inline void setBuffer(char *buff) { if (!isSSO()) ptr.buff = buff; }
|
||||||
// Buffer accessor functions
|
// Buffer accessor functions
|
||||||
inline const char *buffer() const { return (const char *)(isSSO() ? sso.buff : ptr.buff); }
|
inline const char *buffer() const { return (const char *)(isSSO() ? sso.buff : ptr.buff); }
|
||||||
inline char *wbuffer() const { return isSSO() ? const_cast<char *>(sso.buff) : ptr.buff; } // Writable version of buffer
|
inline char *wbuffer() const { return isSSO() ? const_cast<char *>(sso.buff) : ptr.buff; } // Writable version of buffer
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
#include "esp32-hal-adc.h"
|
#include "esp32-hal-adc.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_intr.h"
|
|
||||||
#include "soc/rtc_io_reg.h"
|
#include "soc/rtc_io_reg.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "soc/sens_reg.h"
|
#include "soc/sens_reg.h"
|
||||||
@ -25,6 +23,19 @@
|
|||||||
#include "driver/adc.h"
|
#include "driver/adc.h"
|
||||||
#include "esp_adc_cal.h"
|
#include "esp_adc_cal.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_VREF 1100
|
#define DEFAULT_VREF 1100
|
||||||
static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL};
|
static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL};
|
||||||
static uint8_t __analogAttenuation = 3;//11db
|
static uint8_t __analogAttenuation = 3;//11db
|
||||||
|
@ -18,12 +18,11 @@
|
|||||||
|
|
||||||
bool btInUse(){ return true; }
|
bool btInUse(){ return true; }
|
||||||
|
|
||||||
|
#ifdef CONFIG_BLUEDROID_ENABLED
|
||||||
#include "esp_bt.h"
|
#include "esp_bt.h"
|
||||||
|
|
||||||
#ifdef CONFIG_BTDM_CONTROLLER_MODE_BTDM
|
#ifdef CONFIG_CLASSIC_BT_ENABLED
|
||||||
#define BT_MODE ESP_BT_MODE_BTDM
|
#define BT_MODE ESP_BT_MODE_BTDM
|
||||||
#elif defined(CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY)
|
|
||||||
#define BT_MODE ESP_BT_MODE_CLASSIC_BT
|
|
||||||
#else
|
#else
|
||||||
#define BT_MODE ESP_BT_MODE_BLE
|
#define BT_MODE ESP_BT_MODE_BLE
|
||||||
#endif
|
#endif
|
||||||
@ -80,7 +79,7 @@ bool btStop(){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // CONFIG_BT_ENABLED
|
#else
|
||||||
bool btStarted()
|
bool btStarted()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -95,6 +94,6 @@ bool btStop()
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif // CONFIG_BT_ENABLED
|
#endif
|
||||||
|
|
||||||
|
@ -21,12 +21,22 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "rom/rtc.h"
|
|
||||||
#include "soc/apb_ctrl_reg.h"
|
#include "soc/apb_ctrl_reg.h"
|
||||||
#include "soc/efuse_reg.h"
|
#include "soc/efuse_reg.h"
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
#include "esp32-hal-cpu.h"
|
#include "esp32-hal-cpu.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/rtc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/rtc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct apb_change_cb_s {
|
typedef struct apb_change_cb_s {
|
||||||
struct apb_change_cb_s * prev;
|
struct apb_change_cb_s * prev;
|
||||||
struct apb_change_cb_s * next;
|
struct apb_change_cb_s * next;
|
||||||
|
@ -15,13 +15,24 @@
|
|||||||
#include "esp32-hal-dac.h"
|
#include "esp32-hal-dac.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_intr.h"
|
|
||||||
#include "soc/rtc_io_reg.h"
|
#include "soc/rtc_io_reg.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "soc/sens_reg.h"
|
#include "soc/sens_reg.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void IRAM_ATTR __dacWrite(uint8_t pin, uint8_t value)
|
void IRAM_ATTR __dacWrite(uint8_t pin, uint8_t value)
|
||||||
{
|
{
|
||||||
if(pin < 25 || pin > 26){
|
if(pin < 25 || pin > 26){
|
||||||
|
@ -15,15 +15,27 @@
|
|||||||
#include "esp32-hal-gpio.h"
|
#include "esp32-hal-gpio.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_intr.h"
|
|
||||||
#include "rom/gpio.h"
|
|
||||||
#include "soc/gpio_reg.h"
|
#include "soc/gpio_reg.h"
|
||||||
#include "soc/io_mux_reg.h"
|
#include "soc/io_mux_reg.h"
|
||||||
#include "soc/gpio_struct.h"
|
#include "soc/gpio_struct.h"
|
||||||
#include "soc/rtc_io_reg.h"
|
#include "soc/rtc_io_reg.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp32/rom/gpio.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#include "rom/gpio.h"
|
||||||
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
const int8_t esp32_adc2gpio[20] = {36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26};
|
const int8_t esp32_adc2gpio[20] = {36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26};
|
||||||
|
|
||||||
const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
|
const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
|
||||||
|
@ -18,13 +18,25 @@
|
|||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "driver/periph_ctrl.h"
|
#include "driver/periph_ctrl.h"
|
||||||
#include "soc/i2c_reg.h"
|
#include "soc/i2c_reg.h"
|
||||||
#include "soc/i2c_struct.h"
|
#include "soc/i2c_struct.h"
|
||||||
#include "soc/dport_reg.h"
|
#include "soc/dport_reg.h"
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp32-hal-cpu.h" // cpu clock change support 31DEC2018
|
#include "esp32-hal-cpu.h" // cpu clock change support 31DEC2018
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//#define I2C_DEV(i) (volatile i2c_dev_t *)((i)?DR_REG_I2C1_EXT_BASE:DR_REG_I2C_EXT_BASE)
|
//#define I2C_DEV(i) (volatile i2c_dev_t *)((i)?DR_REG_I2C1_EXT_BASE:DR_REG_I2C_EXT_BASE)
|
||||||
//#define I2C_DEV(i) ((i2c_dev_t *)(REG_I2C_BASE(i)))
|
//#define I2C_DEV(i) ((i2c_dev_t *)(REG_I2C_BASE(i)))
|
||||||
#define I2C_SCL_IDX(p) ((p==0)?I2CEXT0_SCL_OUT_IDX:((p==1)?I2CEXT1_SCL_OUT_IDX:0))
|
#define I2C_SCL_IDX(p) ((p==0)?I2CEXT0_SCL_OUT_IDX:((p==1)?I2CEXT1_SCL_OUT_IDX:0))
|
||||||
@ -945,14 +957,6 @@ static void IRAM_ATTR i2c_isr_handler_default(void* arg)
|
|||||||
activeInt &=~I2C_RXFIFO_FULL_INT_ST;
|
activeInt &=~I2C_RXFIFO_FULL_INT_ST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(activeInt & I2C_RXFIFO_OVF_INT_ST) {
|
|
||||||
emptyRxFifo(p_i2c);
|
|
||||||
p_i2c->dev->int_clr.rx_fifo_full=1;
|
|
||||||
p_i2c->dev->int_ena.rx_fifo_full=1; //why?
|
|
||||||
|
|
||||||
activeInt &=~I2C_RXFIFO_OVF_INT_ST;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeInt & I2C_ACK_ERR_INT_ST_M) {//fatal error, abort i2c service
|
if (activeInt & I2C_ACK_ERR_INT_ST_M) {//fatal error, abort i2c service
|
||||||
if (p_i2c->mode == I2C_MASTER) {
|
if (p_i2c->mode == I2C_MASTER) {
|
||||||
i2c_update_error_byte_cnt(p_i2c); // calc which byte caused ack Error, check if address or data
|
i2c_update_error_byte_cnt(p_i2c); // calc which byte caused ack Error, check if address or data
|
||||||
|
@ -16,12 +16,22 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp32-hal-matrix.h"
|
#include "esp32-hal-matrix.h"
|
||||||
#include "soc/dport_reg.h"
|
#include "soc/dport_reg.h"
|
||||||
#include "soc/ledc_reg.h"
|
#include "soc/ledc_reg.h"
|
||||||
#include "soc/ledc_struct.h"
|
#include "soc/ledc_struct.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CONFIG_DISABLE_HAL_LOCKS
|
#if CONFIG_DISABLE_HAL_LOCKS
|
||||||
#define LEDC_MUTEX_LOCK()
|
#define LEDC_MUTEX_LOCK()
|
||||||
#define LEDC_MUTEX_UNLOCK()
|
#define LEDC_MUTEX_UNLOCK()
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
#ifndef __MY_LOG__
|
|
||||||
#define __MY_LOG__
|
|
||||||
#include "stdio.h"
|
|
||||||
#include "esp32-hal-log.h"
|
|
||||||
void log_to_esp(char* tag, esp_log_level_t level, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list va_args;
|
|
||||||
va_start(va_args, format);
|
|
||||||
|
|
||||||
char log_buffer[512];
|
|
||||||
int len = vsnprintf(log_buffer, sizeof(log_buffer), format, va_args);
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
ESP_LOG_LEVEL_LOCAL(level, tag, "%s", log_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(va_args);
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -36,9 +36,6 @@ extern "C"
|
|||||||
#define ARDUHAL_LOG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
|
#define ARDUHAL_LOG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
|
||||||
#else
|
#else
|
||||||
#define ARDUHAL_LOG_LEVEL CORE_DEBUG_LEVEL
|
#define ARDUHAL_LOG_LEVEL CORE_DEBUG_LEVEL
|
||||||
#ifdef USE_ESP_IDF_LOG
|
|
||||||
#define LOG_LOCAL_LEVEL CORE_DEBUG_LEVEL
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ARDUHAL_LOG_COLORS
|
#ifndef CONFIG_ARDUHAL_LOG_COLORS
|
||||||
@ -74,8 +71,6 @@ extern "C"
|
|||||||
#define ARDUHAL_LOG_RESET_COLOR
|
#define ARDUHAL_LOG_RESET_COLOR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char * pathToFileName(const char * path);
|
const char * pathToFileName(const char * path);
|
||||||
int log_printf(const char *fmt, ...);
|
int log_printf(const char *fmt, ...);
|
||||||
|
|
||||||
@ -83,92 +78,55 @@ int log_printf(const char *fmt, ...);
|
|||||||
#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__
|
#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__
|
||||||
|
|
||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
|
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
#ifndef USE_ESP_IDF_LOG
|
|
||||||
#define log_v(format, ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
|
#define log_v(format, ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
|
||||||
#define isr_log_v(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
|
#define isr_log_v(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define log_v(format, ...) do {log_to_esp(TAG, ESP_LOG_VERBOSE, 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)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define log_v(format, ...)
|
#define log_v(format, ...)
|
||||||
#define isr_log_v(format, ...)
|
#define isr_log_v(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
|
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
|
||||||
#ifndef USE_ESP_IDF_LOG
|
|
||||||
#define log_d(format, ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
|
#define log_d(format, ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
|
||||||
#define isr_log_d(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
|
#define isr_log_d(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define log_d(format, ...) do {log_to_esp(TAG, ESP_LOG_DEBUG, 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)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define log_d(format, ...)
|
#define log_d(format, ...)
|
||||||
#define isr_log_d(format, ...)
|
#define isr_log_d(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
|
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
|
||||||
#ifndef USE_ESP_IDF_LOG
|
|
||||||
#define log_i(format, ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
|
#define log_i(format, ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
|
||||||
#define isr_log_i(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
|
#define isr_log_i(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define log_i(format, ...) do {log_to_esp(TAG, ESP_LOG_INFO, 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)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define log_i(format, ...)
|
#define log_i(format, ...)
|
||||||
#define isr_log_i(format, ...)
|
#define isr_log_i(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
|
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
|
||||||
#ifndef USE_ESP_IDF_LOG
|
|
||||||
#define log_w(format, ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
|
#define log_w(format, ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
|
||||||
#define isr_log_w(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
|
#define isr_log_w(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define log_w(format, ...) do {log_to_esp(TAG, ESP_LOG_WARN, 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)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define log_w(format, ...)
|
#define log_w(format, ...)
|
||||||
#define isr_log_w(format, ...)
|
#define isr_log_w(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
|
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
|
||||||
#ifndef USE_ESP_IDF_LOG
|
|
||||||
#define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
#define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
||||||
#define isr_log_e(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
#define isr_log_e(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define log_e(format, ...) do {log_to_esp(TAG, ESP_LOG_ERROR, 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)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define log_e(format, ...)
|
#define log_e(format, ...)
|
||||||
#define isr_log_e(format, ...)
|
#define isr_log_e(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE
|
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE
|
||||||
#ifndef USE_ESP_IDF_LOG
|
|
||||||
#define log_n(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
#define log_n(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
||||||
#define isr_log_n(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
#define isr_log_n(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define log_n(format, ...) do {log_to_esp(TAG, ESP_LOG_ERROR, 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)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define log_n(format, ...)
|
#define log_n(format, ...)
|
||||||
#define isr_log_n(format, ...)
|
#define isr_log_n(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF_LOG
|
|
||||||
#ifndef TAG
|
|
||||||
#define TAG "ARDUINO"
|
|
||||||
#endif
|
|
||||||
void log_to_esp(char* tag, esp_log_level_t level, const char* format, ...);
|
|
||||||
//#define log_n(format, ...) myLog(ESP_LOG_NONE, format, ##__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#ifdef CONFIG_ARDUHAL_ESP_LOG
|
#ifdef CONFIG_ARDUHAL_ESP_LOG
|
||||||
#undef ESP_LOGE
|
#undef ESP_LOGE
|
||||||
#undef ESP_LOGW
|
#undef ESP_LOGW
|
||||||
@ -192,7 +150,6 @@ void log_to_esp(char* tag, esp_log_level_t level, const char* format, ...);
|
|||||||
#define ESP_EARLY_LOGD(tag, ...) isr_log_d(__VA_ARGS__)
|
#define ESP_EARLY_LOGD(tag, ...) isr_log_d(__VA_ARGS__)
|
||||||
#define ESP_EARLY_LOGV(tag, ...) isr_log_v(__VA_ARGS__)
|
#define ESP_EARLY_LOGV(tag, ...) isr_log_v(__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,17 @@
|
|||||||
|
|
||||||
#include "esp32-hal-matrix.h"
|
#include "esp32-hal-matrix.h"
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/gpio.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
#include "rom/gpio.h"
|
#include "rom/gpio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MATRIX_DETACH_OUT_SIG 0x100
|
#define MATRIX_DETACH_OUT_SIG 0x100
|
||||||
#define MATRIX_DETACH_IN_LOW_PIN 0x30
|
#define MATRIX_DETACH_IN_LOW_PIN 0x30
|
||||||
|
@ -31,10 +31,20 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "soc/apb_ctrl_reg.h"
|
#include "soc/apb_ctrl_reg.h"
|
||||||
#include "rom/rtc.h"
|
|
||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/rtc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/rtc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
//Undocumented!!! Get chip temperature in Farenheit
|
//Undocumented!!! Get chip temperature in Farenheit
|
||||||
//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino
|
//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino
|
||||||
uint8_t temprature_sens_read();
|
uint8_t temprature_sens_read();
|
||||||
|
@ -1,11 +1,34 @@
|
|||||||
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
|
|
||||||
#if CONFIG_SPIRAM_SUPPORT
|
#if CONFIG_SPIRAM_SUPPORT
|
||||||
#include "esp_spiram.h"
|
|
||||||
#include "soc/efuse_reg.h"
|
#include "soc/efuse_reg.h"
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/spiram.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "esp_spiram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static volatile bool spiramDetected = false;
|
static volatile bool spiramDetected = false;
|
||||||
static volatile bool spiramFailed = false;
|
static volatile bool spiramFailed = false;
|
||||||
|
|
||||||
|
@ -94,7 +94,6 @@ struct rmt_obj_s
|
|||||||
transaction_state_t tx_state;
|
transaction_state_t tx_state;
|
||||||
rmt_rx_data_cb_t cb;
|
rmt_rx_data_cb_t cb;
|
||||||
bool data_alloc;
|
bool data_alloc;
|
||||||
void * arg;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,14 +104,14 @@ static xSemaphoreHandle g_rmt_objlocks[MAX_CHANNELS] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static rmt_obj_t g_rmt_objects[MAX_CHANNELS] = {
|
static rmt_obj_t g_rmt_objects[MAX_CHANNELS] = {
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false, NULL},
|
{ false, NULL, 0, 0, 0, 0, 0, NULL, E_NO_INTR, E_INACTIVE, NULL, false},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,7 +323,6 @@ bool rmtReadData(rmt_obj_t* rmt, uint32_t* data, size_t size)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool rmtBeginReceive(rmt_obj_t* rmt)
|
bool rmtBeginReceive(rmt_obj_t* rmt)
|
||||||
{
|
{
|
||||||
if (!rmt) {
|
if (!rmt) {
|
||||||
@ -358,7 +356,7 @@ bool rmtReceiveCompleted(rmt_obj_t* rmt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb, void * arg)
|
bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb)
|
||||||
{
|
{
|
||||||
if (!rmt && !cb) {
|
if (!rmt && !cb) {
|
||||||
return false;
|
return false;
|
||||||
@ -366,7 +364,6 @@ bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb, void * arg)
|
|||||||
int channel = rmt->channel;
|
int channel = rmt->channel;
|
||||||
|
|
||||||
RMT_MUTEX_LOCK(channel);
|
RMT_MUTEX_LOCK(channel);
|
||||||
rmt->arg = arg;
|
|
||||||
rmt->intr_mode = E_RX_INTR;
|
rmt->intr_mode = E_RX_INTR;
|
||||||
rmt->tx_state = E_FIRST_HALF;
|
rmt->tx_state = E_FIRST_HALF;
|
||||||
rmt->cb = cb;
|
rmt->cb = cb;
|
||||||
@ -393,19 +390,6 @@ bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb, void * arg)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rmtEnd(rmt_obj_t* rmt) {
|
|
||||||
if (!rmt) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int channel = rmt->channel;
|
|
||||||
|
|
||||||
RMT_MUTEX_LOCK(channel);
|
|
||||||
RMT.conf_ch[channel].conf1.rx_en = 1;
|
|
||||||
RMT_MUTEX_UNLOCK(channel);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rmtReadAsync(rmt_obj_t* rmt, rmt_data_t* data, size_t size, void* eventFlag, bool waitForData, uint32_t timeout)
|
bool rmtReadAsync(rmt_obj_t* rmt, rmt_data_t* data, size_t size, void* eventFlag, bool waitForData, uint32_t timeout)
|
||||||
{
|
{
|
||||||
if (!rmt) {
|
if (!rmt) {
|
||||||
@ -538,8 +522,6 @@ rmt_obj_t* rmtInit(int pin, bool tx_not_rx, rmt_reserve_memsize_t memsize)
|
|||||||
rmt->tx_not_rx = tx_not_rx;
|
rmt->tx_not_rx = tx_not_rx;
|
||||||
rmt->buffers =buffers;
|
rmt->buffers =buffers;
|
||||||
rmt->channel = channel;
|
rmt->channel = channel;
|
||||||
rmt->arg = NULL;
|
|
||||||
|
|
||||||
_initPin(pin, channel, tx_not_rx);
|
_initPin(pin, channel, tx_not_rx);
|
||||||
|
|
||||||
// Initialize the registers in default mode:
|
// Initialize the registers in default mode:
|
||||||
@ -561,7 +543,6 @@ rmt_obj_t* rmtInit(int pin, bool tx_not_rx, rmt_reserve_memsize_t memsize)
|
|||||||
RMT.conf_ch[channel].conf1.idle_out_lv = 0; // signal level for idle
|
RMT.conf_ch[channel].conf1.idle_out_lv = 0; // signal level for idle
|
||||||
RMT.conf_ch[channel].conf1.idle_out_en = 1; // enable idle
|
RMT.conf_ch[channel].conf1.idle_out_en = 1; // enable idle
|
||||||
RMT.conf_ch[channel].conf1.ref_always_on = 0; // base clock
|
RMT.conf_ch[channel].conf1.ref_always_on = 0; // base clock
|
||||||
|
|
||||||
RMT.apb_conf.fifo_mask = 1;
|
RMT.apb_conf.fifo_mask = 1;
|
||||||
|
|
||||||
if (tx_not_rx) {
|
if (tx_not_rx) {
|
||||||
@ -677,7 +658,7 @@ static void IRAM_ATTR _rmt_isr(void* arg)
|
|||||||
}
|
}
|
||||||
if (g_rmt_objects[ch].cb) {
|
if (g_rmt_objects[ch].cb) {
|
||||||
// actually received data ptr
|
// actually received data ptr
|
||||||
(g_rmt_objects[ch].cb)(data_received, _rmt_get_mem_len(ch), g_rmt_objects[ch].arg);
|
(g_rmt_objects[ch].cb)(data_received, _rmt_get_mem_len(ch));
|
||||||
|
|
||||||
// restart the reception
|
// restart the reception
|
||||||
RMT.conf_ch[ch].conf1.mem_owner = 1;
|
RMT.conf_ch[ch].conf1.mem_owner = 1;
|
||||||
|
@ -40,7 +40,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct rmt_obj_s rmt_obj_t;
|
typedef struct rmt_obj_s rmt_obj_t;
|
||||||
|
|
||||||
typedef void (*rmt_rx_data_cb_t)(uint32_t *data, size_t len, void *arg);
|
typedef void (*rmt_rx_data_cb_t)(uint32_t *data, size_t len);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
@ -90,13 +90,8 @@ bool rmtReadAsync(rmt_obj_t* rmt, rmt_data_t* data, size_t size, void* eventFlag
|
|||||||
* and callback with data from ISR
|
* and callback with data from ISR
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb, void * arg);
|
bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb);
|
||||||
|
|
||||||
/***
|
|
||||||
* Ends async receive started with rmtRead(); but does not
|
|
||||||
* rmtDeInit().
|
|
||||||
*/
|
|
||||||
bool rmtEnd(rmt_obj_t* rmt);
|
|
||||||
|
|
||||||
/* Additional interface */
|
/* Additional interface */
|
||||||
|
|
||||||
|
@ -16,11 +16,21 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp32-hal-matrix.h"
|
#include "esp32-hal-matrix.h"
|
||||||
#include "soc/gpio_sd_reg.h"
|
#include "soc/gpio_sd_reg.h"
|
||||||
#include "soc/gpio_sd_struct.h"
|
#include "soc/gpio_sd_struct.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if CONFIG_DISABLE_HAL_LOCKS
|
#if CONFIG_DISABLE_HAL_LOCKS
|
||||||
#define SD_MUTEX_LOCK()
|
#define SD_MUTEX_LOCK()
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_intr.h"
|
|
||||||
#include "rom/gpio.h"
|
|
||||||
#include "soc/spi_reg.h"
|
#include "soc/spi_reg.h"
|
||||||
#include "soc/spi_struct.h"
|
#include "soc/spi_struct.h"
|
||||||
#include "soc/io_mux_reg.h"
|
#include "soc/io_mux_reg.h"
|
||||||
@ -28,6 +25,21 @@
|
|||||||
#include "soc/dport_reg.h"
|
#include "soc/dport_reg.h"
|
||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp32/rom/gpio.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#include "rom/gpio.h"
|
||||||
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_IDX:((p==1)?SPICLK_OUT_IDX:((p==2)?HSPICLK_OUT_IDX:((p==3)?VSPICLK_OUT_IDX:0))))
|
#define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_IDX:((p==1)?SPICLK_OUT_IDX:((p==2)?HSPICLK_OUT_IDX:((p==3)?VSPICLK_OUT_IDX:0))))
|
||||||
#define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?SPIQ_OUT_IDX:((p==2)?HSPIQ_OUT_IDX:((p==3)?VSPIQ_OUT_IDX:0))))
|
#define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?SPIQ_OUT_IDX:((p==2)?HSPIQ_OUT_IDX:((p==3)?VSPIQ_OUT_IDX:0))))
|
||||||
#define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?SPID_IN_IDX:((p==2)?HSPID_IN_IDX:((p==3)?VSPID_IN_IDX:0))))
|
#define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?SPID_IN_IDX:((p==2)?HSPID_IN_IDX:((p==3)?VSPID_IN_IDX:0))))
|
||||||
@ -384,8 +396,12 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spiInitBus(spi_t * spi)
|
void spiStopBus(spi_t * spi)
|
||||||
{
|
{
|
||||||
|
if(!spi) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SPI_MUTEX_LOCK();
|
||||||
spi->dev->slave.trans_done = 0;
|
spi->dev->slave.trans_done = 0;
|
||||||
spi->dev->slave.slave_mode = 0;
|
spi->dev->slave.slave_mode = 0;
|
||||||
spi->dev->pin.val = 0;
|
spi->dev->pin.val = 0;
|
||||||
@ -395,19 +411,8 @@ static void spiInitBus(spi_t * spi)
|
|||||||
spi->dev->ctrl1.val = 0;
|
spi->dev->ctrl1.val = 0;
|
||||||
spi->dev->ctrl2.val = 0;
|
spi->dev->ctrl2.val = 0;
|
||||||
spi->dev->clock.val = 0;
|
spi->dev->clock.val = 0;
|
||||||
}
|
|
||||||
|
|
||||||
void spiStopBus(spi_t * spi)
|
|
||||||
{
|
|
||||||
if(!spi) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeApbChangeCallback(spi, _on_apb_change);
|
|
||||||
|
|
||||||
SPI_MUTEX_LOCK();
|
|
||||||
spiInitBus(spi);
|
|
||||||
SPI_MUTEX_UNLOCK();
|
SPI_MUTEX_UNLOCK();
|
||||||
|
removeApbChangeCallback(spi, _on_apb_change);
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder)
|
spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder)
|
||||||
@ -438,8 +443,12 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_
|
|||||||
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST);
|
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spiStopBus(spi);
|
||||||
|
spiSetDataMode(spi, dataMode);
|
||||||
|
spiSetBitOrder(spi, bitOrder);
|
||||||
|
spiSetClockDiv(spi, clockDiv);
|
||||||
|
|
||||||
SPI_MUTEX_LOCK();
|
SPI_MUTEX_LOCK();
|
||||||
spiInitBus(spi);
|
|
||||||
spi->dev->user.usr_mosi = 1;
|
spi->dev->user.usr_mosi = 1;
|
||||||
spi->dev->user.usr_miso = 1;
|
spi->dev->user.usr_miso = 1;
|
||||||
spi->dev->user.doutdin = 1;
|
spi->dev->user.doutdin = 1;
|
||||||
@ -450,10 +459,6 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_
|
|||||||
}
|
}
|
||||||
SPI_MUTEX_UNLOCK();
|
SPI_MUTEX_UNLOCK();
|
||||||
|
|
||||||
spiSetDataMode(spi, dataMode);
|
|
||||||
spiSetBitOrder(spi, bitOrder);
|
|
||||||
spiSetClockDiv(spi, clockDiv);
|
|
||||||
|
|
||||||
addApbChangeCallback(spi, _on_apb_change);
|
addApbChangeCallback(spi, _on_apb_change);
|
||||||
return spi;
|
return spi;
|
||||||
}
|
}
|
||||||
@ -914,20 +919,8 @@ void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, u
|
|||||||
spi->dev->cmd.usr = 1;
|
spi->dev->cmd.usr = 1;
|
||||||
while(spi->dev->cmd.usr);
|
while(spi->dev->cmd.usr);
|
||||||
if(result){
|
if(result){
|
||||||
if(c_len & 3){
|
for (int i=0; i<c_longs; i++) {
|
||||||
for (int i=0; i<(c_longs-1); i++) {
|
result[i] = spi->dev->data_buf[i];
|
||||||
result[i] = spi->dev->data_buf[i];
|
|
||||||
}
|
|
||||||
uint32_t last_data = spi->dev->data_buf[c_longs-1];
|
|
||||||
uint8_t * last_out8 = &result[c_longs-1];
|
|
||||||
uint8_t * last_data8 = &last_data;
|
|
||||||
for (int i=0; i<(c_len & 3); i++) {
|
|
||||||
last_out8[i] = last_data8[i];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int i=0; i<c_longs; i++) {
|
|
||||||
result[i] = spi->dev->data_buf[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(data){
|
if(data){
|
||||||
|
@ -54,7 +54,7 @@ extern "C" {
|
|||||||
struct spi_struct_t;
|
struct spi_struct_t;
|
||||||
typedef struct spi_struct_t spi_t;
|
typedef struct spi_struct_t spi_t;
|
||||||
|
|
||||||
spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder);
|
spi_t * spiStartBus(uint8_t spi_num, uint32_t freq, uint8_t dataMode, uint8_t bitOrder);
|
||||||
void spiStopBus(spi_t * spi);
|
void spiStopBus(spi_t * spi);
|
||||||
|
|
||||||
//Attach/Detach Signal Pins
|
//Attach/Detach Signal Pins
|
||||||
|
@ -16,11 +16,22 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/xtensa_api.h"
|
#include "freertos/xtensa_api.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "soc/timer_group_struct.h"
|
#include "soc/timer_group_struct.h"
|
||||||
#include "soc/dport_reg.h"
|
#include "soc/dport_reg.h"
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
#include "esp_intr.h"
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock)
|
#define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock)
|
||||||
#define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock)
|
#define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock)
|
||||||
@ -90,56 +101,56 @@ void IRAM_ATTR __timerISR(void * arg){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t IRAM_ATTR timerRead(hw_timer_t *timer){
|
uint64_t timerRead(hw_timer_t *timer){
|
||||||
timer->dev->update = 1;
|
timer->dev->update = 1;
|
||||||
uint64_t h = timer->dev->cnt_high;
|
uint64_t h = timer->dev->cnt_high;
|
||||||
uint64_t l = timer->dev->cnt_low;
|
uint64_t l = timer->dev->cnt_low;
|
||||||
return (h << 32) | l;
|
return (h << 32) | l;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t IRAM_ATTR timerAlarmRead(hw_timer_t *timer){
|
uint64_t timerAlarmRead(hw_timer_t *timer){
|
||||||
uint64_t h = timer->dev->alarm_high;
|
uint64_t h = timer->dev->alarm_high;
|
||||||
uint64_t l = timer->dev->alarm_low;
|
uint64_t l = timer->dev->alarm_low;
|
||||||
return (h << 32) | l;
|
return (h << 32) | l;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerWrite(hw_timer_t *timer, uint64_t val){
|
void timerWrite(hw_timer_t *timer, uint64_t val){
|
||||||
timer->dev->load_high = (uint32_t) (val >> 32);
|
timer->dev->load_high = (uint32_t) (val >> 32);
|
||||||
timer->dev->load_low = (uint32_t) (val);
|
timer->dev->load_low = (uint32_t) (val);
|
||||||
timer->dev->reload = 1;
|
timer->dev->reload = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerAlarmWrite(hw_timer_t *timer, uint64_t alarm_value, bool autoreload){
|
void timerAlarmWrite(hw_timer_t *timer, uint64_t alarm_value, bool autoreload){
|
||||||
timer->dev->alarm_high = (uint32_t) (alarm_value >> 32);
|
timer->dev->alarm_high = (uint32_t) (alarm_value >> 32);
|
||||||
timer->dev->alarm_low = (uint32_t) alarm_value;
|
timer->dev->alarm_low = (uint32_t) alarm_value;
|
||||||
timer->dev->config.autoreload = autoreload;
|
timer->dev->config.autoreload = autoreload;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerSetConfig(hw_timer_t *timer, uint32_t config){
|
void timerSetConfig(hw_timer_t *timer, uint32_t config){
|
||||||
timer->dev->config.val = config;
|
timer->dev->config.val = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t IRAM_ATTR timerGetConfig(hw_timer_t *timer){
|
uint32_t timerGetConfig(hw_timer_t *timer){
|
||||||
return timer->dev->config.val;
|
return timer->dev->config.val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerSetCountUp(hw_timer_t *timer, bool countUp){
|
void timerSetCountUp(hw_timer_t *timer, bool countUp){
|
||||||
timer->dev->config.increase = countUp;
|
timer->dev->config.increase = countUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRAM_ATTR timerGetCountUp(hw_timer_t *timer){
|
bool timerGetCountUp(hw_timer_t *timer){
|
||||||
return timer->dev->config.increase;
|
return timer->dev->config.increase;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerSetAutoReload(hw_timer_t *timer, bool autoreload){
|
void timerSetAutoReload(hw_timer_t *timer, bool autoreload){
|
||||||
timer->dev->config.autoreload = autoreload;
|
timer->dev->config.autoreload = autoreload;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRAM_ATTR timerGetAutoReload(hw_timer_t *timer){
|
bool timerGetAutoReload(hw_timer_t *timer){
|
||||||
return timer->dev->config.autoreload;
|
return timer->dev->config.autoreload;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerSetDivider(hw_timer_t *timer, uint16_t divider){//2 to 65536
|
void timerSetDivider(hw_timer_t *timer, uint16_t divider){//2 to 65536
|
||||||
if(!divider){
|
if(!divider){
|
||||||
divider = 0xFFFF;
|
divider = 0xFFFF;
|
||||||
} else if(divider == 1){
|
} else if(divider == 1){
|
||||||
@ -151,41 +162,41 @@ void IRAM_ATTR timerSetDivider(hw_timer_t *timer, uint16_t divider){//2 to 65536
|
|||||||
timer->dev->config.enable = timer_en;
|
timer->dev->config.enable = timer_en;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t IRAM_ATTR timerGetDivider(hw_timer_t *timer){
|
uint16_t timerGetDivider(hw_timer_t *timer){
|
||||||
return timer->dev->config.divider;
|
return timer->dev->config.divider;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerStart(hw_timer_t *timer){
|
void timerStart(hw_timer_t *timer){
|
||||||
timer->dev->config.enable = 1;
|
timer->dev->config.enable = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerStop(hw_timer_t *timer){
|
void timerStop(hw_timer_t *timer){
|
||||||
timer->dev->config.enable = 0;
|
timer->dev->config.enable = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerRestart(hw_timer_t *timer){
|
void timerRestart(hw_timer_t *timer){
|
||||||
timer->dev->config.enable = 0;
|
timer->dev->config.enable = 0;
|
||||||
timer->dev->reload = 1;
|
timer->dev->reload = 1;
|
||||||
timer->dev->config.enable = 1;
|
timer->dev->config.enable = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRAM_ATTR timerStarted(hw_timer_t *timer){
|
bool timerStarted(hw_timer_t *timer){
|
||||||
return timer->dev->config.enable;
|
return timer->dev->config.enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerAlarmEnable(hw_timer_t *timer){
|
void timerAlarmEnable(hw_timer_t *timer){
|
||||||
timer->dev->config.alarm_en = 1;
|
timer->dev->config.alarm_en = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerAlarmDisable(hw_timer_t *timer){
|
void timerAlarmDisable(hw_timer_t *timer){
|
||||||
timer->dev->config.alarm_en = 0;
|
timer->dev->config.alarm_en = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRAM_ATTR timerAlarmEnabled(hw_timer_t *timer){
|
bool timerAlarmEnabled(hw_timer_t *timer){
|
||||||
return timer->dev->config.alarm_en;
|
return timer->dev->config.alarm_en;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IRAM_ATTR _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb){
|
static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb){
|
||||||
hw_timer_t * timer = (hw_timer_t *)arg;
|
hw_timer_t * timer = (hw_timer_t *)arg;
|
||||||
if(ev_type == APB_BEFORE_CHANGE){
|
if(ev_type == APB_BEFORE_CHANGE){
|
||||||
timer->dev->config.enable = 0;
|
timer->dev->config.enable = 0;
|
||||||
@ -197,7 +208,7 @@ static void IRAM_ATTR _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hw_timer_t * IRAM_ATTR timerBegin(uint8_t num, uint16_t divider, bool countUp){
|
hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){
|
||||||
if(num > 3){
|
if(num > 3){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -222,13 +233,13 @@ hw_timer_t * IRAM_ATTR timerBegin(uint8_t num, uint16_t divider, bool countUp){
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerEnd(hw_timer_t *timer){
|
void timerEnd(hw_timer_t *timer){
|
||||||
timer->dev->config.enable = 0;
|
timer->dev->config.enable = 0;
|
||||||
timerAttachInterrupt(timer, NULL, false);
|
timerAttachInterrupt(timer, NULL, false);
|
||||||
removeApbChangeCallback(timer, _on_apb_change);
|
removeApbChangeCallback(timer, _on_apb_change);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
|
void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
static intr_handle_t intr_handle = NULL;
|
static intr_handle_t intr_handle = NULL;
|
||||||
if(intr_handle){
|
if(intr_handle){
|
||||||
@ -279,29 +290,29 @@ void IRAM_ATTR timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool ed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR timerDetachInterrupt(hw_timer_t *timer){
|
void timerDetachInterrupt(hw_timer_t *timer){
|
||||||
timerAttachInterrupt(timer, NULL, false);
|
timerAttachInterrupt(timer, NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t IRAM_ATTR timerReadMicros(hw_timer_t *timer){
|
uint64_t timerReadMicros(hw_timer_t *timer){
|
||||||
uint64_t timer_val = timerRead(timer);
|
uint64_t timer_val = timerRead(timer);
|
||||||
uint16_t div = timerGetDivider(timer);
|
uint16_t div = timerGetDivider(timer);
|
||||||
return timer_val * div / (getApbFrequency() / 1000000);
|
return timer_val * div / (getApbFrequency() / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
double IRAM_ATTR timerReadSeconds(hw_timer_t *timer){
|
double timerReadSeconds(hw_timer_t *timer){
|
||||||
uint64_t timer_val = timerRead(timer);
|
uint64_t timer_val = timerRead(timer);
|
||||||
uint16_t div = timerGetDivider(timer);
|
uint16_t div = timerGetDivider(timer);
|
||||||
return (double)timer_val * div / getApbFrequency();
|
return (double)timer_val * div / getApbFrequency();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t IRAM_ATTR timerAlarmReadMicros(hw_timer_t *timer){
|
uint64_t timerAlarmReadMicros(hw_timer_t *timer){
|
||||||
uint64_t timer_val = timerAlarmRead(timer);
|
uint64_t timer_val = timerAlarmRead(timer);
|
||||||
uint16_t div = timerGetDivider(timer);
|
uint16_t div = timerGetDivider(timer);
|
||||||
return timer_val * div / (getApbFrequency() / 1000000);
|
return timer_val * div / (getApbFrequency() / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
double IRAM_ATTR timerAlarmReadSeconds(hw_timer_t *timer){
|
double timerAlarmReadSeconds(hw_timer_t *timer){
|
||||||
uint64_t timer_val = timerAlarmRead(timer);
|
uint64_t timer_val = timerAlarmRead(timer);
|
||||||
uint16_t div = timerGetDivider(timer);
|
uint16_t div = timerGetDivider(timer);
|
||||||
return (double)timer_val * div / getApbFrequency();
|
return (double)timer_val * div / getApbFrequency();
|
||||||
|
@ -15,13 +15,24 @@
|
|||||||
#include "esp32-hal-touch.h"
|
#include "esp32-hal-touch.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_intr.h"
|
|
||||||
#include "soc/rtc_io_reg.h"
|
#include "soc/rtc_io_reg.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "soc/sens_reg.h"
|
#include "soc/sens_reg.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static uint16_t __touchSleepCycles = 0x1000;
|
static uint16_t __touchSleepCycles = 0x1000;
|
||||||
static uint16_t __touchMeasureCycles = 0x1000;
|
static uint16_t __touchMeasureCycles = 0x1000;
|
||||||
|
|
||||||
|
@ -18,10 +18,7 @@
|
|||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "rom/ets_sys.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_intr.h"
|
|
||||||
#include "rom/uart.h"
|
|
||||||
#include "soc/uart_reg.h"
|
#include "soc/uart_reg.h"
|
||||||
#include "soc/uart_struct.h"
|
#include "soc/uart_struct.h"
|
||||||
#include "soc/io_mux_reg.h"
|
#include "soc/io_mux_reg.h"
|
||||||
@ -30,6 +27,20 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "esp_intr_alloc.h"
|
#include "esp_intr_alloc.h"
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||||
|
#include "esp32/rom/ets_sys.h"
|
||||||
|
#include "esp32/rom/uart.h"
|
||||||
|
#else
|
||||||
|
#error Target CONFIG_IDF_TARGET is not supported
|
||||||
|
#endif
|
||||||
|
#else // ESP32 Before IDF 4.0
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
#include "rom/uart.h"
|
||||||
|
#include "esp_intr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0)))
|
#define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0)))
|
||||||
#define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0)))
|
#define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0)))
|
||||||
#define UART_TXD_IDX(u) ((u==0)?U0TXD_OUT_IDX:( (u==1)?U1TXD_OUT_IDX:( (u==2)?U2TXD_OUT_IDX:0)))
|
#define UART_TXD_IDX(u) ((u==0)?U0TXD_OUT_IDX:( (u==1)?U1TXD_OUT_IDX:( (u==2)?U2TXD_OUT_IDX:0)))
|
||||||
@ -85,7 +96,7 @@ static void IRAM_ATTR _uart_isr(void *arg)
|
|||||||
uart->dev->int_clr.rxfifo_tout = 1;
|
uart->dev->int_clr.rxfifo_tout = 1;
|
||||||
while(uart->dev->status.rxfifo_cnt || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
|
while(uart->dev->status.rxfifo_cnt || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
|
||||||
c = uart->dev->fifo.rw_byte;
|
c = uart->dev->fifo.rw_byte;
|
||||||
if(uart->queue != NULL) {
|
if(uart->queue != NULL && !xQueueIsQueueFullFromISR(uart->queue)) {
|
||||||
xQueueSendFromISR(uart->queue, &c, &xHigherPriorityTaskWoken);
|
xQueueSendFromISR(uart->queue, &c, &xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,21 +135,21 @@ void uartDisableInterrupt(uart_t* uart)
|
|||||||
UART_MUTEX_UNLOCK();
|
UART_MUTEX_UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartDetachRx(uart_t* uart, uint8_t rxPin)
|
void uartDetachRx(uart_t* uart)
|
||||||
{
|
{
|
||||||
if(uart == NULL) {
|
if(uart == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pinMatrixInDetach(rxPin, false, false);
|
pinMatrixInDetach(UART_RXD_IDX(uart->num), false, false);
|
||||||
uartDisableInterrupt(uart);
|
uartDisableInterrupt(uart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartDetachTx(uart_t* uart, uint8_t txPin)
|
void uartDetachTx(uart_t* uart)
|
||||||
{
|
{
|
||||||
if(uart == NULL) {
|
if(uart == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pinMatrixOutDetach(txPin, false, false);
|
pinMatrixOutDetach(UART_TXD_IDX(uart->num), false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted)
|
void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted)
|
||||||
@ -208,11 +219,6 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
|||||||
uart->dev->conf0.stop_bit_num = ONE_STOP_BITS_CONF;
|
uart->dev->conf0.stop_bit_num = ONE_STOP_BITS_CONF;
|
||||||
uart->dev->rs485_conf.dl1_en = 1;
|
uart->dev->rs485_conf.dl1_en = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx_idle_num : idle interval after tx FIFO is empty(unit: the time it takes to send one bit under current baudrate)
|
|
||||||
// Setting it to 0 prevents line idle time/delays when sending messages with small intervals
|
|
||||||
uart->dev->idle_conf.tx_idle_num = 0; //
|
|
||||||
|
|
||||||
UART_MUTEX_UNLOCK();
|
UART_MUTEX_UNLOCK();
|
||||||
|
|
||||||
if(rxPin != -1) {
|
if(rxPin != -1) {
|
||||||
@ -226,7 +232,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
|
|||||||
return uart;
|
return uart;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartEnd(uart_t* uart, uint8_t txPin, uint8_t rxPin)
|
void uartEnd(uart_t* uart)
|
||||||
{
|
{
|
||||||
if(uart == NULL) {
|
if(uart == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -243,8 +249,8 @@ void uartEnd(uart_t* uart, uint8_t txPin, uint8_t rxPin)
|
|||||||
|
|
||||||
UART_MUTEX_UNLOCK();
|
UART_MUTEX_UNLOCK();
|
||||||
|
|
||||||
uartDetachRx(uart, rxPin);
|
uartDetachRx(uart);
|
||||||
uartDetachTx(uart, txPin);
|
uartDetachTx(uart);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
|
size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
|
||||||
@ -257,8 +263,7 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
|
|||||||
vQueueDelete(uart->queue);
|
vQueueDelete(uart->queue);
|
||||||
uart->queue = xQueueCreate(new_size, sizeof(uint8_t));
|
uart->queue = xQueueCreate(new_size, sizeof(uint8_t));
|
||||||
if(uart->queue == NULL) {
|
if(uart->queue == NULL) {
|
||||||
UART_MUTEX_UNLOCK();
|
return 0;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UART_MUTEX_UNLOCK();
|
UART_MUTEX_UNLOCK();
|
||||||
@ -266,23 +271,12 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
|
|||||||
return new_size;
|
return new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartSetRxInvert(uart_t* uart, bool invert)
|
|
||||||
{
|
|
||||||
if (uart == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (invert)
|
|
||||||
uart->dev->conf0.rxd_inv = 1;
|
|
||||||
else
|
|
||||||
uart->dev->conf0.rxd_inv = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t uartAvailable(uart_t* uart)
|
uint32_t uartAvailable(uart_t* uart)
|
||||||
{
|
{
|
||||||
if(uart == NULL || uart->queue == NULL) {
|
if(uart == NULL || uart->queue == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return (uxQueueMessagesWaiting(uart->queue) + uart->dev->status.rxfifo_cnt) ;
|
return uxQueueMessagesWaiting(uart->queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t uartAvailableForWrite(uart_t* uart)
|
uint32_t uartAvailableForWrite(uart_t* uart)
|
||||||
@ -293,35 +287,12 @@ uint32_t uartAvailableForWrite(uart_t* uart)
|
|||||||
return 0x7f - uart->dev->status.txfifo_cnt;
|
return 0x7f - uart->dev->status.txfifo_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartRxFifoToQueue(uart_t* uart)
|
|
||||||
{
|
|
||||||
uint8_t c;
|
|
||||||
UART_MUTEX_LOCK();
|
|
||||||
//disable interrupts
|
|
||||||
uart->dev->int_ena.val = 0;
|
|
||||||
uart->dev->int_clr.val = 0xffffffff;
|
|
||||||
while (uart->dev->status.rxfifo_cnt || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
|
|
||||||
c = uart->dev->fifo.rw_byte;
|
|
||||||
xQueueSend(uart->queue, &c, 0);
|
|
||||||
}
|
|
||||||
//enable interrupts
|
|
||||||
uart->dev->int_ena.rxfifo_full = 1;
|
|
||||||
uart->dev->int_ena.frm_err = 1;
|
|
||||||
uart->dev->int_ena.rxfifo_tout = 1;
|
|
||||||
uart->dev->int_clr.val = 0xffffffff;
|
|
||||||
UART_MUTEX_UNLOCK();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t uartRead(uart_t* uart)
|
uint8_t uartRead(uart_t* uart)
|
||||||
{
|
{
|
||||||
if(uart == NULL || uart->queue == NULL) {
|
if(uart == NULL || uart->queue == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
if ((uxQueueMessagesWaiting(uart->queue) == 0) && (uart->dev->status.rxfifo_cnt > 0))
|
|
||||||
{
|
|
||||||
uartRxFifoToQueue(uart);
|
|
||||||
}
|
|
||||||
if(xQueueReceive(uart->queue, &c, 0)) {
|
if(xQueueReceive(uart->queue, &c, 0)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@ -334,10 +305,6 @@ uint8_t uartPeek(uart_t* uart)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
if ((uxQueueMessagesWaiting(uart->queue) == 0) && (uart->dev->status.rxfifo_cnt > 0))
|
|
||||||
{
|
|
||||||
uartRxFifoToQueue(uart);
|
|
||||||
}
|
|
||||||
if(xQueuePeek(uart->queue, &c, 0)) {
|
if(xQueuePeek(uart->queue, &c, 0)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@ -371,7 +338,7 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len)
|
|||||||
|
|
||||||
void uartFlush(uart_t* uart)
|
void uartFlush(uart_t* uart)
|
||||||
{
|
{
|
||||||
uartFlushTxOnly(uart,true);
|
uartFlushTxOnly(uart,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartFlushTxOnly(uart_t* uart, bool txOnly)
|
void uartFlushTxOnly(uart_t* uart, bool txOnly)
|
||||||
|
@ -52,7 +52,7 @@ struct uart_struct_t;
|
|||||||
typedef struct uart_struct_t uart_t;
|
typedef struct uart_struct_t uart_t;
|
||||||
|
|
||||||
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted);
|
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted);
|
||||||
void uartEnd(uart_t* uart, uint8_t rxPin, uint8_t txPin);
|
void uartEnd(uart_t* uart);
|
||||||
|
|
||||||
uint32_t uartAvailable(uart_t* uart);
|
uint32_t uartAvailable(uart_t* uart);
|
||||||
uint32_t uartAvailableForWrite(uart_t* uart);
|
uint32_t uartAvailableForWrite(uart_t* uart);
|
||||||
@ -70,8 +70,6 @@ uint32_t uartGetBaudRate(uart_t* uart);
|
|||||||
|
|
||||||
size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
|
size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
|
||||||
|
|
||||||
void uartSetRxInvert(uart_t* uart, bool invert);
|
|
||||||
|
|
||||||
void uartSetDebug(uart_t* uart);
|
void uartSetDebug(uart_t* uart);
|
||||||
int uartGetDebug();
|
int uartGetDebug();
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ extern "C" {
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
#include "esp_sleep.h"
|
||||||
|
|
||||||
#ifndef F_CPU
|
#ifndef F_CPU
|
||||||
#define F_CPU (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000U)
|
#define F_CPU (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000U)
|
||||||
|
@ -3,10 +3,6 @@
|
|||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#ifndef CONFIG_ARDUINO_LOOP_STACK_SIZE
|
|
||||||
#define CONFIG_ARDUINO_LOOP_STACK_SIZE 8192
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TaskHandle_t loopTaskHandle = NULL;
|
TaskHandle_t loopTaskHandle = NULL;
|
||||||
|
|
||||||
#if CONFIG_AUTOSTART_ARDUINO
|
#if CONFIG_AUTOSTART_ARDUINO
|
||||||
@ -29,7 +25,7 @@ extern "C" void app_main()
|
|||||||
{
|
{
|
||||||
loopTaskWDTEnabled = false;
|
loopTaskWDTEnabled = false;
|
||||||
initArduino();
|
initArduino();
|
||||||
xTaskCreateUniversal(loopTask, "loopTask", CONFIG_ARDUINO_LOOP_STACK_SIZE, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);
|
xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,8 +53,6 @@ typedef unsigned long prog_uint32_t;
|
|||||||
*(void * const *)(_addr); \
|
*(void * const *)(_addr); \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define pgm_get_far_address(x) ((uint32_t)(&(x)))
|
|
||||||
|
|
||||||
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
|
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
|
||||||
#define pgm_read_word_near(addr) pgm_read_word(addr)
|
#define pgm_read_word_near(addr) pgm_read_word(addr)
|
||||||
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
|
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
Boston, MA 02111-1307 USA
|
Boston, MA 02111-1307 USA
|
||||||
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
|
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
Make your question, not a Statement, inclusive. Include all pertinent information:
|
Make your question, not a Statement, inclusive. Include all pertinent information:
|
||||||
|
|
||||||
What you are trying to do
|
What you are trying to do.
|
||||||
Describe your system (Hardware, computer, O/S, core version, environment)
|
Describe your system( Hardware, computer, O/S, core version, environment)
|
||||||
Describe what is failing
|
Describe what is failing
|
||||||
Show the shortest possible code that will duplicate the error
|
Show the shortest possible code that will duplicate the error
|
||||||
Show the EXACT error message (it doesn't work is not enough)
|
Show the EXACT error message(it doesn't work is not enough)
|
||||||
Then if someone is interested and knowledgeable you might get a answer. All of this work on your part shows us that you have worked to solve YOUR problem. The more complete your issue posting is, the more likely someone will volunteer their time to help you.
|
Then if someone is interested and knowledgeable you might get a answer. All of this work on your part shows us that you have worked to solve YOUR problem. The more complete your issue posting is, the more likely someone will volunteer their time to help you.
|
||||||
|
|
||||||
If you have a Guru Meditation Error or Backtrace, ***please decode it***:
|
If you have a Guru Meditation Error or Backtrace, ***please decode it***:
|
||||||
[ExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder)
|
https://github.com/me-no-dev/EspExceptionDecoder
|
||||||
|
|
||||||
----------------------------- Remove above -----------------------------
|
----------------------------- Remove above -----------------------------
|
||||||
|
|
||||||
|
|
||||||
### Hardware:
|
### Hardware:
|
||||||
|||||||
|
Board: ?ESP32 Dev Module? ?node32? ?ttgo_lora?
|
||||||
|:---|---|---|---|---|---|
|
Core Installation/update date: ?11/jul/2017?
|
||||||
|<B>Board</B>|ESP32 Dev Module|node32|ttgo_lora|ESP32-S2-Saola|Custom w/ ESP32-S2-WROVER 16MB|
|
IDE name: ?Arduino IDE? ?Platform.io? ?IDF component?
|
||||||
|<B>Version/Date</B>|1.0.4|2.0.0|0badbeef|11/jul/2017|today's master|
|
Flash Frequency: ?40Mhz?
|
||||||
|<B>IDE name</B>|Arduino IDE|Atom + Platform.io|IDF component|VSCode|
|
PSRAM enabled: ?no?
|
||||||
|<B>Flash Frequency</B>|40Mhz|80Mhz|
|
Upload Speed: ?115200?
|
||||||
|<B>PSRAM enabled</B>|yes|no|
|
Computer OS: ?Windows 10? ?Mac OSX? ?Ubuntu?
|
||||||
|<B>Upload Speed</B>|115200|
|
|
||||||
|<B>Computer OS</B>|Windows 10|Mac OSX|Ubuntu|
|
|
||||||
|
|
||||||
### Description:
|
### Description:
|
||||||
Describe your problem here
|
Describe your problem here
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
- Stable release link: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json`
|
- Stable release link: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json`
|
||||||
- Development release link: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json`
|
- Development release link: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json`
|
||||||
|
|
||||||
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (x86, amd64, armhf and arm64).
|
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32, 64 bit and ARM).
|
||||||
|
|
||||||
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is at the [Arduino website](http://www.arduino.cc/en/main/software).
|
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is at the [Arduino website](http://www.arduino.cc/en/main/software).
|
||||||
- Start Arduino and open Preferences window.
|
- Start Arduino and open Preferences window.
|
||||||
|
@ -8,8 +8,8 @@ Installation instructions for Debian / Ubuntu OS
|
|||||||
sudo usermod -a -G dialout $USER && \
|
sudo usermod -a -G dialout $USER && \
|
||||||
sudo apt-get install git && \
|
sudo apt-get install git && \
|
||||||
wget https://bootstrap.pypa.io/get-pip.py && \
|
wget https://bootstrap.pypa.io/get-pip.py && \
|
||||||
sudo python3 get-pip.py && \
|
sudo python get-pip.py && \
|
||||||
sudo pip3 install pyserial && \
|
sudo pip install pyserial && \
|
||||||
mkdir -p ~/Arduino/hardware/espressif && \
|
mkdir -p ~/Arduino/hardware/espressif && \
|
||||||
cd ~/Arduino/hardware/espressif && \
|
cd ~/Arduino/hardware/espressif && \
|
||||||
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
|
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
|
||||||
|
@ -7,9 +7,9 @@ Installation instructions for Mac OS
|
|||||||
```bash
|
```bash
|
||||||
mkdir -p ~/Documents/Arduino/hardware/espressif && \
|
mkdir -p ~/Documents/Arduino/hardware/espressif && \
|
||||||
cd ~/Documents/Arduino/hardware/espressif && \
|
cd ~/Documents/Arduino/hardware/espressif && \
|
||||||
git clone https://github.com/espressif/arduino-esp32.git esp32 --depth 1 && \
|
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
|
||||||
cd esp32 && \
|
cd esp32 && \
|
||||||
git submodule update --init --recursive --depth 1 && \
|
git submodule update --init --recursive && \
|
||||||
cd tools && \
|
cd tools && \
|
||||||
python get.py
|
python get.py
|
||||||
```
|
```
|
||||||
|
@ -72,11 +72,6 @@ If you are writing code that does not require Arduino to compile and you want yo
|
|||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
||||||
## FreeRTOS Tick Rate (Hz)
|
|
||||||
|
|
||||||
You might notice that Arduino-esp32's `delay()` function will only work in multiples of 10ms. That is because, by default, esp-idf handles task events 100 times per second.
|
|
||||||
To fix that behavior you need to set FreeRTOS tick rate to 1000Hz in `make menuconfig` -> `Component config` -> `FreeRTOS` -> `Tick rate`.
|
|
||||||
|
|
||||||
## Compilation Errors
|
## Compilation Errors
|
||||||
|
|
||||||
As commits are made to esp-idf and submodules, the codebases can develop incompatibilities which cause compilation errors. If you have problems compiling, follow the instructions in [Issue #1142](https://github.com/espressif/arduino-esp32/issues/1142) to roll esp-idf back to a known good version.
|
As commits are made to esp-idf and submodules, the codebases can develop incompatibilities which cause compilation errors. If you have problems compiling, follow the instructions in [Issue #1142](https://github.com/espressif/arduino-esp32/issues/1142) to roll esp-idf back to a known good version.
|
||||||
|
@ -14,7 +14,7 @@ WebServer server(80);
|
|||||||
* Login page
|
* Login page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char* loginIndex =
|
const char* loginIndex =
|
||||||
"<form name='loginForm'>"
|
"<form name='loginForm'>"
|
||||||
"<table width='20%' bgcolor='A09F9F' align='center'>"
|
"<table width='20%' bgcolor='A09F9F' align='center'>"
|
||||||
"<tr>"
|
"<tr>"
|
||||||
@ -25,9 +25,8 @@ const char* loginIndex =
|
|||||||
"<br>"
|
"<br>"
|
||||||
"<br>"
|
"<br>"
|
||||||
"</tr>"
|
"</tr>"
|
||||||
"<tr>"
|
"<td>Username:</td>"
|
||||||
"<td>Username:</td>"
|
"<td><input type='text' size=25 name='userid'><br></td>"
|
||||||
"<td><input type='text' size=25 name='userid'><br></td>"
|
|
||||||
"</tr>"
|
"</tr>"
|
||||||
"<br>"
|
"<br>"
|
||||||
"<br>"
|
"<br>"
|
||||||
@ -55,12 +54,12 @@ const char* loginIndex =
|
|||||||
"}"
|
"}"
|
||||||
"}"
|
"}"
|
||||||
"</script>";
|
"</script>";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Server Index Page
|
* Server Index Page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char* serverIndex =
|
const char* serverIndex =
|
||||||
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
|
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
|
||||||
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
|
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
|
||||||
"<input type='file' name='update'>"
|
"<input type='file' name='update'>"
|
||||||
@ -89,7 +88,7 @@ const char* serverIndex =
|
|||||||
"return xhr;"
|
"return xhr;"
|
||||||
"},"
|
"},"
|
||||||
"success:function(d, s) {"
|
"success:function(d, s) {"
|
||||||
"console.log('success!')"
|
"console.log('success!')"
|
||||||
"},"
|
"},"
|
||||||
"error: function (a, b, c) {"
|
"error: function (a, b, c) {"
|
||||||
"}"
|
"}"
|
||||||
|
@ -88,17 +88,6 @@ ArduinoOTAClass& ArduinoOTAClass::setPasswordHash(const char * password) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArduinoOTAClass& ArduinoOTAClass::setPartitionLabel(const char * partition_label) {
|
|
||||||
if (!_initialized && !_partition_label.length() && partition_label) {
|
|
||||||
_partition_label = partition_label;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
String ArduinoOTAClass::getPartitionLabel() {
|
|
||||||
return _partition_label;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArduinoOTAClass& ArduinoOTAClass::setRebootOnSuccess(bool reboot){
|
ArduinoOTAClass& ArduinoOTAClass::setRebootOnSuccess(bool reboot){
|
||||||
_rebootOnSuccess = reboot;
|
_rebootOnSuccess = reboot;
|
||||||
return *this;
|
return *this;
|
||||||
@ -246,8 +235,7 @@ void ArduinoOTAClass::_onRx(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoOTAClass::_runUpdate() {
|
void ArduinoOTAClass::_runUpdate() {
|
||||||
const char *partition_label = _partition_label.length() ? _partition_label.c_str() : NULL;
|
if (!Update.begin(_size, _cmd)) {
|
||||||
if (!Update.begin(_size, _cmd, -1, LOW, partition_label)) {
|
|
||||||
|
|
||||||
log_e("Begin ERROR: %s", Update.errorString());
|
log_e("Begin ERROR: %s", Update.errorString());
|
||||||
|
|
||||||
@ -370,7 +358,7 @@ void ArduinoOTAClass::end() {
|
|||||||
|
|
||||||
void ArduinoOTAClass::handle() {
|
void ArduinoOTAClass::handle() {
|
||||||
if (!_initialized) {
|
if (!_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_state == OTA_RUNUPDATE) {
|
if (_state == OTA_RUNUPDATE) {
|
||||||
_runUpdate();
|
_runUpdate();
|
||||||
|
@ -44,10 +44,6 @@ class ArduinoOTAClass
|
|||||||
//Sets the password as above but in the form MD5(password). Default NULL
|
//Sets the password as above but in the form MD5(password). Default NULL
|
||||||
ArduinoOTAClass& setPasswordHash(const char *password);
|
ArduinoOTAClass& setPasswordHash(const char *password);
|
||||||
|
|
||||||
//Sets the partition label to write to when updating SPIFFS. Default NULL
|
|
||||||
ArduinoOTAClass &setPartitionLabel(const char *partition_label);
|
|
||||||
String getPartitionLabel();
|
|
||||||
|
|
||||||
//Sets if the device should be rebooted after successful update. Default true
|
//Sets if the device should be rebooted after successful update. Default true
|
||||||
ArduinoOTAClass& setRebootOnSuccess(bool reboot);
|
ArduinoOTAClass& setRebootOnSuccess(bool reboot);
|
||||||
|
|
||||||
@ -84,7 +80,6 @@ class ArduinoOTAClass
|
|||||||
int _port;
|
int _port;
|
||||||
String _password;
|
String _password;
|
||||||
String _hostname;
|
String _hostname;
|
||||||
String _partition_label;
|
|
||||||
String _nonce;
|
String _nonce;
|
||||||
WiFiUDP _udp_ota;
|
WiFiUDP _udp_ota;
|
||||||
bool _initialized;
|
bool _initialized;
|
||||||
|
@ -150,7 +150,7 @@ static bool _udp_task_start(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!_udp_task_handle){
|
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, 3, (TaskHandle_t*)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE);
|
||||||
if(!_udp_task_handle){
|
if(!_udp_task_handle){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -277,22 +277,6 @@ void AsyncUDPMessage::flush()
|
|||||||
_index = 0;
|
_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){
|
|
||||||
_udp = packet._udp;
|
|
||||||
_pb = packet._pb;
|
|
||||||
_if = packet._if;
|
|
||||||
_data = packet._data;
|
|
||||||
_len = packet._len;
|
|
||||||
_index = 0;
|
|
||||||
|
|
||||||
memcpy(&_remoteIp, &packet._remoteIp, sizeof(ip_addr_t));
|
|
||||||
memcpy(&_localIp, &packet._localIp, sizeof(ip_addr_t));
|
|
||||||
_localPort = packet._localPort;
|
|
||||||
_remotePort = packet._remotePort;
|
|
||||||
memcpy(_remoteMac, packet._remoteMac, 6);
|
|
||||||
|
|
||||||
pbuf_ref(_pb);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif * ntif)
|
AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif * ntif)
|
||||||
{
|
{
|
||||||
@ -310,18 +294,18 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr,
|
|||||||
_localIp.type = _remoteIp.type;
|
_localIp.type = _remoteIp.type;
|
||||||
|
|
||||||
eth_hdr* eth = NULL;
|
eth_hdr* eth = NULL;
|
||||||
udp_hdr* udphdr = (udp_hdr *)(_data - UDP_HLEN);
|
udp_hdr* udphdr = reinterpret_cast<udp_hdr*>(_data - UDP_HLEN);
|
||||||
_localPort = ntohs(udphdr->dest);
|
_localPort = ntohs(udphdr->dest);
|
||||||
_remotePort = ntohs(udphdr->src);
|
_remotePort = ntohs(udphdr->src);
|
||||||
|
|
||||||
if (_remoteIp.type == IPADDR_TYPE_V4) {
|
if (_remoteIp.type == IPADDR_TYPE_V4) {
|
||||||
eth = (eth_hdr *)(_data - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
|
eth = (eth_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
|
||||||
struct ip_hdr * iphdr = (struct ip_hdr *)(_data - UDP_HLEN - IP_HLEN);
|
struct ip_hdr * iphdr = (struct ip_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP_HLEN);
|
||||||
_localIp.u_addr.ip4.addr = iphdr->dest.addr;
|
_localIp.u_addr.ip4.addr = iphdr->dest.addr;
|
||||||
_remoteIp.u_addr.ip4.addr = iphdr->src.addr;
|
_remoteIp.u_addr.ip4.addr = iphdr->src.addr;
|
||||||
} else {
|
} else {
|
||||||
eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
|
eth = (eth_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
|
||||||
struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN);
|
struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP6_HLEN);
|
||||||
memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16);
|
memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16);
|
||||||
memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16);
|
memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16);
|
||||||
}
|
}
|
||||||
@ -495,7 +479,6 @@ AsyncUDP::AsyncUDP()
|
|||||||
{
|
{
|
||||||
_pcb = NULL;
|
_pcb = NULL;
|
||||||
_connected = false;
|
_connected = false;
|
||||||
_lastErr = ERR_OK;
|
|
||||||
_handler = NULL;
|
_handler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,8 +517,8 @@ bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port)
|
|||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
UDP_MUTEX_LOCK();
|
UDP_MUTEX_LOCK();
|
||||||
_lastErr = _udp_connect(_pcb, addr, port);
|
err_t err = _udp_connect(_pcb, addr, port);
|
||||||
if(_lastErr != ERR_OK) {
|
if(err != ERR_OK) {
|
||||||
UDP_MUTEX_UNLOCK();
|
UDP_MUTEX_UNLOCK();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -663,7 +646,7 @@ size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * add
|
|||||||
if(len > CONFIG_TCP_MSS) {
|
if(len > CONFIG_TCP_MSS) {
|
||||||
len = CONFIG_TCP_MSS;
|
len = CONFIG_TCP_MSS;
|
||||||
}
|
}
|
||||||
_lastErr = ERR_OK;
|
err_t err = ERR_OK;
|
||||||
pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||||
if(pbt != NULL) {
|
if(pbt != NULL) {
|
||||||
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
|
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
|
||||||
@ -673,16 +656,16 @@ size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * add
|
|||||||
void * nif = NULL;
|
void * nif = NULL;
|
||||||
tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif);
|
tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif);
|
||||||
if(!nif){
|
if(!nif){
|
||||||
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
|
err = _udp_sendto(_pcb, pbt, addr, port);
|
||||||
} else {
|
} else {
|
||||||
_lastErr = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
|
err = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
|
err = _udp_sendto(_pcb, pbt, addr, port);
|
||||||
}
|
}
|
||||||
UDP_MUTEX_UNLOCK();
|
UDP_MUTEX_UNLOCK();
|
||||||
pbuf_free(pbt);
|
pbuf_free(pbt);
|
||||||
if(_lastErr < ERR_OK) {
|
if(err < ERR_OK) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
@ -699,8 +682,9 @@ void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t po
|
|||||||
if(_handler) {
|
if(_handler) {
|
||||||
AsyncUDPPacket packet(this, this_pb, addr, port, netif);
|
AsyncUDPPacket packet(this, this_pb, addr, port, netif);
|
||||||
_handler(packet);
|
_handler(packet);
|
||||||
|
} else {
|
||||||
|
pbuf_free(this_pb);
|
||||||
}
|
}
|
||||||
pbuf_free(this_pb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,10 +870,6 @@ bool AsyncUDP::connected()
|
|||||||
return _connected;
|
return _connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t AsyncUDP::lastErr() {
|
|
||||||
return _lastErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void * arg)
|
void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void * arg)
|
||||||
{
|
{
|
||||||
onPacket(std::bind(cb, arg, std::placeholders::_1));
|
onPacket(std::bind(cb, arg, std::placeholders::_1));
|
||||||
|
@ -58,7 +58,6 @@ protected:
|
|||||||
size_t _len;
|
size_t _len;
|
||||||
size_t _index;
|
size_t _index;
|
||||||
public:
|
public:
|
||||||
AsyncUDPPacket(AsyncUDPPacket &packet);
|
|
||||||
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
||||||
virtual ~AsyncUDPPacket();
|
virtual ~AsyncUDPPacket();
|
||||||
|
|
||||||
@ -96,7 +95,6 @@ protected:
|
|||||||
udp_pcb *_pcb;
|
udp_pcb *_pcb;
|
||||||
//xSemaphoreHandle _lock;
|
//xSemaphoreHandle _lock;
|
||||||
bool _connected;
|
bool _connected;
|
||||||
esp_err_t _lastErr;
|
|
||||||
AuPacketHandlerFunction _handler;
|
AuPacketHandlerFunction _handler;
|
||||||
|
|
||||||
bool _init();
|
bool _init();
|
||||||
@ -146,7 +144,6 @@ public:
|
|||||||
IPAddress listenIP();
|
IPAddress listenIP();
|
||||||
IPv6Address listenIPv6();
|
IPv6Address listenIPv6();
|
||||||
bool connected();
|
bool connected();
|
||||||
esp_err_t lastErr();
|
|
||||||
operator bool();
|
operator bool();
|
||||||
|
|
||||||
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
||||||
|
Submodule libraries/AzureIoT deleted from 5e8ffb2111
@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
|
|
||||||
Ported to Arduino ESP32 by Evandro Copercini
|
|
||||||
Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include <BLEDevice.h>
|
|
||||||
#include <BLEUtils.h>
|
|
||||||
#include <BLEScan.h>
|
|
||||||
#include <BLEAdvertisedDevice.h>
|
|
||||||
#include <BLEEddystoneURL.h>
|
|
||||||
#include <BLEEddystoneTLM.h>
|
|
||||||
#include <BLEBeacon.h>
|
|
||||||
|
|
||||||
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))
|
|
||||||
|
|
||||||
int scanTime = 5; //In seconds
|
|
||||||
BLEScan *pBLEScan;
|
|
||||||
|
|
||||||
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
|
|
||||||
{
|
|
||||||
void onResult(BLEAdvertisedDevice advertisedDevice)
|
|
||||||
{
|
|
||||||
if (advertisedDevice.haveName())
|
|
||||||
{
|
|
||||||
Serial.print("Device name: ");
|
|
||||||
Serial.println(advertisedDevice.getName().c_str());
|
|
||||||
Serial.println("");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (advertisedDevice.haveServiceUUID())
|
|
||||||
{
|
|
||||||
BLEUUID devUUID = advertisedDevice.getServiceUUID();
|
|
||||||
Serial.print("Found ServiceUUID: ");
|
|
||||||
Serial.println(devUUID.toString().c_str());
|
|
||||||
Serial.println("");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (advertisedDevice.haveManufacturerData() == true)
|
|
||||||
{
|
|
||||||
std::string strManufacturerData = advertisedDevice.getManufacturerData();
|
|
||||||
|
|
||||||
uint8_t cManufacturerData[100];
|
|
||||||
strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
|
|
||||||
|
|
||||||
if (strManufacturerData.length() == 25 && cManufacturerData[0] == 0x4C && cManufacturerData[1] == 0x00)
|
|
||||||
{
|
|
||||||
Serial.println("Found an iBeacon!");
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Serial.println("Found another manufacturers beacon!");
|
|
||||||
Serial.printf("strManufacturerData: %d ", strManufacturerData.length());
|
|
||||||
for (int i = 0; i < strManufacturerData.length(); i++)
|
|
||||||
{
|
|
||||||
Serial.printf("[%X]", cManufacturerData[i]);
|
|
||||||
}
|
|
||||||
Serial.printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *payLoad = advertisedDevice.getPayload();
|
|
||||||
|
|
||||||
BLEUUID checkUrlUUID = (uint16_t)0xfeaa;
|
|
||||||
|
|
||||||
if (advertisedDevice.getServiceUUID().equals(checkUrlUUID))
|
|
||||||
{
|
|
||||||
if (payLoad[11] == 0x10)
|
|
||||||
{
|
|
||||||
Serial.println("Found an EddystoneURL beacon!");
|
|
||||||
BLEEddystoneURL foundEddyURL = BLEEddystoneURL();
|
|
||||||
std::string eddyContent((char *)&payLoad[11]); // incomplete EddystoneURL struct!
|
|
||||||
|
|
||||||
foundEddyURL.setData(eddyContent);
|
|
||||||
std::string bareURL = foundEddyURL.getURL();
|
|
||||||
if (bareURL[0] == 0x00)
|
|
||||||
{
|
|
||||||
size_t payLoadLen = advertisedDevice.getPayloadLength();
|
|
||||||
Serial.println("DATA-->");
|
|
||||||
for (int idx = 0; idx < payLoadLen; idx++)
|
|
||||||
{
|
|
||||||
Serial.printf("0x%08X ", payLoad[idx]);
|
|
||||||
}
|
|
||||||
Serial.println("\nInvalid Data");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.printf("Found URL: %s\n", foundEddyURL.getURL().c_str());
|
|
||||||
Serial.printf("Decoded URL: %s\n", foundEddyURL.getDecodedURL().c_str());
|
|
||||||
Serial.printf("TX power %d\n", foundEddyURL.getPower());
|
|
||||||
Serial.println("\n");
|
|
||||||
}
|
|
||||||
else if (payLoad[11] == 0x20)
|
|
||||||
{
|
|
||||||
Serial.println("Found an EddystoneTLM beacon!");
|
|
||||||
BLEEddystoneTLM foundEddyURL = BLEEddystoneTLM();
|
|
||||||
std::string eddyContent((char *)&payLoad[11]); // incomplete EddystoneURL struct!
|
|
||||||
|
|
||||||
eddyContent = "01234567890123";
|
|
||||||
|
|
||||||
for (int idx = 0; idx < 14; idx++)
|
|
||||||
{
|
|
||||||
eddyContent[idx] = payLoad[idx + 11];
|
|
||||||
}
|
|
||||||
|
|
||||||
foundEddyURL.setData(eddyContent);
|
|
||||||
Serial.printf("Reported battery voltage: %dmV\n", foundEddyURL.getVolt());
|
|
||||||
Serial.printf("Reported temperature from TLM class: %.2fC\n", (double)foundEddyURL.getTemp());
|
|
||||||
int temp = (int)payLoad[16] + (int)(payLoad[15] << 8);
|
|
||||||
float calcTemp = temp / 256.0f;
|
|
||||||
Serial.printf("Reported temperature from data: %.2fC\n", calcTemp);
|
|
||||||
Serial.printf("Reported advertise count: %d\n", foundEddyURL.getCount());
|
|
||||||
Serial.printf("Reported time since last reboot: %ds\n", foundEddyURL.getTime());
|
|
||||||
Serial.println("\n");
|
|
||||||
Serial.print(foundEddyURL.toString().c_str());
|
|
||||||
Serial.println("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.println("Scanning...");
|
|
||||||
|
|
||||||
BLEDevice::init("");
|
|
||||||
pBLEScan = BLEDevice::getScan(); //create new scan
|
|
||||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
|
||||||
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
|
|
||||||
pBLEScan->setInterval(100);
|
|
||||||
pBLEScan->setWindow(99); // less or equal setInterval value
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
|
|
||||||
Serial.print("Devices found: ");
|
|
||||||
Serial.println(foundDevices.getCount());
|
|
||||||
Serial.println("Scan done!");
|
|
||||||
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
|
|
||||||
delay(2000);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
## BLE Beacon Scanner
|
|
||||||
|
|
||||||
Initiates a BLE device scan.
|
|
||||||
Checks if the discovered devices are
|
|
||||||
- an iBeacon
|
|
||||||
- an Eddystone TLM beacon
|
|
||||||
- an Eddystone URL beacon
|
|
||||||
|
|
||||||
and sends the decoded beacon information over Serial log
|
|
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
EddystoneTLM beacon by BeeGee based on https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_Eddystone_TLM_deepsleep/ESP32_Eddystone_TLM_deepsleep.ino
|
|
||||||
EddystoneTLM frame specification https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Create a BLE server that will send periodic Eddystone URL frames.
|
|
||||||
The design of creating the BLE server is:
|
|
||||||
1. Create a BLE Server
|
|
||||||
2. Create advertising data
|
|
||||||
3. Start advertising.
|
|
||||||
4. wait
|
|
||||||
5. Stop advertising.
|
|
||||||
6. deep sleep
|
|
||||||
|
|
||||||
*/
|
|
||||||
#include "sys/time.h"
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include "BLEDevice.h"
|
|
||||||
#include "BLEUtils.h"
|
|
||||||
#include "BLEBeacon.h"
|
|
||||||
#include "BLEAdvertising.h"
|
|
||||||
#include "BLEEddystoneURL.h"
|
|
||||||
|
|
||||||
#include "esp_sleep.h"
|
|
||||||
|
|
||||||
#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up
|
|
||||||
RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory
|
|
||||||
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory
|
|
||||||
|
|
||||||
// See the following for generating UUIDs:
|
|
||||||
// https://www.uuidgenerator.net/
|
|
||||||
BLEAdvertising *pAdvertising;
|
|
||||||
struct timeval nowTimeStruct;
|
|
||||||
|
|
||||||
time_t lastTenth;
|
|
||||||
|
|
||||||
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/)
|
|
||||||
|
|
||||||
// Check
|
|
||||||
// https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
|
|
||||||
// and http://www.hugi.scene.org/online/coding/hugi%2015%20-%20cmtadfix.htm
|
|
||||||
// for the temperature value. It is a 8.8 fixed-point notation
|
|
||||||
void setBeacon()
|
|
||||||
{
|
|
||||||
char beacon_data[25];
|
|
||||||
uint16_t beconUUID = 0xFEAA;
|
|
||||||
uint16_t volt = random(2800, 3700); // 3300mV = 3.3V
|
|
||||||
float tempFloat = random(2000, 3100) / 100.0f;
|
|
||||||
Serial.printf("Random temperature is %.2fC\n", tempFloat);
|
|
||||||
int temp = (int)(tempFloat * 256); //(uint16_t)((float)23.00);
|
|
||||||
Serial.printf("Converted to 8.8 format %0X%0X\n", (temp >> 8), (temp & 0xFF));
|
|
||||||
|
|
||||||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
|
|
||||||
BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
|
|
||||||
|
|
||||||
oScanResponseData.setFlags(0x06); // GENERAL_DISC_MODE 0x02 | BR_EDR_NOT_SUPPORTED 0x04
|
|
||||||
oScanResponseData.setCompleteServices(BLEUUID(beconUUID));
|
|
||||||
|
|
||||||
beacon_data[0] = 0x20; // Eddystone Frame Type (Unencrypted Eddystone-TLM)
|
|
||||||
beacon_data[1] = 0x00; // TLM version
|
|
||||||
beacon_data[2] = (volt >> 8); // Battery voltage, 1 mV/bit i.e. 0xCE4 = 3300mV = 3.3V
|
|
||||||
beacon_data[3] = (volt & 0xFF); //
|
|
||||||
beacon_data[4] = (temp >> 8); // Beacon temperature
|
|
||||||
beacon_data[5] = (temp & 0xFF); //
|
|
||||||
beacon_data[6] = ((bootcount & 0xFF000000) >> 24); // Advertising PDU count
|
|
||||||
beacon_data[7] = ((bootcount & 0xFF0000) >> 16); //
|
|
||||||
beacon_data[8] = ((bootcount & 0xFF00) >> 8); //
|
|
||||||
beacon_data[9] = (bootcount & 0xFF); //
|
|
||||||
beacon_data[10] = ((lastTenth & 0xFF000000) >> 24); // Time since power-on or reboot as 0.1 second resolution counter
|
|
||||||
beacon_data[11] = ((lastTenth & 0xFF0000) >> 16); //
|
|
||||||
beacon_data[12] = ((lastTenth & 0xFF00) >> 8); //
|
|
||||||
beacon_data[13] = (lastTenth & 0xFF); //
|
|
||||||
|
|
||||||
oScanResponseData.setServiceData(BLEUUID(beconUUID), std::string(beacon_data, 14));
|
|
||||||
oAdvertisementData.setName("TLMBeacon");
|
|
||||||
pAdvertising->setAdvertisementData(oAdvertisementData);
|
|
||||||
pAdvertising->setScanResponseData(oScanResponseData);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
gettimeofday(&nowTimeStruct, NULL);
|
|
||||||
|
|
||||||
Serial.printf("start ESP32 %d\n", bootcount++);
|
|
||||||
|
|
||||||
Serial.printf("deep sleep (%lds since last reset, %lds since last boot)\n", nowTimeStruct.tv_sec, nowTimeStruct.tv_sec - last);
|
|
||||||
|
|
||||||
last = nowTimeStruct.tv_sec;
|
|
||||||
lastTenth = nowTimeStruct.tv_sec * 10; // Time since last reset as 0.1 second resolution counter
|
|
||||||
|
|
||||||
// Create the BLE Device
|
|
||||||
BLEDevice::init("TLMBeacon");
|
|
||||||
|
|
||||||
BLEDevice::setPower(ESP_PWR_LVL_N12);
|
|
||||||
|
|
||||||
pAdvertising = BLEDevice::getAdvertising();
|
|
||||||
|
|
||||||
setBeacon();
|
|
||||||
// Start advertising
|
|
||||||
pAdvertising->start();
|
|
||||||
Serial.println("Advertizing started for 10s ...");
|
|
||||||
delay(10000);
|
|
||||||
pAdvertising->stop();
|
|
||||||
Serial.printf("enter deep sleep for 10s\n");
|
|
||||||
esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);
|
|
||||||
Serial.printf("in deep sleep\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
## Eddystone TLM beacon
|
|
||||||
EddystoneTLM beacon by BeeGee based on
|
|
||||||
[pcbreflux ESP32 Eddystone TLM deepsleep](https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_Eddystone_TLM_deepsleep/ESP32_Eddystone_TLM_deepsleep.ino)
|
|
||||||
|
|
||||||
[EddystoneTLM frame specification](https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md)
|
|
||||||
|
|
||||||
Create a BLE server that will send periodic Eddystone TLM frames.
|
|
||||||
The design of creating the BLE server is:
|
|
||||||
1. Create a BLE Server
|
|
||||||
2. Create advertising data
|
|
||||||
3. Start advertising.
|
|
||||||
4. wait
|
|
||||||
5. Stop advertising.
|
|
||||||
6. deep sleep
|
|
@ -1,192 +0,0 @@
|
|||||||
/*
|
|
||||||
EddystoneURL beacon by BeeGee
|
|
||||||
EddystoneURL frame specification https://github.com/google/eddystone/blob/master/eddystone-url/README.md
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Create a BLE server that will send periodic Eddystone URL frames.
|
|
||||||
The design of creating the BLE server is:
|
|
||||||
1. Create a BLE Server
|
|
||||||
2. Create advertising data
|
|
||||||
3. Start advertising.
|
|
||||||
4. wait
|
|
||||||
5. Stop advertising.
|
|
||||||
6. deep sleep
|
|
||||||
|
|
||||||
*/
|
|
||||||
#include "sys/time.h"
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include "BLEDevice.h"
|
|
||||||
#include "BLEUtils.h"
|
|
||||||
#include "BLEBeacon.h"
|
|
||||||
#include "BLEAdvertising.h"
|
|
||||||
#include "BLEEddystoneURL.h"
|
|
||||||
|
|
||||||
#include "esp_sleep.h"
|
|
||||||
|
|
||||||
#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up
|
|
||||||
RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory
|
|
||||||
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory
|
|
||||||
|
|
||||||
// See the following for generating UUIDs:
|
|
||||||
// https://www.uuidgenerator.net/
|
|
||||||
BLEAdvertising *pAdvertising;
|
|
||||||
struct timeval now;
|
|
||||||
|
|
||||||
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/)
|
|
||||||
|
|
||||||
static const char *eddystone_url_prefix_subs[] = {
|
|
||||||
"http://www.",
|
|
||||||
"https://www.",
|
|
||||||
"http://",
|
|
||||||
"https://",
|
|
||||||
"urn:uuid:",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *eddystone_url_suffix_subs[] = {
|
|
||||||
".com/",
|
|
||||||
".org/",
|
|
||||||
".edu/",
|
|
||||||
".net/",
|
|
||||||
".info/",
|
|
||||||
".biz/",
|
|
||||||
".gov/",
|
|
||||||
".com",
|
|
||||||
".org",
|
|
||||||
".edu",
|
|
||||||
".net",
|
|
||||||
".info",
|
|
||||||
".biz",
|
|
||||||
".gov",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
static int string_begin_with(const char *str, const char *prefix)
|
|
||||||
{
|
|
||||||
int prefix_len = strlen(prefix);
|
|
||||||
if (strncmp(prefix, str, prefix_len) == 0)
|
|
||||||
{
|
|
||||||
return prefix_len;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBeacon()
|
|
||||||
{
|
|
||||||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
|
|
||||||
BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
|
|
||||||
|
|
||||||
const char url[] = "https://d.giesecke.tk";
|
|
||||||
|
|
||||||
int scheme_len, ext_len = 1, i, idx, url_idx;
|
|
||||||
char *ret_data;
|
|
||||||
int url_len = strlen(url);
|
|
||||||
|
|
||||||
ret_data = (char *)calloc(1, url_len + 13);
|
|
||||||
|
|
||||||
ret_data[0] = 2; // Len
|
|
||||||
ret_data[1] = 0x01; // Type Flags
|
|
||||||
ret_data[2] = 0x06; // GENERAL_DISC_MODE 0x02 | BR_EDR_NOT_SUPPORTED 0x04
|
|
||||||
ret_data[3] = 3; // Len
|
|
||||||
ret_data[4] = 0x03; // Type 16-Bit UUID
|
|
||||||
ret_data[5] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB
|
|
||||||
ret_data[6] = 0xFE; // Eddystone UUID 1 MSB
|
|
||||||
ret_data[7] = 19; // Length of Beacon Data
|
|
||||||
ret_data[8] = 0x16; // Type Service Data
|
|
||||||
ret_data[9] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB
|
|
||||||
ret_data[10] = 0xFE; // Eddystone UUID 1 MSB
|
|
||||||
ret_data[11] = 0x10; // Eddystone Frame Type
|
|
||||||
ret_data[12] = 0xF4; // Beacons TX power at 0m
|
|
||||||
|
|
||||||
i = 0, idx = 13, url_idx = 0;
|
|
||||||
|
|
||||||
//replace prefix
|
|
||||||
scheme_len = 0;
|
|
||||||
while (eddystone_url_prefix_subs[i] != NULL)
|
|
||||||
{
|
|
||||||
if ((scheme_len = string_begin_with(url, eddystone_url_prefix_subs[i])) > 0)
|
|
||||||
{
|
|
||||||
ret_data[idx] = i;
|
|
||||||
idx++;
|
|
||||||
url_idx += scheme_len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (url_idx < url_len)
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
ret_data[idx] = url[url_idx];
|
|
||||||
ext_len = 1;
|
|
||||||
while (eddystone_url_suffix_subs[i] != NULL)
|
|
||||||
{
|
|
||||||
if ((ext_len = string_begin_with(&url[url_idx], eddystone_url_suffix_subs[i])) > 0)
|
|
||||||
{
|
|
||||||
ret_data[idx] = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ext_len = 1; //inc 1
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
url_idx += ext_len;
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
ret_data[7] = idx - 8;
|
|
||||||
|
|
||||||
Serial.printf("struct size %d url size %d reported len %d\n",
|
|
||||||
url_len + 13,
|
|
||||||
url_len, ret_data[7]);
|
|
||||||
|
|
||||||
Serial.printf("URL in data %s\n", &ret_data[13]);
|
|
||||||
|
|
||||||
std::string eddyStoneData(ret_data);
|
|
||||||
|
|
||||||
oAdvertisementData.addData(eddyStoneData);
|
|
||||||
oScanResponseData.setName("URLBeacon");
|
|
||||||
pAdvertising->setAdvertisementData(oAdvertisementData);
|
|
||||||
pAdvertising->setScanResponseData(oScanResponseData);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
Serial.printf("start ESP32 %d\n", bootcount++);
|
|
||||||
|
|
||||||
Serial.printf("deep sleep (%lds since last reset, %lds since last boot)\n", now.tv_sec, now.tv_sec - last);
|
|
||||||
|
|
||||||
last = now.tv_sec;
|
|
||||||
|
|
||||||
// Create the BLE Device
|
|
||||||
BLEDevice::init("URLBeacon");
|
|
||||||
|
|
||||||
BLEDevice::setPower(ESP_PWR_LVL_N12);
|
|
||||||
|
|
||||||
// Create the BLE Server
|
|
||||||
// BLEServer *pServer = BLEDevice::createServer(); // <-- no longer required to instantiate BLEServer, less flash and ram usage
|
|
||||||
|
|
||||||
pAdvertising = BLEDevice::getAdvertising();
|
|
||||||
|
|
||||||
setBeacon();
|
|
||||||
// Start advertising
|
|
||||||
pAdvertising->start();
|
|
||||||
Serial.println("Advertizing started...");
|
|
||||||
delay(10000);
|
|
||||||
pAdvertising->stop();
|
|
||||||
Serial.printf("enter deep sleep\n");
|
|
||||||
esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);
|
|
||||||
Serial.printf("in deep sleep\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
## Eddystone URL beacon
|
|
||||||
EddystoneURL beacon by BeeGee based on
|
|
||||||
[pcbreflux ESP32 Eddystone URL deepsleep](https://github.com/pcbreflux/espressif/tree/master/esp32/arduino/sketchbook/ESP32_Eddystone_URL_deepsleep)
|
|
||||||
|
|
||||||
[EddystoneURL frame specification](https://github.com/google/eddystone/blob/master/eddystone-url/README.md)
|
|
||||||
|
|
||||||
Create a BLE server that will send periodic Eddystone URL frames.
|
|
||||||
The design of creating the BLE server is:
|
|
||||||
1. Create a BLE Server
|
|
||||||
2. Create advertising data
|
|
||||||
3. Start advertising.
|
|
||||||
4. wait
|
|
||||||
5. Stop advertising.
|
|
||||||
6. deep sleep
|
|
@ -59,37 +59,14 @@ BLEAddress::BLEAddress(std::string stringAddress) {
|
|||||||
* @return True if the addresses are equal.
|
* @return True if the addresses are equal.
|
||||||
*/
|
*/
|
||||||
bool BLEAddress::equals(BLEAddress otherAddress) {
|
bool BLEAddress::equals(BLEAddress otherAddress) {
|
||||||
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
|
return memcmp(otherAddress.getNative(), m_address, 6) == 0;
|
||||||
} // equals
|
} // equals
|
||||||
|
|
||||||
bool BLEAddress::operator==(const BLEAddress& otherAddress) const {
|
|
||||||
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BLEAddress::operator!=(const BLEAddress& otherAddress) const {
|
|
||||||
return !(*this == otherAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BLEAddress::operator<(const BLEAddress& otherAddress) const {
|
|
||||||
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BLEAddress::operator<=(const BLEAddress& otherAddress) const {
|
|
||||||
return !(*this > otherAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BLEAddress::operator>=(const BLEAddress& otherAddress) const {
|
|
||||||
return !(*this < otherAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BLEAddress::operator>(const BLEAddress& otherAddress) const {
|
|
||||||
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the native representation of the address.
|
* @brief Return the native representation of the address.
|
||||||
* @return The native representation of the address.
|
* @return The native representation of the address.
|
||||||
*/
|
*/
|
||||||
esp_bd_addr_t *BLEAddress::getNative() {
|
esp_bd_addr_t *BLEAddress::getNative() {
|
||||||
return &m_address;
|
return &m_address;
|
||||||
} // getNative
|
} // getNative
|
||||||
|
@ -23,12 +23,6 @@ public:
|
|||||||
BLEAddress(esp_bd_addr_t address);
|
BLEAddress(esp_bd_addr_t address);
|
||||||
BLEAddress(std::string stringAddress);
|
BLEAddress(std::string stringAddress);
|
||||||
bool equals(BLEAddress otherAddress);
|
bool equals(BLEAddress otherAddress);
|
||||||
bool operator==(const BLEAddress& otherAddress) const;
|
|
||||||
bool operator!=(const BLEAddress& otherAddress) const;
|
|
||||||
bool operator<(const BLEAddress& otherAddress) const;
|
|
||||||
bool operator<=(const BLEAddress& otherAddress) const;
|
|
||||||
bool operator>(const BLEAddress& otherAddress) const;
|
|
||||||
bool operator>=(const BLEAddress& otherAddress) const;
|
|
||||||
esp_bd_addr_t* getNative();
|
esp_bd_addr_t* getNative();
|
||||||
std::string toString();
|
std::string toString();
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
|
|||||||
m_manufacturerData = "";
|
m_manufacturerData = "";
|
||||||
m_name = "";
|
m_name = "";
|
||||||
m_rssi = -9999;
|
m_rssi = -9999;
|
||||||
m_serviceUUIDs = {};
|
|
||||||
m_serviceData = {};
|
m_serviceData = {};
|
||||||
m_serviceDataUUIDs = {};
|
m_serviceDataUUIDs = {};
|
||||||
m_txPower = 0;
|
m_txPower = 0;
|
||||||
@ -35,6 +34,8 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
|
|||||||
m_haveManufacturerData = false;
|
m_haveManufacturerData = false;
|
||||||
m_haveName = false;
|
m_haveName = false;
|
||||||
m_haveRSSI = false;
|
m_haveRSSI = false;
|
||||||
|
m_haveServiceData = false;
|
||||||
|
m_haveServiceUUID = false;
|
||||||
m_haveTXPower = false;
|
m_haveTXPower = false;
|
||||||
|
|
||||||
} // BLEAdvertisedDevice
|
} // BLEAdvertisedDevice
|
||||||
@ -106,7 +107,11 @@ BLEScan* BLEAdvertisedDevice::getScan() {
|
|||||||
* @return Number of service data discovered.
|
* @return Number of service data discovered.
|
||||||
*/
|
*/
|
||||||
int BLEAdvertisedDevice::getServiceDataCount() {
|
int BLEAdvertisedDevice::getServiceDataCount() {
|
||||||
return m_serviceData.size();
|
if (m_haveServiceData)
|
||||||
|
return m_serviceData.size();
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
} //getServiceDataCount
|
} //getServiceDataCount
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +119,7 @@ int BLEAdvertisedDevice::getServiceDataCount() {
|
|||||||
* @return The ServiceData of the advertised device.
|
* @return The ServiceData of the advertised device.
|
||||||
*/
|
*/
|
||||||
std::string BLEAdvertisedDevice::getServiceData() {
|
std::string BLEAdvertisedDevice::getServiceData() {
|
||||||
return m_serviceData.empty() ? std::string() : m_serviceData.front();
|
return m_serviceData[0];
|
||||||
} //getServiceData
|
} //getServiceData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,20 +130,12 @@ std::string BLEAdvertisedDevice::getServiceData(int i) {
|
|||||||
return m_serviceData[i];
|
return m_serviceData[i];
|
||||||
} //getServiceData
|
} //getServiceData
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the number of service data UUIDs.
|
|
||||||
* @return Number of service data UUIDs discovered.
|
|
||||||
*/
|
|
||||||
int BLEAdvertisedDevice::getServiceDataUUIDCount() {
|
|
||||||
return m_serviceDataUUIDs.size();
|
|
||||||
} //getServiceDataUUIDCount
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the service data UUID.
|
* @brief Get the service data UUID.
|
||||||
* @return The service data UUID.
|
* @return The service data UUID.
|
||||||
*/
|
*/
|
||||||
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
|
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
|
||||||
return m_serviceDataUUIDs.empty() ? BLEUUID() : m_serviceDataUUIDs.front();
|
return m_serviceDataUUIDs[0];
|
||||||
} // getServiceDataUUID
|
} // getServiceDataUUID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,20 +146,12 @@ BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) {
|
|||||||
return m_serviceDataUUIDs[i];
|
return m_serviceDataUUIDs[i];
|
||||||
} // getServiceDataUUID
|
} // getServiceDataUUID
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the number of service UUIDs.
|
|
||||||
* @return Number of service UUIDs discovered.
|
|
||||||
*/
|
|
||||||
int BLEAdvertisedDevice::getServiceUUIDCount() {
|
|
||||||
return m_serviceUUIDs.size();
|
|
||||||
} //getServiceUUIDCount
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Service UUID.
|
* @brief Get the Service UUID.
|
||||||
* @return The Service UUID of the advertised device.
|
* @return The Service UUID of the advertised device.
|
||||||
*/
|
*/
|
||||||
BLEUUID BLEAdvertisedDevice::getServiceUUID() {
|
BLEUUID BLEAdvertisedDevice::getServiceUUID() {
|
||||||
return m_serviceUUIDs.empty() ? BLEUUID() : m_serviceUUIDs.front();
|
return m_serviceUUIDs[0];
|
||||||
} // getServiceUUID
|
} // getServiceUUID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,7 +167,7 @@ BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) {
|
|||||||
* @return Return true if service is advertised
|
* @return Return true if service is advertised
|
||||||
*/
|
*/
|
||||||
bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){
|
bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){
|
||||||
for (int i = 0; i < getServiceUUIDCount(); i++) {
|
for (int i = 0; i < m_serviceUUIDs.size(); i++) {
|
||||||
if (m_serviceUUIDs[i].equals(uuid)) return true;
|
if (m_serviceUUIDs[i].equals(uuid)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -235,7 +224,7 @@ bool BLEAdvertisedDevice::haveRSSI() {
|
|||||||
* @return True if there is a service data value present.
|
* @return True if there is a service data value present.
|
||||||
*/
|
*/
|
||||||
bool BLEAdvertisedDevice::haveServiceData() {
|
bool BLEAdvertisedDevice::haveServiceData() {
|
||||||
return !m_serviceData.empty();
|
return m_haveServiceData;
|
||||||
} // haveServiceData
|
} // haveServiceData
|
||||||
|
|
||||||
|
|
||||||
@ -244,7 +233,7 @@ bool BLEAdvertisedDevice::haveServiceData() {
|
|||||||
* @return True if there is a service UUID value present.
|
* @return True if there is a service UUID value present.
|
||||||
*/
|
*/
|
||||||
bool BLEAdvertisedDevice::haveServiceUUID() {
|
bool BLEAdvertisedDevice::haveServiceUUID() {
|
||||||
return !m_serviceUUIDs.empty();
|
return m_haveServiceUUID;
|
||||||
} // haveServiceUUID
|
} // haveServiceUUID
|
||||||
|
|
||||||
|
|
||||||
@ -399,15 +388,6 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
|
|||||||
} // !finished
|
} // !finished
|
||||||
} // parseAdvertisement
|
} // parseAdvertisement
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Parse the advertising payload.
|
|
||||||
* @param [in] payload The payload of the advertised device.
|
|
||||||
* @param [in] total_len The length of payload
|
|
||||||
*/
|
|
||||||
void BLEAdvertisedDevice::setPayload(uint8_t* payload, size_t total_len) {
|
|
||||||
m_payload = payload;
|
|
||||||
m_payloadLength = total_len;
|
|
||||||
} // setPayload
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the address of the advertised device.
|
* @brief Set the address of the advertised device.
|
||||||
@ -497,6 +477,7 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
|
|||||||
*/
|
*/
|
||||||
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
|
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
|
||||||
m_serviceUUIDs.push_back(serviceUUID);
|
m_serviceUUIDs.push_back(serviceUUID);
|
||||||
|
m_haveServiceUUID = true;
|
||||||
log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
|
log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
|
||||||
} // setServiceUUID
|
} // setServiceUUID
|
||||||
|
|
||||||
@ -506,6 +487,7 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
|
|||||||
* @param [in] data ServiceData value.
|
* @param [in] data ServiceData value.
|
||||||
*/
|
*/
|
||||||
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
|
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
|
||||||
|
m_haveServiceData = true; // Set the flag that indicates we have service data.
|
||||||
m_serviceData.push_back(serviceData); // Save the service data that we received.
|
m_serviceData.push_back(serviceData); // Save the service data that we received.
|
||||||
} //setServiceData
|
} //setServiceData
|
||||||
|
|
||||||
@ -515,6 +497,7 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
|
|||||||
* @param [in] data ServiceDataUUID value.
|
* @param [in] data ServiceDataUUID value.
|
||||||
*/
|
*/
|
||||||
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
|
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
|
||||||
|
m_haveServiceData = true; // Set the flag that indicates we have service data.
|
||||||
m_serviceDataUUIDs.push_back(uuid);
|
m_serviceDataUUIDs.push_back(uuid);
|
||||||
log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
|
log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
|
||||||
} // setServiceDataUUID
|
} // setServiceDataUUID
|
||||||
@ -550,12 +533,12 @@ std::string BLEAdvertisedDevice::toString() {
|
|||||||
free(pHex);
|
free(pHex);
|
||||||
}
|
}
|
||||||
if (haveServiceUUID()) {
|
if (haveServiceUUID()) {
|
||||||
for (int i=0; i < getServiceUUIDCount(); i++) {
|
for (int i=0; i < m_serviceUUIDs.size(); i++) {
|
||||||
res += ", serviceUUID: " + getServiceUUID(i).toString();
|
res += ", serviceUUID: " + getServiceUUID(i).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (haveTXPower()) {
|
if (haveTXPower()) {
|
||||||
char val[4];
|
char val[6];
|
||||||
snprintf(val, sizeof(val), "%d", getTXPower());
|
snprintf(val, sizeof(val), "%d", getTXPower());
|
||||||
res += ", txPower: ";
|
res += ", txPower: ";
|
||||||
res += val;
|
res += val;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <esp_gattc_api.h>
|
#include <esp_gattc_api.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "BLEAddress.h"
|
#include "BLEAddress.h"
|
||||||
#include "BLEScan.h"
|
#include "BLEScan.h"
|
||||||
@ -42,8 +43,6 @@ public:
|
|||||||
BLEUUID getServiceUUID();
|
BLEUUID getServiceUUID();
|
||||||
BLEUUID getServiceUUID(int i);
|
BLEUUID getServiceUUID(int i);
|
||||||
int getServiceDataCount();
|
int getServiceDataCount();
|
||||||
int getServiceDataUUIDCount();
|
|
||||||
int getServiceUUIDCount();
|
|
||||||
int8_t getTXPower();
|
int8_t getTXPower();
|
||||||
uint8_t* getPayload();
|
uint8_t* getPayload();
|
||||||
size_t getPayloadLength();
|
size_t getPayloadLength();
|
||||||
@ -66,7 +65,6 @@ private:
|
|||||||
friend class BLEScan;
|
friend class BLEScan;
|
||||||
|
|
||||||
void parseAdvertisement(uint8_t* payload, size_t total_len=62);
|
void parseAdvertisement(uint8_t* payload, size_t total_len=62);
|
||||||
void setPayload(uint8_t* payload, size_t total_len=62);
|
|
||||||
void setAddress(BLEAddress address);
|
void setAddress(BLEAddress address);
|
||||||
void setAdFlag(uint8_t adFlag);
|
void setAdFlag(uint8_t adFlag);
|
||||||
void setAdvertizementResult(uint8_t* payload);
|
void setAdvertizementResult(uint8_t* payload);
|
||||||
@ -85,6 +83,8 @@ private:
|
|||||||
bool m_haveManufacturerData;
|
bool m_haveManufacturerData;
|
||||||
bool m_haveName;
|
bool m_haveName;
|
||||||
bool m_haveRSSI;
|
bool m_haveRSSI;
|
||||||
|
bool m_haveServiceData;
|
||||||
|
bool m_haveServiceUUID;
|
||||||
bool m_haveTXPower;
|
bool m_haveTXPower;
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,9 +28,7 @@
|
|||||||
* @brief Construct a default advertising object.
|
* @brief Construct a default advertising object.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
BLEAdvertising::BLEAdvertising()
|
BLEAdvertising::BLEAdvertising() {
|
||||||
: m_scanRespData{}
|
|
||||||
{
|
|
||||||
m_advData.set_scan_rsp = false;
|
m_advData.set_scan_rsp = false;
|
||||||
m_advData.include_name = true;
|
m_advData.include_name = true;
|
||||||
m_advData.include_txpower = true;
|
m_advData.include_txpower = true;
|
||||||
@ -91,10 +89,6 @@ void BLEAdvertising::setAdvertisementType(esp_ble_adv_type_t adv_type){
|
|||||||
m_advParams.adv_type = adv_type;
|
m_advParams.adv_type = adv_type;
|
||||||
} // setAdvertisementType
|
} // setAdvertisementType
|
||||||
|
|
||||||
void BLEAdvertising::setAdvertisementChannelMap(esp_ble_adv_channel_t channel_map) {
|
|
||||||
m_advParams.channel_map = channel_map;
|
|
||||||
} // setAdvertisementChannelMap
|
|
||||||
|
|
||||||
void BLEAdvertising::setMinInterval(uint16_t mininterval) {
|
void BLEAdvertising::setMinInterval(uint16_t mininterval) {
|
||||||
m_advParams.adv_int_min = mininterval;
|
m_advParams.adv_int_min = mininterval;
|
||||||
} // setMinInterval
|
} // setMinInterval
|
||||||
@ -221,15 +215,10 @@ void BLEAdvertising::start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_customScanResponseData && m_scanResp) {
|
if (!m_customScanResponseData && m_scanResp) {
|
||||||
// Set the configuration for scan response.
|
m_advData.set_scan_rsp = true;
|
||||||
memcpy(&m_scanRespData, &m_advData, sizeof(esp_ble_adv_data_t)); // Copy the content of m_advData.
|
m_advData.include_name = m_scanResp;
|
||||||
m_scanRespData.set_scan_rsp = true; // Define this struct as scan response data
|
m_advData.include_txpower = m_scanResp;
|
||||||
m_scanRespData.include_name = true; // Caution: This may lead to a crash if the device name has more than 29 characters
|
errRc = ::esp_ble_gap_config_adv_data(&m_advData);
|
||||||
m_scanRespData.include_txpower = true;
|
|
||||||
m_scanRespData.appearance = 0; // If defined the 'Appearance' attribute is already included in the advertising data
|
|
||||||
m_scanRespData.flag = 0; // 'Flags' attribute should no be included in the scan response
|
|
||||||
|
|
||||||
errRc = ::esp_ble_gap_config_adv_data(&m_scanRespData);
|
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
return;
|
return;
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
void setPartialServices(BLEUUID uuid);
|
void setPartialServices(BLEUUID uuid);
|
||||||
void setServiceData(BLEUUID uuid, std::string data);
|
void setServiceData(BLEUUID uuid, std::string data);
|
||||||
void setShortName(std::string name);
|
void setShortName(std::string name);
|
||||||
void addData(std::string data); // Add data to the payload.
|
void addData(std::string data); // Add data to the payload.
|
||||||
std::string getPayload(); // Retrieve the current advert payload.
|
std::string getPayload(); // Retrieve the current advert payload.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -53,7 +53,6 @@ public:
|
|||||||
void stop();
|
void stop();
|
||||||
void setAppearance(uint16_t appearance);
|
void setAppearance(uint16_t appearance);
|
||||||
void setAdvertisementType(esp_ble_adv_type_t adv_type);
|
void setAdvertisementType(esp_ble_adv_type_t adv_type);
|
||||||
void setAdvertisementChannelMap(esp_ble_adv_channel_t channel_map);
|
|
||||||
void setMaxInterval(uint16_t maxinterval);
|
void setMaxInterval(uint16_t maxinterval);
|
||||||
void setMinInterval(uint16_t mininterval);
|
void setMinInterval(uint16_t mininterval);
|
||||||
void setAdvertisementData(BLEAdvertisementData& advertisementData);
|
void setAdvertisementData(BLEAdvertisementData& advertisementData);
|
||||||
@ -69,13 +68,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
esp_ble_adv_data_t m_advData;
|
esp_ble_adv_data_t m_advData;
|
||||||
esp_ble_adv_data_t m_scanRespData; // Used for configuration of scan response data when m_scanResp is true
|
|
||||||
esp_ble_adv_params_t m_advParams;
|
esp_ble_adv_params_t m_advParams;
|
||||||
std::vector<BLEUUID> m_serviceUUIDs;
|
std::vector<BLEUUID> m_serviceUUIDs;
|
||||||
bool m_customAdvData = false; // Are we using custom advertising data?
|
bool m_customAdvData = false; // Are we using custom advertising data?
|
||||||
bool m_customScanResponseData = false; // Are we using custom scan response data?
|
bool m_customScanResponseData = false; // Are we using custom scan response data?
|
||||||
FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert");
|
FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert");
|
||||||
bool m_scanResp = true;
|
bool m_scanResp = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif /* CONFIG_BT_ENABLED */
|
#endif /* CONFIG_BT_ENABLED */
|
||||||
|
@ -219,22 +219,19 @@ void BLECharacteristic::handleGATTServerEvent(
|
|||||||
// - uint8_t exec_write_flag - Either ESP_GATT_PREP_WRITE_EXEC or ESP_GATT_PREP_WRITE_CANCEL
|
// - uint8_t exec_write_flag - Either ESP_GATT_PREP_WRITE_EXEC or ESP_GATT_PREP_WRITE_CANCEL
|
||||||
//
|
//
|
||||||
case ESP_GATTS_EXEC_WRITE_EVT: {
|
case ESP_GATTS_EXEC_WRITE_EVT: {
|
||||||
if(m_writeEvt){
|
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
|
||||||
m_writeEvt = false;
|
m_value.commit();
|
||||||
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
|
m_pCallbacks->onWrite(this); // Invoke the onWrite callback handler.
|
||||||
m_value.commit();
|
} else {
|
||||||
m_pCallbacks->onWrite(this); // Invoke the onWrite callback handler.
|
m_value.cancel();
|
||||||
} else {
|
}
|
||||||
m_value.cancel();
|
// ???
|
||||||
}
|
esp_err_t errRc = ::esp_ble_gatts_send_response(
|
||||||
// ???
|
gatts_if,
|
||||||
esp_err_t errRc = ::esp_ble_gatts_send_response(
|
param->write.conn_id,
|
||||||
gatts_if,
|
param->write.trans_id, ESP_GATT_OK, nullptr);
|
||||||
param->write.conn_id,
|
if (errRc != ESP_OK) {
|
||||||
param->write.trans_id, ESP_GATT_OK, nullptr);
|
log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
if (errRc != ESP_OK) {
|
|
||||||
log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} // ESP_GATTS_EXEC_WRITE_EVT
|
} // ESP_GATTS_EXEC_WRITE_EVT
|
||||||
@ -280,7 +277,6 @@ void BLECharacteristic::handleGATTServerEvent(
|
|||||||
if (param->write.handle == m_handle) {
|
if (param->write.handle == m_handle) {
|
||||||
if (param->write.is_prep) {
|
if (param->write.is_prep) {
|
||||||
m_value.addPart(param->write.value, param->write.len);
|
m_value.addPart(param->write.value, param->write.len);
|
||||||
m_writeEvt = true;
|
|
||||||
} else {
|
} else {
|
||||||
setValue(param->write.value, param->write.len);
|
setValue(param->write.value, param->write.len);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,6 @@ private:
|
|||||||
BLEService* m_pService;
|
BLEService* m_pService;
|
||||||
BLEValue m_value;
|
BLEValue m_value;
|
||||||
esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
|
esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
|
||||||
bool m_writeEvt = false; // If we have started a long write, this tells the commit code that we were the target
|
|
||||||
|
|
||||||
void handleGATTServerEvent(
|
void handleGATTServerEvent(
|
||||||
esp_gatts_cb_event_t event,
|
esp_gatts_cb_event_t event,
|
||||||
|
@ -60,7 +60,6 @@ BLEClient::~BLEClient() {
|
|||||||
delete myPair.second;
|
delete myPair.second;
|
||||||
}
|
}
|
||||||
m_servicesMap.clear();
|
m_servicesMap.clear();
|
||||||
m_servicesMapByInstID.clear();
|
|
||||||
} // ~BLEClient
|
} // ~BLEClient
|
||||||
|
|
||||||
|
|
||||||
@ -106,21 +105,10 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
|
|||||||
esp_err_t errRc = ::esp_ble_gattc_app_register(m_appId);
|
esp_err_t errRc = ::esp_ble_gattc_app_register(m_appId);
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
log_e("esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
BLEDevice::removePeerDevice(m_appId, true);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t rc = m_semaphoreRegEvt.wait("connect");
|
m_semaphoreRegEvt.wait("connect");
|
||||||
|
|
||||||
if (rc != ESP_GATT_OK) {
|
|
||||||
// fixes ESP_GATT_NO_RESOURCES error mostly
|
|
||||||
log_e("esp_ble_gattc_app_register_error: rc=%d", rc);
|
|
||||||
BLEDevice::removePeerDevice(m_appId, true);
|
|
||||||
// not sure if this is needed here
|
|
||||||
// esp_ble_gattc_app_unregister(m_gattc_if);
|
|
||||||
// m_gattc_if = ESP_GATT_IF_NONE;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_peerAddress = address;
|
m_peerAddress = address;
|
||||||
|
|
||||||
@ -134,17 +122,10 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
|
|||||||
);
|
);
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
BLEDevice::removePeerDevice(m_appId, true);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete.
|
uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete.
|
||||||
// check the status of the connection and cleanup in case of failure
|
|
||||||
if (rc != ESP_GATT_OK) {
|
|
||||||
BLEDevice::removePeerDevice(m_appId, true);
|
|
||||||
esp_ble_gattc_app_unregister(m_gattc_if);
|
|
||||||
m_gattc_if = ESP_GATT_IF_NONE;
|
|
||||||
}
|
|
||||||
log_v("<< connect(), rc=%d", rc==ESP_GATT_OK);
|
log_v("<< connect(), rc=%d", rc==ESP_GATT_OK);
|
||||||
return rc == ESP_GATT_OK;
|
return rc == ESP_GATT_OK;
|
||||||
} // connect
|
} // connect
|
||||||
@ -176,11 +157,6 @@ void BLEClient::gattClientEventHandler(
|
|||||||
log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s",
|
log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s",
|
||||||
gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str());
|
gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str());
|
||||||
|
|
||||||
// it is possible to receive events from other connections while waiting for registration
|
|
||||||
if (m_gattc_if == ESP_GATT_IF_NONE && event != ESP_GATTC_REG_EVT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute handler code based on the type of event received.
|
// Execute handler code based on the type of event received.
|
||||||
switch(event) {
|
switch(event) {
|
||||||
|
|
||||||
@ -202,20 +178,17 @@ void BLEClient::gattClientEventHandler(
|
|||||||
// - uint16_t conn_id
|
// - uint16_t conn_id
|
||||||
// - esp_bd_addr_t remote_bda
|
// - esp_bd_addr_t remote_bda
|
||||||
case ESP_GATTC_DISCONNECT_EVT: {
|
case ESP_GATTC_DISCONNECT_EVT: {
|
||||||
if (evtParam->disconnect.conn_id != getConnId()) break;
|
|
||||||
// If we receive a disconnect event, set the class flag that indicates that we are
|
// If we receive a disconnect event, set the class flag that indicates that we are
|
||||||
// no longer connected.
|
// no longer connected.
|
||||||
bool m_wasConnected = m_isConnected;
|
|
||||||
m_isConnected = false;
|
m_isConnected = false;
|
||||||
|
if (m_pClientCallbacks != nullptr) {
|
||||||
|
m_pClientCallbacks->onDisconnect(this);
|
||||||
|
}
|
||||||
esp_ble_gattc_app_unregister(m_gattc_if);
|
esp_ble_gattc_app_unregister(m_gattc_if);
|
||||||
m_gattc_if = ESP_GATT_IF_NONE;
|
|
||||||
m_semaphoreOpenEvt.give(ESP_GATT_IF_NONE);
|
m_semaphoreOpenEvt.give(ESP_GATT_IF_NONE);
|
||||||
m_semaphoreRssiCmplEvt.give();
|
m_semaphoreRssiCmplEvt.give();
|
||||||
m_semaphoreSearchCmplEvt.give(1);
|
m_semaphoreSearchCmplEvt.give(1);
|
||||||
BLEDevice::removePeerDevice(m_appId, true);
|
BLEDevice::removePeerDevice(m_appId, true);
|
||||||
if (m_wasConnected && m_pClientCallbacks != nullptr) {
|
|
||||||
m_pClientCallbacks->onDisconnect(this);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
} // ESP_GATTC_DISCONNECT_EVT
|
} // ESP_GATTC_DISCONNECT_EVT
|
||||||
|
|
||||||
@ -229,13 +202,11 @@ void BLEClient::gattClientEventHandler(
|
|||||||
//
|
//
|
||||||
case ESP_GATTC_OPEN_EVT: {
|
case ESP_GATTC_OPEN_EVT: {
|
||||||
m_conn_id = evtParam->open.conn_id;
|
m_conn_id = evtParam->open.conn_id;
|
||||||
|
if (m_pClientCallbacks != nullptr) {
|
||||||
|
m_pClientCallbacks->onConnect(this);
|
||||||
|
}
|
||||||
if (evtParam->open.status == ESP_GATT_OK) {
|
if (evtParam->open.status == ESP_GATT_OK) {
|
||||||
m_isConnected = true; // Flag us as connected.
|
m_isConnected = true; // Flag us as connected.
|
||||||
if (m_pClientCallbacks != nullptr) {
|
|
||||||
m_pClientCallbacks->onConnect(this);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log_e("Failed to connect, status=%s", GeneralUtils::errorToString(evtParam->open.status));
|
|
||||||
}
|
}
|
||||||
m_semaphoreOpenEvt.give(evtParam->open.status);
|
m_semaphoreOpenEvt.give(evtParam->open.status);
|
||||||
break;
|
break;
|
||||||
@ -251,13 +222,11 @@ void BLEClient::gattClientEventHandler(
|
|||||||
//
|
//
|
||||||
case ESP_GATTC_REG_EVT: {
|
case ESP_GATTC_REG_EVT: {
|
||||||
m_gattc_if = gattc_if;
|
m_gattc_if = gattc_if;
|
||||||
// pass on the registration status result, in case of failure
|
m_semaphoreRegEvt.give();
|
||||||
m_semaphoreRegEvt.give(evtParam->reg.status);
|
|
||||||
break;
|
break;
|
||||||
} // ESP_GATTC_REG_EVT
|
} // ESP_GATTC_REG_EVT
|
||||||
|
|
||||||
case ESP_GATTC_CFG_MTU_EVT:
|
case ESP_GATTC_CFG_MTU_EVT:
|
||||||
if (evtParam->cfg_mtu.conn_id != getConnId()) break;
|
|
||||||
if(evtParam->cfg_mtu.status != ESP_GATT_OK) {
|
if(evtParam->cfg_mtu.status != ESP_GATT_OK) {
|
||||||
log_e("Config mtu failed");
|
log_e("Config mtu failed");
|
||||||
}
|
}
|
||||||
@ -265,8 +234,7 @@ void BLEClient::gattClientEventHandler(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_GATTC_CONNECT_EVT: {
|
case ESP_GATTC_CONNECT_EVT: {
|
||||||
if (evtParam->connect.conn_id != getConnId()) break;
|
BLEDevice::updatePeerDevice(this, true, m_gattc_if);
|
||||||
BLEDevice::updatePeerDevice(this, true, m_appId);
|
|
||||||
esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id);
|
esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id);
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
log_e("esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
@ -287,7 +255,6 @@ void BLEClient::gattClientEventHandler(
|
|||||||
// - uint16_t conn_id
|
// - uint16_t conn_id
|
||||||
//
|
//
|
||||||
case ESP_GATTC_SEARCH_CMPL_EVT: {
|
case ESP_GATTC_SEARCH_CMPL_EVT: {
|
||||||
if (evtParam->search_cmpl.conn_id != getConnId()) break;
|
|
||||||
esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam;
|
esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam;
|
||||||
if (p_data->search_cmpl.status != ESP_GATT_OK){
|
if (p_data->search_cmpl.status != ESP_GATT_OK){
|
||||||
log_e("search service failed, error status = %x", p_data->search_cmpl.status);
|
log_e("search service failed, error status = %x", p_data->search_cmpl.status);
|
||||||
@ -318,7 +285,6 @@ void BLEClient::gattClientEventHandler(
|
|||||||
// - esp_gatt_id_t srvc_id
|
// - esp_gatt_id_t srvc_id
|
||||||
//
|
//
|
||||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||||
if (evtParam->search_res.conn_id != getConnId()) break;
|
|
||||||
BLEUUID uuid = BLEUUID(evtParam->search_res.srvc_id);
|
BLEUUID uuid = BLEUUID(evtParam->search_res.srvc_id);
|
||||||
BLERemoteService* pRemoteService = new BLERemoteService(
|
BLERemoteService* pRemoteService = new BLERemoteService(
|
||||||
evtParam->search_res.srvc_id,
|
evtParam->search_res.srvc_id,
|
||||||
|
@ -499,7 +499,11 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
|
|||||||
*/
|
*/
|
||||||
void BLEDevice::whiteListAdd(BLEAddress address) {
|
void BLEDevice::whiteListAdd(BLEAddress address) {
|
||||||
log_v(">> whiteListAdd: %s", address.toString().c_str());
|
log_v(">> whiteListAdd: %s", address.toString().c_str());
|
||||||
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! True to add an entry.
|
||||||
|
#else
|
||||||
|
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
|
||||||
|
#endif
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
}
|
}
|
||||||
@ -513,7 +517,11 @@ void BLEDevice::whiteListAdd(BLEAddress address) {
|
|||||||
*/
|
*/
|
||||||
void BLEDevice::whiteListRemove(BLEAddress address) {
|
void BLEDevice::whiteListRemove(BLEAddress address) {
|
||||||
log_v(">> whiteListRemove: %s", address.toString().c_str());
|
log_v(">> whiteListRemove: %s", address.toString().c_str());
|
||||||
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! False to remove an entry.
|
||||||
|
#else
|
||||||
|
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
|
||||||
|
#endif
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,6 @@
|
|||||||
*
|
*
|
||||||
* Created on: Mar 12, 2018
|
* Created on: Mar 12, 2018
|
||||||
* Author: pcbreflux
|
* Author: pcbreflux
|
||||||
* Edited on: Mar 20, 2020 by beegee-tokyo
|
|
||||||
* Fix temperature value (8.8 fixed format)
|
|
||||||
* Fix time stamp (0.1 second resolution)
|
|
||||||
* Fixes based on EddystoneTLM frame specification https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#if defined(CONFIG_BT_ENABLED)
|
#if defined(CONFIG_BT_ENABLED)
|
||||||
@ -25,7 +20,7 @@ BLEEddystoneTLM::BLEEddystoneTLM() {
|
|||||||
m_eddystoneData.frameType = EDDYSTONE_TLM_FRAME_TYPE;
|
m_eddystoneData.frameType = EDDYSTONE_TLM_FRAME_TYPE;
|
||||||
m_eddystoneData.version = 0;
|
m_eddystoneData.version = 0;
|
||||||
m_eddystoneData.volt = 3300; // 3300mV = 3.3V
|
m_eddystoneData.volt = 3300; // 3300mV = 3.3V
|
||||||
m_eddystoneData.temp = (uint16_t) ((float) 23.00)/256;
|
m_eddystoneData.temp = (uint16_t) ((float) 23.00);
|
||||||
m_eddystoneData.advCount = 0;
|
m_eddystoneData.advCount = 0;
|
||||||
m_eddystoneData.tmil = 0;
|
m_eddystoneData.tmil = 0;
|
||||||
} // BLEEddystoneTLM
|
} // BLEEddystoneTLM
|
||||||
@ -43,50 +38,41 @@ uint8_t BLEEddystoneTLM::getVersion() {
|
|||||||
} // getVersion
|
} // getVersion
|
||||||
|
|
||||||
uint16_t BLEEddystoneTLM::getVolt() {
|
uint16_t BLEEddystoneTLM::getVolt() {
|
||||||
return ENDIAN_CHANGE_U16(m_eddystoneData.volt);
|
return m_eddystoneData.volt;
|
||||||
} // getVolt
|
} // getVolt
|
||||||
|
|
||||||
float BLEEddystoneTLM::getTemp() {
|
float BLEEddystoneTLM::getTemp() {
|
||||||
return ENDIAN_CHANGE_U16(m_eddystoneData.temp) / 256.0f;
|
return (float)m_eddystoneData.temp;
|
||||||
} // getTemp
|
} // getTemp
|
||||||
|
|
||||||
uint32_t BLEEddystoneTLM::getCount() {
|
uint32_t BLEEddystoneTLM::getCount() {
|
||||||
return ENDIAN_CHANGE_U32(m_eddystoneData.advCount);
|
return m_eddystoneData.advCount;
|
||||||
} // getCount
|
} // getCount
|
||||||
|
|
||||||
uint32_t BLEEddystoneTLM::getTime() {
|
uint32_t BLEEddystoneTLM::getTime() {
|
||||||
return (ENDIAN_CHANGE_U32(m_eddystoneData.tmil)) / 10;
|
return m_eddystoneData.tmil;
|
||||||
} // getTime
|
} // getTime
|
||||||
|
|
||||||
std::string BLEEddystoneTLM::toString() {
|
std::string BLEEddystoneTLM::toString() {
|
||||||
std::string out = "";
|
std::string out = "";
|
||||||
uint32_t rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil);
|
uint32_t rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil);
|
||||||
char val[12];
|
char val[6];
|
||||||
|
|
||||||
out += "Version "; // + std::string(m_eddystoneData.version);
|
out += "Version " + m_eddystoneData.version;
|
||||||
snprintf(val, sizeof(val), "%d", m_eddystoneData.version);
|
|
||||||
out += val;
|
|
||||||
out += "\n";
|
out += "\n";
|
||||||
out += "Battery Voltage "; // + ENDIAN_CHANGE_U16(m_eddystoneData.volt);
|
out += "Battery Voltage " + ENDIAN_CHANGE_U16(m_eddystoneData.volt);
|
||||||
snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U16(m_eddystoneData.volt));
|
|
||||||
out += val;
|
|
||||||
out += " mV\n";
|
out += " mV\n";
|
||||||
|
|
||||||
out += "Temperature ";
|
out += "Temperature ";
|
||||||
snprintf(val, sizeof(val), "%.2f", ENDIAN_CHANGE_U16(m_eddystoneData.temp) / 256.0f);
|
snprintf(val, sizeof(val), "%d", m_eddystoneData.temp);
|
||||||
out += val;
|
out += val;
|
||||||
out += " C\n";
|
out += ".0 °C\n";
|
||||||
|
|
||||||
out += "Adv. Count ";
|
out += "Adv. Count ";
|
||||||
snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U32(m_eddystoneData.advCount));
|
snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U32(m_eddystoneData.advCount));
|
||||||
out += val;
|
out += val;
|
||||||
out += "\n";
|
out += "\n";
|
||||||
|
|
||||||
out += "Time in seconds ";
|
|
||||||
snprintf(val, sizeof(val), "%d", rawsec/10);
|
|
||||||
out += val;
|
|
||||||
out += "\n";
|
|
||||||
|
|
||||||
out += "Time ";
|
out += "Time ";
|
||||||
|
|
||||||
snprintf(val, sizeof(val), "%04d", rawsec / 864000);
|
snprintf(val, sizeof(val), "%04d", rawsec / 864000);
|
||||||
|
@ -194,7 +194,6 @@ BLECharacteristic* BLEHIDDevice::protocolMode() {
|
|||||||
|
|
||||||
void BLEHIDDevice::setBatteryLevel(uint8_t level) {
|
void BLEHIDDevice::setBatteryLevel(uint8_t level) {
|
||||||
m_batteryLevelCharacteristic->setValue(&level, 1);
|
m_batteryLevelCharacteristic->setValue(&level, 1);
|
||||||
m_batteryLevelCharacteristic->notify();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* @brief Returns battery level characteristic
|
* @brief Returns battery level characteristic
|
||||||
|
@ -52,7 +52,6 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
|
|||||||
*/
|
*/
|
||||||
BLERemoteCharacteristic::~BLERemoteCharacteristic() {
|
BLERemoteCharacteristic::~BLERemoteCharacteristic() {
|
||||||
removeDescriptors(); // Release resources for any descriptor information we may have allocated.
|
removeDescriptors(); // Release resources for any descriptor information we may have allocated.
|
||||||
free(m_rawData);
|
|
||||||
} // ~BLERemoteCharacteristic
|
} // ~BLERemoteCharacteristic
|
||||||
|
|
||||||
|
|
||||||
@ -238,18 +237,7 @@ void BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t event,
|
|||||||
break;
|
break;
|
||||||
} // ESP_GATTC_WRITE_CHAR_EVT
|
} // ESP_GATTC_WRITE_CHAR_EVT
|
||||||
|
|
||||||
case ESP_GATTC_READ_DESCR_EVT:
|
|
||||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
|
||||||
for (auto &myPair : m_descriptorMap) {
|
|
||||||
myPair.second->gattClientEventHandler(
|
|
||||||
event, gattc_if, evtParam);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESP_GATTC_DISCONNECT_EVT:
|
|
||||||
m_semaphoreWriteCharEvt.give(1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
} // End switch
|
} // End switch
|
||||||
@ -458,7 +446,7 @@ std::string BLERemoteCharacteristic::readValue() {
|
|||||||
* unregistering a notification.
|
* unregistering a notification.
|
||||||
* @return N/A.
|
* @return N/A.
|
||||||
*/
|
*/
|
||||||
void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications, bool descriptorRequiresRegistration) {
|
void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications) {
|
||||||
log_v(">> registerForNotify(): %s", toString().c_str());
|
log_v(">> registerForNotify(): %s", toString().c_str());
|
||||||
|
|
||||||
m_notifyCallback = notifyCallback; // Save the notification callback.
|
m_notifyCallback = notifyCallback; // Save the notification callback.
|
||||||
@ -479,8 +467,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
|
|||||||
uint8_t val[] = {0x01, 0x00};
|
uint8_t val[] = {0x01, 0x00};
|
||||||
if(!notifications) val[0] = 0x02;
|
if(!notifications) val[0] = 0x02;
|
||||||
BLERemoteDescriptor* desc = getDescriptor(BLEUUID((uint16_t)0x2902));
|
BLERemoteDescriptor* desc = getDescriptor(BLEUUID((uint16_t)0x2902));
|
||||||
if (desc != nullptr && descriptorRequiresRegistration)
|
desc->writeValue(val, 2);
|
||||||
desc->writeValue(val, 2, true);
|
|
||||||
} // End Register
|
} // End Register
|
||||||
else { // If we weren't passed a callback function, then this is an unregistration.
|
else { // If we weren't passed a callback function, then this is an unregistration.
|
||||||
esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify(
|
esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify(
|
||||||
@ -495,8 +482,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
|
|||||||
|
|
||||||
uint8_t val[] = {0x00, 0x00};
|
uint8_t val[] = {0x00, 0x00};
|
||||||
BLERemoteDescriptor* desc = getDescriptor((uint16_t)0x2902);
|
BLERemoteDescriptor* desc = getDescriptor((uint16_t)0x2902);
|
||||||
if (desc != nullptr && descriptorRequiresRegistration)
|
desc->writeValue(val, 2);
|
||||||
desc->writeValue(val, 2, true);
|
|
||||||
} // End Unregister
|
} // End Unregister
|
||||||
|
|
||||||
m_semaphoreRegForNotifyEvt.wait("registerForNotify");
|
m_semaphoreRegForNotifyEvt.wait("registerForNotify");
|
||||||
@ -547,7 +533,7 @@ std::string BLERemoteCharacteristic::toString() {
|
|||||||
* @return N/A.
|
* @return N/A.
|
||||||
*/
|
*/
|
||||||
void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
|
void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
|
||||||
writeValue((uint8_t*)newValue.data(), newValue.length(), response);
|
writeValue((uint8_t*)newValue.c_str(), strlen(newValue.c_str()), response);
|
||||||
} // writeValue
|
} // writeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#if defined(CONFIG_BT_ENABLED)
|
#if defined(CONFIG_BT_ENABLED)
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include <esp_gattc_api.h>
|
#include <esp_gattc_api.h>
|
||||||
|
|
||||||
@ -22,7 +21,8 @@
|
|||||||
|
|
||||||
class BLERemoteService;
|
class BLERemoteService;
|
||||||
class BLERemoteDescriptor;
|
class BLERemoteDescriptor;
|
||||||
typedef std::function<void(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify)> notify_callback;
|
typedef void (*notify_callback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A model of a remote %BLE characteristic.
|
* @brief A model of a remote %BLE characteristic.
|
||||||
*/
|
*/
|
||||||
@ -39,7 +39,6 @@ public:
|
|||||||
bool canWriteNoResponse();
|
bool canWriteNoResponse();
|
||||||
BLERemoteDescriptor* getDescriptor(BLEUUID uuid);
|
BLERemoteDescriptor* getDescriptor(BLEUUID uuid);
|
||||||
std::map<std::string, BLERemoteDescriptor*>* getDescriptors();
|
std::map<std::string, BLERemoteDescriptor*>* getDescriptors();
|
||||||
BLERemoteService* getRemoteService();
|
|
||||||
uint16_t getHandle();
|
uint16_t getHandle();
|
||||||
BLEUUID getUUID();
|
BLEUUID getUUID();
|
||||||
std::string readValue();
|
std::string readValue();
|
||||||
@ -47,7 +46,7 @@ public:
|
|||||||
uint16_t readUInt16();
|
uint16_t readUInt16();
|
||||||
uint32_t readUInt32();
|
uint32_t readUInt32();
|
||||||
float readFloat();
|
float readFloat();
|
||||||
void registerForNotify(notify_callback _callback, bool notifications = true, bool descriptorRequiresRegistration = true);
|
void registerForNotify(notify_callback _callback, bool notifications = true);
|
||||||
void writeValue(uint8_t* data, size_t length, bool response = false);
|
void writeValue(uint8_t* data, size_t length, bool response = false);
|
||||||
void writeValue(std::string newValue, bool response = false);
|
void writeValue(std::string newValue, bool response = false);
|
||||||
void writeValue(uint8_t newValue, bool response = false);
|
void writeValue(uint8_t newValue, bool response = false);
|
||||||
@ -64,6 +63,7 @@ private:
|
|||||||
// Private member functions
|
// Private member functions
|
||||||
void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam);
|
void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam);
|
||||||
|
|
||||||
|
BLERemoteService* getRemoteService();
|
||||||
void removeDescriptors();
|
void removeDescriptors();
|
||||||
void retrieveDescriptors();
|
void retrieveDescriptors();
|
||||||
|
|
||||||
|
@ -49,23 +49,6 @@ BLEUUID BLERemoteDescriptor::getUUID() {
|
|||||||
return m_uuid;
|
return m_uuid;
|
||||||
} // getUUID
|
} // getUUID
|
||||||
|
|
||||||
void BLERemoteDescriptor::gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) {
|
|
||||||
switch(event) {
|
|
||||||
case ESP_GATTC_READ_DESCR_EVT:
|
|
||||||
if (evtParam->read.handle != getHandle())
|
|
||||||
break;
|
|
||||||
m_semaphoreReadDescrEvt.give();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
|
||||||
if (evtParam->write.handle != getHandle())
|
|
||||||
break;
|
|
||||||
m_semaphoreWriteDescrEvt.give();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BLERemoteDescriptor::readValue() {
|
std::string BLERemoteDescriptor::readValue() {
|
||||||
log_v(">> readValue: %s", toString().c_str());
|
log_v(">> readValue: %s", toString().c_str());
|
||||||
@ -154,8 +137,6 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_semaphoreWriteDescrEvt.take("writeValue");
|
|
||||||
|
|
||||||
esp_err_t errRc = ::esp_ble_gattc_write_char_descr(
|
esp_err_t errRc = ::esp_ble_gattc_write_char_descr(
|
||||||
m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(),
|
m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(),
|
||||||
m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(),
|
m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(),
|
||||||
@ -168,8 +149,6 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response
|
|||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
|
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_semaphoreWriteDescrEvt.wait("writeValue");
|
|
||||||
log_v("<< writeValue");
|
log_v("<< writeValue");
|
||||||
} // writeValue
|
} // writeValue
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
void writeValue(std::string newValue, bool response = false);
|
void writeValue(std::string newValue, bool response = false);
|
||||||
void writeValue(uint8_t newValue, bool response = false);
|
void writeValue(uint8_t newValue, bool response = false);
|
||||||
void setAuth(esp_gatt_auth_req_t auth);
|
void setAuth(esp_gatt_auth_req_t auth);
|
||||||
void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class BLERemoteCharacteristic;
|
friend class BLERemoteCharacteristic;
|
||||||
@ -49,7 +49,6 @@ private:
|
|||||||
std::string m_value; // Last received value of the descriptor.
|
std::string m_value; // Last received value of the descriptor.
|
||||||
BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated.
|
BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated.
|
||||||
FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt");
|
FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt");
|
||||||
FreeRTOS::Semaphore m_semaphoreWriteDescrEvt = FreeRTOS::Semaphore("WriteDescrEvt");
|
|
||||||
esp_gatt_auth_req_t m_auth;
|
esp_gatt_auth_req_t m_auth;
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,17 +243,8 @@ std::map<uint16_t, BLERemoteCharacteristic*>* BLERemoteService::getCharacteristi
|
|||||||
/**
|
/**
|
||||||
* @brief This function is designed to get characteristics map when we have multiple characteristics with the same UUID
|
* @brief This function is designed to get characteristics map when we have multiple characteristics with the same UUID
|
||||||
*/
|
*/
|
||||||
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap) {
|
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>** pCharacteristicMap) {
|
||||||
log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str());
|
*pCharacteristicMap = &m_characteristicMapByHandle;
|
||||||
(void)pCharacteristicMap;
|
|
||||||
// If is possible that we have not read the characteristics associated with the service so do that
|
|
||||||
// now. The request to retrieve the characteristics by calling "retrieveCharacteristics" is a blocking
|
|
||||||
// call and does not return until all the characteristics are available.
|
|
||||||
if (!m_haveCharacteristics) {
|
|
||||||
retrieveCharacteristics();
|
|
||||||
}
|
|
||||||
log_v("<< getCharacteristics() for service: %s", getUUID().toString().c_str());
|
|
||||||
*pCharacteristicMap = m_characteristicMapByHandle;
|
|
||||||
} // Get the characteristics map.
|
} // Get the characteristics map.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,10 +302,13 @@ std::string BLERemoteService::getValue(BLEUUID characteristicUuid) {
|
|||||||
* @return N/A.
|
* @return N/A.
|
||||||
*/
|
*/
|
||||||
void BLERemoteService::removeCharacteristics() {
|
void BLERemoteService::removeCharacteristics() {
|
||||||
|
for (auto &myPair : m_characteristicMap) {
|
||||||
|
delete myPair.second;
|
||||||
|
//m_characteristicMap.erase(myPair.first); // Should be no need to delete as it will be deleted by the clear
|
||||||
|
}
|
||||||
m_characteristicMap.clear(); // Clear the map
|
m_characteristicMap.clear(); // Clear the map
|
||||||
for (auto &myPair : m_characteristicMapByHandle) {
|
for (auto &myPair : m_characteristicMapByHandle) {
|
||||||
delete myPair.second;
|
delete myPair.second;
|
||||||
// delete the characteristics only once
|
|
||||||
}
|
}
|
||||||
m_characteristicMapByHandle.clear(); // Clear the map
|
m_characteristicMapByHandle.clear(); // Clear the map
|
||||||
} // removeCharacteristics
|
} // removeCharacteristics
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference.
|
BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference.
|
||||||
std::map<std::string, BLERemoteCharacteristic*>* getCharacteristics();
|
std::map<std::string, BLERemoteCharacteristic*>* getCharacteristics();
|
||||||
std::map<uint16_t, BLERemoteCharacteristic*>* getCharacteristicsByHandle(); // Get the characteristics map.
|
std::map<uint16_t, BLERemoteCharacteristic*>* getCharacteristicsByHandle(); // Get the characteristics map.
|
||||||
void getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap);
|
void getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>** pCharacteristicMap);
|
||||||
|
|
||||||
BLEClient* getClient(void); // Get a reference to the client associated with this service.
|
BLEClient* getClient(void); // Get a reference to the client associated with this service.
|
||||||
uint16_t getHandle(); // Get the handle of this service.
|
uint16_t getHandle(); // Get the handle of this service.
|
||||||
|
@ -22,15 +22,12 @@
|
|||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
BLEScan::BLEScan() {
|
BLEScan::BLEScan() {
|
||||||
memset(&m_scan_params, 0, sizeof(m_scan_params)); // Initialize all params
|
|
||||||
m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; // Default is a passive scan.
|
m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; // Default is a passive scan.
|
||||||
m_scan_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
m_scan_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||||
m_scan_params.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL;
|
m_scan_params.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL;
|
||||||
m_scan_params.scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE;
|
|
||||||
m_pAdvertisedDeviceCallbacks = nullptr;
|
m_pAdvertisedDeviceCallbacks = nullptr;
|
||||||
m_stopped = true;
|
m_stopped = true;
|
||||||
m_wantDuplicates = false;
|
m_wantDuplicates = false;
|
||||||
m_shouldParse = true;
|
|
||||||
setInterval(100);
|
setInterval(100);
|
||||||
setWindow(100);
|
setWindow(100);
|
||||||
} // BLEScan
|
} // BLEScan
|
||||||
@ -91,18 +88,15 @@ void BLEScan::handleGAPEvent(
|
|||||||
// ignore it.
|
// ignore it.
|
||||||
BLEAddress advertisedAddress(param->scan_rst.bda);
|
BLEAddress advertisedAddress(param->scan_rst.bda);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
bool shouldDelete = true;
|
|
||||||
|
|
||||||
if (!m_wantDuplicates) {
|
if (m_scanResults.m_vectorAdvertisedDevices.count(advertisedAddress.toString()) != 0) {
|
||||||
if (m_scanResults.m_vectorAdvertisedDevices.count(advertisedAddress.toString()) != 0) {
|
found = true;
|
||||||
found = true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (found) { // If we found a previous entry AND we don't want duplicates, then we are done.
|
if (found && !m_wantDuplicates) { // If we found a previous entry AND we don't want duplicates, then we are done.
|
||||||
log_d("Ignoring %s, already seen it.", advertisedAddress.toString().c_str());
|
log_d("Ignoring %s, already seen it.", advertisedAddress.toString().c_str());
|
||||||
vTaskDelay(1); // <--- allow to switch task in case we scan infinity and dont have new devices to report, or we are blocked here
|
vTaskDelay(1); // <--- allow to switch task in case we scan infinity and dont have new devices to report, or we are blocked here
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We now construct a model of the advertised device that we have just found for the first
|
// We now construct a model of the advertised device that we have just found for the first
|
||||||
@ -113,23 +107,19 @@ void BLEScan::handleGAPEvent(
|
|||||||
advertisedDevice->setAddress(advertisedAddress);
|
advertisedDevice->setAddress(advertisedAddress);
|
||||||
advertisedDevice->setRSSI(param->scan_rst.rssi);
|
advertisedDevice->setRSSI(param->scan_rst.rssi);
|
||||||
advertisedDevice->setAdFlag(param->scan_rst.flag);
|
advertisedDevice->setAdFlag(param->scan_rst.flag);
|
||||||
if (m_shouldParse) {
|
advertisedDevice->parseAdvertisement((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len);
|
||||||
advertisedDevice->parseAdvertisement((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len);
|
|
||||||
} else {
|
|
||||||
advertisedDevice->setPayload((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len);
|
|
||||||
}
|
|
||||||
advertisedDevice->setScan(this);
|
advertisedDevice->setScan(this);
|
||||||
advertisedDevice->setAddressType(param->scan_rst.ble_addr_type);
|
advertisedDevice->setAddressType(param->scan_rst.ble_addr_type);
|
||||||
|
|
||||||
if (m_pAdvertisedDeviceCallbacks) { // if has callback, no need to record to vector
|
if (!found) { // If we have previously seen this device, don't record it again.
|
||||||
m_pAdvertisedDeviceCallbacks->onResult(*advertisedDevice);
|
|
||||||
} else if (!m_wantDuplicates && !found) { // if no callback and not want duplicate, and not already in vector, record it
|
|
||||||
m_scanResults.m_vectorAdvertisedDevices.insert(std::pair<std::string, BLEAdvertisedDevice*>(advertisedAddress.toString(), advertisedDevice));
|
m_scanResults.m_vectorAdvertisedDevices.insert(std::pair<std::string, BLEAdvertisedDevice*>(advertisedAddress.toString(), advertisedDevice));
|
||||||
shouldDelete = false;
|
|
||||||
}
|
}
|
||||||
if (shouldDelete) {
|
|
||||||
|
if (m_pAdvertisedDeviceCallbacks) {
|
||||||
|
m_pAdvertisedDeviceCallbacks->onResult(*advertisedDevice);
|
||||||
|
}
|
||||||
|
if(found)
|
||||||
delete advertisedDevice;
|
delete advertisedDevice;
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} // ESP_GAP_SEARCH_INQ_RES_EVT
|
} // ESP_GAP_SEARCH_INQ_RES_EVT
|
||||||
@ -169,14 +159,13 @@ void BLEScan::setActiveScan(bool active) {
|
|||||||
* @brief Set the call backs to be invoked.
|
* @brief Set the call backs to be invoked.
|
||||||
* @param [in] pAdvertisedDeviceCallbacks Call backs to be invoked.
|
* @param [in] pAdvertisedDeviceCallbacks Call backs to be invoked.
|
||||||
* @param [in] wantDuplicates True if we wish to be called back with duplicates. Default is false.
|
* @param [in] wantDuplicates True if we wish to be called back with duplicates. Default is false.
|
||||||
* @param [in] shouldParse True if we wish to parse advertised package or raw payload. Default is true.
|
|
||||||
*/
|
*/
|
||||||
void BLEScan::setAdvertisedDeviceCallbacks(BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, bool wantDuplicates, bool shouldParse) {
|
void BLEScan::setAdvertisedDeviceCallbacks(BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, bool wantDuplicates) {
|
||||||
m_wantDuplicates = wantDuplicates;
|
m_wantDuplicates = wantDuplicates;
|
||||||
m_pAdvertisedDeviceCallbacks = pAdvertisedDeviceCallbacks;
|
m_pAdvertisedDeviceCallbacks = pAdvertisedDeviceCallbacks;
|
||||||
m_shouldParse = shouldParse;
|
|
||||||
} // setAdvertisedDeviceCallbacks
|
} // setAdvertisedDeviceCallbacks
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the interval to scan.
|
* @brief Set the interval to scan.
|
||||||
* @param [in] The interval in msecs.
|
* @param [in] The interval in msecs.
|
||||||
|
@ -51,8 +51,7 @@ public:
|
|||||||
void setActiveScan(bool active);
|
void setActiveScan(bool active);
|
||||||
void setAdvertisedDeviceCallbacks(
|
void setAdvertisedDeviceCallbacks(
|
||||||
BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks,
|
BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks,
|
||||||
bool wantDuplicates = false,
|
bool wantDuplicates = false);
|
||||||
bool shouldParse = true);
|
|
||||||
void setInterval(uint16_t intervalMSecs);
|
void setInterval(uint16_t intervalMSecs);
|
||||||
void setWindow(uint16_t windowMSecs);
|
void setWindow(uint16_t windowMSecs);
|
||||||
bool start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false);
|
bool start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false);
|
||||||
@ -74,7 +73,6 @@ private:
|
|||||||
esp_ble_scan_params_t m_scan_params;
|
esp_ble_scan_params_t m_scan_params;
|
||||||
BLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr;
|
BLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr;
|
||||||
bool m_stopped = true;
|
bool m_stopped = true;
|
||||||
bool m_shouldParse = true;
|
|
||||||
FreeRTOS::Semaphore m_semaphoreScanEnd = FreeRTOS::Semaphore("ScanEnd");
|
FreeRTOS::Semaphore m_semaphoreScanEnd = FreeRTOS::Semaphore("ScanEnd");
|
||||||
BLEScanResults m_scanResults;
|
BLEScanResults m_scanResults;
|
||||||
bool m_wantDuplicates;
|
bool m_wantDuplicates;
|
||||||
|
@ -61,17 +61,6 @@ void BLESecurity::setKeySize(uint8_t key_size) {
|
|||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t));
|
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t));
|
||||||
} //setKeySize
|
} //setKeySize
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup for static PIN connection, call it first and then call setAuthenticationMode eventually to change it
|
|
||||||
*/
|
|
||||||
void BLESecurity::setStaticPIN(uint32_t pin){
|
|
||||||
uint32_t passkey = pin;
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
|
|
||||||
setCapability(ESP_IO_CAP_OUT);
|
|
||||||
setKeySize();
|
|
||||||
setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY);
|
|
||||||
setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Debug function to display what keys are exchanged by peers
|
* @brief Debug function to display what keys are exchanged by peers
|
||||||
|
@ -21,7 +21,6 @@ public:
|
|||||||
void setInitEncryptionKey(uint8_t init_key);
|
void setInitEncryptionKey(uint8_t init_key);
|
||||||
void setRespEncryptionKey(uint8_t resp_key);
|
void setRespEncryptionKey(uint8_t resp_key);
|
||||||
void setKeySize(uint8_t key_size = 16);
|
void setKeySize(uint8_t key_size = 16);
|
||||||
void setStaticPIN(uint32_t pin);
|
|
||||||
static char* esp_key_type_to_str(esp_ble_key_type_t key_type);
|
static char* esp_key_type_to_str(esp_ble_key_type_t key_type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -202,19 +202,13 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
|
|||||||
// If we receive a disconnect event then invoke the callback for disconnects (if one is present).
|
// If we receive a disconnect event then invoke the callback for disconnects (if one is present).
|
||||||
// we also want to start advertising again.
|
// we also want to start advertising again.
|
||||||
case ESP_GATTS_DISCONNECT_EVT: {
|
case ESP_GATTS_DISCONNECT_EVT: {
|
||||||
|
m_connectedCount--; // Decrement the number of connected devices count.
|
||||||
if (m_pServerCallbacks != nullptr) { // If we have callbacks, call now.
|
if (m_pServerCallbacks != nullptr) { // If we have callbacks, call now.
|
||||||
m_pServerCallbacks->onDisconnect(this);
|
m_pServerCallbacks->onDisconnect(this);
|
||||||
}
|
}
|
||||||
if(m_connId == ESP_GATT_IF_NONE) {
|
startAdvertising(); //- do this with some delay from the loop()
|
||||||
return;
|
removePeerDevice(param->disconnect.conn_id, false);
|
||||||
}
|
break;
|
||||||
|
|
||||||
// only decrement if connection is found in map and removed
|
|
||||||
// sometimes this event triggers w/o a valid connection
|
|
||||||
if(removePeerDevice(param->disconnect.conn_id, false)) {
|
|
||||||
m_connectedCount--; // Decrement the number of connected devices count.
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} // ESP_GATTS_DISCONNECT_EVT
|
} // ESP_GATTS_DISCONNECT_EVT
|
||||||
|
|
||||||
|
|
||||||
@ -401,8 +395,8 @@ void BLEServer::addPeerDevice(void* peer, bool _client, uint16_t conn_id) {
|
|||||||
m_connectedServersMap.insert(std::pair<uint16_t, conn_status_t>(conn_id, status));
|
m_connectedServersMap.insert(std::pair<uint16_t, conn_status_t>(conn_id, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BLEServer::removePeerDevice(uint16_t conn_id, bool _client) {
|
void BLEServer::removePeerDevice(uint16_t conn_id, bool _client) {
|
||||||
return m_connectedServersMap.erase(conn_id) > 0;
|
m_connectedServersMap.erase(conn_id);
|
||||||
}
|
}
|
||||||
/* multi connect support */
|
/* multi connect support */
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public:
|
|||||||
/* multi connection support */
|
/* multi connection support */
|
||||||
std::map<uint16_t, conn_status_t> getPeerDevices(bool client);
|
std::map<uint16_t, conn_status_t> getPeerDevices(bool client);
|
||||||
void addPeerDevice(void* peer, bool is_client, uint16_t conn_id);
|
void addPeerDevice(void* peer, bool is_client, uint16_t conn_id);
|
||||||
bool removePeerDevice(uint16_t conn_id, bool client);
|
void removePeerDevice(uint16_t conn_id, bool client);
|
||||||
BLEServer* getServerByConnId(uint16_t conn_id);
|
BLEServer* getServerByConnId(uint16_t conn_id);
|
||||||
void updatePeerMTU(uint16_t connId, uint16_t mtu);
|
void updatePeerMTU(uint16_t connId, uint16_t mtu);
|
||||||
uint16_t getPeerMTU(uint16_t conn_id);
|
uint16_t getPeerMTU(uint16_t conn_id);
|
||||||
|
@ -193,8 +193,8 @@ bool FreeRTOS::Semaphore::take(std::string owner) {
|
|||||||
} else {
|
} else {
|
||||||
rc = ::xSemaphoreTake(m_semaphore, portMAX_DELAY) == pdTRUE;
|
rc = ::xSemaphoreTake(m_semaphore, portMAX_DELAY) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
m_owner = owner;
|
||||||
if (rc) {
|
if (rc) {
|
||||||
m_owner = owner;
|
|
||||||
log_v("Semaphore taken: %s", toString().c_str());
|
log_v("Semaphore taken: %s", toString().c_str());
|
||||||
} else {
|
} else {
|
||||||
log_e("Semaphore NOT taken: %s", toString().c_str());
|
log_e("Semaphore NOT taken: %s", toString().c_str());
|
||||||
@ -218,8 +218,8 @@ bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, std::string owner) {
|
|||||||
} else {
|
} else {
|
||||||
rc = ::xSemaphoreTake(m_semaphore, timeoutMs / portTICK_PERIOD_MS) == pdTRUE;
|
rc = ::xSemaphoreTake(m_semaphore, timeoutMs / portTICK_PERIOD_MS) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
m_owner = owner;
|
||||||
if (rc) {
|
if (rc) {
|
||||||
m_owner = owner;
|
|
||||||
log_v("Semaphore taken: %s", toString().c_str());
|
log_v("Semaphore taken: %s", toString().c_str());
|
||||||
} else {
|
} else {
|
||||||
log_e("Semaphore NOT taken: %s", toString().c_str());
|
log_e("Semaphore NOT taken: %s", toString().c_str());
|
||||||
@ -257,7 +257,12 @@ void FreeRTOS::Semaphore::setName(std::string name) {
|
|||||||
* @param [in] length The amount of storage to allocate for the ring buffer.
|
* @param [in] length The amount of storage to allocate for the ring buffer.
|
||||||
* @param [in] type The type of buffer. One of RINGBUF_TYPE_NOSPLIT, RINGBUF_TYPE_ALLOWSPLIT, RINGBUF_TYPE_BYTEBUF.
|
* @param [in] type The type of buffer. One of RINGBUF_TYPE_NOSPLIT, RINGBUF_TYPE_ALLOWSPLIT, RINGBUF_TYPE_BYTEBUF.
|
||||||
*/
|
*/
|
||||||
Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) {
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type)
|
||||||
|
#else
|
||||||
|
Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
m_handle = ::xRingbufferCreate(length, type);
|
m_handle = ::xRingbufferCreate(length, type);
|
||||||
} // Ringbuffer
|
} // Ringbuffer
|
||||||
|
|
||||||
|
@ -60,7 +60,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
class Ringbuffer {
|
class Ringbuffer {
|
||||||
public:
|
public:
|
||||||
Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
Ringbuffer(size_t length, RingbufferType_t type = RINGBUF_TYPE_NOSPLIT);
|
||||||
|
#else
|
||||||
|
Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
|
||||||
|
#endif
|
||||||
~Ringbuffer();
|
~Ringbuffer();
|
||||||
|
|
||||||
void* receive(size_t* size, TickType_t wait = portMAX_DELAY);
|
void* receive(size_t* size, TickType_t wait = portMAX_DELAY);
|
||||||
|
@ -14,7 +14,7 @@ String MACadd = "AA:BB:CC:11:22:33";
|
|||||||
uint8_t address[6] = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33};
|
uint8_t address[6] = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33};
|
||||||
//uint8_t address[6] = {0x00, 0x1D, 0xA5, 0x02, 0xC3, 0x22};
|
//uint8_t address[6] = {0x00, 0x1D, 0xA5, 0x02, 0xC3, 0x22};
|
||||||
String name = "OBDII";
|
String name = "OBDII";
|
||||||
char *pin = "1234"; //<- standard pin would be provided by default
|
const char *pin = "1234"; //<- standard pin would be provided by default
|
||||||
bool connected;
|
bool connected;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
//This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
||||||
//By Richard Li - 2020
|
|
||||||
//
|
|
||||||
//This example creates a bridge between Serial and Classical Bluetooth (SPP with authentication)
|
|
||||||
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
|
|
||||||
|
|
||||||
#include "BluetoothSerial.h"
|
|
||||||
|
|
||||||
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
|
||||||
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BluetoothSerial SerialBT;
|
|
||||||
boolean confirmRequestPending = true;
|
|
||||||
|
|
||||||
void BTConfirmRequestCallback(uint32_t numVal)
|
|
||||||
{
|
|
||||||
confirmRequestPending = true;
|
|
||||||
Serial.println(numVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BTAuthCompleteCallback(boolean success)
|
|
||||||
{
|
|
||||||
confirmRequestPending = false;
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
Serial.println("Pairing success!!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Serial.println("Pairing failed, rejected by user!!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
|
||||||
SerialBT.enableSSP();
|
|
||||||
SerialBT.onConfirmRequest(BTConfirmRequestCallback);
|
|
||||||
SerialBT.onAuthComplete(BTAuthCompleteCallback);
|
|
||||||
SerialBT.begin("ESP32test"); //Bluetooth device name
|
|
||||||
Serial.println("The device started, now you can pair it with bluetooth!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
if (confirmRequestPending)
|
|
||||||
{
|
|
||||||
if (Serial.available())
|
|
||||||
{
|
|
||||||
int dat = Serial.read();
|
|
||||||
if (dat == 'Y' || dat == 'y')
|
|
||||||
{
|
|
||||||
SerialBT.confirmReply(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SerialBT.confirmReply(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Serial.available())
|
|
||||||
{
|
|
||||||
SerialBT.write(Serial.read());
|
|
||||||
}
|
|
||||||
if (SerialBT.available())
|
|
||||||
{
|
|
||||||
Serial.write(SerialBT.read());
|
|
||||||
}
|
|
||||||
delay(20);
|
|
||||||
}
|
|
||||||
}
|
|
@ -42,10 +42,6 @@ const char * _spp_server_name = "ESP32SPP";
|
|||||||
|
|
||||||
#define RX_QUEUE_SIZE 512
|
#define RX_QUEUE_SIZE 512
|
||||||
#define TX_QUEUE_SIZE 32
|
#define TX_QUEUE_SIZE 32
|
||||||
#define SPP_TX_QUEUE_TIMEOUT 1000
|
|
||||||
#define SPP_TX_DONE_TIMEOUT 1000
|
|
||||||
#define SPP_CONGESTED_TIMEOUT 1000
|
|
||||||
|
|
||||||
static uint32_t _spp_client = 0;
|
static uint32_t _spp_client = 0;
|
||||||
static xQueueHandle _spp_rx_queue = NULL;
|
static xQueueHandle _spp_rx_queue = NULL;
|
||||||
static xQueueHandle _spp_tx_queue = NULL;
|
static xQueueHandle _spp_tx_queue = NULL;
|
||||||
@ -55,9 +51,6 @@ static EventGroupHandle_t _spp_event_group = NULL;
|
|||||||
static boolean secondConnectionAttempt;
|
static boolean secondConnectionAttempt;
|
||||||
static esp_spp_cb_t * custom_spp_callback = NULL;
|
static esp_spp_cb_t * custom_spp_callback = NULL;
|
||||||
static BluetoothSerialDataCb custom_data_callback = NULL;
|
static BluetoothSerialDataCb custom_data_callback = NULL;
|
||||||
static esp_bd_addr_t current_bd_addr;
|
|
||||||
static ConfirmRequestCb confirm_request_callback = NULL;
|
|
||||||
static AuthCompleteCb auth_complete_callback = NULL;
|
|
||||||
|
|
||||||
#define INQ_LEN 0x10
|
#define INQ_LEN 0x10
|
||||||
#define INQ_NUM_RSPS 20
|
#define INQ_NUM_RSPS 20
|
||||||
@ -147,7 +140,7 @@ static esp_err_t _spp_queue_packet(uint8_t *data, size_t len){
|
|||||||
}
|
}
|
||||||
packet->len = len;
|
packet->len = len;
|
||||||
memcpy(packet->data, data, len);
|
memcpy(packet->data, data, len);
|
||||||
if (!_spp_tx_queue || xQueueSend(_spp_tx_queue, &packet, SPP_TX_QUEUE_TIMEOUT) != pdPASS) {
|
if (xQueueSend(_spp_tx_queue, &packet, portMAX_DELAY) != pdPASS) {
|
||||||
log_e("SPP TX Queue Send Failed!");
|
log_e("SPP TX Queue Send Failed!");
|
||||||
free(packet);
|
free(packet);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
@ -160,25 +153,19 @@ static uint8_t _spp_tx_buffer[SPP_TX_MAX];
|
|||||||
static uint16_t _spp_tx_buffer_len = 0;
|
static uint16_t _spp_tx_buffer_len = 0;
|
||||||
|
|
||||||
static bool _spp_send_buffer(){
|
static bool _spp_send_buffer(){
|
||||||
if((xEventGroupWaitBits(_spp_event_group, SPP_CONGESTED, pdFALSE, pdTRUE, SPP_CONGESTED_TIMEOUT) & SPP_CONGESTED) != 0){
|
if((xEventGroupWaitBits(_spp_event_group, SPP_CONGESTED, pdFALSE, pdTRUE, portMAX_DELAY) & SPP_CONGESTED) != 0){
|
||||||
if(!_spp_client){
|
|
||||||
log_v("SPP Client Gone!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
log_v("SPP Write %u", _spp_tx_buffer_len);
|
|
||||||
esp_err_t err = esp_spp_write(_spp_client, _spp_tx_buffer_len, _spp_tx_buffer);
|
esp_err_t err = esp_spp_write(_spp_client, _spp_tx_buffer_len, _spp_tx_buffer);
|
||||||
if(err != ESP_OK){
|
if(err != ESP_OK){
|
||||||
log_e("SPP Write Failed! [0x%X]", err);
|
log_e("SPP Write Failed! [0x%X]", err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_spp_tx_buffer_len = 0;
|
_spp_tx_buffer_len = 0;
|
||||||
if(xSemaphoreTake(_spp_tx_done, SPP_TX_DONE_TIMEOUT) != pdTRUE){
|
if(xSemaphoreTake(_spp_tx_done, portMAX_DELAY) != pdTRUE){
|
||||||
log_e("SPP Ack Failed!");
|
log_e("SPP Ack Failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log_e("SPP Write Congested!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,18 +191,13 @@ static void _spp_tx_task(void * arg){
|
|||||||
_spp_tx_buffer_len = SPP_TX_MAX;
|
_spp_tx_buffer_len = SPP_TX_MAX;
|
||||||
data += to_send;
|
data += to_send;
|
||||||
len -= to_send;
|
len -= to_send;
|
||||||
if(!_spp_send_buffer()){
|
_spp_send_buffer();
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
while(len >= SPP_TX_MAX){
|
while(len >= SPP_TX_MAX){
|
||||||
memcpy(_spp_tx_buffer, data, SPP_TX_MAX);
|
memcpy(_spp_tx_buffer, data, SPP_TX_MAX);
|
||||||
_spp_tx_buffer_len = SPP_TX_MAX;
|
_spp_tx_buffer_len = SPP_TX_MAX;
|
||||||
data += SPP_TX_MAX;
|
data += SPP_TX_MAX;
|
||||||
len -= SPP_TX_MAX;
|
len -= SPP_TX_MAX;
|
||||||
if(!_spp_send_buffer()){
|
_spp_send_buffer();
|
||||||
len = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(len){
|
if(len){
|
||||||
memcpy(_spp_tx_buffer, data, len);
|
memcpy(_spp_tx_buffer, data, len);
|
||||||
@ -241,7 +223,11 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
{
|
{
|
||||||
case ESP_SPP_INIT_EVT:
|
case ESP_SPP_INIT_EVT:
|
||||||
log_i("ESP_SPP_INIT_EVT");
|
log_i("ESP_SPP_INIT_EVT");
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
#else
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||||
|
#endif
|
||||||
if (!_isMaster) {
|
if (!_isMaster) {
|
||||||
log_i("ESP_SPP_INIT_EVT: slave: start");
|
log_i("ESP_SPP_INIT_EVT: slave: start");
|
||||||
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
|
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
|
||||||
@ -250,36 +236,26 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_SPP_SRV_OPEN_EVT://Server connection open
|
case ESP_SPP_SRV_OPEN_EVT://Server connection open
|
||||||
if (param->srv_open.status == ESP_SPP_SUCCESS) {
|
log_i("ESP_SPP_SRV_OPEN_EVT");
|
||||||
log_i("ESP_SPP_SRV_OPEN_EVT: %u", _spp_client);
|
if (!_spp_client){
|
||||||
if (!_spp_client){
|
_spp_client = param->open.handle;
|
||||||
_spp_client = param->srv_open.handle;
|
|
||||||
_spp_tx_buffer_len = 0;
|
|
||||||
} else {
|
|
||||||
secondConnectionAttempt = true;
|
|
||||||
esp_spp_disconnect(param->srv_open.handle);
|
|
||||||
}
|
|
||||||
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
|
|
||||||
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
|
|
||||||
} else {
|
} else {
|
||||||
log_e("ESP_SPP_SRV_OPEN_EVT Failed!, status:%d", param->srv_open.status);
|
secondConnectionAttempt = true;
|
||||||
|
esp_spp_disconnect(param->open.handle);
|
||||||
}
|
}
|
||||||
|
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
|
||||||
|
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_SPP_CLOSE_EVT://Client connection closed
|
case ESP_SPP_CLOSE_EVT://Client connection closed
|
||||||
if ((param->close.async == false && param->close.status == ESP_SPP_SUCCESS) || param->close.async) {
|
log_i("ESP_SPP_CLOSE_EVT");
|
||||||
log_i("ESP_SPP_CLOSE_EVT: %u", secondConnectionAttempt);
|
if(secondConnectionAttempt) {
|
||||||
if(secondConnectionAttempt) {
|
secondConnectionAttempt = false;
|
||||||
secondConnectionAttempt = false;
|
|
||||||
} else {
|
|
||||||
_spp_client = 0;
|
|
||||||
xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED);
|
|
||||||
xEventGroupSetBits(_spp_event_group, SPP_CONGESTED);
|
|
||||||
}
|
|
||||||
xEventGroupClearBits(_spp_event_group, SPP_CONNECTED);
|
|
||||||
} else {
|
} else {
|
||||||
log_e("ESP_SPP_CLOSE_EVT failed!, status:%d", param->close.status);
|
_spp_client = 0;
|
||||||
}
|
xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED);
|
||||||
|
}
|
||||||
|
xEventGroupClearBits(_spp_event_group, SPP_CONNECTED);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_SPP_CONG_EVT://connection congestion status changed
|
case ESP_SPP_CONG_EVT://connection congestion status changed
|
||||||
@ -292,15 +268,11 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_SPP_WRITE_EVT://write operation completed
|
case ESP_SPP_WRITE_EVT://write operation completed
|
||||||
if (param->write.status == ESP_SPP_SUCCESS) {
|
if(param->write.cong){
|
||||||
if(param->write.cong){
|
xEventGroupClearBits(_spp_event_group, SPP_CONGESTED);
|
||||||
xEventGroupClearBits(_spp_event_group, SPP_CONGESTED);
|
|
||||||
}
|
|
||||||
log_v("ESP_SPP_WRITE_EVT: %u %s", param->write.len, param->write.cong?"CONGESTED":"");
|
|
||||||
} else {
|
|
||||||
log_e("ESP_SPP_WRITE_EVT failed!, status:%d", param->write.status);
|
|
||||||
}
|
}
|
||||||
xSemaphoreGive(_spp_tx_done);//we can try to send another packet
|
xSemaphoreGive(_spp_tx_done);//we can try to send another packet
|
||||||
|
log_v("ESP_SPP_WRITE_EVT: %u %s", param->write.len, param->write.cong?"CONGESTED":"FREE");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_SPP_DATA_IND_EVT://connection received data
|
case ESP_SPP_DATA_IND_EVT://connection received data
|
||||||
@ -325,8 +297,6 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
if (param->disc_comp.status == ESP_SPP_SUCCESS) {
|
if (param->disc_comp.status == ESP_SPP_SUCCESS) {
|
||||||
log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote");
|
log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote");
|
||||||
esp_spp_connect(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp.scn[0], _peer_bd_addr);
|
esp_spp_connect(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp.scn[0], _peer_bd_addr);
|
||||||
} else {
|
|
||||||
log_e("ESP_SPP_DISCOVERY_COMP_EVT failed!, status:%d", param->disc_comp.status);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -340,7 +310,6 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
}
|
}
|
||||||
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
|
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
|
||||||
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
|
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
|
||||||
xEventGroupSetBits(_spp_event_group, SPP_CONGESTED);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_SPP_START_EVT://server started
|
case ESP_SPP_START_EVT://server started
|
||||||
@ -433,14 +402,8 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
|
|||||||
case ESP_BT_GAP_AUTH_CMPL_EVT:
|
case ESP_BT_GAP_AUTH_CMPL_EVT:
|
||||||
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
|
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
|
||||||
log_v("authentication success: %s", param->auth_cmpl.device_name);
|
log_v("authentication success: %s", param->auth_cmpl.device_name);
|
||||||
if (auth_complete_callback) {
|
|
||||||
auth_complete_callback(true);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log_e("authentication failed, status:%d", param->auth_cmpl.stat);
|
log_e("authentication failed, status:%d", param->auth_cmpl.stat);
|
||||||
if (auth_complete_callback) {
|
|
||||||
auth_complete_callback(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -462,13 +425,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
|
|||||||
|
|
||||||
case ESP_BT_GAP_CFM_REQ_EVT:
|
case ESP_BT_GAP_CFM_REQ_EVT:
|
||||||
log_i("ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
|
log_i("ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
|
||||||
if (confirm_request_callback) {
|
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
|
||||||
memcpy(current_bd_addr, param->cfm_req.bda, sizeof(esp_bd_addr_t));
|
|
||||||
confirm_request_callback(param->cfm_req.num_val);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_BT_GAP_KEY_NOTIF_EVT:
|
case ESP_BT_GAP_KEY_NOTIF_EVT:
|
||||||
@ -547,9 +504,7 @@ static bool _init_bt(const char *deviceName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why only master need this? Slave need this during pairing as well
|
if (_isMaster && esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
|
||||||
// if (_isMaster && esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
|
|
||||||
if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
|
|
||||||
log_e("gap register failed");
|
log_e("gap register failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -564,9 +519,9 @@ static bool _init_bt(const char *deviceName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (esp_bt_sleep_disable() != ESP_OK){
|
if (esp_bt_sleep_disable() != ESP_OK){
|
||||||
// log_e("esp_bt_sleep_disable failed");
|
log_e("esp_bt_sleep_disable failed");
|
||||||
// }
|
}
|
||||||
|
|
||||||
log_i("device name set");
|
log_i("device name set");
|
||||||
esp_bt_dev_set_device_name(deviceName);
|
esp_bt_dev_set_device_name(deviceName);
|
||||||
@ -711,7 +666,7 @@ void BluetoothSerial::flush()
|
|||||||
{
|
{
|
||||||
if (_spp_tx_queue != NULL){
|
if (_spp_tx_queue != NULL){
|
||||||
while(uxQueueMessagesWaiting(_spp_tx_queue) > 0){
|
while(uxQueueMessagesWaiting(_spp_tx_queue) > 0){
|
||||||
delay(100);
|
delay(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -721,22 +676,6 @@ void BluetoothSerial::end()
|
|||||||
_stop_bt();
|
_stop_bt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothSerial::onConfirmRequest(ConfirmRequestCb cb)
|
|
||||||
{
|
|
||||||
confirm_request_callback = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BluetoothSerial::onAuthComplete(AuthCompleteCb cb)
|
|
||||||
{
|
|
||||||
auth_complete_callback = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BluetoothSerial::confirmReply(boolean confirm)
|
|
||||||
{
|
|
||||||
esp_bt_gap_ssp_confirm_reply(current_bd_addr, confirm);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t * callback)
|
esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t * callback)
|
||||||
{
|
{
|
||||||
custom_spp_callback = callback;
|
custom_spp_callback = callback;
|
||||||
@ -782,7 +721,11 @@ bool BluetoothSerial::connect(String remoteName)
|
|||||||
_remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0;
|
_remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0;
|
||||||
log_i("master : remoteName");
|
log_i("master : remoteName");
|
||||||
// will first resolve name to address
|
// will first resolve name to address
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
#else
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||||
|
#endif
|
||||||
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
|
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
|
||||||
return waitForConnect(SCAN_TIMEOUT);
|
return waitForConnect(SCAN_TIMEOUT);
|
||||||
}
|
}
|
||||||
@ -822,7 +765,11 @@ bool BluetoothSerial::connect()
|
|||||||
disconnect();
|
disconnect();
|
||||||
log_i("master : remoteName");
|
log_i("master : remoteName");
|
||||||
// will resolve name to address first - it may take a while
|
// will resolve name to address first - it may take a while
|
||||||
|
#ifdef ESP_IDF_VERSION_MAJOR
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
#else
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||||
|
#endif
|
||||||
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
|
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
|
||||||
return waitForConnect(SCAN_TIMEOUT);
|
return waitForConnect(SCAN_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user