Skip to content

Commit

Permalink
Merge c8eb858 into 3b848d9
Browse files Browse the repository at this point in the history
  • Loading branch information
lucazulian committed Jan 26, 2021
2 parents 3b848d9 + c8eb858 commit ac01e9a
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 23 deletions.
149 changes: 149 additions & 0 deletions .github/workflows/em7180-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: em7180-ci

on:
push:
pull_request:
schedule:
- cron: 0 0 * * 0

env:
RUSTFLAGS: '--deny warnings'

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly, 1.49.0]
TARGET:
#- x86_64-unknown-linux-gnu
#- x86_64-unknown-linux-musl
#- arm-unknown-linux-gnueabi # Raspberry Pi 1
#- armv7-unknown-linux-gnueabihf # Raspberry Pi 2, 3, etc
# Bare metal
#- thumbv6m-none-eabi
- thumbv7em-none-eabi
- thumbv7em-none-eabihf
- thumbv7m-none-eabi

include:
# Test nightly but don't fail
- rust: nightly
experimental: true

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.TARGET }}
override: true

- name: Checkout CI scripts
uses: actions/checkout@v2
with:
repository: 'eldruin/rust-driver-ci-scripts'
ref: 'master'
path: 'ci'

- run: ./ci/patch-no-std.sh
if: ${{ ! contains(matrix.TARGET, 'x86_64') }}

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.TARGET }}

checks:
name: Checks
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta]
TARGET:
- x86_64-unknown-linux-gnu

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.TARGET }}
override: true
components: clippy, rustfmt

- name: Doc
uses: actions-rs/cargo@v1
with:
command: doc

- name: Formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

test:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly]
TARGET: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl]
include:
- rust: nightly
experimental: true
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.TARGET }}
override: true

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --target=${{ matrix.TARGET }}

- name: Build examples
uses: actions-rs/cargo@v1
if: contains(matrix.TARGET, 'x86_64')
with:
command: build
args: --target=${{ matrix.TARGET }} --examples

coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
with:
args: '--out Lcov -- --test-threads 1'

- name: upload to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: './lcov.info'
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

> no_std driver for [EM7180](https://github.com/kriswiner/EM7180_SENtral_sensor_hub/wiki) (Sensor hub with MPU9250 gyro/accelerometer, embedded Asahi Kasei AK8963C magnetometer, Measurement Specialties' MS5637 Barometer, and ST's M24512DFC I2C EEPROM module)
[![Build Status](https://travis-ci.org/lucazulian/em7180.svg?branch=master)](https://travis-ci.org/lucazulian/em7180)
[![Build Status](https://github.com/lucazulian/em7180/workflows/em7180-ci/badge.svg)](https://github.com/lucazulian/em7180/actions?query=workflow%3Aem7180-ci)
[![crates.io](http://meritbadge.herokuapp.com/em7180?style=flat-square)](https://crates.io/crates/em7180)
[![Docs](https://docs.rs/em7180/badge.svg)](https://docs.rs/em7180)
[![Coverage Status](https://coveralls.io/repos/github/lucazulian/em7180/badge.svg?branch=master)](https://coveralls.io/github/lucazulian/em7180?branch=master)

## Basic usage

Expand All @@ -13,9 +16,7 @@ Include this [library](https://crates.io/crates/em7180) as a dependency in your
version = "<version>"
```

## Documentation

API Docs available on [docs.rs](https://docs.rs/em7180/0.1.0/em7180/)
## Sensor documentation

[EM7180 SENtral Sensor Fusion Coprocessor](https://www.emmicroelectronic.com/sites/default/files/products/datasheets/7180sfp-ds.pdf)

Expand Down
38 changes: 19 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
unused_qualifications,
//warnings
)]
#![allow(dead_code)]
#![allow(dead_code, clippy::uninit_assumed_init, clippy::too_many_arguments)]

extern crate cast;
extern crate embedded_hal as ehal;
Expand Down Expand Up @@ -197,7 +197,7 @@ where
self.write_register(Register::EM7180_AlgorithmControl, 0x80)?; // Request parameter transfer procedure
let mut stat = self.read_register(Register::EM7180_ParamAcknowledge)?; // Check the parameter acknowledge register and loop until the result matches parameter request byte

while !(stat == param) {
while stat != param {
stat = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

Expand All @@ -221,7 +221,7 @@ where
self.write_register(Register::EM7180_AlgorithmControl, 0x80)?; // Request parameter transfer procedure
let mut stat = self.read_register(Register::EM7180_ParamAcknowledge)?; // Check the parameter acknowledge register and loop until the result matches parameter request byte

while !(stat == 0xCA) {
while stat != 0xCA {
stat = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

Expand All @@ -245,7 +245,7 @@ where
self.write_register(Register::EM7180_AlgorithmControl, 0x80)?; // Request parameter transfer procedure
let mut stat = self.read_register(Register::EM7180_ParamAcknowledge)?; // Check the parameter acknowledge register and loop until the result matches parameter request byte

while !(stat == 0xCB) {
while stat != 0xCB {
stat = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

Expand All @@ -261,7 +261,7 @@ where
let mut count = 0;
while stat != 0 {
self.write_register(Register::EM7180_ResetRequest, 0x01)?;
count = count + 1;
count += 1;
stat = self.read_register(Register::EM7180_SentralStatus)? & 0x01;
if count > 10 {
break;
Expand Down Expand Up @@ -315,13 +315,13 @@ where

self.write_register(Register::EM7180_AlgorithmControl, 0x80)?; // Request parameter transfer process
let mut param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
while !(param_xfer == 0x4A) {
while param_xfer != 0x4A {
param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

self.write_register(Register::EM7180_ParamRequest, 0x4B)?; // Request to read parameter 75
let mut param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
while !(param_xfer == 0x4B) {
while param_xfer != 0x4B {
param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

Expand All @@ -339,13 +339,13 @@ where
self.write_register(Register::EM7180_ParamRequest, 0x4A)?; // Request to read parameter 74
self.write_register(Register::EM7180_AlgorithmControl, 0x80)?; // Request parameter transfer process
let mut param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
while !(param_xfer == 0x4A) {
while param_xfer != 0x4A {
param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

self.write_register(Register::EM7180_ParamRequest, 0x4B)?; // Request to read parameter 75
let mut param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
while !(param_xfer == 0x4B) {
while param_xfer != 0x4B {
param_xfer = self.read_register(Register::EM7180_ParamAcknowledge)?;
}

Expand Down Expand Up @@ -392,16 +392,16 @@ where

/// Check ErrorRegister Software-Related Error Conditions on address 0x50
/// Non-zero value indicates an error
/// value | error condition | response
/// 0x00 | no error |
/// 0x80 | invalid sample rate selected | check sensor rate settings
/// 0x30 | mathematical error | check for software updates
/// 0x21 | Magnetometer initialization failed | this error can be caused by a wrong driver,
/// 0x22 | accelerometer initialization failed | physically bad sensor connection, or
/// 0x24 | gyroscope initialization failed | incorrect I2C device address in the driver
/// 0x11 | magnetometer rate failure | this error indicates the given sensor
/// 0x12 | accelerometer rate failure | is unreliable and has stopped
/// 0x14 | Gyroscope rate failure | producing data
/// value | error condition | response
/// 0x00 | no error |
/// 0x80 | invalid sample rate selected | check sensor rate settings
/// 0x30 | mathematical error | check for software updates
/// 0x21 | Magnetometer initialization failed | this error can be caused by a wrong driver,
/// 0x22 | accelerometer initialization failed | physically bad sensor connection, or
/// 0x24 | gyroscope initialization failed | incorrect I2C device address in the driver
/// 0x11 | magnetometer rate failure | this error indicates the given sensor
/// 0x12 | accelerometer rate failure | is unreliable and has stopped
/// 0x14 | Gyroscope rate failure | producing data
pub fn check_errors(&mut self) -> Result<u8, E> {
self.read_register(Register::EM7180_Error)
}
Expand Down

0 comments on commit ac01e9a

Please sign in to comment.