Skip to content

APDS-9960 digital proximity, ambient light, RGB and gesture sensor driver for Drone OS.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

smartoris/smartoris-apds9960

Repository files navigation

crates.io maintenance

smartoris-apds9960

APDS-9960 digital proximity, ambient light, RGB and gesture sensor driver for Drone OS.

Usage

Add the crate to your Cargo.toml dependencies:

[dependencies]
smartoris-apds9960 = { version = "0.1.0" }

Add or extend std feature as follows:

[features]
std = ["smartoris-apds9960/std"]

The driver can be used with any I²C implementation. Here is an example of integration with smartoris-i2c crate.

/// Adapters for external crates.
mod adapters {
    /// A marker type for port implementations in this module.
    pub struct Adapters;

    /// APDS-9960 adapters.
    mod apds9960 {
        use super::Adapters;
        use async_trait::async_trait;
        use drone_cortexm::thr::prelude::*;
        use drone_stm32_map::periph::{dma::ch::DmaChMap, i2c::I2CMap};
        use smartoris_apds9960::Apds9960I2CPort;
        use smartoris_i2c::I2CDrv;

        #[async_trait]
        impl<
            I2C: I2CMap,
            I2CEv: IntToken,
            I2CEr: IntToken,
            DmaTx: DmaChMap,
            DmaTxInt: IntToken,
            DmaRx: DmaChMap,
            DmaRxInt: IntToken,
        > Apds9960I2CPort<Adapters>
            for I2CDrv<I2C, I2CEv, I2CEr, DmaTx, DmaTxInt, DmaRx, DmaRxInt>
        {
            type Error = !;

            async fn write(
                &mut self,
                addr: u8,
                buf: Box<[u8]>,
                count: usize,
            ) -> Result<Box<[u8]>, (Box<[u8]>, !)> {
                Ok(self.master(buf).write(addr, ..count).await.stop())
            }

            async fn read(
                &mut self,
                addr: u8,
                buf: Box<[u8]>,
                count: usize,
            ) -> Result<Box<[u8]>, (Box<[u8]>, !)> {
                Ok(self.master(buf).write(addr, ..1).await.read(addr, ..count).await.stop())
            }
        }
    }
}

use smartoris_apds9960::Apds9960Drv;

let mut apds9960 = Apds9960Drv::init();
apds9960.store_enable(&mut i2c1, |r| r.set_pon().set_pen()).await.into_ok();
loop {
    if apds9960.load_status(&mut i2c1).await.into_ok().pvalid() {
        let pdata = apds9960.load_pdata(&mut i2c1).await.into_ok();
        println!("proximity: {}", pdata);
    }
}

References

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

APDS-9960 digital proximity, ambient light, RGB and gesture sensor driver for Drone OS.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages