Library for Akizuki MCP3425 ADC module

Fork of MCP3425 by yasuyuki onodera

Library for MCP3425 ADC module from Akizuki-denshi.

Revision:
3:378672292488
Parent:
2:7375e645e806
--- a/MCP3425.h	Wed Apr 13 14:45:11 2016 +0000
+++ b/MCP3425.h	Fri Apr 15 13:41:32 2016 +0000
@@ -1,6 +1,8 @@
 //**********************
 // MCP3425.h for mbed
 //
+// (C)Copyright 2016 Satoshi Nihonyanagi, All Rights Reserved.
+//
 // (C)Copyright 2014 All rights reserved by Y.Onodera
 // http://einstlab.web.fc2.com
 //**********************
@@ -9,29 +11,64 @@
 #define MCP3425_H_
 
 #include "mbed.h"
+/** MCP3425 class.
+ *  Used for MCP3425 ADC module from Akizuki-denshi.
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "MCP3425.h"
+ * 
+ * I2C i2c(dp13, dp15);
+ * MCP3425 adc(i2c);
+ * 
+ * int main() 
+ * {
+ *     adc.set(MCP3425::G1);
+ *     adc.set(MCP3425::W12);
+ *     adc.set(MCP3425::CONTINUOUS);
+ *
+ *     short c = adc.code();
+ *     float v = adc.read();
+ * }
+ * @endcode
+ */
 
 class MCP3425
 {
-public:
-
-    static const int ADDR;
-    static const float VREF;
-    
+public:    
     enum Gain { G1 = 0, G2 = 1, G4 = 2, G8 = 3 };
     enum Resolution {W12 = 0, W14 = 1, W16 = 2};
     enum Conversion {ONESHOT = 0, CONTINUOUS = 1};
 
+    /** Construct a new instance.*/
     MCP3425(I2C& i2c);
+    
+    /** Construct a new instance with the specified I2C slave address. 
+        ( Address of MCP3425 from akizuki-denshi is fixed to 0x0D.)
+    */
     MCP3425(I2C& i2c, int addr);
 
+    /** Specify gain. */
     void set(Gain gain);
+    
+    /** Specify resolution (sample bits). */
     void set(Resolution resolution);
+    
+    /** Specify conversion operation mode. */
     void set(Conversion conversion);
 
-    short get(); // Returns AD code
-    float read(); // Returns voltage
+    /** Return AD code. */
+    short get();
+    
+    /** Return voltage. */
+    float read();
 
 private:
+
+    static const int ADDR;
+    static const float VREF;
+
     typedef union
     {
         unsigned short int  Val;
@@ -66,6 +103,7 @@
     void _init();
     void _write_cfg();
     short _get_code();
+    float _c2v(short code);
 };
 
 #endif /* MCP3425_H_ */