Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of max14661 by
max14661.cpp
00001 /******************************************************************//** 00002 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 **********************************************************************/ 00032 00033 00034 #include "max14661.h" 00035 00036 00037 //********************************************************************* 00038 Max14661::Max14661(PinName sda, PinName scl, max14661_i2c_adrs_t i2c_adrs) 00039 :_i2c(new I2C(sda, scl)), _i2c_owner(true), _w_adrs(i2c_adrs << 1), _r_adrs((i2c_adrs << 1) | 1) 00040 { 00041 00042 } 00043 00044 00045 //********************************************************************* 00046 Max14661::Max14661(I2C & i2c_bus, max14661_i2c_adrs_t i2c_adrs) 00047 :_i2c(&i2c_bus), _i2c_owner(false), _w_adrs(i2c_adrs << 1), _r_adrs((i2c_adrs << 1) | 1) 00048 { 00049 } 00050 00051 00052 //********************************************************************* 00053 Max14661::~Max14661() 00054 { 00055 if(_i2c_owner) 00056 { 00057 delete _i2c; 00058 } 00059 } 00060 00061 00062 //********************************************************************* 00063 uint16_t Max14661::wrt_cmd_registers(max14661_cmds_t cmdA, 00064 max14661_cmds_t cmdB) 00065 { 00066 uint8_t data[3]; 00067 uint8_t data_length = 0; 00068 uint16_t rtn_val = 1; 00069 00070 //build packet 00071 data[data_length++] = CMD_A; 00072 data[data_length++] = cmdA; 00073 data[data_length++] = cmdB; 00074 00075 rtn_val = _i2c->write(_w_adrs,(const char*) data, data_length); 00076 00077 return(rtn_val); 00078 } 00079 00080 00081 //********************************************************************* 00082 uint16_t Max14661::wrt_shadow_registers(uint16_t bankA, uint16_t bankB) 00083 { 00084 uint8_t data[5]; 00085 uint8_t data_length = 0; 00086 uint16_t rtn_val = 1; 00087 00088 data[data_length++] = SHDW0; 00089 data[data_length++] = (bankA & 0x00FF); 00090 data[data_length++] = ((bankA >> 8) & 0x00FF); 00091 data[data_length++] = (bankB & 0x00FF); 00092 data[data_length++] = ((bankB >> 8) & 0x00FF); 00093 00094 rtn_val = _i2c->write(_w_adrs,(const char*) data, data_length); 00095 00096 return(rtn_val); 00097 } 00098 00099 00100 //********************************************************************* 00101 uint16_t Max14661::wrt_dir_registers(uint16_t bankA, uint16_t bankB) 00102 { 00103 uint8_t data[5]; 00104 uint8_t data_length = 0; 00105 uint16_t rtn_val = 1; 00106 00107 data[data_length++] = DIR0; 00108 data[data_length++] = (bankA & 0x00FF); 00109 data[data_length++] = ((bankA >> 8) & 0x00FF); 00110 data[data_length++] = (bankB & 0x00FF); 00111 data[data_length++] = ((bankB >> 8) & 0x00FF); 00112 00113 rtn_val = _i2c->write(_w_adrs,(const char*) data, data_length); 00114 00115 return(rtn_val); 00116 } 00117 00118 00119 //********************************************************************* 00120 uint16_t Max14661::set_switches(uint16_t bankA, uint16_t bankB) 00121 { 00122 uint8_t data[7]; 00123 uint8_t data_length = 0; 00124 uint16_t rtn_val = 1; 00125 00126 data[data_length++] = SHDW0; 00127 data[data_length++] = (bankA & 0x00FF); 00128 data[data_length++] = ((bankA >> 8) & 0x00FF); 00129 data[data_length++] = (bankB & 0x00FF); 00130 data[data_length++] = ((bankB >> 8) & 0x00FF); 00131 data[data_length++] = COPY_SHADOW; 00132 data[data_length++] = COPY_SHADOW; 00133 00134 rtn_val = _i2c->write(_w_adrs,(const char*) data, data_length); 00135 00136 return(rtn_val); 00137 } 00138 00139 00140 //********************************************************************* 00141 uint16_t Max14661::rd_dir_registers(uint8_t* data) 00142 { 00143 uint16_t rtn_val = 1; 00144 00145 data[0] = DIR0; 00146 00147 rtn_val = _i2c->write(_w_adrs,(const char*) data, 1); 00148 00149 if(!rtn_val) 00150 { 00151 rtn_val = _i2c->read(_r_adrs,(char*) data, 4); 00152 } 00153 00154 return(rtn_val); 00155 } 00156 00157 00158 //********************************************************************* 00159 uint16_t Max14661::rd_shadow_registers(uint8_t* data) 00160 { 00161 uint16_t rtn_val = 1; 00162 00163 data[0] = SHDW0; 00164 00165 rtn_val = _i2c->write(_w_adrs,(const char*) data, 1); 00166 00167 if(!rtn_val) 00168 { 00169 rtn_val = _i2c->read(_r_adrs,(char*) data, 4); 00170 } 00171 00172 return(rtn_val); 00173 }
Generated on Thu Jul 14 2022 13:39:06 by
