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: Test_Menu_MAX11043.cpp
- Revision:
- 52:607010f0c54e
- Child:
- 53:3d5a3d241a5e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test_Menu_MAX11043.cpp Tue Feb 11 01:16:34 2020 +0000 @@ -0,0 +1,630 @@ +// /******************************************************************************* +// * 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. +// ******************************************************************************* +// */ +#include "CmdLine.h" +#include "MaximTinyTester.h" +// CODE GENERATOR: class declaration and docstrings +// CODE GENERATOR: example code includes +// example code includes +// standard include for target platform -- Platform_Include_Boilerplate +#include "mbed.h" +// Platforms: +// - MAX32625MBED +// - supports mbed-os-5.11, requires USBDevice library +// - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/ +// - remove max32630fthr library (if present) +// - remove MAX32620FTHR library (if present) +// - MAX32600MBED +// - remove max32630fthr library (if present) +// - remove MAX32620FTHR library (if present) +// - Windows 10 note: Don't connect HDK until you are ready to load new firmware into the board. +// - NUCLEO_F446RE +// - remove USBDevice library +// - remove max32630fthr library (if present) +// - remove MAX32620FTHR library (if present) +// - NUCLEO_F401RE +// - remove USBDevice library +// - remove max32630fthr library (if present) +// - remove MAX32620FTHR library (if present) +// - MAX32630FTHR +// - #include "max32630fthr.h" +// - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/ +// - remove MAX32620FTHR library (if present) +// - MAX32620FTHR +// - #include "MAX32620FTHR.h" +// - remove max32630fthr library (if present) +// - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/ +// - not tested yet +// - MAX32625PICO +// - remove max32630fthr library (if present) +// - remove MAX32620FTHR library (if present) +// - not tested yet +// +// end Platform_Include_Boilerplate +#include "MAX11043.h" +#include "CmdLine.h" +#include "MaximTinyTester.h" +// CODE GENERATOR: class declaration statement open + +// CODE GENERATOR: Test_Menu externs +#include "MAX11043.h" +extern MAX11043 g_MAX11043_device; // defined in main.cpp + +// CODE GENERATOR: build testMenuCommand list +// CODE GENERATOR: build testMenuGlobalArgsDict common/global argument list +// CODE GENERATOR: class member function declarations +// CODE GENERATOR: MAX11043 Command Name = Init (void) --> uint8_t +// CODE GENERATOR: Menu item hint description Menu item '!' +// CODE GENERATOR: Menu item '!' -- Menu item ! +// CODE GENERATOR: test menu case '!': +// CODE GENERATOR: helpString '! -- Init' +// CODE GENERATOR: CMD_ 'None' +// CODE GENERATOR: CommandName 'Init' +// CODE GENERATOR: CommandParamIn 'void' +// CODE GENERATOR: CommandReturnType 'uint8_t' +// CODE GENERATOR: CommandPre '' +// CODE GENERATOR: CommandDocParamIn '' +// CODE GENERATOR: CommandDocParamOut '' +// CODE GENERATOR: CommandPost '' +// CODE GENERATOR: CommandReturn '@return 1 on success; 0 on failure' +// CODE GENERATOR: MAX11043 Command Name = RegWrite (MAX11043_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: MAX11043 Command Name = RegWrite CMD_1aaa_aaaa_REGISTER_READ (MAX11043_CMD_enum_t commandByte, uint32_t regData) --> uint8_t +// CODE GENERATOR: MAX11043 Command Name = RegRead (MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t +// CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ +// CODE GENERATOR: MAX11043 Command Name = RegRead CMD_1aaa_aaaa_REGISTER_READ (MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t +// CODE GENERATOR: MAX11043 Command Name = RegSize (MAX11043_CMD_enum_t commandByte) --> uint8_t +// CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: MAX11043 Command Name = RegAddrOfCommand (MAX11043_CMD_enum_t commandByte) --> uint8_t +// CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: MAX11043 Command Name = IsRegReadCommand (MAX11043_CMD_enum_t commandByte) --> uint8_t +// CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: MAX11043 Command Name = RegName (MAX11043_CMD_enum_t commandByte) --> const char* +// CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: testMenuGlobalArgsDict scan global property list g_MAX11043_device + +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.VRef_xxxxxx +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.VRef_xxxxxx argname = VRef_xxxxxx +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['argtype'] = 'double' +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['usedBytestMenuItemName'] = 'None' + +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.ctrl +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.ctrl shadow of argname = ctrl +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.ctrl argname = ctrl +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['argtype'] = 'uint32_t' +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['usedBytestMenuItemName'] = 'None' + +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.pgaGain +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.pgaGain argname = pgaGain +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['argtype'] = 'uint8_t' +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['usedBytestMenuItemName'] = 'None' + +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.status +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.status shadow of argname = status +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.status argname = status +// CODE GENERATOR: testMenuGlobalArgsDict['status']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['status']['argtype'] = 'uint32_t' +// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedBytestMenuItemName'] = 'None' + +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.data0 +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.data0 shadow of argname = data0 +// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11043_device.data0 argname = data0 +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['argtype'] = 'uint32_t' +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedBytestMenuItemName'] = 'None' + +// CODE GENERATOR: testMenuGlobalArgsDict skip array property g_MAX11043_device.AINcode[11] + +// CODE GENERATOR: scan testMenuCommand list for items that can be shortened to single character +// CODE GENERATOR: shorten testMenuCommand to single character if unambiguous +// CODE GENERATOR: testMenuCommand '!' already single character + +// CODE GENERATOR: help menu +bool MAX11043_menu_help(CmdLine & cmdLine) +{ + // CODE GENERATOR: command: ! + // CODE GENERATOR: help: ! -- Init + cmdLine.serial().printf("\r\n ! -- Init"); + // + cmdLine.serial().printf("\r\n @ -- print MAX11043 configuration"); + +// CODE GENERATOR: help menu if has_register_write_command: *regname? -- read register; *regname=regvalue -- write register + cmdLine.serial().printf("\r\n *regname? -- read register\r\n *regname=regvalue -- write register"); + + // +// 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: testMenuGPIOItemsDict['CONVRUN']['PinName'] = 'CONVRUN' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['FunctionName'] = 'CONVRUNoutputValue' + +// CODE GENERATOR: warning: conflict testMenuGPIOItemsDict['CONVRUN']['PinName'] = 'CONVRUN' +#warning "No command case for 'CONVRUN' 'PinName' 'CONVRUN' due to conflict with reserved commands A-F, try changing pin name" +#warning "Randomly assigned command 'G' for 'CONVRUN' due to name conflict" +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['PinName'] = 'DACSTEP' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['FunctionName'] = 'DACSTEPoutputValue' + +// CODE GENERATOR: warning: conflict testMenuGPIOItemsDict['DACSTEP']['PinName'] = 'DACSTEP' +#warning "No command case for 'DACSTEP' 'PinName' 'DACSTEP' due to conflict with reserved commands A-F, try changing pin name" +#warning "Randomly assigned command 'H' for 'DACSTEP' due to name conflict" +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['PinName'] = 'EOC' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['Direction'] = 'input' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['FunctionName'] = 'EOCinputValue' + +// CODE GENERATOR: warning: conflict testMenuGPIOItemsDict['EOC']['PinName'] = 'EOC' +#warning "No command case for 'EOC' 'PinName' 'EOC' due to conflict with reserved commands A-F, try changing pin name" +#warning "Randomly assigned command 'I' for 'EOC' due to name conflict" +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['PinName'] = 'SHDN' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['FunctionName'] = 'SHDNoutputValue' + +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['PinName'] = 'UP_slash_DWNb' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['FunctionName'] = 'UP_slash_DWNboutputValue' + +// 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 'G' 'CONVRUN' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['PinName'] = 'CONVRUN' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['FunctionName'] = 'CONVRUNoutputValue' + cmdLine.serial().printf("\r\n G -- CONVRUN output GH high GL low"); // TODO: ExternFunctionGPIOPinCommand testMenuGPIOItemsDict +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'H' 'DACSTEP' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['PinName'] = 'DACSTEP' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['FunctionName'] = 'DACSTEPoutputValue' + cmdLine.serial().printf("\r\n H -- DACSTEP output HH high HL low"); // TODO: ExternFunctionGPIOPinCommand testMenuGPIOItemsDict +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'I' 'EOC' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['PinName'] = 'EOC' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['Direction'] = 'input' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['FunctionName'] = 'EOCinputValue' + cmdLine.serial().printf("\r\n I -- EOC input value"); // TODO: ExternFunctionGPIOPinCommand testMenuGPIOItemsDict +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'S' 'SHDN' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['PinName'] = 'SHDN' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['FunctionName'] = 'SHDNoutputValue' + cmdLine.serial().printf("\r\n S -- SHDN output SH high SL low"); // TODO: ExternFunctionGPIOPinCommand testMenuGPIOItemsDict +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'U' 'UP_slash_DWNb' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['PinName'] = 'UP_slash_DWNb' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['FunctionName'] = 'UP_slash_DWNboutputValue' + cmdLine.serial().printf("\r\n U -- UP_slash_DWNb output UH high UL low"); // TODO: ExternFunctionGPIOPinCommand testMenuGPIOItemsDict +// 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' + + // +} + +bool MAX11043_menu_onEOLcommandParser(CmdLine & cmdLine) +{ + +// CODE GENERATOR: testMenuGlobalArgsDict Consolidate common/global argument parsing + +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['argtype'] = 'double' +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['VRef_xxxxxx']['usedBytestMenuItemName'] = 'None' + // parse argument double VRef_xxxxxx + double VRef_xxxxxx = g_MAX11043_device.VRef_xxxxxx; // default to global property value + if (cmdLine.parse_double("VRef_xxxxxx", VRef_xxxxxx)) + { + g_MAX11043_device.VRef_xxxxxx = VRef_xxxxxx; // update global property value + } + +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['argtype'] = 'uint32_t' +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['ctrl']['usedBytestMenuItemName'] = 'None' + // parse argument uint32_t ctrl + uint32_t ctrl = g_MAX11043_device.ctrl; // default to global property value + if (cmdLine.parse_uint32_dec("ctrl", ctrl)) + { + g_MAX11043_device.ctrl = ctrl; // update global property value + } + +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['argtype'] = 'uint32_t' +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedBytestMenuItemName'] = 'None' + // parse argument uint32_t data0 + uint32_t data0 = g_MAX11043_device.data0; // default to global property value + if (cmdLine.parse_uint32_dec("data0", data0)) + { + g_MAX11043_device.data0 = data0; // update global property value + } + +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['argtype'] = 'uint8_t' +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['pgaGain']['usedBytestMenuItemName'] = 'None' + // parse argument uint8_t pgaGain + uint8_t pgaGain = g_MAX11043_device.pgaGain; // default to global property value + if (cmdLine.parse_uint8_dec("pgaGain", pgaGain)) + { + g_MAX11043_device.pgaGain = pgaGain; // update global property value + } + +// CODE GENERATOR: testMenuGlobalArgsDict['status']['alias'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['status']['argtype'] = 'uint32_t' +// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedByCommandName'] = 'None' +// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedBytestMenuItemName'] = 'None' + // parse argument uint32_t status + uint32_t status = g_MAX11043_device.status; // default to global property value + if (cmdLine.parse_uint32_dec("status", status)) + { + g_MAX11043_device.status = status; // update global property value + } + + switch (cmdLine[0]) + { +// CODE GENERATOR: generate * command read/write reg *reg? *reg=value + case '*': + { + // if buffer starts with a regName: + // for each reg value (0..n) if(cmdLine.has_keyword(device.regName(r))): + cmdLine.serial().printf(" scan RegName...\r\n"); + for (uint8_t regAddress = 0; regAddress < 0x80; regAddress++) + { + uint32_t regData = 0; + bool is_regname_query = false; + bool is_regname_assignment = false; + if (cmdLine.parse_uint32_dec(g_MAX11043_device.RegName((MAX11043::MAX11043_CMD_enum_t)regAddress), regData)) + { + cmdLine.serial().printf(" regAddress=0x%2.2X\r\n", (regAddress & 0xFF)); + cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11043_device.RegName((MAX11043::MAX11043_CMD_enum_t)regAddress)); + // accept regName "?" as "RegRead" by name + is_regname_query = (cmdLine.chSeparator == '?'); + is_regname_assignment = (cmdLine.chSeparator == '='); + if (is_regname_query) + { + cmdLine.serial().printf(" RegRead"); + g_MAX11043_device.RegRead((MAX11043::MAX11043_CMD_enum_t)regAddress, ®Data); + cmdLine.serial().printf("regData=0x%6.6x\r\n", (regData & 0x00FFFFFF)); + return true; // command handled by MAX11043 + } + // accept regName "=0x123456" as "RegWrite" by name + if (is_regname_assignment) + { + cmdLine.serial().printf(" RegWrite"); + cmdLine.serial().printf("regData=0x%6.6x\r\n", (regData & 0x00FFFFFF)); + g_MAX11043_device.RegWrite((MAX11043::MAX11043_CMD_enum_t)regAddress, regData); + return true; // command handled by MAX11043 + } + } + } // end for regAddr + // not a valid register name + // read "all" registers by name + const uint8_t readAllRegFirst = 0x00; // first MAX11043 register address for read-all block + const uint8_t readAllRegLast = 0x39; // last MAX11043 register address for read-all block + Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11043_device.onSPIprint; + g_MAX11043_device.onSPIprint = NULL; + for (uint8_t regAddress = readAllRegFirst; regAddress <= readAllRegLast; regAddress++) + { + uint32_t regData = 0; + if (g_MAX11043_device.RegSize((MAX11043::MAX11043_CMD_enum_t)regAddress) == 0) continue; // skip undefined regs + if (g_MAX11043_device.RegRead((MAX11043::MAX11043_CMD_enum_t)regAddress, ®Data) == 0) continue; // skip unreadable regs + cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11043_device.RegName((MAX11043::MAX11043_CMD_enum_t)regAddress), regData); + } // end for regAddr + g_MAX11043_device.onSPIprint = saved_onSPIprint_handler; + return true; // command handled by MAX11043 + } + break; + +// CODE GENERATOR: generate @ command print global property values of g_MAX11043_device + case '@': + { +// CODE GENERATOR: @ command print double g_MAX11043_device.VRef_xxxxxx + cmdLine.serial().printf("VRef_xxxxxx = "); + cmdLine.serial().printf("%f\r\n", g_MAX11043_device.VRef_xxxxxx); +// CODE GENERATOR: @ command print uint32_t g_MAX11043_device.ctrl + cmdLine.serial().printf("ctrl = "); + cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11043_device.ctrl, g_MAX11043_device.ctrl); +// CODE GENERATOR: @ command print uint8_t g_MAX11043_device.pgaGain + cmdLine.serial().printf("pgaGain = "); + cmdLine.serial().printf("%d = 0x%2.2x\r\n", g_MAX11043_device.pgaGain, g_MAX11043_device.pgaGain); +// CODE GENERATOR: @ command print uint32_t g_MAX11043_device.status + cmdLine.serial().printf("status = "); + cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11043_device.status, g_MAX11043_device.status); +// CODE GENERATOR: @ command print uint32_t g_MAX11043_device.data0 + cmdLine.serial().printf("data0 = "); + cmdLine.serial().printf("%d = 0x%8.8x\r\n", g_MAX11043_device.data0, g_MAX11043_device.data0); +// CODE GENERATOR: @ command print uint32_t array g_MAX11043_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\r\n", g_MAX11043_device.AINcode[index], g_MAX11043_device.AINcode[index]); + } + return true; // command handled by MAX11043 + break; + } +// 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 'G' 'CONVRUN' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['PinName'] = 'CONVRUN' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['CONVRUN']['FunctionName'] = 'CONVRUNoutputValue' + case 'G': + { + switch (cmdLine[1]) + { + case 'H': + { + g_MAX11043_device.CONVRUNoutputValue(1); + break; + } + case 'L': + { + g_MAX11043_device.CONVRUNoutputValue(0); + break; + } + } + return true; // command handled by MAX11043 + break; + } + +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'H' 'DACSTEP' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['PinName'] = 'DACSTEP' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['DACSTEP']['FunctionName'] = 'DACSTEPoutputValue' + case 'H': + { + switch (cmdLine[1]) + { + case 'H': + { + g_MAX11043_device.DACSTEPoutputValue(1); + break; + } + case 'L': + { + g_MAX11043_device.DACSTEPoutputValue(0); + break; + } + } + return true; // command handled by MAX11043 + break; + } + +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'I' 'EOC' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['PinName'] = 'EOC' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['Direction'] = 'input' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['EOC']['FunctionName'] = 'EOCinputValue' + case 'I': + { + // TODO capture and print input Value + cmdLine.serial().printf("%d", g_MAX11043_device.EOCinputValue()); + return true; // command handled by MAX11043 + break; + } + +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'S' 'SHDN' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['PinName'] = 'SHDN' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['SHDN']['FunctionName'] = 'SHDNoutputValue' + case 'S': + { + switch (cmdLine[1]) + { + case 'H': + { + g_MAX11043_device.SHDNoutputValue(1); + break; + } + case 'L': + { + g_MAX11043_device.SHDNoutputValue(0); + break; + } + } + return true; // command handled by MAX11043 + break; + } + +// CODE GENERATOR: ExternFunctionGPIOPinCommand 'U' 'UP_slash_DWNb' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['PinName'] = 'UP_slash_DWNb' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['Direction'] = 'output' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['Operation'] = 'Value' +// CODE GENERATOR: testMenuGPIOItemsDict['UP_slash_DWNb']['FunctionName'] = 'UP_slash_DWNboutputValue' + case 'U': + { + switch (cmdLine[1]) + { + case 'H': + { + g_MAX11043_device.UP_slash_DWNboutputValue(1); + break; + } + case 'L': + { + g_MAX11043_device.UP_slash_DWNboutputValue(0); + break; + } + } + return true; // command handled by MAX11043 + break; + } + +// 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 + // has_register_write_command: case '0'..'9','A'..'F','a'..'f' letters are reserved for bitstream commands +// CODE GENERATOR: top of loop: testMenuCommand="!", testMenuFirstCharHandler="None" +// CODE GENERATOR: test menu case '!': +// CODE GENERATOR: helpString '! -- Init' +// CODE GENERATOR: CMD_ 'None' +// CODE GENERATOR: CommandName 'Init' +// CODE GENERATOR: CommandParamIn 'void' +// CODE GENERATOR: CommandReturnType 'uint8_t' +// CODE GENERATOR: CommandPre '' +// CODE GENERATOR: CommandDocParamIn '' +// CODE GENERATOR: CommandDocParamOut '' +// CODE GENERATOR: CommandPost '' +// CODE GENERATOR: CommandReturn '@return 1 on success; 0 on failure' + // case '!': // (single character) (testMenuFirstCharHandler="None") + case '!': + { + // test menu command '!' handler: + // helpString='! -- Init' + // CMD_='None' + // CommandName='Init' + // CommandParamIn='void' + // CommandReturnType='uint8_t' + // @Pre='' + // @Param[in]='' + // @Param[out]='' + // @Post='' + // displayPost='' + // @Return='@return 1 on success; 0 on failure' + cmdLine.serial().printf("Init"); + // call function Init + uint8_t result = g_MAX11043_device.Init(); + cmdLine.serial().printf(" =%d", result); + return true; // command handled by MAX11043 +// CODE GENERATOR: bottom of loop: testMenuCommand="!", testMenuFirstCharHandler="None" + } // end case '!' + break; + + // has_register_write_command: case '0'..'9','A'..'F','a'..'f' letters are reserved for bitstream commands + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + { + // hexadecimal codes get parsed as bytecodes + // + // parse_byteCount_byteList_dec() assumes all keyword args have already been removed from the buffer + // parse cmdLine byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT]; + #define MAX_SPI_BYTE_COUNT 32 + size_t byteCount = byteCount; + static char mosiData[MAX_SPI_BYTE_COUNT]; + static char misoData[MAX_SPI_BYTE_COUNT]; + 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 'IsRegReadCommand' + // register_write_function 'RegWrite' + // register_name_function 'RegName' + // register_size_function 'RegSize' +// CODE GENERATOR: does the chip have a defined CMD_1aaa_aaaa_REGISTER_READ bit? + // MAX11043::MAX11043_CMD_enum_t regAddress = (MAX11043::MAX11043_CMD_enum_t)((mosiData[0] &~ MAX11043::CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); + MAX11043::MAX11043_CMD_enum_t commandByte = (MAX11043::MAX11043_CMD_enum_t)(mosiData[0]); + int regAddress = g_MAX11043_device.RegAddrOfCommand(commandByte); + cmdLine.serial().printf(" regAddress=0x%2.2x\r\n", (regAddress & 0xFF)); + cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11043_device.RegName(commandByte)); + uint32_t regData = 0; + int regSize = g_MAX11043_device.RegSize(commandByte); + cmdLine.serial().printf(" RegSize=%d\r\n", regSize); + switch(regSize) + { + case 8: + regData = ((uint32_t)mosiData[1] & 0xFF); + break; + case 16: + regData = (((uint32_t)mosiData[1] & 0xFF) << 8) + ((uint32_t)mosiData[2] & 0xFF); + break; + case 24: + regData = (((uint32_t)mosiData[1] & 0xFF) << 16) + (((uint32_t)mosiData[2] & 0xFF) << 8) + ((uint32_t)mosiData[3] & 0xFF); + break; + } +// CODE GENERATOR: does the chip have a defined CMD_1aaa_aaaa_REGISTER_READ bit? + // if ((byteCount == 1) || (regAddress & MAX11043::CMD_1aaa_aaaa_REGISTER_READ)) + if ((byteCount == 1) || g_MAX11043_device.IsRegReadCommand(commandByte)) + { + cmdLine.serial().printf(" RegRead"); + g_MAX11043_device.RegRead(commandByte, ®Data); + 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_MAX11043_device.RegWrite(commandByte, regData); + } + // is there support function shadow regValue of regAddr? + } + return true; // command handled by MAX11043 + // + } // end case '0'..'9','A'..'F','a'..'f' + break; + } // end switch (cmdLine[0]) + return false; // command not handled by MAX11043 +} // end bool MAX11043_menu_onEOLcommandParser(CmdLine & cmdLine) + +// CODE GENERATOR: class declaration statement close +