Skip to content

Commit

Permalink
Account for missing floating point operations in core
Browse files Browse the repository at this point in the history
See rust-lang/rfcs#2505 for details.
  • Loading branch information
paxswill committed Sep 24, 2021
1 parent 51ff041 commit c1e6d4a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tasks:
source $HOME/.cargo/env
# Test with and without std
cargo test
cargo test --no-default-features
cargo test --no-default-features --features libm
# TODO: Add clippy and rustfmt lints. When doing that, make sure to add those
# components to the rustup task above.
- test-docs: |
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ linux-embedded-hal = "0.3"

[features]
default = ["std"]
std = ["arrayvec/std"]
examples = ["anyhow", "linux-embedded-hal", "std"]
libm = ["num-traits/libm"]
std = ["arrayvec/std", "num-traits/std"]

[[example]]
name = "true-frame-rate"
Expand Down
5 changes: 5 additions & 0 deletions src/calculations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ use core::convert::TryInto;

use embedded_hal::blocking::i2c;

// Various floating point operations are not implemented in core, so we use libm to provide them as
// needed.
#[cfg_attr(feature = "std", allow(unused_imports))]
use num_traits::Float;

use crate::common::{Address, CalibrationData, MelexisCamera};
use crate::register::Subpage;

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@

#![no_std]

#[cfg(not(any(feature = "std", feature = "libm")))]
compile_error!("Either the 'std' or 'libm' feature must be enabled.");

pub mod calculations;
pub mod common;
pub mod driver;
Expand Down
5 changes: 5 additions & 0 deletions src/mlx90640/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use core::slice;
use arrayvec::ArrayVec;
use embedded_hal::blocking::i2c;

// Various floating point operations are not implemented in core, so we use libm to provide them as
// needed.
#[cfg_attr(feature = "std", allow(unused_imports))]
use num_traits::Float;

use crate::common::*;
use crate::error::{Error, LibraryError};
use crate::expose_member;
Expand Down
6 changes: 5 additions & 1 deletion src/mlx90640/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
mod address;
mod eeprom;

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

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

pub use address::RamAddress;
pub use eeprom::Mlx90640Calibration;

/// The height of the image captured by sensor in pixels.
pub const HEIGHT: usize = 24;
Expand Down
5 changes: 5 additions & 0 deletions src/mlx90641/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use core::slice;
use arrayvec::ArrayVec;
use embedded_hal::blocking::i2c;

// Various floating point operations are not implemented in core, so we use libm to provide them as
// needed.
#[cfg_attr(feature = "std", allow(unused_imports))]
use num_traits::Float;

use crate::common::*;
use crate::error::{Error, LibraryError};
use crate::expose_member;
Expand Down
5 changes: 5 additions & 0 deletions src/mlx90641/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ mod address;
mod eeprom;
pub mod hamming;

// Various floating point operations are not implemented in core, so we use libm to provide them as
// needed.
#[cfg_attr(feature = "std", allow(unused_imports))]
use num_traits::Float;

use core::cmp::Ordering;
use core::iter;

Expand Down

0 comments on commit c1e6d4a

Please sign in to comment.