Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.

Dependencies:   MaximTinyTester MAX11410 CmdLine USBDevice

Revision:
52:d3fb6f1722bf
Parent:
51:15d9a9e0b623
Child:
54:ba810c1d6264
--- a/Test_Menu_MAX11410.cpp	Wed Jan 22 07:57:46 2020 +0000
+++ b/Test_Menu_MAX11410.cpp	Fri Feb 14 03:36:13 2020 +0000
@@ -31,6 +31,7 @@
 // *******************************************************************************
 // */
 #include "CmdLine.h"
+#include "MaximTinyTester.h"
 // CODE GENERATOR: class declaration and docstrings
 // CODE GENERATOR: example code includes
 // example code includes
@@ -71,6 +72,7 @@
 // end Platform_Include_Boilerplate
 #include "MAX11410.h"
 #include "CmdLine.h"
+#include "MaximTinyTester.h"
 // CODE GENERATOR: class declaration statement open
 
 // CODE GENERATOR: Test_Menu externs
@@ -102,17 +104,19 @@
 // CODE GENERATOR: no Menu item hint in description
 // CODE GENERATOR: MAX11410 Command Name = VoltageOfCode (uint32_t value_u24) --> double
 // CODE GENERATOR: no Menu item hint in description
-// CODE GENERATOR: MAX11410 Command Name = RegWrite (MAX11410_CMD_enum_t regAddress, uint32_t regData) --> uint8_t
+// CODE GENERATOR: MAX11410 Command Name = RegWrite (MAX11410_CMD_enum_t commandByte, uint32_t regData) --> uint8_t
 // CODE GENERATOR: no Menu item hint in description
-// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ
-// CODE GENERATOR: MAX11410 Command Name = RegWrite CMD_1aaa_aaaa_REGISTER_READ (MAX11410_CMD_enum_t regAddress, uint32_t regData) --> uint8_t
-// CODE GENERATOR: MAX11410 Command Name = RegRead (MAX11410_CMD_enum_t regAddress, uint32_t* ptrRegData) --> uint8_t
+// CODE GENERATOR: MAX11410 Command Name = RegRead (MAX11410_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t
+// CODE GENERATOR: no Menu item hint in description
+// CODE GENERATOR: MAX11410 Command Name = RegSize (MAX11410_CMD_enum_t commandByte) --> uint8_t
 // CODE GENERATOR: no Menu item hint in description
-// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ
-// CODE GENERATOR: MAX11410 Command Name = RegRead CMD_1aaa_aaaa_REGISTER_READ (MAX11410_CMD_enum_t regAddress, uint32_t* ptrRegData) --> uint8_t
-// CODE GENERATOR: MAX11410 Command Name = RegSize (MAX11410_CMD_enum_t regAddress) --> uint8_t
+// CODE GENERATOR: MAX11410 Command Name = DecodeCommand (MAX11410_CMD_enum_t commandByte) --> MAX11410::MAX11410_CMDOP_enum_t
+// CODE GENERATOR: no Menu item hint in description
+// CODE GENERATOR: MAX11410 Command Name = RegAddrOfCommand (MAX11410_CMD_enum_t commandByte) --> uint8_t
 // CODE GENERATOR: no Menu item hint in description
-// CODE GENERATOR: MAX11410 Command Name = RegName (MAX11410_CMD_enum_t regAddress) --> const char*
+// CODE GENERATOR: MAX11410 Command Name = IsRegReadCommand (MAX11410_CMD_enum_t commandByte) --> uint8_t
+// CODE GENERATOR: no Menu item hint in description
+// CODE GENERATOR: MAX11410 Command Name = RegName (MAX11410_CMD_enum_t commandByte) --> const char*
 // CODE GENERATOR: no Menu item hint in description
 // CODE GENERATOR: MAX11410 Command Name = Configure_FILTER (uint8_t linef, uint8_t rate) --> uint8_t
 // CODE GENERATOR: Menu item hint description Menu item 'XF'
@@ -355,8 +359,6 @@
 // CODE GENERATOR:           CommandDocParamOut ''
 // CODE GENERATOR:           CommandPost '@post AINcode[ainp]: measurement result LSB code'
 // CODE GENERATOR:           CommandReturn '@return ideal voltage calculated from raw LSB code and reference voltage'
-// CODE GENERATOR: MAX11410 Command Name = Configure_RTD (MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) --> uint8_t
-// CODE GENERATOR: no Menu item hint in description
 // CODE GENERATOR: MAX11410 Command Name = Measure_RTD (MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) --> double
 // CODE GENERATOR: Menu item hint description Menu item 'R' -> rtd_resistance, RTD_Temperature
 // CODE GENERATOR: Menu item 'R' -> rtd_resistance, RTD_Temperature -- Menu item R
@@ -380,8 +382,6 @@
 // CODE GENERATOR:           CommandReturn '@return resistance calculated from raw LSB code and reference resistance'
 // CODE GENERATOR: MAX11410 Command Name = TemperatureOfRTD_PT1000 (double rtd_resistance) --> double
 // CODE GENERATOR: no Menu item hint in description
-// CODE GENERATOR: MAX11410 Command Name = Configure_Thermocouple (MAX11410_AINP_SEL_enum_t tc_ainp, MAX11410_AINN_SEL_enum_t tc_ainn, MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) --> uint8_t
-// CODE GENERATOR: no Menu item hint in description
 // CODE GENERATOR: MAX11410 Command Name = Measure_Thermocouple (MAX11410_AINP_SEL_enum_t tc_ainp, MAX11410_AINN_SEL_enum_t tc_ainn, MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) --> double
 // CODE GENERATOR: Menu item hint description Menu item 'TM'
 // CODE GENERATOR: Menu item 'TM' -- Menu item TM
@@ -647,6 +647,19 @@
 // CODE GENERATOR: TODO1: generate GPIO commands for LDAC, CLR, etc. based on device driver function names (menu_help)
         // case 'G'..'Z','g'..'z' are reserved for GPIO commands
         // case 'A'..'F','a'..'f' may be available if not claimed by bitstream commands
+// CODE GENERATOR: TODO1: prevent conflict ExternFunctionGPIOPinCommand with reserved case 'A'..'F','a'..'f'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'A' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'B' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'C' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'D' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'E' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'F' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'a' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'b' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'c' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'd' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'e' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'f' 'None'
 
     //
 }
@@ -773,7 +786,7 @@
         {
             // if buffer starts with a regName:
             // for each reg value (0..n) if(cmdLine.has_keyword(device.regName(r))):
-            cmdLine.serial().printf(" scan RegName... ");
+            cmdLine.serial().printf(" scan RegName...\r\n");
             for (uint8_t regAddress = 0; regAddress < 0x80; regAddress++)
             {
                 uint32_t regData = 0;
@@ -804,17 +817,46 @@
                 }
             } // end for regAddr
             // not a valid register name
+            Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11410_device.onSPIprint;
+            g_MAX11410_device.onSPIprint = NULL; // temporarily suppress SPI diagnostic messages
             // read "all" registers by name
-            const uint8_t readAllRegFirst = 0x00; // first MAX11410 register address for read-all block
-            const uint8_t readAllRegLast = 0x39; // last MAX11410 register address for read-all block
-            Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11410_device.onSPIprint;
-            g_MAX11410_device.onSPIprint = NULL;
-            for (uint8_t regAddress = readAllRegFirst; regAddress <= readAllRegLast; regAddress++)
+            // TODO: KLUDGE: this constant array should live in the device driver, not the menu
+            const MAX11410::MAX11410_CMD_enum_t readAllStatusList[] = {
+                    MAX11410::CMD_r000_0000_xxxx_xxdd_PD,
+                    MAX11410::CMD_r000_0001_xddd_xxdd_CONV_START,
+                    MAX11410::CMD_r000_0010_xddd_dddd_SEQ_START,
+                    MAX11410::CMD_r000_0011_xxxx_xddd_CAL_START,
+                    MAX11410::CMD_r000_0100_dddd_xddd_GP0_CTRL,
+                    MAX11410::CMD_r000_0101_dddd_xddd_GP1_CTRL,
+                    MAX11410::CMD_r000_0110_xddd_xxdd_GP_CONV,
+                    MAX11410::CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR,
+                    MAX11410::CMD_r000_1000_x0dd_dddd_FILTER,
+                    MAX11410::CMD_r000_1001_dddd_dddd_CTRL,
+                    MAX11410::CMD_r000_1010_dddd_dddd_SOURCE,
+                    MAX11410::CMD_r000_1011_dddd_dddd_MUX_CTRL0,
+                    MAX11410::CMD_r000_1100_dddd_dddd_MUX_CTRL1,
+                    MAX11410::CMD_r000_1101_dddd_dddd_MUX_CTRL2,
+                    MAX11410::CMD_r000_1110_xxdd_xddd_PGA,
+                    MAX11410::CMD_r000_1111_dddd_dddd_WAIT_EXT,
+                    MAX11410::CMD_r001_0000_xxxx_xxxx_WAIT_START,
+                    MAX11410::CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID,
+                    MAX11410::CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0,
+                    MAX11410::CMD_r011_0001_dddd_dddd_dddd_dddd_dddd_dddd_DATA1,
+                    MAX11410::CMD_r011_0010_dddd_dddd_dddd_dddd_dddd_dddd_DATA2,
+                    MAX11410::CMD_r011_0011_dddd_dddd_dddd_dddd_dddd_dddd_DATA3,
+                    MAX11410::CMD_r011_0100_dddd_dddd_dddd_dddd_dddd_dddd_DATA4,
+                    MAX11410::CMD_r011_0101_dddd_dddd_dddd_dddd_dddd_dddd_DATA5,
+                    MAX11410::CMD_r011_0110_dddd_dddd_dddd_dddd_dddd_dddd_DATA6,
+                    MAX11410::CMD_r011_0111_dddd_dddd_dddd_dddd_dddd_dddd_DATA7,
+                    MAX11410::CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS,
+                };
+            for (uint8_t readAllStatusIndex = 0; readAllStatusIndex < (sizeof(readAllStatusList)/sizeof(MAX11410::MAX11410_CMD_enum_t)); readAllStatusIndex++)
             {
+                MAX11410::MAX11410_CMD_enum_t regAddress = readAllStatusList[readAllStatusIndex];
                 uint32_t regData = 0;
-                if (g_MAX11410_device.RegSize((MAX11410::MAX11410_CMD_enum_t)regAddress) == 0) continue; // skip undefined regs
-                if (g_MAX11410_device.RegRead((MAX11410::MAX11410_CMD_enum_t)regAddress, &regData) == 0) continue; // skip unreadable regs
-                cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11410_device.RegName((MAX11410::MAX11410_CMD_enum_t)regAddress), regData);
+                if (g_MAX11410_device.RegSize(regAddress) == 0) continue; // skip undefined regs
+                if (g_MAX11410_device.RegRead(regAddress, &regData) == 0) continue; // skip unreadable regs
+                cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11410_device.RegName(regAddress), regData);
             } // end for regAddr
             g_MAX11410_device.onSPIprint = saved_onSPIprint_handler;
             return true; // command handled by MAX11410
@@ -826,38 +868,38 @@
         {
 // CODE GENERATOR: @ command print double g_MAX11410_device.VRef_REF0
                     cmdLine.serial().printf("VRef_REF0 = ");
-                    cmdLine.serial().printf("%f\n", g_MAX11410_device.VRef_REF0);
+                    cmdLine.serial().printf("%f\r\n", g_MAX11410_device.VRef_REF0);
 // CODE GENERATOR: @ command print double g_MAX11410_device.VRef_REF1
                     cmdLine.serial().printf("VRef_REF1 = ");
-                    cmdLine.serial().printf("%f\n", g_MAX11410_device.VRef_REF1);
+                    cmdLine.serial().printf("%f\r\n", g_MAX11410_device.VRef_REF1);
 // CODE GENERATOR: @ command print double g_MAX11410_device.VRef_REF2
                     cmdLine.serial().printf("VRef_REF2 = ");
-                    cmdLine.serial().printf("%f\n", g_MAX11410_device.VRef_REF2);
+                    cmdLine.serial().printf("%f\r\n", g_MAX11410_device.VRef_REF2);
 // CODE GENERATOR: @ command print double g_MAX11410_device.VRef_AVDD
                     cmdLine.serial().printf("VRef_AVDD = ");
-                    cmdLine.serial().printf("%f\n", g_MAX11410_device.VRef_AVDD);
+                    cmdLine.serial().printf("%f\r\n", g_MAX11410_device.VRef_AVDD);
 // CODE GENERATOR: @ command print double g_MAX11410_device.rtd_resistance
                     cmdLine.serial().printf("rtd_resistance = ");
-                    cmdLine.serial().printf("%f\n", g_MAX11410_device.rtd_resistance);
+                    cmdLine.serial().printf("%f\r\n", g_MAX11410_device.rtd_resistance);
 // CODE GENERATOR: @ command print double g_MAX11410_device.RTD_Temperature
                     cmdLine.serial().printf("RTD_Temperature = ");
-                    cmdLine.serial().printf("%f\n", g_MAX11410_device.RTD_Temperature);
+                    cmdLine.serial().printf("%f\r\n", g_MAX11410_device.RTD_Temperature);
 // CODE GENERATOR: @ command print uint32_t g_MAX11410_device.ctrl
                     cmdLine.serial().printf("ctrl = ");
-                    cmdLine.serial().printf("%d = 0x%8.8x\n", g_MAX11410_device.ctrl, g_MAX11410_device.ctrl);
+                    cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11410_device.ctrl, g_MAX11410_device.ctrl);
 // CODE GENERATOR: @ command print uint8_t g_MAX11410_device.pgaGain
                     cmdLine.serial().printf("pgaGain = ");
-                    cmdLine.serial().printf("%d = 0x%2.2x\n", g_MAX11410_device.pgaGain, g_MAX11410_device.pgaGain);
+                    cmdLine.serial().printf("%d = 0x%2.2x\r\n", g_MAX11410_device.pgaGain, g_MAX11410_device.pgaGain);
 // CODE GENERATOR: @ command print uint32_t g_MAX11410_device.status
                     cmdLine.serial().printf("status = ");
-                    cmdLine.serial().printf("%d = 0x%8.8x\n", g_MAX11410_device.status, g_MAX11410_device.status);
+                    cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11410_device.status, g_MAX11410_device.status);
 // CODE GENERATOR: @ command print uint32_t g_MAX11410_device.data0
                     cmdLine.serial().printf("data0 = ");
-                    cmdLine.serial().printf("%d = 0x%8.8x\n", g_MAX11410_device.data0, g_MAX11410_device.data0);
+                    cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11410_device.data0, g_MAX11410_device.data0);
 // CODE GENERATOR: @ command print uint32_t array g_MAX11410_device.AINcode[0..10]
                 for(int index = 0; (index < 11) && (index < 16); index++) {
                     cmdLine.serial().printf("AINcode[%d] = ", index);
-                    cmdLine.serial().printf("%d = 0x%8.8x\n", g_MAX11410_device.AINcode[index], g_MAX11410_device.AINcode[index]);
+                    cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11410_device.AINcode[index], g_MAX11410_device.AINcode[index]);
                 }
                     return true; // command handled by MAX11410
             break;
@@ -865,6 +907,18 @@
 // CODE GENERATOR: TODO1: generate GPIO commands for LDAC, CLR, etc. based on device driver function names
         // case 'G'..'Z','g'..'z' are reserved for GPIO commands
         // case 'A'..'F','a'..'f' may be available if not claimed by bitstream commands
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'A' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'B' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'C' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'D' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'E' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'F' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'a' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'b' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'c' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'd' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'e' 'None'
+// CODE GENERATOR: ExternFunctionGPIOPinCommand 'f' 'None'
 
 // CODE GENERATOR: test menu
         // case '0'..'9','A'..'F','a'..'f' letters are reserved for bitstream commands
@@ -1989,16 +2043,21 @@
                     if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData,
                                                              MAX_SPI_BYTE_COUNT))
                     {
-                        // if length is 1 byte then operation is RegRead, otherwise RegWrite
-                        // register_read_function 'RegRead'
+                        // TODO: decode operation from commandByte
+                        // TODO: OVERSIMPLIFICATION: if length is 1 byte then operation is RegRead, otherwise RegWrite
+                        // register_read_function 'IsRegReadCommand'
                         // register_write_function 'RegWrite'
                         // register_name_function 'RegName'
                         // register_size_function 'RegSize'
-                        MAX11410::MAX11410_CMD_enum_t regAddress = (MAX11410::MAX11410_CMD_enum_t)((mosiData[0] &~ MAX11410::CMD_1aaa_aaaa_REGISTER_READ) & 0xFF);
+// CODE GENERATOR: does the chip have a defined CMDOP_1aaa_aaaa_ReadRegister bit?
+                        // MAX11410::MAX11410_CMD_enum_t regAddress = (MAX11410::MAX11410_CMD_enum_t)((mosiData[0] &~ MAX11410::CMDOP_1aaa_aaaa_ReadRegister) & 0xFF);
+                        MAX11410::MAX11410_CMD_enum_t commandByte = (MAX11410::MAX11410_CMD_enum_t)(mosiData[0]);
+                        MAX11410::MAX11410_CMDOP_enum_t commandOp = g_MAX11410_device.DecodeCommand(commandByte);
+                        int regAddress = g_MAX11410_device.RegAddrOfCommand(commandByte);
                         cmdLine.serial().printf(" regAddress=0x%2.2x\r\n", (regAddress & 0xFF));
-                        cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11410_device.RegName(regAddress));
+                        cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11410_device.RegName(commandByte));
                         uint32_t regData = 0;
-                        int regSize = g_MAX11410_device.RegSize(regAddress);
+                        int regSize = g_MAX11410_device.RegSize(commandByte);
                         cmdLine.serial().printf(" RegSize=%d\r\n", regSize);
                         switch(regSize)
                         {
@@ -2012,16 +2071,18 @@
                             regData = (((uint32_t)mosiData[1] & 0xFF) << 16) + (((uint32_t)mosiData[2] & 0xFF) << 8) + ((uint32_t)mosiData[3] & 0xFF);
                             break;
                         }
-                        if ((byteCount == 1) || (regAddress & MAX11410::CMD_1aaa_aaaa_REGISTER_READ))
+// CODE GENERATOR: does the chip have a defined CMDOP_1aaa_aaaa_ReadRegister bit?
+                        // if ((byteCount == 1) || (regAddress & MAX11410::CMDOP_1aaa_aaaa_ReadRegister))
+                        if ((byteCount == 1) || g_MAX11410_device.IsRegReadCommand(commandByte))
                         {
                             cmdLine.serial().printf(" RegRead");
-                            g_MAX11410_device.RegRead(regAddress, &regData);
+                            g_MAX11410_device.RegRead(commandByte, &regData);
                             cmdLine.serial().printf("regData=0x%6.6x\r\n", (regData & 0x00FFFFFF));
                         }
                         else
                         {
                             cmdLine.serial().printf(" RegWrite regData=0x%6.6X\r\n", (regData & 0x00FFFFFF));
-                            g_MAX11410_device.RegWrite(regAddress, regData);
+                            g_MAX11410_device.RegWrite(commandByte, regData);
                         }
                         // is there support function shadow regValue of regAddr?
                     }