Library for MAX5387 dual channel digi pot

Dependents:   MAX14871_Shield

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max5387.cpp Source File

max5387.cpp

Go to the documentation of this file.
00001 /******************************************************************//**
00002 * @file max5387.cpp
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 #include "max5387.h"
00036 
00037 
00038 #define MAX5387_CMD_A  (0x11)
00039 #define MAX5387_CMD_B  (0x12)
00040 #define MAX5387_CMD_AB (0x13)
00041 
00042 
00043 //*********************************************************************
00044 Max5387::Max5387(I2C *i2c_bus, max5387_i2c_adrs_t i2c_adrs): _p_i2c(i2c_bus)
00045 {
00046     _i2c_owner = false;
00047     
00048     _w_adrs = (i2c_adrs << 1);
00049 }
00050   
00051     
00052 //*********************************************************************
00053 Max5387::Max5387(PinName sda, PinName scl, max5387_i2c_adrs_t i2c_adrs)
00054 {
00055     _p_i2c = new I2C(sda, scl);
00056     _i2c_owner = true;
00057     
00058     _w_adrs = (i2c_adrs << 1);
00059 }
00060     
00061 
00062 //*********************************************************************  
00063 Max5387::~Max5387()
00064 {
00065     if(_i2c_owner) 
00066     {
00067         delete _p_i2c;
00068     }
00069 }
00070     
00071 
00072 //********************************************************************* 
00073 int16_t Max5387::write_ch_A(uint8_t val)
00074 {
00075     char data[] = {MAX5387_CMD_A, val};
00076     
00077     return(_p_i2c->write(_w_adrs, data, 2, false));
00078 }
00079     
00080 
00081 //********************************************************************* 
00082 int16_t Max5387::write_ch_B(uint8_t val)
00083 {
00084     char data[] = {MAX5387_CMD_B, val};
00085     
00086     return(_p_i2c->write(_w_adrs, data, 2, false));
00087 }
00088     
00089     
00090 //********************************************************************* 
00091 int16_t Max5387::write_ch_AB(uint8_t val)
00092 {
00093     char data[] = {MAX5387_CMD_AB, val};
00094     
00095     return(_p_i2c->write(_w_adrs, data, 2, false));
00096 }
00097