Library for MAX5387 dual channel digi pot

Dependents:   MAX14871_Shield

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max5387.h Source File

max5387.h

Go to the documentation of this file.
00001 /******************************************************************//**
00002 * @file max5387.h
00003 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
00004 *
00005 * Permission is hereby granted, free of charge, to any person obtaining a
00006 * copy of this software and associated documentation files (the "Software"),
00007 * to deal in the Software without restriction, including without limitation
00008 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00009 * and/or sell copies of the Software, and to permit persons to whom the
00010 * Software is furnished to do so, subject to the following conditions:
00011 *
00012 * The above copyright notice and this permission notice shall be included
00013 * in all copies or substantial portions of the Software.
00014 *
00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00019 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00020 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00021 * OTHER DEALINGS IN THE SOFTWARE.
00022 *
00023 * Except as contained in this notice, the name of Maxim Integrated
00024 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00025 * Products, Inc. Branding Policy.
00026 *
00027 * The mere transfer of this software does not imply any licenses
00028 * of trade secrets, proprietary technology, copyrights, patents,
00029 * trademarks, maskwork rights, or any other form of intellectual
00030 * property whatsoever. Maxim Integrated Products, Inc. retains all
00031 * ownership rights.
00032 **********************************************************************/
00033 
00034 
00035 #ifndef MAX5387_H
00036 #define MAX5387_H
00037 
00038 #include "mbed.h"
00039 
00040 
00041 /**
00042 * @brief Dual, 256-Tap, Volatile, Low-Voltage Linear Taper Digital 
00043 * Potentiometer
00044 *
00045 * @details The MAX5387 dual, 256-tap, volatile, low-voltage linear 
00046 * taper digital potentiometer offers three end-to-end resistance values
00047 * of 10kΩ, 50kΩ, and 100kΩ. Operating from a single +2.6V to +5.5V power
00048 * supply, the device provides a low 35ppm/°C end-to-end temperature 
00049 * coefficient. The device features an I2C interface.
00050 *
00051 * @code 
00052 * #include "mbed.h"
00053 * #include "max5387.h"
00054 * 
00055 * int main (void)
00056 * {
00057 *      Max5387 digiPot(D14, D15, Max5387::MAX5387_I2C_ADRS0);
00058 *      uint8_t data;
00059 *      
00060 *      //set data...
00061 *
00062 *      digiPot.write_ch_A(data);
00063 *      
00064 *      //... rest of application
00065 * }
00066 * @endcode
00067 */
00068 class Max5387
00069 {
00070     public:
00071     
00072     /**
00073     * @brief Valid 7-bit I2C addresses 
00074     * @details The 8 valid I2C addresses set via A0, A1, and A2 pins
00075     * of the MAX5387
00076     */ 
00077     typedef enum
00078     {
00079         MAX5387_I2C_ADRS0 = 0x28,
00080         MAX5387_I2C_ADRS1,
00081         MAX5387_I2C_ADRS2,
00082         MAX5387_I2C_ADRS3,
00083         MAX5387_I2C_ADRS4,
00084         MAX5387_I2C_ADRS5,
00085         MAX5387_I2C_ADRS6,
00086         MAX5387_I2C_ADRS7
00087     }max5387_i2c_adrs_t;
00088     
00089     
00090     /**********************************************************//**
00091     * @brief Constructor for Max5387 Class.  
00092     * 
00093     * @details Allows user to use existing I2C object
00094     *
00095     * On Entry:
00096     *     @param[in] i2c_bus - pointer to existing I2C object
00097     *     @param[in] i2c_adrs - 7-bit slave address of MAX5387
00098     *
00099     * On Exit:
00100     *
00101     * @return None
00102     **************************************************************/
00103     Max5387(I2C *i2c_bus, max5387_i2c_adrs_t i2c_adrs);
00104     
00105     
00106     /**********************************************************//**
00107     * @brief Constructor for Max5387 Class.  
00108     * 
00109     * @details Allows user to create a new I2C object if not 
00110     *          already using one
00111     *
00112     * On Entry:
00113     *     @param[in] sda - sda pin of I2C bus
00114     *     @param[in] scl - scl pin of I2C bus
00115     *     @param[in] i2c_adrs - 7-bit slave address of MAX5387
00116     *
00117     * On Exit:
00118     *
00119     * @return None
00120     **************************************************************/
00121     Max5387(PinName sda, PinName scl, max5387_i2c_adrs_t i2c_adrs);
00122     
00123     
00124     /**********************************************************//**
00125     * @brief Default destructor for Max5387 Class.  
00126     *
00127     * @details Destroys I2C object if owner 
00128     *
00129     * On Entry:
00130     *
00131     * On Exit:
00132     *
00133     * @return None
00134     **************************************************************/
00135     ~Max5387();
00136     
00137     
00138     /**********************************************************//**
00139     * @brief Write channel A
00140     *
00141     * @details    
00142     *
00143     * On Entry:
00144     *    @param[in] val - wiper position of channel A
00145     *
00146     * On Exit:
00147     *
00148     * @return 0 on success, non-0 on failure
00149     **************************************************************/
00150     int16_t write_ch_A(uint8_t val);
00151     
00152     
00153     /**********************************************************//**
00154     * @brief Write channel B
00155     *
00156     * @details    
00157     *
00158     * On Entry:
00159     *    @param[in] val - wiper position of channel B
00160     *
00161     * On Exit:
00162     *
00163     * @return 0 on success, non-0 on failure
00164     **************************************************************/
00165     int16_t write_ch_B(uint8_t val);
00166     
00167     
00168     /**********************************************************//**
00169     * @brief Write channel A&B
00170     *
00171     * @details    
00172     *
00173     * On Entry:
00174     *    @param[in] val - wiper position of channel A&B
00175     *
00176     * On Exit:
00177     *
00178     * @return 0 on success, non-0 on failure
00179     **************************************************************/
00180     int16_t write_ch_AB(uint8_t val);
00181     
00182     
00183     private:
00184     
00185     I2C *_p_i2c;
00186     bool _i2c_owner;
00187     uint8_t _w_adrs;
00188 };
00189 
00190 #endif/* MAX5387_H */