General usable MCP4728 quad DAC implementation only limited function has to be used together with the DevInterface lib

Dependents:   mbedSerialInterface_talkback2 MCP4728test mbedSerialInterface_sequencer

Revision:
2:366e996af95c
Parent:
1:cd7c70a46739
Child:
3:2a2eafba8a1d
--- a/mcp4728.h	Fri Jan 08 11:58:33 2016 +0000
+++ b/mcp4728.h	Tue Jan 12 15:03:38 2016 +0000
@@ -4,6 +4,7 @@
 
 #include "stdbool.h"
 
+
 #include "dev_interface_def.h"
 #include "I2CInterface.h" 
 #include "DACInterface.h" 
@@ -13,7 +14,13 @@
 /** MCP4728 class.
  *  Used for interfacing with a mcp4728 12-Bit QUAD  Digital-to-Analog Converter.
  *  For version 0.4X mode can not be set ( Intern ref,  gain x2  power mode normal) 
+ *  It has to be used with the  https://developer.mbed.org/users/wbeaumont/code/DevInterfaces/ package 
+ *  This includes the "virtual" I2CInterface class that is the interface to the I2C device 
+ *  An implementation of the I2Cinterface class for the MBED can be found at 
+ * 
  *  ( DACInterface inherits getVersion  )
+ * ee-prom set / read not tested / implemented. 
+ * 
  * (C) Wim Beaumont Universiteit Antwerpen 2015        
  *  
  */
@@ -36,42 +43,21 @@
         /** Enter the device into a power down mode, and pull Vout to ground using an internal 500k resistor. */
         PowerDown500k=3
     };
-    
+    /** Voltage reference can be either External, this means the Vdd or internal , 2.048 V 
+        The output goes from 0 to Vref ( either 2.048 V or Vdd ), 
+    */
     enum VrefMode {
         ExternRef=0,  // == VDD 
         InternRef=1    
     };
-
+    /** In case the internal reference is used the output can be multiplied by a factor 2. 
+        in that case the output goes between 0 and 4.096 V 
+    */ 
     enum GainMode {
         GainX1=0,
         GainX2=1
     };
     
-    typedef struct MCP4728ChCfg{
-         GainMode gain;
-         VrefMode  vref;
-         PowerMode pwr;
-    } MCP4728ChCfgdummy;
-    
-    MCP4728ChCfg ChCfg[4]; //used for setting 
-    
-    typedef struct MCP4728ChStatus{
-         GainMode gain;
-         VrefMode  vref;
-         PowerMode pwr;
-         bool bussy;
-         bool por;
-         short int dacvalue;
-         short int promvalue;
-         GainMode promgain;
-         VrefMode  promvref;
-         PowerMode prompwr;
-         
-    } MCP4728Chstatus;
-    
-    
-    MCP4728ChStatus chstat[4]; // for readback .
-    
     
     
         
@@ -85,6 +71,13 @@
         /** High Speed 3.4Mhz bus. WARNING: the test suite fails for the mbed LPC1768 when this frequency is selected - not tested on other platforms.*/
         HighSpeed3_4Mhz
     };
+    /** structure used to set the channel configuration */
+    typedef struct MCP4728ChCfg{
+         GainMode gain;
+         VrefMode  vref;
+         PowerMode pwr;
+    } MCP4728ChCfgdummy;
+
     
     /** Create an mcp4725 I2C interface
      * 
@@ -122,6 +115,9 @@
     /** set the dac value for a certain channel. */
     virtual int setDACvalue( int value, int ch=0);
     virtual int setVoltage (float voltage, int ch=0);
+    
+    
+    
     protected:
     /** pointer to the I2C interface driver. */
     I2CInterface* _i2c_interface;
@@ -133,6 +129,31 @@
     short int volt2dig( float voltage,GainMode gain,  VrefMode  vref);
     float Vdd;
     
+    
+
+    /** used for read back the setting  */
+    MCP4728ChCfg ChCfg[4]; 
+    
+    typedef struct MCP4728ChStatus{
+         GainMode gain;
+         VrefMode  vref;
+         PowerMode pwr;
+         bool bussy;
+         bool por;
+         short int dacvalue;
+         short int promvalue;
+         GainMode promgain;
+         VrefMode  promvref;
+         PowerMode prompwr;
+         
+    } MCP4728Chstatus;
+    
+    
+    MCP4728ChStatus chstat[4]; // for readback .
+    
+    
+    
+    
 };
 
 #endif
\ No newline at end of file