Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 USBDevice
Diff: MAX11043/MAX11043.cpp
- Revision:
- 53:3d5a3d241a5e
- Parent:
- 52:607010f0c54e
- Child:
- 57:1c9da8e90737
diff -r 607010f0c54e -r 3d5a3d241a5e MAX11043/MAX11043.cpp --- a/MAX11043/MAX11043.cpp Tue Feb 11 01:16:34 2020 +0000 +++ b/MAX11043/MAX11043.cpp Tue Feb 11 09:01:20 2020 +0000 @@ -1,934 +1,933 @@ -// /******************************************************************************* -// * Copyright (C) 2020 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 MAX11043.cpp -// ********************************************************************* -// Device Driver file -// DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. -// generated by XMLSystemOfDevicesToMBED.py -// System Name = ExampleSystem -// System Description = Device driver example - -#include "MAX11043.h" - -// Device Name = MAX11043 -// Device Description = 200ksps, Low-Power, Serial SPI 24-Bit, 4-Channel, Differential/Single-Ended Input, Simultaneous-Sampling SD ADC -// Device DeviceBriefDescription = 24-bit 200ksps Delta-Sigma ADC -// Device Manufacturer = Maxim Integrated -// Device PartNumber = MAX11043ATL+ -// Device RegValue_Width = DataWidth16bit_HL -// -// ADC MaxOutputDataRate = 200ksps -// ADC NumChannels = 4 -// ADC ResolutionBits = 24 -// -// 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 = 40 -// SPI SCLKMinMHz = 0 -// -// InputPin Name = CONVRUN -// InputPin Description = CONVRUN (digital input). Convert Run. Drive high to start continuous conversions on all 4 channels. The device is idle when -// CONVRUN is low. -// InputPin Function = Configuration -// -// InputPin Name = SHDN -// InputPin Description = Shutdown (digital input). Active-High Shutdown Input. Drive high to shut down the MAX11043. -// InputPin Function = Configuration -// -// InputPin Name = DACSTEP -// InputPin Description = DACSTEP (digital input). DAC Step Input. Drive high to move the DAC output in the direction of UP/DWN on the next rising -// edge of the system clock. -// InputPin Function = Configuration -// -// InputPin Name = UP/DWN# -// InputPin Description = UP/DWN# (digital input). DAC Step Direction Select. Drive high to step up, drive low to step down when DACSTEP is toggled. -// InputPin Function = Configuration -// -// OutputPin Name = EOC -// OutputPin Description = End of Conversion Output. Active-Low End-of-Conversion Indicator. EOC asserts low to indicate that new data is ready. -// OutputPin Function = Event -// - -// CODE GENERATOR: class constructor definition -MAX11043::MAX11043(SPI &spi, DigitalOut &cs_pin, // SPI interface - // CODE GENERATOR: class constructor definition gpio InputPin pins - DigitalOut &CONVRUN_pin, // Digital Configuration Input to MAX11043 device - DigitalOut &SHDN_pin, // Digital Configuration Input to MAX11043 device - DigitalOut &DACSTEP_pin, // Digital Configuration Input to MAX11043 device - DigitalOut &UP_slash_DWNb_pin, // Digital Configuration Input to MAX11043 device - // CODE GENERATOR: class constructor definition gpio OutputPin pins - DigitalIn &EOC_pin, // Digital Event Output from MAX11043 device - // CODE GENERATOR: class constructor definition ic_variant - MAX11043_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_CONVRUN_pin(CONVRUN_pin), // Digital Configuration Input to MAX11043 device - m_SHDN_pin(SHDN_pin), // Digital Configuration Input to MAX11043 device - m_DACSTEP_pin(DACSTEP_pin), // Digital Configuration Input to MAX11043 device - m_UP_slash_DWNb_pin(UP_slash_DWNb_pin), // Digital Configuration Input to MAX11043 device - // CODE GENERATOR: class constructor initializer list gpio OutputPin pins - m_EOC_pin(EOC_pin), // Digital Event Output from MAX11043 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; - m_cs_pin = m_SPI_cs_state; - - // SPI CPOL = 0 - // SPI CPHA = 0 - // SPI MOSI and MISO Data are both stable on Rising edge of SCLK - // SPI SCLK Idle Low - m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low - m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 - - // SPI SCLKMaxMHz = 40 - // SPI SCLKMinMHz = 0 - //#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 4000000 // 4MHz - //#define SPI_SCLK_Hz 2000000 // 2MHz - //#define SPI_SCLK_Hz 1000000 // 1MHz - m_SPI_SCLK_Hz = 12000000; // 12MHz; MAX11043 limit is 40MHz - m_spi.frequency(m_SPI_SCLK_Hz); - - // - // CODE GENERATOR: class constructor definition gpio InputPin (Input to device) initialization - // - // CONVRUN Configuration Input to MAX11043 device - m_CONVRUN_pin = 1; // output logic high -- initial value in constructor - // - // SHDN Configuration Input to MAX11043 device - m_SHDN_pin = 1; // output logic high -- initial value in constructor - // - // DACSTEP Configuration Input to MAX11043 device - m_DACSTEP_pin = 1; // output logic high -- initial value in constructor - // - // UP_slash_DWNb Configuration Input to MAX11043 device - m_UP_slash_DWNb_pin = 1; // output logic high -- initial value in constructor - // - // CODE GENERATOR: class constructor definition gpio OutputPin (Output from MAX11043 device) initialization - // - // EOC Event Output from device -} - -// CODE GENERATOR: class destructor definition -MAX11043::~MAX11043() -{ - // do nothing -} - -// CODE GENERATOR: spi_frequency setter definition -/// set SPI SCLK frequency -void MAX11043::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_MAX11043_device -// CODE GENERATOR: extern function declarations -// CODE GENERATOR: extern function requirement MAX11043::SPIoutputCS -// Assert SPI Chip Select -// SPI chip-select for MAX11043 -// -void MAX11043::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 MAX11043::SPIwrite16bits -// SPI write 16 bits -// SPI interface to MAX11043 shift 16 bits mosiData into MAX11043 DIN -// -void MAX11043::SPIwrite16bits(int16_t mosiData16) -{ - // CODE GENERATOR: extern function definition for function SPIwrite16bits - // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIwrite16bits(int16_t mosiData16) - size_t byteCount = 2; - static char mosiData[2]; - static char misoData[2]; - mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte - mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte - // - // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() - //~ noInterrupts(); - // - //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin - // - unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); - //~ m_spi.transfer(mosiData8_FF0000); - //~ m_spi.transfer(mosiData16_00FF00); - //~ m_spi.transfer(mosiData16_0000FF); - // - //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin - // - // 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->")); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData16_0000FF & 0xFF), HEX); - // hex dump mosiData[0..byteCount-1] -#if 0 // HAS_MICROUSBSERIAL - cmdLine_microUSBserial.serial().printf("\r\nSPI"); - if (byteCount > 7) { - cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); - } - cmdLine_microUSBserial.serial().printf(" MOSI->"); - for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) - { - cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); - } - // hex dump misoData[0..byteCount-1] - cmdLine_microUSBserial.serial().printf(" MISO<-"); - for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) - { - cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); - } - cmdLine_microUSBserial.serial().printf(" "); -#endif -#if 0 // HAS_DAPLINK_SERIAL - cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); - if (byteCount > 7) { - cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); - } - cmdLine_DAPLINKserial.serial().printf(" MOSI->"); - for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) - { - cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); - } - // hex dump misoData[0..byteCount-1] - cmdLine_DAPLINKserial.serial().printf(" MISO<-"); - for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) - { - cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); - } - cmdLine_DAPLINKserial.serial().printf(" "); -#endif - // VERIFY: DIAGNOSTIC: print MAX5715 device register write - // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); - // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); - // - // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; - // return misoData16; -} - -// CODE GENERATOR: extern function requirement MAX11043::SPIreadWrite16bits -// SPI read and write 16 bits -// SPI interface to MAX11043 shift 16 bits mosiData16 into MAX11043 DIN -// while simultaneously capturing 16 bits miso data from MAX11043 DOUT -// -int16_t MAX11043::SPIreadWrite16bits(int16_t mosiData16) -{ - // CODE GENERATOR: extern function definition for function SPIreadWrite16bits - // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite16bits(int16_t mosiData16) - size_t byteCount = 2; - static char mosiData[2]; - static char misoData[2]; - mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte - mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte - // - // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() - //~ noInterrupts(); - // - //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin - // - unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); - //~ m_spi.transfer(mosiData8_FF0000); - //~ m_spi.transfer(mosiData16_00FF00); - //~ m_spi.transfer(mosiData16_0000FF); - // - //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin - // - // 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->")); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData16_0000FF & 0xFF), HEX); - // hex dump mosiData[0..byteCount-1] -#if 0 // HAS_MICROUSBSERIAL - cmdLine_microUSBserial.serial().printf("\r\nSPI"); - if (byteCount > 7) { - cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); - } - cmdLine_microUSBserial.serial().printf(" MOSI->"); - for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) - { - cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); - } - // hex dump misoData[0..byteCount-1] - cmdLine_microUSBserial.serial().printf(" MISO<-"); - for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) - { - cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); - } - cmdLine_microUSBserial.serial().printf(" "); -#endif -#if 0 // HAS_DAPLINK_SERIAL - cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); - if (byteCount > 7) { - cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); - } - cmdLine_DAPLINKserial.serial().printf(" MOSI->"); - for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) - { - cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); - } - // hex dump misoData[0..byteCount-1] - cmdLine_DAPLINKserial.serial().printf(" MISO<-"); - for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) - { - cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); - } - cmdLine_DAPLINKserial.serial().printf(" "); -#endif - // VERIFY: DIAGNOSTIC: print MAX5715 device register write - // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); - // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); - // - //int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; - int misoData16 = (misoData[0] << 8) | misoData[1]; - return misoData16; -} - -// CODE GENERATOR: extern function requirement MAX11043::SPIreadWrite32bits -// SPI read and write 32 bits -// SPI interface to MAX11043 shift 32 bits mosiData into MAX11043 DIN -// while simultaneously capturing 32 bits miso data from MAX11043 DOUT -// -int32_t MAX11043::SPIreadWrite32bits(int32_t mosiData32) -{ - // CODE GENERATOR: extern function definition for function SPIreadWrite32bits - // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite32bits(int32_t mosiData32) - size_t byteCount = 4; - static char mosiData[4]; - static char misoData[4]; - mosiData[0] = (char)((mosiData32 >> 24) & 0xFF); // MSByte - mosiData[1] = (char)((mosiData32 >> 16) & 0xFF); - mosiData[2] = (char)((mosiData32 >> 8) & 0xFF); - mosiData[3] = (char)((mosiData32 >> 0) & 0xFF); // LSByte - // - // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() - //~ noInterrupts(); - // - //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin - // - unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); - //~ m_spi.transfer(mosiData8_FF0000); - //~ m_spi.transfer(mosiData16_00FF00); - //~ m_spi.transfer(mosiData16_0000FF); - // - //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin - // - // 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->")); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); - //cmdLine.serial().printf(" 0x")); - //Serial.print( (mosiData16_0000FF & 0xFF), HEX); - // hex dump mosiData[0..byteCount-1] -#if 0 // HAS_MICROUSBSERIAL - cmdLine_microUSBserial.serial().printf("\r\nSPI"); - if (byteCount > 7) { - cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); - } - cmdLine_microUSBserial.serial().printf(" MOSI->"); - for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) - { - cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); - } - // hex dump misoData[0..byteCount-1] - cmdLine_microUSBserial.serial().printf(" MISO<-"); - for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) - { - cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); - } - cmdLine_microUSBserial.serial().printf(" "); -#endif -#if 0 // HAS_DAPLINK_SERIAL - cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); - if (byteCount > 7) { - cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); - } - cmdLine_DAPLINKserial.serial().printf(" MOSI->"); - for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) - { - cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); - } - // hex dump misoData[0..byteCount-1] - cmdLine_DAPLINKserial.serial().printf(" MISO<-"); - for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) - { - cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); - } - cmdLine_DAPLINKserial.serial().printf(" "); -#endif - // VERIFY: DIAGNOSTIC: print MAX5715 device register write - // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); - // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); - // - //int misoData32 = (misoData32_FF000000 << 24) | (misoData32_FF0000 << 16) | (misoData32_0000FF00 << 8) | misoData32_000000FF; - int misoData32 = (misoData[0] << 24) | (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; - return misoData32; -} - -// TODO1: CODE GENERATOR: extern function GPIOoutputSHDN alias SHDNoutputValue -// CODE GENERATOR: extern function requirement MAX11043::SHDNoutputValue -// Assert MAX11043 SHDN pin : High = _____, Low = _____. -// -void MAX11043::SHDNoutputValue(int isLogicHigh) -{ - // CODE GENERATOR: extern function definition for function SHDNoutputValue - // TODO1: CODE GENERATOR: extern function definition for gpio interface function SHDNoutputValue - // TODO1: CODE GENERATOR: gpio pin SHDN assuming member function m_SHDN_pin - // TODO1: CODE GENERATOR: gpio direction output - // m_SHDN_pin.output(); // only applicable to DigitalInOut - // TODO1: CODE GENERATOR: gpio function Value - m_SHDN_pin = isLogicHigh; -} - -// TODO1: CODE GENERATOR: extern function GPIOoutputCONVRUN alias CONVRUNoutputValue -// CODE GENERATOR: extern function requirement MAX11043::CONVRUNoutputValue -// Assert MAX11043 CONVRUN pin : High = _____, Low = _____. -// -void MAX11043::CONVRUNoutputValue(int isLogicHigh) -{ - // CODE GENERATOR: extern function definition for function CONVRUNoutputValue - // TODO1: CODE GENERATOR: extern function definition for gpio interface function CONVRUNoutputValue - // TODO1: CODE GENERATOR: gpio pin CONVRUN assuming member function m_CONVRUN_pin - // TODO1: CODE GENERATOR: gpio direction output - // m_CONVRUN_pin.output(); // only applicable to DigitalInOut - // TODO1: CODE GENERATOR: gpio function Value - m_CONVRUN_pin = isLogicHigh; -} - -// TODO1: CODE GENERATOR: extern function GPIOoutputDACSTEP alias DACSTEPoutputValue -// CODE GENERATOR: extern function requirement MAX11043::DACSTEPoutputValue -// Assert MAX11043 DACSTEP pin : High = _____, Low = _____. -// -void MAX11043::DACSTEPoutputValue(int isLogicHigh) -{ - // CODE GENERATOR: extern function definition for function DACSTEPoutputValue - // TODO1: CODE GENERATOR: extern function definition for gpio interface function DACSTEPoutputValue - // TODO1: CODE GENERATOR: gpio pin DACSTEP assuming member function m_DACSTEP_pin - // TODO1: CODE GENERATOR: gpio direction output - // m_DACSTEP_pin.output(); // only applicable to DigitalInOut - // TODO1: CODE GENERATOR: gpio function Value - m_DACSTEP_pin = isLogicHigh; -} - -// TODO1: CODE GENERATOR: extern function GPIOoutputUP_slash_DWNb alias UP_slash_DWNboutputValue -// CODE GENERATOR: extern function requirement MAX11043::UP_slash_DWNboutputValue -// Assert MAX11043 UP_slash_DWNb pin : High = _____, Low = _____. -// -void MAX11043::UP_slash_DWNboutputValue(int isLogicHigh) -{ - // CODE GENERATOR: extern function definition for function UP_slash_DWNboutputValue - // TODO1: CODE GENERATOR: extern function definition for gpio interface function UP_slash_DWNboutputValue - // TODO1: CODE GENERATOR: gpio pin UP_slash_DWNb assuming member function m_UP_slash_DWNb_pin - // TODO1: CODE GENERATOR: gpio direction output - // m_UP_slash_DWNb_pin.output(); // only applicable to DigitalInOut - // TODO1: CODE GENERATOR: gpio function Value - m_UP_slash_DWNb_pin = isLogicHigh; -} - -// CODE GENERATOR: extern function requirement MAX11043::EOCinputWaitUntilLow -// Wait for MAX11043 EOC pin low, indicating end of conversion. -// Required when using any of the InternalClock modes. -// -void MAX11043::EOCinputWaitUntilLow() -{ - // CODE GENERATOR: extern function definition for function EOCinputWaitUntilLow - // TODO1: CODE GENERATOR: extern function definition for gpio interface function EOCinputWaitUntilLow - // TODO1: CODE GENERATOR: gpio pin EOC assuming member function m_EOC_pin - // TODO1: CODE GENERATOR: gpio direction input - // m_EOC_pin.input(); // only applicable to DigitalInOut - // TODO1: CODE GENERATOR: gpio function WaitUntilLow - while (m_EOC_pin != 0) - { - // spinlock waiting for logic low pin state - } -} - -// CODE GENERATOR: extern function requirement MAX11043::EOCinputValue -// Return the status of the MAX11043 EOC pin. -// -int MAX11043::EOCinputValue() -{ - // CODE GENERATOR: extern function definition for function EOCinputValue - // TODO1: CODE GENERATOR: extern function definition for gpio interface function EOCinputValue - // TODO1: CODE GENERATOR: gpio pin EOC assuming member function m_EOC_pin - // TODO1: CODE GENERATOR: gpio direction input - // m_EOC_pin.input(); // only applicable to DigitalInOut - // TODO1: CODE GENERATOR: gpio function Value - return m_EOC_pin.read(); -} - -// CODE GENERATOR: class member function definitions -//---------------------------------------- -// Menu item '!' -// Initialize device -// @return 1 on success; 0 on failure -uint8_t MAX11043::Init(void) -{ - - //---------------------------------------- - // TODO1: AC79 MAX11043 AIN0-AIN1 reference voltage, in Volts - VRef_xxxxxx = 2.500; - - //---------------------------------------- - // shadow of register ctrl CMD_r000_1001_dddd_dddd_CTRL - ctrl = 0x01; - - //---------------------------------------- - // set by Configure_PGA gain index register pga CMD_r000_1110_xxdd_xddd_PGA - pgaGain = 1; - - //---------------------------------------- - // init (based on old EV kit GUI) - #warning "Not Implemented Yet: MAX11043::Init init..." - // bool bOpResult = false; - // String FWVersionString = "00"; - // bool bDemoMode = true; - // int scan_resolution = 0; - // int scan_channels = 0; - // int scan_bits = 0; - // int sampleRateFactore = 0; - // double sampleRate = 0; - // unsigned long banks_requested = 0; - // bool bScanMode = 0; - - //---------------------------------------- - // Device ID Validation - #warning "Not Implemented Yet: MAX11043::Init Device ID Validation..." - // const uint32_t part_id_expect = 0x000F02; - // uint32_t part_id_readback; - // RegRead(xxxxxxxxxxxxCMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback); - // if (part_id_readback != part_id_expect) return 0; - - //---------------------------------------- - // write8 0x00 PD = 0x03 (Reset Registers; enter Standby mode) - // RegWrite(xxxxxxxxxxxCMD_r000_0000_xxxx_xxdd_PD, PD_11_Reset); - - //---------------------------------------- - // write8 0x00 PD = 0x00 (NOP) - // RegWrite(xxxxxxxxxxxxCMD_r000_0000_xxxx_xxdd_PD, PD_00_Normal); - - //---------------------------------------- - // success - return 1; -} - -//---------------------------------------- -// Write a MAX11043 register. -// -// CMD_1aaa_aaaa_REGISTER_READ bit is cleared 0 indicating a write operation. -// -// MAX11043 register length can be determined by function RegSize. -// -// For 8-bit register size: -// -// SPI 16-bit transfer -// -// SPI MOSI = 0aaa_aaaa_dddd_dddd -// -// SPI MISO = xxxx_xxxx_xxxx_xxxx -// -// For 16-bit register size: -// -// SPI 24-bit or 32-bit transfer -// -// SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd -// -// SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx -// -// For 24-bit register size: -// -// SPI 32-bit transfer -// -// SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd -// -// SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx -// -// @return 1 on success; 0 on failure -uint8_t MAX11043::RegWrite(MAX11043_CMD_enum_t commandByte, uint32_t regData) -{ - - //---------------------------------------- - // switch based on register address szie RegSize(commandByte) - //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); - switch(RegSize(commandByte)) - { - case 8: // 8-bit register size - { - // SPI 16-bit transfer - // SPI MOSI = 0aaa_aaaa_dddd_dddd - // SPI MISO = xxxx_xxxx_xxxx_xxxx - int16_t mosiData16 = ((int16_t)commandByte << 8) | ((int16_t)regData & 0xFF); - SPIoutputCS(0); - SPIwrite16bits(mosiData16); - SPIoutputCS(1); - } - break; - case 16: // 16-bit register size - #warning "Not Verified Yet: MAX11043::RegWrite 16-bit SPIreadWrite32bits" - { - // SPI 24-bit or 32-bit transfer - // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd - // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx - // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_0000_0000 - // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx - int32_t mosiData32 = ((int32_t)commandByte << 24) | (((int32_t)regData & 0xFFFF) << 8); - SPIoutputCS(0); - SPIreadWrite32bits(mosiData32); - SPIoutputCS(1); - } - break; - case 24: // 24-bit register size - { - // SPI 32-bit transfer - // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd - // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx - int32_t mosiData32 = ((int32_t)commandByte << 24) | ((int32_t)regData & 0x00FFFFFF); - SPIoutputCS(0); - SPIreadWrite32bits(mosiData32); - SPIoutputCS(1); - } - break; - } - - //---------------------------------------- - // success - return 1; -} - -//---------------------------------------- -// Read an 8-bit MAX11043 register -// -// CMD_1aaa_aaaa_REGISTER_READ bit is set 1 indicating a read operation. -// -// MAX11043 register length can be determined by function RegSize. -// -// For 8-bit register size: -// -// SPI 16-bit transfer -// -// SPI MOSI = 1aaa_aaaa_0000_0000 -// -// SPI MISO = xxxx_xxxx_dddd_dddd -// -// For 16-bit register size: -// -// SPI 24-bit or 32-bit transfer -// -// SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 -// -// SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd -// -// For 24-bit register size: -// -// SPI 32-bit transfer -// -// SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 -// -// SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd -// -// -// @return 1 on success; 0 on failure -uint8_t MAX11043::RegRead(MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) -{ - - //---------------------------------------- - // switch based on register address szie RegSize(regAddress) - //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); - switch(RegSize(commandByte)) - { - case 8: // 8-bit register size - { - // SPI 16-bit transfer - // SPI MOSI = 1aaa_aaaa_0000_0000 - // SPI MISO = xxxx_xxxx_dddd_dddd - int16_t mosiData16 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int16_t)commandByte) << 8) | ((int16_t)0); - SPIoutputCS(0); - int16_t misoData16 = SPIreadWrite16bits(mosiData16); - SPIoutputCS(1); - (*ptrRegData) = (misoData16 & 0x00FF); - } - break; - case 16: // 16-bit register size - #warning "Not Verified Yet: MAX11043::RegRead 16-bit SPIreadWrite32bits" - { - // SPI 24-bit or 32-bit transfer - // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 - // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd - // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 - // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_xxxx_xxxx - int32_t mosiData32 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int32_t)commandByte) << 24); - SPIoutputCS(0); - int32_t misoData32 = SPIreadWrite32bits(mosiData32); - SPIoutputCS(1); - (*ptrRegData) = ((misoData32 >> 8) & 0x00FFFF); - } - break; - case 24: // 24-bit register size - { - // SPI 32-bit transfer - // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 - // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd - int32_t mosiData32 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int32_t)commandByte) << 24); - SPIoutputCS(0); - int32_t misoData32 = SPIreadWrite32bits(mosiData32); - SPIoutputCS(1); - (*ptrRegData) = (misoData32 & 0x00FFFFFF); - } - break; - } - - //---------------------------------------- - // success - return 1; -} - -//---------------------------------------- -// Return the size of a MAX11043 register -// -// @return 8 for 8-bit, 16 for 16-bit, 24 for 24-bit, else 0 for undefined register size -uint8_t MAX11043::RegSize(MAX11043_CMD_enum_t commandByte) -{ - - //---------------------------------------- - // switch based on register address value regAddress - // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); - switch(commandByte) - { - default: - case CMD_0aaa_aa00_WrAddr_WriteAnyRegister: - case CMD_0aaa_aa10_RdAddr_ReadAnyRegister: - case CMD_1111_1111_NoOperationMOSIidleHigh: - return 0; // undefined register size - case CMD_0001_1110_d8_Rd07_Status: - case CMD_0101_0100_d8_Wr15_FilterCAddress: - case CMD_0101_0110_d8_Rd15_FilterCAddress: - case CMD_0110_0000_d8_Wr18_FlashMode: - case CMD_0110_0010_d8_Rd18_FlashMode: - return 8; // 8-bit register size - case CMD_0010_0000_d16_Wr08_Configuration: - case CMD_0010_0010_d16_Rd08_Configuration: - case CMD_0010_0100_d16_Wr09_DAC: - case CMD_0010_0110_d16_Rd09_DAC: - case CMD_0010_1000_d16_Wr0A_DACStep: - case CMD_0010_1010_d16_Rd0A_DACStep: - case CMD_0010_1100_d16_Wr0B_DACHDACL: - case CMD_0010_1110_d16_Rd0B_DACHDACL: - case CMD_0011_0000_d16_Wr0C_ConfigA: - case CMD_0011_0010_d16_Rd0C_ConfigA: - case CMD_0011_0100_d16_Wr0D_ConfigB: - case CMD_0011_0110_d16_Rd0D_ConfigB: - case CMD_0011_1000_d16_Wr0E_ConfigC: - case CMD_0011_1010_d16_Rd0E_ConfigC: - case CMD_0011_1100_d16_Wr0F_ConfigD: - case CMD_0011_1110_d16_Rd0F_ConfigD: - case CMD_0100_0000_d16_Wr10_Reference: - case CMD_0100_0010_d16_Rd10_Reference: - case CMD_0100_0100_d16_Wr11_AGain: - case CMD_0100_0110_d16_Rd11_AGain: - case CMD_0100_1000_d16_Wr12_BGain: - case CMD_0100_1010_d16_Rd12_BGain: - case CMD_0100_1100_d16_Wr13_CGain: - case CMD_0100_1110_d16_Rd13_CGain: - case CMD_0101_0000_d16_Wr14_DGain: - case CMD_0101_0010_d16_Rd14_DGain: - case CMD_0110_0100_d16_Wr19_FlashAddr: - case CMD_0110_0110_d16_Rd19_FlashAddr: - case CMD_0110_1000_d16_Wr1A_FlashDataIn: - case CMD_0110_1010_d16_Rd1A_FlashDataIn: - case CMD_0110_1110_d16_Rd1B_FlashDataOut: - return 16; // 16-bit register size - case CMD_0000_0010_d24_Rd00_ADCa: - case CMD_0000_0110_d24_Rd01_ADCb: - case CMD_0000_1010_d24_Rd02_ADCc: - case CMD_0000_1110_d24_Rd03_ADCd: - return 24; // 24-bit register size - case CMD_0001_0010_d24_d24_Rd04_ADCab: - case CMD_0001_0110_d24_d24_Rd05_ADCcd: - return 48; // 24-bit register size - case CMD_0001_1010_d24_d24_d24_d24_Rd06_ADCabcd: - return 96; // 24-bit register size - case CMD_0101_1000_d32_Wr16_FilterCDataOut: - case CMD_0101_1010_d32_Rd16_FilterCDataOut: - case CMD_0101_1100_d32_Wr17_FilterCDataIn: - case CMD_0101_1110_d32_Rd17_FilterCDataIn: - return 32; // 32-bit register size - } -} - -//---------------------------------------- -// Return the address field of a MAX11043 register -// -// @return register address field as given in datasheet -uint8_t MAX11043::RegAddrOfCommand(MAX11043_CMD_enum_t commandByte) -{ - - //---------------------------------------- - // extract register address value from command byte - return (uint8_t)((commandByte &~ 0x83) >> 2); // CMD_0aaa_aa10_RdAddr_ReadAnyRegister -} - -//---------------------------------------- -// Test whether a command byte is a register read command -// -// @return true if command byte is a register read command -uint8_t MAX11043::IsRegReadCommand(MAX11043_CMD_enum_t commandByte) -{ - - //---------------------------------------- - // Test whether a command byte is a register read command - return (commandByte &~ 0x02) ? 1 : 0; // CMD_0aaa_aa10_RdAddr_ReadAnyRegister -} - -//---------------------------------------- -// Return the name of a MAX11043 register -// -// @return null-terminated constant C string containing register name or empty string -const char* MAX11043::RegName(MAX11043_CMD_enum_t commandByte) -{ - - //---------------------------------------- - // switch based on register address value regAddress - // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); - switch(commandByte) - { - default: - return ""; // undefined register - // case CMD_0aaa_aa00_WrAddr_WriteAnyRegister: return "_______"; - // case CMD_0aaa_aa10_RdAddr_ReadAnyRegister: return "_______"; - // case CMD_1111_1111_NoOperationMOSIidleHigh: return "_______"; - case CMD_0000_0010_d24_Rd00_ADCa: return "ADCa"; - case CMD_0000_0110_d24_Rd01_ADCb: return "ADCb"; - case CMD_0000_1010_d24_Rd02_ADCc: return "ADCc"; - case CMD_0000_1110_d24_Rd03_ADCd: return "ADCd"; - case CMD_0001_0010_d24_d24_Rd04_ADCab: return "ADCab"; - case CMD_0001_0110_d24_d24_Rd05_ADCcd: return "ADCcd"; - case CMD_0001_1010_d24_d24_d24_d24_Rd06_ADCabcd: return "ADCabcd"; - case CMD_0001_1110_d8_Rd07_Status: return "Status"; - case CMD_0010_0000_d16_Wr08_Configuration: return "Configuration"; - case CMD_0010_0010_d16_Rd08_Configuration: return "Configuration"; - case CMD_0010_0100_d16_Wr09_DAC: return "DAC"; - case CMD_0010_0110_d16_Rd09_DAC: return "DAC"; - case CMD_0010_1000_d16_Wr0A_DACStep: return "DACStep"; - case CMD_0010_1010_d16_Rd0A_DACStep: return "DACStep"; - case CMD_0010_1100_d16_Wr0B_DACHDACL: return "DACHDACL"; - case CMD_0010_1110_d16_Rd0B_DACHDACL: return "DACHDACL"; - case CMD_0011_0000_d16_Wr0C_ConfigA: return "ConfigA"; - case CMD_0011_0010_d16_Rd0C_ConfigA: return "ConfigA"; - case CMD_0011_0100_d16_Wr0D_ConfigB: return "ConfigB"; - case CMD_0011_0110_d16_Rd0D_ConfigB: return "ConfigB"; - case CMD_0011_1000_d16_Wr0E_ConfigC: return "ConfigC"; - case CMD_0011_1010_d16_Rd0E_ConfigC: return "ConfigC"; - case CMD_0011_1100_d16_Wr0F_ConfigD: return "ConfigD"; - case CMD_0011_1110_d16_Rd0F_ConfigD: return "ConfigD"; - case CMD_0100_0000_d16_Wr10_Reference: return "Reference"; - case CMD_0100_0010_d16_Rd10_Reference: return "Reference"; - case CMD_0100_0100_d16_Wr11_AGain: return "AGain"; - case CMD_0100_0110_d16_Rd11_AGain: return "AGain"; - case CMD_0100_1000_d16_Wr12_BGain: return "BGain"; - case CMD_0100_1010_d16_Rd12_BGain: return "BGain"; - case CMD_0100_1100_d16_Wr13_CGain: return "CGain"; - case CMD_0100_1110_d16_Rd13_CGain: return "CGain"; - case CMD_0101_0000_d16_Wr14_DGain: return "DGain"; - case CMD_0101_0010_d16_Rd14_DGain: return "DGain"; - case CMD_0101_0100_d8_Wr15_FilterCAddress: return "FilterCAddress"; - case CMD_0101_0110_d8_Rd15_FilterCAddress: return "FilterCAddress"; - case CMD_0101_1000_d32_Wr16_FilterCDataOut: return "FilterCDataOut"; - case CMD_0101_1010_d32_Rd16_FilterCDataOut: return "FilterCDataOut"; - case CMD_0101_1100_d32_Wr17_FilterCDataIn: return "FilterCDataIn"; - case CMD_0101_1110_d32_Rd17_FilterCDataIn: return "FilterCDataIn"; - case CMD_0110_0000_d8_Wr18_FlashMode: return "FlashMode"; - case CMD_0110_0010_d8_Rd18_FlashMode: return "FlashMode"; - case CMD_0110_0100_d16_Wr19_FlashAddr: return "FlashAddr"; - case CMD_0110_0110_d16_Rd19_FlashAddr: return "FlashAddr"; - case CMD_0110_1000_d16_Wr1A_FlashDataIn: return "FlashDataIn"; - case CMD_0110_1010_d16_Rd1A_FlashDataIn: return "FlashDataIn"; - case CMD_0110_1110_d16_Rd1B_FlashDataOut: return "FlashDataOut"; - } -} - - -// End of file +// /******************************************************************************* +// * Copyright (C) 2020 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 MAX11043.cpp +// ********************************************************************* +// Device Driver file +// DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. +// generated by XMLSystemOfDevicesToMBED.py +// System Name = ExampleSystem +// System Description = Device driver example + +#include "MAX11043.h" + +// Device Name = MAX11043 +// Device Description = 200ksps, Low-Power, Serial SPI 24-Bit, 4-Channel, Differential/Single-Ended Input, Simultaneous-Sampling SD ADC +// Device DeviceBriefDescription = 24-bit 200ksps Delta-Sigma ADC +// Device Manufacturer = Maxim Integrated +// Device PartNumber = MAX11043ATL+ +// Device RegValue_Width = DataWidth16bit_HL +// +// ADC MaxOutputDataRate = 200ksps +// ADC NumChannels = 4 +// ADC ResolutionBits = 24 +// +// 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 = 40 +// SPI SCLKMinMHz = 0 +// +// InputPin Name = CONVRUN +// InputPin Description = CONVRUN (digital input). Convert Run. Drive high to start continuous conversions on all 4 channels. The device is idle when +// CONVRUN is low. +// InputPin Function = Configuration +// +// InputPin Name = SHDN +// InputPin Description = Shutdown (digital input). Active-High Shutdown Input. Drive high to shut down the MAX11043. +// InputPin Function = Configuration +// +// InputPin Name = DACSTEP +// InputPin Description = DACSTEP (digital input). DAC Step Input. Drive high to move the DAC output in the direction of UP/DWN on the next rising +// edge of the system clock. +// InputPin Function = Configuration +// +// InputPin Name = UP/DWN# +// InputPin Description = UP/DWN# (digital input). DAC Step Direction Select. Drive high to step up, drive low to step down when DACSTEP is toggled. +// InputPin Function = Configuration +// +// OutputPin Name = EOC +// OutputPin Description = End of Conversion Output. Active-Low End-of-Conversion Indicator. EOC asserts low to indicate that new data is ready. +// OutputPin Function = Event +// + +// CODE GENERATOR: class constructor definition +MAX11043::MAX11043(SPI &spi, DigitalOut &cs_pin, // SPI interface + // CODE GENERATOR: class constructor definition gpio InputPin pins + DigitalOut &CONVRUN_pin, // Digital Configuration Input to MAX11043 device + DigitalOut &SHDN_pin, // Digital Configuration Input to MAX11043 device + DigitalOut &DACSTEP_pin, // Digital Configuration Input to MAX11043 device + DigitalOut &UP_slash_DWNb_pin, // Digital Configuration Input to MAX11043 device + // CODE GENERATOR: class constructor definition gpio OutputPin pins + DigitalIn &EOC_pin, // Digital Event Output from MAX11043 device + // CODE GENERATOR: class constructor definition ic_variant + MAX11043_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_CONVRUN_pin(CONVRUN_pin), // Digital Configuration Input to MAX11043 device + m_SHDN_pin(SHDN_pin), // Digital Configuration Input to MAX11043 device + m_DACSTEP_pin(DACSTEP_pin), // Digital Configuration Input to MAX11043 device + m_UP_slash_DWNb_pin(UP_slash_DWNb_pin), // Digital Configuration Input to MAX11043 device + // CODE GENERATOR: class constructor initializer list gpio OutputPin pins + m_EOC_pin(EOC_pin), // Digital Event Output from MAX11043 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; + m_cs_pin = m_SPI_cs_state; + + // SPI CPOL = 0 + // SPI CPHA = 0 + // SPI MOSI and MISO Data are both stable on Rising edge of SCLK + // SPI SCLK Idle Low + m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low + m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 + + // SPI SCLKMaxMHz = 40 + // SPI SCLKMinMHz = 0 + //#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 4000000 // 4MHz + //#define SPI_SCLK_Hz 2000000 // 2MHz + //#define SPI_SCLK_Hz 1000000 // 1MHz + m_SPI_SCLK_Hz = 12000000; // 12MHz; MAX11043 limit is 40MHz + m_spi.frequency(m_SPI_SCLK_Hz); + + // + // CODE GENERATOR: class constructor definition gpio InputPin (Input to device) initialization + // + // CONVRUN Configuration Input to MAX11043 device + m_CONVRUN_pin = 1; // output logic high -- initial value in constructor + // + // SHDN Configuration Input to MAX11043 device + m_SHDN_pin = 1; // output logic high -- initial value in constructor + // + // DACSTEP Configuration Input to MAX11043 device + m_DACSTEP_pin = 1; // output logic high -- initial value in constructor + // + // UP_slash_DWNb Configuration Input to MAX11043 device + m_UP_slash_DWNb_pin = 1; // output logic high -- initial value in constructor + // + // CODE GENERATOR: class constructor definition gpio OutputPin (Output from MAX11043 device) initialization + // + // EOC Event Output from device +} + +// CODE GENERATOR: class destructor definition +MAX11043::~MAX11043() +{ + // do nothing +} + +// CODE GENERATOR: spi_frequency setter definition +/// set SPI SCLK frequency +void MAX11043::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_MAX11043_device +// CODE GENERATOR: extern function declarations +// CODE GENERATOR: extern function requirement MAX11043::SPIoutputCS +// Assert SPI Chip Select +// SPI chip-select for MAX11043 +// +void MAX11043::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 MAX11043::SPIwrite16bits +// SPI write 16 bits +// SPI interface to MAX11043 shift 16 bits mosiData into MAX11043 DIN +// +void MAX11043::SPIwrite16bits(int16_t mosiData16) +{ + // CODE GENERATOR: extern function definition for function SPIwrite16bits + // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIwrite16bits(int16_t mosiData16) + size_t byteCount = 2; + static char mosiData[2]; + static char misoData[2]; + mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte + mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ noInterrupts(); + // + //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin + // + unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); + //~ m_spi.transfer(mosiData8_FF0000); + //~ m_spi.transfer(mosiData16_00FF00); + //~ m_spi.transfer(mosiData16_0000FF); + // + //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin + // + // 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->")); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_0000FF & 0xFF), HEX); + // hex dump mosiData[0..byteCount-1] +#if 0 // HAS_MICROUSBSERIAL + cmdLine_microUSBserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_microUSBserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_microUSBserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_microUSBserial.serial().printf(" "); +#endif +#if 0 // HAS_DAPLINK_SERIAL + cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_DAPLINKserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_DAPLINKserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_DAPLINKserial.serial().printf(" "); +#endif + // VERIFY: DIAGNOSTIC: print MAX5715 device register write + // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); + // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); + // + // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; + // return misoData16; +} + +// CODE GENERATOR: extern function requirement MAX11043::SPIreadWrite16bits +// SPI read and write 16 bits +// SPI interface to MAX11043 shift 16 bits mosiData16 into MAX11043 DIN +// while simultaneously capturing 16 bits miso data from MAX11043 DOUT +// +int16_t MAX11043::SPIreadWrite16bits(int16_t mosiData16) +{ + // CODE GENERATOR: extern function definition for function SPIreadWrite16bits + // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite16bits(int16_t mosiData16) + size_t byteCount = 2; + static char mosiData[2]; + static char misoData[2]; + mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte + mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ noInterrupts(); + // + //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin + // + unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); + //~ m_spi.transfer(mosiData8_FF0000); + //~ m_spi.transfer(mosiData16_00FF00); + //~ m_spi.transfer(mosiData16_0000FF); + // + //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin + // + // 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->")); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_0000FF & 0xFF), HEX); + // hex dump mosiData[0..byteCount-1] +#if 0 // HAS_MICROUSBSERIAL + cmdLine_microUSBserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_microUSBserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_microUSBserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_microUSBserial.serial().printf(" "); +#endif +#if 0 // HAS_DAPLINK_SERIAL + cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_DAPLINKserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_DAPLINKserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_DAPLINKserial.serial().printf(" "); +#endif + // VERIFY: DIAGNOSTIC: print MAX5715 device register write + // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); + // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); + // + //int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF; + int misoData16 = (misoData[0] << 8) | misoData[1]; + return misoData16; +} + +// CODE GENERATOR: extern function requirement MAX11043::SPIreadWrite32bits +// SPI read and write 32 bits +// SPI interface to MAX11043 shift 32 bits mosiData into MAX11043 DIN +// while simultaneously capturing 32 bits miso data from MAX11043 DOUT +// +int32_t MAX11043::SPIreadWrite32bits(int32_t mosiData32) +{ + // CODE GENERATOR: extern function definition for function SPIreadWrite32bits + // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWrite32bits(int32_t mosiData32) + size_t byteCount = 4; + static char mosiData[4]; + static char misoData[4]; + mosiData[0] = (char)((mosiData32 >> 24) & 0xFF); // MSByte + mosiData[1] = (char)((mosiData32 >> 16) & 0xFF); + mosiData[2] = (char)((mosiData32 >> 8) & 0xFF); + mosiData[3] = (char)((mosiData32 >> 0) & 0xFF); // LSByte + // + // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() + //~ noInterrupts(); + // + //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin + // + unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount); + //~ m_spi.transfer(mosiData8_FF0000); + //~ m_spi.transfer(mosiData16_00FF00); + //~ m_spi.transfer(mosiData16_0000FF); + // + //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin + // + // 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->")); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData8_FF0000 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_00FF00 & 0xFF), HEX); + //cmdLine.serial().printf(" 0x")); + //Serial.print( (mosiData16_0000FF & 0xFF), HEX); + // hex dump mosiData[0..byteCount-1] +#if 0 // HAS_MICROUSBSERIAL + cmdLine_microUSBserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_microUSBserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_microUSBserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_microUSBserial.serial().printf(" "); +#endif +#if 0 // HAS_DAPLINK_SERIAL + cmdLine_DAPLINKserial.serial().printf("\r\nSPI"); + if (byteCount > 7) { + cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount); + } + cmdLine_DAPLINKserial.serial().printf(" MOSI->"); + for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]); + } + // hex dump misoData[0..byteCount-1] + cmdLine_DAPLINKserial.serial().printf(" MISO<-"); + for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++) + { + cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]); + } + cmdLine_DAPLINKserial.serial().printf(" "); +#endif + // VERIFY: DIAGNOSTIC: print MAX5715 device register write + // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF); + // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF); + // + //int misoData32 = (misoData32_FF000000 << 24) | (misoData32_FF0000 << 16) | (misoData32_0000FF00 << 8) | misoData32_000000FF; + int misoData32 = (misoData[0] << 24) | (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; + return misoData32; +} + +// TODO1: CODE GENERATOR: extern function GPIOoutputSHDN alias SHDNoutputValue +// CODE GENERATOR: extern function requirement MAX11043::SHDNoutputValue +// Assert MAX11043 SHDN pin : High = _____, Low = _____. +// +void MAX11043::SHDNoutputValue(int isLogicHigh) +{ + // CODE GENERATOR: extern function definition for function SHDNoutputValue + // TODO1: CODE GENERATOR: extern function definition for gpio interface function SHDNoutputValue + // TODO1: CODE GENERATOR: gpio pin SHDN assuming member function m_SHDN_pin + // TODO1: CODE GENERATOR: gpio direction output + // m_SHDN_pin.output(); // only applicable to DigitalInOut + // TODO1: CODE GENERATOR: gpio function Value + m_SHDN_pin = isLogicHigh; +} +// TODO1: CODE GENERATOR: extern function GPIOoutputCONVRUN alias CONVRUNoutputValue +// CODE GENERATOR: extern function requirement MAX11043::CONVRUNoutputValue +// Assert MAX11043 CONVRUN pin : High = _____, Low = _____. +// +void MAX11043::CONVRUNoutputValue(int isLogicHigh) +{ + // CODE GENERATOR: extern function definition for function CONVRUNoutputValue + // TODO1: CODE GENERATOR: extern function definition for gpio interface function CONVRUNoutputValue + // TODO1: CODE GENERATOR: gpio pin CONVRUN assuming member function m_CONVRUN_pin + // TODO1: CODE GENERATOR: gpio direction output + // m_CONVRUN_pin.output(); // only applicable to DigitalInOut + // TODO1: CODE GENERATOR: gpio function Value + m_CONVRUN_pin = isLogicHigh; +} + +// TODO1: CODE GENERATOR: extern function GPIOoutputDACSTEP alias DACSTEPoutputValue +// CODE GENERATOR: extern function requirement MAX11043::DACSTEPoutputValue +// Assert MAX11043 DACSTEP pin : High = _____, Low = _____. +// +void MAX11043::DACSTEPoutputValue(int isLogicHigh) +{ + // CODE GENERATOR: extern function definition for function DACSTEPoutputValue + // TODO1: CODE GENERATOR: extern function definition for gpio interface function DACSTEPoutputValue + // TODO1: CODE GENERATOR: gpio pin DACSTEP assuming member function m_DACSTEP_pin + // TODO1: CODE GENERATOR: gpio direction output + // m_DACSTEP_pin.output(); // only applicable to DigitalInOut + // TODO1: CODE GENERATOR: gpio function Value + m_DACSTEP_pin = isLogicHigh; +} + +// TODO1: CODE GENERATOR: extern function GPIOoutputUP_slash_DWNb alias UP_slash_DWNboutputValue +// CODE GENERATOR: extern function requirement MAX11043::UP_slash_DWNboutputValue +// Assert MAX11043 UP_slash_DWNb pin : High = _____, Low = _____. +// +void MAX11043::UP_slash_DWNboutputValue(int isLogicHigh) +{ + // CODE GENERATOR: extern function definition for function UP_slash_DWNboutputValue + // TODO1: CODE GENERATOR: extern function definition for gpio interface function UP_slash_DWNboutputValue + // TODO1: CODE GENERATOR: gpio pin UP_slash_DWNb assuming member function m_UP_slash_DWNb_pin + // TODO1: CODE GENERATOR: gpio direction output + // m_UP_slash_DWNb_pin.output(); // only applicable to DigitalInOut + // TODO1: CODE GENERATOR: gpio function Value + m_UP_slash_DWNb_pin = isLogicHigh; +} + +// CODE GENERATOR: extern function requirement MAX11043::EOCinputWaitUntilLow +// Wait for MAX11043 EOC pin low, indicating end of conversion. +// Required when using any of the InternalClock modes. +// +void MAX11043::EOCinputWaitUntilLow() +{ + // CODE GENERATOR: extern function definition for function EOCinputWaitUntilLow + // TODO1: CODE GENERATOR: extern function definition for gpio interface function EOCinputWaitUntilLow + // TODO1: CODE GENERATOR: gpio pin EOC assuming member function m_EOC_pin + // TODO1: CODE GENERATOR: gpio direction input + // m_EOC_pin.input(); // only applicable to DigitalInOut + // TODO1: CODE GENERATOR: gpio function WaitUntilLow + while (m_EOC_pin != 0) + { + // spinlock waiting for logic low pin state + } +} + +// CODE GENERATOR: extern function requirement MAX11043::EOCinputValue +// Return the status of the MAX11043 EOC pin. +// +int MAX11043::EOCinputValue() +{ + // CODE GENERATOR: extern function definition for function EOCinputValue + // TODO1: CODE GENERATOR: extern function definition for gpio interface function EOCinputValue + // TODO1: CODE GENERATOR: gpio pin EOC assuming member function m_EOC_pin + // TODO1: CODE GENERATOR: gpio direction input + // m_EOC_pin.input(); // only applicable to DigitalInOut + // TODO1: CODE GENERATOR: gpio function Value + return m_EOC_pin.read(); +} + +// CODE GENERATOR: class member function definitions +//---------------------------------------- +// Menu item '!' +// Initialize device +// @return 1 on success; 0 on failure +uint8_t MAX11043::Init(void) +{ + + //---------------------------------------- + // TODO1: AC79 MAX11043 AIN0-AIN1 reference voltage, in Volts + VRef_xxxxxx = 2.500; + + //---------------------------------------- + // shadow of register ctrl CMD_r000_1001_dddd_dddd_CTRL + ctrl = 0x01; + + //---------------------------------------- + // set by Configure_PGA gain index register pga CMD_r000_1110_xxdd_xddd_PGA + pgaGain = 1; + + //---------------------------------------- + // init (based on old EV kit GUI) + #warning "Not Implemented Yet: MAX11043::Init init..." + // bool bOpResult = false; + // String FWVersionString = "00"; + // bool bDemoMode = true; + // int scan_resolution = 0; + // int scan_channels = 0; + // int scan_bits = 0; + // int sampleRateFactore = 0; + // double sampleRate = 0; + // unsigned long banks_requested = 0; + // bool bScanMode = 0; + + //---------------------------------------- + // Device ID Validation + #warning "Not Implemented Yet: MAX11043::Init Device ID Validation..." + // const uint32_t part_id_expect = 0x000F02; + // uint32_t part_id_readback; + // RegRead(xxxxxxxxxxxxCMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback); + // if (part_id_readback != part_id_expect) return 0; + + //---------------------------------------- + // write8 0x00 PD = 0x03 (Reset Registers; enter Standby mode) + // RegWrite(xxxxxxxxxxxCMD_r000_0000_xxxx_xxdd_PD, PD_11_Reset); + + //---------------------------------------- + // write8 0x00 PD = 0x00 (NOP) + // RegWrite(xxxxxxxxxxxxCMD_r000_0000_xxxx_xxdd_PD, PD_00_Normal); + + //---------------------------------------- + // success + return 1; +} + +//---------------------------------------- +// Write a MAX11043 register. +// +// CMD_1aaa_aaaa_REGISTER_READ bit is cleared 0 indicating a write operation. +// +// MAX11043 register length can be determined by function RegSize. +// +// For 8-bit register size: +// +// SPI 16-bit transfer +// +// SPI MOSI = 0aaa_aaaa_dddd_dddd +// +// SPI MISO = xxxx_xxxx_xxxx_xxxx +// +// For 16-bit register size: +// +// SPI 24-bit or 32-bit transfer +// +// SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd +// +// SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx +// +// For 24-bit register size: +// +// SPI 32-bit transfer +// +// SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd +// +// SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx +// +// @return 1 on success; 0 on failure +uint8_t MAX11043::RegWrite(MAX11043_CMD_enum_t commandByte, uint32_t regData) +{ + + //---------------------------------------- + // switch based on register address szie RegSize(commandByte) + //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + switch(RegSize(commandByte)) + { + case 8: // 8-bit register size + { + // SPI 16-bit transfer + // SPI MOSI = 0aaa_aaaa_dddd_dddd + // SPI MISO = xxxx_xxxx_xxxx_xxxx + int16_t mosiData16 = ((int16_t)commandByte << 8) | ((int16_t)regData & 0xFF); + SPIoutputCS(0); + SPIwrite16bits(mosiData16); + SPIoutputCS(1); + } + break; + case 16: // 16-bit register size + #warning "Not Verified Yet: MAX11043::RegWrite 16-bit SPIreadWrite32bits" + { + // SPI 24-bit or 32-bit transfer + // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd + // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx + // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_0000_0000 + // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx + int32_t mosiData32 = ((int32_t)commandByte << 24) | (((int32_t)regData & 0xFFFF) << 8); + SPIoutputCS(0); + SPIreadWrite32bits(mosiData32); + SPIoutputCS(1); + } + break; + case 24: // 24-bit register size + { + // SPI 32-bit transfer + // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd + // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx + int32_t mosiData32 = ((int32_t)commandByte << 24) | ((int32_t)regData & 0x00FFFFFF); + SPIoutputCS(0); + SPIreadWrite32bits(mosiData32); + SPIoutputCS(1); + } + break; + } + + //---------------------------------------- + // success + return 1; +} + +//---------------------------------------- +// Read an 8-bit MAX11043 register +// +// CMD_1aaa_aaaa_REGISTER_READ bit is set 1 indicating a read operation. +// +// MAX11043 register length can be determined by function RegSize. +// +// For 8-bit register size: +// +// SPI 16-bit transfer +// +// SPI MOSI = 1aaa_aaaa_0000_0000 +// +// SPI MISO = xxxx_xxxx_dddd_dddd +// +// For 16-bit register size: +// +// SPI 24-bit or 32-bit transfer +// +// SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 +// +// SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd +// +// For 24-bit register size: +// +// SPI 32-bit transfer +// +// SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 +// +// SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd +// +// +// @return 1 on success; 0 on failure +uint8_t MAX11043::RegRead(MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) +{ + + //---------------------------------------- + // switch based on register address szie RegSize(regAddress) + //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + switch(RegSize(commandByte)) + { + case 8: // 8-bit register size + { + // SPI 16-bit transfer + // SPI MOSI = 1aaa_aaaa_0000_0000 + // SPI MISO = xxxx_xxxx_dddd_dddd + int16_t mosiData16 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int16_t)commandByte) << 8) | ((int16_t)0); + SPIoutputCS(0); + int16_t misoData16 = SPIreadWrite16bits(mosiData16); + SPIoutputCS(1); + (*ptrRegData) = (misoData16 & 0x00FF); + } + break; + case 16: // 16-bit register size + #warning "Not Verified Yet: MAX11043::RegRead 16-bit SPIreadWrite32bits" + { + // SPI 24-bit or 32-bit transfer + // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 + // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd + // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 + // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_xxxx_xxxx + int32_t mosiData32 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int32_t)commandByte) << 24); + SPIoutputCS(0); + int32_t misoData32 = SPIreadWrite32bits(mosiData32); + SPIoutputCS(1); + (*ptrRegData) = ((misoData32 >> 8) & 0x00FFFF); + } + break; + case 24: // 24-bit register size + { + // SPI 32-bit transfer + // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 + // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd + int32_t mosiData32 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int32_t)commandByte) << 24); + SPIoutputCS(0); + int32_t misoData32 = SPIreadWrite32bits(mosiData32); + SPIoutputCS(1); + (*ptrRegData) = (misoData32 & 0x00FFFFFF); + } + break; + } + + //---------------------------------------- + // success + return 1; +} + +//---------------------------------------- +// Return the size of a MAX11043 register +// +// @return 8 for 8-bit, 16 for 16-bit, 24 for 24-bit, else 0 for undefined register size +uint8_t MAX11043::RegSize(MAX11043_CMD_enum_t commandByte) +{ + + //---------------------------------------- + // switch based on register address value regAddress + // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + switch(commandByte) + { + default: + case CMD_0aaa_aa00_WrAddr_WriteAnyRegister: + case CMD_0aaa_aa10_RdAddr_ReadAnyRegister: + case CMD_1111_1111_NoOperationMOSIidleHigh: + return 0; // undefined register size + case CMD_0001_1110_d8_Rd07_Status: + case CMD_0101_0100_d8_Wr15_FilterCAddress: + case CMD_0101_0110_d8_Rd15_FilterCAddress: + case CMD_0110_0000_d8_Wr18_FlashMode: + case CMD_0110_0010_d8_Rd18_FlashMode: + return 8; // 8-bit register size + case CMD_0010_0000_d16_Wr08_Configuration: + case CMD_0010_0010_d16_Rd08_Configuration: + case CMD_0010_0100_d16_Wr09_DAC: + case CMD_0010_0110_d16_Rd09_DAC: + case CMD_0010_1000_d16_Wr0A_DACStep: + case CMD_0010_1010_d16_Rd0A_DACStep: + case CMD_0010_1100_d16_Wr0B_DACHDACL: + case CMD_0010_1110_d16_Rd0B_DACHDACL: + case CMD_0011_0000_d16_Wr0C_ConfigA: + case CMD_0011_0010_d16_Rd0C_ConfigA: + case CMD_0011_0100_d16_Wr0D_ConfigB: + case CMD_0011_0110_d16_Rd0D_ConfigB: + case CMD_0011_1000_d16_Wr0E_ConfigC: + case CMD_0011_1010_d16_Rd0E_ConfigC: + case CMD_0011_1100_d16_Wr0F_ConfigD: + case CMD_0011_1110_d16_Rd0F_ConfigD: + case CMD_0100_0000_d16_Wr10_Reference: + case CMD_0100_0010_d16_Rd10_Reference: + case CMD_0100_0100_d16_Wr11_AGain: + case CMD_0100_0110_d16_Rd11_AGain: + case CMD_0100_1000_d16_Wr12_BGain: + case CMD_0100_1010_d16_Rd12_BGain: + case CMD_0100_1100_d16_Wr13_CGain: + case CMD_0100_1110_d16_Rd13_CGain: + case CMD_0101_0000_d16_Wr14_DGain: + case CMD_0101_0010_d16_Rd14_DGain: + case CMD_0110_0100_d16_Wr19_FlashAddr: + case CMD_0110_0110_d16_Rd19_FlashAddr: + case CMD_0110_1000_d16_Wr1A_FlashDataIn: + case CMD_0110_1010_d16_Rd1A_FlashDataIn: + case CMD_0110_1110_d16_Rd1B_FlashDataOut: + return 16; // 16-bit register size + case CMD_0000_0010_d24_Rd00_ADCa: + case CMD_0000_0110_d24_Rd01_ADCb: + case CMD_0000_1010_d24_Rd02_ADCc: + case CMD_0000_1110_d24_Rd03_ADCd: + return 24; // 24-bit register size + case CMD_0001_0010_d24_d24_Rd04_ADCab: + case CMD_0001_0110_d24_d24_Rd05_ADCcd: + return 48; // 24-bit register size + case CMD_0001_1010_d24_d24_d24_d24_Rd06_ADCabcd: + return 96; // 24-bit register size + case CMD_0101_1000_d32_Wr16_FilterCDataOut: + case CMD_0101_1010_d32_Rd16_FilterCDataOut: + case CMD_0101_1100_d32_Wr17_FilterCDataIn: + case CMD_0101_1110_d32_Rd17_FilterCDataIn: + return 32; // 32-bit register size + } +} + +//---------------------------------------- +// Return the address field of a MAX11043 register +// +// @return register address field as given in datasheet +uint8_t MAX11043::RegAddrOfCommand(MAX11043_CMD_enum_t commandByte) +{ + + //---------------------------------------- + // extract register address value from command byte + return (uint8_t)((commandByte &~ 0x83) >> 2); // CMD_0aaa_aa10_RdAddr_ReadAnyRegister +} + +//---------------------------------------- +// Test whether a command byte is a register read command +// +// @return true if command byte is a register read command +uint8_t MAX11043::IsRegReadCommand(MAX11043_CMD_enum_t commandByte) +{ + + //---------------------------------------- + // Test whether a command byte is a register read command + return (commandByte &~ 0x02) ? 1 : 0; // CMD_0aaa_aa10_RdAddr_ReadAnyRegister +} + +//---------------------------------------- +// Return the name of a MAX11043 register +// +// @return null-terminated constant C string containing register name or empty string +const char* MAX11043::RegName(MAX11043_CMD_enum_t commandByte) +{ + + //---------------------------------------- + // switch based on register address value regAddress + // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + switch(commandByte) + { + default: + return ""; // undefined register + // case CMD_0aaa_aa00_WrAddr_WriteAnyRegister: return "_______"; + // case CMD_0aaa_aa10_RdAddr_ReadAnyRegister: return "_______"; + // case CMD_1111_1111_NoOperationMOSIidleHigh: return "_______"; + case CMD_0000_0010_d24_Rd00_ADCa: return "ADCa"; + case CMD_0000_0110_d24_Rd01_ADCb: return "ADCb"; + case CMD_0000_1010_d24_Rd02_ADCc: return "ADCc"; + case CMD_0000_1110_d24_Rd03_ADCd: return "ADCd"; + case CMD_0001_0010_d24_d24_Rd04_ADCab: return "ADCab"; + case CMD_0001_0110_d24_d24_Rd05_ADCcd: return "ADCcd"; + case CMD_0001_1010_d24_d24_d24_d24_Rd06_ADCabcd: return "ADCabcd"; + case CMD_0001_1110_d8_Rd07_Status: return "Status"; + case CMD_0010_0000_d16_Wr08_Configuration: return "Configuration"; + case CMD_0010_0010_d16_Rd08_Configuration: return "Configuration"; + case CMD_0010_0100_d16_Wr09_DAC: return "DAC"; + case CMD_0010_0110_d16_Rd09_DAC: return "DAC"; + case CMD_0010_1000_d16_Wr0A_DACStep: return "DACStep"; + case CMD_0010_1010_d16_Rd0A_DACStep: return "DACStep"; + case CMD_0010_1100_d16_Wr0B_DACHDACL: return "DACHDACL"; + case CMD_0010_1110_d16_Rd0B_DACHDACL: return "DACHDACL"; + case CMD_0011_0000_d16_Wr0C_ConfigA: return "ConfigA"; + case CMD_0011_0010_d16_Rd0C_ConfigA: return "ConfigA"; + case CMD_0011_0100_d16_Wr0D_ConfigB: return "ConfigB"; + case CMD_0011_0110_d16_Rd0D_ConfigB: return "ConfigB"; + case CMD_0011_1000_d16_Wr0E_ConfigC: return "ConfigC"; + case CMD_0011_1010_d16_Rd0E_ConfigC: return "ConfigC"; + case CMD_0011_1100_d16_Wr0F_ConfigD: return "ConfigD"; + case CMD_0011_1110_d16_Rd0F_ConfigD: return "ConfigD"; + case CMD_0100_0000_d16_Wr10_Reference: return "Reference"; + case CMD_0100_0010_d16_Rd10_Reference: return "Reference"; + case CMD_0100_0100_d16_Wr11_AGain: return "AGain"; + case CMD_0100_0110_d16_Rd11_AGain: return "AGain"; + case CMD_0100_1000_d16_Wr12_BGain: return "BGain"; + case CMD_0100_1010_d16_Rd12_BGain: return "BGain"; + case CMD_0100_1100_d16_Wr13_CGain: return "CGain"; + case CMD_0100_1110_d16_Rd13_CGain: return "CGain"; + case CMD_0101_0000_d16_Wr14_DGain: return "DGain"; + case CMD_0101_0010_d16_Rd14_DGain: return "DGain"; + case CMD_0101_0100_d8_Wr15_FilterCAddress: return "FilterCAddress"; + case CMD_0101_0110_d8_Rd15_FilterCAddress: return "FilterCAddress"; + case CMD_0101_1000_d32_Wr16_FilterCDataOut: return "FilterCDataOut"; + case CMD_0101_1010_d32_Rd16_FilterCDataOut: return "FilterCDataOut"; + case CMD_0101_1100_d32_Wr17_FilterCDataIn: return "FilterCDataIn"; + case CMD_0101_1110_d32_Rd17_FilterCDataIn: return "FilterCDataIn"; + case CMD_0110_0000_d8_Wr18_FlashMode: return "FlashMode"; + case CMD_0110_0010_d8_Rd18_FlashMode: return "FlashMode"; + case CMD_0110_0100_d16_Wr19_FlashAddr: return "FlashAddr"; + case CMD_0110_0110_d16_Rd19_FlashAddr: return "FlashAddr"; + case CMD_0110_1000_d16_Wr1A_FlashDataIn: return "FlashDataIn"; + case CMD_0110_1010_d16_Rd1A_FlashDataIn: return "FlashDataIn"; + case CMD_0110_1110_d16_Rd1B_FlashDataOut: return "FlashDataOut"; + } +} + + +// End of file