Skip to content

Commit c1e6d4a

Browse files
committed
Account for missing floating point operations in core
See rust-lang/rfcs#2505 for details.
1 parent 51ff041 commit c1e6d4a

File tree

8 files changed

+31
-3
lines changed

8 files changed

+31
-3
lines changed

.build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tasks:
2424
source $HOME/.cargo/env
2525
# Test with and without std
2626
cargo test
27-
cargo test --no-default-features
27+
cargo test --no-default-features --features libm
2828
# TODO: Add clippy and rustfmt lints. When doing that, make sure to add those
2929
# components to the rustup task above.
3030
- test-docs: |

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ linux-embedded-hal = "0.3"
2828

2929
[features]
3030
default = ["std"]
31-
std = ["arrayvec/std"]
3231
examples = ["anyhow", "linux-embedded-hal", "std"]
32+
libm = ["num-traits/libm"]
33+
std = ["arrayvec/std", "num-traits/std"]
3334

3435
[[example]]
3536
name = "true-frame-rate"

src/calculations.rs

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ use core::convert::TryInto;
5454

5555
use embedded_hal::blocking::i2c;
5656

57+
// Various floating point operations are not implemented in core, so we use libm to provide them as
58+
// needed.
59+
#[cfg_attr(feature = "std", allow(unused_imports))]
60+
use num_traits::Float;
61+
5762
use crate::common::{Address, CalibrationData, MelexisCamera};
5863
use crate::register::Subpage;
5964

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
111111
#![no_std]
112112

113+
#[cfg(not(any(feature = "std", feature = "libm")))]
114+
compile_error!("Either the 'std' or 'libm' feature must be enabled.");
115+
113116
pub mod calculations;
114117
pub mod common;
115118
pub mod driver;

src/mlx90640/eeprom.rs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ use core::slice;
55
use arrayvec::ArrayVec;
66
use embedded_hal::blocking::i2c;
77

8+
// Various floating point operations are not implemented in core, so we use libm to provide them as
9+
// needed.
10+
#[cfg_attr(feature = "std", allow(unused_imports))]
11+
use num_traits::Float;
12+
813
use crate::common::*;
914
use crate::error::{Error, LibraryError};
1015
use crate::expose_member;

src/mlx90640/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
mod address;
44
mod eeprom;
55

6-
pub use eeprom::Mlx90640Calibration;
6+
// Various floating point operations are not implemented in core, so we use libm to provide them as
7+
// needed.
8+
#[cfg_attr(feature = "std", allow(unused_imports))]
9+
use num_traits::Float;
710

811
use crate::common::{Address, MelexisCamera, PixelAddressRange};
912
use crate::register::{AccessPattern, Subpage};
1013

1114
pub use address::RamAddress;
15+
pub use eeprom::Mlx90640Calibration;
1216

1317
/// The height of the image captured by sensor in pixels.
1418
pub const HEIGHT: usize = 24;

src/mlx90641/eeprom.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ use core::slice;
88
use arrayvec::ArrayVec;
99
use embedded_hal::blocking::i2c;
1010

11+
// Various floating point operations are not implemented in core, so we use libm to provide them as
12+
// needed.
13+
#[cfg_attr(feature = "std", allow(unused_imports))]
14+
use num_traits::Float;
15+
1116
use crate::common::*;
1217
use crate::error::{Error, LibraryError};
1318
use crate::expose_member;

src/mlx90641/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ mod address;
44
mod eeprom;
55
pub mod hamming;
66

7+
// Various floating point operations are not implemented in core, so we use libm to provide them as
8+
// needed.
9+
#[cfg_attr(feature = "std", allow(unused_imports))]
10+
use num_traits::Float;
11+
712
use core::cmp::Ordering;
813
use core::iter;
914

0 commit comments

Comments
 (0)