A collection of Analog Devices drivers for the mbed platform

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CN0357.h Source File

CN0357.h

00001 /**
00002 *   @file     cn0357.h
00003 *   @brief    Header file for CN0357
00004 *   @author   Analog Devices Inc.
00005 *
00006 * For support please go to:
00007 * Github: https://github.com/analogdevicesinc/mbed-adi
00008 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
00009 * Product: www.analog.com/EVAL-CN0357-ARDZ
00010 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
00011 
00012 ********************************************************************************
00013 * Copyright 2016(c) Analog Devices, Inc.
00014 *
00015 * All rights reserved.
00016 *
00017 * Redistribution and use in source and binary forms, with or without
00018 * modification, are permitted provided that the following conditions are met:
00019 *  - Redistributions of source code must retain the above copyright
00020 *    notice, this list of conditions and the following disclaimer.
00021 *  - Redistributions in binary form must reproduce the above copyright
00022 *    notice, this list of conditions and the following disclaimer in
00023 *    the documentation and/or other materials provided with the
00024 *    distribution.
00025 *  - Neither the name of Analog Devices, Inc. nor the names of its
00026 *    contributors may be used to endorse or promote products derived
00027 *    from this software without specific prior written permission.
00028 *  - The use of this software may or may not infringe the patent rights
00029 *    of one or more patent holders.  This license does not release you
00030 *    from the requirement that you obtain separate licenses from these
00031 *    patent holders to use this software.
00032 *  - Use of the software either in source or binary form, must be run
00033 *    on or directly connected to an Analog Devices Inc. component.
00034 *
00035 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
00036 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
00037 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00038 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
00039 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00040 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
00041 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00042 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00043 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00044 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00045 *
00046 ********************************************************************************/
00047 
00048 #ifndef CN0357_H
00049 #define CN0357_H
00050 
00051 #include "mbed.h"
00052 #include "AD7790.h"
00053 #include "AD5270.h"
00054 
00055 /**
00056  * @brief EVAL-CN0357 toxic gas sensor shield
00057  */
00058 class CN0357
00059 {
00060 public:
00061 
00062 private:
00063     float _vref;
00064     float _sensor_sensitivity;
00065     float _sensor_range;
00066     float _RDACvalue;
00067 public:
00068     AD7790 ad7790; ///< AD7790 instance - can be used for manual overriding
00069     AD5270 ad5270; ///< AD5270 instance - can be used for manual overriding
00070 
00071     /// CN0357 shield jumper configuration
00072     typedef enum {
00073         INTERNAL_AD7790 = 0,    ///< The shield's AD7790 is used
00074         EXTERNAL_ADC            ///< Sensor analog output is routed to A1 pin of the shield
00075     } JumperConfig_t;
00076 
00077     CN0357(PinName CSAD7790 = D8, PinName CSAD5270 = D6, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK);
00078     void init(float range, float sensitivity, JumperConfig_t jp = INTERNAL_AD7790, uint8_t mode_val = _DEFAULT_MODE_VAL, uint8_t filter_val = _DEFAULT_FILTER_VAL);
00079 
00080     uint8_t  read_adc_status(void);
00081     uint16_t read_sensor(void);
00082     float read_sensor_voltage(void);
00083     float data_to_voltage(uint16_t data);
00084     float calc_ppm(float adcVoltage);
00085     float read_ppm(void);
00086 
00087     void  set_RDAC_value(float resistor_val);
00088     float get_RDAC_value(void);
00089     float set_sensor_parameters(float range, float sensitivity);
00090     float get_sensor_range(void);
00091     float get_sensor_sensitivity(void);
00092 
00093 private:
00094     const static int _RESET = 0xff;
00095     const static int _DEFAULT_MODE_VAL = AD7790::MD1 | AD7790::MD0; // POWERDOWN MODE
00096     const static int _DEFAULT_FILTER_VAL = AD7790::FS0 | AD7790::FS1 | AD7790::FS2;
00097     void _rdac_init(float resistanceValue);
00098     void _AD7790_init(uint8_t mode_val, uint8_t filter_val);
00099 
00100 };
00101 
00102 #endif // CN0357_H