Maxim Integrated MAX5171 14-bit Force/Sense DAC
Dependents: MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester
Diff: MAX5171.h
- Revision:
- 1:e73245718b2a
- Parent:
- 0:80a9add62408
- Child:
- 2:d1340b334b0d
--- a/MAX5171.h Fri May 31 21:50:12 2019 +0000 +++ b/MAX5171.h Fri Jun 07 21:53:56 2019 +0000 @@ -1,453 +1,458 @@ -// /******************************************************************************* -// * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. -// * -// * Permission is hereby granted, free of charge, to any person obtaining a -// * copy of this software and associated documentation files (the "Software"), -// * to deal in the Software without restriction, including without limitation -// * the rights to use, copy, modify, merge, publish, distribute, sublicense, -// * and/or sell copies of the Software, and to permit persons to whom the -// * Software is furnished to do so, subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included -// * in all copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES -// * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// * OTHER DEALINGS IN THE SOFTWARE. -// * -// * Except as contained in this notice, the name of Maxim Integrated -// * Products, Inc. shall not be used except as stated in the Maxim Integrated -// * Products, Inc. Branding Policy. -// * -// * The mere transfer of this software does not imply any licenses -// * of trade secrets, proprietary technology, copyrights, patents, -// * trademarks, maskwork rights, or any other form of intellectual -// * property whatsoever. Maxim Integrated Products, Inc. retains all -// * ownership rights. -// ******************************************************************************* -// */ -// ********************************************************************* -// @file MAX5171.h -// ********************************************************************* -// Header file -// DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. -// generated by XMLSystemOfDevicesToMBED.py -// System Name = ExampleSystem -// System Description = Device driver example -// Device Name = MAX5171 -// Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface -// Device Manufacturer = Maxim Integrated -// Device PartNumber = MAX5171AEEE+ -// Device RegValue_Width = DataWidth16bit_HL -// -// DAC NumChannels = 1 -// DAC ResolutionBits = 14 -// -// SPI CS = ActiveLow -// SPI FrameStart = CS -// SPI CPOL = 0 -// SPI CPHA = 0 -// SPI MOSI and MISO Data are both stable on Rising edge of SCLK -// SPI SCLK Idle Low -// SPI SCLKMaxMHz = 10 -// SPI SCLKMinMHz = 0 -// - - -// Prevent multiple declaration -#ifndef __MAX5171_H__ -#define __MAX5171_H__ - -#include "mbed.h" - -// CODE GENERATOR: conditional defines -// CODE GENERATOR: class declaration and docstrings -/** - * @brief MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface - * - * //---------- CODE GENERATOR: testMainCppCodeList - * @code - * // CODE GENERATOR: example code includes - * // example code includes - * #include "mbed.h" - * //#include "max32625.h" - * #include "MAX5171.h" - * - * // optional: serial port - * // note: some platforms such as Nucleo-F446RE do not support the USBSerial library. - * // In those cases, remove the USBDevice lib from the project and rebuild. - * #if defined(TARGET_MAX32625MBED) - * #include "USBSerial.h" - * USBSerial serial; // virtual serial port over USB (DEV connector) - * #elif defined(TARGET_MAX32630MBED) - * #include "USBSerial.h" - * USBSerial serial; // virtual serial port over USB (DEV connector) - * #else - * //#include "USBSerial.h" - * Serial serial(USBTX, USBRX); // tx, rx - * #endif - * - * // example code board support - * //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); - * //DigitalOut rLED(LED1); - * //DigitalOut gLED(LED2); - * //DigitalOut bLED(LED3); - * // - * // Arduino "shield" connector port definitions (MAX32625MBED shown) - * #if defined(TARGET_MAX32625MBED) - * #define A0 AIN_0 - * #define A1 AIN_1 - * #define A2 AIN_2 - * #define A3 AIN_3 - * #define D0 P0_0 - * #define D1 P0_1 - * #define D2 P0_2 - * #define D3 P0_3 - * #define D4 P0_4 - * #define D5 P0_5 - * #define D6 P0_6 - * #define D7 P0_7 - * #define D8 P1_4 - * #define D9 P1_5 - * #define D10 P1_3 - * #define D11 P1_1 - * #define D12 P1_2 - * #define D13 P1_0 - * #endif - * - * // example code declare SPI interface - * #if defined(TARGET_MAX32625MBED) - * SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13 - * DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10 - * #elif defined(TARGET_MAX32600MBED) - * SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 - * DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10 - * #else - * SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 - * DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10 - * #endif - * - * // example code declare GPIO interface pins - * // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device - * DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device - * DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device - * DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device - * DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device - * // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device - * DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device - * // example code declare device instance - * MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC); - * - * // example code main function - * int main() - * { - * while (1) - * { - * // example code: serial port banner message - * #if defined(TARGET_MAX32625MBED) - * serial.printf("MAX32625MBED "); - * #elif defined(TARGET_MAX32600MBED) - * serial.printf("MAX32600MBED "); - * #elif defined(TARGET_NUCLEO_F446RE) - * serial.printf("NUCLEO_F446RE "); - * #endif - * serial.printf("MAX5715BOB\r\n"); - * - * //MAX5171 dac(spi, spi_cs, MAX5171::MAX5171_IC); - * //dac.Init(); - * - * // CODE GENERATOR: example code: member function Init - * g_MAX5171_device.Init(); - * - * // CODE GENERATOR: example code: has no member function REF - * // CODE GENERATOR: example code: member function CODE_LOAD - * // - * uint16_t code = 0xccc; - * g_MAX5171_device.CODE_LOAD(code); - * // - * code = 0x800; - * g_MAX5171_device.CODE_LOAD(code); - * // - * code = 0x666; - * g_MAX5171_device.CODE_LOAD(code); - * // - * code = 0xFFF; - * g_MAX5171_device.CODE_LOAD(code); - * - * // CODE GENERATOR: example code: has no member function CODEallLOADall - * // CODE GENERATOR: example code: has no member function CODEnLOADn - * // CODE GENERATOR: example code: has no member function ScanManual - * // CODE GENERATOR: example code: has no member function ReadAINcode - * wait(3.0); - * } - * } - * @endcode - * //---------- CODE GENERATOR: end testMainCppCodeList - */ -class MAX5171 { -public: -// CODE GENERATOR: TypedefEnum EnumItem declarations -// CODE GENERATOR: TypedefEnum MAX5171_CMD_enum_t - //---------------------------------------- - /// Command Codes (first byte) - /// - /// Naming convention is CMD_bitstream_FUNCTION_NAME - /// - dd_dddd_dddd_dddd = data field - /// - xxxx = don't care - typedef enum MAX5171_CMD_enum_t { - CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 16'b0000000000000000 - CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 16'b0100000000000000 - CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 16'b1000000000000000 - CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 16'b1100000000000000 - CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 16'b1101000000000000 - CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 16'b1110000000000000 - CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 16'b1110100000000000 - CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 16'b1111000000000000 - CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 16'b1111100000000000 - } MAX5171_CMD_enum_t; - -// TODO1: CODE GENERATOR: ic_variant -- IC's supported with this driver - /** - * @brief IC's supported with this driver - * @details MAX5171 - */ - typedef enum - { - MAX5171_IC = 0, - //MAX5171_IC = 1 - } MAX5171_ic_t; - -// TODO1: CODE GENERATOR: class constructor declaration - /**********************************************************//** - * @brief Constructor for MAX5171 Class. - * - * @details Requires an existing SPI object as well as a DigitalOut object. - * The DigitalOut object is used for a chip enable signal - * - * On Entry: - * @param[in] spi - pointer to existing SPI object - * @param[in] cs_pin - pointer to a DigitalOut pin object - * CODE GENERATOR: class constructor docstrings gpio InputPin pins - * @param[in] RS_pin - pointer to a DigitalOut pin object - * @param[in] PDLb_pin - pointer to a DigitalOut pin object - * @param[in] CLRb_pin - pointer to a DigitalOut pin object - * @param[in] SHDN_pin - pointer to a DigitalOut pin object - * CODE GENERATOR: class constructor docstrings gpio OutputPin pins - * @param[in] UPO_pin - pointer to a DigitalIn pin object - * @param[in] ic_variant - which type of MAX5171 is used - * - * On Exit: - * - * @return None - **************************************************************/ - MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface - // CODE GENERATOR: class constructor declaration gpio InputPin pins - // AnalogOut &FB_pin, // Analog Input to MAX5171 device - DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device - DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device - DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device - DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device - // CODE GENERATOR: class constructor declaration gpio OutputPin pins - // AnalogIn &OUT_pin, // Analog Output from MAX5171 device - DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device - MAX5171_ic_t ic_variant); - -// CODE GENERATOR: class destructor declaration - /************************************************************ - * @brief Default destructor for MAX5171 Class. - * - * @details Destroys SPI object if owner - * - * On Entry: - * - * On Exit: - * - * @return None - **************************************************************/ - ~MAX5171(); - - // CODE GENERATOR: spi_frequency setter declaration - // set SPI SCLK frequency - void spi_frequency(int spi_sclk_Hz); - -//---------------------------------------- -// CODE GENERATOR: omit typedef enum MAX5171_device_t, class members instead of global device object -public: - - /// reference voltage, in Volts - double VRef; - - /// shadow of write-only dacCodeLsbs field CMD_00dd_dddd_dddd_dddd_CODE or CMD_01dd_dddd_dddd_dddd_CODE_LOAD - int16_t DACCode; - -// CODE GENERATOR: omit global g_MAX5171_device - -// CODE GENERATOR: extern function declarations -// CODE GENERATOR: extern function declaration SPIoutputCS -//---------------------------------------- -// Assert SPI Chip Select -// SPI chip-select for MAX5171 -// - void SPIoutputCS(int isLogicHigh); - -// CODE GENERATOR: extern function declaration SPIwrite16bits -//---------------------------------------- -// SPI write 16 bits -// SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN -// - void SPIwrite16bits(int16_t mosiData16); - -// CODE GENERATOR: class member data -private: -// CODE GENERATOR: class member data for SPI interface - // SPI object - SPI &m_spi; - int m_SPI_SCLK_Hz; - int m_SPI_dataMode; - int m_SPI_cs_state; - - // Selector pin object - DigitalOut &m_cs_pin; - -// CODE GENERATOR: class member data for gpio InputPin pins -// InputPin Name = FB -// InputPin Description = Feedback Input -// InputPin Function = Analog -// -// InputPin Name = RS -// InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND -// to select 0 reset output value. -// InputPin Function = Configuration - DigitalOut &m_RS_pin; -// -// InputPin Name = PDL# -// InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown. -// InputPin Function = Configuration - DigitalOut &m_PDLb_pin; -// -// InputPin Name = CLR# -// InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS. -// InputPin Function = Configuration - DigitalOut &m_CLRb_pin; -// -// InputPin Name = SHDN -// InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a -// maximum shutdown current 0f 10uA. -// InputPin Function = Configuration - DigitalOut &m_SHDN_pin; -// -// CODE GENERATOR: class member data for gpio OutputPin pins -// OutputPin Name = OUT -// OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD. -// OutputPin Function = Analog - // AnalogIn &m_OUT_pin; -// -// OutputPin Name = UPO -// OutputPin Description = User-Programmable Output. State is set by serial input. -// OutputPin Function = General-Purpose - DigitalIn &m_UPO_pin; -// - - // Identifies which IC variant is being used - MAX5171_ic_t m_ic_variant; - -public: - -// CODE GENERATOR: class member function declarations - //---------------------------------------- - /// Initialize device - /// @return 1 on success; 0 on failure - uint8_t Init(void); - - //---------------------------------------- - /// Return the DAC register value corresponding to physical voltage. - /// Does not perform any offset or gain correction. - /// - /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts - /// @param[in] voltage = physical voltage in Volts - /// @return raw 14-bit MAX5171 code (right justified). - uint16_t DACCodeOfVoltage(double voltageV); - - //---------------------------------------- - /// Return the physical voltage corresponding to DAC register. - /// Does not perform any offset or gain correction. - /// - /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts - /// @param[in] value_u14: raw 14-bit MAX5171 code (right justified). - /// @return physical voltage corresponding to MAX5171 code. - double VoltageOfCode(uint16_t value_u14); - - //---------------------------------------- - /// CMD_00dd_dddd_dddd_dddd_CODE - /// - /// Load input register; DAC registers are unchanged. - /// @return 1 on success; 0 on failure - uint8_t CODE(uint16_t dacCodeLsbs); - - //---------------------------------------- - /// CMD_01dd_dddd_dddd_dddd_CODE_LOAD - /// - /// Load input register; DAC registers are updated (start up DAC with new data). - /// @return 1 on success; 0 on failure - uint8_t CODE_LOAD(uint16_t dacCodeLsbs); - - //---------------------------------------- - /// CMD_10xx_xxxx_xxxx_xxxx_LOAD - /// - /// Update DAC register from input register (start up DAC with data previously - /// stored in the input registers). - /// @return 1 on success; 0 on failure - uint8_t LOAD(void); - - //---------------------------------------- - /// CMD_1100_xxxx_xxxx_xxxx_NOP - /// - /// No operation (NOP). - /// @return 1 on success; 0 on failure - uint8_t NOP(void); - - //---------------------------------------- - /// CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN - /// - /// Shut down DAC (provided PDL# = 1). - /// @return 1 on success; 0 on failure - uint8_t SHUTDOWN(void); - - //---------------------------------------- - /// CMD_1110_0xxx_xxxx_xxxx_UPO_LOW - /// - /// UPO goes low (default). - /// @return 1 on success; 0 on failure - uint8_t UPO_LOW(void); - - //---------------------------------------- - /// CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH - /// - /// UPO goes high. - /// @return 1 on success; 0 on failure - uint8_t UPO_HIGH(void); - - //---------------------------------------- - /// CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE - /// - /// Mode 1, DOUT clocked out on SCLK’s rising edge. - /// @return 1 on success; 0 on failure - uint8_t MODE1_DOUT_SCLK_RISING_EDGE(void); - - //---------------------------------------- - /// CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE - /// - /// Mode 0, DOUT clocked out on SCLK’s falling edge (default). - /// @return 1 on success; 0 on failure - uint8_t MODE0_DOUT_SCLK_FALLING_EDGE(void); - -}; // end of class MAX5171 - -#endif // __MAX5171_H__ - -// End of file +// /******************************************************************************* +// * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. +// * +// * Permission is hereby granted, free of charge, to any person obtaining a +// * copy of this software and associated documentation files (the "Software"), +// * to deal in the Software without restriction, including without limitation +// * the rights to use, copy, modify, merge, publish, distribute, sublicense, +// * and/or sell copies of the Software, and to permit persons to whom the +// * Software is furnished to do so, subject to the following conditions: +// * +// * The above copyright notice and this permission notice shall be included +// * in all copies or substantial portions of the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +// * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// * OTHER DEALINGS IN THE SOFTWARE. +// * +// * Except as contained in this notice, the name of Maxim Integrated +// * Products, Inc. shall not be used except as stated in the Maxim Integrated +// * Products, Inc. Branding Policy. +// * +// * The mere transfer of this software does not imply any licenses +// * of trade secrets, proprietary technology, copyrights, patents, +// * trademarks, maskwork rights, or any other form of intellectual +// * property whatsoever. Maxim Integrated Products, Inc. retains all +// * ownership rights. +// ******************************************************************************* +// */ +// ********************************************************************* +// @file MAX5171.h +// ********************************************************************* +// Header file +// DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. +// generated by XMLSystemOfDevicesToMBED.py +// System Name = ExampleSystem +// System Description = Device driver example +// Device Name = MAX5171 +// Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface +// Device Manufacturer = Maxim Integrated +// Device PartNumber = MAX5171AEEE+ +// Device RegValue_Width = DataWidth16bit_HL +// +// DAC NumChannels = 1 +// DAC ResolutionBits = 14 +// +// SPI CS = ActiveLow +// SPI FrameStart = CS +// SPI CPOL = 0 +// SPI CPHA = 0 +// SPI MOSI and MISO Data are both stable on Rising edge of SCLK +// SPI SCLK Idle Low +// SPI SCLKMaxMHz = 10 +// SPI SCLKMinMHz = 0 +// + + +// Prevent multiple declaration +#ifndef __MAX5171_H__ +#define __MAX5171_H__ + +#include "mbed.h" + +// CODE GENERATOR: conditional defines +// CODE GENERATOR: class declaration and docstrings +/** + * @brief MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface + * + * + * + * Datasheet: https://www.maximintegrated.com/MAX5171 + * + * + * + * //---------- CODE GENERATOR: testMainCppCodeList + * @code + * // CODE GENERATOR: example code includes + * // example code includes + * #include "mbed.h" + * //#include "max32625.h" + * #include "MAX5171.h" + * + * // optional: serial port + * // note: some platforms such as Nucleo-F446RE do not support the USBSerial library. + * // In those cases, remove the USBDevice lib from the project and rebuild. + * #if defined(TARGET_MAX32625MBED) + * #include "USBSerial.h" + * USBSerial serial; // virtual serial port over USB (DEV connector) + * #elif defined(TARGET_MAX32630MBED) + * #include "USBSerial.h" + * USBSerial serial; // virtual serial port over USB (DEV connector) + * #else + * //#include "USBSerial.h" + * Serial serial(USBTX, USBRX); // tx, rx + * #endif + * + * // example code board support + * //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); + * //DigitalOut rLED(LED1); + * //DigitalOut gLED(LED2); + * //DigitalOut bLED(LED3); + * // + * // Arduino "shield" connector port definitions (MAX32625MBED shown) + * #if defined(TARGET_MAX32625MBED) + * #define A0 AIN_0 + * #define A1 AIN_1 + * #define A2 AIN_2 + * #define A3 AIN_3 + * #define D0 P0_0 + * #define D1 P0_1 + * #define D2 P0_2 + * #define D3 P0_3 + * #define D4 P0_4 + * #define D5 P0_5 + * #define D6 P0_6 + * #define D7 P0_7 + * #define D8 P1_4 + * #define D9 P1_5 + * #define D10 P1_3 + * #define D11 P1_1 + * #define D12 P1_2 + * #define D13 P1_0 + * #endif + * + * // example code declare SPI interface + * #if defined(TARGET_MAX32625MBED) + * SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13 + * DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10 + * #elif defined(TARGET_MAX32600MBED) + * SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 + * DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10 + * #else + * SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 + * DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10 + * #endif + * + * // example code declare GPIO interface pins + * // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device + * DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device + * DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device + * DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device + * DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device + * // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device + * DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device + * // example code declare device instance + * MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC); + * + * // example code main function + * int main() + * { + * while (1) + * { + * // example code: serial port banner message + * #if defined(TARGET_MAX32625MBED) + * serial.printf("MAX32625MBED "); + * #elif defined(TARGET_MAX32600MBED) + * serial.printf("MAX32600MBED "); + * #elif defined(TARGET_NUCLEO_F446RE) + * serial.printf("NUCLEO_F446RE "); + * #endif + * serial.printf("MAX5715BOB\r\n"); + * + * //MAX5171 dac(spi, spi_cs, MAX5171::MAX5171_IC); + * //dac.Init(); + * + * // CODE GENERATOR: example code: member function Init + * g_MAX5171_device.Init(); + * + * // CODE GENERATOR: example code: has no member function REF + * // CODE GENERATOR: example code: member function CODE_LOAD + * // + * uint16_t code = 0xccc; + * g_MAX5171_device.CODE_LOAD(code); + * // + * code = 0x800; + * g_MAX5171_device.CODE_LOAD(code); + * // + * code = 0x666; + * g_MAX5171_device.CODE_LOAD(code); + * // + * code = 0xFFF; + * g_MAX5171_device.CODE_LOAD(code); + * + * // CODE GENERATOR: example code: has no member function CODEallLOADall + * // CODE GENERATOR: example code: has no member function CODEnLOADn + * // CODE GENERATOR: example code: has no member function ScanManual + * // CODE GENERATOR: example code: has no member function ReadAINcode + * wait(3.0); + * } + * } + * @endcode + * //---------- CODE GENERATOR: end testMainCppCodeList + */ +class MAX5171 +{ +public: +// CODE GENERATOR: TypedefEnum EnumItem declarations +// CODE GENERATOR: TypedefEnum MAX5171_CMD_enum_t + //---------------------------------------- + /// Command Codes (first byte) + /// + /// Naming convention is CMD_bitstream_FUNCTION_NAME + /// - dd_dddd_dddd_dddd = data field + /// - xxxx = don't care + typedef enum MAX5171_CMD_enum_t { + CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 16'b0000000000000000 + CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 16'b0100000000000000 + CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 16'b1000000000000000 + CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 16'b1100000000000000 + CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 16'b1101000000000000 + CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 16'b1110000000000000 + CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 16'b1110100000000000 + CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 16'b1111000000000000 + CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 16'b1111100000000000 + } MAX5171_CMD_enum_t; + +// TODO1: CODE GENERATOR: ic_variant -- IC's supported with this driver + /** + * @brief IC's supported with this driver + * @details MAX5171 + */ + typedef enum { + MAX5171_IC = 0, + //MAX5171_IC = 1 + } MAX5171_ic_t; +// TODO1: CODE GENERATOR: class constructor declaration + /**********************************************************//** + * @brief Constructor for MAX5171 Class. + * + * @details Requires an existing SPI object as well as a DigitalOut object. + * The DigitalOut object is used for a chip enable signal + * + * On Entry: + * @param[in] spi - pointer to existing SPI object + * @param[in] cs_pin - pointer to a DigitalOut pin object + * CODE GENERATOR: class constructor docstrings gpio InputPin pins + * @param[in] RS_pin - pointer to a DigitalOut pin object + * @param[in] PDLb_pin - pointer to a DigitalOut pin object + * @param[in] CLRb_pin - pointer to a DigitalOut pin object + * @param[in] SHDN_pin - pointer to a DigitalOut pin object + * CODE GENERATOR: class constructor docstrings gpio OutputPin pins + * @param[in] UPO_pin - pointer to a DigitalIn pin object + * @param[in] ic_variant - which type of MAX5171 is used + * + * On Exit: + * + * @return None + **************************************************************/ + MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface + // CODE GENERATOR: class constructor declaration gpio InputPin pins + // AnalogOut &FB_pin, // Analog Input to MAX5171 device + DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device + DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device + DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device + DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device + // CODE GENERATOR: class constructor declaration gpio OutputPin pins + // AnalogIn &OUT_pin, // Analog Output from MAX5171 device + DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device + MAX5171_ic_t ic_variant); + +// CODE GENERATOR: class destructor declaration + /************************************************************ + * @brief Default destructor for MAX5171 Class. + * + * @details Destroys SPI object if owner + * + * On Entry: + * + * On Exit: + * + * @return None + **************************************************************/ + ~MAX5171(); + + // CODE GENERATOR: spi_frequency setter declaration + // set SPI SCLK frequency + void spi_frequency(int spi_sclk_Hz); + +//---------------------------------------- +// CODE GENERATOR: omit typedef enum MAX5171_device_t, class members instead of global device object +public: + + /// reference voltage, in Volts + double VRef; + + /// shadow of write-only dacCodeLsbs field CMD_00dd_dddd_dddd_dddd_CODE or CMD_01dd_dddd_dddd_dddd_CODE_LOAD + int16_t DACCode; + +// CODE GENERATOR: omit global g_MAX5171_device + +// CODE GENERATOR: extern function declarations +// CODE GENERATOR: extern function declaration SPIoutputCS +//---------------------------------------- +// Assert SPI Chip Select +// SPI chip-select for MAX5171 +// + void SPIoutputCS(int isLogicHigh); + +// CODE GENERATOR: extern function declaration SPIwrite16bits +//---------------------------------------- +// SPI write 16 bits +// SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN +// + void SPIwrite16bits(int16_t mosiData16); + +// CODE GENERATOR: class member data +private: +// CODE GENERATOR: class member data for SPI interface + // SPI object + SPI &m_spi; + int m_SPI_SCLK_Hz; + int m_SPI_dataMode; + int m_SPI_cs_state; + + // Selector pin object + DigitalOut &m_cs_pin; + +// CODE GENERATOR: class member data for gpio InputPin pins +// InputPin Name = FB +// InputPin Description = Feedback Input +// InputPin Function = Analog +// +// InputPin Name = RS +// InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND +// to select 0 reset output value. +// InputPin Function = Configuration + DigitalOut &m_RS_pin; +// +// InputPin Name = PDL# +// InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown. +// InputPin Function = Configuration + DigitalOut &m_PDLb_pin; +// +// InputPin Name = CLR# +// InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS. +// InputPin Function = Configuration + DigitalOut &m_CLRb_pin; +// +// InputPin Name = SHDN +// InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a +// maximum shutdown current 0f 10uA. +// InputPin Function = Configuration + DigitalOut &m_SHDN_pin; +// +// CODE GENERATOR: class member data for gpio OutputPin pins +// OutputPin Name = OUT +// OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD. +// OutputPin Function = Analog + // AnalogIn &m_OUT_pin; +// +// OutputPin Name = UPO +// OutputPin Description = User-Programmable Output. State is set by serial input. +// OutputPin Function = General-Purpose + DigitalIn &m_UPO_pin; +// + + // Identifies which IC variant is being used + MAX5171_ic_t m_ic_variant; + +public: + +// CODE GENERATOR: class member function declarations + //---------------------------------------- + /// Initialize device + /// @return 1 on success; 0 on failure + uint8_t Init(void); + + //---------------------------------------- + /// Return the DAC register value corresponding to physical voltage. + /// Does not perform any offset or gain correction. + /// + /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts + /// @param[in] voltage = physical voltage in Volts + /// @return raw 14-bit MAX5171 code (right justified). + uint16_t DACCodeOfVoltage(double voltageV); + + //---------------------------------------- + /// Return the physical voltage corresponding to DAC register. + /// Does not perform any offset or gain correction. + /// + /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts + /// @param[in] value_u14: raw 14-bit MAX5171 code (right justified). + /// @return physical voltage corresponding to MAX5171 code. + double VoltageOfCode(uint16_t value_u14); + + //---------------------------------------- + /// CMD_00dd_dddd_dddd_dddd_CODE + /// + /// Load input register; DAC registers are unchanged. + /// @return 1 on success; 0 on failure + uint8_t CODE(uint16_t dacCodeLsbs); + + //---------------------------------------- + /// CMD_01dd_dddd_dddd_dddd_CODE_LOAD + /// + /// Load input register; DAC registers are updated (start up DAC with new data). + /// @return 1 on success; 0 on failure + uint8_t CODE_LOAD(uint16_t dacCodeLsbs); + + //---------------------------------------- + /// CMD_10xx_xxxx_xxxx_xxxx_LOAD + /// + /// Update DAC register from input register (start up DAC with data previously + /// stored in the input registers). + /// @return 1 on success; 0 on failure + uint8_t LOAD(void); + + //---------------------------------------- + /// CMD_1100_xxxx_xxxx_xxxx_NOP + /// + /// No operation (NOP). + /// @return 1 on success; 0 on failure + uint8_t NOP(void); + + //---------------------------------------- + /// CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN + /// + /// Shut down DAC (provided PDL# = 1). + /// @return 1 on success; 0 on failure + uint8_t SHUTDOWN(void); + + //---------------------------------------- + /// CMD_1110_0xxx_xxxx_xxxx_UPO_LOW + /// + /// UPO goes low (default). + /// @return 1 on success; 0 on failure + uint8_t UPO_LOW(void); + + //---------------------------------------- + /// CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH + /// + /// UPO goes high. + /// @return 1 on success; 0 on failure + uint8_t UPO_HIGH(void); + + //---------------------------------------- + /// CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE + /// + /// Mode 1, DOUT clocked out on SCLK’s rising edge. + /// @return 1 on success; 0 on failure + uint8_t MODE1_DOUT_SCLK_RISING_EDGE(void); + + //---------------------------------------- + /// CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE + /// + /// Mode 0, DOUT clocked out on SCLK’s falling edge (default). + /// @return 1 on success; 0 on failure + uint8_t MODE0_DOUT_SCLK_FALLING_EDGE(void); + +}; // end of class MAX5171 + +#endif // __MAX5171_H__ + +// End of file