A collection of Analog Devices drivers for the mbed platform

For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all

Committer:
Adrian Suciu
Date:
Mon Nov 07 16:27:12 2016 +0200
Revision:
33:c3ec596a29c2
Parent:
11:2e67c719ce37
Added CN0391, CN0396 and CN0397 shields

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Adrian Suciu 11:2e67c719ce37 1 /**
Adrian Suciu 11:2e67c719ce37 2 * @file cn0357.h
Adrian Suciu 11:2e67c719ce37 3 * @brief Header file for CN0357
Adrian Suciu 11:2e67c719ce37 4 * @author Analog Devices Inc.
Adrian Suciu 11:2e67c719ce37 5 *
Adrian Suciu 11:2e67c719ce37 6 * For support please go to:
Adrian Suciu 11:2e67c719ce37 7 * Github: https://github.com/analogdevicesinc/mbed-adi
Adrian Suciu 11:2e67c719ce37 8 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
Adrian Suciu 11:2e67c719ce37 9 * Product: www.analog.com/EVAL-CN0357-ARDZ
Adrian Suciu 11:2e67c719ce37 10 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Adrian Suciu 11:2e67c719ce37 11
Adrian Suciu 11:2e67c719ce37 12 ********************************************************************************
Adrian Suciu 11:2e67c719ce37 13 * Copyright 2016(c) Analog Devices, Inc.
Adrian Suciu 11:2e67c719ce37 14 *
Adrian Suciu 11:2e67c719ce37 15 * All rights reserved.
Adrian Suciu 11:2e67c719ce37 16 *
Adrian Suciu 11:2e67c719ce37 17 * Redistribution and use in source and binary forms, with or without
Adrian Suciu 11:2e67c719ce37 18 * modification, are permitted provided that the following conditions are met:
Adrian Suciu 11:2e67c719ce37 19 * - Redistributions of source code must retain the above copyright
Adrian Suciu 11:2e67c719ce37 20 * notice, this list of conditions and the following disclaimer.
Adrian Suciu 11:2e67c719ce37 21 * - Redistributions in binary form must reproduce the above copyright
Adrian Suciu 11:2e67c719ce37 22 * notice, this list of conditions and the following disclaimer in
Adrian Suciu 11:2e67c719ce37 23 * the documentation and/or other materials provided with the
Adrian Suciu 11:2e67c719ce37 24 * distribution.
Adrian Suciu 11:2e67c719ce37 25 * - Neither the name of Analog Devices, Inc. nor the names of its
Adrian Suciu 11:2e67c719ce37 26 * contributors may be used to endorse or promote products derived
Adrian Suciu 11:2e67c719ce37 27 * from this software without specific prior written permission.
Adrian Suciu 11:2e67c719ce37 28 * - The use of this software may or may not infringe the patent rights
Adrian Suciu 11:2e67c719ce37 29 * of one or more patent holders. This license does not release you
Adrian Suciu 11:2e67c719ce37 30 * from the requirement that you obtain separate licenses from these
Adrian Suciu 11:2e67c719ce37 31 * patent holders to use this software.
Adrian Suciu 11:2e67c719ce37 32 * - Use of the software either in source or binary form, must be run
Adrian Suciu 11:2e67c719ce37 33 * on or directly connected to an Analog Devices Inc. component.
Adrian Suciu 11:2e67c719ce37 34 *
Adrian Suciu 11:2e67c719ce37 35 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
Adrian Suciu 11:2e67c719ce37 36 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
Adrian Suciu 11:2e67c719ce37 37 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Adrian Suciu 11:2e67c719ce37 38 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
Adrian Suciu 11:2e67c719ce37 39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Adrian Suciu 11:2e67c719ce37 40 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
Adrian Suciu 11:2e67c719ce37 41 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Adrian Suciu 11:2e67c719ce37 42 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Adrian Suciu 11:2e67c719ce37 43 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Adrian Suciu 11:2e67c719ce37 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Adrian Suciu 11:2e67c719ce37 45 *
Adrian Suciu 11:2e67c719ce37 46 ********************************************************************************/
Adrian Suciu 11:2e67c719ce37 47
Adrian Suciu 11:2e67c719ce37 48 #ifndef CN0357_H
Adrian Suciu 11:2e67c719ce37 49 #define CN0357_H
Adrian Suciu 11:2e67c719ce37 50
Adrian Suciu 11:2e67c719ce37 51 #include "mbed.h"
Adrian Suciu 11:2e67c719ce37 52 #include "AD7790.h"
Adrian Suciu 11:2e67c719ce37 53 #include "AD5270.h"
Adrian Suciu 11:2e67c719ce37 54
Adrian Suciu 11:2e67c719ce37 55 /**
Adrian Suciu 11:2e67c719ce37 56 * @brief EVAL-CN0357 toxic gas sensor shield
Adrian Suciu 11:2e67c719ce37 57 */
Adrian Suciu 11:2e67c719ce37 58 class CN0357
Adrian Suciu 11:2e67c719ce37 59 {
Adrian Suciu 11:2e67c719ce37 60 public:
Adrian Suciu 11:2e67c719ce37 61
Adrian Suciu 11:2e67c719ce37 62 private:
Adrian Suciu 11:2e67c719ce37 63 float _vref;
Adrian Suciu 11:2e67c719ce37 64 float _sensor_sensitivity;
Adrian Suciu 11:2e67c719ce37 65 float _sensor_range;
Adrian Suciu 11:2e67c719ce37 66 float _RDACvalue;
Adrian Suciu 11:2e67c719ce37 67 public:
Adrian Suciu 11:2e67c719ce37 68 AD7790 ad7790; ///< AD7790 instance - can be used for manual overriding
Adrian Suciu 11:2e67c719ce37 69 AD5270 ad5270; ///< AD5270 instance - can be used for manual overriding
Adrian Suciu 11:2e67c719ce37 70
Adrian Suciu 11:2e67c719ce37 71 /// CN0357 shield jumper configuration
Adrian Suciu 11:2e67c719ce37 72 typedef enum {
Adrian Suciu 11:2e67c719ce37 73 INTERNAL_AD7790 = 0, ///< The shield's AD7790 is used
Adrian Suciu 11:2e67c719ce37 74 EXTERNAL_ADC ///< Sensor analog output is routed to A1 pin of the shield
Adrian Suciu 11:2e67c719ce37 75 } JumperConfig_t;
Adrian Suciu 11:2e67c719ce37 76
Adrian Suciu 11:2e67c719ce37 77 CN0357(PinName CSAD7790 = D8, PinName CSAD5270 = D6, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK);
Adrian Suciu 11:2e67c719ce37 78 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);
Adrian Suciu 11:2e67c719ce37 79
Adrian Suciu 11:2e67c719ce37 80 uint8_t read_adc_status(void);
Adrian Suciu 11:2e67c719ce37 81 uint16_t read_sensor(void);
Adrian Suciu 11:2e67c719ce37 82 float read_sensor_voltage(void);
Adrian Suciu 11:2e67c719ce37 83 float data_to_voltage(uint16_t data);
Adrian Suciu 11:2e67c719ce37 84 float calc_ppm(float adcVoltage);
Adrian Suciu 11:2e67c719ce37 85 float read_ppm(void);
Adrian Suciu 11:2e67c719ce37 86
Adrian Suciu 11:2e67c719ce37 87 void set_RDAC_value(float resistor_val);
Adrian Suciu 11:2e67c719ce37 88 float get_RDAC_value(void);
Adrian Suciu 11:2e67c719ce37 89 float set_sensor_parameters(float range, float sensitivity);
Adrian Suciu 11:2e67c719ce37 90 float get_sensor_range(void);
Adrian Suciu 11:2e67c719ce37 91 float get_sensor_sensitivity(void);
Adrian Suciu 11:2e67c719ce37 92
Adrian Suciu 11:2e67c719ce37 93 private:
Adrian Suciu 11:2e67c719ce37 94 const static int _RESET = 0xff;
Adrian Suciu 11:2e67c719ce37 95 const static int _DEFAULT_MODE_VAL = AD7790::MD1 | AD7790::MD0; // POWERDOWN MODE
Adrian Suciu 11:2e67c719ce37 96 const static int _DEFAULT_FILTER_VAL = AD7790::FS0 | AD7790::FS1 | AD7790::FS2;
Adrian Suciu 11:2e67c719ce37 97 void _rdac_init(float resistanceValue);
Adrian Suciu 11:2e67c719ce37 98 void _AD7790_init(uint8_t mode_val, uint8_t filter_val);
Adrian Suciu 11:2e67c719ce37 99
Adrian Suciu 11:2e67c719ce37 100 };
Adrian Suciu 11:2e67c719ce37 101
Adrian Suciu 11:2e67c719ce37 102 #endif // CN0357_H