Internal_Datalogger but with USB support removed (for MAX40108 Demo board), proof of concept that MAX32625 can be used successfully with VDDB(USB) left unpowered, as long as the USB library is not used.

Dependencies:   max32625pico CmdLine

DataLogger_Internal.cpp

Committer:
whismanoid
Date:
2021-02-02
Revision:
13:184a08909405
Parent:
12:2dfc1f2009e0
Child:
14:d4092094dbfe

File content as of revision 13:184a08909405:

// /*******************************************************************************
// * 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.
// *******************************************************************************
// */
// *******************************************************************************
//          COM port settings are 9600 baud 8N1
// *******************************************************************************
//---------- CODE GENERATOR: DataLogHelloCppCodeList
// 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
//      - Please note the last supported version is Mbed OS 6.3.
//      - 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://developer.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
//      - #include "max32625pico.h"
//      - add https://os.mbed.com/users/switches/code/max32625pico/
//      - remove max32630fthr library (if present)
//      - remove MAX32620FTHR library (if present)
//      - not tested yet
//      - see https://os.mbed.com/users/switches/code/max32625pico/
//      - see https://os.mbed.com/users/switches/code/PICO_board_demo/
//      - see https://os.mbed.com/users/switches/code/PICO_USB_I2C_SPI/
//      - see https://os.mbed.com/users/switches/code/SerialInterface/
//      - Note: To load the MAX32625PICO firmware, hold the button while
//        connecting the USB cable, then copy firmware bin file 
//        to the MAINTENANCE drive.
//      - see https://os.mbed.com/platforms/MAX32625PICO/
//      - see https://os.mbed.com/teams/MaximIntegrated/wiki/MAX32625PICO-Firmware-Updates
//
// end Platform_Include_Boilerplate

//--------------------------------------------------
// Option to use SPI connected ADC
#ifndef SPI_ADC_DeviceName
#define SPI_ADC_DeviceName MAX11410
#undef SPI_ADC_DeviceName
#endif
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
#include "MAX11410.h"
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC

#if defined(TARGET)
// TARGET_NAME macros from targets/TARGET_Maxim/TARGET_MAX32625/device/mxc_device.h
// Create a string definition for the TARGET
#define STRING_ARG(arg) #arg
#define STRING_NAME(name) STRING_ARG(name)
#define TARGET_NAME STRING_NAME(TARGET)
#elif defined(TARGET_MAX32600)
#define TARGET_NAME "MAX32600"
#elif defined(TARGET_LPC1768)
#define TARGET_NAME "LPC1768"
#elif defined(TARGET_NUCLEO_F446RE)
#define TARGET_NAME "NUCLEO_F446RE"
#elif defined(TARGET_NUCLEO_F401RE)
#define TARGET_NAME "NUCLEO_F401RE"
#else
#error TARGET NOT DEFINED
#endif
#if defined(TARGET_MAX32630)
//--------------------------------------------------
// TARGET=MAX32630FTHR ARM Cortex-M4F 96MHz 2048kB Flash 512kB SRAM
//             +-------------[microUSB]-------------+
//             | J1         MAX32630FTHR        J2  |
//      ______ | [ ] RST                    GND [ ] |
//      ______ | [ ] 3V3                    BAT+[ ] |
//      ______ | [ ] 1V8                  reset SW1 |
//      ______ | [ ] GND       J4               J3  |
// analogIn0/4 | [a] AIN_0 1.2Vfs     (bat) SYS [ ] | switched BAT+
// analogIn1/5 | [a] AIN_1 1.2Vfs           PWR [ ] | external pwr btn
// analogIn2   | [a] AIN_2 1.2Vfs      +5V VBUS [ ] | USB +5V power
// analogIn3   | [a] AIN_3 1.2Vfs   1-WIRE P4_0 [d] | D0 dig9
//  (I2C2.SDA) | [d] P5_7  SDA2        SRN P5_6 [d] | D1 dig8
//  (I2C2.SCL) | [d] P6_0  SCL2      SDIO3 P5_5 [d] | D2 dig7
//    D13/SCLK | [s] P5_0  SCLK      SDIO2 P5_4 [d] | D3 dig6
//    D11/MOSI | [s] P5_1  MOSI       SSEL P5_3 [d] | D4 dig5
//    D12/MISO | [s] P5_2  MISO        RTS P3_3 [d] | D5 dig4
//    D10/CS   | [s] P3_0  RX          CTS P3_2 [d] | D6 dig3
//    D9  dig0 | [d] P3_1  TX          SCL P3_5 [d] | D7 dig2
//      ______ | [ ] GND               SDA P3_4 [d] | D8 dig1
//             |                                    |
//             | XIP Flash      MAX14690N           |
//             | XIP_SCLK P1_0  SDA2 P5_7           |
//             | XIP_MOSI P1_1  SCL2 P6_0           |
//             | XIP_MISO P1_2  PMIC_INIT P3_7      |
//             | XIP_SSEL P1_3  MPC P2_7            |
//             | XIP_DIO2 P1_4  MON AIN_0           |
//             | XIP_DIO3 P1_5                      |
//             |                                    |
//             | PAN1326B     MicroSD        LED    |
//             | BT_RX  P0_0  SD_SCLK P0_4   r P2_4 |
//             | BT_TX  P0_1  SD_MOSI P0_5   g P2_5 |
//             | BT_CTS P0_2  SD_MISO P0_6   b P2_6 |
//             | BT_RTS P0_3  SD_SSEL P0_7          |
//             | BT_RST P1_6  DETECT  P2_2          |
//             | BT_CLK P1_7               SW2 P2_3 |
//             +------------------------------------+
// MAX32630FTHR board has MAX14690 PMIC on I2C bus (P5_7 SDA, P6_0 SCL) at slave address 0101_000r 0x50 (or 0x28 for 7 MSbit address).
// MAX32630FTHR board has BMI160 accelerometer on I2C bus (P5_7 SDA, P6_0 SCL) at slave address 1101_000r 0xD0 (or 0x68 for 7 MSbit address).
// AIN_0 = AIN0 pin       fullscale is 1.2V
// AIN_1 = AIN1 pin       fullscale is 1.2V
// AIN_2 = AIN2 pin       fullscale is 1.2V
// AIN_3 = AIN3 pin       fullscale is 1.2V
// AIN_4 = AIN0 / 5.0     fullscale is 6.0V
// AIN_5 = AIN1 / 5.0     fullscale is 6.0V
// AIN_6 = VDDB / 4.0     fullscale is 4.8V
// AIN_7 = VDD18          fullscale is 1.2V
// AIN_8 = VDD12          fullscale is 1.2V
// AIN_9 = VRTC / 2.0     fullscale is 2.4V
// AIN_10 = x undefined?
// AIN_11 = VDDIO / 4.0   fullscale is 4.8V
// AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
//
    #include "max32630fthr.h"
MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
// MAX32630FTHR board supports only internal VREF = 1.200V at bypass capacitor C15
const float ADC_FULL_SCALE_VOLTAGE = 1.200;
// Arduino connector
#ifndef A0
#define A0 AIN_0
#endif
#ifndef A1
#define A1 AIN_1
#endif
#ifndef A2
#define A2 AIN_2
#endif
#ifndef A3
#define A3 AIN_3
#endif
#ifndef D0
#define D0 P4_0
#endif
#ifndef D1
#define D1 P5_6
#endif
#ifndef D2
#define D2 P5_5
#endif
#ifndef D3
#define D3 P5_4
#endif
#ifndef D4
#define D4 P5_3
#endif
#ifndef D5
#define D5 P3_3
#endif
#ifndef D6
#define D6 P3_2
#endif
#ifndef D7
#define D7 P3_5
#endif
#ifndef D8
#define D8 P3_4
#endif
#ifndef D9
#define D9 P3_1
#endif
#ifndef D10
#define D10 P3_0
#endif
#ifndef D11
#define D11 P5_1
#endif
#ifndef D12
#define D12 P5_2
#endif
#ifndef D13
#define D13 P5_0
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32625MBED)
//--------------------------------------------------
// TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
//             +-------------------------------------+
//             |   MAX32625MBED Arduino UNO header   |
//             |                                     |
//             |                           A5/SCL[ ] |   P1_7 dig15
//             |                           A4/SDA[ ] |   P1_6 dig14
//             |                         AREF=N/C[ ] |
//             |                              GND[ ] |
//             | [ ]N/C                    SCK/13[ ] |   P1_0 dig13
//             | [ ]IOREF=3V3             MISO/12[ ] |   P1_2 dig12
//             | [ ]RST                   MOSI/11[ ]~|   P1_1 dig11
//             | [ ]3V3                     CS/10[ ]~|   P1_3 dig10
//             | [ ]5V0                         9[ ]~|   P1_5 dig9
//             | [ ]GND                         8[ ] |   P1_4 dig8
//             | [ ]GND                              |
//             | [ ]Vin                         7[ ] |   P0_7 dig7
//             |                                6[ ]~|   P0_6 dig6
//       AIN_0 | [ ]A0                          5[ ]~|   P0_5 dig5
//       AIN_1 | [ ]A1                          4[ ] |   P0_4 dig4
//       AIN_2 | [ ]A2                     INT1/3[ ]~|   P0_3 dig3
//       AIN_3 | [ ]A3                     INT0/2[ ] |   P0_2 dig2
// dig16  P3_4 | [ ]A4/SDA  RST SCK MISO     TX>1[ ] |   P0_1 dig1
// dig17  P3_5 | [ ]A5/SCL  [ ] [ ] [ ]      RX<0[ ] |   P0_0 dig0
//             |            [ ] [ ] [ ]              |
//             |  UNO_R3    GND MOSI 5V  ____________/
//              \_______________________/
//
//             +------------------------+
//             |                        |
//             |  MicroSD        LED    |
//             |  SD_SCLK P2_4   r P3_0 |
//             |  SD_MOSI P2_5   g P3_1 |
//             |  SD_MISO P2_6   b P3_2 |
//             |  SD_SSEL P2_7   y P3_3 |
//             |                        |
//             |  DAPLINK      BUTTONS  |
//             |  TX P2_1      SW3 P2_3 |
//             |  RX P2_0      SW2 P2_2 |
//             +------------------------+
//
// AIN_0 = AIN0 pin       fullscale is 1.2V
// AIN_1 = AIN1 pin       fullscale is 1.2V
// AIN_2 = AIN2 pin       fullscale is 1.2V
// AIN_3 = AIN3 pin       fullscale is 1.2V
// AIN_4 = AIN0 / 5.0     fullscale is 6.0V
// AIN_5 = AIN1 / 5.0     fullscale is 6.0V
// AIN_6 = VDDB / 4.0     fullscale is 4.8V
// AIN_7 = VDD18          fullscale is 1.2V
// AIN_8 = VDD12          fullscale is 1.2V
// AIN_9 = VRTC / 2.0     fullscale is 2.4V
// AIN_10 = x undefined?
// AIN_11 = VDDIO / 4.0   fullscale is 4.8V
// AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
//
//#include "max32625mbed.h" // ?
//MAX32625MBED mbed(MAX32625MBED::VIO_3V3); // ?
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
// MAX32630FTHR board supports only internal VREF = 1.200V at bypass capacitor C15
const float ADC_FULL_SCALE_VOLTAGE = 1.200;     // TODO: ADC_FULL_SCALE_VOLTAGE Pico?
// Arduino connector
#ifndef A0
#define A0 AIN_0
#endif
#ifndef A1
#define A1 AIN_1
#endif
#ifndef A2
#define A2 AIN_2
#endif
#ifndef A3
#define A3 AIN_3
#endif
#ifndef D0
#define D0 P0_0
#endif
#ifndef D1
#define D1 P0_1
#endif
#ifndef D2
#define D2 P0_2
#endif
#ifndef D3
#define D3 P0_3
#endif
#ifndef D4
#define D4 P0_4
#endif
#ifndef D5
#define D5 P0_5
#endif
#ifndef D6
#define D6 P0_6
#endif
#ifndef D7
#define D7 P0_7
#endif
#ifndef D8
#define D8 P1_4
#endif
#ifndef D9
#define D9 P1_5
#endif
#ifndef D10
#define D10 P1_3
#endif
#ifndef D11
#define D11 P1_1
#endif
#ifndef D12
#define D12 P1_2
#endif
#ifndef D13
#define D13 P1_0
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32600)
// target MAX32600
//
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 0
const float ADC_FULL_SCALE_VOLTAGE = 1.500;
//
//--------------------------------------------------
#elif defined(TARGET_MAX32620FTHR)
#warning "TARGET_MAX32620FTHR not previously tested; need to define pins..."
#include "MAX32620FTHR.h"
// Initialize I/O voltages on MAX32620FTHR board
MAX32620FTHR fthr(MAX32620FTHR::VIO_3V3);
//#define USE_LEDS 0 ?
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
#warning "TARGET_MAX32620FTHR not previously tested; need to verify ADC_FULL_SCALE_VOLTAGE..."
const float ADC_FULL_SCALE_VOLTAGE = 1.200;
//
//--------------------------------------------------
#elif defined(TARGET_MAX32625PICO)
#warning "TARGET_MAX32625PICO not previously tested; need to define pins..."
#include "max32625pico.h"
// configure MAX32625PICO VDDIOH mode, and I/O voltages for DIP pins and SWD pins
MAX32625PICO pico(
    // Select source of higher-voltage logic high supply VDDIOH
    // vddioh_mode_t iohMode
    //~ MAX32625PICO::IOH_OFF, // No connections to VDDIOH
    //~ MAX32625PICO::IOH_DIP_IN, // VDDIOH input from DIP pin 1 (AIN0)
    //~ MAX32625PICO::IOH_SWD_IN, // VDDIOH input from SWD pin 1
    MAX32625PICO::IOH_3V3, // VDDIOH = 3.3V from local supply
    //~ MAX32625PICO::IOH_DIP_OUT, // VDDIOH = 3.3V output to DIP pin 1
    //~ MAX32625PICO::IOH_SWD_OUT, // VDDIOH = 3.3V output to SWD pin 1
    //
    // Digital I/O pin logic high voltage 1.8V or 3.3V
    // vio_t dipVio = MAX32625PICO::VIO_1V8 or MAX32625PICO::VIO_IOH
    MAX32625PICO::VIO_1V8, // 1.8V IO (local)
    //~ MAX32625PICO::VIO_IOH, // Use VDDIOH (from DIP pin 1, or SWD pin1, or local 3.3V)
    //
    // Software Debug logic high voltage (normally use VIO_IOH)
    // vio_t swdVio
    //~ MAX32625PICO::VIO_1V8  // 1.8V IO (local)
    MAX32625PICO::VIO_IOH  // Use VDDIOH (from DIP pin 1, or SWD pin1, or local 3.3V)
    );
//#define USE_LEDS 0 ?
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
#warning "TARGET_MAX32625PICO not previously tested; need to verify ADC_FULL_SCALE_VOLTAGE..."
const float ADC_FULL_SCALE_VOLTAGE = 1.200;
//
//--------------------------------------------------
#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
// TODO1: target NUCLEO_F446RE
//
// USER_BUTTON PC13
// LED1 is shared with SPI_SCK on NUCLEO_F446RE PA_5, so don't use LED1.
#define USE_LEDS 0
// SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
// Serial serial(SERIAL_TX, SERIAL_RX);
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 0
const float ADC_FULL_SCALE_VOLTAGE = 3.300;     // TODO: ADC_FULL_SCALE_VOLTAGE Pico?
//
//--------------------------------------------------
#elif defined(TARGET_LPC1768)
//--------------------------------------------------
// TARGET=LPC1768 ARM Cortex-M3 100 MHz 512kB flash 64kB SRAM
//               +-------------[microUSB]-------------+
//        ______ | [ ] GND             +3.3V VOUT [ ] | ______
//        ______ | [ ] 4.5V<VIN<9.0V   +5.0V VU   [ ] | ______
//        ______ | [ ] VB                 USB.IF- [ ] | ______
//        ______ | [ ] nR                 USB.IF+ [ ] | ______
// digitalInOut0 | [ ] p5 MOSI       ETHERNET.RD- [ ] | ______
// digitalInOut1 | [ ] p6 MISO       ETHERNET.RD+ [ ] | ______
// digitalInOut2 | [ ] p7 SCLK       ETHERNET.TD- [ ] | ______
// digitalInOut3 | [ ] p8            ETHERNET.TD+ [ ] | ______
// digitalInOut4 | [ ] p9  TX SDA          USB.D- [ ] | ______
// digitalInOut5 | [ ] p10 RX SCL          USB.D+ [ ] | ______
// digitalInOut6 | [ ] p11    MOSI     CAN-RD p30 [ ] | digitalInOut13
// digitalInOut7 | [ ] p12    MISO     CAN-TD p29 [ ] | digitalInOut12
// digitalInOut8 | [ ] p13 TX SCLK     SDA TX p28 [ ] | digitalInOut11
// digitalInOut9 | [ ] p14 RX          SCL RX p27 [ ] | digitalInOut10
//     analogIn0 | [ ] p15 AIN0 3.3Vfs   PWM1 p26 [ ] | pwmDriver1
//     analogIn1 | [ ] p16 AIN1 3.3Vfs   PWM2 p25 [ ] | pwmDriver2
//     analogIn2 | [ ] p17 AIN2 3.3Vfs   PWM3 p24 [ ] | pwmDriver3
//     analogIn3 | [ ] p18 AIN3 AOUT     PWM4 p23 [ ] | pwmDriver4
//     analogIn4 | [ ] p19 AIN4 3.3Vfs   PWM5 p22 [ ] | pwmDriver5
//     analogIn5 | [ ] p20 AIN5 3.3Vfs   PWM6 p21 [ ] | pwmDriver6
//               +------------------------------------+
// AIN6 = P0.3 = TGT_SBL_RXD?
// AIN7 = P0.2 = TGT_SBL_TXD?
//
//--------------------------------------------------
// LPC1768 board uses VREF = 3.300V +A3,3V thru L1 to bypass capacitor C14
#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 0
const float ADC_FULL_SCALE_VOLTAGE = 3.300;
#else // not defined(TARGET_LPC1768 etc.)
//--------------------------------------------------
// unknown target
//--------------------------------------------------
#endif // target definition




// uncrustify-0.66.1 *INDENT-OFF*
//--------------------------------------------------
// Declare the DigitalInOut GPIO pins
// Optional digitalInOut support. If there is only one it should be digitalInOut1.
// D) Digital High/Low/Input Pin
#if defined(TARGET_MAX32630)
//       +-------------[microUSB]-------------+
//       | J1         MAX32630FTHR        J2  |
//       | [ ] RST                    GND [ ] |
//       | [ ] 3V3                    BAT+[ ] |
//       | [ ] 1V8                  reset SW1 |
//       | [ ] GND       J4               J3  |
//       | [ ] AIN_0 1.2Vfs     (bat) SYS [ ] |
//       | [ ] AIN_1 1.2Vfs           PWR [ ] |
//       | [ ] AIN_2 1.2Vfs      +5V VBUS [ ] |
//       | [ ] AIN_3 1.2Vfs   1-WIRE P4_0 [ ] | dig9
// dig10 | [x] P5_7  SDA2        SRN P5_6 [ ] | dig8
// dig11 | [x] P6_0  SCL2      SDIO3 P5_5 [ ] | dig7
// dig12 | [x] P5_0  SCLK      SDIO2 P5_4 [ ] | dig6
// dig13 | [x] P5_1  MOSI       SSEL P5_3 [x] | dig5
// dig14 | [ ] P5_2  MISO        RTS P3_3 [ ] | dig4
// dig15 | [ ] P3_0  RX          CTS P3_2 [ ] | dig3
// dig0  | [ ] P3_1  TX          SCL P3_5 [x] | dig2
//       | [ ] GND               SDA P3_4 [x] | dig1
//       +------------------------------------+
    #define HAS_digitalInOut0 1 // P3_1 TARGET_MAX32630 J1.15
    #define HAS_digitalInOut1 1 // P3_4 TARGET_MAX32630 J3.12
    #define HAS_digitalInOut2 1 // P3_5 TARGET_MAX32630 J3.11
    #define HAS_digitalInOut3 1 // P3_2 TARGET_MAX32630 J3.10
    #define HAS_digitalInOut4 1 // P3_3 TARGET_MAX32630 J3.9
    #define HAS_digitalInOut5 1 // P5_3 TARGET_MAX32630 J3.8
    #define HAS_digitalInOut6 1 // P5_4 TARGET_MAX32630 J3.7
    #define HAS_digitalInOut7 1 // P5_5 TARGET_MAX32630 J3.6
    #define HAS_digitalInOut8 1 // P5_6 TARGET_MAX32630 J3.5
    #define HAS_digitalInOut9 1 // P4_0 TARGET_MAX32630 J3.4
#if HAS_I2C
// avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
    #define HAS_digitalInOut10 0 // P5_7 TARGET_MAX32630 J1.9
    #define HAS_digitalInOut11 0 // P6_0 TARGET_MAX32630 J1.10
#else // HAS_I2C
    #define HAS_digitalInOut10 1 // P5_7 TARGET_MAX32630 J1.9
    #define HAS_digitalInOut11 1 // P6_0 TARGET_MAX32630 J1.10
#endif // HAS_I2C
#if HAS_SPI
// avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
    #define HAS_digitalInOut12 0 // P5_0 TARGET_MAX32630 J1.11
    #define HAS_digitalInOut13 0 // P5_1 TARGET_MAX32630 J1.12
    #define HAS_digitalInOut14 0 // P5_2 TARGET_MAX32630 J1.13
    #define HAS_digitalInOut15 0 // P3_0 TARGET_MAX32630 J1.14
#else // HAS_SPI
    #define HAS_digitalInOut12 1 // P5_0 TARGET_MAX32630 J1.11
    #define HAS_digitalInOut13 1 // P5_1 TARGET_MAX32630 J1.12
    #define HAS_digitalInOut14 1 // P5_2 TARGET_MAX32630 J1.13
    #define HAS_digitalInOut15 1 // P3_0 TARGET_MAX32630 J1.14
#endif // HAS_SPI
#if HAS_digitalInOut0
    DigitalInOut digitalInOut0(P3_1, PIN_INPUT, PullUp, 1); // P3_1 TARGET_MAX32630 J1.15
#endif
#if HAS_digitalInOut1
    DigitalInOut digitalInOut1(P3_4, PIN_INPUT, PullUp, 1); // P3_4 TARGET_MAX32630 J3.12
#endif
#if HAS_digitalInOut2
    DigitalInOut digitalInOut2(P3_5, PIN_INPUT, PullUp, 1); // P3_5 TARGET_MAX32630 J3.11
#endif
#if HAS_digitalInOut3
    DigitalInOut digitalInOut3(P3_2, PIN_INPUT, PullUp, 1); // P3_2 TARGET_MAX32630 J3.10
#endif
#if HAS_digitalInOut4
    DigitalInOut digitalInOut4(P3_3, PIN_INPUT, PullUp, 1); // P3_3 TARGET_MAX32630 J3.9
#endif
#if HAS_digitalInOut5
    DigitalInOut digitalInOut5(P5_3, PIN_INPUT, PullUp, 1); // P5_3 TARGET_MAX32630 J3.8
#endif
#if HAS_digitalInOut6
    DigitalInOut digitalInOut6(P5_4, PIN_INPUT, PullUp, 1); // P5_4 TARGET_MAX32630 J3.7
#endif
#if HAS_digitalInOut7
    DigitalInOut digitalInOut7(P5_5, PIN_INPUT, PullUp, 1); // P5_5 TARGET_MAX32630 J3.6
#endif
#if HAS_digitalInOut8
    DigitalInOut digitalInOut8(P5_6, PIN_INPUT, PullUp, 1); // P5_6 TARGET_MAX32630 J3.5
#endif
#if HAS_digitalInOut9
    DigitalInOut digitalInOut9(P4_0, PIN_INPUT, PullUp, 1); // P4_0 TARGET_MAX32630 J3.4
#endif
#if HAS_digitalInOut10
    DigitalInOut digitalInOut10(P5_7, PIN_INPUT, PullUp, 1); // P5_7 TARGET_MAX32630 J1.9
#endif
#if HAS_digitalInOut11
    DigitalInOut digitalInOut11(P6_0, PIN_INPUT, PullUp, 1); // P6_0 TARGET_MAX32630 J1.10
#endif
#if HAS_digitalInOut12
    DigitalInOut digitalInOut12(P5_0, PIN_INPUT, PullUp, 1); // P5_0 TARGET_MAX32630 J1.11
#endif
#if HAS_digitalInOut13
    DigitalInOut digitalInOut13(P5_1, PIN_INPUT, PullUp, 1); // P5_1 TARGET_MAX32630 J1.12
#endif
#if HAS_digitalInOut14
    DigitalInOut digitalInOut14(P5_2, PIN_INPUT, PullUp, 1); // P5_2 TARGET_MAX32630 J1.13
#endif
#if HAS_digitalInOut15
    DigitalInOut digitalInOut15(P3_0, PIN_INPUT, PullUp, 1); // P3_0 TARGET_MAX32630 J1.14
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32625MBED)
// TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
//             +-------------------------------------+
//             |   MAX32625MBED Arduino UNO header   |
//             |                                     |
//             |                           A5/SCL[ ] |   P1_7 dig15
//             |                           A4/SDA[ ] |   P1_6 dig14
//             |                         AREF=N/C[ ] |
//             |                              GND[ ] |
//             | [ ]N/C                    SCK/13[ ] |   P1_0 dig13
//             | [ ]IOREF=3V3             MISO/12[ ] |   P1_2 dig12
//             | [ ]RST                   MOSI/11[ ]~|   P1_1 dig11
//             | [ ]3V3                     CS/10[ ]~|   P1_3 dig10
//             | [ ]5V0                         9[ ]~|   P1_5 dig9
//             | [ ]GND                         8[ ] |   P1_4 dig8
//             | [ ]GND                              |
//             | [ ]Vin                         7[ ] |   P0_7 dig7
//             |                                6[ ]~|   P0_6 dig6
//       AIN_0 | [ ]A0                          5[ ]~|   P0_5 dig5
//       AIN_1 | [ ]A1                          4[ ] |   P0_4 dig4
//       AIN_2 | [ ]A2                     INT1/3[ ]~|   P0_3 dig3
//       AIN_3 | [ ]A3                     INT0/2[ ] |   P0_2 dig2
// dig16  P3_4 | [ ]A4/SDA  RST SCK MISO     TX>1[ ] |   P0_1 dig1
// dig17  P3_5 | [ ]A5/SCL  [ ] [ ] [ ]      RX<0[ ] |   P0_0 dig0
//             |            [ ] [ ] [ ]              |
//             |  UNO_R3    GND MOSI 5V  ____________/
//              \_______________________/
//
    #define HAS_digitalInOut0 1 // P0_0 TARGET_MAX32625MBED D0
    #define HAS_digitalInOut1 1 // P0_1 TARGET_MAX32625MBED D1
#if APPLICATION_MAX11131
    #define HAS_digitalInOut2 0 // P0_2 TARGET_MAX32625MBED D2 -- MAX11131 EOC DigitalIn
#else
    #define HAS_digitalInOut2 1 // P0_2 TARGET_MAX32625MBED D2
#endif
    #define HAS_digitalInOut3 1 // P0_3 TARGET_MAX32625MBED D3
    #define HAS_digitalInOut4 1 // P0_4 TARGET_MAX32625MBED D4
    #define HAS_digitalInOut5 1 // P0_5 TARGET_MAX32625MBED D5
    #define HAS_digitalInOut6 1 // P0_6 TARGET_MAX32625MBED D6
    #define HAS_digitalInOut7 1 // P0_7 TARGET_MAX32625MBED D7
    #define HAS_digitalInOut8 1 // P1_4 TARGET_MAX32625MBED D8
#if APPLICATION_MAX11131
    #define HAS_digitalInOut9 0 // P1_5 TARGET_MAX32625MBED D9 -- MAX11131 CNVST DigitalOut
#else
    #define HAS_digitalInOut9 1 // P1_5 TARGET_MAX32625MBED D9
#endif
#if HAS_SPI
// avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
    #define HAS_digitalInOut10 0 // P1_3 TARGET_MAX32635MBED CS/10
    #define HAS_digitalInOut11 0 // P1_1 TARGET_MAX32635MBED MOSI/11
    #define HAS_digitalInOut12 0 // P1_2 TARGET_MAX32635MBED MISO/12
    #define HAS_digitalInOut13 0 // P1_0 TARGET_MAX32635MBED SCK/13
#else // HAS_SPI
    #define HAS_digitalInOut10 1 // P1_3 TARGET_MAX32635MBED CS/10
    #define HAS_digitalInOut11 1 // P1_1 TARGET_MAX32635MBED MOSI/11
    #define HAS_digitalInOut12 1 // P1_2 TARGET_MAX32635MBED MISO/12
    #define HAS_digitalInOut13 1 // P1_0 TARGET_MAX32635MBED SCK/13
#endif // HAS_SPI
#if HAS_I2C
// avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
    #define HAS_digitalInOut14 0 // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
    #define HAS_digitalInOut15 0 // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
    #define HAS_digitalInOut16 0 // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
    #define HAS_digitalInOut17 0 // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
#else // HAS_I2C
    #define HAS_digitalInOut14 1 // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
    #define HAS_digitalInOut15 1 // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
    #define HAS_digitalInOut16 1 // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
    #define HAS_digitalInOut17 1 // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
#endif // HAS_I2C
#if HAS_digitalInOut0
    DigitalInOut digitalInOut0(P0_0, PIN_INPUT, PullUp, 1); // P0_0 TARGET_MAX32625MBED D0
#endif
#if HAS_digitalInOut1
    DigitalInOut digitalInOut1(P0_1, PIN_INPUT, PullUp, 1); // P0_1 TARGET_MAX32625MBED D1
#endif
#if HAS_digitalInOut2
    DigitalInOut digitalInOut2(P0_2, PIN_INPUT, PullUp, 1); // P0_2 TARGET_MAX32625MBED D2
#endif
#if HAS_digitalInOut3
    DigitalInOut digitalInOut3(P0_3, PIN_INPUT, PullUp, 1); // P0_3 TARGET_MAX32625MBED D3
#endif
#if HAS_digitalInOut4
    DigitalInOut digitalInOut4(P0_4, PIN_INPUT, PullUp, 1); // P0_4 TARGET_MAX32625MBED D4
#endif
#if HAS_digitalInOut5
    DigitalInOut digitalInOut5(P0_5, PIN_INPUT, PullUp, 1); // P0_5 TARGET_MAX32625MBED D5
#endif
#if HAS_digitalInOut6
    DigitalInOut digitalInOut6(P0_6, PIN_INPUT, PullUp, 1); // P0_6 TARGET_MAX32625MBED D6
#endif
#if HAS_digitalInOut7
    DigitalInOut digitalInOut7(P0_7, PIN_INPUT, PullUp, 1); // P0_7 TARGET_MAX32625MBED D7
#endif
#if HAS_digitalInOut8
    DigitalInOut digitalInOut8(P1_4, PIN_INPUT, PullUp, 1); // P1_4 TARGET_MAX32625MBED D8
#endif
#if HAS_digitalInOut9
    DigitalInOut digitalInOut9(P1_5, PIN_INPUT, PullUp, 1); // P1_5 TARGET_MAX32625MBED D9
#endif
#if HAS_digitalInOut10
    DigitalInOut digitalInOut10(P1_3, PIN_INPUT, PullUp, 1); // P1_3 TARGET_MAX32635MBED CS/10
#endif
#if HAS_digitalInOut11
    DigitalInOut digitalInOut11(P1_1, PIN_INPUT, PullUp, 1); // P1_1 TARGET_MAX32635MBED MOSI/11
#endif
#if HAS_digitalInOut12
    DigitalInOut digitalInOut12(P1_2, PIN_INPUT, PullUp, 1); // P1_2 TARGET_MAX32635MBED MISO/12
#endif
#if HAS_digitalInOut13
    DigitalInOut digitalInOut13(P1_0, PIN_INPUT, PullUp, 1); // P1_0 TARGET_MAX32635MBED SCK/13
#endif
#if HAS_digitalInOut14
    // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
    // DigitalInOut mode can be one of PullUp, PullDown, PullNone, OpenDrain
    DigitalInOut digitalInOut14(P1_6, PIN_INPUT, OpenDrain, 1); // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
#endif
#if HAS_digitalInOut15
    // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
    DigitalInOut digitalInOut15(P1_7, PIN_INPUT, OpenDrain, 1); // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
#endif
#if HAS_digitalInOut16
    // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
    // DigitalInOut mode can be one of PullUp, PullDown, PullNone, OpenDrain
    // PullUp-->3.4V, PullDown-->1.7V, PullNone-->3.5V, OpenDrain-->0.00V
    DigitalInOut digitalInOut16(P3_4, PIN_INPUT, OpenDrain, 0); // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
#endif
#if HAS_digitalInOut17
    // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
    DigitalInOut digitalInOut17(P3_5, PIN_INPUT, OpenDrain, 0); // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
#endif
//--------------------------------------------------
#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
    #define HAS_digitalInOut0 0
    #define HAS_digitalInOut1 0
#if APPLICATION_MAX11131
    // D2 -- MAX11131 EOC DigitalIn
    #define HAS_digitalInOut2 0
#else
    #define HAS_digitalInOut2 1
#endif
    #define HAS_digitalInOut3 1
    #define HAS_digitalInOut4 1
    #define HAS_digitalInOut5 1
    #define HAS_digitalInOut6 1
    #define HAS_digitalInOut7 1
#if APPLICATION_MAX5715
    // D8 -- MAX5715 CLRb DigitalOut
    #define HAS_digitalInOut8 0
#else
    #define HAS_digitalInOut8 1
#endif
#if APPLICATION_MAX5715
    // D9 -- MAX5715 LDACb DigitalOut
    #define HAS_digitalInOut9 0
#elif APPLICATION_MAX11131
    // D9 -- MAX11131 CNVST DigitalOut
    #define HAS_digitalInOut9 0
#else
    #define HAS_digitalInOut9 1
#endif
#if HAS_SPI
// avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
    // Arduino digital pin D10 SPI function is CS/10
    // Arduino digital pin D11 SPI function is MOSI/11
    // Arduino digital pin D12 SPI function is MISO/12
    // Arduino digital pin D13 SPI function is SCK/13
    #define HAS_digitalInOut10 0
    #define HAS_digitalInOut11 0
    #define HAS_digitalInOut12 0
    #define HAS_digitalInOut13 0
#else // HAS_SPI
    #define HAS_digitalInOut10 1
    #define HAS_digitalInOut11 1
    #define HAS_digitalInOut12 1
    #define HAS_digitalInOut13 1
#endif // HAS_SPI
#if HAS_I2C
// avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
    // Arduino digital pin D14 I2C function is A4/SDA (10pin digital connector)
    // Arduino digital pin D15 I2C function is A5/SCL (10pin digital connector)
    // Arduino digital pin D16 I2C function is A4/SDA (6pin analog connector)
    // Arduino digital pin D17 I2C function is A5/SCL (6pin analog connector)
    #define HAS_digitalInOut14 0
    #define HAS_digitalInOut15 0
    #define HAS_digitalInOut16 0
    #define HAS_digitalInOut17 0
#else // HAS_I2C
    #define HAS_digitalInOut14 1
    #define HAS_digitalInOut15 1
    #define HAS_digitalInOut16 0
    #define HAS_digitalInOut17 0
#endif // HAS_I2C
#if HAS_digitalInOut0
    DigitalInOut digitalInOut0(D0, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut1
    DigitalInOut digitalInOut1(D1, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut2
    DigitalInOut digitalInOut2(D2, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut3
    DigitalInOut digitalInOut3(D3, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut4
    DigitalInOut digitalInOut4(D4, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut5
    DigitalInOut digitalInOut5(D5, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut6
    DigitalInOut digitalInOut6(D6, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut7
    DigitalInOut digitalInOut7(D7, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut8
    DigitalInOut digitalInOut8(D8, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut9
    DigitalInOut digitalInOut9(D9, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut10
    // Arduino digital pin D10 SPI function is CS/10
    DigitalInOut digitalInOut10(D10, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut11
    // Arduino digital pin D11 SPI function is MOSI/11
    DigitalInOut digitalInOut11(D11, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut12
    // Arduino digital pin D12 SPI function is MISO/12
    DigitalInOut digitalInOut12(D12, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut13
    // Arduino digital pin D13 SPI function is SCK/13
    DigitalInOut digitalInOut13(D13, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut14
    // Arduino digital pin D14 I2C function is A4/SDA (10pin digital connector)
    DigitalInOut digitalInOut14(D14, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut15
    // Arduino digital pin D15 I2C function is A5/SCL (10pin digital connector)
    DigitalInOut digitalInOut15(D15, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut16
    // Arduino digital pin D16 I2C function is A4/SDA (6pin analog connector)
    DigitalInOut digitalInOut16(D16, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut17
    // Arduino digital pin D17 I2C function is A5/SCL (6pin analog connector)
    DigitalInOut digitalInOut17(D17, PIN_INPUT, PullUp, 1);
#endif
//--------------------------------------------------
#elif defined(TARGET_LPC1768)
    #define HAS_digitalInOut0 1
    #define HAS_digitalInOut1 1
    #define HAS_digitalInOut2 1
    #define HAS_digitalInOut3 1
    #define HAS_digitalInOut4 1
    #define HAS_digitalInOut5 1
    #define HAS_digitalInOut6 1
    #define HAS_digitalInOut7 1
    #define HAS_digitalInOut8 1
    #define HAS_digitalInOut9 1
//    #define HAS_digitalInOut10 1
//    #define HAS_digitalInOut11 1
//    #define HAS_digitalInOut12 1
//    #define HAS_digitalInOut13 1
//    #define HAS_digitalInOut14 1
//    #define HAS_digitalInOut15 1
#if HAS_digitalInOut0
    DigitalInOut digitalInOut0(p5, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.9/I2STX_SDA/MOSI1/MAT2.3
#endif
#if HAS_digitalInOut1
    DigitalInOut digitalInOut1(p6, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.8/I2STX_WS/MISO1/MAT2.2
#endif
#if HAS_digitalInOut2
    DigitalInOut digitalInOut2(p7, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.7/I2STX_CLK/SCK1/MAT2.1
#endif
#if HAS_digitalInOut3
    DigitalInOut digitalInOut3(p8, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.6/I2SRX_SDA/SSEL1/MAT2.0
#endif
#if HAS_digitalInOut4
    DigitalInOut digitalInOut4(p9, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.0/CAN_RX1/TXD3/SDA1
#endif
#if HAS_digitalInOut5
    DigitalInOut digitalInOut5(p10, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.1/CAN_TX1/RXD3/SCL1
#endif
#if HAS_digitalInOut6
    DigitalInOut digitalInOut6(p11, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.18/DCD1/MOSI0/MOSI1
#endif
#if HAS_digitalInOut7
    DigitalInOut digitalInOut7(p12, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.17/CTS1/MISO0/MISO
#endif
#if HAS_digitalInOut8
    DigitalInOut digitalInOut8(p13, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.15/TXD1/SCK0/SCK
#endif
#if HAS_digitalInOut9
    DigitalInOut digitalInOut9(p14, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.16/RXD1/SSEL0/SSEL
#endif
    //
    // these pins support analog input analogIn0 .. analogIn5
    //DigitalInOut digitalInOut_(p15, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.23/AD0.0/I2SRX_CLK/CAP3.0
    //DigitalInOut digitalInOut_(p16, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.24/AD0.1/I2SRX_WS/CAP3.1
    //DigitalInOut digitalInOut_(p17, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.25/AD0.2/I2SRX_SDA/TXD3
    //DigitalInOut digitalInOut_(p18, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.26/AD0.3/AOUT/RXD3
    //DigitalInOut digitalInOut_(p19, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P1.30/VBUS/AD0.4
    //DigitalInOut digitalInOut_(p20, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P1.31/SCK1/AD0.5
    //
    // these pins support PWM pwmDriver1 .. pwmDriver6
    //DigitalInOut digitalInOut_(p21, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.5/PWM1.6/DTR1/TRACEDATA0
    //DigitalInOut digitalInOut_(p22, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.4/PWM1.5/DSR1/TRACEDATA1
    //DigitalInOut digitalInOut_(p23, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.3/PWM1.4/DCD1/TRACEDATA2
    //DigitalInOut digitalInOut_(p24, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.2/PWM1.3/CTS1/TRACEDATA3
    //DigitalInOut digitalInOut_(p25, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.1/PWM1.2/RXD1
    //DigitalInOut digitalInOut_(p26, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.0/PWM1.1/TXD1/TRACECLK
    //
    // these could be additional digitalInOut pins
#if HAS_digitalInOut10
    DigitalInOut digitalInOut10(p27, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.11/RXD2/SCL2/MAT3.1
#endif
#if HAS_digitalInOut11
    DigitalInOut digitalInOut11(p28, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.10/TXD2/SDA2/MAT3.0
#endif
#if HAS_digitalInOut12
    DigitalInOut digitalInOut12(p29, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.5/I2SRX_WS/CAN_TX2/CAP2.1
#endif
#if HAS_digitalInOut13
    DigitalInOut digitalInOut13(p30, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.4/I2SRX_CLK/CAN_RX2/CAP2.0
#endif
#if HAS_digitalInOut14
    DigitalInOut digitalInOut14(___, PIN_INPUT, PullUp, 1);
#endif
#if HAS_digitalInOut15
    DigitalInOut digitalInOut15(___, PIN_INPUT, PullUp, 1);
#endif
#else
    // unknown target
#endif
// uncrustify-0.66.1 *INDENT-ON*
#if HAS_digitalInOut0 || HAS_digitalInOut1 \
    || HAS_digitalInOut2 || HAS_digitalInOut3 \
    || HAS_digitalInOut4 || HAS_digitalInOut5 \
    || HAS_digitalInOut6 || HAS_digitalInOut7 \
    || HAS_digitalInOut8 || HAS_digitalInOut9 \
    || HAS_digitalInOut10 || HAS_digitalInOut11 \
    || HAS_digitalInOut12 || HAS_digitalInOut13 \
    || HAS_digitalInOut14 || HAS_digitalInOut15 \
    || HAS_digitalInOut16 || HAS_digitalInOut17
#define HAS_digitalInOuts 1
#else
#warning "Note: There are no digitalInOut resources defined"
#endif

// uncrustify-0.66.1 *INDENT-OFF*
//--------------------------------------------------
// Declare the AnalogIn driver
// Optional analogIn support. If there is only one it should be analogIn1.
// A) analog input
#if defined(TARGET_MAX32630)
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
    #define HAS_analogIn6 1
    #define HAS_analogIn7 1
    #define HAS_analogIn8 1
    #define HAS_analogIn9 1
//    #define HAS_analogIn10 0
//    #define HAS_analogIn11 0
//    #define HAS_analogIn12 0
//    #define HAS_analogIn13 0
//    #define HAS_analogIn14 0
//    #define HAS_analogIn15 0
#if HAS_analogIn0
    AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
#endif
#if HAS_analogIn6
    AnalogIn analogIn6(AIN_6); // TARGET_MAX32630 AIN_6 = VDDB / 4.0     fullscale is 4.8V
#endif
#if HAS_analogIn7
    AnalogIn analogIn7(AIN_7); // TARGET_MAX32630 AIN_7 = VDD18          fullscale is 1.2V
#endif
#if HAS_analogIn8
    AnalogIn analogIn8(AIN_8); // TARGET_MAX32630 AIN_8 = VDD12          fullscale is 1.2V
#endif
#if HAS_analogIn9
    AnalogIn analogIn9(AIN_9); // TARGET_MAX32630 AIN_9 = VRTC / 2.0     fullscale is 2.4V
#endif
#if HAS_analogIn10
    AnalogIn analogIn10(____); // TARGET_MAX32630 AIN_10 = x undefined?
#endif
#if HAS_analogIn11
    AnalogIn analogIn11(____); // TARGET_MAX32630 AIN_11 = VDDIO / 4.0   fullscale is 4.8V
#endif
#if HAS_analogIn12
    AnalogIn analogIn12(____); // TARGET_MAX32630 AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
#endif
#if HAS_analogIn13
    AnalogIn analogIn13(____);
#endif
#if HAS_analogIn14
    AnalogIn analogIn14(____);
#endif
#if HAS_analogIn15
    AnalogIn analogIn15(____);
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32625MBED)
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
#if HAS_analogIn0
    AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32620FTHR)
#warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..."
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
    #define HAS_analogIn6 1
    #define HAS_analogIn7 1
    #define HAS_analogIn8 1
    #define HAS_analogIn9 1
//    #define HAS_analogIn10 0
//    #define HAS_analogIn11 0
//    #define HAS_analogIn12 0
//    #define HAS_analogIn13 0
//    #define HAS_analogIn14 0
//    #define HAS_analogIn15 0
#if HAS_analogIn0
    AnalogIn analogIn0(AIN_0); // TARGET_MAX32620FTHR J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(AIN_1); // TARGET_MAX32620FTHR J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(AIN_2); // TARGET_MAX32620FTHR J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(AIN_3); // TARGET_MAX32620FTHR J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(AIN_4); // TARGET_MAX32620FTHR J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(AIN_5); // TARGET_MAX32620FTHR J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
#endif
#if HAS_analogIn6
    AnalogIn analogIn6(AIN_6); // TARGET_MAX32620FTHR AIN_6 = VDDB / 4.0     fullscale is 4.8V
#endif
#if HAS_analogIn7
    AnalogIn analogIn7(AIN_7); // TARGET_MAX32620FTHR AIN_7 = VDD18          fullscale is 1.2V
#endif
#if HAS_analogIn8
    AnalogIn analogIn8(AIN_8); // TARGET_MAX32620FTHR AIN_8 = VDD12          fullscale is 1.2V
#endif
#if HAS_analogIn9
    AnalogIn analogIn9(AIN_9); // TARGET_MAX32620FTHR AIN_9 = VRTC / 2.0     fullscale is 2.4V
#endif
#if HAS_analogIn10
    AnalogIn analogIn10(____); // TARGET_MAX32620FTHR AIN_10 = x undefined?
#endif
#if HAS_analogIn11
    AnalogIn analogIn11(____); // TARGET_MAX32620FTHR AIN_11 = VDDIO / 4.0   fullscale is 4.8V
#endif
#if HAS_analogIn12
    AnalogIn analogIn12(____); // TARGET_MAX32620FTHR AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
#endif
#if HAS_analogIn13
    AnalogIn analogIn13(____);
#endif
#if HAS_analogIn14
    AnalogIn analogIn14(____);
#endif
#if HAS_analogIn15
    AnalogIn analogIn15(____);
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32625PICO)
#warning "TARGET_MAX32625PICO not previously tested; need to verify analogIn0..."
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
#if HAS_analogIn0
    AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
#endif
//--------------------------------------------------
#elif defined(TARGET_MAX32600)
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
#if HAS_analogIn0
    AnalogIn analogIn0(A0);
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(A1);
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(A2);
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(A3);
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(A4);
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(A5);
#endif
//--------------------------------------------------
#elif defined(TARGET_NUCLEO_F446RE)
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
#if HAS_analogIn0
    AnalogIn analogIn0(A0);
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(A1);
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(A2);
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(A3);
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(A4);
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(A5);
#endif
//--------------------------------------------------
#elif defined(TARGET_NUCLEO_F401RE)
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
#if HAS_analogIn0
    AnalogIn analogIn0(A0);
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(A1);
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(A2);
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(A3);
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(A4);
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(A5);
#endif
//--------------------------------------------------
// TODO1: TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
#elif defined(TARGET_LPC1768)
    #define HAS_analogIn0 1
    #define HAS_analogIn1 1
    #define HAS_analogIn2 1
    #define HAS_analogIn3 1
    #define HAS_analogIn4 1
    #define HAS_analogIn5 1
//    #define HAS_analogIn6 1
//    #define HAS_analogIn7 1
//    #define HAS_analogIn8 1
//    #define HAS_analogIn9 1
//    #define HAS_analogIn10 1
//    #define HAS_analogIn11 1
//    #define HAS_analogIn12 1
//    #define HAS_analogIn13 1
//    #define HAS_analogIn14 1
//    #define HAS_analogIn15 1
#if HAS_analogIn0
    AnalogIn analogIn0(p15); // TARGET_LPC1768 P0.23/AD0.0/I2SRX_CLK/CAP3.0
#endif
#if HAS_analogIn1
    AnalogIn analogIn1(p16); // TARGET_LPC1768 P0.24/AD0.1/I2SRX_WS/CAP3.1
#endif
#if HAS_analogIn2
    AnalogIn analogIn2(p17); // TARGET_LPC1768 P0.25/AD0.2/I2SRX_SDA/TXD3
#endif
#if HAS_analogIn3
    AnalogIn analogIn3(p18); // TARGET_LPC1768 P0.26/AD0.3/AOUT/RXD3
#endif
#if HAS_analogIn4
    AnalogIn analogIn4(p19); // TARGET_LPC1768 P1.30/VBUS/AD0.4
#endif
#if HAS_analogIn5
    AnalogIn analogIn5(p20); // TARGET_LPC1768 P1.31/SCK1/AD0.5
#endif
#if HAS_analogIn6
    AnalogIn analogIn6(____);
#endif
#if HAS_analogIn7
    AnalogIn analogIn7(____);
#endif
#if HAS_analogIn8
    AnalogIn analogIn8(____);
#endif
#if HAS_analogIn9
    AnalogIn analogIn9(____);
#endif
#if HAS_analogIn10
    AnalogIn analogIn10(____);
#endif
#if HAS_analogIn11
    AnalogIn analogIn11(____);
#endif
#if HAS_analogIn12
    AnalogIn analogIn12(____);
#endif
#if HAS_analogIn13
    AnalogIn analogIn13(____);
#endif
#if HAS_analogIn14
    AnalogIn analogIn14(____);
#endif
#if HAS_analogIn15
    AnalogIn analogIn15(____);
#endif
#else
    // unknown target
#endif
// uncrustify-0.66.1 *INDENT-ON*
#if HAS_analogIn0 || HAS_analogIn1 \
    || HAS_analogIn2 || HAS_analogIn3 \
    || HAS_analogIn4 || HAS_analogIn5 \
    || HAS_analogIn6 || HAS_analogIn7 \
    || HAS_analogIn8 || HAS_analogIn9 \
    || HAS_analogIn10 || HAS_analogIn11 \
    || HAS_analogIn12 || HAS_analogIn13 \
    || HAS_analogIn14 || HAS_analogIn15
#define HAS_analogIns 1
#else
#warning "Note: There are no analogIn resources defined"
#endif

// DigitalInOut pin resource: print the pin index names to serial
#if HAS_digitalInOuts
void list_digitalInOutPins(Stream& serialStream)
{
#if HAS_digitalInOut0
    serialStream.printf(" 0");
#endif
#if HAS_digitalInOut1
    serialStream.printf(" 1");
#endif
#if HAS_digitalInOut2
    serialStream.printf(" 2");
#endif
#if HAS_digitalInOut3
    serialStream.printf(" 3");
#endif
#if HAS_digitalInOut4
    serialStream.printf(" 4");
#endif
#if HAS_digitalInOut5
    serialStream.printf(" 5");
#endif
#if HAS_digitalInOut6
    serialStream.printf(" 6");
#endif
#if HAS_digitalInOut7
    serialStream.printf(" 7");
#endif
#if HAS_digitalInOut8
    serialStream.printf(" 8");
#endif
#if HAS_digitalInOut9
    serialStream.printf(" 9");
#endif
#if HAS_digitalInOut10
    serialStream.printf(" 10");
#endif
#if HAS_digitalInOut11
    serialStream.printf(" 11");
#endif
#if HAS_digitalInOut12
    serialStream.printf(" 12");
#endif
#if HAS_digitalInOut13
    serialStream.printf(" 13");
#endif
#if HAS_digitalInOut14
    serialStream.printf(" 14");
#endif
#if HAS_digitalInOut15
    serialStream.printf(" 15");
#endif
#if HAS_digitalInOut16
    serialStream.printf(" 16");
#endif
#if HAS_digitalInOut17
    serialStream.printf(" 17");
#endif
}
#endif


// DigitalInOut pin resource: search index
#if HAS_digitalInOuts
DigitalInOut& find_digitalInOutPin(int cPinIndex)
{
    switch (cPinIndex)
    {
        default: // default to the first defined digitalInOut pin
#if HAS_digitalInOut0
        case '0': case 0x00: return digitalInOut0;
#endif
#if HAS_digitalInOut1
        case '1': case 0x01: return digitalInOut1;
#endif
#if HAS_digitalInOut2
        case '2': case 0x02: return digitalInOut2;
#endif
#if HAS_digitalInOut3
        case '3': case 0x03: return digitalInOut3;
#endif
#if HAS_digitalInOut4
        case '4': case 0x04: return digitalInOut4;
#endif
#if HAS_digitalInOut5
        case '5': case 0x05: return digitalInOut5;
#endif
#if HAS_digitalInOut6
        case '6': case 0x06: return digitalInOut6;
#endif
#if HAS_digitalInOut7
        case '7': case 0x07: return digitalInOut7;
#endif
#if HAS_digitalInOut8
        case '8': case 0x08: return digitalInOut8;
#endif
#if HAS_digitalInOut9
        case '9': case 0x09: return digitalInOut9;
#endif
#if HAS_digitalInOut10
        case 'a': case 0x0a: return digitalInOut10;
#endif
#if HAS_digitalInOut11
        case 'b': case 0x0b: return digitalInOut11;
#endif
#if HAS_digitalInOut12
        case 'c': case 0x0c: return digitalInOut12;
#endif
#if HAS_digitalInOut13
        case 'd': case 0x0d: return digitalInOut13;
#endif
#if HAS_digitalInOut14
        case 'e': case 0x0e: return digitalInOut14;
#endif
#if HAS_digitalInOut15
        case 'f': case 0x0f: return digitalInOut15;
#endif
#if HAS_digitalInOut16
        case 'g': case 0x10: return digitalInOut16;
#endif
#if HAS_digitalInOut17
        case 'h': case 0x11: return digitalInOut17;
#endif
    }
}
#endif


// AnalogIn pin resource: search index
#if HAS_analogIns
AnalogIn& find_analogInPin(int cPinIndex)
{
    switch (cPinIndex)
    {
        default: // default to the first defined analogIn pin
#if HAS_analogIn0
        case '0': case 0x00: return analogIn0;
#endif
#if HAS_analogIn1
        case '1': case 0x01: return analogIn1;
#endif
#if HAS_analogIn2
        case '2': case 0x02: return analogIn2;
#endif
#if HAS_analogIn3
        case '3': case 0x03: return analogIn3;
#endif
#if HAS_analogIn4
        case '4': case 0x04: return analogIn4;
#endif
#if HAS_analogIn5
        case '5': case 0x05: return analogIn5;
#endif
#if HAS_analogIn6
        case '6': case 0x06: return analogIn6;
#endif
#if HAS_analogIn7
        case '7': case 0x07: return analogIn7;
#endif
#if HAS_analogIn8
        case '8': case 0x08: return analogIn8;
#endif
#if HAS_analogIn9
        case '9': case 0x09: return analogIn9;
#endif
#if HAS_analogIn10
        case 'a': case 0x0a: return analogIn10;
#endif
#if HAS_analogIn11
        case 'b': case 0x0b: return analogIn11;
#endif
#if HAS_analogIn12
        case 'c': case 0x0c: return analogIn12;
#endif
#if HAS_analogIn13
        case 'd': case 0x0d: return analogIn13;
#endif
#if HAS_analogIn14
        case 'e': case 0x0e: return analogIn14;
#endif
#if HAS_analogIn15
        case 'f': case 0x0f: return analogIn15;
#endif
    }
}
#endif

#if HAS_analogIns
const float analogInPin_fullScaleVoltage[] = {
# if defined(TARGET_MAX32630)
    ADC_FULL_SCALE_VOLTAGE, // analogIn0
    ADC_FULL_SCALE_VOLTAGE, // analogIn1
    ADC_FULL_SCALE_VOLTAGE, // analogIn2
    ADC_FULL_SCALE_VOLTAGE, // analogIn3
    ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
    ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
    ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE, // analogIn13
    ADC_FULL_SCALE_VOLTAGE, // analogIn14
    ADC_FULL_SCALE_VOLTAGE // analogIn15
# elif defined(TARGET_MAX32620FTHR)
#warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..."
    ADC_FULL_SCALE_VOLTAGE, // analogIn0
    ADC_FULL_SCALE_VOLTAGE, // analogIn1
    ADC_FULL_SCALE_VOLTAGE, // analogIn2
    ADC_FULL_SCALE_VOLTAGE, // analogIn3
    ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
    ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
    ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE, // analogIn13
    ADC_FULL_SCALE_VOLTAGE, // analogIn14
    ADC_FULL_SCALE_VOLTAGE // analogIn15
#elif defined(TARGET_MAX32625MBED) || defined(TARGET_MAX32625PICO)
    ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn0 // fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn1 // fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn2 // fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn3 // fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
    ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
    ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
    ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
    ADC_FULL_SCALE_VOLTAGE, // analogIn13
    ADC_FULL_SCALE_VOLTAGE, // analogIn14
    ADC_FULL_SCALE_VOLTAGE // analogIn15
#elif defined(TARGET_NUCLEO_F446RE)
    ADC_FULL_SCALE_VOLTAGE, // analogIn0
    ADC_FULL_SCALE_VOLTAGE, // analogIn1
    ADC_FULL_SCALE_VOLTAGE, // analogIn2
    ADC_FULL_SCALE_VOLTAGE, // analogIn3
    ADC_FULL_SCALE_VOLTAGE, // analogIn4
    ADC_FULL_SCALE_VOLTAGE, // analogIn5
    ADC_FULL_SCALE_VOLTAGE, // analogIn6
    ADC_FULL_SCALE_VOLTAGE, // analogIn7
    ADC_FULL_SCALE_VOLTAGE, // analogIn8
    ADC_FULL_SCALE_VOLTAGE, // analogIn9
    ADC_FULL_SCALE_VOLTAGE, // analogIn10
    ADC_FULL_SCALE_VOLTAGE, // analogIn11
    ADC_FULL_SCALE_VOLTAGE, // analogIn12
    ADC_FULL_SCALE_VOLTAGE, // analogIn13
    ADC_FULL_SCALE_VOLTAGE, // analogIn14
    ADC_FULL_SCALE_VOLTAGE // analogIn15
#elif defined(TARGET_NUCLEO_F401RE)
    ADC_FULL_SCALE_VOLTAGE, // analogIn0
    ADC_FULL_SCALE_VOLTAGE, // analogIn1
    ADC_FULL_SCALE_VOLTAGE, // analogIn2
    ADC_FULL_SCALE_VOLTAGE, // analogIn3
    ADC_FULL_SCALE_VOLTAGE, // analogIn4
    ADC_FULL_SCALE_VOLTAGE, // analogIn5
    ADC_FULL_SCALE_VOLTAGE, // analogIn6
    ADC_FULL_SCALE_VOLTAGE, // analogIn7
    ADC_FULL_SCALE_VOLTAGE, // analogIn8
    ADC_FULL_SCALE_VOLTAGE, // analogIn9
    ADC_FULL_SCALE_VOLTAGE, // analogIn10
    ADC_FULL_SCALE_VOLTAGE, // analogIn11
    ADC_FULL_SCALE_VOLTAGE, // analogIn12
    ADC_FULL_SCALE_VOLTAGE, // analogIn13
    ADC_FULL_SCALE_VOLTAGE, // analogIn14
    ADC_FULL_SCALE_VOLTAGE // analogIn15
//#elif defined(TARGET_LPC1768)
#else
    // unknown target
    ADC_FULL_SCALE_VOLTAGE, // analogIn0
    ADC_FULL_SCALE_VOLTAGE, // analogIn1
    ADC_FULL_SCALE_VOLTAGE, // analogIn2
    ADC_FULL_SCALE_VOLTAGE, // analogIn3
    ADC_FULL_SCALE_VOLTAGE, // analogIn4
    ADC_FULL_SCALE_VOLTAGE, // analogIn5
    ADC_FULL_SCALE_VOLTAGE, // analogIn6
    ADC_FULL_SCALE_VOLTAGE, // analogIn7
    ADC_FULL_SCALE_VOLTAGE, // analogIn8
    ADC_FULL_SCALE_VOLTAGE, // analogIn9
    ADC_FULL_SCALE_VOLTAGE, // analogIn10
    ADC_FULL_SCALE_VOLTAGE, // analogIn11
    ADC_FULL_SCALE_VOLTAGE, // analogIn12
    ADC_FULL_SCALE_VOLTAGE, // analogIn13
    ADC_FULL_SCALE_VOLTAGE, // analogIn14
    ADC_FULL_SCALE_VOLTAGE // analogIn15
# endif
};
#endif




//--------------------------------------------------
// Option to use LEDs to show status
#ifndef USE_LEDS
#define USE_LEDS 1
#endif
#if USE_LEDS
#if defined(TARGET_MAX32630)
# define LED_ON  0
# define LED_OFF 1
//--------------------------------------------------
#elif defined(TARGET_MAX32625MBED)
# define LED_ON  0
# define LED_OFF 1
#elif defined(TARGET_MAX32625PICO)
# define LED_ON  0
# define LED_OFF 1
//--------------------------------------------------
// TODO1: TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
#elif defined(TARGET_LPC1768)
# define LED_ON  1
# define LED_OFF 0
#else // not defined(TARGET_LPC1768 etc.)
// USE_LEDS with some platform other than MAX32630, MAX32625MBED, LPC1768
// bugfix for MAX32600MBED LED blink pattern: check if LED_ON/LED_OFF already defined
# ifndef LED_ON
#  define LED_ON  0
# endif
# ifndef LED_OFF
#  define LED_OFF 1
# endif
//# define LED_ON  1
//# define LED_OFF 0
#endif // target definition
DigitalOut led1(LED1, LED_OFF); // MAX32630FTHR: LED1 = LED_RED
DigitalOut led2(LED2, LED_OFF); // MAX32630FTHR: LED2 = LED_GREEN
DigitalOut led3(LED3, LED_OFF); // MAX32630FTHR: LED3 = LED_BLUE
DigitalOut led4(LED4, LED_OFF);
#else // USE_LEDS=0
// issue #41 support Nucleo_F446RE
// there are no LED indicators on the board, LED1 interferes with SPI;
// but we still need placeholders led1 led2 led3 led4.
// Declare DigitalOut led1 led2 led3 led4 targeting safe pins.
// PinName NC means NOT_CONNECTED; DigitalOut::is_connected() returns false
# define LED_ON  0
# define LED_OFF 1
DigitalOut led1(NC, LED_OFF);
DigitalOut led2(NC, LED_OFF);
DigitalOut led3(NC, LED_OFF);
DigitalOut led4(NC, LED_OFF);
#endif // USE_LEDS
#define led1_RFailLED led1
#define led2_GPassLED led2
#define led3_BBusyLED led3

//--------------------------------------------------
// TODO support CmdLine command menus (like on Serial_Tester)
#ifndef USE_CMDLINE_MENUS
#define USE_CMDLINE_MENUS 1
//~ #undef USE_CMDLINE_MENUS
#endif
#if USE_CMDLINE_MENUS // support CmdLine command menus
#include "CmdLine.h"
#endif // USE_CMDLINE_MENUS support CmdLine command menus
#if USE_CMDLINE_MENUS // support CmdLine command menus
extern CmdLine cmdLine; // declared later
#endif // USE_CMDLINE_MENUS support CmdLine command menus

//--------------------------------------------------
// Datalog trigger types
#ifndef USE_DATALOGGER_TRIGGER
#define USE_DATALOGGER_TRIGGER 1
//~ #undef USE_DATALOGGER_TRIGGER
#endif
#if USE_DATALOGGER_TRIGGER // support Datalog trigger
typedef enum Datalogger_Trigger_enum_t {
    trigger_Halt = 0,               //!< halt
    trigger_FreeRun = 1,            //!< free run as fast as possible
    trigger_Timer = 2,              //!< timer (configure interval)
    trigger_PlatformDigitalInput,   //!< platform digital input (configure digital input pin reference)
    trigger_SPIDeviceRegRead,       //!< SPI device register read (configure regaddr, mask value, match value)
} Datalogger_Trigger_enum_t;
Datalogger_Trigger_enum_t Datalogger_Trigger = trigger_FreeRun;
#endif // USE_DATALOGGER_TRIGGER support Datalog trigger

//--------------------------------------------------
// print column header banner for csv data columns
uint8_t Datalogger_Need_PrintHeader = true;
uint8_t need_reinit = true;
void Datalogger_PrintHeader(CmdLine& cmdLine);
void Datalogger_AcquireRow();
void Datalogger_PrintRow(CmdLine& cmdLine);

//--------------------------------------------------
// Option to validate SPI link by reading PART_ID register
#ifndef VERIFY_PART_ID_IN_LOOP
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
#define VERIFY_PART_ID_IN_LOOP 1
#else
#define VERIFY_PART_ID_IN_LOOP 0
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#endif

//--------------------------------------------------
#define NUM_DUT_ANALOG_IN_CHANNELS 10

#if defined(SPI_ADC_DeviceName) // SPI connected ADC
// MAX11410 individual channels 1=LSB, 2=Volt, 0=Disabled
typedef enum SPI_AIN_Enable_t {
    SPI_AIN_Disable = 0,
    SPI_AIN_Enable_LSB = 1,
    SPI_AIN_Enable_Volt = 2,
} SPI_AIN_Enable_t;
uint8_t SPI_AIN_Enable_ch[NUM_DUT_ANALOG_IN_CHANNELS] = {
    SPI_AIN_Enable_LSB,  // AIN0 1=LSB
    SPI_AIN_Enable_LSB,  // AIN1 1=LSB
    SPI_AIN_Enable_LSB,  // AIN2 1=LSB
    SPI_AIN_Enable_LSB,  // AIN3 1=LSB
    SPI_AIN_Enable_LSB,  // AIN4 1=LSB
    SPI_AIN_Enable_LSB,  // AIN5 1=LSB
    SPI_AIN_Enable_LSB,  // AIN6 1=LSB
    SPI_AIN_Enable_LSB,  // AIN7 1=LSB
    SPI_AIN_Enable_LSB,  // AIN8 1=LSB
    SPI_AIN_Enable_LSB,  // AIN9 1=LSB
};
//
double SPI_AIN_Voltage[NUM_DUT_ANALOG_IN_CHANNELS];
// Optional custom per-channel header suffix
#ifndef HAS_SPI_AIN_customChannelHeader
#define HAS_SPI_AIN_customChannelHeader 0
#endif
#if HAS_SPI_AIN_customChannelHeader // Optional custom per-channel header suffix
const char* const SPI_AIN_customChannelHeader_ch[NUM_DUT_ANALOG_IN_CHANNELS] = {
    "", // MAX40108: AIN0_1V0_current_   0.591202*100/3.34 = 17.70065868263473mA
    "", // MAX40108: AIN1_1V0_voltage
    "WE", // MAX40108: AIN2_WE
    "CE", // MAX40108: AIN3_CE
    "*100/3.34=mA", // MAX40108: AIN4_*100/3.34=mA
    "CELL_VOLTAGE", // MAX40108: AIN5_CELL_VOLTAGE
};
#endif // HAS_SPI_AIN_customChannelHeader
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
//  ---------- Measure_Voltage_custom_props in Measure_Voltage @pre and in class properties ----------
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
// MAX11410 specific per-channel config register v_filter
uint8_t SPI_AIN_Cfg_v_filter_ch[NUM_DUT_ANALOG_IN_CHANNELS] = {
    0x34, // AIN0 @ v_filter=0x34
    0x34, // AIN1 @ v_filter=0x34
    0x34, // AIN2 @ v_filter=0x34
    0x34, // AIN3 @ v_filter=0x34
    0x34, // AIN4 @ v_filter=0x34
    0x34, // AIN5 @ v_filter=0x34
    0x34, // AIN6 @ v_filter=0x34
    0x34, // AIN7 @ v_filter=0x34
    0x34, // AIN8 @ v_filter=0x34
    0x34, // AIN9 @ v_filter=0x34
};
//
// MAX11410 specific per-channel config register v_ctrl
uint8_t SPI_AIN_Cfg_v_ctrl_ch[NUM_DUT_ANALOG_IN_CHANNELS] = {
    0x42, // AIN0 @ v_ctrl=0x42
    0x42, // AIN1 @ v_ctrl=0x42
    0x42, // AIN2 @ v_ctrl=0x42
    0x42, // AIN3 @ v_ctrl=0x42
    0x42, // AIN4 @ v_ctrl=0x42
    0x42, // AIN5 @ v_ctrl=0x42
    0x42, // AIN6 @ v_ctrl=0x42
    0x42, // AIN7 @ v_ctrl=0x42
    0x42, // AIN8 @ v_ctrl=0x42
    0x42, // AIN9 @ v_ctrl=0x42
};
//
// MAX11410 specific per-channel config register v_pga
uint8_t SPI_AIN_Cfg_v_pga_ch[NUM_DUT_ANALOG_IN_CHANNELS] = {
    0x00, // AIN0 @ v_pga=0x00
    0x00, // AIN1 @ v_pga=0x00
    0x00, // AIN2 @ v_pga=0x00
    0x00, // AIN3 @ v_pga=0x00
    0x00, // AIN4 @ v_pga=0x00
    0x00, // AIN5 @ v_pga=0x00
    0x00, // AIN6 @ v_pga=0x00
    0x00, // AIN7 @ v_pga=0x00
    0x00, // AIN8 @ v_pga=0x00
    0x00, // AIN9 @ v_pga=0x00
};
//
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
//  ---------- Measure_Voltage_custom_props ----------
//  ---------- CUSTOMIZED from MAX11410_Hello after g_MAX11410_device.Init() ----------
// filter register configuration in Measure_Voltage and Read_All_Voltages CONV_TYPE_01_Continuous
//~ const uint8_t custom_v_filter = 0x34; // @ v_filter=0x34 --*LINEF_11_SINC4          RATE_0100 |   60SPS
//~ const uint8_t custom_v_filter = 0x00; // @ v_filter=0x00 -- LINEF_00_50Hz_60Hz_FIR  RATE_0000 |  1.1SPS
//~ const uint8_t custom_v_filter = 0x01; // @ v_filter=0x01 -- LINEF_00_50Hz_60Hz_FIR  RATE_0001 |  2.1SPS
//~ const uint8_t custom_v_filter = 0x02; // @ v_filter=0x02 -- LINEF_00_50Hz_60Hz_FIR  RATE_0010 |  4.2SPS
//~ const uint8_t custom_v_filter = 0x03; // @ v_filter=0x03 -- LINEF_00_50Hz_60Hz_FIR  RATE_0011 |  8.4SPS
//~ const uint8_t custom_v_filter = 0x04; // @ v_filter=0x04 -- LINEF_00_50Hz_60Hz_FIR  RATE_0100 | 16.8SPS
//~ const uint8_t custom_v_filter = 0x10; // @ v_filter=0x10 -- LINEF_01_50Hz_FIR       RATE_0000 |  1.3SPS
//~ const uint8_t custom_v_filter = 0x11; // @ v_filter=0x11 -- LINEF_01_50Hz_FIR       RATE_0001 |  2.7SPS
//~ const uint8_t custom_v_filter = 0x12; // @ v_filter=0x12 -- LINEF_01_50Hz_FIR       RATE_0010 |  5.3SPS
//~ const uint8_t custom_v_filter = 0x13; // @ v_filter=0x13 -- LINEF_01_50Hz_FIR       RATE_0011 | 10.7SPS
//~ const uint8_t custom_v_filter = 0x14; // @ v_filter=0x14 -- LINEF_01_50Hz_FIR       RATE_0100 | 21.3SPS
//~ const uint8_t custom_v_filter = 0x15; // @ v_filter=0x15 -- LINEF_01_50Hz_FIR       RATE_0101 | 40.0SPS
//~ const uint8_t custom_v_filter = 0x20; // @ v_filter=0x20 -- LINEF_10_60Hz_FIR       RATE_0000 |   1.3SPS
//~ const uint8_t custom_v_filter = 0x21; // @ v_filter=0x21 -- LINEF_10_60Hz_FIR       RATE_0001 |   2.7SPS
//~ const uint8_t custom_v_filter = 0x22; // @ v_filter=0x22 -- LINEF_10_60Hz_FIR       RATE_0010 |   5.3SPS
//~ const uint8_t custom_v_filter = 0x23; // @ v_filter=0x23 -- LINEF_10_60Hz_FIR       RATE_0011 |  10.7SPS
//~ const uint8_t custom_v_filter = 0x24; // @ v_filter=0x24 -- LINEF_10_60Hz_FIR       RATE_0100 |  21.3SPS
//~ const uint8_t custom_v_filter = 0x25; // @ v_filter=0x25 -- LINEF_10_60Hz_FIR       RATE_0101 |  40.0SPS
//~ const uint8_t custom_v_filter = 0x30; // @ v_filter=0x30 -- LINEF_11_SINC4          RATE_0000 |    4SPS
//~ const uint8_t custom_v_filter = 0x31; // @ v_filter=0x31 -- LINEF_11_SINC4          RATE_0001 |   10SPS
//~ const uint8_t custom_v_filter = 0x32; // @ v_filter=0x32 -- LINEF_11_SINC4          RATE_0010 |   20SPS
//~ const uint8_t custom_v_filter = 0x33; // @ v_filter=0x33 -- LINEF_11_SINC4          RATE_0011 |   40SPS
//~ const uint8_t custom_v_filter = 0x34; // @ v_filter=0x34 --*LINEF_11_SINC4          RATE_0100 |   60SPS
//~ const uint8_t custom_v_filter = 0x35; // @ v_filter=0x35 -- LINEF_11_SINC4          RATE_0101 |  120SPS
//~ const uint8_t custom_v_filter = 0x36; // @ v_filter=0x36 -- LINEF_11_SINC4          RATE_0110 |  240SPS
//~ const uint8_t custom_v_filter = 0x37; // @ v_filter=0x37 -- LINEF_11_SINC4          RATE_0111 |  480SPS
//~ const uint8_t custom_v_filter = 0x38; // @ v_filter=0x38 -- LINEF_11_SINC4          RATE_1000 |  960SPS
//~ const uint8_t custom_v_filter = 0x39; // @ v_filter=0x39 -- LINEF_11_SINC4          RATE_1001 | 1920SPS
//  ---------- CUSTOMIZED from MAX11410_Hello ----------
//
//  ---------- CUSTOMIZED from MAX11410_Hello after g_MAX11410_device.Init() ----------
// pga register configuration in Measure_Voltage and Read_All_Voltages
//~ const uint8_t custom_v_pga = 0x00;    // @ v_pga=0x00 -- 0x00 SIG_PATH_00_BUFFERED
//~ const uint8_t custom_v_pga = 0x00;    // @ v_pga=0x00 -- 0x00 SIG_PATH_00_BUFFERED
//~ const uint8_t custom_v_pga = 0x10;    // @ v_pga=0x10 -- 0x10 SIG_PATH_01_BYPASS
//~ const uint8_t custom_v_pga = 0x20;    // @ v_pga=0x20 -- 0x20 SIG_PATH_10_PGA GAIN_000_1
//~ const uint8_t custom_v_pga = 0x21;    // @ v_pga=0x21 --*0x21 SIG_PATH_10_PGA GAIN_001_2
//~ const uint8_t custom_v_pga = 0x22;    // @ v_pga=0x22 -- 0x22 SIG_PATH_10_PGA GAIN_010_4
//~ const uint8_t custom_v_pga = 0x23;    // @ v_pga=0x23 -- 0x23 SIG_PATH_10_PGA GAIN_011_8
//~ const uint8_t custom_v_pga = 0x24;    // @ v_pga=0x24 -- 0x24 SIG_PATH_10_PGA GAIN_100_16
//~ const uint8_t custom_v_pga = 0x25;    // @ v_pga=0x25 -- 0x25 SIG_PATH_10_PGA GAIN_101_32
//~ const uint8_t custom_v_pga = 0x26;    // @ v_pga=0x26 -- 0x26 SIG_PATH_10_PGA GAIN_110_64
//~ const uint8_t custom_v_pga = 0x27;    // @ v_pga=0x27 -- 0x27 SIG_PATH_10_PGA GAIN_111_128
//  ---------- CUSTOMIZED from MAX11410_Hello ----------
//
//  ---------- CUSTOMIZED from MAX11410_Hello after g_MAX11410_device.Init() ----------
// ctrl register configuration in Measure_Voltage and Read_All_Voltages
//~ const uint8_t custom_v_ctrl = 0x42;   // @ v_ctrl=0x42 -- 0x40 unipolar, 0x02 REF_SEL_010_REF2P_REF2N
//~ const uint8_t custom_v_ctrl = 0x40;   // @ v_ctrl=0x40 -- 0x40 unipolar, 0x00 REF_SEL_000_AIN0_AIN1
//~ const uint8_t custom_v_ctrl = 0x44;   // @ v_ctrl=0x44 -- 0x40 unipolar, 0x04 REF_SEL_100_AIN0_AGND
//~ const uint8_t custom_v_ctrl = 0x58;   // @ v_ctrl=0x58 -- 0x40 unipolar, 0x00 REF_SEL_000_AIN0_AIN1, 0x18 refbuf
//
//~ const uint8_t custom_v_ctrl = 0x41;   // @ v_ctrl=0x41 -- 0x40 unipolar, 0x01 REF_SEL_001_REF1P_REF1N
//~ const uint8_t custom_v_ctrl = 0x45;   // @ v_ctrl=0x45 -- 0x40 unipolar, 0x05 REF_SEL_101_REF1P_AGND
//~ const uint8_t custom_v_ctrl = 0x59;   // @ v_ctrl=0x59 -- 0x40 unipolar, 0x01 REF_SEL_001_REF1P_REF1N, 0x18 refbuf
//
//~ const uint8_t custom_v_ctrl = 0x42;   // @ v_ctrl=0x42 -- 0x40 unipolar, 0x02 REF_SEL_010_REF2P_REF2N
//~ const uint8_t custom_v_ctrl = 0x46;   // @ v_ctrl=0x46 -- 0x40 unipolar, 0x06 REF_SEL_110_REF2P_AGND
//~ const uint8_t custom_v_ctrl = 0x22;   // @ v_ctrl=0x22 -- 0x20 bipolar offset binary, 0x02 REF_SEL_010_REF2P_REF2N
//~ const uint8_t custom_v_ctrl = 0x02;   // @ v_ctrl=0x02 -- 0x00 bipolar 2's complement, 0x02 REF_SEL_010_REF2P_REF2N
//
//~ const uint8_t custom_v_ctrl = 0x44;   // @ v_ctrl=0x44 -- 0x40 unipolar, 0x04 REF_SEL_100_AIN0_AGND
//~ const uint8_t custom_v_ctrl = 0x47;   // @ v_ctrl=0x47 -- 0x40 unipolar, 0x07 REF_SEL_111_AVDD_AGND
//~ const uint8_t custom_v_ctrl = 0x27;   // @ v_ctrl=0x27 -- 0x20 bipolar offset binary, 0x07 REF_SEL_111_AVDD_AGND
//~ const uint8_t custom_v_ctrl = 0x07;   // @ v_ctrl=0x07 -- 0x00 bipolar 2's complement, 0x07 REF_SEL_111_AVDD_AGND
//  ---------- CUSTOMIZED from MAX11410_Hello ----------

#if defined(SPI_ADC_DeviceName) // SPI connected ADC
// example code declare SPI interface (GPIO controlled CS)
#if defined(TARGET_MAX32625MBED)
SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13
DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
#elif defined(TARGET_MAX32625PICO)
#warning "TARGET_MAX32625PICO not previously tested; need to define pins..."
SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625PICO: pin P0_5 P0_6 P0_4
DigitalOut spi_cs(SPI0_SS); // TARGET_MAX32625PICO: pin P0_7
#elif defined(TARGET_MAX32600MBED)
SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
// TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
// void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
//
// TODO1: NUCLEO_F446RE SPI not working; CS and MOSI data looks OK but no SCLK clock pulses.
SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_NUCLEO_F446RE: Arduino 10-pin header D11 D12 D13
DigitalOut spi_cs(SPI_CS); // TARGET_NUCLEO_F446RE: PB_6 Arduino 10-pin header D10
//
#else
SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
#endif

// example code declare GPIO interface pins
// example code declare device instance
MAX11410 g_MAX11410_device(spi, spi_cs, MAX11410::MAX11410_IC);
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC

//--------------------------------------------------
// Option to Datalog Arduino platform analog inputs
#ifndef LOG_PLATFORM_AIN
#define LOG_PLATFORM_AIN 6
//~ #undef LOG_PLATFORM_AIN
#endif
#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs
//#ifndef NUM_PLATFORM_ANALOG_IN_CHANNELS
//#define NUM_PLATFORM_ANALOG_IN_CHANNELS 6
//#endif
const int NUM_PLATFORM_ANALOG_IN_CHANNELS = 6;
const double adc_full_scale_voltage[NUM_PLATFORM_ANALOG_IN_CHANNELS] = {
    analogInPin_fullScaleVoltage[0], // 1.2,
    analogInPin_fullScaleVoltage[1], // 1.2,
    analogInPin_fullScaleVoltage[2], // 1.2,
    analogInPin_fullScaleVoltage[3], // 1.2,
    analogInPin_fullScaleVoltage[4], // 6.0
    analogInPin_fullScaleVoltage[5], // 6.0
};
// Platform ADC individual channels 1=LSB, 2=Volt, 0=Disabled
typedef enum Platform_AIN_Enable_t {
    Platform_AIN_Disable = 0,
    Platform_AIN_Enable_LSB = 1,
    Platform_AIN_Enable_Volt = 2,
} Platform_AIN_Enable_t;
uint8_t Platform_Enable_ch[NUM_PLATFORM_ANALOG_IN_CHANNELS] = {
    Platform_AIN_Enable_Volt,  // AIN0 2=Volt
    Platform_AIN_Enable_Volt,  // AIN1 2=Volt
    Platform_AIN_Enable_Volt,  // AIN2 2=Volt
    Platform_AIN_Enable_Volt,  // AIN3 2=Volt
    Platform_AIN_Enable_Volt,  // AIN4 2=Volt
    Platform_AIN_Enable_Volt,  // AIN5 2=Volt
};
#ifndef HAS_Platform_AIN_customChannelHeader
#define HAS_Platform_AIN_customChannelHeader 1
#endif
#if HAS_Platform_AIN_customChannelHeader // Optional custom per-channel header suffix
const char* const Platform_AIN_customChannelHeader_ch[NUM_PLATFORM_ANALOG_IN_CHANNELS] = {
    "=AIN4", // MAX40108: AIN0_1V0_current_   0.591202*100/3.34 = 17.70065868263473mA
    "=AIN5", // MAX40108: AIN1_1V0_voltage
    "WE", // MAX40108: AIN2_WE
    "CE", // MAX40108: AIN3_CE
    "*100/3.34=mA", // MAX40108: AIN4_*100/3.34=mA
    "CELL_VOLTAGE", // MAX40108: AIN5_CELL_VOLTAGE
};
#endif // HAS_Platform_AIN_customChannelHeader
//--------------------------------------------------
// Option to log platform analog inputs as raw LSB code
#ifndef LOG_PLATFORM_ANALOG_IN_LSB
#define LOG_PLATFORM_ANALOG_IN_LSB 0
#endif
#if LOG_PLATFORM_ANALOG_IN_LSB
int Platform_LSB[NUM_PLATFORM_ANALOG_IN_CHANNELS];
#endif

//--------------------------------------------------
// Option to use platform analog inputs as Voltage
#ifndef LOG_PLATFORM_ANALOG_IN_VOLTS
#define LOG_PLATFORM_ANALOG_IN_VOLTS 1
#endif
#if LOG_PLATFORM_ANALOG_IN_VOLTS
double Platform_Voltage[NUM_PLATFORM_ANALOG_IN_CHANNELS];
#endif
#endif // defined(LOG_PLATFORM_AIN)

//--------------------------------------------------
// Option to use Command forwarding to Auxiliary serial port
// Command forwarding to Auxiliary serial port TX/RX
// Command forwarding to AUX serial TX/RX cmdLine_AUXserial
// Command forwarding to DAPLINK serial TX/RX cmdLine_DAPLINKserial
// prefer cmdLine_AUXserial if available, else cmdLine_DAPLINKserial; else we don't have this feature
#ifndef USE_AUX_SERIAL_CMD_FORWARDING
#define USE_AUX_SERIAL_CMD_FORWARDING 1
#endif // USE_AUX_SERIAL_CMD_FORWARDING
#if USE_AUX_SERIAL_CMD_FORWARDING
// Command forwarding to Auxiliary serial port TX/RX #257 -- global parameters
const size_t RX_STRING_BUF_SIZE = 1000;
int g_auxSerialCom_baud = 9600; //!< baud rate Auxiliary serial port
// transmit command string by AUX TX
#if 0
int g_auxSerialCom_tx_wait_echo = 0;       //!< TX wait for each character echo?
int g_auxSerialCom_tx_char_delay_ms = 0;   //!< TX delay after each char?
int g_auxSerialCom_tx_line_delay_ms = 0;   //!< TX delay after each CR/LF?
#endif
//  capture received string from AUX RX
Timer g_auxSerialCom_Timer;
int g_auxSerialCom_Timer_begin_message_ms = 0; //!< start of message
int g_auxSerialCom_Timer_begin_rx_idle_ms = 0; //!< recent RX character timestamp
int g_auxSerialCom_message_ms = 10000;     //!< maximum RX message total response time
int g_auxSerialCom_rx_idle_ms = 500;     //!< maximum RX message idle time between characters
int g_auxSerialCom_rx_max_count = RX_STRING_BUF_SIZE-1;   //!< maximum RX message total length
const int aux_serial_cmd_forwarding_rx_eot_not_used = 'x';
int g_auxSerialCom_rx_eot = aux_serial_cmd_forwarding_rx_eot_not_used;         //!< capture RX until match end of text char
//~ int g_auxSerialCom_rx_eot = 0;     //!< capture RX until match end of text string?
#endif // USE_AUX_SERIAL_CMD_FORWARDING
#if USE_AUX_SERIAL_CMD_FORWARDING
    // TODO WIP Command forwarding to Auxiliary serial port TX/RX #257
    // prefer cmdLine_AUXserial if available, else cmdLine_DAPLINKserial; else we don't have this feature
# if HAS_AUX_SERIAL
    // TODO WIP Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257
# elif HAS_DAPLINK_SERIAL
    // TODO WIP Command forwarding to DAPLINK serial TX/RX cmdLine_DAPLINKserial #257
# else // neither HAS_AUX_SERIAL HAS_DAPLINK_SERIAL
#warning "USE_AUX_SERIAL_CMD_FORWARDING should not be enabled without HAS_AUX_SERIAL or HAS_DAPLINK_SERIAL"
# endif // HAS_AUX_SERIAL HAS_DAPLINK_SERIAL
# if HAS_AUX_SERIAL
    // TODO WIP Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
    // TODO WIP Command forwarding to DAPLINK serial TX/RX cmdLine_DAPLINKserial #257
# endif // HAS_DAPLINK_SERIAL
#endif // USE_AUX_SERIAL_CMD_FORWARDING

// CODE GENERATOR: example code for ADC: serial port declaration
//--------------------------------------------------
// Declare the Serial driver
// default baud rate settings are 9600 8N1
// install device driver from http://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe
// see docs https://docs.mbed.com/docs/mbed-os-handbook/en/5.5/getting_started/what_need/
//--------------------------------------------------
#if defined(TARGET_MAX32630)
//Serial UART0serial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32630FTHR: P0_1,P0_0 (Bluetooth PAN1326B)
//Serial UART1serial(UART1_TX,UART1_RX); // tx,rx UART1 MAX32630FTHR: P2_1,P2_0 (DAPLINK)
//Serial UART2serial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32630FTHR: P3_1,P3_0 (J1.15,J1.14)
//Serial UART3serial(UART3_TX,UART3_RX); // tx,rx UART3 MAX32630FTHR: P5_4,P5_3 (J3.7,J3.8)
//
// TX/RX auxiliary UART port cmdLine_AUXserial AUXserial
Serial AUXserial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32630FTHR: P3_1,P3_0 (J1.15,J1.14)
//Serial J3AUXserial(UART3_TX,UART3_RX); // tx,rx UART3 MAX32630FTHR: P5_4,P5_3 (J3.7,J3.8)
//Serial BTAUXserial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32630FTHR: P0_1,P0_0 (Bluetooth PAN1326B)
    #define HAS_AUX_SERIAL 1
//
// Hardware serial port over DAPLink
// The default baud rate for the DapLink UART is 9600
Serial DAPLINKserial(P2_1,P2_0); // tx,rx UART1 MAX32630FTHR: P2_1,P2_0 (DAPLINK)
    #define HAS_DAPLINK_SERIAL 1
//
// Virtual serial port over USB
    #include "USBSerial.h"
// The baud rate does not affect the virtual USBSerial UART.
USBSerial serial;
//--------------------------------------------------
#elif defined(TARGET_MAX32625MBED)
//Serial UART0serial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32625MBED: P0_1,P0_0 (Arduino D1,D0)
//Serial UART1serial(UART1_TX,UART1_RX); // tx,rx UART1 MAX32625MBED: P2_1,P2_0 (DAPLINK)
//Serial UART2serial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32625MBED: P3_1,P3_0 (J15-LEDgreen,LEDred)
//
// Hardware serial port over DAPLink
// The default baud rate for the DapLink UART is 9600
Serial DAPLINKserial(P2_1,P2_0); // tx,rx UART1 MAX32625MBED: P2_1,P2_0 (DAPLINK)
    #define HAS_DAPLINK_SERIAL 1
//
// Virtual serial port over USB
    #include "USBSerial.h"
// The baud rate does not affect the virtual USBSerial UART.
USBSerial serial;
//--------------------------------------------------
#elif defined(TARGET_MAX32625PICO)
//Serial UART0serial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32625PICO: P0_1,P0_0 (pin 19/20)
//Serial UART1serial(UART1_TX,UART1_RX); // tx,rx UART1 MAX32625PICO: P2_1,P2_0 (underside?)
//Serial UART2serial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32625PICO: P3_1,P3_0 (DAPLINK)
//
// TX/RX auxiliary UART port cmdLine_AUXserial AUXserial
Serial AUXserial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32625PICO: P0_1,P0_0 (pin 19/20)
    #define HAS_AUX_SERIAL 1
//
// Hardware serial port over DAPLink
Serial DAPLINKserial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32625PICO: P3_1,P3_0 (DAPLINK)
    #define HAS_DAPLINK_SERIAL 1
//
// Virtual serial port over USB
    #include "USBSerial.h"
// The baud rate does not affect the virtual USBSerial UART.
USBSerial serial;
//--------------------------------------------------
#elif defined(TARGET_MAX32620FTHR)
#warning "TARGET_MAX32620FTHR not previously tested; need to define serial pins..."
//Serial UART0serial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32620FTHR: P0_1,P0_0 (PMOD0.2,PMOD0.3)
//Serial UART1serial(UART1_TX,UART1_RX); // tx,rx UART1 MAX32620FTHR: P2_1,P2_0 (DAPLINK)
//Serial UART2serial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32620FTHR: P3_1,P3_0 (J1.15,J1.14)
//Serial UART3serial(UART3_TX,UART3_RX); // tx,rx UART3 MAX32620FTHR: P5_4,P5_3 (J2.7,J2.8)
//
// TX/RX auxiliary UART port cmdLine_AUXserial AUXserial
Serial serial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32620FTHR: P3_1,P3_0 (J1.15,J1.14)
//Serial AUXserial(UART2_TX,UART2_RX); // tx,rx UART2 MAX32620FTHR: P3_1,P3_0 (J1.15,J1.14)
Serial AUXserial(UART3_TX,UART3_RX); // tx,rx UART3 MAX32620FTHR: P5_4,P5_3 (J2.7,J2.8)
//Serial PMOD0AUXserial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32620FTHR: P0_1,P0_0 (PMOD0.2,PMOD0.3)
    #define HAS_AUX_SERIAL 1
//
// Hardware serial port over DAPLink
// The default baud rate for the DapLink UART is 9600
Serial DAPLINKserial(USBTX, USBRX);     // tx,rx MAX32620FTHR: P2_1,P2_0
//Serial DAPLINKserial(STDIO_UART_TX, STDIO_UART_RX);     // tx, rx
    #define HAS_DAPLINK_SERIAL 1
//
// Virtual serial port over USB
//    #include "USBSerial.h"
// The baud rate does not affect the virtual USBSerial UART.
//USBSerial serial; // MAX32620FTHR: USBSerial crash??
#warning "TARGET_MAX32620FTHR not previously tested; USBSerial crash?"
//--------------------------------------------------
#elif defined(TARGET_MAX32600)
//Serial UART0serial(UART0_TX,UART0_RX); // tx,rx UART0 MAX32600MBED: P1_1,P1_0 (Arduino D1,D0)(DAPLINK)
//Serial UART1serial(UART1_TX,UART1_RX); // tx,rx UART2 MAX32625MBED: P1_3,P1_2 (Arduino D3,D2)
//Serial UART2serial(UART2_TX,UART2_RX); // tx,rx UART1 MAX32625MBED: P7_3,P7_2 ( ?? )
//
// Hardware serial port over DAPLink
// The default baud rate for the DapLink UART is 9600
Serial DAPLINKserial(P1_1,P1_0); // tx,rx UART0 MAX32600MBED: P1_1,P1_0 (Arduino D1,D0)(DAPLINK)
    #define HAS_DAPLINK_SERIAL 1
//
// Virtual serial port over USB
    #include "USBSerial.h"
// The baud rate does not affect the virtual USBSerial UART.
USBSerial serial;
//--------------------------------------------------
#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
Serial serial(SERIAL_TX, SERIAL_RX);     // tx, rx
//--------------------------------------------------
#else
#if defined(SERIAL_TX)
#warning "target not previously tested; guess serial pins are SERIAL_TX, SERIAL_RX..."
Serial serial(SERIAL_TX, SERIAL_RX);     // tx, rx
#elif defined(USBTX)
#warning "target not previously tested; guess serial pins are USBTX, USBRX..."
Serial serial(USBTX, USBRX); // tx, rx
#elif defined(UART_TX)
#warning "target not previously tested; guess serial pins are UART_TX, UART_RX..."
Serial serial(UART_TX, UART_RX);     // tx, rx
#else
#warning "target not previously tested; need to define serial pins..."
#endif
#endif
//
#include "CmdLine.h"

# if HAS_AUX_SERIAL
// TX/RX auxiliary UART port cmdLine_AUXserial AUXserial
CmdLine cmdLine_AUXserial(AUXserial, "AUXserial");
uint8_t Datalogger_enable_AUXserial = {
#if USE_AUX_SERIAL_CMD_FORWARDING
    // Command forwarding to Auxiliary serial port;
    // don't accept commands from Auxiliary serial port
    false
#else // USE_AUX_SERIAL_CMD_FORWARDING
    true
#endif // USE_AUX_SERIAL_CMD_FORWARDING
};
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
CmdLine cmdLine_DAPLINKserial(DAPLINKserial, "DAPLINK");
uint8_t Datalogger_enable_DAPLINKserial = true;
# endif // HAS_DAPLINK_SERIAL
CmdLine cmdLine(serial, "serial");
uint8_t Datalogger_enable_serial = true;
// CODE GENERATOR: example code for ADC: serial port declaration (end)

#if USE_CMDLINE_MENUS // support CmdLine command menus
//--------------------------------------------------
inline void print_command_prompt()
{
    //~ Serial.println(F(">"));
    cmdLine.serial().printf("\r\n> ");
}
#endif // USE_CMDLINE_MENUS support CmdLine command menus

#if USE_CMDLINE_MENUS // support CmdLine command menus
//--------------------------------------------------
void main_menu_status(CmdLine & cmdLine)
{
    cmdLine.serial().printf("\r\nMain menu");
#if APPLICATION_MAX5715 // main_menu_status banner
    cmdLine.serial().printf(" MAX5715 12-bit 4-ch SPI VOUT DAC");
#elif APPLICATION_MAX11131 // main_menu_status banner
    cmdLine.serial().printf(" MAX11131 12-bit 3MSps 16-ch ADC");
#elif APPLICATION_MAX5171 // main_menu_status banner
    cmdLine.serial().printf(" MAX5171 14-bit Force/Sense VOUT DAC");
#elif APPLICATION_MAX11410 // main_menu_status banner
    cmdLine.serial().printf(" MAX11410 24-bit 1.9ksps Delta-Sigma ADC");
#elif APPLICATION_MAX12345 // main_menu_status banner
    cmdLine.serial().printf(" MAX12345");
#else
    //cmdLine.serial().printf(" ");
#endif
    //cmdLine.serial().printf(" %s", TARGET_NAME);
    if (cmdLine.nameStr())
    {
        cmdLine.serial().printf(" [%s]", cmdLine.nameStr());
    }
#if HAS_BUTTON1_DEMO_INTERRUPT
    cmdLine.serial().printf(" [Button1=DemoConfig1]");
#endif
#if HAS_BUTTON2_DEMO_INTERRUPT
    cmdLine.serial().printf(" [Button2=DemoConfig2]");
#endif
#if HAS_BUTTON1_DEMO
    // print BUTTON1 status
    cmdLine.serial().printf("\r\n BUTTON1 = %d", button1.read());
#endif
#if HAS_BUTTON2_DEMO
    // print BUTTON1 status
    cmdLine.serial().printf("\r\n BUTTON2 = %d", button2.read());
#endif
    cmdLine.serial().printf("\r\n ? -- help");
}
#endif // USE_CMDLINE_MENUS support CmdLine command menus

#if USE_CMDLINE_MENUS // support CmdLine command menus
//--------------------------------------------------
void main_menu_help(CmdLine & cmdLine)
{
    // ? -- help
    //~ cmdLine.serial().printf("\r\nMenu:");
    //
    cmdLine.serial().printf("\r\n # -- lines beginning with # are comments");
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
    cmdLine.serial().printf("\r\n ! -- Init");
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#if USE_SELFTEST
    cmdLine.serial().printf("\r\n . -- SelfTest");
#endif // USE_SELFTEST
#if USE_STAR_REG_READWRITE // * command read/write reg *reg? *reg=value
// CODE GENERATOR: help menu if has_register_write_command: *regname? -- read register; *regname=regvalue -- write register
    cmdLine.serial().printf("\r\n * -- read core registers\r\n *regname? -- read register\r\n *regname=regvalue -- write register");
    // cmdLine.serial().printf("\r\n 01 23 45 67 89 ab cd ef -- write and read raw hex codes");
#endif // USE_STAR_REG_READWRITE
//
#if USE_AUX_SERIAL_CMD_FORWARDING
    // Command forwarding to Auxiliary serial port TX/RX #257 -- main_menu_help
    //~ cmdLine.serial().printf("\r\n > -- auxiliary UART port");
    // prefer cmdLine_AUXserial if available, else cmdLine_DAPLINKserial; else we don't have this feature
# if HAS_AUX_SERIAL
    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257
    if (cmdLine_AUXserial.nameStr())
    {
        cmdLine.serial().printf("\r\n > -- auxiliary UART port [%s]", cmdLine_AUXserial.nameStr());
    }
# elif HAS_DAPLINK_SERIAL
    // Command forwarding to DAPLINK serial TX/RX cmdLine_DAPLINKserial #257
    if (cmdLine_DAPLINKserial.nameStr())
    {
        cmdLine.serial().printf("\r\n > -- auxiliary UART port [%s]", cmdLine_DAPLINKserial.nameStr());
    }
# endif // HAS_AUX_SERIAL HAS_DAPLINK_SERIAL
# if HAS_AUX_SERIAL || HAS_DAPLINK_SERIAL
    // WIP Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257
    cmdLine.serial().printf("\r\n >xyzzy -- Forward command/data 'xyzzy' to aux TX/RX");
    cmdLine.serial().printf("\r\n >>xyzzy -- Forward 'xyzzy' to aux TX/RX, no key=value parsing");
    cmdLine.serial().printf("\r\n >>>xyzzy -- Forward '>xyzzy' to aux TX/RX, no key=value parsing");
    cmdLine.serial().printf("\r\n >baud=%d -- configure aux TX/RX port", g_auxSerialCom_baud);
#if 0
    cmdLine.serial().printf("\r\n >tx_wait_echo=%d -- configure TX wait for each character echo", g_auxSerialCom_tx_wait_echo);
    cmdLine.serial().printf("\r\n >tx_char_delay_ms=%d -- configure TX delay after each char", g_auxSerialCom_tx_char_delay_ms);
    cmdLine.serial().printf("\r\n >tx_line_delay_ms=%d -- configure TX delay after each CR/LF", g_auxSerialCom_tx_line_delay_ms);
#endif
    cmdLine.serial().printf("\r\n >message_ms=%d -- maximum RX message total response time", g_auxSerialCom_message_ms);
    cmdLine.serial().printf("\r\n >rx_idle_ms=%d -- maximum RX message idle time between characters", g_auxSerialCom_rx_idle_ms);
    cmdLine.serial().printf("\r\n >rx_max_count=%d -- maximum RX message total length", g_auxSerialCom_rx_max_count);
    cmdLine.serial().printf("\r\n >rx_eot=%d -- capture RX until match end of text char (unless %d)", g_auxSerialCom_rx_eot, aux_serial_cmd_forwarding_rx_eot_not_used);
# endif // HAS_AUX_SERIAL
#endif // USE_AUX_SERIAL_CMD_FORWARDING
//
#if USE_DATALOGGER_TRIGGER // support Datalog trigger
    // TODO Datalog trigger menu
    // set Datalogger_Trigger to trigger_Halt or trigger_FreeRun
    // Datalogger_Trigger = trigger_Halt // halt the datalogger; continue accepting commands
    // cmdLine.serial().print(F("\r\n L -- halt the datalogger; continue accepting commands"));
    //
    // Datalogger_Trigger = trigger_FreeRun // free run as fast as possible
    cmdLine.serial().printf("\r\n LR -- Datalog free run as fast as possible");
    //
    // TODO: Datalogger_Trigger = trigger_Timer // timer (configure interval)
    // TODO: cmdLine.serial().printf("\r\n L_ -- Datalog _______"); // trigger_Timer
    //
    // TODO: Datalogger_Trigger = trigger_PlatformDigitalInput // platform digital input (configure digital input pin reference)
    // TODO: cmdLine.serial().printf("\r\n L_ -- Datalog _______"); // trigger_PlatformDigitalInput
    //
    // TODO: Datalogger_Trigger = trigger_SPIDeviceRegRead // SPI device register read (configure regaddr, mask value, match value)
    // TODO: cmdLine.serial().printf("\r\n L_ -- Datalog _______"); // trigger_SPIDeviceRegRead
    //
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
    // LS<channel ID><verb>: Configure SPI_AIN channels
    // channel ID: 0,1,2,... or - for all channels
    // verb: D for disable, V for Voltage, L for LSB
    cmdLine.serial().printf("\r\n LS-D -- Datalog SPI ADC channel '-'(all) Disable");
    cmdLine.serial().printf("\r\n LS-V -- Datalog SPI ADC channel '-'(all) Volt");
    cmdLine.serial().printf("\r\n LS-L -- Datalog SPI ADC channel '-'(all) LSB");
    cmdLine.serial().printf("\r\n LS2D -- Datalog SPI ADC channel channel 2 Disable");
    cmdLine.serial().printf("\r\n LS3V -- Datalog SPI ADC channel channel 3 Volt");
    cmdLine.serial().printf("\r\n LS4L -- Datalog SPI ADC channel channel 4 LSB");
    //
    // MAX11410 verb for configuring SPI_AIN_Cfg_v_filter_ch[channel_index]
    // cmdLine.serial().print(F("\r\n LS-CF34 -- Datalog SPI ADC channel channel 5 v_filter 0x34"));
    cmdLine.serial().printf("\r\n LS-CF34 -- Datalog SPI ADC channel '-'(all) v_filter 0x34");
    //
    // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index]
    // cmdLine.serial().print(F("\r\n LS-CC42 -- Datalog SPI ADC channel '-'(all) v_ctrl 0x42"));
    cmdLine.serial().printf("\r\n LS-CC42 -- Datalog SPI ADC channel '-'(all) v_ctrl 0x42");    
    //
    // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index]
    // cmdLine.serial().print(F("\r\n LS5___ -- Datalog SPI ADC channel channel 5 v_ctrl"));
    // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index]
    cmdLine.serial().printf("\r\n LS5CU -- Datalog SPI ADC channel channel 5 v_ctrl Unipolar");
    // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar"
    cmdLine.serial().printf("\r\n LS5CB -- Datalog SPI ADC channel channel 5 v_ctrl Bipolar");
    // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar"
    //
    // MAX11410 verb for configuring SPI_AIN_Cfg_v_pga_ch[channel_index]
    // cmdLine.serial().print(F("\r\n LS5CP00 -- Datalog SPI ADC channel channel 5 v_pga 0x00"));
    cmdLine.serial().printf("\r\n LS-CP00 -- Datalog SPI ADC channel '-'(all) v_pga 0x00");
    //
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
    //
#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs
    // LA<channel ID><verb>: Configure Platform_AIN channels
    // channel ID: 0,1,2,... or - for all channels
    // verb: D for disable, V for Voltage, L for LSB
    cmdLine.serial().printf("\r\n LA-D -- Datalog Platform-AIN all-channel Disable");
#if LOG_PLATFORM_ANALOG_IN_VOLTS
    cmdLine.serial().printf("\r\n LA-V -- Datalog Platform-AIN all-channel Volt");
#endif // LOG_PLATFORM_ANALOG_IN_VOLTS
#if LOG_PLATFORM_ANALOG_IN_LSB
    cmdLine.serial().printf("\r\n LA-L -- Datalog Platform-AIN all-channel LSB");
#endif // LOG_PLATFORM_ANALOG_IN_LSB
    cmdLine.serial().printf("\r\n LA2D -- Datalog Platform-AIN channel 2 Disable");
#if LOG_PLATFORM_ANALOG_IN_VOLTS
    cmdLine.serial().printf("\r\n LA3V -- Datalog Platform-AIN channel 3 Volt");
#endif // LOG_PLATFORM_ANALOG_IN_VOLTS
#if LOG_PLATFORM_ANALOG_IN_LSB
    cmdLine.serial().printf("\r\n LA4L -- Datalog Platform-AIN channel 4 LSB");
#endif // LOG_PLATFORM_ANALOG_IN_LSB
#endif // defined(LOG_PLATFORM_AIN)
#endif // USE_DATALOGGER_TRIGGER support Datalog trigger
# if HAS_AUX_SERIAL
    cmdLine.serial().printf("\r\n L>A -- Datalogger_enable_AUXserial %s", (Datalogger_enable_AUXserial?"disable":"enable"));
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
    cmdLine.serial().printf("\r\n L>D -- Datalogger_enable_DAPLINKserial %s", (Datalogger_enable_DAPLINKserial?"disable":"enable"));
# endif // HAS_DAPLINK_SERIAL
    cmdLine.serial().printf("\r\n L>S -- Datalogger_enable_serial %s", (Datalogger_enable_serial?"disable":"enable"));
    //
    //cmdLine.serial().print(F("\r\n ! -- Initial Configuration"));
    //
    // % standardize diagnostic commands
    // %Hpin -- digital output high
    // %Lpin -- digital output low
    // %?pin -- digital input
    // %A %Apin -- analog input
    // %Ppin df=xx -- pwm output
    // %Wpin -- measure high pulsewidth input in usec
    // %wpin -- measure low pulsewidth input in usec
    // %I... -- I2C diagnostics
    // %IP -- I2C probe
    // %IC scl=100khz ADDR=? -- I2C configure
    // %IW ADDR=? cmd=? data,data,data -- write
    // %IR ADDR=? RD=? -- read
    // %I^ cmd=? -- i2c_smbus_read_word_data
    // %S... -- SPI diagnostics
    // %SC sclk=1Mhz -- SPI configure
    // %SW -- write (write and read)
    // %SR -- read (alias for %SW because SPI always write and read)
    // A-Z,a-z,0-9 reserved for application use
    //
#if HAS_digitalInOuts
    // %Hpin -- digital output high
    // %Lpin -- digital output low
    // %?pin -- digital input
    cmdLine.serial().printf("\r\n %%Hn {pin:");
    list_digitalInOutPins(cmdLine.serial());
    cmdLine.serial().printf("} -- High Output");
    cmdLine.serial().printf("\r\n %%Ln {pin:");
    list_digitalInOutPins(cmdLine.serial());
    cmdLine.serial().printf("} -- Low Output");
    cmdLine.serial().printf("\r\n %%?n {pin:");
    list_digitalInOutPins(cmdLine.serial());
    cmdLine.serial().printf("} -- Input");
#endif

#if HAS_analogIns
    // Menu A) analogRead A0..7
    // %A %Apin -- analog input
    // analogRead(pinIndex) // analog input pins A0, A1, A2, A3, A4, A5; float voltage = analogRead(A0) * (5.0 / 1023.0)
    cmdLine.serial().printf("\r\n %%A -- analogRead");
#endif

#if HAS_SPI2_MAX541
    // TODO1: MAX541 max541(spi2_max541, spi2_max541_cs);
    cmdLine.serial().printf("\r\n %%D -- DAC output MAX541 (SPI2)");
#endif

#if HAS_I2C // SUPPORT_I2C
    // TODO: support I2C HAS_I2C // SUPPORT_I2C
    // VERIFY: I2C utility commands SUPPORT_I2C
    // VERIFY: report g_I2C_SCL_Hz = (F_CPU / ((TWBR * 2) + 16)) from last Wire_Sr.setClock(I2C_SCL_Hz);
    // %I... -- I2C diagnostics
    // %IP -- I2C probe
    // %IC scl=100khz ADDR=? -- I2C configure
    // %IW byte byte ... byte RD=? ADDR=0x -- write
    // %IR ADDR=? RD=? -- read
    // %I^ cmd=? -- i2c_smbus_read_word_data
    //g_I2C_SCL_Hz = (F_CPU / ((TWBR * 2) + 16));   // 'F_CPU' 'TWBR' not declared in this scope
    cmdLine.serial().printf("\r\n %%IC ADDR=0x%2.2x=(0x%2.2x>>1) SCL=%d=%1.3fkHz -- I2C config",
                            g_I2C_deviceAddress7, (g_I2C_deviceAddress7 << 1), g_I2C_SCL_Hz,
                            (g_I2C_SCL_Hz / 1000.));
    cmdLine.serial().printf("\r\n %%IW byte byte ... byte RD=? ADDR=0x%2.2x -- I2C write/read",
                            g_I2C_deviceAddress7);
    //
#if SUPPORT_I2C
    // Menu ^ cmd=?) i2c_smbus_read_word_data
    cmdLine.serial().printf("\r\n %%I^ cmd=? -- i2c_smbus_read_word_data");
    // test low-level I2C i2c_smbus_read_word_data
#endif // SUPPORT_I2C
    //cmdLine.serial().printf(" H) Hunt for attached I2C devices");
    cmdLine.serial().printf("\r\n %%IP -- I2C Probe for attached devices");
    // cmdLine.serial().printf(" s) search i2c address");
#endif // SUPPORT_I2C

#if HAS_SPI // SUPPORT_SPI
    // TODO: support SPI HAS_SPI // SUPPORT_SPI
    // SPI test command  S (mosiData)+
    // %S... -- SPI diagnostics
    // %SC sclk=1Mhz -- SPI configure
    // %SW -- write (write and read)
    // %SR -- read (alias for %SW because SPI always write and read)
    // spi.format(8,0); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
    // spi.format(8,1); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=1 falling edge (initial default)
    // spi.format(8,2); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=0 falling edge (initial default)
    // spi.format(8,3); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=1 rising edge (initial default)
    // spi.frequency(1000000); // int SCLK_Hz=1000000 = 1MHz (initial default)
    // mode | POL PHA
    // -----+--------
    //   0  |  0   0
    //   1  |  0   1
    //   2  |  1   0
    //   3  |  1   1
    //cmdLine.serial().printf(" S) SPI mosi,mosi,...mosi hex bytes SCLK=1000000 CPOL=0 CPHA=0");
    // fixed: mbed-os-5.11: [Warning] format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
    cmdLine.serial().printf("\r\n %%SC SCLK=%ld=%1.3fMHz CPOL=%d CPHA=%d -- SPI config",
                            g_SPI_SCLK_Hz, (g_SPI_SCLK_Hz / 1000000.),
                            ((g_SPI_dataMode & SPI_MODE2) ? 1 : 0),
                            ((g_SPI_dataMode & SPI_MODE1) ? 1 : 0));
    cmdLine.serial().printf("\r\n %%SD -- SPI diagnostic messages ");
    if (g_MAX11410_device.onSPIprint) {
        cmdLine.serial().printf("hide");
    }
    else {
        cmdLine.serial().printf("show");
    }
    cmdLine.serial().printf("\r\n %%SW mosi,mosi,...mosi -- SPI write hex bytes");
    // VERIFY: parse new SPI settings parse_strCommandArgs() SCLK=1000000 CPOL=0 CPHA=0
#endif // SUPPORT_SPI
       //
       // Application-specific commands (help text) here
       //
#if APPLICATION_ArduinoPinsMonitor
    cmdLine.serial().printf("\r\n A-Z,a-z,0-9 -- reserved for application use");     // ArduinoPinsMonitor
#endif // APPLICATION_ArduinoPinsMonitor
       //

    //~ extern void MAX11410_menu_help(CmdLine & cmdLine); // defined in Test_Menu_MAX11410.cpp\n
    //~ MAX11410_menu_help(cmdLine);
}
#endif // USE_CMDLINE_MENUS support CmdLine command menus

#if USE_CMDLINE_MENUS // support CmdLine command menus
//--------------------------------------------------
void main_menu_onEOLcommandParser(CmdLine& cmdLine)
{
    // process command line
    cmdLine.serial().printf("\r\nCmdLine buf:\"%s\"\r\n", cmdLine.str());

#if USE_DATALOGGER_TRIGGER // support Datalog trigger
    // If datalog is free running, halt on any possible received command
    if (Datalogger_Trigger == trigger_FreeRun) {
        Datalogger_Trigger = trigger_Halt;
        cmdLine.serial().printf("Datalog stopped by USB command input\r\n");
        cmdLine.serial().printf("Restart datalog by sending LR\r\n");
    }
#endif // USE_DATALOGGER_TRIGGER support Datalog trigger

    // DIAGNOSTIC: print line buffer
    //~ cmdLine.serial().printf("\r\nmain_menu_onEOLcommandParser: ~%s~\r\n", cmdLine.str());
    //
    switch (cmdLine[0])
    {
        case '?':
            main_menu_status(cmdLine);
            main_menu_help(cmdLine);
            // print command prompt
            //cmdLine.serial().printf("\r\n>");
            break;
        case '\r': case '\n':     // ignore blank line
        case '\0':     // ignore empty line
        case '#':     // ignore comment line
            // # -- lines beginning with # are comments
            main_menu_status(cmdLine);
            //~ main_menu_help(cmdLine);
            // print command prompt
            //cmdLine.serial().printf("\r\n>");
            break;
#if ECHO_EOF_ON_EOL
        case '\x04':     // Unicode (U+0004) EOT END OF TRANSMISSION = CTRL+D as EOF end of file
            cmdLine.serial().printf("\x04");     // immediately echo EOF for test scripting
            diagnostic_led_EOF();
            break;
        case '\x1a':     // Unicode (U+001A) SUB SUBSTITUTE = CTRL+Z as EOF end of file
            cmdLine.serial().printf("\x1a");     // immediately echo EOF for test scripting
            diagnostic_led_EOF();
            break;
#endif
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
        case '!':     // device init
            {
                cmdLine.serial().printf("Init");
                // call function Init
                uint8_t result = g_MAX11410_device.Init();
                // cmdLine.serial().printf(" =%d\r\n", result);
                cmdLine.serial().printf(" =%d\r\n", result);
#if USE_CUSTOM_REG_INIT // custom_reg_init_addr[], custom_reg_init_data[], custom_reg_init_count
                // in command '!' device init, apply list of custom register writes after init
                // custom_reg_init_addr[], custom_reg_init_data[], custom_reg_init_count
                for (unsigned int index = 0; index < custom_reg_init_count; index++) {
                    uint8_t regAddress = custom_reg_init_addr[index];
                    uint32_t regData = custom_reg_init_data[index];
                    cmdLine.serial().printf("*%s=0x%06.6x",
                        g_MAX11410_device.RegName((MAX11410::MAX11410_CMD_enum_t)regAddress),
                        regData
                    );
                    g_MAX11410_device.RegWrite((MAX11410::MAX11410_CMD_enum_t)regAddress, regData);
                }
#endif // USE_CUSTOM_REG_INIT
                g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0];
                g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[0];
                g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[0];
            }
            break;
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#if USE_SELFTEST
        case '.':
        {
            // . -- SelfTest
            cmdLine.serial().printf("SelfTest()");
            SelfTest(cmdLine);
        }
        break;
#endif // USE_SELFTEST
#if 0 // APPLICATION_ArduinoPinsMonitor
        case '%':
        {
            pinsMonitor_submenu_onEOLcommandParser(cmdLine);
        }
        break;         // case '%'
#endif // APPLICATION_ArduinoPinsMonitor
#if USE_STAR_REG_READWRITE // * command read/write reg *reg? *reg=value
        // reuse the Serial_Tester command *regName=regValue
// 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");
        }
        break;
#endif // USE_STAR_REG_READWRITE // * command read/write reg *reg? *reg=value
//
#if 1 // USE_AUX_SERIAL_CMD_FORWARDING && (HAS_AUX_SERIAL || HAS_DAPLINK_SERIAL)
        // TODO WIP Command forwarding to Auxiliary serial port TX/RX #257 -- main_menu_onEOLcommandParser
        case '>':
        {
            // prefer cmdLine_AUXserial if available, else cmdLine_DAPLINKserial; else we don't have this feature
# if HAS_AUX_SERIAL
            // TODO WIP Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257
            CmdLine& cmdLine_AuxSerial = cmdLine_AUXserial;
            Serial& AuxSerial = AUXserial;
# elif HAS_DAPLINK_SERIAL
            // TODO WIP Command forwarding to DAPLINK serial TX/RX cmdLine_DAPLINKserial #257
            CmdLine& cmdLine_AuxSerial = cmdLine_DAPLINKserial;
            Serial& AuxSerial = DAPLINKserial;
# else // neither HAS_AUX_SERIAL HAS_DAPLINK_SERIAL
#warning "USE_AUX_SERIAL_CMD_FORWARDING should not be enabled without HAS_AUX_SERIAL or HAS_DAPLINK_SERIAL"
# endif // HAS_AUX_SERIAL HAS_DAPLINK_SERIAL
            //
            // >> suppress key=value parsing
            bool suppress_parsing = (cmdLine[1] == '>');
            if (suppress_parsing == false) {
                // int g_auxSerialCom_baud = 9600; //!< baud rate Auxiliary serial port
                if (cmdLine.parse_int_dec("baud", g_auxSerialCom_baud))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- baud rate
                    cmdLine_AuxSerial.serial().printf("\r\n*** New Baud Rate %d ***\r\n", g_auxSerialCom_baud);
                    AuxSerial.baud(g_auxSerialCom_baud);
                    cmdLine_AuxSerial.serial().printf("\r\n*** Baud Rate was set to %d ***\r\n", g_auxSerialCom_baud);
                }
#if 0
                // int g_auxSerialCom_tx_wait_echo = 0;       //!< TX wait for each character echo?
                if (cmdLine.parse_int_dec("tx_wait_echo", g_auxSerialCom_tx_wait_echo))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- tx_wait_echo
                    //~ cmdLine_AuxSerial.serial().printf("\r\n*** tx_wait_echo was set to %d ***\r\n", g_auxSerialCom_tx_wait_echo);
                    cmdLine.serial().printf("\r\n  tx_wait_echo=%d", g_auxSerialCom_tx_wait_echo);
                }
                // int g_auxSerialCom_tx_char_delay_ms = 0;   //!< TX delay after each char?
                if (cmdLine.parse_int_dec("tx_char_delay_ms", g_auxSerialCom_tx_char_delay_ms))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- tx_char_delay_ms
                    //~ cmdLine_AuxSerial.serial().printf("\r\n*** tx_char_delay_ms was set to %d ***\r\n", g_auxSerialCom_tx_char_delay_ms);
                    cmdLine.serial().printf("\r\n  tx_char_delay_ms=%dms", g_auxSerialCom_tx_char_delay_ms);
                }
                // int g_auxSerialCom_tx_line_delay_ms = 0;   //!< TX delay after each CR/LF?
                if (cmdLine.parse_int_dec("tx_line_delay_ms", g_auxSerialCom_tx_line_delay_ms))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- tx_line_delay_ms
                    //~ cmdLine_AuxSerial.serial().printf("\r\n*** tx_line_delay_ms was set to %d ***\r\n", g_auxSerialCom_tx_line_delay_ms);
                    cmdLine.serial().printf("\r\n  tx_line_delay_ms=%dms", g_auxSerialCom_tx_line_delay_ms);
                }
#endif
                // int g_auxSerialCom_message_ms = 0;     //!< capture RX until response timeout?
                if (cmdLine.parse_int_dec("message_ms", g_auxSerialCom_message_ms))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- message_ms
                    //~ cmdLine_AuxSerial.serial().printf("\r\n*** message_ms was set to %d ***\r\n", g_auxSerialCom_message_ms);
                    cmdLine.serial().printf("\r\n  message_ms timeout %dms", g_auxSerialCom_message_ms);
                }
                // int g_auxSerialCom_rx_idle_ms = 0;     //!< capture RX until idle timeout?
                if (cmdLine.parse_int_dec("rx_idle_ms", g_auxSerialCom_rx_idle_ms))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- rx_idle_ms
                    //~ cmdLine_AuxSerial.serial().printf("\r\n*** rx_idle_ms was set to %d ***\r\n", g_auxSerialCom_rx_idle_ms);
                    cmdLine.serial().printf("\r\n  rx_idle_ms timeout %dms", g_auxSerialCom_rx_idle_ms);
                }
                // int g_auxSerialCom_rx_max_count = 0;   //!< capture RX until max character count?
                if (cmdLine.parse_int_dec("rx_max_count", g_auxSerialCom_rx_max_count))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- rx_max_count
                    //~ cmdLine_AuxSerial.serial().printf("\r\n*** rx_max_count was set to %d ***\r\n", g_auxSerialCom_rx_max_count);
                    cmdLine.serial().printf("\r\n  rx_max_count %d bytes", g_auxSerialCom_rx_max_count);
                }
                // int g_auxSerialCom_rx_eot = 0;         //!< capture RX until match end of text char?
                if (cmdLine.parse_int_dec("rx_eot", g_auxSerialCom_rx_eot))
                {
                    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- rx_eot
                    //~ cmdLine_AUXserial.serial().printf("\r\n*** rx_eot was set to %d ***\r\n", g_auxSerialCom_rx_eot);
                    cmdLine.serial().printf("\r\n  rx_eot %d", g_auxSerialCom_rx_eot);
                }
            }
            // Command forwarding to AUX serial TX/RX cmdLine_AuxSerial #257 -- send outgoing_string
            char* outgoing_string = (char*)cmdLine.str();
            // > use key=value parsing
            // >> suppress key=value parsing
            if (suppress_parsing) {
                cmdLine.serial().printf("\r\n  suppress_parsing outgoing_string=\"%s\"", outgoing_string);
                outgoing_string++; // skip the first '>'
                outgoing_string++; // skip the second '>'
            } else {
                // TODO: after parsing, key=value pairs should be deleted, but outgoing_string=">xyzzy abc=def"
                cmdLine.serial().printf("\r\n  after parsing, outgoing_string=\"%s\"", outgoing_string);
                outgoing_string++; // skip the first '>'
            }
            static char rx_string_buf[RX_STRING_BUF_SIZE];
            unsigned int rx_string_length = 0;
            cmdLine.serial().printf("\r\n  >%s\r\n  <", outgoing_string);
            rx_string_buf[0] = '\0';
            rx_string_length = 0;
            //
            // int g_auxSerialCom_tx_wait_echo = 0;       //!< TX wait for each character echo?
            // int g_auxSerialCom_tx_char_delay_ms = 0;   //!< TX delay after each char?
            // int g_auxSerialCom_tx_line_delay_ms = 0;   //!< TX delay after each CR/LF?
            //
            // int g_auxSerialCom_Timer_begin_message_ms = 0; //!< start of message
            // int g_auxSerialCom_Timer_begin_rx_idle_ms = 0; //!< recent RX character timestamp
            // int g_auxSerialCom_message_ms = 10000;     //!< maximum RX message total response time
            // int g_auxSerialCom_rx_idle_ms = 2000;     //!< maximum RX message idle time between characters
            // int g_auxSerialCom_rx_max_count = RX_STRING_BUF_SIZE-1;   //!< maximum RX message total length
            // int g_auxSerialCom_rx_eot = '\r';         //!< capture RX until match end of text char
            //~ cmdLine_AuxSerial.serial().printf("\r\n*** TODO forward %s ***\r\n", outgoing_string);
            //
            // TODO: send whole string or send character-by-character?
            cmdLine_AuxSerial.serial().printf("%s", outgoing_string);
            cmdLine_AuxSerial.serial().printf("\r\n");
            g_auxSerialCom_Timer.start();
            g_auxSerialCom_Timer_begin_message_ms = g_auxSerialCom_Timer.read_ms(); // start of message
            g_auxSerialCom_Timer_begin_rx_idle_ms = g_auxSerialCom_Timer.read_ms(); // recent RX character timestamp
            while (rx_string_length < (RX_STRING_BUF_SIZE-1)) {
                if ((g_auxSerialCom_Timer.read_ms() - g_auxSerialCom_Timer_begin_message_ms) > g_auxSerialCom_message_ms) {
                    cmdLine.serial().printf("\r\n  message_ms timeout %dms", g_auxSerialCom_message_ms);
                    break;
                }
                if ((g_auxSerialCom_Timer.read_ms() - g_auxSerialCom_Timer_begin_rx_idle_ms) > g_auxSerialCom_rx_idle_ms) {
                    cmdLine.serial().printf("\r\n  rx_idle_ms timeout %dms", g_auxSerialCom_rx_idle_ms);
                    break;
                }
                if (rx_string_length >= g_auxSerialCom_rx_max_count) {
                    cmdLine.serial().printf("\r\n  rx_max_count %d bytes", g_auxSerialCom_rx_max_count);
                    break;
                }
                if (AuxSerial.readable()) {
                    g_auxSerialCom_Timer_begin_rx_idle_ms = g_auxSerialCom_Timer.read_ms(); // recent RX character timestamp
                    char ch = AuxSerial.getc();
                    rx_string_buf[rx_string_length++] = ch;
                    rx_string_buf[rx_string_length] = '\0'; // null terminate buffer
                    cmdLine.serial().printf("%s", &(rx_string_buf[rx_string_length-1]) ); // immediate character echo
                    if (g_auxSerialCom_rx_eot != aux_serial_cmd_forwarding_rx_eot_not_used) {
                        if (ch == g_auxSerialCom_rx_eot) {
                            cmdLine.serial().printf("\r\n  rx_eot %d", g_auxSerialCom_rx_eot);
                            break;
                        }
                    }
                }
            } // end while (rx_string_length < (RX_STRING_BUF_SIZE-1))
            #if 1
            // print summary. is this needed? we already print aux rx as it is received.
            rx_string_buf[rx_string_length] = '\0'; // null terminate buffer
            cmdLine.serial().printf("\r\n  >%s", outgoing_string);
            cmdLine.serial().printf("\r\n  <%s\r\n", rx_string_buf);
            #endif
            //
        }
        break;         // case '>'
#endif // USE_AUX_SERIAL_CMD_FORWARDING
//
#if USE_DATALOGGER_TRIGGER // support Datalog trigger
        // TODO Datalog trigger menu
        // set Datalogger_Trigger to trigger_Halt or trigger_FreeRun
        // Datalogger_Trigger = trigger_Halt // halt the datalogger; continue accepting commands
        // Datalogger_Trigger = trigger_FreeRun // free run as fast as possible
        case 'L': case 'l':
        {
            // halt the datalogger; continue accepting commands
            Datalogger_Trigger = trigger_Halt;
            switch (cmdLine[1])
            {
                case 'R': case 'r':
                    // free run as fast as possible
                    Datalogger_Trigger = trigger_FreeRun;
                    Datalogger_Need_PrintHeader = true;
                    return; // instead of break; avoid falling through to print_command_prompt();
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
                // LS<channel ID><verb>: Configure SPI_AIN channels
                // channel ID: 0,1,2,... or - for all channels
                // verb: D for disable, V for Voltage, L for LSB
                case 'S': case 's':
                    {
                        for (int channel_index = 0; channel_index < NUM_DUT_ANALOG_IN_CHANNELS; channel_index++) {
                            if ((cmdLine[2] == '-' /* all channels */) 
                            ||  (cmdLine[2] == '0'+channel_index)
                               )
                            {
                                // it's me
                                // test cmdLine[3] to determine action
                                // Platform_Enable_ch[channel_index] = Platform_AIN_xxxxx;
                                switch (cmdLine[3])
                                {
                                    case 'D': case 'd':
                                        SPI_AIN_Enable_ch[channel_index] = SPI_AIN_Disable;
                                        break;
                                    case 'L': case 'l':
                                        SPI_AIN_Enable_ch[channel_index] = SPI_AIN_Enable_LSB;
                                        break;
                                    case 'V': case 'v':
                                        SPI_AIN_Enable_ch[channel_index] = SPI_AIN_Enable_Volt;
                                        break;
                                    //
                                    //
                                    // TODO: MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index]
                                    case 'C': case 'c':
                                    {
                                        uint8_t hexValue = 0;
                                        hexValue = hexValueOfChar(cmdLine[5]) * 0x10 + hexValueOfChar(cmdLine[6]);
                                        switch (cmdLine[4])
                                        {
                                            //
                                            // MAX11410 verb for configuring SPI_AIN_Cfg_v_filter_ch[channel_index]
                                            // cmdLine.serial().print(F("\r\n LS-CF34 -- Datalog SPI ADC channel '-'(all) v_filter 0x34"));
                                            case 'F': case 'f':
                                                SPI_AIN_Cfg_v_filter_ch[channel_index] = hexValue;
                                                break;
                                            //
                                            // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index]
                                            // cmdLine.serial().print(F("\r\n LS-CC42 -- Datalog SPI ADC channel '-'(all) v_ctrl 0x42"));
                                            case 'C': case 'c':
                                                SPI_AIN_Cfg_v_ctrl_ch[channel_index] = hexValue;
                                                break;
                                            //
                                            // MAX11410 verb for configuring SPI_AIN_Cfg_v_pga_ch[channel_index]
                                            // cmdLine.serial().print(F("\r\n LS-CP00 -- Datalog SPI ADC channel '-'(all) v_pga 0x00"));
                                            case 'P': case 'p':
                                                SPI_AIN_Cfg_v_pga_ch[channel_index] = hexValue;
                                                break;
                                            //
                                            // cmdLine.serial().print(F("\r\n LS5CU -- Datalog SPI ADC channel channel 5 v_ctrl Unipolar"));
                                            // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar"
                                            case 'U': case 'u':
                                                SPI_AIN_Cfg_v_ctrl_ch[channel_index] = SPI_AIN_Cfg_v_ctrl_ch[channel_index] | 0x40;
                                                break;
                                            //
                                            // cmdLine.serial().print(F("\r\n LS5CB -- Datalog SPI ADC channel channel 5 v_ctrl Bipolar"));
                                            // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar"
                                            case 'B': case 'b':
                                                SPI_AIN_Cfg_v_ctrl_ch[channel_index] = SPI_AIN_Cfg_v_ctrl_ch[channel_index] &~ 0x40;
                                                break;
                                        }
                                        break;
                                    }
                                    //
                                    //
                                }
                            } // end if cmdLine[2] channel_index
                        } // end for channel_index
                        Datalogger_PrintHeader();
                        Datalogger_Need_PrintHeader = true;
                    }
                    break;
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs
                // LA<channel ID><verb>: Configure Platform_AIN channels
                // channel ID: 0,1,2,... or - for all channels
                // verb: D for disable, V for Voltage, L for LSB
                case 'A': case 'a':
                    {
                        // all-channel: loop through all valid channel_index, test cmdLine[2] 'is it me'?
                        // for channel_index loop through 0..NUM_DUT_ANALOG_IN_CHANNELS
                        //   if ((cmdLine[2] == '-' /* all channels */) 
                        //   ||  (cmdLine[2] == '0'+channel_index)
                        //      ) {
                        //       // it's me
                        //       // test cmdLine[3] to determine action
                        //       // Platform_Enable_ch[channel_index] = Platform_AIN_xxxxx;
                        //   } end if cmdLine[2] channel_index
                        // } end for channel_index
                        for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; channel_index++) {
                            if ((cmdLine[2] == '-' /* all channels */) 
                            ||  (cmdLine[2] == '0'+channel_index)
                               )
                            {
                                // it's me
                                // test cmdLine[3] to determine action
                                // Platform_Enable_ch[channel_index] = Platform_AIN_xxxxx;
                                switch (cmdLine[3])
                                {
                                    case 'D': case 'd':
                                        Platform_Enable_ch[channel_index] = Platform_AIN_Disable;
                                        break;
#if LOG_PLATFORM_ANALOG_IN_LSB
                                    case 'L': case 'l':
                                        Platform_Enable_ch[channel_index] = Platform_AIN_Enable_LSB;
                                        break;
#endif // LOG_PLATFORM_ANALOG_IN_LSB
#if LOG_PLATFORM_ANALOG_IN_VOLTS
                                    case 'V': case 'v':
                                        Platform_Enable_ch[channel_index] = Platform_AIN_Enable_Volt;
                                        break;
#endif // LOG_PLATFORM_ANALOG_IN_VOLTS
                                }
                            } // end if cmdLine[2] channel_index
                        } // end for channel_index
                        // Datalogger_PrintHeader(cmdLine);
                        if (Datalogger_enable_serial) {
                            Datalogger_PrintHeader(cmdLine);
                        }
        # if HAS_AUX_SERIAL
                        if (Datalogger_enable_AUXserial) {
                            Datalogger_PrintHeader(cmdLine_AUXserial);
                        }
        # endif // HAS_AUX_SERIAL
        # if HAS_DAPLINK_SERIAL
                        if (Datalogger_enable_DAPLINKserial) {
                            Datalogger_PrintHeader(cmdLine_DAPLINKserial);
                        }
        # endif // HAS_DAPLINK_SERIAL
                        Datalogger_Need_PrintHeader = true;
                    }
                    break;
#endif // defined(LOG_PLATFORM_AIN)
                case '>':
                    // L>A -- Datalogger_enable_AUXserial
                    // L>D -- Datalogger_enable_DAPLINKserial
                    // L>S -- Datalogger_enable_serial
                    switch (cmdLine[2])
                    {
# if HAS_AUX_SERIAL
                        case 'A': case 'a':
                            Datalogger_enable_AUXserial = !Datalogger_enable_AUXserial;
                            Datalogger_Need_PrintHeader = true;
                            break;
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
                        case 'D': case 'd':
                            Datalogger_enable_DAPLINKserial = !Datalogger_enable_DAPLINKserial;
                            Datalogger_Need_PrintHeader = true;
                            break;
# endif // HAS_DAPLINK_SERIAL
                        case 'S': case 's':
                            Datalogger_enable_serial = !Datalogger_enable_serial;
                            Datalogger_Need_PrintHeader = true;
                            break;
                    }
                    break; // case '>' L>S serial enable toggle
            }
        }
        break;         // case 'L'
#endif // USE_DATALOGGER_TRIGGER support Datalog trigger
       //
       // Application-specific commands here
       // alphanumeric command codes A-Z,a-z,0-9 reserved for application use
       //
#if APPLICATION_ArduinoPinsMonitor
#endif // APPLICATION_ArduinoPinsMonitor

        //
        // TODO1: add new commands here
        //
        default:
#if APPLICATION_MAX5715 // main_menu_onEOLcommandParser print command prompt
            extern bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX5715.cpp
            if (!MAX5715_menu_onEOLcommandParser(cmdLine))
#elif APPLICATION_MAX11131 // main_menu_onEOLcommandParser print command prompt
            extern bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX11131.cpp
            if (!MAX11131_menu_onEOLcommandParser(cmdLine))
#elif APPLICATION_MAX5171 // main_menu_onEOLcommandParser print command prompt
            extern bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX5171.cpp
            if (!MAX5171_menu_onEOLcommandParser(cmdLine))
#elif APPLICATION_MAX11410 // main_menu_onEOLcommandParser print command prompt
            extern bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX11410.cpp
            if (!MAX11410_menu_onEOLcommandParser(cmdLine))
#elif APPLICATION_MAX12345 // main_menu_onEOLcommandParser print command prompt
            extern bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX12345.cpp
            if (!MAX12345_menu_onEOLcommandParser(cmdLine))
#else
            if (0) // not_handled_by_device_submenu
#endif
            {
                cmdLine.serial().printf("\r\n unknown command ");
                //~ cmdLine.serial().printf("\r\n unknown command 0x%2.2x \"%s\"\r\n", cmdLine.str()[0], cmdLine.str());
# if HAS_DAPLINK_SERIAL
                cmdLine_DAPLINKserial.serial().printf("\r\n unknown command 0x%2.2x \"%s\"\r\n",
                                                      cmdLine.str()[0], cmdLine.str());
# endif // HAS_DAPLINK_SERIAL
            }
    }     // switch (cmdLine[0])
//
// print command prompt
    // print_command_prompt();
    cmdLine.serial().printf("\r\n> ");
}
#endif // USE_CMDLINE_MENUS support CmdLine command menus

//--------------------------------------------------
// print column header banner for csv data columns
void Datalogger_PrintHeader(CmdLine& cmdLine)
{
    // column header banner for csv data columns
        int field_index = 0;
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
        for (int channel_index = 0; channel_index < NUM_DUT_ANALOG_IN_CHANNELS; channel_index++) {
            if (SPI_AIN_Enable_ch[channel_index] == SPI_AIN_Disable) {
                continue;
            }
            // comma between fields
            if (field_index > 0) {
                cmdLine.serial().printf(",");
            }
            field_index++;
            // AIN_index column header prefix
#if SPI_ADC_DeviceName == MAX11410 // SPI connected ADC
            // MAX11410 v_ctrl bipolar configuration or unipolar?
            if ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) {
                cmdLine.serial().printf("\"AIN%d-%d_BIP", channel_index, channel_index+1);
            }
            else {
                cmdLine.serial().printf("\"AIN%d", channel_index);
            }
#else // SPI_ADC_DeviceName == MAX11410 // SPI connected ADC
            cmdLine.serial().printf("\"AIN%d", channel_index);
#endif // SPI_ADC_DeviceName == MAX11410 // SPI connected ADC
            if (SPI_AIN_Enable_ch[channel_index] == SPI_AIN_Enable_LSB) {
                // _LSB column header suffix
                cmdLine.serial().printf("_LSB");
# if HAS_DAPLINK_SERIAL
                cmdLine_DAPLINKserial.serial().printf("_LSB");
# endif // HAS_DAPLINK_SERIAL
            }
            else if (SPI_AIN_Enable_ch[channel_index] == SPI_AIN_Enable_Volt) {
                // _V column header suffix
                cmdLine.serial().printf("_V");
# if HAS_DAPLINK_SERIAL
                cmdLine_DAPLINKserial.serial().printf("_V");
# endif // HAS_DAPLINK_SERIAL
            }
#if HAS_SPI_AIN_customChannelHeader // Optional custom per-channel header suffix
            // Optional custom per-channel header suffix
            if (SPI_AIN_customChannelHeader_ch[channel_index] && SPI_AIN_customChannelHeader_ch[channel_index][0]) {
                // not a null pointer, and not an empty string
                cmdLine.serial().printf("_%s", SPI_AIN_customChannelHeader_ch[channel_index]);
# if HAS_DAPLINK_SERIAL
                cmdLine_DAPLINKserial.serial().printf("_%s", SPI_AIN_customChannelHeader_ch[channel_index]);
# endif // HAS_DAPLINK_SERIAL
            } else {
                // no custom channel name for this channel
                //~ cmdLine.serial().printf("~");
# if HAS_DAPLINK_SERIAL
                //~ cmdLine_DAPLINKserial.serial().printf("~");
# endif // HAS_DAPLINK_SERIAL
            }
#endif // HAS_SPI_AIN_customChannelHeader
            // close quote
            cmdLine.serial().printf("\"");
# if HAS_DAPLINK_SERIAL
            cmdLine_DAPLINKserial.serial().printf("\"");
# endif // HAS_DAPLINK_SERIAL
        }

#if VERIFY_PART_ID_IN_LOOP
        // PART_ID field: Device ID Validation
        cmdLine.serial().printf(",\"PART_ID\"");
# if HAS_DAPLINK_SERIAL
        cmdLine_DAPLINKserial.serial().printf(",\"PART_ID\"");
# endif // HAS_DAPLINK_SERIAL
#endif // VERIFY_PART_ID_IN_LOOP
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs
        for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; channel_index++) {
            if (Platform_Enable_ch[channel_index] == Platform_AIN_Disable) {
                continue;
            }
            // comma between fields
            if (field_index > 0) {
                cmdLine.serial().printf(",");
            }
            field_index++;
            // AIN_index column header prefix
            cmdLine.serial().printf("\"A%d", channel_index);
            if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_LSB) {
                // _LSB column header suffix
                cmdLine.serial().printf("_LSB");
            }
            if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_Volt) {
                // _V column header suffix
                cmdLine.serial().printf("_V");
            }
#if HAS_Platform_AIN_customChannelHeader // Optional custom per-channel header suffix
            // Optional custom per-channel header suffix
            if (Platform_AIN_customChannelHeader_ch[channel_index] && Platform_AIN_customChannelHeader_ch[channel_index][0]) {
                // not a null pointer, and not an empty string
                cmdLine.serial().printf("_%s", Platform_AIN_customChannelHeader_ch[channel_index]);
# if HAS_DAPLINK_SERIAL
                cmdLine_DAPLINKserial.serial().printf("_%s", Platform_AIN_customChannelHeader_ch[channel_index]);
# endif // HAS_DAPLINK_SERIAL
            } else {
                // no custom channel name for this channel
                //~ cmdLine.serial().printf("~");
# if HAS_DAPLINK_SERIAL
                //~ cmdLine_DAPLINKserial.serial().printf("~");
# endif // HAS_DAPLINK_SERIAL
            }
#endif // HAS_Platform_AIN_customChannelHeader
            // close quote
            cmdLine.serial().printf("\"");
# if HAS_DAPLINK_SERIAL
            cmdLine_DAPLINKserial.serial().printf("\"");
# endif // HAS_DAPLINK_SERIAL
        }
#endif // defined(LOG_PLATFORM_AIN)
        // end of column header line
        cmdLine.serial().printf("\r\n");
# if HAS_DAPLINK_SERIAL
        cmdLine_DAPLINKserial.serial().printf("\r\n");
# endif // HAS_DAPLINK_SERIAL
} // void Datalogger_PrintHeader()

//--------------------------------------------------
void Datalogger_AcquireRow()
{
            // CODE GENERATOR: example code: has no member function ScanStandardExternalClock
            // CODE GENERATOR: example code: has no member function ReadAINcode
            // CODE GENERATOR: example code: member function Read_All_Voltages
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
            // Measure ADC channels in sequence from AIN0 to channelNumber_0_9.
            // @param[in] g_MAX11410_device.channelNumber_0_15: AIN Channel Number
            // @param[in] g_MAX11410_device.PowerManagement_0_2: 0=Normal, 1=AutoShutdown, 2=AutoStandby
            // @param[in] g_MAX11410_device.chan_id_0_1: ADC_MODE_CONTROL.CHAN_ID
            //~ int channelId_0_9 = NUM_DUT_ANALOG_IN_CHANNELS-1+1;
            //g_MAX11410_device.channelNumber_0_15 = channelId_0_9;
            //g_MAX11410_device.PowerManagement_0_2 = 0;
            //g_MAX11410_device.chan_id_0_1 = 1;
            //----------------------------------------
            // scan AIN0..AIN9
            //
#if 1
            g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0];
            g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[0];
            g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[0];
            //
            // diagnostic GPIO pulse on MAX11410 GP1 pin (0xc3 = logic 0, 0xc4 = logic 1)
            g_MAX11410_device.RegWrite(MAX11410::CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc3); // GP1 = 0
            //
            int field_index = 0;
            for (int channel_index = 0; channel_index < NUM_DUT_ANALOG_IN_CHANNELS; channel_index++) {
                if (SPI_AIN_Enable_ch[channel_index] == SPI_AIN_Disable) {
                    continue;
                }
                field_index++;
                g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[channel_index];
                g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[channel_index];
                g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[channel_index];
                //
                // WIP SampleRate_of_FILTER_CONV_START() MAX11410EMC-FW slow ODR 10Sps #262
                // adjust the MAX11410.loop_limit value if the sample rate is set to a value slower than 20sps
                // SampleRate_of_FILTER_CONV_START(uint8_t FILTER_RegValue, uint8_t CONV_START_RegValue)
                double SampleRate = g_MAX11410_device.SampleRate_of_FILTER_CONV_START(g_MAX11410_device.v_filter, MAX11410::MAX11410_CONV_TYPE_enum_t::CONV_TYPE_01_Continuous);
                if (SampleRate < 20.0) {
                    g_MAX11410_device.loop_limit = 32767; // TODO: is this timeout long enough for the slow output data rates?
                }
                //
                // diagnostic GPIO pulse on MAX11410 GP0 pin (0xc3 = logic 0, 0xc4 = logic 1)
                g_MAX11410_device.RegWrite(MAX11410::CMD_r000_0100_dddd_xddd_GP0_CTRL, 0xc3); // GP0 = 0
                //
#if SPI_ADC_DeviceName == MAX11410 // SPI connected ADC
                // MAX11410 v_ctrl bipolar configuration or unipolar?
                if ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) {
                    const MAX11410::MAX11410_AINP_SEL_enum_t ainp = (MAX11410::MAX11410_AINP_SEL_enum_t)(channel_index);
                    const MAX11410::MAX11410_AINN_SEL_enum_t ainn = (MAX11410::MAX11410_AINN_SEL_enum_t)(channel_index^1);
                    SPI_AIN_Voltage[channel_index] = g_MAX11410_device.Measure_Voltage(ainp, ainn);
                    // @post AINcode[ainp]: measurement result LSB code
                }
                else {
                    const MAX11410::MAX11410_AINP_SEL_enum_t ainp = (MAX11410::MAX11410_AINP_SEL_enum_t)(channel_index);
                    const MAX11410::MAX11410_AINN_SEL_enum_t ainn = MAX11410::AINN_SEL_1010_GND;
                    SPI_AIN_Voltage[channel_index] = g_MAX11410_device.Measure_Voltage(ainp, ainn);
                    // @post AINcode[ainp]: measurement result LSB code
                }
#endif // SPI_ADC_DeviceName == MAX11410 // SPI connected ADC
                //
                // diagnostic GPIO pulse on MAX11410 GP0 pin (0xc3 = logic 0, 0xc4 = logic 1)
                g_MAX11410_device.RegWrite(MAX11410::CMD_r000_0100_dddd_xddd_GP0_CTRL, 0xc4); // GP0 = 1
                //
            }
            // diagnostic GPIO pulse on MAX11410 GP1 pin (0xc3 = logic 0, 0xc4 = logic 1)
            g_MAX11410_device.RegWrite(MAX11410::CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc4); // GP1 = 1
#else
            g_MAX11410_device.Read_All_Voltages();
#endif
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs
            // mbed
            // Platform board uses simple analog inputs
#if LOG_PLATFORM_ANALOG_IN_LSB
            Platform_LSB[0] = analogIn0.read();
            Platform_LSB[1] = analogIn1.read();
            Platform_LSB[2] = analogIn2.read();
            Platform_LSB[3] = analogIn3.read();
            Platform_LSB[4] = analogIn4.read();
            Platform_LSB[5] = analogIn5.read();
#endif
#if LOG_PLATFORM_ANALOG_IN_VOLTS
            Platform_Voltage[0] = analogIn0.read() * adc_full_scale_voltage[0];
            Platform_Voltage[1] = analogIn1.read() * adc_full_scale_voltage[1];
            Platform_Voltage[2] = analogIn2.read() * adc_full_scale_voltage[2];
            Platform_Voltage[3] = analogIn3.read() * adc_full_scale_voltage[3];
            Platform_Voltage[4] = analogIn4.read() * adc_full_scale_voltage[4];
            Platform_Voltage[5] = analogIn5.read() * adc_full_scale_voltage[5];
#endif
#endif // defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs

#if VERIFY_PART_ID_IN_LOOP
            // PART_ID field: Device ID Validation
            const uint32_t part_id_expect = 0x000F02;
            uint32_t part_id_readback;
            g_MAX11410_device.RegRead(MAX11410::CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback);
#endif // VERIFY_PART_ID_IN_LOOP
} // void Datalogger_AcquireRow()

//--------------------------------------------------
void Datalogger_PrintRow(CmdLine& cmdLine)
{
            int field_index = 0;
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
            for (int channel_index = 0; channel_index < NUM_DUT_ANALOG_IN_CHANNELS; channel_index++) {
                if (SPI_AIN_Enable_ch[channel_index] == SPI_AIN_Disable) {
                    continue;
                }
                // comma between fields
                if (field_index > 0) {
                    cmdLine.serial().printf(",");
                }
                field_index++;
                if (SPI_AIN_Enable_ch[channel_index] == Platform_AIN_Enable_LSB) {
                    cmdLine.serial().printf("%d", g_MAX11410_device.AINcode[channel_index]);
                }
                if (SPI_AIN_Enable_ch[channel_index] == Platform_AIN_Enable_Volt) {
                    // TODO: report Voltage instead of LSB
                    // Serial.print(SPI_AIN_Voltage[channel_index]);
                    static char strOutLineBuffer[16];
                    cmdLine.serial().printf("%6.6f", SPI_AIN_Voltage[channel_index]);
                }
            }
#if VERIFY_PART_ID_IN_LOOP
            // PART_ID field: Device ID Validation
            if (part_id_readback != part_id_expect) {
                cmdLine.serial().printf(",\"FAIL\"");
                need_reinit = true;
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
                g_MAX11410_device.Init();
                g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0];
                g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[0];
                g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[0];
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
            }
            else {
                cmdLine.serial().printf(",\"OK\"");
            }
#endif // VERIFY_PART_ID_IN_LOOP
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs
            for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; channel_index++) {
                if (Platform_Enable_ch[channel_index] == Platform_AIN_Disable) {
                    continue;
                }
                // comma between fields
                if (field_index > 0) {
                    cmdLine.serial().printf(",");
                }
                field_index++;
                if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_LSB) {
#if LOG_PLATFORM_ANALOG_IN_LSB
                    cmdLine.serial().printf("%u", Platform_LSB[channel_index]);
#endif
                }
                if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_Volt) {
#if LOG_PLATFORM_ANALOG_IN_VOLTS
                    // Datalog Volts omit V suffix from numbers #275
                    // because Excel graphs can't handle numbers that have a suffix.
                    cmdLine.serial().printf("%6.6f", Platform_Voltage[channel_index]);
#endif
                }
            }
#endif // defined(LOG_PLATFORM_AIN)
            if (need_reinit) {
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
                if (g_MAX11410_device.Init() == 0) {
                    //~ cmdLine.serial().printf(",\"Init() failed\"");
                } else {
                    //~ cmdLine.serial().printf(",\"Init() success\"");
#if USE_CUSTOM_REG_INIT // custom_reg_init_addr[], custom_reg_init_data[], custom_reg_init_count
                    // in Datalogger_PrintRow(), when part_id test fails, 
                    // apply list of custom register writes after re-init
                    // custom_reg_init_addr[], custom_reg_init_data[], custom_reg_init_count
                    for (unsigned int index = 0; index < custom_reg_init_count; index++) {
                        uint8_t regAddress = custom_reg_init_addr[index];
                        uint32_t regData = custom_reg_init_data[index];
                        cmdLine.serial().printf("*%s=0x%06.6x", g_MAX11410_device.RegName(regAddress), regData);
                        g_MAX11410_device.RegWrite((MAX11410::MAX11410_CMD_enum_t)regAddress, regData);
                    }
#endif // USE_CUSTOM_REG_INIT
                    g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0];
                    g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[0];
                    g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[0];
                    need_reinit = false;
                }
#else // defined(SPI_ADC_DeviceName) // SPI connected ADC
                need_reinit = false;
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
            }
            cmdLine.serial().printf("\r\n");
            if (need_reinit) {
                //~ delay(500); // platform_delay_ms 500ms timing delay function
            }
} // void Datalogger_PrintRow()

// example code main function
int main()
{
    // setup: put your setup code here, to run once
#if USE_CMDLINE_MENUS // support CmdLine command menus
    // Configure serial ports
    cmdLine.clear();
    //~ cmdLine.serial().printf("\r\n cmdLine.serial().printf test\r\n");
    cmdLine.onEOLcommandParser = main_menu_onEOLcommandParser;
    //~ cmdLine.diagnostic_led_EOF = diagnostic_led_EOF;
    /// CmdLine::set_immediate_handler(char, functionPointer_void_void_on_immediate_0x21);
    //~ cmdLine.on_immediate_0x21 = on_immediate_0x21;
    //~ cmdLine.on_immediate_0x7b = on_immediate_0x7b;
    //~ cmdLine.on_immediate_0x7d = on_immediate_0x7d;
# if HAS_DAPLINK_SERIAL
#if 0 // HARD CRASH -- USE_AUX_SERIAL_CMD_FORWARDING
    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- init aux baud rate g_auxSerialCom_baud
    // TODO: if g_auxSerialCom_baud is other than the default 9600 baud,
    // then the auxiliary serial port baud rate should be updated.
# if HAS_AUX_SERIAL
# else
    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- init aux baud rate g_auxSerialCom_baud
    DAPLINKserial.baud(g_auxSerialCom_baud);
# endif
#endif // USE_AUX_SERIAL_CMD_FORWARDING
    cmdLine_DAPLINKserial.clear();
    //~ cmdLine_DAPLINKserial.serial().printf("\r\n cmdLine_DAPLINKserial.serial().printf test\r\n");
    cmdLine_DAPLINKserial.onEOLcommandParser = main_menu_onEOLcommandParser;
    //~ cmdLine_DAPLINKserial.on_immediate_0x21 = on_immediate_0x21;
    //~ cmdLine_DAPLINKserial.on_immediate_0x7b = on_immediate_0x7b;
    //~ cmdLine_DAPLINKserial.on_immediate_0x7d = on_immediate_0x7d;
# endif
# if HAS_AUX_SERIAL
    // TX/RX auxiliary UART port cmdLine_AUXserial AUXserial
#if 0 // HARD CRASH -- USE_AUX_SERIAL_CMD_FORWARDING
    // Command forwarding to AUX serial TX/RX cmdLine_AUXserial #257 -- init aux baud rate g_auxSerialCom_baud
    // TODO: if g_auxSerialCom_baud is other than the default 9600 baud,
    // then the auxiliary serial port baud rate should be updated.
    AUXserial.baud(g_auxSerialCom_baud);
#endif // USE_AUX_SERIAL_CMD_FORWARDING
    cmdLine_AUXserial.clear();
    //~ cmdLine_AUXserial.serial().printf("\r\n cmdLine_AUXserial.serial().printf test\r\n");
    cmdLine_AUXserial.onEOLcommandParser = main_menu_onEOLcommandParser;
    //~ cmdLine_AUXserial.on_immediate_0x21 = on_immediate_0x21;
    //~ cmdLine_AUXserial.on_immediate_0x7b = on_immediate_0x7b;
    //~ cmdLine_AUXserial.on_immediate_0x7d = on_immediate_0x7d;
# endif // HAS_AUX_SERIAL
#endif // USE_CMDLINE_MENUS support CmdLine command menus

    // example code: serial port banner message
    wait(3); // 3000ms timing delay function, platform-specific
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
    cmdLine.serial().printf("\r\nDataLogger_MAX11410\r\n"); // instead of Hello_MAX11410
#else // defined(SPI_ADC_DeviceName) // SPI connected ADC
    cmdLine.serial().printf("\r\nInternal_DataLogger\r\n"); // instead of Hello_MAX11410
# if HAS_DAPLINK_SERIAL
    cmdLine_DAPLINKserial.serial().printf("\r\nInternal_DataLogger\r\n"); // instead of Hello_MAX11410
# endif // HAS_DAPLINK_SERIAL
# if HAS_AUX_SERIAL
    cmdLine_AUXserial.serial().printf("\r\nInternal_DataLogger\r\n"); // instead of Hello_MAX11410
# endif // HAS_AUX_SERIAL
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC

    // CODE GENERATOR: get spi properties from device
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
    if (g_SPI_SCLK_Hz > g_MAX11410_device.get_spi_frequency())
    {  // Device limits SPI SCLK frequency
        g_SPI_SCLK_Hz = g_MAX11410_device.get_spi_frequency();
        cmdLine.serial().printf("\r\nMAX11410 limits SPI SCLK frequency to %ld Hz\r\n", g_SPI_SCLK_Hz);

        g_MAX11410_device.Init();
    }
    if (g_MAX11410_device.get_spi_frequency() > g_SPI_SCLK_Hz)
    {  // Platform limits SPI SCLK frequency
        g_MAX11410_device.spi_frequency(g_SPI_SCLK_Hz);
        cmdLine.serial().printf("\r\nPlatform limits MAX11410 SPI SCLK frequency to %ld Hz\r\n", g_SPI_SCLK_Hz);

        g_MAX11410_device.Init();
    }
    // g_SPI_dataMode = g_MAX11410_device.get_spi_dataMode();
    while (g_MAX11410_device.Init() == 0)
    {
        wait(3); // 3000ms timing delay function, platform-specific
        cmdLine.serial().printf("\r\nMAX11410 Init failed; retry...\r\n");

    }

    //  ---------- CUSTOMIZED from MAX11410_Hello after g_MAX11410_device.Init() ----------
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
    g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0];
    g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[0];
    g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[0];
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
    //  ---------- CUSTOMIZED from MAX11410_Hello ----------
#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC
        // CODE GENERATOR: example code: has no member function REF
        // CODE GENERATOR: example code for ADC: repeat-forever convert and print conversion result, one record per line
        // CODE GENERATOR: ResolutionBits = 24
        // CODE GENERATOR: FScode = 0xffffff
        // CODE GENERATOR: NumChannels = 10
        // CODE GENERATOR: banner before DataLogHelloCppCodeList while(1)
#if defined(SPI_ADC_DeviceName) // SPI connected ADC
        cmdLine.serial().printf("v_filter = 0x%2.2x\r\n", g_MAX11410_device.v_filter);

        cmdLine.serial().printf("v_pga = 0x%2.2x\r\n", g_MAX11410_device.v_pga);

        cmdLine.serial().printf("v_ctrl = 0x%2.2x\r\n", g_MAX11410_device.v_ctrl);

#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC

        // column header banner for csv data columns
        Datalogger_Need_PrintHeader = true;

#if USE_LEDS
#if defined(TARGET_MAX32630)
        led1 = LED_ON; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led RED
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_ON; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led RED+GREEN+BLUE=WHITE
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led GREEN+BLUE=CYAN
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_ON; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led RED+BLUE=MAGENTA
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led BLACK
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
#elif defined(TARGET_MAX32625MBED) || defined(TARGET_MAX32625PICO)
        led1 = LED_ON; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led RED
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_ON; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led RED+GREEN+BLUE=WHITE
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led GREEN+BLUE=CYAN
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_ON; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led RED+BLUE=MAGENTA
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
        led1 = LED_OFF; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led BLACK
        ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
#else // not defined(TARGET_LPC1768 etc.)
        led1 = LED_ON;
        led2 = LED_OFF;
        led3 = LED_OFF;
        led4 = LED_OFF;
        ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
        //led1 = LED_ON;
        led2 = LED_ON;
        ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
        led1 = LED_OFF;
        //led2 = LED_ON;
        led3 = LED_ON;
        ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
        led2 = LED_OFF;
        //led3 = LED_ON;
        led4 = LED_ON;
        ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
        led3 = LED_OFF;
        led4 = LED_ON;
        //
#endif // target definition
#endif

        if (led1.is_connected()) {
            led1 = LED_ON;
        }
        if (led2.is_connected()) {
            led2 = LED_ON;
        }
        if (led3.is_connected()) {
            led3 = LED_ON;
        }

        while(1) { // this code repeats forever
        // this code repeats forever

#if USE_CMDLINE_MENUS // support CmdLine command menus
            // TODO support CmdLine command menus (like on Serial_Tester); help and usual boilerplate
#if USE_AUX_SERIAL_CMD_FORWARDING
            // Command forwarding to Auxiliary serial port;
            // don't accept commands from Auxiliary serial port
#else // USE_AUX_SERIAL_CMD_FORWARDING
            // Accept commands from Auxiliary serial port
# if HAS_AUX_SERIAL
            if (AUXserial.readable()) {
                cmdLine_AUXserial.append(AUXserial.getc());
            }
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
            if (DAPLINKserial.readable()) {
                cmdLine_DAPLINKserial.append(DAPLINKserial.getc());
            }
# endif // HAS_DAPLINK_SERIAL
#endif // USE_AUX_SERIAL_CMD_FORWARDING
            if (serial.readable()) {
                int c = serial.getc(); // instead of getc() or fgetc()
                cmdLine.append(c);
                // cmdLine.onEOLcommandParser handler implements menus
            } // if (Serial.available())
#endif // USE_CMDLINE_MENUS support CmdLine command menus

#if USE_DATALOGGER_TRIGGER // support Datalog trigger
            // TODO Datalog trigger
            if (Datalogger_Trigger == trigger_Halt) {
                // halt the datalogger; continue accepting commands
                continue;
            }
            if (Datalogger_Trigger == trigger_FreeRun) {
                // free run as fast as possible
            }
            if (Datalogger_Trigger == trigger_Timer) {
                // timer (configure interval)
            }
            if (Datalogger_Trigger == trigger_PlatformDigitalInput) {
                // platform digital input (configure digital input pin reference)
            }
            if (Datalogger_Trigger == trigger_SPIDeviceRegRead) {
                // SPI device register read (configure regaddr, mask value, match value)
            }
#endif // USE_DATALOGGER_TRIGGER support Datalog trigger

            // column header banner for csv data columns
            if (Datalogger_Need_PrintHeader) {
                if (Datalogger_enable_serial) {
                    Datalogger_PrintHeader(cmdLine);
                }
# if HAS_AUX_SERIAL
                if (Datalogger_enable_AUXserial) {
                    Datalogger_PrintHeader(cmdLine_AUXserial);
                }
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
                if (Datalogger_enable_DAPLINKserial) {
                    Datalogger_PrintHeader(cmdLine_DAPLINKserial);
                }
# endif // HAS_DAPLINK_SERIAL
                Datalogger_Need_PrintHeader = false;
            }
            Datalogger_AcquireRow();
            // wait(3.0);
            // CODE GENERATOR: print conversion result
            // Use Arduino Serial Plotter to view output: Tools | Serial Plotter
            if (Datalogger_enable_serial) {
                Datalogger_PrintRow(cmdLine);
            }
# if HAS_AUX_SERIAL
            if (Datalogger_enable_AUXserial) {
                Datalogger_PrintRow(cmdLine_AUXserial);
            }
# endif // HAS_AUX_SERIAL
# if HAS_DAPLINK_SERIAL
            if (Datalogger_enable_DAPLINKserial) {
                Datalogger_PrintRow(cmdLine_DAPLINKserial);
            }
# endif // HAS_DAPLINK_SERIAL

        } // this code repeats forever
}
//---------- CODE GENERATOR: end DataLogHelloCppCodeList