Compare commits
183 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b6be35735 | |||
| d634baf9be | |||
| c4eb278f6e | |||
| 21f18d4bd9 | |||
| f226295606 | |||
| d05df816ed | |||
| 04d5133114 | |||
| b60fc6d816 | |||
| a8bd52efe4 | |||
| 45df41c50c | |||
| cd36584474 | |||
| b990a011be | |||
| 04e05ad5b9 | |||
| 18c5d83f72 | |||
| 41f3ddc11a | |||
| 5e4a44f3f1 | |||
| 68b3514d96 | |||
| 77ad793a13 | |||
| 8a4b6be12c | |||
| 5df8cf47d8 | |||
| 40d58728f6 | |||
| f7f37d83e2 | |||
| 14662c90f3 | |||
| 7c46e28bb8 | |||
| 45dd66f174 | |||
| a8f62dd194 | |||
| 6601e1b0ed | |||
| 674f54ad63 | |||
| 6b3993bd03 | |||
| dbe8ef9c15 | |||
| 446fd125d9 | |||
| a9bbead698 | |||
| 24219f7100 | |||
| 78531c7a26 | |||
| 2c1388114d | |||
| 6881ee0ffe | |||
| 6cf010d723 | |||
| 9b28a3579c | |||
| e0ca3fa5aa | |||
| ee2160d233 | |||
| 3be4bda2b2 | |||
| af23ee56c3 | |||
| cecf3fb425 | |||
| fde9930ede | |||
| 26ff38347a | |||
| 6f004d667f | |||
| 69410ae557 | |||
| 980aa23d44 | |||
| 0b9666b263 | |||
| ca3e1f84bf | |||
| 88cca17b7e | |||
| fa49795d28 | |||
| 60fe08462e | |||
| 692f578346 | |||
| 2c764acf8c | |||
| 5108256570 | |||
| 82c39ab8d9 | |||
| 1eeb84f019 | |||
| 3bcc2a303f | |||
| e0acfb6ba1 | |||
| a2a063603d | |||
| eeb8b9162a | |||
| 10d166a1d4 | |||
| 1c94c54a52 | |||
| 71e06b381b | |||
| ffd5b181e6 | |||
| cfb4a005ae | |||
| 343083e94e | |||
| 133f2330e9 | |||
| 9dcf7f30c3 | |||
| 65f998bbc8 | |||
| b51268854b | |||
| c4c954888e | |||
| 73dca24048 | |||
| e2d289fdc6 | |||
| 9e90a1d255 | |||
| 0adf18d035 | |||
| 240a558aa9 | |||
| 0f6bb6721e | |||
| e8e1d73cae | |||
| 533d8e20a8 | |||
| 120d37091f | |||
| 405c5438b3 | |||
| 0710699f72 | |||
| 8b7b462a86 | |||
| 3e8f21f689 | |||
| 03b08e4c98 | |||
| e1d418a34a | |||
| e2bb387d67 | |||
| f12adf1c44 | |||
| 9444158a58 | |||
| c0e593554c | |||
| 59e7c921b2 | |||
| 316004289f | |||
| 86f3933c11 | |||
| b8f4775807 | |||
| 71a7a5aeac | |||
| d1cf670ac6 | |||
| bb3f65048d | |||
| 35276d320c | |||
| 7353050f4d | |||
| 8518065bf8 | |||
| 42ff16acb4 | |||
| 0668385b2c | |||
| 2bce6c5281 | |||
| 0924e7bc2c | |||
| e129cb58cd | |||
| 632b7a4544 | |||
| 7e5256f271 | |||
| 74bdd3076c | |||
| a83643cfb1 | |||
| 9a35484b76 | |||
| 2cf8157cfd | |||
| 7c8e38559a | |||
| 643364f303 | |||
| 07b922e042 | |||
| 15e5d4b48d | |||
| b437a13a7f | |||
| 39b2029b0f | |||
| 90454c2342 | |||
| 1580467b60 | |||
| 028f4501b3 | |||
| bd39c083ad | |||
| 71f96b3e2b | |||
| 3fae2f08fe | |||
| 16ecee550b | |||
| 351e5bb9a1 | |||
| ac80fcf1de | |||
| fc0e8e9fcf | |||
| e162fd1128 | |||
| 73902d640c | |||
| 69feac8526 | |||
| d6e455259d | |||
| f655f99107 | |||
| 9e6ac6e4d9 | |||
| 4ea9c1079a | |||
| c44348f1bc | |||
| 147cd8d2c1 | |||
| 6f3f6056ee | |||
| e5fa22c10a | |||
| ce7a883892 | |||
| 6d1aa846fd | |||
| a6d4718bf5 | |||
| 52d8a4826c | |||
| 363c27cd33 | |||
| b477b995e4 | |||
| c79bff40ba | |||
| 1e74a3024c | |||
| 2c3fe7c8d6 | |||
| 9ddbf76bae | |||
| 838eeb70f5 | |||
| 8d1a1f2d60 | |||
| e3a6b0ac0f | |||
| e7043978ae | |||
| eb4eca7db1 | |||
| f8a49d5354 | |||
| 18cdc818fb | |||
| a15977815e | |||
| 878a85fab1 | |||
| a402a76445 | |||
| c39e0645ff | |||
| 942ffe8b7f | |||
| cff007b792 | |||
| 920e0bb5d4 | |||
| f06ef6fd5a | |||
| f4111fcc7f | |||
| 37ef188719 | |||
| 35dab1fa34 | |||
| a81dd08f10 | |||
| 1a55f34014 | |||
| f0a6907bfb | |||
| 8e3cb948d8 | |||
| 48f1c93386 | |||
| 7a0b04b6d3 | |||
| 0d670dd6b2 | |||
| d107512720 | |||
| ccc2711129 | |||
| ced426421d | |||
| 3ce4318326 | |||
| b3dae46172 | |||
| 65fa207d68 | |||
| db4453e78c | |||
| 23ea6519b6 |
@@ -0,0 +1,194 @@
|
||||
# Copyright 2022 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.
|
||||
|
||||
# This workflow build examples, store the artifacts and deploy them to github pages.
|
||||
# Generates the launchpad configuration file that can be used with the url.
|
||||
|
||||
name: "Build examples to github pages"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow one concurrent deployment
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
delete-old-artifacts:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: List and Delete artifacts
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const artifacts = await github.rest.actions.listArtifactsForRepo({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
});
|
||||
|
||||
console.log('Found artifacts:', artifacts.data.artifacts.map(a => a.name));
|
||||
|
||||
for (const artifact of artifacts.data.artifacts) {
|
||||
if (artifact.name.startsWith('build-images-')) {
|
||||
console.log(`Deleting artifact: ${artifact.name}`);
|
||||
try {
|
||||
await github.rest.actions.deleteArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: artifact.id,
|
||||
});
|
||||
console.log(`Successfully deleted: ${artifact.name}`);
|
||||
} catch (error) {
|
||||
console.log(`Failed to delete ${artifact.name}:`, error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
job1:
|
||||
needs: [delete-old-artifacts]
|
||||
runs-on: ubuntu-latest
|
||||
container: espressif/idf:release-v5.1
|
||||
strategy:
|
||||
matrix:
|
||||
build-dir: [
|
||||
'chatgpt_demo',
|
||||
'factory_demo',
|
||||
'image_display',
|
||||
'lv_demos',
|
||||
'mp3_demo',
|
||||
'usb_camera_lcd_display',
|
||||
'usb_headset',
|
||||
'watering_demo']
|
||||
boards: ['sdkconfig.ci.box', 'sdkconfig.ci.box-lite', 'sdkconfig.ci.box-3']
|
||||
exclude:
|
||||
- boards: sdkconfig.ci.box-lite
|
||||
build-dir: usb_camera_lcd_display
|
||||
- boards: sdkconfig.ci.box
|
||||
build-dir: usb_camera_lcd_display
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
- run: mkdir -p images
|
||||
- name: Build examples
|
||||
shell: bash
|
||||
run: |
|
||||
. $IDF_PATH/export.sh
|
||||
pip install --upgrade idf-component-manager
|
||||
pip install "idf_build_apps<2.0"
|
||||
|
||||
cd $GITHUB_WORKSPACE/examples/${{matrix.build-dir}}
|
||||
comm -23 <(grep -v '^#' ${{matrix.boards}} | sort) <(grep -v '^#' sdkconfig.defaults | sort) | sed 's/.*/\n&/' >> sdkconfig.defaults
|
||||
|
||||
if [[ ${{matrix.build-dir}} == chatgpt_demo ]]; then
|
||||
cd factory_nvs
|
||||
comm -23 <(grep -v '^#' ${{matrix.boards}} | sort) <(grep -v '^#' sdkconfig.defaults | sort) | sed 's/.*/\n&/' >> sdkconfig.defaults
|
||||
idf.py build
|
||||
cd ../
|
||||
fi
|
||||
|
||||
idf.py build
|
||||
cd build
|
||||
esptool.py --chip esp32s3 merge_bin -o "$GITHUB_WORKSPACE/images/${{matrix.build-dir}}_${{matrix.boards}}.bin" @flash_args
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-images-${{matrix.build-dir}}-${{matrix.boards}}
|
||||
path: images/
|
||||
overwrite: true
|
||||
|
||||
job2:
|
||||
needs: [delete-old-artifacts]
|
||||
runs-on: ubuntu-latest
|
||||
container: espressif/esp-matter:latest_idf_v5.1.1
|
||||
strategy:
|
||||
matrix:
|
||||
build-dir: ['matter_switch']
|
||||
boards: ['sdkconfig.ci.box', 'sdkconfig.ci.box-lite', 'sdkconfig.ci.box-3']
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
- run: mkdir -p images
|
||||
- name: Build examples
|
||||
shell: bash
|
||||
run: |
|
||||
. $IDF_PATH/export.sh
|
||||
. $ESP_MATTER_PATH/export.sh
|
||||
pip install --upgrade "idf-component-manager~=1.2"
|
||||
pip install "idf_build_apps<2.0"
|
||||
|
||||
cd $GITHUB_WORKSPACE/examples/${{matrix.build-dir}}
|
||||
comm -23 <(grep -v '^#' ${{matrix.boards}} | sort) <(grep -v '^#' sdkconfig.defaults | sort) | sed 's/.*/\n&/' >> sdkconfig.defaults
|
||||
|
||||
idf.py set-target esp32s3 build
|
||||
cd build
|
||||
esptool.py --chip esp32s3 merge_bin -o "$GITHUB_WORKSPACE/images/${{matrix.build-dir}}_${{matrix.boards}}.bin" @flash_args
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-images-${{matrix.build-dir}}-${{matrix.boards}}
|
||||
path: images/
|
||||
overwrite: true
|
||||
|
||||
deploy:
|
||||
needs: [job1, job2]
|
||||
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
|
||||
- name: Download builds
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: build-images-*
|
||||
path: images/
|
||||
merge-multiple: true
|
||||
|
||||
- name: generate launchpad config
|
||||
run: |
|
||||
cd images/
|
||||
mv $GITHUB_WORKSPACE/bin/*.bin ./
|
||||
ls *
|
||||
$GITHUB_WORKSPACE/tools/launchpad/rename.sh $GITHUB_WORKSPACE
|
||||
$GITHUB_WORKSPACE/tools/launchpad/generate_launchpad_config.sh $GITHUB_REPOSITORY
|
||||
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v2
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: images/
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -1,42 +0,0 @@
|
||||
name: Build examples
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
Build-examples:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
PROJECT_PATH: examples/factory_demo
|
||||
BIN_FILE: ESP-Box_Demo_V0.3.0.bin
|
||||
container: espressif/idf:release-v4.4
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
- name: esp-idf build
|
||||
run: |
|
||||
pwd
|
||||
ls -al
|
||||
cd /opt/esp/idf
|
||||
git checkout 2bdea81b2a
|
||||
git submodule update --init --recursive
|
||||
./install.sh
|
||||
source ./export.sh
|
||||
cd $GITHUB_WORKSPACE/$PROJECT_PATH
|
||||
idf.py build
|
||||
esptool.py --chip esp32s3 merge_bin -o build/$BIN_FILE --flash_mode dio --flash_size 16MB 0x0 build/bootloader/bootloader.bin 0x20000 build/factory_demo.bin 0x8000 build/partition_table/partition-table.bin 0x16000 build/ota_data_initial.bin 0x3bd000 build/storage.bin 0x647000 build/model.bin
|
||||
shell: bash
|
||||
|
||||
- name: Upload a Build Artifact
|
||||
uses: actions/upload-artifact@v3.0.0
|
||||
with:
|
||||
# Artifact name
|
||||
name: factory-firmware
|
||||
# A file, directory or wildcard pattern that describes what to upload
|
||||
path: |
|
||||
examples/factory_demo/build/ESP-*.bin
|
||||
retention-days: 90
|
||||
@@ -0,0 +1,24 @@
|
||||
name: Sync issue comments to JIRA
|
||||
|
||||
# This workflow will be triggered when new issue comment is created (including PR comments)
|
||||
on: issue_comment
|
||||
|
||||
# Limit to single concurrent run for workflows which can create Jira issues.
|
||||
# Same concurrency group is used in new_issues.yml
|
||||
concurrency: jira_issues
|
||||
|
||||
jobs:
|
||||
sync_issue_comments_to_jira:
|
||||
name: Sync Issue Comments to Jira
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Sync issue comments to JIRA
|
||||
uses: espressif/github-actions/sync_issues_to_jira@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
JIRA_PASS: ${{ secrets.JIRA_PASS }}
|
||||
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}
|
||||
JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }}
|
||||
JIRA_URL: ${{ secrets.JIRA_URL }}
|
||||
JIRA_USER: ${{ secrets.JIRA_USER }}
|
||||
@@ -0,0 +1,24 @@
|
||||
name: Sync issues to Jira
|
||||
|
||||
# This workflow will be triggered when a new issue is opened
|
||||
on: issues
|
||||
|
||||
# Limit to single concurrent run for workflows which can create Jira issues.
|
||||
# Same concurrency group is used in issue_comment.yml
|
||||
concurrency: jira_issues
|
||||
|
||||
jobs:
|
||||
sync_issues_to_jira:
|
||||
name: Sync issues to Jira
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Sync GitHub issues to Jira project
|
||||
uses: espressif/github-actions/sync_issues_to_jira@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
JIRA_PASS: ${{ secrets.JIRA_PASS }}
|
||||
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}
|
||||
JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }}
|
||||
JIRA_URL: ${{ secrets.JIRA_URL }}
|
||||
JIRA_USER: ${{ secrets.JIRA_USER }}
|
||||
@@ -0,0 +1,29 @@
|
||||
name: Sync remain PRs to Jira
|
||||
|
||||
# This workflow will be triggered every hour, to sync remaining PRs (i.e. PRs with zero comment) to Jira project
|
||||
# Note that, PRs can also get synced when new PR comment is created
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 * * * *"
|
||||
|
||||
# Limit to single concurrent run for workflows which can create Jira issues.
|
||||
# Same concurrency group is used in issue_comment.yml
|
||||
concurrency: jira_issues
|
||||
|
||||
jobs:
|
||||
sync_prs_to_jira:
|
||||
name: Sync PRs to Jira
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Sync PRs to Jira project
|
||||
uses: espressif/github-actions/sync_issues_to_jira@master
|
||||
with:
|
||||
cron_job: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
JIRA_PASS: ${{ secrets.JIRA_PASS }}
|
||||
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}
|
||||
JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }}
|
||||
JIRA_URL: ${{ secrets.JIRA_URL }}
|
||||
JIRA_USER: ${{ secrets.JIRA_USER }}
|
||||
@@ -1,6 +1,7 @@
|
||||
.config
|
||||
*.o
|
||||
*.pyc
|
||||
*.orig
|
||||
|
||||
# gtags
|
||||
GTAGS
|
||||
@@ -25,6 +26,7 @@ GPATH
|
||||
**/examples/**/sdkconfig
|
||||
**/examples/**/sdkconfig.old
|
||||
**/examples/**/build
|
||||
**/examples/**/target
|
||||
|
||||
**/sdkconfig
|
||||
**/sdkconfig.old
|
||||
@@ -76,6 +78,9 @@ flake8_output.txt
|
||||
|
||||
# ESP-IDF default build directory name
|
||||
build
|
||||
build_esp*/
|
||||
build_linux*/
|
||||
size_info.txt
|
||||
|
||||
# lock files for examples and components
|
||||
dependencies.lock
|
||||
|
||||
+22
-61
@@ -1,71 +1,32 @@
|
||||
stages:
|
||||
- pre_check
|
||||
- build
|
||||
- deploy
|
||||
|
||||
workflow:
|
||||
rules:
|
||||
# Disable those non-protected push triggered pipelines
|
||||
- if: '$CI_COMMIT_REF_NAME != "master" && $CI_COMMIT_BRANCH !~ /^release\/v/ && $CI_COMMIT_TAG !~ /^v\d+\.\d+(\.\d+)?($|-)/ && $CI_PIPELINE_SOURCE == "push"'
|
||||
when: never
|
||||
# when running merged result pipelines, it would create a temp commit id. use $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA instead of $CI_COMMIT_SHA.
|
||||
# Please use PIPELINE_COMMIT_SHA at all places that require a commit sha
|
||||
- if: $CI_OPEN_MERGE_REQUESTS != null
|
||||
variables:
|
||||
PIPELINE_COMMIT_SHA: $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
|
||||
- if: $CI_OPEN_MERGE_REQUESTS == null
|
||||
variables:
|
||||
PIPELINE_COMMIT_SHA: $CI_COMMIT_SHA
|
||||
- when: always
|
||||
|
||||
variables:
|
||||
ESP_BOX_PATH: "$CI_PROJECT_DIR"
|
||||
BATCH_BUILD: "1"
|
||||
V: "0"
|
||||
IDF_CI_BUILD: "1"
|
||||
|
||||
before_script:
|
||||
# add gitlab ssh key
|
||||
- mkdir -p ~/.ssh
|
||||
- chmod 700 ~/.ssh
|
||||
- echo -n $GITLAB_KEY > ~/.ssh/id_rsa_base64
|
||||
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||
- git --version
|
||||
- git submodule update --init --recursive --force
|
||||
|
||||
.build_examples_template: &build_examples_template
|
||||
stage: build
|
||||
image: espressif/idf:release-v4.4
|
||||
tags:
|
||||
- build
|
||||
|
||||
build_demo_cmake:
|
||||
<<: *build_examples_template
|
||||
script:
|
||||
- cd examples/factory_demo
|
||||
- idf.py fullclean
|
||||
- idf.py build
|
||||
- cd ../
|
||||
- cd image_display
|
||||
- idf.py fullclean
|
||||
- idf.py build
|
||||
- cd ../
|
||||
- cd lv_demos
|
||||
- idf.py fullclean
|
||||
- idf.py build
|
||||
- cd ../
|
||||
- cd mp3_demo
|
||||
- idf.py fullclean
|
||||
- idf.py build
|
||||
- cd ../
|
||||
- cd watering_demo
|
||||
- idf.py fullclean
|
||||
- idf.py build
|
||||
|
||||
push_to_github:
|
||||
stage: deploy
|
||||
only:
|
||||
- master
|
||||
- /^release\/v/
|
||||
# when: on_success
|
||||
image: $CI_DOCKER_REGISTRY/esp32-ci-env
|
||||
variables:
|
||||
GIT_STRATEGY: clone
|
||||
before_script:
|
||||
- echo "skip default before_script"
|
||||
script:
|
||||
- mkdir -p ~/.ssh
|
||||
- chmod 700 ~/.ssh
|
||||
- echo -n $GH_PUSH_KEY > ~/.ssh/id_rsa_base64
|
||||
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||
- git remote remove github &>/dev/null || true
|
||||
- git remote add github git@github.com:espressif/esp-box.git
|
||||
- ${ESP_BOX_PATH}/tools/ci/push_to_github.sh
|
||||
include:
|
||||
- '.gitlab/ci/danger.yml'
|
||||
- '.gitlab/ci/rules.yml'
|
||||
- '.gitlab/ci/pre_check.yml'
|
||||
- '.gitlab/ci/build.yml'
|
||||
- '.gitlab/ci/deploy.yml'
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
.build_template: &build_template
|
||||
stage: build
|
||||
tags:
|
||||
- build
|
||||
image: ${IMAGE}
|
||||
variables:
|
||||
# Enable ccache for all build jobs. See configure_ci_environment.sh for more ccache related settings.
|
||||
IDF_CCACHE_ENABLE: "1"
|
||||
BATCH_BUILD: "1"
|
||||
V: "0"
|
||||
WARNING_STR: ""
|
||||
|
||||
.build_examples_template: &build_examples_template
|
||||
<<: *build_template
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "**/build*/size.json"
|
||||
- "**/build*/build_log.txt"
|
||||
- "**/build*/*.bin"
|
||||
# upload to s3 server to save the artifacts size
|
||||
- "**/build*/*.map"
|
||||
- "**/build*/*.elf"
|
||||
- "**/build*/flasher_args.json"
|
||||
- "**/build*/flash_project_args"
|
||||
- "**/build*/config/sdkconfig.json"
|
||||
- "**/build*/bootloader/*.bin"
|
||||
- "**/build*/bootloader/*.elf"
|
||||
- "**/build*/partition_table/*.bin"
|
||||
- size_info.txt
|
||||
expire_in: 1 week
|
||||
variables:
|
||||
IDF_CI_BUILD: "1"
|
||||
# By configuring this macro, you can append the compiled configuration file.
|
||||
# For example, using "sdkconf.etc=default" specifies the default sdkconfig file.
|
||||
EXAMPLE_CONFIG: "="
|
||||
script:
|
||||
- pip install --upgrade idf-component-manager
|
||||
- pip install "idf_build_apps<2.0"
|
||||
- python tools/build_apps.py ${EXAMPLE_DIR} --config ${EXAMPLE_CONFIG} -t esp32s3 -vv
|
||||
|
||||
.build_matter_template: &build_matter_template
|
||||
before_script:
|
||||
- . ${ESP_MATTER_PATH}/export.sh
|
||||
|
||||
build_example_matter_switch:
|
||||
extends:
|
||||
- .build_matter_template
|
||||
- .build_examples_template
|
||||
- .rules:build:example_matter_switch
|
||||
image: espressif/esp-matter:latest_idf_v5.1.1
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/matter_switch
|
||||
script:
|
||||
- pip install --upgrade "idf-component-manager~=1.2"
|
||||
- pip install "idf_build_apps<2.0"
|
||||
- python tools/build_apps.py ${EXAMPLE_DIR} --config ${EXAMPLE_CONFIG} -t esp32s3 -vv
|
||||
|
||||
build_example_chatgpt_demo:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_chatgpt_demo
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/chatgpt_demo
|
||||
NVS_DIR: examples/chatgpt_demo/factory_nvs
|
||||
before_script:
|
||||
- pwd
|
||||
- mkdir ${NVS_DIR}/build
|
||||
- touch ${NVS_DIR}/build/factory_nvs.bin
|
||||
|
||||
build_example_chatgpt_demo_factory_nvs:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_chatgpt_demo_factory_nvs
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/chatgpt_demo/factory_nvs
|
||||
|
||||
build_example_factory_demo:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_factory_demo
|
||||
parallel:
|
||||
matrix:
|
||||
#- IMAGE: espressif/idf:release-v5.0 don't support release-v5.0 now.
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/factory_demo
|
||||
|
||||
build_example_image_display:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_image_display
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/image_display
|
||||
|
||||
build_example_lv_demos:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_lv_demos
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/lv_demos
|
||||
|
||||
build_example_mp3_demo:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_mp3_demo
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/mp3_demo
|
||||
|
||||
build_example_usb_camera_lcd_display:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_usb_camera_lcd_display
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
# - IMAGE: espressif/idf:release-v5.3 don't support release-v5.3 now.
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
# - IMAGE: espressif/idf:latest usb_stream do not support release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/usb_camera_lcd_display
|
||||
|
||||
build_example_esp_joystick:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_esp_joystick
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
# - IMAGE: espressif/idf:release-v5.5 esp_now do not support release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/esp_joystick
|
||||
|
||||
build_example_usb_headset:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_usb_headset
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/usb_headset
|
||||
|
||||
build_example_watering_demo:
|
||||
extends:
|
||||
- .build_examples_template
|
||||
- .rules:build:example_watering_demo
|
||||
parallel:
|
||||
matrix:
|
||||
- IMAGE: espressif/idf:release-v5.0
|
||||
- IMAGE: espressif/idf:release-v5.1
|
||||
- IMAGE: espressif/idf:release-v5.2
|
||||
- IMAGE: espressif/idf:release-v5.3
|
||||
- IMAGE: espressif/idf:release-v5.4
|
||||
- IMAGE: espressif/idf:release-v5.5
|
||||
variables:
|
||||
EXAMPLE_DIR: examples/watering_demo
|
||||
@@ -0,0 +1,12 @@
|
||||
# External DangerJS
|
||||
include:
|
||||
- project: espressif/shared-ci-dangerjs
|
||||
ref: master
|
||||
file: danger.yaml
|
||||
|
||||
run-danger-mr-linter:
|
||||
stage: pre_check
|
||||
# just ignore for now until the BOT_TOKEN is ready
|
||||
allow_failure: true
|
||||
tags:
|
||||
- dangerjs
|
||||
@@ -0,0 +1,21 @@
|
||||
push_to_github:
|
||||
stage: deploy
|
||||
only:
|
||||
- master
|
||||
- /^release\/v/
|
||||
# when: on_success
|
||||
image: $CI_DOCKER_REGISTRY/esp32-ci-env
|
||||
variables:
|
||||
GIT_STRATEGY: clone
|
||||
before_script:
|
||||
- echo "skip default before_script"
|
||||
script:
|
||||
- mkdir -p ~/.ssh
|
||||
- chmod 700 ~/.ssh
|
||||
- echo -n $GH_PUSH_KEY > ~/.ssh/id_rsa_base64
|
||||
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||
- git remote remove github &>/dev/null || true
|
||||
- git remote add github git@github.com:espressif/esp-box.git
|
||||
- ${ESP_BOX_PATH}/tools/ci/push_to_github.sh
|
||||
@@ -0,0 +1,50 @@
|
||||
.pre_check_template:
|
||||
stage: pre_check
|
||||
image: python:3.9
|
||||
tags: ["build", "amd64", "internet"]
|
||||
dependencies: []
|
||||
|
||||
check_readme_links:
|
||||
extends:
|
||||
- .pre_check_template
|
||||
- .rules:pre_check:readme
|
||||
allow_failure: false
|
||||
script:
|
||||
- python ${CI_PROJECT_DIR}/tools/ci/check_readme_links.py
|
||||
|
||||
check_copyright:
|
||||
extends:
|
||||
- .pre_check_template
|
||||
allow_failure: false
|
||||
before_script:
|
||||
- pip install git+https://github.com/espressif/check-copyright.git@master
|
||||
script:
|
||||
- python -m check_copyright --verbose --dry-run --ignore tools/ci/ignore_list_copyright.txt --config tools/ci/check_copyright_config.yaml .
|
||||
|
||||
check_pre_commit:
|
||||
extends:
|
||||
- .pre_check_template
|
||||
before_script:
|
||||
- pip install pre-commit
|
||||
script:
|
||||
- |
|
||||
# merged results pipelines, by default
|
||||
if [[ -n $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA ]]; then
|
||||
MODIFIED_FILES=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA)
|
||||
# merge request pipelines, when the mr got conflicts
|
||||
elif [[ -n $CI_MERGE_REQUEST_DIFF_BASE_SHA ]]; then
|
||||
MODIFIED_FILES=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA)
|
||||
# other pipelines, like the protected branches pipelines
|
||||
else
|
||||
if [[ -z $CI_COMMIT_BEFORE_SHA || $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000" ]]; then
|
||||
echo "Warning: CI_COMMIT_BEFORE_SHA is empty or invalid. Cannot determine modified files based on this value."
|
||||
exit 0
|
||||
else
|
||||
MODIFIED_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA)
|
||||
fi
|
||||
fi
|
||||
# print the MODIFIED_FILES
|
||||
echo "MODIFIED_FILES: $MODIFIED_FILES"
|
||||
- pre-commit install --allow-missing-config -t pre-commit -t commit-msg
|
||||
- export SKIP=check-copyright # copyrights has been checked in separate job
|
||||
- pre-commit run --files $MODIFIED_FILES
|
||||
@@ -0,0 +1,171 @@
|
||||
############
|
||||
# Patterns #
|
||||
############
|
||||
|
||||
# components folder, in the alphabetic order
|
||||
.patterns-components_bsp: &patterns-components_bsp
|
||||
- "components/bsp/**/*"
|
||||
|
||||
# examples folder, in the alphabetic order
|
||||
.patterns-example_chatgpt_demo: &patterns-example_chatgpt_demo
|
||||
- "examples/chatgpt_demo/**/*"
|
||||
|
||||
.patterns-example_chatgpt_demo_factory_nvs: &patterns-example_chatgpt_demo_factory_nvs
|
||||
- "examples/chatgpt_demo/factory_nvs/**/*"
|
||||
|
||||
.patterns-example_matter_switch: &patterns-example_matter_switch
|
||||
- "examples/matter_switch/**/*"
|
||||
|
||||
.patterns-example_factory_demo: &patterns-example_factory_demo
|
||||
- "examples/factory_demo/**/*"
|
||||
|
||||
.patterns-example_image_display: &patterns-example_image_display
|
||||
- "examples/image_display/**/*"
|
||||
|
||||
.patterns-example_lv_demos: &patterns-example_lv_demos
|
||||
- "examples/lv_demos/**/*"
|
||||
|
||||
.patterns-example_mp3_demo: &patterns-example_mp3_demo
|
||||
- "examples/mp3_demo/**/*"
|
||||
|
||||
.patterns-example_usb_camera_lcd_display: &patterns-example_usb_camera_lcd_display
|
||||
- "examples/usb_camera_lcd_display/**/*"
|
||||
|
||||
.patterns-example_esp_joystick: &patterns-example_esp_joystick
|
||||
- "examples/esp_joystick/**/*"
|
||||
|
||||
.patterns-example_usb_headset: &patterns-example_usb_headset
|
||||
- "examples/usb_headset/**/*"
|
||||
|
||||
.patterns-example_watering_demo: &patterns-example_watering_demo
|
||||
- "examples/watering_demo/**/*"
|
||||
|
||||
.patterns-docs_md: &patterns-docs_md
|
||||
- "**/*.md"
|
||||
|
||||
##############
|
||||
# if anchors #
|
||||
##############
|
||||
.if-protected: &if-protected
|
||||
if: '($CI_COMMIT_REF_NAME == "master" || $CI_COMMIT_BRANCH =~ /^release\/v/ || $CI_COMMIT_TAG =~ /^v\d+\.\d+(\.\d+)?($|-)/)'
|
||||
|
||||
.if-dev-push: &if-dev-push
|
||||
if: '$CI_COMMIT_REF_NAME != "master" && $CI_COMMIT_BRANCH !~ /^release\/v/ && $CI_COMMIT_TAG !~ /^v\d+\.\d+(\.\d+)?($|-)/ && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event")'
|
||||
|
||||
##################
|
||||
# Auto Generated #
|
||||
##################
|
||||
.if-label-build: &if-label-build
|
||||
if: '$CI_MERGE_REQUEST_LABELS =~ /^(?:[^,\n\r]+,)*build(?:,[^,\n\r]+)*$/i'
|
||||
|
||||
.if-label-pre_check: &if-label-pre_check
|
||||
if: '$BOT_LABEL_PRE_CHECK || $CI_MERGE_REQUEST_LABELS =~ /^(?:[^,\n\r]+,)*pre_check(?:,[^,\n\r]+)*$/i'
|
||||
|
||||
# rules for examples
|
||||
.rules:build:example_chatgpt_demo:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_chatgpt_demo
|
||||
|
||||
.rules:build:example_chatgpt_demo_factory_nvs:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_chatgpt_demo_factory_nvs
|
||||
|
||||
.rules:build:example_matter_switch:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_matter_switch
|
||||
|
||||
.rules:build:example_factory_demo:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_factory_demo
|
||||
|
||||
.rules:build:example_image_display:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_image_display
|
||||
|
||||
.rules:build:example_lv_demos:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_lv_demos
|
||||
|
||||
.rules:build:example_mp3_demo:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_mp3_demo
|
||||
|
||||
.rules:build:example_usb_camera_lcd_display:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_usb_camera_lcd_display
|
||||
|
||||
.rules:build:example_esp_joystick:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_esp_joystick
|
||||
|
||||
.rules:build:example_usb_headset:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_usb_headset
|
||||
|
||||
.rules:build:example_watering_demo:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-build
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-example_watering_demo
|
||||
|
||||
.rules:pre_check:readme:
|
||||
rules:
|
||||
- <<: *if-protected
|
||||
- <<: *if-label-pre_check
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-components_bsp
|
||||
- <<: *if-dev-push
|
||||
changes: *patterns-docs_md
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
[submodule "components/lvgl/lv_demos"]
|
||||
path = components/lvgl/lv_demos
|
||||
url = https://github.com/lvgl/lv_demos.git
|
||||
[submodule "components/lvgl/lvgl"]
|
||||
path = components/lvgl/lvgl
|
||||
url = https://github.com/lvgl/lvgl.git
|
||||
[submodule "components/esp-sr"]
|
||||
path = components/esp-sr
|
||||
url = https://github.com/espressif/esp-sr.git
|
||||
[submodule "components/esp-rainmaker"]
|
||||
path = components/esp-rainmaker
|
||||
url = https://github.com/espressif/esp-rainmaker.git
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
---
|
||||
minimum_pre_commit_version: 3.3.0
|
||||
default_install_hook_types: [pre-commit,commit-msg]
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/espressif/check-copyright/
|
||||
rev: v1.0.3
|
||||
hooks:
|
||||
- id: check-copyright
|
||||
args: ['--config', 'tools/ci/check_copyright_config.yaml', '--ignore', 'tools/ci/check_copyright_ignore.txt']
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: file-contents-sorter
|
||||
files: 'tools\/ci\/(executable-list\.txt|check_copyright_ignore\.txt)'
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
# note: whitespace exclusions use multiline regex, see https://pre-commit.com/#regular-expressions
|
||||
# items are:
|
||||
# 1 - some file extensions
|
||||
# 2 - any file matching *test*/*expected* (for host tests, if possible use this naming pattern always)
|
||||
# 3 - any file with known-warnings in the name
|
||||
# 4 - any directory named 'testdata'
|
||||
# 5 - protobuf auto-generated files
|
||||
exclude: &whitespace_excludes |
|
||||
(?x)^(
|
||||
.+\.(md|rst|map|bin)|
|
||||
.+test.*\/.*expected.*|
|
||||
.+known-warnings.*|
|
||||
.+\/testdata\/.+|
|
||||
.*_pb2.py|
|
||||
.*.pb-c.h|
|
||||
.*.pb-c.c|
|
||||
.*.yuv
|
||||
)$
|
||||
- id: end-of-file-fixer
|
||||
exclude: *whitespace_excludes
|
||||
- id: check-executables-have-shebangs
|
||||
- id: check-shebang-scripts-are-executable
|
||||
- id: mixed-line-ending
|
||||
args: ['-f=lf']
|
||||
- id: double-quote-string-fixer
|
||||
- id: no-commit-to-branch
|
||||
name: Do not use more than one slash in the branch name
|
||||
args: ['--pattern', '^[^/]*/[^/]*/']
|
||||
- id: no-commit-to-branch
|
||||
name: Do not use uppercase letters in the branch name
|
||||
args: ['--pattern', '^[^A-Z]*[A-Z]']
|
||||
- repo: https://github.com/espressif/astyle_py.git
|
||||
rev: v1.0.5
|
||||
hooks:
|
||||
- id: astyle_py
|
||||
# If you are modifying astyle version, update tools/format.sh as well
|
||||
args: ['--astyle-version=3.4.7', '--rules=tools/ci/astyle-rules.yml']
|
||||
|
||||
- repo: https://github.com/espressif/conventional-precommit-linter
|
||||
rev: v1.8.0
|
||||
hooks:
|
||||
- id: conventional-precommit-linter
|
||||
stages: [commit-msg]
|
||||
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: codespell
|
||||
args: [-w, "--ignore-words=codespell-ignore-list"]
|
||||
@@ -1,81 +1,113 @@
|
||||
* [中文版本](README_cn.md)
|
||||
<p align="center">
|
||||
<img src="docs/_static/banner2.jpg" width="auto" height="auto" alt="ESPRESSIF">
|
||||
</p>
|
||||
|
||||
* [中文版本](README_cn.md)
|
||||
* [Promotional Video](https://www.youtube.com/watch?v=KGVOi1Mrjb0)
|
||||
# ESP-BOX AIoT Development Framework
|
||||
|
||||
<p align="left">
|
||||
<a href="https://github.com/espressif/esp-box/blob/master/LICENSE" alt="Build examples">
|
||||
<img alt="GitHub" src="https://img.shields.io/github/license/espressif/esp-box"></a>
|
||||
<a href="https://github.com/espressif/esp-box/actions/workflows/build.yml" alt="Build examples">
|
||||
<img src="https://github.com/espressif/esp-box/actions/workflows/build.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/actions/workflows/build-examples-gh-pages-on-push.yml" alt="Build examples">
|
||||
<img src="https://github.com/espressif/esp-box/actions/workflows/build-examples-gh-pages-on-push.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/graphs/contributors" alt="Contributors">
|
||||
<img src="https://img.shields.io/github/contributors/espressif/esp-box" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/releases" alt="GitHub all releases">
|
||||
<img src="https://img.shields.io/github/downloads/espressif/esp-box/total" /></a>
|
||||
</p>
|
||||
|
||||
<a href="https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-box/launchpad.toml">
|
||||
<img alt="Try it with ESP Launchpad" src="https://espressif.github.io/esp-launchpad/assets/try_with_launchpad.png" width="250" height="70">
|
||||
</a>
|
||||
|
||||
**Important Note:**
|
||||
|
||||
> We recommend [updating the application firmware](./docs/firmware_update.md) when you first receive the product to have the new features and bugfix. Click [here](./docs/getting_started.md) to access the user guide of the latest release firmware. Click [here](https://github.com/espressif/esp-box/releases) to visit the older firmware.
|
||||
> Upon receiving the ESP32-S3-BOX-3, we advise updating the built-in factory firmware to ensure you have the latest bugfixes via Espressif's online firmware flashing tool ESP Launchpad. Up till now, the latest version is **ESP-BOX-3_Demo_V1.2.4**. To verify the software version, please go to the 'About Us' Page.
|
||||
|
||||
The ESP-BOX is a new generation AIoT development platform released by Espressif Systems. The ESP32-S3-BOX and ESP32-S3-BOX-Lite are AIoT development boards that are based on Espressif’s ESP32-S3 Wi-Fi + Bluetooth 5 (LE) SoC. They provide a platform for developing the control of home appliances using Voice Assistance + touch and screen controller, sensor, infrared controller, and intelligent Wi-Fi gateway. Development boards come with pre-built firmware that supports offline voice interaction, with the SDKs and examples provided by Espressif, you will be able to develop a wide variety of AIoT applications based on the BOX series products such as online and offline voice assistants, voice-enabled devices, human-computer interaction devices, control panels, multi-protocol gateways easily.
|
||||
The ESP-BOX is an advanced AIoT, Edge AI, and IIoT applications development platform released by Espressif Systems. The ESP32-S3-BOX, ESP32-S3-BOX-Lite, and ESP32-S3-BOX-3 are a series of development boards designed for this platform, they are built on Espressif’s powerful ESP32-S3 Wi-Fi + Bluetooth 5 (LE) SoC and feature compact and beautiful enclosures. Leveraging the multi-functional accessories and reliable examples from the repo’s, these development boards cater to both prototyping new projects and building complex IoT systems, providing a perfect balance of form and function.
|
||||
|
||||
| Product Name | Product Figure |
|
||||
| :-----: | :---------------------: |
|
||||
| [ESP32-S3-BOX](docs/hardware_overview/esp32_s3_box/hardware_overview_for_box.md) | <img src="docs/_static/esp32_s3_box.png" width="200px" /> |
|
||||
| [ESP32-S3-BOX-Lite](docs/hardware_overview/esp32_s3_box_lite/hardware_overview_for_lite.md) | <img src="docs/_static/esp32_s3_box_lite.png" width="200px" /> |
|
||||
ESP-BOX provides a platform for developing applications in various domains, including Offline Voice Assistants, Online AI Chatbots (developed using OpenAI and other large language model platforms), Matter Device/Controller, Robot Controller, USB Device/Host, Wireless Sensor Application and a wide range of Human Machine Interaction (HMI) applications. Experience the possibilities—add one to your toolkit and explore the limitless potential!
|
||||
|
||||
|
||||
| Product Name | Product Figure | Marketing Status |
|
||||
| :-----: | :---------------------: |:---------------------: |
|
||||
| [ESP32-S3-BOX<sup> **1** </sup>](docs/hardware_overview/esp32_s3_box/hardware_overview_for_box.md) | <img src="docs/_static/esp32_s3_box.png" width="200px" /> |End of Life <br> [User Guide](https://github.com/espressif/esp-box/blob/v0.5.0/docs/getting_started.md) |
|
||||
| [ESP32-S3-BOX-Lite<sup> **1**</sup>](docs/hardware_overview/esp32_s3_box_lite/hardware_overview_for_lite.md) | <img src="docs/_static/esp32_s3_box_lite.png" width="200px" /> |End of Life <br> [User Guide](https://github.com/espressif/esp-box/blob/v0.5.0/docs/getting_started.md)|
|
||||
| [ESP32-S3-BOX-3<sup> **2**</sup>](docs/hardware_overview/esp32_s3_box_3/hardware_overview_for_box_3.md) | <img src="docs/_static/esp32_s3_box_3.png" width="200px" /> |[Active](https://www.aliexpress.com/item/1005005920207976.html) <br> [User Guide](./docs/getting_started.md)|
|
||||
|
||||
**Note 1**: Upon receiving the ESP32-S3-BOX and ESP32-S3-BOX-Lite, we advise updating the [built-in factory firmware](./docs/firmware_update.md) to ensure you have the latest bug fixes. In the master branch, we will gradually offer limited support for these two development boards. For further information, kindly refer to the examples readme.
|
||||
|
||||
**Note 2**: The ESP32-S3-BOX-3 offers two different versions: ESP32-S3-BOX-3 and ESP32-S3-BOX-3B. The ESP32-S3-BOX-3 represents the standard edition with four blue accessories, the ESP32-S3-BOX-3B provides fewer accessories to meet starters who don’t need much unnecessary hardware. For more details on the distinctions, please check [here](https://github.com/espressif/esp-box/blob/master/docs/getting_started.md#variant-description).
|
||||
## Versions
|
||||
|
||||
| ESP-BOX | Dependent ESP-IDF | Branch Note | Support State |
|
||||
| :--------------: | :---------------: | :----------------------------------------------------: | -------------- |
|
||||
| master | release/v4.4<br>commit id: 2bdea81b2a | Latest developing firmware <br/>esp-sr version: dev/v2.0<br>commit id: c873a35 | New feature develop, compatible with ESP32-S3-BOX and ESP32-S3-BOX-Lite |
|
||||
| master | >= release/v5.1<br/>commit id: 22cfbf30c3 | Latest developing firmware <br/>esp-sr components version: v1.4.1 | Partial support for ESP32-S3-BOX, ESP32-S3-BOX-Lite, and ESP32-S3-BOX-3 <br>**Use menuconfig to select board**<br> Refer to the Examples **README** for more details. |
|
||||
| Tag 0.5.0 | release/v5.1<br>commit id: 22cfbf30c3 | esp-sr components version: v1.3.4 | Compatible with ESP32-S3-BOX and ESP32-S3-BOX-Lite <br/>Use menuconfig to select board |
|
||||
| Tag 0.3.0 | release/v4.4<br>commit id: 2bdea81b2a | esp-sr version: dev/v2.0<br>commit id: c873a35 | Compatible with ESP32-S3-BOX and ESP32-S3-BOX-Lite |
|
||||
| Tag 0.2.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.2.1/idf_patch) | esp-sr version: close v1.0<br/>commit id: 3ce34fe | Support ESP32-S3-BOX only |
|
||||
| Tag 0.1.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.1.1/idf_patch) | esp-sr version: v0.9.6<br/>commit id: 3ce34fe | Support ESP32-S3-BOX only |
|
||||
|
||||
## Features
|
||||
|
||||
* Supports far-field voice interaction with 2 mics
|
||||
* Offline voice wake-up with high wake-up rate
|
||||
* Offline speech commands recognition in Chinese and English languages with high recognition rate
|
||||
* Reconfigurable 200+ speech commands in Chinese and English languages
|
||||
* Continuous Identification and Wakeup Interrupt
|
||||
* Flexible and reusable GUI framework
|
||||
* End-to-end AIoT dvelopment framwork ESP-RainMaker
|
||||
* Pmod™ compatible headers support expand peripheral modules
|
||||
* An out-of-the-box entry-level edge AI + HMI application development board.
|
||||
* FreeRTOS-based four-in-one voice interaction panel: offline voice recognition, network communication, screen display, peripheral control.
|
||||
* Supports far-field voice interaction with 2 mics.
|
||||
* Offline voice wake-up and commands recognition with high wake-up rate.
|
||||
* Allows continuous recognition, wake-up interrupt, and over 200 customizable command words.
|
||||
* Flexible and versatile home automation solutions: Matter, Home Assistant, ESP-RainMaker
|
||||
* Visual drag-and-drop GUI development: LVGL SquareLine Studio, Embedded Wizard, etc.
|
||||
* Rich development framework: ESP-IDF, Arduino, PlatformIO, Circuit Python, and more.
|
||||
|
||||
|
||||
## Open-Source Content
|
||||
|
||||
* [Schematic and PCB Source File](./hardware)
|
||||
* [Shell 3D Print Source File](./hardware)
|
||||
* [Firmware Source Code](./examples/factory_demo)
|
||||
* [Examples Source Code](./examples)
|
||||
* [Built-in Firmware Source Code](./examples/factory_demo)
|
||||
* [Other Examples](./examples)
|
||||
|
||||
> Based on [Apache 2.0](https://github.com/espressif/esp-box/blob/master/LICENSE) open source license, you can modify, develop, or distribute the contents freely.
|
||||
> Based on [Apache 2.0](https://github.com/espressif/esp-box/blob/master/LICENSE) open source license, you can modify, develop, or distribute the contents freely.
|
||||
|
||||
## User Guide
|
||||
## Built-in Firmware User Guide
|
||||
|
||||
* For getting start of BOX serial development boards, please refer to the [Getting Started](./docs/getting_started.md).
|
||||
* For experiencing voice assistant, please refer to the [Voice Assistance Control and Customization](./docs/getting_started.md#offline-voice-assistant-with-your-device).
|
||||
* For experiencing a more humanized interactive experience, please refer to the [Continuous Speech Recognition](./docs/getting_started.md#continuous-recognition).
|
||||
* For defining the speech commands by mobile APP, please refer to the [ESP-BOX APP User Guide](./docs/getting_started.md#voice-command-customization).
|
||||
* It is recommended to start by reading the product [Hardware Overview](./docs/hardware_overview/esp32_s3_box_3/hardware_overview_for_box_3.md).
|
||||
* Next you can explore the [Getting Started](./docs/getting_started.md).
|
||||
* For exploring interesting sensor demos, please refer to [Sensor Applications](./docs/getting_started.md#sensor-monitor).
|
||||
* For experiencing voice assistant, please refer to the [Voice Assistance Control](./docs/getting_started.md#offline-voice-assistant).
|
||||
* For experiencing a more humanized interactive experience, please refer to the [Continuous Speech Recognition](./docs/getting_started.md#continuous-speech-recognition).
|
||||
* For defining the speech commands by mobile APP, please refer to the [ESP BOX APP User Guide](./docs/getting_started.md#voice-command-customization).
|
||||
* For switching the voice model language, please refer to [Switch Voice Model Language](./docs/getting_started.md#switch-voice-model-language).
|
||||
* For product exploded-view and disassembly tutorial, please refer to [Disassembly Tutorial](docs/disassembly_tutorial.md).
|
||||
* For more details of hardware information, please refer to the [Hardware Overview](./docs/hardware_overview).
|
||||
* For latest version firmware, please refer to the [Firmware Update](./docs/firmware_update.md).
|
||||
|
||||
## Developer Guide
|
||||
|
||||
ESP-BOX integrates components commonly used in AIOT development that you can leverage to build your own applications.
|
||||
ESP-BOX integrates ESP-IDF components commonly used in AIoT development from [ESP Registry](https://components.espressif.com/components?q=lcd) that you can leverage to build your own applications.
|
||||
|
||||
### Quick Start
|
||||
|
||||
* **Step 1**. ESP-IDF (Espressif IoT Development Framework) is required to build the application. If this is your first time using the ESP-IDF, please refer to [ESP-IDF development guide](https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32s3/index.html) to understand the open-source drivers and components provided by Espressif.
|
||||
* **Step 2**. Next, setting up development environment. Please refer to [ESP-IDF(release/v4.4) Installation Step by Step](https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32s3/get-started/index.html#installation-step-by-step).
|
||||
* **Step 1**. ESP-IDF (Espressif IoT Development Framework) is required to build the application. If this is your first time using the ESP-IDF, please refer to [ESP-IDF development guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/index.html) to understand the open-source drivers and components provided by Espressif.
|
||||
* **Step 2**. Next, setting up development environment. Please refer to [ESP-IDF (release/v5.1) Installation Step by Step](https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32s3/get-started/index.html#ide).
|
||||
* **Step 3**. Run command `git clone --recursive https://github.com/espressif/esp-box.git` to download the code of this project and then switch the ESP-IDF version to [specified version](#versions);
|
||||
* **Step 4**. Take a small step, you can [build and flash a simple example](./examples/image_display).
|
||||
* **Step 5**. Moving further, please read [ESP-BOX technical architecture](./docs/technical_architecture.md) to understand the technical details.
|
||||
* **Step 6**. Going deeper, please read [ESP Speech Recognition Application Guide](https://github.com/espressif/esp-sr), [ESP RainMaker Programming Guide](https://docs.espressif.com/projects/esp-rainmaker/en/latest/), [LVGL GUI Quick overview](https://docs.lvgl.io/8.1/get-started/index.html).
|
||||
* **Step 7**. For extended function, please read [Pmod™ compatible headers](./docs/hardware_overview) and [ESP-IDF API reference](https://docs.espressif.com/projects/esp-idf/en/v4.4/esp32s3/api-reference/index.html), to develop drivers for more extended devices.
|
||||
* **Step 6**. Going deeper, please read [ESP Speech Recognition Application Guide](https://github.com/espressif/esp-sr), [ESP RainMaker Programming Guide](https://docs.espressif.com/projects/esp-rainmaker/en/latest/), [LVGL GUI Quick overview](https://docs.lvgl.io/8.3/).
|
||||
* **Step 7**. For extended function, please read [Pmod™ compatible headers](./docs/hardware_overview) and [ESP-IDF API reference](https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32s3/api-reference/index.html), to develop drivers for more extended devices.
|
||||
### Cloud Quick Start
|
||||
The ESP BOX APP is built based on the commercial mobile APP architecture, Nova Home, which provides fancy UI and better user experience but has limited openness. To gain access to it, customers are required to contact us commercially via email at sales@espressif.com.
|
||||
For developer, we offer [ESP RainMaker](https://rainmaker.espressif.com/) solution, which includes publicly available development document and API guide. Below is the pathway to access them:
|
||||
* [ESP RainMaker Get Started](https://rainmaker.espressif.com/docs/get-started.html)
|
||||
* [ESP RainMaker Programming Guide](https://docs.espressif.com/projects/esp-rainmaker/en/latest/)
|
||||
* [RainMaker App APIs Definitions](https://swaggerapis.rainmaker.espressif.com)
|
||||
|
||||
### NuttX
|
||||
The ESP32-S3-BOX-3 also supports integration with [NuttX](https://github.com/apache/nuttx/tree/master/boards/xtensa/esp32s3/esp32s3-box), offering further flexibility and functionality. Nuttx is a real-time operating system (RTOS) known for its compact size, efficiency, and real-time performance, making it an excellent choice for embedded systems.
|
||||
|
||||
### Great Projects from Developers
|
||||
We actively collect [outstanding projects](./docs/great_projects.md) based on ESP-BOX to inspire more developers to innovate. We thank the enthusiasts promoting thriving community culture and welcome more developers to contribute to the vibrant ESP32 community.
|
||||
|
||||
## Contact Us
|
||||
|
||||
@@ -84,5 +116,5 @@ ESP-BOX integrates components commonly used in AIOT development that you can lev
|
||||
|
||||
## Contributing Examples
|
||||
|
||||
We welcome any open-source software or hardware contribution. If you have any examples you want to share with us, please click the [Contributions Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/contribute/index.html) and commit to the [Pull Requests](https://github.com/espressif/esp-box/pulls) to contribute your code.
|
||||
We welcome any open-source software or hardware contribution. If you have any examples you want to share with us, please click the [Contributions Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/contribute/index.html) and commit to the [Pull Requests](https://github.com/espressif/esp-box/pulls) to contribute your code.
|
||||
|
||||
|
||||
+122
-88
@@ -1,88 +1,122 @@
|
||||
* [English Version](./README.md)
|
||||
* [Gitee 镜像仓库](https://gitee.com/EspressifSystems/esp-box)
|
||||
|
||||
# ESP-BOX AIoT 开发框架
|
||||
|
||||
<p align="left">
|
||||
<a href="https://github.com/espressif/esp-box/blob/master/LICENSE" alt="Build examples">
|
||||
<img alt="GitHub" src="https://img.shields.io/github/license/espressif/esp-box"></a>
|
||||
<a href="https://github.com/espressif/esp-box/actions/workflows/build.yml" alt="Build examples">
|
||||
<img src="https://github.com/espressif/esp-box/actions/workflows/build.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/graphs/contributors" alt="Contributors">
|
||||
<img src="https://img.shields.io/github/contributors/espressif/esp-box" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/releases" alt="GitHub all releases">
|
||||
<img src="https://img.shields.io/github/downloads/espressif/esp-box/total" /></a>
|
||||
</p>
|
||||
|
||||
**重要提醒:**
|
||||
> 我们建议您在第一次收到产品时[更新应用固件](./docs/firmware_update_cn.md)以获得最新功能和 bug 的修复,点此[链接](./docs/getting_started_cn.md)获取应用固件的使用说明。点击[此处](https://github.com/espressif/esp-box/releases)查看历史固件。
|
||||
|
||||
ESP-BOX 是乐鑫信息科技发布的新一代 AIoT 应用开发平台。ESP32-S3-BOX 和 ESP32-S3-BOX-Lite 是目前对应的 AIoT 应用开发板,搭载支持 AI 加速的 ESP32-S3 Wi-Fi + Bluetooth 5 (LE) SoC。他们为用户提供了一个基于语音助手 + 触摸屏控制、传感器、红外控制器和智能 Wi-Fi 网关等功能,开发和控制智能家居设备的平台。开发板出厂支持离线语音交互功能,用户通过乐鑫丰富的 SDK 和解决方案,能够轻松构建在线和离线语音助手、智能语音设备、HMI 人机交互设备、控制面板、多协议网关等多样的应用。
|
||||
|
||||
| 开发板名称 | 产品图 |
|
||||
| :-----: | :---------------------: |
|
||||
| [ESP32-S3-BOX](docs/hardware_overview/esp32_s3_box/hardware_overview_for_box_cn.md) | <img src="docs/_static/esp32_s3_box.png" width="200px" /> |
|
||||
| [ESP32-S3-BOX-Lite](docs/hardware_overview/esp32_s3_box_lite/hardware_overview_for_lite_cn.md) | <img src="docs/_static/esp32_s3_box_lite.png" width="200px" /> |
|
||||
|
||||
## 版本信息
|
||||
|
||||
| ESP-BOX | 依赖的 ESP-IDF | 分支信息 | 支持状态 |
|
||||
| :-------: | :----------------------------------------------------------: | :----------------------------------------------------------: | ------------------------------------------------------- |
|
||||
| master | release/v4.4<br/>commit id: 2bdea81b2a | Latest developing firmware <br/>esp-sr version: dev/v2.0<br/>commit id: c873a35 | 新功能开发分支,兼容 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite |
|
||||
| Tag 0.3.0 | release/v4.4<br/>commit id: 2bdea81b2a | esp-sr version: dev/v2.0<br/>commit id: c873a35 | 兼容 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite |
|
||||
| Tag 0.2.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.2.1/idf_patch) | esp-sr version: close v1.0<br/>commit id: 3ce34fe | 仅支持 ESP32-S3-BOX |
|
||||
| Tag 0.1.1 | Release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.1.1/idf_patch) | esp-sr version: v0.9.6<br/>commit id: 3ce34fe | 仅支持 ESP32-S3-BOX |
|
||||
|
||||
## 支持特性
|
||||
|
||||
* 双麦克风支持远场语音交互
|
||||
* 高唤醒率的离线语音唤醒
|
||||
* 高识别率的离线中英文命令词识别
|
||||
* 可动态配置 200+ 中英文命令词
|
||||
* 连续识别和唤醒打断
|
||||
* 灵活可复用的 GUI 框架
|
||||
* 端到端一站式接入云平台
|
||||
* Pmod™ 兼容接口支持多种外设扩展
|
||||
|
||||
## 开源内容
|
||||
|
||||
* [原理图与 PCB 源文件](./hardware)
|
||||
* [外壳 3D 打印源文件](./hardware)
|
||||
* [出厂固件源代码](./examples/factory_demo)
|
||||
* [示例程序源代码](./examples)
|
||||
|
||||
> 基于 [Apache 2.0](https://github.com/espressif/esp-box/blob/master/LICENSE) 开源协议,你可以免费且自由的修改、创作和分享。
|
||||
|
||||
## 使用指引
|
||||
|
||||
* 首次拿到 BOX 系列开发板,您可以查看 [首次使用操作指引](./docs/getting_started_cn.md#给设备供电);
|
||||
* 想要体验离线语音助手功能,您可以查看 [离线语音识别](./docs/getting_started_cn.md#体验离线语音识别);
|
||||
* 体验更人性化的语音交互,可查看 [连续语音识别](./docs/getting_started_cn.md#连续语音识别);
|
||||
* 想要通过手机 APP 设置独特的语音命令词,请查看 [ESP-BOX APP 操作指引](./docs/getting_started_cn.md#语音命令词自定义);
|
||||
* 想要了解产品爆炸图和拆机说明,请查看 [拆机教程](docs/disassembly_tutorial.md);
|
||||
* 想要了解开发板硬件和接口细节,请查看 [硬件总览](./docs/hardware_overview);
|
||||
* 想要使用最新版本固件,请查看 [固件更新说明](./docs/firmware_update_cn.md)。
|
||||
|
||||
## 开发指引
|
||||
|
||||
esp-box 集成了 AIOT 开发中常用的组件,您可以利用这些组件构建自己的应用。
|
||||
|
||||
### 快速开始
|
||||
|
||||
* **Step 1**. 如果您首次接触 ESP-IDF 开发,建议先浏览 [ESP-IDF 编程指南](https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32s3/index.html),了解乐鑫已经提供的开源驱动和组件;
|
||||
* **Step 2**. 接下来您可以详细阅读 [ESP-IDF(release/v4.4) 环境搭建指引](https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32s3/get-started/index.html#installation-step-by-step),一步一步完成开发环境搭建;
|
||||
* **Step 3**. 使用指令 `git clone --recursive https://github.com/espressif/esp-box.git` 下载本项目的代码,然后需要将 esp-idf 版本切换到[指定的版本](#版本信息);
|
||||
* **Step 4**. 小试牛刀,您可以尝试 [构建并烧录一个新的示例程序](./examples/image_display);
|
||||
* **Step 5**. 更进一步,您可以阅读 [ESP-BOX 技术架构说明](./docs/technical_architecture_cn.md),了解更多技术细节;
|
||||
* **Step 6**. 深入开发,您可以阅读 [ESP 语音识别应用开发指南](https://github.com/espressif/esp-sr),[ESP RainMaker 编程指南](https://docs.espressif.com/projects/esp-rainmaker/en/latest/),[LVGL UI 界面开发快速总览](https://docs.lvgl.io/8.1/get-started/index.html);
|
||||
* **Step 7**. 扩展功能,您可以阅读 [开发板 Pmod™ 兼容接口介绍](./docs/hardware_overview) 和 [ESP-IDF API 参考手册](https://docs.espressif.com/projects/esp-idf/en/v4.4/esp32s3/api-reference/index.html),为更多扩展设备开发驱动。
|
||||
|
||||
## 联系我们
|
||||
|
||||
* 如果有任何开发和使用问题,您可添加 [GitHub Issues](https://github.com/espressif/esp-box/issues) 或到 [esp32.com](https://esp32.com/) 论坛寻求帮助;
|
||||
* 如果你对 ESP-BOX 项目感兴趣,欢迎到论坛 [ESP-BOX 版块](https://www.esp32.com/viewforum.php?f=43) 交流想法。
|
||||
|
||||
|
||||
## 贡献示例
|
||||
|
||||
我们欢迎任何软件或硬件相关的开源贡献,如果您有任何要与我们分享的示例,请参考 [贡献指南](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/contribute/index.html) 后提交 [Pull Requests](https://github.com/espressif/esp-box/pulls) 贡献代码。
|
||||
<p align="center">
|
||||
<img src="docs/_static/banner2.jpg" width="auto" height="auto" alt="ESPRESSIF">
|
||||
</p>
|
||||
|
||||
* [English Version](./README.md)
|
||||
* [Gitee 镜像仓库](https://gitee.com/EspressifSystems/esp-box)
|
||||
* [宣传视频](https://www.bilibili.com/video/BV11N4y197Qu/?spm_id_from=333.337.search-card.all.click)
|
||||
# ESP-BOX AIoT 开发框架
|
||||
|
||||
<p align="left">
|
||||
<a href="https://github.com/espressif/esp-box/blob/master/LICENSE" alt="Build examples">
|
||||
<img alt="GitHub" src="https://img.shields.io/github/license/espressif/esp-box"></a>
|
||||
<a href="https://github.com/espressif/esp-box/actions/workflows/build-examples-gh-pages-on-push.yml" alt="Build examples">
|
||||
<img src="https://github.com/espressif/esp-box/actions/workflows/build-examples-gh-pages-on-push.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/graphs/contributors" alt="Contributors">
|
||||
<img src="https://img.shields.io/github/contributors/espressif/esp-box" /></a>
|
||||
<a href="https://github.com/espressif/esp-box/releases" alt="GitHub all releases">
|
||||
<img src="https://img.shields.io/github/downloads/espressif/esp-box/total" /></a>
|
||||
</p>
|
||||
|
||||
<a href="https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-box/launchpad.toml">
|
||||
<img alt="Try it with ESP Launchpad" src="https://espressif.github.io/esp-launchpad/assets/try_with_launchpad.png" width="250" height="70">
|
||||
</a>
|
||||
|
||||
**重要提醒:**
|
||||
> 在收到 ESP32-S3-BOX-3 后,我们建议您更新内置的出厂固件,以确保拥有最新的 bug 修复。您可以使用乐鑫在线固件烧录工具 ESP Launchpad 进行此操作。截止目前,最新版本为 **ESP-BOX-3_Demo_V1.2.4**。请前往 “About Us” 页面验证设备出厂固件版本。
|
||||
|
||||
ESP-BOX 是乐鑫科技推出的面向 AIoT、边缘 AI 和 IIoT 应用的开发平台。ESP32-S3-BOX、ESP32-S3-BOX-Lite 和 ESP32-S3-BOX-3 是为该平台设计的系列开发板,它们基于乐鑫强大的 ESP32-S3 Wi-Fi + Bluetooth 5(LE) SoC 构建,并拥有紧凑美观的外壳结构。借助多功能配件和 ESP-BOX 项目内的可靠例程,这些开发板既适用于构建新项目原型,也适用于打造复杂的物联网系统,提供了形式上和功能上的完美平衡。
|
||||
|
||||
ESP-BOX 为各个领域的应用提供了开发资源,包括离线语音助手、在线 AI 聊天机器人(使用 OpenAI 和其他大型语言模型平台开发)、Matter 设备/控制器、机器人控制器、USB 主从设备、无线传感器应用以及广泛的人机交互(HMI)应用。将其加入工具箱,尽情体验各种可能性,发掘无限潜力!
|
||||
|
||||
|
||||
| 产品名称 | 产品图 | 市场状态 |
|
||||
| :-----: | :---------------------: |:---------------------: |
|
||||
| [ESP32-S3-BOX<sup> **1** </sup>](docs/hardware_overview/esp32_s3_box/hardware_overview_for_box_cn.md) | <img src="docs/_static/esp32_s3_box.png" width="200px" /> |寿命终止 <br> [用户指南](https://github.com/espressif/esp-box/blob/v0.5.0/docs/getting_started_cn.md) |
|
||||
| [ESP32-S3-BOX-Lite<sup> **1** **2** </sup>](docs/hardware_overview/esp32_s3_box_lite/hardware_overview_for_lite_cn.md) | <img src="docs/_static/esp32_s3_box_lite.png" width="200px" /> |寿命终止 <br> [用户指南](https://github.com/espressif/esp-box/blob/v0.5.0/docs/getting_started_cn.md)|
|
||||
| [ESP32-S3-BOX-3<sup> **3** </sup>](docs/hardware_overview/esp32_s3_box_3/hardware_overview_for_box_3_cn.md) | <img src="docs/_static/esp32_s3_box_3.png" width="200px" /> |[在售](https://item.taobao.com/item.htm?ft=t&id=732842971319) <br> [用户指南](./docs/getting_started_cn.md)|
|
||||
|
||||
**Note 1**: 对于 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite,我们建议您更新内置的[出厂应用固件](./docs/firmware_update_cn.md)以确保拥有最新的 bug 修复。在 Master 分支,我们将逐步对这两款开发板提供有限的支持。有关更多信息,请阅读各例程的 README。
|
||||
|
||||
**Note 2**: ESP32-S3-BOX-Lite 整个工程包括 PCB,外壳结构已开源到[立创开源硬件平台](https://oshwhub.com/esp-college/esp32-s3-box_lite),有需要复刻该项目的开发者,请自行购买 LCD 后进行工程复刻,LCD 屏[购买链接](https://item.taobao.com/item.htm?id=658634202331&spm=a312a.7700824.w4002-8715811646.9.4048605fNqggSF&skuId=5283401261405)。
|
||||
|
||||
**Note 3**: ESP32-S3-BOX-3 提供两款不同配置的套件:分别命名为 ESP32-S3-BOX-3 和 ESP32-S3-BOX-3B。ESP32-S3-BOX-3 代表标准版,配备四款蓝色配件,而 ESP32-S3-BOX-3B 代表基础版,仅提供了一款配件,适用于不需要太多不必要硬件的初学者。点击[此处](https://github.com/espressif/esp-box/blob/master/docs/getting_started_cn.md#%E5%8F%98%E4%BD%93%E8%AF%B4%E6%98%8E)了解两者区别。
|
||||
## 版本信息
|
||||
| ESP-BOX | 依赖的 ESP-IDF | 分支信息 | 支持状态 |
|
||||
| :-------: | :----------------------------------------------------------: | :----------------------------------------------------------: | ------------------------------------------------------- |
|
||||
| master | >= release/v5.1<br/>commit id: 22cfbf30c3 | Latest developing firmware <br/>esp-sr components version: v1.4.1 | 部分支持 ESP32-S3-BOX,ESP32-S3-BOX-Lite 和 ESP32-S3-BOX-3<br/>**使用 menuconfig 选择开发板**<br/>详见 Examples **README** |
|
||||
| Tag 0.5.0 | release/v5.1<br/>commit id: 22cfbf30c3 | esp-sr components version: v1.3.4 | 兼容 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite<br/>使用 menuconfig 选择开发板 |
|
||||
| Tag 0.3.0 | release/v4.4<br/>commit id: 22cfbf30c3 | esp-sr version: dev/v2.0<br/>commit id: c873a35 | 兼容 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite |
|
||||
| Tag 0.2.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.2.1/idf_patch) | esp-sr version: close v1.0<br/>commit id: 3ce34fe | 仅支持 ESP32-S3-BOX |
|
||||
| Tag 0.1.1 | Release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.1.1/idf_patch) | esp-sr version: v0.9.6<br/>commit id: 3ce34fe | 仅支持 ESP32-S3-BOX |
|
||||
|
||||
## 支持特性
|
||||
|
||||
* 即开即用的入门级边缘 AI + HMI 应用开发板
|
||||
* 基于 FreeRTOS 的四合一语音交互面板:离线语音识别、网络通信、屏幕显示、外设控制
|
||||
* 双麦克风支持远场语音交互
|
||||
* 支持高唤醒率的离线语音唤醒和命令词识别
|
||||
* 允许连续命令词识别、唤醒打断以及自定义配置 200+ 中英文命令词
|
||||
* 灵活多样的家庭自动化解决方案:Matter、Home Assistant、ESP-RainMaker
|
||||
* 可视化拖放式 GUI 开发:LVGL SquareLine Studio、Embedded Wizard 等
|
||||
* 丰富的开发框架:ESP-IDF、Arduino、PlatformIO、Circuit Python 等
|
||||
|
||||
## 开源内容
|
||||
|
||||
* [原理图与 PCB 源文件](./hardware)
|
||||
* [外壳 3D 打印源文件](./hardware)
|
||||
* [出厂固件源代码](./examples/factory_demo)
|
||||
* [示例程序源代码](./examples)
|
||||
|
||||
> 基于 [Apache 2.0](https://github.com/espressif/esp-box/blob/master/LICENSE) 开源协议,你可以免费且自由的修改、创作和分享。
|
||||
|
||||
## 内置固件使用指引
|
||||
|
||||
* 首次拿到开发板,建议先阅读产品[硬件概览](./docs/hardware_overview);
|
||||
* 接着可以查看[首次使用操作指引](./docs/getting_started_cn.md#开始使用);
|
||||
* 体验有意思的[传感器应用](./docs/getting_started_cn.md#传感器监测);
|
||||
* 体验离线语音助手功能,您可以查看[离线语音识别](./docs/getting_started_cn.md#体验离线语音识别);
|
||||
* 体验更人性化的语音交互,可查看[连续语音识别](./docs/getting_started_cn.md#连续语音识别);
|
||||
* 通过手机 APP 设置独特的语音命令词,请查看 [ESP BOX APP 操作指引](./docs/getting_started_cn.md#语音命令词自定义);
|
||||
* 如需切换语音模型语言,请查看[中英文语音模型切换](./docs/getting_started_cn.md#中英文语音模型切换);
|
||||
* 了解产品爆炸图和拆机说明,请查看[拆机教程](./docs/disassembly_tutorial.md);
|
||||
* 更新最新版本固件,请查看[固件更新说明](./docs/firmware_update_cn.md)。
|
||||
|
||||
## 开发指引
|
||||
|
||||
ESP-BOX 调用乐鑫 ESP-IDF 的包管理器 [ESP Registry](https://components.espressif.com/components?q=lcd) 中常用的组件,您可以利用这些组件构建自己的应用。
|
||||
|
||||
### 快速开始
|
||||
|
||||
* **Step 1**. 如果您首次接触 ESP-IDF 开发,建议先浏览 [ESP-IDF 编程指南](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32s3/index.html),了解乐鑫已经提供的开源驱动和组件;
|
||||
* **Step 2**. 接下来您可以详细阅读 [ESP-IDF(release/v5.1) 环境搭建指引](https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32s3/get-started/index.html#ide),一步一步完成开发环境搭建;
|
||||
* **Step 3**. 使用指令 `git clone --recursive https://github.com/espressif/esp-box.git` 下载本项目的代码,然后需要将 esp-idf 版本切换到[指定的版本](#版本信息);
|
||||
* **Step 4**. 小试牛刀,您可以尝试 [构建并烧录一个新的示例程序](./examples/image_display);
|
||||
* **Step 5**. 更进一步,您可以阅读 [ESP-BOX 技术架构说明](./docs/technical_architecture_cn.md),了解更多技术细节;
|
||||
* **Step 6**. 深入开发,您可以阅读 [ESP 语音识别应用开发指南](https://github.com/espressif/esp-sr),[ESP RainMaker 编程指南](https://docs.espressif.com/projects/esp-rainmaker/en/latest/),[LVGL UI 界面开发快速总览](https://docs.lvgl.io/8.3/);
|
||||
* **Step 7**. 扩展功能,您可以阅读 [开发板 Pmod™ 兼容接口介绍](./docs/hardware_overview) 和 [ESP-IDF API 参考手册](https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32s3/api-reference/index.html),为更多扩展设备开发驱动。
|
||||
|
||||
### 云连接开发指南
|
||||
|
||||
ESP BOX APP 基于商业版 Nova Home 应用 APP 构建,拥有精美的用户界面和更好的用户体验,但由于 Nova Home App 有限开放,客户如需项目资源,可通过 sales@espressif.com 邮件与我们联系。
|
||||
对于个人开发者,我们提供 [ESP RainMaker](https://rainmaker.espressif.com/zh-hans/) 解决方案,其中包括公开可用的开发文档和 API 指南。以下是开发资源访问路径:
|
||||
|
||||
- [ESP RainMaker 快速入门](https://rainmaker.espressif.com/docs/get-started.html)
|
||||
- [RainMaker App API 定义](https://swaggerapis.rainmaker.espressif.com)
|
||||
- [ESP RainMaker 编程指南](https://docs.espressif.com/projects/esp-rainmaker/en/latest/index.html#)
|
||||
|
||||
|
||||
### NuttX
|
||||
ESP32-S3-BOX-3 支持与 [NuttX](https://github.com/apache/nuttx/tree/master/boards/xtensa/esp32s3/esp32s3-box) 集成,提供了更多的灵活性和功能。Nuttx 是一款以其小巧、高效和实时性能而闻名的实时操作系统(RTOS),使其成为嵌入式系统的绝佳选择。
|
||||
|
||||
### 优秀开源社区项目
|
||||
我们积极搜集基于 ESP-BOX 的[优秀项目](./docs/great_projects.md),以激发更多 makers 的创新思维。我们对推动社区文化繁荣的倡导者表示由衷的感谢,并欢迎更多的开发人员为充满活力的ESP32社区贡献力量。
|
||||
|
||||
## 联系我们
|
||||
|
||||
* 如果有任何开发和使用问题,您可添加 [GitHub Issues](https://github.com/espressif/esp-box/issues) 或到 [esp32.com](https://esp32.com/) 论坛寻求帮助;
|
||||
* 如果你对 ESP-BOX 项目感兴趣,欢迎到论坛 [ESP-BOX 版块](https://www.esp32.com/viewforum.php?f=43)交流想法。
|
||||
|
||||
## 贡献示例
|
||||
|
||||
我们欢迎任何软件或硬件相关的开源贡献,如果您有任何要与我们分享的示例,请参考[贡献指南](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/contribute/index.html)后提交 [Pull Requests](https://github.com/espressif/esp-box/pulls) 贡献代码。
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
ALS
|
||||
ALS
|
||||
ANS
|
||||
ans
|
||||
co-ordinate
|
||||
co-ordinates
|
||||
compresed
|
||||
DOUT
|
||||
dout
|
||||
ERRO
|
||||
ges
|
||||
gien
|
||||
MOT
|
||||
regist
|
||||
ser
|
||||
TE
|
||||
uncompressible
|
||||
wHeigh
|
||||
@@ -1,30 +1,56 @@
|
||||
string(REGEX MATCH "factory_demo" PROJECT_IS_FACTORY_DEMO "${PROJECT_DIR}")
|
||||
|
||||
if(EXISTS ${PROJECT_DIR}/sdkconfig)
|
||||
message(STATUS "use sdkconfig")
|
||||
file(READ ${PROJECT_DIR}/sdkconfig SDKCONFIG_RULE)
|
||||
elseif(EXISTS ${PROJECT_DIR}/sdkconfig.defaults)
|
||||
message(STATUS "use sdkconfig.defaults")
|
||||
file(READ ${PROJECT_DIR}/sdkconfig.defaults SDKCONFIG_RULE)
|
||||
endif()
|
||||
|
||||
if(SDKCONFIG_RULE)
|
||||
string(REGEX MATCH "CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y" COMPILER_TARGET_IS_BOX_LITE "${SDKCONFIG_RULE}")
|
||||
string(REGEX MATCH "CONFIG_BSP_BOARD_ESP32_S3_BOX=y" COMPILER_TARGET_IS_ESP_BOX "${SDKCONFIG_RULE}")
|
||||
string(REGEX MATCH "CONFIG_BSP_BOARD_ESP32_S3_BOX_3=y" COMPILER_TARGET_IS_ESP_BOX_3 "${SDKCONFIG_RULE}")
|
||||
endif()
|
||||
|
||||
if(NOT COMPILER_TARGET_IS_BOX_LITE AND NOT COMPILER_TARGET_IS_ESP_BOX AND NOT COMPILER_TARGET_IS_ESP_BOX_3)
|
||||
message(STATUS "use Kconfig.projbuild")
|
||||
file(READ ${CMAKE_CURRENT_LIST_DIR}/Kconfig.projbuild SDKCONFIG_RULE)
|
||||
string(REGEX MATCH "default BSP_BOARD_ESP32_S3_BOX_Lite" COMPILER_TARGET_IS_BOX_LITE "${SDKCONFIG_RULE}")
|
||||
string(REGEX MATCH "default BSP_BOARD_ESP32_S3_BOX_3" COMPILER_TARGET_IS_ESP_BOX_3 "${SDKCONFIG_RULE}")
|
||||
string(REGEX MATCH "default BSP_BOARD_ESP32_S3_\\bBOX\\b$" COMPILER_TARGET_IS_ESP_BOX "${SDKCONFIG_RULE}")
|
||||
endif()
|
||||
|
||||
if(COMPILER_TARGET_IS_ESP_BOX_3)
|
||||
message(STATUS "PLATFORM ESP32_S3_BOX_3.")
|
||||
set(box_alias "-3")
|
||||
elseif(COMPILER_TARGET_IS_BOX_LITE)
|
||||
message(STATUS "PLATFORM ESP32_S3_BOX_Lite.")
|
||||
set(box_alias "-lite")
|
||||
set(bsp_src "src/storage/bsp_sdcard.c")
|
||||
elseif(COMPILER_TARGET_IS_ESP_BOX)
|
||||
message(STATUS "PLATFORM ESP32_S3_BOX.")
|
||||
set(bsp_src "src/storage/bsp_sdcard.c")
|
||||
else()
|
||||
message(FATAL_ERROR "PLATFORM unknown.")
|
||||
endif()
|
||||
|
||||
set(requires "driver" "fatfs")
|
||||
set(priv_requires "esp-box${box_alias}")
|
||||
|
||||
if (PROJECT_IS_FACTORY_DEMO AND COMPILER_TARGET_IS_ESP_BOX_3)
|
||||
list(APPEND priv_requires "aht20" "at581x")
|
||||
list(APPEND bsp_src "src/boards/esp32_bsp_sensor.c")
|
||||
else()
|
||||
list(APPEND bsp_src "src/boards/esp32_bsp_no_sensor.c")
|
||||
endif()
|
||||
|
||||
list(APPEND bsp_src "src/boards/esp32_bsp_board.c")
|
||||
|
||||
idf_component_register(
|
||||
SRC_DIRS
|
||||
"src/boards"
|
||||
"src/peripherals"
|
||||
"src/storage"
|
||||
"src/codec/es7210"
|
||||
"src/codec/es7243e"
|
||||
"src/codec/es8156"
|
||||
"src/codec/es8311"
|
||||
"src/codec/es8388"
|
||||
INCLUDE_DIRS
|
||||
"src/boards"
|
||||
"include"
|
||||
"src/codec/es7210"
|
||||
"src/codec/es7243e"
|
||||
"src/codec/es8156"
|
||||
"src/codec/es8311"
|
||||
"src/codec/es8388"
|
||||
"src/codec/include"
|
||||
REQUIRES
|
||||
iot_button
|
||||
esp_hid
|
||||
esp_lcd
|
||||
fatfs
|
||||
i2c_bus
|
||||
i2c_devices
|
||||
spiffs)
|
||||
SRCS ${bsp_src}
|
||||
INCLUDE_DIRS "src/boards" "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
PRIV_REQUIRES ${priv_requires}
|
||||
REQUIRES ${requires})
|
||||
|
||||
@@ -1,23 +1,115 @@
|
||||
menu "HMI Board Config"
|
||||
choice BSP_LCD_BOARD
|
||||
prompt "Select BSP board"
|
||||
default BSP_BOARD_ESP32_S3_BOX_3
|
||||
|
||||
config BSP_BOARD_ESP32_S3_BOX
|
||||
bool "BSP board ESP32-S3-BOX"
|
||||
|
||||
config BSP_BOARD_ESP32_S3_BOX_Lite
|
||||
bool "BSP board ESP32-S3-BOX-Lite"
|
||||
|
||||
choice LCD_INTERFACE
|
||||
prompt "Select LCD interface"
|
||||
depends on ESP_CUSTOM_BOARD
|
||||
default LCD_INTERFACE_I80
|
||||
help
|
||||
Select LCD interface of custom board
|
||||
|
||||
config LCD_INTERFACE_I2C
|
||||
bool "LCD_INTERFACE_I2C"
|
||||
config LCD_INTERFACE_I80
|
||||
bool "LCD_INTERFACE_I80"
|
||||
config LCD_INTERFACE_SPI
|
||||
bool "LCD_INTERFACE_SPI"
|
||||
config BSP_BOARD_ESP32_S3_BOX_3
|
||||
bool "BSP board ESP32-S3-BOX-3"
|
||||
|
||||
endchoice
|
||||
endmenu
|
||||
|
||||
menu "Power Save Configuration"
|
||||
depends on BSP_BOARD_ESP32_S3_BOX_3
|
||||
config EXAMPLE_WIFI_LISTEN_INTERVAL
|
||||
int "WiFi listen interval"
|
||||
default 3
|
||||
help
|
||||
Interval for station to listen to beacon from AP. The unit of listen interval is one beacon interval.
|
||||
For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen
|
||||
to beacon is 300 ms.
|
||||
|
||||
|
||||
endmenu
|
||||
config EXAMPLE_WIFI_BEACON_TIMEOUT
|
||||
int "WiFi beacon timeout"
|
||||
default 6
|
||||
range 6 30
|
||||
help
|
||||
For Station, If the station does not receive a beacon frame from the connected SoftAP during the
|
||||
inactive time, disconnect from SoftAP. Default 6s.
|
||||
|
||||
choice EXAMPLE_POWER_SAVE_MODE
|
||||
prompt "power save mode"
|
||||
default EXAMPLE_POWER_SAVE_MIN_MODEM
|
||||
help
|
||||
Power save mode for the esp32 to use. Modem sleep mode includes minimum and maximum power save modes.
|
||||
In minimum power save mode, station wakes up every DTIM to receive beacon. Broadcast data will not be
|
||||
lost because it is transmitted after DTIM. However, it can not save much more power if DTIM is short
|
||||
for DTIM is determined by AP.
|
||||
In maximum power save mode, station wakes up every listen interval to receive beacon. Broadcast data
|
||||
may be lost because station may be in sleep state at DTIM time. If listen interval is longer, more power
|
||||
is saved but broadcast data is more easy to lose.
|
||||
|
||||
config EXAMPLE_POWER_SAVE_NONE
|
||||
bool "none"
|
||||
config EXAMPLE_POWER_SAVE_MIN_MODEM
|
||||
bool "minimum modem"
|
||||
config EXAMPLE_POWER_SAVE_MAX_MODEM
|
||||
bool "maximum modem"
|
||||
endchoice
|
||||
|
||||
choice EXAMPLE_MAX_CPU_FREQ
|
||||
prompt "Maximum CPU frequency"
|
||||
default EXAMPLE_MAX_CPU_FREQ_80
|
||||
depends on PM_ENABLE
|
||||
help
|
||||
Maximum CPU frequency to use for dynamic frequency scaling.
|
||||
|
||||
config EXAMPLE_MAX_CPU_FREQ_80
|
||||
bool "80 MHz"
|
||||
config EXAMPLE_MAX_CPU_FREQ_120
|
||||
bool "120 MHz"
|
||||
depends on IDF_TARGET_ESP32C2
|
||||
config EXAMPLE_MAX_CPU_FREQ_160
|
||||
bool "160 MHz"
|
||||
depends on !IDF_TARGET_ESP32C2
|
||||
config EXAMPLE_MAX_CPU_FREQ_240
|
||||
bool "240 MHz"
|
||||
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_MAX_CPU_FREQ_MHZ
|
||||
int
|
||||
default 80 if EXAMPLE_MAX_CPU_FREQ_80
|
||||
default 120 if EXAMPLE_MAX_CPU_FREQ_120
|
||||
default 160 if EXAMPLE_MAX_CPU_FREQ_160
|
||||
default 240 if EXAMPLE_MAX_CPU_FREQ_240
|
||||
|
||||
choice EXAMPLE_MIN_CPU_FREQ
|
||||
prompt "Minimum CPU frequency"
|
||||
default EXAMPLE_MIN_CPU_FREQ_10M
|
||||
depends on PM_ENABLE
|
||||
help
|
||||
Minimum CPU frequency to use for dynamic frequency scaling.
|
||||
Should be set to XTAL frequency or XTAL frequency divided by integer.
|
||||
|
||||
config EXAMPLE_MIN_CPU_FREQ_40M
|
||||
bool "40 MHz (use with 40MHz XTAL)"
|
||||
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO
|
||||
config EXAMPLE_MIN_CPU_FREQ_20M
|
||||
bool "20 MHz (use with 40MHz XTAL)"
|
||||
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO
|
||||
config EXAMPLE_MIN_CPU_FREQ_10M
|
||||
bool "10 MHz (use with 40MHz XTAL)"
|
||||
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO
|
||||
config EXAMPLE_MIN_CPU_FREQ_26M
|
||||
bool "26 MHz (use with 26MHz XTAL)"
|
||||
depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO
|
||||
config EXAMPLE_MIN_CPU_FREQ_13M
|
||||
bool "13 MHz (use with 26MHz XTAL)"
|
||||
depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_MIN_CPU_FREQ_MHZ
|
||||
int
|
||||
default 40 if EXAMPLE_MIN_CPU_FREQ_40M
|
||||
default 20 if EXAMPLE_MIN_CPU_FREQ_20M
|
||||
default 10 if EXAMPLE_MIN_CPU_FREQ_10M
|
||||
default 26 if EXAMPLE_MIN_CPU_FREQ_26M
|
||||
default 13 if EXAMPLE_MIN_CPU_FREQ_13M
|
||||
endmenu
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
|
||||
esp_codec_dev:
|
||||
public: true
|
||||
version: "1.1.0"
|
||||
|
||||
espressif/button:
|
||||
version: "^3.5.0"
|
||||
|
||||
espressif/esp-box:
|
||||
version: "3.0.*"
|
||||
require: "no"
|
||||
|
||||
espressif/esp-box-lite:
|
||||
version: "2.0.*"
|
||||
require: "no"
|
||||
|
||||
espressif/esp-box-3:
|
||||
version: "1.1.*"
|
||||
require: "no"
|
||||
+199
-148
@@ -10,98 +10,35 @@
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/adc.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_types.h"
|
||||
#include "audio_hal.h"
|
||||
#include "driver/i2s_std.h"
|
||||
|
||||
#include "bsp/esp-bsp.h"
|
||||
#include "iot_button.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BOARD_S3_BOX,
|
||||
BOARD_S3_BOX_LITE,
|
||||
} boards_id_t;
|
||||
#define BSP_I2C_EXPAND_SCL (GPIO_NUM_40)
|
||||
#define BSP_I2C_EXPAND_SDA (GPIO_NUM_41)
|
||||
|
||||
#define BSP_RADAR_OUT_IO (GPIO_NUM_21)
|
||||
#define BSP_IR_CTRL_GPIO (GPIO_NUM_44)
|
||||
#define BSP_IR_TX_GPIO (GPIO_NUM_39)
|
||||
#define BSP_IR_RX_GPIO (GPIO_NUM_38)
|
||||
|
||||
typedef enum {
|
||||
BOARD_BTN_ID_BOOT = 0, // The index is the same as the sequence number of the board_button_t array
|
||||
BOARD_BTN_ID_PREV = 1,
|
||||
BOARD_BTN_ID_ENTER = 2,
|
||||
BOARD_BTN_ID_NEXT = 3,
|
||||
} board_btn_id_t;
|
||||
BOTTOM_ID_SENSOR, /*!< bottom is ESP32-S3-BOX-3-SENSOR */
|
||||
BOTTOM_ID_UNKNOW, /*!< bottom isn't ESP32-S3-BOX-3-SENSOR */
|
||||
BOTTOM_ID_LOST, /*!< bottom ESP32-S3-BOX-3-SENSOR is connect when poweron, and lost */
|
||||
} bottom_id_t;
|
||||
|
||||
typedef struct {
|
||||
board_btn_id_t id;
|
||||
uint32_t vol; // for adc button
|
||||
gpio_num_t io_num; // for gpio button, Set GPIO_NUM_NC to indicate this button is adc button
|
||||
bool active_level; // for gpio button
|
||||
} board_button_t;
|
||||
|
||||
typedef struct {
|
||||
gpio_num_t row1[4]; //The first row
|
||||
gpio_num_t row2[4];
|
||||
gpio_num_t row1[4]; /*!< first row */
|
||||
gpio_num_t row2[4]; /*!< second row */
|
||||
} pmod_pins_t;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief ESP-Dev-Board LCD GPIO defination and config
|
||||
*
|
||||
*/
|
||||
bool FUNC_LCD_EN ;
|
||||
int LCD_BUS_WIDTH ;
|
||||
int LCD_IFACE_SPI ;
|
||||
int LCD_DISP_IC_ST ;
|
||||
int LCD_WIDTH ;
|
||||
int LCD_HEIGHT ;
|
||||
int LCD_FREQ ;
|
||||
int LCD_CMD_BITS ;
|
||||
int LCD_PARAM_BITS ;
|
||||
spi_host_device_t LCD_HOST;
|
||||
|
||||
bool LCD_SWAP_XY ;
|
||||
bool LCD_MIRROR_X ;
|
||||
bool LCD_MIRROR_Y ;
|
||||
bool LCD_COLOR_INV ;
|
||||
esp_lcd_color_space_t LCD_COLOR_SPACE;
|
||||
|
||||
int GPIO_LCD_BL ;
|
||||
int GPIO_LCD_BL_ON ;
|
||||
int GPIO_LCD_CS ;
|
||||
int GPIO_LCD_RST ;
|
||||
int GPIO_LCD_DC ;
|
||||
int GPIO_LCD_CLK ;
|
||||
int GPIO_LCD_DIN ;
|
||||
int GPIO_LCD_DOUT ;
|
||||
int GPIO_LCD_D00 ; // only use for OCTAL SPI(aka 8080 interface)
|
||||
int GPIO_LCD_D01 ;
|
||||
int GPIO_LCD_D02 ;
|
||||
int GPIO_LCD_D03 ;
|
||||
int GPIO_LCD_D04 ;
|
||||
int GPIO_LCD_D05 ;
|
||||
int GPIO_LCD_D06 ;
|
||||
int GPIO_LCD_D07 ;
|
||||
|
||||
bool BSP_INDEV_IS_TP;
|
||||
bool TOUCH_PANEL_SWAP_XY;
|
||||
bool TOUCH_PANEL_INVERSE_X;
|
||||
bool TOUCH_PANEL_INVERSE_Y;
|
||||
int TOUCH_PANEL_I2C_ADDR;
|
||||
bool TOUCH_WITH_HOME_BUTTON;
|
||||
|
||||
bool BSP_BUTTON_EN;
|
||||
adc1_channel_t BUTTON_ADC_CHAN; // only use for adc button
|
||||
const board_button_t *BUTTON_TAB;
|
||||
uint8_t BUTTON_TAB_LEN;
|
||||
|
||||
/**
|
||||
* @brief ESP-Dev-Board I2C GPIO defineation
|
||||
*
|
||||
*/
|
||||
bool FUNC_I2C_EN ;
|
||||
int GPIO_I2C_SCL ;
|
||||
int GPIO_I2C_SDA ;
|
||||
|
||||
/**
|
||||
* @brief ESP-Dev-Board SDMMC GPIO defination
|
||||
*
|
||||
@@ -146,84 +83,156 @@ typedef struct {
|
||||
int GPIO_RMT_IR ;
|
||||
int GPIO_RMT_LED ;
|
||||
|
||||
/**
|
||||
* @brief ESP-Dev-Board I2S GPIO defination
|
||||
*
|
||||
*/
|
||||
bool FUNC_I2S_EN ;
|
||||
int GPIO_I2S_LRCK ;
|
||||
int GPIO_I2S_MCLK ;
|
||||
int GPIO_I2S_SCLK ;
|
||||
int GPIO_I2S_SDIN ;
|
||||
int GPIO_I2S_DOUT ;
|
||||
int CODEC_I2C_ADDR;
|
||||
int AUDIO_ADC_I2C_ADDR;
|
||||
|
||||
int IMU_I2C_ADDR;
|
||||
|
||||
/**
|
||||
* @brief ESP32-S3-HMI-DevKit power control IO
|
||||
*
|
||||
* @note Some power control pins might not be listed yet
|
||||
*
|
||||
*/
|
||||
int FUNC_PWR_CTRL ;
|
||||
int GPIO_PWR_CTRL ;
|
||||
int GPIO_PWR_ON_LEVEL ;
|
||||
|
||||
int GPIO_MUTE_NUM ;
|
||||
int GPIO_MUTE_LEVEL ;
|
||||
|
||||
const pmod_pins_t *PMOD1;
|
||||
const pmod_pins_t *PMOD2;
|
||||
|
||||
} board_res_desc_t;
|
||||
|
||||
/**
|
||||
* @brief Power module of dev board. This can be expanded in the future.
|
||||
* @brief Get sleep mode
|
||||
*
|
||||
* @return
|
||||
* - true: sleep mode
|
||||
* - false: nornal mode
|
||||
*/
|
||||
typedef enum {
|
||||
POWER_MODULE_LCD = 1, /*!< LCD power control */
|
||||
POWER_MODULE_AUDIO, /*!< Audio PA power control */
|
||||
POWER_MODULE_ALL = 0xff, /*!< All module power control */
|
||||
} power_module_t;
|
||||
typedef bool (*bsp_sys_get_sleep_mode)();
|
||||
|
||||
/**
|
||||
* @brief Get radar status
|
||||
*
|
||||
* @return
|
||||
* - true: active
|
||||
* - false: passive
|
||||
*/
|
||||
typedef bool (*bsp_bottom_get_radar_status)();
|
||||
|
||||
/**
|
||||
* @brief Set radar onoff
|
||||
*
|
||||
* @param enable: Enable or disable radar module
|
||||
*/
|
||||
typedef void (*bsp_bottom_set_radar_enable)(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Get bottom status
|
||||
*
|
||||
* @return
|
||||
* - BOTTOM_ID_SENSOR: sensor bottom connected
|
||||
* - BOTTOM_ID_LOST: sensor bottom lost
|
||||
* - BOTTOM_ID_UNKNOW: unknow
|
||||
*/
|
||||
typedef bottom_id_t (*bsp_sys_get_bottom_id)();
|
||||
|
||||
/**
|
||||
* @brief Get temp and humidity data
|
||||
*
|
||||
* @param temperature: Output temperature
|
||||
* @param humidity: Output humidity
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: read successfully
|
||||
* - ESP_FAIL: read failed
|
||||
*/
|
||||
typedef esp_err_t (*bsp_bottom_get_humiture)(float *temperature, float *humidity);
|
||||
|
||||
/**
|
||||
* @brief Player set mute.
|
||||
*
|
||||
* @param enable: true or false
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_mute_set(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Player set volume.
|
||||
*
|
||||
* @param volume: volume set
|
||||
* @param volume_set: volume set response
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_volume_set(int volume, int *volume_set);
|
||||
|
||||
/**
|
||||
* @brief Stop I2S function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_dev_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Resume I2S function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_dev_resume(void);
|
||||
|
||||
/**
|
||||
* @brief Set I2S format to codec.
|
||||
*
|
||||
* @param rate: Sample rate of sample
|
||||
* @param bits_cfg: Bit lengths of one channel data
|
||||
* @param ch: Channels of sample
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_set_fs(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch);
|
||||
|
||||
/**
|
||||
* @brief Read data from recoder.
|
||||
*
|
||||
* @param audio_buffer: The pointer of receiving data buffer
|
||||
* @param len: Max data buffer length
|
||||
* @param bytes_read: Byte number that actually be read, can be NULL if not needed
|
||||
* @param timeout_ms: Max block time
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_i2s_read(void *audio_buffer, size_t len, size_t *bytes_read, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Write data to player.
|
||||
*
|
||||
* @param audio_buffer: The pointer of sent data buffer
|
||||
* @param len: Max data buffer length
|
||||
* @param bytes_written: Byte number that actually be sent, can be NULL if not needed
|
||||
* @param timeout_ms: Max block time
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_i2s_write(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms);
|
||||
|
||||
typedef struct {
|
||||
bsp_sys_get_sleep_mode get_sleep_mode;
|
||||
bsp_sys_get_bottom_id get_bottom_id;
|
||||
|
||||
bsp_bottom_set_radar_enable set_radar_enable;
|
||||
bsp_bottom_get_radar_status get_radar_status;
|
||||
bsp_bottom_get_humiture get_humiture;
|
||||
} bsp_bottom_property_t;
|
||||
|
||||
typedef struct {
|
||||
boards_id_t id;
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* @brief Special config for dev board
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t (*board_init)(void);
|
||||
|
||||
/**
|
||||
* @brief Control power of dev board
|
||||
*
|
||||
* @param module Refer to `power_module_t`
|
||||
* @param on Turn on or off specified power module. On if true
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t (*board_power_ctrl)(power_module_t module, bool on);
|
||||
|
||||
/**
|
||||
* @brief Get board description
|
||||
*
|
||||
* @return pointer of board_res_desc_t
|
||||
*/
|
||||
const board_res_desc_t *(*board_get_res_desc)(void);
|
||||
|
||||
const board_res_desc_t *board_desc; /*!< Get board description */
|
||||
} boards_info_t;
|
||||
|
||||
/**
|
||||
* @brief Special config for dev board
|
||||
* @brief Special config for board
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
@@ -246,15 +255,57 @@ const boards_info_t *bsp_board_get_info(void);
|
||||
const board_res_desc_t *bsp_board_get_description(void);
|
||||
|
||||
/**
|
||||
* @brief Control power of dev board
|
||||
* @brief Get the sensor operation function
|
||||
*
|
||||
* @return pointer of bsp_bottom_property_t
|
||||
*/
|
||||
bsp_bottom_property_t *bsp_board_get_sensor_handle(void);
|
||||
|
||||
/**
|
||||
* @brief Call default button init code
|
||||
*
|
||||
* @param module Refer to `power_module_t`
|
||||
* @param on Turn on or off specified power module. On if true
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_board_power_ctrl(power_module_t module, bool on);
|
||||
esp_err_t bsp_btn_init(void);
|
||||
|
||||
/**
|
||||
* @brief Register the button event callback function.
|
||||
*
|
||||
* @param btn: A button handle to register
|
||||
* @param event: Button event
|
||||
* @param callback: Callback function.
|
||||
* @param user_data: user data
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is invalid.
|
||||
*/
|
||||
esp_err_t bsp_btn_register_callback(bsp_button_t btn, button_event_t event, button_cb_t callback, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Unregister the button event callback function.
|
||||
*
|
||||
* @param btn: A button handle to unregister
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is invalid.
|
||||
*/
|
||||
esp_err_t bsp_btn_rm_all_callback(bsp_button_t btn);
|
||||
|
||||
/**
|
||||
* @brief Unregister the button event callback function.
|
||||
*
|
||||
* @param btn: A button handle to unregister
|
||||
* @param event: Unregister event
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is invalid.
|
||||
*/
|
||||
esp_err_t bsp_btn_rm_event_callback(bsp_button_t btn, size_t event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "button.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Call default button init code
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_btn_init_default(void);
|
||||
|
||||
/**
|
||||
* @brief Register callback for button event
|
||||
*
|
||||
* @param btn_id 0 based index of the button
|
||||
* @param event Event of button to register
|
||||
* @param callback Callback function
|
||||
* @param user_data User data
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_btn_register_callback(board_btn_id_t btn_id, button_event_t event, button_cb_t callback, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Remove all callbacks of the button
|
||||
*
|
||||
* @param btn_id 0 based index of the button
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_INVALID_STATE: button not be initialize
|
||||
* - ESP_ERR_INVALID_ARG: button id error
|
||||
*/
|
||||
esp_err_t bsp_btn_rm_all_callback(board_btn_id_t btn_id);
|
||||
|
||||
/**
|
||||
* @brief Get the press state of the button
|
||||
*
|
||||
* @param btn_id 0 based index of the button
|
||||
*
|
||||
* @return
|
||||
* - TRUE pressed state
|
||||
* - FALSE released state
|
||||
*/
|
||||
bool bsp_btn_get_state(board_btn_id_t btn_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "audio_hal.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CODEC_DEV_ES7210 = 0x01,
|
||||
CODEC_DEV_ES7243 = 0x02,
|
||||
CODEC_DEV_ES8156 = 0x04,
|
||||
CODEC_DEV_ES8311 = 0x08,
|
||||
// CODEC_DEV_ES8388,
|
||||
} codec_dev_t;
|
||||
|
||||
/**
|
||||
* @brief Detect Codecs on the board
|
||||
*
|
||||
* @param devices [out] bitmask of detected codec devices, see codec_dev_t
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_NOT_FOUND: Codec not detected on I2C bus
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_detect(uint32_t *devices);
|
||||
|
||||
/**
|
||||
* @brief Initialize Codec on dev board
|
||||
*
|
||||
* @param sample_rate
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_NOT_FOUND: Codec not detected on I2C bus
|
||||
* - ESP_ERR_NOT_SUPPORTED: Unsupported Codec or t
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_init(audio_hal_iface_samples_t sample_rate);
|
||||
|
||||
/**
|
||||
* @brief Set output volume of Codec
|
||||
*
|
||||
* @param volume volume to set
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_NOT_FOUND: Codec not detected on I2C bus
|
||||
*/
|
||||
esp_err_t bsp_codec_set_voice_volume(uint8_t volume);
|
||||
|
||||
/**
|
||||
* @brief Set input microphone gain of Codec
|
||||
*
|
||||
* @param channel_mask mask of channel
|
||||
* @param volume volume to set
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_NOT_FOUND: Codec not detected on I2C bus
|
||||
*/
|
||||
esp_err_t bsp_codec_set_voice_gain(uint8_t channel_mask, uint8_t volume);
|
||||
|
||||
/**
|
||||
* @brief Configure I2S format
|
||||
*
|
||||
* @param fmt: I2S format
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_FAIL: Fail
|
||||
*/
|
||||
esp_err_t bsp_codec_set_fmt(audio_hal_iface_format_t fmt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_err.h"
|
||||
#include "i2c_bus.h"
|
||||
|
||||
#ifndef I2C_ACK_CHECK_EN
|
||||
#define I2C_ACK_CHECK_EN 1
|
||||
#endif
|
||||
|
||||
#ifndef I2C_ACK_CHECK_DIS
|
||||
#define I2C_ACK_CHECK_DIS 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize I2C bus of dev board
|
||||
*
|
||||
* @param i2c_num I2C port num
|
||||
* @param clk_speed I2C clock speed
|
||||
* @param scl_io
|
||||
* @param sda_io
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_i2c_init(i2c_port_t i2c_num, uint32_t clk_speed, gpio_num_t scl_io, gpio_num_t sda_io);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize I2C bus
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t bsp_i2c_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Prob given address on I2C bus
|
||||
*
|
||||
* @param addr 7 bit Address to prob
|
||||
* @return
|
||||
* - ESP_OK: Device found on I2C bus
|
||||
* - ESP_ERR_INVALID_ARG: Invalid I2C address
|
||||
* - ESP_ERR_INVALID_STATE: I2C bus not initialized
|
||||
* - Others: Device not found on I2C bus or error occurred during I2C transmission
|
||||
*/
|
||||
esp_err_t bsp_i2c_probe_addr(uint8_t addr);
|
||||
|
||||
/**
|
||||
* @brief Add device to I2C bus
|
||||
*
|
||||
* @param i2c_device_handle Handle of I2C device
|
||||
* @param dev_addr 7 bit address of device
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - Others: Refer to error code `esp_err.h`.
|
||||
*/
|
||||
esp_err_t bsp_i2c_add_device(i2c_bus_device_handle_t *i2c_device_handle, uint8_t dev_addr);
|
||||
|
||||
/**
|
||||
* @brief Get handle of I2C bus
|
||||
*
|
||||
* @return Handle of i2c bus. NULL if not or failed initialized.
|
||||
*/
|
||||
i2c_bus_handle_t bsp_i2c_bus_get_handle(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "driver/i2s.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Init I2S bus
|
||||
*
|
||||
* @param i2s_num I2S port num
|
||||
* @param sample_rate Audio sample rate. For I2S signal, it refers to LRCK/WS frequency
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_i2s_init(i2s_port_t i2s_num, uint32_t sample_rate);
|
||||
|
||||
/**
|
||||
* @brief Deinit I2S bus
|
||||
*
|
||||
* @param i2s_num I2S port num
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_i2s_deinit(i2s_port_t i2s_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "bsp_board.h"
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef bool (*bsp_lcd_trans_cb_t)(esp_lcd_panel_io_handle_t, esp_lcd_panel_io_event_data_t *, void *);
|
||||
|
||||
/**
|
||||
* @brief Init LCD
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_lcd_init(void);
|
||||
|
||||
/**
|
||||
* @brief Deinit LCD
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_lcd_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Flush LCD
|
||||
*
|
||||
* @param x1 Start index on x-axis (x1 included)
|
||||
* @param y1 Start index on y-axis (y1 included)
|
||||
* @param x2 End index on x-axis (x2 not included)
|
||||
* @param y2 End index on y-axis (y2 not included)
|
||||
* @param p_data RGB color data that will be dumped to the specific range
|
||||
* @param ticks_to_wait Maximum blocking time
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_TIMEOUT: Timeout waiting for previous transaction finished
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_lcd_flush(int x1, int y1, int x2, int y2, const void *p_data, TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Wait for a a single flush transaction finished
|
||||
*
|
||||
* @param ticks_to_wait Maximum blocking time
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_lcd_flush_wait_done(TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Set callback function when a single flush transaction is finished
|
||||
*
|
||||
* @param trans_done_cb Callback function
|
||||
* @param data User data
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_lcd_set_cb(bool (*trans_done_cb)(void *), void *data);
|
||||
|
||||
/**
|
||||
* @brief Deinit LCD with SPI interface
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_spi_lcd_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Set backlight
|
||||
*
|
||||
* @param en 0: OFF, other: ON
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_lcd_set_backlight(bool en);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -15,7 +15,7 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @brief Init SD crad
|
||||
*
|
||||
*
|
||||
* @param mount_point Path where partition should be registered (e.g. "/sdcard")
|
||||
* @param max_files Maximum number of files which can be open at the same time
|
||||
* @return
|
||||
@@ -29,7 +29,7 @@ esp_err_t bsp_sdcard_init(char *mount_point, size_t max_files);
|
||||
|
||||
/**
|
||||
* @brief Init SD crad with default config
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_STATE If esp_vfs_fat_register was already called
|
||||
@@ -41,9 +41,9 @@ esp_err_t bsp_sdcard_init_default(void);
|
||||
|
||||
/**
|
||||
* @brief Deinit SD card
|
||||
*
|
||||
*
|
||||
* @param mount_point Path where partition was registered (e.g. "/sdcard")
|
||||
* @return
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
@@ -51,57 +51,13 @@ esp_err_t bsp_sdcard_deinit(char *mount_point);
|
||||
|
||||
/**
|
||||
* @brief Deinit SD card initialized by `bsp_sdcard_init_default`
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_sdcard_deinit_default(void);
|
||||
|
||||
/**
|
||||
* @brief Init SPIFFS
|
||||
*
|
||||
* @param partition_label Label of the partition which should be used
|
||||
* @param mount_point Path where partition should be registered (e.g. "/sdcard")
|
||||
* @param max_files Maximum number of files which can be open at the same time
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_NO_MEM Objects could not be allocated
|
||||
* - ESP_ERR_INVALID_STATE Already mounted or partition is encrypted
|
||||
* - ESP_ERR_NOT_FOUND Partition for SPIFFS was not found
|
||||
* - ESP_FAIL Mount or format fails
|
||||
* - Others Fail
|
||||
*/
|
||||
esp_err_t bsp_spiffs_init(char *partition_label, char *mount_point, size_t max_files);
|
||||
|
||||
/**
|
||||
* @brief Init SPIFFS with default config
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_spiffs_init_default(void);
|
||||
|
||||
/**
|
||||
* @brief Deinit SPIFFS
|
||||
*
|
||||
* @param partition_label Label of the partition which was used
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_spiffs_deinit(char *partition_label);
|
||||
|
||||
/**
|
||||
* @brief Deinit SPIFFS initialized by `bsp_spiffs_init_default`
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_spiffs_deinit_default(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief init sensor module
|
||||
*
|
||||
*/
|
||||
esp_err_t bsp_sensor_init(bsp_bottom_property_t *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "esp_log.h"
|
||||
#include "bsp_board.h"
|
||||
#include "bsp_i2c.h"
|
||||
#include "bsp_i2s.h"
|
||||
#include "bsp_codec.h"
|
||||
#include "esp32_s3_box.h"
|
||||
#include "esp32_s3_box_lite.h"
|
||||
|
||||
static const char *TAG = "bsp boards";
|
||||
|
||||
static const boards_info_t g_boards_info[] = {
|
||||
{BOARD_S3_BOX, "S3_BOX", bsp_board_s3_box_init, bsp_board_s3_box_power_ctrl, bsp_board_s3_box_get_res_desc},
|
||||
{BOARD_S3_BOX_LITE, "S3_BOX_LITE", bsp_board_s3_box_lite_init, bsp_board_s3_box_lite_power_ctrl, bsp_board_s3_box_lite_get_res_desc},
|
||||
};
|
||||
static boards_info_t *g_board = NULL;
|
||||
|
||||
static esp_err_t bsp_board_detect()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
for (size_t i = 0; i < sizeof(g_boards_info) / sizeof(boards_info_t); i++) {
|
||||
const board_res_desc_t *brd = g_boards_info[i].board_get_res_desc();
|
||||
/*!< Initialize I2C bus, used for TP ,audio codec and IMU */
|
||||
bsp_i2c_init(I2C_NUM_0, 400 * 1000, brd->GPIO_I2C_SCL, brd->GPIO_I2C_SDA);
|
||||
uint32_t codecs = 0;
|
||||
bsp_codec_detect(&codecs);
|
||||
|
||||
if ((CODEC_DEV_ES7210 | CODEC_DEV_ES8311) == codecs) {
|
||||
g_board = (boards_info_t *)&g_boards_info[BOARD_S3_BOX];
|
||||
} else if ((CODEC_DEV_ES7243 | CODEC_DEV_ES8156) == codecs) {
|
||||
g_board = (boards_info_t *)&g_boards_info[BOARD_S3_BOX_LITE];
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Can't Detect a correct board");
|
||||
bsp_i2c_deinit();
|
||||
ret = ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
if (g_board) {
|
||||
ESP_LOGI(TAG, "Detected board: [%s]", g_board->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const boards_info_t *bsp_board_get_info(void)
|
||||
{
|
||||
return g_board;
|
||||
}
|
||||
|
||||
const board_res_desc_t *bsp_board_get_description(void)
|
||||
{
|
||||
return g_board->board_get_res_desc();
|
||||
}
|
||||
|
||||
esp_err_t bsp_board_init(void)
|
||||
{
|
||||
if (ESP_OK == bsp_board_detect()) {
|
||||
return g_board->board_init();
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t bsp_board_power_ctrl(power_module_t module, bool on)
|
||||
{
|
||||
if (g_board) {
|
||||
return g_board->board_power_ctrl(module, on);
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
#include "bsp/esp-bsp.h"
|
||||
#include "bsp_board.h"
|
||||
#include "bsp_board_priv.h"
|
||||
|
||||
#define CODEC_DEFAULT_SAMPLE_RATE (16000)
|
||||
#define CODEC_DEFAULT_BIT_WIDTH (16)
|
||||
#define CODEC_DEFAULT_ADC_VOLUME (24.0)
|
||||
#define CODEC_DEFAULT_CHANNEL (2)
|
||||
|
||||
static const pmod_pins_t g_pmod[2] = {
|
||||
{
|
||||
{BSP_PMOD2_IO5, BSP_PMOD2_IO6, BSP_PMOD2_IO7, BSP_PMOD2_IO8},
|
||||
{BSP_PMOD2_IO1, BSP_PMOD2_IO2, BSP_PMOD2_IO3, BSP_PMOD2_IO4},
|
||||
},
|
||||
{
|
||||
{BSP_PMOD1_IO5, BSP_PMOD1_IO6, BSP_PMOD1_IO7, BSP_PMOD1_IO8},
|
||||
{BSP_PMOD1_IO1, BSP_PMOD1_IO2, BSP_PMOD1_IO3, BSP_PMOD1_IO4},
|
||||
},
|
||||
};
|
||||
|
||||
static const board_res_desc_t g_board_box_res = {
|
||||
|
||||
.FUNC_SDMMC_EN = (1),
|
||||
.SDMMC_BUS_WIDTH = (4),
|
||||
.GPIO_SDMMC_CLK = (BSP_PMOD2_IO3),
|
||||
.GPIO_SDMMC_CMD = (BSP_PMOD2_IO2),
|
||||
.GPIO_SDMMC_D0 = (BSP_PMOD2_IO8),
|
||||
.GPIO_SDMMC_D1 = (BSP_PMOD2_IO4),
|
||||
.GPIO_SDMMC_D2 = (BSP_PMOD2_IO1),
|
||||
.GPIO_SDMMC_D3 = (BSP_PMOD2_IO5),
|
||||
.GPIO_SDMMC_DET = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_SDSPI_EN = (0),
|
||||
.SDSPI_HOST = (SPI2_HOST),
|
||||
.GPIO_SDSPI_CS = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_SCLK = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_MISO = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_MOSI = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_SPI_EN = (0),
|
||||
.GPIO_SPI_CS = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_MISO = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_MOSI = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_SCLK = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_RMT_EN = (0),
|
||||
.GPIO_RMT_IR = (GPIO_NUM_NC),
|
||||
.GPIO_RMT_LED = (GPIO_NUM_39),
|
||||
|
||||
.PMOD1 = &g_pmod[0],
|
||||
.PMOD2 = &g_pmod[1],
|
||||
};
|
||||
|
||||
static esp_codec_dev_handle_t play_dev_handle;
|
||||
static esp_codec_dev_handle_t record_dev_handle;
|
||||
|
||||
static button_handle_t *g_btn_handle = NULL;
|
||||
static bsp_bottom_property_t g_bottom_handle;
|
||||
|
||||
static const boards_info_t g_boards_info = {
|
||||
#ifdef CONFIG_BSP_BOARD_ESP32_S3_BOX_3
|
||||
.name = "S3_BOX_3",
|
||||
#elif CONFIG_BSP_BOARD_ESP32_S3_BOX
|
||||
.name = "S3_BOX",
|
||||
#else
|
||||
.name = "S3_BOX_LITE",
|
||||
#endif
|
||||
.board_desc = &g_board_box_res
|
||||
};
|
||||
|
||||
static const char *TAG = "bsp_board";
|
||||
|
||||
esp_err_t bsp_btn_init(void)
|
||||
{
|
||||
ESP_ERROR_CHECK((NULL != g_btn_handle));
|
||||
|
||||
int btn_num = 0;
|
||||
g_btn_handle = calloc(BSP_BUTTON_NUM, sizeof(button_handle_t));
|
||||
assert((g_btn_handle) && "memory is insufficient for button");
|
||||
esp_log_level_set("button", ESP_LOG_NONE);
|
||||
return bsp_iot_button_create(g_btn_handle, &btn_num, BSP_BUTTON_NUM);
|
||||
}
|
||||
|
||||
esp_err_t bsp_btn_register_callback(bsp_button_t btn, button_event_t event, button_cb_t callback, void *user_data)
|
||||
{
|
||||
assert((g_btn_handle) && "button not initialized");
|
||||
assert((btn < BSP_BUTTON_NUM) && "button id incorrect");
|
||||
|
||||
if (NULL == callback) {
|
||||
return iot_button_unregister_cb(g_btn_handle[btn], event);
|
||||
}
|
||||
return iot_button_register_cb(g_btn_handle[btn], event, callback, user_data);
|
||||
}
|
||||
|
||||
esp_err_t bsp_btn_rm_all_callback(bsp_button_t btn)
|
||||
{
|
||||
assert((g_btn_handle) && "button not initialized");
|
||||
assert((btn < BSP_BUTTON_NUM) && "button id incorrect");
|
||||
|
||||
for (size_t event = 0; event < BUTTON_EVENT_MAX; event++) {
|
||||
iot_button_unregister_cb(g_btn_handle[btn], event);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_btn_rm_event_callback(bsp_button_t btn, size_t event)
|
||||
{
|
||||
assert((g_btn_handle) && "button not initialized");
|
||||
assert((btn < BSP_BUTTON_NUM) && "button id incorrect");
|
||||
|
||||
iot_button_unregister_cb(g_btn_handle[btn], event);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2s_read(void *audio_buffer, size_t len, size_t *bytes_read, uint32_t timeout_ms)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_codec_dev_read(record_dev_handle, audio_buffer, len);
|
||||
*bytes_read = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2s_write(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_codec_dev_write(play_dev_handle, audio_buffer, len);
|
||||
*bytes_written = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_set_fs(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
esp_codec_dev_sample_info_t fs = {
|
||||
.sample_rate = rate,
|
||||
.channel = ch,
|
||||
.bits_per_sample = bits_cfg,
|
||||
};
|
||||
|
||||
if (play_dev_handle) {
|
||||
ret = esp_codec_dev_close(play_dev_handle);
|
||||
}
|
||||
if (record_dev_handle) {
|
||||
ret |= esp_codec_dev_close(record_dev_handle);
|
||||
ret |= esp_codec_dev_set_in_gain(record_dev_handle, CODEC_DEFAULT_ADC_VOLUME);
|
||||
}
|
||||
|
||||
if (play_dev_handle) {
|
||||
ret |= esp_codec_dev_open(play_dev_handle, &fs);
|
||||
}
|
||||
if (record_dev_handle) {
|
||||
ret |= esp_codec_dev_open(record_dev_handle, &fs);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_volume_set(int volume, int *volume_set)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
float v = volume;
|
||||
ret = esp_codec_dev_set_out_vol(play_dev_handle, (int)v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_mute_set(bool enable)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret = esp_codec_dev_set_out_mute(play_dev_handle, enable);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_dev_stop(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if (play_dev_handle) {
|
||||
ret = esp_codec_dev_close(play_dev_handle);
|
||||
}
|
||||
|
||||
if (record_dev_handle) {
|
||||
ret = esp_codec_dev_close(record_dev_handle);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_dev_resume(void)
|
||||
{
|
||||
return bsp_codec_set_fs(CODEC_DEFAULT_SAMPLE_RATE, CODEC_DEFAULT_BIT_WIDTH, CODEC_DEFAULT_CHANNEL);
|
||||
}
|
||||
|
||||
static esp_err_t bsp_codec_init()
|
||||
{
|
||||
play_dev_handle = bsp_audio_codec_speaker_init();
|
||||
assert((play_dev_handle) && "play_dev_handle not initialized");
|
||||
|
||||
record_dev_handle = bsp_audio_codec_microphone_init();
|
||||
assert((record_dev_handle) && "record_dev_handle not initialized");
|
||||
|
||||
bsp_codec_set_fs(CODEC_DEFAULT_SAMPLE_RATE, CODEC_DEFAULT_BIT_WIDTH, CODEC_DEFAULT_CHANNEL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const boards_info_t *bsp_board_get_info(void)
|
||||
{
|
||||
return &g_boards_info;
|
||||
}
|
||||
|
||||
const board_res_desc_t *bsp_board_get_description(void)
|
||||
{
|
||||
return g_boards_info.board_desc;
|
||||
}
|
||||
|
||||
bsp_bottom_property_t *bsp_board_get_sensor_handle(void)
|
||||
{
|
||||
return &g_bottom_handle;
|
||||
}
|
||||
|
||||
__attribute__((weak)) void mute_btn_handler(void *handle, void *arg)
|
||||
{
|
||||
button_event_t event = (button_event_t)arg;
|
||||
|
||||
if (BUTTON_PRESS_DOWN == event) {
|
||||
esp_rom_printf(DRAM_STR("Mute On\r\n"));
|
||||
} else {
|
||||
esp_rom_printf(DRAM_STR("Mute Off\r\n"));
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t bsp_board_init(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_LOGD(TAG, "Board init");
|
||||
|
||||
ESP_ERROR_CHECK(bsp_btn_init());
|
||||
#if !CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
|
||||
ESP_ERROR_CHECK(bsp_btn_register_callback(BSP_BUTTON_MUTE, BUTTON_PRESS_DOWN, mute_btn_handler, (void *)BUTTON_PRESS_DOWN));
|
||||
ESP_ERROR_CHECK(bsp_btn_register_callback(BSP_BUTTON_MUTE, BUTTON_PRESS_UP, mute_btn_handler, (void *)BUTTON_PRESS_UP));
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(bsp_codec_init());
|
||||
bsp_sensor_init(&g_bottom_handle);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "bsp_board.h"
|
||||
|
||||
static const char *TAG = "bsp_sensor";
|
||||
|
||||
static bool bsp_get_sleep_mode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bottom_id_t bsp_get_bottom_id()
|
||||
{
|
||||
return BOTTOM_ID_UNKNOW;
|
||||
}
|
||||
|
||||
static bool bsp_sensor_get_radar_status()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static void bsp_sensor_set_radar_enable(bool enable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_sensor_get_humiture(float *temperature, float *humidity)
|
||||
{
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t bsp_sensor_init(bsp_bottom_property_t *handle)
|
||||
{
|
||||
ESP_LOGW(TAG, "This example don't support Sensor!!");
|
||||
|
||||
handle->get_sleep_mode = bsp_get_sleep_mode;
|
||||
handle->get_bottom_id = bsp_get_bottom_id;
|
||||
handle->get_radar_status = bsp_sensor_get_radar_status;
|
||||
handle->set_radar_enable = bsp_sensor_set_radar_enable;
|
||||
handle->get_humiture = bsp_sensor_get_humiture;
|
||||
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_pm.h"
|
||||
|
||||
#include "bsp_board.h"
|
||||
#include "aht20.h"
|
||||
#include "at581x.h"
|
||||
|
||||
#define BSP_I2C_EXPAND_NUM ((1 == BSP_I2C_NUM) ? (0):(1))
|
||||
#define BSP_I2C_EXPAND_CLK_SPEED_HZ CONFIG_BSP_I2C_CLK_SPEED_HZ
|
||||
|
||||
#define RADAE_POWER_DELAY (60 * 2) // 2min
|
||||
#define RADAE_FUNC_STOP (RADAE_POWER_DELAY + 1)
|
||||
|
||||
static bool sys_sleep_entered = false;
|
||||
static bottom_id_t sys_bottom_id;
|
||||
|
||||
static float sys_temp_result;
|
||||
static float sys_RH_result;
|
||||
static uint16_t power_off_delay;
|
||||
|
||||
static aht20_dev_handle_t aht20 = NULL;
|
||||
static esp_pm_lock_handle_t g_pm_apb_lock = NULL;
|
||||
static esp_pm_lock_handle_t g_pm_light_lock = NULL;
|
||||
static esp_pm_lock_handle_t g_pm_cpu_lock = NULL;
|
||||
|
||||
static const char *TAG = "bsp_sensor";
|
||||
|
||||
static esp_err_t bsp_pm_init();
|
||||
static esp_err_t bsp_pm_exit_sleep();
|
||||
static esp_err_t bsp_pm_enter_sleep();
|
||||
|
||||
static bool bsp_i2c_device_probe(i2c_port_t i2c_num, uint8_t addr);
|
||||
|
||||
static bool bsp_get_sleep_mode()
|
||||
{
|
||||
return sys_sleep_entered;
|
||||
}
|
||||
|
||||
static bottom_id_t bsp_get_bottom_id()
|
||||
{
|
||||
return sys_bottom_id;
|
||||
}
|
||||
|
||||
static bool bsp_sensor_get_radar_status()
|
||||
{
|
||||
if (BOTTOM_ID_SENSOR == sys_bottom_id) {
|
||||
return ((power_off_delay > RADAE_POWER_DELAY / 2) ? (true) : (false));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void bsp_sensor_set_radar_onoff(bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
power_off_delay = RADAE_POWER_DELAY;
|
||||
} else {
|
||||
power_off_delay = RADAE_FUNC_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t bsp_sensor_get_humiture(float *temperature, float *humidity)
|
||||
{
|
||||
if (BOTTOM_ID_SENSOR == sys_bottom_id) {
|
||||
*temperature = sys_temp_result;
|
||||
*humidity = sys_RH_result;
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
static void low_power_monitor_task(void *arg)
|
||||
{
|
||||
static uint8_t gpio_level_prev = 1;
|
||||
uint32_t temp_raw, RH_raw;
|
||||
uint8_t gpio_level;
|
||||
|
||||
gpio_config_t io_conf = {};
|
||||
io_conf.intr_type = GPIO_INTR_POSEDGE;
|
||||
io_conf.pin_bit_mask = (1ULL << BSP_RADAR_OUT_IO);
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = 1;
|
||||
gpio_config(&io_conf);
|
||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
if (sys_bottom_id != BOTTOM_ID_UNKNOW) {
|
||||
sys_bottom_id = (bsp_i2c_device_probe(BSP_I2C_EXPAND_NUM, AT581X_ADDRRES_0)) ? BOTTOM_ID_SENSOR : BOTTOM_ID_LOST;
|
||||
}
|
||||
|
||||
if (BOTTOM_ID_SENSOR == sys_bottom_id) {
|
||||
gpio_level = gpio_get_level(BSP_RADAR_OUT_IO);
|
||||
if ((RADAE_FUNC_STOP != power_off_delay) && power_off_delay) {
|
||||
power_off_delay--;
|
||||
}
|
||||
aht20_read_temperature_humidity(aht20, &temp_raw, &sys_temp_result, &RH_raw, &sys_RH_result);
|
||||
} else {
|
||||
gpio_level = 1;
|
||||
}
|
||||
|
||||
if (gpio_level_prev ^ gpio_level) {
|
||||
gpio_level_prev = gpio_level;
|
||||
if (gpio_level && (RADAE_FUNC_STOP != power_off_delay)) {
|
||||
power_off_delay = RADAE_POWER_DELAY;
|
||||
ESP_LOGD(TAG, "Radar: %s", "active");
|
||||
}
|
||||
}
|
||||
|
||||
if ((gpio_level) && (true == sys_sleep_entered)) {
|
||||
bsp_pm_exit_sleep();
|
||||
|
||||
ESP_LOGD(TAG, "power on");
|
||||
bsp_display_exit_sleep();
|
||||
|
||||
lvgl_port_resume();
|
||||
iot_button_resume();
|
||||
bsp_codec_dev_resume();
|
||||
sys_sleep_entered = false;
|
||||
} else if ((1 == power_off_delay) && (BOTTOM_ID_SENSOR == sys_bottom_id)) {
|
||||
ESP_LOGD(TAG, "power off");
|
||||
sys_sleep_entered = true;
|
||||
bsp_display_enter_sleep();
|
||||
|
||||
lvgl_port_stop();
|
||||
iot_button_stop();
|
||||
bsp_codec_dev_stop();
|
||||
bsp_pm_enter_sleep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t bsp_init_temp_humudity()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
aht20_i2c_config_t i2c_conf = {
|
||||
.i2c_port = BSP_I2C_EXPAND_NUM,
|
||||
.i2c_addr = AHT20_ADDRRES_0,
|
||||
};
|
||||
|
||||
ret |= aht20_new_sensor(&i2c_conf, &aht20);
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Temp & humidity init ok");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_init_radar()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
at581x_dev_handle_t at581x = NULL;
|
||||
|
||||
at581x_default_cfg_t def_cfg = ATH581X_INITIALIZATION_CONFIG();
|
||||
|
||||
at581x_i2c_config_t i2c_conf = {
|
||||
.i2c_port = BSP_I2C_EXPAND_NUM,
|
||||
.i2c_addr = AT581X_ADDRRES_0,
|
||||
.def_conf = &def_cfg,
|
||||
};
|
||||
|
||||
ret |= at581x_new_sensor(&i2c_conf, &at581x);
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Radar init ok");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_pm_exit_sleep()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_pm_lock_acquire(g_pm_apb_lock);
|
||||
ret |= esp_pm_lock_acquire(g_pm_light_lock);
|
||||
ret |= esp_pm_lock_acquire(g_pm_cpu_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_pm_enter_sleep()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_pm_lock_release(g_pm_apb_lock);
|
||||
ret |= esp_pm_lock_release(g_pm_light_lock);
|
||||
ret |= esp_pm_lock_release(g_pm_cpu_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_pm_init()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
#if CONFIG_PM_ENABLE
|
||||
esp_pm_config_t pm_config = {
|
||||
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
|
||||
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,
|
||||
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
.light_sleep_enable = true
|
||||
#endif
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
||||
#endif
|
||||
|
||||
if (g_pm_apb_lock == NULL) {
|
||||
ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "l_apb", &g_pm_apb_lock),
|
||||
TAG, "create l_apb pm lock failed");
|
||||
}
|
||||
|
||||
if (g_pm_light_lock == NULL) {
|
||||
ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "l_ls", &g_pm_light_lock),
|
||||
TAG, "create l_ls pm lock failed");
|
||||
}
|
||||
if (g_pm_cpu_lock == NULL) {
|
||||
ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "l_cpu", &g_pm_cpu_lock),
|
||||
TAG, "create l_cpu pm lock failed");
|
||||
}
|
||||
bsp_pm_exit_sleep();
|
||||
|
||||
ret = xTaskCreatePinnedToCore(&low_power_monitor_task, "Lowpower Task", 4 * 1024, NULL, 5, NULL, 1);
|
||||
ESP_RETURN_ON_ERROR(pdPASS != ret, TAG, "create Lowpower task failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool bsp_i2c_device_probe(i2c_port_t i2c_num, uint8_t addr)
|
||||
{
|
||||
bool probe_result = false;
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, addr | I2C_MASTER_WRITE, true);
|
||||
i2c_master_stop(cmd);
|
||||
if (i2c_master_cmd_begin(i2c_num, cmd, 2000) == ESP_OK) {
|
||||
probe_result = true;
|
||||
}
|
||||
i2c_cmd_link_delete(cmd);
|
||||
return probe_result;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_i2c_expand_init(void)
|
||||
{
|
||||
static bool i2c_initialized = false;
|
||||
|
||||
/* I2C was initialized before */
|
||||
if (i2c_initialized) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const i2c_config_t i2c_expand_conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = BSP_I2C_EXPAND_SDA,
|
||||
.sda_pullup_en = GPIO_PULLUP_DISABLE,
|
||||
.scl_io_num = BSP_I2C_EXPAND_SCL,
|
||||
.scl_pullup_en = GPIO_PULLUP_DISABLE,
|
||||
.master.clk_speed = BSP_I2C_EXPAND_CLK_SPEED_HZ
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(i2c_param_config(BSP_I2C_EXPAND_NUM, &i2c_expand_conf),
|
||||
TAG, "create expand i2c failed");
|
||||
ESP_RETURN_ON_ERROR(i2c_driver_install(BSP_I2C_EXPAND_NUM, i2c_expand_conf.mode, 0, 0, 0),
|
||||
TAG, "install expand i2c failed");
|
||||
|
||||
i2c_initialized = true;
|
||||
|
||||
ESP_LOGI(TAG, "I2C num: %d, [%d, %d], speed:%d",
|
||||
BSP_I2C_EXPAND_NUM, BSP_I2C_EXPAND_SCL, BSP_I2C_EXPAND_SDA, BSP_I2C_EXPAND_CLK_SPEED_HZ);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t bsp_i2c_expand_deinit(void)
|
||||
{
|
||||
ESP_RETURN_ON_ERROR(i2c_driver_delete(BSP_I2C_EXPAND_NUM),
|
||||
TAG, "uninstall expand i2c failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_sensor_init(bsp_bottom_property_t *handle)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= bsp_pm_init();
|
||||
ret |= bsp_i2c_expand_init();
|
||||
|
||||
if (bsp_i2c_device_probe(BSP_I2C_EXPAND_NUM, AT581X_ADDRRES_0)) {
|
||||
ESP_LOGW(TAG, "Sensor bottom connected");
|
||||
ret |= bsp_init_radar();
|
||||
ret |= bsp_init_temp_humudity();
|
||||
sys_bottom_id = BOTTOM_ID_SENSOR;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Sensor bottom lost");
|
||||
sys_bottom_id = BOTTOM_ID_UNKNOW;
|
||||
bsp_i2c_expand_deinit();
|
||||
}
|
||||
|
||||
handle->get_sleep_mode = bsp_get_sleep_mode;
|
||||
handle->get_bottom_id = bsp_get_bottom_id;
|
||||
handle->get_radar_status = bsp_sensor_get_radar_status;
|
||||
handle->set_radar_enable = bsp_sensor_set_radar_onoff;
|
||||
handle->get_humiture = bsp_sensor_get_humiture;
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "bsp_board.h"
|
||||
#include "bsp_i2s.h"
|
||||
#include "bsp_codec.h"
|
||||
#include "button.h"
|
||||
#include "bsp_btn.h"
|
||||
|
||||
static const board_button_t g_btns[] = {
|
||||
{BOARD_BTN_ID_BOOT, 0, GPIO_NUM_0, 0},
|
||||
};
|
||||
|
||||
static const pmod_pins_t g_pmod[2] = {
|
||||
{
|
||||
{9, 43, 44, 14},
|
||||
{10, 11, 13, 12},
|
||||
},
|
||||
{
|
||||
{38, 39, 40, 41},
|
||||
{42, 21, 19, 20},
|
||||
},
|
||||
};
|
||||
|
||||
static const board_res_desc_t g_board_s3_box_res = {
|
||||
.FUNC_LCD_EN = (1),
|
||||
.LCD_BUS_WIDTH = (1),
|
||||
.LCD_IFACE_SPI = (1),
|
||||
.LCD_DISP_IC_ST = (1),
|
||||
.LCD_WIDTH = (320),
|
||||
.LCD_HEIGHT = (240),
|
||||
.LCD_FREQ = (40 * 1000 * 1000),
|
||||
.LCD_CMD_BITS = 8,
|
||||
.LCD_PARAM_BITS = 8,
|
||||
.LCD_HOST = (SPI2_HOST),
|
||||
|
||||
.LCD_SWAP_XY = (0),
|
||||
.LCD_MIRROR_X = (true),
|
||||
.LCD_MIRROR_Y = (true),
|
||||
.LCD_COLOR_INV = (false),
|
||||
.LCD_COLOR_SPACE = ESP_LCD_COLOR_SPACE_BGR,
|
||||
|
||||
.GPIO_LCD_BL = (GPIO_NUM_45),
|
||||
.GPIO_LCD_BL_ON = (1),
|
||||
.GPIO_LCD_CS = (GPIO_NUM_5),
|
||||
.GPIO_LCD_RST = (GPIO_NUM_48),
|
||||
.GPIO_LCD_DC = (GPIO_NUM_4),
|
||||
.GPIO_LCD_CLK = (GPIO_NUM_7),
|
||||
.GPIO_LCD_DIN = (GPIO_NUM_6),
|
||||
.GPIO_LCD_DOUT = (GPIO_NUM_NC),
|
||||
|
||||
.BSP_INDEV_IS_TP = (1),
|
||||
.TOUCH_PANEL_SWAP_XY = (0),
|
||||
.TOUCH_PANEL_INVERSE_X = (1),
|
||||
.TOUCH_PANEL_INVERSE_Y = (0),
|
||||
.TOUCH_PANEL_I2C_ADDR = 0,
|
||||
.TOUCH_WITH_HOME_BUTTON = 1,
|
||||
|
||||
.BSP_BUTTON_EN = (1),
|
||||
.BUTTON_ADC_CHAN = ADC1_CHANNEL_0,
|
||||
.BUTTON_TAB = g_btns,
|
||||
.BUTTON_TAB_LEN = sizeof(g_btns) / sizeof(g_btns[0]),
|
||||
|
||||
.FUNC_I2C_EN = (1),
|
||||
.GPIO_I2C_SCL = (GPIO_NUM_18),
|
||||
.GPIO_I2C_SDA = (GPIO_NUM_8),
|
||||
|
||||
.FUNC_SDMMC_EN = (1),
|
||||
.SDMMC_BUS_WIDTH = (4),
|
||||
.GPIO_SDMMC_CLK = (GPIO_NUM_13),
|
||||
.GPIO_SDMMC_CMD = (GPIO_NUM_11),
|
||||
.GPIO_SDMMC_D0 = (GPIO_NUM_14),
|
||||
.GPIO_SDMMC_D1 = (GPIO_NUM_12),
|
||||
.GPIO_SDMMC_D2 = (GPIO_NUM_10),
|
||||
.GPIO_SDMMC_D3 = (GPIO_NUM_9),
|
||||
.GPIO_SDMMC_DET = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_SDSPI_EN = (0),
|
||||
.SDSPI_HOST = (SPI2_HOST),
|
||||
.GPIO_SDSPI_CS = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_SCLK = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_MISO = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_MOSI = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_SPI_EN = (0),
|
||||
.GPIO_SPI_CS = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_MISO = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_MOSI = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_SCLK = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_RMT_EN = (0),
|
||||
.GPIO_RMT_IR = (GPIO_NUM_NC),
|
||||
.GPIO_RMT_LED = (GPIO_NUM_39),
|
||||
|
||||
.FUNC_I2S_EN = (1),
|
||||
.GPIO_I2S_LRCK = (GPIO_NUM_47),
|
||||
.GPIO_I2S_MCLK = (GPIO_NUM_2),
|
||||
.GPIO_I2S_SCLK = (GPIO_NUM_17),
|
||||
.GPIO_I2S_SDIN = (GPIO_NUM_16),
|
||||
.GPIO_I2S_DOUT = (GPIO_NUM_15),
|
||||
.CODEC_I2C_ADDR = 0,
|
||||
.AUDIO_ADC_I2C_ADDR = 0,
|
||||
|
||||
.IMU_I2C_ADDR = 0,
|
||||
|
||||
.FUNC_PWR_CTRL = (1),
|
||||
.GPIO_PWR_CTRL = (GPIO_NUM_46),
|
||||
.GPIO_PWR_ON_LEVEL = (1),
|
||||
|
||||
.GPIO_MUTE_NUM = GPIO_NUM_1,
|
||||
.GPIO_MUTE_LEVEL = 1,
|
||||
|
||||
.PMOD1 = &g_pmod[0],
|
||||
.PMOD2 = &g_pmod[1],
|
||||
};
|
||||
|
||||
static const char *TAG = "board";
|
||||
|
||||
__attribute__((weak)) void mute_btn_handler(void *arg)
|
||||
{
|
||||
if (g_board_s3_box_res.GPIO_MUTE_LEVEL == gpio_get_level(g_board_s3_box_res.GPIO_MUTE_NUM)) {
|
||||
ets_printf(DRAM_STR("Mute Off"));
|
||||
} else {
|
||||
ets_printf(DRAM_STR("Mute On"));
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t bsp_board_s3_box_init(void)
|
||||
{
|
||||
/*!< Mute_Button on ESP32-S3-Box */
|
||||
gpio_config_t io_conf_key;
|
||||
io_conf_key.intr_type = GPIO_INTR_ANYEDGE;
|
||||
io_conf_key.mode = GPIO_MODE_INPUT;
|
||||
io_conf_key.pin_bit_mask = 1ULL << g_board_s3_box_res.GPIO_MUTE_NUM;
|
||||
io_conf_key.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf_key.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf_key));
|
||||
|
||||
/* Install GPIO ISR service to enable GPIO ISR callback */
|
||||
gpio_install_isr_service(0);
|
||||
ESP_ERROR_CHECK(gpio_isr_handler_add(g_board_s3_box_res.GPIO_MUTE_NUM, mute_btn_handler, NULL));
|
||||
|
||||
bsp_btn_init_default();
|
||||
|
||||
/**
|
||||
* @brief Initialize I2S and audio codec
|
||||
*
|
||||
* @note Actually the sampling rate can be reconfigured.
|
||||
* `MP3GetLastFrameInfo` can fill the `MP3FrameInfo`, which includes `samprate`.
|
||||
* So theoretically, the sampling rate can be dynamically changed according to the MP3 frame information.
|
||||
*/
|
||||
ESP_ERROR_CHECK(bsp_i2s_init(I2S_NUM_0, 16000));
|
||||
ESP_ERROR_CHECK(bsp_codec_init(AUDIO_HAL_16K_SAMPLES));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_board_s3_box_power_ctrl(power_module_t module, bool on)
|
||||
{
|
||||
/* Config power control IO */
|
||||
static esp_err_t bsp_io_config_state = ESP_FAIL;
|
||||
if (ESP_OK != bsp_io_config_state) {
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.pin_bit_mask = 1ULL << g_board_s3_box_res.GPIO_PWR_CTRL;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
bsp_io_config_state = gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
/* Checko IO config result */
|
||||
if (ESP_OK != bsp_io_config_state) {
|
||||
ESP_LOGE(TAG, "Failed initialize power control IO");
|
||||
return bsp_io_config_state;
|
||||
}
|
||||
|
||||
/* Control independent power domain */
|
||||
switch (module) {
|
||||
case POWER_MODULE_LCD:
|
||||
gpio_set_level(g_board_s3_box_res.GPIO_LCD_BL, on ? (g_board_s3_box_res.GPIO_LCD_BL_ON) : (!g_board_s3_box_res.GPIO_LCD_BL_ON));
|
||||
break;
|
||||
case POWER_MODULE_AUDIO:
|
||||
case POWER_MODULE_ALL:
|
||||
gpio_set_level(g_board_s3_box_res.GPIO_PWR_CTRL, on ? (g_board_s3_box_res.GPIO_PWR_ON_LEVEL) : (!g_board_s3_box_res.GPIO_PWR_ON_LEVEL));
|
||||
break;
|
||||
default:
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const board_res_desc_t *bsp_board_s3_box_get_res_desc(void)
|
||||
{
|
||||
return &g_board_s3_box_res;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "bsp_board.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Special config for dev board
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_board_s3_box_init(void);
|
||||
|
||||
/**
|
||||
* @brief Control power of dev board
|
||||
*
|
||||
* @param module Refer to `power_module_t`
|
||||
* @param on Turn on or off specified power module. On if true
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_board_s3_box_power_ctrl(power_module_t module, bool on);
|
||||
|
||||
/**
|
||||
* @brief Get board description
|
||||
*
|
||||
* @return pointer of board_res_desc_t
|
||||
*/
|
||||
const board_res_desc_t *bsp_board_s3_box_get_res_desc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "esp_log.h"
|
||||
#include "bsp_board.h"
|
||||
#include "bsp_i2s.h"
|
||||
#include "bsp_codec.h"
|
||||
#include "button.h"
|
||||
#include "bsp_btn.h"
|
||||
|
||||
static const board_button_t g_btns[] = {
|
||||
{BOARD_BTN_ID_BOOT, 0, GPIO_NUM_0, 0},
|
||||
{BOARD_BTN_ID_PREV, 2971UL, GPIO_NUM_NC, 0},
|
||||
{BOARD_BTN_ID_ENTER, 2427UL, GPIO_NUM_NC, 0},
|
||||
{BOARD_BTN_ID_NEXT, 957UL, GPIO_NUM_NC, 0},
|
||||
};
|
||||
|
||||
static const pmod_pins_t g_pmod[2] = {
|
||||
{
|
||||
{9, 43, 44, 14},
|
||||
{10, 11, 13, 12},
|
||||
},
|
||||
{
|
||||
{38, 39, 40, 41},
|
||||
{42, 21, 19, 20},
|
||||
},
|
||||
};
|
||||
|
||||
static const board_res_desc_t g_board_s3_box_lite_res = {
|
||||
|
||||
.FUNC_LCD_EN = (1),
|
||||
.LCD_BUS_WIDTH = (1),
|
||||
.LCD_IFACE_SPI = (1),
|
||||
.LCD_DISP_IC_ST = (1),
|
||||
.LCD_WIDTH = (320),
|
||||
.LCD_HEIGHT = (240),
|
||||
.LCD_FREQ = (80 * 1000 * 1000),
|
||||
.LCD_CMD_BITS = 8,
|
||||
.LCD_PARAM_BITS = 8,
|
||||
.LCD_HOST = (SPI2_HOST),
|
||||
|
||||
.LCD_SWAP_XY = (true),
|
||||
.LCD_MIRROR_X = (false),
|
||||
.LCD_MIRROR_Y = (true),
|
||||
.LCD_COLOR_INV = (true),
|
||||
.LCD_COLOR_SPACE = ESP_LCD_COLOR_SPACE_RGB,
|
||||
|
||||
.GPIO_LCD_BL = (GPIO_NUM_45),
|
||||
.GPIO_LCD_BL_ON = (0),
|
||||
.GPIO_LCD_CS = (GPIO_NUM_5),
|
||||
.GPIO_LCD_RST = (GPIO_NUM_48),
|
||||
.GPIO_LCD_DC = (GPIO_NUM_4),
|
||||
.GPIO_LCD_CLK = (GPIO_NUM_7),
|
||||
.GPIO_LCD_DIN = (GPIO_NUM_6),
|
||||
.GPIO_LCD_DOUT = (GPIO_NUM_NC),
|
||||
|
||||
.BSP_INDEV_IS_TP = (0),
|
||||
.TOUCH_PANEL_SWAP_XY = (0),
|
||||
.TOUCH_PANEL_INVERSE_X = (1),
|
||||
.TOUCH_PANEL_INVERSE_Y = (0),
|
||||
.TOUCH_PANEL_I2C_ADDR = 0,
|
||||
.TOUCH_WITH_HOME_BUTTON = 0,
|
||||
|
||||
.BSP_BUTTON_EN = (1),
|
||||
.BUTTON_ADC_CHAN = ADC1_CHANNEL_0,
|
||||
.BUTTON_TAB = g_btns,
|
||||
.BUTTON_TAB_LEN = sizeof(g_btns) / sizeof(g_btns[0]),
|
||||
|
||||
.FUNC_I2C_EN = (1),
|
||||
.GPIO_I2C_SCL = (GPIO_NUM_18),
|
||||
.GPIO_I2C_SDA = (GPIO_NUM_8),
|
||||
|
||||
.FUNC_SDMMC_EN = (1),
|
||||
.SDMMC_BUS_WIDTH = (4),
|
||||
.GPIO_SDMMC_CLK = (GPIO_NUM_13),
|
||||
.GPIO_SDMMC_CMD = (GPIO_NUM_11),
|
||||
.GPIO_SDMMC_D0 = (GPIO_NUM_14),
|
||||
.GPIO_SDMMC_D1 = (GPIO_NUM_12),
|
||||
.GPIO_SDMMC_D2 = (GPIO_NUM_10),
|
||||
.GPIO_SDMMC_D3 = (GPIO_NUM_9),
|
||||
.GPIO_SDMMC_DET = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_SDSPI_EN = (0),
|
||||
.SDSPI_HOST = (SPI2_HOST),
|
||||
.GPIO_SDSPI_CS = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_SCLK = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_MISO = (GPIO_NUM_NC),
|
||||
.GPIO_SDSPI_MOSI = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_SPI_EN = (0),
|
||||
.GPIO_SPI_CS = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_MISO = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_MOSI = (GPIO_NUM_NC),
|
||||
.GPIO_SPI_SCLK = (GPIO_NUM_NC),
|
||||
|
||||
.FUNC_RMT_EN = (0),
|
||||
.GPIO_RMT_IR = (GPIO_NUM_NC),
|
||||
.GPIO_RMT_LED = (GPIO_NUM_39),
|
||||
|
||||
.FUNC_I2S_EN = (1),
|
||||
.GPIO_I2S_LRCK = (GPIO_NUM_47),
|
||||
.GPIO_I2S_MCLK = (GPIO_NUM_2),
|
||||
.GPIO_I2S_SCLK = (GPIO_NUM_17),
|
||||
.GPIO_I2S_SDIN = (GPIO_NUM_16),
|
||||
.GPIO_I2S_DOUT = (GPIO_NUM_15),
|
||||
.CODEC_I2C_ADDR = 0,
|
||||
.AUDIO_ADC_I2C_ADDR = 0,
|
||||
|
||||
.IMU_I2C_ADDR = 0,
|
||||
|
||||
.FUNC_PWR_CTRL = (1),
|
||||
.GPIO_PWR_CTRL = (GPIO_NUM_46),
|
||||
.GPIO_PWR_ON_LEVEL = (1),
|
||||
|
||||
.GPIO_MUTE_NUM = GPIO_NUM_1,
|
||||
.GPIO_MUTE_LEVEL = 1,
|
||||
|
||||
.PMOD1 = &g_pmod[0],
|
||||
.PMOD2 = &g_pmod[1],
|
||||
};
|
||||
|
||||
static const char *TAG = "board";
|
||||
|
||||
esp_err_t bsp_board_s3_box_lite_init(void)
|
||||
{
|
||||
bsp_btn_init_default();
|
||||
|
||||
/**
|
||||
* @brief Initialize I2S and audio codec
|
||||
*
|
||||
* @note Actually the sampling rate can be reconfigured.
|
||||
* `MP3GetLastFrameInfo` can fill the `MP3FrameInfo`, which includes `samprate`.
|
||||
* So theoretically, the sampling rate can be dynamically changed according to the MP3 frame information.
|
||||
*/
|
||||
ESP_ERROR_CHECK(bsp_i2s_init(I2S_NUM_0, 16000));
|
||||
ESP_ERROR_CHECK(bsp_codec_init(AUDIO_HAL_16K_SAMPLES));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_board_s3_box_lite_power_ctrl(power_module_t module, bool on)
|
||||
{
|
||||
/* Config power control IO */
|
||||
static esp_err_t bsp_io_config_state = ESP_FAIL;
|
||||
if (ESP_OK != bsp_io_config_state) {
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.pin_bit_mask = 1ULL << g_board_s3_box_lite_res.GPIO_PWR_CTRL;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
bsp_io_config_state = gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
/* Checko IO config result */
|
||||
if (ESP_OK != bsp_io_config_state) {
|
||||
ESP_LOGE(TAG, "Failed initialize power control IO");
|
||||
return bsp_io_config_state;
|
||||
}
|
||||
|
||||
/* Control independent power domain */
|
||||
switch (module) {
|
||||
case POWER_MODULE_LCD:
|
||||
gpio_set_level(g_board_s3_box_lite_res.GPIO_LCD_BL, on ? (g_board_s3_box_lite_res.GPIO_LCD_BL_ON) : (!g_board_s3_box_lite_res.GPIO_LCD_BL_ON));
|
||||
break;
|
||||
case POWER_MODULE_AUDIO:
|
||||
case POWER_MODULE_ALL:
|
||||
gpio_set_level(g_board_s3_box_lite_res.GPIO_PWR_CTRL, on ? (g_board_s3_box_lite_res.GPIO_PWR_ON_LEVEL) : (!g_board_s3_box_lite_res.GPIO_PWR_ON_LEVEL));
|
||||
break;
|
||||
default:
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const board_res_desc_t *bsp_board_s3_box_lite_get_res_desc(void)
|
||||
{
|
||||
return &g_board_s3_box_lite_res;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "bsp_board.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Special config for dev board
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_board_s3_box_lite_init(void);
|
||||
|
||||
/**
|
||||
* @brief Control power of dev board
|
||||
*
|
||||
* @param module Refer to `power_module_t`
|
||||
* @param on Turn on or off specified power module. On if true
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t bsp_board_s3_box_lite_power_ctrl(power_module_t module, bool on);
|
||||
|
||||
/**
|
||||
* @brief Get board description
|
||||
*
|
||||
* @return pointer of board_res_desc_t
|
||||
*/
|
||||
const board_res_desc_t *bsp_board_s3_box_lite_get_res_desc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,534 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "i2c_bus.h"
|
||||
#include "es7210.h"
|
||||
#include "bsp_i2c.h"
|
||||
|
||||
#define I2S_DSP_MODE_A 0
|
||||
#define MCLK_DIV_FRE 256
|
||||
|
||||
/* ES7210 address*/
|
||||
#define ES7210_ADDR ES7210_AD1_AD0_00
|
||||
#define ES7210_MCLK_SOURCE FROM_CLOCK_DOUBLE_PIN /* In master mode, 0 : MCLK from pad 1 : MCLK from clock doubler */
|
||||
#define FROM_PAD_PIN 0
|
||||
#define FROM_CLOCK_DOUBLE_PIN 1
|
||||
|
||||
/*
|
||||
* Clock coefficient structer
|
||||
*/
|
||||
struct _coeff_div {
|
||||
uint32_t mclk; /* mclk frequency */
|
||||
uint32_t lrck; /* lrck */
|
||||
uint8_t ss_ds;
|
||||
uint8_t adc_div; /* adcclk divider */
|
||||
uint8_t dll; /* dll_bypass */
|
||||
uint8_t doubler; /* doubler enable */
|
||||
uint8_t osr; /* adc osr */
|
||||
uint8_t mclk_src; /* select mclk source */
|
||||
uint32_t lrck_h; /* The high 4 bits of lrck */
|
||||
uint32_t lrck_l; /* The low 8 bits of lrck */
|
||||
};
|
||||
|
||||
static const char *TAG = "ES7210";
|
||||
static i2c_bus_handle_t i2c_handle;
|
||||
static es7210_input_mics_t mic_select = ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2 | ES7210_INPUT_MIC3 | ES7210_INPUT_MIC4;
|
||||
|
||||
/* Codec hifi mclk clock divider coefficients
|
||||
* MEMBER REG
|
||||
* mclk: 0x03
|
||||
* lrck: standard
|
||||
* ss_ds: --
|
||||
* adc_div: 0x02
|
||||
* dll: 0x06
|
||||
* doubler: 0x02
|
||||
* osr: 0x07
|
||||
* mclk_src: 0x03
|
||||
* lrckh: 0x04
|
||||
* lrckl: 0x05
|
||||
*/
|
||||
static const struct _coeff_div coeff_div[] = {
|
||||
//mclk lrck ss_ds adc_div dll doubler osr mclk_src lrckh lrckl
|
||||
/* 8k */
|
||||
{12288000, 8000 , 0x00, 0x03, 0x01, 0x00, 0x20, 0x00, 0x06, 0x00},
|
||||
{16384000, 8000 , 0x00, 0x04, 0x01, 0x00, 0x20, 0x00, 0x08, 0x00},
|
||||
{19200000, 8000 , 0x00, 0x1e, 0x00, 0x01, 0x28, 0x00, 0x09, 0x60},
|
||||
{4096000, 8000 , 0x00, 0x01, 0x01, 0x00, 0x20, 0x00, 0x02, 0x00},
|
||||
|
||||
/* 11.025k */
|
||||
{11289600, 11025, 0x00, 0x02, 0x01, 0x00, 0x20, 0x00, 0x01, 0x00},
|
||||
|
||||
/* 12k */
|
||||
{12288000, 12000, 0x00, 0x02, 0x01, 0x00, 0x20, 0x00, 0x04, 0x00},
|
||||
{19200000, 12000, 0x00, 0x14, 0x00, 0x01, 0x28, 0x00, 0x06, 0x40},
|
||||
|
||||
/* 16k */
|
||||
{4096000, 16000, 0x00, 0x01, 0x01, 0x01, 0x20, 0x00, 0x01, 0x00},
|
||||
{19200000, 16000, 0x00, 0x0a, 0x00, 0x00, 0x1e, 0x00, 0x04, 0x80},
|
||||
{16384000, 16000, 0x00, 0x02, 0x01, 0x00, 0x20, 0x00, 0x04, 0x00},
|
||||
{12288000, 16000, 0x00, 0x03, 0x01, 0x01, 0x20, 0x00, 0x03, 0x00},
|
||||
|
||||
/* 22.05k */
|
||||
{11289600, 22050, 0x00, 0x01, 0x01, 0x00, 0x20, 0x00, 0x02, 0x00},
|
||||
|
||||
/* 24k */
|
||||
{12288000, 24000, 0x00, 0x01, 0x01, 0x00, 0x20, 0x00, 0x02, 0x00},
|
||||
{19200000, 24000, 0x00, 0x0a, 0x00, 0x01, 0x28, 0x00, 0x03, 0x20},
|
||||
|
||||
/* 32k */
|
||||
{12288000, 32000, 0x00, 0x03, 0x00, 0x00, 0x20, 0x00, 0x01, 0x80},
|
||||
{16384000, 32000, 0x00, 0x01, 0x01, 0x00, 0x20, 0x00, 0x02, 0x00},
|
||||
{19200000, 32000, 0x00, 0x05, 0x00, 0x00, 0x1e, 0x00, 0x02, 0x58},
|
||||
|
||||
/* 44.1k */
|
||||
{11289600, 44100, 0x00, 0x01, 0x01, 0x01, 0x20, 0x00, 0x01, 0x00},
|
||||
|
||||
/* 48k */
|
||||
{12288000, 48000, 0x00, 0x01, 0x01, 0x01, 0x20, 0x00, 0x01, 0x00},
|
||||
{19200000, 48000, 0x00, 0x05, 0x00, 0x01, 0x28, 0x00, 0x01, 0x90},
|
||||
|
||||
/* 64k */
|
||||
{16384000, 64000, 0x01, 0x01, 0x01, 0x00, 0x20, 0x00, 0x01, 0x00},
|
||||
{19200000, 64000, 0x00, 0x05, 0x00, 0x01, 0x1e, 0x00, 0x01, 0x2c},
|
||||
|
||||
/* 88.2k */
|
||||
{11289600, 88200, 0x01, 0x01, 0x01, 0x01, 0x20, 0x00, 0x00, 0x80},
|
||||
|
||||
/* 96k */
|
||||
{12288000, 96000, 0x01, 0x01, 0x01, 0x01, 0x20, 0x00, 0x00, 0x80},
|
||||
{19200000, 96000, 0x01, 0x05, 0x00, 0x01, 0x28, 0x00, 0x00, 0xc8},
|
||||
};
|
||||
|
||||
static esp_err_t es7210_write_reg(uint8_t reg_addr, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_byte(i2c_handle, reg_addr, data);
|
||||
}
|
||||
|
||||
static esp_err_t es7210_update_reg_bit(uint8_t reg_addr, uint8_t update_bits, uint8_t data)
|
||||
{
|
||||
uint8_t regv;
|
||||
regv = es7210_read_reg(reg_addr);
|
||||
regv = (regv & (~update_bits)) | (update_bits & data);
|
||||
return es7210_write_reg(reg_addr, regv);
|
||||
}
|
||||
|
||||
static int get_coeff(uint32_t mclk, uint32_t lrck)
|
||||
{
|
||||
for (int i = 0; i < (sizeof(coeff_div) / sizeof(coeff_div[0])); i++) {
|
||||
if (coeff_div[i].lrck == lrck && coeff_div[i].mclk == mclk)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int8_t get_es7210_mclk_src(void)
|
||||
{
|
||||
return ES7210_MCLK_SOURCE;
|
||||
}
|
||||
|
||||
int es7210_read_reg(uint8_t reg_addr)
|
||||
{
|
||||
uint8_t data;
|
||||
i2c_bus_read_byte(i2c_handle, reg_addr, &data);
|
||||
return (int)data;
|
||||
}
|
||||
|
||||
esp_err_t es7210_config_sample(audio_hal_iface_samples_t sample)
|
||||
{
|
||||
uint8_t regv;
|
||||
int coeff;
|
||||
int sample_fre = 0;
|
||||
int mclk_fre = 0;
|
||||
esp_err_t ret = ESP_OK;
|
||||
switch (sample) {
|
||||
case AUDIO_HAL_08K_SAMPLES:
|
||||
sample_fre = 8000;
|
||||
break;
|
||||
case AUDIO_HAL_11K_SAMPLES:
|
||||
sample_fre = 11025;
|
||||
break;
|
||||
case AUDIO_HAL_16K_SAMPLES:
|
||||
sample_fre = 16000;
|
||||
break;
|
||||
case AUDIO_HAL_22K_SAMPLES:
|
||||
sample_fre = 22050;
|
||||
break;
|
||||
case AUDIO_HAL_24K_SAMPLES:
|
||||
sample_fre = 24000;
|
||||
break;
|
||||
case AUDIO_HAL_32K_SAMPLES:
|
||||
sample_fre = 32000;
|
||||
break;
|
||||
case AUDIO_HAL_44K_SAMPLES:
|
||||
sample_fre = 44100;
|
||||
break;
|
||||
case AUDIO_HAL_48K_SAMPLES:
|
||||
sample_fre = 48000;
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unable to configure sample rate %dHz", sample_fre);
|
||||
break;
|
||||
}
|
||||
mclk_fre = sample_fre * MCLK_DIV_FRE;
|
||||
coeff = get_coeff(mclk_fre, sample_fre);
|
||||
if (coeff < 0) {
|
||||
ESP_LOGE(TAG, "Unable to configure sample rate %dHz with %dHz MCLK", sample_fre, mclk_fre);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
/* Set clock parammeters */
|
||||
if (coeff >= 0) {
|
||||
/* Set adc_div & doubler & dll */
|
||||
regv = es7210_read_reg(ES7210_MAINCLK_REG02) & 0x00;
|
||||
regv |= coeff_div[coeff].adc_div;
|
||||
regv |= coeff_div[coeff].doubler << 6;
|
||||
regv |= coeff_div[coeff].dll << 7;
|
||||
ret |= es7210_write_reg(ES7210_MAINCLK_REG02, regv);
|
||||
/* Set osr */
|
||||
regv = coeff_div[coeff].osr;
|
||||
ret |= es7210_write_reg(ES7210_OSR_REG07, regv);
|
||||
/* Set lrck */
|
||||
regv = coeff_div[coeff].lrck_h;
|
||||
ret |= es7210_write_reg(ES7210_LRCK_DIVH_REG04, regv);
|
||||
regv = coeff_div[coeff].lrck_l;
|
||||
ret |= es7210_write_reg(ES7210_LRCK_DIVL_REG05, regv);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_mic_select(es7210_input_mics_t mic)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
mic_select = mic;
|
||||
if (mic_select & (ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2 | ES7210_INPUT_MIC3 | ES7210_INPUT_MIC4)) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC1_GAIN_REG43 + i, 0x10, 0x00);
|
||||
}
|
||||
ret |= es7210_write_reg(ES7210_MIC12_POWER_REG4B, 0xff);
|
||||
ret |= es7210_write_reg(ES7210_MIC34_POWER_REG4C, 0xff);
|
||||
if (mic_select & ES7210_INPUT_MIC1) {
|
||||
ESP_LOGI(TAG, "Enable ES7210_INPUT_MIC1");
|
||||
ret |= es7210_update_reg_bit(ES7210_CLOCK_OFF_REG01, 0x0b, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC12_POWER_REG4B, 0x00);
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC1_GAIN_REG43, 0x10, 0x10);
|
||||
}
|
||||
if (mic_select & ES7210_INPUT_MIC2) {
|
||||
ESP_LOGI(TAG, "Enable ES7210_INPUT_MIC2");
|
||||
ret |= es7210_update_reg_bit(ES7210_CLOCK_OFF_REG01, 0x0b, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC12_POWER_REG4B, 0x00);
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC2_GAIN_REG44, 0x10, 0x10);
|
||||
}
|
||||
if (mic_select & ES7210_INPUT_MIC3) {
|
||||
ESP_LOGI(TAG, "Enable ES7210_INPUT_MIC3");
|
||||
ret |= es7210_update_reg_bit(ES7210_CLOCK_OFF_REG01, 0x15, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC34_POWER_REG4C, 0x00);
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC3_GAIN_REG45, 0x10, 0x10);
|
||||
}
|
||||
if (mic_select & ES7210_INPUT_MIC4) {
|
||||
ESP_LOGI(TAG, "Enable ES7210_INPUT_MIC4");
|
||||
ret |= es7210_update_reg_bit(ES7210_CLOCK_OFF_REG01, 0x15, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC34_POWER_REG4C, 0x00);
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC4_GAIN_REG46, 0x10, 0x10);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Microphone selection error");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_init(audio_hal_codec_config_t *codec_cfg)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= bsp_i2c_add_device(&i2c_handle, ES7210_ADDR);
|
||||
|
||||
ret |= es7210_write_reg(ES7210_RESET_REG00, 0xff);
|
||||
ret |= es7210_write_reg(ES7210_RESET_REG00, 0x41);
|
||||
ret |= es7210_write_reg(ES7210_CLOCK_OFF_REG01, 0x1f);
|
||||
ret |= es7210_write_reg(ES7210_TIME_CONTROL0_REG09, 0x30); /* Set chip state cycle */
|
||||
ret |= es7210_write_reg(ES7210_TIME_CONTROL1_REG0A, 0x30); /* Set power on state cycle */
|
||||
// ret |= es7210_write_reg(ES7210_ADC12_HPF2_REG23, 0x2a); /* Quick setup */
|
||||
// ret |= es7210_write_reg(ES7210_ADC12_HPF1_REG22, 0x0a);
|
||||
// ret |= es7210_write_reg(ES7210_ADC34_HPF2_REG20, 0x0a);
|
||||
// ret |= es7210_write_reg(ES7210_ADC34_HPF1_REG21, 0x2a);
|
||||
/* Set master/slave audio interface */
|
||||
audio_hal_codec_i2s_iface_t *i2s_cfg = & (codec_cfg->i2s_iface);
|
||||
switch (i2s_cfg->mode) {
|
||||
case AUDIO_HAL_MODE_MASTER: /* MASTER MODE */
|
||||
ESP_LOGI(TAG, "ES7210 in Master mode");
|
||||
// ret |= es7210_update_reg_bit(ES7210_MODE_CONFIG_REG08, 0x01, 0x01);
|
||||
ret |= es7210_write_reg(ES7210_MODE_CONFIG_REG08, 0x20);
|
||||
/* Select clock source for internal mclk */
|
||||
switch (get_es7210_mclk_src()) {
|
||||
case FROM_PAD_PIN:
|
||||
ret |= es7210_update_reg_bit(ES7210_MASTER_CLK_REG03, 0x80, 0x00);
|
||||
break;
|
||||
case FROM_CLOCK_DOUBLE_PIN:
|
||||
ret |= es7210_update_reg_bit(ES7210_MASTER_CLK_REG03, 0x80, 0x80);
|
||||
break;
|
||||
default:
|
||||
ret |= es7210_update_reg_bit(ES7210_MASTER_CLK_REG03, 0x80, 0x00);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case AUDIO_HAL_MODE_SLAVE: /* SLAVE MODE */
|
||||
ESP_LOGI(TAG, "ES7210 in Slave mode");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ret |= es7210_write_reg(ES7210_ANALOG_REG40, 0xC3); /* Select power off analog, vdda = 3.3V, close vx20ff, VMID select 5KΩ start */
|
||||
ret |= es7210_write_reg(ES7210_MIC12_BIAS_REG41, 0x70); /* Select 2.87v */
|
||||
ret |= es7210_write_reg(ES7210_MIC34_BIAS_REG42, 0x70); /* Select 2.87v */
|
||||
ret |= es7210_write_reg(ES7210_OSR_REG07, 0x20);
|
||||
ret |= es7210_write_reg(ES7210_MAINCLK_REG02, 0xc1); /* Set the frequency division coefficient and use dll except clock doubler, and need to set 0xc1 to clear the state */
|
||||
ret |= es7210_config_sample(i2s_cfg->samples);
|
||||
ret |= es7210_mic_select(mic_select);
|
||||
ret |= es7210_adc_set_gain_all(GAIN_0DB);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_deinit()
|
||||
{
|
||||
i2c_bus_delete(i2c_handle);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es7210_config_fmt(audio_hal_iface_format_t fmt)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t adc_iface = 0;
|
||||
adc_iface = es7210_read_reg(ES7210_SDP_INTERFACE1_REG11);
|
||||
adc_iface &= 0xfc;
|
||||
switch (fmt) {
|
||||
case AUDIO_HAL_I2S_NORMAL:
|
||||
ESP_LOGD(TAG, "ES7210 in I2S Format");
|
||||
adc_iface |= 0x00;
|
||||
break;
|
||||
case AUDIO_HAL_I2S_LEFT:
|
||||
case AUDIO_HAL_I2S_RIGHT:
|
||||
ESP_LOGD(TAG, "ES7210 in LJ Format");
|
||||
adc_iface |= 0x01;
|
||||
break;
|
||||
case AUDIO_HAL_I2S_DSP:
|
||||
if (I2S_DSP_MODE_A) {
|
||||
ESP_LOGD(TAG, "ES7210 in DSP-A Format");
|
||||
adc_iface |= 0x03;
|
||||
} else {
|
||||
ESP_LOGD(TAG, "ES7210 in DSP-B Format");
|
||||
adc_iface |= 0x13;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
adc_iface &= 0xfc;
|
||||
break;
|
||||
}
|
||||
ret |= es7210_write_reg(ES7210_SDP_INTERFACE1_REG11, adc_iface);
|
||||
/* Force ADC1/2 output to SDOUT1 and ADC3/4 output to SDOUT2 */
|
||||
ret |= es7210_write_reg(ES7210_SDP_INTERFACE2_REG12, 0x00);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_set_bits(audio_hal_iface_bits_t bits)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t adc_iface = 0;
|
||||
adc_iface = es7210_read_reg(ES7210_SDP_INTERFACE1_REG11);
|
||||
adc_iface &= 0x1f;
|
||||
switch (bits) {
|
||||
case AUDIO_HAL_BIT_LENGTH_16BITS:
|
||||
adc_iface |= 0x60;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_24BITS:
|
||||
adc_iface |= 0x00;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_32BITS:
|
||||
adc_iface |= 0x80;
|
||||
break;
|
||||
default:
|
||||
adc_iface |= 0x60;
|
||||
break;
|
||||
}
|
||||
ret |= es7210_write_reg(ES7210_SDP_INTERFACE1_REG11, adc_iface);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret |= es7210_set_bits(iface->bits);
|
||||
ret |= es7210_config_fmt(iface->fmt);
|
||||
ret |= es7210_config_sample(iface->samples);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_start(uint8_t clock_reg_value)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret |= es7210_write_reg(ES7210_CLOCK_OFF_REG01, clock_reg_value);
|
||||
ret |= es7210_write_reg(ES7210_POWER_DOWN_REG06, 0x00);
|
||||
// ret |= es7210_write_reg(ES7210_ANALOG_REG40, 0x40);
|
||||
ret |= es7210_write_reg(ES7210_MIC1_POWER_REG47, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC2_POWER_REG48, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC3_POWER_REG49, 0x00);
|
||||
ret |= es7210_write_reg(ES7210_MIC4_POWER_REG4A, 0x00);
|
||||
ret |= es7210_mic_select(mic_select);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_stop(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ret |= es7210_write_reg(ES7210_MIC1_POWER_REG47, 0xff);
|
||||
ret |= es7210_write_reg(ES7210_MIC2_POWER_REG48, 0xff);
|
||||
ret |= es7210_write_reg(ES7210_MIC3_POWER_REG49, 0xff);
|
||||
ret |= es7210_write_reg(ES7210_MIC4_POWER_REG4A, 0xff);
|
||||
ret |= es7210_write_reg(ES7210_MIC12_POWER_REG4B,0xff);
|
||||
ret |= es7210_write_reg(ES7210_MIC34_POWER_REG4C, 0xff);
|
||||
// ret |= es7210_write_reg(ES7210_ANALOG_REG40, 0xc0);
|
||||
ret |= es7210_write_reg(ES7210_CLOCK_OFF_REG01, 0x7f);
|
||||
ret |= es7210_write_reg(ES7210_POWER_DOWN_REG06, 0x07);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state)
|
||||
{
|
||||
static uint8_t regv;
|
||||
esp_err_t ret = ESP_OK;
|
||||
// ESP_LOGW(TAG, "ES7210 only supports ADC mode");
|
||||
ret = es7210_read_reg(ES7210_CLOCK_OFF_REG01);
|
||||
if ((ret != 0x7f) && (ret != 0xff)) {
|
||||
regv = es7210_read_reg(ES7210_CLOCK_OFF_REG01);
|
||||
}
|
||||
if (ctrl_state == AUDIO_HAL_CTRL_START) {
|
||||
ESP_LOGI(TAG, "The ES7210_CLOCK_OFF_REG01 value before stop is %x",regv);
|
||||
ret |= es7210_start(regv);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "The codec is about to stop");
|
||||
regv = es7210_read_reg(ES7210_CLOCK_OFF_REG01);
|
||||
ret |= es7210_stop();
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_set_gain(es7210_input_mics_t mic_mask, es7210_gain_value_t gain)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
if (gain < GAIN_0DB) {
|
||||
gain = GAIN_0DB;
|
||||
}
|
||||
|
||||
if (gain > GAIN_37_5DB) {
|
||||
gain = GAIN_37_5DB;
|
||||
}
|
||||
|
||||
if (mic_mask & ES7210_INPUT_MIC1) {
|
||||
ret_val |= es7210_update_reg_bit(ES7210_MIC1_GAIN_REG43, 0x0f, gain);
|
||||
}
|
||||
if (mic_mask & ES7210_INPUT_MIC2) {
|
||||
ret_val |= es7210_update_reg_bit(ES7210_MIC2_GAIN_REG44, 0x0f, gain);
|
||||
}
|
||||
if (mic_mask & ES7210_INPUT_MIC3) {
|
||||
ret_val |= es7210_update_reg_bit(ES7210_MIC3_GAIN_REG45, 0x0f, gain);
|
||||
}
|
||||
if (mic_mask & ES7210_INPUT_MIC4) {
|
||||
ret_val |= es7210_update_reg_bit(ES7210_MIC4_GAIN_REG46, 0x0f, gain);
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_set_gain_all(es7210_gain_value_t gain)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint32_t max_gain_vaule = 14;
|
||||
if (gain < 0) {
|
||||
gain = 0;
|
||||
} else if (gain > max_gain_vaule) {
|
||||
gain = max_gain_vaule;
|
||||
}
|
||||
ESP_LOGD(TAG, "SET: gain:%d", gain);
|
||||
if (mic_select & ES7210_INPUT_MIC1) {
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC1_GAIN_REG43, 0x0f, gain);
|
||||
}
|
||||
if (mic_select & ES7210_INPUT_MIC2) {
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC2_GAIN_REG44, 0x0f, gain);
|
||||
}
|
||||
if (mic_select & ES7210_INPUT_MIC3) {
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC3_GAIN_REG45, 0x0f, gain);
|
||||
}
|
||||
if (mic_select & ES7210_INPUT_MIC4) {
|
||||
ret |= es7210_update_reg_bit(ES7210_MIC4_GAIN_REG46, 0x0f, gain);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_get_gain(es7210_input_mics_t mic_mask, es7210_gain_value_t *gain)
|
||||
{
|
||||
int regv = 0;
|
||||
uint8_t gain_value;
|
||||
if (mic_mask & ES7210_INPUT_MIC1) {
|
||||
regv = es7210_read_reg(ES7210_MIC1_GAIN_REG43);
|
||||
} else if (mic_mask & ES7210_INPUT_MIC2) {
|
||||
regv = es7210_read_reg(ES7210_MIC2_GAIN_REG44);
|
||||
} else if (mic_mask & ES7210_INPUT_MIC3) {
|
||||
regv = es7210_read_reg(ES7210_MIC3_GAIN_REG45);
|
||||
} else if (mic_mask & ES7210_INPUT_MIC4) {
|
||||
regv = es7210_read_reg(ES7210_MIC4_GAIN_REG46);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "No MIC selected");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (regv == ESP_FAIL) {
|
||||
return regv;
|
||||
}
|
||||
gain_value = (regv & 0x0f); /* Retain the last four bits for gain */
|
||||
*gain = gain_value;
|
||||
ESP_LOGI(TAG, "GET: gain_value:%d", gain_value);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es7210_adc_set_volume(int volume)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_LOGD(TAG, "ADC can adjust gain");
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es7210_set_mute(bool enable)
|
||||
{
|
||||
ESP_LOGD(TAG, "ES7210 SetMute :%d", enable);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void es7210_read_all(void)
|
||||
{
|
||||
for (int i = 0; i <= 0x4E; i++) {
|
||||
uint8_t reg = es7210_read_reg(i);
|
||||
ets_printf("REG:%02x, %02x\n", reg, i);
|
||||
}
|
||||
}
|
||||
@@ -1,254 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ES7210_H
|
||||
#define _ES7210_H
|
||||
|
||||
#include "audio_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ES7210_RESET_REG00 0x00 /* Reset control */
|
||||
#define ES7210_CLOCK_OFF_REG01 0x01 /* Used to turn off the ADC clock */
|
||||
#define ES7210_MAINCLK_REG02 0x02 /* Set ADC clock frequency division */
|
||||
#define ES7210_MASTER_CLK_REG03 0x03 /* MCLK source $ SCLK division */
|
||||
#define ES7210_LRCK_DIVH_REG04 0x04 /* lrck_divh */
|
||||
#define ES7210_LRCK_DIVL_REG05 0x05 /* lrck_divl */
|
||||
#define ES7210_POWER_DOWN_REG06 0x06 /* power down */
|
||||
#define ES7210_OSR_REG07 0x07
|
||||
#define ES7210_MODE_CONFIG_REG08 0x08 /* Set master/slave & channels */
|
||||
#define ES7210_TIME_CONTROL0_REG09 0x09 /* Set Chip intial state period*/
|
||||
#define ES7210_TIME_CONTROL1_REG0A 0x0A /* Set Power up state period */
|
||||
#define ES7210_SDP_INTERFACE1_REG11 0x11 /* Set sample & fmt */
|
||||
#define ES7210_SDP_INTERFACE2_REG12 0x12 /* Pins state */
|
||||
#define ES7210_ADC_AUTOMUTE_REG13 0x13 /* Set mute */
|
||||
#define ES7210_ADC34_MUTERANGE_REG14 0x14 /* Set mute range */
|
||||
#define ES7210_ADC34_HPF2_REG20 0x20 /* HPF */
|
||||
#define ES7210_ADC34_HPF1_REG21 0x21
|
||||
#define ES7210_ADC12_HPF1_REG22 0x22
|
||||
#define ES7210_ADC12_HPF2_REG23 0x23
|
||||
#define ES7210_ANALOG_REG40 0x40 /* ANALOG Power */
|
||||
#define ES7210_MIC12_BIAS_REG41 0x41
|
||||
#define ES7210_MIC34_BIAS_REG42 0x42
|
||||
#define ES7210_MIC1_GAIN_REG43 0x43
|
||||
#define ES7210_MIC2_GAIN_REG44 0x44
|
||||
#define ES7210_MIC3_GAIN_REG45 0x45
|
||||
#define ES7210_MIC4_GAIN_REG46 0x46
|
||||
#define ES7210_MIC1_POWER_REG47 0x47
|
||||
#define ES7210_MIC2_POWER_REG48 0x48
|
||||
#define ES7210_MIC3_POWER_REG49 0x49
|
||||
#define ES7210_MIC4_POWER_REG4A 0x4A
|
||||
#define ES7210_MIC12_POWER_REG4B 0x4B /* MICBias & ADC & PGA Power */
|
||||
#define ES7210_MIC34_POWER_REG4C 0x4C
|
||||
|
||||
typedef enum {
|
||||
ES7210_AD1_AD0_00 = 0x40,
|
||||
ES7210_AD1_AD0_01 = 0x41,
|
||||
ES7210_AD1_AD0_10 = 0x42,
|
||||
ES7210_AD1_AD0_11 = 0x43,
|
||||
} es7210_address_t;
|
||||
|
||||
typedef enum {
|
||||
ES7210_INPUT_MIC1 = 0x01,
|
||||
ES7210_INPUT_MIC2 = 0x02,
|
||||
ES7210_INPUT_MIC3 = 0x04,
|
||||
ES7210_INPUT_MIC4 = 0x08
|
||||
} es7210_input_mics_t;
|
||||
|
||||
typedef enum gain_value{
|
||||
GAIN_0DB = 0,
|
||||
GAIN_3DB,
|
||||
GAIN_6DB,
|
||||
GAIN_9DB,
|
||||
GAIN_12DB,
|
||||
GAIN_15DB,
|
||||
GAIN_18DB,
|
||||
GAIN_21DB,
|
||||
GAIN_24DB,
|
||||
GAIN_27DB,
|
||||
GAIN_30DB,
|
||||
GAIN_33DB,
|
||||
GAIN_34_5DB,
|
||||
GAIN_36DB,
|
||||
GAIN_37_5DB,
|
||||
} es7210_gain_value_t;
|
||||
|
||||
/*
|
||||
* @brief Initialize ES7210 ADC chip
|
||||
*
|
||||
* @param[in] codec_cfg: configuration of ES7210
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7210_adc_init(audio_hal_codec_config_t *codec_cfg);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ES7210 ADC chip
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7210_adc_deinit();
|
||||
|
||||
/**
|
||||
* @brief Configure ES7210 ADC mode and I2S interface
|
||||
*
|
||||
* @param[in] mode: codec mode
|
||||
* @param[in] iface: I2S config
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es7210_adc_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);
|
||||
|
||||
/**
|
||||
* @brief Control ES7210 ADC chip
|
||||
*
|
||||
* @param[in] mode: codec mode
|
||||
* @param[in] ctrl_state: start or stop progress
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es7210_adc_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state);
|
||||
|
||||
/**
|
||||
* @brief Set gain of given mask
|
||||
*
|
||||
* @param[in] mic_mask Mask of MIC channel
|
||||
*
|
||||
* @param[in] gain: gain
|
||||
*
|
||||
* gain : value
|
||||
* GAIN_0DB : 1
|
||||
* GAIN_3DB : 2
|
||||
* GAIN_6DB : 3
|
||||
* ·
|
||||
* ·
|
||||
* ·
|
||||
* GAIN_30DB : 10
|
||||
* GAIN_33DB : 11
|
||||
* GAIN_34_5DB : 12
|
||||
* GAIN_36DB : 13
|
||||
* GAIN_37_5DB : 14
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7210_adc_set_gain(es7210_input_mics_t mic_mask, es7210_gain_value_t gain);
|
||||
|
||||
/**
|
||||
* @brief Set gain (Note: the enabled microphone sets the same gain)
|
||||
*
|
||||
* @param[in] gain: gain
|
||||
*
|
||||
* gain : value
|
||||
* GAIN_0DB : 1
|
||||
* GAIN_3DB : 2
|
||||
* GAIN_6DB : 3
|
||||
* ·
|
||||
* ·
|
||||
* ·
|
||||
* GAIN_30DB : 10
|
||||
* GAIN_33DB : 11
|
||||
* GAIN_34_5DB : 12
|
||||
* GAIN_36DB : 13
|
||||
* GAIN_37_5DB : 14
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7210_adc_set_gain_all(es7210_gain_value_t gain);
|
||||
|
||||
/**
|
||||
* @brief Get MIC gain
|
||||
*
|
||||
* @param mic_mask Selected MIC
|
||||
* @param gain Pointer to `es7210_gain_value_t`
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7210_adc_get_gain(es7210_input_mics_t mic_mask, es7210_gain_value_t *gain);
|
||||
|
||||
/**
|
||||
* @brief Set volume
|
||||
*
|
||||
* @param[in] volume: volume
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t es7210_adc_set_volume(int volume);
|
||||
|
||||
/**
|
||||
* @brief Set ES7210 ADC mute status
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t es7210_set_mute(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Select ES7210 mic
|
||||
*
|
||||
* @param[in] mic: mics
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t es7210_mic_select(es7210_input_mics_t mic);
|
||||
|
||||
/**
|
||||
* @brief Read regs of ES7210
|
||||
*
|
||||
* @param[in] reg_addr: reg_addr
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL
|
||||
* - ESP_OK
|
||||
*/
|
||||
int es7210_read_reg(uint8_t reg_addr);
|
||||
|
||||
/**
|
||||
* @brief Read all regs of ES7210
|
||||
*/
|
||||
void es7210_read_all(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ES7210_H_ */
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bsp_i2c.h"
|
||||
#include "es7243e.h"
|
||||
#include "i2c_bus.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define ES7243_ADDR 0x10
|
||||
|
||||
static char *TAG = "DRV7243E";
|
||||
static i2c_bus_handle_t i2c_handle;
|
||||
|
||||
static esp_err_t es7243e_write_reg(uint8_t reg_add, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_byte(i2c_handle, reg_add, data);
|
||||
}
|
||||
|
||||
esp_err_t es7243e_adc_init(audio_hal_codec_config_t *codec_cfg)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
bsp_i2c_add_device(&i2c_handle, ES7243_ADDR);
|
||||
|
||||
ret |= es7243e_write_reg(0x01, 0x3A);
|
||||
ret |= es7243e_write_reg(0x00, 0x80);
|
||||
ret |= es7243e_write_reg(0xF9, 0x00);
|
||||
ret |= es7243e_write_reg(0x04, 0x02);
|
||||
ret |= es7243e_write_reg(0x04, 0x01);
|
||||
ret |= es7243e_write_reg(0xF9, 0x01);
|
||||
ret |= es7243e_write_reg(0x00, 0x1E);
|
||||
ret |= es7243e_write_reg(0x01, 0x00);
|
||||
|
||||
ret |= es7243e_write_reg(0x02, 0x00);
|
||||
ret |= es7243e_write_reg(0x03, 0x20);
|
||||
ret |= es7243e_write_reg(0x04, 0x01);
|
||||
ret |= es7243e_write_reg(0x0D, 0x00);
|
||||
ret |= es7243e_write_reg(0x05, 0x00);
|
||||
ret |= es7243e_write_reg(0x06, 0x03); // SCLK=MCLK/4
|
||||
ret |= es7243e_write_reg(0x07, 0x00); // LRCK=MCLK/256
|
||||
ret |= es7243e_write_reg(0x08, 0xFF); // LRCK=MCLK/256
|
||||
|
||||
ret |= es7243e_write_reg(0x09, 0xCA);
|
||||
ret |= es7243e_write_reg(0x0A, 0x85);
|
||||
ret |= es7243e_write_reg(0x0B, 0x00);
|
||||
ret |= es7243e_write_reg(0x0E, 0xBF);
|
||||
ret |= es7243e_write_reg(0x0F, 0x80);
|
||||
ret |= es7243e_write_reg(0x14, 0x0C);
|
||||
ret |= es7243e_write_reg(0x15, 0x0C);
|
||||
ret |= es7243e_write_reg(0x17, 0x02);
|
||||
ret |= es7243e_write_reg(0x18, 0x26);
|
||||
ret |= es7243e_write_reg(0x19, 0x77);
|
||||
ret |= es7243e_write_reg(0x1A, 0xF4);
|
||||
ret |= es7243e_write_reg(0x1B, 0x66);
|
||||
ret |= es7243e_write_reg(0x1C, 0x44);
|
||||
ret |= es7243e_write_reg(0x1E, 0x00);
|
||||
ret |= es7243e_write_reg(0x1F, 0x0C);
|
||||
ret |= es7243e_write_reg(0x20, 0x1E); //PGA gain +30dB
|
||||
ret |= es7243e_write_reg(0x21, 0x1E); //PGA gain +30dB
|
||||
|
||||
ret |= es7243e_write_reg(0x00, 0x80); //Slave Mode
|
||||
ret |= es7243e_write_reg(0x01, 0x3A);
|
||||
ret |= es7243e_write_reg(0x16, 0x3F);
|
||||
ret |= es7243e_write_reg(0x16, 0x00);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "Es7243e initialize failed!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ES7243E_H_
|
||||
#define _ES7243E_H_
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "audio_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize ES7243E adc chip
|
||||
*
|
||||
* @param codec_cfg configuration of ES7243E
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7243e_adc_init(audio_hal_codec_config_t *codec_cfg);
|
||||
|
||||
/**
|
||||
* @brief Set gain of given mask
|
||||
*
|
||||
* @param[in] mic_mask Mask of MIC channel
|
||||
*
|
||||
* @param[in] gain: gain
|
||||
*
|
||||
* gain : value
|
||||
* GAIN_0DB : 1
|
||||
* GAIN_3DB : 2
|
||||
* GAIN_6DB : 3
|
||||
* ·
|
||||
* ·
|
||||
* ·
|
||||
* GAIN_30DB : 10
|
||||
* GAIN_33DB : 11
|
||||
* GAIN_34_5DB : 12
|
||||
* GAIN_36DB : 13
|
||||
* GAIN_37_5DB : 14
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
// esp_err_t es7243_adc_set_gain(es7243_input_mics_t mic_mask, es7243_gain_value_t gain);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bsp_i2c.h"
|
||||
#include "string.h"
|
||||
#include "esp_log.h"
|
||||
#include "i2c_bus.h"
|
||||
#include "es8156.h"
|
||||
|
||||
static const char *TAG = "es8156";
|
||||
|
||||
#define ES8156_ADDR (0x08)
|
||||
|
||||
static i2c_bus_handle_t i2c_handle;
|
||||
|
||||
static esp_err_t es8156_write_reg(uint8_t reg_addr, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_byte(i2c_handle, reg_addr, data);
|
||||
}
|
||||
|
||||
static uint8_t es8156_read_reg(uint8_t reg_addr)
|
||||
{
|
||||
uint8_t data;
|
||||
i2c_bus_read_byte(i2c_handle, reg_addr, &data);
|
||||
return data;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_init(audio_hal_codec_config_t *cfg)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
ret_val |= bsp_i2c_add_device(&i2c_handle, ES8156_ADDR);
|
||||
|
||||
uint8_t misc_ctrl_reg_val = 0x00;
|
||||
uint8_t dac_iface_reg_val = 0x00;
|
||||
|
||||
if (AUDIO_HAL_MODE_MASTER == cfg->i2s_iface.mode) {
|
||||
misc_ctrl_reg_val |= 0b00100000;
|
||||
} else {
|
||||
misc_ctrl_reg_val |= 0b00000000;
|
||||
}
|
||||
|
||||
switch (cfg->i2s_iface.bits) {
|
||||
case AUDIO_HAL_BIT_LENGTH_16BITS:
|
||||
dac_iface_reg_val |= 0b00110000;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_24BITS:
|
||||
dac_iface_reg_val |= 0b00000000;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_32BITS:
|
||||
dac_iface_reg_val |= 0b01000000;
|
||||
break;
|
||||
default: /* Use 32 bit as default */
|
||||
dac_iface_reg_val |= 0b01000000;
|
||||
break;
|
||||
}
|
||||
|
||||
ret_val |= es8156_write_reg(0x09, misc_ctrl_reg_val); // MCLK from pad, Slave mode, power down DLL, enable pin pull up
|
||||
ret_val |= es8156_write_reg(0x11, dac_iface_reg_val); // DAC Interface Config
|
||||
ret_val |= es8156_write_reg(0x14, ES8156_VOL_MIN_3dB); // Set default volume to 0dB
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_deinit(void)
|
||||
{
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_set_voice_mute(bool enable)
|
||||
{
|
||||
int regv = es8156_read_reg(ES8156_DAC_MUTE_REG13);
|
||||
if (enable) {
|
||||
regv = regv | BIT(1) | BIT(2);
|
||||
} else {
|
||||
regv = regv & (~(BIT(1) | BIT(2))) ;
|
||||
}
|
||||
es8156_write_reg(ES8156_DAC_MUTE_REG13, regv);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_set_voice_volume(uint8_t volume)
|
||||
{
|
||||
if (volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
uint8_t d = 0xBF - 60 + 6 * volume / 10;
|
||||
if (0 == volume) {
|
||||
d = 0;
|
||||
}
|
||||
return es8156_write_reg(ES8156_VOLUME_CONTROL_REG14, d);
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_get_voice_volume(uint8_t *volume)
|
||||
{
|
||||
*volume = es8156_read_reg(ES8156_VOLUME_CONTROL_REG14);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8156_config_fmt(es_i2s_fmt_t fmt)
|
||||
{
|
||||
ESP_LOGW(TAG, "Not support config format for es8156 now");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t es8156_set_channel(uint8_t is_right)
|
||||
{
|
||||
uint8_t reg = es8156_read_reg(ES8156_DAC_SDP_REG11);
|
||||
if (is_right) {
|
||||
reg |= 0b00000100;
|
||||
} else {
|
||||
reg &= 0b11111011;
|
||||
}
|
||||
return es8156_write_reg(ES8156_DAC_SDP_REG11, reg);
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ES8156_H
|
||||
#define _ES8156_H
|
||||
|
||||
#include "audio_hal.h"
|
||||
#include "esp_types.h"
|
||||
#include "esxxx_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ES8156 register space */
|
||||
/*
|
||||
* RESET Control
|
||||
*/
|
||||
#define ES8156_RESET_REG00 0x00
|
||||
/*
|
||||
* Clock Managerment
|
||||
*/
|
||||
#define ES8156_MAINCLOCK_CTL_REG01 0x01
|
||||
#define ES8156_SCLK_MODE_REG02 0x02
|
||||
#define ES8156_LRCLK_DIV_H_REG03 0x03
|
||||
#define ES8156_LRCLK_DIV_L_REG04 0x04
|
||||
#define ES8156_SCLK_DIV_REG05 0x05
|
||||
#define ES8156_NFS_CONFIG_REG06 0x06
|
||||
#define ES8156_MISC_CONTROL1_REG07 0x07
|
||||
#define ES8156_CLOCK_ON_OFF_REG08 0x08
|
||||
#define ES8156_MISC_CONTROL2_REG09 0x09
|
||||
#define ES8156_TIME_CONTROL1_REG0A 0x0a
|
||||
#define ES8156_TIME_CONTROL2_REG0B 0x0b
|
||||
/*
|
||||
* System Control
|
||||
*/
|
||||
#define ES8156_CHIP_STATUS_REG0C 0x0c
|
||||
#define ES8156_P2S_CONTROL_REG0D 0x0d
|
||||
#define ES8156_DAC_OSR_COUNTER_REG10 0x10
|
||||
/*
|
||||
* SDP Control
|
||||
*/
|
||||
#define ES8156_DAC_SDP_REG11 0x11
|
||||
#define ES8156_AUTOMUTE_SET_REG12 0x12
|
||||
#define ES8156_DAC_MUTE_REG13 0x13
|
||||
#define ES8156_VOLUME_CONTROL_REG14 0x14
|
||||
|
||||
/*
|
||||
* ALC Control
|
||||
*/
|
||||
#define ES8156_ALC_CONFIG1_REG15 0x15
|
||||
#define ES8156_ALC_CONFIG2_REG16 0x16
|
||||
#define ES8156_ALC_CONFIG3_REG17 0x17
|
||||
#define ES8156_MISC_CONTROL3_REG18 0x18
|
||||
#define ES8156_EQ_CONTROL1_REG19 0x19
|
||||
#define ES8156_EQ_CONTROL2_REG1A 0x1a
|
||||
/*
|
||||
* Analog System Control
|
||||
*/
|
||||
#define ES8156_ANALOG_SYS1_REG20 0x20
|
||||
#define ES8156_ANALOG_SYS2_REG21 0x21
|
||||
#define ES8156_ANALOG_SYS3_REG22 0x22
|
||||
#define ES8156_ANALOG_SYS4_REG23 0x23
|
||||
#define ES8156_ANALOG_LP_REG24 0x24
|
||||
#define ES8156_ANALOG_SYS5_REG25 0x25
|
||||
/*
|
||||
* Chip Information
|
||||
*/
|
||||
#define ES8156_I2C_PAGESEL_REGFC 0xFC
|
||||
#define ES8156_CHIPID1_REGFD 0xFD
|
||||
#define ES8156_CHIPID0_REGFE 0xFE
|
||||
#define ES8156_CHIP_VERSION_REGFF 0xFF
|
||||
|
||||
typedef enum {
|
||||
ES8156_VOL_MIN = 0x00, /*!< -95.5dB */
|
||||
ES8156_VOL_MIN_10dB = 0xAB, /*!< -10dB */
|
||||
ES8156_VOL_MIN_9dB = 0xAD, /*!< -9dB */
|
||||
ES8156_VOL_MIN_6dB = 0xB3, /*!< -6dB */
|
||||
ES8156_VOL_MIN_3dB = 0xB9, /*!< -3dB */
|
||||
ES8156_VOL_0dB = 0xBF, /*!< 0dB */
|
||||
ES8156_VOL_3dB = 0xC5, /*!< +3dB */
|
||||
ES8156_VOL_10dB = 0xD3, /*!< +10dB */
|
||||
ES8156_VOL_MAX = 0xFF, /*!< +32dB */
|
||||
} es8156_volume_t;
|
||||
|
||||
/*
|
||||
* @brief Initialize ES8156 codec chip
|
||||
*
|
||||
* @param codec_cfg configuration of ES8156
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_init(audio_hal_codec_config_t *codec_cfg);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ES8156 codec chip
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_deinit(void);
|
||||
|
||||
|
||||
esp_err_t es8156_config_fmt(es_i2s_fmt_t fmt);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8156 DAC mute or not. Basically you can use this function to mute the output or unmute
|
||||
*
|
||||
* @param enable enable(1) or disable(0)
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8156_codec_set_voice_mute(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Set voice volume
|
||||
*
|
||||
* @param volume: voice volume (0~100)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_set_voice_volume(uint8_t volume);
|
||||
|
||||
/**
|
||||
* @brief Get voice volume
|
||||
*
|
||||
* @param[out] *volume: voice volume (0~255)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_get_voice_volume(uint8_t *volume);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param is_right
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t es8156_set_channel(uint8_t is_right);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,683 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "i2c_bus.h"
|
||||
#include "esp_log.h"
|
||||
#include "es8311.h"
|
||||
#include "bsp_i2c.h"
|
||||
|
||||
/* ES8311 address
|
||||
* 0x32:CE=1;0x30:CE=0
|
||||
*/
|
||||
#define ES8311_ADDR 0x18
|
||||
|
||||
/*
|
||||
* to define the clock soure of MCLK
|
||||
*/
|
||||
#define FROM_MCLK_PIN 0
|
||||
#define FROM_SCLK_PIN 1
|
||||
#define ES8311_MCLK_SOURCE FROM_MCLK_PIN
|
||||
|
||||
/*
|
||||
* to define whether to reverse the clock
|
||||
*/
|
||||
#define INVERT_MCLK 0 // do not invert
|
||||
#define INVERT_SCLK 0
|
||||
|
||||
#define IS_DMIC 0 // Is it a digital microphone
|
||||
|
||||
#define MCLK_DIV_FRE 256
|
||||
|
||||
static i2c_bus_handle_t i2c_handle;
|
||||
|
||||
/*
|
||||
* Clock coefficient structer
|
||||
*/
|
||||
struct _coeff_div {
|
||||
uint32_t mclk; /* mclk frequency */
|
||||
uint32_t rate; /* sample rate */
|
||||
uint8_t pre_div; /* the pre divider with range from 1 to 8 */
|
||||
uint8_t pre_multi; /* the pre multiplier with x1, x2, x4 and x8 selection */
|
||||
uint8_t adc_div; /* adcclk divider */
|
||||
uint8_t dac_div; /* dacclk divider */
|
||||
uint8_t fs_mode; /* double speed or single speed, =0, ss, =1, ds */
|
||||
uint8_t lrck_h; /* adclrck divider and daclrck divider */
|
||||
uint8_t lrck_l;
|
||||
uint8_t bclk_div; /* sclk divider */
|
||||
uint8_t adc_osr; /* adc osr */
|
||||
uint8_t dac_osr; /* dac osr */
|
||||
};
|
||||
|
||||
/* codec hifi mclk clock divider coefficients */
|
||||
static const struct _coeff_div coeff_div[] = {
|
||||
//mclk rate pre_div mult adc_div dac_div fs_mode lrch lrcl bckdiv osr
|
||||
/* 8k */
|
||||
{12288000, 8000 , 0x06, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 8000 , 0x03, 0x02, 0x03, 0x03, 0x00, 0x05, 0xff, 0x18, 0x10, 0x10},
|
||||
{16384000, 8000 , 0x08, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{8192000 , 8000 , 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 8000 , 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{4096000 , 8000 , 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 8000 , 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2048000 , 8000 , 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 8000 , 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1024000 , 8000 , 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 11.025k */
|
||||
{11289600, 11025, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{5644800 , 11025, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2822400 , 11025, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1411200 , 11025, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 12k */
|
||||
{12288000, 12000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 12000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 12000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 12000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 16k */
|
||||
{12288000, 16000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 16000, 0x03, 0x02, 0x03, 0x03, 0x00, 0x02, 0xff, 0x0c, 0x10, 0x10},
|
||||
{16384000, 16000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{8192000 , 16000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 16000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{4096000 , 16000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 16000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2048000 , 16000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 16000, 0x03, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1024000 , 16000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 22.05k */
|
||||
{11289600, 22050, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{5644800 , 22050, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2822400 , 22050, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1411200 , 22050, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 24k */
|
||||
{12288000, 24000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 24000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 24000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 24000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 24000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 32k */
|
||||
{12288000, 32000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 32000, 0x03, 0x04, 0x03, 0x03, 0x00, 0x02, 0xff, 0x0c, 0x10, 0x10},
|
||||
{16384000, 32000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{8192000 , 32000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 32000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{4096000 , 32000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 32000, 0x03, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2048000 , 32000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 32000, 0x03, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
|
||||
{1024000 , 32000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 44.1k */
|
||||
{11289600, 44100, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{5644800 , 44100, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2822400 , 44100, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1411200 , 44100, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 48k */
|
||||
{12288000, 48000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 48000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 48000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 48000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 48000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
|
||||
/* 64k */
|
||||
{12288000, 64000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 64000, 0x03, 0x04, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
|
||||
{16384000, 64000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{8192000 , 64000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 64000, 0x01, 0x04, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
|
||||
{4096000 , 64000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 64000, 0x01, 0x08, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
|
||||
{2048000 , 64000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 64000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0xbf, 0x03, 0x18, 0x18},
|
||||
{1024000 , 64000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
|
||||
|
||||
/* 88.2k */
|
||||
{11289600, 88200, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{5644800 , 88200, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{2822400 , 88200, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1411200 , 88200, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
|
||||
|
||||
/* 96k */
|
||||
{12288000, 96000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{18432000, 96000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{6144000 , 96000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{3072000 , 96000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
|
||||
{1536000 , 96000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
|
||||
};
|
||||
|
||||
static const char *TAG = "DRV8311";
|
||||
|
||||
#define ES_ASSERT(a, format, b, ...) \
|
||||
if ((a) != 0) { \
|
||||
ESP_LOGE(TAG, format, ##__VA_ARGS__); \
|
||||
return b;\
|
||||
}
|
||||
|
||||
static esp_err_t es8311_write_reg(uint8_t reg_addr, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_byte(i2c_handle, reg_addr, data);
|
||||
}
|
||||
|
||||
static int es8311_read_reg(uint8_t reg_addr)
|
||||
{
|
||||
uint8_t data;
|
||||
i2c_bus_read_byte(i2c_handle, reg_addr, &data);
|
||||
return (int)data;
|
||||
}
|
||||
|
||||
/*
|
||||
* look for the coefficient in coeff_div[] table
|
||||
*/
|
||||
static int get_coeff(uint32_t mclk, uint32_t rate)
|
||||
{
|
||||
for (int i = 0; i < (sizeof(coeff_div) / sizeof(coeff_div[0])); i++) {
|
||||
if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* set es8311 dac mute or not
|
||||
* if mute = 0, dac un-mute
|
||||
* if mute = 1, dac mute
|
||||
*/
|
||||
static void es8311_mute(int mute)
|
||||
{
|
||||
uint8_t regv;
|
||||
regv = es8311_read_reg(ES8311_DAC_REG31) & 0x9f;
|
||||
if (mute) {
|
||||
es8311_write_reg(ES8311_SYSTEM_REG12, 0x02);
|
||||
es8311_write_reg(ES8311_DAC_REG31, regv | 0x60);
|
||||
es8311_write_reg(ES8311_DAC_REG32, 0x00);
|
||||
es8311_write_reg(ES8311_DAC_REG37, 0x08);
|
||||
} else {
|
||||
es8311_write_reg(ES8311_DAC_REG31, regv);
|
||||
es8311_write_reg(ES8311_SYSTEM_REG12, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* set es8311 into suspend mode
|
||||
*/
|
||||
static void es8311_suspend(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Enter into es8311_suspend()");
|
||||
es8311_write_reg(ES8311_DAC_REG32, 0x00);
|
||||
es8311_write_reg(ES8311_ADC_REG17, 0x00);
|
||||
es8311_write_reg(ES8311_SYSTEM_REG0E, 0xFF);
|
||||
es8311_write_reg(ES8311_SYSTEM_REG12, 0x02);
|
||||
es8311_write_reg(ES8311_SYSTEM_REG14, 0x00);
|
||||
es8311_write_reg(ES8311_SYSTEM_REG0D, 0xFA);
|
||||
es8311_write_reg(ES8311_ADC_REG15, 0x00);
|
||||
es8311_write_reg(ES8311_DAC_REG37, 0x08);
|
||||
es8311_write_reg(ES8311_GP_REG45, 0x01);
|
||||
}
|
||||
|
||||
esp_err_t es8311_codec_init(audio_hal_codec_config_t *codec_cfg)
|
||||
{
|
||||
uint8_t datmp, regv;
|
||||
int coeff;
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= bsp_i2c_add_device(&i2c_handle, ES8311_ADDR);
|
||||
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, 0x30);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG02, 0x00);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG03, 0x10);
|
||||
ret |= es8311_write_reg(ES8311_ADC_REG16, 0x24);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG04, 0x10);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG05, 0x00);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG0B, 0x00);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG0C, 0x00);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG10, 0x1F);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG11, 0x7F);
|
||||
ret |= es8311_write_reg(ES8311_RESET_REG00, 0x80);
|
||||
/*
|
||||
* Set Codec into Master or Slave mode
|
||||
*/
|
||||
regv = es8311_read_reg(ES8311_RESET_REG00);
|
||||
/*
|
||||
* Set master/slave audio interface
|
||||
*/
|
||||
audio_hal_codec_i2s_iface_t *i2s_cfg = &(codec_cfg->i2s_iface);
|
||||
switch (i2s_cfg->mode) {
|
||||
case AUDIO_HAL_MODE_MASTER: /* MASTER MODE */
|
||||
ESP_LOGI(TAG, "ES8311 in Master mode");
|
||||
regv |= 0x40;
|
||||
break;
|
||||
case AUDIO_HAL_MODE_SLAVE: /* SLAVE MODE */
|
||||
ESP_LOGI(TAG, "ES8311 in Slave mode");
|
||||
regv &= 0xBF;
|
||||
break;
|
||||
default:
|
||||
regv &= 0xBF;
|
||||
}
|
||||
ret |= es8311_write_reg(ES8311_RESET_REG00, regv);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, 0x3F);
|
||||
/*
|
||||
* Select clock source for internal mclk
|
||||
*/
|
||||
|
||||
int es8311_mclk_src = ES8311_MCLK_SOURCE;
|
||||
switch (es8311_mclk_src) {
|
||||
case FROM_MCLK_PIN:
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
|
||||
regv &= 0x7F;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
|
||||
break;
|
||||
case FROM_SCLK_PIN:
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
|
||||
regv |= 0x80;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
|
||||
break;
|
||||
default:
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
|
||||
regv &= 0x7F;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
|
||||
break;
|
||||
}
|
||||
int sample_fre = 0;
|
||||
int mclk_fre = 0;
|
||||
switch (i2s_cfg->samples) {
|
||||
case AUDIO_HAL_08K_SAMPLES:
|
||||
sample_fre = 8000;
|
||||
break;
|
||||
case AUDIO_HAL_11K_SAMPLES:
|
||||
sample_fre = 11025;
|
||||
break;
|
||||
case AUDIO_HAL_16K_SAMPLES:
|
||||
sample_fre = 16000;
|
||||
break;
|
||||
case AUDIO_HAL_22K_SAMPLES:
|
||||
sample_fre = 22050;
|
||||
break;
|
||||
case AUDIO_HAL_24K_SAMPLES:
|
||||
sample_fre = 24000;
|
||||
break;
|
||||
case AUDIO_HAL_32K_SAMPLES:
|
||||
sample_fre = 32000;
|
||||
break;
|
||||
case AUDIO_HAL_44K_SAMPLES:
|
||||
sample_fre = 44100;
|
||||
break;
|
||||
case AUDIO_HAL_48K_SAMPLES:
|
||||
sample_fre = 48000;
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unable to configure sample rate %dHz", sample_fre);
|
||||
break;
|
||||
}
|
||||
mclk_fre = sample_fre * MCLK_DIV_FRE;
|
||||
coeff = get_coeff(mclk_fre, sample_fre);
|
||||
if (coeff < 0) {
|
||||
ESP_LOGE(TAG, "Unable to configure sample rate %dHz with %dHz MCLK", sample_fre, mclk_fre);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
/*
|
||||
* Set clock parammeters
|
||||
*/
|
||||
if (coeff >= 0) {
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG02) & 0x07;
|
||||
regv |= (coeff_div[coeff].pre_div - 1) << 5;
|
||||
datmp = 0;
|
||||
switch (coeff_div[coeff].pre_multi) {
|
||||
case 1:
|
||||
datmp = 0;
|
||||
break;
|
||||
case 2:
|
||||
datmp = 1;
|
||||
break;
|
||||
case 4:
|
||||
datmp = 2;
|
||||
break;
|
||||
case 8:
|
||||
datmp = 3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ES8311_MCLK_SOURCE == FROM_SCLK_PIN) {
|
||||
datmp = 3; /* DIG_MCLK = LRCK * 256 = BCLK * 8 */
|
||||
}
|
||||
regv |= (datmp) << 3;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG02, regv);
|
||||
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG05) & 0x00;
|
||||
regv |= (coeff_div[coeff].adc_div - 1) << 4;
|
||||
regv |= (coeff_div[coeff].dac_div - 1) << 0;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG05, regv);
|
||||
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG03) & 0x80;
|
||||
regv |= coeff_div[coeff].fs_mode << 6;
|
||||
regv |= coeff_div[coeff].adc_osr << 0;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG03, regv);
|
||||
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG04) & 0x80;
|
||||
regv |= coeff_div[coeff].dac_osr << 0;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG04, regv);
|
||||
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG07) & 0xC0;
|
||||
regv |= coeff_div[coeff].lrck_h << 0;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG07, regv);
|
||||
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG08) & 0x00;
|
||||
regv |= coeff_div[coeff].lrck_l << 0;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG08, regv);
|
||||
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG06) & 0xE0;
|
||||
if (coeff_div[coeff].bclk_div < 19) {
|
||||
regv |= (coeff_div[coeff].bclk_div - 1) << 0;
|
||||
} else {
|
||||
regv |= (coeff_div[coeff].bclk_div) << 0;
|
||||
}
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG06, regv);
|
||||
}
|
||||
|
||||
/*
|
||||
* mclk inverted or not
|
||||
*/
|
||||
if (INVERT_MCLK) {
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
|
||||
regv |= 0x40;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
|
||||
} else {
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
|
||||
regv &= ~(0x40);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
|
||||
}
|
||||
/*
|
||||
* sclk inverted or not
|
||||
*/
|
||||
if (INVERT_SCLK) {
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG06);
|
||||
regv |= 0x20;
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG06, regv);
|
||||
} else {
|
||||
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG06);
|
||||
regv &= ~(0x20);
|
||||
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG06, regv);
|
||||
}
|
||||
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG13, 0x10);
|
||||
ret |= es8311_write_reg(ES8311_ADC_REG1B, 0x0A);
|
||||
ret |= es8311_write_reg(ES8311_ADC_REG1C, 0x6A);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8311_codec_deinit()
|
||||
{
|
||||
i2c_bus_delete(i2c_handle);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8311_config_fmt(es_i2s_fmt_t fmt)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t adc_iface = 0, dac_iface = 0;
|
||||
dac_iface = es8311_read_reg(ES8311_SDPIN_REG09);
|
||||
adc_iface = es8311_read_reg(ES8311_SDPOUT_REG0A);
|
||||
switch (fmt) {
|
||||
case AUDIO_HAL_I2S_NORMAL:
|
||||
ESP_LOGD(TAG, "ES8311 in I2S Format");
|
||||
dac_iface &= 0xFC;
|
||||
adc_iface &= 0xFC;
|
||||
break;
|
||||
case AUDIO_HAL_I2S_LEFT:
|
||||
case AUDIO_HAL_I2S_RIGHT:
|
||||
ESP_LOGD(TAG, "ES8311 in LJ Format");
|
||||
adc_iface &= 0xFC;
|
||||
dac_iface &= 0xFC;
|
||||
adc_iface |= 0x01;
|
||||
dac_iface |= 0x01;
|
||||
break;
|
||||
case AUDIO_HAL_I2S_DSP:
|
||||
ESP_LOGD(TAG, "ES8311 in DSP-B Format");
|
||||
adc_iface &= 0xDC;
|
||||
dac_iface &= 0xDC;
|
||||
adc_iface |= 0x23;
|
||||
dac_iface |= 0x23;
|
||||
break;
|
||||
default:
|
||||
dac_iface &= 0xFC;
|
||||
adc_iface &= 0xFC;
|
||||
break;
|
||||
}
|
||||
ret |= es8311_write_reg(ES8311_SDPIN_REG09, dac_iface);
|
||||
ret |= es8311_write_reg(ES8311_SDPOUT_REG0A, adc_iface);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es8311_set_bits_per_sample(audio_hal_iface_bits_t bits)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t adc_iface = 0, dac_iface = 0;
|
||||
dac_iface = es8311_read_reg(ES8311_SDPIN_REG09);
|
||||
adc_iface = es8311_read_reg(ES8311_SDPOUT_REG0A);
|
||||
switch (bits) {
|
||||
case AUDIO_HAL_BIT_LENGTH_16BITS:
|
||||
dac_iface |= 0x0c;
|
||||
adc_iface |= 0x0c;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_24BITS:
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_32BITS:
|
||||
dac_iface |= 0x10;
|
||||
adc_iface |= 0x10;
|
||||
break;
|
||||
default:
|
||||
dac_iface |= 0x0c;
|
||||
adc_iface |= 0x0c;
|
||||
break;
|
||||
|
||||
}
|
||||
ret |= es8311_write_reg(ES8311_SDPIN_REG09, dac_iface);
|
||||
ret |= es8311_write_reg(ES8311_SDPOUT_REG0A, adc_iface);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es8311_codec_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface)
|
||||
{
|
||||
int ret = ESP_OK;
|
||||
ret |= es8311_set_bits_per_sample(iface->bits);
|
||||
ret |= es8311_config_fmt(iface->fmt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es8311_codec_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
es_module_t es_mode = ES_MODULE_MIN;
|
||||
|
||||
switch (mode) {
|
||||
case AUDIO_HAL_CODEC_MODE_ENCODE:
|
||||
es_mode = ES_MODULE_ADC;
|
||||
break;
|
||||
case AUDIO_HAL_CODEC_MODE_LINE_IN:
|
||||
es_mode = ES_MODULE_LINE;
|
||||
break;
|
||||
case AUDIO_HAL_CODEC_MODE_DECODE:
|
||||
es_mode = ES_MODULE_DAC;
|
||||
break;
|
||||
case AUDIO_HAL_CODEC_MODE_BOTH:
|
||||
es_mode = ES_MODULE_ADC_DAC;
|
||||
break;
|
||||
default:
|
||||
es_mode = ES_MODULE_DAC;
|
||||
ESP_LOGW(TAG, "Codec mode not support, default is decode mode");
|
||||
break;
|
||||
}
|
||||
|
||||
if (ctrl_state == AUDIO_HAL_CTRL_START) {
|
||||
ret |= es8311_start(es_mode);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "The codec is about to stop");
|
||||
ret |= es8311_stop(es_mode);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es8311_start(es_module_t mode)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t adc_iface = 0, dac_iface = 0;
|
||||
|
||||
dac_iface = es8311_read_reg(ES8311_SDPIN_REG09) & 0xBF;
|
||||
adc_iface = es8311_read_reg(ES8311_SDPOUT_REG0A) & 0xBF;
|
||||
adc_iface |= BIT(6);
|
||||
dac_iface |= BIT(6);
|
||||
|
||||
if (mode == ES_MODULE_LINE) {
|
||||
ESP_LOGE(TAG, "The codec es8311 doesn't support ES_MODULE_LINE mode");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
|
||||
adc_iface &= ~(BIT(6));
|
||||
}
|
||||
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
|
||||
dac_iface &= ~(BIT(6));
|
||||
}
|
||||
|
||||
ret |= es8311_write_reg(ES8311_SDPIN_REG09, dac_iface);
|
||||
ret |= es8311_write_reg(ES8311_SDPOUT_REG0A, adc_iface);
|
||||
|
||||
ret |= es8311_write_reg(ES8311_ADC_REG17, 0xBF);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG0E, 0x02);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG12, 0x00);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG14, 0x1A);
|
||||
|
||||
/*
|
||||
* pdm dmic enable or disable
|
||||
*/
|
||||
int regv = 0;
|
||||
if (IS_DMIC) {
|
||||
regv = es8311_read_reg(ES8311_SYSTEM_REG14);
|
||||
regv |= 0x40;
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG14, regv);
|
||||
} else {
|
||||
regv = es8311_read_reg(ES8311_SYSTEM_REG14);
|
||||
regv &= ~(0x40);
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG14, regv);
|
||||
}
|
||||
|
||||
ret |= es8311_write_reg(ES8311_SYSTEM_REG0D, 0x01);
|
||||
ret |= es8311_write_reg(ES8311_ADC_REG15, 0x40);
|
||||
ret |= es8311_write_reg(ES8311_DAC_REG37, 0x48);
|
||||
ret |= es8311_write_reg(ES8311_GP_REG45, 0x00);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es8311_stop(es_module_t mode)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
es8311_suspend();
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t es8311_codec_set_voice_volume(int volume)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
if (volume < 0) {
|
||||
volume = 0;
|
||||
} else if (volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
int vol = (volume) * 2550 / 1000;
|
||||
ESP_LOGD(TAG, "SET: volume:%d", vol);
|
||||
es8311_write_reg(ES8311_DAC_REG32, vol);
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t es8311_codec_get_voice_volume(int *volume)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
int regv = 0;
|
||||
regv = es8311_read_reg(ES8311_DAC_REG32);
|
||||
if (regv == ESP_FAIL) {
|
||||
*volume = 0;
|
||||
res = ESP_FAIL;
|
||||
} else {
|
||||
*volume = regv * 100 / 256;
|
||||
}
|
||||
ESP_LOGD(TAG, "GET: res:%d, volume:%d", regv, *volume);
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t es8311_set_voice_mute(bool enable)
|
||||
{
|
||||
ESP_LOGD(TAG, "Es8311SetVoiceMute volume:%d", enable);
|
||||
es8311_mute(enable);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8311_get_voice_mute(int *mute)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t reg = 0;
|
||||
res = es8311_read_reg(ES8311_DAC_REG31);
|
||||
if (res != ESP_FAIL) {
|
||||
reg = (res & 0x20) >> 5;
|
||||
}
|
||||
*mute = reg;
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t es8311_set_mic_gain(es8311_mic_gain_t gain_db)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
res = es8311_write_reg(ES8311_ADC_REG16, gain_db); // MIC gain scale
|
||||
return res;
|
||||
}
|
||||
|
||||
void es8311_read_all()
|
||||
{
|
||||
for (int i = 0; i < 0x4A; i++) {
|
||||
uint8_t reg = es8311_read_reg(i);
|
||||
ets_printf("REG:%02x, %02x\n", reg, i);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t es8311_set_channel(int is_right)
|
||||
{
|
||||
uint8_t reg_val = es8311_read_reg(ES8311_SDPIN_REG09);
|
||||
if (is_right) {
|
||||
reg_val |= 0b10000000;
|
||||
} else {
|
||||
reg_val &= 0b01111111;
|
||||
}
|
||||
return es8311_write_reg(ES8311_SDPIN_REG09, reg_val);
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ES8311_H
|
||||
#define _ES8311_H
|
||||
|
||||
#include "audio_hal.h"
|
||||
#include "esp_types.h"
|
||||
#include "esxxx_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ES8311_REGISTER NAME_REG_REGISTER ADDRESS
|
||||
*/
|
||||
#define ES8311_RESET_REG00 0x00 /*reset digital,csm,clock manager etc.*/
|
||||
|
||||
/*
|
||||
* Clock Scheme Register definition
|
||||
*/
|
||||
#define ES8311_CLK_MANAGER_REG01 0x01 /* select clk src for mclk, enable clock for codec */
|
||||
#define ES8311_CLK_MANAGER_REG02 0x02 /* clk divider and clk multiplier */
|
||||
#define ES8311_CLK_MANAGER_REG03 0x03 /* adc fsmode and osr */
|
||||
#define ES8311_CLK_MANAGER_REG04 0x04 /* dac osr */
|
||||
#define ES8311_CLK_MANAGER_REG05 0x05 /* clk divier for adc and dac */
|
||||
#define ES8311_CLK_MANAGER_REG06 0x06 /* bclk inverter and divider */
|
||||
#define ES8311_CLK_MANAGER_REG07 0x07 /* tri-state, lrck divider */
|
||||
#define ES8311_CLK_MANAGER_REG08 0x08 /* lrck divider */
|
||||
/*
|
||||
* SDP
|
||||
*/
|
||||
#define ES8311_SDPIN_REG09 0x09 /* dac serial digital port */
|
||||
#define ES8311_SDPOUT_REG0A 0x0A /* adc serial digital port */
|
||||
/*
|
||||
* SYSTEM
|
||||
*/
|
||||
#define ES8311_SYSTEM_REG0B 0x0B /* system */
|
||||
#define ES8311_SYSTEM_REG0C 0x0C /* system */
|
||||
#define ES8311_SYSTEM_REG0D 0x0D /* system, power up/down */
|
||||
#define ES8311_SYSTEM_REG0E 0x0E /* system, power up/down */
|
||||
#define ES8311_SYSTEM_REG0F 0x0F /* system, low power */
|
||||
#define ES8311_SYSTEM_REG10 0x10 /* system */
|
||||
#define ES8311_SYSTEM_REG11 0x11 /* system */
|
||||
#define ES8311_SYSTEM_REG12 0x12 /* system, Enable DAC */
|
||||
#define ES8311_SYSTEM_REG13 0x13 /* system */
|
||||
#define ES8311_SYSTEM_REG14 0x14 /* system, select DMIC, select analog pga gain */
|
||||
/*
|
||||
* ADC
|
||||
*/
|
||||
#define ES8311_ADC_REG15 0x15 /* ADC, adc ramp rate, dmic sense */
|
||||
#define ES8311_ADC_REG16 0x16 /* ADC */
|
||||
#define ES8311_ADC_REG17 0x17 /* ADC, volume */
|
||||
#define ES8311_ADC_REG18 0x18 /* ADC, alc enable and winsize */
|
||||
#define ES8311_ADC_REG19 0x19 /* ADC, alc maxlevel */
|
||||
#define ES8311_ADC_REG1A 0x1A /* ADC, alc automute */
|
||||
#define ES8311_ADC_REG1B 0x1B /* ADC, alc automute, adc hpf s1 */
|
||||
#define ES8311_ADC_REG1C 0x1C /* ADC, equalizer, hpf s2 */
|
||||
/*
|
||||
* DAC
|
||||
*/
|
||||
#define ES8311_DAC_REG31 0x31 /* DAC, mute */
|
||||
#define ES8311_DAC_REG32 0x32 /* DAC, volume */
|
||||
#define ES8311_DAC_REG33 0x33 /* DAC, offset */
|
||||
#define ES8311_DAC_REG34 0x34 /* DAC, drc enable, drc winsize */
|
||||
#define ES8311_DAC_REG35 0x35 /* DAC, drc maxlevel, minilevel */
|
||||
#define ES8311_DAC_REG37 0x37 /* DAC, ramprate */
|
||||
/*
|
||||
*GPIO
|
||||
*/
|
||||
#define ES8311_GPIO_REG44 0x44 /* GPIO, dac2adc for test */
|
||||
#define ES8311_GP_REG45 0x45 /* GP CONTROL */
|
||||
/*
|
||||
* CHIP
|
||||
*/
|
||||
#define ES8311_CHD1_REGFD 0xFD /* CHIP ID1 */
|
||||
#define ES8311_CHD2_REGFE 0xFE /* CHIP ID2 */
|
||||
#define ES8311_CHVER_REGFF 0xFF /* VERSION */
|
||||
#define ES8311_CHD1_REGFD 0xFD /* CHIP ID1 */
|
||||
|
||||
#define ES8311_MAX_REGISTER 0xFF
|
||||
|
||||
typedef enum {
|
||||
ES8311_MIC_GAIN_MIN = -1,
|
||||
ES8311_MIC_GAIN_0DB,
|
||||
ES8311_MIC_GAIN_6DB,
|
||||
ES8311_MIC_GAIN_12DB,
|
||||
ES8311_MIC_GAIN_18DB,
|
||||
ES8311_MIC_GAIN_24DB,
|
||||
ES8311_MIC_GAIN_30DB,
|
||||
ES8311_MIC_GAIN_36DB,
|
||||
ES8311_MIC_GAIN_42DB,
|
||||
ES8311_MIC_GAIN_MAX
|
||||
} es8311_mic_gain_t;
|
||||
|
||||
/*
|
||||
* @brief Initialize ES8311 codec chip
|
||||
*
|
||||
* @param codec_cfg configuration of ES8311
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_codec_init(audio_hal_codec_config_t *codec_cfg);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ES8311 codec chip
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_codec_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Control ES8311 codec chip
|
||||
*
|
||||
* @param mode codec mode
|
||||
* @param ctrl_state start or stop decode or encode progress
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8311_codec_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8311 codec mode and I2S interface
|
||||
*
|
||||
* @param mode codec mode
|
||||
* @param iface I2S config
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8311_codec_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8311 DAC mute or not. Basically you can use this function to mute the output or unmute
|
||||
*
|
||||
* @param enable enable(1) or disable(0)
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8311_set_voice_mute(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Set voice volume
|
||||
*
|
||||
* @param volume: voice volume (0~100)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_codec_set_voice_volume(int volume);
|
||||
|
||||
/**
|
||||
* @brief Get voice volume
|
||||
*
|
||||
* @param[out] *volume: voice volume (0~100)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_codec_get_voice_volume(int *volume);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8311 I2S format
|
||||
*
|
||||
* @param cfg: ES8388 I2S format
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_config_fmt(es_i2s_fmt_t fmt);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8311 data sample bits
|
||||
*
|
||||
* @param bit_per_sample: bit number of per sample
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_set_bits_per_sample(audio_hal_iface_bits_t bits);
|
||||
|
||||
/**
|
||||
* @brief Start ES8311 codec chip
|
||||
*
|
||||
* @param mode: set ADC or DAC or both
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_start(es_module_t mode);
|
||||
|
||||
/**
|
||||
* @brief Stop ES8311 codec chip
|
||||
*
|
||||
* @param mode: set ADC or DAC or both
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8311_stop(es_module_t mode);
|
||||
|
||||
/**
|
||||
* @brief Get ES8311 DAC mute status
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t es8311_get_voice_mute(int *mute);
|
||||
|
||||
/**
|
||||
* @brief Set ES8311 mic gain
|
||||
*
|
||||
* @param gain db of mic gain
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8311_set_mic_gain(es8311_mic_gain_t gain_db);
|
||||
|
||||
/**
|
||||
* @brief Print all ES8311 registers
|
||||
*
|
||||
* @return
|
||||
* - void
|
||||
*/
|
||||
void es8311_read_all();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param is_right
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t es8311_set_channel(int is_right);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,494 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "i2c_bus.h"
|
||||
#include "es8388.h"
|
||||
#include "bsp_i2c.h"
|
||||
|
||||
static const char *ES_TAG = "ES8388_DRIVER";
|
||||
static i2c_bus_handle_t i2c_handle;
|
||||
|
||||
#define ES_ASSERT(a, format, b, ...) \
|
||||
if ((a) != 0) { \
|
||||
ESP_LOGE(ES_TAG, format, ##__VA_ARGS__); \
|
||||
return b;\
|
||||
}
|
||||
|
||||
static esp_err_t es_write_reg(uint8_t slave_addr, uint8_t reg_add, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_byte(i2c_handle, reg_add, data);
|
||||
}
|
||||
|
||||
static esp_err_t es_read_reg(uint8_t reg_add, uint8_t *p_data)
|
||||
{
|
||||
return i2c_bus_read_byte(i2c_handle, reg_add, p_data);
|
||||
}
|
||||
|
||||
void es8388_read_all()
|
||||
{
|
||||
for (int i = 0; i < 50; i++) {
|
||||
uint8_t reg = 0;
|
||||
es_read_reg(i, ®);
|
||||
ets_printf("%x: %x\n", i, reg);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t es8388_write_reg(uint8_t reg_add, uint8_t data)
|
||||
{
|
||||
return es_write_reg(ES8388_ADDR, reg_add, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 ADC and DAC volume. Basicly you can consider this as ADC and DAC gain
|
||||
*
|
||||
* @param mode: set ADC or DAC or all
|
||||
* @param volume: -96 ~ 0 for example Es8388SetAdcDacVolume(ES_MODULE_ADC, 30, 6); means set ADC volume -30.5db
|
||||
* @param dot: whether include 0.5. for example Es8388SetAdcDacVolume(ES_MODULE_ADC, 30, 4); means set ADC volume -30db
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - (0) Success
|
||||
*/
|
||||
static int es8388_set_adc_dac_volume(int mode, int volume, int dot)
|
||||
{
|
||||
int res = 0;
|
||||
if ( volume < -96 || volume > 0 ) {
|
||||
ESP_LOGW(ES_TAG, "Warning: volume < -96! or > 0!\n");
|
||||
if (volume < -96)
|
||||
volume = -96;
|
||||
else
|
||||
volume = 0;
|
||||
}
|
||||
dot = (dot >= 5 ? 1 : 0);
|
||||
volume = (-volume << 1) + dot;
|
||||
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL8, volume);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL9, volume); //ADC Right Volume=0db
|
||||
}
|
||||
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL5, volume);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL4, volume);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Power Management
|
||||
*
|
||||
* @param mod: if ES_POWER_CHIP, the whole chip including ADC and DAC is enabled
|
||||
* @param enable: false to disable true to enable
|
||||
*
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_start(es_module_t mode)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t prev_data = 0, data = 0;
|
||||
es_read_reg(ES8388_DACCONTROL21, &prev_data);
|
||||
if (mode == ES_MODULE_LINE) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL16, 0x09); // 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2 by pass enable
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL17, 0x50); // left DAC to left mixer enable and LIN signal to left mixer enable 0db : bupass enable
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL20, 0x50); // right DAC to right mixer enable and LIN signal to right mixer enable 0db : bupass enable
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL21, 0xC0); //enable adc
|
||||
} else {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL21, 0x80); //enable dac
|
||||
}
|
||||
es_read_reg(ES8388_DACCONTROL21, &data);
|
||||
if (prev_data != data) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_CHIPPOWER, 0xF0); //start state machine
|
||||
// res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL1, 0x16);
|
||||
// res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL2, 0x50);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_CHIPPOWER, 0x00); //start state machine
|
||||
}
|
||||
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC || mode == ES_MODULE_LINE) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCPOWER, 0x00); //power up adc and line in
|
||||
}
|
||||
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC || mode == ES_MODULE_LINE) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER, 0x3c); //power up dac and line out
|
||||
res |= es8388_set_voice_mute(false);
|
||||
ESP_LOGD(ES_TAG, "es8388_start default is mode:%d", mode);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Power Management
|
||||
*
|
||||
* @param mod: if ES_POWER_CHIP, the whole chip including ADC and DAC is enabled
|
||||
* @param enable: false to disable true to enable
|
||||
*
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_stop(es_module_t mode)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
if (mode == ES_MODULE_LINE) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL21, 0x80); //enable dac
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL16, 0x00); // 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL17, 0x90); // only left DAC to left mixer enable 0db
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL20, 0x90); // only right DAC to right mixer enable 0db
|
||||
return res;
|
||||
}
|
||||
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER, 0x00);
|
||||
res |= es8388_set_voice_mute(true); //res |= Es8388SetAdcDacVolume(ES_MODULE_DAC, -96, 5); // 0db
|
||||
//res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER, 0xC0); //power down dac and line out
|
||||
}
|
||||
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
|
||||
//res |= Es8388SetAdcDacVolume(ES_MODULE_ADC, -96, 5); // 0db
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCPOWER, 0xFF); //power down adc and line in
|
||||
}
|
||||
if (mode == ES_MODULE_ADC_DAC) {
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL21, 0x9C); //disable mclk
|
||||
// res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL1, 0x00);
|
||||
// res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL2, 0x58);
|
||||
// res |= es_write_reg(ES8388_ADDR, ES8388_CHIPPOWER, 0xF3); //stop state machine
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Config I2s clock in MSATER mode
|
||||
*
|
||||
* @param cfg.sclkDiv: generate SCLK by dividing MCLK in MSATER mode
|
||||
* @param cfg.lclkDiv: generate LCLK by dividing MCLK in MSATER mode
|
||||
*
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_i2s_config_clock(es_i2s_clock_t cfg)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_MASTERMODE, cfg.sclk_div);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL5, cfg.lclk_div); //ADCFsMode,singel SPEED,RATIO=256
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL2, cfg.lclk_div); //ADCFsMode,singel SPEED,RATIO=256
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t es8388_deinit(void)
|
||||
{
|
||||
int res = 0;
|
||||
res = es_write_reg(ES8388_ADDR, ES8388_CHIPPOWER, 0xFF); //reset and stop es8388
|
||||
i2c_bus_delete(i2c_handle);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_init(audio_hal_codec_config_t *cfg)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
bsp_i2c_add_device(&i2c_handle, ES8388_ADDR);
|
||||
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL3, 0x04); // 0x04 mute/0x00 unmute&ramp;DAC unmute and disabled digital volume control soft ramp
|
||||
/* Chip Control and Power Management */
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL2, 0x50);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_CHIPPOWER, 0x00); //normal all and power up all
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_MASTERMODE, cfg->i2s_iface.mode); //CODEC IN I2S SLAVE MODE
|
||||
|
||||
/* dac */
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER, 0xC0); //disable DAC and disable Lout/Rout/1/2
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL1, 0x12); //Enfr=0,Play&Record Mode,(0x17-both of mic&paly)
|
||||
// res |= es_write_reg(ES8388_ADDR, ES8388_CONTROL2, 0); //LPVrefBuf=0,Pdn_ana=0
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL1, 0x18);//1a 0x18:16bit iis , 0x00:24
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL2, 0x02); //DACFsMode,SINGLE SPEED; DACFsRatio,256
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL16, 0x00); // 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL17, 0x90); // only left DAC to left mixer enable 0db
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL20, 0x90); // only right DAC to right mixer enable 0db
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL21, 0x80); //set internal ADC and DAC use the same LRCK clock, ADC LRCK as internal LRCK
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL23, 0x00); //vroi=0
|
||||
res |= es8388_set_adc_dac_volume(ES_MODULE_DAC, 0, 0); // 0db
|
||||
int tmp = 0;
|
||||
if (AUDIO_HAL_DAC_OUTPUT_LINE2 == cfg->dac_output) {
|
||||
tmp = DAC_OUTPUT_LOUT1 | DAC_OUTPUT_ROUT1;
|
||||
} else if (AUDIO_HAL_DAC_OUTPUT_LINE1 == cfg->dac_output) {
|
||||
tmp = DAC_OUTPUT_LOUT2 | DAC_OUTPUT_ROUT2;
|
||||
} else {
|
||||
tmp = DAC_OUTPUT_LOUT1 | DAC_OUTPUT_LOUT2 | DAC_OUTPUT_ROUT1 | DAC_OUTPUT_ROUT2;
|
||||
}
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER, tmp); //0x3c Enable DAC and Enable Lout/Rout/1/2
|
||||
/* adc */
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCPOWER, 0xFF);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL1, 0xbb); // MIC Left and Right channel PGA gain
|
||||
tmp = 0;
|
||||
if (AUDIO_HAL_ADC_INPUT_LINE1 == cfg->adc_input) {
|
||||
tmp = ADC_INPUT_LINPUT1_RINPUT1;
|
||||
} else if (AUDIO_HAL_ADC_INPUT_LINE2 == cfg->adc_input) {
|
||||
tmp = ADC_INPUT_LINPUT2_RINPUT2;
|
||||
} else {
|
||||
tmp = ADC_INPUT_DIFFERENCE;
|
||||
}
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL2, tmp); //0x00 LINSEL & RINSEL, LIN1/RIN1 as ADC Input; DSSEL,use one DS Reg11; DSR, LINPUT1-RINPUT1
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL3, 0x02);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL4, 0x0d); // Left/Right data, Left/Right justified mode, Bits length, I2S format
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL5, 0x02); //ADCFsMode,singel SPEED,RATIO=256
|
||||
//ALC for Microphone
|
||||
res |= es8388_set_adc_dac_volume(ES_MODULE_ADC, 0, 0); // 0db
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCPOWER, 0x09); //Power on ADC, Enable LIN&RIN, Power off MICBIAS, set int1lp to low power mode
|
||||
|
||||
ESP_LOGI(ES_TAG, "init,out:%02x, in:%02x", cfg->dac_output, cfg->adc_input);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 I2S format
|
||||
*
|
||||
* @param mode: set ADC or DAC or all
|
||||
* @param bitPerSample: see Es8388I2sFmt
|
||||
*
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_config_fmt(es_module_t mode, es_i2s_fmt_t fmt)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t reg = 0;
|
||||
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
|
||||
res = es_read_reg(ES8388_ADCCONTROL4, ®);
|
||||
reg = reg & 0xfc;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL4, reg | fmt);
|
||||
}
|
||||
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
|
||||
res = es_read_reg(ES8388_DACCONTROL1, ®);
|
||||
reg = reg & 0xf9;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL1, reg | (fmt << 1));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param volume: 0 ~ 100
|
||||
*
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_set_voice_volume(int volume)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
if (volume < 0)
|
||||
volume = 0;
|
||||
else if (volume > 100)
|
||||
volume = 100;
|
||||
volume /= 3;
|
||||
res = es_write_reg(ES8388_ADDR, ES8388_DACCONTROL24, volume);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL25, volume);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL26, 0);
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL27, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* volume
|
||||
*/
|
||||
esp_err_t es8388_get_voice_volume(int *volume)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t reg = 0;
|
||||
res = es_read_reg(ES8388_DACCONTROL24, ®);
|
||||
if (res == ESP_FAIL) {
|
||||
*volume = 0;
|
||||
} else {
|
||||
*volume = reg;
|
||||
*volume *= 3;
|
||||
if (*volume == 99)
|
||||
*volume = 100;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 data sample bits
|
||||
*
|
||||
* @param mode: set ADC or DAC or all
|
||||
* @param bitPerSample: see BitsLength
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_set_bits_per_sample(es_module_t mode, es_bits_length_t bits_length)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t reg = 0;
|
||||
int bits = (int)bits_length;
|
||||
|
||||
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
|
||||
res = es_read_reg(ES8388_ADCCONTROL4, ®);
|
||||
reg = reg & 0xe3;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL4, reg | (bits << 2));
|
||||
}
|
||||
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
|
||||
res = es_read_reg(ES8388_DACCONTROL1, ®);
|
||||
reg = reg & 0xc7;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL1, reg | (bits << 3));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 DAC mute or not. Basically you can use this function to mute the output or unmute
|
||||
*
|
||||
* @param enable: enable or disable
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_set_voice_mute(bool enable)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t reg = 0;
|
||||
res = es_read_reg(ES8388_DACCONTROL3, ®);
|
||||
reg = reg & 0xFB;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL3, reg | (((int)enable) << 2));
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t es8388_get_voice_mute(void)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
uint8_t reg = 0;
|
||||
res = es_read_reg(ES8388_DACCONTROL3, ®);
|
||||
if (res == ESP_OK) {
|
||||
reg = (reg & 0x04) >> 2;
|
||||
}
|
||||
return res == ESP_OK ? reg : res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gain: Config DAC Output
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_config_dac_output(int output)
|
||||
{
|
||||
esp_err_t res;
|
||||
uint8_t reg = 0;
|
||||
res = es_read_reg(ES8388_DACPOWER, ®);
|
||||
reg = reg & 0xc3;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER, reg | output);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gain: Config ADC input
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_config_adc_input(es_adc_input_t input)
|
||||
{
|
||||
esp_err_t res;
|
||||
uint8_t reg = 0;
|
||||
res = es_read_reg(ES8388_ADCCONTROL2, ®);
|
||||
reg = reg & 0x0f;
|
||||
res |= es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL2, reg | input);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gain: see es_mic_gain_t
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - (0) Success
|
||||
*/
|
||||
esp_err_t es8388_set_mic_gain(es_mic_gain_t gain)
|
||||
{
|
||||
esp_err_t res, gain_n;
|
||||
gain_n = (int)gain / 3;
|
||||
gain_n = (gain_n << 4) + gain_n;
|
||||
res = es_write_reg(ES8388_ADDR, ES8388_ADCCONTROL1, gain_n); //MIC PGA
|
||||
return res;
|
||||
}
|
||||
|
||||
int es8388_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state)
|
||||
{
|
||||
int res = 0;
|
||||
int es_mode_t = 0;
|
||||
switch (mode) {
|
||||
case AUDIO_HAL_CODEC_MODE_ENCODE:
|
||||
es_mode_t = ES_MODULE_ADC;
|
||||
break;
|
||||
case AUDIO_HAL_CODEC_MODE_LINE_IN:
|
||||
es_mode_t = ES_MODULE_LINE;
|
||||
break;
|
||||
case AUDIO_HAL_CODEC_MODE_DECODE:
|
||||
es_mode_t = ES_MODULE_DAC;
|
||||
break;
|
||||
case AUDIO_HAL_CODEC_MODE_BOTH:
|
||||
es_mode_t = ES_MODULE_ADC_DAC;
|
||||
break;
|
||||
default:
|
||||
es_mode_t = ES_MODULE_DAC;
|
||||
ESP_LOGW(ES_TAG, "Codec mode not support, default is decode mode");
|
||||
break;
|
||||
}
|
||||
if (AUDIO_HAL_CTRL_STOP == ctrl_state) {
|
||||
res = es8388_stop(es_mode_t);
|
||||
} else {
|
||||
res = es8388_start(es_mode_t);
|
||||
ESP_LOGD(ES_TAG, "start default is decode mode:%d", es_mode_t);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t es8388_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface)
|
||||
{
|
||||
esp_err_t res = ESP_OK;
|
||||
int tmp = 0;
|
||||
res |= es8388_config_fmt(ES_MODULE_ADC_DAC, iface->fmt);
|
||||
if (iface->bits == AUDIO_HAL_BIT_LENGTH_16BITS) {
|
||||
tmp = BIT_LENGTH_16BITS;
|
||||
} else if (iface->bits == AUDIO_HAL_BIT_LENGTH_24BITS) {
|
||||
tmp = BIT_LENGTH_24BITS;
|
||||
} else {
|
||||
tmp = BIT_LENGTH_32BITS;
|
||||
}
|
||||
res |= es8388_set_bits_per_sample(ES_MODULE_ADC_DAC, tmp);
|
||||
return res;
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ES8388_H__
|
||||
#define __ES8388_H__
|
||||
|
||||
#include "esp_types.h"
|
||||
#include "audio_hal.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "esxxx_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ES8388 address */
|
||||
#define ES8388_ADDR 0x20 /*!< 0x22:CE=1;0x20:CE=0*/
|
||||
|
||||
/* ES8388 register */
|
||||
#define ES8388_CONTROL1 0x00
|
||||
#define ES8388_CONTROL2 0x01
|
||||
|
||||
#define ES8388_CHIPPOWER 0x02
|
||||
|
||||
#define ES8388_ADCPOWER 0x03
|
||||
#define ES8388_DACPOWER 0x04
|
||||
|
||||
#define ES8388_CHIPLOPOW1 0x05
|
||||
#define ES8388_CHIPLOPOW2 0x06
|
||||
|
||||
#define ES8388_ANAVOLMANAG 0x07
|
||||
|
||||
#define ES8388_MASTERMODE 0x08
|
||||
/* ADC */
|
||||
#define ES8388_ADCCONTROL1 0x09
|
||||
#define ES8388_ADCCONTROL2 0x0a
|
||||
#define ES8388_ADCCONTROL3 0x0b
|
||||
#define ES8388_ADCCONTROL4 0x0c
|
||||
#define ES8388_ADCCONTROL5 0x0d
|
||||
#define ES8388_ADCCONTROL6 0x0e
|
||||
#define ES8388_ADCCONTROL7 0x0f
|
||||
#define ES8388_ADCCONTROL8 0x10
|
||||
#define ES8388_ADCCONTROL9 0x11
|
||||
#define ES8388_ADCCONTROL10 0x12
|
||||
#define ES8388_ADCCONTROL11 0x13
|
||||
#define ES8388_ADCCONTROL12 0x14
|
||||
#define ES8388_ADCCONTROL13 0x15
|
||||
#define ES8388_ADCCONTROL14 0x16
|
||||
/* DAC */
|
||||
#define ES8388_DACCONTROL1 0x17
|
||||
#define ES8388_DACCONTROL2 0x18
|
||||
#define ES8388_DACCONTROL3 0x19
|
||||
#define ES8388_DACCONTROL4 0x1a
|
||||
#define ES8388_DACCONTROL5 0x1b
|
||||
#define ES8388_DACCONTROL6 0x1c
|
||||
#define ES8388_DACCONTROL7 0x1d
|
||||
#define ES8388_DACCONTROL8 0x1e
|
||||
#define ES8388_DACCONTROL9 0x1f
|
||||
#define ES8388_DACCONTROL10 0x20
|
||||
#define ES8388_DACCONTROL11 0x21
|
||||
#define ES8388_DACCONTROL12 0x22
|
||||
#define ES8388_DACCONTROL13 0x23
|
||||
#define ES8388_DACCONTROL14 0x24
|
||||
#define ES8388_DACCONTROL15 0x25
|
||||
#define ES8388_DACCONTROL16 0x26
|
||||
#define ES8388_DACCONTROL17 0x27
|
||||
#define ES8388_DACCONTROL18 0x28
|
||||
#define ES8388_DACCONTROL19 0x29
|
||||
#define ES8388_DACCONTROL20 0x2a
|
||||
#define ES8388_DACCONTROL21 0x2b
|
||||
#define ES8388_DACCONTROL22 0x2c
|
||||
#define ES8388_DACCONTROL23 0x2d
|
||||
#define ES8388_DACCONTROL24 0x2e
|
||||
#define ES8388_DACCONTROL25 0x2f
|
||||
#define ES8388_DACCONTROL26 0x30
|
||||
#define ES8388_DACCONTROL27 0x31
|
||||
#define ES8388_DACCONTROL28 0x32
|
||||
#define ES8388_DACCONTROL29 0x33
|
||||
#define ES8388_DACCONTROL30 0x34
|
||||
|
||||
/**
|
||||
* @brief Initialize ES8388 codec chip
|
||||
*
|
||||
* @param cfg configuration of ES8388
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_init(audio_hal_codec_config_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ES8388 codec chip
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 I2S format
|
||||
*
|
||||
* @param mod: set ADC or DAC or both
|
||||
* @param cfg: ES8388 I2S format
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_config_fmt(es_module_t mod, es_i2s_fmt_t cfg);
|
||||
|
||||
/**
|
||||
* @brief Configure I2s clock in MSATER mode
|
||||
*
|
||||
* @param cfg: set bits clock and WS clock
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_i2s_config_clock(es_i2s_clock_t cfg);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 data sample bits
|
||||
*
|
||||
* @param mode: set ADC or DAC or both
|
||||
* @param bit_per_sample: bit number of per sample
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_set_bits_per_sample(es_module_t mode, es_bits_length_t bit_per_sample);
|
||||
|
||||
/**
|
||||
* @brief Start ES8388 codec chip
|
||||
*
|
||||
* @param mode: set ADC or DAC or both
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_start(es_module_t mode);
|
||||
|
||||
/**
|
||||
* @brief Stop ES8388 codec chip
|
||||
*
|
||||
* @param mode: set ADC or DAC or both
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_stop(es_module_t mode);
|
||||
|
||||
/**
|
||||
* @brief Set voice volume
|
||||
*
|
||||
* @param volume: voice volume (0~100)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_set_voice_volume(int volume);
|
||||
|
||||
/**
|
||||
* @brief Get voice volume
|
||||
*
|
||||
* @param[out] *volume: voice volume (0~100)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8388_get_voice_volume(int *volume);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 DAC mute or not. Basically you can use this function to mute the output or unmute
|
||||
*
|
||||
* @param enable enable(1) or disable(0)
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_set_voice_mute(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Get ES8388 DAC mute status
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_get_voice_mute(void);
|
||||
|
||||
/**
|
||||
* @brief Set ES8388 mic gain
|
||||
*
|
||||
* @param gain db of mic gain
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_set_mic_gain(es_mic_gain_t gain);
|
||||
|
||||
/**
|
||||
* @brief Set ES8388 adc input mode
|
||||
*
|
||||
* @param input adc input mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_config_adc_input(es_adc_input_t input);
|
||||
|
||||
/**
|
||||
* @brief Set ES8388 dac output mode
|
||||
*
|
||||
* @param output dac output mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_config_dac_output(es_dac_output_t output);
|
||||
|
||||
/**
|
||||
* @brief Write ES8388 register
|
||||
*
|
||||
* @param reg_add address of register
|
||||
* @param data data of register
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_write_reg(uint8_t reg_add, uint8_t data);
|
||||
|
||||
/**
|
||||
* @brief Print all ES8388 registers
|
||||
*
|
||||
* @return
|
||||
* - void
|
||||
*/
|
||||
void es8388_read_all();
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 codec mode and I2S interface
|
||||
*
|
||||
* @param mode codec mode
|
||||
* @param iface I2S config
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);
|
||||
|
||||
/**
|
||||
* @brief Control ES8388 codec chip
|
||||
*
|
||||
* @param mode codec mode
|
||||
* @param ctrl_state start or stop decode or encode progress
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t es8388_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //__ES8388_H__
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _AUDIO_HAL_H_
|
||||
#define _AUDIO_HAL_H_
|
||||
|
||||
#define AUDIO_HAL_VOL_DEFAULT 60
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Select media hal codec mode
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_CODEC_MODE_ENCODE = 1, /*!< select adc */
|
||||
AUDIO_HAL_CODEC_MODE_DECODE, /*!< select dac */
|
||||
AUDIO_HAL_CODEC_MODE_BOTH, /*!< select both adc and dac */
|
||||
AUDIO_HAL_CODEC_MODE_LINE_IN, /*!< set adc channel */
|
||||
} audio_hal_codec_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Select adc channel for input mic signal
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_ADC_INPUT_LINE1 = 0x00, /*!< mic input to adc channel 1 */
|
||||
AUDIO_HAL_ADC_INPUT_LINE2, /*!< mic input to adc channel 2 */
|
||||
AUDIO_HAL_ADC_INPUT_ALL, /*!< mic input to both channels of adc */
|
||||
AUDIO_HAL_ADC_INPUT_DIFFERENCE, /*!< mic input to adc difference channel */
|
||||
} audio_hal_adc_input_t;
|
||||
|
||||
/**
|
||||
* @brief Select channel for dac output
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_DAC_OUTPUT_LINE1 = 0x00, /*!< dac output signal to channel 1 */
|
||||
AUDIO_HAL_DAC_OUTPUT_LINE2, /*!< dac output signal to channel 2 */
|
||||
AUDIO_HAL_DAC_OUTPUT_ALL, /*!< dac output signal to both channels */
|
||||
} audio_hal_dac_output_t;
|
||||
|
||||
/**
|
||||
* @brief Select operating mode i.e. start or stop for audio codec chip
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_CTRL_STOP = 0x00, /*!< set stop mode */
|
||||
AUDIO_HAL_CTRL_START = 0x01, /*!< set start mode */
|
||||
} audio_hal_ctrl_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface operating mode i.e. master or slave for audio codec chip
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_MODE_SLAVE = 0x00, /*!< set slave mode */
|
||||
AUDIO_HAL_MODE_MASTER = 0x01, /*!< set master mode */
|
||||
} audio_hal_iface_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface samples per second
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_08K_SAMPLES, /*!< set to 8k samples per second */
|
||||
AUDIO_HAL_11K_SAMPLES, /*!< set to 11.025k samples per second */
|
||||
AUDIO_HAL_16K_SAMPLES, /*!< set to 16k samples in per second */
|
||||
AUDIO_HAL_22K_SAMPLES, /*!< set to 22.050k samples per second */
|
||||
AUDIO_HAL_24K_SAMPLES, /*!< set to 24k samples in per second */
|
||||
AUDIO_HAL_32K_SAMPLES, /*!< set to 32k samples in per second */
|
||||
AUDIO_HAL_44K_SAMPLES, /*!< set to 44.1k samples per second */
|
||||
AUDIO_HAL_48K_SAMPLES, /*!< set to 48k samples per second */
|
||||
} audio_hal_iface_samples_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface number of bits per sample
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_BIT_LENGTH_16BITS = 1, /*!< set 16 bits per sample */
|
||||
AUDIO_HAL_BIT_LENGTH_24BITS, /*!< set 24 bits per sample */
|
||||
AUDIO_HAL_BIT_LENGTH_32BITS, /*!< set 32 bits per sample */
|
||||
} audio_hal_iface_bits_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface format for audio codec chip
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_I2S_NORMAL = 0, /*!< set normal I2S format */
|
||||
AUDIO_HAL_I2S_LEFT, /*!< set all left format */
|
||||
AUDIO_HAL_I2S_RIGHT, /*!< set all right format */
|
||||
AUDIO_HAL_I2S_DSP, /*!< set dsp/pcm format */
|
||||
} audio_hal_iface_format_t;
|
||||
|
||||
/**
|
||||
* @brief I2s interface configuration for audio codec chip
|
||||
*/
|
||||
typedef struct {
|
||||
audio_hal_iface_mode_t mode; /*!< audio codec chip mode */
|
||||
audio_hal_iface_format_t fmt; /*!< I2S interface format */
|
||||
audio_hal_iface_samples_t samples; /*!< I2S interface samples per second */
|
||||
audio_hal_iface_bits_t bits; /*!< i2s interface number of bits per sample */
|
||||
} audio_hal_codec_i2s_iface_t;
|
||||
|
||||
/**
|
||||
* @brief Configure media hal for initialization of audio codec chip
|
||||
*/
|
||||
typedef struct {
|
||||
audio_hal_adc_input_t adc_input; /*!< set adc channel */
|
||||
audio_hal_dac_output_t dac_output; /*!< set dac channel */
|
||||
audio_hal_codec_mode_t codec_mode; /*!< select codec mode: adc, dac or both */
|
||||
audio_hal_codec_i2s_iface_t i2s_iface; /*!< set I2S interface configuration */
|
||||
} audio_hal_codec_config_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //__AUDIO_HAL_H__
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ESXXX_COMMON_H_
|
||||
#define _ESXXX_COMMON_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BIT_LENGTH_MIN = -1,
|
||||
BIT_LENGTH_16BITS = 0x03,
|
||||
BIT_LENGTH_18BITS = 0x02,
|
||||
BIT_LENGTH_20BITS = 0x01,
|
||||
BIT_LENGTH_24BITS = 0x00,
|
||||
BIT_LENGTH_32BITS = 0x04,
|
||||
BIT_LENGTH_MAX,
|
||||
} es_bits_length_t;
|
||||
|
||||
typedef enum {
|
||||
MCLK_DIV_MIN = -1,
|
||||
MCLK_DIV_1 = 1,
|
||||
MCLK_DIV_2 = 2,
|
||||
MCLK_DIV_3 = 3,
|
||||
MCLK_DIV_4 = 4,
|
||||
MCLK_DIV_6 = 5,
|
||||
MCLK_DIV_8 = 6,
|
||||
MCLK_DIV_9 = 7,
|
||||
MCLK_DIV_11 = 8,
|
||||
MCLK_DIV_12 = 9,
|
||||
MCLK_DIV_16 = 10,
|
||||
MCLK_DIV_18 = 11,
|
||||
MCLK_DIV_22 = 12,
|
||||
MCLK_DIV_24 = 13,
|
||||
MCLK_DIV_33 = 14,
|
||||
MCLK_DIV_36 = 15,
|
||||
MCLK_DIV_44 = 16,
|
||||
MCLK_DIV_48 = 17,
|
||||
MCLK_DIV_66 = 18,
|
||||
MCLK_DIV_72 = 19,
|
||||
MCLK_DIV_5 = 20,
|
||||
MCLK_DIV_10 = 21,
|
||||
MCLK_DIV_15 = 22,
|
||||
MCLK_DIV_17 = 23,
|
||||
MCLK_DIV_20 = 24,
|
||||
MCLK_DIV_25 = 25,
|
||||
MCLK_DIV_30 = 26,
|
||||
MCLK_DIV_32 = 27,
|
||||
MCLK_DIV_34 = 28,
|
||||
MCLK_DIV_7 = 29,
|
||||
MCLK_DIV_13 = 30,
|
||||
MCLK_DIV_14 = 31,
|
||||
MCLK_DIV_MAX,
|
||||
} es_sclk_div_t;
|
||||
|
||||
typedef enum {
|
||||
LCLK_DIV_MIN = -1,
|
||||
LCLK_DIV_128 = 0,
|
||||
LCLK_DIV_192 = 1,
|
||||
LCLK_DIV_256 = 2,
|
||||
LCLK_DIV_384 = 3,
|
||||
LCLK_DIV_512 = 4,
|
||||
LCLK_DIV_576 = 5,
|
||||
LCLK_DIV_768 = 6,
|
||||
LCLK_DIV_1024 = 7,
|
||||
LCLK_DIV_1152 = 8,
|
||||
LCLK_DIV_1408 = 9,
|
||||
LCLK_DIV_1536 = 10,
|
||||
LCLK_DIV_2112 = 11,
|
||||
LCLK_DIV_2304 = 12,
|
||||
|
||||
LCLK_DIV_125 = 16,
|
||||
LCLK_DIV_136 = 17,
|
||||
LCLK_DIV_250 = 18,
|
||||
LCLK_DIV_272 = 19,
|
||||
LCLK_DIV_375 = 20,
|
||||
LCLK_DIV_500 = 21,
|
||||
LCLK_DIV_544 = 22,
|
||||
LCLK_DIV_750 = 23,
|
||||
LCLK_DIV_1000 = 24,
|
||||
LCLK_DIV_1088 = 25,
|
||||
LCLK_DIV_1496 = 26,
|
||||
LCLK_DIV_1500 = 27,
|
||||
LCLK_DIV_MAX,
|
||||
} es_lclk_div_t;
|
||||
|
||||
typedef enum {
|
||||
D2SE_PGA_GAIN_MIN = -1,
|
||||
D2SE_PGA_GAIN_DIS = 0,
|
||||
D2SE_PGA_GAIN_EN = 1,
|
||||
D2SE_PGA_GAIN_MAX = 2,
|
||||
} es_d2se_pga_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_INPUT_MIN = -1,
|
||||
ADC_INPUT_LINPUT1_RINPUT1 = 0x00,
|
||||
ADC_INPUT_MIC1 = 0x05,
|
||||
ADC_INPUT_MIC2 = 0x06,
|
||||
ADC_INPUT_LINPUT2_RINPUT2 = 0x50,
|
||||
ADC_INPUT_DIFFERENCE = 0xf0,
|
||||
ADC_INPUT_MAX,
|
||||
} es_adc_input_t;
|
||||
|
||||
typedef enum {
|
||||
DAC_OUTPUT_MIN = -1,
|
||||
DAC_OUTPUT_LOUT1 = 0x04,
|
||||
DAC_OUTPUT_LOUT2 = 0x08,
|
||||
DAC_OUTPUT_SPK = 0x09,
|
||||
DAC_OUTPUT_ROUT1 = 0x10,
|
||||
DAC_OUTPUT_ROUT2 = 0x20,
|
||||
DAC_OUTPUT_ALL = 0x3c,
|
||||
DAC_OUTPUT_MAX,
|
||||
} es_dac_output_t;
|
||||
|
||||
typedef enum {
|
||||
MIC_GAIN_MIN = -1,
|
||||
MIC_GAIN_0DB = 0,
|
||||
MIC_GAIN_3DB = 3,
|
||||
MIC_GAIN_6DB = 6,
|
||||
MIC_GAIN_9DB = 9,
|
||||
MIC_GAIN_12DB = 12,
|
||||
MIC_GAIN_15DB = 15,
|
||||
MIC_GAIN_18DB = 18,
|
||||
MIC_GAIN_21DB = 21,
|
||||
MIC_GAIN_24DB = 24,
|
||||
MIC_GAIN_MAX,
|
||||
} es_mic_gain_t;
|
||||
|
||||
typedef enum {
|
||||
ES_MODULE_MIN = -1,
|
||||
ES_MODULE_ADC = 0x01,
|
||||
ES_MODULE_DAC = 0x02,
|
||||
ES_MODULE_ADC_DAC = 0x03,
|
||||
ES_MODULE_LINE = 0x04,
|
||||
ES_MODULE_MAX
|
||||
} es_module_t;
|
||||
|
||||
typedef enum {
|
||||
ES_MODE_MIN = -1,
|
||||
ES_MODE_SLAVE = 0x00,
|
||||
ES_MODE_MASTER = 0x01,
|
||||
ES_MODE_MAX,
|
||||
} es_mode_t;
|
||||
|
||||
typedef enum {
|
||||
ES_I2S_MIN = -1,
|
||||
ES_I2S_NORMAL = 0,
|
||||
ES_I2S_LEFT = 1,
|
||||
ES_I2S_RIGHT = 2,
|
||||
ES_I2S_DSP = 3,
|
||||
ES_I2S_MAX
|
||||
} es_i2s_fmt_t;
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 clock
|
||||
*/
|
||||
typedef struct {
|
||||
es_sclk_div_t sclk_div; /*!< bits clock divide */
|
||||
es_lclk_div_t lclk_div; /*!< WS clock divide */
|
||||
} es_i2s_clock_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_check.h"
|
||||
#include "bsp_board.h"
|
||||
#include "driver/adc.h"
|
||||
#include "esp_err.h"
|
||||
#include "button.h"
|
||||
|
||||
static const char *TAG = "bsp btn";
|
||||
|
||||
static button_handle_t *g_btn_handle = NULL;
|
||||
|
||||
static esp_err_t adc_button_init(button_handle_t *handle, size_t btn_id, adc1_channel_t adc_chanel, uint32_t voltage_err, const uint32_t voltage)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
button_config_t btn_cfg = {
|
||||
.type = BUTTON_TYPE_ADC,
|
||||
.adc_button_config = {
|
||||
.adc_channel = adc_chanel,
|
||||
},
|
||||
};
|
||||
|
||||
btn_cfg.adc_button_config.button_index = btn_id;
|
||||
btn_cfg.adc_button_config.min = voltage - voltage_err;
|
||||
btn_cfg.adc_button_config.max = voltage + voltage_err;
|
||||
*handle = button_create(&btn_cfg);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
static esp_err_t gpio_btn_init(button_handle_t *handle, const gpio_num_t gpio, const bool active_level)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
button_config_t btn_cfg = {
|
||||
.type = BUTTON_TYPE_GPIO,
|
||||
.gpio_button_config = {
|
||||
.active_level = 0,
|
||||
.gpio_num = 0,
|
||||
},
|
||||
};
|
||||
|
||||
btn_cfg.gpio_button_config.gpio_num = gpio;
|
||||
btn_cfg.gpio_button_config.active_level = active_level;
|
||||
*handle = button_create(&btn_cfg);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t bsp_btn_init_default(void)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(NULL == g_btn_handle, ESP_ERR_INVALID_STATE, TAG, "button already initialized ");
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
g_btn_handle = calloc(sizeof(button_handle_t), brd->BUTTON_TAB_LEN);
|
||||
ESP_RETURN_ON_FALSE(NULL != g_btn_handle, ESP_ERR_NO_MEM, TAG, "memory is insufficient for button");
|
||||
for (size_t i = 0; i < brd->BUTTON_TAB_LEN; i++) {
|
||||
const board_button_t *btn = &brd->BUTTON_TAB[i];
|
||||
if (GPIO_NUM_NC != btn->io_num) {
|
||||
ret = gpio_btn_init(&g_btn_handle[btn->id], btn->io_num, btn->active_level);
|
||||
} else {
|
||||
ret = adc_button_init(&g_btn_handle[btn->id], btn->id, brd->BUTTON_ADC_CHAN, 150, btn->vol);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_btn_register_callback(board_btn_id_t btn_id, button_event_t event, button_cb_t callback, void *user_data)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(NULL != g_btn_handle, ESP_ERR_INVALID_STATE, TAG, "button not initialized");
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
ESP_RETURN_ON_FALSE(btn_id < brd->BUTTON_TAB_LEN, ESP_ERR_INVALID_ARG, TAG, "button id incorrect");
|
||||
|
||||
if (NULL == callback) {
|
||||
return button_unregister_cb(g_btn_handle[btn_id], event);
|
||||
}
|
||||
|
||||
button_dev_t *btn = (button_dev_t *) g_btn_handle[btn_id];
|
||||
btn->cb_user_data = user_data;
|
||||
return button_register_cb(g_btn_handle[btn_id], event, callback);
|
||||
}
|
||||
|
||||
esp_err_t bsp_btn_rm_all_callback(board_btn_id_t btn_id)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(NULL != g_btn_handle, ESP_ERR_INVALID_STATE, TAG, "button not initialized");
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
ESP_RETURN_ON_FALSE(btn_id < brd->BUTTON_TAB_LEN, ESP_ERR_INVALID_ARG, TAG, "button id incorrect");
|
||||
|
||||
for (size_t event = 0; event < BUTTON_EVENT_MAX; event++) {
|
||||
button_unregister_cb(g_btn_handle[btn_id], event);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool bsp_btn_get_state(board_btn_id_t btn_id)
|
||||
{
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
ESP_RETURN_ON_FALSE(btn_id < brd->BUTTON_TAB_LEN, 0, TAG, "button id incorrect");
|
||||
|
||||
button_dev_t *btn = (button_dev_t *) g_btn_handle[btn_id];
|
||||
return btn->event == BUTTON_PRESS_DOWN ? 1 : 0;
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "bsp_codec.h"
|
||||
#include "bsp_i2c.h"
|
||||
#include "esp_err.h"
|
||||
#include "es8156.h"
|
||||
#include "es7210.h"
|
||||
#include "es7243e.h"
|
||||
#include "es8311.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "codec";
|
||||
|
||||
typedef struct {
|
||||
codec_dev_t dev;
|
||||
uint8_t dev_addr;
|
||||
char *dev_name;
|
||||
esp_err_t (*init)(void);
|
||||
} codec_desc_t;
|
||||
|
||||
static uint32_t s_codec_detect_flag = 0;
|
||||
|
||||
/**
|
||||
* @brief Default init function declaration for aduio CODEC
|
||||
*/
|
||||
static esp_err_t es7210_init_default(void);
|
||||
static esp_err_t es7243_init_default(void);
|
||||
static esp_err_t es8156_init_default(void);
|
||||
static esp_err_t es8311_init_default(void);
|
||||
|
||||
static codec_desc_t codec_dev_list[] = {
|
||||
{CODEC_DEV_ES7210, 0x40, "ES7210", es7210_init_default },
|
||||
{CODEC_DEV_ES7243, 0x08, "ES7243", es7243_init_default },
|
||||
{CODEC_DEV_ES8156, 0x10, "ES8156", es8156_init_default },
|
||||
{CODEC_DEV_ES8311, 0x18, "ES8311", es8311_init_default },
|
||||
// { 0x20, "ES8388", es8388_init_default }, /* Currently not supported */
|
||||
};
|
||||
|
||||
static esp_err_t es7210_init_default(void)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
audio_hal_codec_config_t cfg = {
|
||||
.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE,
|
||||
.adc_input = AUDIO_HAL_ADC_INPUT_ALL,
|
||||
.i2s_iface = {
|
||||
.bits = AUDIO_HAL_BIT_LENGTH_16BITS,
|
||||
.fmt = AUDIO_HAL_I2S_NORMAL,
|
||||
.mode = AUDIO_HAL_MODE_SLAVE,
|
||||
.samples = AUDIO_HAL_16K_SAMPLES,
|
||||
},
|
||||
};
|
||||
|
||||
ret_val |= es7210_adc_init(&cfg);
|
||||
ret_val |= es7210_adc_config_i2s(cfg.codec_mode, &cfg.i2s_iface);
|
||||
ret_val |= es7210_adc_set_gain(ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2, GAIN_37_5DB);
|
||||
ret_val |= es7210_adc_set_gain(ES7210_INPUT_MIC3 | ES7210_INPUT_MIC4, GAIN_0DB);
|
||||
ret_val |= es7210_adc_ctrl_state(cfg.codec_mode, AUDIO_HAL_CTRL_START);
|
||||
|
||||
if (ESP_OK != ret_val) {
|
||||
ESP_LOGE(TAG, "Failed initialize codec");
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
static esp_err_t es7243_init_default(void)
|
||||
{
|
||||
audio_hal_codec_config_t cfg = {
|
||||
.i2s_iface = {
|
||||
.bits = AUDIO_HAL_BIT_LENGTH_16BITS,
|
||||
.mode = AUDIO_HAL_MODE_SLAVE,
|
||||
}
|
||||
};
|
||||
|
||||
return es7243e_adc_init(&cfg);
|
||||
}
|
||||
|
||||
static esp_err_t es8156_init_default(void)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
audio_hal_codec_config_t cfg = {
|
||||
.i2s_iface = {
|
||||
.bits = AUDIO_HAL_BIT_LENGTH_16BITS,
|
||||
.mode = AUDIO_HAL_MODE_SLAVE,
|
||||
}
|
||||
};
|
||||
ret_val |= es8156_codec_init(&cfg);
|
||||
ret_val |= es8156_codec_set_voice_volume(75);
|
||||
if (ESP_OK != ret_val) {
|
||||
ESP_LOGE(TAG, "Failed initialize codec");
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
static esp_err_t es8311_init_default(void)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
audio_hal_codec_config_t cfg = {
|
||||
.codec_mode = AUDIO_HAL_CODEC_MODE_DECODE,
|
||||
.dac_output = AUDIO_HAL_DAC_OUTPUT_LINE1,
|
||||
.i2s_iface = {
|
||||
.bits = AUDIO_HAL_BIT_LENGTH_16BITS,
|
||||
.fmt = AUDIO_HAL_I2S_NORMAL,
|
||||
.mode = AUDIO_HAL_MODE_SLAVE,
|
||||
.samples = AUDIO_HAL_16K_SAMPLES,
|
||||
},
|
||||
};
|
||||
|
||||
ret_val |= es8311_codec_init(&cfg);
|
||||
ret_val |= es8311_set_bits_per_sample(cfg.i2s_iface.bits);
|
||||
ret_val |= es8311_config_fmt(cfg.i2s_iface.fmt);
|
||||
ret_val |= es8311_codec_set_voice_volume(75);
|
||||
ret_val |= es8311_codec_ctrl_state(cfg.codec_mode, AUDIO_HAL_CTRL_START);
|
||||
|
||||
if (ESP_OK != ret_val) {
|
||||
ESP_LOGE(TAG, "Failed initialize codec");
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
bool bsp_codec_has_dev(codec_dev_t dev)
|
||||
{
|
||||
if (s_codec_detect_flag & dev) {
|
||||
return true;
|
||||
} return false;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_detect(uint32_t *devices)
|
||||
{
|
||||
for (size_t i = 0 ; i < sizeof(codec_dev_list) / sizeof(codec_dev_list[0]); i++) {
|
||||
if (ESP_OK == bsp_i2c_probe_addr(codec_dev_list[i].dev_addr)) {
|
||||
*devices |= codec_dev_list[i].dev;
|
||||
ESP_LOGI(TAG, "Detected codec at 0x%02X. Name : %s",
|
||||
codec_dev_list[i].dev_addr, codec_dev_list[i].dev_name);
|
||||
}
|
||||
}
|
||||
return 0 == *devices ? ESP_ERR_NOT_FOUND : ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_init(audio_hal_iface_samples_t sample_rate)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
ret_val = bsp_codec_detect(&s_codec_detect_flag);
|
||||
if (ESP_OK == ret_val) {
|
||||
for (size_t i = 0; i < sizeof(codec_dev_list) / sizeof(codec_dev_list[0]); i++) {
|
||||
if (codec_dev_list[i].dev & s_codec_detect_flag) {
|
||||
ret_val |= codec_dev_list[i].init();
|
||||
ESP_LOGI(TAG, "init %s", codec_dev_list[i].dev_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_set_voice_volume(uint8_t volume)
|
||||
{
|
||||
if (bsp_codec_has_dev(CODEC_DEV_ES8311)) {
|
||||
// reduce volume for S3-BOX board
|
||||
float v = volume;
|
||||
v *= 0.6f;
|
||||
v = -0.01f * (v * v) + 2.0f * v;
|
||||
return es8311_codec_set_voice_volume((int)v);
|
||||
} else if (bsp_codec_has_dev(CODEC_DEV_ES8156)) {
|
||||
return es8156_codec_set_voice_volume(volume);
|
||||
}
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_set_fmt(audio_hal_iface_format_t fmt)
|
||||
{
|
||||
if (bsp_codec_has_dev(CODEC_DEV_ES8311)) {
|
||||
return es8311_config_fmt(fmt);
|
||||
} else if (bsp_codec_has_dev(CODEC_DEV_ES8156)) {
|
||||
return es8156_config_fmt(fmt);
|
||||
}
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
esp_err_t bsp_codec_set_voice_gain(uint8_t channel_mask, uint8_t volume)
|
||||
{
|
||||
if (bsp_codec_has_dev(CODEC_DEV_ES7210)) {
|
||||
return es7210_adc_set_gain(channel_mask, volume);
|
||||
}
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "bsp_i2c.h"
|
||||
#include "bsp_board.h"
|
||||
#include "driver/i2c.h"
|
||||
|
||||
static const char *TAG = "bsp_i2c";
|
||||
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
|
||||
static i2c_bus_handle_t i2c_bus_handle = NULL;
|
||||
|
||||
esp_err_t bsp_i2c_init(i2c_port_t i2c_num, uint32_t clk_speed, gpio_num_t scl_io, gpio_num_t sda_io)
|
||||
{
|
||||
/* Check if bus is already created */
|
||||
if (NULL != i2c_bus_handle) {
|
||||
ESP_LOGE(TAG, "I2C bus already initialized.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.scl_io_num = scl_io,
|
||||
.sda_io_num = sda_io,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = clk_speed,
|
||||
};
|
||||
|
||||
i2c_bus_handle = i2c_bus_create(i2c_num, &conf);
|
||||
|
||||
if (NULL == i2c_bus_handle) {
|
||||
ESP_LOGE(TAG, "Failed create I2C bus");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2c_deinit(void)
|
||||
{
|
||||
/* Check if bus is already created */
|
||||
if (NULL == i2c_bus_handle) {
|
||||
ESP_LOGE(TAG, "I2C bus already deinitialized.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
i2c_bus_delete(&i2c_bus_handle);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2c_add_device(i2c_bus_device_handle_t *i2c_device_handle, uint8_t dev_addr)
|
||||
{
|
||||
if (NULL == i2c_bus_handle) {
|
||||
ESP_LOGE(TAG, "Failed create I2C device");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
*i2c_device_handle = i2c_bus_device_create(i2c_bus_handle, dev_addr, 400000);
|
||||
|
||||
if (NULL == i2c_device_handle) {
|
||||
ESP_LOGE(TAG, "Failed create I2C device");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2c_probe(void)
|
||||
{
|
||||
if (NULL == bsp_i2c_bus_get_handle()) {
|
||||
ESP_LOGE(TAG, "I2C bus not initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *) bsp_i2c_bus_get_handle();
|
||||
|
||||
for (size_t i = 1; i < 0x80; i++) {
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, ( i << 1 ), ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret_val = i2c_master_cmd_begin(i2c_bus->i2c_port, cmd, pdMS_TO_TICKS(500));
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if(ESP_OK == ret_val) {
|
||||
ESP_LOGW(TAG, "Found I2C Device at 0x%02X", i);
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2c_probe_addr(uint8_t addr)
|
||||
{
|
||||
/* Use 7 bit address here */
|
||||
if (addr >= 0x80) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* Check if I2C bus initialized */
|
||||
if (NULL == bsp_i2c_bus_get_handle()) {
|
||||
ESP_LOGE(TAG, "I2C bus not initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
/* Get I2C bus object from i2c_bus_handle */
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *) bsp_i2c_bus_get_handle();
|
||||
|
||||
/* Create probe cmd link */
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, ( addr << 1 ), ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
|
||||
/* Start probe cmd link */
|
||||
esp_err_t ret_val = i2c_master_cmd_begin(i2c_bus->i2c_port, cmd, pdMS_TO_TICKS(500));
|
||||
|
||||
/* Delete cmd link after probe ends */
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
/* Get probe result if ESP_OK equals to ret_val */
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
i2c_bus_handle_t bsp_i2c_bus_get_handle(void)
|
||||
{
|
||||
return i2c_bus_handle;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "bsp_board.h"
|
||||
#include "bsp_i2s.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2s.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
/* Required for I2S driver workaround */
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "hal/gpio_hal.h"
|
||||
#include "hal/i2s_ll.h"
|
||||
|
||||
#define I2S_CONFIG_DEFAULT() { \
|
||||
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX, \
|
||||
.sample_rate = sample_rate, \
|
||||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, \
|
||||
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
|
||||
.communication_format = I2S_COMM_FORMAT_STAND_I2S, \
|
||||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, \
|
||||
.dma_buf_count = 6, \
|
||||
.dma_buf_len = 160, \
|
||||
.use_apll = false, \
|
||||
.tx_desc_auto_clear = true, \
|
||||
.fixed_mclk = 0, \
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, \
|
||||
.bits_per_chan = I2S_BITS_PER_CHAN_16BIT, \
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2s_init(i2s_port_t i2s_num, uint32_t sample_rate)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
|
||||
i2s_config_t i2s_config = I2S_CONFIG_DEFAULT();
|
||||
|
||||
i2s_pin_config_t pin_config = {
|
||||
.bck_io_num = brd->GPIO_I2S_SCLK,
|
||||
.ws_io_num = brd->GPIO_I2S_LRCK,
|
||||
.data_out_num = brd->GPIO_I2S_DOUT,
|
||||
.data_in_num = brd->GPIO_I2S_SDIN,
|
||||
.mck_io_num = brd->GPIO_I2S_MCLK,
|
||||
};
|
||||
|
||||
ret_val |= i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
|
||||
ret_val |= i2s_set_pin(i2s_num, &pin_config);
|
||||
ret_val |= i2s_zero_dma_buffer(i2s_num);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t bsp_i2s_deinit(i2s_port_t i2s_num)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
ret_val |= i2s_stop(I2S_NUM_0);
|
||||
ret_val |= i2s_driver_uninstall(i2s_num);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "bsp_lcd.h"
|
||||
#include "bsp_board.h"
|
||||
#include "esp_compiler.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
|
||||
static const char *TAG = "bsp_lcd";
|
||||
|
||||
static esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
static esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
|
||||
static void *p_user_data = NULL;
|
||||
static bool (*p_on_trans_done_cb)(void *) = NULL;
|
||||
static SemaphoreHandle_t bsp_lcd_flush_done_sem = NULL;
|
||||
|
||||
|
||||
static esp_err_t bsp_spi_lcd_init(esp_lcd_panel_io_handle_t *p_io_handle, bsp_lcd_trans_cb_t trans_done_cb)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
|
||||
if (NULL == p_io_handle) {
|
||||
ESP_LOGE(TAG, "Invalid LCD IO handle");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (brd->LCD_BUS_WIDTH == 8) {
|
||||
spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = brd->GPIO_LCD_CLK,
|
||||
.data0_io_num = brd->GPIO_LCD_D00,
|
||||
.data1_io_num = brd->GPIO_LCD_D01,
|
||||
.data2_io_num = brd->GPIO_LCD_D02,
|
||||
.data3_io_num = brd->GPIO_LCD_D03,
|
||||
.data4_io_num = brd->GPIO_LCD_D04,
|
||||
.data5_io_num = brd->GPIO_LCD_D05,
|
||||
.data6_io_num = brd->GPIO_LCD_D06,
|
||||
.data7_io_num = brd->GPIO_LCD_D07,
|
||||
.flags = SPICOMMON_BUSFLAG_OCTAL,
|
||||
.max_transfer_sz = brd->LCD_WIDTH * brd->LCD_HEIGHT * sizeof(uint16_t)
|
||||
};
|
||||
ret_val |= spi_bus_initialize(brd->LCD_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||
} else if (brd->LCD_BUS_WIDTH == 1) {
|
||||
spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = brd->GPIO_LCD_CLK,
|
||||
.mosi_io_num = brd->GPIO_LCD_DIN,
|
||||
.miso_io_num = GPIO_NUM_NC,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = brd->LCD_WIDTH * brd->LCD_HEIGHT * sizeof(uint16_t)
|
||||
};
|
||||
ret_val |= spi_bus_initialize(brd->LCD_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||
}
|
||||
esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.dc_gpio_num = brd->GPIO_LCD_DC,
|
||||
.cs_gpio_num = brd->GPIO_LCD_CS,
|
||||
.pclk_hz = brd->LCD_FREQ,
|
||||
.spi_mode = 0,
|
||||
.trans_queue_depth = 10,
|
||||
.lcd_cmd_bits = brd->LCD_CMD_BITS,
|
||||
.lcd_param_bits = brd->LCD_PARAM_BITS,
|
||||
.on_color_trans_done = trans_done_cb,
|
||||
.user_ctx = NULL,
|
||||
};
|
||||
|
||||
if (brd->LCD_BUS_WIDTH == 8) {
|
||||
io_config.flags.octal_mode = 1;
|
||||
io_config.spi_mode = 3;
|
||||
}
|
||||
ret_val |= esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t) brd->LCD_HOST, &io_config, p_io_handle);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_spi_lcd_deinit(void)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
|
||||
ret_val |= spi_bus_free(brd->LCD_HOST);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
static bool lcd_trans_done_cb(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *user_data, void *event_data)
|
||||
{
|
||||
(void) panel_io;
|
||||
(void) user_data;
|
||||
(void) event_data;
|
||||
|
||||
/* Used for `bsp_lcd_flush_wait` */
|
||||
if (likely(NULL != bsp_lcd_flush_done_sem)) {
|
||||
xSemaphoreGive(bsp_lcd_flush_done_sem);
|
||||
}
|
||||
|
||||
/* Call user registered function */
|
||||
if (NULL != p_on_trans_done_cb) {
|
||||
return p_on_trans_done_cb(p_user_data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t bsp_lcd_init(void)
|
||||
{
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
bsp_spi_lcd_init(&io_handle, lcd_trans_done_cb);
|
||||
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = brd->GPIO_LCD_RST,
|
||||
.color_space = brd->LCD_COLOR_SPACE,
|
||||
.bits_per_pixel = 16,
|
||||
};
|
||||
|
||||
if (!brd->LCD_DISP_IC_ST) {
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_nt35510(io_handle, &panel_config, &panel_handle));
|
||||
} else {
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure LCD rotation and mirror
|
||||
*
|
||||
*/
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
ret_val |= esp_lcd_panel_reset(panel_handle);
|
||||
ret_val |= esp_lcd_panel_init(panel_handle);
|
||||
ret_val |= esp_lcd_panel_invert_color(panel_handle, brd->LCD_COLOR_INV);
|
||||
ret_val |= esp_lcd_panel_set_gap(panel_handle, 0, 0);
|
||||
ret_val |= esp_lcd_panel_swap_xy(panel_handle, brd->LCD_SWAP_XY);
|
||||
ret_val |= esp_lcd_panel_mirror(panel_handle, brd->LCD_MIRROR_X, brd->LCD_MIRROR_Y);
|
||||
|
||||
/**
|
||||
* @brief Configure LCD backlight IO.
|
||||
*
|
||||
*/
|
||||
if (GPIO_NUM_NC != brd->GPIO_LCD_BL) {
|
||||
gpio_config_t bk_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
/*!< Prevent left shift negtive value warning */
|
||||
.pin_bit_mask = brd->GPIO_LCD_BL > 0 ? 1ULL << brd->GPIO_LCD_BL : 0ULL,
|
||||
};
|
||||
gpio_config(&bk_gpio_config);
|
||||
gpio_set_level(brd->GPIO_LCD_BL, !brd->GPIO_LCD_BL_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create mutex to receive LCD flush event.
|
||||
*
|
||||
*/
|
||||
if (NULL != bsp_lcd_flush_done_sem) {
|
||||
ESP_LOGE(TAG, "LCD already initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
bsp_lcd_flush_done_sem = xSemaphoreCreateBinary();
|
||||
|
||||
if (NULL == bsp_lcd_flush_done_sem) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
/* If any function is checking LCD trans status before transmition */
|
||||
xSemaphoreGive(bsp_lcd_flush_done_sem);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_lcd_deinit(void)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
ret_val |= esp_lcd_panel_del(panel_handle);
|
||||
ret_val |= esp_lcd_panel_io_del(io_handle);
|
||||
ret_val |= bsp_spi_lcd_deinit();
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t bsp_lcd_flush(int x1, int y1, int x2, int y2, const void *p_data, TickType_t ticks_to_wait)
|
||||
{
|
||||
/* Wait for previous tansmition done */
|
||||
if (pdPASS != xSemaphoreTake(bsp_lcd_flush_done_sem, ticks_to_wait)) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
return esp_lcd_panel_draw_bitmap(panel_handle, x1, y1, x2, y2, p_data);
|
||||
}
|
||||
|
||||
esp_err_t bsp_lcd_flush_wait_done(TickType_t ticks_to_wait)
|
||||
{
|
||||
if (pdPASS != xSemaphoreTake(bsp_lcd_flush_done_sem, ticks_to_wait)) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
xSemaphoreGive(bsp_lcd_flush_done_sem);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_lcd_set_cb(bool (*trans_done_cb)(void *), void *data)
|
||||
{
|
||||
if (esp_ptr_executable(trans_done_cb)) {
|
||||
p_on_trans_done_cb = trans_done_cb;
|
||||
p_user_data = data;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid function pointer");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_lcd_set_backlight(bool en)
|
||||
{
|
||||
const board_res_desc_t *brd = bsp_board_get_description();
|
||||
return gpio_set_level(brd->GPIO_LCD_BL, en ? brd->GPIO_LCD_BL_ON : !brd->GPIO_LCD_BL_ON);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_spiffs.h"
|
||||
|
||||
#define DEFAULT_FD_NUM 2
|
||||
#define DEFAULT_MOUNT_POINT "/spiffs"
|
||||
|
||||
static const char *TAG = "bsp_spiffs";
|
||||
|
||||
esp_err_t bsp_spiffs_init(char *partition_label, char *mount_point, size_t max_files)
|
||||
{
|
||||
esp_vfs_spiffs_conf_t conf = {
|
||||
.base_path = mount_point,
|
||||
.partition_label = partition_label,
|
||||
.max_files = max_files,
|
||||
.format_if_mount_failed = false,
|
||||
};
|
||||
|
||||
esp_err_t ret_val = esp_vfs_spiffs_register(&conf);
|
||||
|
||||
if (ESP_OK != ret_val) {
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
size_t total = 0, used = 0;
|
||||
ret_val = esp_spiffs_info(conf.partition_label, &total, &used);
|
||||
if (ret_val != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret_val));
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t bsp_spiffs_init_default(void)
|
||||
{
|
||||
return bsp_spiffs_init(NULL, DEFAULT_MOUNT_POINT, DEFAULT_FD_NUM);
|
||||
}
|
||||
|
||||
esp_err_t bsp_spiffs_deinit(char *partition_label)
|
||||
{
|
||||
return esp_vfs_spiffs_unregister(partition_label);
|
||||
}
|
||||
|
||||
esp_err_t bsp_spiffs_deinit_default(void)
|
||||
{
|
||||
return bsp_spiffs_deinit(NULL);
|
||||
}
|
||||
Submodule components/esp-rainmaker deleted from cef427bb59
Submodule components/esp-sr deleted from c873a359e7
@@ -1,5 +0,0 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS
|
||||
"."
|
||||
INCLUDE_DIRS
|
||||
"include" )
|
||||
@@ -1,466 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "i2c_bus.h"
|
||||
|
||||
#define I2C_ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
#define I2C_ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define I2C_BUS_FLG_DEFAULT (0)
|
||||
#define I2C_BUS_MASTER_BUF_LEN (0)
|
||||
#define I2C_BUS_MS_TO_WAIT (1000)
|
||||
#define I2C_BUS_TICKS_TO_WAIT (I2C_BUS_MS_TO_WAIT/portTICK_RATE_MS)
|
||||
#define I2C_BUS_MUTEX_TICKS_TO_WAIT (I2C_BUS_MS_TO_WAIT/portTICK_RATE_MS)
|
||||
|
||||
static const char *TAG = "i2c_bus";
|
||||
static i2c_bus_t s_i2c_bus[I2C_NUM_MAX];
|
||||
|
||||
#define I2C_BUS_CHECK(a, str, ret) if(!(a)) { \
|
||||
ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
#define I2C_BUS_CHECK_GOTO(a, str, lable) if(!(a)) { \
|
||||
ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
|
||||
goto lable; \
|
||||
}
|
||||
|
||||
#define I2C_BUS_INIT_CHECK(is_init, ret) if(!is_init) { \
|
||||
ESP_LOGE(TAG,"%s:%d (%s):i2c_bus has not inited", __FILE__, __LINE__, __FUNCTION__); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
#define I2C_BUS_MUTEX_TAKE(mutex, ret) if (!xSemaphoreTake(mutex, I2C_BUS_MUTEX_TICKS_TO_WAIT)) { \
|
||||
ESP_LOGE(TAG, "i2c_bus take mutex timeout, max wait = %d ms", I2C_BUS_MUTEX_TICKS_TO_WAIT); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
#define I2C_BUS_MUTEX_TAKE_MAX_DELAY(mutex, ret) if (!xSemaphoreTake(mutex, portMAX_DELAY)) { \
|
||||
ESP_LOGE(TAG, "i2c_bus take mutex timeout, max wait = %d ms", portMAX_DELAY); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
#define I2C_BUS_MUTEX_GIVE(mutex, ret) if (!xSemaphoreGive(mutex)) { \
|
||||
ESP_LOGE(TAG, "i2c_bus give mutex failed"); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
static esp_err_t i2c_driver_reinit(i2c_port_t port, const i2c_config_t *conf);
|
||||
static esp_err_t i2c_driver_deinit(i2c_port_t port);
|
||||
static esp_err_t i2c_bus_write_reg8(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, const uint8_t *data);
|
||||
static esp_err_t i2c_bus_read_reg8(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, uint8_t *data);
|
||||
inline static bool i2c_config_compare(i2c_port_t port, const i2c_config_t *conf);
|
||||
/**************************************** Public Functions (Application level)*********************************************/
|
||||
|
||||
i2c_bus_handle_t i2c_bus_create(i2c_port_t port, const i2c_config_t *conf)
|
||||
{
|
||||
I2C_BUS_CHECK(port < I2C_NUM_MAX, "I2C port error", NULL);
|
||||
I2C_BUS_CHECK(conf != NULL, "pointer = NULL error", NULL);
|
||||
I2C_BUS_CHECK(conf->mode == I2C_MODE_MASTER, "i2c_bus only supports master mode", NULL);
|
||||
|
||||
if (s_i2c_bus[port].is_init) {
|
||||
/**if i2c_bus has been inited and configs not changed, return the handle directly**/
|
||||
if (i2c_config_compare(port, conf)) {
|
||||
ESP_LOGW(TAG, "i2c%d has been inited, return handle directly, ref_counter=%d", port, s_i2c_bus[port].ref_counter);
|
||||
return (i2c_bus_handle_t)&s_i2c_bus[port];
|
||||
}
|
||||
} else {
|
||||
s_i2c_bus[port].mutex = xSemaphoreCreateMutex();
|
||||
I2C_BUS_CHECK(s_i2c_bus[port].mutex != NULL, "i2c_bus xSemaphoreCreateMutex failed", NULL);
|
||||
s_i2c_bus[port].ref_counter = 0;
|
||||
}
|
||||
|
||||
esp_err_t ret = i2c_driver_reinit(port, conf);
|
||||
I2C_BUS_CHECK(ret == ESP_OK, "init error", NULL);
|
||||
s_i2c_bus[port].conf_active = *conf;
|
||||
s_i2c_bus[port].i2c_port = port;
|
||||
return (i2c_bus_handle_t)&s_i2c_bus[port];
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_delete(i2c_bus_handle_t *p_bus)
|
||||
{
|
||||
I2C_BUS_CHECK(p_bus != NULL && *p_bus != NULL, "pointer = NULL error", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *)(*p_bus);
|
||||
I2C_BUS_INIT_CHECK(i2c_bus->is_init, ESP_FAIL);
|
||||
I2C_BUS_MUTEX_TAKE_MAX_DELAY(i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
|
||||
/** if ref_counter == 0, de-init the bus**/
|
||||
if ((i2c_bus->ref_counter) > 0) {
|
||||
ESP_LOGW(TAG, "i2c%d is also handled by others ref_counter=%u, won't be de-inited", i2c_bus->i2c_port, i2c_bus->ref_counter);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ret = i2c_driver_deinit(i2c_bus->i2c_port);
|
||||
I2C_BUS_CHECK(ret == ESP_OK, "deinit error", ret);
|
||||
vSemaphoreDelete(i2c_bus->mutex);
|
||||
*p_bus = NULL;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint8_t i2c_bus_scan(i2c_bus_handle_t bus_handle, uint8_t *buf, uint8_t num)
|
||||
{
|
||||
I2C_BUS_CHECK(bus_handle != NULL, "Handle error", 0);
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *)bus_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_bus->is_init, 0);
|
||||
uint8_t device_count = 0;
|
||||
I2C_BUS_MUTEX_TAKE_MAX_DELAY(i2c_bus->mutex, 0);
|
||||
for (uint8_t dev_address = 1; dev_address < 127; dev_address++) {
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (dev_address << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin(i2c_bus->i2c_port, cmd, I2C_BUS_TICKS_TO_WAIT);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI(TAG, "found i2c device address = 0x%02x", dev_address);
|
||||
if (buf != NULL && device_count < num) {
|
||||
*(buf + device_count) = dev_address;
|
||||
}
|
||||
device_count++;
|
||||
}
|
||||
|
||||
i2c_cmd_link_delete(cmd);
|
||||
}
|
||||
I2C_BUS_MUTEX_GIVE(i2c_bus->mutex, 0);
|
||||
return device_count;
|
||||
}
|
||||
|
||||
uint32_t i2c_bus_get_current_clk_speed(i2c_bus_handle_t bus_handle)
|
||||
{
|
||||
I2C_BUS_CHECK(bus_handle != NULL, "Null Bus Handle", 0);
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *)bus_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_bus->is_init, 0);
|
||||
return i2c_bus->conf_active.master.clk_speed;
|
||||
}
|
||||
|
||||
uint8_t i2c_bus_get_created_device_num(i2c_bus_handle_t bus_handle)
|
||||
{
|
||||
I2C_BUS_CHECK(bus_handle != NULL, "Null Bus Handle", 0);
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *)bus_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_bus->is_init, 0);
|
||||
return i2c_bus->ref_counter;
|
||||
}
|
||||
|
||||
i2c_bus_device_handle_t i2c_bus_device_create(i2c_bus_handle_t bus_handle, uint8_t dev_addr, uint32_t clk_speed)
|
||||
{
|
||||
I2C_BUS_CHECK(bus_handle != NULL, "Null Bus Handle", NULL);
|
||||
I2C_BUS_CHECK(clk_speed <= 400000, "clk_speed must <= 400000", NULL);
|
||||
i2c_bus_t *i2c_bus = (i2c_bus_t *)bus_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_bus->is_init, NULL);
|
||||
i2c_bus_device_t *i2c_device = calloc(1, sizeof(i2c_bus_device_t));
|
||||
I2C_BUS_CHECK(i2c_device != NULL, "calloc memory failed", NULL);
|
||||
I2C_BUS_MUTEX_TAKE_MAX_DELAY(i2c_bus->mutex, NULL);
|
||||
i2c_device->dev_addr = dev_addr;
|
||||
i2c_device->conf = i2c_bus->conf_active;
|
||||
|
||||
/*if clk_speed == 0, current active clock speed will be used, else set a specified value*/
|
||||
if (clk_speed != 0) {
|
||||
i2c_device->conf.master.clk_speed = clk_speed;
|
||||
}
|
||||
|
||||
i2c_device->i2c_bus = i2c_bus;
|
||||
i2c_bus->ref_counter++;
|
||||
I2C_BUS_MUTEX_GIVE(i2c_bus->mutex, NULL);
|
||||
return (i2c_bus_device_handle_t)i2c_device;
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_device_delete(i2c_bus_device_handle_t *p_dev_handle)
|
||||
{
|
||||
I2C_BUS_CHECK(p_dev_handle != NULL && *p_dev_handle != NULL, "Null Device Handle", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)(*p_dev_handle);
|
||||
I2C_BUS_MUTEX_TAKE_MAX_DELAY(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
i2c_device->i2c_bus->ref_counter--;
|
||||
I2C_BUS_MUTEX_GIVE(i2c_device->i2c_bus->mutex, ESP_FAIL);
|
||||
free(i2c_device);
|
||||
*p_dev_handle = NULL;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint8_t i2c_bus_device_get_address(i2c_bus_device_handle_t dev_handle)
|
||||
{
|
||||
I2C_BUS_CHECK(dev_handle != NULL, "device handle error", NULL_I2C_DEV_ADDR);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)dev_handle;
|
||||
return i2c_device->dev_addr;
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_read_bytes(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, uint8_t *data)
|
||||
{
|
||||
return i2c_bus_read_reg8(dev_handle, mem_address, data_len, data);
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_read_byte(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t *data)
|
||||
{
|
||||
return i2c_bus_read_reg8(dev_handle, mem_address, 1, data);
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_read_bit(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_num, uint8_t *data)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
esp_err_t ret = i2c_bus_read_reg8(dev_handle, mem_address, 1, &byte);
|
||||
*data = byte & (1 << bit_num);
|
||||
*data = (*data != 0) ? 1 : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_read_bits(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_start, uint8_t length, uint8_t *data)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
esp_err_t ret = i2c_bus_read_byte(dev_handle, mem_address, &byte);
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t mask = ((1 << length) - 1) << (bit_start - length + 1);
|
||||
byte &= mask;
|
||||
byte >>= (bit_start - length + 1);
|
||||
*data = byte;
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_write_byte(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_reg8(dev_handle, mem_address, 1, &data);
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_write_bytes(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, const uint8_t *data)
|
||||
{
|
||||
return i2c_bus_write_reg8(dev_handle, mem_address, data_len, data);
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_write_bit(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_num, uint8_t data)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
esp_err_t ret = i2c_bus_read_byte(dev_handle, mem_address, &byte);
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
byte = (data != 0) ? (byte | (1 << bit_num)) : (byte & ~(1 << bit_num));
|
||||
return i2c_bus_write_byte(dev_handle, mem_address, byte);
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_write_bits(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_start, uint8_t length, uint8_t data)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
esp_err_t ret = i2c_bus_read_byte(dev_handle, mem_address, &byte);
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t mask = ((1 << length) - 1) << (bit_start - length + 1);
|
||||
data <<= (bit_start - length + 1); // shift data into correct position
|
||||
data &= mask; // zero all non-important bits in data
|
||||
byte &= ~(mask); // zero all important bits in existing byte
|
||||
byte |= data; // combine data with existing byte
|
||||
return i2c_bus_write_byte(dev_handle, mem_address, byte);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C master send queued commands.
|
||||
* This function will trigger sending all queued commands.
|
||||
* The task will be blocked until all the commands have been sent out.
|
||||
* If I2C_BUS_DYNAMIC_CONFIG enable, i2c_bus will dynamically check configs and re-install i2c driver before each transfer,
|
||||
* hence multiple devices with different configs on a single bus can be supported.
|
||||
* @note
|
||||
* Only call this function in I2C master mode
|
||||
*
|
||||
* @param i2c_num I2C port number
|
||||
* @param cmd_handle I2C command handler
|
||||
* @param ticks_to_wait maximum wait ticks.
|
||||
* @param conf pointer to I2C parameter settings
|
||||
* @return esp_err_t
|
||||
*/
|
||||
inline static esp_err_t i2c_master_cmd_begin_with_conf(i2c_port_t i2c_num, i2c_cmd_handle_t cmd_handle, TickType_t ticks_to_wait, const i2c_config_t *conf)
|
||||
{
|
||||
esp_err_t ret;
|
||||
#ifdef CONFIG_I2C_BUS_DYNAMIC_CONFIG
|
||||
/*if configs changed, i2c driver will reinit with new configuration*/
|
||||
if (conf != NULL && false == i2c_config_compare(i2c_num, conf)) {
|
||||
ret = i2c_driver_reinit(i2c_num, conf);
|
||||
I2C_BUS_CHECK(ret == ESP_OK, "reinit error", ret);
|
||||
s_i2c_bus[i2c_num].conf_active = *conf;
|
||||
}
|
||||
#endif
|
||||
ret = i2c_master_cmd_begin(i2c_num, cmd_handle, ticks_to_wait);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**************************************** Public Functions (Low level)*********************************************/
|
||||
|
||||
esp_err_t i2c_bus_cmd_begin(i2c_bus_device_handle_t dev_handle, i2c_cmd_handle_t cmd)
|
||||
{
|
||||
I2C_BUS_CHECK(dev_handle != NULL, "device handle error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(cmd != NULL, "I2C command error", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)dev_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_device->i2c_bus->is_init, ESP_ERR_INVALID_STATE);
|
||||
I2C_BUS_MUTEX_TAKE(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
esp_err_t ret = i2c_master_cmd_begin_with_conf(i2c_device->i2c_bus->i2c_port, cmd, I2C_BUS_TICKS_TO_WAIT, &i2c_device->conf);
|
||||
I2C_BUS_MUTEX_GIVE(i2c_device->i2c_bus->mutex, ESP_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t i2c_bus_read_reg8(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, uint8_t *data)
|
||||
{
|
||||
I2C_BUS_CHECK(dev_handle != NULL, "device handle error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(data != NULL, "data pointer error", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)dev_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_device->i2c_bus->is_init, ESP_ERR_INVALID_STATE);
|
||||
I2C_BUS_MUTEX_TAKE(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
|
||||
if (mem_address != NULL_I2C_MEM_ADDR) {
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, mem_address, I2C_ACK_CHECK_EN);
|
||||
}
|
||||
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_READ, I2C_ACK_CHECK_EN);
|
||||
i2c_master_read(cmd, data, data_len, I2C_MASTER_LAST_NACK);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin_with_conf(i2c_device->i2c_bus->i2c_port, cmd, I2C_BUS_TICKS_TO_WAIT, &i2c_device->conf);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
I2C_BUS_MUTEX_GIVE(i2c_device->i2c_bus->mutex, ESP_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_read_reg16(i2c_bus_device_handle_t dev_handle, uint16_t mem_address, size_t data_len, uint8_t *data)
|
||||
{
|
||||
I2C_BUS_CHECK(dev_handle != NULL, "device handle error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(data != NULL, "data pointer error", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)dev_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_device->i2c_bus->is_init, ESP_ERR_INVALID_STATE);
|
||||
uint8_t memAddress8[2];
|
||||
memAddress8[0] = (uint8_t)((mem_address >> 8) & 0x00FF);
|
||||
memAddress8[1] = (uint8_t)(mem_address & 0x00FF);
|
||||
I2C_BUS_MUTEX_TAKE(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
|
||||
if (mem_address != NULL_I2C_MEM_ADDR) {
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
|
||||
i2c_master_write(cmd, memAddress8, 2, I2C_ACK_CHECK_EN);
|
||||
}
|
||||
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_READ, I2C_ACK_CHECK_EN);
|
||||
i2c_master_read(cmd, data, data_len, I2C_MASTER_LAST_NACK);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin_with_conf(i2c_device->i2c_bus->i2c_port, cmd, I2C_BUS_TICKS_TO_WAIT, &i2c_device->conf);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
I2C_BUS_MUTEX_GIVE(i2c_device->i2c_bus->mutex, ESP_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t i2c_bus_write_reg8(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, const uint8_t *data)
|
||||
{
|
||||
I2C_BUS_CHECK(dev_handle != NULL, "device handle error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(data != NULL, "data pointer error", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)dev_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_device->i2c_bus->is_init, ESP_ERR_INVALID_STATE);
|
||||
I2C_BUS_MUTEX_TAKE(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
|
||||
|
||||
if (mem_address != NULL_I2C_MEM_ADDR) {
|
||||
i2c_master_write_byte(cmd, mem_address, I2C_ACK_CHECK_EN);
|
||||
}
|
||||
|
||||
i2c_master_write(cmd, (uint8_t *)data, data_len, I2C_ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin_with_conf(i2c_device->i2c_bus->i2c_port, cmd, I2C_BUS_TICKS_TO_WAIT, &i2c_device->conf);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
I2C_BUS_MUTEX_GIVE(i2c_device->i2c_bus->mutex, ESP_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t i2c_bus_write_reg16(i2c_bus_device_handle_t dev_handle, uint16_t mem_address, size_t data_len, const uint8_t *data)
|
||||
{
|
||||
I2C_BUS_CHECK(dev_handle != NULL, "device handle error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(data != NULL, "data pointer error", ESP_ERR_INVALID_ARG);
|
||||
i2c_bus_device_t *i2c_device = (i2c_bus_device_t *)dev_handle;
|
||||
I2C_BUS_INIT_CHECK(i2c_device->i2c_bus->is_init, ESP_ERR_INVALID_STATE);
|
||||
uint8_t memAddress8[2];
|
||||
memAddress8[0] = (uint8_t)((mem_address >> 8) & 0x00FF);
|
||||
memAddress8[1] = (uint8_t)(mem_address & 0x00FF);
|
||||
I2C_BUS_MUTEX_TAKE(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
|
||||
|
||||
if (mem_address != NULL_I2C_MEM_ADDR) {
|
||||
i2c_master_write(cmd, memAddress8, 2, I2C_ACK_CHECK_EN);
|
||||
}
|
||||
|
||||
i2c_master_write(cmd, (uint8_t *)data, data_len, I2C_ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin_with_conf(i2c_device->i2c_bus->i2c_port, cmd, I2C_BUS_TICKS_TO_WAIT, &i2c_device->conf);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
I2C_BUS_MUTEX_GIVE(i2c_device->i2c_bus->mutex, ESP_FAIL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**************************************** Private Functions*********************************************/
|
||||
static esp_err_t i2c_driver_reinit(i2c_port_t port, const i2c_config_t *conf)
|
||||
{
|
||||
I2C_BUS_CHECK(port < I2C_NUM_MAX, "i2c port error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(conf != NULL, "pointer = NULL error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
if (s_i2c_bus[port].is_init) {
|
||||
i2c_driver_delete(port);
|
||||
s_i2c_bus[port].is_init = false;
|
||||
ESP_LOGI(TAG, "i2c%d bus deinited", port);
|
||||
}
|
||||
|
||||
esp_err_t ret = i2c_param_config(port, conf);
|
||||
I2C_BUS_CHECK(ret == ESP_OK, "i2c param config failed", ret);
|
||||
ret = i2c_driver_install(port, conf->mode, I2C_BUS_MASTER_BUF_LEN, I2C_BUS_MASTER_BUF_LEN, I2C_BUS_FLG_DEFAULT);
|
||||
I2C_BUS_CHECK(ret == ESP_OK, "i2c driver install failed", ret);
|
||||
s_i2c_bus[port].is_init = true;
|
||||
ESP_LOGD(TAG, "i2c%d bus inited", port);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t i2c_driver_deinit(i2c_port_t port)
|
||||
{
|
||||
I2C_BUS_CHECK(port < I2C_NUM_MAX, "i2c port error", ESP_ERR_INVALID_ARG);
|
||||
I2C_BUS_CHECK(s_i2c_bus[port].is_init == true, "i2c not inited", ESP_ERR_INVALID_STATE);
|
||||
i2c_driver_delete(port); //always return ESP_OK
|
||||
s_i2c_bus[port].is_init = false;
|
||||
ESP_LOGD(TAG,"i2c%d bus deinited",port);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief compare with active i2c_bus configuration
|
||||
*
|
||||
* @param port choose which i2c_port's configuration will be compared
|
||||
* @param conf new configuration
|
||||
* @return true new configuration is equal to active configuration
|
||||
* @return false new configuration is not equal to active configuration
|
||||
*/
|
||||
inline static bool i2c_config_compare(i2c_port_t port, const i2c_config_t *conf)
|
||||
{
|
||||
if (s_i2c_bus[port].conf_active.master.clk_speed == conf->master.clk_speed
|
||||
&& s_i2c_bus[port].conf_active.sda_io_num == conf->sda_io_num
|
||||
&& s_i2c_bus[port].conf_active.scl_io_num == conf->scl_io_num
|
||||
&& s_i2c_bus[port].conf_active.scl_pullup_en == conf->scl_pullup_en
|
||||
&& s_i2c_bus[port].conf_active.sda_pullup_en == conf->sda_pullup_en) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _I2C_BUS_H_
|
||||
#define _I2C_BUS_H_
|
||||
#include "driver/i2c.h"
|
||||
|
||||
#define NULL_I2C_MEM_ADDR 0xFF /*!< set mem_address to NULL_I2C_MEM_ADDR if i2c device has no internal address during read/write */
|
||||
#define NULL_I2C_DEV_ADDR 0xFF /*!< invalid i2c device address */
|
||||
typedef void *i2c_bus_handle_t; /*!< i2c bus handle */
|
||||
typedef void *i2c_bus_device_handle_t; /*!< i2c device handle */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
i2c_port_t i2c_port; /*!<I2C port number */
|
||||
bool is_init; /*if bus is initialized*/
|
||||
i2c_config_t conf_active; /*!<I2C active configuration */
|
||||
SemaphoreHandle_t mutex; /* mutex to achive thread-safe*/
|
||||
int32_t ref_counter; /*reference count*/
|
||||
} i2c_bus_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t dev_addr; /*device address*/
|
||||
i2c_config_t conf; /*!<I2C active configuration */
|
||||
i2c_bus_t *i2c_bus; /*!<I2C bus*/
|
||||
} i2c_bus_device_t;
|
||||
|
||||
/**************************************** Public Functions (Application level)*********************************************/
|
||||
|
||||
/**
|
||||
* @brief Create an I2C bus instance then return a handle if created successfully. Each I2C bus works in a singleton mode,
|
||||
* which means for an i2c port only one group parameter works. When i2c_bus_create is called more than one time for the
|
||||
* same i2c port, following parameter will override the previous one.
|
||||
*
|
||||
* @param port I2C port number
|
||||
* @param conf Pointer to I2C bus configuration
|
||||
* @return i2c_bus_handle_t Return the I2C bus handle if created successfully, return NULL if failed.
|
||||
*/
|
||||
i2c_bus_handle_t i2c_bus_create(i2c_port_t port, const i2c_config_t *conf);
|
||||
|
||||
/**
|
||||
* @brief Delete and release the I2C bus resource.
|
||||
*
|
||||
* @param p_bus_handle Point to the I2C bus handle, if delete succeed handle will set to NULL.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Fail
|
||||
*/
|
||||
esp_err_t i2c_bus_delete(i2c_bus_handle_t *p_bus_handle);
|
||||
|
||||
/**
|
||||
* @brief Scan i2c devices attached on i2c bus
|
||||
*
|
||||
* @param bus_handle I2C bus handle
|
||||
* @param buf Pointer to a buffer to save devices' address, if NULL no address will be saved.
|
||||
* @param num Maximum number of addresses to save, invalid if buf set to NULL,
|
||||
* higer addresses will be discarded if num less-than the total number found on the I2C bus.
|
||||
* @return uint8_t Total number of devices found on the I2C bus
|
||||
*/
|
||||
uint8_t i2c_bus_scan(i2c_bus_handle_t bus_handle, uint8_t *buf, uint8_t num);
|
||||
|
||||
/**
|
||||
* @brief Get current active clock speed.
|
||||
*
|
||||
* @param bus_handle I2C bus handle
|
||||
* @return uint32_t current clock speed
|
||||
*/
|
||||
uint32_t i2c_bus_get_current_clk_speed(i2c_bus_handle_t bus_handle);
|
||||
|
||||
/**
|
||||
* @brief Get created device number of the bus.
|
||||
*
|
||||
* @param bus_handle I2C bus handle
|
||||
* @return uint8_t created device number of the bus
|
||||
*/
|
||||
uint8_t i2c_bus_get_created_device_num(i2c_bus_handle_t bus_handle);
|
||||
|
||||
/**
|
||||
* @brief Create an I2C device on specific bus.
|
||||
* Dynamic configuration must be enable to achieve multiple devices with different configs on a single bus.
|
||||
* menuconfig:Bus Options->I2C Bus Options->enable dynamic configuration
|
||||
*
|
||||
* @param bus_handle Point to the I2C bus handle
|
||||
* @param dev_addr i2c device address
|
||||
* @param clk_speed device specified clock frequency the i2c_bus will switch to during each transfer. 0 if use current bus speed.
|
||||
* @return i2c_bus_device_handle_t return a device handle if created successfully, return NULL if failed.
|
||||
*/
|
||||
i2c_bus_device_handle_t i2c_bus_device_create(i2c_bus_handle_t bus_handle, uint8_t dev_addr, uint32_t clk_speed);
|
||||
|
||||
/**
|
||||
* @brief Delete and release the I2C device resource, i2c_bus_device_delete should be used in pairs with i2c_bus_device_create.
|
||||
*
|
||||
* @param p_dev_handle Point to the I2C device handle, if delete succeed handle will set to NULL.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Fail
|
||||
*/
|
||||
esp_err_t i2c_bus_device_delete(i2c_bus_device_handle_t *p_dev_handle);
|
||||
|
||||
/**
|
||||
* @brief Get device's I2C address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @return uint8_t I2C address, return NULL_I2C_DEV_ADDR if dev_handle is invalid.
|
||||
*/
|
||||
uint8_t i2c_bus_device_get_address(i2c_bus_device_handle_t dev_handle);
|
||||
|
||||
/**
|
||||
* @brief Read single byte from i2c device with 8-bit internal register/memory address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to read from, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param data Pointer to a buffer to save the data that was read
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_read_byte(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Read multiple bytes from i2c device with 8-bit internal register/memory address.
|
||||
* If internal reg/mem address is 16-bit, please refer i2c_bus_read_reg16
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to read from, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param data_len Number of bytes to read
|
||||
* @param data Pointer to a buffer to save the data that was read
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_read_bytes(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Read single bit of a byte from i2c device with 8-bit internal register/memory address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to read from, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param bit_num The bit number 0 - 7 to read
|
||||
* @param data Pointer to a buffer to save the data that was read. *data == 0 -> bit = 0, *data !=0 -> bit = 1.
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_read_bit(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_num, uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Read multiple bits of a byte from i2c device with 8-bit internal register/memory address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to read from, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param bit_start The bit to start from, 0 - 7, MSB at 0
|
||||
* @param length The number of bits to read, 1 - 8
|
||||
* @param data Pointer to a buffer to save the data that was read
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_read_bits(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_start, uint8_t length, uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Write single byte to i2c device with 8-bit internal register/memory address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to write to, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param data The byte to write.
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_write_byte(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t data);
|
||||
|
||||
/**
|
||||
* @brief Write multiple byte to i2c device with 8-bit internal register/memory address
|
||||
* If internal reg/mem address is 16-bit, please refer i2c_bus_write_reg16
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to write to, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param data_len Number of bytes to write
|
||||
* @param data Pointer to the bytes to write.
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_write_bytes(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, size_t data_len, const uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Write single bit of a byte to an i2c device with 8-bit internal register/memory address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to write to, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param bit_num The bit number 0 - 7 to write
|
||||
* @param data The bit to write, data == 0 means set bit = 0, data !=0 means set bit = 1.
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_write_bit(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_num, uint8_t data);
|
||||
|
||||
/**
|
||||
* @brief Write multiple bits of a byte to an i2c device with 8-bit internal register/memory address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal reg/mem address to write to, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param bit_start The bit to start from, 0 - 7, MSB at 0
|
||||
* @param length The number of bits to write, 1 - 8
|
||||
* @param data The bits to write.
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_write_bits(i2c_bus_device_handle_t dev_handle, uint8_t mem_address, uint8_t bit_start, uint8_t length, uint8_t data);
|
||||
|
||||
/**************************************** Public Functions (Low level)*********************************************/
|
||||
|
||||
/**
|
||||
* @brief I2C master send queued commands create by ``i2c_cmd_link_create`` .
|
||||
* This function will trigger sending all queued commands.
|
||||
* The task will be blocked until all the commands have been sent out.
|
||||
* If I2C_BUS_DYNAMIC_CONFIG enable, i2c_bus will dynamically check configs and re-install i2c driver before each transfer,
|
||||
* hence multiple devices with different configs on a single bus can be supported.
|
||||
* @note
|
||||
* Only call this function when ``i2c_bus_read/write_xx`` do not meet the requirements
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param cmd I2C command handler
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_cmd_begin(i2c_bus_device_handle_t dev_handle, i2c_cmd_handle_t cmd);
|
||||
|
||||
/**
|
||||
* @brief Write date to an i2c device with 16-bit internal reg/mem address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal 16-bit reg/mem address to write to, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param data_len Number of bytes to write
|
||||
* @param data Pointer to the bytes to write.
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_write_reg16(i2c_bus_device_handle_t dev_handle, uint16_t mem_address, size_t data_len, const uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Read date from i2c device with 16-bit internal reg/mem address
|
||||
*
|
||||
* @param dev_handle I2C device handle
|
||||
* @param mem_address The internal 16-bit reg/mem address to read from, set to NULL_I2C_MEM_ADDR if no internal address.
|
||||
* @param data_len Number of bytes to read
|
||||
* @param data Pointer to a buffer to save the data that was read
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
|
||||
* - ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
|
||||
*/
|
||||
esp_err_t i2c_bus_read_reg16(i2c_bus_device_handle_t dev_handle, uint16_t mem_address, size_t data_len, uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
idf_component_register(
|
||||
SRC_DIRS
|
||||
"icm42670"
|
||||
"touch_panel"
|
||||
INCLUDE_DIRS
|
||||
"icm42670/include"
|
||||
"touch_panel/include"
|
||||
REQUIRES
|
||||
bsp)
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE
|
||||
-Wno-unused-variable
|
||||
-Wno-unused-function
|
||||
-Wno-incompatible-pointer-types)
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#include "Message.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int msg_level;
|
||||
static inv_msg_printer_t msg_printer;
|
||||
|
||||
void inv_msg_printer_default(int level, const char * str, va_list ap)
|
||||
{
|
||||
#if !defined(__ICCARM__)
|
||||
const char * s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
" [E] ", // INV_MSG_LEVEL_ERROR
|
||||
" [W] ", // INV_MSG_LEVEL_WARNING
|
||||
" [I] ", // INV_MSG_LEVEL_INFO
|
||||
" [V] ", // INV_MSG_LEVEL_VERBOSE
|
||||
" [D] ", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
|
||||
fprintf(stderr, "%s", s[level]);
|
||||
vfprintf(stderr, str, ap);
|
||||
fprintf(stderr, "\n");
|
||||
#else
|
||||
(void)level, (void)str, (void)ap;
|
||||
#endif
|
||||
}
|
||||
|
||||
void inv_msg_setup(int level, inv_msg_printer_t printer)
|
||||
{
|
||||
msg_level = level;
|
||||
if (level < INV_MSG_LEVEL_OFF)
|
||||
msg_level = INV_MSG_LEVEL_OFF;
|
||||
else if (level > INV_MSG_LEVEL_MAX)
|
||||
msg_level = INV_MSG_LEVEL_MAX;
|
||||
msg_printer = printer;
|
||||
}
|
||||
|
||||
void inv_msg(int level, const char * str, ...)
|
||||
{
|
||||
if(level && level <= msg_level && msg_printer) {
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
msg_printer(level, str, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
int inv_msg_get_level(void)
|
||||
{
|
||||
return msg_level;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
## ICM-42670-P
|
||||
|
||||
The [ICM-42670-P](https://3cfeqx1hf82y3xcoull08ihx-wpengine.netdna-ssl.com/wp-content/uploads/2021/07/DS-000451-ICM-42670-P-v1.0.pdf) is a 6-axis MEMS Motion Tracking device that combines a 3‑axis gyroscope and a 3‑axis accelerometer.
|
||||
|
||||
**ICM-42607-P** labled in schematic is an used name of **ICM-42670-P**, the two chips are fully pin-to-pin compatible.
|
||||
@@ -1,169 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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 "stdio.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "bsp_i2c.h"
|
||||
#include "Message.h"
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
static const char *TAG = "icm42670";
|
||||
|
||||
|
||||
/*
|
||||
* Set of timers used throughout standalone applications
|
||||
*/
|
||||
|
||||
#define SENSOR_ODR_1600HZ 1600
|
||||
#define SENSOR_ODR_800HZ 800
|
||||
#define SENSOR_ODR_400HZ 400
|
||||
#define SENSOR_ODR_200HZ 200
|
||||
#define SENSOR_ODR_100HZ 100
|
||||
#define SENSOR_ODR_50HZ 50
|
||||
#define SENSOR_ODR_25HZ 25
|
||||
#define SENSOR_ODR_12_5HZ 12.5
|
||||
|
||||
|
||||
static i2c_bus_device_handle_t g_i2c_dev_handle;
|
||||
|
||||
static int platform_io_hal_read_reg(void *context, uint8_t reg, uint8_t *buf, uint32_t len)
|
||||
{
|
||||
return i2c_bus_read_bytes(g_i2c_dev_handle, reg, len, buf);
|
||||
}
|
||||
|
||||
static int platform_io_hal_write_reg(void *context, uint8_t reg, const uint8_t *buf, uint32_t len)
|
||||
{
|
||||
return i2c_bus_write_bytes(g_i2c_dev_handle, reg, len, buf);
|
||||
}
|
||||
|
||||
static void platform_delay_ms(uint32_t ms)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(ms));
|
||||
}
|
||||
|
||||
static void platform_delay_us(uint32_t us)
|
||||
{
|
||||
ets_delay_us(us);
|
||||
}
|
||||
|
||||
/*
|
||||
* Printer function for message facility
|
||||
*/
|
||||
static void msg_printer(int level, const char *str, va_list ap)
|
||||
{
|
||||
static char out_str[2560]; /* static to limit stack usage */
|
||||
uint32_t idx = 0;
|
||||
#define LOG_COLOR_BLACK "30"
|
||||
#define LOG_COLOR_RED "31"
|
||||
#define LOG_COLOR_GREEN "32"
|
||||
#define LOG_COLOR_BROWN "33"
|
||||
#define LOG_COLOR_BLUE "34"
|
||||
#define LOG_COLOR_PURPLE "35"
|
||||
#define LOG_COLOR_CYAN "36"
|
||||
#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
|
||||
#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
|
||||
#define LOG_RESET_COLOR "\033[0m"
|
||||
#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
|
||||
#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
|
||||
#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
|
||||
const char *s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
LOG_COLOR_E "[E]", // INV_MSG_LEVEL_ERROR
|
||||
LOG_COLOR_W "[W]", // INV_MSG_LEVEL_WARNING
|
||||
LOG_COLOR_I "[I]", // INV_MSG_LEVEL_INFO
|
||||
LOG_COLOR_BLUE "[V]", // INV_MSG_LEVEL_VERBOSE
|
||||
LOG_COLOR_BLUE "[D]", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
if (level >= INV_MSG_LEVEL_MAX) {
|
||||
printf("message error!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "%s %s: ", s[level], TAG);
|
||||
if (idx >= (sizeof(out_str))) {
|
||||
return;
|
||||
}
|
||||
idx += vsnprintf(&out_str[idx], sizeof(out_str) - idx, str, ap);
|
||||
if (idx >= (sizeof(out_str))) {
|
||||
return;
|
||||
}
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, LOG_RESET_COLOR "\r\n");
|
||||
if (idx >= (sizeof(out_str))) {
|
||||
return;
|
||||
}
|
||||
printf(out_str);
|
||||
}
|
||||
|
||||
esp_err_t icm42670_init(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
if (NULL != g_i2c_dev_handle) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
bsp_i2c_add_device(&g_i2c_dev_handle, 0x68);
|
||||
|
||||
if (NULL == g_i2c_dev_handle) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Setup message facility to see internal traces from FW */
|
||||
inv_msg_setup(INV_MSG_LEVEL_INFO, msg_printer);
|
||||
|
||||
inv_imu_set_serif(platform_io_hal_read_reg, platform_io_hal_write_reg);
|
||||
inv_imu_set_delay(platform_delay_ms, platform_delay_us);
|
||||
|
||||
float hw_rate = 0.0;
|
||||
|
||||
/* Init device */
|
||||
ret = inv_imu_initialize();
|
||||
|
||||
if (ret != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize INV concise driver!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "IMU device successfully initialized");
|
||||
|
||||
// We may customize full scale range here.
|
||||
ret |= inv_imu_set_accel_fsr(ACCEL_CONFIG0_FS_SEL_4g);
|
||||
ret |= inv_imu_set_gyro_fsr(GYRO_CONFIG0_FS_SEL_2000dps);
|
||||
|
||||
// Below settings are required to configure and enable sensors.
|
||||
ret |= inv_imu_acc_enable();
|
||||
ret |= inv_imu_acc_set_rate(SENSOR_ODR_400HZ, 2, &hw_rate); //200Hz ODR, watermark: 2 packets.
|
||||
ret |= inv_imu_gyro_enable();
|
||||
ret |= inv_imu_gyro_set_rate(SENSOR_ODR_400HZ, 4, &hw_rate); //50Hz ODR, watermark 4.
|
||||
|
||||
if (ret != 0) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Feature enable Failed. Do nothing %d", ret);
|
||||
return ret;
|
||||
}
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "HW odr setting %f ", hw_rate);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t icm42670_get_raw_data(AccDataPacket *accData,
|
||||
GyroDataPacket *gyroData,
|
||||
chip_temperature *imu_chip_temperature)
|
||||
{
|
||||
int ret = inv_data_handler(accData, gyroData, imu_chip_temperature, 1);
|
||||
if (0 != ret) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#ifndef _INV_IDD_EXPORT_H_
|
||||
#define _INV_IDD_EXPORT_H_
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if !defined(INV_EXPORT) && defined(INV_DO_DLL_EXPORT)
|
||||
#define INV_EXPORT __declspec(dllexport)
|
||||
#elif !defined(INV_EXPORT) && defined(INV_DO_DLL_IMPORT)
|
||||
#define INV_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(INV_EXPORT)
|
||||
#define INV_EXPORT
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IDD_EXPORT_H_ */
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup Message Message
|
||||
* @brief Utility functions to display and redirect diagnostic messages
|
||||
*
|
||||
* Use INV_MSG_DISABLE or INV_MSG_ENABLE define before including
|
||||
* this header to enable/disable messages for a compilation unit.
|
||||
*
|
||||
* Under Linux, Windows or Arduino, messages are enabled by default.
|
||||
* Use INV_MSG_DISABLE to disable them.
|
||||
*
|
||||
* Under orther environmment, message are disabled by default.
|
||||
* Use INV_MSG_ENABLE to disable them.
|
||||
*
|
||||
* @ingroup EmbUtils
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _INV_MESSAGE_H_
|
||||
#define _INV_MESSAGE_H_
|
||||
|
||||
#include "InvExport.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/** @brief For eMD target, disable log by default
|
||||
* If compile switch is set for a compilation unit
|
||||
* messages will be totally disabled by default
|
||||
*/
|
||||
#if !defined(__linux) && !defined(_WIN32) && !defined(ARDUINO)
|
||||
#define INV_MSG_DISABLE 1
|
||||
#endif
|
||||
|
||||
#define INV_MSG_ENABLE
|
||||
|
||||
/** @brief Allow to force enabling messaging using INV_MSG_ENABLE define */
|
||||
#ifdef INV_MSG_ENABLE
|
||||
#undef INV_MSG_DISABLE
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief Helper macro for calling inv_msg()
|
||||
* If INV_MSG_DISABLE compile switch is set for a compilation unit
|
||||
* messages will be totally disabled
|
||||
*/
|
||||
#define INV_MSG(level, ...) _INV_MSG(level, __VA_ARGS__)
|
||||
|
||||
/** @brief Helper macro for calling inv_msg_setup()
|
||||
* If INV_MSG_DISABLE compile switch is set for a compilation unit
|
||||
* messages will be totally disabled
|
||||
*/
|
||||
#define INV_MSG_SETUP(level, printer) _INV_MSG_SETUP(level, printer)
|
||||
|
||||
/** @brief Helper macro for calling inv_msg_setup_level()
|
||||
* If INV_MSG_DISABLE compile switch is set for a compilation unit
|
||||
* messages will be totally disabled
|
||||
*/
|
||||
#define INV_MSG_SETUP_LEVEL(level) _INV_MSG_SETUP_LEVEL(level)
|
||||
|
||||
/** @brief Helper macro for calling inv_msg_setup_default()
|
||||
* If INV_MSG_DISABLE compile switch is set for a compilation unit
|
||||
* messages will be totally disabled
|
||||
*/
|
||||
#define INV_MSG_SETUP_DEFAULT() _INV_MSG_SETUP_DEFAULT()
|
||||
|
||||
/** @brief Return current level
|
||||
* @warning This macro may expand as a function call
|
||||
*/
|
||||
#define INV_MSG_LEVEL _INV_MSG_LEVEL
|
||||
|
||||
#if defined(INV_MSG_DISABLE)
|
||||
#define _INV_MSG(level, ...) (void)0
|
||||
#define _INV_MSG_SETUP(level, printer) (void)0
|
||||
#define _INV_MSG_SETUP_LEVEL(level) (void)0
|
||||
#define _INV_MSG_LEVEL INV_MSG_LEVEL_OFF
|
||||
#else
|
||||
#define _INV_MSG(level, ...) inv_msg(level, __VA_ARGS__)
|
||||
#define _INV_MSG_SETUP(level, printer) inv_msg_setup(level, printer)
|
||||
#define _INV_MSG_SETUP_LEVEL(level) inv_msg_setup(level, inv_msg_printer_default)
|
||||
#define _INV_MSG_SETUP_DEFAULT() inv_msg_setup_default()
|
||||
#define _INV_MSG_LEVEL inv_msg_get_level()
|
||||
#endif
|
||||
|
||||
/** @brief message level definition
|
||||
*/
|
||||
enum inv_msg_level {
|
||||
INV_MSG_LEVEL_OFF = 0,
|
||||
INV_MSG_LEVEL_ERROR,
|
||||
INV_MSG_LEVEL_WARNING,
|
||||
INV_MSG_LEVEL_INFO,
|
||||
INV_MSG_LEVEL_VERBOSE,
|
||||
INV_MSG_LEVEL_DEBUG,
|
||||
INV_MSG_LEVEL_MAX
|
||||
};
|
||||
|
||||
|
||||
/** @brief Prototype for print routine function
|
||||
*/
|
||||
typedef void (*inv_msg_printer_t)(int level, const char * str, va_list ap);
|
||||
|
||||
|
||||
/** @brief Set message level and printer function
|
||||
* @param[in] level only message above level will be passed to printer function
|
||||
* @param[in] printer user provided function in charge printing message
|
||||
* @return none
|
||||
*/
|
||||
void INV_EXPORT inv_msg_setup(int level, inv_msg_printer_t printer);
|
||||
|
||||
|
||||
/** @brief Default printer function that display messages to stderr
|
||||
* Function uses stdio. Care must be taken on embeded platfrom.
|
||||
* Function does nothing with IAR compiler.
|
||||
* @return none
|
||||
*/
|
||||
void INV_EXPORT inv_msg_printer_default(int level, const char * str, va_list ap);
|
||||
|
||||
/** @brief Set message level
|
||||
* Default printer function will be used.
|
||||
* @param[in] level only message above level will be passed to printer function
|
||||
* @return none
|
||||
*/
|
||||
static inline void inv_msg_setup_level(int level)
|
||||
{
|
||||
inv_msg_setup(level, inv_msg_printer_default);
|
||||
}
|
||||
|
||||
|
||||
/** @brief Set default message level and printer
|
||||
* @return none
|
||||
*/
|
||||
static inline void inv_msg_setup_default(void)
|
||||
{
|
||||
inv_msg_setup(INV_MSG_LEVEL_INFO, inv_msg_printer_default);
|
||||
}
|
||||
|
||||
/** @brief Return current message level
|
||||
* @return current message level
|
||||
*/
|
||||
int INV_EXPORT inv_msg_get_level(void);
|
||||
|
||||
/** @brief Display a message (through means of printer function)
|
||||
* @param[in] level for the message
|
||||
* @param[in] str message string
|
||||
* @param[in] ... optional arguments
|
||||
* @return none
|
||||
*/
|
||||
void INV_EXPORT inv_msg(int level, const char * str, ...);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* INV_MESSAGE_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _ICM_42670_H_
|
||||
#define _ICM_42670_H_
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Init ICM-42670 IMU
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t icm42670_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get raw data from ICM-42670
|
||||
*
|
||||
* @param accData Pointer to accelerometer data
|
||||
* @param gyroData Pointor to gyroscope data
|
||||
* @param imu_chip_temperature Pointer to temperature data
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t icm42670_get_raw_data(AccDataPacket *accData,
|
||||
GyroDataPacket *gyroData,
|
||||
chip_temperature *imu_chip_temperature);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively Software is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
#ifndef _INV_ICM4N607_CONFIG_H_
|
||||
#define _INV_ICM4N607_CONFIG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
#define FIFO_WM_MODE_EN 0 //1:fifo mode 0:dri mode
|
||||
#define IS_HIGH_RES_MODE 0 // 1: FIFO high resolution mode (20bits data format); 0: 16 bits data format;
|
||||
#define SPI_MODE_EN 1 //1:spi 0:i2c
|
||||
|
||||
#define DATA_FORMAT_DPS_G 1 // output sensor data with unit in default accel: m/s2 gyro: rad/s
|
||||
|
||||
#define SUPPORT_FIFO_TS 1 // support fifo timestamp by default
|
||||
#define DMP_POWERSAVE_FF 0 // disable apex power save mode for apex freefall for better performance
|
||||
#define DMP_POWERSAVE_PEDO 1 // setting apex power save mode for apex pedometer by default
|
||||
|
||||
#define SUPPORT_DELAY_US 1 // 1: platform supports delay in us; 0: platform does not support delay in ms.
|
||||
|
||||
#define SENSOR_REG_DUMP 0 // register dump control
|
||||
#define SENSOR_LOG_LEVEL 3 //INV_LOG_LEVEL_INFO
|
||||
#define SENSOR_LOG_TS_ONLY 1 //only print log sensor data TS , FIFO Timestampe is only available in fifo mode
|
||||
|
||||
|
||||
#define SENSOR_DIRECTION 0 // 0~7 sensorConvert map index below
|
||||
/* { { 1, 1, 1}, {0, 1, 2} },
|
||||
{ { -1, 1, 1}, {1, 0, 2} },
|
||||
{ { -1, -1, 1}, {0, 1, 2} },
|
||||
{ { 1, -1, 1}, {1, 0, 2} },
|
||||
{ { -1, 1, -1}, {0, 1, 2} },
|
||||
{ { 1, 1, -1}, {1, 0, 2} },
|
||||
{ { 1, -1, -1}, {0, 1, 2} },
|
||||
{ { -1, -1, -1}, {1, 0, 2} }, */
|
||||
|
||||
// For Xian the max FIFO size is 2048 Bytes; common FIFO package is 16 Bytes; so the max number of FIFO pakage is ~128.
|
||||
#define MAX_RECV_PACKET 128
|
||||
|
||||
|
||||
/* Initial WOM threshold to be applied to IMU in mg */
|
||||
#define WOM_THRESHOLD_INITIAL_MG 200
|
||||
|
||||
/* WOM threshold to be applied to IMU, ranges from 1 to 255, in 4mg unit */
|
||||
#define WOM_THRESHOLD WOM_THRESHOLD_INITIAL_MG/3
|
||||
#define WOM_THRESHOLD_X WOM_THRESHOLD
|
||||
#define WOM_THRESHOLD_Y WOM_THRESHOLD
|
||||
#define WOM_THRESHOLD_Z WOM_THRESHOLD
|
||||
|
||||
|
||||
#if 0
|
||||
/* customer board, need invoke system marco*/
|
||||
#define INV_LOG //define INV_LOG(loglevel,fmt,arg...) printf("ICM4n607: "fmt"\n",##arg)
|
||||
//#define INV_LOG(loglevel,fmt, args...) pr_err("INV icm4n607 "fmt"\n",##args)
|
||||
|
||||
//#define INV_MSG(loglevel,fmt, args...) pr_err("INV icm4n607 "fmt"\n",##args)
|
||||
#define EXIT(a) ;
|
||||
#else
|
||||
/* smart motion board*/
|
||||
#include "Message.h"
|
||||
#define INV_LOG INV_MSG
|
||||
#define EXIT(a) exit(a)
|
||||
#endif
|
||||
|
||||
/** @brief enumeration of serial interfaces available on IMU */
|
||||
typedef enum
|
||||
{
|
||||
UI_I2C,
|
||||
UI_SPI4,
|
||||
UI_SPI3
|
||||
} SERIAL_IF_TYPE_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,3 +0,0 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity test_utils icm42670)
|
||||
@@ -1,5 +0,0 @@
|
||||
#
|
||||
#Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
||||
@@ -1,273 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software? is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/* std */
|
||||
#include <stdio.h>
|
||||
|
||||
/* board driver */
|
||||
#include "common.h"
|
||||
#include "uart_mngr.h"
|
||||
#include "delay.h"
|
||||
#include "gpio.h"
|
||||
#include "timer.h"
|
||||
#include "system_interface.h"
|
||||
|
||||
/* InvenSense utils */
|
||||
#include "Invn/EmbUtils/Message.h"
|
||||
#include "Invn/EmbUtils/RingBuffer.h"
|
||||
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
/*
|
||||
* Select UART port on which INV_MSG() will be printed.
|
||||
*/
|
||||
#define LOG_UART_ID INV_UART_SENSOR_CTRL
|
||||
|
||||
/*
|
||||
* Define msg level
|
||||
*/
|
||||
#define MSG_LEVEL INV_MSG_LEVEL_DEBUG
|
||||
|
||||
/*
|
||||
* Set of timers used throughout standalone applications
|
||||
*/
|
||||
#define TIMEBASE_TIMER INV_TIMER1
|
||||
#define DELAY_TIMER INV_TIMER2
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Buffer to keep track of the timestamp when IMU data ready interrupt fires.
|
||||
* The buffer can contain up to 64 items in order to store one timestamp for each packet in FIFO.
|
||||
*/
|
||||
RINGBUFFER(timestamp_buffer, 64, uint64_t);
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Flag set from IMU device irq handler */
|
||||
static volatile int irq_from_device;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Forward declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static int setup_mcu();
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num);
|
||||
|
||||
void msg_printer(int level, const char * str, va_list ap);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definitions
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* This function initializes MCU on which this software is running.
|
||||
* It configures:
|
||||
* - a UART link used to print some messages
|
||||
* - interrupt priority group and GPIO so that MCU can receive interrupts from IMU
|
||||
* - a microsecond timer requested by IMU driver to compute some delay
|
||||
* - a microsecond timer used to get some timestamps
|
||||
* - a serial link to communicate from MCU to IMU
|
||||
*/
|
||||
static int setup_mcu()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
platform_io_hal_board_init();
|
||||
|
||||
/* configure UART */
|
||||
config_uart(LOG_UART_ID);
|
||||
|
||||
/* Setup message facility to see internal traces from FW */
|
||||
PLATFORM_MSG_SETUP(MSG_LEVEL, msg_printer);
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "# #XIAN MCU Driver V1.0 FF EXAMPLE #");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
|
||||
/*
|
||||
* Configure input capture mode GPIO connected to pin EXT3-9 (pin PB03).
|
||||
* This pin is connected to Icm406xx INT1 output and thus will receive interrupts
|
||||
* enabled on INT1 from the device.
|
||||
* A callback function is also passed that will be executed each time an interrupt
|
||||
* fires.
|
||||
*/
|
||||
platform_gpio_sensor_irq_init(INV_GPIO_INT1, ext_interrupt_cb, 0);
|
||||
|
||||
/* Init timer peripheral for delay */
|
||||
rc |= platform_delay_init(DELAY_TIMER);
|
||||
|
||||
/*
|
||||
* Configure the timer for the timebase
|
||||
*/
|
||||
rc |= platform_timer_configure_timebase(1000000);
|
||||
platform_timer_enable(TIMEBASE_TIMER);
|
||||
|
||||
inv_imu_set_serif(platform_io_hal_read_reg, platform_io_hal_write_reg);
|
||||
inv_imu_set_delay(platform_delay_ms,platform_delay_us); //void (*delay_ms)(uint32_t), void (*delay_us)(uint32_t))
|
||||
rc |= platform_io_hal_init();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMU interrupt handler.
|
||||
* Function is executed when an IMU interrupt rises on MCU.
|
||||
* This function get a timestamp and store it in the timestamp buffer.
|
||||
* Note that this function is executed in an interrupt handler and thus no protection
|
||||
* are implemented for shared variable timestamp_buffer.
|
||||
*/
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num)
|
||||
{
|
||||
(void)context;
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Read timestamp from the timer dedicated to timestamping
|
||||
*/
|
||||
uint64_t timestamp = platform_timer_get_counter(TIMEBASE_TIMER);
|
||||
|
||||
if(int_num == INV_GPIO_INT1) {
|
||||
if (!RINGBUFFER_FULL(×tamp_buffer))
|
||||
RINGBUFFER_PUSH(×tamp_buffer, ×tamp);
|
||||
}
|
||||
#endif
|
||||
|
||||
irq_from_device |= TO_MASK(int_num);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int setup_imu_device()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize IMU!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Main
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc = 0;
|
||||
bool ff_detect_result = false;
|
||||
float freefall_distance = 0.0f;
|
||||
|
||||
rc |= setup_mcu();
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize INV concise driver!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "IMU device successfully initialized");
|
||||
|
||||
rc = inv_imu_freefall_enable() ;
|
||||
|
||||
|
||||
if (rc != 0) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "freefall enable Failed. Do nothing %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
/* Poll device for data */
|
||||
if (irq_from_device & TO_MASK(INV_GPIO_INT1)) {
|
||||
|
||||
inv_disable_irq();
|
||||
|
||||
freefall_distance = inv_imu_freefall_get_event(&ff_detect_result);
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "ff result %d, cm %f",ff_detect_result,freefall_distance);
|
||||
|
||||
irq_from_device &= ~TO_MASK(INV_GPIO_INT1);
|
||||
inv_enable_irq();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == 30) {
|
||||
rc = inv_imu_freefall_disable();
|
||||
i++;
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Printer function for message facility
|
||||
*/
|
||||
void msg_printer(int level, const char * str, va_list ap)
|
||||
{
|
||||
static char out_str[256]; /* static to limit stack usage */
|
||||
unsigned idx = 0;
|
||||
const char * s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
"[E] ", // INV_MSG_LEVEL_ERROR
|
||||
"[W] ", // INV_MSG_LEVEL_WARNING
|
||||
"[I] ", // INV_MSG_LEVEL_INFO
|
||||
"[V] ", // INV_MSG_LEVEL_VERBOSE
|
||||
"[D] ", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "%s", s[level]);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += vsnprintf(&out_str[idx], sizeof(out_str) - idx, str, ap);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "\r\n");
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
|
||||
platform_uart_mngr_puts(LOG_UART_ID, out_str, idx);
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software? is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/* std */
|
||||
#include <stdio.h>
|
||||
|
||||
/* board driver */
|
||||
#include "common.h"
|
||||
#include "uart_mngr.h"
|
||||
#include "delay.h"
|
||||
#include "gpio.h"
|
||||
#include "timer.h"
|
||||
#include "system_interface.h"
|
||||
|
||||
/* InvenSense utils */
|
||||
#include "Invn/EmbUtils/Message.h"
|
||||
#include "Invn/EmbUtils/RingBuffer.h"
|
||||
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
/*
|
||||
* Select UART port on which INV_MSG() will be printed.
|
||||
*/
|
||||
#define LOG_UART_ID INV_UART_SENSOR_CTRL
|
||||
|
||||
/*
|
||||
* Define msg level
|
||||
*/
|
||||
#define MSG_LEVEL INV_MSG_LEVEL_DEBUG
|
||||
|
||||
/*
|
||||
* Set of timers used throughout standalone applications
|
||||
*/
|
||||
#define TIMEBASE_TIMER INV_TIMER1
|
||||
#define DELAY_TIMER INV_TIMER2
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Buffer to keep track of the timestamp when IMU data ready interrupt fires.
|
||||
* The buffer can contain up to 64 items in order to store one timestamp for each packet in FIFO.
|
||||
*/
|
||||
RINGBUFFER(timestamp_buffer, 64, uint64_t);
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Flag set from IMU device irq handler */
|
||||
static volatile int irq_from_device;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Forward declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static int setup_mcu();
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num);
|
||||
|
||||
void msg_printer(int level, const char * str, va_list ap);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definitions
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* This function initializes MCU on which this software is running.
|
||||
* It configures:
|
||||
* - a UART link used to print some messages
|
||||
* - interrupt priority group and GPIO so that MCU can receive interrupts from IMU
|
||||
* - a microsecond timer requested by IMU driver to compute some delay
|
||||
* - a microsecond timer used to get some timestamps
|
||||
* - a serial link to communicate from MCU to IMU
|
||||
*/
|
||||
static int setup_mcu()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
platform_io_hal_board_init();
|
||||
|
||||
/* configure UART */
|
||||
config_uart(LOG_UART_ID);
|
||||
|
||||
/* Setup message facility to see internal traces from FW */
|
||||
PLATFORM_MSG_SETUP(MSG_LEVEL, msg_printer);
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "# #XIAN MCU Driver V1.0 PEDO EXAMPLE#");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
|
||||
/*
|
||||
* Configure input capture mode GPIO connected to pin EXT3-9 (pin PB03).
|
||||
* This pin is connected to Icm406xx INT1 output and thus will receive interrupts
|
||||
* enabled on INT1 from the device.
|
||||
* A callback function is also passed that will be executed each time an interrupt
|
||||
* fires.
|
||||
*/
|
||||
platform_gpio_sensor_irq_init(INV_GPIO_INT1, ext_interrupt_cb, 0);
|
||||
|
||||
/* Init timer peripheral for delay */
|
||||
rc |= platform_delay_init(DELAY_TIMER);
|
||||
|
||||
/*
|
||||
* Configure the timer for the timebase
|
||||
*/
|
||||
rc |= platform_timer_configure_timebase(1000000);
|
||||
platform_timer_enable(TIMEBASE_TIMER);
|
||||
|
||||
inv_imu_set_serif(platform_io_hal_read_reg, platform_io_hal_write_reg);
|
||||
inv_imu_set_delay(platform_delay_ms,platform_delay_us); //void (*delay_ms)(uint32_t), void (*delay_us)(uint32_t))
|
||||
rc |= platform_io_hal_init();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMU interrupt handler.
|
||||
* Function is executed when an IMU interrupt rises on MCU.
|
||||
* This function get a timestamp and store it in the timestamp buffer.
|
||||
* Note that this function is executed in an interrupt handler and thus no protection
|
||||
* are implemented for shared variable timestamp_buffer.
|
||||
*/
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num)
|
||||
{
|
||||
(void)context;
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Read timestamp from the timer dedicated to timestamping
|
||||
*/
|
||||
uint64_t timestamp = platform_timer_get_counter(TIMEBASE_TIMER);
|
||||
|
||||
if(int_num == INV_GPIO_INT1) {
|
||||
if (!RINGBUFFER_FULL(×tamp_buffer))
|
||||
RINGBUFFER_PUSH(×tamp_buffer, ×tamp);
|
||||
}
|
||||
#endif
|
||||
|
||||
irq_from_device |= TO_MASK(int_num);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int setup_imu_device()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize IMU!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Main
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc = 0;
|
||||
APEX_DATA3_ACTIVITY_CLASS_t activity_class;
|
||||
float cadence_step_per_sec;
|
||||
int step_result = 0;
|
||||
|
||||
rc |= setup_mcu();
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize INV concise driver!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "IMU device successfully initialized");
|
||||
|
||||
rc = inv_imu_pedometer_enable() ;
|
||||
|
||||
if (rc != 0) {
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "pedometer enable Failed. Do nothing %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
/* Poll device for data */
|
||||
if (irq_from_device & TO_MASK(INV_GPIO_INT1)) {
|
||||
|
||||
inv_disable_irq();
|
||||
|
||||
step_result = inv_imu_pedometer_get_event(&cadence_step_per_sec,&activity_class);
|
||||
|
||||
if(step_result < 0)
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "pedometer get event failure %d",step_result);
|
||||
else
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "step value %d, %.2f steps/sec, type %d",step_result,cadence_step_per_sec,activity_class);
|
||||
|
||||
irq_from_device &= ~TO_MASK(INV_GPIO_INT1);
|
||||
inv_enable_irq();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == 100) {
|
||||
rc = inv_imu_pedometer_disable();
|
||||
i++;
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Printer function for message facility
|
||||
*/
|
||||
void msg_printer(int level, const char * str, va_list ap)
|
||||
{
|
||||
static char out_str[256]; /* static to limit stack usage */
|
||||
unsigned idx = 0;
|
||||
const char * s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
"[E] ", // INV_MSG_LEVEL_ERROR
|
||||
"[W] ", // INV_MSG_LEVEL_WARNING
|
||||
"[I] ", // INV_MSG_LEVEL_INFO
|
||||
"[V] ", // INV_MSG_LEVEL_VERBOSE
|
||||
"[D] ", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "%s", s[level]);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += vsnprintf(&out_str[idx], sizeof(out_str) - idx, str, ap);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "\r\n");
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
|
||||
platform_uart_mngr_puts(LOG_UART_ID, out_str, idx);
|
||||
}
|
||||
@@ -1,396 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software? is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/* std */
|
||||
#include <stdio.h>
|
||||
|
||||
/* board driver */
|
||||
#include "common.h"
|
||||
#include "uart_mngr.h"
|
||||
#include "delay.h"
|
||||
#include "gpio.h"
|
||||
#include "timer.h"
|
||||
#include "system_interface.h"
|
||||
|
||||
/* InvenSense utils */
|
||||
#include "Invn/EmbUtils/Message.h"
|
||||
#include "Invn/EmbUtils/RingBuffer.h"
|
||||
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
|
||||
struct SensorData Acc_Receive_dataBuff[2048];
|
||||
struct SensorData Gyro_Receive_dataBuff[2048];
|
||||
|
||||
|
||||
AccDataPacket accData;
|
||||
GyroDataPacket gyroData;
|
||||
chip_temperature imu_chip_temperature;
|
||||
|
||||
uint32_t cur_index = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Select UART port on which INV_MSG() will be printed.
|
||||
*/
|
||||
#define LOG_UART_ID INV_UART_SENSOR_CTRL
|
||||
|
||||
/*
|
||||
* Define msg level
|
||||
*/
|
||||
#define MSG_LEVEL INV_MSG_LEVEL_DEBUG
|
||||
|
||||
/*
|
||||
* Set of timers used throughout standalone applications
|
||||
*/
|
||||
#define TIMEBASE_TIMER INV_TIMER1
|
||||
#define DELAY_TIMER INV_TIMER2
|
||||
|
||||
#define SENSOR_ODR_1600HZ 1600
|
||||
#define SENSOR_ODR_800HZ 800
|
||||
#define SENSOR_ODR_400HZ 400
|
||||
#define SENSOR_ODR_200HZ 200
|
||||
#define SENSOR_ODR_100HZ 100
|
||||
#define SENSOR_ODR_50HZ 50
|
||||
#define SENSOR_ODR_25HZ 25
|
||||
#define SENSOR_ODR_12_5HZ 12.5
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Buffer to keep track of the timestamp when IMU data ready interrupt fires.
|
||||
* The buffer can contain up to 64 items in order to store one timestamp for each packet in FIFO.
|
||||
*/
|
||||
RINGBUFFER(timestamp_buffer, 64, uint64_t);
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Flag set from IMU device irq handler */
|
||||
static volatile int irq_from_device;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Forward declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static int setup_mcu();
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num);
|
||||
|
||||
void msg_printer(int level, const char * str, va_list ap);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definitions
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* This function initializes MCU on which this software is running.
|
||||
* It configures:
|
||||
* - a UART link used to print some messages
|
||||
* - interrupt priority group and GPIO so that MCU can receive interrupts from IMU
|
||||
* - a microsecond timer requested by IMU driver to compute some delay
|
||||
* - a microsecond timer used to get some timestamps
|
||||
* - a serial link to communicate from MCU to IMU
|
||||
*/
|
||||
static int setup_mcu()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
platform_io_hal_board_init();
|
||||
|
||||
/* configure UART */
|
||||
config_uart(LOG_UART_ID);
|
||||
|
||||
/* Setup message facility to see internal traces from FW */
|
||||
PLATFORM_MSG_SETUP(MSG_LEVEL, msg_printer);
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "# Example Raw AG #");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################");
|
||||
|
||||
/*
|
||||
* Configure input capture mode GPIO connected to pin EXT3-9 (pin PB03).
|
||||
* This pin is connected to Icm406xx INT1 output and thus will receive interrupts
|
||||
* enabled on INT1 from the device.
|
||||
* A callback function is also passed that will be executed each time an interrupt
|
||||
* fires.
|
||||
*/
|
||||
platform_gpio_sensor_irq_init(INV_GPIO_INT1, ext_interrupt_cb, 0);
|
||||
|
||||
/* Init timer peripheral for delay */
|
||||
rc |= platform_delay_init(DELAY_TIMER);
|
||||
|
||||
/*
|
||||
* Configure the timer for the timebase
|
||||
*/
|
||||
rc |= platform_timer_configure_timebase(1000000);
|
||||
platform_timer_enable(TIMEBASE_TIMER);
|
||||
|
||||
inv_imu_set_serif(platform_io_hal_read_reg, platform_io_hal_write_reg);
|
||||
inv_imu_set_delay(platform_delay_ms,platform_delay_us); //void (*delay_ms)(uint32_t), void (*delay_us)(uint32_t))
|
||||
rc |= platform_io_hal_init();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMU interrupt handler.
|
||||
* Function is executed when an IMU interrupt rises on MCU.
|
||||
* This function get a timestamp and store it in the timestamp buffer.
|
||||
* Note that this function is executed in an interrupt handler and thus no protection
|
||||
* are implemented for shared variable timestamp_buffer.
|
||||
*/
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num)
|
||||
{
|
||||
(void)context;
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Read timestamp from the timer dedicated to timestamping
|
||||
*/
|
||||
uint64_t timestamp = platform_timer_get_counter(TIMEBASE_TIMER);
|
||||
|
||||
if(int_num == INV_GPIO_INT1) {
|
||||
if (!RINGBUFFER_FULL(×tamp_buffer))
|
||||
RINGBUFFER_PUSH(×tamp_buffer, ×tamp);
|
||||
}
|
||||
#endif
|
||||
|
||||
irq_from_device |= TO_MASK(int_num);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int setup_imu_device()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize IMU!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
uint32_t get_imu_data()
|
||||
{
|
||||
inv_data_handler(&accData,&gyroData,&imu_chip_temperature,false);
|
||||
if(accData.accDataSize != 0){
|
||||
memcpy(&Acc_Receive_dataBuff[cur_index], &accData.databuff[0], accData.accDataSize * sizeof(accData.databuff[0]));
|
||||
//INV_MSG(INV_MSG_LEVEL_ERROR, "acDS %u cidex %u",accData.accDataSize,cur_index);
|
||||
}
|
||||
|
||||
if(gyroData.gyroDataSize != 0){
|
||||
memcpy(&Gyro_Receive_dataBuff[cur_index], &gyroData.databuff[0], gyroData.gyroDataSize * sizeof(gyroData.databuff[0]));
|
||||
}
|
||||
|
||||
if ((accData.accDataSize != 0) && (gyroData.gyroDataSize != 0))
|
||||
cur_index = cur_index + (uint32_t)accData.accDataSize;
|
||||
else if(accData.accDataSize != 0)
|
||||
cur_index = cur_index + (uint32_t)accData.accDataSize;
|
||||
else if(gyroData.gyroDataSize != 0)
|
||||
cur_index = cur_index + (uint32_t)gyroData.gyroDataSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Main
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc = 0;
|
||||
float hw_rate = 0.0;
|
||||
|
||||
memset(Acc_Receive_dataBuff,0,sizeof(Acc_Receive_dataBuff));
|
||||
memset(Gyro_Receive_dataBuff,0,sizeof(Gyro_Receive_dataBuff));
|
||||
rc |= setup_mcu();
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize INV concise driver!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "IMU device successfully initialized");
|
||||
|
||||
// We may customize full scale range here.
|
||||
rc |= inv_imu_set_accel_fsr(ACCEL_CONFIG0_FS_SEL_4g);
|
||||
rc |= inv_imu_set_gyro_fsr(GYRO_CONFIG0_FS_SEL_2000dps);
|
||||
|
||||
// Below settings are required to configure and enable sensors.
|
||||
rc |= inv_imu_acc_enable();
|
||||
rc |= inv_imu_acc_set_rate(SENSOR_ODR_400HZ, 2,&hw_rate); //200Hz ODR, watermark: 2 packets.
|
||||
rc |= inv_imu_gyro_enable();
|
||||
rc |= inv_imu_gyro_set_rate(SENSOR_ODR_400HZ, 4,&hw_rate); //50Hz ODR, watermark 4.
|
||||
|
||||
if (rc != 0) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Feature enable Failed. Do nothing %d", rc);
|
||||
return rc;
|
||||
}
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "HW odr setting %f ", hw_rate);
|
||||
|
||||
do {
|
||||
|
||||
/* Poll device for data */
|
||||
if (irq_from_device & TO_MASK(INV_GPIO_INT1)) {
|
||||
|
||||
get_imu_data();
|
||||
//INV_MSG(INV_MSG_LEVEL_ERROR, "cur idex %lu!",cur_index);
|
||||
|
||||
inv_disable_irq();
|
||||
irq_from_device &= ~TO_MASK(INV_GPIO_INT1);
|
||||
inv_enable_irq();
|
||||
|
||||
}
|
||||
} while(cur_index <2048);
|
||||
|
||||
rc |= inv_imu_acc_disable();
|
||||
rc |= inv_imu_gyro_disable();
|
||||
|
||||
#if SENSOR_LOG_TS_ONLY
|
||||
uint32_t i;
|
||||
for(i=0;i< cur_index; i++){
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "ACC %d TS %lld ", i+1,Acc_Receive_dataBuff[i].timeStamp);
|
||||
platform_delay_ms(5);
|
||||
}
|
||||
|
||||
for(i=0;i< cur_index; i++){
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Gyro %d TS %lld ", i+1,Gyro_Receive_dataBuff[i].timeStamp);
|
||||
platform_delay_ms(5);
|
||||
}
|
||||
#endif
|
||||
|
||||
// following code is just repeating the previous code, just to confirm the testing could be alwasys run
|
||||
int j = 2;
|
||||
while(1){
|
||||
|
||||
memset(Acc_Receive_dataBuff,0,sizeof(Acc_Receive_dataBuff));
|
||||
memset(Gyro_Receive_dataBuff,0,sizeof(Gyro_Receive_dataBuff));
|
||||
|
||||
memset(&accData,0,sizeof(accData));
|
||||
memset(&gyroData,0,sizeof(gyroData));
|
||||
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "repeating test round %d", j);
|
||||
// Below settings are required to configure and enable sensors.
|
||||
rc |= inv_imu_acc_enable();
|
||||
rc |= inv_imu_acc_set_rate(SENSOR_ODR_200HZ, 2,&hw_rate); //200Hz ODR, watermark: 2 packets.
|
||||
rc |= inv_imu_gyro_enable();
|
||||
rc |= inv_imu_gyro_set_rate(SENSOR_ODR_200HZ, 4,&hw_rate); //50Hz ODR, watermark 4.
|
||||
|
||||
if (rc != 0) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Feature enable Failed. Do nothing %d", rc);
|
||||
return rc;
|
||||
}
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "HW odr setting %f ", hw_rate);
|
||||
|
||||
|
||||
cur_index = 0;
|
||||
do {
|
||||
|
||||
/* Poll device for data */
|
||||
if (irq_from_device & TO_MASK(INV_GPIO_INT1)) {
|
||||
|
||||
get_imu_data();
|
||||
//INV_MSG(INV_MSG_LEVEL_ERROR, "cur idex %lu!",cur_index);
|
||||
|
||||
inv_disable_irq();
|
||||
irq_from_device &= ~TO_MASK(INV_GPIO_INT1);
|
||||
inv_enable_irq();
|
||||
|
||||
}
|
||||
} while(cur_index <2048);
|
||||
|
||||
rc |= inv_imu_acc_disable();
|
||||
rc |= inv_imu_gyro_disable();
|
||||
|
||||
#if SENSOR_LOG_TS_ONLY
|
||||
|
||||
for(i=0;i< cur_index; i++){
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "ACC %d TS %lld ", i+1,Acc_Receive_dataBuff[i].timeStamp);
|
||||
platform_delay_ms(5);
|
||||
}
|
||||
|
||||
for(i=0;i< cur_index; i++){
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Gyro %d TS %lld ", i+1,Gyro_Receive_dataBuff[i].timeStamp);
|
||||
platform_delay_ms(5);
|
||||
}
|
||||
#endif
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Printer function for message facility
|
||||
*/
|
||||
void msg_printer(int level, const char * str, va_list ap)
|
||||
{
|
||||
static char out_str[256]; /* static to limit stack usage */
|
||||
unsigned idx = 0;
|
||||
const char * s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
"[E] ", // INV_MSG_LEVEL_ERROR
|
||||
"[W] ", // INV_MSG_LEVEL_WARNING
|
||||
"[I] ", // INV_MSG_LEVEL_INFO
|
||||
"[V] ", // INV_MSG_LEVEL_VERBOSE
|
||||
"[D] ", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "%s", s[level]);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += vsnprintf(&out_str[idx], sizeof(out_str) - idx, str, ap);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "\r\n");
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
|
||||
platform_uart_mngr_puts(LOG_UART_ID, out_str, idx);
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software? is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/* std */
|
||||
#include <stdio.h>
|
||||
|
||||
/* board driver */
|
||||
#include "common.h"
|
||||
#include "uart_mngr.h"
|
||||
#include "delay.h"
|
||||
#include "gpio.h"
|
||||
#include "timer.h"
|
||||
#include "system_interface.h"
|
||||
|
||||
/* InvenSense utils */
|
||||
#include "Invn/EmbUtils/Message.h"
|
||||
#include "Invn/EmbUtils/RingBuffer.h"
|
||||
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
/*
|
||||
* Select UART port on which INV_MSG() will be printed.
|
||||
*/
|
||||
#define LOG_UART_ID INV_UART_SENSOR_CTRL
|
||||
|
||||
/*
|
||||
* Define msg level
|
||||
*/
|
||||
#define MSG_LEVEL INV_MSG_LEVEL_DEBUG
|
||||
|
||||
/*
|
||||
* Set of timers used throughout standalone applications
|
||||
*/
|
||||
#define TIMEBASE_TIMER INV_TIMER1
|
||||
#define DELAY_TIMER INV_TIMER2
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Buffer to keep track of the timestamp when IMU data ready interrupt fires.
|
||||
* The buffer can contain up to 64 items in order to store one timestamp for each packet in FIFO.
|
||||
*/
|
||||
RINGBUFFER(timestamp_buffer, 64, uint64_t);
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Flag set from IMU device irq handler */
|
||||
static volatile int irq_from_device;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Forward declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static int setup_mcu();
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num);
|
||||
|
||||
void msg_printer(int level, const char * str, va_list ap);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definitions
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* This function initializes MCU on which this software is running.
|
||||
* It configures:
|
||||
* - a UART link used to print some messages
|
||||
* - interrupt priority group and GPIO so that MCU can receive interrupts from IMU
|
||||
* - a microsecond timer requested by IMU driver to compute some delay
|
||||
* - a microsecond timer used to get some timestamps
|
||||
* - a serial link to communicate from MCU to IMU
|
||||
*/
|
||||
static int setup_mcu()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
platform_io_hal_board_init();
|
||||
|
||||
/* configure UART */
|
||||
config_uart(LOG_UART_ID);
|
||||
|
||||
/* Setup message facility to see internal traces from FW */
|
||||
PLATFORM_MSG_SETUP(MSG_LEVEL, msg_printer);
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "# #XIAN MCU Driver V1.0 SELFTEST EX #");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
|
||||
/*
|
||||
* Configure input capture mode GPIO connected to pin EXT3-9 (pin PB03).
|
||||
* This pin is connected to Icm406xx INT1 output and thus will receive interrupts
|
||||
* enabled on INT1 from the device.
|
||||
* A callback function is also passed that will be executed each time an interrupt
|
||||
* fires.
|
||||
*/
|
||||
platform_gpio_sensor_irq_init(INV_GPIO_INT1, ext_interrupt_cb, 0);
|
||||
|
||||
/* Init timer peripheral for delay */
|
||||
rc |= platform_delay_init(DELAY_TIMER);
|
||||
|
||||
/*
|
||||
* Configure the timer for the timebase
|
||||
*/
|
||||
rc |= platform_timer_configure_timebase(1000000);
|
||||
platform_timer_enable(TIMEBASE_TIMER);
|
||||
|
||||
inv_imu_set_serif(platform_io_hal_read_reg, platform_io_hal_write_reg);
|
||||
inv_imu_set_delay(platform_delay_ms,platform_delay_us); //void (*delay_ms)(uint32_t), void (*delay_us)(uint32_t))
|
||||
rc |= platform_io_hal_init();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMU interrupt handler.
|
||||
* Function is executed when an IMU interrupt rises on MCU.
|
||||
* This function get a timestamp and store it in the timestamp buffer.
|
||||
* Note that this function is executed in an interrupt handler and thus no protection
|
||||
* are implemented for shared variable timestamp_buffer.
|
||||
*/
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num)
|
||||
{
|
||||
(void)context;
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Read timestamp from the timer dedicated to timestamping
|
||||
*/
|
||||
uint64_t timestamp = platform_timer_get_counter(TIMEBASE_TIMER);
|
||||
|
||||
if(int_num == INV_GPIO_INT1) {
|
||||
if (!RINGBUFFER_FULL(×tamp_buffer))
|
||||
RINGBUFFER_PUSH(×tamp_buffer, ×tamp);
|
||||
}
|
||||
#endif
|
||||
|
||||
irq_from_device |= TO_MASK(int_num);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int setup_imu_device()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize IMU!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Main
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc = 0;
|
||||
uint8_t acc_control = 1;
|
||||
uint8_t gyro_control = 1;
|
||||
|
||||
struct inv_imu_selftest_output selftest_result;
|
||||
|
||||
rc |= setup_mcu();
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize INV concise driver!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "IMU device successfully initialized");
|
||||
|
||||
rc |= inv_imu_run_selftest(acc_control,gyro_control, &selftest_result);
|
||||
|
||||
if (rc != 0) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "selftest run failure. Do nothing %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (selftest_result.accel_status == 0x1)
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "accel Selftest PASS\n");
|
||||
else
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "accel Selftest fail\n");
|
||||
|
||||
if (selftest_result.gyro_status == 0x1)
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "gyro Selftest PASS\n");
|
||||
else
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "gyro Selftest fail\n");
|
||||
|
||||
|
||||
do {
|
||||
|
||||
} while(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Printer function for message facility
|
||||
*/
|
||||
void msg_printer(int level, const char * str, va_list ap)
|
||||
{
|
||||
static char out_str[256]; /* static to limit stack usage */
|
||||
unsigned idx = 0;
|
||||
const char * s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
"[E] ", // INV_MSG_LEVEL_ERROR
|
||||
"[W] ", // INV_MSG_LEVEL_WARNING
|
||||
"[I] ", // INV_MSG_LEVEL_INFO
|
||||
"[V] ", // INV_MSG_LEVEL_VERBOSE
|
||||
"[D] ", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "%s", s[level]);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += vsnprintf(&out_str[idx], sizeof(out_str) - idx, str, ap);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "\r\n");
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
|
||||
platform_uart_mngr_puts(LOG_UART_ID, out_str, idx);
|
||||
}
|
||||
@@ -1,273 +0,0 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software? is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/* std */
|
||||
#include <stdio.h>
|
||||
|
||||
/* board driver */
|
||||
#include "common.h"
|
||||
#include "uart_mngr.h"
|
||||
#include "delay.h"
|
||||
#include "gpio.h"
|
||||
#include "timer.h"
|
||||
#include "system_interface.h"
|
||||
|
||||
/* InvenSense utils */
|
||||
#include "Invn/EmbUtils/Message.h"
|
||||
#include "Invn/EmbUtils/RingBuffer.h"
|
||||
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
|
||||
/*
|
||||
* Select UART port on which INV_MSG() will be printed.
|
||||
*/
|
||||
#define LOG_UART_ID INV_UART_SENSOR_CTRL
|
||||
|
||||
/*
|
||||
* Define msg level
|
||||
*/
|
||||
#define MSG_LEVEL INV_MSG_LEVEL_DEBUG
|
||||
|
||||
/*
|
||||
* Set of timers used throughout standalone applications
|
||||
*/
|
||||
#define TIMEBASE_TIMER INV_TIMER1
|
||||
#define DELAY_TIMER INV_TIMER2
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Buffer to keep track of the timestamp when IMU data ready interrupt fires.
|
||||
* The buffer can contain up to 64 items in order to store one timestamp for each packet in FIFO.
|
||||
*/
|
||||
RINGBUFFER(timestamp_buffer, 64, uint64_t);
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Flag set from IMU device irq handler */
|
||||
static volatile int irq_from_device;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Forward declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static int setup_mcu();
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num);
|
||||
|
||||
void msg_printer(int level, const char * str, va_list ap);
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definitions
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* This function initializes MCU on which this software is running.
|
||||
* It configures:
|
||||
* - a UART link used to print some messages
|
||||
* - interrupt priority group and GPIO so that MCU can receive interrupts from IMU
|
||||
* - a microsecond timer requested by IMU driver to compute some delay
|
||||
* - a microsecond timer used to get some timestamps
|
||||
* - a serial link to communicate from MCU to IMU
|
||||
*/
|
||||
static int setup_mcu()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
platform_io_hal_board_init();
|
||||
|
||||
/* configure UART */
|
||||
config_uart(LOG_UART_ID);
|
||||
|
||||
/* Setup message facility to see internal traces from FW */
|
||||
PLATFORM_MSG_SETUP(MSG_LEVEL, msg_printer);
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "# #XIAN MCU Driver V1.0 WOM EXAMPLE #");
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "######################################");
|
||||
|
||||
/*
|
||||
* Configure input capture mode GPIO connected to pin EXT3-9 (pin PB03).
|
||||
* This pin is connected to Icm406xx INT1 output and thus will receive interrupts
|
||||
* enabled on INT1 from the device.
|
||||
* A callback function is also passed that will be executed each time an interrupt
|
||||
* fires.
|
||||
*/
|
||||
platform_gpio_sensor_irq_init(INV_GPIO_INT1, ext_interrupt_cb, 0);
|
||||
|
||||
/* Init timer peripheral for delay */
|
||||
rc |= platform_delay_init(DELAY_TIMER);
|
||||
|
||||
/*
|
||||
* Configure the timer for the timebase
|
||||
*/
|
||||
rc |= platform_timer_configure_timebase(1000000);
|
||||
platform_timer_enable(TIMEBASE_TIMER);
|
||||
|
||||
inv_imu_set_serif(platform_io_hal_read_reg, platform_io_hal_write_reg);
|
||||
inv_imu_set_delay(platform_delay_ms,platform_delay_us); //void (*delay_ms)(uint32_t), void (*delay_us)(uint32_t))
|
||||
rc |= platform_io_hal_init();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMU interrupt handler.
|
||||
* Function is executed when an IMU interrupt rises on MCU.
|
||||
* This function get a timestamp and store it in the timestamp buffer.
|
||||
* Note that this function is executed in an interrupt handler and thus no protection
|
||||
* are implemented for shared variable timestamp_buffer.
|
||||
*/
|
||||
static void ext_interrupt_cb(void * context, unsigned int int_num)
|
||||
{
|
||||
(void)context;
|
||||
|
||||
#if !USE_FIFO
|
||||
/*
|
||||
* Read timestamp from the timer dedicated to timestamping
|
||||
*/
|
||||
uint64_t timestamp = platform_timer_get_counter(TIMEBASE_TIMER);
|
||||
|
||||
if(int_num == INV_GPIO_INT1) {
|
||||
if (!RINGBUFFER_FULL(×tamp_buffer))
|
||||
RINGBUFFER_PUSH(×tamp_buffer, ×tamp);
|
||||
}
|
||||
#endif
|
||||
|
||||
irq_from_device |= TO_MASK(int_num);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int setup_imu_device()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize IMU!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Main
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc = 0;
|
||||
bool wom_detect_result = false;
|
||||
int wom_flag;
|
||||
|
||||
rc |= setup_mcu();
|
||||
|
||||
|
||||
#if !USE_FIFO
|
||||
RINGBUFFER_CLEAR(×tamp_buffer);
|
||||
#endif
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_initialize();
|
||||
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
INV_MSG(INV_MSG_LEVEL_ERROR, "Failed to initialize INV concise driver!");
|
||||
return rc;
|
||||
}
|
||||
|
||||
INV_MSG(INV_MSG_LEVEL_INFO, "IMU device successfully initialized");
|
||||
|
||||
rc += inv_imu_wom_enable(WOM_THRESHOLD_X,WOM_THRESHOLD_Y,WOM_THRESHOLD_Z,WOM_CONFIG_WOM_INT_DUR_4_SMPL);
|
||||
|
||||
|
||||
if (rc != 0) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Feature enable Failed. Do nothing %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
/* Poll device for data */
|
||||
if (irq_from_device & TO_MASK(INV_GPIO_INT1)) {
|
||||
|
||||
inv_disable_irq();
|
||||
|
||||
wom_flag = inv_imu_wom_get_event(&wom_detect_result);
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "wom result %d, flag %x",wom_detect_result,wom_flag);
|
||||
|
||||
irq_from_device &= ~TO_MASK(INV_GPIO_INT1);
|
||||
inv_enable_irq();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == 20) {
|
||||
rc = inv_imu_wom_disable();
|
||||
i++;
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Printer function for message facility
|
||||
*/
|
||||
void msg_printer(int level, const char * str, va_list ap)
|
||||
{
|
||||
static char out_str[256]; /* static to limit stack usage */
|
||||
unsigned idx = 0;
|
||||
const char * s[INV_MSG_LEVEL_MAX] = {
|
||||
"", // INV_MSG_LEVEL_OFF
|
||||
"[E] ", // INV_MSG_LEVEL_ERROR
|
||||
"[W] ", // INV_MSG_LEVEL_WARNING
|
||||
"[I] ", // INV_MSG_LEVEL_INFO
|
||||
"[V] ", // INV_MSG_LEVEL_VERBOSE
|
||||
"[D] ", // INV_MSG_LEVEL_DEBUG
|
||||
};
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "%s", s[level]);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += vsnprintf(&out_str[idx], sizeof(out_str) - idx, str, ap);
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
idx += snprintf(&out_str[idx], sizeof(out_str) - idx, "\r\n");
|
||||
if(idx >= (sizeof(out_str)))
|
||||
return;
|
||||
|
||||
platform_uart_mngr_puts(LOG_UART_ID, out_str, idx);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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 "stdio.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/timers.h"
|
||||
#include "esp_log.h"
|
||||
#include "unity.h"
|
||||
#include "icm42670.h"
|
||||
|
||||
static const char *TAG = "IMU TEST";
|
||||
|
||||
|
||||
static void icm42670_test(void *args)
|
||||
{
|
||||
AccDataPacket accData;
|
||||
GyroDataPacket gyroData;
|
||||
chip_temperature imu_chip_temperature;
|
||||
|
||||
icm42670_init();
|
||||
while (1) {
|
||||
int ret = icm42670_get_raw_data(&accData, &gyroData, &imu_chip_temperature);
|
||||
if (0 == ret) {
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "temperature=%.1f", imu_chip_temperature);
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "ACC %d (%.1f, %.1f, %.1f)", accData.accDataSize, accData.databuff[0].x, accData.databuff[0].y, accData.databuff[0].z);
|
||||
INV_LOG(SENSOR_LOG_LEVEL, "Gyro%d (%.1f, %.1f, %.1f)", gyroData.gyroDataSize, gyroData.databuff[0].x, gyroData.databuff[0].y, gyroData.databuff[0].z);
|
||||
} else {
|
||||
INV_LOG(INV_LOG_LEVEL_ERROR, "read err");
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ICM42670 test", "[imu][box]")
|
||||
{
|
||||
icm42670_test(NULL);
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "bsp_i2c.h"
|
||||
#include "ft5x06.h"
|
||||
|
||||
/** @brief FT5x06 register map and function codes */
|
||||
#define FT5x06_ADDR (0x38)
|
||||
|
||||
#define FT5x06_DEVICE_MODE (0x00)
|
||||
#define FT5x06_GESTURE_ID (0x01)
|
||||
#define FT5x06_TOUCH_POINTS (0x02)
|
||||
|
||||
#define FT5x06_TOUCH1_EV_FLAG (0x03)
|
||||
#define FT5x06_TOUCH1_XH (0x03)
|
||||
#define FT5x06_TOUCH1_XL (0x04)
|
||||
#define FT5x06_TOUCH1_YH (0x05)
|
||||
#define FT5x06_TOUCH1_YL (0x06)
|
||||
|
||||
#define FT5x06_TOUCH2_EV_FLAG (0x09)
|
||||
#define FT5x06_TOUCH2_XH (0x09)
|
||||
#define FT5x06_TOUCH2_XL (0x0A)
|
||||
#define FT5x06_TOUCH2_YH (0x0B)
|
||||
#define FT5x06_TOUCH2_YL (0x0C)
|
||||
|
||||
#define FT5x06_TOUCH3_EV_FLAG (0x0F)
|
||||
#define FT5x06_TOUCH3_XH (0x0F)
|
||||
#define FT5x06_TOUCH3_XL (0x10)
|
||||
#define FT5x06_TOUCH3_YH (0x11)
|
||||
#define FT5x06_TOUCH3_YL (0x12)
|
||||
|
||||
#define FT5x06_TOUCH4_EV_FLAG (0x15)
|
||||
#define FT5x06_TOUCH4_XH (0x15)
|
||||
#define FT5x06_TOUCH4_XL (0x16)
|
||||
#define FT5x06_TOUCH4_YH (0x17)
|
||||
#define FT5x06_TOUCH4_YL (0x18)
|
||||
|
||||
#define FT5x06_TOUCH5_EV_FLAG (0x1B)
|
||||
#define FT5x06_TOUCH5_XH (0x1B)
|
||||
#define FT5x06_TOUCH5_XL (0x1C)
|
||||
#define FT5x06_TOUCH5_YH (0x1D)
|
||||
#define FT5x06_TOUCH5_YL (0x1E)
|
||||
|
||||
#define FT5x06_ID_G_THGROUP (0x80)
|
||||
#define FT5x06_ID_G_THPEAK (0x81)
|
||||
#define FT5x06_ID_G_THCAL (0x82)
|
||||
#define FT5x06_ID_G_THWATER (0x83)
|
||||
#define FT5x06_ID_G_THTEMP (0x84)
|
||||
#define FT5x06_ID_G_THDIFF (0x85)
|
||||
#define FT5x06_ID_G_CTRL (0x86)
|
||||
#define FT5x06_ID_G_TIME_ENTER_MONITOR (0x87)
|
||||
#define FT5x06_ID_G_PERIODACTIVE (0x88)
|
||||
#define FT5x06_ID_G_PERIODMONITOR (0x89)
|
||||
#define FT5x06_ID_G_AUTO_CLB_MODE (0xA0)
|
||||
#define FT5x06_ID_G_LIB_VERSION_H (0xA1)
|
||||
#define FT5x06_ID_G_LIB_VERSION_L (0xA2)
|
||||
#define FT5x06_ID_G_CIPHER (0xA3)
|
||||
#define FT5x06_ID_G_MODE (0xA4)
|
||||
#define FT5x06_ID_G_PMODE (0xA5)
|
||||
#define FT5x06_ID_G_FIRMID (0xA6)
|
||||
#define FT5x06_ID_G_STATE (0xA7)
|
||||
#define FT5x06_ID_G_FT5201ID (0xA8)
|
||||
#define FT5x06_ID_G_ERR (0xA9)
|
||||
|
||||
static i2c_bus_device_handle_t ft5x06_handle = NULL;
|
||||
|
||||
static inline esp_err_t ft5x06_read_byte(uint8_t reg_addr, uint8_t *data)
|
||||
{
|
||||
return i2c_bus_read_byte(ft5x06_handle, reg_addr, data);
|
||||
}
|
||||
|
||||
static inline esp_err_t ft5x06_read_bytes(uint8_t reg_addr, size_t data_len, uint8_t *data)
|
||||
{
|
||||
return i2c_bus_read_bytes(ft5x06_handle, reg_addr, data_len, data);
|
||||
}
|
||||
|
||||
static inline esp_err_t ft5x06_write_byte(uint8_t reg_addr, uint8_t data)
|
||||
{
|
||||
return i2c_bus_write_byte(ft5x06_handle, reg_addr, data);
|
||||
}
|
||||
|
||||
esp_err_t ft5x06_init(void)
|
||||
{
|
||||
if (NULL != ft5x06_handle) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
bsp_i2c_add_device(&ft5x06_handle, FT5x06_ADDR);
|
||||
|
||||
if (NULL == ft5x06_handle) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
// Valid touching detect threshold
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_THGROUP, 70);
|
||||
|
||||
// valid touching peak detect threshold
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_THPEAK, 60);
|
||||
|
||||
// Touch focus threshold
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_THCAL, 16);
|
||||
|
||||
// threshold when there is surface water
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_THWATER, 60);
|
||||
|
||||
// threshold of temperature compensation
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_THTEMP, 10);
|
||||
|
||||
// Touch difference threshold
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_THDIFF, 20);
|
||||
|
||||
// Delay to enter 'Monitor' status (s)
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_TIME_ENTER_MONITOR, 2);
|
||||
|
||||
// Period of 'Active' status (ms)
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_PERIODACTIVE, 12);
|
||||
|
||||
// Timer to enter 'idle' when in 'Monitor' (ms)
|
||||
i2c_bus_write_byte(ft5x06_handle, FT5x06_ID_G_PERIODMONITOR, 40);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t ft5x06_get_touch_points_num(uint8_t *touch_points_num)
|
||||
{
|
||||
return ft5x06_read_byte(FT5x06_TOUCH_POINTS, touch_points_num);
|
||||
}
|
||||
|
||||
esp_err_t ft5x06_read_pos(uint8_t *touch_points_num, uint16_t *x, uint16_t *y)
|
||||
{
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
static uint8_t data[4];
|
||||
|
||||
ret_val |= ft5x06_get_touch_points_num(touch_points_num);
|
||||
|
||||
if (0 == *touch_points_num) {
|
||||
} else {
|
||||
ret_val |= ft5x06_read_bytes(FT5x06_TOUCH1_XH, 4, data);
|
||||
|
||||
*x = ((data[0] & 0x0f) << 8) + data[1];
|
||||
*y = ((data[2] & 0x0f) << 8) + data[3];
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t fx5x06_read_gesture(ft5x06_gesture_t *gesture)
|
||||
{
|
||||
return ft5x06_read_byte(FT5x06_GESTURE_ID, (uint8_t *)gesture);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ft5x06_gesture_none = 0x00,
|
||||
ft5x06_gesture_move_up = 0x10,
|
||||
ft5x06_gesture_move_left = 0x14,
|
||||
ft5x06_gesture_move_down = 0x18,
|
||||
ft5x06_gesture_move_right = 0x1c,
|
||||
ft5x06_gesture_zoom_in = 0x48,
|
||||
ft5x06_gesture_zoom_out = 0x49,
|
||||
} ft5x06_gesture_t;
|
||||
|
||||
/**
|
||||
* @brief Init FT5x06 series touch panel
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t ft5x06_init(void);
|
||||
|
||||
/**
|
||||
* @brief Read touch point from FT5x06
|
||||
*
|
||||
* @param touch_points_num Touch point number
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t ft5x06_read_pos(uint8_t *touch_points_num, uint16_t *x, uint16_t *y);
|
||||
|
||||
/**
|
||||
* @brief Read guesture from FT5x06
|
||||
*
|
||||
* @param gesture Gesture read from FT5x06
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t fx5x06_read_gesture(ft5x06_gesture_t *gesture);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Init TT21100 touch panel
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t tt21100_tp_init(void);
|
||||
|
||||
/**
|
||||
* @brief Read packet from TT21100
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t tt21100_tp_read(void);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param p_tp_num
|
||||
* @param p_x
|
||||
* @param p_y
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t tt21100_get_touch_point(uint8_t *p_tp_num, uint16_t *p_x, uint16_t *p_y);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param p_btn_val
|
||||
* @param p_btn_signal
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t tt21100_get_btn_val(uint8_t *p_btn_val, uint16_t *p_btn_signal);
|
||||
|
||||
/**
|
||||
* @brief TT21100 will keep COMM_INT low until all data read.
|
||||
* So if the INT line is low after read the packet, read again.
|
||||
*
|
||||
* @return true Data avaliable
|
||||
* @return false All data has been read
|
||||
*/
|
||||
bool tt21100_data_avaliable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "bsp_i2c.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "i2c_bus.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#define TT21100_CHIP_ADDR_DEFAULT (0x24)
|
||||
#define TT21100_REG_TP_NUM (0x1)
|
||||
#define TT21100_REG_X_POS (0x2)
|
||||
#define TT21100_REG_Y_POS (0x3)
|
||||
|
||||
static const char *TAG = "tt21100";
|
||||
|
||||
static uint8_t tp_num, btn_val;
|
||||
static uint16_t x, y, btn_signal;
|
||||
static i2c_bus_device_handle_t tt21100_handle = NULL;
|
||||
|
||||
static esp_err_t tt21100_read(uint8_t *data, size_t data_len)
|
||||
{
|
||||
static uint8_t cmd_buffer[I2C_LINK_RECOMMENDED_SIZE(4)];
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create_static(cmd_buffer, I2C_LINK_RECOMMENDED_SIZE(4));
|
||||
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (TT21100_CHIP_ADDR_DEFAULT << 1) | I2C_MASTER_READ, I2C_ACK_CHECK_EN);
|
||||
i2c_master_read(cmd, data, data_len, I2C_MASTER_LAST_NACK);
|
||||
i2c_master_stop(cmd);
|
||||
|
||||
esp_err_t ret_val = i2c_bus_cmd_begin(tt21100_handle, cmd);
|
||||
i2c_cmd_link_delete_static(cmd);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t tt21100_tp_init(void)
|
||||
{
|
||||
if (NULL != tt21100_handle) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
ret_val |= bsp_i2c_add_device(&tt21100_handle, TT21100_CHIP_ADDR_DEFAULT);
|
||||
|
||||
if (NULL == tt21100_handle) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
uint16_t reg_val = 0;
|
||||
do {
|
||||
tt21100_read(®_val, sizeof(reg_val));
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
} while (0x0002 != reg_val);
|
||||
|
||||
gpio_config_t io_conf_key;
|
||||
io_conf_key.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||
io_conf_key.mode = GPIO_MODE_INPUT;
|
||||
io_conf_key.pin_bit_mask = 1ULL << GPIO_NUM_3;
|
||||
io_conf_key.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf_key.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf_key));
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t tt21100_tp_read(void)
|
||||
{
|
||||
typedef struct {
|
||||
uint8_t :5;
|
||||
uint8_t touch_type:3;
|
||||
uint8_t tip:1;
|
||||
uint8_t event_id:2;
|
||||
uint8_t touch_id:5;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint8_t pressure;
|
||||
uint16_t major_axis_length;
|
||||
uint8_t orientation;
|
||||
} __attribute__((packed)) touch_record_struct_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t data_len;
|
||||
uint8_t report_id;
|
||||
uint16_t time_stamp;
|
||||
uint8_t :2;
|
||||
uint8_t large_object : 1;
|
||||
uint8_t record_num : 5;
|
||||
uint8_t report_counter:2;
|
||||
uint8_t :3;
|
||||
uint8_t noise_efect:3;
|
||||
touch_record_struct_t touch_record[0];
|
||||
} __attribute__((packed)) touch_report_struct_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t length; /*!< Always 14(0x000E) */
|
||||
uint8_t report_id; /*!< Always 03h */
|
||||
uint16_t time_stamp; /*!< Number in units of 100 us */
|
||||
uint8_t btn_val; /*!< Only use bit[0..3] */
|
||||
uint16_t btn_signal[4];
|
||||
} __attribute__((packed)) button_record_struct_t;
|
||||
|
||||
touch_report_struct_t *p_report_data = NULL;
|
||||
touch_record_struct_t *p_touch_data = NULL;
|
||||
button_record_struct_t *p_btn_data = NULL;
|
||||
|
||||
static uint16_t data_len;
|
||||
static uint8_t data[256];
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
|
||||
/* Get report data length */
|
||||
ret_val |= tt21100_read(&data_len, sizeof(data_len));
|
||||
ESP_LOGD(TAG, "Data len : %u", data_len);
|
||||
|
||||
/* Read report data if length */
|
||||
if (data_len < 0xff) {
|
||||
tt21100_read(data, data_len);
|
||||
switch (data_len) {
|
||||
case 2: /* No avaliable data*/
|
||||
break;
|
||||
case 7:
|
||||
case 17:
|
||||
case 27:
|
||||
p_report_data = (touch_report_struct_t *) data;
|
||||
p_touch_data = &p_report_data->touch_record[0];
|
||||
x = p_touch_data->x;
|
||||
y = p_touch_data->y;
|
||||
|
||||
tp_num = (data_len - sizeof(touch_report_struct_t)) / sizeof(touch_record_struct_t);
|
||||
for (size_t i = 0; i < tp_num; i++) {
|
||||
p_touch_data = &p_report_data->touch_record[i];
|
||||
ESP_LOGD(TAG, "(%zu) [%3u][%3u]", i, p_touch_data->x, p_touch_data->y);
|
||||
}
|
||||
break;
|
||||
case 14: /* Button event */
|
||||
p_btn_data = (button_record_struct_t *) data;
|
||||
btn_val = p_btn_data->btn_val;
|
||||
btn_signal = p_btn_data->btn_signal[0];
|
||||
ESP_LOGD(TAG, "Len : %04Xh. ID : %02Xh. Time : %5u. Val : [%u] - [%04X][%04X][%04X][%04X]",
|
||||
p_btn_data->length, p_btn_data->report_id, p_btn_data->time_stamp, p_btn_data->btn_val,
|
||||
p_btn_data->btn_signal[0], p_btn_data->btn_signal[1], p_btn_data->btn_signal[2], p_btn_data->btn_signal[3]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t tt21100_get_touch_point(uint8_t *p_tp_num, uint16_t *p_x, uint16_t *p_y)
|
||||
{
|
||||
*p_x = x;
|
||||
*p_y = y;
|
||||
*p_tp_num = tp_num;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t tt21100_get_btn_val(uint8_t *p_btn_val, uint16_t *p_btn_signal)
|
||||
{
|
||||
*p_btn_val = btn_val;
|
||||
*p_btn_signal = btn_signal;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool tt21100_data_avaliable(void)
|
||||
{
|
||||
int level = gpio_get_level(GPIO_NUM_3);
|
||||
if (level) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
idf_component_register(SRCS "button_adc.c" "button_gpio.c" "iot_button.c"
|
||||
INCLUDE_DIRS include
|
||||
PRIV_REQUIRES esp_adc_cal)
|
||||
@@ -1,46 +0,0 @@
|
||||
menu "IoT Button"
|
||||
|
||||
config BUTTON_PERIOD_TIME_MS
|
||||
int "BUTTON PERIOD TIME (MS)"
|
||||
range 2 20
|
||||
default 5
|
||||
help
|
||||
"Button scan interval"
|
||||
|
||||
config BUTTON_DEBOUNCE_TICKS
|
||||
int "BUTTON DEBOUNCE TICKS"
|
||||
range 1 8
|
||||
default 2
|
||||
|
||||
config BUTTON_SHORT_PRESS_TIME_MS
|
||||
int "BUTTON SHORT PRESS TIME (MS)"
|
||||
range 50 800
|
||||
default 180
|
||||
|
||||
config BUTTON_LONG_PRESS_TIME_MS
|
||||
int "BUTTON LONG PRESS TIME (MS)"
|
||||
range 500 5000
|
||||
default 1500
|
||||
|
||||
config ADC_BUTTON_MAX_CHANNEL
|
||||
int "ADC BUTTON MAX CHANNEL"
|
||||
range 1 5
|
||||
default 3
|
||||
help
|
||||
"Maximum number of channels for ADC buttons"
|
||||
|
||||
config ADC_BUTTON_MAX_BUTTON_PER_CHANNEL
|
||||
int "ADC BUTTON MAX BUTTON PER CHANNEL"
|
||||
range 1 10
|
||||
default 8
|
||||
help
|
||||
"Maximum number of buttons per channel"
|
||||
|
||||
config ADC_BUTTON_SAMPLE_TIMES
|
||||
int "ADC BUTTON SAMPLE TIMES"
|
||||
range 1 4
|
||||
default 1
|
||||
help
|
||||
"Number of samples per scan"
|
||||
|
||||
endmenu
|
||||
@@ -1,204 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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 <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/adc.h"
|
||||
#include "esp_adc_cal.h"
|
||||
#include "button_adc.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
static const char *TAG = "adc button";
|
||||
|
||||
#define ADC_BTN_CHECK(a, str, ret_val) \
|
||||
if (!(a)) \
|
||||
{ \
|
||||
ESP_LOGE(TAG, "%s(%d): %s", __FUNCTION__, __LINE__, str); \
|
||||
return (ret_val); \
|
||||
}
|
||||
|
||||
#define DEFAULT_VREF 1100
|
||||
#define NO_OF_SAMPLES CONFIG_ADC_BUTTON_SAMPLE_TIMES //Multisampling
|
||||
|
||||
#define ADC_BUTTON_WIDTH ADC_WIDTH_BIT_DEFAULT
|
||||
#define ADC_BUTTON_ATTEN ADC_ATTEN_DB_11
|
||||
#define ADC_BUTTON_ADC_UNIT ADC_UNIT_1
|
||||
#define ADC_BUTTON_MAX_CHANNEL CONFIG_ADC_BUTTON_MAX_CHANNEL
|
||||
#define ADC_BUTTON_MAX_BUTTON CONFIG_ADC_BUTTON_MAX_BUTTON_PER_CHANNEL
|
||||
|
||||
typedef struct {
|
||||
uint16_t min;
|
||||
uint16_t max;
|
||||
} button_data_t;
|
||||
|
||||
typedef struct {
|
||||
adc1_channel_t channel;
|
||||
uint8_t is_init;
|
||||
button_data_t btns[ADC_BUTTON_MAX_BUTTON]; /* all button on the channel */
|
||||
uint64_t last_time; /* the last time of adc sample */
|
||||
} btn_adc_channel_t;
|
||||
|
||||
typedef struct {
|
||||
bool is_configured;
|
||||
esp_adc_cal_characteristics_t adc_chars;
|
||||
btn_adc_channel_t ch[ADC_BUTTON_MAX_CHANNEL];
|
||||
uint8_t ch_num;
|
||||
} adc_button_t;
|
||||
|
||||
static adc_button_t g_button = {0};
|
||||
|
||||
static int find_unused_channel(void)
|
||||
{
|
||||
for (size_t i = 0; i < ADC_BUTTON_MAX_CHANNEL; i++) {
|
||||
if (0 == g_button.ch[i].is_init) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int find_channel(adc1_channel_t channel)
|
||||
{
|
||||
for (size_t i = 0; i < ADC_BUTTON_MAX_CHANNEL; i++) {
|
||||
if (channel == g_button.ch[i].channel) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
esp_err_t button_adc_init(const button_adc_config_t *config)
|
||||
{
|
||||
ADC_BTN_CHECK(NULL != config, "Pointer of config is invalid", ESP_ERR_INVALID_ARG);
|
||||
ADC_BTN_CHECK(config->adc_channel < ADC1_CHANNEL_MAX, "channel out of range", ESP_ERR_NOT_SUPPORTED);
|
||||
ADC_BTN_CHECK(config->button_index < ADC_BUTTON_MAX_BUTTON, "button_index out of range", ESP_ERR_NOT_SUPPORTED);
|
||||
ADC_BTN_CHECK(config->max > 0, "key max voltage invalid", ESP_ERR_INVALID_ARG);
|
||||
|
||||
int ch_index = find_channel(config->adc_channel);
|
||||
if (ch_index >= 0) { /**< the channel has been initialized */
|
||||
ADC_BTN_CHECK(g_button.ch[ch_index].btns[config->button_index].max == 0, "The button_index has been used", ESP_ERR_INVALID_STATE);
|
||||
} else { /**< this is a new channel */
|
||||
int unused_ch_index = find_unused_channel();
|
||||
ADC_BTN_CHECK(unused_ch_index >= 0, "exceed max channel number, can't create a new channel", ESP_ERR_INVALID_STATE);
|
||||
ch_index = unused_ch_index;
|
||||
}
|
||||
|
||||
/** initialize adc */
|
||||
if (0 == g_button.is_configured) {
|
||||
//Configure ADC
|
||||
adc1_config_width(ADC_BUTTON_WIDTH);
|
||||
//Characterize ADC
|
||||
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_BUTTON_ADC_UNIT, ADC_BUTTON_ATTEN, ADC_BUTTON_WIDTH, DEFAULT_VREF, &g_button.adc_chars);
|
||||
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
|
||||
ESP_LOGI(TAG, "Characterized using Two Point Value");
|
||||
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
|
||||
ESP_LOGI(TAG, "Characterized using eFuse Vref");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Characterized using Default Vref");
|
||||
}
|
||||
g_button.is_configured = 1;
|
||||
}
|
||||
|
||||
/** initialize adc channel */
|
||||
if (0 == g_button.ch[ch_index].is_init) {
|
||||
adc1_config_channel_atten(config->adc_channel, ADC_BUTTON_ATTEN);
|
||||
g_button.ch[ch_index].channel = config->adc_channel;
|
||||
g_button.ch[ch_index].is_init = 1;
|
||||
g_button.ch[ch_index].last_time = 0;
|
||||
}
|
||||
g_button.ch[ch_index].btns[config->button_index].max = config->max;
|
||||
g_button.ch[ch_index].btns[config->button_index].min = config->min;
|
||||
g_button.ch_num++;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t button_adc_deinit(adc1_channel_t channel, int button_index)
|
||||
{
|
||||
ADC_BTN_CHECK(channel < ADC1_CHANNEL_MAX, "channel out of range", ESP_ERR_INVALID_ARG);
|
||||
ADC_BTN_CHECK(button_index < ADC_BUTTON_MAX_BUTTON, "button_index out of range", ESP_ERR_INVALID_ARG);
|
||||
|
||||
int ch_index = find_channel(channel);
|
||||
ADC_BTN_CHECK(ch_index >= 0, "can't find the channel", ESP_ERR_INVALID_ARG);
|
||||
|
||||
g_button.ch[ch_index].btns[button_index].max = 0;
|
||||
g_button.ch[ch_index].btns[button_index].min = 0;
|
||||
|
||||
/** check button usage on the channel*/
|
||||
uint8_t unused_button = 0;
|
||||
for (size_t i = 0; i < ADC_BUTTON_MAX_BUTTON; i++) {
|
||||
if (0 == g_button.ch[ch_index].btns[i].max) {
|
||||
unused_button++;
|
||||
}
|
||||
}
|
||||
if (unused_button == ADC_BUTTON_MAX_BUTTON && g_button.ch[ch_index].is_init) { /**< if all button is unused, deinit the channel */
|
||||
/* TODO: to deinit the channel */
|
||||
g_button.ch[ch_index].is_init = 0;
|
||||
g_button.ch[ch_index].channel = ADC1_CHANNEL_MAX;
|
||||
ESP_LOGD(TAG, "all button is unused on channel%d, deinit the channel", g_button.ch[ch_index].channel);
|
||||
}
|
||||
|
||||
/** check channel usage on the adc*/
|
||||
uint8_t unused_ch = 0;
|
||||
for (size_t i = 0; i < ADC_BUTTON_MAX_CHANNEL; i++) {
|
||||
if (0 == g_button.ch[i].is_init) {
|
||||
unused_ch++;
|
||||
}
|
||||
}
|
||||
if (unused_ch == ADC_BUTTON_MAX_CHANNEL && g_button.is_configured) { /**< if all channel is unused, deinit the adc */
|
||||
/* TODO: to deinit the peripheral adc */
|
||||
g_button.is_configured = false;
|
||||
memset(&g_button, 0, sizeof(adc_button_t));
|
||||
ESP_LOGD(TAG, "all channel is unused, , deinit adc");
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static uint32_t get_adc_volatge(adc1_channel_t channel)
|
||||
{
|
||||
uint32_t adc_reading = 0;
|
||||
//Multisampling
|
||||
for (int i = 0; i < NO_OF_SAMPLES; i++) {
|
||||
adc_reading += adc1_get_raw(channel);
|
||||
}
|
||||
adc_reading /= NO_OF_SAMPLES;
|
||||
//Convert adc_reading to voltage in mV
|
||||
uint32_t voltage = adc_reading; //esp_adc_cal_raw_to_voltage(adc_reading, &g_button.adc_chars);
|
||||
ESP_LOGV(TAG, "Raw: %d\tVoltage: %dmV", adc_reading, voltage);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
uint8_t button_adc_get_key_level(void *button_index)
|
||||
{
|
||||
static uint16_t vol = 0;
|
||||
uint32_t ch = ADC_BUTTON_SPLIT_CHANNEL(button_index);
|
||||
uint32_t index = ADC_BUTTON_SPLIT_INDEX(button_index);
|
||||
ADC_BTN_CHECK(ch < ADC1_CHANNEL_MAX, "channel out of range", 0);
|
||||
ADC_BTN_CHECK(index < ADC_BUTTON_MAX_BUTTON, "button_index out of range", 0);
|
||||
int ch_index = find_channel(ch);
|
||||
ADC_BTN_CHECK(ch_index >= 0, "The button_index is not init", 0);
|
||||
|
||||
/** It starts only when the elapsed time is more than 1ms */
|
||||
if ((esp_timer_get_time() - g_button.ch[ch_index].last_time) > 1000) {
|
||||
vol = get_adc_volatge(ch);
|
||||
g_button.ch[ch_index].last_time = esp_timer_get_time();
|
||||
}
|
||||
|
||||
if (vol <= g_button.ch[ch_index].btns[index].max &&
|
||||
vol > g_button.ch[ch_index].btns[index].min) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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 "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "button_gpio.h"
|
||||
|
||||
static const char *TAG = "gpio button";
|
||||
|
||||
#define GPIO_BTN_CHECK(a, str, ret_val) \
|
||||
if (!(a)) \
|
||||
{ \
|
||||
ESP_LOGE(TAG, "%s(%d): %s", __FUNCTION__, __LINE__, str); \
|
||||
return (ret_val); \
|
||||
}
|
||||
|
||||
esp_err_t button_gpio_init(const button_gpio_config_t *config)
|
||||
{
|
||||
GPIO_BTN_CHECK(NULL != config, "Pointer of config is invalid", ESP_ERR_INVALID_ARG);
|
||||
|
||||
gpio_config_t gpio_conf;
|
||||
gpio_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
gpio_conf.mode = GPIO_MODE_INPUT;
|
||||
gpio_conf.pin_bit_mask = (1ULL << config->gpio_num);
|
||||
if (config->active_level) {
|
||||
gpio_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
|
||||
gpio_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
} else {
|
||||
gpio_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
gpio_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
}
|
||||
gpio_config(&gpio_conf);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t button_gpio_deinit(int gpio_num)
|
||||
{
|
||||
/** both disable pullup and pulldown */
|
||||
gpio_config_t gpio_conf = {
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pin_bit_mask = (1ULL << gpio_num),
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
};
|
||||
gpio_config(&gpio_conf);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint8_t button_gpio_get_key_level(void *gpio_num)
|
||||
{
|
||||
return (uint8_t)gpio_get_level((uint32_t)gpio_num);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS := ./include
|
||||
COMPONENT_SRCDIRS := .
|
||||
@@ -1,147 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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.
|
||||
#ifndef _BUTTON_H_
|
||||
#define _BUTTON_H_
|
||||
|
||||
#include "button_adc.h"
|
||||
#include "button_gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (* button_cb_t)(void *);
|
||||
typedef void *button_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Button events
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
BUTTON_PRESS_DOWN = 0,
|
||||
BUTTON_PRESS_UP,
|
||||
BUTTON_PRESS_REPEAT,
|
||||
BUTTON_SINGLE_CLICK,
|
||||
BUTTON_DOUBLE_CLICK,
|
||||
BUTTON_LONG_PRESS_START,
|
||||
BUTTON_LONG_PRESS_HOLD,
|
||||
BUTTON_EVENT_MAX,
|
||||
BUTTON_NONE_PRESS,
|
||||
} button_event_t;
|
||||
|
||||
/**
|
||||
* @brief Supported button type
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
BUTTON_TYPE_GPIO,
|
||||
BUTTON_TYPE_ADC,
|
||||
} button_type_t;
|
||||
|
||||
/**
|
||||
* @brief Button configuration
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
button_type_t type; /**< button type, The corresponding button configuration must be filled */
|
||||
union {
|
||||
button_gpio_config_t gpio_button_config; /**< gpio button configuration */
|
||||
button_adc_config_t adc_button_config; /**< adc button configuration */
|
||||
}; /**< button configuration */
|
||||
} button_config_t;
|
||||
|
||||
typedef struct Button {
|
||||
uint16_t ticks;
|
||||
uint8_t repeat;
|
||||
button_event_t event;
|
||||
uint8_t state: 3;
|
||||
uint8_t debounce_cnt: 3;
|
||||
uint8_t active_level: 1;
|
||||
uint8_t button_level: 1;
|
||||
uint8_t (*hal_button_Level)(void *usr_data);
|
||||
void *usr_data;
|
||||
button_type_t type;
|
||||
button_cb_t cb[BUTTON_EVENT_MAX];
|
||||
void *cb_user_data;
|
||||
struct Button *next;
|
||||
} button_dev_t;
|
||||
|
||||
/**
|
||||
* @brief Create a button
|
||||
*
|
||||
* @param config pointer of button configuration, must corresponding the button type
|
||||
*
|
||||
* @return A handle to the created button, or NULL in case of error.
|
||||
*/
|
||||
button_handle_t button_create(const button_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Delete a button
|
||||
*
|
||||
* @param btn_handle A button handle to delete
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Failure
|
||||
*/
|
||||
esp_err_t button_delete(button_handle_t btn_handle);
|
||||
|
||||
/**
|
||||
* @brief Register the button event callback function.
|
||||
*
|
||||
* @param btn_handle A button handle to register
|
||||
* @param event Button event
|
||||
* @param cb Callback function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is invalid.
|
||||
*/
|
||||
esp_err_t button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb);
|
||||
|
||||
/**
|
||||
* @brief Unregister the button event callback function.
|
||||
*
|
||||
* @param btn_handle A button handle to unregister
|
||||
* @param event Button event
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is invalid.
|
||||
*/
|
||||
esp_err_t button_unregister_cb(button_handle_t btn_handle, button_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Get button event
|
||||
*
|
||||
* @param btn_handle Button handle
|
||||
*
|
||||
* @return Current button event. See button_event_t
|
||||
*/
|
||||
button_event_t button_get_event(button_handle_t btn_handle);
|
||||
|
||||
/**
|
||||
* @brief Get button repeat times
|
||||
*
|
||||
* @param btn_handle Button handle
|
||||
*
|
||||
* @return button pressed times. For example, double-click return 2, triple-click return 3, etc.
|
||||
*/
|
||||
uint8_t button_get_repeat(button_handle_t btn_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,79 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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.
|
||||
#ifndef _IOT_BUTTON_ADC_H_
|
||||
#define _IOT_BUTTON_ADC_H_
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/adc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ADC_BUTTON_COMBINE(channel, index) ((channel)<<8 | (index))
|
||||
#define ADC_BUTTON_SPLIT_INDEX(data) ((uint32_t)(data)&0xff)
|
||||
#define ADC_BUTTON_SPLIT_CHANNEL(data) (((uint32_t)(data) >> 8) & 0xff)
|
||||
|
||||
/**
|
||||
* @brief adc button configuration
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
adc1_channel_t adc_channel; /**< Channel of ADC */
|
||||
uint8_t button_index; /**< button index on the channel */
|
||||
uint16_t min; /**< min voltage in mv corresponding to the button */
|
||||
uint16_t max; /**< max voltage in mv corresponding to the button */
|
||||
} button_adc_config_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize gpio button
|
||||
*
|
||||
* @param config pointer of configuration struct
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is NULL.
|
||||
* - ESP_ERR_NOT_SUPPORTED Arguments out of range.
|
||||
* - ESP_ERR_INVALID_STATE State is error.
|
||||
*/
|
||||
esp_err_t button_adc_init(const button_adc_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize gpio button
|
||||
*
|
||||
* @param channel ADC channel
|
||||
* @param button_index Button index on the channel
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is invalid.
|
||||
*/
|
||||
esp_err_t button_adc_deinit(adc1_channel_t channel, int button_index);
|
||||
|
||||
/**
|
||||
* @brief Get the adc button level
|
||||
*
|
||||
* @param button_index It is compressed by ADC channel and button index, use the macro ADC_BUTTON_COMBINE to generate. It will be treated as a uint32_t variable.
|
||||
*
|
||||
* @return
|
||||
* - 0 Not pressed
|
||||
* - 1 Pressed
|
||||
*/
|
||||
uint8_t button_adc_get_key_level(void *button_index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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.
|
||||
#ifndef _IOT_BUTTON_GPIO_H_
|
||||
#define _IOT_BUTTON_GPIO_H_
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief gpio button configuration
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t gpio_num;
|
||||
uint8_t active_level;
|
||||
} button_gpio_config_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize gpio button
|
||||
*
|
||||
* @param config pointer of configuration struct
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG Arguments is NULL.
|
||||
*/
|
||||
esp_err_t button_gpio_init(const button_gpio_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize gpio button
|
||||
*
|
||||
* @param gpio_num gpio number of button
|
||||
*
|
||||
* @return Always return ESP_OK
|
||||
*/
|
||||
esp_err_t button_gpio_deinit(int gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Get current level on button gpio
|
||||
*
|
||||
* @param gpio_num gpio number of button, it will be treated as a uint32_t variable.
|
||||
*
|
||||
* @return Level on gpio
|
||||
*/
|
||||
uint8_t button_gpio_get_key_level(void *gpio_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,290 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "button.h"
|
||||
#include "esp_timer.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char *TAG = "button";
|
||||
|
||||
#define BTN_CHECK(a, str, ret_val) \
|
||||
if (!(a)) \
|
||||
{ \
|
||||
ESP_LOGE(TAG, "%s(%d): %s", __FUNCTION__, __LINE__, str); \
|
||||
return (ret_val); \
|
||||
}
|
||||
|
||||
//button handle list head.
|
||||
static button_dev_t *g_head_handle = NULL;
|
||||
static esp_timer_handle_t g_button_timer_handle;
|
||||
static bool g_is_timer_running = false;
|
||||
|
||||
#define TICKS_INTERVAL CONFIG_BUTTON_PERIOD_TIME_MS
|
||||
#define DEBOUNCE_TICKS CONFIG_BUTTON_DEBOUNCE_TICKS //MAX 8
|
||||
#define SHORT_TICKS (CONFIG_BUTTON_SHORT_PRESS_TIME_MS /TICKS_INTERVAL)
|
||||
#define LONG_TICKS (CONFIG_BUTTON_LONG_PRESS_TIME_MS /TICKS_INTERVAL)
|
||||
|
||||
#define CALL_EVENT_CB(ev) if(btn->cb[ev])btn->cb[ev](btn)
|
||||
|
||||
/**
|
||||
* @brief Button driver core function, driver state machine.
|
||||
*/
|
||||
static void button_handler(button_dev_t *btn)
|
||||
{
|
||||
uint8_t read_gpio_level = btn->hal_button_Level(btn->usr_data);
|
||||
|
||||
/** ticks counter working.. */
|
||||
if ((btn->state) > 0) {
|
||||
btn->ticks++;
|
||||
}
|
||||
|
||||
/**< button debounce handle */
|
||||
if (read_gpio_level != btn->button_level) {
|
||||
if (++(btn->debounce_cnt) >= DEBOUNCE_TICKS) {
|
||||
btn->button_level = read_gpio_level;
|
||||
btn->debounce_cnt = 0;
|
||||
}
|
||||
} else {
|
||||
btn->debounce_cnt = 0;
|
||||
}
|
||||
|
||||
/** State machine */
|
||||
switch (btn->state) {
|
||||
case 0:
|
||||
if (btn->button_level == btn->active_level) {
|
||||
btn->event = (uint8_t)BUTTON_PRESS_DOWN;
|
||||
CALL_EVENT_CB(BUTTON_PRESS_DOWN);
|
||||
btn->ticks = 0;
|
||||
btn->repeat = 1;
|
||||
btn->state = 1;
|
||||
} else {
|
||||
btn->event = (uint8_t)BUTTON_NONE_PRESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (btn->button_level != btn->active_level) {
|
||||
btn->event = (uint8_t)BUTTON_PRESS_UP;
|
||||
CALL_EVENT_CB(BUTTON_PRESS_UP);
|
||||
btn->ticks = 0;
|
||||
btn->state = 2;
|
||||
|
||||
} else if (btn->ticks > LONG_TICKS) {
|
||||
btn->event = (uint8_t)BUTTON_LONG_PRESS_START;
|
||||
CALL_EVENT_CB(BUTTON_LONG_PRESS_START);
|
||||
btn->state = 5;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (btn->button_level == btn->active_level) {
|
||||
btn->event = (uint8_t)BUTTON_PRESS_DOWN;
|
||||
CALL_EVENT_CB(BUTTON_PRESS_DOWN);
|
||||
btn->repeat++;
|
||||
CALL_EVENT_CB(BUTTON_PRESS_REPEAT); // repeat hit
|
||||
btn->ticks = 0;
|
||||
btn->state = 3;
|
||||
} else if (btn->ticks > SHORT_TICKS) {
|
||||
if (btn->repeat == 1) {
|
||||
btn->event = (uint8_t)BUTTON_SINGLE_CLICK;
|
||||
CALL_EVENT_CB(BUTTON_SINGLE_CLICK);
|
||||
} else if (btn->repeat == 2) {
|
||||
btn->event = (uint8_t)BUTTON_DOUBLE_CLICK;
|
||||
CALL_EVENT_CB(BUTTON_DOUBLE_CLICK); // repeat hit
|
||||
}
|
||||
btn->state = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (btn->button_level != btn->active_level) {
|
||||
btn->event = (uint8_t)BUTTON_PRESS_UP;
|
||||
CALL_EVENT_CB(BUTTON_PRESS_UP);
|
||||
if (btn->ticks < SHORT_TICKS) {
|
||||
btn->ticks = 0;
|
||||
btn->state = 2; //repeat press
|
||||
} else {
|
||||
btn->state = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (btn->button_level == btn->active_level) {
|
||||
//continue hold trigger
|
||||
btn->event = (uint8_t)BUTTON_LONG_PRESS_HOLD;
|
||||
CALL_EVENT_CB(BUTTON_LONG_PRESS_HOLD);
|
||||
} else { //releasd
|
||||
btn->event = (uint8_t)BUTTON_PRESS_UP;
|
||||
CALL_EVENT_CB(BUTTON_PRESS_UP);
|
||||
btn->state = 0; //reset
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void button_cb(void *args)
|
||||
{
|
||||
button_dev_t *target;
|
||||
for (target = g_head_handle; target; target = target->next) {
|
||||
button_handler(target);
|
||||
}
|
||||
}
|
||||
|
||||
static button_dev_t *button_create_com(uint8_t active_level, uint8_t (*hal_get_key_state)(void *usr_data), void *usr_data)
|
||||
{
|
||||
BTN_CHECK(NULL != hal_get_key_state, "Function pointer is invalid", NULL);
|
||||
|
||||
button_dev_t *btn = (button_dev_t *) calloc(1, sizeof(button_dev_t));
|
||||
BTN_CHECK(NULL != btn, "Button memory alloc failed", NULL);
|
||||
btn->usr_data = usr_data;
|
||||
btn->event = BUTTON_NONE_PRESS;
|
||||
btn->active_level = active_level;
|
||||
btn->hal_button_Level = hal_get_key_state;
|
||||
btn->button_level = !active_level;
|
||||
|
||||
/** Add handle to list */
|
||||
btn->next = g_head_handle;
|
||||
g_head_handle = btn;
|
||||
|
||||
if (false == g_is_timer_running) {
|
||||
esp_timer_create_args_t button_timer;
|
||||
button_timer.arg = NULL;
|
||||
button_timer.callback = button_cb;
|
||||
button_timer.dispatch_method = ESP_TIMER_TASK;
|
||||
button_timer.name = "button_timer";
|
||||
esp_timer_create(&button_timer, &g_button_timer_handle);
|
||||
esp_timer_start_periodic(g_button_timer_handle, TICKS_INTERVAL * 1000U);
|
||||
g_is_timer_running = true;
|
||||
}
|
||||
|
||||
return btn;
|
||||
}
|
||||
|
||||
static esp_err_t button_delete_com(button_dev_t *btn)
|
||||
{
|
||||
BTN_CHECK(NULL != btn, "Pointer of handle is invalid", ESP_ERR_INVALID_ARG);
|
||||
|
||||
button_dev_t **curr;
|
||||
for (curr = &g_head_handle; *curr; ) {
|
||||
button_dev_t *entry = *curr;
|
||||
if (entry == btn) {
|
||||
*curr = entry->next;
|
||||
free(entry);
|
||||
} else {
|
||||
curr = &entry->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* count button number */
|
||||
uint16_t number = 0;
|
||||
button_dev_t *target = g_head_handle;
|
||||
while (target) {
|
||||
target = target->next;
|
||||
number++;
|
||||
}
|
||||
ESP_LOGD(TAG, "remain btn number=%d", number);
|
||||
|
||||
if (0 == number && g_is_timer_running) { /**< if all button is deleted, stop the timer */
|
||||
esp_timer_stop(g_button_timer_handle);
|
||||
esp_timer_delete(g_button_timer_handle);
|
||||
g_is_timer_running = false;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
button_handle_t button_create(const button_config_t *config)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
button_dev_t *btn = NULL;
|
||||
switch (config->type) {
|
||||
case BUTTON_TYPE_GPIO: {
|
||||
const button_gpio_config_t *cfg = &(config->gpio_button_config);
|
||||
ret = button_gpio_init(cfg);
|
||||
BTN_CHECK(ESP_OK == ret, "gpio button init failed", NULL);
|
||||
btn = button_create_com(cfg->active_level, button_gpio_get_key_level, (void *)cfg->gpio_num);
|
||||
} break;
|
||||
case BUTTON_TYPE_ADC: {
|
||||
const button_adc_config_t *cfg = &(config->adc_button_config);
|
||||
ret = button_adc_init(cfg);
|
||||
BTN_CHECK(ESP_OK == ret, "adc button init failed", NULL);
|
||||
btn = button_create_com(1, button_adc_get_key_level, (void *)ADC_BUTTON_COMBINE(cfg->adc_channel, cfg->button_index));
|
||||
} break;
|
||||
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unsupported button type");
|
||||
break;
|
||||
}
|
||||
BTN_CHECK(NULL != btn, "button create failed", NULL);
|
||||
btn->type = config->type;
|
||||
return (button_handle_t)btn;
|
||||
}
|
||||
|
||||
esp_err_t button_delete(button_handle_t btn_handle)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", ESP_ERR_INVALID_ARG);
|
||||
button_dev_t *btn = (button_dev_t *)btn_handle;
|
||||
switch (btn->type) {
|
||||
case BUTTON_TYPE_GPIO:
|
||||
ret = button_gpio_deinit((int)(btn->usr_data));
|
||||
break;
|
||||
case BUTTON_TYPE_ADC:
|
||||
ret = button_adc_deinit(ADC_BUTTON_SPLIT_CHANNEL(btn->usr_data), ADC_BUTTON_SPLIT_INDEX(btn->usr_data));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
BTN_CHECK(ESP_OK == ret, "button deinit failed", ESP_FAIL);
|
||||
button_delete_com(btn);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb)
|
||||
{
|
||||
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", ESP_ERR_INVALID_ARG);
|
||||
BTN_CHECK(event < BUTTON_EVENT_MAX, "event is invalid", ESP_ERR_INVALID_ARG);
|
||||
button_dev_t *btn = (button_dev_t *) btn_handle;
|
||||
btn->cb[event] = cb;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t button_unregister_cb(button_handle_t btn_handle, button_event_t event)
|
||||
{
|
||||
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", ESP_ERR_INVALID_ARG);
|
||||
BTN_CHECK(event < BUTTON_EVENT_MAX, "event is invalid", ESP_ERR_INVALID_ARG);
|
||||
button_dev_t *btn = (button_dev_t *) btn_handle;
|
||||
btn->cb[event] = NULL;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
button_event_t button_get_event(button_handle_t btn_handle)
|
||||
{
|
||||
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", BUTTON_NONE_PRESS);
|
||||
button_dev_t *btn = (button_dev_t *) btn_handle;
|
||||
return btn->event;
|
||||
}
|
||||
|
||||
uint8_t button_get_repeat(button_handle_t btn_handle)
|
||||
{
|
||||
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", 0);
|
||||
button_dev_t *btn = (button_dev_t *) btn_handle;
|
||||
return btn->repeat;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity test_utils)
|
||||
@@ -1,234 +0,0 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) Co. 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 "stdio.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/timers.h"
|
||||
#include "esp_log.h"
|
||||
#include "unity.h"
|
||||
#include "iot_button.h"
|
||||
|
||||
static const char *TAG = "BUTTON TEST";
|
||||
|
||||
#define BUTTON_IO_NUM 0
|
||||
#define BUTTON_ACTIVE_LEVEL 0
|
||||
#define BUTTON_NUM 16
|
||||
|
||||
static button_handle_t g_btns[BUTTON_NUM] = {0};
|
||||
|
||||
static int get_btn_index(button_handle_t btn)
|
||||
{
|
||||
for (size_t i = 0; i < BUTTON_NUM; i++) {
|
||||
if (btn == g_btns[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void button_press_down_cb(void *arg)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_DOWN, iot_button_get_event(arg));
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_DOWN", get_btn_index((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void button_press_up_cb(void *arg)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_UP, iot_button_get_event(arg));
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_UP", get_btn_index((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void button_press_repeat_cb(void *arg)
|
||||
{
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_REPEAT[%d]", get_btn_index((button_handle_t)arg), iot_button_get_repeat((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void button_single_click_cb(void *arg)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(BUTTON_SINGLE_CLICK, iot_button_get_event(arg));
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_SINGLE_CLICK", get_btn_index((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void button_double_click_cb(void *arg)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(BUTTON_DOUBLE_CLICK, iot_button_get_event(arg));
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_DOUBLE_CLICK", get_btn_index((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void button_long_press_start_cb(void *arg)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(BUTTON_LONG_PRESS_START, iot_button_get_event(arg));
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_LONG_PRESS_START", get_btn_index((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void button_long_press_hold_cb(void *arg)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(BUTTON_LONG_PRESS_HOLD, iot_button_get_event(arg));
|
||||
ESP_LOGI(TAG, "BTN%d: BUTTON_LONG_PRESS_HOLD", get_btn_index((button_handle_t)arg));
|
||||
}
|
||||
|
||||
static void print_button_event(button_handle_t btn)
|
||||
{
|
||||
button_event_t evt = iot_button_get_event(btn);
|
||||
switch (evt) {
|
||||
case BUTTON_PRESS_DOWN:
|
||||
ESP_LOGI(TAG, "BUTTON_PRESS_DOWN");
|
||||
break;
|
||||
case BUTTON_PRESS_UP:
|
||||
ESP_LOGI(TAG, "BUTTON_PRESS_UP");
|
||||
break;
|
||||
case BUTTON_PRESS_REPEAT:
|
||||
ESP_LOGI(TAG, "BUTTON_PRESS_REPEAT");
|
||||
break;
|
||||
case BUTTON_SINGLE_CLICK:
|
||||
ESP_LOGI(TAG, "BUTTON_SINGLE_CLICK");
|
||||
break;
|
||||
case BUTTON_DOUBLE_CLICK:
|
||||
ESP_LOGI(TAG, "BUTTON_DOUBLE_CLICK");
|
||||
break;
|
||||
case BUTTON_LONG_PRESS_START:
|
||||
ESP_LOGI(TAG, "BUTTON_LONG_PRESS_START");
|
||||
break;
|
||||
case BUTTON_LONG_PRESS_HOLD:
|
||||
ESP_LOGI(TAG, "BUTTON_LONG_PRESS_HOLD");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("gpio button test", "[button][iot]")
|
||||
{
|
||||
button_config_t cfg = {
|
||||
.type = BUTTON_TYPE_GPIO,
|
||||
.gpio_button_config = {
|
||||
.gpio_num = 0,
|
||||
.active_level = 0,
|
||||
},
|
||||
};
|
||||
g_btns[0] = iot_button_create(&cfg);
|
||||
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb);
|
||||
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb);
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
iot_button_delete(g_btns[0]);
|
||||
}
|
||||
|
||||
TEST_CASE("adc button test", "[button][iot]")
|
||||
{
|
||||
/** ESP32-LyraT-Mini board */
|
||||
const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410};
|
||||
button_config_t cfg = {0};
|
||||
cfg.type = BUTTON_TYPE_ADC;
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
cfg.adc_button_config.adc_channel = 3,
|
||||
cfg.adc_button_config.button_index = i;
|
||||
if (i == 0) {
|
||||
cfg.adc_button_config.min = (0 + vol[i]) / 2;
|
||||
} else {
|
||||
cfg.adc_button_config.min = (vol[i - 1] + vol[i]) / 2;
|
||||
}
|
||||
|
||||
if (i == 5) {
|
||||
cfg.adc_button_config.max = (vol[i] + 3000) / 2;
|
||||
} else {
|
||||
cfg.adc_button_config.max = (vol[i] + vol[i + 1]) / 2;
|
||||
}
|
||||
|
||||
g_btns[i] = iot_button_create(&cfg);
|
||||
TEST_ASSERT_NOT_NULL(g_btns[i]);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_PRESS_DOWN, button_press_down_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_PRESS_UP, button_press_up_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT, button_press_repeat_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_SINGLE_CLICK, button_single_click_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_DOUBLE_CLICK, button_double_click_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_START, button_long_press_start_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
iot_button_delete(g_btns[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("adc gpio button test", "[button][iot]")
|
||||
{
|
||||
button_config_t cfg = {
|
||||
.type = BUTTON_TYPE_GPIO,
|
||||
.gpio_button_config = {
|
||||
.gpio_num = 0,
|
||||
.active_level = 0,
|
||||
},
|
||||
};
|
||||
g_btns[8] = iot_button_create(&cfg);
|
||||
TEST_ASSERT_NOT_NULL(g_btns[8]);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_PRESS_DOWN, button_press_down_cb);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_PRESS_UP, button_press_up_cb);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_PRESS_REPEAT, button_press_repeat_cb);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_SINGLE_CLICK, button_single_click_cb);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_DOUBLE_CLICK, button_double_click_cb);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_LONG_PRESS_START, button_long_press_start_cb);
|
||||
iot_button_register_cb(g_btns[8], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb);
|
||||
|
||||
/** ESP32-LyraT-Mini board */
|
||||
const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410};
|
||||
// button_config_t cfg = {0};
|
||||
cfg.type = BUTTON_TYPE_ADC;
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
cfg.adc_button_config.adc_channel = 3,
|
||||
cfg.adc_button_config.button_index = i;
|
||||
if (i == 0) {
|
||||
cfg.adc_button_config.min = (0 + vol[i]) / 2;
|
||||
} else {
|
||||
cfg.adc_button_config.min = (vol[i - 1] + vol[i]) / 2;
|
||||
}
|
||||
|
||||
if (i == 5) {
|
||||
cfg.adc_button_config.max = (vol[i] + 3000) / 2;
|
||||
} else {
|
||||
cfg.adc_button_config.max = (vol[i] + vol[i + 1]) / 2;
|
||||
}
|
||||
|
||||
g_btns[i] = iot_button_create(&cfg);
|
||||
TEST_ASSERT_NOT_NULL(g_btns[i]);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_PRESS_DOWN, button_press_down_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_PRESS_UP, button_press_up_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT, button_press_repeat_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_SINGLE_CLICK, button_single_click_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_DOUBLE_CLICK, button_double_click_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_START, button_long_press_start_cb);
|
||||
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
iot_button_delete(g_btns[i]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#
|
||||
#Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
||||
@@ -1,11 +0,0 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS
|
||||
"."
|
||||
"real"
|
||||
INCLUDE_DIRS
|
||||
"pub"
|
||||
PRIV_INCLUDE_DIRS
|
||||
"real")
|
||||
|
||||
# Some of warinings from LVGL. Block them.
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-but-set-variable)
|
||||
@@ -1,30 +0,0 @@
|
||||
Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
|
||||
|
||||
The contents of this directory, and (except where otherwise
|
||||
indicated) the directories included within this directory, are
|
||||
subject to the current version of the RealNetworks Public Source
|
||||
License (the "RPSL") available at RPSL.txt in this directory, unless
|
||||
you have licensed the directory under the current version of the
|
||||
RealNetworks Community Source License (the "RCSL") available at
|
||||
RCSL.txt in this directory, in which case the RCSL will apply. You
|
||||
may also obtain the license terms directly from RealNetworks. You
|
||||
may not use the files in this directory except in compliance with the
|
||||
RPSL or, if you have a valid RCSL with RealNetworks applicable to
|
||||
this directory, the RCSL. Please see the applicable RPSL or RCSL for
|
||||
the rights, obligations and limitations governing use of the contents
|
||||
of the directory.
|
||||
|
||||
This directory is part of the Helix DNA Technology. RealNetworks is
|
||||
the developer of the Original Code and owns the copyrights in the
|
||||
portions it created.
|
||||
|
||||
This directory, and the directories included with this directory, are
|
||||
distributed and made available on an 'AS IS' basis, WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY
|
||||
DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
|
||||
Technology Compatibility Kit Test Suite(s) Location:
|
||||
http://www.helixcommunity.org/content/tck
|
||||
|
||||
@@ -1,948 +0,0 @@
|
||||
The RCSL is made up of a base agreement and a few Attachments.
|
||||
|
||||
For Research and Development use, you agree to the terms of the
|
||||
RCSL R&D License (base RCSL and Attachments A, B, and C)
|
||||
|
||||
For Commercial Use (either distribution or internal commercial
|
||||
deployment) of the Helix DNA with or without support for RealNetworks'
|
||||
RealAudio and RealVideo Add-on Technology, you agree to the
|
||||
terms of the same RCSL R&D license
|
||||
and execute one or more additional Commercial Use License attachments
|
||||
<see http://www.helixcommunity.org/content/rcsl-attachments>.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
|
||||
REALNETWORKS COMMUNITY SOURCE LICENSE
|
||||
|
||||
Version 1.2 (Rev. Date: January 22, 2003).
|
||||
|
||||
|
||||
RECITALS
|
||||
|
||||
Original Contributor has developed Specifications, Source Code
|
||||
implementations and Executables of certain Technology; and
|
||||
|
||||
Original Contributor desires to license the Technology to a large
|
||||
community to facilitate research, innovation and product development
|
||||
while maintaining compatibility of such products with the Technology as
|
||||
delivered by Original Contributor; and
|
||||
|
||||
Original Contributor desires to license certain Trademarks for the
|
||||
purpose of branding products that are compatible with the relevant
|
||||
Technology delivered by Original Contributor; and
|
||||
|
||||
You desire to license the Technology and possibly certain Trademarks
|
||||
from Original Contributor on the terms and conditions specified in this
|
||||
License.
|
||||
|
||||
In consideration for the mutual covenants contained herein, You and
|
||||
Original Contributor agree as follows:
|
||||
|
||||
|
||||
AGREEMENT
|
||||
|
||||
*1. Introduction.*
|
||||
|
||||
The RealNetworks Community Source License ("RCSL") and effective
|
||||
attachments ("License") may include five distinct licenses:
|
||||
|
||||
i) Research Use license -- License plus Attachments A, B and C only.
|
||||
|
||||
ii) Commercial Use and Trademark License, which may be for Internal
|
||||
Deployment Use or external distribution, or both -- License plus
|
||||
Attachments A, B, C, and D.
|
||||
|
||||
iii) Technology Compatibility Kit (TCK) license -- Attachment C.
|
||||
|
||||
iv) Add-On Technology License (Executable) Commercial Use License
|
||||
-Attachment F.
|
||||
|
||||
v) Add-On Technology Source Code Porting and Optimization
|
||||
License-Attachment G.
|
||||
|
||||
The Research Use license is effective when You click and accept this
|
||||
License. The TCK is effective when You click and accept this License,
|
||||
unless otherwise specified in the TCK attachments. The Commercial Use
|
||||
and Trademark, Add-On Technology License, and the Add-On Technology
|
||||
Source Code Porting and Optimization licenses must each be signed by You
|
||||
and Original Contributor to become effective. Once effective, these
|
||||
licenses and the associated requirements and responsibilities are
|
||||
cumulative. Capitalized terms used in this License are defined in the
|
||||
Glossary.
|
||||
|
||||
*2. License Grants.*
|
||||
|
||||
2.1 Original Contributor Grant.
|
||||
|
||||
Subject to Your compliance with Sections 3, 8.10 and Attachment A of
|
||||
this License, Original Contributor grants to You a worldwide,
|
||||
royalty-free, non-exclusive license, to the extent of Original
|
||||
Contributor's Intellectual Property Rights covering the Original Code,
|
||||
Upgraded Code and Specifications, to do the following:
|
||||
|
||||
(a) Research Use License:
|
||||
|
||||
(i) use, reproduce and modify the Original Code, Upgraded Code and
|
||||
Specifications to create Modifications and Reformatted Specifications
|
||||
for Research Use by You;
|
||||
|
||||
(ii) publish and display Original Code, Upgraded Code and Specifications
|
||||
with, or as part of Modifications, as permitted under Section 3.1(b) below;
|
||||
|
||||
(iii) reproduce and distribute copies of Original Code and Upgraded Code
|
||||
to Licensees and students for Research Use by You;
|
||||
|
||||
(iv) compile, reproduce and distribute Original Code and Upgraded Code
|
||||
in Executable form, and Reformatted Specifications to anyone for
|
||||
Research Use by You.
|
||||
|
||||
(b) Other than the licenses expressly granted in this License, Original
|
||||
Contributor retains all right, title, and interest in Original Code and
|
||||
Upgraded Code and Specifications.
|
||||
|
||||
2.2 Your Grants.
|
||||
|
||||
(a) To Other Licensees. You hereby grant to each Licensee a license to
|
||||
Your Error Corrections and Shared Modifications, of the same scope and
|
||||
extent as Original Contributor's licenses under Section 2.1 a) above
|
||||
relative to Research Use and Attachment D relative to Commercial Use.
|
||||
|
||||
(b) To Original Contributor. You hereby grant to Original Contributor a
|
||||
worldwide, royalty-free, non-exclusive, perpetual and irrevocable
|
||||
license, to the extent of Your Intellectual Property Rights covering
|
||||
Your Error Corrections, Shared Modifications and Reformatted
|
||||
Specifications, to use, reproduce, modify, display and distribute Your
|
||||
Error Corrections, Shared Modifications and Reformatted Specifications,
|
||||
in any form, including the right to sublicense such rights through
|
||||
multiple tiers of distribution.
|
||||
|
||||
(c) Other than the licenses expressly granted in Sections 2.2(a) and (b)
|
||||
above, and the restrictions set forth in Section 3.1(d)(iv) below, You
|
||||
retain all right, title, and interest in Your Error Corrections, Shared
|
||||
Modifications and Reformatted Specifications.
|
||||
|
||||
2.3 Contributor Modifications.
|
||||
|
||||
You may use, reproduce, modify, display and distribute Contributor Error
|
||||
Corrections, Shared Modifications and Reformatted Specifications,
|
||||
obtained by You under this License, to the same scope and extent as with
|
||||
Original Code, Upgraded Code and Specifications.
|
||||
|
||||
2.4 Subcontracting.
|
||||
|
||||
You may deliver the Source Code of Covered Code to other Licensees
|
||||
having at least a Research Use license, for the sole purpose of
|
||||
furnishing development services to You in connection with Your rights
|
||||
granted in this License. All such Licensees must execute appropriate
|
||||
documents with respect to such work consistent with the terms of this
|
||||
License, and acknowledging their work-made-for-hire status or assigning
|
||||
exclusive right to the work product and associated Intellectual Property
|
||||
Rights to You.
|
||||
|
||||
*3. Requirements and Responsibilities*.
|
||||
|
||||
3.1 Research Use License.
|
||||
|
||||
As a condition of exercising the rights granted under Section 2.1(a)
|
||||
above, You agree to comply with the following:
|
||||
|
||||
(a) Your Contribution to the Community. All Error Corrections and Shared
|
||||
Modifications which You create or contribute to are automatically
|
||||
subject to the licenses granted under Section 2.2 above. You are
|
||||
encouraged to license all of Your other Modifications under Section 2.2
|
||||
as Shared Modifications, but are not required to do so. You agree to
|
||||
notify Original Contributor of any errors in the Specification.
|
||||
|
||||
(b) Source Code Availability. You agree to provide all Your Error
|
||||
Corrections to Original Contributor as soon as reasonably practicable
|
||||
and, in any event, prior to Internal Deployment Use or Commercial Use,
|
||||
if applicable. Original Contributor may, at its discretion, post Source
|
||||
Code for Your Error Corrections and Shared Modifications on the
|
||||
Community Webserver. You may also post Error Corrections and Shared
|
||||
Modifications on a web-server of Your choice; provided, that You must
|
||||
take reasonable precautions to ensure that only Licensees have access to
|
||||
such Error Corrections and Shared Modifications. Such precautions shall
|
||||
include, without limitation, a password protection scheme limited to
|
||||
Licensees and a click-on, download certification of Licensee status
|
||||
required of those attempting to download from the server. An example of
|
||||
an acceptable certification is attached as Attachment A-2.
|
||||
|
||||
(c) Notices. All Error Corrections and Shared Modifications You create
|
||||
or contribute to must include a file documenting the additions and
|
||||
changes You made and the date of such additions and changes. You must
|
||||
also include the notice set forth in Attachment A-1 in the file header.
|
||||
If it is not possible to put the notice in a particular Source Code file
|
||||
due to its structure, then You must include the notice in a location
|
||||
(such as a relevant directory file), where a recipient would be most
|
||||
likely to look for such a notice.
|
||||
|
||||
(d) Redistribution.
|
||||
|
||||
(i) Source. Covered Code may be distributed in Source Code form only to
|
||||
another Licensee (except for students as provided below). You may not
|
||||
offer or impose any terms on any Covered Code that alter the rights,
|
||||
requirements, or responsibilities of such Licensee. You may distribute
|
||||
Covered Code to students for use in connection with their course work
|
||||
and research projects undertaken at accredited educational institutions.
|
||||
Such students need not be Licensees, but must be given a copy of the
|
||||
notice set forth in Attachment A-3 and such notice must also be included
|
||||
in a file header or prominent location in the Source Code made available
|
||||
to such students.
|
||||
|
||||
(ii) Executable. You may distribute Executable version(s) of Covered
|
||||
Code to Licensees and other third parties only for the purpose of
|
||||
evaluation and comment in connection with Research Use by You and under
|
||||
a license of Your choice, but which limits use of such Executable
|
||||
version(s) of Covered Code only to that purpose.
|
||||
|
||||
(iii) Modified Class, Interface and Package Naming. In connection with
|
||||
Research Use by You only, You may use Original Contributor's class,
|
||||
Interface and package names only to accurately reference or invoke the
|
||||
Source Code files You modify. Original Contributor grants to You a
|
||||
limited license to the extent necessary for such purposes.
|
||||
|
||||
(iv) You expressly agree that any distribution, in whole or in part, of
|
||||
Modifications developed by You shall only be done pursuant to the terms
|
||||
and conditions of this License.
|
||||
|
||||
(e) Extensions.
|
||||
|
||||
(i) Covered Code. You may not include any Source Code of Community Code
|
||||
in any Extensions. You may include the compiled Header Files of
|
||||
Community Code in an Extension provided that Your use of the Covered
|
||||
Code, including Heading Files, complies with the Commercial Use License,
|
||||
the TCK and all other terms of this License.
|
||||
|
||||
(ii) Publication. No later than the date on which You first distribute
|
||||
such Extension for Commercial Use, You must publish to the industry, on
|
||||
a non-confidential basis and free of all copyright restrictions with
|
||||
respect to reproduction and use, an accurate and current specification
|
||||
for any Extension. In addition, You must make available an appropriate
|
||||
test suite, pursuant to the same rights as the specification,
|
||||
sufficiently detailed to allow any third party reasonably skilled in the
|
||||
technology to produce implementations of the Extension compatible with
|
||||
the specification. Such test suites must be made available as soon as
|
||||
reasonably practicable but, in no event, later than ninety (90) days
|
||||
after Your first Commercial Use of the Extension. You must use
|
||||
reasonable efforts to promptly clarify and correct the specification and
|
||||
the test suite upon written request by Original Contributor.
|
||||
|
||||
(iii) Open. You agree to refrain from enforcing any Intellectual
|
||||
Property Rights You may have covering any interface(s) of Your
|
||||
Extension, which would prevent the implementation of such interface(s)
|
||||
by Original Contributor or any Licensee. This obligation does not
|
||||
prevent You from enforcing any Intellectual Property Right You have that
|
||||
would otherwise be infringed by an implementation of Your Extension.
|
||||
|
||||
(iv) Interface Modifications and Naming. You may not modify or add to
|
||||
the GUID space * * "xxxxxxxx-0901-11d1-8B06-00A024406D59" or any other
|
||||
GUID space designated by Original Contributor. You may not modify any
|
||||
Interface prefix provided with the Covered Code or any other prefix
|
||||
designated by Original Contributor.* *
|
||||
|
||||
* *
|
||||
|
||||
(f) You agree that any Specifications provided to You by Original
|
||||
Contributor are confidential and proprietary information of Original
|
||||
Contributor. You must maintain the confidentiality of the Specifications
|
||||
and may not disclose them to any third party without Original
|
||||
Contributor's prior written consent. You may only use the Specifications
|
||||
under the terms of this License and only for the purpose of implementing
|
||||
the terms of this License with respect to Covered Code. You agree not
|
||||
use, copy or distribute any such Specifications except as provided in
|
||||
writing by Original Contributor.
|
||||
|
||||
3.2 Commercial Use License.
|
||||
|
||||
You may not make Commercial Use of any Covered Code unless You and
|
||||
Original Contributor have executed a copy of the Commercial Use and
|
||||
Trademark License attached as Attachment D.
|
||||
|
||||
*4. Versions of the License.*
|
||||
|
||||
4.1 License Versions.
|
||||
|
||||
Original Contributor may publish revised versions of the License from
|
||||
time to time. Each version will be given a distinguishing version number.
|
||||
|
||||
4.2 Effect.
|
||||
|
||||
Once a particular version of Covered Code has been provided under a
|
||||
version of the License, You may always continue to use such Covered Code
|
||||
under the terms of that version of the License. You may also choose to
|
||||
use such Covered Code under the terms of any subsequent version of the
|
||||
License. No one other than Original Contributor has the right to
|
||||
promulgate License versions.
|
||||
|
||||
4.3 Multiple-Licensed Code.
|
||||
|
||||
Original Contributor may designate portions of the Covered Code as
|
||||
"Multiple-Licensed." "Multiple-Licensed" means that the Original
|
||||
Contributor permits You to utilize those designated portions of the
|
||||
Covered Code under Your choice of this License or the alternative
|
||||
license(s), if any, specified by the Original Contributor in an
|
||||
Attachment to this License.
|
||||
|
||||
*5. Disclaimer of Warranty.*
|
||||
|
||||
5.1 COVERED CODE PROVIDED AS IS.
|
||||
|
||||
COVERED CODE IS PROVIDED UNDER THIS LICENSE "AS IS," WITHOUT WARRANTY OF
|
||||
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
|
||||
WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT
|
||||
FOR A PARTICULAR PURPOSE OR NON-INFRINGING. YOU AGREE TO BEAR THE ENTIRE
|
||||
RISK IN CONNECTION WITH YOUR USE AND DISTRIBUTION OF COVERED CODE UNDER
|
||||
THIS LICENSE. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART
|
||||
OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER
|
||||
EXCEPT SUBJECT TO THIS DISCLAIMER.
|
||||
|
||||
5.2 Not Designed for High Risk Activities.
|
||||
|
||||
You acknowledge that Original Code, Upgraded Code and Specifications are
|
||||
not designed or intended for use in high risk activities including, but
|
||||
not limited to: (i) on-line control of aircraft, air traffic, aircraft
|
||||
navigation or aircraft communications; or (ii) in the design,
|
||||
construction, operation or maintenance of any nuclear facility. Original
|
||||
Contributor disclaims any express or implied warranty of fitness for
|
||||
such uses.
|
||||
|
||||
*6. Termination.*
|
||||
|
||||
6.1 By You.
|
||||
|
||||
You may terminate this Research Use license at anytime by providing
|
||||
written notice to Original Contributor.
|
||||
|
||||
6.2 By Original Contributor.
|
||||
|
||||
This License and the rights granted hereunder will terminate:
|
||||
|
||||
(i) automatically if You fail to comply with the terms of this License
|
||||
and fail to cure such breach within 30 days of receipt of written notice
|
||||
of the breach;
|
||||
|
||||
(ii) immediately in the event of circumstances specified in Sections 7.1
|
||||
and 8.4; or
|
||||
|
||||
(iii) at Original Contributor's discretion upon any action initiated by
|
||||
You (including by cross-claim or counter claim) alleging that use or
|
||||
distribution by Original Contributor or any Licensee, of Original Code,
|
||||
Upgraded Code, Error Corrections, Shared Modifications or Specifications
|
||||
infringe a patent owned or controlled by You.
|
||||
|
||||
6.3 Effective of Termination.
|
||||
|
||||
Upon termination, You agree to discontinue use of and destroy all copies
|
||||
of Covered Code in Your possession. All sublicenses to the Covered Code
|
||||
which You have properly granted shall survive any termination of this
|
||||
License. Provisions that, by their nature, should remain in effect
|
||||
beyond the termination of this License shall survive including, without
|
||||
limitation, Sections 2.2, 3, 5, 7 and 8.
|
||||
|
||||
6.4 No Compensation.
|
||||
|
||||
Each party waives and releases the other from any claim to compensation
|
||||
or indemnity for permitted or lawful termination of the business
|
||||
relationship established by this License.
|
||||
|
||||
*7. Liability.*
|
||||
|
||||
7.1 Infringement. Should any of the Original Code, Upgraded Code, TCK or
|
||||
Specifications ("Materials") become the subject of a claim of
|
||||
infringement, Original Contributor may, at its sole option, (i) attempt
|
||||
to procure the rights necessary for You to continue using the Materials,
|
||||
(ii) modify the Materials so that they are no longer infringing, or
|
||||
(iii) terminate Your right to use the Materials, immediately upon
|
||||
written notice, and refund to You the amount, if any, having then
|
||||
actually been paid by You to Original Contributor for the Original Code,
|
||||
Upgraded Code and TCK, depreciated on a straight line, five year basis.
|
||||
|
||||
7.2 LIMITATION OF LIABILITY. TO THE FULL EXTENT ALLOWED BY APPLICABLE
|
||||
LAW, ORIGINAL CONTRIBUTOR'S LIABILITY TO YOU FOR CLAIMS RELATING TO THIS
|
||||
LICENSE, WHETHER FOR BREACH OR IN TORT, SHALL BE LIMITED TO ONE HUNDRED
|
||||
PERCENT (100%) OF THE AMOUNT HAVING THEN ACTUALLY BEEN PAID BY YOU TO
|
||||
ORIGINAL CONTRIBUTOR FOR ALL COPIES LICENSED HEREUNDER OF THE PARTICULAR
|
||||
ITEMS GIVING RISE TO SUCH CLAIM, IF ANY, DURING THE TWELVE MONTHS
|
||||
PRECEDING THE CLAIMED BREACH. IN NO EVENT WILL YOU (RELATIVE TO YOUR
|
||||
SHARED MODIFICATIONS OR ERROR CORRECTIONS) OR ORIGINAL CONTRIBUTOR BE
|
||||
LIABLE FOR ANY INDIRECT, PUNITIVE, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
|
||||
DAMAGES IN CONNECTION WITH OR RISING OUT OF THIS LICENSE (INCLUDING,
|
||||
WITHOUT LIMITATION, LOSS OF PROFITS, USE, DATA, OR OTHER ECONOMIC
|
||||
ADVANTAGE), HOWEVER IT ARISES AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
AN ACTION FOR CONTRACT, STRICT LIABILITY OR TORT (INCLUDING NEGLIGENCE)
|
||||
OR OTHERWISE, WHETHER OR NOT YOU OR ORIGINAL CONTRIBUTOR HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE AND NOTWITHSTANDING THE
|
||||
FAILURE OF ESSENTIAL PURPOSE OF ANY REMEDY.
|
||||
|
||||
*8. Miscellaneous.*
|
||||
|
||||
8.1 Trademark.
|
||||
|
||||
You shall not use any Trademark unless You and Original Contributor
|
||||
execute a copy of the Commercial Use and Trademark License Agreement
|
||||
attached hereto as Attachment D. Except as expressly provided in the
|
||||
License, You are granted no right, title or license to, or interest in,
|
||||
any Trademarks. Whether or not You and Original Contributor enter into
|
||||
the Trademark License, You agree not to (i) challenge Original
|
||||
Contributor's ownership or use of Trademarks; (ii) attempt to register
|
||||
any Trademarks, or any mark or logo substantially similar thereto; or
|
||||
(iii) incorporate any Trademarks into Your own trademarks, product
|
||||
names, service marks, company names, or domain names.
|
||||
|
||||
8.2 Integration.
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof.
|
||||
|
||||
8.3 Assignment.
|
||||
|
||||
Original Contributor may assign this License, and its rights and
|
||||
obligations hereunder, in its sole discretion. You may assign the
|
||||
Research Use portions of this License and the TCK license to a third
|
||||
party upon prior written notice to Original Contributor (which may be
|
||||
provided electronically via the Community Web-Server). You may not
|
||||
assign the Commercial Use and Trademark license, the Add-On Technology
|
||||
License, or the Add-On Technology Source Code Porting License, including
|
||||
by way of merger (regardless of whether You are the surviving entity) or
|
||||
acquisition, without Original Contributor's prior written consent.
|
||||
|
||||
8.4 Severability.
|
||||
|
||||
If any provision of this License is held to be unenforceable, such
|
||||
provision shall be reformed only to the extent necessary to make it
|
||||
enforceable. Notwithstanding the foregoing, if You are prohibited by law
|
||||
from fully and specifically complying with Sections 2.2 or 3, this
|
||||
License will immediately terminate and You must immediately discontinue
|
||||
any use of Covered Code.
|
||||
|
||||
8.5 Governing Law.
|
||||
|
||||
This License shall be governed by the laws of the United States and the
|
||||
State of Washington, as applied to contracts entered into and to be
|
||||
performed in Washington between Washington residents. The application of
|
||||
the United Nations Convention on Contracts for the International Sale of
|
||||
Goods is expressly excluded. You agree that the state and federal courts
|
||||
located in Seattle, Washington have exclusive jurisdiction over any
|
||||
claim relating to the License, including contract and tort claims.
|
||||
|
||||
8.6 Dispute Resolution.
|
||||
|
||||
a) Arbitration. Any dispute arising out of or relating to this License
|
||||
shall be finally settled by arbitration as set out herein, except that
|
||||
either party may bring any action, in a court of competent jurisdiction
|
||||
(which jurisdiction shall be exclusive), with respect to any dispute
|
||||
relating to such party's Intellectual Property Rights or with respect to
|
||||
Your compliance with the TCK license. Arbitration shall be administered:
|
||||
(i) by the American Arbitration Association (AAA), (ii) in accordance
|
||||
with the rules of the United Nations Commission on International Trade
|
||||
Law (UNCITRAL) (the "Rules") in effect at the time of arbitration as
|
||||
modified herein; and (iii) the arbitrator will apply the substantive
|
||||
laws of Washington and the United States. Judgment upon the award
|
||||
rendered by the arbitrator may be entered in any court having
|
||||
jurisdiction to enforce such award.
|
||||
|
||||
b) Arbitration language, venue and damages. All arbitration proceedings
|
||||
shall be conducted in English by a single arbitrator selected in
|
||||
accordance with the Rules, who must be fluent in English and be either a
|
||||
retired judge or practicing attorney having at least ten (10) years
|
||||
litigation experience and be reasonably familiar with the technology
|
||||
matters relative to the dispute. Unless otherwise agreed, arbitration
|
||||
venue shall be in Seattle, Washington. The arbitrator may award monetary
|
||||
damages only and nothing shall preclude either party from seeking
|
||||
provisional or emergency relief from a court of competent jurisdiction.
|
||||
The arbitrator shall have no authority to award damages in excess of
|
||||
those permitted in this License and any such award in excess is void.
|
||||
All awards will be payable in U.S. dollars and may include, for the
|
||||
prevailing party (i) pre-judgment award interest, (ii) reasonable
|
||||
attorneys' fees incurred in connection with the arbitration, and (iii)
|
||||
reasonable costs and expenses incurred in enforcing the award. The
|
||||
arbitrator will order each party to produce identified documents and
|
||||
respond to no more than twenty-five single question interrogatories.
|
||||
|
||||
8.7 Construction.
|
||||
|
||||
Any law or regulation, which provides that the language of a contract
|
||||
shall be construed against the drafter, shall not apply to this License.
|
||||
|
||||
8.8 U.S. Government End Users.
|
||||
|
||||
The Covered Code is a "commercial item," as that term is defined in 48
|
||||
C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software"
|
||||
and "commercial computer software documentation," as such terms are used
|
||||
in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and
|
||||
48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government
|
||||
End Users acquire Covered Code with only those rights set forth herein.
|
||||
You agree to pass this notice to our licensees.
|
||||
|
||||
8.9 Marketing Activities.
|
||||
|
||||
Licensee hereby grants Original Contributor a non-exclusive,
|
||||
non-transferable, limited license to use the Licensee's company name and
|
||||
logo ("Licensee Marks") in any presentations, press releases, or
|
||||
marketing materials solely for the purpose of identifying Licensee as a
|
||||
member of the Helix Community. Licensee shall provide samples of
|
||||
Licensee Marks to Original Contributor upon request by Original
|
||||
Contributor. Original Contributor acknowledges that the Licensee Marks
|
||||
are the trademarks of Licensee. Original Contributor shall not use the
|
||||
Licensee Marks in a way that may imply that Original Contributor is an
|
||||
agency or branch of Licensee. Original Contributor understands and
|
||||
agrees that the use of any Licensee Marks in connection with this
|
||||
Agreement shall not create any right, title or interest, in, or to the
|
||||
Licensee Marks or any Licensee trademarks and that all such use and
|
||||
goodwill associated with any such trademarks will inure to the benefit
|
||||
of Licensee. Further the Original Contributor will stop usage of the
|
||||
Licensee Marks upon Licensee's request.
|
||||
|
||||
8.10 Press Announcements.
|
||||
|
||||
You may make press announcements or other public statements regarding
|
||||
this License without the prior written consent of the Original
|
||||
Contributor, if Your statement is limited to announcing the licensing of
|
||||
the Covered Code or the availability of Your Product and its
|
||||
compatibility with the Covered Code. All other public announcements
|
||||
regarding this license require the prior written consent of the Original
|
||||
Contributor. Consent requests are welcome at press@helixcommunity.org.
|
||||
|
||||
8.11 International Use.
|
||||
|
||||
a) Export/Import laws. Covered Code is subject to U.S. export control
|
||||
laws and may be subject to export or import regulations in other
|
||||
countries. Each party agrees to comply strictly with all such laws and
|
||||
regulations and acknowledges their responsibility to obtain such
|
||||
licenses to export, re-export, or import as may be required. You agree
|
||||
to pass these obligations to Your licensees.
|
||||
|
||||
b) Intellectual Property Protection. Due to limited intellectual
|
||||
property protection and enforcement in certain countries, You agree not
|
||||
to redistribute the Original Code, Upgraded Code, TCK and Specifications
|
||||
to any country on the list of restricted countries on the Community Web
|
||||
Server.
|
||||
|
||||
8.12 Language.
|
||||
|
||||
This License is in the English language only, which language shall be
|
||||
controlling in all respects, and all versions of this License in any
|
||||
other language shall be for accommodation only and shall not be binding
|
||||
on the parties to this License. All communications and notices made or
|
||||
given pursuant to this License, and all documentation and support to be
|
||||
provided, unless otherwise noted, shall be in the English language.
|
||||
|
||||
PLEASE READ THE TERMS OF THIS LICENSE CAREFULLY. BY CLICKING ON THE
|
||||
"ACCEPT" BUTTON BELOW YOU ARE ACCEPTING AND AGREEING TO THE TERMS AND
|
||||
CONDITIONS OF THIS LICENSE WITH REALNETWORKS, INC. IF YOU ARE AGREEING
|
||||
TO THIS LICENSE ON BEHALF OF A COMPANY, YOU REPRESENT THAT YOU ARE
|
||||
AUTHORIZED TO BIND THE COMPANY TO SUCH A LICENSE. WHETHER YOU ARE ACTING
|
||||
ON YOUR OWN BEHALF, OR REPRESENTING A COMPANY, YOU MUST BE OF MAJORITY
|
||||
AGE AND BE OTHERWISE COMPETENT TO ENTER INTO CONTRACTS. IF YOU DO NOT
|
||||
MEET THIS CRITERIA OR YOU DO NOT AGREE TO ANY OF THE TERMS AND
|
||||
CONDITIONS OF THIS LICENSE, CLICK ON THE REJECT BUTTON TO EXIT.
|
||||
|
||||
|
||||
GLOSSARY
|
||||
|
||||
1. *"Added Value"* means code which:
|
||||
|
||||
(i) has a principal purpose which is substantially different from that
|
||||
of the stand-alone Technology;
|
||||
|
||||
(ii) represents a significant functional and value enhancement to the
|
||||
Technology;
|
||||
|
||||
(iii) operates in conjunction with the Technology; and
|
||||
|
||||
(iv) is not marketed as a technology which replaces or substitutes for
|
||||
the Technology
|
||||
|
||||
2. "*Applicable Patent Rights*" mean: (a) in the case where Original
|
||||
Contributor is the grantor of rights, claims of patents that (i) are now
|
||||
or hereafter acquired, owned by or assigned to Original Contributor and
|
||||
(ii) are necessarily infringed by using or making the Original Code or
|
||||
Upgraded Code, including Modifications provided by Original Contributor,
|
||||
alone and not in combination with other software or hardware; and (b) in
|
||||
the case where Licensee is the grantor of rights, claims of patents that
|
||||
(i) are now or hereafter acquired, owned by or assigned to Licensee and
|
||||
(ii) are infringed (directly or indirectly) by using or making
|
||||
Licensee's Modifications or Error Corrections, taken alone or in
|
||||
combination with Covered Code.
|
||||
|
||||
3. "*Application Programming Interfaces (APIs)"* means the interfaces,
|
||||
associated header files, service provider interfaces, and protocols that
|
||||
enable a device, application, Operating System, or other program to
|
||||
obtain services from or make requests of (or provide services in
|
||||
response to requests from) other programs, and to use, benefit from, or
|
||||
rely on the resources, facilities, and capabilities of the relevant
|
||||
programs using the APIs. APIs includes the technical documentation
|
||||
describing the APIs, the Source Code constituting the API, and any
|
||||
Header Files used with the APIs.
|
||||
|
||||
4. "*Commercial Use*" means any use (internal or external), copying,
|
||||
sublicensing or distribution (internal or external), directly or
|
||||
indirectly of Covered Code by You other than Your Research Use of
|
||||
Covered Code within Your business or organization or in conjunction with
|
||||
other Licensees with equivalent Research Use rights. Commercial Use
|
||||
includes any use of the Covered Code for direct or indirect commercial
|
||||
or strategic gain, advantage or other business purpose. Any Commercial
|
||||
Use requires execution of Attachment D by You and Original Contributor.
|
||||
|
||||
5. "*Community Code*" means the Original Code, Upgraded Code, Error
|
||||
Corrections, Shared Modifications, or any combination thereof.
|
||||
|
||||
6. "*Community Webserver(s)"* means the webservers designated by
|
||||
Original Contributor for access to the Original Code, Upgraded Code, TCK
|
||||
and Specifications and for posting Error Corrections and Shared
|
||||
Modifications.
|
||||
|
||||
7. "*Compliant Covered Code*" means Covered Code that complies with the
|
||||
requirements of the TCK.
|
||||
|
||||
8. "*Contributor*" means each Licensee that creates or contributes to
|
||||
the creation of any Error Correction or Shared Modification.
|
||||
|
||||
9. "*Covered Code*" means the Original Code, Upgraded Code,
|
||||
Modifications, or any combination thereof.
|
||||
|
||||
10. "*Error Correction*" means any change made to Community Code which
|
||||
conforms to the Specification and corrects the adverse effect of a
|
||||
failure of Community Code to perform any function set forth in or
|
||||
required by the Specifications.
|
||||
|
||||
11. "*Executable*" means Covered Code that has been converted from
|
||||
Source Code to the preferred form for execution by a computer or digital
|
||||
processor (e.g. binary form).
|
||||
|
||||
12. "*Extension(s)"* means any additional Interfaces developed by or for
|
||||
You which: (i) are designed for use with the Technology; (ii) constitute
|
||||
an API for a library of computing functions or services; and (iii) are
|
||||
disclosed or otherwise made available to third party software developers
|
||||
for the purpose of developing software which invokes such additional
|
||||
Interfaces. The foregoing shall not apply to software developed by Your
|
||||
subcontractors to be exclusively used by You.
|
||||
|
||||
13. "*Header File(s)"* means that portion of the Source Code that
|
||||
provides the names and types of member functions, data members, class
|
||||
definitions, and interface definitions necessary to implement the APIs
|
||||
for the Covered Code. Header Files include, files specifically
|
||||
designated by Original Contributor as Header Files. Header Files do not
|
||||
include the code necessary to implement the functionality underlying the
|
||||
Interface.
|
||||
|
||||
14. *"Helix DNA Server Technology"* means the program(s) that implement
|
||||
the Helix Universal Server streaming engine for the Technology as
|
||||
defined in the Specification.
|
||||
|
||||
15. *"Helix DNA Client Technology"* means the Covered Code that
|
||||
implements the RealOne Player engine as defined in the Specification.
|
||||
|
||||
16. *"Helix DNA Producer Technology"* means the Covered Code that
|
||||
implements the Helix Producer engine as defined in the Specification.
|
||||
|
||||
17. *"Helix DNA Technology"* means the Helix DNA Server Technology, the
|
||||
Helix DNA Client Technology, the Helix DNA Producer Technology and other
|
||||
Helix technologies designated by Original Contributor.
|
||||
|
||||
18. "*Intellectual Property Rights*" means worldwide statutory and
|
||||
common law rights associated solely with (i) Applicable Patent Rights;
|
||||
(ii) works of authorship including copyrights, copyright applications,
|
||||
copyright registrations and "moral rights"; (iii) the protection of
|
||||
trade and industrial secrets and confidential information; and (iv)
|
||||
divisions, continuations, renewals, and re-issuances of the foregoing
|
||||
now existing or acquired in the future.
|
||||
|
||||
19. *"Interface*" means interfaces, functions, properties, class
|
||||
definitions, APIs, Header Files, GUIDs, V-Tables, and/or protocols
|
||||
allowing one piece of software, firmware or hardware to communicate or
|
||||
interoperate with another piece of software, firmware or hardware.
|
||||
|
||||
20. "*Internal Deployment Use*" means use of Compliant Covered Code
|
||||
(excluding Research Use) within Your business or organization only by
|
||||
Your employees and/or agents on behalf of Your business or organization,
|
||||
but not to provide services, including content distribution, to third
|
||||
parties, subject to execution of Attachment D by You and Original
|
||||
Contributor, if required.
|
||||
|
||||
21. "*Licensee*" means any party that has entered into and has in effect
|
||||
a version of this License with Original Contributor.
|
||||
|
||||
22. "*MIME type*" means a description of what type of media or other
|
||||
content is in a file, including by way of example but not limited to
|
||||
'audio/x-pn-realaudio-plugin.'
|
||||
|
||||
23. "*Modification(s)"* means (i) any addition to, deletion from and/or
|
||||
change to the substance and/or structure of the Covered Code, including
|
||||
Interfaces; (ii) the combination of any Covered Code and any previous
|
||||
Modifications; (iii) any new file or other representation of computer
|
||||
program statements that contains any portion of Covered Code; and/or
|
||||
(iv) any new Source Code implementing any portion of the Specifications.
|
||||
|
||||
24. "*MP3 Patents*" means any patents necessary to make, use or sell
|
||||
technology implementing any portion of the specification developed by
|
||||
the Moving Picture Experts Group known as MPEG-1 Audio Layer-3 or MP3,
|
||||
including but not limited to all past and future versions, profiles,
|
||||
extensions, parts and amendments relating to the MP3 specification.
|
||||
|
||||
25. "*MPEG-4 Patents*" means any patents necessary to make, use or sell
|
||||
technology implementing any portion of the specification developed by
|
||||
the Moving Pictures Experts Group known as MPEG-4, including but not
|
||||
limited to all past and future versions, profiles, extensions, parts and
|
||||
amendments relating to the MPEG-4 specification.
|
||||
|
||||
26. "*Original Code*" means the initial Source Code for the Technology
|
||||
as described on the Community Web Server.
|
||||
|
||||
27. "*Original Contributor*" means RealNetworks, Inc., its affiliates
|
||||
and its successors and assigns.
|
||||
|
||||
28. "*Original Contributor MIME Type*" means the MIME registry, browser
|
||||
preferences, or local file/protocol associations invoking any Helix DNA
|
||||
Client-based application, including the RealOne Player, for playback of
|
||||
RealAudio, RealVideo, other RealMedia MIME types or datatypes (e.g.,
|
||||
.ram, .rnx, .rpm, .ra, .rm, .rp, .rt, .rf, .prx, .mpe, .rmp, .rmj, .rav,
|
||||
.rjs, .rmx, .rjt, .rms), and any other Original Contributor-specific or
|
||||
proprietary MIME types that Original Contributor may introduce in the
|
||||
future.
|
||||
|
||||
29. "*Personal Use*" means use of Covered Code by an individual solely
|
||||
for his or her personal, private and non-commercial purposes. An
|
||||
individual's use of Covered Code in his or her capacity as an officer,
|
||||
employee, member, independent contractor or agent of a corporation,
|
||||
business or organization (commercial or non-commercial) does not qualify
|
||||
as Personal Use.
|
||||
|
||||
30. "*RealMedia File Format*" means the file format designed and
|
||||
developed by RealNetworks for storing multimedia data and used to store
|
||||
RealAudio and RealVideo encoded streams. Valid RealMedia File Format
|
||||
extensions include: .rm, .rmj, .rmc, .rmvb, .rms.
|
||||
|
||||
31. "*RCSL Webpage*" means the RealNetworks Community Source License
|
||||
webpage located at https://www.helixcommunity.org/content/rcsl or such
|
||||
other URL that Original Contributor may designate from time to time.
|
||||
|
||||
32. "*Reformatted Specifications*" means any revision to the
|
||||
Specifications which translates or reformats the Specifications (as for
|
||||
example in connection with Your documentation) but which does not alter,
|
||||
subset or superset * *the functional or operational aspects of the
|
||||
Specifications.
|
||||
|
||||
33. "*Research Use*" means use and distribution of Covered Code only for
|
||||
Your Personal Use, research or development use and expressly excludes
|
||||
Internal Deployment Use and Commercial Use. Research Use also includes
|
||||
use of Covered Code to teach individuals how to use Covered Code.
|
||||
|
||||
34. "*Shared Modifications*" means Modifications that You distribute or
|
||||
use for a Commercial Use, in addition to any Modifications provided by
|
||||
You, at Your option, pursuant to Section 2.2, or received by You from a
|
||||
Contributor pursuant to Section 2.3.
|
||||
|
||||
35. "*Source Code*" means the preferred form of the Covered Code for
|
||||
making modifications to it, including all modules it contains, plus any
|
||||
associated interface definition files, scripts used to control
|
||||
compilation and installation of an Executable, or source code
|
||||
differential comparisons against either the Original Code or another
|
||||
well known, available Covered Code of the Contributor's choice. The
|
||||
Source Code can be in a compressed or archival form, provided the
|
||||
appropriate decompression or de-archiving software is widely available
|
||||
for no charge.
|
||||
|
||||
36. "*Specifications*" means the specifications for the Technology and
|
||||
other documentation, as designated on the Community Web Server, as may
|
||||
be revised by Original Contributor from time to time.
|
||||
|
||||
37. "*Trademarks*" means Original Contributor's trademarks and logos,
|
||||
including, but not limited to, RealNetworks, RealAudio, RealVideo,
|
||||
RealOne, RealSystem, SureStream, Helix, Helix DNA and other trademarks
|
||||
whether now used or adopted in the future.
|
||||
|
||||
38. "*Technology*" means the technology described in Attachment B, and
|
||||
Upgrades.
|
||||
|
||||
39. "*Technology Compatibility Kit"* or *"TCK*" means the test programs,
|
||||
procedures, acceptance criteria and/or other requirements, designated by
|
||||
Original Contributor for use in verifying compliance of Covered Code
|
||||
with the Specifications, in conjunction with the Original Code and
|
||||
Upgraded Code. Original Contributor may, in its sole discretion and from
|
||||
time to time, revise a TCK to correct errors and/or omissions and in
|
||||
connection with Upgrades.
|
||||
|
||||
40. "*Upgrade(s)"* means new versions of Technology designated
|
||||
exclusively by Original Contributor as an "Upgrade" and released by
|
||||
Original Contributor from time to time under the terms of the License.
|
||||
|
||||
41. "*Upgraded Code*" means the Source Code and/or Executables for
|
||||
Upgrades, possibly including Modifications made by Contributors.
|
||||
|
||||
42. *"User's Guide"* means the users guide for the TCK which Original
|
||||
Contributor makes available to You to provide direction in how to run
|
||||
the TCK and properly interpret the results, as may be revised by
|
||||
Original Contributor from time to time.
|
||||
|
||||
43. "*You(r)*" means an individual, or a legal entity acting by and
|
||||
through an individual or individuals, exercising rights either under
|
||||
this License or under a future version of this License issued pursuant
|
||||
to Section 4.1. For legal entities, "You(r)" includes any entity that by
|
||||
majority voting interest controls, is controlled by, or is under common
|
||||
control with You.
|
||||
|
||||
44. "*Your Products*" means any (i) hardware products You distribute
|
||||
integrating the Covered Code; (ii) any software products You distribute
|
||||
with the Covered Code that utilize the APIs of the Covered Code; or
|
||||
(iii) any services You provide using the Covered Code.
|
||||
|
||||
|
||||
ATTACHMENT A
|
||||
|
||||
REQUIRED NOTICES
|
||||
|
||||
|
||||
ATTACHMENT A-1
|
||||
|
||||
REQUIRED IN ALL CASES
|
||||
|
||||
Notice to be included in header file of all Error Corrections and Shared
|
||||
Modifications:
|
||||
|
||||
Portions Copyright 1994-2003 © RealNetworks, Inc. All rights reserved.
|
||||
|
||||
The contents of this file, and the files included with this file, are
|
||||
subject to the current version of RealNetworks Community Source License
|
||||
Version 1.1 (the "License"). You may not use this file except in
|
||||
compliance with the License executed by both You and RealNetworks. You
|
||||
may obtain a copy of the License at *
|
||||
https://www.helixcommunity.org/content/rcsl.* You may also obtain a copy
|
||||
of the License by contacting RealNetworks directly. Please see the
|
||||
License for the rights, obligations and limitations governing use of the
|
||||
contents of the file.
|
||||
|
||||
This file is part of the Helix DNA technology. RealNetworks, Inc., is
|
||||
the developer of the Original code and owns the copyrights in the
|
||||
portions it created.
|
||||
|
||||
This file, and the files included with this file, are distributed on an
|
||||
'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
|
||||
LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
_______________________________________________
|
||||
|
||||
Technology Compatibility Kit Test Suite(s) Location:
|
||||
|
||||
________________________________
|
||||
|
||||
|
||||
ATTACHMENT A-2
|
||||
|
||||
SAMPLE LICENSEE CERTIFICATION
|
||||
|
||||
"By clicking the `Agree' button below, You certify that You are a
|
||||
Licensee in good standing under the RealNetworks Community Source
|
||||
License, ("License") and that Your access, use and distribution of code
|
||||
and information You may obtain at this site is subject to the License.
|
||||
If You are not a Licensee under the RealNetworks Community Source
|
||||
License You agree not to download, copy or use the Helix DNA technology.
|
||||
|
||||
|
||||
ATTACHMENT A-3
|
||||
|
||||
REQUIRED STUDENT NOTIFICATION
|
||||
|
||||
"This software and related documentation has been obtained by Your
|
||||
educational institution subject to the RealNetworks Community Source
|
||||
License. You have been provided access to the software and related
|
||||
documentation for use only in connection with your course work and
|
||||
research activities as a matriculated student of Your educational
|
||||
institution. Any other use is expressly prohibited.
|
||||
|
||||
THIS SOFTWARE AND RELATED DOCUMENTATION CONTAINS PROPRIETARY MATERIAL OF
|
||||
REALNETWORKS, INC, WHICH ARE PROTECTED BY VARIOUS INTELLECTUAL PROPERTY
|
||||
RIGHTS.
|
||||
|
||||
You may not use this file except in compliance with the License. You may
|
||||
obtain a copy of the License on the web at
|
||||
https://www.helixcommunity.org/content/rcsl.
|
||||
|
||||
*
|
||||
*
|
||||
|
||||
|
||||
ATTACHMENT B
|
||||
|
||||
Description of Technology
|
||||
|
||||
Helix DNA, which consists of Helix DNA Client, Helix DNA Server and
|
||||
Helix DNA Producer.
|
||||
|
||||
Description of "Technology"
|
||||
|
||||
Helix DNA Technology v1.0 as described on the Community Web Server.
|
||||
|
||||
|
||||
ATTACHMENT C
|
||||
|
||||
TECHNOLOGY COMPATIBILITY KIT LICENSE
|
||||
|
||||
The following license is effective for the *Helix DNA* Technology
|
||||
Compatibility Kit - as described on the Community Web Server. The
|
||||
Technology Compatibility Kit(s) for the Technology specified in
|
||||
Attachment B may be accessed at the Community Web Server.
|
||||
|
||||
1. TCK License.
|
||||
|
||||
1.1 Grants to use TCK
|
||||
|
||||
Subject to the terms and restrictions set forth below and the
|
||||
RealNetworks Community Source License, and the Research Use license,
|
||||
Original Contributor grants to You a worldwide, non-exclusive,
|
||||
non-transferable license, to the extent of Original Contributor's
|
||||
Intellectual Property Rights in the TCK (without the right to
|
||||
sublicense), to use the TCK to develop and test Covered Code.
|
||||
|
||||
1.2 TCK Use Restrictions.
|
||||
|
||||
You are not authorized to create derivative works of the TCK or use the
|
||||
TCK to test any implementation of the Specification that is not Covered
|
||||
Code. You may not publish Your test results or make claims of
|
||||
comparative compatibility with respect to other implementations of the
|
||||
Specification. In consideration for the license grant in Section 1.1
|
||||
above You agree not to develop Your own tests that are intended to
|
||||
validate conformation with the Specification.
|
||||
|
||||
2. Test Results.
|
||||
|
||||
You agree to provide to Original Contributor or the third party test
|
||||
facility if applicable, Your test results that demonstrate that Covered
|
||||
Code is Compliant Covered Code and that Original Contributor may publish
|
||||
or otherwise distribute such test results.
|
||||
|
||||
PLEASE READ THE TERMS OF THIS LICENSE CAREFULLY. BY CLICKING ON THE
|
||||
"ACCEPT" BUTTON BELOW YOU ARE ACCEPTING AND AGREEING TO THE TERMS AND
|
||||
CONDITIONS OF THIS LICENSE WITH THE ORIGINAL CONTRIBUTOR, REALNETWORKS,
|
||||
INC. IF YOU ARE AGREEING TO THIS LICENSE ON BEHALF OF A COMPANY, YOU
|
||||
REPRESENT THAT YOU ARE AUTHORIZED TO BIND THE COMPANY TO SUCH A LICENSE.
|
||||
WHETHER YOU ARE ACTING ON YOUR OWN BEHALF, OR REPRESENTING A COMPANY,
|
||||
YOU MUST BE OF MAJORITY AGE AND BE OTHERWISE COMPETENT TO ENTER INTO
|
||||
CONTRACTS. IF YOU DO NOT MEET THIS CRITERIA OR YOU DO NOT AGREE TO ANY
|
||||
OF THE TERMS AND CONDITIONS OF THIS LICENSE, CLICK ON THE REJECT BUTTON
|
||||
TO EXIT.
|
||||
|
||||
*ACCEPT / REJECT
|
||||
*
|
||||
|
||||
*
|
||||
*
|
||||
|
||||
*To agree to the R&D/academic terms of this license, please register
|
||||
<https://www.helixcommunity.org/2002/intro/why-register> on the site --
|
||||
you will then be given a chance to agree to the clickwrap RCSL
|
||||
<https://reguseronly.helixcommunity.org/2002/clickwrap/rcsl-clickwrap>
|
||||
R&D License
|
||||
<https://reguseronly.helixcommunity.org/2002/clickwrap/rcsl-clickwrap>
|
||||
and gain access to the RCSL-licensed source code. To build or deploy
|
||||
commercial applications based on the RCSL, you will need to agree to the
|
||||
Commercial Use license attachments
|
||||
<https://www.helixcommunity.org/content/rcsl-attachments>*
|
||||
|
||||
|
||||
|
||||
@@ -1,518 +0,0 @@
|
||||
RealNetworks Public Source License Version 1.0
|
||||
(Rev. Date October 28, 2002)
|
||||
|
||||
1. General Definitions. This License applies to any program or other work which
|
||||
RealNetworks, Inc., or any other entity that elects to use this license,
|
||||
("Licensor") makes publicly available and which contains a notice placed by
|
||||
Licensor identifying such program or work as "Original Code" and stating that it
|
||||
is subject to the terms of this RealNetworks Public Source License version 1.0
|
||||
(or subsequent version thereof) ("License"). You are not required to accept this
|
||||
License. However, nothing else grants You permission to use, copy, modify or
|
||||
distribute the software or its derivative works. These actions are prohibited by
|
||||
law if You do not accept this License. Therefore, by modifying, copying or
|
||||
distributing the software (or any work based on the software), You indicate your
|
||||
acceptance of this License to do so, and all its terms and conditions. In
|
||||
addition, you agree to the terms of this License by clicking the Accept button
|
||||
or downloading the software. As used in this License:
|
||||
|
||||
1.1 "Applicable Patent Rights" mean: (a) in the case where Licensor is the
|
||||
grantor of rights, claims of patents that (i) are now or hereafter acquired,
|
||||
owned by or assigned to Licensor and (ii) are necessarily infringed by using or
|
||||
making the Original Code alone and not in combination with other software or
|
||||
hardware; and (b) in the case where You are the grantor of rights, claims of
|
||||
patents that (i) are now or hereafter acquired, owned by or assigned to You and
|
||||
(ii) are infringed (directly or indirectly) by using or making Your
|
||||
Modifications, taken alone or in combination with Original Code.
|
||||
|
||||
1.2 "Compatible Source License" means any one of the licenses listed on Exhibit
|
||||
B or at https://www.helixcommunity.org/content/complicense or other licenses
|
||||
specifically identified by Licensor in writing. Notwithstanding any term to the
|
||||
contrary in any Compatible Source License, any code covered by any Compatible
|
||||
Source License that is used with Covered Code must be made readily available in
|
||||
Source Code format for royalty-free use under the terms of the Compatible Source
|
||||
License or this License.
|
||||
|
||||
1.3 "Contributor" means any person or entity that creates or contributes to the
|
||||
creation of Modifications.
|
||||
|
||||
1.4 "Covered Code" means the Original Code, Modifications, the combination of
|
||||
Original Code and any Modifications, and/or any respective portions thereof.
|
||||
|
||||
1.5 "Deploy" means to use, sublicense or distribute Covered Code other than for
|
||||
Your internal research and development (R&D) and/or Personal Use, and includes
|
||||
without limitation, any and all internal use or distribution of Covered Code
|
||||
within Your business or organization except for R&D use and/or Personal Use, as
|
||||
well as direct or indirect sublicensing or distribution of Covered Code by You
|
||||
to any third party in any form or manner.
|
||||
|
||||
1.6 "Derivative Work" means either the Covered Code or any derivative work under
|
||||
United States copyright law, and including any work containing or including any
|
||||
portion of the Covered Code or Modifications, either verbatim or with
|
||||
modifications and/or translated into another language. Derivative Work also
|
||||
includes any work which combines any portion of Covered Code or Modifications
|
||||
with code not otherwise governed by the terms of this License.
|
||||
|
||||
1.7 "Externally Deploy" means to Deploy the Covered Code in any way that may be
|
||||
accessed or used by anyone other than You, used to provide any services to
|
||||
anyone other than You, or used in any way to deliver any content to anyone other
|
||||
than You, whether the Covered Code is distributed to those parties, made
|
||||
available as an application intended for use over a computer network, or used to
|
||||
provide services or otherwise deliver content to anyone other than You.
|
||||
|
||||
1.8. "Interface" means interfaces, functions, properties, class definitions,
|
||||
APIs, header files, GUIDs, V-Tables, and/or protocols allowing one piece of
|
||||
software, firmware or hardware to communicate or interoperate with another piece
|
||||
of software, firmware or hardware.
|
||||
|
||||
1.9 "Modifications" mean any addition to, deletion from, and/or change to, the
|
||||
substance and/or structure of the Original Code, any previous Modifications, the
|
||||
combination of Original Code and any previous Modifications, and/or any
|
||||
respective portions thereof. When code is released as a series of files, a
|
||||
Modification is: (a) any addition to or deletion from the contents of a file
|
||||
containing Covered Code; and/or (b) any new file or other representation of
|
||||
computer program statements that contains any part of Covered Code.
|
||||
|
||||
1.10 "Original Code" means (a) the Source Code of a program or other work as
|
||||
originally made available by Licensor under this License, including the Source
|
||||
Code of any updates or upgrades to such programs or works made available by
|
||||
Licensor under this License, and that has been expressly identified by Licensor
|
||||
as such in the header file(s) of such work; and (b) the object code compiled
|
||||
from such Source Code and originally made available by Licensor under this
|
||||
License.
|
||||
|
||||
1.11 "Personal Use" means use of Covered Code by an individual solely for his or
|
||||
her personal, private and non-commercial purposes. An individual's use of
|
||||
Covered Code in his or her capacity as an officer, employee, member, independent
|
||||
contractor or agent of a corporation, business or organization (commercial or
|
||||
non-commercial) does not qualify as Personal Use.
|
||||
|
||||
1.12 "Source Code" means the human readable form of a program or other work that
|
||||
is suitable for making modifications to it, including all modules it contains,
|
||||
plus any associated interface definition files, scripts used to control
|
||||
compilation and installation of an executable (object code).
|
||||
|
||||
1.13 "You" or "Your" means an individual or a legal entity exercising rights
|
||||
under this License. For legal entities, "You" or "Your" includes any entity
|
||||
which controls, is controlled by, or is under common control with, You, where
|
||||
"control" means (a) the power, direct or indirect, to cause the direction or
|
||||
management of such entity, whether by contract or otherwise, or (b) ownership of
|
||||
fifty percent (50%) or more of the outstanding shares or beneficial ownership of
|
||||
such entity.
|
||||
|
||||
2. Permitted Uses; Conditions & Restrictions. Subject to the terms and
|
||||
conditions of this License, Licensor hereby grants You, effective on the date
|
||||
You accept this License (via downloading or using Covered Code or otherwise
|
||||
indicating your acceptance of this License), a worldwide, royalty-free,
|
||||
non-exclusive copyright license, to the extent of Licensor's copyrights cover
|
||||
the Original Code, to do the following:
|
||||
|
||||
2.1 You may reproduce, display, perform, modify and Deploy Covered Code,
|
||||
provided that in each instance:
|
||||
|
||||
(a) You must retain and reproduce in all copies of Original Code the copyright
|
||||
and other proprietary notices and disclaimers of Licensor as they appear in the
|
||||
Original Code, and keep intact all notices in the Original Code that refer to
|
||||
this License;
|
||||
|
||||
(b) You must include a copy of this License with every copy of Source Code of
|
||||
Covered Code and documentation You distribute, and You may not offer or impose
|
||||
any terms on such Source Code that alter or restrict this License or the
|
||||
recipients' rights hereunder, except as permitted under Section 6;
|
||||
|
||||
(c) You must duplicate, to the extent it does not already exist, the notice in
|
||||
Exhibit A in each file of the Source Code of all Your Modifications, and cause
|
||||
the modified files to carry prominent notices stating that You changed the files
|
||||
and the date of any change;
|
||||
|
||||
(d) You must make Source Code of all Your Externally Deployed Modifications
|
||||
publicly available under the terms of this License, including the license grants
|
||||
set forth in Section 3 below, for as long as you Deploy the Covered Code or
|
||||
twelve (12) months from the date of initial Deployment, whichever is longer. You
|
||||
should preferably distribute the Source Code of Your Deployed Modifications
|
||||
electronically (e.g. download from a web site); and
|
||||
|
||||
(e) if You Deploy Covered Code in object code, executable form only, You must
|
||||
include a prominent notice, in the code itself as well as in related
|
||||
documentation, stating that Source Code of the Covered Code is available under
|
||||
the terms of this License with information on how and where to obtain such
|
||||
Source Code. You must also include the Object Code Notice set forth in Exhibit A
|
||||
in the "about" box or other appropriate place where other copyright notices are
|
||||
placed, including any packaging materials.
|
||||
|
||||
2.2 You expressly acknowledge and agree that although Licensor and each
|
||||
Contributor grants the licenses to their respective portions of the Covered Code
|
||||
set forth herein, no assurances are provided by Licensor or any Contributor that
|
||||
the Covered Code does not infringe the patent or other intellectual property
|
||||
rights of any other entity. Licensor and each Contributor disclaim any liability
|
||||
to You for claims brought by any other entity based on infringement of
|
||||
intellectual property rights or otherwise. As a condition to exercising the
|
||||
rights and licenses granted hereunder, You hereby assume sole responsibility to
|
||||
secure any other intellectual property rights needed, if any. For example, if a
|
||||
third party patent license is required to allow You to make, use, sell, import
|
||||
or offer for sale the Covered Code, it is Your responsibility to acquire such
|
||||
license(s).
|
||||
|
||||
2.3 Subject to the terms and conditions of this License, Licensor hereby grants
|
||||
You, effective on the date You accept this License (via downloading or using
|
||||
Covered Code or otherwise indicating your acceptance of this License), a
|
||||
worldwide, royalty-free, perpetual, non-exclusive patent license under
|
||||
Licensor's Applicable Patent Rights to make, use, sell, offer for sale and
|
||||
import the Covered Code, provided that in each instance you comply with the
|
||||
terms of this License.
|
||||
|
||||
3. Your Grants. In consideration of, and as a condition to, the licenses granted
|
||||
to You under this License:
|
||||
|
||||
(a) You grant to Licensor and all third parties a non-exclusive, perpetual,
|
||||
irrevocable, royalty free license under Your Applicable Patent Rights and other
|
||||
intellectual property rights owned or controlled by You, to make, sell, offer
|
||||
for sale, use, import, reproduce, display, perform, modify, distribute and
|
||||
Deploy Your Modifications of the same scope and extent as Licensor's licenses
|
||||
under Sections 2.1 and 2.2; and
|
||||
|
||||
(b) You grant to Licensor and its subsidiaries a non-exclusive, worldwide,
|
||||
royalty-free, perpetual and irrevocable license, under Your Applicable Patent
|
||||
Rights and other intellectual property rights owned or controlled by You, to
|
||||
make, use, sell, offer for sale, import, reproduce, display, perform,
|
||||
distribute, modify or have modified (for Licensor and/or its subsidiaries),
|
||||
sublicense and distribute Your Modifications, in any form and for any purpose,
|
||||
through multiple tiers of distribution.
|
||||
|
||||
(c) You agree not use any information derived from Your use and review of the
|
||||
Covered Code, including but not limited to any algorithms or inventions that may
|
||||
be contained in the Covered Code, for the purpose of asserting any of Your
|
||||
patent rights, or assisting a third party to assert any of its patent rights,
|
||||
against Licensor or any Contributor.
|
||||
|
||||
4. Derivative Works. You may create a Derivative Work by combining Covered Code
|
||||
with other code not otherwise governed by the terms of this License and
|
||||
distribute the Derivative Work as an integrated product. In each such instance,
|
||||
You must make sure the requirements of this License are fulfilled for the
|
||||
Covered Code or any portion thereof, including all Modifications.
|
||||
|
||||
4.1 You must cause any Derivative Work that you distribute, publish or
|
||||
Externally Deploy, that in whole or in part contains or is derived from the
|
||||
Covered Code or any part thereof, to be licensed as a whole at no charge to all
|
||||
third parties under the terms of this License and no other license except as
|
||||
provided in Section 4.2. You also must make Source Code available for the
|
||||
Derivative Work under the same terms as Modifications, described in Sections 2
|
||||
and 3, above.
|
||||
|
||||
4.2 Compatible Source Licenses. Software modules that have been independently
|
||||
developed without any use of Covered Code and which contain no portion of the
|
||||
Covered Code, Modifications or other Derivative Works, but are used or combined
|
||||
in any way wtih the Covered Code or any Derivative Work to form a larger
|
||||
Derivative Work, are exempt from the conditions described in Section 4.1 but
|
||||
only to the extent that: the software module, including any software that is
|
||||
linked to, integrated with, or part of the same applications as, the software
|
||||
module by any method must be wholly subject to one of the Compatible Source
|
||||
Licenses. Notwithstanding the foregoing, all Covered Code must be subject to the
|
||||
terms of this License. Thus, the entire Derivative Work must be licensed under a
|
||||
combination of the RPSL (for Covered Code) and a Compatible Source License for
|
||||
any independently developed software modules within the Derivative Work. The
|
||||
foregoing requirement applies even if the Compatible Source License would
|
||||
ordinarily allow the software module to link with, or form larger works with,
|
||||
other software that is not subject to the Compatible Source License. For
|
||||
example, although the Mozilla Public License v1.1 allows Mozilla code to be
|
||||
combined with proprietary software that is not subject to the MPL, if
|
||||
MPL-licensed code is used with Covered Code the MPL-licensed code could not be
|
||||
combined or linked with any code not governed by the MPL. The general intent of
|
||||
this section 4.2 is to enable use of Covered Code with applications that are
|
||||
wholly subject to an acceptable open source license. You are responsible for
|
||||
determining whether your use of software with Covered Code is allowed under Your
|
||||
license to such software.
|
||||
|
||||
4.3 Mere aggregation of another work not based on the Covered Code with the
|
||||
Covered Code (or with a work based on the Covered Code) on a volume of a storage
|
||||
or distribution medium does not bring the other work under the scope of this
|
||||
License. If You deliver the Covered Code for combination and/or integration with
|
||||
an application previously provided by You (for example, via automatic updating
|
||||
technology), such combination and/or integration constitutes a Derivative Work
|
||||
subject to the terms of this License.
|
||||
|
||||
5. Exclusions From License Grant. Nothing in this License shall be deemed to
|
||||
grant any rights to trademarks, copyrights, patents, trade secrets or any other
|
||||
intellectual property of Licensor or any Contributor except as expressly stated
|
||||
herein. No right is granted to the trademarks of Licensor or any Contributor
|
||||
even if such marks are included in the Covered Code. Nothing in this License
|
||||
shall be interpreted to prohibit Licensor from licensing under different terms
|
||||
from this License any code that Licensor otherwise would have a right to
|
||||
license. Modifications, Derivative Works and/or any use or combination of
|
||||
Covered Code with other technology provided by Licensor or third parties may
|
||||
require additional patent licenses from Licensor which Licensor may grant in its
|
||||
sole discretion. No patent license is granted separate from the Original Code or
|
||||
combinations of the Original Code with other software or hardware.
|
||||
|
||||
5.1. Trademarks. This License does not grant any rights to use the trademarks or
|
||||
trade names owned by Licensor ("Licensor Marks" defined in Exhibit C) or to any
|
||||
trademark or trade name belonging to any Contributor. No Licensor Marks may be
|
||||
used to endorse or promote products derived from the Original Code other than as
|
||||
permitted by the Licensor Trademark Policy defined in Exhibit C.
|
||||
|
||||
6. Additional Terms. You may choose to offer, and to charge a fee for, warranty,
|
||||
support, indemnity or liability obligations and/or other rights consistent with
|
||||
the scope of the license granted herein ("Additional Terms") to one or more
|
||||
recipients of Covered Code. However, You may do so only on Your own behalf and
|
||||
as Your sole responsibility, and not on behalf of Licensor or any Contributor.
|
||||
You must obtain the recipient's agreement that any such Additional Terms are
|
||||
offered by You alone, and You hereby agree to indemnify, defend and hold
|
||||
Licensor and every Contributor harmless for any liability incurred by or claims
|
||||
asserted against Licensor or such Contributor by reason of any such Additional
|
||||
Terms.
|
||||
|
||||
7. Versions of the License. Licensor may publish revised and/or new versions of
|
||||
this License from time to time. Each version will be given a distinguishing
|
||||
version number. Once Original Code has been published under a particular version
|
||||
of this License, You may continue to use it under the terms of that version. You
|
||||
may also choose to use such Original Code under the terms of any subsequent
|
||||
version of this License published by Licensor. No one other than Licensor has
|
||||
the right to modify the terms applicable to Covered Code created under this
|
||||
License.
|
||||
|
||||
8. NO WARRANTY OR SUPPORT. The Covered Code may contain in whole or in part
|
||||
pre-release, untested, or not fully tested works. The Covered Code may contain
|
||||
errors that could cause failures or loss of data, and may be incomplete or
|
||||
contain inaccuracies. You expressly acknowledge and agree that use of the
|
||||
Covered Code, or any portion thereof, is at Your sole and entire risk. THE
|
||||
COVERED CODE IS PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT OF
|
||||
ANY KIND AND LICENSOR AND LICENSOR'S LICENSOR(S) (COLLECTIVELY REFERRED TO AS
|
||||
"LICENSOR" FOR THE PURPOSES OF SECTIONS 8 AND 9) AND ALL CONTRIBUTORS EXPRESSLY
|
||||
DISCLAIM ALL WARRANTIES AND/OR CONDITIONS, EXPRESS OR IMPLIED, INCLUDING, BUT
|
||||
NOT LIMITED TO, THE IMPLIED WARRANTIES AND/OR CONDITIONS OF MERCHANTABILITY, OF
|
||||
SATISFACTORY QUALITY, OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY, OF QUIET
|
||||
ENJOYMENT, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. LICENSOR AND EACH
|
||||
CONTRIBUTOR DOES NOT WARRANT AGAINST INTERFERENCE WITH YOUR ENJOYMENT OF THE
|
||||
COVERED CODE, THAT THE FUNCTIONS CONTAINED IN THE COVERED CODE WILL MEET YOUR
|
||||
REQUIREMENTS, THAT THE OPERATION OF THE COVERED CODE WILL BE UNINTERRUPTED OR
|
||||
ERROR-FREE, OR THAT DEFECTS IN THE COVERED CODE WILL BE CORRECTED. NO ORAL OR
|
||||
WRITTEN DOCUMENTATION, INFORMATION OR ADVICE GIVEN BY LICENSOR, A LICENSOR
|
||||
AUTHORIZED REPRESENTATIVE OR ANY CONTRIBUTOR SHALL CREATE A WARRANTY. You
|
||||
acknowledge that the Covered Code is not intended for use in high risk
|
||||
activities, including, but not limited to, the design, construction, operation
|
||||
or maintenance of nuclear facilities, aircraft navigation, aircraft
|
||||
communication systems, or air traffic control machines in which case the failure
|
||||
of the Covered Code could lead to death, personal injury, or severe physical or
|
||||
environmental damage. Licensor disclaims any express or implied warranty of
|
||||
fitness for such uses.
|
||||
|
||||
9. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT
|
||||
SHALL LICENSOR OR ANY CONTRIBUTOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
|
||||
INDIRECT OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO THIS LICENSE OR
|
||||
YOUR USE OR INABILITY TO USE THE COVERED CODE, OR ANY PORTION THEREOF, WHETHER
|
||||
UNDER A THEORY OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE OR STRICT
|
||||
LIABILITY), PRODUCTS LIABILITY OR OTHERWISE, EVEN IF LICENSOR OR SUCH
|
||||
CONTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND
|
||||
NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF ANY REMEDY. SOME
|
||||
JURISDICTIONS DO NOT ALLOW THE LIMITATION OF LIABILITY OF INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY TO YOU. In no event
|
||||
shall Licensor's total liability to You for all damages (other than as may be
|
||||
required by applicable law) under this License exceed the amount of ten dollars
|
||||
($10.00).
|
||||
|
||||
10. Ownership. Subject to the licenses granted under this License, each
|
||||
Contributor retains all rights, title and interest in and to any Modifications
|
||||
made by such Contributor. Licensor retains all rights, title and interest in and
|
||||
to the Original Code and any Modifications made by or on behalf of Licensor
|
||||
("Licensor Modifications"), and such Licensor Modifications will not be
|
||||
automatically subject to this License. Licensor may, at its sole discretion,
|
||||
choose to license such Licensor Modifications under this License, or on
|
||||
different terms from those contained in this License or may choose not to
|
||||
license them at all.
|
||||
|
||||
11. Termination.
|
||||
|
||||
11.1 Term and Termination. The term of this License is perpetual unless
|
||||
terminated as provided below. This License and the rights granted hereunder will
|
||||
terminate:
|
||||
|
||||
(a) automatically without notice from Licensor if You fail to comply with any
|
||||
term(s) of this License and fail to cure such breach within 30 days of becoming
|
||||
aware of such breach;
|
||||
|
||||
(b) immediately in the event of the circumstances described in Section 12.5(b);
|
||||
or
|
||||
|
||||
(c) automatically without notice from Licensor if You, at any time during the
|
||||
term of this License, commence an action for patent infringement against
|
||||
Licensor (including by cross-claim or counter claim in a lawsuit);
|
||||
|
||||
(d) upon written notice from Licensor if You, at any time during the term of
|
||||
this License, commence an action for patent infringement against any third party
|
||||
alleging that the Covered Code itself (excluding combinations with other
|
||||
software or hardware) infringes any patent (including by cross-claim or counter
|
||||
claim in a lawsuit).
|
||||
|
||||
11.2 Effect of Termination. Upon termination, You agree to immediately stop any
|
||||
further use, reproduction, modification, sublicensing and distribution of the
|
||||
Covered Code and to destroy all copies of the Covered Code that are in your
|
||||
possession or control. All sublicenses to the Covered Code which have been
|
||||
properly granted prior to termination shall survive any termination of this
|
||||
License. Provisions which, by their nature, should remain in effect beyond the
|
||||
termination of this License shall survive, including but not limited to Sections
|
||||
3, 5, 8, 9, 10, 11, 12.2 and 13. No party will be liable to any other for
|
||||
compensation, indemnity or damages of any sort solely as a result of terminating
|
||||
this License in accordance with its terms, and termination of this License will
|
||||
be without prejudice to any other right or remedy of any party.
|
||||
|
||||
12. Miscellaneous.
|
||||
|
||||
12.1 Government End Users. The Covered Code is a "commercial item" as defined in
|
||||
FAR 2.101. Government software and technical data rights in the Covered Code
|
||||
include only those rights customarily provided to the public as defined in this
|
||||
License. This customary commercial license in technical data and software is
|
||||
provided in accordance with FAR 12.211 (Technical Data) and 12.212 (Computer
|
||||
Software) and, for Department of Defense purchases, DFAR 252.227-7015 (Technical
|
||||
Data -- Commercial Items) and 227.7202-3 (Rights in Commercial Computer Software
|
||||
or Computer Software Documentation). Accordingly, all U.S. Government End Users
|
||||
acquire Covered Code with only those rights set forth herein.
|
||||
|
||||
12.2 Relationship of Parties. This License will not be construed as creating an
|
||||
agency, partnership, joint venture or any other form of legal association
|
||||
between or among You, Licensor or any Contributor, and You will not represent to
|
||||
the contrary, whether expressly, by implication, appearance or otherwise.
|
||||
|
||||
12.3 Independent Development. Nothing in this License will impair Licensor's
|
||||
right to acquire, license, develop, have others develop for it, market and/or
|
||||
distribute technology or products that perform the same or similar functions as,
|
||||
or otherwise compete with, Modifications, Derivative Works, technology or
|
||||
products that You may develop, produce, market or distribute.
|
||||
|
||||
12.4 Waiver; Construction. Failure by Licensor or any Contributor to enforce any
|
||||
provision of this License will not be deemed a waiver of future enforcement of
|
||||
that or any other provision. Any law or regulation which provides that the
|
||||
language of a contract shall be construed against the drafter will not apply to
|
||||
this License.
|
||||
|
||||
12.5 Severability. (a) If for any reason a court of competent jurisdiction finds
|
||||
any provision of this License, or portion thereof, to be unenforceable, that
|
||||
provision of the License will be enforced to the maximum extent permissible so
|
||||
as to effect the economic benefits and intent of the parties, and the remainder
|
||||
of this License will continue in full force and effect. (b) Notwithstanding the
|
||||
foregoing, if applicable law prohibits or restricts You from fully and/or
|
||||
specifically complying with Sections 2 and/or 3 or prevents the enforceability
|
||||
of either of those Sections, this License will immediately terminate and You
|
||||
must immediately discontinue any use of the Covered Code and destroy all copies
|
||||
of it that are in your possession or control.
|
||||
|
||||
12.6 Dispute Resolution. Any litigation or other dispute resolution between You
|
||||
and Licensor relating to this License shall take place in the Seattle,
|
||||
Washington, and You and Licensor hereby consent to the personal jurisdiction of,
|
||||
and venue in, the state and federal courts within that District with respect to
|
||||
this License. The application of the United Nations Convention on Contracts for
|
||||
the International Sale of Goods is expressly excluded.
|
||||
|
||||
12.7 Export/Import Laws. This software is subject to all export and import laws
|
||||
and restrictions and regulations of the country in which you receive the Covered
|
||||
Code and You are solely responsible for ensuring that You do not export,
|
||||
re-export or import the Covered Code or any direct product thereof in violation
|
||||
of any such restrictions, laws or regulations, or without all necessary
|
||||
authorizations.
|
||||
|
||||
12.8 Entire Agreement; Governing Law. This License constitutes the entire
|
||||
agreement between the parties with respect to the subject matter hereof. This
|
||||
License shall be governed by the laws of the United States and the State of
|
||||
Washington.
|
||||
|
||||
Where You are located in the province of Quebec, Canada, the following clause
|
||||
applies: The parties hereby confirm that they have requested that this License
|
||||
and all related documents be drafted in English. Les parties ont exigé
|
||||
que le présent contrat et tous les documents connexes soient
|
||||
rédigés en anglais.
|
||||
|
||||
EXHIBIT A.
|
||||
|
||||
"Copyright © 1995-2002
|
||||
RealNetworks, Inc. and/or its licensors. All Rights Reserved.
|
||||
|
||||
The contents of this file, and the files included with this file, are subject to
|
||||
the current version of the RealNetworks Public Source License Version 1.0 (the
|
||||
"RPSL") available at https://www.helixcommunity.org/content/rpsl unless you have
|
||||
licensed the file under the RealNetworks Community Source License Version 1.0
|
||||
(the "RCSL") available at https://www.helixcommunity.org/content/rcsl, in which
|
||||
case the RCSL will apply. You may also obtain the license terms directly from
|
||||
RealNetworks. You may not use this file except in compliance with the RPSL or,
|
||||
if you have a valid RCSL with RealNetworks applicable to this file, the RCSL.
|
||||
Please see the applicable RPSL or RCSL for the rights, obligations and
|
||||
limitations governing use of the contents of the file.
|
||||
|
||||
This file is part of the Helix DNA Technology. RealNetworks is the developer of
|
||||
the Original code and owns the copyrights in the portions it created.
|
||||
|
||||
This file, and the files included with this file, is distributed and made
|
||||
available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
|
||||
IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
|
||||
WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
|
||||
Contributor(s): ____________________________________
|
||||
|
||||
Technology Compatibility Kit Test
|
||||
Suite(s) Location (if licensed under the RCSL): ______________________________
|
||||
|
||||
Object Code Notice: Helix DNA Client technology included. Copyright (c)
|
||||
RealNetworks, Inc., 1995-2002. All rights reserved.
|
||||
|
||||
|
||||
EXHIBIT B
|
||||
|
||||
Compatible Source Licenses for the RealNetworks Public Source License. The
|
||||
following list applies to the most recent version of the license as of October
|
||||
25, 2002, unless otherwise indicated.
|
||||
|
||||
* Academic Free License
|
||||
* Apache Software License
|
||||
* Apple Public Source License
|
||||
* Artistic license
|
||||
* Attribution Assurance Licenses
|
||||
* BSD license
|
||||
* Common Public License (1)
|
||||
* Eiffel Forum License
|
||||
* GNU General Public License (GPL) (1)
|
||||
* GNU Library or "Lesser" General Public License (LGPL) (1)
|
||||
* IBM Public License
|
||||
* Intel Open Source License
|
||||
* Jabber Open Source License
|
||||
* MIT license
|
||||
* MITRE Collaborative Virtual Workspace License (CVW License)
|
||||
* Motosoto License
|
||||
* Mozilla Public License 1.0 (MPL)
|
||||
* Mozilla Public License 1.1 (MPL)
|
||||
* Nokia Open Source License
|
||||
* Open Group Test Suite License
|
||||
* Python Software Foundation License
|
||||
* Ricoh Source Code Public License
|
||||
* Sun Industry Standards Source License (SISSL)
|
||||
* Sun Public License
|
||||
* University of Illinois/NCSA Open Source License
|
||||
* Vovida Software License v. 1.0
|
||||
* W3C License
|
||||
* X.Net License
|
||||
* Zope Public License
|
||||
* zlib/libpng license
|
||||
|
||||
(1) Note: because this license contains certain reciprocal licensing terms that
|
||||
purport to extend to independently developed code, You may be prohibited under
|
||||
the terms of this otherwise compatible license from using code licensed under
|
||||
its terms with Covered Code because Covered Code may only be licensed under the
|
||||
RealNetworks Public Source License. Any attempt to apply non RPSL license terms,
|
||||
including without limitation the GPL, to Covered Code is expressly forbidden.
|
||||
You are responsible for ensuring that Your use of Compatible Source Licensed
|
||||
code does not violate either the RPSL or the Compatible Source License.
|
||||
|
||||
The latest version of this list can be found at:
|
||||
https://www.helixcommunity.org/content/complicense
|
||||
|
||||
EXHIBIT C
|
||||
|
||||
RealNetworks' Trademark policy.
|
||||
|
||||
RealNetworks defines the following trademarks collectively as "Licensor
|
||||
Trademarks": "RealNetworks", "RealPlayer", "RealJukebox", "RealSystem",
|
||||
"RealAudio", "RealVideo", "RealOne Player", "RealMedia", "Helix" or any other
|
||||
trademarks or trade names belonging to RealNetworks.
|
||||
|
||||
RealNetworks "Licensor Trademark Policy" forbids any use of Licensor Trademarks
|
||||
except as permitted by and in strict compliance at all times with RealNetworks'
|
||||
third party trademark usage guidelines which are posted at
|
||||
http://www.realnetworks.com/info/helixlogo.html.
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: RCSL 1.0/RPSL 1.0
|
||||
#
|
||||
# Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
|
||||
#
|
||||
# The contents of this file, and the files included with this file, are
|
||||
# subject to the current version of the RealNetworks Public Source License
|
||||
# Version 1.0 (the "RPSL") available at
|
||||
# http://www.helixcommunity.org/content/rpsl unless you have licensed
|
||||
# the file under the RealNetworks Community Source License Version 1.0
|
||||
# (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
|
||||
# in which case the RCSL will apply. You may also obtain the license terms
|
||||
# directly from RealNetworks. You may not use this file except in
|
||||
# compliance with the RPSL or, if you have a valid RCSL with RealNetworks
|
||||
# applicable to this file, the RCSL. Please see the applicable RPSL or
|
||||
# RCSL for the rights, obligations and limitations governing use of the
|
||||
# contents of the file.
|
||||
#
|
||||
# This file is part of the Helix DNA Technology. RealNetworks is the
|
||||
# developer of the Original Code and owns the copyrights in the portions
|
||||
# it created.
|
||||
#
|
||||
# This file, and the files included with this file, is distributed and made
|
||||
# available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
# EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
# FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
#
|
||||
# Technology Compatibility Kit Test Suite(s) Location:
|
||||
# http://www.helixcommunity.org/content/tck
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
#
|
||||
|
||||
UmakefileVersion(2,1)
|
||||
|
||||
# old C++ shim layer for backwards compatibility with Player
|
||||
# if you don't want to use this, just use the public C api
|
||||
# in mp3dec.c/.h
|
||||
project.AddSources("mpadecobj.cpp")
|
||||
|
||||
project.AddSources("mp3dec.c", "mp3tabs.c")
|
||||
|
||||
if (sysinfo.arch == 'arm') and project.IsDefined('HELIX_FEATURE_USE_IPP4'):
|
||||
project.AddDefines('USE_IPP_MP3')
|
||||
|
||||
if ('USE_IPP_MP3' in project.defines):
|
||||
project.AddSources("ipp/bitstream.c", "ipp/buffers.c", "ipp/dequant.c",
|
||||
"ipp/huffman.c", "ipp/imdct.c", "ipp/subband.c")
|
||||
if('_LINUX' in project.defines):
|
||||
project.AddIncludes('%s/include/' % GetSDKPath("ipp_mp3_tools"))
|
||||
else:
|
||||
project.AddIncludes('\"%s\include\"' % GetSDKPath("ipp_mp3_tools"))
|
||||
|
||||
else:
|
||||
project.AddSources("real/bitstream.c", "real/buffers.c", "real/dct32.c",
|
||||
"real/dequant.c", "real/dqchan.c", "real/huffman.c", "real/hufftabs.c",
|
||||
"real/imdct.c", "real/scalfact.c",
|
||||
"real/stproc.c", "real/subband.c", "real/trigtabs.c")
|
||||
if ('ARM_ADS' in project.defines):
|
||||
project.AddSources("real/arm/asmpoly.s")
|
||||
elif ('_WINCE' in project.defines and '_ARM' in project.defines):
|
||||
project.AddSources("real/arm/asmpoly.s", "real/arm/asmmisc.s")
|
||||
elif (('_SYMBIAN' in project.defines or '_LINUX' in project.defines ) and
|
||||
'ARM' in project.defines):
|
||||
project.AddSources("real/arm/asmpoly_gcc.s")
|
||||
else:
|
||||
project.AddSources("real/polyphase.c")
|
||||
|
||||
project.AddIncludes("./pub")
|
||||
project.AddModuleIncludes("common/include")
|
||||
project.AddModuleIncludes("common/runtime/pub")
|
||||
|
||||
LibraryTarget("mp3codecfixpt")
|
||||
|
||||
DependTarget()
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
|
||||
|
||||
The contents of this directory, and (except where otherwise
|
||||
indicated) the directories included within this directory, are
|
||||
subject to the current version of the RealNetworks Public Source
|
||||
License (the "RPSL") available at RPSL.txt in this directory, unless
|
||||
you have licensed the directory under the current version of the
|
||||
RealNetworks Community Source License (the "RCSL") available at
|
||||
RCSL.txt in this directory, in which case the RCSL will apply. You
|
||||
may also obtain the license terms directly from RealNetworks. You
|
||||
may not use the files in this directory except in compliance with the
|
||||
RPSL or, if you have a valid RCSL with RealNetworks applicable to
|
||||
this directory, the RCSL. Please see the applicable RPSL or RCSL for
|
||||
the rights, obligations and limitations governing use of the contents
|
||||
of the directory.
|
||||
|
||||
This directory is part of the Helix DNA Technology. RealNetworks is
|
||||
the developer of the Original Code and owns the copyrights in the
|
||||
portions it created.
|
||||
|
||||
This directory, and the directories included with this directory, are
|
||||
distributed and made available on an 'AS IS' basis, WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY
|
||||
DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
|
||||
Technology Compatibility Kit Test Suite(s) Location:
|
||||
http://www.helixcommunity.org/content/tck
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user