Library for the MAX11300

Revision:
13:546dd29b1c7a
Parent:
12:8054ee101bad
Child:
15:fb674d741844
--- a/MAX113XX_Pixi.cpp	Tue May 09 19:04:38 2017 +0000
+++ b/MAX113XX_Pixi.cpp	Tue May 09 22:06:19 2017 +0000
@@ -161,13 +161,32 @@
 
 //*********************************************************************
 MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::differentialADCRead(Ports_e posPort, 
-                                                              Ports_e negPort, 
-                                                              uint16_t &data)
+                                                              int16_t &data)
 {
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
     
     if(m_device == MAX11300 || m_device == MAX11301) //20 port device
     {
+        if(((portConfigDesignVals[posPort] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_8)
+        {
+            uint8_t num_samples = ((portConfigDesignVals[posPort] & port_cfg_00_funcprm_nsamples) >> 5);
+            num_samples = (1 << num_samples);
+            
+            while(num_samples--)
+            {
+                m_cnvt = 0;
+                wait_us(1);
+                m_cnvt = 1;
+                wait_us(100);
+            }
+            data = readRegister((adc_data_port_00 + posPort));
+            if(data & 0x0800)
+            {
+                data |= 0xF000;
+            }
+            
+            result = MAX113XX_Pixi::Success;
+        }
     }
     else //12 port device
     {
@@ -198,6 +217,36 @@
 }
 
 //*********************************************************************
+MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::dacWriteADCMonitor(Ports_e port, 
+                                                            const uint16_t data, 
+                                                            uint16_t &adcData)
+{
+    MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
+    
+    if(m_device == MAX11300 || m_device == MAX11301) //20 port device
+    {
+        if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_6)
+        {
+            writeRegister((dac_data_port_00 + port) , data);
+            
+            m_cnvt = 0;
+            wait_us(1);
+            m_cnvt = 1;
+            wait_us(100);
+
+            adcData = readRegister((adc_data_port_00 + port));
+            
+            result = MAX113XX_Pixi::Success;
+        }
+    }
+    else //12 port device
+    {
+    }
+    
+    return result;
+}
+
+//*********************************************************************
 MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioRead(Ports_e port, uint8_t &state)
 {
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
@@ -278,14 +327,80 @@
 }
 
 //*********************************************************************
-MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::setAnalogSwitchState(Ports_e portA, 
-                                                               Ports_e portB, 
+MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::setAnalogSwitchState(Ports_e lowPort, 
                                                                bool state)
 {
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
     
     if(m_device == MAX11300 || m_device == MAX11301) //20 port device
     {
+        if(((portConfigDesignVals[lowPort] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_12)
+        {
+            uint16_t data = readRegister(port_cfg_00 + lowPort);
+            if(state)
+            {
+                data = ((data & 0x0FFF) | (MAX113XX_Pixi::MODE_12 << 12));
+            }
+            else
+            {
+                data = ((data & 0x0FFF) | (MAX113XX_Pixi::MODE_0 << 12));
+            }
+            writeRegister((port_cfg_00 + lowPort), data);
+            
+            result = MAX113XX_Pixi::Success;
+        }
+    }
+    else //12 port device
+    {
+    }
+    
+    return result;
+}
+
+//*********************************************************************
+MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::readTempSensor(TempSensor_e sensor, 
+                                                         float &data)
+{
+    MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
+    int16_t temp;
+    
+    if(m_device == MAX11300 || m_device == MAX11301) //20 port device
+    {
+        switch(sensor)
+        {
+            case Internal:
+                if(device_control_DESIGNVALUE & device_control_TMPCTLINT)
+                {
+                    temp = readRegister(tmp_int_data);
+                    result = MAX113XX_Pixi::Success;
+                }
+            break;
+            
+            case External1:
+                if(device_control_DESIGNVALUE & device_control_TMPCTLEXT0)
+                {
+                    temp = readRegister(tmp_ext1_data);
+                    result = MAX113XX_Pixi::Success;
+                }
+            break;
+            
+            case External2:
+                if(device_control_DESIGNVALUE & device_control_TMPCTLEXT1)
+                {
+                    temp = readRegister(tmp_ext2_data);
+                    result = MAX113XX_Pixi::Success;
+                }
+            break;
+        };
+        
+        if(result == MAX113XX_Pixi::Success)
+        {
+            if(temp & 0x0800)
+            {
+                temp |= 0xF000;
+            }
+            data = (temp/8.0F);
+        }
     }
     else //12 port device
     {