Library for the MAX11300

Revision:
11:31e7ca030b8f
Parent:
10:6efe114ef882
Child:
12:8054ee101bad
--- a/MAX113XX_Pixi.cpp	Mon May 08 17:49:57 2017 +0000
+++ b/MAX113XX_Pixi.cpp	Mon May 08 19:24:55 2017 +0000
@@ -57,6 +57,23 @@
     port_cfg_17_DESIGNVALUE,
     port_cfg_18_DESIGNVALUE,
     port_cfg_19_DESIGNVALUE};
+    
+static const uint16_t deviceDesignVals[15] = {
+    device_control_DESIGNVALUE,
+    interrupt_mask_DESIGNVALUE,
+    gpi_irqmode_7_to_0_DESIGNVALUE,
+    gpi_irqmode_15_to_8_DESIGNVALUE,
+    gpi_irqmode_19_to_16_DESIGNVALUE,
+    0, //reserved
+    dac_preset_data_1_DESIGNVALUE,
+    dac_preset_data_2_DESIGNVALUE,
+    tmp_mon_cfg_DESIGNVALUE,
+    tmp_mon_int_hi_thresh_DESIGNVALUE,
+    tmp_mon_int_lo_thresh_DESIGNVALUE,
+    tmp_mon_ext1_hi_thresh_DESIGNVALUE,
+    tmp_mon_ext1_lo_thresh_DESIGNVALUE,
+    tmp_mon_ext2_hi_thresh_DESIGNVALUE,
+    tmp_mon_ext2_lo_thresh_DESIGNVALUE};  
 #endif
 
 //12 port devices...
@@ -81,7 +98,8 @@
 MAX113XX_Pixi::MAX113XX_Pixi(Device_e device, PinName cnvt):
 m_device(device), m_cnvt(cnvt, 1)
 {
-} 
+}
+
 
 //*********************************************************************
 MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioWrite(Ports_e port, 
@@ -242,7 +260,15 @@
 MAX113XX_Pixi::Device_e device, PinName cnvt):
 MAX113XX_Pixi(device, cnvt), m_spiBus(spiBus), m_cs(cs, 1)
 {
-    
+    if((m_device == MAX11300) || (m_device == MAX11301)) //20 port device
+    {
+        blockWrite(device_control, deviceDesignVals, 15);
+        blockWrite(port_cfg_00, portConfigDesignVals, 20);
+        wait(0.1);
+    }
+    else //12 port device
+    {
+    }
 }
 
 //*********************************************************************
@@ -279,19 +305,30 @@
 void MAX113XX_SPI::blockWrite(uint8_t reg, const uint16_t *data, 
                               const uint8_t num_reg)
 {
+    m_cs = 0;
+    m_spiBus.write(MAX113XXAddr_SPI_Write(reg));
     for(uint8_t idx = 0; idx < num_reg; idx++)
     {
-        writeRegister((reg + idx), data[idx]);
+        m_spiBus.write(((0xFF00 & data[idx]) >> 8));
+        m_spiBus.write((0x00FF & data[idx]));
     }
+    m_cs = 1;
 }
 
 //*********************************************************************        
 void MAX113XX_SPI::blockRead(uint8_t reg, uint16_t *data, const uint8_t num_reg)
 {
-    for(uint8_t idx = 0; idx < num_reg; idx++)
+    uint16_t temp;
+    m_cs = 0;
+    m_spiBus.write(MAX113XXAddr_SPI_Read(reg));
+    for(uint8_t idx = 0; idx < num_reg; idx ++)
     {
-        data[idx] = readRegister((reg + idx));
+        temp = 0;
+        temp |= (m_spiBus.write(0xFF) << 8);
+        temp |= m_spiBus.write(0xFF);
+        data[idx] = temp;
     }
+    m_cs = 1;
 }
 
 
@@ -299,7 +336,15 @@
 MAX113XX_I2C::MAX113XX_I2C(I2C &i2cBus, MAX113XX_Pixi::Device_e device, PinName cnvt):
 MAX113XX_Pixi(device, cnvt), m_i2cBus(i2cBus)
 {
-    
+    if((m_device == MAX11300) || (m_device == MAX11301)) //20 port device
+    {
+        blockWrite(device_control, deviceDesignVals, 15);
+        blockWrite(port_cfg_00, portConfigDesignVals, 20);
+        wait(0.1);
+    }
+    else //12 port device
+    {
+    }
 }
 
 //*********************************************************************