/* ----------------------------------------------------------------------
 * Copyright (C) 2014-2015 Cambridge CMOS Sensors. All rights reserved.
 *
 * $Date:        22 July 2016
 * $Revision: 	V.2016.07.22.2016
 *
 * Project: 	    CCS MOX Library
 * Title:	    ccsmox_common.h
 *
 * Description:	Common header file for CCS MOX Library
 *
 * Target Processor: All
 *
 * Preprocessor Options:
 *     For CCS801, add -DCCS801;
 *     For CCS803, add -DCCS803
 *
 * -------------------------------------------------------------------- */

/**
   \mainpage CCS MOX Library
   *
   * Introduction
   * ------------
   *
   * This library release is designed for general VOC detection applications.
   *
   * Using the Library
   * ------------
   *
   * prebuilt versions of libraries are located in <code>lib</code> folder.
   * - libCcsMox801_m0_xxxxxxxx.a (Cortex-M0)
   * - libCcsMox801_m3_xxxxxxxx.a (Cortex-M3)
   * - libCcsMox801_m4_xxxxxxxx.a (Cortex-M4)
   * - libCcsMox801_MSP430LR_xxxxxxxx.LIB (Library for MSP430, Memory Model Large, Data Model Restricted)
   * - libCcsMox801_C51C_xxxxxxxx.LIB (Library for Keil C51, Memory Model Compact)
   * - libCcsMox801_C51L_xxxxxxxx.LIB (Library for Keil C51, Memory Model Large)
   * - libCcsMox801_IARLB_xxxxxxxx.LIB (Library for IAR 8051, Memory Model Large, Code Model Banked)
   *
   *
   * Copyright Notice
   * ------------
   *
   * Copyright (C) 2014-2016 Cambridge CMOS Sensors. All rights reserved.
   */

#ifndef INCCCSMOXCOMMON_H_
#define INCCCSMOXCOMMON_H_

/**
* @brief library functions
*/
extern uint8_t ccsmox_set_conf(uint8_t conf, uintptr_t ccs_data, uint8_t size);

#if defined CCS801
    extern uint8_t ccsmox_801_set_conf(uint8_t conf, uintptr_t ccs_data, uint8_t size);
    extern uint8_t ccsmox_801_set_data(uintptr_t ccs_data, uint8_t size);
    extern uint8_t ccsmox_801_get_profile(uint8_t * params);
    extern uint8_t ccsmox_801_set_baseline(uint8_t options, uint32_t baseline);
#endif

#if defined CCS803
    extern uint8_t ccsmox_803_set_conf(uint8_t conf, uintptr_t ccs_data, uint8_t size);
    extern int16_t ccsmox_803_set_data(uintptr_t ccs_data, uint8_t size);
    extern int16_t ccsmox_803_calibrate(uintptr_t ccs_data, uint8_t size, uint8_t * params);
#endif

typedef enum {
    PPM = 0, ECO2 = 1, TVOC = 2
} Concentration_Type;

/**
* @brief measurement data format
*/
typedef struct
{
    uint32_t value;         /** Sensor resistance in ohms */
    uint32_t timestamp;     /** RESERVED */
} CcsValueRef;

/**
* @brief RESERVED
*/
typedef struct
{
    uint16_t temperature; /* Value = (10°C ~ 50%) + 25°C */
    uint16_t humidity;    /* Value = (0% ~ 100%) */
} CcsValueAttribute;

/**
* @brief Measurment data and algorithm result to be passed between platform applications and CCMOSS library
*/
typedef struct
{
    CcsValueRef ref;                         /** see CcsValueRef struct definitions */
    CcsValueAttribute attributes;        /** RESERVED */
    uint8_t level;                              /** RESERVED */
    Concentration_Type type;                     /** concentration type, e.g. eCO2 PPM, TVOC PPB */
    uint16_t concentration;                /** concentration in PPM */
} CcsValue;

/**
* @brief RESERVED - Sensor power configurations
*/
typedef struct
{
    uint8_t voltage;       /** see voltage = 100 * {heater voltage in V} */
    uint16_t duration;    /** duration in milliseconds, 0 = infinite */
    uint16_t interval;     /** sampling frequency in milliseconds */
} CcsPulseConf;

/**
* @brief data structure format of library configurations
*/
typedef struct
{
    uint8_t type;
    uint8_t size;
    uintptr_t buffer;
} CcsConf;


#ifndef _PROFILE_BLOCK_SIZE_
#define _PROFILE_BLOCK_SIZE_
#define PROFILE_BLOCK_SIZE 32
#endif

#define DEFAULT_CONF_PULSE_SIZE 64
#define DEFAULT_CONF_BUFFER_SIZE 64

/**
* @brief library configuration type definitions.
*/
#define CONF_RESET 0x00
#define CONF_GET_POWER 0x02
#define CONF_GET_CAL 0x03
#define CONF_SET_PROFILE 0x81
#define CONF_SET_POWER 0x82

/**
* @brief baseline configuration type definitions.
*/
#define BASELINE_RESET 0x02
#define BASELINE24_DISABLE 0x10
#define BASELINE24_ENABLE 0x11
#define BASELINE24_RESET 0x12

/**
* @brief gas type definitions.
*/
#define TYPE_BREATHALYSER 0x00
#define TYPE_CO 0x01
#define TYPE_VOC 0x02


#ifdef CCS803

/**
* @brief gas type definitions.
*/
#define IND_GAS_LOW 0x00
#define IND_GAS_MEDIUM 0x01
#define IND_GAS_HIGH 0x02
#define IND_CAL_OK 0x41

#endif // CCS803


/**
* @brief function return code definitions.
*/
#define ERROR_OK 0
#define ERROR_NOT_READY 1
#define ERROR_NOT_SUPPORTED 2
#define ERROR_INVALID_BUFFER 0x21
#define ERROR_INSUFFICIENT_BUFFER 0x31
#define ERROR_INVAILD_PARAMETER 0x22

#endif /* INCCCSMOXCOMMON_H_ */
