diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 00000000..8e390bc1 --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,175 @@ +# 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: # yamllint disable-line rule:truthy - false positive + # Comment this line to trigger action only on pull-requests + # (not recommended if you don't pay for GH Actions) + push: + + 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: commit + + concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + + permissions: {} + + jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + # Give the default GITHUB_TOKEN write permission to commit and push, comment + # issues & post new PR; remove the ones you do not need + permissions: + contents: write + issues: write + pull-requests: 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 + + id: ml + + # All available variables are described in documentation + # https://megalinter.io/latest/configuration/ + 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' && + # contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) + # }} + VALIDATE_ALL_CODEBASE: >- + ${{ + github.event_name == 'push' && + contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) + }} + + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE + # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY + + # Uncomment to disable copy-paste and spell checks + # DISABLE: COPYPASTE,SPELL + + # Upload MegaLinter artifacts + - name: Archive production artifacts + if: success() || failure() + uses: actions/upload-artifact@v4 + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log + + # Set APPLY_FIXES_IF var for use in future steps + - name: Set APPLY_FIXES_IF var + run: | + printf 'APPLY_FIXES_IF=%s\n' "${{ + steps.ml.outputs.has_updated_sources == 1 && + ( + env.APPLY_FIXES_EVENT == 'all' || + env.APPLY_FIXES_EVENT == github.event_name + ) && + ( + github.event_name == 'push' || + github.event.pull_request.head.repo.full_name == github.repository + ) + }}" >> "${GITHUB_ENV}" + + # Set APPLY_FIXES_IF_* vars for use in future steps + - name: Set APPLY_FIXES_IF_* vars + run: | + printf 'APPLY_FIXES_IF_PR=%s\n' "${{ + env.APPLY_FIXES_IF == 'true' && + env.APPLY_FIXES_MODE == 'pull_request' + }}" >> "${GITHUB_ENV}" + printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{ + env.APPLY_FIXES_IF == 'true' && + env.APPLY_FIXES_MODE == 'commit' && + (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)) + }}" >> "${GITHUB_ENV}" + + # 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: env.APPLY_FIXES_IF_PR == 'true' + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + commit-message: "[MegaLinter] Apply linters automatic fixes" + title: "[MegaLinter] Apply linters automatic fixes" + labels: bot + + - name: Create PR output + if: env.APPLY_FIXES_IF_PR == 'true' + run: | + echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}" + + # Push new commit if applicable + # (for now works only on PR from same repository, not from forks) + - name: Prepare commit + if: env.APPLY_FIXES_IF_COMMIT == 'true' + run: sudo chown -Rc $UID .git/ + + - name: Commit and push applied linter fixes + uses: stefanzweifel/git-auto-commit-action@v4 + if: env.APPLY_FIXES_IF_COMMIT == 'true' + with: + branch: >- + ${{ + github.event.pull_request.head.ref || + github.head_ref || + github.ref + }} + commit_message: "[MegaLinter] Apply linters fixes" + commit_user_name: megalinter-bot + commit_user_email: nicolas.vuillamy@ox.security \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7db2abcc..5c57fde8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Compiled files /target/ +utils/target/ # Dependency directories Cargo.lock @@ -13,4 +14,5 @@ Cargo.toml.bkp *.rs.bk # Editor-specific files -.idea/ \ No newline at end of file +.idea/ +megalinter-reports/ diff --git a/.markdownlint.json b/.markdownlint.json deleted file mode 100644 index cec4996d..00000000 --- a/.markdownlint.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "line-length": { - "line_length": 800, - "code_blocks": false, - "tables": true - } -} \ No newline at end of file diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 00000000..d555b3c6 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,34 @@ +# 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 +- COPYPASTE_JSCPD +# DISABLE: +# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes +# - SPELL # Uncomment to disable checks of spelling mistakes + +SHOW_ELAPSED_TIME: true + +FILEIO_REPORTER: false + +# Uncomment if you want MegaLinter to detect errors but not block CI to pass +DISABLE_ERRORS: false +GITHUB_COMMENT_REPORTER: true +GITHUB_STATUS_REPORTER: true diff --git a/README.md b/README.md new file mode 100644 index 00000000..bede1688 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +# 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): + +>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). + +## 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) diff --git a/ReadMe.md b/ReadMe.md deleted file mode 100644 index 3a907bcd..00000000 --- a/ReadMe.md +++ /dev/null @@ -1,62 +0,0 @@ -# TMAG5273 Rust Driver - -## 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): - ->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`. - -## 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) diff --git a/examples/ReadMe.md b/examples/README.md similarity index 54% rename from examples/ReadMe.md rename to examples/README.md index 92c4e614..210ed3a9 100644 --- a/examples/ReadMe.md +++ b/examples/README.md @@ -2,10 +2,13 @@ ## Summary -Within this directory are a set of examples for different platforms the goal being to show the developer how to use the driver on each platform. The driver should be -platform agnostic and the API should be the same regardless of whether you are on MCU or Linux/Mac. However what will change is the setup of the I2C bus. +Within this directory are a set of examples for different platforms the goal +being to show the developer how to use the driver on each platform. The driver +should be platform agnostic and the API should be the same regardless of whether +you are on MCU or Linux/Mac. However what will change is the setup of the I2C bus. -When working on a desktop environment the sensor will be attached via [FT232H Breakout Board](https://www.adafruit.com/product/2264) +When working on a desktop environment the sensor will be attached via +[FT232H Breakout Board](https://www.adafruit.com/product/2264) The different set ups are shown below in the architectural diagram: ![alt text](../docs/Example%20Setup.png) @@ -14,7 +17,8 @@ The different set ups are shown below in the architectural diagram: ### How to Install (Desktop Linux) -When working with the Desktop Linux you may find you need to install the following in order to work with the [FT232H](https://www.adafruit.com/product/2264) +When working with the Desktop Linux you may find you need to install the following +in order to work with the [FT232H](https://www.adafruit.com/product/2264) ```bash sudo apt update @@ -33,7 +37,8 @@ If you are having trouble it may be worth looking into: - [CircuitPython Libraries on Any Computer with FT232H](https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h/mac-osx) -or subsequently brew might not install correctly the libftdi library. It may be worth unlinking and linking the library using the following command: +or subsequently brew might not install correctly the libftdi library. It may be +worth unlinking and linking the library using the following command: ```bash brew unlink libftdi && brew link libftdi @@ -41,7 +46,8 @@ brew unlink libftdi && brew link libftdi ## Optional Dependencies -When listing usb devices you might find ```lsusb``` useful to which you will need to do the following: +When listing usb devices you might find `lsusb` useful to which you will +need to do the following: ### Linux @@ -58,7 +64,11 @@ brew install lsusb ## How to Run -When running the examples you can choose whether or not you are using the default features or not. The default in this case is using the [F232H breakout Board](https://www.adafruit.com/product/2264). If for example you are on an embedded linux target such as [Raspberry Pi 4](https://thepihut.com/products/raspberry-pi-4-model-b?srsltid=AfmBOoolrtsYiOQS76-MPYKOBSdasCelv9UJTsQdYcnP0x3TWljbWtMN) you can use the `rpi` feature that will use the on board i2c hardware. This will swap the `setup_i2c` method and allow the examples to work as expected. +When running the examples you can choose whether or not you are using the default +features or not. The default in this case is using the [F232H breakout Board](https://www.adafruit.com/product/2264). +If for example you are on an embedded linux target such as [Raspberry Pi 4](https://thepihut.com/products/raspberry-pi-4-model-b?srsltid=AfmBOoolrtsYiOQS76-MPYKOBSdasCelv9UJTsQdYcnP0x3TWljbWtMN) +you can use the `rpi` feature that will use the on board i2c hardware. +This will swap the `setup_i2c` method and allow the examples to work as expected. ```bash cargo build @@ -68,15 +78,21 @@ cargo run --example example_1_basic_readings --no-default-features --features rp ### Running a BareMetal Example -As the library adheres to the [embedded-hal](https://docs.rs/embedded-hal/latest/embedded_hal/), the library should be able to run in `no-std` environment such as baremetal. A [esp32c3](https://github.com/esp-rs/esp-rust-board)example is shown [here](./esp32-c3/src/main.rs). Due to it using a baremetal environment its recommended to go to that directory and call cargo run from within it and flash the code on to the device. +As the library adheres to the [embedded-hal](https://docs.rs/embedded-hal/latest/embedded_hal/), +the library should be able to run in `no-std` environment. A +[esp32c3](https://github.com/esp-rs/esp-rust-board) example is shown [here](./esp32-c3/src/main.rs). +Due to it using a baremetal environment its recommended to go to that directory +and call `cargo run` from within it and flash the code on to the device. ### SparkFun Examples -The examples provided for `std` targets are heavily based off the corresponding Arduino/C++ Library written by Sparkfun linked [here](https://github.com/sparkfun/SparkFun_TMAG5273_Arduino_Library). +The examples provided for `std` targets are heavily based off the corresponding +Arduino/C++ Library written by Sparkfun linked [here](https://github.com/sparkfun/SparkFun_TMAG5273_Arduino_Library). ### F232H on MAC -When working with the [FT32H](https://www.adafruit.com/product/2264), you must find the right device id, this can be done by using `lsusb`: +When working with [FT32H](https://www.adafruit.com/product/2264), you must +find the right device id, this can be done by using `lsusb`: ```bash ❯ lsusb diff --git a/src/lib.rs b/src/lib.rs index b7a355c6..564f426a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,8 @@ where pub fn get_manufacturer_id(&mut self) -> Result { let mut data: [u8; 2] = [0x00, 0x00]; let register_address = TMAG5273Register::ManufacturerIdLsb.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; let manufacturer_id = u16::from_le_bytes(data); match manufacturer_id != MANUFACTURER_ID_VALUE { @@ -174,7 +175,8 @@ where let threshold_normalized = { let mut buf: [u8; 1] = [0x00]; let register_address = register.into(); - self.i2c.write_read(self.address, &[register_address], &mut buf)?; + self.i2c + .write_read(self.address, &[register_address], &mut buf)?; let threshold_raw = i8::from_le_bytes(buf); // always one byte (-128 to 127) threshold_raw as f32 / 128.0 // convert to -1.0 to 1.0 }; @@ -203,7 +205,8 @@ where pub fn get_magnetic_gain(&mut self) -> Result { let mut data: [u8; 1] = [0x00]; let register_address = TMAG5273Register::MagGainConfig.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; Ok(data[0]) } @@ -253,7 +256,8 @@ where let _data = { let mut buf: [u8; 1] = [0x00]; let register_address = register_address.into(); - self.i2c.write_read(self.address, &[register_address], &mut buf)?; + self.i2c + .write_read(self.address, &[register_address], &mut buf)?; buf[0] // always one byte }; unimplemented!("Offset doesn't work yet"); @@ -273,7 +277,8 @@ where self.check_temp_channel()?; let mut data: [u8; 2] = [0x00; 2]; let register_address = TMAG5273Register::TMsbResult.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; Ok(Self::convert_temp(data)) } @@ -321,7 +326,8 @@ where let range = range.get_range(self.device_version); let mut data: [u8; 2] = [0x00; 2]; let register_address = register.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; Ok(Self::convert_magnetism(axis, data, range)) } @@ -341,7 +347,8 @@ where // Full Data Read let mut data: [u8; 8] = [0x00; 8]; let register_address = TMAG5273Register::TMsbResult.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; let xy_range = config2.xy_range().get_range(self.device_version); let z_range = config2.z_range().get_range(self.device_version); @@ -363,7 +370,8 @@ where } let mut data = [0x00; 2]; let register_address = TMAG5273Register::AngleResultMSB.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; // The angle is calculated as follows: // x x x x x x x x x x x x x x x x @@ -381,7 +389,8 @@ where pub fn get_magnitude(&mut self) -> Result { let mut data: [u8; 1] = [0x00]; let register_address = TMAG5273Register::MagnitudeResult.into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; Ok(data[0]) } @@ -444,7 +453,8 @@ where fn check_temp_channel(&mut self) -> Result<(), TMag5273Error> { let register_address = TMAG5273Register::TConfig.into(); let mut data: [u8; 1] = [0x00]; - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; let tch_en = TConfigRegister::new_with_raw_value(data[0]).temperature_channel_enabled(); if tch_en { diff --git a/src/registers.rs b/src/registers.rs index 79d26f29..3fdf79cc 100644 --- a/src/registers.rs +++ b/src/registers.rs @@ -55,7 +55,8 @@ where { let mut data: [u8; 1] = [0x00]; let register_address = Register::get_address().into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; Ok(Register::new_with_raw_value(data[0])) } @@ -63,13 +64,14 @@ where /// /// Generic function to get a register value from the device. The Register must implement the traits /// ByteFieldDeviceConfiguration in order to get it from the device. - pub (crate) fn get_dual_config_register(&mut self) -> Result + pub(crate) fn get_dual_config_register(&mut self) -> Result where Register: ByteFieldDeviceConfiguration, { let mut data: [u8; 2] = [0x00, 2]; let register_address = Register::get_address().into(); - self.i2c.write_read(self.address, &[register_address], &mut data)?; + self.i2c + .write_read(self.address, &[register_address], &mut data)?; Ok(Register::new_with_raw_value(u16::from_le_bytes(data))) } } diff --git a/src/tests/README.md b/src/tests/README.md index f0e9cf8c..23097ee6 100644 --- a/src/tests/README.md +++ b/src/tests/README.md @@ -2,7 +2,9 @@ ## Summary -This folder contains all the unit tests and system integration tests for the library. Due to the nature of the device we can not run our tests concurrently as they are interacting with the hardware. As such we must run our tests with one thread: +This folder contains all the unit tests and system integration tests for the library. +Due to the nature of the device we can not run our tests concurrently as they are +interacting with the hardware. As such we must run our tests with one thread: ```bash cargo test -- --test-threads=1 @@ -16,6 +18,9 @@ cargo test -p tmag5273 --lib cold_start_tests -- --test-threads=1 # Run tests w Currently there are two sets of tests: -- [connection_tests](./connection_tests.rs) Tests if the device is on the bus and that it is the correct device. Ideally this should run first. -- [cold_start_tests](./cold_start_tests.rs) Tests the sensor from a 'cold' start, this requires the sensor to be power cycled. -- [setting_register_tests](./setting_registers_tests.rs) Tests the setting and resetting of registers on the sensor and the API for gathering. +- [connection_tests](./connection_tests.rs) Tests if the device is on the bus and +that it is the correct device. Ideally this should run first. +- [cold_start_tests](./cold_start_tests.rs) Tests the sensor from a 'cold' start, +this requires the sensor to be power cycled. +- [setting_register_tests](./setting_registers_tests.rs) Tests the setting and +resetting of registers on the sensor and the API for gathering. diff --git a/src/types.rs b/src/types.rs index 1f2f1ae8..48354ca5 100644 --- a/src/types.rs +++ b/src/types.rs @@ -26,7 +26,7 @@ impl DeviceVersion { Self::TMAG5273D1 | Self::TMAG5273D2 => 0x44, } } - + /// Gets the device id associated with the hardware version pub fn get_device_id(self) -> DeviceId { match self { diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 00000000..73801bc0 --- /dev/null +++ b/utils/README.md @@ -0,0 +1,22 @@ +# Utils + +## Summary + +This internal crate is a utilities package designed for connecting the Embedded +Targets to the Library as such it is not to be used as part of the library. + +The main thing this crate offers is a generic way of setting up the I2C Bus on +different Linux/MacOS targets. This is done through the `setup_i2c()` method +outlined in [lib.rs](./src/lib.rs). + +### Features + +This crates offers essentially two features: + +- std: This pulls in the [ftdi-embedded-hal](https://github.com/ftdi-rs/ftdi-embedded-hal/tree/main) +crate which allows the user to use the [F232H Breakout Board](https://thepihut.com/products/adafruit-ft232h-breakout-general-purpose-usb-to-gpio-spi-i2c) + +- rpi: This pulls both the [ftdi-embedded-hal](https://github.com/ftdi-rs/ftdi-embedded-hal/tree/main) +crate and the [rppal](https://github.com/golemparts/rppal) crate allowing the +user to select either I2C via hardware on the board or through the +[FT232H Breakout Board](https://thepihut.com/products/adafruit-ft232h-breakout-general-purpose-usb-to-gpio-spi-i2c). diff --git a/utils/ReadMe.md b/utils/ReadMe.md deleted file mode 100644 index 17315aa1..00000000 --- a/utils/ReadMe.md +++ /dev/null @@ -1,15 +0,0 @@ -# Utils - -## Summary - -This internal crate is a utilities package designed for connecting the Embedded Targets to the Library as such it is not to be used as part of the library. - -The main thing this crate offers is a generic way of setting up the I2C Bus on different Linux/MacOS targets. This is done through the ```setup_i2c()``` method outlined in [lib.rs](./src/lib.rs). - -### Features - -This crates offers essentially two features: - -- std: This pulls in the [ftdi-embedded-hal](https://github.com/ftdi-rs/ftdi-embedded-hal/tree/main) crate which allows the user to use the [F232H Breakout Board](https://thepihut.com/products/adafruit-ft232h-breakout-general-purpose-usb-to-gpio-spi-i2c) - -- rpi: This pulls both the [ftdi-embedded-hal](https://github.com/ftdi-rs/ftdi-embedded-hal/tree/main) crate and the [rppal](https://github.com/golemparts/rppal) crate allowing the user to select either I2C via hardware on the board or through the [FT232H Breakout Board](https://thepihut.com/products/adafruit-ft232h-breakout-general-purpose-usb-to-gpio-spi-i2c).