diff --git a/.ci/config.json b/.ci/config.json index efa33378..3ffb12ad 100644 --- a/.ci/config.json +++ b/.ci/config.json @@ -13,7 +13,7 @@ "probe": "303a:1001:60:55:F9:BF:A9:44", "labels": { "target": "esp32", - "board": "esp-rust-board" + "board": "esp-rust-board" } } ] diff --git a/.github/rodbot.yaml b/.github/rodbot.yaml index 6ad3f6c1..81209275 100644 --- a/.github/rodbot.yaml +++ b/.github/rodbot.yaml @@ -1,3 +1,4 @@ +--- on: issue_comment: - if: diff --git a/.github/workflows/.mega-linter.yaml b/.github/workflows/.mega-linter.yaml new file mode 100644 index 00000000..a9d58fbe --- /dev/null +++ b/.github/workflows/.mega-linter.yaml @@ -0,0 +1,272 @@ +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +--- +name: MegaLinter + +# Trigger mega-linter at every push. Action will also be visible from +# Pull Requests to main +on: + # Comment this line to trigger action only on pull-requests---------------------------------------------------------------- + # (not recommended if you don't pay for GH Actions) + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + workflow_call: + +# Comment env block if you do not want to apply fixes +env: + # Apply linter fixes configuration + # + # When active, APPLY_FIXES must also be defined as environment variable + # (in github/workflows/mega-linter.yml or other CI tool) + APPLY_FIXES: all + + # Decide which event triggers application of fixes in a commit or a PR + # (pull_request, push, all) + APPLY_FIXES_EVENT: pull_request + + # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) + # or posted in a PR (pull_request) + APPLY_FIXES_MODE: pull_request + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + # Give the default GITHUB_TOKEN write permission to commit and push, comment + # issues, and post new Pull Requests; remove the ones you do not need + permissions: + contents: write + issues: write + pull-requests: write + statuses: write + + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + + # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to + # improve performance + fetch-depth: 0 + + # MegaLinter + - name: MegaLinter + + # You can override MegaLinter flavor used to have faster performances + # More info at https://megalinter.io/latest/flavors/ + uses: oxsecurity/megalinter@v8.3.0 + + id: ml + + # All available variables are described in documentation + # https://megalinter.io/latest/config-file/ + env: + # Validates all source when push on main, else just the git diff with + # main. Override with true if you always want to lint all sources + # + # To validate the entire codebase, set to: + # VALIDATE_ALL_CODEBASE: true + # + # To validate only diff with main, set to: + # VALIDATE_ALL_CODEBASE: >- + # ${{ + # github.event_name == 'push' && + # github.ref == 'refs/heads/main' + # }} + VALIDATE_ALL_CODEBASE: true + + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF + # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY + + # Upload MegaLinter artifacts + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log + + # Create pull request if applicable + # (for now works only on PR from same repository, not from forks) + - name: Create Pull Request with applied fixes + uses: peter-evans/create-pull-request@v7 + id: cpr + if: >- + steps.ml.outputs.has_updated_sources == 1 && + ( + env.APPLY_FIXES_EVENT == 'all' || + env.APPLY_FIXES_EVENT == github.event_name + ) && + env.APPLY_FIXES_MODE == 'pull_request' && + ( + github.event_name == 'push' || + github.event.pull_request.head.repo.full_name == github.repository + ) && + !contains(github.event.head_commit.message, 'skip fix') + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + commit-message: "[MegaLinter] Apply linters automatic fixes" + title: "[MegaLinter] Apply linters automatic fixes" + labels: bot + branch: megalinter-fixes-${{ github.head_ref }} + body: | + MegaLinter has automatically applied linters fixes on this PR. + Please review the changes and merge if they are correct. + base: ${{ github.head_ref }} + + - name: Post PR Comment + if: >- + steps.ml.outputs.has_updated_sources == 1 && + ( + env.APPLY_FIXES_EVENT == 'all' || + env.APPLY_FIXES_EVENT == github.event_name + ) && + env.APPLY_FIXES_MODE == 'pull_request' && + ( + github.event_name == 'push' || + github.event.pull_request.head.repo.full_name == github.repository + ) && + !contains(github.event.head_commit.message, 'skip fix') + uses: marocchino/sticky-pull-request-comment@v2 + with: + message: | + MegaLinter has automatically applied linters fixes on this PR. + Please review the changes and merge if they are correct. + PR: ${{ steps.cpr.outputs.pull-request-url }} + hide_and_recreate: true + + - name: Fail if PR Created + run: | + if [ "${{ steps.cpr.outputs.pull-request-url }}" != "" ]; then + echo "A PR with formatting fixes has been created. Please merge it before proceeding." + exit 1 + fi + # Required due to Mega Linter not currently supporting Rust Format + cargo_fmt_library: + name: Cargo Formatter (Library) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install Toolchains + run: | + rustup toolchain install nightly-x86_64-unknown-linux-gnu + rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt + - name: Rustfmt check on host + run: cargo +nightly fmt --manifest-path host/Cargo.toml -- --check + - name: Rustfmt check on host macros + + run: cargo +nightly fmt --manifest-path host-macros/Cargo.toml -- --check + + cargo_fmt_examples: + name: Cargo Formatter (Examples) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install Toolchains + run: | + rustup toolchain install nightly-x86_64-unknown-linux-gnu + rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt + - name: Rustfmt check on apache-nimble + run: cargo +nightly fmt --manifest-path examples/apache-nimble/Cargo.toml -- --check + - name: Rustfmt check on apps + run: cargo +nightly fmt --manifest-path examples/apps/Cargo.toml -- --check + - name: Rustfmt check on esp32 + run: cargo +nightly fmt --manifest-path examples/esp32/Cargo.toml -- --check + - name: Rustfmt check on nrf-sdc + run: cargo +nightly fmt --manifest-path examples/nrf-sdc/Cargo.toml -- --check + - name: Rustfmt check on rp-pico-2-w + run: cargo +nightly fmt --manifest-path examples/rp-pico-2-w/Cargo.toml -- --check + - name: Rustfmt check on rp-pico-w + run: cargo +nightly fmt --manifest-path examples/rp-pico-w/Cargo.toml -- --check + - name: Rustfmt check on serial-hci + run: cargo +nightly fmt --manifest-path examples/serial-hci/Cargo.toml -- --check + - name: Rustfmt check on tests + run: cargo +nightly fmt --manifest-path examples/tests/Cargo.toml -- --check + + cargo_clippy_library: + name: Cargo Clippy (Host Macros) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Cargo Clippy check on host Macros + run: | + cd host-macros + cargo clippy -- --D warnings + + cargo_clippy_examples: + name: Cargo Clippy (Examples) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install toolchains + run: | + rustup target add riscv32imac-unknown-none-elf + # - name: Cargo Clippy check on apache-nimble # (Disabled due to version bumps needed) + # run: | + # cd examples/apache-nimble + # cargo clippy -- --D warnings + - name: Cargo Clippy apps + run: | + cd examples/apps + cargo clippy -- --D warnings + - name: Cargo Clippy esp32 + run: | + cd examples/esp32 + # echo "Checking esp32" + # cargo clippy --no-default-features --features=esp32 --target=xtensa-esp32-none-elf -- -D warnings # (Disabled due to missing toolchain) + echo "Checking esp32c2" + cargo clippy --no-default-features --features=esp32c2 --target=riscv32imc-unknown-none-elf -- -D warnings + echo "Checking esp32c3" + cargo clippy --no-default-features --features=esp32c3 --target=riscv32imc-unknown-none-elf -- -D warnings + echo "Checking esp32c6" + cargo clippy --no-default-features --features=esp32c6 --target=riscv32imac-unknown-none-elf -- -D warnings + echo "Checking esp32h2" + cargo clippy --no-default-features --features=esp32h2 --target=riscv32imac-unknown-none-elf -- -D warnings + # echo "Checking esp32s3" + # cargo clippy --no-default-features --features=esp32s3 --target=xtensa-esp32s3-none-elf -- -D warnings # (Disabled due to missing toolchain) + - name: Cargo Clippy nrf-sdc + run: | + cd examples/nrf-sdc + echo "Checking nrf52832" + cargo clippy --features=nrf52832 -- -D warnings + echo "Checking nrf52833" + cargo clippy --features=nrf52833 -- -D warnings + echo "Checking nrf52840" + cargo clippy --features=nrf52840 -- -D warnings + - name: Cargo Clippy rp-pico-2-w + run: | + cd examples/rp-pico-2-w + cargo clippy -- --D warnings + - name: Cargo Clippy rp-pico-w + run: | + cd examples/rp-pico-w + cargo clippy -- --D warnings + - name: Cargo Clippy serial-hci + run: | + cd examples/serial-hci + cargo clippy -- --D warnings + - name: Cargo Clippy tests + run: | + cd examples/tests + cargo clippy -- --D warnings diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 557c0ba4..470ee305 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,3 +1,4 @@ +--- name: CI on: @@ -17,7 +18,7 @@ jobs: run: | sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | diff --git a/.github/workflows/release_trouble_host.yaml b/.github/workflows/release_trouble_host.yaml index 0bf6eebb..cf22f655 100644 --- a/.github/workflows/release_trouble_host.yaml +++ b/.github/workflows/release_trouble_host.yaml @@ -1,13 +1,14 @@ -name: Trouble Host Release +--- +name: Trouble Host Release on: push: tags: - - 'trouble-host-v[0-9]+.[0-9]+.[0-9]+' + - "trouble-host-v[0-9]+.[0-9]+.[0-9]+" permissions: contents: write - + jobs: # Re Run the Checks build: @@ -18,7 +19,7 @@ jobs: run: | sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | @@ -42,48 +43,48 @@ jobs: timeout-minutes: 10 if: github.ref == 'refs/heads/main' steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Verify Version - run: | - TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-v} - CARGO_VERSION=$(grep '^version =' host/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') - if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then - echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" - exit 1 # Exits with a non-zero status to fail the workflow - fi - shell: bash + - name: Verify Version + run: | + TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-v} + CARGO_VERSION=$(grep '^version =' host/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then + echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" + exit 1 # Exits with a non-zero status to fail the workflow + fi + shell: bash - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable - - name: Build project - run: | - cd host - cargo build --release - - - name: Create GitHub release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ github.ref_name }} - run: | - gh release create "$tag" \ - --repo="$GITHUB_REPOSITORY" \ - --title="${GITHUB_REPOSITORY#*/} host v${tag#trouble-host-v}" \ - --generate-notes + - name: Build project + run: | + cd host + cargo build --release - - name: Publish to crates.io - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - # Publish to the main registry - run: | - echo "Publishing to crates.io" - cargo publish - # To perform a dry run uncomment the following lines - # run: | - # echo "Performing dry-run publish to crates.io" - # cd host - # cargo publish --dry-run + - name: Create GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + gh release create "$tag" \ + --repo="$GITHUB_REPOSITORY" \ + --title="${GITHUB_REPOSITORY#*/} host v${tag#trouble-host-v}" \ + --generate-notes + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + # Publish to the main registry + run: | + echo "Publishing to crates.io" + cargo publish + # To perform a dry run uncomment the following lines + # run: | + # echo "Performing dry-run publish to crates.io" + # cd host + # cargo publish --dry-run diff --git a/.github/workflows/release_trouble_host_macros.yaml b/.github/workflows/release_trouble_host_macros.yaml index 2080fcbb..551be443 100644 --- a/.github/workflows/release_trouble_host_macros.yaml +++ b/.github/workflows/release_trouble_host_macros.yaml @@ -1,13 +1,14 @@ +--- name: Trouble Host macros Release on: push: tags: - - 'trouble-host-macros-v[0-9]+.[0-9]+.[0-9]+' + - "trouble-host-macros-v[0-9]+.[0-9]+.[0-9]+" permissions: contents: write - + jobs: # Re Run the Checks build: @@ -18,7 +19,7 @@ jobs: run: | sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | @@ -42,48 +43,48 @@ jobs: timeout-minutes: 10 if: github.ref == 'refs/heads/main' steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Verify Version - run: | - TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-macros-v} - CARGO_VERSION=$(grep '^version =' host-macros/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') - if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then - echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" - exit 1 # Exits with a non-zero status to fail the workflow - fi - shell: bash + - name: Verify Version + run: | + TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-macros-v} + CARGO_VERSION=$(grep '^version =' host-macros/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then + echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" + exit 1 # Exits with a non-zero status to fail the workflow + fi + shell: bash - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable - - name: Build project - run: | - cd host-macros - cargo build --release - - - name: Create GitHub release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ github.ref_name }} - run: | - gh release create "$tag" \ - --repo="$GITHUB_REPOSITORY" \ - --title="${GITHUB_REPOSITORY#*/} host macros v${tag#trouble-host-macros-v}" \ - --generate-notes + - name: Build project + run: | + cd host-macros + cargo build --release - - name: Publish to crates.io - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - # Publish to the main registry - run: | - echo "Publishing to crates.io" - cargo publish - # To perform a dry run uncomment the following lines - # run: | - # echo "Performing dry-run publish to crates.io" - # cd host-macros - # cargo publish --dry-run + - name: Create GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + gh release create "$tag" \ + --repo="$GITHUB_REPOSITORY" \ + --title="${GITHUB_REPOSITORY#*/} host macros v${tag#trouble-host-macros-v}" \ + --generate-notes + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + # Publish to the main registry + run: | + echo "Publishing to crates.io" + cargo publish + # To perform a dry run uncomment the following lines + # run: | + # echo "Performing dry-run publish to crates.io" + # cd host-macros + # cargo publish --dry-run diff --git a/.github/workflows/rodbot.yaml b/.github/workflows/rodbot.yaml index 330285cd..87f2e0bb 100644 --- a/.github/workflows/rodbot.yaml +++ b/.github/workflows/rodbot.yaml @@ -1,8 +1,9 @@ +--- name: rodbot on: issue_comment: - types: [ "created" ] + types: ["created"] jobs: rodbot: @@ -13,11 +14,11 @@ jobs: steps: - run: | - echo $GITHUB_EVENT_PATH - cat $GITHUB_EVENT_PATH + echo $"GITHUB_EVENT_PATH" + cat $"GITHUB_EVENT_PATH" - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: ctron/rodbot-action@v0.1 with: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0f6e3cbb..760abf28 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,3 +1,4 @@ +--- name: Tests on: @@ -22,7 +23,7 @@ jobs: run: | sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | @@ -61,7 +62,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=pending" -f "description=Running integration tests" -f "context=integration-tests" - name: Test env: @@ -77,7 +78,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=failure" -f "description=The integration tests failed" -f "context=integration-tests" - name: Update success status if: success() @@ -86,7 +87,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=success" -f "description=The integration tests succeeded!" -f "context=integration-tests" example-tests: @@ -107,7 +108,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=pending" -f "description=Running example tests" -f "context=example-tests" - uses: actions/download-artifact@v4 @@ -130,7 +131,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=failure" -f "description=The example tests failed" -f "context=example-tests" - name: Update success status if: success() @@ -139,5 +140,5 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=success" -f "description=The example tests succeeded!" -f "context=example-tests" diff --git a/.gitignore b/.gitignore index 93871a3d..996ae9ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ **/target **/target_ci -Cargo.lock \ No newline at end of file +Cargo.lock +megalinter-reports/ +# Mac Users +.DS_Store \ No newline at end of file diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..984d3733 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,4 @@ +{ + "default": true, + "line-length": false +} diff --git a/.mega-linter.yaml b/.mega-linter.yaml new file mode 100644 index 00000000..39d5a0cd --- /dev/null +++ b/.mega-linter.yaml @@ -0,0 +1,54 @@ +--- +# Configuration file for MegaLinter +# +# See all available variables at https://megalinter.io/latest/config-file/ and in +# linters documentation + +# all, none, or list of linter keys +APPLY_FIXES: all + +# If you use ENABLE variable, all other languages/formats/tooling-formats will +# be disabled by default +# ENABLE: + +# If you use ENABLE_LINTERS variable, all other linters will be disabled by default +ENABLE_LINTERS: + - ACTION_ACTIONLINT + - RUST_CLIPPY + - MARKDOWN_MARKDOWNLINT + - MARKDOWN_MARKDOWN_LINK_CHECK + - MARKDOWN_MARKDOWN_TABLE_FORMATTER + - YAML_YAMLLINT + - YAML_PRETTIER + - JSON_JSONLINT + - JSON_PRETTIER + - PYTHON_RUFF + - PYTHON_RUFF_FORMAT + - BASH_SHELLCHECK + - BASH_SHFMT + +# DISABLE: + +SHOW_ELAPSED_TIME: true + +FILEIO_REPORTER: false + +# Uncomment if you want MegaLinter to detect errors but not block CI to pass +# DISABLE_ERRORS: true +GITHUB_COMMENT_REPORTER: true +GITHUB_STATUS_REPORTER: true +VALIDATE_ALL_CODEBASE: true +OUTPUT_DETAIL: detailed + +# Linter Configuration +MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdownlint.json + +RUST_CLIPPY_ARGUMENTS: + - -- + - --manifest-path + - host/Cargo.toml + - --features + - gatt,peripheral,central + +JSON_JSONLINT_ARGUMENTS: + - --comments diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4dadd879..85b8d01e 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,12 +1,18 @@ { - // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "rust-lang.rust-analyzer", - "tamasfe.even-better-toml", - "fill-labs.dependi", - ], - // List of extensions recommended by VS Code that should not be recommended for users of this workspace. - "unwantedRecommendations": [] -} \ No newline at end of file + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "fill-labs.dependi", + "tamasfe.even-better-toml", + "esbenp.prettier-vscode", + "foxundermoon.shell-format", + "charliermarsh.ruff", + "timonwong.shellcheck", + "davidanson.vscode-markdownlint" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 40f3a478..922b66c7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,25 +1,25 @@ -{ - "[rust]": { - "editor.formatOnSave": true, - "editor.formatOnSaveMode": "file", - }, - "[toml]": { - "editor.formatOnSave": false - }, - "[markdown]": { - "editor.formatOnSave": false - }, - "rust-analyzer.check.allTargets": false, - "rust-analyzer.linkedProjects": [ - "host/Cargo.toml", - "host-macros/Cargo.toml", - "examples/apps/Cargo.toml", - // uncomment the examples you want to explore below - // "examples/esp32/Cargo.toml", - // "examples/nrf-sdc/Cargo.toml", - // "examples/rp-pico-w/Cargo.toml", - // "examples/rp-pico-2-w/Cargo.toml", - // "examples/serial-hci/Cargo.toml", - // "examples/apache-nimble/Cargo.toml", - ] -} \ No newline at end of file +{ + "[rust]": { + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file" + }, + "[toml]": { + "editor.formatOnSave": false + }, + "[markdown]": { + "editor.formatOnSave": false + }, + "rust-analyzer.check.allTargets": false, + "rust-analyzer.linkedProjects": [ + "host/Cargo.toml", + "host-macros/Cargo.toml", + "examples/apps/Cargo.toml" + // uncomment the examples you want to explore below + // "examples/esp32/Cargo.toml", + // "examples/nrf-sdc/Cargo.toml", + // "examples/rp-pico-w/Cargo.toml", + // "examples/rp-pico-2-w/Cargo.toml", + // "examples/serial-hci/Cargo.toml", + // "examples/apache-nimble/Cargo.toml" + ] +} diff --git a/README.md b/README.md index 20f52b8d..7dde64c8 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,11 @@ See `examples` for example applications for different BLE controllers. * `serial-hci` which runs on std using a controller attached via a serial port (Such as [this Zephyr sample](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/bluetooth/hci_uart/README.html)). * `apache-nimble` which uses the controller from the [NimBLE stack](https://github.com/apache/mynewt-nimble) through high-level bindings from the [`apache-nimble`](https://github.com/benbrittain/apache-nimble-sys) crate. * `esp32` which uses the BLE controller in the [esp-hal](https://github.com/esp-rs/esp-hal). + + * `rp-pico-w` which uses the BLE controller in the [Raspberry Pi Pico W](https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#raspberry-pi-pico-w). * `rp-pico-2-w` which uses the BLE controller in the [Raspberry Pi Pico 2 W](https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#raspberry-pi-pico-2-w). + Since a lot of the examples demo the same BLE functionality, they only contain basic wiring specific to the BLE controller, and share the 'business logic' within the `examples/apps` folder. diff --git a/ci.sh b/ci.sh index f5361889..8c908db6 100755 --- a/ci.sh +++ b/ci.sh @@ -2,40 +2,39 @@ set -eo pipefail -if ! command -v cargo-batch &> /dev/null; then - mkdir -p $HOME/.cargo/bin - curl -L https://github.com/embassy-rs/cargo-batch/releases/download/batch-0.6.0/cargo-batch > $HOME/.cargo/bin/cargo-batch - chmod +x $HOME/.cargo/bin/cargo-batch +if ! command -v cargo-batch &>/dev/null; then + mkdir -p "$HOME"/.cargo/bin + curl -L https://github.com/embassy-rs/cargo-batch/releases/download/batch-0.6.0/cargo-batch >"$HOME"/.cargo/bin/cargo-batch + chmod +x "$HOME"/.cargo/bin/cargo-batch fi export RUSTFLAGS=-Dwarnings export DEFMT_LOG=trace export CARGO_NET_GIT_FETCH_WITH_CLI=true if [[ -z "${CARGO_TARGET_DIR}" ]]; then - export CARGO_TARGET_DIR=target_ci + export CARGO_TARGET_DIR=target_ci fi cargo batch \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features peripheral \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,scan \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral,defmt \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,central \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan \ - --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ - --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52833 --artifact-dir tests/nrf-sdc \ - --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52832 \ - --- build --release --manifest-path examples/esp32/Cargo.toml --features esp32c3 --target riscv32imc-unknown-none-elf --artifact-dir tests/esp32 \ - --- build --release --manifest-path examples/serial-hci/Cargo.toml \ - --- build --release --manifest-path examples/tests/Cargo.toml \ - --- build --release --manifest-path examples/rp-pico-w/Cargo.toml --target thumbv6m-none-eabi --features skip-cyw43-firmware \ - --- build --release --manifest-path examples/rp-pico-2-w/Cargo.toml --target thumbv8m.main-none-eabihf --features skip-cyw43-firmware + --- build --release --manifest-path host/Cargo.toml --no-default-features --features peripheral \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features central \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,scan \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral,defmt \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,central \ + --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan \ + --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ + --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52833 --artifact-dir tests/nrf-sdc \ + --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52832 \ + --- build --release --manifest-path examples/esp32/Cargo.toml --features esp32c3 --target riscv32imc-unknown-none-elf --artifact-dir tests/esp32 \ + --- build --release --manifest-path examples/serial-hci/Cargo.toml \ + --- build --release --manifest-path examples/tests/Cargo.toml \ + --- build --release --manifest-path examples/rp-pico-w/Cargo.toml --target thumbv6m-none-eabi --features skip-cyw43-firmware \ + --- build --release --manifest-path examples/rp-pico-2-w/Cargo.toml --target thumbv8m.main-none-eabihf --features skip-cyw43-firmware # --- build --release --manifest-path examples/apache-nimble/Cargo.toml --target thumbv7em-none-eabihf -cargo fmt --check --manifest-path ./host/Cargo.toml -cargo clippy --manifest-path ./host/Cargo.toml --features gatt,peripheral,central +# Run tests cargo test --manifest-path ./host/Cargo.toml --lib -- --nocapture cargo test --manifest-path ./host/Cargo.toml --no-run -- --nocapture cargo test --manifest-path ./examples/tests/Cargo.toml --no-run -- --nocapture diff --git a/examples/apache-nimble/src/bin/ble_bas_peripheral.rs b/examples/apache-nimble/src/bin/ble_bas_peripheral.rs index 36ee65e7..5e56a9ff 100644 --- a/examples/apache-nimble/src/bin/ble_bas_peripheral.rs +++ b/examples/apache-nimble/src/bin/ble_bas_peripheral.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -use apache_nimble::controller::NimbleController; -use apache_nimble::controller::NimbleControllerTask; +use apache_nimble::controller::{NimbleController, NimbleControllerTask}; use embassy_time::{Duration, Ticker, Timer}; use trouble_example_apps::ble_bas_peripheral; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/apps/src/ble_scanner.rs b/examples/apps/src/ble_scanner.rs index 75f00c37..9acf26f1 100644 --- a/examples/apps/src/ble_scanner.rs +++ b/examples/apps/src/ble_scanner.rs @@ -1,6 +1,7 @@ +use core::cell::RefCell; + use bt_hci::cmd::le::LeSetScanParams; use bt_hci::controller::ControllerCmdSync; -use core::cell::RefCell; use embassy_futures::join::join; use embassy_time::{Duration, Timer}; use heapless::Deque; @@ -31,11 +32,13 @@ where }; let mut scanner = Scanner::new(central); let _ = join(runner.run_with_handler(&printer), async { - let mut config = ScanConfig::default(); - config.active = true; - config.phys = PhySet::M1; - config.interval = Duration::from_secs(1); - config.window = Duration::from_secs(1); + let config = ScanConfig::<'_> { + active: true, + phys: PhySet::M1, + interval: Duration::from_secs(1), + window: Duration::from_secs(1), + ..Default::default() + }; let mut _session = scanner.scan(&config).await.unwrap(); // Scan forever loop { @@ -53,7 +56,7 @@ impl EventHandler for Printer { fn on_adv_reports(&self, mut it: LeAdvReportsIter<'_>) { let mut seen = self.seen.borrow_mut(); while let Some(Ok(report)) = it.next() { - if seen.iter().find(|b| b.raw() == report.addr.raw()).is_none() { + if !seen.iter().any(|b| b.raw() == report.addr.raw()) { info!("discovered: {:?}", report.addr); if seen.is_full() { seen.pop_front(); diff --git a/examples/apps/src/fmt.rs b/examples/apps/src/fmt.rs index c46fff33..6c8f7402 100644 --- a/examples/apps/src/fmt.rs +++ b/examples/apps/src/fmt.rs @@ -233,19 +233,19 @@ impl Try for Result { #[allow(unused)] pub(crate) struct Bytes<'a>(pub &'a [u8]); -impl<'a> Debug for Bytes<'a> { +impl Debug for Bytes<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:#02x?}", self.0) } } -impl<'a> Display for Bytes<'a> { +impl Display for Bytes<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:#02x?}", self.0) } } -impl<'a> LowerHex for Bytes<'a> { +impl LowerHex for Bytes<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:#02x?}", self.0) } diff --git a/examples/esp32/build.rs b/examples/esp32/build.rs index d1771291..5efe9c99 100644 --- a/examples/esp32/build.rs +++ b/examples/esp32/build.rs @@ -1,3 +1,3 @@ fn main() { println!("cargo:rustc-link-arg-bins=-Tlinkall.x"); -} \ No newline at end of file +} diff --git a/examples/esp32/src/bin/ble_bas_central.rs b/examples/esp32/src/bin/ble_bas_central.rs index cc016c95..11d16ab1 100644 --- a/examples/esp32/src/bin/ble_bas_central.rs +++ b/examples/esp32/src/bin/ble_bas_central.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_bas_central; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/esp32/src/bin/ble_bas_peripheral.rs b/examples/esp32/src/bin/ble_bas_peripheral.rs index ded57aa5..ec9f41d6 100644 --- a/examples/esp32/src/bin/ble_bas_peripheral.rs +++ b/examples/esp32/src/bin/ble_bas_peripheral.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_bas_peripheral; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/esp32/src/bin/ble_l2cap_central.rs b/examples/esp32/src/bin/ble_l2cap_central.rs index 03024fe3..b0a10d4d 100644 --- a/examples/esp32/src/bin/ble_l2cap_central.rs +++ b/examples/esp32/src/bin/ble_l2cap_central.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_l2cap_central; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/esp32/src/bin/ble_l2cap_peripheral.rs b/examples/esp32/src/bin/ble_l2cap_peripheral.rs index 4a0d19e0..49002078 100644 --- a/examples/esp32/src/bin/ble_l2cap_peripheral.rs +++ b/examples/esp32/src/bin/ble_l2cap_peripheral.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_l2cap_peripheral; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/rp-pico-w/build.rs b/examples/rp-pico-w/build.rs index ff241da0..00e2b38c 100644 --- a/examples/rp-pico-w/build.rs +++ b/examples/rp-pico-w/build.rs @@ -48,7 +48,7 @@ fn download_cyw43_firmware() { "43439A0_clm.bin", "LICENSE-permissive-binary-license-1.0.txt", "README.md", - ]; + ]; println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed={}", download_folder); diff --git a/examples/tests/src/lib.rs b/examples/tests/src/lib.rs index dbccd3ee..5df228f7 100644 --- a/examples/tests/src/lib.rs +++ b/examples/tests/src/lib.rs @@ -31,3 +31,9 @@ impl TestContext { Ok(DeviceUnderTest::new(target)) } } + +impl Default for TestContext { + fn default() -> Self { + Self::new() + } +} diff --git a/examples/tests/src/probe/mod.rs b/examples/tests/src/probe/mod.rs index df369ad3..a9e4444a 100644 --- a/examples/tests/src/probe/mod.rs +++ b/examples/tests/src/probe/mod.rs @@ -1,13 +1,11 @@ use std::process::Stdio; -use tokio::io::AsyncBufReadExt; -use tokio::io::BufReader; + +use hilbench_agent::{ProbeConfig, Target}; +use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::Command; use tokio::select; use tokio_util::sync::CancellationToken; -use hilbench_agent::ProbeConfig; -use hilbench_agent::Target; - pub fn init(config: ProbeConfig) { hilbench_agent::init(config); } diff --git a/examples/tests/tests/ble_l2cap_central.rs b/examples/tests/tests/ble_l2cap_central.rs index ccc620c8..f5adb463 100644 --- a/examples/tests/tests/ble_l2cap_central.rs +++ b/examples/tests/tests/ble_l2cap_central.rs @@ -1,5 +1,6 @@ -use futures::future::join; use std::time::Duration; + +use futures::future::join; use tokio::select; use trouble_example_tests::{serial, TestContext}; use trouble_host::prelude::*; diff --git a/examples/tests/tests/ble_l2cap_peripheral.rs b/examples/tests/tests/ble_l2cap_peripheral.rs index 4601c0bd..cb6a828f 100644 --- a/examples/tests/tests/ble_l2cap_peripheral.rs +++ b/examples/tests/tests/ble_l2cap_peripheral.rs @@ -1,5 +1,6 @@ -use futures::future::join; use std::time::Duration; + +use futures::future::join; use tokio::select; use trouble_example_tests::{serial, TestContext}; use trouble_host::prelude::*; diff --git a/host/gen_config.py b/host/gen_config.py index 3a16efd5..5267eb4b 100644 --- a/host/gen_config.py +++ b/host/gen_config.py @@ -19,7 +19,7 @@ def feature(name, default, min=None, max=None, pow2=None, vals=None, factors=[]) for f in factors: if val*f <= max: vals.add(val*f) - if (pow2 == True or (isinstance(pow2, int) and val >= pow2)) and val > 0: + if (pow2 is True or (isinstance(pow2, int) and val >= pow2)) and val > 0: val *= 2 else: val += 1 diff --git a/host/src/attribute.rs b/host/src/attribute.rs index 2773ab7d..d740587f 100644 --- a/host/src/attribute.rs +++ b/host/src/attribute.rs @@ -7,6 +7,7 @@ use bt_hci::uuid::declarations::{CHARACTERISTIC, PRIMARY_SERVICE}; use bt_hci::uuid::descriptors::CLIENT_CHARACTERISTIC_CONFIGURATION; use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::blocking_mutex::Mutex; +use heapless::Vec; use crate::att::AttErrorCode; use crate::attribute_server::AttributeServer; @@ -15,7 +16,6 @@ use crate::prelude::Connection; use crate::types::gatt_traits::GattValue; pub use crate::types::uuid::Uuid; use crate::Error; -use heapless::Vec; /// Characteristic properties #[derive(Debug, Clone, Copy)] diff --git a/host/src/central.rs b/host/src/central.rs index 5c8ca412..20a2a81e 100644 --- a/host/src/central.rs +++ b/host/src/central.rs @@ -1,6 +1,4 @@ //! Functionality for the BLE central role. -use crate::connection::{ConnectConfig, Connection, PhySet}; -use crate::{BleHostError, Error, Stack}; use bt_hci::cmd::le::{LeAddDeviceToFilterAcceptList, LeClearFilterAcceptList, LeCreateConn, LeExtCreateConn}; use bt_hci::controller::{Controller, ControllerCmdAsync, ControllerCmdSync}; use bt_hci::param::{AddrKind, BdAddr, InitiatingPhy, LeConnRole, PhyParams}; @@ -8,6 +6,9 @@ use bt_hci::param::{AddrKind, BdAddr, InitiatingPhy, LeConnRole, PhyParams}; use bt_hci::param::{ConnHandleCompletedPackets, ControllerToHostFlowControl}; use embassy_futures::select::{select, Either}; +use crate::connection::{ConnectConfig, Connection, PhySet}; +use crate::{BleHostError, Error, Stack}; + /// A type implementing the BLE central role. pub struct Central<'stack, C> { pub(crate) stack: &'stack Stack<'stack, C>, diff --git a/host/src/gatt.rs b/host/src/gatt.rs index b4d3e771..3e0ceff0 100644 --- a/host/src/gatt.rs +++ b/host/src/gatt.rs @@ -8,8 +8,7 @@ use bt_hci::controller::Controller; use bt_hci::param::ConnHandle; use bt_hci::uuid::declarations::{CHARACTERISTIC, PRIMARY_SERVICE}; use bt_hci::uuid::descriptors::CLIENT_CHARACTERISTIC_CONFIGURATION; -use embassy_sync::blocking_mutex::raw::NoopRawMutex; -use embassy_sync::blocking_mutex::raw::RawMutex; +use embassy_sync::blocking_mutex::raw::{NoopRawMutex, RawMutex}; use embassy_sync::channel::{Channel, DynamicReceiver}; use embassy_sync::pubsub::{self, PubSubChannel, WaitResult}; use heapless::Vec; diff --git a/host/src/lib.rs b/host/src/lib.rs index 67ec0cf4..edef180c 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -15,6 +15,7 @@ use core::mem::MaybeUninit; use advertise::AdvertisementDataError; use bt_hci::cmd::status::ReadRssi; use bt_hci::cmd::{AsyncCmd, SyncCmd}; +use bt_hci::param::{AddrKind, BdAddr}; use bt_hci::FromHciBytesError; use crate::att::AttErrorCode; @@ -22,7 +23,6 @@ use crate::channel_manager::{ChannelStorage, PacketChannel}; use crate::connection_manager::{ConnectionStorage, EventChannel}; use crate::l2cap::sar::SarType; use crate::packet_pool::PacketPool; -use bt_hci::param::{AddrKind, BdAddr}; mod fmt; @@ -44,11 +44,10 @@ mod pdu; pub mod peripheral; pub mod types; -#[cfg(feature = "peripheral")] -use peripheral::*; - #[cfg(feature = "central")] use central::*; +#[cfg(feature = "peripheral")] +use peripheral::*; pub mod advertise; pub mod connection; @@ -66,7 +65,6 @@ use host::{AdvHandleState, BleHost, HostMetrics, Runner}; #[allow(missing_docs)] pub mod prelude { - pub use super::Host; pub use bt_hci::param::{AddrKind, BdAddr, LeConnRole as Role}; pub use bt_hci::uuid::*; #[cfg(feature = "derive")] @@ -75,7 +73,7 @@ pub mod prelude { pub use trouble_host_macros::*; pub use super::att::AttErrorCode; - pub use super::{BleHostError, Controller, Error, HostResources, Stack}; + pub use super::{BleHostError, Controller, Error, Host, HostResources, Stack}; #[cfg(feature = "peripheral")] pub use crate::advertise::*; #[cfg(feature = "gatt")] @@ -376,9 +374,10 @@ pub fn new< #[cfg(feature = "gatt")] let tx_pool = unsafe { core::mem::transmute::<&'resources dyn Pool, &'static dyn Pool>(tx_pool) }; + use bt_hci::param::ConnHandle; + use crate::l2cap::sar::AssembledPacket; use crate::types::l2cap::L2capHeader; - use bt_hci::param::ConnHandle; let connections: &mut [ConnectionStorage] = &mut *resources.connections.write([ConnectionStorage::DISCONNECTED; CONNS]); let connections: &'resources mut [ConnectionStorage] = unsafe { transmute_slice(connections) }; diff --git a/host/src/scan.rs b/host/src/scan.rs index d516c329..a73ed242 100644 --- a/host/src/scan.rs +++ b/host/src/scan.rs @@ -1,17 +1,16 @@ //! Scan config. -use crate::command::CommandState; -use crate::connection::ScanConfig; -use crate::BleHostError; -use bt_hci::cmd::le::LeSetScanParams; use bt_hci::cmd::le::{ LeAddDeviceToFilterAcceptList, LeClearFilterAcceptList, LeSetExtScanEnable, LeSetExtScanParams, LeSetScanEnable, + LeSetScanParams, }; use bt_hci::controller::{Controller, ControllerCmdSync}; use bt_hci::param::{AddrKind, FilterDuplicates, ScanningPhy}; pub use bt_hci::param::{LeAdvReportsIter, LeExtAdvReportsIter}; use embassy_time::Instant; -use crate::Central; +use crate::command::CommandState; +use crate::connection::ScanConfig; +use crate::{BleHostError, Central}; /// A scanner that wraps a central to provide additional functionality /// around BLE scanning. diff --git a/host/tests/common.rs b/host/tests/common.rs index 4004a754..e73572e0 100644 --- a/host/tests/common.rs +++ b/host/tests/common.rs @@ -1,8 +1,9 @@ +use std::path::PathBuf; + use bt_hci::controller::ExternalController; use bt_hci::transport::SerialTransport; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embedded_io_adapters::tokio_1::FromTokio; -use std::path::PathBuf; use tokio::io::{ReadHalf, WriteHalf}; use tokio::time::Duration; use tokio_serial::{DataBits, Parity, SerialStream, StopBits};