diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5cde165 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/gp2y0e02b-ci.yml b/.github/workflows/gp2y0e02b-ci.yml new file mode 100644 index 0000000..ba962f0 --- /dev/null +++ b/.github/workflows/gp2y0e02b-ci.yml @@ -0,0 +1,129 @@ +--- +name: gp2y0e02b-ci + +on: + push: + branches: + - '**' + tags: + - "*.*.*" + schedule: + - cron: 0 0 * * 0 + +env: + RUSTFLAGS: '--deny warnings' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + rust: [stable, beta, nightly, 1.52.1, 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: + - 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: + args: --all-targets --all-features -- -D warnings + 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 diff --git a/.gitignore b/.gitignore index e3200e0..fa9d8f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,56 +1,13 @@ -*.gem -*.rbc -/.config -/coverage/ -/InstalledFiles -/pkg/ -/spec/reports/ -/spec/examples.txt -/test/tmp/ -/test/version_tmp/ -/tmp/ +# Generated by Cargo +# will have compiled files and executables +/target/ -# Used by dotenv library to load environment variables. -# .env +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock -# Ignore Byebug command history file. -.byebug_history +# These are backup files generated by rustfmt +**/*.rs.bk -## Specific to RubyMotion: -.dat* -.repl_history -build/ -*.bridgesupport -build-iPhoneOS/ -build-iPhoneSimulator/ - -## Specific to RubyMotion (use of CocoaPods): -# -# We recommend against adding the Pods directory to your .gitignore. However -# you should judge for yourself, the pros and cons are mentioned at: -# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control -# -# vendor/Pods/ - -## Documentation cache and generated files: -/.yardoc/ -/_yardoc/ -/doc/ -/rdoc/ - -## Environment normalization: -/.bundle/ -/vendor/bundle -/lib/bundler/man/ - -# for a library or gem, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# Gemfile.lock -# .ruby-version -# .ruby-gemset - -# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: -.rvmrc - -# Used by RuboCop. Remote config files pulled in from inherit_from directive. -# .rubocop-https?--* +# CLion +.idea/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6430477 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "gp2y0e02b" +version = "0.1.0" +description = "A rust driver for the GP2Y0E02B (SHARP I2C Distance Measuring Sensor, 4-50cm)" +authors = ["Luca Zulian "] +categories = ["embedded", "hardware-support", "no-std"] +keywords = ["hal", "IO"] +license = "MIT" +readme = "README.md" +repository = "https://github.com/lucazulian/gp2y0e02b" +edition = "2018" +exclude = [] + +[dependencies] +embedded-hal = "0.2.3" +generic-array = "0.14.5" +nb = "1.0.0" + +[dependencies.cast] +default-features = false +version = "0.3.0" +uninit = "0.1.0" diff --git a/LICENSE b/LICENSE index 3099880..4363cf1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 luca zulian +Copyright (c) 2019 Luca Zulian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 730a71f..4bc3532 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ -# gp2y0e02b -GP2Y0E02B a SHARP I2C Distance Measuring Sensor, 4-50cm +# `gp2y0e02b` + +> no_std driver for [GP2Y0E02B](https://www.sharpsde.com/fileadmin/products/Optoelectronics/Sensors/Specs/GP2Y0E02B_TI_OP13004EN.pdf) (SHARP I2C Distance Measuring Sensor, 4-50cm) + +[![Build Status](https://github.com/lucazulian/gp2y0e02b/workflows/gp2y0e02b-ci/badge.svg)](https://github.com/lucazulian/gp2y0e02b/actions?query=workflow%3Agp2y0e02b-ci) +[![crates.io](https://img.shields.io/crates/v/gp2y0e02b.svg)](https://crates.io/crates/gp2y0e02b) +[![Docs](https://docs.rs/gp2y0e02b/badge.svg)](https://docs.rs/gp2y0e02b) + +## Basic usage + +Include this [library](https://crates.io/crates/gp2y0e02b) as a dependency in your `Cargo.toml`: + +```rust +[dependencies.gp2y0e02b] +version = "" +``` + +Use [embedded-hal](https://github.com/rust-embedded/embedded-hal) implementation to get I2C handle and then create gp2y0e02b handle. + +```rust +extern crate gp2y0e02b; +``` + +## License + +[MIT license](http://opensource.org/licenses/MIT) diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..17b91b9 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,27 @@ +#![no_std] + +//! Manages a new GP2Y0E02B, SHARP I2C Distance Measuring Sensor, 4-50cm + +#![deny( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + trivial_casts, + unstable_features, + unused_import_braces, + unused_qualifications, + warnings +)] +#![allow(dead_code)] +#![allow(clippy::uninit_assumed_init, clippy::upper_case_acronyms)] + +extern crate cast; +extern crate embedded_hal as ehal; +extern crate generic_array; +extern crate nb; + +use cast::u16; +use core::mem::MaybeUninit; +use ehal::blocking::i2c::{Read, Write, WriteRead}; +use generic_array::typenum::consts::*; +use generic_array::{ArrayLength, GenericArray};