nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
Go to the documentation of this file. 8 #ifndef NRFCXX_SENSOR_CCS811_HPP 9 #define NRFCXX_SENSOR_CCS811_HPP 122 return iface_config_;
256 return retained_state_;
280 iface_config_type& ifc,
281 bool addr_sec =
false);
287 return iface_config_.
twi;
297 static constexpr uint8_t FL_ENABLE_TWI = 0x01;
300 static constexpr uint8_t FL_ASSERT_WAKEn = 0x02;
306 flags((twi.
enabled() ? 0U : FL_ENABLE_TWI)
307 | (waken.
asserted() ? 0U : FL_ASSERT_WAKEn))
309 if (FL_ENABLE_TWI & flags) {
317 && (FL_ASSERT_WAKEn & flags)) {
330 if (FL_ASSERT_WAKEn & flags) {
333 if (FL_ENABLE_TWI & flags) {
340 operator bool ()
const 372 if (0 > intn_psel_) {
375 return !((1U << intn_psel_) & nrf5::GPIO->IN);
399 return {
twi(), waken_};
548 return observations_;
580 static constexpr
size_t SPAN = 4+4+2+2+2+1+1;
612 static constexpr
size_t SPAN = 4+2+2+2;
749 static uint32_t
encode_env (int16_t temp_cCel,
798 int baseline (uint16_t value)
const;
864 int lpsm_process_ (
int& delay,
865 process_flags_type& pf)
override;
871 int read_u8_ (uint8_t reg)
const;
874 int status_ ()
const;
875 int baseline_ ()
const;
876 int baseline_ (uint16_t value)
const;
877 int fetch_ (observations_type& obs);
881 int active_drive_mode_ ()
const 883 const auto rsp = &retained_state_;
889 static retained_state_type retained_state_;
891 iface_config_type& iface_config_;
897 observations_type observations_{};
898 version_s version_{};
899 uint64_t baseline_saved_utt_{};
900 uint32_t env_data_ = -1;
uint64_t reset_utt
The aggregate uptime at which the sensor was last reset.
Definition: ccs811.hpp:144
uint16_t eCO2_ppm
Threshold for changes in observations_type::eCO2.
Definition: ccs811.hpp:645
int drive_mode() const
Read the configured drive mode.
Definition: ccs811.hpp:843
static constexpr auto PF_CONDITIONED
Bit set in non-negative lpsm_process() result when the sensor has completed its conditioning period.
Definition: ccs811.hpp:721
gpio::generic_pin & resetn
GPIO pin selector for RESETn signal.
Definition: ccs811.hpp:106
periph::TWI & twi() const
Directly access the TWI peripheral used to communicate with the device.
Definition: ccs811.hpp:285
uint16_t fw_boot_version
Native byte order boot firmware version identifier.
Definition: ccs811.hpp:414
(Boot mode only) Set indicates that a verify operation succeeded.
Definition: ccs811.hpp:464
Mask to isolate active drive mode in flags.
Definition: ccs811.hpp:193
static constexpr unsigned int CONDITIONING_DELAY_utt
Duration of the conditioning period, in uptime ticks.
Definition: ccs811.hpp:87
uint16_t baseline
The BASELINE register read immediately before the ALG_RESULT_DATA register.
Definition: ccs811.hpp:501
const iface_config_type & iface_config() const
Access the interface configuration for the sensor.
Definition: ccs811.hpp:120
If set new data is available in the ALG_RESULT_DATA register.
Definition: ccs811.hpp:458
int8_t intn_psel
GPIO pin selector for INTn signal.
Definition: ccs811.hpp:109
Flag set when baseline has been set to a valid value.
Definition: ccs811.hpp:183
uint16_t baseline[4]
Recorded baseline values indexed by MEAS_MODE drive mode.
Definition: ccs811.hpp:217
static constexpr auto PF_BASELINED
Bit set in non-negative lpsm_process() result when the machine saved the BASELINE register to retaine...
Definition: ccs811.hpp:730
uint16_t eCO2
Equivalent CO2 estimate, in ppm.
Definition: ccs811.hpp:504
Class obtained from scoped_enable().
Definition: ccs811.hpp:291
observation_beacon_type observation_beacon() const
Populate and return an observation beacon structure from the current state.
Idle mode, no measurements will be produced.
Definition: ccs811.hpp:819
constexpr static unsigned int Frequency_Hz
Frequency of the uptime clock as a symbolic constant.
Definition: clock.hpp:247
uint32_t env_data() const
Read the last written environment data setting.
Definition: ccs811.hpp:781
flags_enum
Defined values for flags.
Definition: ccs811.hpp:163
unsigned int i2c_address() const
Access the I2C address used for the device.
Definition: ccs811.hpp:858
If set an I2C write was attempted to an unwritable register.
Definition: ccs811.hpp:474
Class supporting a generic GPIO pin interface.
Definition: gpio.hpp:439
uint16_t baseline
The most recently validated BASELINE register value.
Definition: ccs811.hpp:160
static const retained_state_type & retained_state()
Access the retained state.
Definition: ccs811.hpp:254
Constant power, measurements every second.
Definition: ccs811.hpp:821
Aggregate identity and version from hardware and firmware registers.
Definition: ccs811.hpp:407
periph::TWI & twi
Reference to TWI device used to communicate with sensor.
Definition: ccs811.hpp:100
bool asserted() const
Indicate whether the signal is currently asserted.
Definition: gpio.hpp:634
Material supporting low-power-mode operations.
Object used to manage sense callbacks.
Definition: periph.hpp:854
uint16_t eTVOC
Copied from observations_type::eTVOC.
Definition: ccs811.hpp:608
gpio::generic_pin & waken
GPIO pin selector for WAKEn signal.
Definition: ccs811.hpp:103
static uint32_t encode_env(int16_t temp_cCel, uint16_t rh_pptt)
Convert temperature and humidity to CCS811 ENV_DATA format.
const observations_type & observations() const
Access the most recent collected observations.
Definition: ccs811.hpp:546
Wrapper around the nRF51 TWI peripheral.
Definition: periph.hpp:1528
uint16_t raw
Optional raw data.
Definition: ccs811.hpp:529
static constexpr unsigned int RESET_DELAY_us
Value for minimum t_RESET in microseconds.
Definition: ccs811.hpp:77
DRIVE_MODE_e
Allowed drive modes for the MEAS_MODE register.
Definition: ccs811.hpp:816
If set the sensor or I2C bus has produced an error.
Definition: ccs811.hpp:455
uint16_t eTVOC
Equivalent total volatile organic compound estimate, in ppb.
Definition: ccs811.hpp:511
Structure holding retained state of the sensor.
Definition: ccs811.hpp:130
static constexpr auto PF_RESTORED
Bit set in non-negative lpsm_process() result when the machine updated the CCS811 baseline from retai...
Definition: ccs811.hpp:717
int baseline() const
Read the current baseline value.
Wrapper supporting GPIO control of output signals by explicit or scoped assertion.
Definition: gpio.hpp:578
STATUS_e
Definition: ccs811.hpp:450
int restore_from_persisted(const persisted_state_type &ps)
Update the retained state with information from persisted state.
uint8_t hw_version
Hardware version identifier.
Definition: ccs811.hpp:433
Low-pulse model, measurements every 60 seconds.
Definition: ccs811.hpp:825
If set a the sensor has reached the maximum range.
Definition: ccs811.hpp:484
void disable()
Disable the TWI peripheral.
Definition: periph.hpp:1608
int result() const
Return the result of invoking periph::TWI::enable() in the constructor.
Definition: ccs811.hpp:349
State that should be persisted in non-volatile memory using the utility::Persist infrastructure.
Definition: ccs811.hpp:214
Thresholds for detecting significant changes in readings.
Definition: ccs811.hpp:642
void assert() const
Clear the associated GPIO to assert the active-low signal.
Definition: gpio.hpp:640
virtual int lpsm_sample()
Ask the LPM infrastructure to initiate a new sample.
static constexpr uint8_t HARDWARE_ID
The value expected to be read back in version_s::hw_id.
Definition: ccs811.hpp:403
uint16_t eCO2
Copied from observations_type::eCO2.
Definition: ccs811.hpp:605
int reset() const
Toggle the RESETn line to reset the sensor.
If set an I2C read was attempted from an unreadable register.
Definition: ccs811.hpp:477
static constexpr auto DEFAULT_DRIVE_MODE
Default value for drive_mode()
Definition: ccs811.hpp:829
int status() const
Read the STATUS and, if necessary, ERROR_ID registers.
void assert()
Assert WAKEn and delay until I2C operations are allowed.
Definition: ccs811.hpp:355
Position in flags where the active drive mode is stored.
Definition: ccs811.hpp:190
int update_persisted(persisted_state_type &ps) const
Update a persisted state with information from retained state.
bool is_ready() const
Test whether the ST_DATA_READY flag is set.
Definition: ccs811.hpp:523
uint8_t flags_type
Type used to hold state flags.
Definition: ccs811.hpp:133
Flag set when the first valid (but unconditioned) observation has been provided to the application.
Definition: ccs811.hpp:167
static constexpr unsigned int BASELINE_CAPTURE_INTERVAL_utt
Duration between retention of the BASELINE register.
Definition: ccs811.hpp:90
static constexpr unsigned int APP_START_DELAY_utt
Value for maximum t_APP_START in uptime ticks.
Definition: ccs811.hpp:59
uint16_t bl_latest
The most recently observed value of the BASELINE register.
Definition: ccs811.hpp:567
If set an I2C write to MEAS_MODE provided an unacceptable value.
Definition: ccs811.hpp:481
uint32_t env_data
Copied from ccs811::env_data().
Definition: ccs811.hpp:599
uint8_t hw_id
Hardware identifer, which should be HARDWARE_ID.
Definition: ccs811.hpp:427
static constexpr auto PF_CCS811_ERROR
Bit set in non-negative lpsm_process() result when a new observation identifies a CCS811 error in obs...
Definition: ccs811.hpp:735
void deassert() const
Set the associated GPIO to deassert the active-low signal.
Definition: gpio.hpp:646
uint16_t status_type
Value for a valid CCS811 status.
Definition: ccs811.hpp:448
The raw data supporting cross-reset state transfer.
Definition: core.hpp:993
static constexpr auto PF_REPORTING
Bit set in non-negative lpsm_process() result when the sensor has started providing observations.
Definition: ccs811.hpp:710
Structure used to convey information about pin levels to sense_listener callbacks.
Definition: periph.hpp:672
int observation_beacon_changed(const observation_beacon_type &ob1, const observation_beacon_type &ob2) const
Assess whether two observations differ significantly.
ccs811(notifier_type setter, iface_config_type &ifc, bool addr_sec=false)
Instantiate the device.
int16_t status
Untransmitted content to simplify change detection.
Definition: ccs811.hpp:624
uint8_t humidity_pph
Threshold for changes to the relative humidity value in env_data().
Definition: ccs811.hpp:655
status_type status
The combined STATUS and ERROR_ID register values.
Definition: ccs811.hpp:519
uint32_t active_ds
How long the sensor has been running, in deciseconds.
Definition: ccs811.hpp:556
Clear indicates device is in boot mode; set indicates device is in application mode.
Definition: ccs811.hpp:471
Structure providing the system resources necessary to interact with the CCS811.
Definition: ccs811.hpp:97
uint16_t baseline
Copied from observations_type::baseline.
Definition: ccs811.hpp:602
static void state_setup(const systemState::state_type &ss, bool is_reset, bool retained)
Function to maintain CCS811 state across resets.
Structure that can be broadcast as a beacon to provide observation data.
Definition: ccs811.hpp:596
int fill_system_beacon(system_beacon_type &fr) const
Set the contents of a system beacon frame.
std::function< void()> notifier_type
Type used to hold a notifier.
Definition: core.hpp:514
ssize_type enable()
Enable the TWI peripheral.
Definition: periph.hpp:1602
If set the heater supply voltage is not correct.
Definition: ccs811.hpp:490
Base (or mixin) class for anything that supports a state_machine.
Definition: lpm.hpp:426
int active_drive_mode() const
Read the drive mode from the active state.
State machine abstraction for time-delayed transitions and error captures.
Definition: lpm.hpp:36
scoped_enabler scoped_enable() const
Construct and return an RAII object that supports TWI interaction.
Definition: ccs811.hpp:397
Interface to the ams CCS811 indoor air quality sensor.
Definition: ccs811.hpp:50
uint16_t fw_app_version
Native byte order application firmware version identifier.
Definition: ccs811.hpp:421
int retain_baseline()
Record the current baseline in retained state.
If set a valid application image is available in the sensor.
Definition: ccs811.hpp:461
static constexpr unsigned int COLD_START_DELAY_utt
Value for maximum t_START after power-on in uptime ticks.
Definition: ccs811.hpp:65
constexpr static int64_t from_ms(int64_t ms)
Convert integral milliseconds to uptime ticks (rounding down).
Definition: clock.hpp:422
static constexpr unsigned int DWAKE_DELAY_us
Value for minimum t_DWAKE in microseconds.
Definition: ccs811.hpp:71
uint8_t hw_version
Value from version_s::hw_version.
Definition: ccs811.hpp:573
Pulse mode, measurements every 10 seconds.
Definition: ccs811.hpp:823
If set the heater supply current is out of range.
Definition: ccs811.hpp:487
uint16_t app_version
Value from version_s::fw_app_version.
Definition: ccs811.hpp:570
Structure that can be broadcast as a beacon to provide detailed system state.
Definition: ccs811.hpp:553
static constexpr process_flags_type PF_APP_BASE
First lpsm_capable::lpsm_process() flag bit available for application-specific result code bits.
Definition: lpm.hpp:255
uint8_t flags
A copy of retained_state_type::flags.
Definition: ccs811.hpp:576
const lpm::state_machine & machine() const
Gain read-only access to the LPM machine state.
Definition: ccs811.hpp:699
static constexpr unsigned int DRESET_DELAY_us
Value for minimum t_DRESET in microseconds.
Definition: ccs811.hpp:74
static constexpr unsigned int WAKE_DELAY_us
Value for maximum t_WAKE in microseconds.
Definition: ccs811.hpp:62
uint32_t bl_age_ds
How long since the baseline register was updated, in deciseconds.
Definition: ccs811.hpp:561
uint16_t bl_retained
The most recently retained value of the BASELINE register.
Definition: ccs811.hpp:564
uint8_t flags
Flags recording the stage of processing of the device.
Definition: ccs811.hpp:209
const version_s & id_version() const
Access the version state managed by the LPM machine.
Definition: ccs811.hpp:540
uint16_t eTVOC_ppb
Threshold for changes in observations_type::eTVOC.
Definition: ccs811.hpp:648
Flag set on the first observation received more than CONDITIONING_DELAY_utt after reset_utt.
Definition: ccs811.hpp:176
void delay_us(unsigned int number_of_us)
Delay for exactly the specified duration.
Definition: core.hpp:292
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17
static constexpr size_t SPAN
The transmitted length of this structure, excluding trailing padding.
Definition: ccs811.hpp:580
int env_data_changed(uint32_t ed1, uint32_t ed2) const
Compare two encoded environmental values for closeness.
bool intn_asserted() const
Programmatic test for whether INTn is asserted.
Definition: ccs811.hpp:370
static constexpr size_t SPAN
The transmitted length of this structure, excluding trailing padding and untransmitted status.
Definition: ccs811.hpp:612
Captured results after an observation.
Definition: ccs811.hpp:497
(Boot mode only) Set indicates that an erase operation succeeded.
Definition: ccs811.hpp:467
uint8_t temperature_Cel
Threshold for changes to the temperature value in env_data().
Definition: ccs811.hpp:651
uint64_t baselined_utt
The aggregate uptime at which the BASELINE register was last stored in baseline.
Definition: ccs811.hpp:151
static constexpr unsigned int WARM_START_DELAY_utt
Value for maximum t_START after reset in uptime ticks.
Definition: ccs811.hpp:68
bool enabled() const
Return true iff the device is enabled.
Definition: periph.hpp:1541
void deassert()
De-assert WAKEn and delay as required.
Definition: ccs811.hpp:362