Fix i2c read bytes

This commit is contained in:
marcelbuesing 2018-05-18 22:12:42 +02:00 committed by marcelbuesing
parent a5f8310bf6
commit 266c8b70ea
No known key found for this signature in database
GPG key ID: EF3934305E975944
4 changed files with 223 additions and 34 deletions

171
Cargo.lock generated
View file

@ -1,3 +1,21 @@
[[package]]
name = "aho-corasick"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.7" version = "0.3.7"
@ -45,8 +63,10 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"embedded-hal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"linux-embedded-hal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "linux-embedded-hal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -109,6 +129,18 @@ dependencies = [
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "env_logger"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "error-chain" name = "error-chain"
version = "0.11.0" version = "0.11.0"
@ -141,6 +173,14 @@ name = "glob"
version = "0.2.11" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "humantime"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "i2cdev" name = "i2cdev"
version = "0.3.2" version = "0.3.2"
@ -167,6 +207,11 @@ name = "itoa"
version = "0.4.1" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.40" version = "0.2.40"
@ -184,6 +229,22 @@ dependencies = [
"sysfs_gpio 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "sysfs_gpio 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "log"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "nb" name = "nb"
version = "0.1.1" version = "0.1.1"
@ -231,6 +292,11 @@ dependencies = [
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "quick-error"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "quote" name = "quote"
version = "0.5.2" version = "0.5.2"
@ -249,6 +315,39 @@ dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "redox_syscall"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "remove_dir_all" name = "remove_dir_all"
version = "0.5.1" version = "0.5.1"
@ -374,11 +473,56 @@ dependencies = [
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "termcolor"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ucd-util"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "utf8-ranges"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "void" name = "void"
version = "1.0.2" version = "1.0.2"
@ -417,7 +561,17 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wincolor"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata] [metadata]
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
"checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639" "checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661" "checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "32866f4d103c4e438b1db1158aa1b1a80ee078e5d77a59a2f906fd62a577389c" "checksum bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "32866f4d103c4e438b1db1158aa1b1a80ee078e5d77a59a2f906fd62a577389c"
@ -433,23 +587,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum embedded-hal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26944677e4934eb5fb4025501dc0d6cdbcf6bfabd6200fcfee2e7e8eef8c0362" "checksum embedded-hal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26944677e4934eb5fb4025501dc0d6cdbcf6bfabd6200fcfee2e7e8eef8c0362"
"checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a"
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
"checksum i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3c10164c76056ea2af0beb6a3f76ed9fb1b941716a53b4319242090d7f26368e" "checksum i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3c10164c76056ea2af0beb6a3f76ed9fb1b941716a53b4319242090d7f26368e"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" "checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum linux-embedded-hal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ff46245fb2338f6df956f389ccd62ed82d4b71cf778da946a7fce27d9c7e1a3" "checksum linux-embedded-hal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ff46245fb2338f6df956f389ccd62ed82d4b71cf778da946a7fce27d9c7e1a3"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "69f380b5fe9fab8c0d7a6a99cda23e2cc0463bedb2cbc3aada0813b98496ecdc" "checksum nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "69f380b5fe9fab8c0d7a6a99cda23e2cc0463bedb2cbc3aada0813b98496ecdc"
"checksum nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fd5681d13fda646462cfbd4e5f2051279a89a544d50eb98c365b507246839f" "checksum nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fd5681d13fda646462cfbd4e5f2051279a89a544d50eb98c365b507246839f"
"checksum nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a7bb1da2be7da3cbffda73fc681d509ffd9e665af478d2bee1907cee0bc64b2" "checksum nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a7bb1da2be7da3cbffda73fc681d509ffd9e665af478d2bee1907cee0bc64b2"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7" "checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32" "checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32"
"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" "checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3"
"checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649" "checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
@ -465,10 +629,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum syn 0.13.10 (registry+https://github.com/rust-lang/crates.io-index)" = "77961dcdac942fa8bc033c16f3a790b311c8a27d00811b878ebd8cf9b7ba39d5" "checksum syn 0.13.10 (registry+https://github.com/rust-lang/crates.io-index)" = "77961dcdac942fa8bc033c16f3a790b311c8a27d00811b878ebd8cf9b7ba39d5"
"checksum sysfs_gpio 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3d68f2cae3c7d39f54ce8a858cc31ffb01974744ee65e5b4999b6037cd691e3f" "checksum sysfs_gpio 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3d68f2cae3c7d39f54ce8a858cc31ffb01974744ee65e5b4999b6037cd691e3f"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "63636bd0eb3d00ccb8b9036381b526efac53caf112b7783b730ab3f8e44da369" "checksum walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "63636bd0eb3d00ccb8b9036381b526efac53caf112b7783b730ab3f8e44da369"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767"

View file

@ -6,7 +6,9 @@ authors = ["marcelbuesing <buesing.marcel@googlemail.com>"]
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
embedded-hal = "0.2" embedded-hal = "0.2"
log = "0.4"
[dev-dependencies] [dev-dependencies]
env_logger = "0.5"
i2cdev = "0.3" i2cdev = "0.3"
linux-embedded-hal = "0.2" linux-embedded-hal = "0.2"

View file

@ -1,4 +1,5 @@
extern crate embedded_hal; extern crate embedded_hal;
extern crate env_logger;
extern crate linux_embedded_hal as hal; extern crate linux_embedded_hal as hal;
extern crate bme680_rs; extern crate bme680_rs;
@ -11,6 +12,8 @@ use std::time::Duration;
fn main() -> result::Result<(), Bme680Error<<hal::I2cdev as i2c::Read>::Error , <hal::I2cdev as i2c::Write>::Error>>{ fn main() -> result::Result<(), Bme680Error<<hal::I2cdev as i2c::Read>::Error , <hal::I2cdev as i2c::Write>::Error>>{
env_logger::init();
let i2c = I2cdev::new("/dev/i2c-1").unwrap(); let i2c = I2cdev::new("/dev/i2c-1").unwrap();
let mut dev = Bme680_dev::init(i2c, Delay{}, 0x76, 25)?; let mut dev = Bme680_dev::init(i2c, Delay{}, 0x76, 25)?;

View file

@ -1,6 +1,8 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
extern crate embedded_hal as hal; extern crate embedded_hal as hal;
#[macro_use]
extern crate log;
use hal::blocking::delay::DelayMs; use hal::blocking::delay::DelayMs;
use hal::blocking::i2c::{Read, Write}; use hal::blocking::i2c::{Read, Write};
@ -198,7 +200,7 @@ impl PowerMode {
} }
} }
#[derive(Default, Copy)] #[derive(Debug, Default, Copy)]
#[repr(C)] #[repr(C)]
pub struct CalibData { pub struct CalibData {
pub par_h1: u16, pub par_h1: u16,
@ -338,20 +340,25 @@ pub struct I2CUtil {}
impl I2CUtil impl I2CUtil
{ {
pub fn get_regs_u8<I2C>(i2c: &mut I2C, reg_addr: u8) -> Result<u8, <I2C as Read>::Error, <I2C as Write>::Error> pub fn read_byte<I2C>(i2c: &mut I2C, dev_id: u8, reg_addr: u8) -> Result<u8, <I2C as Read>::Error, <I2C as Write>::Error>
where I2C: Read + Write { where I2C: Read + Write {
let mut buf = [0; 1]; let mut buf = [0; 1];
match i2c.read(reg_addr, &mut buf) {
i2c.write(dev_id, &mut [reg_addr]).map_err(|e| Bme680Error::I2CWrite(e))?;
match i2c.read(dev_id, &mut buf) {
Ok(()) => Ok(buf[0]), Ok(()) => Ok(buf[0]),
Err(e) => Err(Bme680Error::I2CRead(e)), Err(e) => Err(Bme680Error::I2CRead(e)),
} }
} }
pub fn get_regs_i8<I2C>(i2c: &mut I2C, reg_addr: u8) -> Result<i8, <I2C as Read>::Error, <I2C as Write>::Error> pub fn read_bytes<I2C>(i2c: &mut I2C, dev_id: u8, reg_addr: u8, buf: &mut [u8]) -> Result<(), <I2C as Read>::Error, <I2C as Write>::Error>
where I2C: Read + Write { where I2C: Read + Write {
let mut buf = [0; 1];
match i2c.read(reg_addr, &mut buf) { i2c.write(dev_id, &mut [reg_addr]).map_err(|e| Bme680Error::I2CWrite(e))?;
Ok(()) => Ok(buf[0] as i8),
match i2c.read(dev_id, buf) {
Ok(()) => Ok(()),
Err(e) => Err(Bme680Error::I2CRead(e)), Err(e) => Err(Bme680Error::I2CRead(e)),
} }
} }
@ -414,15 +421,16 @@ where
pub fn init(mut i2c: I2C, mut delay: D, dev_id: u8, ambient_temperature: i8) -> Result<Bme680_dev<I2C, D>, <I2C as Read>::Error, <I2C as Write>::Error> { pub fn init(mut i2c: I2C, mut delay: D, dev_id: u8, ambient_temperature: i8) -> Result<Bme680_dev<I2C, D>, <I2C as Read>::Error, <I2C as Write>::Error> {
Bme680_dev::soft_reset(&mut i2c, &mut delay, dev_id)?; Bme680_dev::soft_reset(&mut i2c, &mut delay, dev_id)?;
let mut buf = [0; 1]; debug!("Reading chip id");
/* Soft reset to restore it to default values*/ /* Soft reset to restore it to default values*/
let chip_id = i2c.read(BME680_CHIP_ID_ADDR, &mut buf) let chip_id = I2CUtil::read_byte::<I2C>(&mut i2c, dev_id, BME680_CHIP_ID_ADDR)?;
.map_err(|e| Bme680Error::I2CRead(e))
.map(move |_| buf[0])?;
//let chip_id = dev.get_regs_u8(BME680_CHIP_ID_ADDR)?; debug!("Chip id: {}", chip_id);
//let chip_id = dev.read_byte(BME680_CHIP_ID_ADDR)?;
if chip_id == BME680_CHIP_ID { if chip_id == BME680_CHIP_ID {
let calib = Bme680_dev::<I2C, D>::get_calib_data::<I2C>(&mut i2c)?; debug!("Reading calib data");
let calib = Bme680_dev::<I2C, D>::get_calib_data::<I2C>(&mut i2c, dev_id)?;
debug!("Calib data {:?}", calib);
let dev = Bme680_dev { let dev = Bme680_dev {
i2c: i2c, i2c: i2c,
delay: delay, delay: delay,
@ -435,6 +443,7 @@ where
}; };
Ok(dev) Ok(dev)
} else { } else {
error!("Device does not match chip id {}", BME680_CHIP_ID);
Err(Bme680Error::DeviceNotFound) Err(Bme680Error::DeviceNotFound)
} }
} }
@ -482,7 +491,7 @@ where
if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) { if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) {
let tph_sett_filter = boundary_check::<I2C>(tph_sett.filter, 0, 7)?; let tph_sett_filter = boundary_check::<I2C>(tph_sett.filter, 0, 7)?;
reg_addr = 0x75u8; reg_addr = 0x75u8;
let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?; let mut data = I2CUtil::read_byte(&mut self.i2c, self.dev_id, reg_addr)?;
// TODO duplicate check of condition ? // TODO duplicate check of condition ?
if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) { if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) {
@ -495,7 +504,7 @@ where
if desired_settings.contains(DesiredSensorSettings::HCNTRL_SEL) { if desired_settings.contains(DesiredSensorSettings::HCNTRL_SEL) {
let gas_sett_heatr_ctrl = boundary_check::<I2C>(gas_sett.heatr_ctrl, 0x0u8, 0x8u8)?; let gas_sett_heatr_ctrl = boundary_check::<I2C>(gas_sett.heatr_ctrl, 0x0u8, 0x8u8)?;
reg_addr = 0x70u8; reg_addr = 0x70u8;
let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?; let mut data = I2CUtil::read_byte(&mut self.i2c, self.dev_id, reg_addr)?;
data = (data as (i32) & !0x8i32 | gas_sett_heatr_ctrl as (i32) & 0x8) as (u8) ; data = (data as (i32) & !0x8i32 | gas_sett_heatr_ctrl as (i32) & 0x8) as (u8) ;
reg.push((reg_addr, data)); reg.push((reg_addr, data));
} }
@ -505,7 +514,7 @@ where
.contains(DesiredSensorSettings::OST_SEL | DesiredSensorSettings::OSP_SEL) .contains(DesiredSensorSettings::OST_SEL | DesiredSensorSettings::OSP_SEL)
{ {
reg_addr = 0x74u8; reg_addr = 0x74u8;
let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?; let mut data = I2CUtil::read_byte(&mut self.i2c, self.dev_id, reg_addr)?;
if desired_settings.contains(DesiredSensorSettings::OST_SEL) { if desired_settings.contains(DesiredSensorSettings::OST_SEL) {
let tph_sett_os_temp = boundary_check::<I2C>(tph_sett.os_temp, 0, 5)?; let tph_sett_os_temp = boundary_check::<I2C>(tph_sett.os_temp, 0, 5)?;
@ -526,7 +535,7 @@ where
if desired_settings.contains(DesiredSensorSettings::OSH_SEL) { if desired_settings.contains(DesiredSensorSettings::OSH_SEL) {
let tph_sett_os_hum = boundary_check::<I2C>(self.tph_sett.os_hum, 0, 5)?; let tph_sett_os_hum = boundary_check::<I2C>(self.tph_sett.os_hum, 0, 5)?;
reg_addr = 0x72u8; reg_addr = 0x72u8;
let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?; let mut data = I2CUtil::read_byte(&mut self.i2c, self.dev_id, reg_addr)?;
data = (data as (i32) & !0x7i32 | tph_sett_os_hum as (i32) & 0x7i32) as (u8); data = (data as (i32) & !0x7i32 | tph_sett_os_hum as (i32) & 0x7i32) as (u8);
reg.push((reg_addr, data)); reg.push((reg_addr, data));
} }
@ -536,7 +545,7 @@ where
.contains(DesiredSensorSettings::RUN_GAS_SEL | DesiredSensorSettings::NBCONV_SEL) .contains(DesiredSensorSettings::RUN_GAS_SEL | DesiredSensorSettings::NBCONV_SEL)
{ {
reg_addr = 0x71u8; reg_addr = 0x71u8;
let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?; let mut data = I2CUtil::read_byte(&mut self.i2c, self.dev_id, reg_addr)?;
if desired_settings.contains(DesiredSensorSettings::RUN_GAS_SEL) { if desired_settings.contains(DesiredSensorSettings::RUN_GAS_SEL) {
let gas_sett_run_gas = boundary_check::<I2C>(gas_sett.run_gas, 0, 1)?; let gas_sett_run_gas = boundary_check::<I2C>(gas_sett.run_gas, 0, 1)?;
@ -565,7 +574,7 @@ where
let mut data_array: [u8; BME680_REG_BUFFER_LENGTH] = [0; BME680_REG_BUFFER_LENGTH]; let mut data_array: [u8; BME680_REG_BUFFER_LENGTH] = [0; BME680_REG_BUFFER_LENGTH];
let mut sensor_settings: SensorSettings = Default::default(); let mut sensor_settings: SensorSettings = Default::default();
self.i2c.read(reg_addr, &mut data_array).map_err(|e| Bme680Error::I2CRead(e))?; I2CUtil::read_bytes(&mut self.i2c, self.dev_id, reg_addr, &mut data_array)?;
if desired_settings.contains(DesiredSensorSettings::GAS_MEAS_SEL){ if desired_settings.contains(DesiredSensorSettings::GAS_MEAS_SEL){
sensor_settings.gas_sett = self.get_gas_config()?; sensor_settings.gas_sett = self.get_gas_config()?;
@ -607,7 +616,7 @@ where
/* Call repeatedly until in sleep */ /* Call repeatedly until in sleep */
loop { loop {
tmp_pow_mode = I2CUtil::get_regs_u8(&mut self.i2c, BME680_CONF_T_P_MODE_ADDR)?; tmp_pow_mode = I2CUtil::read_byte(&mut self.i2c, self.dev_id, BME680_CONF_T_P_MODE_ADDR)?;
/* Put to sleep before changing mode */ /* Put to sleep before changing mode */
current_power_mode = PowerMode::from(tmp_pow_mode & BME680_MODE_MSK); current_power_mode = PowerMode::from(tmp_pow_mode & BME680_MODE_MSK);
@ -632,7 +641,7 @@ where
} }
pub fn get_sensor_mode(&mut self) -> Result<PowerMode, <I2C as Read>::Error, <I2C as Write>::Error> { pub fn get_sensor_mode(&mut self) -> Result<PowerMode, <I2C as Read>::Error, <I2C as Write>::Error> {
let regs = I2CUtil::get_regs_u8(&mut self.i2c, BME680_CONF_T_P_MODE_ADDR)?; let regs = I2CUtil::read_byte(&mut self.i2c, self.dev_id, BME680_CONF_T_P_MODE_ADDR)?;
let mode = regs & BME680_MODE_MSK; let mode = regs & BME680_MODE_MSK;
Ok(PowerMode::from(mode)) Ok(PowerMode::from(mode))
} }
@ -686,21 +695,25 @@ where
} }
} }
fn get_calib_data<I2CX>(i2c:&mut I2CX) -> Result<CalibData, <I2CX as Read>::Error, <I2CX as Write>::Error> fn get_calib_data<I2CX>(i2c:&mut I2CX, dev_id: u8) -> Result<CalibData, <I2CX as Read>::Error, <I2CX as Write>::Error>
where I2CX: Read + Write where I2CX: Read + Write
{ {
let mut calib: CalibData = Default::default(); let mut calib: CalibData = Default::default();
let mut coeff_array: [u8; BME680_COEFF_SIZE] = [0; BME680_COEFF_SIZE]; let mut coeff_array: [u8; BME680_COEFF_SIZE] = [0; BME680_COEFF_SIZE];
i2c.read( I2CUtil::read_bytes::<I2CX>(
i2c,
dev_id,
BME680_COEFF_ADDR1, BME680_COEFF_ADDR1,
&mut coeff_array, &mut coeff_array,
).map_err(|e| Bme680Error::I2CRead(e))?; )?;
i2c.read( I2CUtil::read_bytes::<I2CX>(
i2c,
dev_id,
BME680_COEFF_ADDR2, BME680_COEFF_ADDR2,
&mut coeff_array, &mut coeff_array,
).map_err(|e| Bme680Error::I2CRead(e))?; )?;
calib.par_t1 = (coeff_array[34usize] as (u16) as (i32) << 8i32 calib.par_t1 = (coeff_array[34usize] as (u16) as (i32) << 8i32
| coeff_array[33usize] as (u16) as (i32)) as (u16); | coeff_array[33usize] as (u16) as (i32)) as (u16);
@ -737,11 +750,11 @@ where
| coeff_array[35usize] as (u16) as (i32)) as (i16); | coeff_array[35usize] as (u16) as (i32)) as (i16);
calib.par_gh3 = coeff_array[38usize] as (i8); calib.par_gh3 = coeff_array[38usize] as (i8);
calib.res_heat_range = (I2CUtil::get_regs_u8::<I2CX>(i2c, BME680_ADDR_RES_HEAT_RANGE_ADDR)? & 0x30) / 16; calib.res_heat_range = (I2CUtil::read_byte::<I2CX>(i2c, dev_id, BME680_ADDR_RES_HEAT_RANGE_ADDR)? & 0x30) / 16;
calib.res_heat_val = I2CUtil::get_regs_i8::<I2CX>(i2c, BME680_ADDR_RES_HEAT_VAL_ADDR)?; calib.res_heat_val = I2CUtil::read_byte::<I2CX>(i2c, dev_id, BME680_ADDR_RES_HEAT_VAL_ADDR)? as i8;
calib.range_sw_err = (I2CUtil::get_regs_u8::<I2CX>(i2c, BME680_ADDR_RANGE_SW_ERR_ADDR)? & BME680_RSERROR_MSK) / 16; calib.range_sw_err = (I2CUtil::read_byte::<I2CX>(i2c, dev_id, BME680_ADDR_RANGE_SW_ERR_ADDR)? & BME680_RSERROR_MSK) / 16;
Ok(calib) Ok(calib)
} }
@ -765,8 +778,8 @@ where
// TODO move both GasSett fields to new struct // TODO move both GasSett fields to new struct
let mut gas_sett: GasSett = Default::default(); let mut gas_sett: GasSett = Default::default();
// TODO figure out if heat_temp and dur can be u8 // TODO figure out if heat_temp and dur can be u8
gas_sett.heatr_temp = Some(I2CUtil::get_regs_u8(&mut self.i2c, BME680_ADDR_SENS_CONF_START)? as u16); gas_sett.heatr_temp = Some(I2CUtil::read_byte(&mut self.i2c, self.dev_id, BME680_ADDR_SENS_CONF_START)? as u16);
gas_sett.heatr_dur = Some(I2CUtil::get_regs_u8(&mut self.i2c, BME680_ADDR_GAS_CONF_START)? as u16); gas_sett.heatr_dur = Some(I2CUtil::read_byte(&mut self.i2c, self.dev_id, BME680_ADDR_GAS_CONF_START)? as u16);
Ok(gas_sett) Ok(gas_sett)
} }
@ -919,8 +932,8 @@ where
let mut tries: u8 = 10u8; let mut tries: u8 = 10u8;
loop { loop {
self.i2c.read(BME680_FIELD0_ADDR, &mut buff) I2CUtil::read_bytes(&mut self.i2c, self.dev_id, BME680_FIELD0_ADDR, &mut buff)?;
.map_err(|e| Bme680Error::I2CRead(e))?;
data.status = buff[0] & BME680_NEW_DATA_MSK; data.status = buff[0] & BME680_NEW_DATA_MSK;
data.gas_index = buff[0] & BME680_GAS_INDEX_MSK;; data.gas_index = buff[0] & BME680_GAS_INDEX_MSK;;
data.meas_index = buff[1]; data.meas_index = buff[1];