Library for MAX5387 dual channel digi pot

Dependents:   MAX14871_Shield

Committer:
j3
Date:
Thu May 12 22:53:08 2016 +0000
Revision:
4:89d2f70616ee
Parent:
0:bc5ccbaf1650
updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:bc5ccbaf1650 1 /******************************************************************//**
j3 0:bc5ccbaf1650 2 * @file max5387.h
j3 0:bc5ccbaf1650 3 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:bc5ccbaf1650 4 *
j3 0:bc5ccbaf1650 5 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:bc5ccbaf1650 6 * copy of this software and associated documentation files (the "Software"),
j3 0:bc5ccbaf1650 7 * to deal in the Software without restriction, including without limitation
j3 0:bc5ccbaf1650 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:bc5ccbaf1650 9 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:bc5ccbaf1650 10 * Software is furnished to do so, subject to the following conditions:
j3 0:bc5ccbaf1650 11 *
j3 0:bc5ccbaf1650 12 * The above copyright notice and this permission notice shall be included
j3 0:bc5ccbaf1650 13 * in all copies or substantial portions of the Software.
j3 0:bc5ccbaf1650 14 *
j3 0:bc5ccbaf1650 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:bc5ccbaf1650 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:bc5ccbaf1650 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:bc5ccbaf1650 18 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:bc5ccbaf1650 19 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:bc5ccbaf1650 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:bc5ccbaf1650 21 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:bc5ccbaf1650 22 *
j3 0:bc5ccbaf1650 23 * Except as contained in this notice, the name of Maxim Integrated
j3 0:bc5ccbaf1650 24 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:bc5ccbaf1650 25 * Products, Inc. Branding Policy.
j3 0:bc5ccbaf1650 26 *
j3 0:bc5ccbaf1650 27 * The mere transfer of this software does not imply any licenses
j3 0:bc5ccbaf1650 28 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:bc5ccbaf1650 29 * trademarks, maskwork rights, or any other form of intellectual
j3 0:bc5ccbaf1650 30 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:bc5ccbaf1650 31 * ownership rights.
j3 0:bc5ccbaf1650 32 **********************************************************************/
j3 0:bc5ccbaf1650 33
j3 0:bc5ccbaf1650 34
j3 0:bc5ccbaf1650 35 #ifndef MAX5387_H
j3 0:bc5ccbaf1650 36 #define MAX5387_H
j3 0:bc5ccbaf1650 37
j3 0:bc5ccbaf1650 38 #include "mbed.h"
j3 0:bc5ccbaf1650 39
j3 0:bc5ccbaf1650 40
j3 4:89d2f70616ee 41 /**
j3 4:89d2f70616ee 42 * @brief Dual, 256-Tap, Volatile, Low-Voltage Linear Taper Digital
j3 4:89d2f70616ee 43 * Potentiometer
j3 4:89d2f70616ee 44 *
j3 4:89d2f70616ee 45 * @details The MAX5387 dual, 256-tap, volatile, low-voltage linear
j3 4:89d2f70616ee 46 * taper digital potentiometer offers three end-to-end resistance values
j3 4:89d2f70616ee 47 * of 10kΩ, 50kΩ, and 100kΩ. Operating from a single +2.6V to +5.5V power
j3 4:89d2f70616ee 48 * supply, the device provides a low 35ppm/°C end-to-end temperature
j3 4:89d2f70616ee 49 * coefficient. The device features an I2C interface.
j3 4:89d2f70616ee 50 *
j3 4:89d2f70616ee 51 * @code
j3 4:89d2f70616ee 52 * #include "mbed.h"
j3 4:89d2f70616ee 53 * #include "max5387.h"
j3 4:89d2f70616ee 54 *
j3 4:89d2f70616ee 55 * int main (void)
j3 4:89d2f70616ee 56 * {
j3 4:89d2f70616ee 57 * Max5387 digiPot(D14, D15, Max5387::MAX5387_I2C_ADRS0);
j3 4:89d2f70616ee 58 * uint8_t data;
j3 4:89d2f70616ee 59 *
j3 4:89d2f70616ee 60 * //set data...
j3 4:89d2f70616ee 61 *
j3 4:89d2f70616ee 62 * digiPot.write_ch_A(data);
j3 4:89d2f70616ee 63 *
j3 4:89d2f70616ee 64 * //... rest of application
j3 4:89d2f70616ee 65 * }
j3 4:89d2f70616ee 66 * @endcode
j3 4:89d2f70616ee 67 */
j3 0:bc5ccbaf1650 68 class Max5387
j3 0:bc5ccbaf1650 69 {
j3 0:bc5ccbaf1650 70 public:
j3 0:bc5ccbaf1650 71
j3 4:89d2f70616ee 72 /**
j3 4:89d2f70616ee 73 * @brief Valid 7-bit I2C addresses
j3 4:89d2f70616ee 74 * @details The 8 valid I2C addresses set via A0, A1, and A2 pins
j3 4:89d2f70616ee 75 * of the MAX5387
j3 4:89d2f70616ee 76 */
j3 0:bc5ccbaf1650 77 typedef enum
j3 0:bc5ccbaf1650 78 {
j3 0:bc5ccbaf1650 79 MAX5387_I2C_ADRS0 = 0x28,
j3 0:bc5ccbaf1650 80 MAX5387_I2C_ADRS1,
j3 0:bc5ccbaf1650 81 MAX5387_I2C_ADRS2,
j3 0:bc5ccbaf1650 82 MAX5387_I2C_ADRS3,
j3 0:bc5ccbaf1650 83 MAX5387_I2C_ADRS4,
j3 0:bc5ccbaf1650 84 MAX5387_I2C_ADRS5,
j3 0:bc5ccbaf1650 85 MAX5387_I2C_ADRS6,
j3 0:bc5ccbaf1650 86 MAX5387_I2C_ADRS7
j3 0:bc5ccbaf1650 87 }max5387_i2c_adrs_t;
j3 0:bc5ccbaf1650 88
j3 0:bc5ccbaf1650 89
j3 0:bc5ccbaf1650 90 /**********************************************************//**
j3 0:bc5ccbaf1650 91 * @brief Constructor for Max5387 Class.
j3 0:bc5ccbaf1650 92 *
j3 0:bc5ccbaf1650 93 * @details Allows user to use existing I2C object
j3 0:bc5ccbaf1650 94 *
j3 0:bc5ccbaf1650 95 * On Entry:
j3 0:bc5ccbaf1650 96 * @param[in] i2c_bus - pointer to existing I2C object
j3 0:bc5ccbaf1650 97 * @param[in] i2c_adrs - 7-bit slave address of MAX5387
j3 0:bc5ccbaf1650 98 *
j3 0:bc5ccbaf1650 99 * On Exit:
j3 4:89d2f70616ee 100 *
j3 4:89d2f70616ee 101 * @return None
j3 0:bc5ccbaf1650 102 **************************************************************/
j3 0:bc5ccbaf1650 103 Max5387(I2C *i2c_bus, max5387_i2c_adrs_t i2c_adrs);
j3 0:bc5ccbaf1650 104
j3 0:bc5ccbaf1650 105
j3 0:bc5ccbaf1650 106 /**********************************************************//**
j3 0:bc5ccbaf1650 107 * @brief Constructor for Max5387 Class.
j3 0:bc5ccbaf1650 108 *
j3 0:bc5ccbaf1650 109 * @details Allows user to create a new I2C object if not
j3 0:bc5ccbaf1650 110 * already using one
j3 0:bc5ccbaf1650 111 *
j3 0:bc5ccbaf1650 112 * On Entry:
j3 0:bc5ccbaf1650 113 * @param[in] sda - sda pin of I2C bus
j3 0:bc5ccbaf1650 114 * @param[in] scl - scl pin of I2C bus
j3 0:bc5ccbaf1650 115 * @param[in] i2c_adrs - 7-bit slave address of MAX5387
j3 0:bc5ccbaf1650 116 *
j3 0:bc5ccbaf1650 117 * On Exit:
j3 4:89d2f70616ee 118 *
j3 4:89d2f70616ee 119 * @return None
j3 0:bc5ccbaf1650 120 **************************************************************/
j3 0:bc5ccbaf1650 121 Max5387(PinName sda, PinName scl, max5387_i2c_adrs_t i2c_adrs);
j3 0:bc5ccbaf1650 122
j3 0:bc5ccbaf1650 123
j3 0:bc5ccbaf1650 124 /**********************************************************//**
j3 0:bc5ccbaf1650 125 * @brief Default destructor for Max5387 Class.
j3 0:bc5ccbaf1650 126 *
j3 0:bc5ccbaf1650 127 * @details Destroys I2C object if owner
j3 0:bc5ccbaf1650 128 *
j3 0:bc5ccbaf1650 129 * On Entry:
j3 0:bc5ccbaf1650 130 *
j3 0:bc5ccbaf1650 131 * On Exit:
j3 4:89d2f70616ee 132 *
j3 4:89d2f70616ee 133 * @return None
j3 0:bc5ccbaf1650 134 **************************************************************/
j3 0:bc5ccbaf1650 135 ~Max5387();
j3 0:bc5ccbaf1650 136
j3 0:bc5ccbaf1650 137
j3 0:bc5ccbaf1650 138 /**********************************************************//**
j3 0:bc5ccbaf1650 139 * @brief Write channel A
j3 0:bc5ccbaf1650 140 *
j3 0:bc5ccbaf1650 141 * @details
j3 0:bc5ccbaf1650 142 *
j3 0:bc5ccbaf1650 143 * On Entry:
j3 0:bc5ccbaf1650 144 * @param[in] val - wiper position of channel A
j3 0:bc5ccbaf1650 145 *
j3 0:bc5ccbaf1650 146 * On Exit:
j3 4:89d2f70616ee 147 *
j3 4:89d2f70616ee 148 * @return 0 on success, non-0 on failure
j3 0:bc5ccbaf1650 149 **************************************************************/
j3 0:bc5ccbaf1650 150 int16_t write_ch_A(uint8_t val);
j3 0:bc5ccbaf1650 151
j3 0:bc5ccbaf1650 152
j3 0:bc5ccbaf1650 153 /**********************************************************//**
j3 0:bc5ccbaf1650 154 * @brief Write channel B
j3 0:bc5ccbaf1650 155 *
j3 0:bc5ccbaf1650 156 * @details
j3 0:bc5ccbaf1650 157 *
j3 0:bc5ccbaf1650 158 * On Entry:
j3 0:bc5ccbaf1650 159 * @param[in] val - wiper position of channel B
j3 0:bc5ccbaf1650 160 *
j3 0:bc5ccbaf1650 161 * On Exit:
j3 4:89d2f70616ee 162 *
j3 4:89d2f70616ee 163 * @return 0 on success, non-0 on failure
j3 0:bc5ccbaf1650 164 **************************************************************/
j3 0:bc5ccbaf1650 165 int16_t write_ch_B(uint8_t val);
j3 0:bc5ccbaf1650 166
j3 0:bc5ccbaf1650 167
j3 0:bc5ccbaf1650 168 /**********************************************************//**
j3 0:bc5ccbaf1650 169 * @brief Write channel A&B
j3 0:bc5ccbaf1650 170 *
j3 0:bc5ccbaf1650 171 * @details
j3 0:bc5ccbaf1650 172 *
j3 0:bc5ccbaf1650 173 * On Entry:
j3 0:bc5ccbaf1650 174 * @param[in] val - wiper position of channel A&B
j3 0:bc5ccbaf1650 175 *
j3 0:bc5ccbaf1650 176 * On Exit:
j3 4:89d2f70616ee 177 *
j3 4:89d2f70616ee 178 * @return 0 on success, non-0 on failure
j3 0:bc5ccbaf1650 179 **************************************************************/
j3 0:bc5ccbaf1650 180 int16_t write_ch_AB(uint8_t val);
j3 0:bc5ccbaf1650 181
j3 0:bc5ccbaf1650 182
j3 0:bc5ccbaf1650 183 private:
j3 0:bc5ccbaf1650 184
j3 0:bc5ccbaf1650 185 I2C *_p_i2c;
j3 0:bc5ccbaf1650 186 bool _i2c_owner;
j3 0:bc5ccbaf1650 187 uint8_t _w_adrs;
j3 0:bc5ccbaf1650 188 };
j3 0:bc5ccbaf1650 189
j3 0:bc5ccbaf1650 190 #endif/* MAX5387_H */