Skip to content

Commit 9dfb04b

Browse files
committed
move to v0.2.0 of embedded-hal
1 parent 903a986 commit 9dfb04b

File tree

7 files changed

+37
-61
lines changed

7 files changed

+37
-61
lines changed

.travis.yml

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,36 @@
1-
# Based on the "trust" template v0.1.2
2-
# https://github.com/japaric/trust/tree/v0.1.2
3-
41
language: rust
5-
services: docker
62

73
matrix:
84
include:
9-
# Linux
105
- env: TARGET=x86_64-unknown-linux-gnu
11-
rust: nightly
126

13-
# Bare metal
147
- env: TARGET=thumbv6m-none-eabi
15-
rust: nightly
8+
rust: beta
9+
1610
- env: TARGET=thumbv7m-none-eabi
17-
rust: nightly
18-
- env: TARGET=thumbv7em-none-eabi
19-
rust: nightly
20-
- env: TARGET=thumbv7em-none-eabihf
21-
rust: nightly
11+
rust: beta
2212

2313
before_install:
2414
- set -e
25-
- rustup self update
2615

2716
install:
28-
- sh ci/install.sh
29-
- source ~/.cargo/env || true
17+
- bash ci/install.sh
3018

3119
script:
3220
- bash ci/script.sh
3321

3422
after_script: set +e
3523

36-
cache:
37-
cargo: true
38-
directories:
39-
- $HOME/.xargo
24+
cache: cargo
4025

4126
before_cache:
4227
# Travis can't cache files that are not readable by "others"
4328
- chmod -R a+r $HOME/.cargo
4429

4530
branches:
4631
only:
47-
- auto
48-
- master
49-
- try
32+
- staging
33+
- trying
5034

5135
notifications:
5236
email:

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.2.0] - 2018-05-11
11+
12+
### Changed
13+
14+
- [breaking-change] moved to v0.2.0 of the `embedded-hal` traits
15+
1016
## [v0.1.2] - 2018-02-19
1117

1218
### Added
@@ -28,5 +34,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2834
Initial release
2935

3036
[Unreleased]: https://github.com/japaric/l3gd20/compare/v0.1.2...HEAD
37+
[v0.2.0]: https://github.com/japaric/l3gd20/compare/v0.1.2...v0.2.0
3138
[v0.1.2]: https://github.com/japaric/l3gd20/compare/v0.1.1...v0.1.2
3239
[v0.1.1]: https://github.com/japaric/l3gd20/compare/v0.1.0...v0.1.1

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ keywords = ["embedded-hal-driver", "gyroscope", "MEMS"]
77
license = "MIT OR Apache-2.0"
88
name = "l3gd20"
99
repository = "https://github.com/japaric/l3gd20"
10-
version = "0.1.2"
10+
version = "0.2.0"
1111

1212
[dependencies]
13-
embedded-hal = "0.1.0"
13+
# embedded-hal = "0.2.0"
14+
embedded-hal = { git = "https://github.com/japaric/embedded-hal" }
15+
generic-array = "0.11.0"

bors.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
status = [
2+
"continuous-integration/travis-ci/push",
3+
]

ci/install.sh

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
set -ex
1+
set -euxo pipefail
22

33
main() {
4-
# This fetches latest stable release of Xargo
5-
local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/xargo \
6-
| cut -d/ -f3 \
7-
| grep -E '^v[0.1.0-9.]+$' \
8-
| sort --version-sort \
9-
| tail -n1)
10-
11-
curl -LSfs https://japaric.github.io/trust/install.sh | \
12-
sh -s -- \
13-
--force \
14-
--git japaric/xargo \
15-
--tag $tag \
16-
--target x86_64-unknown-linux-musl
17-
18-
rustup component add rust-src
4+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
5+
rustup target add $TARGET
6+
fi
197
}
208

219
main

ci/script.sh

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
# This script takes care of testing your crate
2-
31
set -euxo pipefail
42

53
main() {
6-
case $TARGET in
7-
x86_64-unknown-linux-gnu)
8-
cargo check --target $TARGET
9-
;;
10-
*)
11-
xargo check --target $TARGET
12-
;;
13-
esac
4+
cargo check --target $TARGET
145
}
156

167
main

src/lib.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
//!
33
//! This driver was built using [`embedded-hal`] traits.
44
//!
5-
//! [`embedded-hal`]: https://docs.rs/embedded-hal/~0.1
5+
//! [`embedded-hal`]: https://docs.rs/embedded-hal/0.2
66
//!
77
//! # Examples
88
//!
99
//! You should find at least one example in the [f3] crate.
1010
//!
11-
//! [f3]: https://docs.rs/f3/~0.5
11+
//! [f3]: https://docs.rs/f3/0.6
1212
1313
#![deny(missing_docs)]
1414
#![deny(warnings)]
15-
#![feature(unsize)]
1615
#![no_std]
1716

1817
extern crate embedded_hal as hal;
18+
extern crate generic_array;
1919

20-
use core::marker::Unsize;
2120
use core::mem;
2221

22+
use generic_array::typenum::consts::*;
23+
use generic_array::{ArrayLength, GenericArray};
2324
use hal::blocking::spi::{Transfer, Write};
24-
use hal::spi::{Mode, Phase, Polarity};
2525
use hal::digital::OutputPin;
26+
use hal::spi::{Mode, Phase, Polarity};
2627

2728
/// SPI mode
2829
pub const MODE: Mode = Mode {
@@ -53,7 +54,7 @@ where
5354

5455
/// Temperature measurement + gyroscope measurements
5556
pub fn all(&mut self) -> Result<Measurements, E> {
56-
let bytes: [u8; 9] = self.read_registers(Register::OUT_TEMP)?;
57+
let bytes: GenericArray<u8, U9> = self.read_registers(Register::OUT_TEMP)?;
5758

5859
Ok(Measurements {
5960
gyro: I16x3 {
@@ -67,7 +68,7 @@ where
6768

6869
/// Gyroscope measurements
6970
pub fn gyro(&mut self) -> Result<I16x3, E> {
70-
let bytes: [u8; 7] = self.read_registers(Register::OUT_X_L)?;
71+
let bytes: GenericArray<u8, U7> = self.read_registers(Register::OUT_X_L)?;
7172

7273
Ok(I16x3 {
7374
x: (bytes[1] as u16 + ((bytes[2] as u16) << 8)) as i16,
@@ -144,13 +145,13 @@ where
144145
Ok(buffer[1])
145146
}
146147

147-
fn read_registers<B>(&mut self, reg: Register) -> Result<B, E>
148+
fn read_registers<N>(&mut self, reg: Register) -> Result<GenericArray<u8, N>, E>
148149
where
149-
B: Unsize<[u8]>,
150+
N: ArrayLength<u8>,
150151
{
151152
self.cs.set_low();
152153

153-
let mut buffer: B = unsafe { mem::uninitialized() };
154+
let mut buffer: GenericArray<u8, N> = unsafe { mem::uninitialized() };
154155
{
155156
let slice: &mut [u8] = &mut buffer;
156157
slice[0] = reg.addr() | MULTI | READ;

0 commit comments

Comments
 (0)