Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 MAX5715 USBDevice
Test_Menu_MAX5715.cpp
00001 // /******************************************************************************* 00002 // * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. 00003 // * 00004 // * Permission is hereby granted, free of charge, to any person obtaining a 00005 // * copy of this software and associated documentation files (the "Software"), 00006 // * to deal in the Software without restriction, including without limitation 00007 // * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 // * and/or sell copies of the Software, and to permit persons to whom the 00009 // * Software is furnished to do so, subject to the following conditions: 00010 // * 00011 // * The above copyright notice and this permission notice shall be included 00012 // * in all copies or substantial portions of the Software. 00013 // * 00014 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 // * OTHER DEALINGS IN THE SOFTWARE. 00021 // * 00022 // * Except as contained in this notice, the name of Maxim Integrated 00023 // * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 // * Products, Inc. Branding Policy. 00025 // * 00026 // * The mere transfer of this software does not imply any licenses 00027 // * of trade secrets, proprietary technology, copyrights, patents, 00028 // * trademarks, maskwork rights, or any other form of intellectual 00029 // * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 // * ownership rights. 00031 // ******************************************************************************* 00032 // */ 00033 00034 #include "mbed.h" 00035 #include "MAX5715.h" 00036 #include "CmdLine.h" 00037 00038 //-------------------------------------------------- 00039 // tolerate AT commands, which may be sent during probe, such as: 00040 // AT 00041 // AT+CGMI -- request manufacturer identification AT+CMGI=? 00042 // AT+CGMM -- request manufacturer model 00043 // AT%IPSYS? 00044 // ATE0 -- echo disable 00045 // ATV1 -- verbose result codes OK | ERROR | NO CARRIER 00046 // AT+CMEE=1 00047 // ATX4 00048 // AT&C1 00049 // ATE0 00050 // AT+CMEE=1 00051 // AT+GCAP 00052 // ATI 00053 // AT+CPIN? 00054 // AT+CGMM 00055 #ifndef IGNORE_AT_COMMANDS 00056 #define IGNORE_AT_COMMANDS 1 00057 #endif 00058 00059 extern MAX5715 g_MAX5715_device; // defined in main.cpp 00060 00061 bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine) 00062 { 00063 switch (cmdLine[0]) 00064 { 00065 case '0': 00066 { 00067 // recommended for hex command codes 00..0F 00068 // TODO: cmdLine.serial().printf("\r\n 0 ch=? code=? -- CODEn"); 00069 // Menu 0 ch=? code=?) CODEn 00070 // MAX5715_CODEn(uint8_t channel, uint16_t dacCodeLsbs); 00071 // VERIFY: parse strCommandArgs for additional arguments including key=value pairs 00072 // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs); 00073 uint16_t ch = g_MAX5715_device.channelNumber_0_3; 00074 if (cmdLine.parse_uint16_dec("ch", ch)) 00075 { 00076 } 00077 uint16_t code = g_MAX5715_device.CODE[ch]; 00078 if (cmdLine.parse_uint16_dec("code", code)) 00079 { 00080 } 00081 cmdLine.serial().printf("CODEn ch=%d code=%d", ch, code); 00082 g_MAX5715_device.CODEn(ch, code); 00083 return true; // command was handled by MAX5715 00084 } 00085 break; 00086 case '1': 00087 { 00088 // recommended for hex command codes 10..1F 00089 // TODO: cmdLine.serial().printf("\r\n 1 ch=? -- LOADn"); 00090 // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs); 00091 uint16_t ch = g_MAX5715_device.channelNumber_0_3; 00092 if (cmdLine.parse_uint16_dec("ch", ch)) 00093 { 00094 } 00095 cmdLine.serial().printf("LOADn ch=%d", ch); 00096 g_MAX5715_device.LOADn(ch); 00097 return true; // command was handled by MAX5715 00098 } 00099 break; 00100 case '2': 00101 { 00102 // recommended for hex command codes 20..2F 00103 // TODO: cmdLine.serial().printf("\r\n 2 ch=? code=? -- CODEnLOADall"); 00104 // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs); 00105 uint16_t ch = g_MAX5715_device.channelNumber_0_3; 00106 if (cmdLine.parse_uint16_dec("ch", ch)) 00107 { 00108 } 00109 uint16_t code = g_MAX5715_device.CODE[ch]; 00110 if (cmdLine.parse_uint16_dec("code", code)) 00111 { 00112 } 00113 cmdLine.serial().printf("CODEnLOADall ch=%d code=%d", ch, code); 00114 g_MAX5715_device.CODEnLOADall(ch, code); 00115 return true; // command was handled by MAX5715 00116 } 00117 break; 00118 case '3': 00119 { 00120 // recommended for hex command codes 30..3F 00121 // TODO: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn"); 00122 // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs); 00123 uint16_t ch = g_MAX5715_device.channelNumber_0_3; 00124 uint16_t code; 00125 if (cmdLine.parse_uint16_dec("ch", ch)) 00126 { 00127 } 00128 if (cmdLine.parse_uint16_dec("code", code)) 00129 { 00130 } 00131 cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code); 00132 g_MAX5715_device.CODEnLOADn(ch, code); 00133 return true; // command was handled by MAX5715 00134 } 00135 break; 00136 case '4': 00137 { 00138 // recommended for hex command codes 40..4F 00139 switch (cmdLine[1]) 00140 { 00141 case '0': 00142 { 00143 // cmdLine.serial().printf("\r\n 40 ch=? -- POWERn_Normal"); 00144 cmdLine.serial().printf( 00145 "channel_dcba=%d, POWERn_Normal)", 00146 g_MAX5715_device.channels_bitmask_DCBA); 00147 g_MAX5715_device.POWER(g_MAX5715_device. 00148 channels_bitmask_DCBA, 00149 MAX5715::POWERn_Normal); 00150 return true; // command was handled by MAX5715 00151 } 00152 break; 00153 case '1': 00154 { 00155 // cmdLine.serial().printf("\r\n 41 ch=? -- POWERn_PD1k"); 00156 cmdLine.serial().printf( 00157 "channel_dcba=%d, POWERn_PD1k)", 00158 g_MAX5715_device.channels_bitmask_DCBA); 00159 g_MAX5715_device.POWER(g_MAX5715_device. 00160 channels_bitmask_DCBA, 00161 MAX5715::POWERn_PD1k); 00162 return true; // command was handled by MAX5715 00163 } 00164 break; 00165 case '2': 00166 { 00167 // cmdLine.serial().printf("\r\n 42 ch=? -- POWERn_PD100k"); 00168 cmdLine.serial().printf( 00169 "channel_dcba=%d, POWERn_PD100k)", 00170 g_MAX5715_device.channels_bitmask_DCBA); 00171 g_MAX5715_device.POWER(g_MAX5715_device. 00172 channels_bitmask_DCBA, 00173 MAX5715::POWERn_PD100k); 00174 return true; // command was handled by MAX5715 00175 } 00176 break; 00177 case '3': 00178 { 00179 // cmdLine.serial().printf("\r\n 43 ch=? -- POWERn_PDHiZ"); 00180 cmdLine.serial().printf( 00181 "channel_dcba=%d, POWERn_PDHiZ)", 00182 g_MAX5715_device.channels_bitmask_DCBA); 00183 g_MAX5715_device.POWER(g_MAX5715_device. 00184 channels_bitmask_DCBA, 00185 MAX5715::POWERn_PDHiZ); 00186 return true; // command was handled by MAX5715 00187 } 00188 break; 00189 } 00190 break; 00191 } 00192 break; 00193 case '5': 00194 { 00195 // recommended for hex command codes 50..5F 00196 switch (cmdLine[1]) 00197 { 00198 case '0': 00199 { 00200 // cmdLine.serial().printf("\r\n 50 -- SW_CLEAR"); 00201 cmdLine.serial().printf("SW_CLEAR"); 00202 g_MAX5715_device.SW_CLEAR(); 00203 return true; // command was handled by MAX5715 00204 } 00205 break; 00206 case '1': 00207 { 00208 // cmdLine.serial().printf("\r\n 51 -- SW_RESET"); 00209 cmdLine.serial().printf("SW_RESET"); 00210 g_MAX5715_device.SW_RESET(); 00211 return true; // command was handled by MAX5715 00212 } 00213 break; 00214 } 00215 } 00216 break; 00217 case '6': 00218 { 00219 // recommended for hex command codes 60..6F 00220 switch (cmdLine[1]) 00221 { 00222 case '0': 00223 { 00224 // cmdLine.serial().printf("\r\n 60 ch=? -- CONFIGn_LATCHED"); 00225 cmdLine.serial().printf( 00226 "MAX5715_CONFIGn_LATCHED(channel_dcba=%d)", 00227 g_MAX5715_device. 00228 channels_bitmask_DCBA); 00229 g_MAX5715_device.CONFIGn_LATCHED(g_MAX5715_device. 00230 channels_bitmask_DCBA); 00231 return true; // command was handled by MAX5715 00232 } 00233 break; 00234 case '1': 00235 { 00236 // cmdLine.serial().printf("\r\n 61 ch=? -- CONFIGn_TRANSPARENT"); 00237 cmdLine.serial().printf( 00238 "MAX5715_CONFIGn_TRANSPARENT(channel_dcba=%d)", 00239 g_MAX5715_device. 00240 channels_bitmask_DCBA); 00241 g_MAX5715_device.CONFIGn_TRANSPARENT( 00242 g_MAX5715_device.channels_bitmask_DCBA); 00243 return true; // command was handled by MAX5715 00244 } 00245 break; 00246 case '8': 00247 { 00248 // cmdLine.serial().printf("\r\n 68 -- CONFIGall_LATCHED"); 00249 cmdLine.serial().printf( 00250 "MAX5715_CONFIGall_LATCHED()"); 00251 g_MAX5715_device.CONFIGall_LATCHED(); 00252 return true; // command was handled by MAX5715 00253 } 00254 break; 00255 case '9': 00256 { 00257 // cmdLine.serial().printf("\r\n 69 -- CONFIGall_TRANSPARENT"); 00258 cmdLine.serial().printf( 00259 "MAX5715_CONFIGall_TRANSPARENT()"); 00260 g_MAX5715_device.CONFIGall_TRANSPARENT(); 00261 return true; // command was handled by MAX5715 00262 } 00263 break; 00264 } 00265 } 00266 break; 00267 case '7': 00268 { 00269 // recommended for hex command codes 70..7F 00270 switch (cmdLine[1]) 00271 { 00272 case '0': 00273 { 00274 // cmdLine.serial().printf("\r\n 70 -- REF_EXT"); 00275 cmdLine.serial().printf( 00276 "MAX5715_REF(REF_EXT)"); 00277 g_MAX5715_device.REF(MAX5715::REF_EXT); 00278 return true; // command was handled by MAX5715 00279 } 00280 break; 00281 case '1': 00282 { 00283 // cmdLine.serial().printf("\r\n 71 -- REF_2V500"); 00284 cmdLine.serial().printf( 00285 "MAX5715_REF(REF_2V500)"); 00286 g_MAX5715_device.REF(MAX5715::REF_2V500); 00287 return true; // command was handled by MAX5715 00288 } 00289 break; 00290 case '2': 00291 { 00292 // cmdLine.serial().printf("\r\n 72 -- REF_2V048"); 00293 cmdLine.serial().printf( 00294 "MAX5715_REF(REF_2V048)"); 00295 g_MAX5715_device.REF(MAX5715::REF_2V048); 00296 return true; // command was handled by MAX5715 00297 } 00298 break; 00299 case '3': 00300 { 00301 // cmdLine.serial().printf("\r\n 73 -- REF_4V096"); 00302 cmdLine.serial().printf( 00303 "MAX5715_REF(REF_4V096)"); 00304 g_MAX5715_device.REF(MAX5715::REF_4V096); 00305 return true; // command was handled by MAX5715 00306 } 00307 break; 00308 case '4': 00309 { 00310 // cmdLine.serial().printf("\r\n 74 -- REF_AlwaysOn_EXT"); 00311 cmdLine.serial().printf( 00312 "MAX5715_REF(REF_AlwaysOn_EXT)"); 00313 g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_EXT); 00314 return true; // command was handled by MAX5715 00315 } 00316 break; 00317 case '5': 00318 { 00319 // cmdLine.serial().printf("\r\n 75 -- REF_AlwaysOn_2V500"); 00320 cmdLine.serial().printf( 00321 "MAX5715_REF(REF_AlwaysOn_2V500)"); 00322 g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500); 00323 return true; // command was handled by MAX5715 00324 } 00325 break; 00326 case '6': 00327 { 00328 // cmdLine.serial().printf("\r\n 76 -- REF_AlwaysOn_2V048"); 00329 cmdLine.serial().printf( 00330 "MAX5715_REF(REF_AlwaysOn_2V048)"); 00331 g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048); 00332 return true; // command was handled by MAX5715 00333 } 00334 break; 00335 case '7': 00336 { 00337 // cmdLine.serial().printf("\r\n 77 -- REF_AlwaysOn_4V096"); 00338 cmdLine.serial().printf( 00339 "MAX5715_REF(REF_AlwaysOn_4V096)"); 00340 g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_4V096); 00341 return true; // command was handled by MAX5715 00342 } 00343 break; 00344 } 00345 } 00346 break; 00347 case '8': 00348 { 00349 // recommended for hex command codes 80..8F 00350 switch (cmdLine[1]) 00351 { 00352 case '0': 00353 { 00354 // TODO: cmdLine.serial().printf("\r\n 80 code=? -- CODEall"); 00355 // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs); 00356 g_MAX5715_device.channels_bitmask_DCBA = 0xFF; // store g_MAX5715_device.CODE[allChannels] 00357 uint16_t code = g_MAX5715_device.CODE[0]; 00358 if (cmdLine.parse_uint16_dec("code", code)) 00359 { 00360 } 00361 cmdLine.serial().printf("CODEall code=%d", code); 00362 g_MAX5715_device.CODEall(code); 00363 return true; // command was handled by MAX5715 00364 } 00365 break; 00366 case '1': 00367 { 00368 // TODO: cmdLine.serial().printf("\r\n 81 -- LOADall"); 00369 cmdLine.serial().printf("LOADall"); 00370 g_MAX5715_device.LOADall(); 00371 return true; // command was handled by MAX5715 00372 } 00373 break; 00374 case '2': 00375 { 00376 // TODO: cmdLine.serial().printf("\r\n 82 code=? -- CODEallLOADall"); 00377 uint16_t code = g_MAX5715_device.CODE[0]; 00378 if (cmdLine.parse_uint16_dec("code", code)) 00379 { 00380 } 00381 cmdLine.serial().printf("CODEallLOADall code=%d", code); 00382 g_MAX5715_device.CODEallLOADall(code); 00383 return true; // command was handled by MAX5715 00384 } 00385 break; 00386 } 00387 } 00388 break; 00389 case '9': 00390 { 00391 // recommended for hex command codes 90..9F 00392 } 00393 break; 00394 case 'a': case 'A': 00395 { 00396 // recommended for hex command codes A0..AF 00397 switch (cmdLine[1]) 00398 { 00399 case 't': case 'T': 00400 #if IGNORE_AT_COMMANDS 00401 # if HAS_DAPLINK_SERIAL 00402 cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str()); 00403 # endif // HAS_DAPLINK_SERIAL 00404 // AT command: skip the prompt to avoid confusing modem detector 00405 return false; // command not handled 00406 #endif // IGNORE_AT_COMMANDS 00407 } 00408 } 00409 break; 00410 case 'b': case 'B': 00411 { 00412 // recommended for hex command codes B0..BF 00413 } 00414 break; 00415 case 'c': case 'C': 00416 { 00417 // recommended for hex command codes C0..CF 00418 // // MAX5717 menu function to drive MAX5717_CLRb_Pin CLR# 00419 // cmdLine.serial().printf("\r\n C -- CLR# pulse CH high CL low"); 00420 switch (cmdLine[1]) 00421 { 00422 default: 00423 // g_MAX5715_device.CLRboutputPulseLow(); 00424 g_MAX5715_device.CLRboutputValue(1); 00425 g_MAX5715_device.CLRboutputValue(0); 00426 g_MAX5715_device.CLRboutputValue(1); 00427 break; 00428 case 'H': case 'h': case '1': 00429 g_MAX5715_device.CLRboutputValue(1); // GPIOoutputCLRb(int isLogicHigh); 00430 break; 00431 case 'L': case 'l': case '0': 00432 g_MAX5715_device.CLRboutputValue(0); // GPIOoutputCLRb(int isLogicHigh); 00433 break; 00434 } 00435 return true; // command was handled by MAX5715 00436 } 00437 break; 00438 case 'd': case 'D': 00439 { 00440 // recommended for hex command codes D0..DF 00441 } 00442 break; 00443 case 'e': case 'E': 00444 { 00445 // recommended for hex command codes E0..EF 00446 } 00447 break; 00448 case 'f': case 'F': 00449 { 00450 // recommended for hex command codes F0..FF 00451 } 00452 break; 00453 case 'l': case 'L': 00454 { 00455 // // MAX5717 menu function to drive MAX5717_LDACb_Pin LDAC# 00456 // cmdLine.serial().printf("\r\n L -- LDAC# pulse LH high LL low"); 00457 switch (cmdLine[1]) 00458 { 00459 default: 00460 // g_MAX5715_device.LDACboutputPulseLow(); 00461 g_MAX5715_device.LDACboutputValue(1); 00462 g_MAX5715_device.LDACboutputValue(0); 00463 g_MAX5715_device.LDACboutputValue(1); 00464 break; 00465 case 'H': case 'h': case '1': 00466 g_MAX5715_device.LDACboutputValue(1); // GPIOoutputLDACb(int isLogicHigh); 00467 break; 00468 case 'L': case 'l': case '0': 00469 g_MAX5715_device.LDACboutputValue(0); // GPIOoutputLDACb(int isLogicHigh); 00470 break; 00471 } 00472 return true; // command was handled by MAX5715 00473 } 00474 break; 00475 case 'x': case 'X': 00476 { 00477 } 00478 break; 00479 case 'y': case 'Y': 00480 { 00481 } 00482 break; 00483 case 'z': case 'Z': 00484 { 00485 } 00486 break; 00487 case '~': // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command 00488 { 00489 // TODO: '~' is not recommended for menu commands, interferes with ssh 00490 switch (cmdLine[1]) 00491 { 00492 default: 00493 { 00494 #if IGNORE_AT_COMMANDS 00495 # if HAS_DAPLINK_SERIAL 00496 cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", 00497 cmdLine.str()); 00498 # endif // HAS_DAPLINK_SERIAL 00499 #endif // IGNORE_AT_COMMANDS 00500 } 00501 } 00502 } 00503 break; 00504 case '+': // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command 00505 { 00506 #if IGNORE_AT_COMMANDS 00507 # if HAS_DAPLINK_SERIAL 00508 cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str()); 00509 # endif // HAS_DAPLINK_SERIAL 00510 #endif // IGNORE_AT_COMMANDS 00511 } 00512 break; 00513 case '@': 00514 { 00515 // // 00516 // // Menu @ -- print device configuration 00517 // TODO: cmdLine.serial().printf("\r\n @ -- print MAX5715 configuration"); 00518 // // 00519 // print shadow register configuration 00520 // 00521 // shadow of write-only register CODE dddd_dddd_dddd_0000 00522 //~ int16_t CMD_1000_CODE; 00523 int index = 0; 00524 for (index = 0; index < 4; index++) 00525 { 00526 cmdLine.serial().printf("CODE %c=0x%4.4x MAX5715_VoltageOfCode(%d)=%5.3fV\r\n", 00527 (char)('A' + index), 00528 (g_MAX5715_device.Shadow_0010_nnnn_CODE[index] & 0xFFFF), 00529 g_MAX5715_device.CODE[index], 00530 g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[index]) 00531 ); 00532 } 00533 // 00534 cmdLine.serial().printf("\r\n"); 00535 // 00536 // 00537 // Menu @) print MAX5715 configuration AND g_MAX5715_device globals 00538 // 00539 #if 1 // SUPPORT_CHANNELS 00540 cmdLine.serial().printf("channelNumber_0_3=%d channels_bitmask_DCBA=%d\r\n", 00541 (g_MAX5715_device.channelNumber_0_3 & 0xFFFF), 00542 (g_MAX5715_device.channels_bitmask_DCBA & 0xFFFF)); 00543 #endif // SUPPORT_CHANNELS 00544 // 00545 cmdLine.serial().printf("VRef=%5.3fV\r\n", g_MAX5715_device.VRef); 00546 // dtostrf width and precision: 3.3V / 1024 LSB = 0.00322265625 volts per LSB 00547 return true; // command was handled by MAX5715 00548 } 00549 break; 00550 } // end switch (cmdLine[0]) 00551 return false; // command not handled by MAX5715 00552 } // end bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine) 00553
Generated on Fri Jul 22 2022 03:14:07 by 1.7.2