Maxim Integrated MAX5715 12-bit 4-channel voltage-output DAC

Dependents:   MAX5715BOB_Tester MAX5715BOB_12bit_4ch_SPI_DAC MAX5715BOB_Serial_Tester

Revision:
5:7894decf9375
Parent:
4:500c80398f90
--- a/MAX5715.cpp	Wed Aug 28 03:21:35 2019 -0700
+++ b/MAX5715.cpp	Fri Sep 27 10:35:15 2019 +0000
@@ -43,6 +43,7 @@
 
 // Device Name = MAX5715
 // Device Description = Ultra-Small, 12-Bit, 4-Channel, Buffered Output Voltage DAC with Internal Reference and SPI Interface
+// Device DeviceBriefDescription = 12-bit 4-ch SPI VOUT DAC
 // Device Manufacturer = Maxim Integrated
 // Device PartNumber = MAX5715AAUD+
 // Device RegValue_Width = DataWidth16bit_HL
@@ -106,37 +107,27 @@
 // SupplyPin Function = Digital
 //
 
-// CODE GENERATOR: class constructor definition
 MAX5715::MAX5715(SPI &spi, DigitalOut &cs_pin, // SPI interface
-                 // CODE GENERATOR: class constructor definition gpio InputPin pins
                  DigitalOut &LDACb_pin, // Digital Trigger Input to MAX5715 device
                  DigitalOut &CLRb_pin, // Digital Trigger Input to MAX5715 device
                  // AnalogOut &REF_pin, // Reference Input to MAX5715 device
-                 // CODE GENERATOR: class constructor definition gpio OutputPin pins
                  // AnalogIn &OUTA_pin, // Analog Output from MAX5715 device
                  // AnalogIn &OUTB_pin, // Analog Output from MAX5715 device
                  // AnalogIn &OUTC_pin, // Analog Output from MAX5715 device
                  // AnalogIn &OUTD_pin, // Analog Output from MAX5715 device
                  // DigitalIn &RDYb_pin, // Digital DaisyChain Output from MAX5715 device
-                 // CODE GENERATOR: class constructor definition ic_variant
                  MAX5715_ic_t ic_variant)
-    // CODE GENERATOR: class constructor initializer list
     : m_spi(spi), m_cs_pin(cs_pin), // SPI interface
-    // CODE GENERATOR: class constructor initializer list gpio InputPin pins
     m_LDACb_pin(LDACb_pin), // Digital Trigger Input to MAX5715 device
     m_CLRb_pin(CLRb_pin), // Digital Trigger Input to MAX5715 device
     // m_REF_pin(REF_pin), // Reference Input to MAX5715 device
-    // CODE GENERATOR: class constructor initializer list gpio OutputPin pins
     // m_OUTA_pin(OUTA_pin), // Analog Output from MAX5715 device
     // m_OUTB_pin(OUTB_pin), // Analog Output from MAX5715 device
     // m_OUTC_pin(OUTC_pin), // Analog Output from MAX5715 device
     // m_OUTD_pin(OUTD_pin), // Analog Output from MAX5715 device
     // m_RDYb_pin(RDYb_pin), // Digital DaisyChain Output from MAX5715 device
-    // CODE GENERATOR: class constructor initializer list ic_variant
     m_ic_variant(ic_variant)
 {
-    // CODE GENERATOR: class constructor definition SPI interface initialization
-    //
     // SPI CS = ActiveLow
     // SPI FrameStart = CS
     m_SPI_cs_state = 1;
@@ -154,55 +145,59 @@
     //#define SPI_SCLK_Hz 48000000 // 48MHz
     //#define SPI_SCLK_Hz 24000000 // 24MHz
     //#define SPI_SCLK_Hz 12000000 // 12MHz
-    //#define SPI_SCLK_Hz 6000000 // 6MHz
+    //#define SPI_SCLK_Hz 6000000 // 6MHz
     //#define SPI_SCLK_Hz 4000000 // 4MHz
     //#define SPI_SCLK_Hz 2000000 // 2MHz
     //#define SPI_SCLK_Hz 1000000 // 1MHz
     m_SPI_SCLK_Hz = 12000000; // 12MHz; MAX5715 limit is 50MHz
     m_spi.frequency(m_SPI_SCLK_Hz);
 
-    // TODO1: CODE GENERATOR: class constructor definition gpio InputPin (Input to device) initialization
+    //
+    // LDACb Trigger Input to MAX5715 device
+    m_LDACb_pin = 1; // output logic high -- initial value in constructor
+    //
+    // CLRb Trigger Input to MAX5715 device
+    m_CLRb_pin = 1; // output logic high -- initial value in constructor
+    //
+    // REF Reference Input to MAX5715 device
     //
-    m_LDACb_pin = 1; // output logic high -- initial value in constructor
-    m_CLRb_pin = 1; // output logic high -- initial value in constructor
+    // OUTA Analog Output from device
+    //
+    // OUTB Analog Output from device
+    //
+    // OUTC Analog Output from device
+    //
+    // OUTD Analog Output from device
+    //
+    // RDYb DaisyChain Output from device
 }
 
-// CODE GENERATOR: class destructor definition
 MAX5715::~MAX5715()
 {
     // do nothing
 }
 
-// CODE GENERATOR: spi_frequency setter definition
-/// set SPI SCLK frequency
+/// set SPI SCLK frequency
 void MAX5715::spi_frequency(int spi_sclk_Hz)
 {
     m_SPI_SCLK_Hz = spi_sclk_Hz;
     m_spi.frequency(m_SPI_SCLK_Hz);
 }
 
-// CODE GENERATOR: omit global g_MAX5715_device
-// CODE GENERATOR: extern function declarations
-// CODE GENERATOR: extern function requirement MAX5715::SPIoutputCS
 // Assert SPI Chip Select
 // SPI chip-select for MAX5715
 //
 void MAX5715::SPIoutputCS(int isLogicHigh)
 {
-    // CODE GENERATOR: extern function definition for function SPIoutputCS
-    // CODE GENERATOR: extern function definition for standard SPI interface function SPIoutputCS(int isLogicHigh)
     m_SPI_cs_state = isLogicHigh;
     m_cs_pin = m_SPI_cs_state;
 }
 
-// CODE GENERATOR: extern function requirement MAX5715::SPIwrite24bits
 // SPI write 24 bits
 // SPI interface to MAX5715 shift 24 bits mosiData into MAX5715 DIN
 //
 void MAX5715::SPIwrite24bits(int8_t mosiData8_FF0000, int16_t mosiData16_00FFFF)
 {
-    // CODE GENERATOR: extern function definition for function SPIwrite24bits
-    // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIwrite24bits(int8_t mosiData8_FF0000, int16_t mosiData16_00FFFF)
     size_t byteCount = 3;
     static char mosiData[3];
     static char misoData[3];
@@ -224,6 +219,11 @@
     //
     // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
     //~ interrupts();
+    // Optional Diagnostic function to print SPI transactions
+    if (onSPIprint)
+    {
+        onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData);
+    }
     //
     // VERIFY: SPIwrite24bits print diagnostic information
     //cmdLine.serial().printf(" MOSI->"));
@@ -277,38 +277,24 @@
     // return misoData16;
 }
 
-// TODO1: CODE GENERATOR: extern function GPIOoutputLDACb alias LDACboutputValue
-// CODE GENERATOR: extern function requirement MAX5715::LDACboutputValue
 // Assert MAX5715 LDAC pin : High = inactive, Low = load DAC.
 //
 void MAX5715::LDACboutputValue(int isLogicHigh)
 {
-    // CODE GENERATOR: extern function definition for function LDACboutputValue
-    // TODO1: CODE GENERATOR: extern function definition for gpio interface function LDACboutputValue
-    // TODO1: CODE GENERATOR: gpio pin LDACb assuming member function m_LDACb_pin
-    // TODO1: CODE GENERATOR: gpio direction output
     // m_LDACb_pin.output(); // only applicable to DigitalInOut
-    // TODO1: CODE GENERATOR: gpio function Value
     m_LDACb_pin = isLogicHigh;
 }
 
-// TODO1: CODE GENERATOR: extern function GPIOoutputCLRb alias CLRboutputValue
-// CODE GENERATOR: extern function requirement MAX5715::CLRboutputValue
 // Assert MAX5715 CLR pin : High = inactive, Low = clear DAC.
 //
 void MAX5715::CLRboutputValue(int isLogicHigh)
 {
-    // CODE GENERATOR: extern function definition for function CLRboutputValue
-    // TODO1: CODE GENERATOR: extern function definition for gpio interface function CLRboutputValue
-    // TODO1: CODE GENERATOR: gpio pin CLRb assuming member function m_CLRb_pin
-    // TODO1: CODE GENERATOR: gpio direction output
     // m_CLRb_pin.output(); // only applicable to DigitalInOut
-    // TODO1: CODE GENERATOR: gpio function Value
     m_CLRb_pin = isLogicHigh;
 }
 
-// CODE GENERATOR: class member function definitions
 //----------------------------------------
+// Menu item '!'
 // Initialize device
 // @return 1 on success; 0 on failure
 uint8_t MAX5715::Init(void)
@@ -860,9 +846,9 @@
 
 //----------------------------------------
 // CMD_0100_0000_0000_dcba_0000_0000_POWERn_Normal
-// CMD_0100_0001_0000_dcba_0000_0000_POWERn_PD1k
-// CMD_0100_0010_0000_dcba_0000_0000_POWERn_PD100k
-// CMD_0100_0011_0000_dcba_0000_0000_POWERn_PDHiZ
+// CMD_0100_0001_0000_dcba_0000_0000_POWERn_PD1k
+// CMD_0100_0010_0000_dcba_0000_0000_POWERn_PD100k
+// CMD_0100_0011_0000_dcba_0000_0000_POWERn_PDHiZ
 //
 // Sets the power mode of the selected DACs
 // (DACs selected with a 1 in the corresponding DACn bit are updated,
@@ -936,7 +922,7 @@
 // Sets the reference operating mode.
 // REF Power (B18): 0 = Internal reference is only powered if at least one DAC is powered
 // 1 = Internal reference is always powered
-void MAX5715::REF(MAX5715_REF_enum_t ref)
+void MAX5715::REF(MAX5715_REF_enum_t ref)
 {
     
     //----------------------------------------
@@ -944,33 +930,33 @@
     uint8_t command_regAddress = CMD_0111_0110_0000_0000_0000_0000_REF_AlwaysOn_2V048; // diagnostic
     uint16_t regValue = 0; // 0000_0000_0000_0000
     // select command_regAddress from list of 8 values, based on condition
-    if (ref == REF_EXT) {
+    if (ref == REF_EXT) {
         command_regAddress = CMD_0111_0000_0000_0000_0000_0000_REF_EXT;
     }
-    if (ref == REF_2V500) {
+    if (ref == REF_2V500) {
         command_regAddress = CMD_0111_0001_0000_0000_0000_0000_REF_2V500;
         VRef = 2.500;
     }
-    if (ref == REF_2V048) {
+    if (ref == REF_2V048) {
         command_regAddress = CMD_0111_0010_0000_0000_0000_0000_REF_2V048;
         VRef = 2.048;
     }
-    if (ref == REF_4V096) {
+    if (ref == REF_4V096) {
         command_regAddress = CMD_0111_0011_0000_0000_0000_0000_REF_4V096;
         VRef = 4.096;
     }
-    if (ref == REF_AlwaysOn_EXT) {
+    if (ref == REF_AlwaysOn_EXT) {
         command_regAddress = CMD_0111_0100_0000_0000_0000_0000_REF_AlwaysOn_EXT;
     }
-    if (ref == REF_AlwaysOn_2V500) {
+    if (ref == REF_AlwaysOn_2V500) {
         command_regAddress = CMD_0111_0101_0000_0000_0000_0000_REF_AlwaysOn_2V500;
         VRef = 2.500;
     }
-    if (ref == REF_AlwaysOn_2V048) {
+    if (ref == REF_AlwaysOn_2V048) {
         command_regAddress = CMD_0111_0110_0000_0000_0000_0000_REF_AlwaysOn_2V048;
         VRef = 2.048;
     }
-    if (ref == REF_AlwaysOn_4V096) {
+    if (ref == REF_AlwaysOn_4V096) {
         command_regAddress = CMD_0111_0111_0000_0000_0000_0000_REF_AlwaysOn_4V096;
         VRef = 4.096;
     }