nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
lps22hb.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright 2018-2019 Peter A. Bigot */
3 
8 #ifndef NRFCXX_SENSOR_LPS22HB_HPP
9 #define NRFCXX_SENSOR_LPS22HB_HPP
10 #pragma once
11 
12 #include <climits>
13 
14 #include <nrfcxx/gpio.hpp>
15 #include <nrfcxx/lpm.hpp>
16 
17 namespace nrfcxx {
18 namespace sensor {
19 
36 class lps22hb : public lpm::lpsm_capable
37 {
38  using super = lpm::lpsm_capable;
39 public:
45  {
48 
54  int8_t drdy_psel;
55 
60  uint8_t address;
61 
62  iface_config_type (const iface_config_type&) = delete;
63  iface_config_type& operator= (const iface_config_type&) = delete;
65  iface_config_type& operator= (iface_config_type&&) = delete;
66  };
67 
70  {
71  return iface_config_;
72  }
73 
75  enum STATUS_REG_e : uint8_t
76  {
78  SR_P_DA = 0x01,
79 
81  SR_T_DA = 0x02,
82 
85  };
86 
88  int status () const;
89 
91  static constexpr uint16_t INVALID_TEMPHUMID = 30000;
92 
97  static constexpr unsigned int INVALID_PRESSURE = 0x00C00000;
98 
101  {
104 
108  };
109 
112  {
113  return observations_;
114  }
115 
120  enum ODR_e : uint8_t
121  {
125  ODR_OneShot = 0x00,
126 
128  ODR_1_Hz = 0x01,
129 
131  ODR_10_Hz = 0x02,
132 
134  ODR_25_Hz = 0x03,
135 
137  ODR_50_Hz = 0x04,
138 
140  ODR_75_Hz = 0x05,
141  };
142 
144  static constexpr auto ODR_DEFAULT = ODR_1_Hz;
145 
151  uint8_t odr () const
152  {
153  return odr_;
154  }
155 
162  int odr (uint8_t dr);
163 
174  lps22hb (notifier_type notify,
175  iface_config_type& ifc,
176  unsigned int addr = 0);
177 
179  bool drdy_asserted () const
180  {
181  return nrf5::GPIO->IN & (1U << iface_config_.drdy_psel);
182  }
183 
186  int lpsm_sample () override;
187 
190  uint16_t lost_drdy () const
191  {
192  return lost_drdy_;
193  }
194 
195 private:
196  int lpsm_process_ (int& delay,
197  process_flags_type& pf) override;
198 
199  void drdy_callback_ (const periph::GPIOTE::sense_status_type*);
200 
201  iface_config_type& iface_config_;
202  observations_type observations_{};
203  periph::GPIOTE::sense_listener drdy_listener_;
204  uint8_t odr_ = ODR_DEFAULT;
205  uint16_t lost_drdy_ = 0;
206 };
207 
208 } // ns sensor
209 } // ns nrfcxx
210 
211 #endif /* NRFCXX_SENSOR_LPS22HB_HPP */
nrfcxx::sensor::lps22hb::ODR_OneShot
On-demand observations.
Definition: lps22hb.hpp:125
nrfcxx::sensor::lps22hb::ODR_50_Hz
Observations generated at 50 Hz.
Definition: lps22hb.hpp:137
nrfcxx::sensor::lps22hb::drdy_asserted
bool drdy_asserted() const
Programmatic test for whether DRDY is asserted.
Definition: lps22hb.hpp:179
nrfcxx::sensor::lps22hb::observations_type::temperature_cCel
int16_t temperature_cCel
A recently retrieved valid temperature or INVALID_TEMPHUMID.
Definition: lps22hb.hpp:107
nrfcxx::sensor::lps22hb::iface_config_type
Information required to communicate with a sensor instance.
Definition: lps22hb.hpp:44
nrfcxx::sensor::lps22hb::ODR_25_Hz
Observations generated at 25 Hz.
Definition: lps22hb.hpp:134
nrfcxx::sensor::lps22hb::ODR_75_Hz
Observations generated at 75 Hz.
Definition: lps22hb.hpp:140
nrfcxx::sensor::lps22hb::ODR_e
ODR_e
Bit field values in CTRL_REG1 for observation data rate.
Definition: lps22hb.hpp:120
nrfcxx::sensor::lps22hb::lpsm_sample
int lpsm_sample() override
Post-extend to signal machine if start failed due to undetected drdy.
nrfcxx::sensor::lps22hb::INVALID_TEMPHUMID
static constexpr uint16_t INVALID_TEMPHUMID
Value used for invalid temperature and humidity observations.
Definition: lps22hb.hpp:91
lpm.hpp
Material supporting low-power-mode operations.
nrfcxx::periph::GPIOTE::sense_listener
Object used to manage sense callbacks.
Definition: periph.hpp:854
nrfcxx::sensor::lps22hb::observations_type::pressure_cPa
unsigned int pressure_cPa
A recently retrieved valid pressure or INVALID_PRESSURE.
Definition: lps22hb.hpp:103
nrfcxx::periph::TWI
Wrapper around the nRF51 TWI peripheral.
Definition: periph.hpp:1528
gpio.hpp
Core GPIO functionality.
nrfcxx::sensor::lps22hb::lost_drdy
uint16_t lost_drdy() const
Count of the number of times a DRDY signal was detected to be lost.
Definition: lps22hb.hpp:190
nrfcxx::sensor::lps22hb::STATUS_REG_e
STATUS_REG_e
Bit fields in the LPS22HB STATUS_REG register.
Definition: lps22hb.hpp:75
nrfcxx::sensor::lps22hb::iface_config_type::twi
periph::TWI & twi
Reference to TWI device used to communicate with sensor.
Definition: lps22hb.hpp:47
nrfcxx::sensor::lps22hb::observations
const observations_type & observations() const
Access the most recent completed observation.
Definition: lps22hb.hpp:111
nrfcxx::sensor::lps22hb::SR_READY
Value when all expected data is available.
Definition: lps22hb.hpp:84
nrfcxx::sensor::lps22hb::status
int status() const
Return the value of the STATUS register.
nrfcxx::sensor::lps22hb::ODR_DEFAULT
static constexpr auto ODR_DEFAULT
The default output data rate.
Definition: lps22hb.hpp:144
nrfcxx::periph::GPIOTE::sense_status_type
Structure used to convey information about pin levels to sense_listener callbacks.
Definition: periph.hpp:672
nrfcxx::sensor::lps22hb::ODR_10_Hz
Observations generated at 10 Hz.
Definition: lps22hb.hpp:131
nrfcxx::sensor::lps22hb::SR_T_DA
Bit set to indicate that new temperature data is available.
Definition: lps22hb.hpp:81
nrfcxx::sensor::lps22hb::odr
uint8_t odr() const
Retrieve the configured output data rate.
Definition: lps22hb.hpp:151
nrfcxx::sensor::lps22hb::INVALID_PRESSURE
static constexpr unsigned int INVALID_PRESSURE
Value used for invalid pressure observations.
Definition: lps22hb.hpp:97
nrfcxx::sensor::lps22hb::ODR_1_Hz
Observations generated at 1 Hz.
Definition: lps22hb.hpp:128
nrfcxx::sensor::lps22hb::iface_config_type::address
uint8_t address
The I2C address used to communicate with the device.
Definition: lps22hb.hpp:60
nrfcxx::notifier_type
std::function< void()> notifier_type
Type used to hold a notifier.
Definition: core.hpp:514
nrfcxx::sensor::lps22hb::SR_P_DA
Bit set to indicate that new pressure data is available.
Definition: lps22hb.hpp:78
nrfcxx::lpm::lpsm_capable
Base (or mixin) class for anything that supports a state_machine.
Definition: lpm.hpp:426
nrfcxx::sensor::lps22hb::lps22hb
lps22hb(notifier_type notify, iface_config_type &ifc, unsigned int addr=0)
Instantiate the device.
nrfcxx::sensor::lps22hb::observations_type
Structure used to return sampled values.
Definition: lps22hb.hpp:100
nrfcxx::sensor::lps22hb::iface_config_type::drdy_psel
int8_t drdy_psel
GPIO pin selector usable for interrupt-driven notification of available measurements.
Definition: lps22hb.hpp:54
nrfcxx
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17
nrfcxx::sensor::lps22hb::iface_config
const iface_config_type & iface_config() const
Access the interface configuration for the sensor.
Definition: lps22hb.hpp:69
nrfcxx::sensor::lps22hb
Interface to the ST LPS22HB piezzoresistave absolute pressure sensor.
Definition: lps22hb.hpp:36