8:4 Matrix Multiplexer

Fork of max14661 by Maxim Integrated

This is an untested driver for the MAX14724.

Revision:
4:45fa0192f66d
Parent:
2:88c168ddc145
Child:
6:be4f2d7fc054
diff -r 638bf72e3a00 -r 45fa0192f66d max14661.cpp
--- a/max14661.cpp	Wed Nov 19 04:24:12 2014 +0000
+++ b/max14661.cpp	Fri Nov 21 04:31:05 2014 +0000
@@ -117,10 +117,11 @@
 
 
 /******************************************************************//**
-* Writes data pointed at by 'data' to shadow registers 
+* Writes bankA and bankB to coresponding shadow registers
 *
 * On Entry:
-*     @param[in] data - pointer to data 
+*     @param[in] bankA - binary representation of switch states
+*     @param[in] bankB - binary representation of switch states
 *
 * On Exit:
 *     @return return value = 0 on success, non-0 on failure
@@ -131,38 +132,39 @@
 * //declare mux object
 * Max14661 mux(D14, D15, MAX14661_I2C_ADRS0); 
 *
-* uint8_t data[] = {1, 2, 3, 4};
+* uint16_t bankA = (SW12 | SW02); //example only
+* uint16_t bankB = (SW11 | SW01);
 * uint16_t rtn_val;  
 *  
 * //wite shadow registers
-* rtn_val = mux.wrt_shadow_registers(data);
+* rtn_val = mux.wrt_shadow_registers(bankA, bankB);
 *
 * @endcode
 **********************************************************************/
-uint16_t Max14661::wrt_shadow_registers(uint8_t* data)
+uint16_t Max14661::wrt_shadow_registers(uint16_t bankA, uint16_t bankB)
 {
-    uint8_t local_data[5];
+    uint8_t data[5];
     uint8_t data_length = 0;
     uint16_t rtn_val = 1;
     
-    local_data[data_length++] = SHDW0;
+    data[data_length++] = SHDW0;
+    data[data_length++] = (bankA & 0x00FF);
+    data[data_length++] = ((bankA >> 8) & 0x00FF);
+    data[data_length++] = (bankB & 0x00FF);
+    data[data_length++] = ((bankB >> 8) & 0x00FF);
     
-    for(; data_length < 5; data_length++)
-    {
-        local_data[data_length] = data[data_length-1];
-    }
-    
-    rtn_val = write(w_adrs,(const char*) local_data, data_length);
+    rtn_val = write(w_adrs,(const char*) data, data_length);
     
     return(rtn_val);
 }
 
 
 /******************************************************************//**
-* Writes data pointed at by 'data' to direct access registers 
+* Writes bankA and bankB to coresponding direct access registers 
 *
 * On Entry:
-*     @param[in] data - pointer to data to be written
+*     @param[in] bankA - binary representation of switch states
+*     @param[in] bankB - binary representation of switch states
 *
 * On Exit:
 *     @return return value = 0 on success, non-0 on failure
@@ -173,28 +175,74 @@
 * //declare mux object
 * Max14661 mux(D14, D15, MAX14661_I2C_ADRS0);   
 *
-* uint8_t data[] = {1, 2, 3, 4};
+* uint16_t bankA = (SW12 | SW02); //example only
+* uint16_t bankB = (SW11 | SW01);
 * uint16_t rtn_val;  
 *  
 * //wite shadow registers
-* rtn_val = mux.wrt_shadow_registers(data);
+* rtn_val = mux.wrt_dir_registers(bankA, bankB);
 *
 * @endcode
 **********************************************************************/
-uint16_t Max14661::wrt_dir_registers(uint8_t* data)
+uint16_t Max14661::wrt_dir_registers(uint16_t bankA, uint16_t bankB)
 {
-    uint8_t local_data[5];
+    uint8_t data[5];
     uint8_t data_length = 0;
     uint16_t rtn_val = 1;
     
-    local_data[data_length++] = DIR0;
+    data[data_length++] = DIR0;
+    data[data_length++] = (bankA & 0x00FF);
+    data[data_length++] = ((bankA >> 8) & 0x00FF);
+    data[data_length++] = (bankB & 0x00FF);
+    data[data_length++] = ((bankB >> 8) & 0x00FF);
+    
+    rtn_val = write(w_adrs,(const char*) data, data_length);
     
-    for(; data_length < 5; data_length++)
-    {
-        local_data[data_length] = data[data_length-1];
-    }
+    return(rtn_val);
+}
+
+
+/******************************************************************//**
+* Writes bankA and bankB to coresponding shadow register and then 
+* issues copy command for both banks
+*
+* On Entry:
+*     @param[in] bankA - binary representation of switch states
+*     @param[in] bankB - binary representation of switch states
+*
+* On Exit:
+*     @return return value = 0 on success, non-0 on failure
+*
+* Example:
+* @code  
+*
+* //declare mux object
+* Max14661 mux(D14, D15, MAX14661_I2C_ADRS0);   
+*
+* uint16_t bankA = (SW12 | SW02); //example only
+* uint16_t bankB = (SW11 | SW01);
+* uint16_t rtn_val;  
+*  
+* //wite shadow registers
+* rtn_val = mux.set_switches(bankA, bankB);
+*
+* @endcode
+**********************************************************************/
+uint16_t Max14661::set_switches(uint16_t bankA, uint16_t bankB)
+{
+    uint8_t data[7];
+    uint8_t data_length = 0;
+    uint16_t rtn_val = 1;
     
-    rtn_val = write(w_adrs,(const char*) local_data, data_length);
+    data[data_length++] = SHDW0;
+    data[data_length++] = (bankA & 0x00FF);
+    data[data_length++] = ((bankA >> 8) & 0x00FF);
+    data[data_length++] = (bankB & 0x00FF);
+    data[data_length++] = ((bankB >> 8) & 0x00FF);
+    data[data_length++] = COPY_SHADOW;
+    data[data_length++] = COPY_SHADOW;
+    
+    rtn_val = write(w_adrs,(const char*) data, data_length);
     
     return(rtn_val);
 }