Maxim Integrated 7-bit Sink/Source Current DAC. DS4424, DS4422 input/output current Digital-to-Analog Converter Driver/library code.

Dependents:   DS4424_Hello_Current_DAC_on_MAX32630FTHR

Files at this revision

API Documentation at this revision

Comitter:
phonemacro
Date:
Mon Sep 10 21:53:18 2018 +0000
Parent:
0:8002303900e6
Child:
2:b7a81b724561
Commit message:
Updated to use Mbed coding style for member functions

Changed in this revision

DS4424.cpp Show annotated file Show diff for this revision Revisions of this file
DS4424.h Show annotated file Show diff for this revision Revisions of this file
--- a/DS4424.cpp	Tue Jul 03 20:09:09 2018 +0000
+++ b/DS4424.cpp	Mon Sep 10 21:53:18 2018 +0000
@@ -79,14 +79,14 @@
  
  
 //******************************************************************************
-int DS4424::readRaw(int32_t &result, ChannelRegAddr_e chan_addr) 
+int DS4424::read_raw(int32_t &result, ChannelRegAddr_e chan_addr) 
 {
     uint8_t value;
     int ret = DS4424_ERROR;
     union ds4424_raw_data raw;
     
     if (chan_addr >= REG_OUT0 && chan_addr <=  m_max_ch_reg_addr)
-        ret = readRegister(chan_addr, value);
+        ret = read_register(chan_addr, value);
     if (ret != 0)
         return DS4424_ERROR;
     
@@ -101,7 +101,7 @@
 
 
 //******************************************************************************
-int DS4424::writeRaw(int32_t value, ChannelRegAddr_e chan_addr) 
+int DS4424::write_raw(int32_t value, ChannelRegAddr_e chan_addr) 
 {
     #define U8_MAX     ((uint8_t)~0U)
     #define S8_MAX     ((int8_t)(U8_MAX>>1))
@@ -118,7 +118,7 @@
             raw.source_bit = DS4424_SINK_I;
             raw.dx = -value;
         }
-        ret = writeRegister(chan_addr, raw.bits);
+        ret = write_register(chan_addr, raw.bits);
  
         if (ret != 0)
             return DS4424_ERROR;
@@ -130,7 +130,7 @@
 
  
 //******************************************************************************
-int DS4424::readRegister(ChannelRegAddr_e reg, uint8_t &value) 
+int DS4424::read_register(ChannelRegAddr_e reg, uint8_t &value) 
 {
     int32_t ret;
  
@@ -147,7 +147,7 @@
         printf("%s - failed - ret: %d\r\n", __func__, ret);
         return DS4424_ERROR;
     }
-
+ 
     value = data;
     return DS4424_NO_ERROR;
 
@@ -155,7 +155,7 @@
 
 
 //******************************************************************************
-int DS4424::writeRegister(ChannelRegAddr_e reg, uint8_t value)
+int DS4424::write_register(ChannelRegAddr_e reg, uint8_t value)
 {
     
     int32_t ret;
--- a/DS4424.h	Tue Jul 03 20:09:09 2018 +0000
+++ b/DS4424.h	Mon Sep 10 21:53:18 2018 +0000
@@ -31,7 +31,7 @@
 * ownership rights.
 *******************************************************************************
 */
-#ifndef DS4424_H
+ #ifndef DS4424_H
 #define DS4424_H
  
 #include "mbed.h"
@@ -47,35 +47,36 @@
 #define DS4424_SINK_I       0
 
 /**
- * @brief DS4424 Four/two Channel I2C Sink/Source Current DAC
- * @details The DS4424/DS422 contains four/two I2C
- * programmable current DACs. This driver enables
- * the writing of source/since values to the channel
- * registers.
- * <br>https://www.maximintegrated.com/en/products/analog/data-converters/digital-to-analog-converters/DS4424.html
- *  @version 1.0000.0
- * @code 
- * #include "mbed.h"
- * #include "DS4424.h"
- * #include "max32630fthr.h"
- * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
- * I2C i2cBus(P3_4, P3_5);
- * DS4424 ds4424_dac(i2cBus, DS4424::DS4424_I2C_SLAVE_ADRS0, DS4424::DS4424_IC);
+* @brief Four/two Channel I2C Sink/Source Current DAC
+* @version 1.0000.2
+*
+* @details The DS4424/DS422 contains four/two I2C
+* programmable current DACs. This driver enables
+* the writing of source/since values to the channel
+* registers.
+*
+* @code 
+* #include "mbed.h"
+* #include "DS4424.h"
+* #include "max32630fthr.h"
+* MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+* I2C i2cBus(P3_4, P3_5);
+* DS4424 ds4424_dac(i2cBus, DS4424::DS4424_I2C_SLAVE_ADRS0, DS4424::DS4424_IC);
     
- * int main()
- * {
- *    int32_t value[4]={0,0,0,0};
- *    int ret;
- *    
- *    i2cBus.frequency(400000);
- *
- *    // read channel 0 register
- *    ret = ds4424_dac.readRaw(value[0], DS4424::REG_OUT0); 
- *
- *      //... rest of application
- * }
- * @endcode
- */
+* int main()
+* {
+*    int32_t value[4]={0,0,0,0};
+*    int ret;
+*    
+*    i2cBus.frequency(400000);
+*
+*    // read channel 0 register
+*    ret = ds4424_dac.read_raw(value[0], DS4424::REG_OUT0); 
+*
+*      //... rest of application
+* }
+* @endcode
+*/
 
 class DS4424
 {
@@ -156,7 +157,7 @@
     * @param chan_addr - Channel 0 to 3
     * @return 0 on success, non-zero on failure
     */
-    int readRaw(int32_t &result, ChannelRegAddr_e chan_addr);
+    int read_raw(int32_t &result, ChannelRegAddr_e chan_addr);
     
  /** 
     * @brief Write raw value to a channel.
@@ -164,7 +165,7 @@
     * @param chan_addr - Channel 0 to 3
     * @return 0 on success, non-zero on failure
     */
-    int writeRaw(int32_t value, ChannelRegAddr_e chan_addr);
+    int write_raw(int32_t value, ChannelRegAddr_e chan_addr);
 
 protected:
 
@@ -174,7 +175,7 @@
     * @param[out] value - Read data on success
     * @return 0 on success, non-zero on failure
     */
-    int readRegister(ChannelRegAddr_e reg, uint8_t &value);
+    int read_register(ChannelRegAddr_e reg, uint8_t &value);
 
     /** 
     * @brief Write register of device at slave address
@@ -182,7 +183,7 @@
     * @param value - Value to write
     * @return 0 on success, non-zero on failure
     */
-    int writeRegister(ChannelRegAddr_e reg, uint8_t value);
+    int write_register(ChannelRegAddr_e reg, uint8_t value);
  
 private:
     /// I2C object