-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0135288
commit cd66858
Showing
7 changed files
with
222 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: cargo | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>"] | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
[](https://github.com/lucazulian/gp2y0e02b/actions?query=workflow%3Agp2y0e02b-ci) | ||
[](https://crates.io/crates/gp2y0e02b) | ||
[](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 = "<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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}; |