PAS CO2 Sensor  1.0.3
C++ library for Infineon Photoacoustic Spectroscopy (PAS) XENSIV™ CO2 miniaturized sensor
PASCO2 Class Reference

#include <pas-co2.hpp>

Inheritance diagram for PASCO2:
Collaboration diagram for PASCO2:

Public Member Functions

 PASCO2 (pasco2::SBus *const sbus, pasco2::PWM *const pwm, pasco2::Timer *const timer=nullptr, pasco2::GPIO *const interrupt=nullptr, pasco2::GPIO *const protoSelect=nullptr, pasco2::GPIO *const power3V3=nullptr, pasco2::GPIO *const power12V=nullptr, pasco2::GPIO *const pwmSelect=nullptr)
 PAS CO2 Constructor. More...
 
virtual ~PASCO2 ()
 PAS CO2 Destructor. More...
 
Error_t init ()
 Initializes the sensor hardware interfaces. More...
 
Error_t deinit ()
 Deinitializes the sensor hardware interfaces. More...
 
Error_t enableLogic ()
 Enables the sensor logic. More...
 
Error_t disableLogic ()
 Disables the sensor logic. More...
 
Error_t enableIREmitter ()
 Enables the IR emitter. More...
 
Error_t disableIREmitter ()
 Disables the IR emitter. More...
 
Error_t softReset ()
 Resets the sensor via the serial interface. More...
 
Error_t hardReset ()
 Resets the sensor via the logic 3V3 power GPIO interface. More...
 
Error_t setOperationMode (OpMode_t mode)
 Sets the sensor operation mode. More...
 
Error_t enablePWM ()
 Enables the PWM output. More...
 
Error_t disablePWM ()
 Disables the PWM output. More...
 
Error_t setPWMMode (PWMMode_t mode)
 Sets the PWM pulse mode. More...
 
Error_t setMeasPeriod (int16_t periodInSec)
 Sets the measurement period. More...
 
Error_t getCO2 (int16_t &CO2PMM)
 Gets the CO2 concentration readout value from the sensor. More...
 
Error_t getDiagnosis (Diag_t &diagnosis)
 Gets diagnosis information. More...
 
Error_t getMeasStatus (MeasStatus_t &measSt)
 Gets measurement status information. More...
 
Error_t enableInterrupt (void(*cback)(void *), Int_t intType, IntIOConf_t ioConf)
 Enables the hardware interrupt. More...
 
Error_t disableInterrupt ()
 Disables the hardware interrupt. More...
 
Error_t enableABOCompensation (ABOC_t aboc, int16_t abocRef)
 Enables the automatic baseline compensation. More...
 
Error_t disableABOCompensation ()
 Disables the automatic baseline compensation. More...
 
Error_t setPressureCompensation (uint16_t pressRef)
 Sets the pressure compensation reference. More...
 
Error_t enableAlarm (int16_t thres, Alarm_t alarmType)
 Enables alarm mode. More...
 
Error_t disableAlarm ()
 Disables alarm mode. More...
 
Error_t getDeviceID (uint8_t &prodID, uint8_t &revID)
 Gets device product identifier. More...
 
Status_t getStatus ()
 

Protected Member Functions

virtual Error_t setStatus (const Status_t newStatus, bool enoughIfImplicit=false)
 Sets the device status. More...
 
virtual Error_t preResetSaveConfig (void)
 Saves the sensor register configuration and prepare the device for reset. More...
 
virtual Error_t postResetRestoreConfig (void)
 Restores the device register configuration after reset. More...
 

Protected Attributes

pasco2::SBus *const sbus
 
pasco2::PWM *const pwm
 
pasco2::Timer *const timer
 
pasco2::GPIO *const interrupt
 
pasco2::GPIO *const protoSelect
 
pasco2::GPIO *const power3V3
 
pasco2::GPIO *const power12V
 
pasco2::GPIO *const pwmSelect
 
pasco2::Reg reg
 
Status_t status
 

Static Protected Attributes

static const int16_t periodMeasMin = 0x0005
 
static const int16_t periodMeasMax = 0x0FFF
 
static const uint16_t pressRefMin = 0x258
 
static const uint16_t pressRefMax = 0x640
 

Constructor & Destructor Documentation

◆ PASCO2()

PASCO2::PASCO2 ( pasco2::SBus *const  sbus,
pasco2::PWM *const  pwm,
pasco2::Timer *const  timer = nullptr,
pasco2::GPIO *const  interrupt = nullptr,
pasco2::GPIO *const  protoSelect = nullptr,
pasco2::GPIO *const  power3V3 = nullptr,
pasco2::GPIO *const  power12V = nullptr,
pasco2::GPIO *const  pwmSelect = nullptr 
)

PAS CO2 Constructor.

Mandatory arguments:

  • Either the SBus or the PWM interface need to be provided. Both can be we as well provided, but the main CO2 reading interface will be the serial interface then
  • A timer instance (currently default as nullptr.TODO: Needs to be changed!)

Optional arguments:

  • All GPIO instances

Most of the GPIO will be fixed by hardware. In particular those enabling the sensor main power and the emitter power. They are part of the sensor library to provide potential absolute control by software. The hardware interface and its features, are also provided in the library. But it can be as well handled externally

Parameters
[in]*sbusSerial bus instance
[in]*pwmPwm instance
[in]*timerTimer instance
[in]*interruptInterrupt GPIO instance. Default is nullptr
[in]*protoSelectProtocol select GPIO instance. Default is nullptr
[in]*power3V3Power 3V3 control GPIO instance. Default is nullptr
[in]*power12VPower 12V control GPIO instance. Default is nullptr
[in]*pwmSelectPwm selection GPIO instalce. Default is nullptr
Precondition
None

◆ ~PASCO2()

PASCO2::~PASCO2 ( )
virtual

PAS CO2 Destructor.

Warning
It calls deinit() without exception handling. In order to catch any potential exception, the user must explicitly call deinit() before the destructor is called
Precondition
None
Here is the call graph for this function:

Member Function Documentation

◆ init()

Error_t PASCO2::init ( void  )

Initializes the sensor hardware interfaces.

Note
The PAL provides init() and deinit() functions for each platform abstraction layer interface. Depending on the system design criteria, the init/deinitialization of these interfaces might be done at OS level, and externally managed. These functions will be then empty calls and always return successfully (OK). If the init/deinitialization is delegated to the PAS CO2 instance itself, or handled externally is up to the user. The library supports both scenarios.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ deinit()

Error_t PASCO2::deinit ( void  )

Deinitializes the sensor hardware interfaces.

Note
The PAL provides init() and deinit() functions for each platfom abstraction layer interface. Depending on the system design criteria, the init/deinitialization of these interfaces might be done at OS level, and externally managed. These functions will be then empty calls and always return successfully (OK). If the init/deinitialization is delegated to the PAS CO2 instance itself, or handled externally is up to the user. The library supports both scenarios.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ enableLogic()

Error_t PASCO2::enableLogic ( )

Enables the sensor logic.

This function performs the following operations:

  • Initializes the hardware interfaces (if not yet initialized)
  • Enables the sensor 3V3 power (if the instance has been provided for software power enablement)
  • Reads the register map of the sensor (if the serial interface has been provided) The sensor status is updated (xored) with the LOGIC_ONLY_ON mask.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
IC_POWERON_ERRORif power-on error
Precondition
None
Here is the call graph for this function:

◆ disableLogic()

Error_t PASCO2::disableLogic ( )

Disables the sensor logic.

Disables the sensor 3V3 power if the instance has been provided for software power enablement. Otherwise, just updates the sensor status disabling POWER3V3 flag.

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ enableIREmitter()

Error_t PASCO2::enableIREmitter ( )

Enables the IR emitter.

This function performs the following operations:

  • Initializes the hardware interfaces (if not yet initialized)
  • Enables the sensor 12V power (if the instance has been provided for software IR emitter power enablement)

The sensor status is updated (xored) with the IR_ONLY_ON mask.

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ disableIREmitter()

Error_t PASCO2::disableIREmitter ( )

Disables the IR emitter.

Disables the sensor 12V power if the instance has been provided for software IR emitter power enablement. Otherwise, just updates the sensor status disabling POWER12V flag.

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ softReset()

Error_t PASCO2::softReset ( )

Resets the sensor via the serial interface.

The software reset performs the following operations:

  • Read the current sensor memory register map configuration
  • Send the corresponding software reset serial command
  • Rewrite the previous memory map configuration after reset
Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
RESET_ERRORif the device reset error
Precondition
None
Here is the call graph for this function:

◆ hardReset()

Error_t PASCO2::hardReset ( )

Resets the sensor via the logic 3V3 power GPIO interface.

The software reset performs the following operations:

  • Read the current sensor memory register map configuration (if the serial interface has been provided)
  • Disables the power 3V3 GPIO interface
  • Time delay of 200 meas
  • Enables the power 3V3 GPIO interface
  • Rewrite the previous memory map configuration after reset (if the serial interface has been provided)
Warning
Power 3V3 GPIO interface required. If unavailable the function does nothing and returns without error (OK)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
RESET_ERRORif the device reset error
Precondition
None
Here is the call graph for this function:

◆ setOperationMode()

Error_t PASCO2::setOperationMode ( OpMode_t  mode)

Sets the sensor operation mode.

The sensor supports 3 operating modes:

  • Idle mode. Performs no measurement.
  • Single shot mode. Triggers a measurement and afterwards goes back to idle mode.
  • Continuous mode. Performs measurements periodically according to the register measurement configuration. The initial default mode is the idle mode. If only the PWM interface is used, then the default mode configuration is continuous (as there is no register configuration feasible)
Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]modeOperation mode
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ enablePWM()

Error_t PASCO2::enablePWM ( )

Enables the PWM output.

PWM is enabled by default via the pwmSelect GPIO instance if provided. Otherwise, the serial interface is used.

Warning
PWM interface required. If unavailable the function does nothing and returns without error (OK)
If no interface for software enablement is provided, the hardware configuration must ensure the PWM select sensor GPIO is properly configured as PWM enabled.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ disablePWM()

Error_t PASCO2::disablePWM ( )

Disables the PWM output.

PWM is disabled by default via the pwmSelect GPIO instance if provided. Otherwise, the serial interface is used.

Warning
PWM interface required. If unavailable the function does nothing and returns without error (OK)
If no interface for software disablement is provided, the hardware configuration must ensure the PWM select sensor GPIO is properly configured as PWM disabled.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ setPWMMode()

Error_t PASCO2::setPWMMode ( PWMMode_t  mode)

Sets the PWM pulse mode.

The sensor supports 2 PWM pulse modes:

  • Single pulse. A single PWM pulse is generated before the device goes inactive.
  • Pulse train. A train of 160 pulses is issued before the device goes inactive.

By default, pulse train mode is enabled.

Warning
PWM and serial interfaces required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]modePWM pulse mode
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ setMeasPeriod()

Error_t PASCO2::setMeasPeriod ( int16_t  periodInSec)

Sets the measurement period.

In continuous mode, the sensor will perform measurement with this period.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]periodInSecMeasurement period in seconds. Min period is 5 second, and max 4095 seconds.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
CONFIG_ERRORif period value is invalid
Precondition
None
Here is the call graph for this function:

◆ getCO2()

Error_t PASCO2::getCO2 ( int16_t &  co2ppm)

Gets the CO2 concentration readout value from the sensor.

If both the serial and the pwm interfaces are provided, the serial interface will be used.

Parameters
[out]co2ppmVariable to store the read co2 concentration value (in ppm)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None

10000/100

Here is the call graph for this function:

◆ getDiagnosis()

Error_t PASCO2::getDiagnosis ( Diag_t diagnosis)

Gets diagnosis information.

The sensor status registers includes the following flags:

  • Sensor ready
  • PWM pin enabled
  • Temperature out of range error
  • IR emitter voltage out of range error
  • Communication error which will be stored in the Diag_t struct varible passed by argument. After reading the flags, these are cleared in the device writing in the corresponding clear flag bitfields.
Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[out]diagnosisStruct to store the diagnosis flags values
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ getMeasStatus()

Error_t PASCO2::getMeasStatus ( MeasStatus_t measSt)

Gets measurement status information.

The measurement status register provides the following information:

  • Data ready. After a measurement has been completed.
  • Interrupt active. After an interrupt event has occurred.
  • Alarm active. If the alarm has been activated. which will be stored in the MeasStatus_t struct varible passed by argument. After reading the flags, these are cleared in the device writing in the corresponding clear flag bitfields.
Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[out]measStStruct to store the measurement status flags values
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ enableInterrupt()

Error_t PASCO2::enableInterrupt ( void(*)(void *)  cback,
Int_t  intType,
IntIOConf_t  ioConf 
)

Enables the hardware interrupt.

Warning
For event triggering and IO configuration the serial interface required. If unavailable the default interrupt the default values are INT_EARLY_MEAS and INT_IO_PUSH_PULL_ACTIVE_HIGH, respectively.
Interrupt GPIO interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]*cbackPointer to the interrupt callback function
[in]intTypeInterrupt event
[in]ioConfInterrupt output voltage logic configuration
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ disableInterrupt()

Error_t PASCO2::disableInterrupt ( )

Disables the hardware interrupt.

If the serial interface is available the interupt output will be as well disabled on the sensor. Otherwise, just the controller hardware GPIO interrupt is disabled.

Warning
Interrupt GPIO interface required. If unavailable the function does nothing and returns without error (OK)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ enableABOCompensation()

Error_t PASCO2::enableABOCompensation ( ABOC_t  aboc,
int16_t  abocRef 
)

Enables the automatic baseline compensation.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]abocAutomatic baseline compenstation mode
[in]abocRefAutomatic baseline compensation reference
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ disableABOCompensation()

Error_t PASCO2::disableABOCompensation ( )

Disables the automatic baseline compensation.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ setPressureCompensation()

Error_t PASCO2::setPressureCompensation ( uint16_t  pressRef)

Sets the pressure compensation reference.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]pressRefPressure reference value. Min value is 600, and max 1600.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
CONFIG_ERRORif pressure reference value is invalid
Precondition
None
Here is the call graph for this function:

◆ enableAlarm()

Error_t PASCO2::enableAlarm ( int16_t  thres,
Alarm_t  alarmType 
)

Enables alarm mode.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[in]thresAlarm CO2 concentration threshold (in ppm)
[in]alarmTypeUpper or lower threshold configuration
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ disableAlarm()

Error_t PASCO2::disableAlarm ( )

Disables alarm mode.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ getDeviceID()

Error_t PASCO2::getDeviceID ( uint8_t &  prodID,
uint8_t &  revID 
)

Gets device product identifier.

Warning
Serial interface required. If unavailable the function does nothing and returns without error (OK)
Parameters
[out]prodIDProduct identifier
[out]revIDVersion identifier
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ getStatus()

Status_t PASCO2::getStatus ( )
inline

◆ setStatus()

Error_t PASCO2::setStatus ( const Status_t  newStatus,
bool  enoughIfImplicit = false 
)
protectedvirtual

Sets the device status.

From the host controller point of view, the device can be in the following statuses:

  • UNITED. Controller peripheral not initialized
  • INITED. Controller peripheral initialized
  • LOGIC_ONLY_ON. Sensor VDD power logic on. INITED implicit
  • IR_ONLY_ON. IR emitter power on. INITED implicit
  • ON. Sensor powered on LOGIC_ONLY_ON, IR_ONLY_ON and INITED implicit

The device configuration can be only performed if at least LOGIC_ONLY_ON is fulfilled. For CO2 measurements, the IR emitter power has to be enabled. Thus, getCO2() is only available if the sensor is ON.

Some statuses ential that the sensor has been previously in a certain status. This is what implicit status means. For example, LOGIC_ONLY_ON means as well that the device is INITED.

This functions takes care of the state machine transition between the statuses.

Parameters
[in]newStatusDesired new status to be set
[in]enoughIfImplicitFlag indicating if the the exact status is required, or just implicitly.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ preResetSaveConfig()

Error_t PASCO2::preResetSaveConfig ( void  )
protectedvirtual

Saves the sensor register configuration and prepare the device for reset.

The scratch pad register is used for later if the reser was properly performed. This register must be 0x00 after reset. Serial interface required, but not verified as it is a private function.

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ postResetRestoreConfig()

Error_t PASCO2::postResetRestoreConfig ( void  )
protectedvirtual

Restores the device register configuration after reset.

Once the sensor is ready. The scratch pad register has to be 0x00.s Serial interface required, but not verified as it is a private function.

Returns
PAS CO2 error code
Return values
OKif success
IC_POWERON_ERRORif device power on reset error
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

Member Data Documentation

◆ sbus

pasco2::SBus* const PASCO2::sbus
protected

SBus interface

◆ pwm

pasco2::PWM* const PASCO2::pwm
protected

PWM interface

◆ timer

pasco2::Timer* const PASCO2::timer
protected

Timer

◆ interrupt

pasco2::GPIO* const PASCO2::interrupt
protected

Interrupt

◆ protoSelect

pasco2::GPIO* const PASCO2::protoSelect
protected

Serial protocol select

◆ power3V3

pasco2::GPIO* const PASCO2::power3V3
protected

3V3 power

◆ power12V

pasco2::GPIO* const PASCO2::power12V
protected

12V power

◆ pwmSelect

pasco2::GPIO* const PASCO2::pwmSelect
protected

PWM select

◆ reg

pasco2::Reg PASCO2::reg
protected

Register map

◆ status

Status_t PASCO2::status
protected

Sensor host mcu state machine status

◆ periodMeasMin

const int16_t PASCO2::periodMeasMin = 0x0005
staticprotected

Minimum measurement period in Seconds

◆ periodMeasMax

const int16_t PASCO2::periodMeasMax = 0x0FFF
staticprotected

Maximum measurement period in Seconds

◆ pressRefMin

const uint16_t PASCO2::pressRefMin = 0x258
staticprotected

Minimum pressure reference value

◆ pressRefMax

const uint16_t PASCO2::pressRefMax = 0x640
staticprotected

Maximum pressure reference value


The documentation for this class was generated from the following files: