Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MegaLinter for Linting and Fixing #5

Merged
merged 127 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
8cfff98
Added Super Linter
ScottGibb Nov 20, 2024
182aa29
added Linting badge
ScottGibb Nov 20, 2024
59f25af
Added Markdownlint settings
ScottGibb Nov 20, 2024
e32a1b1
Turning on linters for all file types present in repo
ScottGibb Nov 20, 2024
02ca4ac
disabling on push trigger
ScottGibb Nov 20, 2024
8b80603
added Rust linting
ScottGibb Nov 20, 2024
97f0d3c
changed markdownlint from json to yaml
ScottGibb Nov 20, 2024
9e1acb2
Fixed Markdown linting issues
ScottGibb Nov 20, 2024
1a2f1b9
updated all ReadMe Violations
ScottGibb Nov 20, 2024
2b5a2aa
Adding lint fixing
ScottGibb Nov 20, 2024
f45055a
Added fmt stage
ScottGibb Nov 20, 2024
5740033
Added .gitignore
ScottGibb Nov 20, 2024
1c44ac3
Updated linting and formatting
ScottGibb Nov 20, 2024
e275a84
Added Checkout Code Stage
ScottGibb Nov 20, 2024
e405099
Added Clippy and fmt into workflow
ScottGibb Nov 20, 2024
502d2b9
Updating src fmt
ScottGibb Nov 20, 2024
a703659
Fixed clippy issue
ScottGibb Nov 22, 2024
7818031
Added comment about issue
ScottGibb Nov 22, 2024
e7bee80
Added linting rules
ScottGibb Nov 22, 2024
44e0667
Added todo
ScottGibb Nov 22, 2024
54c84f9
Fixed script formatting
ScottGibb Nov 22, 2024
593a20f
Fixed badge
ScottGibb Nov 22, 2024
4a2d876
Added some new linters
ScottGibb Nov 22, 2024
604f94f
using ` instead of ```
ScottGibb Nov 22, 2024
265842c
removed "such as baremetal"
ScottGibb Nov 22, 2024
1c5c78c
Adding markdown glob that should catch all files now
ScottGibb Nov 22, 2024
2b7061e
Fixed README docs
ScottGibb Nov 22, 2024
b534acf
Adding Lint Fixing Workflow
ScottGibb Nov 22, 2024
3239bbe
added Textlint rules
ScottGibb Nov 22, 2024
b66f400
removed extra spaces
ScottGibb Nov 22, 2024
cfce6f6
Updated README
ScottGibb Nov 22, 2024
96529fe
Attempting to fix linter fix stage
ScottGibb Nov 22, 2024
9a1d28e
Attempt at fixing linter
ScottGibb Nov 22, 2024
04b7d8d
test
ScottGibb Nov 22, 2024
eb57892
Added Fix Flow
ScottGibb Nov 22, 2024
2773558
Fixed util readme issues
ScottGibb Nov 22, 2024
a5989fe
Attempt at using megalinter
ScottGibb Nov 22, 2024
1fe2957
added permissions
ScottGibb Nov 22, 2024
9d873f5
restructuring permissions
ScottGibb Nov 22, 2024
d86dd57
mega linter settings
ScottGibb Nov 22, 2024
e6ae701
removed the 'the'
ScottGibb Nov 25, 2024
9183a4c
configured megalinter
ScottGibb Nov 25, 2024
570d002
created two markdown errors
ScottGibb Nov 25, 2024
9bd1558
Messing around with CI configuration
ScottGibb Nov 25, 2024
653ba86
testing
ScottGibb Nov 25, 2024
2f2ee60
added MegaLinter
ScottGibb Nov 25, 2024
45c7284
updated linter
ScottGibb Nov 25, 2024
aedae88
fixed env variable
ScottGibb Nov 25, 2024
d36dfdb
possivble syntax error
ScottGibb Nov 25, 2024
5033865
reformatting
ScottGibb Nov 25, 2024
1246eee
test
ScottGibb Nov 25, 2024
9b5f461
attempting to fix the aply fix stage
ScottGibb Nov 25, 2024
87fde33
further testing
ScottGibb Nov 25, 2024
836dafa
ovveride
ScottGibb Nov 25, 2024
e8abc7f
reset workflow
ScottGibb Nov 25, 2024
e3d8e0e
Added more markdown lints
ScottGibb Nov 25, 2024
259dad2
Updated Megalinter settings
ScottGibb Nov 25, 2024
a37faef
Added permissions
ScottGibb Nov 25, 2024
05e461f
Setting to Validate All
ScottGibb Nov 25, 2024
0b7da20
Getting rid of broken link
ScottGibb Nov 25, 2024
132acce
Fixed main README
ScottGibb Nov 25, 2024
e53b2c4
changing to on push
ScottGibb Nov 25, 2024
0425dee
reset Linter
ScottGibb Nov 26, 2024
a07b5e9
changed Linters
ScottGibb Nov 26, 2024
23d844d
updates
ScottGibb Nov 26, 2024
ce151de
test commit
ScottGibb Nov 26, 2024
b161268
Fixing
ScottGibb Nov 26, 2024
a236d67
Added yamllint config
ScottGibb Nov 26, 2024
1cf5e34
adjsuted config
ScottGibb Nov 26, 2024
f35ea7c
Added working JOSNB, YAML and Markdown fixes, now fixes the code and …
ScottGibb Nov 26, 2024
c5eadf4
removing apply fixes
ScottGibb Nov 26, 2024
c388591
Added Linter vscode recommended extensions for linting
ScottGibb Nov 26, 2024
bd53afd
removed extra space
ScottGibb Nov 26, 2024
79e89c9
updated vscode recommended extensions
ScottGibb Nov 26, 2024
0a5ea9f
added faulty imports for clippy to find
ScottGibb Nov 26, 2024
434893f
removed
ScottGibb Nov 26, 2024
5bc6695
added command
ScottGibb Nov 26, 2024
b6a0ed4
added missing argument
ScottGibb Nov 26, 2024
6c7036b
utils and main examples confirmed linted
ScottGibb Nov 27, 2024
ff58116
added Rust Analyzer settings
ScottGibb Nov 27, 2024
c8b4a62
added some changes
ScottGibb Nov 27, 2024
3fb5594
runs on every file except esp32c3 example
ScottGibb Nov 27, 2024
ef4a358
Fixed codebase add formatter stage on the mega linter workflow
ScottGibb Nov 27, 2024
571642b
added pull_request flow
ScottGibb Nov 27, 2024
6957f1f
Fixed Linter
ScottGibb Nov 27, 2024
5218f6a
added missing cargo clippy checks
ScottGibb Nov 27, 2024
09e20cd
fixed false clippy error
ScottGibb Nov 27, 2024
dc75680
fixing GitHub permissions
ScottGibb Nov 27, 2024
ac3817e
adjusting permissions
ScottGibb Nov 27, 2024
0184f5d
Added statuses
ScottGibb Nov 27, 2024
a08754a
Merge branch 'main' into add-static-analysis
ScottGibb Nov 27, 2024
ad3656c
testng default branch
ScottGibb Nov 27, 2024
d06e019
linting updates
ScottGibb Nov 27, 2024
003fa9c
removde default branch
ScottGibb Nov 27, 2024
2fe7db6
Added deliberate lint issue
ScottGibb Nov 27, 2024
fa4de25
added default branch
ScottGibb Nov 28, 2024
44ad9e4
added base branch
ScottGibb Nov 28, 2024
9be2372
attempt at fixing
ScottGibb Nov 28, 2024
22ec2e0
added just the base
ScottGibb Nov 28, 2024
1dcb5ec
changed ref
ScottGibb Nov 28, 2024
90b77a4
added comment stage
ScottGibb Nov 28, 2024
bb3379f
fixed formatting
ScottGibb Nov 28, 2024
a29080a
Adjusting workflow triggers
ScottGibb Nov 28, 2024
bf326ba
added fail check
ScottGibb Nov 28, 2024
269ca0d
changed branch name
ScottGibb Nov 28, 2024
89d93a0
[MegaLinter] Apply linters automatic fixes (#11)
github-actions[bot] Nov 28, 2024
e6a2ebd
added bad spacing
ScottGibb Nov 28, 2024
62de040
slight lint change
ScottGibb Nov 28, 2024
8506354
fixed grammar
ScottGibb Nov 29, 2024
e985acd
changed to yaml
ScottGibb Nov 29, 2024
8cd89db
[MegaLinter] Apply linters automatic fixes (#12)
github-actions[bot] Nov 29, 2024
69a57e0
disabled line length check and relying on soft line wraps
ScottGibb Nov 29, 2024
802e42d
removed dead flow
ScottGibb Nov 29, 2024
a9d8815
removed yamllint settings
ScottGibb Nov 29, 2024
b959b89
removed yamllint config
ScottGibb Nov 29, 2024
39a3fc9
updated megalinter
ScottGibb Nov 29, 2024
21bbee2
added line length disable comment
ScottGibb Nov 29, 2024
bd66834
deliberate error
ScottGibb Nov 29, 2024
3464370
made another deliberate error
ScottGibb Nov 29, 2024
d89d8df
ovveridding markdownlint
ScottGibb Nov 29, 2024
70b9c45
attempting to override
ScottGibb Nov 29, 2024
6f550bd
added the lint config
ScottGibb Nov 29, 2024
88abd84
added teh config file back
ScottGibb Nov 29, 2024
b2a0dca
[MegaLinter] Apply linters automatic fixes (#14)
github-actions[bot] Nov 29, 2024
22799ae
added rust fmt section
ScottGibb Nov 29, 2024
32387ad
deliberate formatting error
ScottGibb Dec 5, 2024
36e1fb6
[MegaLinter] Apply linters automatic fixes (#16)
ScottGibb Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/dependabot.yml → .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: fix
prefix-development: chore
include: scope
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: fix
prefix-development: chore
include: scope

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: chore
include: scope
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: chore
include: scope
183 changes: 183 additions & 0 deletions .github/workflows/mega-linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# 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

# 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/flavors/rust@v8

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@v6
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

cargo_fmt:
name: Cargo Formatter
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Rustfmt check on src
run: cargo fmt --manifest-path Cargo.toml -- --check
- name: Rustfmt check on utils
run: cargo fmt --manifest-path utils/Cargo.toml -- --check
- name: Rustfmt check on esp32 example
run: cargo fmt --manifest-path examples/esp32-c3/Cargo.toml -- --check

cargo_clippy:
name: Cargo Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Clippy check on esp32 example
run: |
cd examples/esp32-c3
cargo clippy -- -D warnings
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Compiled files
/target/
utils/target/

# Dependency directories
Cargo.lock
Expand All @@ -13,4 +14,5 @@ Cargo.toml.bkp
*.rs.bk

# Editor-specific files
.idea/
.idea/
megalinter-reports/
8 changes: 1 addition & 7 deletions .markdownlint.json
ScottGibb marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{
"line-length": {
"line_length": 800,
"code_blocks": false,
"tables": true
}
}
{ "default": true, "line-length": false }
ScottGibb marked this conversation as resolved.
Show resolved Hide resolved
47 changes: 47 additions & 0 deletions .mega-linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# 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

# 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:
- "--workspace"
- "--all-targets"
- "--"
- "-D"
- "warnings"
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"DavidAnson.vscode-markdownlint",
jamessizeland marked this conversation as resolved.
Show resolved Hide resolved
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"darkriszty.markdown-table-prettify"
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rust-analyzer.linkedProjects": [
"utils/Cargo.toml",
"examples/esp32-c3/Cargo.toml"
]
}
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ defmt = ["dep:defmt"]
log = ["dep:log"]
std = ["utils/std"]
rpi = ["utils/rpi"]

[workspace]
members = [
"examples/esp32-c3",
jamessizeland marked this conversation as resolved.
Show resolved Hide resolved
"utils",
"./",
]
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# TMAG5273 Rust Driver

[![Linting](https://github.com/dysonltd/tmag5273/actions/workflows/Linting.yaml/badge.svg)](https://github.com/dysonltd/tmag5273/actions/workflows/Linting.yaml)

## Summary

This is a platform agnostic Rust Driver for the TMAG52732 3 Axis I2C Hall effect Sensor by Texas Instruments. The driver is based on the [embedded-hal](https://github.com/rust-embedded/embedded-hal) traits. For more information it is recommended to look at the docs using `cargo doc`

## The Device

An extract taken from the [Texas Instruments Datasheet](./docs/tmag5273.pdf):
jamessizeland marked this conversation as resolved.
Show resolved Hide resolved
>The TMAG5273 is a low-power linear 3D Hall-effect sensor designed for a wide range of industrial and personal electronics applications. This device integrates three independent Hall-effect sensors in the X, Y, and Z axes. A precision analog signal-chain along with an integrated 12-bit ADC digitizes the measured analog magnetic field values. The I2C interface, while supporting multiple operating VCC ranges, ensures seamless data communication with low-voltage microcontrollers. The device has an integrated temperature sensor available for multiple system functions, such as thermal budget check or temperature compensation calculation for a given magnetic field.The TMAG5273 can be configured through the I2C interface to enable any combination of magnetic axes and temperature measurements. Additionally, the device can be configured to various power options (including wake-up and sleep mode) allowing designers to optimize system power consumption based on their system-level needs. Multiple sensor conversion schemes and I2C read frames help optimize throughput and accuracy. A dedicated INT pin can act as a system interrupt during low power wake-up and sleep mode, and can also be used by a microcontroller to trigger a new sensor conversion.An integrated angle calculation engine (CORDIC) provides full 360° angular position information for both on-axis and off-axis angle measurement topologies. The angle calculation is performed using two user-selected magnetic axes. The device features magnetic gain and offset correction to mitigate the
impact of system mechanical error sources.The TMAG5273 is offered in four different factory-programmed I2C addresses. The device also supports additional I2C addresses through the modification
of a user-configurable I2C address register. Each orderable part can be configured to select one of two magnetic field ranges that suits the magnet strength and component placement during system calibration.

## Examples

Examples on how to use the driver across multiple platforms can be found [here](./examples/README.md)

## Architecture Diagrams

The rough architecture of the files and directories of the project can be seen in the following plantUML diagram.

![System Architecture](./docs/architecture.png)

As an application developer, you will spend most of your time working with the TMAG5273 struct outlined in [lib.rs](./src/lib.rs). The device can initialised by the `init_default` method and configuration can be done using the methods outlined in [config.rs](./src/config.rs). However for fine grained control of the device you can set and configure the raw registers outlined in the
folder [registers](./src/registers/). More information around the code can be found using `cargo doc`.

## Helper Utilities

In this repository we also have an internal crate called [utils](./utils/) which contains some simple rust code for using the library on either Raspberry Pi or a Desktop Linux/Mac Machine. For more information, please look at the following [README](./utils/README.md).

## Running your Linter Locally

This project uses [MegaLinter](https://github.com/oxsecurity/megalinter) which provides linters for various different file formats and languages. When a Pull request to main is done, the linters will run and ensure the codebase is in good standing. It is recommended that you run the linter locally beforehand as it can sometimes autofix common mistakes.

```bash
npx mega-linter-runner
```

You will need to have docker and Node installed to use this, more information can be found on their [repo](https://github.com/oxsecurity/megalinter)

### Issues with rust fmt

Currently at the time of this commit `rust fmt` is not supported as part of MegaLinter, thus to ensure it is correctly formatted we have added an extra build stage which can be seen [here](./.github/workflows/mega-linter.yaml). You can run this locally using

```bash
cargo fmt --all
```

## Useful Links

- [Embedded Hal](https://docs.rs/embedded-hal/latest/embedded_hal/)
- [TMAG5273 Breakout Board](https://www.sparkfun.com/products/23880)
- [FT232H Breakout Board](https://www.adafruit.com/product/2264)
Loading
Loading