Struct Bme280

Source
pub struct Bme280<B> { /* private fields */ }
Expand description

BME280 driver.

Implementations§

Source§

impl<I2C, E> Bme280<Bme280Bus<I2C>>
where I2C: Write<Error = E> + WriteRead<Error = E>,

Source

pub fn from_i2c0(i2c: I2C, address: Address) -> Result<Self, E>

Creates a new Bme280 driver from a I2C peripheral, and an I2C device address.

§Example
use bme280_multibus::{Address, Bme280};

let mut bme: Bme280<_> = Bme280::from_i2c0(i2c, Address::SdoGnd)?;
Source§

impl<I2C, E> Bme280<Bme280Bus<I2C>>
where I2C: I2c<Error = E>,

Source

pub fn from_i2c1(i2c: I2C, address: Address) -> Result<Self, E>

Creates a new Bme280 driver from a I2C peripheral, and an I2C device address.

§Example
use bme280_multibus::{i2c1::Address, Bme280};

let mut bme: Bme280<_> = Bme280::from_i2c1(i2c, Address::SdoGnd)?;
Source§

impl<SPI, CS, SpiError, PinError> Bme280<Bme280Bus<SPI, CS>>
where SPI: Transfer<u8, Error = SpiError> + Write<u8, Error = SpiError>, CS: OutputPin<Error = PinError>,

Source

pub fn from_spi0(spi: SPI, cs: CS) -> Result<Self, Error<SpiError, PinError>>

Creates a new Bme280 driver from an embedded-hal version 0.2 SPI peripheral and a chip select digital I/O pin.

§Safety

The chip select pin must be high before being passed to this function.

§Example
use bme280_multibus::Bme280;
use eh0::digital::v2::OutputPin;

pin.set_high()?;
let mut bme: Bme280<_> = Bme280::from_spi0(spi, pin)?;
Source§

impl<SPI, E> Bme280<Bme280Bus<SPI>>
where SPI: SpiDevice<Error = E>,

Source

pub fn from_spi1(spi: SPI) -> Result<Self, E>

Creates a new Bme280 driver from an embedded-hal version 1 SPI device.

§Example
use bme280_multibus::Bme280;

let mut bme: Bme280<_> = Bme280::from_spi1(spi)?;
Source§

impl<SPI, E> Bme280<Bme280Bus<SPI>>
where SPI: SpiDevice<Error = E>,

Source

pub async fn from_spia0a(spi: SPI) -> Result<Self, E>

Creates a new Bme280 driver from an embedded-hal-async SPI device.

§Example
use bme280_multibus::Bme280;

let bme: Bme280<_> = Bme280::from_spia0a(spi).await?;
Source§

impl<B, E> Bme280<B>
where B: Bme280BusAsync<Error = E>,

Source

pub async fn new_async(bus: B) -> Result<Self, E>

Create a new BME280 from a Bme280BusAsync.

§Example
use bme280_multibus::{spi1::Bme280Bus, Bme280};

let bus: Bme280Bus<_> = Bme280Bus::new(spi);
let bme: Bme280<_> = Bme280::new_async(bus).await?;
Source

pub async fn chip_id_async(&mut self) -> Result<u8, E>

BME280 chip ID.

The return value is a constant, CHIP_ID.

This register is useful as a sanity check to ensure communications are working with the BME280.

§Example
use bme280_multibus::{spi1::Bme280Bus, Bme280, CHIP_ID};

let mut bme: Bme280<_> = Bme280::from_spia0a(spi).await?;
let chip_id: u8 = bme.chip_id_async().await?;
assert_eq!(chip_id, CHIP_ID);
Source

pub async fn reset_async(&mut self) -> Result<(), E>

Reset the BME280.

§Example
use bme280_multibus::{spi1::Bme280Bus, Bme280};

let mut bme: Bme280<_> = Bme280::from_spia0a(spi).await?;
bme.reset_async().await?;
Source

pub async fn status_async(&mut self) -> Result<Status, E>

Get the status of the device.

§Example
use bme280_multibus::{spi1::Bme280Bus, Bme280, Status};

let mut bme: Bme280<_> = Bme280::from_spia0a(spi).await?;
let status: Status = bme.status_async().await?;
Source

pub async fn settings_async(&mut self, settings: &Settings) -> Result<(), E>

Configure the BME280 settings.

§Example
use bme280_multibus::{
    spi1::Bme280Bus, Bme280, Config, CtrlMeas, Filter, Mode, Oversampling, Settings, Standby,
};

const SETTINGS: Settings = Settings {
    config: Config::RESET
        .set_standby_time(Standby::Millis1000)
        .set_filter(Filter::X16),
    ctrl_meas: CtrlMeas::RESET
        .set_osrs_t(Oversampling::X8)
        .set_osrs_p(Oversampling::X8)
        .set_mode(Mode::Normal),
    ctrl_hum: Oversampling::X8,
};

let mut bme: Bme280<_> = Bme280::from_spia0a(spi).await?;
bme.settings_async(&SETTINGS).await?;
Source

pub async fn sample_async(&mut self) -> Result<Sample, Error<E>>

Read a sample from the BME280.

use bme280_multibus::{
    spi1::Bme280Bus, Bme280, Config, CtrlMeas, Filter, Mode, Oversampling, Sample, Settings,
    Standby,
};

const SETTINGS: bme280_multibus::Settings = bme280_multibus::Settings {
    config: bme280_multibus::Config::RESET
        .set_standby_time(bme280_multibus::Standby::Millis1000)
        .set_filter(bme280_multibus::Filter::X16),
    ctrl_meas: bme280_multibus::CtrlMeas::RESET
        .set_osrs_t(bme280_multibus::Oversampling::X8)
        .set_osrs_p(bme280_multibus::Oversampling::X8)
        .set_mode(bme280_multibus::Mode::Normal),
    ctrl_hum: bme280_multibus::Oversampling::X8,
};

let mut bme: Bme280<_> = Bme280::from_spia0a(spi).await?;
bme.settings_async(&SETTINGS).await?;
let sample: Sample = bme.sample_async().await.unwrap();
Source§

impl<B, E> Bme280<B>
where B: Bme280Bus<Error = E>,

Source

pub fn new(bus: B) -> Result<Self, E>

Create a new BME280 from a spi0::Bme280Bus or a i2c0::Bme280Bus.

§Example
use bme280_multibus::{
    i2c0::{Address, Bme280Bus},
    Bme280,
};

let bus: Bme280Bus<_> = Bme280Bus::new(i2c, Address::SdoGnd);
let bme: Bme280<_> = Bme280::new(bus)?;
Source

pub fn free(self) -> B

Free the I2C bus from the BME280.

§Example
use bme280_multibus::{
    i2c0::{Address, Bme280Bus},
    Bme280,
};

let bus: Bme280Bus<_> = Bme280Bus::new(i2c, Address::SdoGnd);
let bme: Bme280<_> = Bme280::new(bus)?;
let bus: Bme280Bus<_> = bme.free();
Source

pub fn chip_id(&mut self) -> Result<u8, E>

BME280 chip ID.

The return value is a constant, CHIP_ID.

This register is useful as a sanity check to ensure communications are working with the BME280.

§Example
use bme280_multibus::{Address, Bme280, CHIP_ID};

let mut bme: Bme280<_> = Bme280::from_i2c0(i2c, Address::SdoGnd)?;
let chip_id: u8 = bme.chip_id()?;
assert_eq!(chip_id, CHIP_ID);
Source

pub fn reset(&mut self) -> Result<(), E>

Reset the BME280.

§Example
use bme280_multibus::{Address, Bme280};

let mut bme: Bme280<_> = Bme280::from_i2c0(i2c, Address::SdoGnd)?;
bme.reset()?;
Source

pub fn status(&mut self) -> Result<Status, E>

Get the status of the device.

§Example

Check if a conversion is running.

use bme280_multibus::{Address, Bme280, Status};

let mut bme: Bme280<_> = Bme280::from_i2c0(i2c, Address::SdoGnd)?;
let status: Status = bme.status()?;
Source

pub fn settings(&mut self, settings: &Settings) -> Result<(), E>

Configure the BME280 settings.

§Example
use bme280_multibus::{
    Address, Bme280, Config, CtrlMeas, Filter, Mode, Oversampling, Settings, Standby,
};

const SETTINGS: Settings = Settings {
    config: Config::RESET
        .set_standby_time(Standby::Millis1000)
        .set_filter(Filter::X16),
    ctrl_meas: CtrlMeas::RESET
        .set_osrs_t(Oversampling::X8)
        .set_osrs_p(Oversampling::X8)
        .set_mode(Mode::Normal),
    ctrl_hum: Oversampling::X8,
};

let mut bme: Bme280<_> = Bme280::from_i2c0(i2c, Address::SdoGnd)?;
bme.settings(&SETTINGS)?;
Source

pub fn sample(&mut self) -> Result<Sample, Error<E>>

Read a sample from the BME280.

§Example
use bme280_multibus::{Address, Bme280, Sample};

const SETTINGS: bme280_multibus::Settings = bme280_multibus::Settings {
    config: bme280_multibus::Config::RESET
        .set_standby_time(bme280_multibus::Standby::Millis1000)
        .set_filter(bme280_multibus::Filter::X16),
    ctrl_meas: bme280_multibus::CtrlMeas::RESET
        .set_osrs_t(bme280_multibus::Oversampling::X8)
        .set_osrs_p(bme280_multibus::Oversampling::X8)
        .set_mode(bme280_multibus::Mode::Normal),
    ctrl_hum: bme280_multibus::Oversampling::X8,
};

let mut bme: Bme280<_> = Bme280::from_i2c0(i2c, Address::SdoGnd)?;
bme.settings(&SETTINGS)?;
let sample: Sample = bme.sample().unwrap();

Trait Implementations§

Source§

impl<B: Debug> Debug for Bme280<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for Bme280<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Bme280<B>
where B: RefUnwindSafe,

§

impl<B> Send for Bme280<B>
where B: Send,

§

impl<B> Sync for Bme280<B>
where B: Sync,

§

impl<B> Unpin for Bme280<B>
where B: Unpin,

§

impl<B> UnwindSafe for Bme280<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.