Library for the MAX11300

Revision:
10:6efe114ef882
Parent:
9:094df3de3616
Child:
11:31e7ca030b8f
--- a/MAX113XX_Pixi.cpp	Sat May 06 00:22:47 2017 +0000
+++ b/MAX113XX_Pixi.cpp	Mon May 08 17:49:57 2017 +0000
@@ -87,52 +87,50 @@
 MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioWrite(Ports_e port, 
                                                     const uint8_t state)
 {
+    uint16_t temp;
+    uint16_t port_mask;
+    
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
     
-    if(m_device == MAX11300 || m_device == MAX11301)
+    if(m_device == MAX11300 || m_device == MAX11301) //20 port device
     {
+        if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_3)
+        {
+            if(port < MAX113XX_Pixi::PORT16)
+            {
+                port_mask = (1 << port);
+                temp = readRegister(gpo_data_15_to_0);
+                if(state & 0x01)
+                {
+                    temp |= port_mask;
+                }
+                else
+                {
+                    temp &= ~port_mask;
+                }
+                writeRegister(gpo_data_15_to_0, temp);
+            }
+            else
+            {
+                port_mask = (1 << (port - MAX113XX_Pixi::PORT16));
+                temp = readRegister(gpo_data_19_to_16);
+                if(state & 0x01)
+                {
+                    temp |= port_mask;
+                }
+                else
+                {
+                    temp &= ~port_mask;
+                }
+                writeRegister(gpo_data_19_to_16, temp);
+            }
+            
+            result = MAX113XX_Pixi::Success;
+        }
     }
     else //12 port device
     {
     }
-    /*
-    uint16_t temp;
-    uint16_t port_mask;
-    
-    if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_3)
-    {
-        if(port < MAX113XX_Pixi::PORT16)
-        {
-            port_mask = (1 << port);
-            temp = readRegister(gpo_data_15_to_0);
-            if(state & 0x01)
-            {
-                temp |= port_mask;
-            }
-            else
-            {
-                temp &= ~port_mask;
-            }
-            writeRegister(gpo_data_15_to_0, temp);
-        }
-        else
-        {
-            port_mask = (1 << (port - MAX113XX_Pixi::PORT16));
-            temp = readRegister(gpo_data_19_to_16);
-            if(state & 0x01)
-            {
-                temp |= port_mask;
-            }
-            else
-            {
-                temp &= ~port_mask;
-            }
-            writeRegister(gpo_data_19_to_16, temp);
-        }
-        
-        result = MAX113XX_Pixi::Success;
-    }
-    */
     
     return result;
 }
@@ -142,28 +140,26 @@
 {
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
     
-    if(m_device == MAX11300 || m_device == MAX11301)
+    if(m_device == MAX11300 || m_device == MAX11301) //20 port device
     {
+        if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_1)
+        {
+            if(port < MAX113XX_Pixi::PORT16)
+            {
+                state = (readRegister(gpi_data_15_to_0) >> port);
+            }
+            else
+            {
+                state = (readRegister(gpi_data_19_to_16) >> (port - MAX113XX_Pixi::PORT16));
+            }
+            
+            result = MAX113XX_Pixi::Success;
+        }
     }
     else //12 port device
     {
     }
     
-    /*
-    if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_1)
-    {
-        if(port < MAX113XX_Pixi::PORT16)
-        {
-            state = (readRegister(gpi_data_15_to_0) >> port);
-        }
-        else
-        {
-            state = (readRegister(gpi_data_19_to_16) >> (port - MAX113XX_Pixi::PORT16));
-        }
-        
-        result = MAX113XX_Pixi::Success;
-    }
-    */
     return result;
 }
 
@@ -172,31 +168,29 @@
 {
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
     
-    if(m_device == MAX11300 || m_device == MAX11301)
+    if(m_device == MAX11300 || m_device == MAX11301) //20 port device
     {
+        if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_7)
+        {
+            uint8_t num_samples = ((portConfigDesignVals[port] & 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 + port));
+            
+            result = MAX113XX_Pixi::Success;
+        }
     }
     else //12 port device
     {
     }
     
-    /*
-    if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_7)
-    {
-        uint8_t num_samples = ((port_config_design_vals[port] & 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(static_cast<MAX11300RegAddress_t>(adc_data_port_00 + port));
-        
-        result = MAX113XX_Pixi::Success;
-    }
-    */
     return result;
 }
 
@@ -206,27 +200,25 @@
 {
     MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure;
     
-    if(m_device == MAX11300 || m_device == MAX11301)
+    if(m_device == MAX11300 || m_device == MAX11301) //20 port device
     {
+        if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_5)
+        {
+            writeRegister((dac_data_port_00 + port) , data);
+            result = MAX113XX_Pixi::Success;
+        }
     }
     else //12 port device
     {
     }
     
-    /*
-    if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_5)
-    {
-        writeRegister(static_cast<MAX11300RegAddress_t>(dac_data_port_00 + port) , data);
-        result = MAX113XX_Pixi::Success;
-    }
-    */
     return result;
 }
 
 //*********************************************************************
 void MAX113XX_Pixi::dumpPixiMemory(Serial &ser, MAX113XX_Pixi &pixi)
 {
-    uint16_t mem[256];
+    uint16_t mem[0x74];
     
     pixi.blockRead(dev_id, mem, 0x74);
     for(uint8_t idx = 0; idx < 0x74; idx++)