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

Dependencies:   MaximTinyTester CmdLine MAX541 MAX5715 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 // Test fixture and application menu for breakout boards:
00035 //   - MAX5715BOB
00036 //   - MAX11131BOB
00037 //   - MAX5171BOB
00038 // Platforms:
00039 //   - MAX32625MBED
00040 //      - supports mbed-os-5.11, requires USBDevice library
00041 //      - remove max32630fthr library (if present)
00042 //      - remove MAX32620FTHR library (if present)
00043 //   - MAX32600MBED
00044 //      - remove max32630fthr library (if present)
00045 //      - remove MAX32620FTHR library (if present)
00046 //   - NUCLEO_F446RE
00047 //      - remove USBDevice library
00048 //      - remove max32630fthr library (if present)
00049 //      - remove MAX32620FTHR library (if present)
00050 //   - NUCLEO_F401RE
00051 //      - remove USBDevice library
00052 //      - remove max32630fthr library (if present)
00053 //      - remove MAX32620FTHR library (if present)
00054 //   - MAX32630FTHR
00055 //      - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
00056 //      - remove MAX32620FTHR library (if present)
00057 //   - MAX32620FTHR
00058 //      - remove max32630fthr library (if present)
00059 //      - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
00060 //      - not tested yet
00061 //   - MAX32625PICO
00062 //      - remove max32630fthr library (if present)
00063 //      - remove MAX32620FTHR library (if present)
00064 //      - not tested yet
00065 
00066 #include "mbed.h"
00067 // mbed shared event queue run onTimerTick() in Thread context not Interrupt context
00068 #include "mbed_events.h"
00069 #if defined(TARGET)
00070 // TARGET_NAME macros from targets/TARGET_Maxim/TARGET_MAX32625/device/mxc_device.h
00071 // Create a string definition for the TARGET
00072 #define STRING_ARG(arg) #arg
00073 #define STRING_NAME(name) STRING_ARG(name)
00074 #define TARGET_NAME STRING_NAME(TARGET)
00075 #elif defined(TARGET_MAX32600)
00076 #define TARGET_NAME "MAX32600"
00077 #elif defined(TARGET_LPC1768)
00078 #define TARGET_NAME "LPC1768"
00079 #elif defined(TARGET_NUCLEO_F446RE)
00080 #define TARGET_NAME "NUCLEO_F446RE"
00081 #elif defined(TARGET_NUCLEO_F401RE)
00082 #define TARGET_NAME "NUCLEO_F401RE"
00083 #else
00084 #error TARGET NOT DEFINED
00085 #endif
00086 #if defined(TARGET_MAX32630)
00087 //--------------------------------------------------
00088 // TARGET=MAX32630FTHR ARM Cortex-M4F 96MHz 2048kB Flash 512kB SRAM
00089 //             +-------------[microUSB]-------------+
00090 //             | J1         MAX32630FTHR        J2  |
00091 //      ______ | [ ] RST                    GND [ ] |
00092 //      ______ | [ ] 3V3                    BAT+[ ] |
00093 //      ______ | [ ] 1V8                  reset SW1 |
00094 //      ______ | [ ] GND       J4               J3  |
00095 // analogIn0/4 | [a] AIN_0 1.2Vfs     (bat) SYS [ ] | switched BAT+
00096 // analogIn1/5 | [a] AIN_1 1.2Vfs           PWR [ ] | external pwr btn
00097 // analogIn2   | [a] AIN_2 1.2Vfs      +5V VBUS [ ] | USB +5V power
00098 // analogIn3   | [a] AIN_3 1.2Vfs   1-WIRE P4_0 [d] | D0 dig9
00099 //  (I2C2.SDA) | [d] P5_7  SDA2        SRN P5_6 [d] | D1 dig8
00100 //  (I2C2.SCL) | [d] P6_0  SCL2      SDIO3 P5_5 [d] | D2 dig7
00101 //    D13/SCLK | [s] P5_0  SCLK      SDIO2 P5_4 [d] | D3 dig6
00102 //    D11/MOSI | [s] P5_1  MOSI       SSEL P5_3 [d] | D4 dig5
00103 //    D12/MISO | [s] P5_2  MISO        RTS P3_3 [d] | D5 dig4
00104 //    D10/CS   | [s] P3_0  RX          CTS P3_2 [d] | D6 dig3
00105 //    D9  dig0 | [d] P3_1  TX          SCL P3_5 [d] | D7 dig2
00106 //      ______ | [ ] GND               SDA P3_4 [d] | D8 dig1
00107 //             |                                    |
00108 //             | XIP Flash      MAX14690N           |
00109 //             | XIP_SCLK P1_0  SDA2 P5_7           |
00110 //             | XIP_MOSI P1_1  SCL2 P6_0           |
00111 //             | XIP_MISO P1_2  PMIC_INIT P3_7      |
00112 //             | XIP_SSEL P1_3  MPC P2_7            |
00113 //             | XIP_DIO2 P1_4  MON AIN_0           |
00114 //             | XIP_DIO3 P1_5                      |
00115 //             |                                    |
00116 //             | PAN1326B     MicroSD        LED    |
00117 //             | BT_RX  P0_0  SD_SCLK P0_4   r P2_4 |
00118 //             | BT_TX  P0_1  SD_MOSI P0_5   g P2_5 |
00119 //             | BT_CTS P0_2  SD_MISO P0_6   b P2_6 |
00120 //             | BT_RTS P0_3  SD_SSEL P0_7          |
00121 //             | BT_RST P1_6  DETECT  P2_2          |
00122 //             | BT_CLK P1_7               SW2 P2_3 |
00123 //             +------------------------------------+
00124 // 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).
00125 // 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).
00126 // AIN_0 = AIN0 pin       fullscale is 1.2V
00127 // AIN_1 = AIN1 pin       fullscale is 1.2V
00128 // AIN_2 = AIN2 pin       fullscale is 1.2V
00129 // AIN_3 = AIN3 pin       fullscale is 1.2V
00130 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
00131 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
00132 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
00133 // AIN_7 = VDD18          fullscale is 1.2V
00134 // AIN_8 = VDD12          fullscale is 1.2V
00135 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
00136 // AIN_10 = x undefined?
00137 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
00138 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
00139 //
00140     #include "max32630fthr.h"
00141 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00142 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
00143 // MAX32630FTHR board supports only internal VREF = 1.200V at bypass capacitor C15
00144 const float ADC_FULL_SCALE_VOLTAGE = 1.200;
00145 // Arduino connector
00146 #ifndef A0
00147 #define A0 AIN_0
00148 #endif
00149 #ifndef A1
00150 #define A1 AIN_1
00151 #endif
00152 #ifndef A2
00153 #define A2 AIN_2
00154 #endif
00155 #ifndef A3
00156 #define A3 AIN_3
00157 #endif
00158 #ifndef D0
00159 #define D0 P4_0
00160 #endif
00161 #ifndef D1
00162 #define D1 P5_6
00163 #endif
00164 #ifndef D2
00165 #define D2 P5_5
00166 #endif
00167 #ifndef D3
00168 #define D3 P5_4
00169 #endif
00170 #ifndef D4
00171 #define D4 P5_3
00172 #endif
00173 #ifndef D5
00174 #define D5 P3_3
00175 #endif
00176 #ifndef D6
00177 #define D6 P3_2
00178 #endif
00179 #ifndef D7
00180 #define D7 P3_5
00181 #endif
00182 #ifndef D8
00183 #define D8 P3_4
00184 #endif
00185 #ifndef D9
00186 #define D9 P3_1
00187 #endif
00188 #ifndef D10
00189 #define D10 P3_0
00190 #endif
00191 #ifndef D11
00192 #define D11 P5_1
00193 #endif
00194 #ifndef D12
00195 #define D12 P5_2
00196 #endif
00197 #ifndef D13
00198 #define D13 P5_0
00199 #endif
00200 //--------------------------------------------------
00201 #elif defined(TARGET_MAX32625MBED)
00202 //--------------------------------------------------
00203 // TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
00204 //             +-------------------------------------+
00205 //             |   MAX32625MBED Arduino UNO header   |
00206 //             |                                     |
00207 //             |                           A5/SCL[ ] |   P1_7 dig15
00208 //             |                           A4/SDA[ ] |   P1_6 dig14
00209 //             |                         AREF=N/C[ ] |
00210 //             |                              GND[ ] |
00211 //             | [ ]N/C                    SCK/13[ ] |   P1_0 dig13
00212 //             | [ ]IOREF=3V3             MISO/12[ ] |   P1_2 dig12
00213 //             | [ ]RST                   MOSI/11[ ]~|   P1_1 dig11
00214 //             | [ ]3V3                     CS/10[ ]~|   P1_3 dig10
00215 //             | [ ]5V0                         9[ ]~|   P1_5 dig9
00216 //             | [ ]GND                         8[ ] |   P1_4 dig8
00217 //             | [ ]GND                              |
00218 //             | [ ]Vin                         7[ ] |   P0_7 dig7
00219 //             |                                6[ ]~|   P0_6 dig6
00220 //       AIN_0 | [ ]A0                          5[ ]~|   P0_5 dig5
00221 //       AIN_1 | [ ]A1                          4[ ] |   P0_4 dig4
00222 //       AIN_2 | [ ]A2                     INT1/3[ ]~|   P0_3 dig3
00223 //       AIN_3 | [ ]A3                     INT0/2[ ] |   P0_2 dig2
00224 // dig16  P3_4 | [ ]A4/SDA  RST SCK MISO     TX>1[ ] |   P0_1 dig1
00225 // dig17  P3_5 | [ ]A5/SCL  [ ] [ ] [ ]      RX<0[ ] |   P0_0 dig0
00226 //             |            [ ] [ ] [ ]              |
00227 //             |  UNO_R3    GND MOSI 5V  ____________/
00228 //              \_______________________/
00229 //
00230 //             +------------------------+
00231 //             |                        |
00232 //             |  MicroSD        LED    |
00233 //             |  SD_SCLK P2_4   r P3_0 |
00234 //             |  SD_MOSI P2_5   g P3_1 |
00235 //             |  SD_MISO P2_6   b P3_2 |
00236 //             |  SD_SSEL P2_7   y P3_3 |
00237 //             |                        |
00238 //             |  DAPLINK      BUTTONS  |
00239 //             |  TX P2_1      SW3 P2_3 |
00240 //             |  RX P2_0      SW2 P2_2 |
00241 //             +------------------------+
00242 //
00243 // AIN_0 = AIN0 pin       fullscale is 1.2V
00244 // AIN_1 = AIN1 pin       fullscale is 1.2V
00245 // AIN_2 = AIN2 pin       fullscale is 1.2V
00246 // AIN_3 = AIN3 pin       fullscale is 1.2V
00247 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
00248 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
00249 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
00250 // AIN_7 = VDD18          fullscale is 1.2V
00251 // AIN_8 = VDD12          fullscale is 1.2V
00252 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
00253 // AIN_10 = x undefined?
00254 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
00255 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
00256 //
00257 //#include "max32625mbed.h" // ?
00258 //MAX32625MBED mbed(MAX32625MBED::VIO_3V3); // ?
00259 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
00260 // MAX32630FTHR board supports only internal VREF = 1.200V at bypass capacitor C15
00261 const float ADC_FULL_SCALE_VOLTAGE = 1.200;     // TODO: ADC_FULL_SCALE_VOLTAGE Pico?
00262 // Arduino connector
00263 #ifndef A0
00264 #define A0 AIN_0
00265 #endif
00266 #ifndef A1
00267 #define A1 AIN_1
00268 #endif
00269 #ifndef A2
00270 #define A2 AIN_2
00271 #endif
00272 #ifndef A3
00273 #define A3 AIN_3
00274 #endif
00275 #ifndef D0
00276 #define D0 P0_0
00277 #endif
00278 #ifndef D1
00279 #define D1 P0_1
00280 #endif
00281 #ifndef D2
00282 #define D2 P0_2
00283 #endif
00284 #ifndef D3
00285 #define D3 P0_3
00286 #endif
00287 #ifndef D4
00288 #define D4 P0_4
00289 #endif
00290 #ifndef D5
00291 #define D5 P0_5
00292 #endif
00293 #ifndef D6
00294 #define D6 P0_6
00295 #endif
00296 #ifndef D7
00297 #define D7 P0_7
00298 #endif
00299 #ifndef D8
00300 #define D8 P1_4
00301 #endif
00302 #ifndef D9
00303 #define D9 P1_5
00304 #endif
00305 #ifndef D10
00306 #define D10 P1_3
00307 #endif
00308 #ifndef D11
00309 #define D11 P1_1
00310 #endif
00311 #ifndef D12
00312 #define D12 P1_2
00313 #endif
00314 #ifndef D13
00315 #define D13 P1_0
00316 #endif
00317 //--------------------------------------------------
00318 #elif defined(TARGET_MAX32600)
00319 // target MAX32600
00320 //
00321 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 0
00322 const float ADC_FULL_SCALE_VOLTAGE = 1.500;
00323 //
00324 //--------------------------------------------------
00325 #elif defined(TARGET_MAX32620FTHR)
00326 #warning "TARGET_MAX32620FTHR not previously tested; need to define pins..."
00327 #include "MAX32620FTHR.h"
00328 // Initialize I/O voltages on MAX32620FTHR board
00329 MAX32620FTHR fthr(MAX32620FTHR::VIO_3V3);
00330 //#define USE_LEDS 0 ?
00331 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
00332 #warning "TARGET_MAX32620FTHR not previously tested; need to verify ADC_FULL_SCALE_VOLTAGE..."
00333 const float ADC_FULL_SCALE_VOLTAGE = 1.200;
00334 //
00335 //--------------------------------------------------
00336 #elif defined(TARGET_MAX32625PICO)
00337 #warning "TARGET_MAX32625PICO not previously tested; need to define pins..."
00338 //#define USE_LEDS 0 ?
00339 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1
00340 #warning "TARGET_MAX32625PICO not previously tested; need to verify ADC_FULL_SCALE_VOLTAGE..."
00341 const float ADC_FULL_SCALE_VOLTAGE = 1.200;
00342 //
00343 //--------------------------------------------------
00344 #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
00345 // TODO1: target NUCLEO_F446RE
00346 //
00347 // USER_BUTTON PC13
00348 // LED1 is shared with SPI_SCK on NUCLEO_F446RE PA_5, so don't use LED1.
00349 #define USE_LEDS 0
00350 // SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
00351 // Serial serial(SERIAL_TX, SERIAL_RX);
00352 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 0
00353 const float ADC_FULL_SCALE_VOLTAGE = 3.300;     // TODO: ADC_FULL_SCALE_VOLTAGE Pico?
00354 //
00355 //--------------------------------------------------
00356 #elif defined(TARGET_LPC1768)
00357 //--------------------------------------------------
00358 // TARGET=LPC1768 ARM Cortex-M3 100 MHz 512kB flash 64kB SRAM
00359 //               +-------------[microUSB]-------------+
00360 //        ______ | [ ] GND             +3.3V VOUT [ ] | ______
00361 //        ______ | [ ] 4.5V<VIN<9.0V   +5.0V VU   [ ] | ______
00362 //        ______ | [ ] VB                 USB.IF- [ ] | ______
00363 //        ______ | [ ] nR                 USB.IF+ [ ] | ______
00364 // digitalInOut0 | [ ] p5 MOSI       ETHERNET.RD- [ ] | ______
00365 // digitalInOut1 | [ ] p6 MISO       ETHERNET.RD+ [ ] | ______
00366 // digitalInOut2 | [ ] p7 SCLK       ETHERNET.TD- [ ] | ______
00367 // digitalInOut3 | [ ] p8            ETHERNET.TD+ [ ] | ______
00368 // digitalInOut4 | [ ] p9  TX SDA          USB.D- [ ] | ______
00369 // digitalInOut5 | [ ] p10 RX SCL          USB.D+ [ ] | ______
00370 // digitalInOut6 | [ ] p11    MOSI     CAN-RD p30 [ ] | digitalInOut13
00371 // digitalInOut7 | [ ] p12    MISO     CAN-TD p29 [ ] | digitalInOut12
00372 // digitalInOut8 | [ ] p13 TX SCLK     SDA TX p28 [ ] | digitalInOut11
00373 // digitalInOut9 | [ ] p14 RX          SCL RX p27 [ ] | digitalInOut10
00374 //     analogIn0 | [ ] p15 AIN0 3.3Vfs   PWM1 p26 [ ] | pwmDriver1
00375 //     analogIn1 | [ ] p16 AIN1 3.3Vfs   PWM2 p25 [ ] | pwmDriver2
00376 //     analogIn2 | [ ] p17 AIN2 3.3Vfs   PWM3 p24 [ ] | pwmDriver3
00377 //     analogIn3 | [ ] p18 AIN3 AOUT     PWM4 p23 [ ] | pwmDriver4
00378 //     analogIn4 | [ ] p19 AIN4 3.3Vfs   PWM5 p22 [ ] | pwmDriver5
00379 //     analogIn5 | [ ] p20 AIN5 3.3Vfs   PWM6 p21 [ ] | pwmDriver6
00380 //               +------------------------------------+
00381 // AIN6 = P0.3 = TGT_SBL_RXD?
00382 // AIN7 = P0.2 = TGT_SBL_TXD?
00383 //
00384 //--------------------------------------------------
00385 // LPC1768 board uses VREF = 3.300V +A3,3V thru L1 to bypass capacitor C14
00386 #define analogIn4_IS_HIGH_RANGE_OF_analogIn0 0
00387 const float ADC_FULL_SCALE_VOLTAGE = 3.300;
00388 #else // not defined(TARGET_LPC1768 etc.)
00389 //--------------------------------------------------
00390 // unknown target
00391 //--------------------------------------------------
00392 #endif // target definition
00393 
00394 
00395 //--------------------------------------------------
00396 // alphanumeric command codes A-Z,a-z,0-9 reserved for application use
00397 #ifndef APPLICATION_ArduinoPinsMonitor
00398 #define APPLICATION_ArduinoPinsMonitor 1
00399 #endif // APPLICATION_ArduinoPinsMonitor
00400 
00401 //--------------------------------------------------
00402 // Support MAX5715BOB Breakout Board
00403 #ifndef APPLICATION_MAX5715
00404 #define APPLICATION_MAX5715 1
00405 #endif // APPLICATION_MAX5715
00406 #if APPLICATION_MAX5715 // header file
00407 #include "MAX5715.h"
00408 // suppress the I2C diagnostics, not relevant to this chip
00409 #define HAS_I2C 0
00410 #endif // APPLICATION_MAX5715
00411 
00412 //--------------------------------------------------
00413 // Support MAX11131BOB Breakout Board
00414 #ifndef APPLICATION_MAX11131
00415 #define APPLICATION_MAX11131 0
00416 #endif // APPLICATION_MAX11131
00417 #if APPLICATION_MAX11131 // header file
00418 #include "MAX11131.h"
00419 // suppress the I2C diagnostics, not relevant to this chip
00420 #define HAS_I2C 0
00421 #endif // APPLICATION_MAX11131
00422 
00423 //--------------------------------------------------
00424 // Support MAX5171BOB Breakout Board
00425 #ifndef APPLICATION_MAX5171
00426 #define APPLICATION_MAX5171 0
00427 #endif // APPLICATION_MAX5171
00428 #if APPLICATION_MAX5171 // header file
00429 #include "MAX5171.h"
00430 // suppress the I2C diagnostics, not relevant to this chip
00431 #define HAS_I2C 0
00432 #endif // APPLICATION_MAX5171
00433 
00434 //--------------------------------------------------
00435 // Support MAX11410BOB Breakout Board (placeholder)
00436 #ifndef APPLICATION_MAX11410
00437 #define APPLICATION_MAX11410 0
00438 #endif // APPLICATION_MAX11410
00439 #if APPLICATION_MAX11410 // header file
00440 #include "MAX11410.h"
00441 #define HAS_I2C 0
00442 #endif // APPLICATION_MAX11410
00443 
00444 //--------------------------------------------------
00445 // Support MAX12345BOB Breakout Board (placeholder)
00446 #ifndef APPLICATION_MAX12345
00447 #define APPLICATION_MAX12345 0
00448 #endif // APPLICATION_MAX12345
00449 #if APPLICATION_MAX12345 // header file
00450 #include "MAX12345.h"
00451 #define HAS_I2C 0
00452 #endif // APPLICATION_MAX12345
00453 
00454 
00455 #include "MAX541.h"
00456 
00457 #include "MaximTinyTester.h"
00458 
00459 //--------------------------------------------------
00460 // Option to dedicate SPI port pins
00461 //
00462 //    SPI2_MOSI  = P5_1
00463 //    SPI2_MISO  = P5_2
00464 //    SPI2_SCK   = P5_0
00465 //    On this board I'm using P3_0 as spi_cs
00466 //    SPI2_SS    = P5_3
00467 //    SPI2_SDIO2 = P5_4
00468 //    SPI2_SDIO3 = P5_5
00469 //    SPI2_SRN   = P5_6
00470 //
00471 #ifndef HAS_SPI
00472 #define HAS_SPI 1
00473 #endif
00474 #if HAS_SPI
00475 #define SPI_MODE0 0
00476 #define SPI_MODE1 1
00477 #define SPI_MODE2 2
00478 #define SPI_MODE3 3
00479 //
00480 // Define application-specific default SPI_SCLK_Hz and SPI_dataMode
00481 #if APPLICATION_MAX5715 // SPI interface default settings
00482 //
00483 //#define SPI_SCLK_Hz 48000000 // 48MHz
00484 //#define SPI_SCLK_Hz 24000000 // 24MHz
00485 #define SPI_SCLK_Hz 12000000 // 12MHz
00486 //#define SPI_SCLK_Hz 4000000 // 4MHz
00487 //#define SPI_SCLK_Hz 2000000 // 2MHz
00488 //#define SPI_SCLK_Hz 1000000 // 1MHz
00489 #define SPI_dataMode SPI_MODE2 // CPOL=1,CPHA=0: Falling Edge stable; SCLK idle High
00490 //
00491 #elif APPLICATION_MAX11131 // SPI interface default settings
00492 //
00493 //#define SPI_SCLK_Hz 48000000 // 48MHz
00494 //#define SPI_SCLK_Hz 24000000 // 24MHz
00495 #define SPI_SCLK_Hz 12000000 // 12MHz
00496 //#define SPI_SCLK_Hz 4000000 // 4MHz
00497 //#define SPI_SCLK_Hz 2000000 // 2MHz
00498 //#define SPI_SCLK_Hz 1000000 // 1MHz
00499 #define SPI_dataMode SPI_MODE3 // CPOL=1,CPHA=1: Rising Edge stable; SCLK idle High
00500 //
00501 #elif APPLICATION_MAX5171 // SPI interface default settings
00502 //
00503 //#define SPI_SCLK_Hz 48000000 // 48MHz
00504 //#define SPI_SCLK_Hz 24000000 // 24MHz
00505 #define SPI_SCLK_Hz 12000000 // 12MHz
00506 //#define SPI_SCLK_Hz 4000000 // 4MHz
00507 //#define SPI_SCLK_Hz 2000000 // 2MHz
00508 //#define SPI_SCLK_Hz 1000000 // 1MHz
00509 #define SPI_dataMode SPI_MODE3 // CPOL=1,CPHA=1: Rising Edge stable; SCLK idle High
00510 //
00511 #elif APPLICATION_MAX11410 // SPI interface default settings
00512 //
00513 //#define SPI_SCLK_Hz 48000000 // 48MHz
00514 //#define SPI_SCLK_Hz 24000000 // 24MHz
00515 //#define SPI_SCLK_Hz 12000000 // 12MHz
00516 #define SPI_SCLK_Hz 8000000 // 8MHz
00517 //#define SPI_SCLK_Hz 4000000 // 4MHz
00518 //#define SPI_SCLK_Hz 2000000 // 2MHz
00519 //#define SPI_SCLK_Hz 1000000 // 1MHz
00520 #define SPI_dataMode SPI_MODE0 // CPOL=0,CPHA=0: Falling Edge stable; SCLK idle Low
00521 //
00522 #elif APPLICATION_MAX12345 // SPI interface default settings
00523 //
00524 //#define SPI_SCLK_Hz 48000000 // 48MHz
00525 //#define SPI_SCLK_Hz 24000000 // 24MHz
00526 #define SPI_SCLK_Hz 12000000 // 12MHz
00527 //#define SPI_SCLK_Hz 4000000 // 4MHz
00528 //#define SPI_SCLK_Hz 2000000 // 2MHz
00529 //#define SPI_SCLK_Hz 1000000 // 1MHz
00530 #define SPI_dataMode SPI_MODE3 // CPOL=1,CPHA=1: Rising Edge stable; SCLK idle High
00531 //
00532 #else // APPLICATION_ArduinoPinsMonitor diagnostic
00533 //
00534 //#define SPI_SCLK_Hz 48000000 // 48MHz
00535 //#define SPI_SCLK_Hz 4000000 // 4MHz
00536 //#define SPI_SCLK_Hz 2000000 // 2MHz
00537 #define SPI_SCLK_Hz 1000000 // 1MHz
00538 //#define SPI_dataMode SPI_MODE0 // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low
00539 //#define SPI_dataMode SPI_MODE1 // CPOL=0,CPHA=1: Falling Edge stable; SCLK idle Low
00540 //#define SPI_dataMode SPI_MODE2 // CPOL=1,CPHA=0: Falling Edge stable; SCLK idle High
00541 #define SPI_dataMode SPI_MODE3 // CPOL=1,CPHA=1: Rising Edge stable; SCLK idle High
00542 //
00543 #endif
00544 //
00545 #if defined(TARGET_MAX32630)
00546   // Before setting global variables g_SPI_SCLK_Hz and g_SPI_dataMode,
00547   // workaround for TARGET_MAX32630 SPI_MODE2 SPI_MODE3 problem (issue #30)
00548 #warning "MAX32630 SPI workaround..."
00549   // replace SPI_MODE2 (CPOL=1,CPHA=0) with SPI_MODE1 (CPOL=0,CPHA=1) Falling Edge stable
00550   // replace SPI_MODE3 (CPOL=1,CPHA=1) with SPI_MODE0 (CPOL=0,CPHA=0) Rising Edge stable
00551 # if ((SPI_dataMode) == (SPI_MODE2))
00552 #warning "MAX32630 SPI_MODE2 workaround, changing SPI_dataMode to SPI_MODE1..."
00553   // SPI_dataMode SPI_MODE2 // CPOL=1,CPHA=0: Falling Edge stable; SCLK idle High
00554 #  undef SPI_dataMode
00555 #  define SPI_dataMode SPI_MODE1 // CPOL=0,CPHA=1: Falling Edge stable; SCLK idle Low
00556 # elif ((SPI_dataMode) == (SPI_MODE3))
00557 #warning "MAX32630 SPI_MODE3 workaround, changing SPI_dataMode to SPI_MODE0..."
00558   // SPI_dataMode SPI_MODE3 // CPOL=1,CPHA=1: Rising Edge stable; SCLK idle High
00559 #  undef SPI_dataMode
00560 #  define SPI_dataMode SPI_MODE0 // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low
00561 # endif // workaround for TARGET_MAX32630 SPI_MODE2 SPI_MODE3 problem
00562   // workaround for TARGET_MAX32630 SPI_MODE2 SPI_MODE3 problem (issue #30)
00563   // limit SPI SCLK speed to 6MHz or less
00564 # if ((SPI_SCLK_Hz) > (6000000))
00565 #warning "MAX32630 SPI speed workaround, changing SPI_SCLK_Hz to 6000000 or 6MHz..."
00566 #  undef SPI_SCLK_Hz
00567 #  define SPI_SCLK_Hz 6000000 // 6MHz
00568 # endif
00569 #endif
00570 //
00571 uint32_t g_SPI_SCLK_Hz = SPI_SCLK_Hz;
00572 // TODO1: validate g_SPI_SCLK_Hz against system clock frequency SystemCoreClock F_CPU
00573 #if defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
00574 // Nucleo SPI frequency isn't working quite as expected...
00575 // Looks like STMF4 has an spi clock prescaler (2,4,8,16,32,64,128,256)
00576 // so 180MHz->[90.0, 45.0, 22.5, 11.25, 5.625, 2.8125, 1.40625, 0.703125]
00577 // %SC SCLK=1MHz sets spi frequency 703.125kHz
00578 // %SC SCLK=2MHz sets spi frequency 1.40625MHz
00579 // %SC SCLK=3MHz sets spi frequency 2.8125MHz
00580 // %SC SCLK=6MHz sets spi frequency 5.625MHz
00581 // %SC SCLK=12MHz sets spi frequency 11.25MHz
00582 // %SC SCLK=23MHz sets spi frequency 22.5MHz
00583 // %SC SCLK=45MHz sets spi frequency 45.0MHz
00584 // Don't know why I can't reach spi frequency 90.0MHz, but ok whatever.
00585 const uint32_t limit_min_SPI_SCLK_divisor = 2;
00586 const uint32_t limit_max_SPI_SCLK_divisor = 256;
00587 // not really a divisor, just a powers-of-two prescaler with no intermediate divisors.
00588 #else
00589 const uint32_t limit_min_SPI_SCLK_divisor = 2;
00590 const uint32_t limit_max_SPI_SCLK_divisor = 8191;
00591 #endif
00592 const uint32_t limit_max_SPI_SCLK_Hz = (SystemCoreClock / limit_min_SPI_SCLK_divisor); // F_CPU / 2; // 8MHz / 2 = 4MHz
00593 const uint32_t limit_min_SPI_SCLK_Hz = (SystemCoreClock / limit_max_SPI_SCLK_divisor); // F_CPU / 128; // 8MHz / 128 = 62.5kHz
00594 //
00595 uint8_t g_SPI_dataMode = SPI_dataMode;
00596 uint8_t g_SPI_cs_state = 1;
00597 //
00598 #if defined(TARGET_MAX32630)
00599 // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
00600 // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
00601 //SPI spi0(SPI0_MOSI, SPI0_MISO, SPI0_SCK); // mosi, miso, sclk spi0 MAX32630FTHR: P0_5 P0_6 P0_4 ok but this is the microSD card, can't contact pins
00602 //SPI spi1(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 MAX32630FTHR: P1_1 P1_2 P1_0 ok but this is the xip flash, can't contact pins
00603 //SPI spi2(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 MAX32630FTHR: P5_1, P5_2, P5_0
00604 SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 MAX32630FTHR: P5_1, P5_2, P5_0
00605 //
00606 DigitalOut spi_cs(P3_0);
00607 #elif defined(TARGET_MAX32625MBED)
00608 // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
00609 // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
00610 //SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK); // mosi, miso, sclk spi0 TARGET_MAX32635MBED: P0_5 P0_6 P0_4 Arduino 8-pin header D5 D6 D7
00611 //DigitalOut spi_cs(SPI0_SS); // TARGET_MAX32635MBED: P0_7 Arduino 8-pin header D4
00612 SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32635MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13
00613 DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32635MBED: P1_3 Arduino 10-pin header D10
00614 SPI spi2_max541(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 TARGET_MAX32635MBED: P2_5 P2_6 P2_4 Arduino 2x3-pin header; microSD
00615 DigitalOut spi2_max541_cs(SPI2_SS); // TARGET_MAX32635MBED: P2_7 Arduino 2x3-pin header
00616 #define HAS_SPI2_MAX541 1
00617 //
00618 #elif defined(TARGET_MAX32620FTHR)
00619 #warning "TARGET_MAX32620FTHR not previously tested; need to define SPI pins..."
00620 //
00621 // SPI0 P0_ PMOD Port 0 Back access
00622 //SPI spi0(SPI0_MOSI, SPI0_MISO, SPI0_SCK); // mosi, miso, sclk spi1 TARGET_MAX32620FTHR: PMOD Port 0 Back access
00623 //DigitalOut spi_cs0(SPI0_SS); // TARGET_MAX32620FTHR: PMOD Port 0 Back access
00624 //
00625 // SPI1 P1_ PMOD Port 1 Top Access
00626 SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32620FTHR: PMOD Port 1 Top Access
00627 DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32620FTHR: PMOD Port 1 Top Access
00628 //
00629 // SPI2 P5_ Feather J1.11,12,13
00630 //SPI spi2(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32620FTHR: Feather J1.11,12,13
00631 //DigitalOut spi_cs2(SPI2_SS); // TARGET_MAX32620FTHR: Feather J1.11,12,13
00632 //
00633 #elif defined(TARGET_MAX32625PICO)
00634 #warning "TARGET_MAX32625PICO not previously tested; need to define SPI pins..."
00635 // Note to software maintainer:
00636 // when adding new platform support,
00637 // add another #elif block above to support the new platform
00638 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625PICO: 15 P0_5 MOSI; 14 P0_6 MISO; 16 P0_4 SCLK
00639 DigitalOut spi_cs(SPI_SS); // TARGET_MAX32625PICO: 13 P0_7 SSEL
00640 //
00641 #elif defined(TARGET_MAX32600)
00642 SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
00643 DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
00644 //
00645 #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
00646 // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
00647 // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
00648 //
00649 // TODO1: NUCLEO_F446RE SPI not working; CS and MOSI data looks OK but no SCLK clock pulses.
00650 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_NUCLEO_F446RE: Arduino 10-pin header D11 D12 D13
00651 DigitalOut spi_cs(SPI_CS); // TARGET_NUCLEO_F446RE: PB_6 Arduino 10-pin header D10
00652 //
00653 #elif defined(TARGET_LPC1768)
00654 // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
00655 // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
00656 //SPI spi0(SPI0_MOSI, SPI0_MISO, SPI0_SCK); // mosi, miso, sclk spi0 MAX32630FTHR: P0_5 P0_6 P0_4 ok but this is the microSD card, can't contact pins
00657 //SPI spi1(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 MAX32630FTHR: P1_1 P1_2 P1_0 ok but this is the xip flash, can't contact pins
00658 //SPI spi2(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 MAX32630FTHR: P5_1, P5_2, P5_0
00659 SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 MAX32630FTHR: P5_1, P5_2, P5_0
00660 //
00661 DigitalOut spi_cs(P3_0);
00662 //
00663 #else
00664 // unknown target
00665 #warning "target not previously tested; need to define SPI pins..."
00666 // Note to software maintainer:
00667 // when adding new platform support,
00668 // add another #elif block above to support the new platform
00669 //SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_xxx: Arduino 10-pin header D11 D12 D13
00670 //DigitalOut spi_cs(SPI_CS); // TARGET_xxx: PX_x Arduino 10-pin header D10
00671 #endif
00672 #endif
00673 
00674 //--------------------------------------------------
00675 // Device driver object
00676 #if APPLICATION_MAX5715 // SPI interface default settings
00677 DigitalOut LDACb_pin(D9);   // Arduino 10-pin header D9
00678 DigitalOut CLRb_pin(D8);    // Arduino 10-pin header D8
00679 //~ DigitalIn RDYb_pin(D12);     // Arduino 10-pin header D12 (MISO)
00680 MAX5715 g_MAX5715_device(spi, spi_cs,
00681                          LDACb_pin,
00682                          CLRb_pin,
00683                          ///* RDYb_pin */ digitalInOut12,
00684                          MAX5715::MAX5715_IC);
00685 //
00686 #elif APPLICATION_MAX11131 // SPI interface default settings
00687 DigitalOut CNVSTb_pin(D9);   // Arduino 10-pin header D9
00688 //DigitalOut CLRb_pin(D8);    // Arduino 10-pin header D8
00689 DigitalIn EOCb_pin(D12);     // Arduino 10-pin header D12 (MISO)
00690 MAX11131 g_MAX11131_device(spi, spi_cs,
00691                            CNVSTb_pin,
00692                            EOCb_pin,
00693                            ///* RDYb_pin */ digitalInOut12,
00694                            MAX11131::MAX11131_IC);
00695 //
00696 //
00697 #elif APPLICATION_MAX5171 // SPI interface default settings
00698 // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device
00699 DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device
00700 DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device
00701 DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device
00702 DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device
00703 // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device
00704 DigitalIn UPO_pin(D2); // Digital General-Purpose Output from MAX5171 device
00705 MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC);
00706 //
00707 #elif APPLICATION_MAX11410 // SPI interface default settings
00708 //
00709 MAX11410 g_MAX11410_device(spi, spi_cs, MAX11410::MAX11410_IC);
00710 //
00711 #elif APPLICATION_MAX12345 // SPI interface default settings
00712 //
00713 MAX12345 g_MAX12345_device(spi, spi_cs, ...);
00714 //
00715 #else // APPLICATION_ArduinoPinsMonitor diagnostic
00716 //
00717 #endif
00718 
00719 
00720 //--------------------------------------------------
00721 // Option to dedicate I2C port pins
00722 //
00723 #ifndef HAS_I2C
00724 #define HAS_I2C 1
00725 #endif
00726 #if HAS_I2C
00727 //#include "I2C.h"
00728 //#include "I2CSlave.h"
00729 //#define I2C_SCL_Hz 400000 // 400kHz
00730 //#define I2C_SCL_Hz 200000 // 200kHz
00731 #define I2C_SCL_Hz 100000 // 100kHz
00732 //
00733 #if defined(TARGET_MAX32630)
00734 // TODO1: validate g_I2C_SCL_Hz against system clock frequency SystemCoreClock F_CPU
00735 const uint32_t limit_max_I2C_SCL_Hz = (SystemCoreClock / 2); // F_CPU / 2; // 8MHz / 2 = 4MHz
00736 const uint32_t limit_min_I2C_SCL_Hz = (SystemCoreClock / 8191); // F_CPU / 128; // 8MHz / 128 = 62.5kHz
00737 //
00738 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
00739 //I2C i2cMaster0(I2C0_SDA, I2C0_SCL); // sda scl MAX32630FTHR: NOT_CONNECTED
00740 //I2C i2cMaster1(I2C1_SDA, I2C1_SCL); // sda scl MAX32630FTHR: P3_4, P3_5
00741 //I2C i2cMaster2(I2C2_SDA, I2C2_SCL); // sda scl MAX32630FTHR: P5_7, P6_0
00742 //I2C i2cMaster(I2C2_SDA, I2C2_SCL); // sda scl MAX32630FTHR: P5_7, P6_0
00743 //
00744 //I2CSlave i2cSlave0(I2C0_SDA, I2C0_SCL); // sda scl MAX32630FTHR: NOT_CONNECTED
00745 //I2CSlave i2cSlave1(I2C1_SDA, I2C1_SCL); // sda scl MAX32630FTHR: P3_4, P3_5
00746 //I2CSlave i2cSlave2(I2C2_SDA, I2C2_SCL); // sda scl MAX32630FTHR: P5_7, P6_0
00747 #elif defined(TARGET_MAX32625MBED)
00748 // TODO1: validate g_I2C_SCL_Hz against system clock frequency SystemCoreClock F_CPU
00749 const uint32_t limit_max_I2C_SCL_Hz = (SystemCoreClock / 2); // F_CPU / 2; // 8MHz / 2 = 4MHz
00750 const uint32_t limit_min_I2C_SCL_Hz = (SystemCoreClock / 8191); // F_CPU / 128; // 8MHz / 128 = 62.5kHz
00751 //
00752 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
00753 //I2C i2cMaster0(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
00754 //I2C i2cMaster1(I2C1_SDA, I2C1_SCL); // sda scl TARGET_MAX32635MBED: P3_4, P3_5 Arduino 6-pin header
00755 // declare in narrower scope: MAX32625MBED I2C i2cMaster(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
00756 //
00757 #elif defined(TARGET_NUCLEO_F446RE)
00758 // TODO1: validate g_I2C_SCL_Hz against system clock frequency SystemCoreClock F_CPU
00759 const uint32_t limit_max_I2C_SCL_Hz = (SystemCoreClock / 2); // F_CPU / 2; // 8MHz / 2 = 4MHz
00760 const uint32_t limit_min_I2C_SCL_Hz = (SystemCoreClock / 8191); // F_CPU / 128; // 8MHz / 128 = 62.5kHz
00761 //
00762 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
00763 //I2C i2cMaster0(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
00764 //I2C i2cMaster1(I2C1_SDA, I2C1_SCL); // sda scl TARGET_MAX32635MBED: P3_4, P3_5 Arduino 6-pin header
00765 // declare in narrower scope: MAX32625MBED I2C i2cMaster(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
00766 # ifndef I2C0_SDA
00767 #  define I2C0_SDA I2C_SDA
00768 #  define I2C0_SCL I2C_SCL
00769 # endif
00770 //
00771 #elif defined(TARGET_NUCLEO_F401RE)
00772 // TODO1: validate g_I2C_SCL_Hz against system clock frequency SystemCoreClock F_CPU
00773 const uint32_t limit_max_I2C_SCL_Hz = (SystemCoreClock / 2); // F_CPU / 2; // 8MHz / 2 = 4MHz
00774 const uint32_t limit_min_I2C_SCL_Hz = (SystemCoreClock / 8191); // F_CPU / 128; // 8MHz / 128 = 62.5kHz
00775 //
00776 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
00777 //I2C i2cMaster0(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
00778 //I2C i2cMaster1(I2C1_SDA, I2C1_SCL); // sda scl TARGET_MAX32635MBED: P3_4, P3_5 Arduino 6-pin header
00779 // declare in narrower scope: MAX32625MBED I2C i2cMaster(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
00780 # ifndef I2C0_SDA
00781 #  define I2C0_SDA I2C_SDA
00782 #  define I2C0_SCL I2C_SCL
00783 # endif
00784 //
00785 #elif defined(TARGET_LPC1768)
00786 #else
00787 // unknown target
00788 #warning "target not previously tested; need to define I2C pins..."
00789 #endif
00790 //
00791 #endif
00792 #if HAS_I2C
00793 uint32_t g_I2C_SCL_Hz = I2C_SCL_Hz;
00794 uint8_t g_I2C_status = 0; // g_I2C_status = Wire_Sr.endTransmission();
00795 uint8_t g_I2C_deviceAddress7 = (0xA0 >> 1); // I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified.
00796 uint8_t g_I2C_read_count = 0;
00797 uint8_t g_I2C_write_count = 0;
00798 uint8_t g_I2C_write_data[256];
00799 uint8_t g_I2C_command_regAddress;
00800 //
00801 // TODO: i2c init
00802 // i2cMaster.frequency(g_I2C_SCL_Hz);
00803 #endif
00804 #if HAS_I2C
00805 // TODO: i2c transfer
00806 //const int addr7bit = 0x48;      // 7 bit I2C address
00807 //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
00808 // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
00809 // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
00810 // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
00811 // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
00812 // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
00813 // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
00814 // /* int */    i2cMaster.transfer (int addr8bit, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false) // Start nonblocking I2C transfer. More...
00815 // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
00816 #endif
00817 
00818 
00819 //--------------------------------------------------
00820 // Declare the Serial driver
00821 // default baud rate settings are 9600 8N1
00822 // install device driver from http://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe
00823 // see docs https://docs.mbed.com/docs/mbed-os-handbook/en/5.5/getting_started/what_need/
00824 #if defined(TARGET_MAX32630)
00825     #include "USBSerial.h"
00826 // Hardware serial port over DAPLink
00827 // The default baud rate for the DapLink UART is 9600
00828 Serial DAPLINKserial(P2_1, P2_0);     // tx, rx
00829     #define HAS_DAPLINK_SERIAL 1
00830 // Virtual serial port over USB
00831 // The baud rate does not affect the virtual USBSerial UART.
00832 USBSerial serial;
00833 //--------------------------------------------------
00834 #elif defined(TARGET_MAX32625MBED)
00835     #include "USBSerial.h"
00836 // Hardware serial port over DAPLink
00837 // The default baud rate for the DapLink UART is 9600
00838 Serial DAPLINKserial(P2_1, P2_0);     // tx, rx
00839     #define HAS_DAPLINK_SERIAL 1
00840 // Virtual serial port over USB
00841 // The baud rate does not affect the virtual USBSerial UART.
00842 USBSerial serial;
00843 //
00844 //--------------------------------------------------
00845 #elif defined(TARGET_MAX32620FTHR)
00846 #warning "TARGET_MAX32620FTHR not previously tested; need to define serial pins..."
00847 // Hardware serial port over DAPLink
00848 // The default baud rate for the DapLink UART is 9600
00849 Serial DAPLINKserial(USBTX, USBRX);     // tx, rx MAX32620FTHR: P2_1,P2_0
00850 //Serial DAPLINKserial(STDIO_UART_TX, STDIO_UART_RX);     // tx, rx
00851     #define HAS_DAPLINK_SERIAL 1
00852 // Virtual serial port over USB
00853 // The baud rate does not affect the virtual USBSerial UART.
00854 //    #include "USBSerial.h"
00855 //USBSerial serial;
00856 //Serial serial(UART0_TX, UART0_RX);     // tx, rx MAX32620FTHR: P0_1,P0_0 (PMOD Port 0)
00857 //Serial serial(UART1_TX, UART1_RX);     // tx, rx MAX32620FTHR: P2_1,P2_0 (DAPLINK)
00858 Serial serial(UART2_TX, UART2_RX);     // tx, rx MAX32620FTHR: P3_1,P3_0 (J1.15,J1.14)
00859 //Serial serial(UART3_TX, UART3_RX);     // tx, rx MAX32620FTHR: P5_4,P5_3 (J2.7,J2.8)
00860 //Serial serial(SERIAL_TX, SERIAL_RX);     // tx, rx
00861 //Serial serial(USBTX, USBRX);     // tx, rx
00862 //Serial serial(UART_TX, UART_RX);     // tx, rx
00863 //
00864 //--------------------------------------------------
00865 #elif defined(TARGET_MAX32625PICO)
00866 #warning "TARGET_MAX32625PICO not previously tested; need to verify serial pins..."
00867 // Note to software maintainer:
00868 // when adding new platform support,
00869 // add another #elif block above to support the new platform
00870 Serial serial(UART_TX, UART_RX);     // tx, rx
00871 //
00872 //--------------------------------------------------
00873 #elif defined(TARGET_MAX32600)
00874     #include "USBSerial.h"
00875 // Hardware serial port over DAPLink
00876 // The default baud rate for the DapLink UART is 9600
00877 Serial DAPLINKserial(P1_1, P1_0);     // tx, rx
00878     #define HAS_DAPLINK_SERIAL 1
00879 // Virtual serial port over USB
00880 // The baud rate does not affect the virtual USBSerial UART.
00881 USBSerial serial;
00882 //--------------------------------------------------
00883 #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
00884 Serial serial(SERIAL_TX, SERIAL_RX);     // tx, rx
00885 //--------------------------------------------------
00886 // TODO1: TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
00887 #elif defined(TARGET_LPC1768)
00888 Serial serial(USBTX, USBRX);     // tx, rx
00889 #else
00890 // unknown target
00891 #if defined(SERIAL_TX)
00892 #warning "target not previously tested; guess serial pins are SERIAL_TX, SERIAL_RX..."
00893 Serial serial(SERIAL_TX, SERIAL_RX);     // tx, rx
00894 #elif defined(USBTX)
00895 #warning "target not previously tested; guess serial pins are USBTX, USBRX..."
00896 Serial serial(USBTX, USBRX);     // tx, rx
00897 #elif defined(UART_TX)
00898 #warning "target not previously tested; guess serial pins are UART_TX, UART_RX..."
00899 Serial serial(UART_TX, UART_RX);     // tx, rx
00900 #else
00901 #warning "target not previously tested; need to define serial pins..."
00902 #endif
00903 #endif
00904 
00905 void on_immediate_0x21(); // Unicode (U+0021) ! EXCLAMATION MARK
00906 void on_immediate_0x7b(); // Unicode (U+007B) { LEFT CURLY BRACKET
00907 void on_immediate_0x7d(); // Unicode (U+007D) } RIGHT CURLY BRACKET
00908 
00909 #include "CmdLine.h"
00910 
00911 # if HAS_DAPLINK_SERIAL
00912 CmdLine cmdLine_DAPLINKserial(DAPLINKserial, "DAPLINK");
00913 # endif // HAS_DAPLINK_SERIAL
00914 CmdLine cmdLine_serial(serial, "serial");
00915 
00916 
00917 //--------------------------------------------------
00918 // tolerate AT commands, which may be sent during probe, such as:
00919 //  AT
00920 //  AT+CGMI      -- request manufacturer identification AT+CMGI=?
00921 //  AT+CGMM      -- request manufacturer model
00922 //  AT%IPSYS?
00923 //  ATE0         -- echo disable
00924 //  ATV1         -- verbose result codes OK | ERROR | NO CARRIER
00925 //  AT+CMEE=1
00926 //  ATX4
00927 //  AT&C1
00928 //  ATE0
00929 //  AT+CMEE=1
00930 //  AT+GCAP
00931 //  ATI
00932 //  AT+CPIN?
00933 //  AT+CGMM
00934 #ifndef IGNORE_AT_COMMANDS
00935 #define IGNORE_AT_COMMANDS 1
00936 #endif
00937 
00938 
00939 // uncrustify-0.66.1 *INDENT-OFF*
00940 //--------------------------------------------------
00941 // Declare the DigitalInOut GPIO pins
00942 // Optional digitalInOut support. If there is only one it should be digitalInOut1.
00943 // D) Digital High/Low/Input Pin
00944 #if defined(TARGET_MAX32630)
00945 //       +-------------[microUSB]-------------+
00946 //       | J1         MAX32630FTHR        J2  |
00947 //       | [ ] RST                    GND [ ] |
00948 //       | [ ] 3V3                    BAT+[ ] |
00949 //       | [ ] 1V8                  reset SW1 |
00950 //       | [ ] GND       J4               J3  |
00951 //       | [ ] AIN_0 1.2Vfs     (bat) SYS [ ] |
00952 //       | [ ] AIN_1 1.2Vfs           PWR [ ] |
00953 //       | [ ] AIN_2 1.2Vfs      +5V VBUS [ ] |
00954 //       | [ ] AIN_3 1.2Vfs   1-WIRE P4_0 [ ] | dig9
00955 // dig10 | [x] P5_7  SDA2        SRN P5_6 [ ] | dig8
00956 // dig11 | [x] P6_0  SCL2      SDIO3 P5_5 [ ] | dig7
00957 // dig12 | [x] P5_0  SCLK      SDIO2 P5_4 [ ] | dig6
00958 // dig13 | [x] P5_1  MOSI       SSEL P5_3 [x] | dig5
00959 // dig14 | [ ] P5_2  MISO        RTS P3_3 [ ] | dig4
00960 // dig15 | [ ] P3_0  RX          CTS P3_2 [ ] | dig3
00961 // dig0  | [ ] P3_1  TX          SCL P3_5 [x] | dig2
00962 //       | [ ] GND               SDA P3_4 [x] | dig1
00963 //       +------------------------------------+
00964     #define HAS_digitalInOut0 1 // P3_1 TARGET_MAX32630 J1.15
00965     #define HAS_digitalInOut1 1 // P3_4 TARGET_MAX32630 J3.12
00966     #define HAS_digitalInOut2 1 // P3_5 TARGET_MAX32630 J3.11
00967     #define HAS_digitalInOut3 1 // P3_2 TARGET_MAX32630 J3.10
00968     #define HAS_digitalInOut4 1 // P3_3 TARGET_MAX32630 J3.9
00969     #define HAS_digitalInOut5 1 // P5_3 TARGET_MAX32630 J3.8
00970     #define HAS_digitalInOut6 1 // P5_4 TARGET_MAX32630 J3.7
00971     #define HAS_digitalInOut7 1 // P5_5 TARGET_MAX32630 J3.6
00972     #define HAS_digitalInOut8 1 // P5_6 TARGET_MAX32630 J3.5
00973     #define HAS_digitalInOut9 1 // P4_0 TARGET_MAX32630 J3.4
00974 #if HAS_I2C
00975 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
00976     #define HAS_digitalInOut10 0 // P5_7 TARGET_MAX32630 J1.9
00977     #define HAS_digitalInOut11 0 // P6_0 TARGET_MAX32630 J1.10
00978 #else // HAS_I2C
00979     #define HAS_digitalInOut10 1 // P5_7 TARGET_MAX32630 J1.9
00980     #define HAS_digitalInOut11 1 // P6_0 TARGET_MAX32630 J1.10
00981 #endif // HAS_I2C
00982 #if HAS_SPI
00983 // avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
00984     #define HAS_digitalInOut12 0 // P5_0 TARGET_MAX32630 J1.11
00985     #define HAS_digitalInOut13 0 // P5_1 TARGET_MAX32630 J1.12
00986     #define HAS_digitalInOut14 0 // P5_2 TARGET_MAX32630 J1.13
00987     #define HAS_digitalInOut15 0 // P3_0 TARGET_MAX32630 J1.14
00988 #else // HAS_SPI
00989     #define HAS_digitalInOut12 1 // P5_0 TARGET_MAX32630 J1.11
00990     #define HAS_digitalInOut13 1 // P5_1 TARGET_MAX32630 J1.12
00991     #define HAS_digitalInOut14 1 // P5_2 TARGET_MAX32630 J1.13
00992     #define HAS_digitalInOut15 1 // P3_0 TARGET_MAX32630 J1.14
00993 #endif // HAS_SPI
00994 #if HAS_digitalInOut0
00995     DigitalInOut digitalInOut0(P3_1, PIN_INPUT, PullUp, 1); // P3_1 TARGET_MAX32630 J1.15
00996 #endif
00997 #if HAS_digitalInOut1
00998     DigitalInOut digitalInOut1(P3_4, PIN_INPUT, PullUp, 1); // P3_4 TARGET_MAX32630 J3.12
00999 #endif
01000 #if HAS_digitalInOut2
01001     DigitalInOut digitalInOut2(P3_5, PIN_INPUT, PullUp, 1); // P3_5 TARGET_MAX32630 J3.11
01002 #endif
01003 #if HAS_digitalInOut3
01004     DigitalInOut digitalInOut3(P3_2, PIN_INPUT, PullUp, 1); // P3_2 TARGET_MAX32630 J3.10
01005 #endif
01006 #if HAS_digitalInOut4
01007     DigitalInOut digitalInOut4(P3_3, PIN_INPUT, PullUp, 1); // P3_3 TARGET_MAX32630 J3.9
01008 #endif
01009 #if HAS_digitalInOut5
01010     DigitalInOut digitalInOut5(P5_3, PIN_INPUT, PullUp, 1); // P5_3 TARGET_MAX32630 J3.8
01011 #endif
01012 #if HAS_digitalInOut6
01013     DigitalInOut digitalInOut6(P5_4, PIN_INPUT, PullUp, 1); // P5_4 TARGET_MAX32630 J3.7
01014 #endif
01015 #if HAS_digitalInOut7
01016     DigitalInOut digitalInOut7(P5_5, PIN_INPUT, PullUp, 1); // P5_5 TARGET_MAX32630 J3.6
01017 #endif
01018 #if HAS_digitalInOut8
01019     DigitalInOut digitalInOut8(P5_6, PIN_INPUT, PullUp, 1); // P5_6 TARGET_MAX32630 J3.5
01020 #endif
01021 #if HAS_digitalInOut9
01022     DigitalInOut digitalInOut9(P4_0, PIN_INPUT, PullUp, 1); // P4_0 TARGET_MAX32630 J3.4
01023 #endif
01024 #if HAS_digitalInOut10
01025     DigitalInOut digitalInOut10(P5_7, PIN_INPUT, PullUp, 1); // P5_7 TARGET_MAX32630 J1.9
01026 #endif
01027 #if HAS_digitalInOut11
01028     DigitalInOut digitalInOut11(P6_0, PIN_INPUT, PullUp, 1); // P6_0 TARGET_MAX32630 J1.10
01029 #endif
01030 #if HAS_digitalInOut12
01031     DigitalInOut digitalInOut12(P5_0, PIN_INPUT, PullUp, 1); // P5_0 TARGET_MAX32630 J1.11
01032 #endif
01033 #if HAS_digitalInOut13
01034     DigitalInOut digitalInOut13(P5_1, PIN_INPUT, PullUp, 1); // P5_1 TARGET_MAX32630 J1.12
01035 #endif
01036 #if HAS_digitalInOut14
01037     DigitalInOut digitalInOut14(P5_2, PIN_INPUT, PullUp, 1); // P5_2 TARGET_MAX32630 J1.13
01038 #endif
01039 #if HAS_digitalInOut15
01040     DigitalInOut digitalInOut15(P3_0, PIN_INPUT, PullUp, 1); // P3_0 TARGET_MAX32630 J1.14
01041 #endif
01042 //--------------------------------------------------
01043 #elif defined(TARGET_MAX32625MBED)
01044 // TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
01045 //             +-------------------------------------+
01046 //             |   MAX32625MBED Arduino UNO header   |
01047 //             |                                     |
01048 //             |                           A5/SCL[ ] |   P1_7 dig15
01049 //             |                           A4/SDA[ ] |   P1_6 dig14
01050 //             |                         AREF=N/C[ ] |
01051 //             |                              GND[ ] |
01052 //             | [ ]N/C                    SCK/13[ ] |   P1_0 dig13
01053 //             | [ ]IOREF=3V3             MISO/12[ ] |   P1_2 dig12
01054 //             | [ ]RST                   MOSI/11[ ]~|   P1_1 dig11
01055 //             | [ ]3V3                     CS/10[ ]~|   P1_3 dig10
01056 //             | [ ]5V0                         9[ ]~|   P1_5 dig9
01057 //             | [ ]GND                         8[ ] |   P1_4 dig8
01058 //             | [ ]GND                              |
01059 //             | [ ]Vin                         7[ ] |   P0_7 dig7
01060 //             |                                6[ ]~|   P0_6 dig6
01061 //       AIN_0 | [ ]A0                          5[ ]~|   P0_5 dig5
01062 //       AIN_1 | [ ]A1                          4[ ] |   P0_4 dig4
01063 //       AIN_2 | [ ]A2                     INT1/3[ ]~|   P0_3 dig3
01064 //       AIN_3 | [ ]A3                     INT0/2[ ] |   P0_2 dig2
01065 // dig16  P3_4 | [ ]A4/SDA  RST SCK MISO     TX>1[ ] |   P0_1 dig1
01066 // dig17  P3_5 | [ ]A5/SCL  [ ] [ ] [ ]      RX<0[ ] |   P0_0 dig0
01067 //             |            [ ] [ ] [ ]              |
01068 //             |  UNO_R3    GND MOSI 5V  ____________/
01069 //              \_______________________/
01070 //
01071     #define HAS_digitalInOut0 1 // P0_0 TARGET_MAX32625MBED D0
01072     #define HAS_digitalInOut1 1 // P0_1 TARGET_MAX32625MBED D1
01073 #if APPLICATION_MAX11131
01074     #define HAS_digitalInOut2 0 // P0_2 TARGET_MAX32625MBED D2 -- MAX11131 EOC DigitalIn
01075 #else
01076     #define HAS_digitalInOut2 1 // P0_2 TARGET_MAX32625MBED D2
01077 #endif
01078     #define HAS_digitalInOut3 1 // P0_3 TARGET_MAX32625MBED D3
01079     #define HAS_digitalInOut4 1 // P0_4 TARGET_MAX32625MBED D4
01080     #define HAS_digitalInOut5 1 // P0_5 TARGET_MAX32625MBED D5
01081     #define HAS_digitalInOut6 1 // P0_6 TARGET_MAX32625MBED D6
01082     #define HAS_digitalInOut7 1 // P0_7 TARGET_MAX32625MBED D7
01083     #define HAS_digitalInOut8 1 // P1_4 TARGET_MAX32625MBED D8
01084 #if APPLICATION_MAX11131
01085     #define HAS_digitalInOut9 0 // P1_5 TARGET_MAX32625MBED D9 -- MAX11131 CNVST DigitalOut
01086 #else
01087     #define HAS_digitalInOut9 1 // P1_5 TARGET_MAX32625MBED D9
01088 #endif
01089 #if HAS_SPI
01090 // avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
01091     #define HAS_digitalInOut10 0 // P1_3 TARGET_MAX32635MBED CS/10
01092     #define HAS_digitalInOut11 0 // P1_1 TARGET_MAX32635MBED MOSI/11
01093     #define HAS_digitalInOut12 0 // P1_2 TARGET_MAX32635MBED MISO/12
01094     #define HAS_digitalInOut13 0 // P1_0 TARGET_MAX32635MBED SCK/13
01095 #else // HAS_SPI
01096     #define HAS_digitalInOut10 1 // P1_3 TARGET_MAX32635MBED CS/10
01097     #define HAS_digitalInOut11 1 // P1_1 TARGET_MAX32635MBED MOSI/11
01098     #define HAS_digitalInOut12 1 // P1_2 TARGET_MAX32635MBED MISO/12
01099     #define HAS_digitalInOut13 1 // P1_0 TARGET_MAX32635MBED SCK/13
01100 #endif // HAS_SPI
01101 #if HAS_I2C
01102 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
01103     #define HAS_digitalInOut14 0 // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
01104     #define HAS_digitalInOut15 0 // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
01105     #define HAS_digitalInOut16 0 // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
01106     #define HAS_digitalInOut17 0 // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
01107 #else // HAS_I2C
01108     #define HAS_digitalInOut14 1 // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
01109     #define HAS_digitalInOut15 1 // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
01110     #define HAS_digitalInOut16 1 // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
01111     #define HAS_digitalInOut17 1 // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
01112 #endif // HAS_I2C
01113 #if HAS_digitalInOut0
01114     DigitalInOut digitalInOut0(P0_0, PIN_INPUT, PullUp, 1); // P0_0 TARGET_MAX32625MBED D0
01115 #endif
01116 #if HAS_digitalInOut1
01117     DigitalInOut digitalInOut1(P0_1, PIN_INPUT, PullUp, 1); // P0_1 TARGET_MAX32625MBED D1
01118 #endif
01119 #if HAS_digitalInOut2
01120     DigitalInOut digitalInOut2(P0_2, PIN_INPUT, PullUp, 1); // P0_2 TARGET_MAX32625MBED D2
01121 #endif
01122 #if HAS_digitalInOut3
01123     DigitalInOut digitalInOut3(P0_3, PIN_INPUT, PullUp, 1); // P0_3 TARGET_MAX32625MBED D3
01124 #endif
01125 #if HAS_digitalInOut4
01126     DigitalInOut digitalInOut4(P0_4, PIN_INPUT, PullUp, 1); // P0_4 TARGET_MAX32625MBED D4
01127 #endif
01128 #if HAS_digitalInOut5
01129     DigitalInOut digitalInOut5(P0_5, PIN_INPUT, PullUp, 1); // P0_5 TARGET_MAX32625MBED D5
01130 #endif
01131 #if HAS_digitalInOut6
01132     DigitalInOut digitalInOut6(P0_6, PIN_INPUT, PullUp, 1); // P0_6 TARGET_MAX32625MBED D6
01133 #endif
01134 #if HAS_digitalInOut7
01135     DigitalInOut digitalInOut7(P0_7, PIN_INPUT, PullUp, 1); // P0_7 TARGET_MAX32625MBED D7
01136 #endif
01137 #if HAS_digitalInOut8
01138     DigitalInOut digitalInOut8(P1_4, PIN_INPUT, PullUp, 1); // P1_4 TARGET_MAX32625MBED D8
01139 #endif
01140 #if HAS_digitalInOut9
01141     DigitalInOut digitalInOut9(P1_5, PIN_INPUT, PullUp, 1); // P1_5 TARGET_MAX32625MBED D9
01142 #endif
01143 #if HAS_digitalInOut10
01144     DigitalInOut digitalInOut10(P1_3, PIN_INPUT, PullUp, 1); // P1_3 TARGET_MAX32635MBED CS/10
01145 #endif
01146 #if HAS_digitalInOut11
01147     DigitalInOut digitalInOut11(P1_1, PIN_INPUT, PullUp, 1); // P1_1 TARGET_MAX32635MBED MOSI/11
01148 #endif
01149 #if HAS_digitalInOut12
01150     DigitalInOut digitalInOut12(P1_2, PIN_INPUT, PullUp, 1); // P1_2 TARGET_MAX32635MBED MISO/12
01151 #endif
01152 #if HAS_digitalInOut13
01153     DigitalInOut digitalInOut13(P1_0, PIN_INPUT, PullUp, 1); // P1_0 TARGET_MAX32635MBED SCK/13
01154 #endif
01155 #if HAS_digitalInOut14
01156     // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
01157     // DigitalInOut mode can be one of PullUp, PullDown, PullNone, OpenDrain
01158     DigitalInOut digitalInOut14(P1_6, PIN_INPUT, OpenDrain, 1); // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
01159 #endif
01160 #if HAS_digitalInOut15
01161     // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
01162     DigitalInOut digitalInOut15(P1_7, PIN_INPUT, OpenDrain, 1); // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
01163 #endif
01164 #if HAS_digitalInOut16
01165     // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
01166     // DigitalInOut mode can be one of PullUp, PullDown, PullNone, OpenDrain
01167     // PullUp-->3.4V, PullDown-->1.7V, PullNone-->3.5V, OpenDrain-->0.00V
01168     DigitalInOut digitalInOut16(P3_4, PIN_INPUT, OpenDrain, 0); // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
01169 #endif
01170 #if HAS_digitalInOut17
01171     // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
01172     DigitalInOut digitalInOut17(P3_5, PIN_INPUT, OpenDrain, 0); // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
01173 #endif
01174 //--------------------------------------------------
01175 #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
01176     #define HAS_digitalInOut0 0 // P0_0 TARGET_MAX32625MBED D0
01177     #define HAS_digitalInOut1 0 // P0_1 TARGET_MAX32625MBED D1
01178 #if APPLICATION_MAX11131
01179     #define HAS_digitalInOut2 0 // P0_2 TARGET_MAX32625MBED D2 -- MAX11131 EOC DigitalIn
01180 #else
01181     #define HAS_digitalInOut2 1 // P0_2 TARGET_MAX32625MBED D2
01182 #endif
01183     #define HAS_digitalInOut3 1 // P0_3 TARGET_MAX32625MBED D3
01184     #define HAS_digitalInOut4 1 // P0_4 TARGET_MAX32625MBED D4
01185     #define HAS_digitalInOut5 1 // P0_5 TARGET_MAX32625MBED D5
01186     #define HAS_digitalInOut6 1 // P0_6 TARGET_MAX32625MBED D6
01187     #define HAS_digitalInOut7 1 // P0_7 TARGET_MAX32625MBED D7
01188 #if APPLICATION_MAX5715
01189     #define HAS_digitalInOut8 0 // P1_4 TARGET_MAX32625MBED D8 -- MAX5715 CLRb DigitalOut
01190 #else
01191     #define HAS_digitalInOut8 1 // P1_4 TARGET_MAX32625MBED D8
01192 #endif
01193 #if APPLICATION_MAX5715
01194     #define HAS_digitalInOut9 0 // P1_5 TARGET_MAX32625MBED D9 -- MAX5715 LDACb DigitalOut
01195 #elif APPLICATION_MAX11131
01196     #define HAS_digitalInOut9 0 // P1_5 TARGET_MAX32625MBED D9 -- MAX11131 CNVST DigitalOut
01197 #else
01198     #define HAS_digitalInOut9 1 // P1_5 TARGET_MAX32625MBED D9
01199 #endif
01200 #if HAS_SPI
01201 // avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
01202     // Arduino digital pin D10 SPI function is CS/10
01203     // Arduino digital pin D11 SPI function is MOSI/11
01204     // Arduino digital pin D12 SPI function is MISO/12
01205     // Arduino digital pin D13 SPI function is SCK/13
01206     #define HAS_digitalInOut10 0
01207     #define HAS_digitalInOut11 0
01208     #define HAS_digitalInOut12 0
01209     #define HAS_digitalInOut13 0
01210 #else // HAS_SPI
01211     #define HAS_digitalInOut10 1
01212     #define HAS_digitalInOut11 1
01213     #define HAS_digitalInOut12 1
01214     #define HAS_digitalInOut13 1
01215 #endif // HAS_SPI
01216 #if HAS_I2C
01217 // avoid resource conflict between P5_7, P6_0 I2C and DigitalInOut
01218     // Arduino digital pin D14 I2C function is A4/SDA (10pin digital connector)
01219     // Arduino digital pin D15 I2C function is A5/SCL (10pin digital connector)
01220     // Arduino digital pin D16 I2C function is A4/SDA (6pin analog connector)
01221     // Arduino digital pin D17 I2C function is A5/SCL (6pin analog connector)
01222     #define HAS_digitalInOut14 0
01223     #define HAS_digitalInOut15 0
01224     #define HAS_digitalInOut16 0
01225     #define HAS_digitalInOut17 0
01226 #else // HAS_I2C
01227     #define HAS_digitalInOut14 1
01228     #define HAS_digitalInOut15 1
01229     #define HAS_digitalInOut16 0
01230     #define HAS_digitalInOut17 0
01231 #endif // HAS_I2C
01232 #if HAS_digitalInOut0
01233     DigitalInOut digitalInOut0(D0, PIN_INPUT, PullUp, 1);
01234 #endif
01235 #if HAS_digitalInOut1
01236     DigitalInOut digitalInOut1(D1, PIN_INPUT, PullUp, 1);
01237 #endif
01238 #if HAS_digitalInOut2
01239     DigitalInOut digitalInOut2(D2, PIN_INPUT, PullUp, 1);
01240 #endif
01241 #if HAS_digitalInOut3
01242     DigitalInOut digitalInOut3(D3, PIN_INPUT, PullUp, 1);
01243 #endif
01244 #if HAS_digitalInOut4
01245     DigitalInOut digitalInOut4(D4, PIN_INPUT, PullUp, 1);
01246 #endif
01247 #if HAS_digitalInOut5
01248     DigitalInOut digitalInOut5(D5, PIN_INPUT, PullUp, 1);
01249 #endif
01250 #if HAS_digitalInOut6
01251     DigitalInOut digitalInOut6(D6, PIN_INPUT, PullUp, 1);
01252 #endif
01253 #if HAS_digitalInOut7
01254     DigitalInOut digitalInOut7(D7, PIN_INPUT, PullUp, 1);
01255 #endif
01256 #if HAS_digitalInOut8
01257     DigitalInOut digitalInOut8(D8, PIN_INPUT, PullUp, 1);
01258 #endif
01259 #if HAS_digitalInOut9
01260     DigitalInOut digitalInOut9(D9, PIN_INPUT, PullUp, 1);
01261 #endif
01262 #if HAS_digitalInOut10
01263     // Arduino digital pin D10 SPI function is CS/10
01264     DigitalInOut digitalInOut10(D10, PIN_INPUT, PullUp, 1);
01265 #endif
01266 #if HAS_digitalInOut11
01267     // Arduino digital pin D11 SPI function is MOSI/11
01268     DigitalInOut digitalInOut11(D11, PIN_INPUT, PullUp, 1);
01269 #endif
01270 #if HAS_digitalInOut12
01271     // Arduino digital pin D12 SPI function is MISO/12
01272     DigitalInOut digitalInOut12(D12, PIN_INPUT, PullUp, 1);
01273 #endif
01274 #if HAS_digitalInOut13
01275     // Arduino digital pin D13 SPI function is SCK/13
01276     DigitalInOut digitalInOut13(D13, PIN_INPUT, PullUp, 1);
01277 #endif
01278 #if HAS_digitalInOut14
01279     // Arduino digital pin D14 I2C function is A4/SDA (10pin digital connector)
01280     DigitalInOut digitalInOut14(D14, PIN_INPUT, PullUp, 1);
01281 #endif
01282 #if HAS_digitalInOut15
01283     // Arduino digital pin D15 I2C function is A5/SCL (10pin digital connector)
01284     DigitalInOut digitalInOut15(D15, PIN_INPUT, PullUp, 1);
01285 #endif
01286 #if HAS_digitalInOut16
01287     // Arduino digital pin D16 I2C function is A4/SDA (6pin analog connector)
01288     DigitalInOut digitalInOut16(D16, PIN_INPUT, PullUp, 1);
01289 #endif
01290 #if HAS_digitalInOut17
01291     // Arduino digital pin D17 I2C function is A5/SCL (6pin analog connector)
01292     DigitalInOut digitalInOut17(D17, PIN_INPUT, PullUp, 1);
01293 #endif
01294 //--------------------------------------------------
01295 #elif defined(TARGET_LPC1768)
01296     #define HAS_digitalInOut0 1
01297     #define HAS_digitalInOut1 1
01298     #define HAS_digitalInOut2 1
01299     #define HAS_digitalInOut3 1
01300     #define HAS_digitalInOut4 1
01301     #define HAS_digitalInOut5 1
01302     #define HAS_digitalInOut6 1
01303     #define HAS_digitalInOut7 1
01304     #define HAS_digitalInOut8 1
01305     #define HAS_digitalInOut9 1
01306 //    #define HAS_digitalInOut10 1
01307 //    #define HAS_digitalInOut11 1
01308 //    #define HAS_digitalInOut12 1
01309 //    #define HAS_digitalInOut13 1
01310 //    #define HAS_digitalInOut14 1
01311 //    #define HAS_digitalInOut15 1
01312 #if HAS_digitalInOut0
01313     DigitalInOut digitalInOut0(p5, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.9/I2STX_SDA/MOSI1/MAT2.3
01314 #endif
01315 #if HAS_digitalInOut1
01316     DigitalInOut digitalInOut1(p6, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.8/I2STX_WS/MISO1/MAT2.2
01317 #endif
01318 #if HAS_digitalInOut2
01319     DigitalInOut digitalInOut2(p7, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.7/I2STX_CLK/SCK1/MAT2.1
01320 #endif
01321 #if HAS_digitalInOut3
01322     DigitalInOut digitalInOut3(p8, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.6/I2SRX_SDA/SSEL1/MAT2.0
01323 #endif
01324 #if HAS_digitalInOut4
01325     DigitalInOut digitalInOut4(p9, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.0/CAN_RX1/TXD3/SDA1
01326 #endif
01327 #if HAS_digitalInOut5
01328     DigitalInOut digitalInOut5(p10, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.1/CAN_TX1/RXD3/SCL1
01329 #endif
01330 #if HAS_digitalInOut6
01331     DigitalInOut digitalInOut6(p11, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.18/DCD1/MOSI0/MOSI1
01332 #endif
01333 #if HAS_digitalInOut7
01334     DigitalInOut digitalInOut7(p12, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.17/CTS1/MISO0/MISO
01335 #endif
01336 #if HAS_digitalInOut8
01337     DigitalInOut digitalInOut8(p13, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.15/TXD1/SCK0/SCK
01338 #endif
01339 #if HAS_digitalInOut9
01340     DigitalInOut digitalInOut9(p14, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.16/RXD1/SSEL0/SSEL
01341 #endif
01342     //
01343     // these pins support analog input analogIn0 .. analogIn5
01344     //DigitalInOut digitalInOut_(p15, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.23/AD0.0/I2SRX_CLK/CAP3.0
01345     //DigitalInOut digitalInOut_(p16, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.24/AD0.1/I2SRX_WS/CAP3.1
01346     //DigitalInOut digitalInOut_(p17, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.25/AD0.2/I2SRX_SDA/TXD3
01347     //DigitalInOut digitalInOut_(p18, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.26/AD0.3/AOUT/RXD3
01348     //DigitalInOut digitalInOut_(p19, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P1.30/VBUS/AD0.4
01349     //DigitalInOut digitalInOut_(p20, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P1.31/SCK1/AD0.5
01350     //
01351     // these pins support PWM pwmDriver1 .. pwmDriver6
01352     //DigitalInOut digitalInOut_(p21, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.5/PWM1.6/DTR1/TRACEDATA0
01353     //DigitalInOut digitalInOut_(p22, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.4/PWM1.5/DSR1/TRACEDATA1
01354     //DigitalInOut digitalInOut_(p23, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.3/PWM1.4/DCD1/TRACEDATA2
01355     //DigitalInOut digitalInOut_(p24, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.2/PWM1.3/CTS1/TRACEDATA3
01356     //DigitalInOut digitalInOut_(p25, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.1/PWM1.2/RXD1
01357     //DigitalInOut digitalInOut_(p26, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P2.0/PWM1.1/TXD1/TRACECLK
01358     //
01359     // these could be additional digitalInOut pins
01360 #if HAS_digitalInOut10
01361     DigitalInOut digitalInOut10(p27, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.11/RXD2/SCL2/MAT3.1
01362 #endif
01363 #if HAS_digitalInOut11
01364     DigitalInOut digitalInOut11(p28, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.10/TXD2/SDA2/MAT3.0
01365 #endif
01366 #if HAS_digitalInOut12
01367     DigitalInOut digitalInOut12(p29, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.5/I2SRX_WS/CAN_TX2/CAP2.1
01368 #endif
01369 #if HAS_digitalInOut13
01370     DigitalInOut digitalInOut13(p30, PIN_INPUT, PullUp, 1); // TARGET_LPC1768 P0.4/I2SRX_CLK/CAN_RX2/CAP2.0
01371 #endif
01372 #if HAS_digitalInOut14
01373     DigitalInOut digitalInOut14(___, PIN_INPUT, PullUp, 1);
01374 #endif
01375 #if HAS_digitalInOut15
01376     DigitalInOut digitalInOut15(___, PIN_INPUT, PullUp, 1);
01377 #endif
01378 #else
01379     // unknown target
01380 #endif
01381 // uncrustify-0.66.1 *INDENT-ON*
01382 #if HAS_digitalInOut0 || HAS_digitalInOut1 \
01383     || HAS_digitalInOut2 || HAS_digitalInOut3 \
01384     || HAS_digitalInOut4 || HAS_digitalInOut5 \
01385     || HAS_digitalInOut6 || HAS_digitalInOut7 \
01386     || HAS_digitalInOut8 || HAS_digitalInOut9 \
01387     || HAS_digitalInOut10 || HAS_digitalInOut11 \
01388     || HAS_digitalInOut12 || HAS_digitalInOut13 \
01389     || HAS_digitalInOut14 || HAS_digitalInOut15 \
01390     || HAS_digitalInOut16 || HAS_digitalInOut17
01391 #define HAS_digitalInOuts 1
01392 #endif
01393 
01394 // uncrustify-0.66.1 *INDENT-OFF*
01395 //--------------------------------------------------
01396 // Declare the AnalogIn driver
01397 // Optional analogIn support. If there is only one it should be analogIn1.
01398 // A) analog input
01399 #if defined(TARGET_MAX32630)
01400     #define HAS_analogIn0 1
01401     #define HAS_analogIn1 1
01402     #define HAS_analogIn2 1
01403     #define HAS_analogIn3 1
01404     #define HAS_analogIn4 1
01405     #define HAS_analogIn5 1
01406     #define HAS_analogIn6 1
01407     #define HAS_analogIn7 1
01408     #define HAS_analogIn8 1
01409     #define HAS_analogIn9 1
01410 //    #define HAS_analogIn10 0
01411 //    #define HAS_analogIn11 0
01412 //    #define HAS_analogIn12 0
01413 //    #define HAS_analogIn13 0
01414 //    #define HAS_analogIn14 0
01415 //    #define HAS_analogIn15 0
01416 #if HAS_analogIn0
01417     AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
01418 #endif
01419 #if HAS_analogIn1
01420     AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
01421 #endif
01422 #if HAS_analogIn2
01423     AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
01424 #endif
01425 #if HAS_analogIn3
01426     AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
01427 #endif
01428 #if HAS_analogIn4
01429     AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
01430 #endif
01431 #if HAS_analogIn5
01432     AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
01433 #endif
01434 #if HAS_analogIn6
01435     AnalogIn analogIn6(AIN_6); // TARGET_MAX32630 AIN_6 = VDDB / 4.0     fullscale is 4.8V
01436 #endif
01437 #if HAS_analogIn7
01438     AnalogIn analogIn7(AIN_7); // TARGET_MAX32630 AIN_7 = VDD18          fullscale is 1.2V
01439 #endif
01440 #if HAS_analogIn8
01441     AnalogIn analogIn8(AIN_8); // TARGET_MAX32630 AIN_8 = VDD12          fullscale is 1.2V
01442 #endif
01443 #if HAS_analogIn9
01444     AnalogIn analogIn9(AIN_9); // TARGET_MAX32630 AIN_9 = VRTC / 2.0     fullscale is 2.4V
01445 #endif
01446 #if HAS_analogIn10
01447     AnalogIn analogIn10(____); // TARGET_MAX32630 AIN_10 = x undefined?
01448 #endif
01449 #if HAS_analogIn11
01450     AnalogIn analogIn11(____); // TARGET_MAX32630 AIN_11 = VDDIO / 4.0   fullscale is 4.8V
01451 #endif
01452 #if HAS_analogIn12
01453     AnalogIn analogIn12(____); // TARGET_MAX32630 AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
01454 #endif
01455 #if HAS_analogIn13
01456     AnalogIn analogIn13(____);
01457 #endif
01458 #if HAS_analogIn14
01459     AnalogIn analogIn14(____);
01460 #endif
01461 #if HAS_analogIn15
01462     AnalogIn analogIn15(____);
01463 #endif
01464 //--------------------------------------------------
01465 #elif defined(TARGET_MAX32625MBED)
01466     #define HAS_analogIn0 1
01467     #define HAS_analogIn1 1
01468     #define HAS_analogIn2 1
01469     #define HAS_analogIn3 1
01470     #define HAS_analogIn4 1
01471     #define HAS_analogIn5 1
01472 #if HAS_analogIn0
01473     AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
01474 #endif
01475 #if HAS_analogIn1
01476     AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
01477 #endif
01478 #if HAS_analogIn2
01479     AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
01480 #endif
01481 #if HAS_analogIn3
01482     AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
01483 #endif
01484 #if HAS_analogIn4
01485     AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
01486 #endif
01487 #if HAS_analogIn5
01488     AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
01489 #endif
01490 //--------------------------------------------------
01491 #elif defined(TARGET_MAX32620FTHR)
01492 #warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..."
01493     #define HAS_analogIn0 1
01494     #define HAS_analogIn1 1
01495     #define HAS_analogIn2 1
01496     #define HAS_analogIn3 1
01497     #define HAS_analogIn4 1
01498     #define HAS_analogIn5 1
01499     #define HAS_analogIn6 1
01500     #define HAS_analogIn7 1
01501     #define HAS_analogIn8 1
01502     #define HAS_analogIn9 1
01503 //    #define HAS_analogIn10 0
01504 //    #define HAS_analogIn11 0
01505 //    #define HAS_analogIn12 0
01506 //    #define HAS_analogIn13 0
01507 //    #define HAS_analogIn14 0
01508 //    #define HAS_analogIn15 0
01509 #if HAS_analogIn0
01510     AnalogIn analogIn0(AIN_0); // TARGET_MAX32620FTHR J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
01511 #endif
01512 #if HAS_analogIn1
01513     AnalogIn analogIn1(AIN_1); // TARGET_MAX32620FTHR J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
01514 #endif
01515 #if HAS_analogIn2
01516     AnalogIn analogIn2(AIN_2); // TARGET_MAX32620FTHR J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
01517 #endif
01518 #if HAS_analogIn3
01519     AnalogIn analogIn3(AIN_3); // TARGET_MAX32620FTHR J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
01520 #endif
01521 #if HAS_analogIn4
01522     AnalogIn analogIn4(AIN_4); // TARGET_MAX32620FTHR J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
01523 #endif
01524 #if HAS_analogIn5
01525     AnalogIn analogIn5(AIN_5); // TARGET_MAX32620FTHR J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
01526 #endif
01527 #if HAS_analogIn6
01528     AnalogIn analogIn6(AIN_6); // TARGET_MAX32620FTHR AIN_6 = VDDB / 4.0     fullscale is 4.8V
01529 #endif
01530 #if HAS_analogIn7
01531     AnalogIn analogIn7(AIN_7); // TARGET_MAX32620FTHR AIN_7 = VDD18          fullscale is 1.2V
01532 #endif
01533 #if HAS_analogIn8
01534     AnalogIn analogIn8(AIN_8); // TARGET_MAX32620FTHR AIN_8 = VDD12          fullscale is 1.2V
01535 #endif
01536 #if HAS_analogIn9
01537     AnalogIn analogIn9(AIN_9); // TARGET_MAX32620FTHR AIN_9 = VRTC / 2.0     fullscale is 2.4V
01538 #endif
01539 #if HAS_analogIn10
01540     AnalogIn analogIn10(____); // TARGET_MAX32620FTHR AIN_10 = x undefined?
01541 #endif
01542 #if HAS_analogIn11
01543     AnalogIn analogIn11(____); // TARGET_MAX32620FTHR AIN_11 = VDDIO / 4.0   fullscale is 4.8V
01544 #endif
01545 #if HAS_analogIn12
01546     AnalogIn analogIn12(____); // TARGET_MAX32620FTHR AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
01547 #endif
01548 #if HAS_analogIn13
01549     AnalogIn analogIn13(____);
01550 #endif
01551 #if HAS_analogIn14
01552     AnalogIn analogIn14(____);
01553 #endif
01554 #if HAS_analogIn15
01555     AnalogIn analogIn15(____);
01556 #endif
01557 //--------------------------------------------------
01558 #elif defined(TARGET_MAX32625PICO)
01559 #warning "TARGET_MAX32625PICO not previously tested; need to verify analogIn0..."
01560     #define HAS_analogIn0 1
01561     #define HAS_analogIn1 1
01562     #define HAS_analogIn2 1
01563     #define HAS_analogIn3 1
01564     #define HAS_analogIn4 1
01565     #define HAS_analogIn5 1
01566 #if HAS_analogIn0
01567     AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin       fullscale is 1.2V
01568 #endif
01569 #if HAS_analogIn1
01570     AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin       fullscale is 1.2V
01571 #endif
01572 #if HAS_analogIn2
01573     AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin       fullscale is 1.2V
01574 #endif
01575 #if HAS_analogIn3
01576     AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin       fullscale is 1.2V
01577 #endif
01578 #if HAS_analogIn4
01579     AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
01580 #endif
01581 #if HAS_analogIn5
01582     AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0     fullscale is 6.0V
01583 #endif
01584 //--------------------------------------------------
01585 #elif defined(TARGET_MAX32600)
01586     #define HAS_analogIn0 1
01587     #define HAS_analogIn1 1
01588     #define HAS_analogIn2 1
01589     #define HAS_analogIn3 1
01590     #define HAS_analogIn4 1
01591     #define HAS_analogIn5 1
01592 #if HAS_analogIn0
01593     AnalogIn analogIn0(A0);
01594 #endif
01595 #if HAS_analogIn1
01596     AnalogIn analogIn1(A1);
01597 #endif
01598 #if HAS_analogIn2
01599     AnalogIn analogIn2(A2);
01600 #endif
01601 #if HAS_analogIn3
01602     AnalogIn analogIn3(A3);
01603 #endif
01604 #if HAS_analogIn4
01605     AnalogIn analogIn4(A4);
01606 #endif
01607 #if HAS_analogIn5
01608     AnalogIn analogIn5(A5);
01609 #endif
01610 //--------------------------------------------------
01611 #elif defined(TARGET_NUCLEO_F446RE)
01612     #define HAS_analogIn0 1
01613     #define HAS_analogIn1 1
01614     #define HAS_analogIn2 1
01615     #define HAS_analogIn3 1
01616     #define HAS_analogIn4 1
01617     #define HAS_analogIn5 1
01618 #if HAS_analogIn0
01619     AnalogIn analogIn0(A0);
01620 #endif
01621 #if HAS_analogIn1
01622     AnalogIn analogIn1(A1);
01623 #endif
01624 #if HAS_analogIn2
01625     AnalogIn analogIn2(A2);
01626 #endif
01627 #if HAS_analogIn3
01628     AnalogIn analogIn3(A3);
01629 #endif
01630 #if HAS_analogIn4
01631     AnalogIn analogIn4(A4);
01632 #endif
01633 #if HAS_analogIn5
01634     AnalogIn analogIn5(A5);
01635 #endif
01636 //--------------------------------------------------
01637 #elif defined(TARGET_NUCLEO_F401RE)
01638     #define HAS_analogIn0 1
01639     #define HAS_analogIn1 1
01640     #define HAS_analogIn2 1
01641     #define HAS_analogIn3 1
01642     #define HAS_analogIn4 1
01643     #define HAS_analogIn5 1
01644 #if HAS_analogIn0
01645     AnalogIn analogIn0(A0);
01646 #endif
01647 #if HAS_analogIn1
01648     AnalogIn analogIn1(A1);
01649 #endif
01650 #if HAS_analogIn2
01651     AnalogIn analogIn2(A2);
01652 #endif
01653 #if HAS_analogIn3
01654     AnalogIn analogIn3(A3);
01655 #endif
01656 #if HAS_analogIn4
01657     AnalogIn analogIn4(A4);
01658 #endif
01659 #if HAS_analogIn5
01660     AnalogIn analogIn5(A5);
01661 #endif
01662 //--------------------------------------------------
01663 // TODO1: TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
01664 #elif defined(TARGET_LPC1768)
01665     #define HAS_analogIn0 1
01666     #define HAS_analogIn1 1
01667     #define HAS_analogIn2 1
01668     #define HAS_analogIn3 1
01669     #define HAS_analogIn4 1
01670     #define HAS_analogIn5 1
01671 //    #define HAS_analogIn6 1
01672 //    #define HAS_analogIn7 1
01673 //    #define HAS_analogIn8 1
01674 //    #define HAS_analogIn9 1
01675 //    #define HAS_analogIn10 1
01676 //    #define HAS_analogIn11 1
01677 //    #define HAS_analogIn12 1
01678 //    #define HAS_analogIn13 1
01679 //    #define HAS_analogIn14 1
01680 //    #define HAS_analogIn15 1
01681 #if HAS_analogIn0
01682     AnalogIn analogIn0(p15); // TARGET_LPC1768 P0.23/AD0.0/I2SRX_CLK/CAP3.0
01683 #endif
01684 #if HAS_analogIn1
01685     AnalogIn analogIn1(p16); // TARGET_LPC1768 P0.24/AD0.1/I2SRX_WS/CAP3.1
01686 #endif
01687 #if HAS_analogIn2
01688     AnalogIn analogIn2(p17); // TARGET_LPC1768 P0.25/AD0.2/I2SRX_SDA/TXD3
01689 #endif
01690 #if HAS_analogIn3
01691     AnalogIn analogIn3(p18); // TARGET_LPC1768 P0.26/AD0.3/AOUT/RXD3
01692 #endif
01693 #if HAS_analogIn4
01694     AnalogIn analogIn4(p19); // TARGET_LPC1768 P1.30/VBUS/AD0.4
01695 #endif
01696 #if HAS_analogIn5
01697     AnalogIn analogIn5(p20); // TARGET_LPC1768 P1.31/SCK1/AD0.5
01698 #endif
01699 #if HAS_analogIn6
01700     AnalogIn analogIn6(____);
01701 #endif
01702 #if HAS_analogIn7
01703     AnalogIn analogIn7(____);
01704 #endif
01705 #if HAS_analogIn8
01706     AnalogIn analogIn8(____);
01707 #endif
01708 #if HAS_analogIn9
01709     AnalogIn analogIn9(____);
01710 #endif
01711 #if HAS_analogIn10
01712     AnalogIn analogIn10(____);
01713 #endif
01714 #if HAS_analogIn11
01715     AnalogIn analogIn11(____);
01716 #endif
01717 #if HAS_analogIn12
01718     AnalogIn analogIn12(____);
01719 #endif
01720 #if HAS_analogIn13
01721     AnalogIn analogIn13(____);
01722 #endif
01723 #if HAS_analogIn14
01724     AnalogIn analogIn14(____);
01725 #endif
01726 #if HAS_analogIn15
01727     AnalogIn analogIn15(____);
01728 #endif
01729 #else
01730     // unknown target
01731 #endif
01732 // uncrustify-0.66.1 *INDENT-ON*
01733 #if HAS_analogIn0 || HAS_analogIn1 \
01734     || HAS_analogIn2 || HAS_analogIn3 \
01735     || HAS_analogIn4 || HAS_analogIn5 \
01736     || HAS_analogIn6 || HAS_analogIn7 \
01737     || HAS_analogIn8 || HAS_analogIn9 \
01738     || HAS_analogIn10 || HAS_analogIn11 \
01739     || HAS_analogIn12 || HAS_analogIn13 \
01740     || HAS_analogIn14 || HAS_analogIn15
01741 #define HAS_analogIns 1
01742 #endif
01743 
01744 //--------------------------------------------------
01745 // Option to use LEDs to show status
01746 #ifndef USE_LEDS
01747 #define USE_LEDS 1
01748 #endif
01749 #if USE_LEDS
01750 #if defined(TARGET_MAX32630)
01751 # define LED_ON  0
01752 # define LED_OFF 1
01753 //--------------------------------------------------
01754 #elif defined(TARGET_MAX32625MBED)
01755 # define LED_ON  0
01756 # define LED_OFF 1
01757 //--------------------------------------------------
01758 // TODO1: TARGET=MAX32625MBED ARM Cortex-M4F 96MHz 512kB Flash 160kB SRAM
01759 #elif defined(TARGET_LPC1768)
01760 # define LED_ON  1
01761 # define LED_OFF 0
01762 #else // not defined(TARGET_LPC1768 etc.)
01763 # define LED_ON  1
01764 # define LED_OFF 0
01765 #endif // target definition
01766 DigitalOut led1(LED1, LED_OFF); // MAX32630FTHR: LED1 = LED_RED
01767 DigitalOut led2(LED2, LED_OFF); // MAX32630FTHR: LED2 = LED_GREEN
01768 DigitalOut led3(LED3, LED_OFF); // MAX32630FTHR: LED3 = LED_BLUE
01769 DigitalOut led4(LED4, LED_OFF);
01770 #else // USE_LEDS=0
01771 // issue #41 support Nucleo_F446RE
01772 // there are no LED indicators on the board, LED1 interferes with SPI;
01773 // but we still need placeholders led1 led2 led3 led4.
01774 // Declare DigitalOut led1 led2 led3 led4 targeting safe pins.
01775 // PinName NC means NOT_CONNECTED; DigitalOut::is_connected() returns false
01776 # define LED_ON  0
01777 # define LED_OFF 1
01778 DigitalOut led1(NC, LED_OFF);
01779 DigitalOut led2(NC, LED_OFF);
01780 DigitalOut led3(NC, LED_OFF);
01781 DigitalOut led4(NC, LED_OFF);
01782 #endif // USE_LEDS
01783 
01784 //--------------------------------------------------
01785 #if USE_LEDS
01786 class RGB_LED {
01787 public:
01788     RGB_LED(DigitalOut &led_red, DigitalOut &led_green, DigitalOut &led_blue)
01789         : m_red(led_red), m_green(led_green), m_blue(led_blue)
01790     {
01791     };
01792     DigitalOut &m_red;
01793     DigitalOut &m_green;
01794     DigitalOut &m_blue;
01795     ~RGB_LED()
01796     {
01797     };
01798     /* diagnostic rbg led RED
01799      */
01800     void red() {
01801         m_red = LED_ON; m_green = LED_OFF; m_blue = LED_OFF; // diagnostic rbg led RED
01802     };
01803     /* diagnostic rbg led GREEN
01804      */
01805     void green() {
01806         m_red = LED_OFF; m_green = LED_ON; m_blue = LED_OFF; // diagnostic rbg led GREEN
01807     };
01808     /* diagnostic rbg led BLUE
01809      */
01810     void blue() {
01811         m_red = LED_OFF; m_green = LED_OFF; m_blue = LED_ON; // diagnostic rbg led BLUE
01812     };
01813     /* diagnostic rbg led RED+GREEN+BLUE=WHITE
01814      */
01815     void white() {
01816         m_red = LED_ON; m_green = LED_ON; m_blue = LED_ON; // diagnostic rbg led RED+GREEN+BLUE=WHITE
01817     };
01818     /* diagnostic rbg led GREEN+BLUE=CYAN
01819      */
01820     void cyan() {
01821         m_red = LED_OFF; m_green = LED_ON; m_blue = LED_ON; // diagnostic rbg led GREEN+BLUE=CYAN
01822     };
01823     /* diagnostic rbg led RED+BLUE=MAGENTA
01824      */
01825     void magenta() {
01826         m_red = LED_ON; m_green = LED_OFF; m_blue = LED_ON; // diagnostic rbg led RED+BLUE=MAGENTA
01827     };
01828     /* diagnostic rbg led RED+GREEN=YELLOW
01829      */
01830     void yellow() {
01831         m_red = LED_ON; m_green = LED_ON; m_blue = LED_OFF; // diagnostic rbg led RED+GREEN=YELLOW
01832     };
01833     /* diagnostic rbg led BLACK
01834      */
01835     void black() {
01836         m_red = LED_OFF; m_green = LED_OFF; m_blue = LED_OFF; // diagnostic rbg led BLACK
01837     };
01838 };
01839 RGB_LED rgb_led(led1, led2, led3); // red, green, blue LEDs
01840 #endif // USE_LEDS
01841 
01842 //--------------------------------------------------
01843 // use BUTTON1 trigger some action
01844 #if defined(TARGET_MAX32630)
01845 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01846 #define HAS_BUTTON2_DEMO 0
01847 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01848 #elif defined(TARGET_MAX32625PICO)
01849 #warning "TARGET_MAX32625PICO not previously tested; need to define buttons..."
01850 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01851 #define HAS_BUTTON2_DEMO 0
01852 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01853 #elif defined(TARGET_MAX32625)
01854 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01855 #define HAS_BUTTON2_DEMO_INTERRUPT 1
01856 #elif defined(TARGET_MAX32620FTHR)
01857 #warning "TARGET_MAX32620FTHR not previously tested; need to define buttons..."
01858 #define BUTTON1 SW1
01859 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01860 #define HAS_BUTTON2_DEMO 0
01861 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01862 #elif defined(TARGET_NUCLEO_F446RE)
01863 #define HAS_BUTTON1_DEMO_INTERRUPT 0
01864 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01865 #elif defined(TARGET_NUCLEO_F401RE)
01866 #define HAS_BUTTON1_DEMO_INTERRUPT 0
01867 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01868 #else
01869 #warning "target not previously tested; need to define buttons..."
01870 #endif
01871 //
01872 #ifndef HAS_BUTTON1_DEMO
01873 #define HAS_BUTTON1_DEMO 0
01874 #endif
01875 #ifndef HAS_BUTTON2_DEMO
01876 #define HAS_BUTTON2_DEMO 0
01877 #endif
01878 //
01879 // avoid runtime error on button1 press [mbed-os-5.11]
01880 // instead of using InterruptIn, use DigitalIn and poll in main while(1)
01881 #ifndef HAS_BUTTON1_DEMO_INTERRUPT_POLLING
01882 #define HAS_BUTTON1_DEMO_INTERRUPT_POLLING 1
01883 #endif
01884 //
01885 #ifndef HAS_BUTTON1_DEMO_INTERRUPT
01886 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01887 #endif
01888 #ifndef HAS_BUTTON2_DEMO_INTERRUPT
01889 #define HAS_BUTTON2_DEMO_INTERRUPT 1
01890 #endif
01891 //
01892 #if HAS_BUTTON1_DEMO_INTERRUPT
01893 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
01894 // avoid runtime error on button1 press [mbed-os-5.11]
01895 // instead of using InterruptIn, use DigitalIn and poll in main while(1)
01896 DigitalIn button1(BUTTON1);
01897 # else
01898 InterruptIn button1(BUTTON1);
01899 # endif
01900 #elif HAS_BUTTON1_DEMO
01901 DigitalIn button1(BUTTON1);
01902 #endif
01903 #if HAS_BUTTON2_DEMO_INTERRUPT
01904 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
01905 // avoid runtime error on button1 press [mbed-os-5.11]
01906 // instead of using InterruptIn, use DigitalIn and poll in main while(1)
01907 DigitalIn button2(BUTTON2);
01908 # else
01909 InterruptIn button2(BUTTON2);
01910 # endif
01911 #elif HAS_BUTTON2_DEMO
01912 DigitalIn button2(BUTTON2);
01913 #endif
01914 
01915 //--------------------------------------------------
01916 // Ticker is the periodic interrupt timer itself
01917 #ifndef USE_PERIODIC_TIMER
01918 #define USE_PERIODIC_TIMER 0
01919 #endif
01920 #if USE_PERIODIC_TIMER
01921 Ticker periodicInterruptTimer;
01922 us_timestamp_t periodicInterruptTimer_interval_usec = 50;
01923 us_timestamp_t periodicInterruptTimer_interval_usec_MAX = 1000;
01924 us_timestamp_t periodicInterruptTimer_interval_usec_MIN = 20;
01925 #endif
01926 
01927 
01928 #if APPLICATION_MAX11131 // hardware interface functions
01929 //----------------------------------------
01930 void print_value(CmdLine& cmdLine, int16_t value_u12, int channelId)
01931 {
01932     int channelPairIndex = channelId / 2;
01933     // format: 1 0 0 0 1 UCH0/1 UCH2/3 UCH4/5 UCH6/7 UCH8/9 UCH10/11 UCH12/13 UCH14/15 PDIFF_COM x x
01934     // unused variable: int UCHn = (g_MAX11131_device.UNIPOLAR >> (10 - channelPairIndex)) & 0x01;
01935     int BCHn = (g_MAX11131_device.BIPOLAR >> (10 - channelPairIndex)) & 0x01;
01936     // unused variable: int RANGEn = (g_MAX11131_device.RANGE >> (10 - channelPairIndex)) & 0x01;
01937     //
01938     cmdLine.serial().printf(" ch=");
01939     // TODO1: if CHANID=0 don't print ch=channelId
01940     if ((g_MAX11131_device.isExternalClock == 0) || (g_MAX11131_device.chan_id_0_1 == 1))
01941     {
01942         // Internal clock modes always use channel ID.
01943         // External clock modes use channel ID if ADC_MODE_CONTROL.CHAN_ID is 1.
01944         cmdLine.serial().printf("%d", channelId);
01945     } else {
01946         cmdLine.serial().printf("?");
01947     }
01948     if (BCHn)
01949     {
01950         cmdLine.serial().printf(" xb=%ld", g_MAX11131_device.TwosComplementValue(value_u12));
01951     }
01952     else
01953     {
01954         cmdLine.serial().printf(" xu=%d", value_u12);
01955     }
01956     cmdLine.serial().printf(" = 0x%4.4x = %6.4fV",
01957                             (value_u12 & 0xFFFF),
01958                             g_MAX11131_device.VoltageOfCode(value_u12, channelId)
01959                             );
01960     // dtostrf width and precision: 2.5v / 4096 LSB = 0.0006103515625 volts per LSB
01961 }
01962 
01963 //----------------------------------------
01964 // read data words
01965 // @pre RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
01966 // @pre AINcode[NUM_CHANNELS] contains the latest readings in LSBs
01967 // For internal clock modes, the data format always includes the channel address.
01968 //     misoData16 = CH[3:0] DATA[11:0]
01969 void AINcode_print_value_chanID(CmdLine& cmdLine, int nWords)
01970 {
01971     cmdLine.serial().printf("ScanRead_nWords_chanID nWords=%d\r\n", nWords);
01972     for (int index = 0; index < nWords; index++) {
01973         //~ int16_t misoData16 = MAX11131_ScanRead();
01974         // For internal clock modes, the data format always includes the channel address.
01975         //     misoData16 = CH[3:0] DATA[11:0]
01976         int16_t value_u12 = (g_MAX11131_device.RAW_misoData16[index] & 0x0FFF);
01977         int channelId = ((g_MAX11131_device.RAW_misoData16[index] >> 12) & 0x000F);
01978         // diagnostic: print raw MISO data
01979         cmdLine.serial().printf("      MAX11131.MISO[%u]=0x%4.4x:", index,
01980                                 (g_MAX11131_device.RAW_misoData16[index] & 0xFFFF));
01981         print_value(cmdLine, value_u12, channelId);
01982         cmdLine.serial().printf("\r\n");
01983     }
01984 }
01985 
01986 //----------------------------------------
01987 // read data words
01988 // @pre RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
01989 // @pre AINcode[NUM_CHANNELS] contains the latest readings in LSBs
01990 // For external clock modes, the data format returned depends on the CHAN_ID bit.
01991 //     when CHAN_ID = 0: misoData16 = 0 DATA[11:0] x x x
01992 //     when CHAN_ID = 1: misoData16 = CH[3:0] DATA[11:0]
01993 void AINcode_print_value_externalClock(CmdLine& cmdLine, int nWords)
01994 {
01995     // For external clock modes, the data format returned depends on the CHAN_ID bit.
01996     //     when CHAN_ID = 0: misoData16 = 0 DATA[11:0] x x x
01997     //     when CHAN_ID = 1: misoData16 = CH[3:0] DATA[11:0]
01998     // For internal clock modes, the data format always includes the channel address.
01999     //     misoData16 = CH[3:0] DATA[11:0]
02000     if (g_MAX11131_device.chan_id_0_1 != 0) {
02001         AINcode_print_value_chanID(cmdLine, nWords);
02002         return;
02003     }
02004     cmdLine.serial().printf("ScanRead_nWords_externalClock nWords=%d\r\n", nWords);
02005     for (int index = 0; index < nWords; index++) {
02006         // int16_t misoData16 = MAX11131_ScanRead();
02007         int16_t value_u12 = ((g_MAX11131_device.RAW_misoData16[index] >> 3) & 0x0FFF);
02008         int channelId = g_MAX11131_device.channelNumber_0_15;
02009         // diagnostic: print raw MISO data
02010         cmdLine.serial().printf("      MAX11131.MISO[%u]=0x%4.4x:", index,
02011                                 (g_MAX11131_device.RAW_misoData16[index] & 0xFFFF));
02012         print_value(cmdLine, value_u12, channelId);
02013         cmdLine.serial().printf("\r\n");
02014     }
02015 }
02016 
02017 //----------------------------------------
02018 // read data words and calculate mean, stddev
02019 // @pre RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
02020 // @pre AINcode[NUM_CHANNELS] contains the latest readings in LSBs
02021 void AINcode_print_value_chanID_mean(CmdLine& cmdLine, int nWords)
02022 {
02023     cmdLine.serial().printf("ScanRead_nWords_chanID_mean nWords=%d\r\n", nWords);
02024     double Sx = 0;
02025     double Sxx = 0;
02026     for (int index = 0; index < nWords; index++) {
02027         //~ int16_t misoData16 = MAX11131_ScanRead();
02028         // For internal clock modes, the data format always includes the channel address.
02029         //     misoData16 = CH[3:0] DATA[11:0]
02030         int16_t value_u12 = (g_MAX11131_device.RAW_misoData16[index] & 0x0FFF);
02031         int channelId = ((g_MAX11131_device.RAW_misoData16[index] >> 12) & 0x000F);
02032         // TODO: sign-extend value_s12 from value_u12
02033         //
02034         cmdLine.serial().printf("n=%d", index);
02035         print_value(cmdLine, value_u12, channelId);
02036         //
02037         Sx = Sx + value_u12;
02038         Sxx = Sxx + ((double)value_u12 * value_u12);
02039         cmdLine.serial().printf(" Sx=%f Sxx=%f\r\n", Sx, Sxx);
02040     }
02041     double mean = Sx / nWords;
02042     cmdLine.serial().printf("  mean=%f=0x%4.4x", mean, (int)mean);
02043     // calculate standard deviation from N, Sx, Sxx
02044     if (nWords >= 2)
02045     {
02046         double variance = (Sxx - ( Sx * Sx / nWords)) / (nWords - 1);
02047         // stddev = square root of variance
02048         double stddev = sqrt(variance);
02049         cmdLine.serial().printf("  variance=%f  stddev=%f", variance, stddev);
02050     }
02051     cmdLine.serial().printf("\r\n");
02052 }
02053 
02054 /* MAX11131_print_register_verbose
02055  *
02056  * TODO: document this function
02057  * This header was inserted by uncrustify; see uncrustify_func_header.txt.
02058  *
02059  */
02060 void MAX11131_print_register_verbose(CmdLine& cmdLine, int16_t registerData)
02061 {
02062     if (registerData & 0x8000)
02063     {
02064         switch (registerData & 0xF800)
02065         {
02066             case 0x8000: // ADC_CONFIGURATION 0x8000..0x87FF format: 1 0 0 0 0 REFSEL AVGON NAVG[1:0] NSCAN[1:0] SPM[1:0] ECHO 0 0
02067                 cmdLine.serial().printf(" ADC_CONFIGURATION");
02068                 {
02069                     // define write-only register ADC_CONFIGURATION
02070                     //int16_t ADC_CONFIGURATION = 0x8000; //!< registerData 0x8000..0x87FF format: 1 0 0 0 0 REFSEL AVGON NAVG[1:0] NSCAN[1:0] SPM[1:0] ECHO 0 0
02071                     const int REFSEL_LSB = 10; const int REFSEL_BITS = 0x01; // ADC_CONFIGURATION.REFSEL
02072                     const int AVGON_LSB = 9; const int AVGON_BITS = 0x01; // ADC_CONFIGURATION.AVGON
02073                     const int NAVG_LSB = 7; const int NAVG_BITS = 0x03; // ADC_CONFIGURATION.NAVG[1:0]
02074                     const int NSCAN_LSB = 5; const int NSCAN_BITS = 0x03; // ADC_CONFIGURATION.NSCAN[1:0]
02075                     const int SPM_LSB = 3; const int SPM_BITS = 0x03; // ADC_CONFIGURATION.SPM[1:0]
02076                     const int ECHO_LSB = 2; const int ECHO_BITS = 0x01; // ADC_CONFIGURATION.ECHO
02077 
02078                     const int REFSEL = ((registerData >> REFSEL_LSB) & REFSEL_BITS);
02079                     const int AVGON = ((registerData >> AVGON_LSB) & AVGON_BITS);
02080                     const int NAVG = ((registerData >> NAVG_LSB) & NAVG_BITS);
02081                     const int NSCAN = ((registerData >> NSCAN_LSB) & NSCAN_BITS);
02082                     const int SPM = ((registerData >> SPM_LSB) & SPM_BITS);
02083                     const int ECHO = ((registerData >> ECHO_LSB) & ECHO_BITS);
02084 
02085                     if (REFSEL) {
02086                         cmdLine.serial().printf(" REFSEL=%d", REFSEL);
02087                     }
02088                     if (AVGON) {
02089                         cmdLine.serial().printf(" AVGON=%d", AVGON);
02090                     }
02091                     if (NAVG) {
02092                         cmdLine.serial().printf(" NAVG=%d", NAVG);
02093                     }
02094                     if (NSCAN) {
02095                         cmdLine.serial().printf(" NSCAN=%d", NSCAN);
02096                     }
02097                     if (SPM) {
02098                         cmdLine.serial().printf(" SPM=%d", SPM);
02099                     }
02100                     if (ECHO) {
02101                         cmdLine.serial().printf(" ECHO=%d", ECHO);
02102                     }
02103                 }
02104                 break;
02105             case 0x8800: // UNIPOLAR 0x8800..0x8FFF format: 1 0 0 0 1 UCH0/1 UCH2/3 UCH4/5 UCH6/7 UCH8/9 UCH10/11 UCH12/13 UCH14/15 PDIFF_COM x x
02106                 cmdLine.serial().printf(" UNIPOLAR 0x%4.4x", ((registerData >> 3) & 0xFF));
02107                 if ((registerData >> 2) & 0x01) {
02108                     cmdLine.serial().printf(" PDIFF_COM");
02109                 }
02110                 break;
02111             case 0x9000: // BIPOLAR 0x9000..0x97FF format: 1 0 0 1 0 BCH0/1 BCH2/3 BCH4/5 BCH6/7 BCH8/9 BCH10/11 BCH12/13 BCH14/15 x x x
02112                 cmdLine.serial().printf(" BIPOLAR  0x%4.4x", ((registerData >> 3) & 0xFF));
02113                 break;
02114             case 0x9800: // RANGE 0x9800..0x9FFF format: 1 0 0 1 1 RANGE0/1 RANGE2/3 RANGE4/5 RANGE6/7 RANGE8/9 RANGE10/11 RANGE12/13 RANGE14/15 x x x
02115                 cmdLine.serial().printf(" RANGE    0x%4.4x", ((registerData >> 3) & 0xFF));
02116                 break;
02117             case 0xA000: // CSCAN0 0xA000..0xA7FF format: 1 0 1 0 0 CHSCAN15 CHSCAN14 CHSCAN13 CHSCAN12 CHSCAN11 CHSCAN10 CHSCAN9 CHSCAN8 x x x
02118                 cmdLine.serial().printf(" CSCAN0 0x%4.4x", ((registerData >> 3) & 0xFF));
02119                 break;
02120             case 0xA800: // CSCAN1 0xA800..0xAFFF format: 1 0 1 0 1 CHSCAN7 CHSCAN6 CHSCAN5 CHSCAN4 CHSCAN3 CHSCAN2 CHSCAN1 CHSCAN0 x x x
02121                 cmdLine.serial().printf(" CSCAN1 0x%4.4x", ((registerData >> 3) & 0xFF));
02122                 break;
02123             case 0xB000: // SAMPLESET 0xB000..0xB7FF format: 1 0 1 1 0 SEQ_LENGTH[7:0] x x x
02124                 cmdLine.serial().printf(" SAMPLESET SEQ_LENGTH[7:0]=0x%4.4x", ((registerData >> 3) & 0xFF));
02125                 cmdLine.serial().printf(" so length=%d channels", (((registerData >> 3) & 0xFF) + 1));
02126                 break;
02127             default:
02128                 cmdLine.serial().printf(" ???");
02129                 break;
02130         }
02131     }
02132     else
02133     {
02134         // ADC_MODE_CONTROL 0x0000..0x7FFF format: 0 SCAN[3:0] CHSEL[3:0] RESET[1:0] PM[1:0] CHAN_ID SWCNV 0
02135         cmdLine.serial().printf(" ADC_MODE_CONTROL");
02136 
02137         // define write-only register ADC_MODE_CONTROL
02138         //int16_t ADC_MODE_CONTROL = 0;       //!< registerData 0x0000..0x7FFF format: 0 SCAN[3:0] CHSEL[3:0] RESET[1:0] PM[1:0] CHAN_ID SWCNV 0
02139         const int SCAN_LSB = 11; const int SCAN_BITS = 0x0F;   //!< ADC_MODE_CONTROL.SCAN[3:0] ADC Scan Control (command)
02140         const int CHSEL_LSB = 7; const int CHSEL_BITS = 0x0F;  //!< ADC_MODE_CONTROL.CHSEL[3:0] Analog Input Channel Select AIN0..AIN15
02141         const int RESET_LSB = 5; const int RESET_BITS = 0x03;  //!< ADC_MODE_CONTROL.RESET[1:0] Reset 0=Normal 1=ResetFIFO 2=ResetAllRegisters 3=reserved
02142         const int PM_LSB = 3; const int PM_BITS = 0x03;        //!< ADC_MODE_CONTROL.PM[1:0] Power Management 0=Normal, 1=AutoShutdown, 2=AutoStandby 3=reserved
02143         const int CHAN_ID_LSB = 2; const int CHAN_ID_BITS = 0x01; //!< ADC_MODE_CONTROL.CHAN_ID
02144         const int SWCNV_LSB = 1; const int SWCNV_BITS = 0x01;  //!< ADC_MODE_CONTROL.SWCNV
02145 
02146         const int SCAN = ((registerData >> SCAN_LSB) & SCAN_BITS);
02147         const int CHSEL = ((registerData >> CHSEL_LSB) & CHSEL_BITS);
02148         const int RESET = ((registerData >> RESET_LSB) & RESET_BITS);
02149         const int PM = ((registerData >> PM_LSB) & PM_BITS);
02150         const int CHANID = ((registerData >> CHAN_ID_LSB) & CHAN_ID_BITS);
02151         const int SWCNV = ((registerData >> SWCNV_LSB) & SWCNV_BITS);
02152 
02153         switch (SCAN)
02154         {
02155             case MAX11131::SCAN_0000_NOP:
02156                 cmdLine.serial().printf(" SCAN_0000_NOP");
02157                 break;
02158             case MAX11131::SCAN_0001_Manual:
02159                 cmdLine.serial().printf(" SCAN_0001_Manual CHSEL=%d", CHSEL);
02160                 break;
02161             case MAX11131::SCAN_0010_Repeat:
02162                 cmdLine.serial().printf(" SCAN_0010_Repeat CHSEL=%d", CHSEL);
02163                 break;
02164             case MAX11131::SCAN_0011_StandardInternalClock:
02165                 cmdLine.serial().printf(" SCAN_0011_StandardInt CHSEL=%d", CHSEL);
02166                 break;
02167             case MAX11131::SCAN_0100_StandardExternalClock:
02168                 cmdLine.serial().printf(" SCAN_0100_StandardExt CHSEL=%d", CHSEL);
02169                 break;
02170             case MAX11131::SCAN_0101_UpperInternalClock:
02171                 cmdLine.serial().printf(" SCAN_0101_UpperInt CHSEL=%d", CHSEL);
02172                 break;
02173             case MAX11131::SCAN_0110_UpperExternalClock:
02174                 cmdLine.serial().printf(" SCAN_0110_UpperExt CHSEL=%d", CHSEL);
02175                 break;
02176             case MAX11131::SCAN_0111_CustomInternalClock:
02177                 cmdLine.serial().printf(" SCAN_0111_CustomInt");
02178                 break;
02179             case MAX11131::SCAN_1000_CustomExternalClock:
02180                 cmdLine.serial().printf(" SCAN_1000_CustomExt");
02181                 break;
02182             case MAX11131::SCAN_1001_SampleSetExternalClock:
02183                 cmdLine.serial().printf(" SCAN_1001_SampleSetExt");
02184                 break;
02185             default:
02186                 cmdLine.serial().printf(" SCAN=%d", SCAN);
02187                 cmdLine.serial().printf(" CHSEL=%d", CHSEL);
02188         }
02189         if (RESET) {
02190             cmdLine.serial().printf(" RESET=%d", RESET);
02191         }
02192         if (PM) {
02193             cmdLine.serial().printf(" PM=%d", PM);
02194         }
02195         if (SCAN != MAX11131::SCAN_0000_NOP)
02196         {
02197             if (g_MAX11131_device.isExternalClock)
02198             {
02199                 // if external clock mode, print CHANID
02200                 cmdLine.serial().printf(" CHANID=%d", CHANID);
02201             }
02202             else
02203             {
02204                 // if internal clock mode, print SWCNV
02205                 cmdLine.serial().printf(" SWCNV=%d", SWCNV);
02206             }
02207         }
02208     }
02209     cmdLine.serial().printf("\r\n");
02210 }
02211 #endif
02212 
02213 
02214 #if APPLICATION_MAX5171 // hardware interface functions
02215 #endif
02216 
02217 
02218 #if APPLICATION_MAX11410 // hardware interface functions
02219 #endif
02220 
02221 
02222 #if APPLICATION_MAX12345 // hardware interface functions
02223 #endif
02224 
02225 
02226 //--------------------------------------------------
02227 // print banner message to serial port
02228 void print_banner()
02229 {
02230 #if HAS_DAPLINK_SERIAL
02231     DAPLINKserial.printf("\r\n");
02232 # if defined(TARGET_MAX32630)
02233     DAPLINKserial.printf("MAX32630");
02234 # elif defined(TARGET_MAX32625MBED)
02235     DAPLINKserial.printf("MAX32625MBED");
02236 # elif defined(TARGET_NUCLEO_F446RE)
02237     DAPLINKserial.printf("NUCLEO_F446RE");
02238 # elif defined(TARGET_NUCLEO_F401RE)
02239     DAPLINKserial.printf("NUCLEO_F401RE");
02240 # elif defined(TARGET_LPC1768)
02241     DAPLINKserial.printf("LPC1768");
02242 # else
02243     // unknown target
02244     DAPLINKserial.printf("unknownTarget");
02245 # endif
02246     DAPLINKserial.printf(" DAPLINKserial\r\n");
02247 #endif // HAS_DAPLINK_SERIAL
02248 
02249     serial.printf("\r\n");
02250 # if defined(TARGET_MAX32630)
02251     serial.printf("MAX32630");
02252 # elif defined(TARGET_MAX32625MBED)
02253     serial.printf("MAX32625MBED");
02254 # elif defined(TARGET_NUCLEO_F446RE)
02255     serial.printf("NUCLEO_F446RE");
02256 # elif defined(TARGET_NUCLEO_F401RE)
02257     serial.printf("NUCLEO_F401RE");
02258 # elif defined(TARGET_LPC1768)
02259     serial.printf("LPC1768");
02260 # else
02261     // unknown target
02262     serial.printf("unknownTarget");
02263 # endif
02264     serial.printf(" Tester\r\n");
02265 }
02266 
02267 // DigitalInOut pin resource: print the pin index names to serial
02268 #if HAS_digitalInOuts
02269 void list_digitalInOutPins(Stream& serialStream)
02270 {
02271 #if HAS_digitalInOut0
02272     serialStream.printf(" 0");
02273 #endif
02274 #if HAS_digitalInOut1
02275     serialStream.printf(" 1");
02276 #endif
02277 #if HAS_digitalInOut2
02278     serialStream.printf(" 2");
02279 #endif
02280 #if HAS_digitalInOut3
02281     serialStream.printf(" 3");
02282 #endif
02283 #if HAS_digitalInOut4
02284     serialStream.printf(" 4");
02285 #endif
02286 #if HAS_digitalInOut5
02287     serialStream.printf(" 5");
02288 #endif
02289 #if HAS_digitalInOut6
02290     serialStream.printf(" 6");
02291 #endif
02292 #if HAS_digitalInOut7
02293     serialStream.printf(" 7");
02294 #endif
02295 #if HAS_digitalInOut8
02296     serialStream.printf(" 8");
02297 #endif
02298 #if HAS_digitalInOut9
02299     serialStream.printf(" 9");
02300 #endif
02301 #if HAS_digitalInOut10
02302     serialStream.printf(" 10");
02303 #endif
02304 #if HAS_digitalInOut11
02305     serialStream.printf(" 11");
02306 #endif
02307 #if HAS_digitalInOut12
02308     serialStream.printf(" 12");
02309 #endif
02310 #if HAS_digitalInOut13
02311     serialStream.printf(" 13");
02312 #endif
02313 #if HAS_digitalInOut14
02314     serialStream.printf(" 14");
02315 #endif
02316 #if HAS_digitalInOut15
02317     serialStream.printf(" 15");
02318 #endif
02319 #if HAS_digitalInOut16
02320     serialStream.printf(" 16");
02321 #endif
02322 #if HAS_digitalInOut17
02323     serialStream.printf(" 17");
02324 #endif
02325 }
02326 #endif
02327 
02328 // DigitalInOut pin resource: present?
02329 #if HAS_digitalInOuts
02330 bool has_digitalInOutPin(int cPinIndex)
02331 {
02332     switch (cPinIndex)
02333     {
02334 #if HAS_digitalInOut0
02335         case '0': case 0x00: return true;
02336 #endif
02337 #if HAS_digitalInOut1
02338         case '1': case 0x01: return true;
02339 #endif
02340 #if HAS_digitalInOut2
02341         case '2': case 0x02: return true;
02342 #endif
02343 #if HAS_digitalInOut3
02344         case '3': case 0x03: return true;
02345 #endif
02346 #if HAS_digitalInOut4
02347         case '4': case 0x04: return true;
02348 #endif
02349 #if HAS_digitalInOut5
02350         case '5': case 0x05: return true;
02351 #endif
02352 #if HAS_digitalInOut6
02353         case '6': case 0x06: return true;
02354 #endif
02355 #if HAS_digitalInOut7
02356         case '7': case 0x07: return true;
02357 #endif
02358 #if HAS_digitalInOut8
02359         case '8': case 0x08: return true;
02360 #endif
02361 #if HAS_digitalInOut9
02362         case '9': case 0x09: return true;
02363 #endif
02364 #if HAS_digitalInOut10
02365         case 'a': case 0x0a: return true;
02366 #endif
02367 #if HAS_digitalInOut11
02368         case 'b': case 0x0b: return true;
02369 #endif
02370 #if HAS_digitalInOut12
02371         case 'c': case 0x0c: return true;
02372 #endif
02373 #if HAS_digitalInOut13
02374         case 'd': case 0x0d: return true;
02375 #endif
02376 #if HAS_digitalInOut14
02377         case 'e': case 0x0e: return true;
02378 #endif
02379 #if HAS_digitalInOut15
02380         case 'f': case 0x0f: return true;
02381 #endif
02382         default:
02383             return false;
02384     }
02385 }
02386 #endif
02387 
02388 // DigitalInOut pin resource: search index
02389 #if HAS_digitalInOuts
02390 DigitalInOut& find_digitalInOutPin(int cPinIndex)
02391 {
02392     switch (cPinIndex)
02393     {
02394         default: // default to the first defined digitalInOut pin
02395 #if HAS_digitalInOut0
02396         case '0': case 0x00: return digitalInOut0;
02397 #endif
02398 #if HAS_digitalInOut1
02399         case '1': case 0x01: return digitalInOut1;
02400 #endif
02401 #if HAS_digitalInOut2
02402         case '2': case 0x02: return digitalInOut2;
02403 #endif
02404 #if HAS_digitalInOut3
02405         case '3': case 0x03: return digitalInOut3;
02406 #endif
02407 #if HAS_digitalInOut4
02408         case '4': case 0x04: return digitalInOut4;
02409 #endif
02410 #if HAS_digitalInOut5
02411         case '5': case 0x05: return digitalInOut5;
02412 #endif
02413 #if HAS_digitalInOut6
02414         case '6': case 0x06: return digitalInOut6;
02415 #endif
02416 #if HAS_digitalInOut7
02417         case '7': case 0x07: return digitalInOut7;
02418 #endif
02419 #if HAS_digitalInOut8
02420         case '8': case 0x08: return digitalInOut8;
02421 #endif
02422 #if HAS_digitalInOut9
02423         case '9': case 0x09: return digitalInOut9;
02424 #endif
02425 #if HAS_digitalInOut10
02426         case 'a': case 0x0a: return digitalInOut10;
02427 #endif
02428 #if HAS_digitalInOut11
02429         case 'b': case 0x0b: return digitalInOut11;
02430 #endif
02431 #if HAS_digitalInOut12
02432         case 'c': case 0x0c: return digitalInOut12;
02433 #endif
02434 #if HAS_digitalInOut13
02435         case 'd': case 0x0d: return digitalInOut13;
02436 #endif
02437 #if HAS_digitalInOut14
02438         case 'e': case 0x0e: return digitalInOut14;
02439 #endif
02440 #if HAS_digitalInOut15
02441         case 'f': case 0x0f: return digitalInOut15;
02442 #endif
02443 #if HAS_digitalInOut16
02444         case 'g': case 0x10: return digitalInOut16;
02445 #endif
02446 #if HAS_digitalInOut17
02447         case 'h': case 0x11: return digitalInOut17;
02448 #endif
02449     }
02450 }
02451 #endif
02452 
02453 // AnalogIn pin resource: print the pin index names to serial
02454 #if HAS_analogIns
02455 void list_analogInPins(Stream& serialStream)
02456 {
02457 #if HAS_analogIn0
02458     serialStream.printf(" 0");
02459 #endif
02460 #if HAS_analogIn1
02461     serialStream.printf(" 1");
02462 #endif
02463 #if HAS_analogIn2
02464     serialStream.printf(" 2");
02465 #endif
02466 #if HAS_analogIn3
02467     serialStream.printf(" 3");
02468 #endif
02469 #if HAS_analogIn4
02470     serialStream.printf(" 4");
02471 #endif
02472 #if HAS_analogIn5
02473     serialStream.printf(" 5");
02474 #endif
02475 #if HAS_analogIn6
02476     serialStream.printf(" 6");
02477 #endif
02478 #if HAS_analogIn7
02479     serialStream.printf(" 7");
02480 #endif
02481 #if HAS_analogIn8
02482     serialStream.printf(" 8");
02483 #endif
02484 #if HAS_analogIn9
02485     serialStream.printf(" 9");
02486 #endif
02487 #if HAS_analogIn10
02488     serialStream.printf(" a");
02489 #endif
02490 #if HAS_analogIn11
02491     serialStream.printf(" b");
02492 #endif
02493 #if HAS_analogIn12
02494     serialStream.printf(" c");
02495 #endif
02496 #if HAS_analogIn13
02497     serialStream.printf(" d");
02498 #endif
02499 #if HAS_analogIn14
02500     serialStream.printf(" e");
02501 #endif
02502 #if HAS_analogIn15
02503     serialStream.printf(" f");
02504 #endif
02505 }
02506 #endif
02507 
02508 // AnalogIn pin resource: present?
02509 #if HAS_analogIns
02510 bool has_analogInPin(int cPinIndex)
02511 {
02512     switch (cPinIndex)
02513     {
02514 #if HAS_analogIn0
02515         case '0': case 0x00: return true;
02516 #endif
02517 #if HAS_analogIn1
02518         case '1': case 0x01: return true;
02519 #endif
02520 #if HAS_analogIn2
02521         case '2': case 0x02: return true;
02522 #endif
02523 #if HAS_analogIn3
02524         case '3': case 0x03: return true;
02525 #endif
02526 #if HAS_analogIn4
02527         case '4': case 0x04: return true;
02528 #endif
02529 #if HAS_analogIn5
02530         case '5': case 0x05: return true;
02531 #endif
02532 #if HAS_analogIn6
02533         case '6': case 0x06: return true;
02534 #endif
02535 #if HAS_analogIn7
02536         case '7': case 0x07: return true;
02537 #endif
02538 #if HAS_analogIn8
02539         case '8': case 0x08: return true;
02540 #endif
02541 #if HAS_analogIn9
02542         case '9': case 0x09: return true;
02543 #endif
02544 #if HAS_analogIn10
02545         case 'a': case 0x0a: return true;
02546 #endif
02547 #if HAS_analogIn11
02548         case 'b': case 0x0b: return true;
02549 #endif
02550 #if HAS_analogIn12
02551         case 'c': case 0x0c: return true;
02552 #endif
02553 #if HAS_analogIn13
02554         case 'd': case 0x0d: return true;
02555 #endif
02556 #if HAS_analogIn14
02557         case 'e': case 0x0e: return true;
02558 #endif
02559 #if HAS_analogIn15
02560         case 'f': case 0x0f: return true;
02561 #endif
02562         default:
02563             return false;
02564     }
02565 }
02566 #endif
02567 
02568 // AnalogIn pin resource: search index
02569 #if HAS_analogIns
02570 AnalogIn& find_analogInPin(int cPinIndex)
02571 {
02572     switch (cPinIndex)
02573     {
02574         default: // default to the first defined analogIn pin
02575 #if HAS_analogIn0
02576         case '0': case 0x00: return analogIn0;
02577 #endif
02578 #if HAS_analogIn1
02579         case '1': case 0x01: return analogIn1;
02580 #endif
02581 #if HAS_analogIn2
02582         case '2': case 0x02: return analogIn2;
02583 #endif
02584 #if HAS_analogIn3
02585         case '3': case 0x03: return analogIn3;
02586 #endif
02587 #if HAS_analogIn4
02588         case '4': case 0x04: return analogIn4;
02589 #endif
02590 #if HAS_analogIn5
02591         case '5': case 0x05: return analogIn5;
02592 #endif
02593 #if HAS_analogIn6
02594         case '6': case 0x06: return analogIn6;
02595 #endif
02596 #if HAS_analogIn7
02597         case '7': case 0x07: return analogIn7;
02598 #endif
02599 #if HAS_analogIn8
02600         case '8': case 0x08: return analogIn8;
02601 #endif
02602 #if HAS_analogIn9
02603         case '9': case 0x09: return analogIn9;
02604 #endif
02605 #if HAS_analogIn10
02606         case 'a': case 0x0a: return analogIn10;
02607 #endif
02608 #if HAS_analogIn11
02609         case 'b': case 0x0b: return analogIn11;
02610 #endif
02611 #if HAS_analogIn12
02612         case 'c': case 0x0c: return analogIn12;
02613 #endif
02614 #if HAS_analogIn13
02615         case 'd': case 0x0d: return analogIn13;
02616 #endif
02617 #if HAS_analogIn14
02618         case 'e': case 0x0e: return analogIn14;
02619 #endif
02620 #if HAS_analogIn15
02621         case 'f': case 0x0f: return analogIn15;
02622 #endif
02623     }
02624 }
02625 #endif
02626 
02627 #if HAS_analogIns
02628 const float analogInPin_fullScaleVoltage[] = {
02629 # if defined(TARGET_MAX32630)
02630     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02631     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02632     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02633     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02634     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
02635     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
02636     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
02637     ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
02638     ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
02639     ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
02640     ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
02641     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
02642     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
02643     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02644     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02645     ADC_FULL_SCALE_VOLTAGE // analogIn15
02646 # elif defined(TARGET_MAX32620FTHR)
02647 #warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..."
02648     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02649     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02650     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02651     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02652     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
02653     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
02654     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
02655     ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
02656     ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
02657     ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
02658     ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
02659     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
02660     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
02661     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02662     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02663     ADC_FULL_SCALE_VOLTAGE // analogIn15
02664 #elif defined(TARGET_MAX32625MBED)
02665     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn0 // fullscale is 1.2V
02666     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn1 // fullscale is 1.2V
02667     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn2 // fullscale is 1.2V
02668     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn3 // fullscale is 1.2V
02669     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
02670     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
02671     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
02672     ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
02673     ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
02674     ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
02675     ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
02676     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
02677     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
02678     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02679     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02680     ADC_FULL_SCALE_VOLTAGE // analogIn15
02681 #elif defined(TARGET_NUCLEO_F446RE)
02682     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02683     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02684     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02685     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02686     ADC_FULL_SCALE_VOLTAGE, // analogIn4
02687     ADC_FULL_SCALE_VOLTAGE, // analogIn5
02688     ADC_FULL_SCALE_VOLTAGE, // analogIn6
02689     ADC_FULL_SCALE_VOLTAGE, // analogIn7
02690     ADC_FULL_SCALE_VOLTAGE, // analogIn8
02691     ADC_FULL_SCALE_VOLTAGE, // analogIn9
02692     ADC_FULL_SCALE_VOLTAGE, // analogIn10
02693     ADC_FULL_SCALE_VOLTAGE, // analogIn11
02694     ADC_FULL_SCALE_VOLTAGE, // analogIn12
02695     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02696     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02697     ADC_FULL_SCALE_VOLTAGE // analogIn15
02698 #elif defined(TARGET_NUCLEO_F401RE)
02699     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02700     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02701     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02702     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02703     ADC_FULL_SCALE_VOLTAGE, // analogIn4
02704     ADC_FULL_SCALE_VOLTAGE, // analogIn5
02705     ADC_FULL_SCALE_VOLTAGE, // analogIn6
02706     ADC_FULL_SCALE_VOLTAGE, // analogIn7
02707     ADC_FULL_SCALE_VOLTAGE, // analogIn8
02708     ADC_FULL_SCALE_VOLTAGE, // analogIn9
02709     ADC_FULL_SCALE_VOLTAGE, // analogIn10
02710     ADC_FULL_SCALE_VOLTAGE, // analogIn11
02711     ADC_FULL_SCALE_VOLTAGE, // analogIn12
02712     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02713     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02714     ADC_FULL_SCALE_VOLTAGE // analogIn15
02715 //#elif defined(TARGET_LPC1768)
02716 #else
02717     // unknown target
02718     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02719     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02720     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02721     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02722     ADC_FULL_SCALE_VOLTAGE, // analogIn4
02723     ADC_FULL_SCALE_VOLTAGE, // analogIn5
02724     ADC_FULL_SCALE_VOLTAGE, // analogIn6
02725     ADC_FULL_SCALE_VOLTAGE, // analogIn7
02726     ADC_FULL_SCALE_VOLTAGE, // analogIn8
02727     ADC_FULL_SCALE_VOLTAGE, // analogIn9
02728     ADC_FULL_SCALE_VOLTAGE, // analogIn10
02729     ADC_FULL_SCALE_VOLTAGE, // analogIn11
02730     ADC_FULL_SCALE_VOLTAGE, // analogIn12
02731     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02732     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02733     ADC_FULL_SCALE_VOLTAGE // analogIn15
02734 # endif
02735 };
02736 #endif
02737 
02738 #if HAS_I2C // SUPPORT_I2C
02739 //--------------------------------------------------
02740 // Search I2C device address list
02741 //
02742 // @param[in] deviceAddress7First = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified.
02743 // @param[in] deviceAddress7Last = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified.
02744 // @param[in] numDevicesFoundLimit = maximum number of devices to detect before halting search; in case SCL stuck low or pullups missing.
02745 // @returns deviceAddress on success; 0 on failure
02746 // @post g_I2C_deviceAddress7 is updated with any device that did ACK
02747 //
02748 void HuntAttachedI2CDevices(CmdLine& cmdLine, uint8_t deviceAddress7First, uint8_t deviceAddress7Last,
02749                             const uint8_t numDevicesFoundLimit = 20)
02750 {
02751     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
02752     I2C i2cMaster(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
02753     i2cMaster.frequency(g_I2C_SCL_Hz);
02754 
02755     // %IP -- I2C probe
02756     // TODO: i2c transfer
02757     //const int addr7bit = 0x48;      // 7 bit I2C address
02758     //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
02759     // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
02760     // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
02761     // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
02762     // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
02763     // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
02764     // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
02765     // /* int */    i2cMaster.transfer (int addr8bit, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false) // Start nonblocking I2C transfer. More...
02766     // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
02767 
02768     //const char probeWriteData[] = { 0x00 };
02769     //int probeWriteDataLength = 1;
02770     //bool isRepeatedStart = false;
02771     cmdLine.serial().printf("I2C Probe {0x%2.2X (0x%2.2X >> 1) to 0x%2.2X (0x%2.2X >> 1)}, limit %d\r\n",
02772                             deviceAddress7First,
02773                             deviceAddress7First << 1,
02774                             deviceAddress7Last,
02775                             deviceAddress7Last << 1,
02776                             numDevicesFoundLimit); // HuntAttachedI2CDevices
02777     //~ const int i2cFileDescriptor = i2c_open_adapter(1);
02778     uint8_t numDevicesFound = 0;
02779     uint8_t last_valid_deviceAddress7 = 0;
02780     for (uint8_t deviceAddress7 = deviceAddress7First; deviceAddress7 <= deviceAddress7Last; deviceAddress7++)
02781     {
02782         //cmdLine.serial().printf(" (0x%2.2X >> 1) ", (deviceAddress7 << 1));
02783         //if (i2c_ioctl_I2C_SLAVE_i2cDeviceAddress7bits(i2cFileDescriptor, deviceAddress7) == 0)
02784         int addr8bit = deviceAddress7 * 2;
02785         //
02786         // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
02787         // Returns 0 on success (ack), nonzero on failure (nack)
02788         //bool gotACK = (i2cMaster.write (addr8bit, probeWriteData, probeWriteDataLength, isRepeatedStart) == 0);
02789         //
02790         // SMBusQuick test
02791         i2cMaster.start();
02792         // /** Write single byte out on the I2C bus
02793         //  *
02794         //  *  @param data data to write out on bus
02795         //  *
02796         //  *  @returns
02797         //  *    '0' - NAK was received
02798         //  *    '1' - ACK was received,
02799         //  *    '2' - timeout
02800         //  */
02801         // int write(int data);
02802         int writeStatus = i2cMaster.write(addr8bit);
02803         i2cMaster.stop();
02804         bool gotACK = (writeStatus == 1); // ACK was received
02805         if (writeStatus == 2) // timeout
02806         {
02807             cmdLine.serial().printf("- timeout\r\n");
02808         }
02809         //
02810         if (gotACK)
02811         {
02812             // @return status; error if (fileDescriptor < 0)
02813             cmdLine.serial().printf("+ ADDR=0x%2.2X (0x%2.2X >> 1) ACK\r\n", deviceAddress7, (deviceAddress7 << 1));
02814             numDevicesFound++;
02815             last_valid_deviceAddress7 = deviceAddress7;
02816             if (numDevicesFound > numDevicesFoundLimit)
02817             {
02818                 break;
02819             }
02820             continue;
02821         }
02822     }
02823     if (numDevicesFound == 0)
02824     {
02825         cmdLine.serial().printf("- No I2C devices found. Maybe SCL/SDA are swapped?\r\n");
02826     }
02827     else if (numDevicesFound > numDevicesFoundLimit)
02828     {
02829         cmdLine.serial().printf("- Many I2C devices found. SCL/SDA missing pullup resistors? SCL stuck low?\r\n");
02830     }
02831     else
02832     {
02833         //~ i2c_ioctl_I2C_SLAVE_i2cDeviceAddress7bits(i2cFileDescriptor, last_valid_deviceAddress7);
02834         g_I2C_deviceAddress7 = last_valid_deviceAddress7;
02835     }
02836     //~ i2c_close(i2cFileDescriptor);
02837 }
02838 #endif // SUPPORT_I2C
02839 
02840 //--------------------------------------------------
02841 // periodic interrupt timer onTimerTick handler triggered by Ticker
02842 // analogIn0 (MAX32630:AIN_4 = AIN0 / 5.0) controls angular speed
02843 // analogIn1 (MAX32630:AIN_5 = AIN1 / 5.0) controls PWM duty cycle
02844 // note: measured 500ns overhead for MAX32630FTHR digitalInOut1.write(0); digitalInOut1.write(1);
02845 #if USE_PERIODIC_TIMER
02846 void onTimerTick() {
02847 } // onTimerTick
02848 #endif
02849 
02850 #if USE_PERIODIC_TIMER
02851 // periodic interrupt timer command handlers -- enable timer
02852 void cmd_TE()
02853 {
02854     //us_timestamp_t interval_usec = 100000; // 100ms
02855     periodicInterruptTimer_interval_usec = 100000; // 100ms
02856 #  if HAS_DAPLINK_SERIAL
02857     DAPLINKserial.printf(" TE rate=%lluus -- Timer Enable\r\n", periodicInterruptTimer_interval_usec);
02858 #  endif
02859     serial.printf(" TE rate=%lluus -- Timer Enable", periodicInterruptTimer_interval_usec);
02860 #if 1
02861     // mbed shared event queue run onTimerTick() in Thread context not Interrupt context
02862     periodicInterruptTimer.attach_us(mbed_event_queue()->event(onTimerTick),
02863                                      periodicInterruptTimer_interval_usec);
02864     // Works if rate=620Hz or less, Fails if rate=750Hz
02865     // MbedOS Error Info Error Status 0x80FF0144 code 324 module 255
02866     // Assertion failed; id  location 0xBE6F  mbed-os.lib/events/Event.h+158
02867     // Current thread main id 0x200036f8 entry 0xc22f stacksize 0x1000 stackmem 0x200026f8 sp 0x2007ff60 
02868     // Seems not robust about overrun / sample rate too fast
02869 #else
02870     periodicInterruptTimer.attach_us(&onTimerTick, periodicInterruptTimer_interval_usec);
02871 #endif
02872     // -- periodicInterruptTimer.attach(&onTimerTick, interval_sec); // the address of the function to be attached (onTimerTick) and the interval (2 seconds)
02873     // -- periodicInterruptTimer.attach_us(&onTimerTick, interval_usec); // the address of the function to be attached (onTimerTick) and the interval (2 seconds)
02874     // -- periodicInterruptTimer.attach(Callback<void()> func, float t);
02875     // -- periodicInterruptTimer.attach_us(Callback<void()> func, us_timestamp_t t);
02876     // TODO1: cmd_T add cSubCommand to change interval of Ticker periodic interrupt timer
02877 }
02878 #endif
02879 
02880 #if USE_PERIODIC_TIMER
02881 // periodic interrupt timer command handlers -- disable timer
02882 void cmd_TD()
02883 {
02884 #  if HAS_DAPLINK_SERIAL
02885     DAPLINKserial.printf("  Timer Disable\r\n");
02886 #  endif
02887     serial.printf(" Timer Disable ");
02888     periodicInterruptTimer.detach(); // Detach the function
02889 }
02890 #endif
02891 
02892 //--------------------------------------------------
02893 // When user presses button BUTTON1, perform a demo configuration
02894 #if HAS_BUTTON1_DEMO_INTERRUPT
02895 void onButton1FallingEdge(void)
02896 {
02897     void SelfTest(CmdLine & cmdLine);
02898 
02899     SelfTest(cmdLine_serial);
02900 
02901 #if 0 // APPLICATION_MAX5715 // onButton1FallingEdge BUTTON1 demo configuration MAX5715BOB
02902     //~ cmdLine.serial().printf("MAX5715_REF(REF_AlwaysOn_2V500)");
02903     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500);
02904 
02905     uint16_t code = 4095;
02906     //~ cmdLine.serial().printf("CODEallLOADall code=%d", code);
02907     g_MAX5715_device.CODEallLOADall(code);
02908 #endif // APPLICATION_MAX5715
02909 
02910 }
02911 #endif // HAS_BUTTON1_DEMO_INTERRUPT
02912 
02913 //--------------------------------------------------
02914 // When user presses button BUTTON2, perform a demo configuration
02915 #if HAS_BUTTON2_DEMO_INTERRUPT
02916 void onButton2FallingEdge(void)
02917 {
02918     // TODO1: BUTTON2 demo configuration LED blink
02919 
02920 #if APPLICATION_MAX5715 // onButton2FallingEdge BUTTON2 demo configuration MAX5715BOB
02921     //~ cmdLine.serial().printf("MAX5715_REF(REF_AlwaysOn_2V048)");
02922     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048);
02923     //
02924     uint16_t ch = 0;
02925     uint16_t code = 0xccc;
02926     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02927     g_MAX5715_device.CODEnLOADn(ch, code);
02928     //
02929     ch = 1;
02930     code = 0x800;
02931     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02932     g_MAX5715_device.CODEnLOADn(ch, code);
02933     //
02934     ch = 2;
02935     code = 0x666;
02936     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02937     g_MAX5715_device.CODEnLOADn(ch, code);
02938     //
02939     ch = 3;
02940     code = 0xFFF;
02941     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02942     g_MAX5715_device.CODEnLOADn(ch, code);
02943 #elif APPLICATION_MAX11131 // onButton2FallingEdge BUTTON2 demo configuration MAX11131BOB
02944     // TODO1: demo
02945     // MAX11131 > 4
02946     // ScanStandardExternalClock ch=9 pm=0 id=1
02947     // ScanRead_nWords_chanID nWords=10
02948     //  ch=0 xu=2964 = 0x0b94 = 1.8091V
02949     //  ch=1 xu=2227 = 0x08b3 = 1.3593V
02950     //  ch=2 xu=1570 = 0x0622 = 0.9583V
02951     //  ch=3 xu=865 = 0x0361 = 0.5280V
02952     //  ch=4 xu=630 = 0x0276 = 0.3845V
02953     //  ch=5 xu=594 = 0x0252 = 0.3625V
02954     //  ch=6 xu=461 = 0x01cd = 0.2814V
02955     //  ch=7 xu=364 = 0x016c = 0.2222V
02956     //  ch=8 xu=480 = 0x01e0 = 0.2930V
02957     //  ch=9 xu=616 = 0x0268 = 0.3760V
02958     g_MAX11131_device.channelNumber_0_15 = 9;
02959     g_MAX11131_device.PowerManagement_0_2 = 0;
02960     g_MAX11131_device.chan_id_0_1 = 1;
02961     g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
02962     //
02963     // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
02964     // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
02965     g_MAX11131_device.ReadAINcode();
02966     // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
02967     // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
02968     //
02969     // TODO: compare with mbed/Arduino AIN0-AIN3
02970     //
02971 #elif APPLICATION_MAX5171 // onButton2FallingEdge BUTTON2 demo configuration MAX5171BOB
02972     // TODO: demo
02973     uint16_t code = 0xccc;
02974     g_MAX5171_device.CODE(code);
02975 #elif APPLICATION_MAX11410 // onButton2FallingEdge BUTTON2 demo configuration MAX11410BOB
02976     // TODO: demo
02977     g_MAX11410_device.CODEnLOADn(ch, code);
02978 #elif APPLICATION_MAX12345 // onButton2FallingEdge BUTTON2 demo configuration MAX12345BOB
02979     // TODO: demo
02980     g_MAX12345_device.CODEnLOADn(ch, code);
02981 #endif // APPLICATION_MAX5715
02982     rgb_led.blue(); // diagnostic rbg led BLUE
02983 
02984 }
02985 #endif // HAS_BUTTON2_DEMO_INTERRUPT
02986 
02987 //--------------------------------------------------
02988 // TODO1: use MaximTinyTester encapsulate SelfTest support functions
02989 //--------------------------------------------------
02990 #if APPLICATION_MAX5715 // SelfTest
02991 //
02992 // Note: ide.mbed.com does not support C++11 Lambda Expressions
02993 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
02994 //
02995 // define function under test using C++11 lambda expression [](){}
02996 // uint8_t MAX5715::Init(void)
02997 // uint8_t (*fn_MAX5715_Init)() = [](){ return g_MAX5715_device.Init(); };
02998 uint8_t fn_MAX5715_Init() { return g_MAX5715_device.Init(); };
02999 //
03000 // define function under test using C++11 lambda expression [](){}
03001 // uint16_t MAX5715::DACCodeOfVoltage(double voltageV)
03002 // uint16_t (*fn_MAX5715_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5715_device.DACCodeOfVoltage(voltageV); };
03003 uint16_t fn_MAX5715_DACCodeOfVoltage(double voltageV) { return g_MAX5715_device.DACCodeOfVoltage(voltageV); };
03004 //
03005 // define function under test using C++11 lambda expression [](){}
03006 // double MAX5715::VoltageOfCode(uint16_t value_u14)
03007 //double (*fn_MAX5715_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5715_device.VoltageOfCode(value_u14); };
03008 double fn_MAX5715_VoltageOfCode(uint16_t value_u14) { return g_MAX5715_device.VoltageOfCode(value_u14); };
03009 //
03010 // define function under test using C++11 lambda expression [](){}
03011 // void MAX5715::CODEnLOADn(uint8_t channel_0_3, uint16_t dacCodeLsbs)
03012 // void (*fn_MAX5715_CODEnLOADn)(uint8_t channel_0_3, uint16_t dacCodeLsbs) = [](uint8_t channel_0_3, uint16_t dacCodeLsbs){ return g_MAX5715_device.CODEnLOADn(channel_0_3, dacCodeLsbs); };
03013 void fn_MAX5715_CODEnLOADn (uint8_t channel_0_3, uint16_t dacCodeLsbs) { return g_MAX5715_device.CODEnLOADn(channel_0_3, dacCodeLsbs); };
03014 //
03015 #endif // APPLICATION_MAX5715 // SelfTest
03016 //--------------------------------------------------
03017 #if APPLICATION_MAX11131 // SelfTest
03018 //
03019 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03020 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03021 //
03022 // define function under test using C++11 lambda expression [](){}
03023 //
03024 #endif // APPLICATION_MAX11131 // SelfTest
03025 //--------------------------------------------------
03026 #if APPLICATION_MAX5171 // SelfTest
03027 //
03028 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03029 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03030 //
03031 // define function under test using C++11 lambda expression [](){}
03032 // uint8_t MAX5171::Init(void)
03033 // uint8_t (*fn_MAX5171_Init)() = [](){ return g_MAX5171_device.Init(); };
03034 uint8_t fn_MAX5171_Init() { return g_MAX5171_device.Init(); };
03035 //
03036 // define function under test using C++11 lambda expression [](){}
03037 // uint16_t MAX5171::DACCodeOfVoltage(double voltageV)
03038 // uint16_t (*fn_MAX5171_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5171_device.DACCodeOfVoltage(voltageV); };
03039 uint16_t fn_MAX5171_DACCodeOfVoltage(double voltageV) { return g_MAX5171_device.DACCodeOfVoltage(voltageV); };
03040 //
03041 // define function under test using C++11 lambda expression [](){}
03042 // double MAX5171::VoltageOfCode(uint16_t value_u14)
03043 // double (*fn_MAX5171_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5171_device.VoltageOfCode(value_u14); };
03044 double fn_MAX5171_VoltageOfCode(uint16_t value_u14) { return g_MAX5171_device.VoltageOfCode(value_u14); };
03045 //
03046 // define function under test using C++11 lambda expression [](){}
03047 // uint8_t MAX5171::CODE_LOAD(uint16_t dacCodeLsbs)
03048 // uint8_t (*fn_MAX5171_CODE_LOAD)(uint16_t dacCodeLsbs) = [](uint16_t dacCodeLsbs){ return g_MAX5171_device.CODE_LOAD(dacCodeLsbs); };
03049 uint8_t fn_MAX5171_CODE_LOAD(uint16_t dacCodeLsbs) { return g_MAX5171_device.CODE_LOAD(dacCodeLsbs); };
03050 //
03051 //
03052 #endif // APPLICATION_MAX5171 // SelfTest
03053 //--------------------------------------------------
03054 #if APPLICATION_MAX11410 // SelfTest
03055 //
03056 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03057 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03058 //
03059 // define function under test using C++11 lambda expression [](){}
03060 //
03061 #endif // APPLICATION_MAX11410 // SelfTest
03062 //--------------------------------------------------
03063 #if APPLICATION_MAX12345 // SelfTest
03064 //
03065 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03066 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03067 //
03068 // define function under test using C++11 lambda expression [](){}
03069 //
03070 #endif // APPLICATION_MAX12345 // SelfTest
03071 //--------------------------------------------------
03072 void SelfTest_print_DACCodeOfVoltage(CmdLine& cmdLine, double voltageV)
03073 {
03074     cmdLine.serial().printf("DACCodeOfVoltage(%6.4fV)", voltageV);
03075     // For 12-bit DAC, dtostrf width, precision = 6, 4 i.e. 0.0001
03076     // For 14-bit DAC, dtostrf width, precision = 7, 5 i.e. 0.00001
03077     //~ dtostrf(voltageV, 6, 4, strOutLineBuffer); // value, width, precision, char* buffer
03078     //~ cmdLine.serial().printf(strOutLineBuffer);
03079     //~ cmdLine.serial().printf("V)");
03080 }
03081 //--------------------------------------------------
03082 #if APPLICATION_MAX5171 // SelfTest
03083 void SelfTest_print_VoltageOfCode(CmdLine& cmdLine, uint16_t value_u14)
03084 {
03085     cmdLine.serial().printf("VoltageOfCode(%d)", value_u14);
03086 }
03087 #endif // APPLICATION_MAX5171
03088 //--------------------------------------------------
03089 #if APPLICATION_MAX5715 // SelfTest
03090 void SelfTest_print_Vref(CmdLine & cmdLine)
03091 {
03092     cmdLine.serial().printf("VRef = %6.4fV  LSB=%6.4fV", g_MAX5715_device.VRef, (g_MAX5715_device.VRef / 4095));
03093     //~ dtostrf(g_MAX5715_device.VRef, 6, 4, strOutLineBuffer); // value, width, precision, char* buffer
03094     //~ cmdLine.serial().printf(strOutLineBuffer);
03095     //~ cmdLine.serial().printf("V  LSB=");
03096     // For 12-bit DAC, dtostrf width, precision = 6, 4 i.e. 0.0001
03097     // For 14-bit DAC, dtostrf width, precision = 7, 5 i.e. 0.00001
03098     //~ dtostrf( (g_MAX5715_device.VRef / 4095), 6, 4, strOutLineBuffer); // value, width, precision, char* buffer
03099     //~ cmdLine.serial().printf(strOutLineBuffer);
03100     //~ cmdLine.serial().printf("V");
03101 }
03102 #endif // APPLICATION_MAX5715
03103 //--------------------------------------------------
03104 #if APPLICATION_MAX5171 // SelfTest
03105 void SelfTest_print_Vref(CmdLine & cmdLine)
03106 {
03107     cmdLine.serial().printf("VRef = %7.5fV  LSB=%7.5fV", g_MAX5171_device.VRef, (g_MAX5171_device.VRef / 16383));
03108     // For 12-bit DAC, dtostrf width, precision = 6, 4 i.e. 0.0001
03109     // For 14-bit DAC, dtostrf width, precision = 7, 5 i.e. 0.00001
03110 }
03111 #endif // APPLICATION_MAX5171
03112 //--------------------------------------------------
03113 #if HAS_SPI2_MAX541
03114 MAX541 max541(spi2_max541, spi2_max541_cs);
03115 #endif
03116 //--------------------------------------------------
03117 bool SelfTest_MAX541_Voltage(CmdLine & cmdLine, MAX541 &max541, double voltageV)
03118 {
03119     max541.Set_Voltage(voltageV);
03120     // cmdLine.serial().printf("\r\n      Test Fixture: MAX541 set output to %1.3fV = code 0x%4.4x", max541.Get_Voltage(), max541.Get_Code());
03121     cmdLine.serial().printf("\r\n      Test Fixture: MAX541 set output to 0x%4.4x = %1.3fV",
03122                             max541.Get_Code(), max541.Get_Voltage());
03123 #if analogIn4_IS_HIGH_RANGE_OF_analogIn0
03124     // Platform board uses AIN4,AIN5,.. as high range of AIN0,AIN1,..
03125     MaximTinyTester tinyTester(cmdLine, analogIn4, analogIn5, analogIn2, analogIn3, analogIn0, analogIn4, led1, led2, led3);
03126     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[4]; // board support
03127     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[5]; // board support
03128     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03129     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03130     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[0]; // board support
03131     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[1]; // board support
03132     // low range channels AIN0, AIN1, AIN2, AIN3
03133 #else // analogIn4_IS_HIGH_RANGE_OF_analogIn0
03134     // Platform board uses simple analog inputs
03135     MaximTinyTester tinyTester(cmdLine, analogIn0, analogIn1, analogIn2, analogIn3, analogIn4, analogIn5, led1, led2, led3);
03136     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[0]; // board support
03137     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[1]; // board support
03138     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03139     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03140     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[4]; // board support
03141     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[5]; // board support
03142 #endif
03143     tinyTester.Wait_Output_Settling(); // wait for MAX541 to settle
03144     // TODO: tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03145     tinyTester.err_threshold = 0.100;
03146     return tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03147 }
03148 //--------------------------------------------------
03149 void SelfTest(CmdLine & cmdLine)
03150 {
03151     //--------------------------------------------------
03152 #if analogIn4_IS_HIGH_RANGE_OF_analogIn0
03153     // Platform board uses AIN4,AIN5,.. as high range of AIN0,AIN1,..
03154     MaximTinyTester tinyTester(cmdLine, analogIn4, analogIn5, analogIn2, analogIn3, analogIn0, analogIn4, led1, led2, led3);
03155     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[4]; // board support
03156     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[5]; // board support
03157     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03158     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03159     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[0]; // board support
03160     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[1]; // board support
03161     // low range channels AIN0, AIN1, AIN2, AIN3
03162 #else // analogIn4_IS_HIGH_RANGE_OF_analogIn0
03163     // Platform board uses simple analog inputs
03164     MaximTinyTester tinyTester(cmdLine, analogIn0, analogIn1, analogIn2, analogIn3, analogIn4, analogIn5, led1, led2, led3);
03165     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[0]; // board support
03166     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[1]; // board support
03167     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03168     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03169     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[4]; // board support
03170     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[5]; // board support
03171 #endif
03172     tinyTester.clear();
03173 #if APPLICATION_MAX5715 // SelfTest
03174     //
03175     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03176     //
03177     // Note: ide.mbed.com does not support C++11 Lambda Expressions
03178     // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03179     // define function under test using C++11 lambda expression [](){}
03180     // uint8_t MAX5715::Init(void)
03181     //uint8_t (*fn_MAX5715_Init)() = [](){ return g_MAX5715_device.Init(); };
03182     //
03183     // define function under test using C++11 lambda expression [](){}
03184     // uint16_t MAX5715::DACCodeOfVoltage(double voltageV)
03185     //uint16_t (*fn_MAX5715_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5715_device.DACCodeOfVoltage(voltageV); };
03186     //
03187     // define function under test using C++11 lambda expression [](){}
03188     // double MAX5715::VoltageOfCode(uint16_t value_u14)
03189     //double (*fn_MAX5715_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5715_device.VoltageOfCode(value_u14); };
03190     //
03191     // define function under test using C++11 lambda expression [](){}
03192     // void MAX5715::CODEnLOADn(uint8_t channel_0_3, uint16_t dacCodeLsbs)
03193     //void (*fn_MAX5715_CODEnLOADn)(uint8_t channel_0_3, uint16_t dacCodeLsbs) = [](uint8_t channel_0_3, uint16_t dacCodeLsbs){ return g_MAX5715_device.CODEnLOADn(channel_0_3, dacCodeLsbs); };
03194     //
03195     //
03196     //
03197     //
03198     //
03199     //------------------------------------------------------------
03200     g_MAX5715_device.VRef = 4.096;     // MAX5715 12-bit LSB = 0.0010V
03201     SelfTest_print_Vref(cmdLine);
03202     //~ cmdLine.serial().printf("\r\n");
03203     //
03204     tinyTester.blink_time_msec = 20; // quickly speed through the software verification
03205     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03206     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 10.0, 0x0FFF);     // overrange FS
03207     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0950, 0x0FFF);
03208     //
03209     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0945, 0x0FFF);
03210     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0944, 0x0FFE);
03211     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0943, 0x0FFE);
03212     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0942, 0x0FFE);
03213     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0941, 0x0FFE);
03214     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0940, 0x0FFE);     // search for code transition
03215     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0939, 0x0FFE);
03216     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0938, 0x0FFE);
03217     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0937, 0x0FFE);
03218     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0936, 0x0FFE);
03219     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0935, 0x0FFD);
03220     //
03221     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0930, 0x0FFD);
03222     //
03223     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0480, 0x0800);
03224     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0470, 0x07FF);
03225     //
03226     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0000, 0x03E8);     // 1.0 volt
03227     //
03228     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0030, 0x0003);
03229     //
03230     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0020, 0x0002);
03231     //
03232     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0010, 0x0001);
03233     //
03234     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0000, 0x0000);
03235     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0001, 0x0000);     // overrange ZS
03236     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0002, 0x0000);     // overrange ZS
03237     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -1.0, 0x0000);     // overrange ZS
03238     //
03239     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03240     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFF, 4.0950);
03241     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFE, 4.0940);
03242     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0800, 2.0480);
03243     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07FF, 2.0470);
03244     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x03E8, 1.0000);     // 1.0 volt
03245     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0001, 0.0010);
03246     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0000, 0.0000);
03247     //
03248     //------------------------------------------------------------
03249     cmdLine.serial().printf("\r\n");
03250     g_MAX5715_device.VRef = 2.048;     // 12-bit LSB = 0.0005V
03251     SelfTest_print_Vref(cmdLine);
03252     //~ cmdLine.serial().printf("\r\n");
03253     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03254     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 10.0, 0x0FFF);     // overrange FS
03255     //
03256     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0480, 0x0FFF);
03257     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0479, 0x0FFF);
03258     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0478, 0x0FFF);
03259     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0477, 0x0FFF);
03260     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0476, 0x0FFF);
03261     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0475, 0x0FFF);
03262     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0474, 0x0FFF);
03263     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0473, 0x0FFF);
03264     //
03265     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0472, 0x0FFE);
03266     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0471, 0x0FFE);
03267     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0470, 0x0FFE);
03268     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0469, 0x0FFE);
03269     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0468, 0x0FFE);
03270     //
03271     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0467, 0x0FFD);
03272     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0466, 0x0FFD);
03273     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0465, 0x0FFD);
03274     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0464, 0x0FFD);
03275     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0463, 0x0FFD);
03276     //
03277     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0240, 0x0800);
03278     //
03279     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0235, 0x07FF);
03280     //
03281     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0000, 0x07D0);     // 1.0 volt
03282     //
03283     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0017, 0x0003);
03284     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0016, 0x0003);
03285     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0015, 0x0003);
03286     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0014, 0x0003);
03287     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0013, 0x0003);
03288     //
03289     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0012, 0x0002);
03290     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0011, 0x0002);
03291     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0010, 0x0002);
03292     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0009, 0x0002);
03293     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0008, 0x0002);
03294     //
03295     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0007, 0x0001);
03296     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0006, 0x0001);
03297     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0005, 0x0001);
03298     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0004, 0x0001);
03299     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0003, 0x0001);
03300     //
03301     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0002, 0x0000);
03302     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0001, 0x0000);
03303     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0000, 0x0000);
03304     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0001, 0x0000);     // overrange ZS
03305     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0002, 0x0000);     // overrange ZS
03306     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -1.0, 0x0000);     // overrange ZS
03307     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03308     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFF, 2.0475);
03309     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFE, 2.0470);
03310     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFD, 2.0465);
03311     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0800, 1.0240);
03312     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07FF, 1.0235);
03313     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07D0, 1.0000);     // 1.0 volt
03314     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0002, 0.0010);
03315     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0001, 0.0005);
03316     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0000, 0.0000);
03317     //
03318     //
03319     //------------------------------------------------------------
03320     cmdLine.serial().printf("\r\n");
03321     g_MAX5715_device.VRef = 2.500;     // 12-bit LSB = 0.0006105006105006105V
03322     SelfTest_print_Vref(cmdLine);
03323     //~ cmdLine.serial().printf("\r\n");
03324     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03325     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 10.0, 0x0FFF);     // overrange FS
03326     //
03327     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.5000, 0x0FFF);
03328     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4999, 0x0FFF);
03329     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4998, 0x0FFF);
03330     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4997, 0x0FFF);
03331     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4996, 0x0FFF);
03332     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4995, 0x0FFF);
03333     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4994, 0x0FFF);
03334     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4993, 0x0FFF);
03335     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4992, 0x0FFF);
03336     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4991, 0x0FFF);
03337     //
03338     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4990, 0x0FFE);     // search for code transitions
03339     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4989, 0x0FFE);
03340     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4988, 0x0FFE);
03341     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4987, 0x0FFE);
03342     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4986, 0x0FFE);
03343     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4985, 0x0FFE);
03344     //
03345     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4984, 0x0FFD);
03346     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4983, 0x0FFD);
03347     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4982, 0x0FFD);
03348     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4981, 0x0FFD);
03349     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4980, 0x0FFD);
03350     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4979, 0x0FFD);
03351     //
03352     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4978, 0x0FFC);
03353     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4977, 0x0FFC);
03354     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4976, 0x0FFC);
03355     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4975, 0x0FFC);
03356     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4974, 0x0FFC);
03357     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4973, 0x0FFC);
03358     //
03359     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4972, 0x0FFB);
03360     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4971, 0x0FFB);
03361     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4970, 0x0FFB);
03362     //
03363     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.2500, 0x0800);
03364     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.2494, 0x07FF);
03365     //
03366     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0000, 0x0666);     // 1.0 volt
03367     //
03368     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0019, 0x0003);     // search for code transitions
03369     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0018, 0x0003);
03370     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0017, 0x0003);
03371     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0016, 0x0003);
03372     //
03373     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0015, 0x0002);
03374     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0014, 0x0002);
03375     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0013, 0x0002);
03376     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0012, 0x0002);
03377     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0011, 0x0002);
03378     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0010, 0x0002);
03379     //
03380     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0009, 0x0001);
03381     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0008, 0x0001);
03382     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0007, 0x0001);
03383     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0006, 0x0001);
03384     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0005, 0x0001);
03385     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0004, 0x0001);
03386     //
03387     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0003, 0x0000);
03388     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0002, 0x0000);
03389     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0001, 0x0000);
03390     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0000, 0x0000);
03391     //
03392     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0001, 0x0000);     // overrange ZS
03393     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0002, 0x0000);     // overrange ZS
03394     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -1.0, 0x0000);     // overrange ZS
03395     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03396     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFF, 2.5000);
03397     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFE, 2.4988);
03398     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFD, 2.4976);
03399     //
03400     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0800, 1.2500);
03401     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07FF, 1.2494);
03402     //
03403     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0667, 1.0000);     // 1.0 volt
03404     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0666, 1.0000);     // 1.0 volt
03405     //
03406     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0002, 0.0012);
03407     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0001, 0.0006);
03408     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0000, 0.0000);
03409     //
03410     //
03411     // Device Testing: DAC commands, verify using on-board ADC inputs
03412     //
03413     tinyTester.blink_time_msec = 75;
03414     cmdLine.serial().printf("\r\n      MAX5715.Init()");
03415     g_MAX5715_device.Init();
03416     //
03417     uint16_t ch = 0;
03418     uint16_t code = 0xfff;
03419     double voltageV = 0.5;
03420     //
03421     // full-scale output on ch0, test MAX5715 internal REF options
03422     ch = 0;
03423     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03424     g_MAX5715_device.CODEnLOADn(ch, code);
03425     //
03426     cmdLine.serial().printf("\r\n      MAX5715.REF(MAX5715::REF_AlwaysOn_2V048)");
03427     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048);
03428     // tinyTester.Wait_Output_Settling replaces wait_ms
03429     tinyTester.Wait_Output_Settling();
03430     //  tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03431     tinyTester.err_threshold = 0.030; // 30mV
03432     tinyTester.AnalogIn0_Read_Expect_voltageV(2.048);
03433     //
03434     cmdLine.serial().printf("\r\n      MAX5715.REF(MAX5715::REF_AlwaysOn_4V096)");
03435     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_4V096);
03436     // MAX32625MBED 4.096V may be as low as 3.3V supply
03437     // tinyTester.Wait_Output_Settling replaces wait_ms
03438     tinyTester.Wait_Output_Settling();
03439     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03440     tinyTester.err_threshold = 0.50; // 30mV
03441     tinyTester.AnalogIn0_Read_Expect_voltageV(3.750); // accept 3.25V to 4.25V
03442     //
03443     cmdLine.serial().printf("\r\n      MAX5715.REF(MAX5715::REF_AlwaysOn_2V500)");
03444     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500);
03445     // tinyTester.Wait_Output_Settling replaces wait_ms
03446     tinyTester.Wait_Output_Settling();
03447     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03448     tinyTester.err_threshold = 0.030; // 30mV
03449     tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
03450     //
03451     // test the individual channel outputs
03452     ch = 0;
03453     voltageV = 0.5;
03454     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03455     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03456     g_MAX5715_device.CODEnLOADn(ch, code);
03457     // tinyTester.Wait_Output_Settling replaces wait_ms
03458     tinyTester.Wait_Output_Settling();
03459     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03460     tinyTester.err_threshold = 0.030; // 30mV
03461     tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03462     //
03463     ch = 1;
03464     voltageV = 0.2;
03465     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03466     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03467     g_MAX5715_device.CODEnLOADn(ch, code);
03468     // tinyTester.Wait_Output_Settling replaces wait_ms
03469     tinyTester.Wait_Output_Settling();
03470     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03471     tinyTester.err_threshold = 0.030; // 30mV
03472     tinyTester.AnalogIn1_Read_Expect_voltageV(voltageV);
03473     //
03474     ch = 2;
03475     voltageV = 0.4;
03476     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03477     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03478     g_MAX5715_device.CODEnLOADn(ch, code);
03479     // tinyTester.Wait_Output_Settling replaces wait_ms
03480     tinyTester.Wait_Output_Settling();
03481     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03482     tinyTester.err_threshold = 0.030; // 30mV
03483     tinyTester.AnalogIn2_Read_Expect_voltageV(voltageV);
03484     //
03485     ch = 3;
03486     voltageV = 0.25;
03487     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03488     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03489     g_MAX5715_device.CODEnLOADn(ch, code);
03490     // tinyTester.Wait_Output_Settling replaces wait_ms
03491     tinyTester.Wait_Output_Settling();
03492     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03493     tinyTester.err_threshold = 0.030; // 30mV
03494     tinyTester.AnalogIn3_Read_Expect_voltageV(voltageV);
03495     //
03496     // test that the channels are independent
03497     tinyTester.AnalogIn0_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[0]));
03498     tinyTester.AnalogIn1_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[1]));
03499     tinyTester.AnalogIn2_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[2]));
03500     tinyTester.AnalogIn3_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[3]));
03501     //
03502 #elif APPLICATION_MAX11131
03503     //
03504     // MAX11131BOB self-test functions
03505     //~ SelfTest_FAIL(cmdLine);
03506     //~ cmdLine.serial().printf("test program not implemented yet");
03507     int16_t value_u12;
03508     int channelId;
03509     double voltageV = 0.5;
03510     //
03511     //cmdLine.serial().printf("\r\n      0.0: MAX11131.Init()");
03512     //g_MAX11131_device.Init();
03513     //
03514     // Device Testing: ADC commands, verify with on-board ADC and SPI framing
03515     //
03516     tinyTester.blink_time_msec = 75;
03517     // MAX11131 SelfTest: MAX11131 SPI connections (Power Supply and GND, SCLK, MOSI, MISO, CS)
03518     cmdLine.serial().printf("\r\n");
03519     cmdLine.serial().printf(
03520         "\r\n      1.0: Test SCAN_0100_StandardExt -- verify SPI (VDD, GND, SCLK, MOSI, MISO, CS)");
03521     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03522     g_MAX11131_device.Init();
03523     // Send MOSI data       Expect MISO data    Description
03524     // 1000_0000_0000_0000  xxxx_xxxx_xxxx_xxxx ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0
03525     // 0010_0111_1010_0100  xxxx_xxxx_xxxx_xxxx ADC_MODE_CONTROL SCAN_0100_StandardExt CHSEL=15 RESET=1 CHANID=1
03526     // 0000_0000_0000_0000  0000_xxxx_xxxx_xxxx Channel ID tag = AIN0 expect high nybble 0
03527     // 0000_0000_0000_0000  0001_xxxx_xxxx_xxxx Channel ID tag = AIN1 expect high nybble 1
03528     // 0000_0000_0000_0000  0010_xxxx_xxxx_xxxx Channel ID tag = AIN2 expect high nybble 2
03529     // 0000_0000_0000_0000  0011_xxxx_xxxx_xxxx Channel ID tag = AIN3 expect high nybble 3
03530     //
03531     cmdLine.serial().printf("\r\n      MOSI <-- 1000_0000_0000_0000  ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0");
03532     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03533     g_MAX11131_device.SPIwrite16bits(0x8000);
03534     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03535     //
03536     cmdLine.serial().printf(
03537         "\r\n      MOSI <-- 0010_0111_1010_0100  ADC_MODE_CONTROL SCAN_0100_StandardExt CHSEL=15 RESET=1 CHANID=1");
03538     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03539     g_MAX11131_device.SPIwrite16bits(0x27a4);
03540     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03541     //
03542     for (int channelIndex = 0; channelIndex < 16; channelIndex++) {
03543         //~ cmdLine.serial().printf("\r\n      MISO --> expect 0000_xxxx_xxxx_xxxx");
03544         g_MAX11131_device.SPIoutputCS(0); // drive CS low
03545         g_MAX11131_device.RAW_misoData16[channelIndex] = g_MAX11131_device.SPIread16bits();
03546         g_MAX11131_device.SPIoutputCS(1); // drive CS high
03547         int expect_channelId = channelIndex;
03548         int actual_channelId = (g_MAX11131_device.RAW_misoData16[channelIndex] >> 12) & 0x000F;
03549         if (actual_channelId != expect_channelId)
03550         {
03551             tinyTester.FAIL();
03552             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03553             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03554             cmdLine.serial().printf(" but got 0x%1.1xxxx", actual_channelId);
03555         }
03556         else
03557         {
03558             tinyTester.PASS();
03559             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03560             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03561         }
03562     }
03563     //
03564     // MAX11131 SelfTest: MAX11131 Supports Internal Clock Modes (CNVST, EOC)
03565     cmdLine.serial().printf("\r\n");
03566     cmdLine.serial().printf(
03567         "\r\n      1.1: Test SCAN_0011_StandardInt -- verify Internal Clock signals (CNVST, EOC)");
03568     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03569     g_MAX11131_device.Init();
03570     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03571     g_MAX11131_device.RAW_misoData16[0] = g_MAX11131_device.SPIread16bits();
03572     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03573 //
03574     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_MAX11131_EOC_expect
03575     tinyTester.DigitalIn_Read_Expect_WarnOnly(EOCb_pin, "EOC", 1, "initial value before sending commands");
03576 //
03577     // Send MOSI data       Expect MISO data    Description
03578     // 1000_0000_0000_0000  xxxx_xxxx_xxxx_xxxx ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0 No Averaging
03579     // 0001_1001_1010_0000  xxxx_xxxx_xxxx_xxxx ADC_MODE_CONTROL SCAN_0011_StandardInt CHSEL=3 RESET=1 SWCNV=0
03580     // 0000_0000_0000_0000  0000_xxxx_xxxx_xxxx Channel ID tag = AIN0 expect high nybble 0
03581     // 0000_0000_0000_0000  0001_xxxx_xxxx_xxxx Channel ID tag = AIN1 expect high nybble 1
03582     // 0000_0000_0000_0000  0010_xxxx_xxxx_xxxx Channel ID tag = AIN2 expect high nybble 2
03583     // 0000_0000_0000_0000  0011_xxxx_xxxx_xxxx Channel ID tag = AIN3 expect high nybble 3
03584     //
03585     cmdLine.serial().printf("\r\n      MOSI <-- 1000_0000_0000_0000  ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0");
03586     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03587     g_MAX11131_device.SPIwrite16bits(0x8000);
03588     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03589     //
03590     cmdLine.serial().printf(
03591         "\r\n      MOSI <-- 0001_1001_1010_0000  ADC_MODE_CONTROL SCAN_0011_StandardInt CHSEL=3 RESET=1 SWCNV=0");
03592     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03593     g_MAX11131_device.SPIwrite16bits(0x19a0);
03594     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03595     //
03596     for (int channelIndex = 0; channelIndex < 4; channelIndex++) {
03597         //~ cmdLine.serial().printf("\r\n      MISO --> expect 0000_xxxx_xxxx_xxxx");
03598         //~ wait_ms(200); // delay
03599         g_MAX11131_device.CNVSToutputPulseLow();
03600         //~ g_MAX11131_device.CNVSToutputValue(0);
03601         //~ wait_ms(100); // delay
03602         //~ g_MAX11131_device.CNVSToutputValue(1);
03603         // g_MAX11131_device.EOCinputWaitUntilLow(); // infinite wait hazard, need to fail if timeout exceeded
03604         // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_MAX11131_EOC_expect
03605         tinyTester.DigitalIn_Read_Expect_WarnOnly(EOCb_pin, "EOC", 0, "after CNVST pulse");
03606         g_MAX11131_device.SPIoutputCS(0); // drive CS low
03607         g_MAX11131_device.RAW_misoData16[channelIndex] = g_MAX11131_device.SPIread16bits();
03608         g_MAX11131_device.SPIoutputCS(1); // drive CS high
03609         // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_MAX11131_EOC_expect
03610         tinyTester.DigitalIn_Read_Expect_WarnOnly(EOCb_pin, "EOC", 1, "after SPI read");
03611         int expect_channelId = channelIndex;
03612         int actual_channelId = (g_MAX11131_device.RAW_misoData16[channelIndex] >> 12) & 0x000F;
03613         if (actual_channelId != expect_channelId)
03614         {
03615             tinyTester.FAIL();
03616             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03617             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03618             cmdLine.serial().printf(" but got 0x%1.1xxxx", actual_channelId);
03619         }
03620         else
03621         {
03622             tinyTester.PASS();
03623             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03624             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03625         }
03626     }
03627     //
03628     // MAX11131 SelfTest: Test Fixture: MAX541ACPA+ to MAX32625MBED.AIN0/AIN4
03629     // Test Fixture: MAX541 connected to spi2
03630     // SPI spi2_max541(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 TARGET_MAX32635MBED: P2_5 P2_6 P2_4 Arduino 2x3-pin header; microSD
03631     // DigitalOut spi2_max541_cs(SPI2_SS); // TARGET_MAX32635MBED: P2_7 Arduino 2x3-pin header
03632     // Test Fixture: MAX541 spi2 init
03633     cmdLine.serial().printf("\r\n");
03634     cmdLine.serial().printf("\r\n      2.0: Test Fixture: MAX541 connected to spi2 (P2.4 P2.5 P2.7)?");
03635     bool SelfTest_has_max541 = false;
03636     // Check actual MAX541 reference voltage
03637     cmdLine.serial().printf("\r\n      Test Fixture: MAX541 midscale voltage measure with MAX32625MBED AIN0/4");
03638     max541.Set_Code(0x8000); // we don't know the fullscale voltage yet, so set code to midscale
03639     tinyTester.Wait_Output_Settling(); // wait for MAX541 to settle
03640     //
03641     double max541_midscale_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
03642     const int average_count = 100;
03643     const double average_K = 0.25;
03644     for (int count = 0; count < average_count; count++) {
03645         double measurement_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
03646         max541_midscale_V = ((1 - average_K) * max541_midscale_V) + (average_K * measurement_V);
03647     }
03648     if (max541_midscale_V > 1.0f) {
03649         max541.VRef = 2.0 * max541_midscale_V;
03650         cmdLine.serial().printf("\r\n      Test Fixture: MAX541 midscale = %1.3fV, so fullscale = %1.3fV",
03651                                 max541_midscale_V, max541.VRef);
03652         // Detect whether MAX541 is really connected to MAX32625MBED.AIN0/AIN4
03653         voltageV = 1.0f;
03654         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03655     }
03656     if (SelfTest_has_max541) {
03657         voltageV = 0.0f;
03658         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03659     }
03660     if (SelfTest_has_max541) {
03661         voltageV = 2.7f;
03662         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03663     }
03664     if (SelfTest_has_max541) {
03665         voltageV = 1.65f;
03666         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03667     }
03668     if (SelfTest_has_max541) {
03669         voltageV = 2.0f;
03670         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03671     }
03672     if (SelfTest_has_max541) {
03673         voltageV = 0.25f;
03674         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03675     }
03676     if (SelfTest_has_max541) {
03677         voltageV = 0.5f;
03678         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03679     }
03680     if (SelfTest_has_max541) {
03681         voltageV = 1.0f;
03682         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03683     }
03684     if (SelfTest_has_max541 == false) {
03685         // don't fail just because we're missing the test fixture...
03686         cmdLine.serial().printf("\r\n      Test Fixture: MAX541 not present");
03687         //~ g_SelfTest_nFail--;
03688     }
03689     //
03690     // TODO1: MAX11131 SelfTest: if Test Fixture: drive MAX541, compare MAX32625MBED.AIN0/AIN4 and MAX11131 AIN0
03691     // indirectly verify the reference voltage by reading a known input voltage
03692     if (SelfTest_has_max541) {
03693         cmdLine.serial().printf("\r\n");
03694         cmdLine.serial().printf("\r\n      2.1: TODO1: Check MAX11131 reference voltage using SCAN_0001_Manual");
03695         voltageV = 1.0f;
03696         SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03697         cmdLine.serial().printf("\r\n      MAX11131.Init()");
03698         g_MAX11131_device.Init();
03699         // 1 ScanManual ch=0 pm=0 id=1
03700         g_MAX11131_device.channelNumber_0_15 = 0;
03701         g_MAX11131_device.PowerManagement_0_2 = 0;
03702         g_MAX11131_device.chan_id_0_1 = 1;
03703         cmdLine.serial().printf("\r\n      MAX11131.channelNumber_0_15=%d", g_MAX11131_device.channelNumber_0_15);
03704         cmdLine.serial().printf("\r\n      MAX11131.PowerManagement_0_2=%d", g_MAX11131_device.PowerManagement_0_2);
03705         cmdLine.serial().printf("\r\n      MAX11131.chan_id_0_1=%d", g_MAX11131_device.chan_id_0_1);
03706         g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
03707         cmdLine.serial().printf("\r\n      MAX11131.ScanManual -- NumWords = %d",
03708                                 g_MAX11131_device.NumWords);
03709         g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
03710         g_MAX11131_device.ReadAINcode();
03711         cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03712         AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03713         //
03714         //  2.1: TODO1: Check MAX11131 reference voltage -- why we read 0xffff 2.4999V here?
03715         //
03716         cmdLine.serial().printf("\r\n      MAX11131.ScanManual -- NumWords = %d",
03717                                 g_MAX11131_device.NumWords);
03718         // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
03719         // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
03720         g_MAX11131_device.ReadAINcode();
03721         cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03722         AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03723         //
03724         //  2.1: TODO1: Check MAX11131 reference voltage -- why we read 0xffff 2.4999V here?
03725         //
03726         // compare with mbed/Arduino AIN0-AIN3
03727         // MAX32625MBED.AIN4 = MAX11131.AIN0
03728         channelId = 0;
03729         value_u12 = g_MAX11131_device.AINcode[channelId];
03730         voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03731 //
03732         // tinyTester.Wait_Output_Settling replaces wait_ms
03733         tinyTester.Wait_Output_Settling();
03734         // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03735         tinyTester.err_threshold = 0.100;
03736         tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03737 //
03738     }
03739     //
03740     if (SelfTest_has_max541) {
03741         voltageV = 1.0f;
03742         SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03743     }
03744     cmdLine.serial().printf("\r\n");
03745     cmdLine.serial().printf("\r\n      3.1: Test SCAN_0001_Manual");
03746     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03747     g_MAX11131_device.Init();
03748     // 1 ScanManual ch=0 pm=0 id=1
03749     g_MAX11131_device.channelNumber_0_15 = 0;
03750     g_MAX11131_device.PowerManagement_0_2 = 0;
03751     g_MAX11131_device.chan_id_0_1 = 1;
03752     cmdLine.serial().printf("\r\n      MAX11131.channelNumber_0_15=%d", g_MAX11131_device.channelNumber_0_15);
03753     cmdLine.serial().printf("\r\n      MAX11131.PowerManagement_0_2=%d", g_MAX11131_device.PowerManagement_0_2);
03754     cmdLine.serial().printf("\r\n      MAX11131.chan_id_0_1=%d", g_MAX11131_device.chan_id_0_1);
03755     g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
03756     cmdLine.serial().printf("\r\n      MAX11131.ScanManual -- NumWords = %d",
03757                             g_MAX11131_device.NumWords);
03758     // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
03759     // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
03760     g_MAX11131_device.ReadAINcode();
03761     cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03762     AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03763     // compare with mbed/Arduino AIN0-AIN3
03764     // MAX32625MBED.AIN4 = MAX11131.AIN0
03765     channelId = 0;
03766     value_u12 = g_MAX11131_device.AINcode[channelId];
03767     voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03768 //
03769     // tinyTester.Wait_Output_Settling replaces wait_ms
03770     tinyTester.Wait_Output_Settling();
03771     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03772     tinyTester.err_threshold = 0.100;
03773     tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03774 //
03775     //
03776     cmdLine.serial().printf("\r\n");
03777     cmdLine.serial().printf("\r\n      3.4: Test SCAN_0100_StandardExternalClock");
03778     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03779     g_MAX11131_device.Init();
03780     // MAX11131 > 4
03781     // ScanStandardExternalClock ch=9 pm=0 id=1
03782     // ScanRead_nWords_chanID nWords=10
03783     //  ch=0 xu=2964 = 0x0b94 = 1.8091V
03784     //  ch=1 xu=2227 = 0x08b3 = 1.3593V
03785     //  ch=2 xu=1570 = 0x0622 = 0.9583V
03786     //  ch=3 xu=865 = 0x0361 = 0.5280V
03787     //  ch=4 xu=630 = 0x0276 = 0.3845V
03788     //  ch=5 xu=594 = 0x0252 = 0.3625V
03789     //  ch=6 xu=461 = 0x01cd = 0.2814V
03790     //  ch=7 xu=364 = 0x016c = 0.2222V
03791     //  ch=8 xu=480 = 0x01e0 = 0.2930V
03792     //  ch=9 xu=616 = 0x0268 = 0.3760V
03793     g_MAX11131_device.channelNumber_0_15 = 9;
03794     g_MAX11131_device.PowerManagement_0_2 = 0;
03795     g_MAX11131_device.chan_id_0_1 = 1;
03796     cmdLine.serial().printf("\r\n      MAX11131.channelNumber_0_15=%d", g_MAX11131_device.channelNumber_0_15);
03797     cmdLine.serial().printf("\r\n      MAX11131.PowerManagement_0_2=%d", g_MAX11131_device.PowerManagement_0_2);
03798     cmdLine.serial().printf("\r\n      MAX11131.chan_id_0_1=%d", g_MAX11131_device.chan_id_0_1);
03799     g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
03800     cmdLine.serial().printf("\r\n      MAX11131.ScanStandardExternalClock -- NumWords = %d",
03801                             g_MAX11131_device.NumWords);
03802     // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
03803     // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
03804     g_MAX11131_device.ReadAINcode();
03805     cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03806     // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
03807     // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
03808     // expect g_MAX11131_device.NumWords == g_MAX11131_device.channelNumber_0_15 + 1;
03809     // expect RAW_misoData16[index] msnybble 0,1,2,3,...
03810     AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03811     // compare with mbed/Arduino AIN0-AIN3
03812     // MAX32625MBED.AIN4 = MAX11131.AIN0
03813     channelId = 0;
03814     value_u12 = g_MAX11131_device.AINcode[channelId];
03815     voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03816     // tinyTester.Wait_Output_Settling replaces wait_ms
03817     tinyTester.Wait_Output_Settling();
03818     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03819     tinyTester.err_threshold = 0.100;
03820     tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03821     // compare MAX32625MBED.AIN5 = MAX11131.AIN1
03822     //channelId = 1;
03823     //value_u12 = g_MAX11131_device.AINcode[channelId];
03824     //voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03825     //SelfTest_AnalogInput_Expect_ch_V(cmdLine, 5, voltageV, 0.100);
03826     //
03827 #elif APPLICATION_MAX5171
03828 
03829     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03830     //
03831     // Note: ide.mbed.com does not support C++11 Lambda Expressions
03832     // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03833     // define function under test using C++11 lambda expression [](){}
03834     // uint8_t MAX5171::Init(void)
03835     //uint8_t (*fn_MAX5171_Init)() = [](){ return g_MAX5171_device.Init(); };
03836     //
03837     // define function under test using C++11 lambda expression [](){}
03838     // uint16_t MAX5171::DACCodeOfVoltage(double voltageV)
03839     //uint16_t (*fn_MAX5171_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5171_device.DACCodeOfVoltage(voltageV); };
03840     //
03841     // define function under test using C++11 lambda expression [](){}
03842     // double MAX5171::VoltageOfCode(uint16_t value_u14)
03843     //double (*fn_MAX5171_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5171_device.VoltageOfCode(value_u14); };
03844     //
03845     // define function under test using C++11 lambda expression [](){}
03846     // uint8_t MAX5171::CODE_LOAD(uint16_t dacCodeLsbs)
03847     //uint8_t (*fn_MAX5171_CODE_LOAD)(uint16_t dacCodeLsbs) = [](uint16_t dacCodeLsbs){ return g_MAX5171_device.CODE_LOAD(dacCodeLsbs); };
03848     //
03849     //double one_LSB = (g_MAX5171_device.VRef / 16383); // 14-bit DAC FS
03850     // tinyTester.Wait_Output_Settling replaces wait_ms
03851     tinyTester.settle_time_msec = 250;
03852 
03853     g_MAX5171_device.VRef = 2.500;     // MAX5171 14-bit LSB = 0.00015V
03854     SelfTest_print_Vref(cmdLine);
03855     tinyTester.err_threshold = (g_MAX5171_device.VRef / 16383); // 14-bit DAC FS
03856     //
03857     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03858     tinyTester.blink_time_msec = 20; // quickly speed through the software verification
03859     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.499847412109375, 0x3FFF);
03860     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.49969482421875, 0x3FFE);
03861     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.499542236328125, 0x3FFD);
03862     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.4993896484375, 0x3FFC);
03863     //
03864     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.250152587890625, 0x2001);
03865     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.25, 0x2000);
03866     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.249847412109375, 0x1FFF);
03867     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.24969482421875, 0x1FFE);
03868     //
03869     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.000457763671875, 0x0003);
03870     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.00030517578125, 0x0002);
03871     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.000152587890625, 0x0001);
03872     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.00000, 0x0000);
03873     //
03874     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03875     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFF, 2.499847412109375);
03876     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFE, 2.49969482421875);
03877     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFD, 2.499542236328125);
03878     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFC, 2.4993896484375);
03879     //
03880     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x2001, 1.250152587890625);
03881     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x2000, 1.25);
03882     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x1FFF, 1.249847412109375);
03883     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x1FFE, 1.24969482421875);
03884     //
03885     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0003, 0.000457763671875);
03886     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0002, 0.00030517578125);
03887     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0001, 0.000152587890625);
03888     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0000, 0.00000);
03889     //
03890     // Device Testing: DAC commands, verify using on-board ADC inputs
03891     //
03892     tinyTester.blink_time_msec = 75;
03893     cmdLine.serial().printf("\r\n      MAX5171.Init()");
03894     g_MAX5171_device.Init();
03895     //
03896     tinyTester.err_threshold = 0.030; // 30mV
03897     uint16_t code = 0x3FFF;
03898     //~ double voltageV = 0.5;
03899     //
03900     cmdLine.serial().printf("\r\n      MAX5171.CODE_LOAD code=%d", code);
03901     g_MAX5171_device.CODE_LOAD(code);
03902     // tinyTester.Wait_Output_Settling replaces wait_ms
03903     tinyTester.Wait_Output_Settling();
03904     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03905     tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
03906     //
03907     code = 0x0000;
03908     cmdLine.serial().printf("\r\n      MAX5171.CODE_LOAD code=%d", code);
03909     g_MAX5171_device.CODE_LOAD(code);
03910     // tinyTester.Wait_Output_Settling replaces wait_ms
03911     tinyTester.Wait_Output_Settling();
03912     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03913     tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000);
03914     //
03915     code = 0x1FFF;
03916     cmdLine.serial().printf("\r\n      MAX5171.CODE_LOAD code=%d", code);
03917     g_MAX5171_device.CODE_LOAD(code);
03918     // tinyTester.Wait_Output_Settling replaces wait_ms
03919     tinyTester.Wait_Output_Settling();
03920     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03921     tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
03922     //
03923     // test UPO User Programmable Output, verify using digital input D2
03924     //
03925     cmdLine.serial().printf("\r\n      MAX5171.UPO_HIGH");
03926     g_MAX5171_device.UPO_HIGH();
03927     tinyTester.Wait_Output_Settling();
03928     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
03929     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
03930     //
03931     cmdLine.serial().printf("\r\n      MAX5171.UPO_LOW");
03932     g_MAX5171_device.UPO_LOW();
03933     tinyTester.Wait_Output_Settling();
03934     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
03935     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
03936     //
03937     cmdLine.serial().printf("\r\n      MAX5171.UPO_HIGH");
03938     g_MAX5171_device.UPO_HIGH();
03939     tinyTester.Wait_Output_Settling(); // wait_ms(100); // delay
03940     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
03941     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
03942     //
03943 #elif APPLICATION_MAX11410
03944     //
03945     // TODO: placeholder for self-test functions
03946     tinyTester.FAIL();
03947     cmdLine.serial().printf("test program not implemented yet");
03948     //
03949 #elif APPLICATION_MAX12345
03950     //
03951     // TODO: placeholder for self-test functions
03952     tinyTester.FAIL();
03953     cmdLine.serial().printf("test program not implemented yet");
03954     //
03955 #else // APPLICATION_MAX5715
03956       // TODO: placeholder for self-test functions
03957 #endif // APPLICATION_MAX5715
03958        //
03959 #if INJECT_SELFTEST_FAIL
03960     // Test of the pass/fail report mechanism
03961     tinyTester.FAIL();
03962     cmdLine.serial().printf("injecting one false failure for test reporting");
03963 #endif
03964     //
03965     // Report number of pass and number of fail test results
03966     tinyTester.Report_Summary();
03967 }
03968 
03969 
03970 //--------------------------------------------------
03971 void main_menu_status(CmdLine & cmdLine)
03972 {
03973     cmdLine.serial().printf("\r\nMain menu");
03974 #if APPLICATION_MAX5715 // main_menu_status banner
03975     cmdLine.serial().printf(" MAX5715 12-bit 4-ch SPI VOUT DAC");
03976 #elif APPLICATION_MAX11131 // main_menu_status banner
03977     cmdLine.serial().printf(" MAX11131 12-bit 3MSps 16-ch ADC");
03978 #elif APPLICATION_MAX5171 // main_menu_status banner
03979     cmdLine.serial().printf(" MAX5171 14-bit Force/Sense VOUT DAC");
03980 #elif APPLICATION_MAX11410 // main_menu_status banner
03981     cmdLine.serial().printf(" MAX11410 24-bit 1.9ksps Delta-Sigma ADC");
03982 #elif APPLICATION_MAX12345 // main_menu_status banner
03983     cmdLine.serial().printf(" MAX12345");
03984 #else
03985     //cmdLine.serial().printf(" ");
03986 #endif
03987     cmdLine.serial().printf(" %s", TARGET_NAME);
03988     if (cmdLine.nameStr())
03989     {
03990         cmdLine.serial().printf(" [%s]", cmdLine.nameStr());
03991     }
03992 #if HAS_BUTTON1_DEMO_INTERRUPT
03993     cmdLine.serial().printf(" [Button1=DemoConfig1]");
03994 #endif
03995 #if HAS_BUTTON2_DEMO_INTERRUPT
03996     cmdLine.serial().printf(" [Button2=DemoConfig2]");
03997 #endif
03998 #if HAS_BUTTON1_DEMO
03999     // print BUTTON1 status
04000     cmdLine.serial().printf("\r\n BUTTON1 = %d", button1.read());
04001 #endif
04002 #if HAS_BUTTON2_DEMO
04003     // print BUTTON1 status
04004     cmdLine.serial().printf("\r\n BUTTON2 = %d", button2.read());
04005 #endif
04006     cmdLine.serial().printf("\r\n ? -- help");
04007 }
04008 
04009 //--------------------------------------------------
04010 void main_menu_help(CmdLine & cmdLine)
04011 {
04012     // ? -- help
04013     //~ cmdLine.serial().printf("\r\nMenu:");
04014     cmdLine.serial().printf("\r\n # -- lines beginning with # are comments");
04015     cmdLine.serial().printf("\r\n . -- SelfTest");
04016     //cmdLine.serial().printf("\r\n ! -- Initial Configuration");
04017     //
04018     // % standardize diagnostic commands
04019     // %Hpin -- digital output high
04020     // %Lpin -- digital output low
04021     // %?pin -- digital input
04022     // %A %Apin -- analog input
04023     // %Ppin df=xx -- pwm output
04024     // %Wpin -- measure high pulsewidth input in usec
04025     // %wpin -- measure low pulsewidth input in usec
04026     // %I... -- I2C diagnostics
04027     // %IP -- I2C probe
04028     // %IC scl=100khz ADDR=? -- I2C configure
04029     // %IW ADDR=? cmd=? data,data,data -- write
04030     // %IR ADDR=? RD=? -- read
04031     // %I^ cmd=? -- i2c_smbus_read_word_data
04032     // %S... -- SPI diagnostics
04033     // %SC sclk=1Mhz -- SPI configure
04034     // %SW -- write (write and read)
04035     // %SR -- read (alias for %SW because SPI always write and read)
04036     // A-Z,a-z,0-9 reserved for application use
04037     //
04038 #if HAS_digitalInOuts
04039     // %Hpin -- digital output high
04040     // %Lpin -- digital output low
04041     // %?pin -- digital input
04042     cmdLine.serial().printf("\r\n %%Hn {pin:");
04043     list_digitalInOutPins(cmdLine.serial());
04044     cmdLine.serial().printf("} -- High Output");
04045     cmdLine.serial().printf("\r\n %%Ln {pin:");
04046     list_digitalInOutPins(cmdLine.serial());
04047     cmdLine.serial().printf("} -- Low Output");
04048     cmdLine.serial().printf("\r\n %%?n {pin:");
04049     list_digitalInOutPins(cmdLine.serial());
04050     cmdLine.serial().printf("} -- Input");
04051 #endif
04052 
04053 #if HAS_analogIns
04054     // Menu A) analogRead A0..7
04055     // %A %Apin -- analog input
04056     // analogRead(pinIndex) // analog input pins A0, A1, A2, A3, A4, A5; float voltage = analogRead(A0) * (5.0 / 1023.0)
04057     cmdLine.serial().printf("\r\n %%A -- analogRead");
04058 #endif
04059 
04060 #if HAS_SPI2_MAX541
04061     // TODO1: MAX541 max541(spi2_max541, spi2_max541_cs);
04062     cmdLine.serial().printf("\r\n %%D -- DAC output MAX541 (SPI2)");
04063 #endif
04064 
04065 #if HAS_I2C // SUPPORT_I2C
04066     // TODO: support I2C HAS_I2C // SUPPORT_I2C
04067     // VERIFY: I2C utility commands SUPPORT_I2C
04068     // VERIFY: report g_I2C_SCL_Hz = (F_CPU / ((TWBR * 2) + 16)) from last Wire_Sr.setClock(I2C_SCL_Hz);
04069     // %I... -- I2C diagnostics
04070     // %IP -- I2C probe
04071     // %IC scl=100khz ADDR=? -- I2C configure
04072     // %IW byte byte ... byte RD=? ADDR=0x -- write
04073     // %IR ADDR=? RD=? -- read
04074     // %I^ cmd=? -- i2c_smbus_read_word_data
04075     //g_I2C_SCL_Hz = (F_CPU / ((TWBR * 2) + 16));   // 'F_CPU' 'TWBR' not declared in this scope
04076     cmdLine.serial().printf("\r\n %%IC ADDR=0x%2.2x=(0x%2.2x>>1) SCL=%d=%1.3fkHz -- I2C config",
04077                             g_I2C_deviceAddress7, (g_I2C_deviceAddress7 << 1), g_I2C_SCL_Hz,
04078                             (g_I2C_SCL_Hz / 1000.));
04079     cmdLine.serial().printf("\r\n %%IW byte byte ... byte RD=? ADDR=0x%2.2x -- I2C write/read",
04080                             g_I2C_deviceAddress7);
04081     //
04082 #if SUPPORT_I2C
04083     // Menu ^ cmd=?) i2c_smbus_read_word_data
04084     cmdLine.serial().printf("\r\n %%I^ cmd=? -- i2c_smbus_read_word_data");
04085     // test low-level I2C i2c_smbus_read_word_data
04086 #endif // SUPPORT_I2C
04087     //cmdLine.serial().printf(" H) Hunt for attached I2C devices");
04088     cmdLine.serial().printf("\r\n %%IP -- I2C Probe for attached devices");
04089     // cmdLine.serial().printf(" s) search i2c address");
04090 #endif // SUPPORT_I2C
04091 
04092 #if HAS_SPI // SUPPORT_SPI
04093     // TODO: support SPI HAS_SPI // SUPPORT_SPI
04094     // SPI test command  S (mosiData)+
04095     // %S... -- SPI diagnostics
04096     // %SC sclk=1Mhz -- SPI configure
04097     // %SW -- write (write and read)
04098     // %SR -- read (alias for %SW because SPI always write and read)
04099     // spi.format(8,0); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
04100     // spi.format(8,1); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=1 falling edge (initial default)
04101     // spi.format(8,2); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=0 falling edge (initial default)
04102     // spi.format(8,3); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=1 rising edge (initial default)
04103     // spi.frequency(1000000); // int SCLK_Hz=1000000 = 1MHz (initial default)
04104     // mode | POL PHA
04105     // -----+--------
04106     //   0  |  0   0
04107     //   1  |  0   1
04108     //   2  |  1   0
04109     //   3  |  1   1
04110     //cmdLine.serial().printf(" S) SPI mosi,mosi,...mosi hex bytes SCLK=1000000 CPOL=0 CPHA=0");
04111     // 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=]
04112     cmdLine.serial().printf("\r\n %%SC SCLK=%ld=%1.3fMHz CPOL=%d CPHA=%d -- SPI config",
04113                             g_SPI_SCLK_Hz, (g_SPI_SCLK_Hz / 1000000.),
04114                             ((g_SPI_dataMode & SPI_MODE2) ? 1 : 0),
04115                             ((g_SPI_dataMode & SPI_MODE1) ? 1 : 0));
04116     cmdLine.serial().printf("\r\n %%SW mosi,mosi,...mosi -- SPI write hex bytes");
04117     // VERIFY: parse new SPI settings parse_strCommandArgs() SCLK=1000000 CPOL=0 CPHA=0
04118 #endif // SUPPORT_SPI
04119        //
04120        // Application-specific commands (help text) here
04121        //
04122 #if APPLICATION_ArduinoPinsMonitor
04123 # if APPLICATION_MAX5715 // main_menu_help
04124 # elif APPLICATION_MAX11131 // main_menu_help
04125 # elif APPLICATION_MAX5171 // main_menu_help
04126 # elif APPLICATION_MAX11410 // main_menu_help
04127 # elif APPLICATION_MAX12345 // main_menu_help
04128 # else
04129     cmdLine.serial().printf("\r\n A-Z,a-z,0-9 -- reserved for application use");     // ArduinoPinsMonitor
04130 # endif
04131 #endif // APPLICATION_ArduinoPinsMonitor
04132        //
04133 #if APPLICATION_MAX5715 // main_menu_help
04134     cmdLine.serial().printf("\r\n 0 ch=? code=? -- CODEn");
04135     cmdLine.serial().printf("\r\n 1 ch=? -- LOADn");
04136     cmdLine.serial().printf("\r\n 2 ch=? code=? -- CODEnLOADall");
04137     cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
04138     cmdLine.serial().printf("\r\n 40 ch=? -- POWERn_Normal");
04139     cmdLine.serial().printf("\r\n 41 ch=? -- POWERn_PD1k");
04140     cmdLine.serial().printf("\r\n 42 ch=? -- POWERn_PD100k");
04141     cmdLine.serial().printf("\r\n 43 ch=? -- POWERn_PDHiZ");
04142     cmdLine.serial().printf("\r\n 50 -- SW_CLEAR");
04143     cmdLine.serial().printf("\r\n 51 -- SW_RESET");
04144     cmdLine.serial().printf("\r\n 60 ch=? -- CONFIGn_LATCHED");
04145     cmdLine.serial().printf("\r\n 61 ch=? -- CONFIGn_TRANSPARENT");
04146     cmdLine.serial().printf("\r\n 68 -- CONFIGall_LATCHED");
04147     cmdLine.serial().printf("\r\n 69 -- CONFIGall_TRANSPARENT");
04148     cmdLine.serial().printf("\r\n 70 -- REF_EXT");
04149     cmdLine.serial().printf("\r\n 71 -- REF_2V500");
04150     cmdLine.serial().printf("\r\n 72 -- REF_2V048");
04151     cmdLine.serial().printf("\r\n 73 -- REF_4V096");
04152     cmdLine.serial().printf("\r\n 74 -- REF_AlwaysOn_EXT");
04153     cmdLine.serial().printf("\r\n 75 -- REF_AlwaysOn_2V500");
04154     cmdLine.serial().printf("\r\n 76 -- REF_AlwaysOn_2V048");
04155     cmdLine.serial().printf("\r\n 77 -- REF_AlwaysOn_4V096");
04156     cmdLine.serial().printf("\r\n 80 code=? -- CODEall");
04157     cmdLine.serial().printf("\r\n 81 -- LOADall");
04158     cmdLine.serial().printf("\r\n 82 code=? -- CODEallLOADall");
04159     //cmdLine.serial().printf("\r\n 83 code=? -- CODEallLOADall");
04160     //
04161     // Menu @ -- print device configuration
04162     cmdLine.serial().printf("\r\n @ -- print MAX5715 configuration");
04163     //
04164     // MAX5717 menu function to drive MAX5717_LDACb_Pin LDAC#
04165     // Note: '~' is not recommended for menu commands, interferes with ssh
04166     cmdLine.serial().printf("\r\n L -- LDAC# pulse LH high LL low");
04167     // MAX5717 menu function to drive MAX5717_CLRb_Pin CLR#
04168     cmdLine.serial().printf("\r\n C -- CLR# pulse CH high CL low");
04169 #endif // APPLICATION_MAX5715
04170        //
04171 #if APPLICATION_MAX11131 // main_menu_help
04172     // VERIFY: console menu command 0 int16_t MAX11131_ScanRead(void);
04173     cmdLine.serial().printf("\r\n 0 n=?                                  -- MAX11131_ScanRead");
04174     // VERIFY: console menu command 1 MAX11131_ScanManual(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
04175     cmdLine.serial().printf("\r\n 1 ch=? pm=? id=?                       -- MAX11131_ScanManual");
04176     // VERIFY: console menu command 2 int MAX11131_ScanRepeat(uint8_t channelNumber_0_15, uint8_t average_0_4_8_16_32, uint8_t nscan_4_8_12_16, uint8_t PowerManagement_0_2, uint8_t swcnv_0_1);
04177     cmdLine.serial().printf("\r\n 2 ch=? av=? n=? pm=? swcnv=?           -- MAX11131_ScanRepeat");
04178     // VERIFY: console menu command 3 MAX11131_ScanStandardInternalClock(int channelNumber_0_15, int average_0_4_8_16_32, int PowerManagement_0_2, int swcnv_0_1);
04179     cmdLine.serial().printf("\r\n 3 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanStandardIntClock");
04180     // VERIFY: console menu command 4 MAX11131_ScanStandardExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
04181     cmdLine.serial().printf("\r\n 4 ch=? pm=? id=?                       -- MAX11131_ScanStandardExtClock");
04182     // VERIFY: console menu command 5 MAX11131_ScanUpperInternalClock(int channelNumber_0_15, int average_0_4_8_16_32, int PowerManagement_0_2, int swcnv_0_1);
04183     cmdLine.serial().printf("\r\n 5 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanUpperIntClock");
04184     // VERIFY: console menu command 6 MAX11131_ScanUpperExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
04185     cmdLine.serial().printf("\r\n 6 ch=? pm=? id=?                       -- MAX11131_ScanUpperExtClock");
04186     // VERIFY: console menu command 7 MAX11131_ScanCustomInternalClock(int16_t enabledChannelsMask, int average_0_4_8_16_32, int PowerManagement_0_2, int swcnv_0_1);
04187     cmdLine.serial().printf("\r\n 7 enableMask=0xffff av=? pm=? swcnv=?  -- MAX11131_ScanCustomIntClock");
04188     // VERIFY: console menu command 8 MAX11131_ScanCustomExternalClock(int16_t enabledChannelsMask, int PowerManagement_0_2, int chan_id_0_1);
04189     cmdLine.serial().printf("\r\n 8 enableMask=0xffff pm=0 id=1          -- MAX11131_ScanCustomExtClock");
04190     // VERIFY: console menu command 9 MAX11131_ScanSampleSetExternalClock(uint8_t enabledChannelsPatternLength_1_256, int16_t enabledChannelsPattern[], int PowerManagement_0_2, int chan_id_0_1);
04191     cmdLine.serial().printf("\r\n 9 channelsPattern... pm=? id=? | len=? -- MAX11131_ScanSampleSetExtClock");
04192     cmdLine.serial().printf("\r\n @                                      -- print MAX11131 configuration");
04193     cmdLine.serial().printf("\r\n ISc) IUc) IBc) IRc) reconfigure channel single-ended/unipolar/bipolar/range");
04194     // cmdLine.serial().printf("\r\n & -- MAX11131_Example_ScanManual");
04195     // Note: '~' is not recommended for menu commands, interferes with ssh
04196 #endif // APPLICATION_MAX11131
04197        //
04198 #if APPLICATION_MAX5171 // main_menu_help
04199     // TODO1: MAX5171 main_menu_help
04200     cmdLine.serial().printf("\r\n 0 code=? -- CODE");
04201     cmdLine.serial().printf("\r\n 4 code=? -- CODE_LOAD");
04202     cmdLine.serial().printf("\r\n 8 -- LOAD");
04203     cmdLine.serial().printf("\r\n c -- NOP");
04204     cmdLine.serial().printf("\r\n d -- SHUTDOWN");
04205     cmdLine.serial().printf("\r\n e0 -- UPO_LOW");
04206     cmdLine.serial().printf("\r\n e8 -- UPO_HIGH");
04207     cmdLine.serial().printf("\r\n f0 -- MODE1_DOUT_SCLK_RISING_EDGE");
04208     cmdLine.serial().printf("\r\n f8 -- MODE0_DOUT_SCLK_FALLING_EDGE");
04209     // Note: '~' is not recommended for menu commands, interferes with ssh
04210 #endif // APPLICATION_MAX5171
04211        //
04212 #if APPLICATION_MAX11410 // main_menu_help
04213     // TODO1: MAX11410 main_menu_help
04214     cmdLine.serial().printf("\r\n w reg=? data=? -- write register");
04215     cmdLine.serial().printf("\r\n r reg=? -- read register");
04216     cmdLine.serial().printf("\r\n TC -- thermocouple config");
04217     cmdLine.serial().printf("\r\n T -- RTD measurement");
04218     cmdLine.serial().printf("\r\n RC -- thermocouple config");
04219     cmdLine.serial().printf("\r\n R -- RTD measurement");
04220     // Note: '~' is not recommended for menu commands, interferes with ssh
04221 #endif // APPLICATION_MAX11410
04222        //
04223 #if APPLICATION_MAX12345 // main_menu_help
04224     cmdLine.serial().printf("\r\n 0 -- something");
04225     cmdLine.serial().printf("\r\n 1 -- something");
04226     cmdLine.serial().printf("\r\n 2 -- something");
04227     cmdLine.serial().printf("\r\n A -- something");
04228     cmdLine.serial().printf("\r\n B -- something");
04229     cmdLine.serial().printf("\r\n C -- something");
04230     // Note: '~' is not recommended for menu commands, interferes with ssh
04231 #endif // APPLICATION_MAX12345
04232        //
04233 }
04234 
04235 //--------------------------------------------------
04236 // diagnostic commands submenu
04237 // invoked by main_menu_onEOLcommandParser case '%'
04238 void pinsMonitor_submenu_onEOLcommandParser(CmdLine & cmdLine)
04239 {
04240     // % diagnostic commands submenu
04241     // %Hpin -- digital output high
04242     // %Lpin -- digital output low
04243     // %?pin -- digital input
04244     // %A %Apin -- analog input
04245     // %Ppin df=xx -- pwm output
04246     // %Wpin -- measure high pulsewidth input in usec
04247     // %wpin -- measure low pulsewidth input in usec
04248     // %I... -- I2C diagnostics
04249     // %IP -- I2C probe
04250     // %IC scl=100khz ADDR=? -- I2C configure
04251     // %IW byte byte ... byte RD=? ADDR=0x -- write
04252     // %IR ADDR=? RD=? -- read
04253     // %I^ cmd=? -- i2c_smbus_read_word_data
04254     // %S... -- SPI diagnostics
04255     // %SC sclk=1Mhz -- SPI configure
04256     // %SW -- write (write and read)
04257     // %SR -- read (alias for %SW because SPI always write and read)
04258     // A-Z,a-z,0-9 reserved for application use
04259     //
04260     // get pinIndex from cmdLine[2]
04261     //int pinIndex = cmdLine[2];
04262     // *** warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
04263     //int pinIndex = strtoul((char *)((void *)(cmdLine.str()) + 2), NULL, 10); // strtol(str, NULL, 10): get decimal value
04264     //                                                        ^
04265     char strPinIndex[3];
04266     strPinIndex[0] = cmdLine[2];
04267     strPinIndex[1] = cmdLine[3];
04268     strPinIndex[2] = '\0';
04269     int pinIndex = strtoul(strPinIndex, NULL, 10);         // strtol(str, NULL, 10): get decimal value
04270     //cmdLine.serial().printf(" pinIndex=%d ", pinIndex);
04271     //
04272     // get next character
04273     switch (cmdLine[1])
04274     {
04275 #if HAS_digitalInOuts
04276         case 'H': case 'h':
04277         {
04278             // %Hpin -- digital output high
04279 #if ARDUINO_STYLE
04280             pinMode(pinIndex, OUTPUT);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04281             digitalWrite(pinIndex, HIGH);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04282 #else
04283             DigitalInOut& digitalInOutPin = find_digitalInOutPin(pinIndex);
04284             digitalInOutPin.output();
04285             digitalInOutPin.write(1);
04286 #endif
04287             cmdLine.serial().printf(" digitalInOutPin %d Output High ", pinIndex);
04288         }
04289         break;
04290         case 'L': case 'l':
04291         {
04292             // %Lpin -- digital output low
04293 #if ARDUINO_STYLE
04294             pinMode(pinIndex, OUTPUT);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04295             digitalWrite(pinIndex, LOW);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04296 #else
04297             DigitalInOut& digitalInOutPin = find_digitalInOutPin(pinIndex);
04298             digitalInOutPin.output();
04299             digitalInOutPin.write(0);
04300 #endif
04301             cmdLine.serial().printf(" digitalInOutPin %d Output Low ", pinIndex);
04302         }
04303         break;
04304         case '?':
04305         {
04306             // %?pin -- digital input
04307 #if ARDUINO_STYLE
04308             pinMode(pinIndex, INPUT);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04309 #else
04310             DigitalInOut& digitalInOutPin = find_digitalInOutPin(pinIndex);
04311             digitalInOutPin.input();
04312 #endif
04313             serial.printf(" digitalInOutPin %d Input ", pinIndex);
04314 #if ARDUINO_STYLE
04315             int value = digitalRead(pinIndex);
04316 #else
04317             int value = digitalInOutPin.read();
04318 #endif
04319             cmdLine.serial().printf("%d ", value);
04320         }
04321         break;
04322 #endif
04323         //
04324 #if HAS_analogIns
04325         case 'A': case 'a':
04326         {
04327             // %A %Apin -- analog input
04328 #if analogIn4_IS_HIGH_RANGE_OF_analogIn0
04329             // Platform board uses AIN4,AIN5,.. as high range of AIN0,AIN1,..
04330             for (int pinIndex = 0; pinIndex < 2; pinIndex++)
04331             {
04332                 int cPinIndex = '0' + pinIndex;
04333                 AnalogIn& analogInPin = find_analogInPin(cPinIndex);
04334                 float adc_full_scale_voltage = analogInPin_fullScaleVoltage[pinIndex];
04335                 float normValue_0_1 = analogInPin.read();
04336                 //
04337                 int pinIndexH = pinIndex + 4;
04338                 int cPinIndexH = '0' + pinIndexH;
04339                 AnalogIn& analogInPinH = find_analogInPin(cPinIndexH);
04340                 float adc_full_scale_voltageH = analogInPin_fullScaleVoltage[pinIndexH];
04341                 float normValueH_0_1 = analogInPinH.read();
04342                 //
04343                 cmdLine.serial().printf("AIN%c = %7.3f%% = %1.3fV  AIN%c = %7.3f%% = %1.3fV  \r\n",
04344                                         cPinIndex,
04345                                         normValue_0_1 * 100.0,
04346                                         normValue_0_1 * adc_full_scale_voltage,
04347                                         cPinIndexH,
04348                                         normValueH_0_1 * 100.0,
04349                                         normValueH_0_1 * adc_full_scale_voltageH
04350                                         );
04351             }
04352             for (int pinIndex = 2; pinIndex < 4; pinIndex++)
04353             {
04354                 int cPinIndex = '0' + pinIndex;
04355                 AnalogIn& analogInPin = find_analogInPin(cPinIndex);
04356                 float adc_full_scale_voltage = analogInPin_fullScaleVoltage[pinIndex];
04357                 float normValue_0_1 = analogInPin.read();
04358                 //
04359                 cmdLine.serial().printf("AIN%c = %7.3f%% = %1.3fV\r\n",
04360                                         cPinIndex,
04361                                         normValue_0_1 * 100.0,
04362                                         normValue_0_1 * adc_full_scale_voltage
04363                                         );
04364             }
04365 #else // analogIn4_IS_HIGH_RANGE_OF_analogIn0
04366             // Platform board uses simple analog inputs
04367             // assume standard Arduino analog inputs A0-A5
04368             for (int pinIndex = 0; pinIndex < 6; pinIndex++)
04369             {
04370                 int cPinIndex = '0' + pinIndex;
04371                 AnalogIn& analogInPin = find_analogInPin(cPinIndex);
04372                 float adc_full_scale_voltage = analogInPin_fullScaleVoltage[pinIndex];
04373                 float normValue_0_1 = analogInPin.read();
04374                 //
04375                 cmdLine.serial().printf("AIN%c = %7.3f%% = %1.3fV\r\n",
04376                                         cPinIndex,
04377                                         normValue_0_1 * 100.0,
04378                                         normValue_0_1 * adc_full_scale_voltage
04379                                         );
04380             }
04381 #endif // analogIn4_IS_HIGH_RANGE_OF_analogIn0
04382         }
04383         break;
04384 #endif
04385         //
04386 #if HAS_SPI2_MAX541
04387         case 'D': case 'd':
04388         {
04389             // %D -- DAC output MAX541 (SPI2) -- need cmdLine.parse_float(voltageV)
04390             // MAX541 max541(spi2_max541, spi2_max541_cs);
04391             float voltageV = max541.Get_Voltage();
04392             // if (cmdLine[2] == '+') {
04393             //     // %D+
04394             //     voltageV = voltageV * 1.25f;
04395             //     if (voltageV >= max541.VRef) voltageV = max541.VRef;
04396             //     SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04397             // }
04398             // else if (cmdLine[2] == '-') {
04399             //     // %D-
04400             //     voltageV = voltageV * 0.75f;
04401             //     if (voltageV < 0.1f) voltageV = 0.1f;
04402             //     SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04403             // }
04404             if (cmdLine.parse_float("V", voltageV))
04405             {
04406                 // %D V=1.234 -- set voltage
04407                 max541.Set_Voltage(voltageV);
04408             }
04409             else if (cmdLine.parse_float("TEST", voltageV))
04410             {
04411                 // %D TEST=1.234 -- set voltage and compare with AIN0
04412                 SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04413             }
04414             else if (cmdLine.parse_float("CAL", voltageV))
04415             {
04416                 // %D CAL=1.234 -- calibrate VRef and compare with AIN0
04417 
04418                 max541.Set_Code(0x8000); // we don't know the fullscale voltage yet, so set code to midscale
04419                 double max541_midscale_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
04420                 const int average_count = 100;
04421                 const double average_K = 0.25;
04422                 for (int count = 0; count < average_count; count++) {
04423                     double measurement_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
04424                     max541_midscale_V = ((1 - average_K) * max541_midscale_V) + (average_K * measurement_V);
04425                 }
04426                 max541.VRef = 2.0 * max541_midscale_V;
04427                 cmdLine.serial().printf(
04428                     "\r\n      MAX541 midscale = %1.3fV, so fullscale = %1.3fV",
04429                     max541_midscale_V, max541.VRef);
04430                 // Detect whether MAX541 is really connected to MAX32625MBED.AIN0/AIN4
04431                 voltageV = 1.0f;
04432                 SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04433             }
04434             else {
04435                 // %D -- print MAX541 DAC status
04436                 cmdLine.serial().printf("MAX541 code=0x%4.4x = %1.3fV  VRef=%1.3fV\r\n",
04437                                         max541.Get_Code(), max541.Get_Voltage(), max541.VRef);
04438             }
04439         }
04440         break;
04441 #endif
04442 
04443         //
04444 #if HAS_I2C // SUPPORT_I2C
04445         case 'I': case 'i':
04446             // %I... -- I2C diagnostics
04447             // %IP -- I2C probe
04448             // %IC scl=100khz ADDR=? -- I2C configure
04449             // %IW byte byte ... byte RD=? ADDR=0x -- write
04450             // %IR ADDR=? RD=? -- read
04451             // %I^ cmd=? -- i2c_smbus_read_word_data
04452             // get next character
04453             // TODO: parse cmdLine arg (ADDR=\d+)? --> g_I2C_deviceAddress7
04454             cmdLine.parse_byte_hex("ADDR", g_I2C_deviceAddress7);
04455             // TODO: parse cmdLine arg (RD=\d)? --> g_I2C_read_count
04456             g_I2C_read_count = 0;         // read count must be reset every command
04457             cmdLine.parse_byte_dec("RD", g_I2C_read_count);
04458             // TODO: parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
04459             cmdLine.parse_byte_hex("CMD", g_I2C_command_regAddress);
04460             switch (cmdLine[2])
04461             {
04462                 case 'P': case 'p':
04463                 {
04464                     // %IP -- I2C probe
04465                     HuntAttachedI2CDevices(cmdLine, 0x03, 0x77);
04466                 }
04467                 break;
04468                 case 'C': case 'c':
04469                 {
04470                     bool isUpdatedI2CConfig = false;
04471                     // %IC scl=100khz ADDR=? -- I2C configure
04472                     // parse cmdLine arg (SCL=\d+(kHZ|MHZ)?)? --> g_I2C_SCL_Hz
04473                     if (cmdLine.parse_frequency_Hz("SCL", g_I2C_SCL_Hz))
04474                     {
04475                         isUpdatedI2CConfig = true;
04476                         // TODO1: validate g_I2C_SCL_Hz against system clock frequency F_CPU
04477                         if (g_I2C_SCL_Hz > limit_max_I2C_SCL_Hz)
04478                         {
04479                             g_I2C_SCL_Hz = limit_max_I2C_SCL_Hz;
04480                         }
04481                         if (g_I2C_SCL_Hz < limit_min_I2C_SCL_Hz)
04482                         {
04483                             g_I2C_SCL_Hz = limit_min_I2C_SCL_Hz;
04484                         }
04485                     }
04486                     if (isUpdatedI2CConfig)
04487                     {
04488                         // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04489                         I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04490                         i2cMaster.frequency(g_I2C_SCL_Hz);
04491                         i2cMaster.start();
04492                         i2cMaster.stop();
04493                         i2cMaster.frequency(g_I2C_SCL_Hz);
04494                         cmdLine.serial().printf(
04495                             "\r\n %%IC ADDR=0x%2.2x=(0x%2.2x>>1) SCL=%d=%1.3fkHz -- I2C config",
04496                             g_I2C_deviceAddress7, (g_I2C_deviceAddress7 << 1), g_I2C_SCL_Hz,
04497                             (g_I2C_SCL_Hz / 1000.));
04498                         i2cMaster.start();
04499                         i2cMaster.stop();
04500                     }
04501                 }
04502                 break;
04503                 case 'W': case 'w':
04504                 {
04505                     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04506                     I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04507                     i2cMaster.frequency(g_I2C_SCL_Hz);
04508                     // %IW byte byte ... byte RD=? ADDR=0x -- write
04509                     // parse cmdLine byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
04510                     #define MAX_I2C_BYTE_COUNT 32
04511                     size_t byteCount = byteCount;
04512                     static char mosiData[MAX_I2C_BYTE_COUNT];
04513                     static char misoData[MAX_I2C_BYTE_COUNT];
04514                     if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData,
04515                                                              MAX_I2C_BYTE_COUNT))
04516                     {
04517                         // hex dump mosiData[0..byteCount-1]
04518                         cmdLine.serial().printf(
04519                             "\r\nADDR=0x%2.2x=(0x%2.2x>>1) byteCount:%d RD=%d\r\nI2C MOSI->",
04520                             g_I2C_deviceAddress7,
04521                             (g_I2C_deviceAddress7 << 1), byteCount, g_I2C_read_count);
04522                         for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
04523                         {
04524                             cmdLine.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
04525                         }
04526                         //
04527                         // TODO: i2c transfer
04528                         //const int addr7bit = 0x48;      // 7 bit I2C address
04529                         //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
04530                         // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
04531                         // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
04532                         // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
04533                         // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
04534                         // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
04535                         // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
04536                         // /* int */    i2cMaster.transfer (int addr8bit, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false) // Start nonblocking I2C transfer. More...
04537                         // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
04538                         const int addr8bit = g_I2C_deviceAddress7 << 1;             // 8bit I2C address, 0x90
04539                         unsigned int misoLength = 0;
04540                         bool repeated = (g_I2C_read_count > 0);
04541                         //
04542                         int writeStatus = i2cMaster.write (addr8bit, mosiData, byteCount, repeated);
04543                         switch (writeStatus)
04544                         {
04545                             case 0: cmdLine.serial().printf(" ack "); break;
04546                             case 1: cmdLine.serial().printf(" nack "); break;
04547                             default: cmdLine.serial().printf(" {writeStatus 0x%2.2X} ",
04548                                                              writeStatus);
04549                         }
04550                         if (repeated)
04551                         {
04552                             int readStatus =
04553                                 i2cMaster.read (addr8bit, misoData, g_I2C_read_count, false);
04554                             switch (readStatus)
04555                             {
04556                                 case 1: cmdLine.serial().printf(" nack "); break;
04557                                 case 0: cmdLine.serial().printf(" ack "); break;
04558                                 default: cmdLine.serial().printf(" {readStatus 0x%2.2X} ",
04559                                                                  readStatus);
04560                             }
04561                         }
04562                         //
04563                         if (misoLength > 0)
04564                         {
04565                             // hex dump misoData[0..byteCount-1]
04566                             cmdLine.serial().printf("  MISO<-");
04567                             for (unsigned int byteIndex = 0; byteIndex < g_I2C_read_count;
04568                                  byteIndex++)
04569                             {
04570                                 cmdLine.serial().printf(" 0x%2.2X", misoData[byteIndex]);
04571                             }
04572                         }
04573                         cmdLine.serial().printf(" ");
04574                     }
04575                 }
04576                 break;
04577                 case 'R': case 'r':
04578                 {
04579                     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04580                     I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04581                     i2cMaster.frequency(g_I2C_SCL_Hz);
04582                     // %IR ADDR=? RD=? -- read
04583                     // TODO: i2c transfer
04584                     //const int addr7bit = 0x48;      // 7 bit I2C address
04585                     //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
04586                     // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
04587                     // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
04588                     // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
04589                     // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
04590                     // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
04591                     // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
04592                     // /* int */    i2cMaster.transfer (int addr8bit, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false) // Start nonblocking I2C transfer. More...
04593                     // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
04594                 }
04595                 break;
04596                 case '^':
04597                 {
04598                     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04599                     I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04600                     i2cMaster.frequency(g_I2C_SCL_Hz);
04601                     // %I^ cmd=? -- i2c_smbus_read_word_data
04602                     // TODO: i2c transfer
04603                     //const int addr7bit = 0x48;      // 7 bit I2C address
04604                     //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
04605                     // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
04606                     // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
04607                     // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
04608                     // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
04609                     // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
04610                     // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
04611                     // /* int */    i2cMaster.transfer (int addr8bit, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false) // Start nonblocking I2C transfer. More...
04612                     // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
04613                 }
04614                 break;
04615             }         // switch(cmdLine[2])
04616             break;
04617 #endif
04618         //
04619 #if HAS_SPI // SUPPORT_SPI
04620         case 'S': case 's':
04621         {
04622             // %S... -- SPI diagnostics
04623             // %SC sclk=1Mhz -- SPI configure
04624             // %SW -- write (write and read)
04625             // %SR -- read (alias for %SW because SPI always write and read)
04626             //
04627             // Process arguments SCLK=\d+(kHZ|MHZ) CPOL=\d CPHA=\d
04628             bool isUpdatedSPIConfig = false;
04629             // parse cmdLine arg (CPOL=\d)? --> g_SPI_dataMode | SPI_MODE2
04630             // parse cmdLine arg (CPHA=\d)? --> g_SPI_dataMode | SPI_MODE1
04631             if (cmdLine.parse_flag("CPOL", g_SPI_dataMode, SPI_MODE2))
04632             {
04633                 isUpdatedSPIConfig = true;
04634             }
04635             if (cmdLine.parse_flag("CPHA", g_SPI_dataMode, SPI_MODE1))
04636             {
04637                 isUpdatedSPIConfig = true;
04638             }
04639             if (cmdLine.parse_flag("CS", g_SPI_cs_state, 1))
04640             {
04641                 isUpdatedSPIConfig = true;
04642             }
04643             // parse cmdLine arg (SCLK=\d+(kHZ|MHZ)?)? --> g_SPI_SCLK_Hz
04644             if (cmdLine.parse_frequency_Hz("SCLK", g_SPI_SCLK_Hz))
04645             {
04646                 isUpdatedSPIConfig = true;
04647                 // TODO1: validate g_SPI_SCLK_Hz against system clock frequency F_CPU
04648                 if (g_SPI_SCLK_Hz > limit_max_SPI_SCLK_Hz)
04649                 {
04650                     g_SPI_SCLK_Hz = limit_max_SPI_SCLK_Hz;
04651                 }
04652                 if (g_SPI_SCLK_Hz < limit_min_SPI_SCLK_Hz)
04653                 {
04654                     g_SPI_SCLK_Hz = limit_min_SPI_SCLK_Hz;
04655                 }
04656             }
04657             // Update SPI configuration
04658             if (isUpdatedSPIConfig)
04659             {
04660                 // %SC sclk=1Mhz -- SPI configure
04661                 spi_cs = g_SPI_cs_state;
04662                 spi.format(8,g_SPI_dataMode);             // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0
04663 #if APPLICATION_MAX5715
04664                 g_MAX5715_device.spi_frequency(g_SPI_SCLK_Hz);
04665 #elif APPLICATION_MAX11131
04666                 g_MAX11131_device.spi_frequency(g_SPI_SCLK_Hz);
04667 #elif APPLICATION_MAX5171
04668                 g_MAX5171_device.spi_frequency(g_SPI_SCLK_Hz);
04669 #elif APPLICATION_MAX11410
04670                 g_MAX11410_device.spi_frequency(g_SPI_SCLK_Hz);
04671 #elif APPLICATION_MAX12345
04672                 g_MAX12345_device.spi_frequency(g_SPI_SCLK_Hz);
04673 #else
04674                 spi.frequency(g_SPI_SCLK_Hz);             // int SCLK_Hz=1000000 = 1MHz (initial default)
04675 #endif
04676                 //
04677                 double ideal_divisor = ((double)SystemCoreClock) / g_SPI_SCLK_Hz;
04678                 int actual_divisor = (int)(ideal_divisor + 0.0);             // frequency divisor truncate
04679                 double actual_SCLK_Hz = SystemCoreClock / actual_divisor;
04680                 //
04681                 // fixed: mbed-os-5.11: [Warning] format '%d' expects argument of type 'int', but argument 6 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
04682                 cmdLine.serial().printf(
04683                     "\r\n %%SC CPOL=%d CPHA=%d CS=%d SCLK=%ld=%1.3fMHz (%1.1fMHz/%1.2f = actual %1.3fMHz) -- SPI config",
04684                     ((g_SPI_dataMode & SPI_MODE2) ? 1 : 0),
04685                     ((g_SPI_dataMode & SPI_MODE1) ? 1 : 0),
04686                     g_SPI_cs_state,
04687                     g_SPI_SCLK_Hz,
04688                     (g_SPI_SCLK_Hz / 1000000.),
04689                     ((double)(SystemCoreClock / 1000000.)),
04690                     ideal_divisor,
04691                     (actual_SCLK_Hz / 1000000.)
04692                     );
04693             }
04694             // get next character
04695             switch (cmdLine[2])
04696             {
04697                 case 'C': case 's':
04698                     // %SC sclk=1Mhz -- SPI configure
04699                     break;
04700                 case 'W': case 'R': case 'w': case 'r':
04701                 {
04702                     // %SW -- write (write and read)
04703                     // %SR -- read (alias for %SW because SPI always write and read)
04704                     // parse cmdLine byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
04705                     #define MAX_SPI_BYTE_COUNT 32
04706                     size_t byteCount = byteCount;
04707                     static char mosiData[MAX_SPI_BYTE_COUNT];
04708                     static char misoData[MAX_SPI_BYTE_COUNT];
04709                     if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData,
04710                                                              MAX_SPI_BYTE_COUNT))
04711                     {
04712                         // hex dump mosiData[0..byteCount-1]
04713                         cmdLine.serial().printf("\r\nSPI");
04714                         if (byteCount > 7) {
04715                             cmdLine.serial().printf(" byteCount:%d", byteCount);
04716                         }
04717                         cmdLine.serial().printf(" MOSI->");
04718                         for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
04719                         {
04720                             cmdLine.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
04721                         }
04722                         spi_cs = 0;
04723                         unsigned int numBytesTransferred =
04724                             spi.write(mosiData, byteCount, misoData, byteCount);
04725                         spi_cs = 1;
04726                         // hex dump misoData[0..byteCount-1]
04727                         cmdLine.serial().printf("  MISO<-");
04728                         for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred;
04729                              byteIndex++)
04730                         {
04731                             cmdLine.serial().printf(" 0x%2.2X", misoData[byteIndex]);
04732                         }
04733                         cmdLine.serial().printf(" ");
04734                     }
04735                 }
04736                 break;
04737             }             // switch(cmdLine[2])
04738         }             // case 'S': // %S... -- SPI diagnostics
04739         break;
04740 #endif
04741         //
04742         // A-Z,a-z,0-9 reserved for application use
04743     }         // switch(cmdLine[1])
04744 } // end void pinsMonitor_submenu_onEOLcommandParser(CmdLine & cmdLine)
04745 
04746 
04747 //--------------------------------------------------
04748 #if 0 // APPLICATION_MAX5715 // MAX5715_menu_onEOLcommandParser moved to Test_Menu_MAX5715.cpp
04749 bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine)
04750 {
04751     switch (cmdLine[0])
04752     {
04753         case '0':
04754         {
04755             // recommended for hex command codes 00..0F
04756             // TODO: cmdLine.serial().printf("\r\n 0 ch=? code=? -- CODEn");
04757             // Menu 0 ch=? code=?) CODEn
04758             // MAX5715_CODEn(uint8_t channel, uint16_t dacCodeLsbs);
04759             // VERIFY: parse strCommandArgs for additional arguments including key=value pairs
04760             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04761             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04762             if (cmdLine.parse_uint16_dec("ch", ch))
04763             {
04764             }
04765             uint16_t code = g_MAX5715_device.CODE[ch];
04766             if (cmdLine.parse_uint16_dec("code", code))
04767             {
04768             }
04769             cmdLine.serial().printf("CODEn ch=%d code=%d", ch, code);
04770             g_MAX5715_device.CODEn(ch, code);
04771             return true; // command was handled by MAX5715
04772         }
04773         break;
04774         case '1':
04775         {
04776             // recommended for hex command codes 10..1F
04777             // TODO: cmdLine.serial().printf("\r\n 1 ch=? -- LOADn");
04778             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04779             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04780             if (cmdLine.parse_uint16_dec("ch", ch))
04781             {
04782             }
04783             cmdLine.serial().printf("LOADn ch=%d", ch);
04784             g_MAX5715_device.LOADn(ch);
04785             return true; // command was handled by MAX5715
04786         }
04787         break;
04788         case '2':
04789         {
04790             // recommended for hex command codes 20..2F
04791             // TODO: cmdLine.serial().printf("\r\n 2 ch=? code=? -- CODEnLOADall");
04792             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04793             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04794             if (cmdLine.parse_uint16_dec("ch", ch))
04795             {
04796             }
04797             uint16_t code = g_MAX5715_device.CODE[ch];
04798             if (cmdLine.parse_uint16_dec("code", code))
04799             {
04800             }
04801             cmdLine.serial().printf("CODEnLOADall ch=%d code=%d", ch, code);
04802             g_MAX5715_device.CODEnLOADall(ch, code);
04803             return true; // command was handled by MAX5715
04804         }
04805         break;
04806         case '3':
04807         {
04808             // recommended for hex command codes 30..3F
04809             // TODO: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
04810             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04811             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04812             uint16_t code;
04813             if (cmdLine.parse_uint16_dec("ch", ch))
04814             {
04815             }
04816             if (cmdLine.parse_uint16_dec("code", code))
04817             {
04818             }
04819             cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
04820             g_MAX5715_device.CODEnLOADn(ch, code);
04821             return true; // command was handled by MAX5715
04822         }
04823         break;
04824         case '4':
04825         {
04826             // recommended for hex command codes 40..4F
04827             switch (cmdLine[1])
04828             {
04829                 case '0':
04830                 {
04831                     // cmdLine.serial().printf("\r\n 40 ch=? -- POWERn_Normal");
04832                     cmdLine.serial().printf(
04833                         "channel_dcba=%d, POWERn_Normal)",
04834                         g_MAX5715_device.channels_bitmask_DCBA);
04835                     g_MAX5715_device.POWER(g_MAX5715_device.
04836                                            channels_bitmask_DCBA,
04837                                            MAX5715::POWERn_Normal);
04838                     return true; // command was handled by MAX5715
04839                 }
04840                 break;
04841                 case '1':
04842                 {
04843                     // cmdLine.serial().printf("\r\n 41 ch=? -- POWERn_PD1k");
04844                     cmdLine.serial().printf(
04845                         "channel_dcba=%d, POWERn_PD1k)",
04846                         g_MAX5715_device.channels_bitmask_DCBA);
04847                     g_MAX5715_device.POWER(g_MAX5715_device.
04848                                            channels_bitmask_DCBA,
04849                                            MAX5715::POWERn_PD1k);
04850                     return true; // command was handled by MAX5715
04851                 }
04852                 break;
04853                 case '2':
04854                 {
04855                     // cmdLine.serial().printf("\r\n 42 ch=? -- POWERn_PD100k");
04856                     cmdLine.serial().printf(
04857                         "channel_dcba=%d, POWERn_PD100k)",
04858                         g_MAX5715_device.channels_bitmask_DCBA);
04859                     g_MAX5715_device.POWER(g_MAX5715_device.
04860                                            channels_bitmask_DCBA,
04861                                            MAX5715::POWERn_PD100k);
04862                     return true; // command was handled by MAX5715
04863                 }
04864                 break;
04865                 case '3':
04866                 {
04867                     // cmdLine.serial().printf("\r\n 43 ch=? -- POWERn_PDHiZ");
04868                     cmdLine.serial().printf(
04869                         "channel_dcba=%d, POWERn_PDHiZ)",
04870                         g_MAX5715_device.channels_bitmask_DCBA);
04871                     g_MAX5715_device.POWER(g_MAX5715_device.
04872                                            channels_bitmask_DCBA,
04873                                            MAX5715::POWERn_PDHiZ);
04874                     return true; // command was handled by MAX5715
04875                 }
04876                 break;
04877             }
04878             break;
04879         }
04880         break;
04881         case '5':
04882         {
04883             // recommended for hex command codes 50..5F
04884             switch (cmdLine[1])
04885             {
04886                 case '0':
04887                 {
04888                     // cmdLine.serial().printf("\r\n 50 -- SW_CLEAR");
04889                     cmdLine.serial().printf("SW_CLEAR");
04890                     g_MAX5715_device.SW_CLEAR();
04891                     return true; // command was handled by MAX5715
04892                 }
04893                 break;
04894                 case '1':
04895                 {
04896                     // cmdLine.serial().printf("\r\n 51 -- SW_RESET");
04897                     cmdLine.serial().printf("SW_RESET");
04898                     g_MAX5715_device.SW_RESET();
04899                     return true; // command was handled by MAX5715
04900                 }
04901                 break;
04902             }
04903         }
04904         break;
04905         case '6':
04906         {
04907             // recommended for hex command codes 60..6F
04908             switch (cmdLine[1])
04909             {
04910                 case '0':
04911                 {
04912                     // cmdLine.serial().printf("\r\n 60 ch=? -- CONFIGn_LATCHED");
04913                     cmdLine.serial().printf(
04914                         "MAX5715_CONFIGn_LATCHED(channel_dcba=%d)",
04915                         g_MAX5715_device.
04916                         channels_bitmask_DCBA);
04917                     g_MAX5715_device.CONFIGn_LATCHED(g_MAX5715_device.
04918                                                      channels_bitmask_DCBA);
04919                     return true; // command was handled by MAX5715
04920                 }
04921                 break;
04922                 case '1':
04923                 {
04924                     // cmdLine.serial().printf("\r\n 61 ch=? -- CONFIGn_TRANSPARENT");
04925                     cmdLine.serial().printf(
04926                         "MAX5715_CONFIGn_TRANSPARENT(channel_dcba=%d)",
04927                         g_MAX5715_device.
04928                         channels_bitmask_DCBA);
04929                     g_MAX5715_device.CONFIGn_TRANSPARENT(
04930                         g_MAX5715_device.channels_bitmask_DCBA);
04931                     return true; // command was handled by MAX5715
04932                 }
04933                 break;
04934                 case '8':
04935                 {
04936                     // cmdLine.serial().printf("\r\n 68 -- CONFIGall_LATCHED");
04937                     cmdLine.serial().printf(
04938                         "MAX5715_CONFIGall_LATCHED()");
04939                     g_MAX5715_device.CONFIGall_LATCHED();
04940                     return true; // command was handled by MAX5715
04941                 }
04942                 break;
04943                 case '9':
04944                 {
04945                     // cmdLine.serial().printf("\r\n 69 -- CONFIGall_TRANSPARENT");
04946                     cmdLine.serial().printf(
04947                         "MAX5715_CONFIGall_TRANSPARENT()");
04948                     g_MAX5715_device.CONFIGall_TRANSPARENT();
04949                     return true; // command was handled by MAX5715
04950                 }
04951                 break;
04952             }
04953         }
04954         break;
04955         case '7':
04956         {
04957             // recommended for hex command codes 70..7F
04958             switch (cmdLine[1])
04959             {
04960                 case '0':
04961                 {
04962                     // cmdLine.serial().printf("\r\n 70 -- REF_EXT");
04963                     cmdLine.serial().printf(
04964                         "MAX5715_REF(REF_EXT)");
04965                     g_MAX5715_device.REF(MAX5715::REF_EXT);
04966                     return true; // command was handled by MAX5715
04967                 }
04968                 break;
04969                 case '1':
04970                 {
04971                     // cmdLine.serial().printf("\r\n 71 -- REF_2V500");
04972                     cmdLine.serial().printf(
04973                         "MAX5715_REF(REF_2V500)");
04974                     g_MAX5715_device.REF(MAX5715::REF_2V500);
04975                     return true; // command was handled by MAX5715
04976                 }
04977                 break;
04978                 case '2':
04979                 {
04980                     // cmdLine.serial().printf("\r\n 72 -- REF_2V048");
04981                     cmdLine.serial().printf(
04982                         "MAX5715_REF(REF_2V048)");
04983                     g_MAX5715_device.REF(MAX5715::REF_2V048);
04984                     return true; // command was handled by MAX5715
04985                 }
04986                 break;
04987                 case '3':
04988                 {
04989                     // cmdLine.serial().printf("\r\n 73 -- REF_4V096");
04990                     cmdLine.serial().printf(
04991                         "MAX5715_REF(REF_4V096)");
04992                     g_MAX5715_device.REF(MAX5715::REF_4V096);
04993                     return true; // command was handled by MAX5715
04994                 }
04995                 break;
04996                 case '4':
04997                 {
04998                     // cmdLine.serial().printf("\r\n 74 -- REF_AlwaysOn_EXT");
04999                     cmdLine.serial().printf(
05000                         "MAX5715_REF(REF_AlwaysOn_EXT)");
05001                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_EXT);
05002                     return true; // command was handled by MAX5715
05003                 }
05004                 break;
05005                 case '5':
05006                 {
05007                     // cmdLine.serial().printf("\r\n 75 -- REF_AlwaysOn_2V500");
05008                     cmdLine.serial().printf(
05009                         "MAX5715_REF(REF_AlwaysOn_2V500)");
05010                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500);
05011                     return true; // command was handled by MAX5715
05012                 }
05013                 break;
05014                 case '6':
05015                 {
05016                     // cmdLine.serial().printf("\r\n 76 -- REF_AlwaysOn_2V048");
05017                     cmdLine.serial().printf(
05018                         "MAX5715_REF(REF_AlwaysOn_2V048)");
05019                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048);
05020                     return true; // command was handled by MAX5715
05021                 }
05022                 break;
05023                 case '7':
05024                 {
05025                     // cmdLine.serial().printf("\r\n 77 -- REF_AlwaysOn_4V096");
05026                     cmdLine.serial().printf(
05027                         "MAX5715_REF(REF_AlwaysOn_4V096)");
05028                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_4V096);
05029                     return true; // command was handled by MAX5715
05030                 }
05031                 break;
05032             }
05033         }
05034         break;
05035         case '8':
05036         {
05037             // recommended for hex command codes 80..8F
05038             switch (cmdLine[1])
05039             {
05040                 case '0':
05041                 {
05042                     // TODO: cmdLine.serial().printf("\r\n 80 code=? -- CODEall");
05043                     // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
05044                     g_MAX5715_device.channels_bitmask_DCBA = 0xFF;             // store g_MAX5715_device.CODE[allChannels]
05045                     uint16_t code = g_MAX5715_device.CODE[0];
05046                     if (cmdLine.parse_uint16_dec("code", code))
05047                     {
05048                     }
05049                     cmdLine.serial().printf("CODEall code=%d", code);
05050                     g_MAX5715_device.CODEall(code);
05051                     return true; // command was handled by MAX5715
05052                 }
05053                 break;
05054                 case '1':
05055                 {
05056                     // TODO: cmdLine.serial().printf("\r\n 81 -- LOADall");
05057                     cmdLine.serial().printf("LOADall");
05058                     g_MAX5715_device.LOADall();
05059                     return true; // command was handled by MAX5715
05060                 }
05061                 break;
05062                 case '2':
05063                 {
05064                     // TODO: cmdLine.serial().printf("\r\n 82 code=? -- CODEallLOADall");
05065                     uint16_t code = g_MAX5715_device.CODE[0];
05066                     if (cmdLine.parse_uint16_dec("code", code))
05067                     {
05068                     }
05069                     cmdLine.serial().printf("CODEallLOADall code=%d", code);
05070                     g_MAX5715_device.CODEallLOADall(code);
05071                     return true; // command was handled by MAX5715
05072                 }
05073                 break;
05074             }
05075         }
05076         break;
05077         case '9':
05078         {
05079             // recommended for hex command codes 90..9F
05080         }
05081         break;
05082         case 'a': case 'A':
05083         {
05084             // recommended for hex command codes A0..AF
05085             switch (cmdLine[1])
05086             {
05087                 case 't': case 'T':
05088 #if IGNORE_AT_COMMANDS
05089 # if HAS_DAPLINK_SERIAL
05090                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05091 # endif // HAS_DAPLINK_SERIAL
05092                     // AT command: skip the prompt to avoid confusing modem detector
05093                     return false; // command not handled
05094 #endif // IGNORE_AT_COMMANDS
05095             }
05096         }
05097         break;
05098         case 'b': case 'B':
05099         {
05100             // recommended for hex command codes B0..BF
05101         }
05102         break;
05103         case 'c': case 'C':
05104         {
05105             // recommended for hex command codes C0..CF
05106             // // MAX5717 menu function to drive MAX5717_CLRb_Pin CLR#
05107             // cmdLine.serial().printf("\r\n C -- CLR# pulse CH high CL low");
05108             switch (cmdLine[1])
05109             {
05110                 default:
05111                     // g_MAX5715_device.CLRboutputPulseLow();
05112                     g_MAX5715_device.CLRboutputValue(1);
05113                     g_MAX5715_device.CLRboutputValue(0);
05114                     g_MAX5715_device.CLRboutputValue(1);
05115                     break;
05116                 case 'H': case 'h': case '1':
05117                     g_MAX5715_device.CLRboutputValue(1);         // GPIOoutputCLRb(int isLogicHigh);
05118                     break;
05119                 case 'L': case 'l': case '0':
05120                     g_MAX5715_device.CLRboutputValue(0);         // GPIOoutputCLRb(int isLogicHigh);
05121                     break;
05122             }
05123             return true; // command was handled by MAX5715
05124         }
05125         break;
05126         case 'd': case 'D':
05127         {
05128             // recommended for hex command codes D0..DF
05129         }
05130         break;
05131         case 'e': case 'E':
05132         {
05133             // recommended for hex command codes E0..EF
05134         }
05135         break;
05136         case 'f': case 'F':
05137         {
05138             // recommended for hex command codes F0..FF
05139         }
05140         break;
05141         case 'l': case 'L':
05142         {
05143             // // MAX5717 menu function to drive MAX5717_LDACb_Pin LDAC#
05144             // cmdLine.serial().printf("\r\n L -- LDAC# pulse LH high LL low");
05145             switch (cmdLine[1])
05146             {
05147                 default:
05148                     // g_MAX5715_device.LDACboutputPulseLow();
05149                     g_MAX5715_device.LDACboutputValue(1);
05150                     g_MAX5715_device.LDACboutputValue(0);
05151                     g_MAX5715_device.LDACboutputValue(1);
05152                     break;
05153                 case 'H': case 'h': case '1':
05154                     g_MAX5715_device.LDACboutputValue(1);         // GPIOoutputLDACb(int isLogicHigh);
05155                     break;
05156                 case 'L': case 'l': case '0':
05157                     g_MAX5715_device.LDACboutputValue(0);         // GPIOoutputLDACb(int isLogicHigh);
05158                     break;
05159             }
05160             return true; // command was handled by MAX5715
05161         }
05162         break;
05163         case 'x': case 'X':
05164         {
05165         }
05166         break;
05167         case 'y': case 'Y':
05168         {
05169         }
05170         break;
05171         case 'z': case 'Z':
05172         {
05173         }
05174         break;
05175         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
05176         {
05177             // TODO: '~' is not recommended for menu commands, interferes with ssh
05178             switch (cmdLine[1])
05179             {
05180                 default:
05181                 {
05182 #if IGNORE_AT_COMMANDS
05183 # if HAS_DAPLINK_SERIAL
05184                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n",
05185                                                           cmdLine.str());
05186 # endif // HAS_DAPLINK_SERIAL
05187 #endif // IGNORE_AT_COMMANDS
05188                 }
05189             }
05190         }
05191         break;
05192         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
05193         {
05194 #if IGNORE_AT_COMMANDS
05195 # if HAS_DAPLINK_SERIAL
05196             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05197 # endif // HAS_DAPLINK_SERIAL
05198 #endif // IGNORE_AT_COMMANDS
05199         }
05200         break;
05201         case '@':
05202         {
05203             // //
05204             // // Menu @ -- print device configuration
05205             // TODO: cmdLine.serial().printf("\r\n @ -- print MAX5715 configuration");
05206             // //
05207             // print shadow register configuration
05208             //
05209             // shadow of write-only register CODE dddd_dddd_dddd_0000
05210             //~ int16_t CMD_1000_CODE;
05211             int index = 0;
05212             for (index = 0; index < 4; index++)
05213             {
05214                 cmdLine.serial().printf("CODE %c=0x%4.4x MAX5715_VoltageOfCode(%d)=%5.3fV\r\n",
05215                                         (char)('A' + index),
05216                                         (g_MAX5715_device.Shadow_0010_nnnn_CODE[index] & 0xFFFF),
05217                                         g_MAX5715_device.CODE[index],
05218                                         g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[index])
05219                                         );
05220             }
05221             //
05222             cmdLine.serial().printf("\r\n");
05223             //
05224             //
05225             // Menu @) print MAX5715 configuration AND g_MAX5715_device globals
05226             //
05227 #if 1 // SUPPORT_CHANNELS
05228             cmdLine.serial().printf("channelNumber_0_3=%d channels_bitmask_DCBA=%d\r\n",
05229                                     (g_MAX5715_device.channelNumber_0_3 & 0xFFFF),
05230                                     (g_MAX5715_device.channels_bitmask_DCBA & 0xFFFF));
05231 #endif // SUPPORT_CHANNELS
05232             //
05233             cmdLine.serial().printf("VRef=%5.3fV\r\n", g_MAX5715_device.VRef);
05234             // dtostrf width and precision: 3.3V / 1024 LSB = 0.00322265625 volts per LSB
05235             return true; // command was handled by MAX5715
05236         }
05237         break;
05238     } // end switch (cmdLine[0])
05239     return false; // command not handled by MAX5715
05240 } // end bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine)
05241 #endif
05242 
05243 //--------------------------------------------------
05244 #if 0 // APPLICATION_MAX11131 // MAX11131_menu_onEOLcommandParser moved to Test_Menu_MAX11131.cpp
05245 bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine)
05246 {
05247     switch (cmdLine[0])
05248     {
05249         case '0':
05250         {
05251             // recommended for hex command codes 00..0F
05252             // VERIFY: console menu command 0 int16_t MAX11131_ScanRead(void);
05253             // TODO: cmdLine.serial().printf("\r\n 0 n=?                                  -- MAX11131_ScanRead");
05254             if (cmdLine.parse_uint16_dec("n", g_MAX11131_device.NumWords))
05255             {
05256             }
05257             cmdLine.serial().printf("ScanRead NumWords=%d", g_MAX11131_device.NumWords);
05258             if (g_MAX11131_device.isExternalClock)
05259             {
05260                 cmdLine.serial().printf(" External Clock");
05261                 //
05262                 // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05263                 // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05264                 g_MAX11131_device.ReadAINcode();
05265                 // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05266                 // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05267                 //
05268                 AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05269             }
05270             else
05271             {
05272                 cmdLine.serial().printf(" Internal Clock");
05273                 //
05274                 // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05275                 // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05276                 g_MAX11131_device.ReadAINcode();
05277                 // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05278                 // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05279                 //
05280                 AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05281             }
05282             return true; // command was handled by MAX11131
05283         }
05284         break;
05285         case '1':
05286         {
05287             // recommended for hex command codes 10..1F
05288             // VERIFY: console menu command 1 MAX11131_ScanManual(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
05289             // TODO: cmdLine.serial().printf("\r\n 1 ch=? pm=? id=?                       -- MAX11131_ScanManual");
05290             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05291             {
05292             }
05293             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05294             {
05295             }
05296             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05297             {
05298             }
05299             cmdLine.serial().printf("ScanManual ch=%d pm=%d id=%d\r\n",
05300                                     g_MAX11131_device.channelNumber_0_15,
05301                                     g_MAX11131_device.PowerManagement_0_2,
05302                                     g_MAX11131_device.chan_id_0_1);
05303             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05304             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05305             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05306             g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
05307             //
05308             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05309             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05310             g_MAX11131_device.ReadAINcode();
05311             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05312             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05313             //
05314             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05315             return true; // command was handled by MAX11131
05316         }
05317         break;
05318         case '2':
05319         {
05320             // recommended for hex command codes 20..2F
05321             // VERIFY: console menu command 2 int MAX11131_ScanRepeat(uint8_t channelNumber_0_15, uint8_t average_0_4_8_16_32, uint8_t nscan_4_8_12_16, uint8_t PowerManagement_0_2, uint8_t swcnv_0_1);
05322             // TODO: cmdLine.serial().printf("\r\n 2 ch=? av=? n=? pm=? swcnv=?           -- MAX11131_ScanRepeat");
05323             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05324             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05325             // VERIFY: update value of g_MAX11131_device.nscan_4_8_12_16 option from strCommandArgs
05326             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05327             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05328             // VERIFY: parse strCommandArgs for additional arguments including key=value pairs
05329             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05330             {
05331             }
05332             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05333             {
05334             }
05335             if (cmdLine.parse_byte_dec("n", g_MAX11131_device.nscan_4_8_12_16))
05336             {
05337             }
05338             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05339             {
05340             }
05341             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05342             {
05343             }
05344             cmdLine.serial().printf(
05345                 "ScanRepeat ch=%d average_0_4_8_16_32:%d nscan_4_8_12_16:%d swcnv=%d pm=%d\r\n",
05346                 g_MAX11131_device.channelNumber_0_15,
05347                 g_MAX11131_device.average_0_4_8_16_32,
05348                 g_MAX11131_device.nscan_4_8_12_16,
05349                 g_MAX11131_device.swcnv_0_1,
05350                 g_MAX11131_device.PowerManagement_0_2);
05351             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05352             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05353             // VERIFY: replace argument with driver global; g_MAX11131_device.nscan_4_8_12_16 replaces nscan_4_8_12_16
05354             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05355             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05356             g_MAX11131_device.NumWords = g_MAX11131_device.ScanRepeat();
05357             //
05358             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05359             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05360             g_MAX11131_device.ReadAINcode();
05361             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05362             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05363             //
05364             AINcode_print_value_chanID_mean(cmdLine, g_MAX11131_device.NumWords);
05365             return true; // command was handled by MAX11131
05366         }
05367         break;
05368         case '3':
05369         {
05370             // recommended for hex command codes 30..3F
05371             // VERIFY: console menu command 3 MAX11131_ScanStandardInternalClock(int channelNumber_0_15, int average_0_4_8_16_32, int PowerManagement_0_2, int swcnv_0_1);
05372             // TODO: cmdLine.serial().printf("\r\n 3 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanStandardIntClock");
05373             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05374             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05375             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05376             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05377             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05378             {
05379             }
05380             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05381             {
05382             }
05383             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05384             {
05385             }
05386             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05387             {
05388             }
05389             cmdLine.serial().printf("ScanStandardInternalClock ch=%d average_0_4_8_16_32:%d swcnv=%d pm=%d\r\n",
05390                                     g_MAX11131_device.channelNumber_0_15,
05391                                     g_MAX11131_device.average_0_4_8_16_32,
05392                                     g_MAX11131_device.swcnv_0_1,
05393                                     g_MAX11131_device.PowerManagement_0_2
05394                                     );
05395             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05396             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05397             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05398             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05399             g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardInternalClock();
05400             //
05401             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05402             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05403             g_MAX11131_device.ReadAINcode();
05404             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05405             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05406             //
05407             AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05408             return true; // command was handled by MAX11131
05409         }
05410         break;
05411         case '4':
05412         {
05413             // recommended for hex command codes 40..4F
05414             // VERIFY: console menu command 4 MAX11131_ScanStandardExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
05415             // TODO: cmdLine.serial().printf("\r\n 4 ch=? pm=? id=?                       -- MAX11131_ScanStandardExtClock");
05416             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05417             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05418             // VERIFY: update value of g_MAX11131_device.chan_id_0_1 option from strCommandArgs
05419             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05420             {
05421             }
05422             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05423             {
05424             }
05425             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05426             {
05427             }
05428             cmdLine.serial().printf("ScanStandardExternalClock ch=%d pm=%d id=%d\r\n",
05429                                     g_MAX11131_device.channelNumber_0_15,
05430                                     g_MAX11131_device.PowerManagement_0_2,
05431                                     g_MAX11131_device.chan_id_0_1
05432                                     );
05433             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05434             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05435             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05436             g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
05437             //
05438             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05439             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05440             g_MAX11131_device.ReadAINcode();
05441             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05442             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05443             //
05444             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05445             return true; // command was handled by MAX11131
05446         }
05447         break;
05448         case '5':
05449         {
05450             // recommended for hex command codes 50..5F
05451             // VERIFY: console menu command 5 MAX11131_ScanUpperInternalClock(int channelNumber_0_15, int average_0_4_8_16_32, int PowerManagement_0_2, int swcnv_0_1);
05452             // TODO: cmdLine.serial().printf("\r\n 5 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanUpperIntClock");
05453             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05454             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05455             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05456             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05457             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05458             {
05459             }
05460             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05461             {
05462             }
05463             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05464             {
05465             }
05466             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05467             {
05468             }
05469             cmdLine.serial().printf("ScanUpperInternalClock ch=%d average_0_4_8_16_32:%d swcnv=%d pm=%d\r\n",
05470                                     g_MAX11131_device.channelNumber_0_15,
05471                                     g_MAX11131_device.average_0_4_8_16_32,
05472                                     g_MAX11131_device.swcnv_0_1,
05473                                     g_MAX11131_device.PowerManagement_0_2
05474                                     );
05475             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05476             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05477             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05478             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05479             g_MAX11131_device.NumWords = g_MAX11131_device.ScanUpperInternalClock();
05480             //
05481             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05482             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05483             g_MAX11131_device.ReadAINcode();
05484             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05485             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05486             //
05487             AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05488             return true; // command was handled by MAX11131
05489         }
05490         break;
05491         case '6':
05492         {
05493             // recommended for hex command codes 60..6F
05494             // VERIFY: console menu command 6 MAX11131_ScanUpperExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
05495             // TODO: cmdLine.serial().printf("\r\n 6 ch=? pm=? id=?                       -- MAX11131_ScanUpperExtClock");
05496             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05497             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05498             // VERIFY: update value of g_MAX11131_device.chan_id_0_1 option from strCommandArgs
05499             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05500             {
05501             }
05502             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05503             {
05504             }
05505             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05506             {
05507             }
05508             cmdLine.serial().printf("ScanUpperExternalClock ch=%d pm=%d id=%d\r\n",
05509                                     g_MAX11131_device.channelNumber_0_15,
05510                                     g_MAX11131_device.PowerManagement_0_2,
05511                                     g_MAX11131_device.chan_id_0_1
05512                                     );
05513             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05514             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05515             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05516             g_MAX11131_device.NumWords = g_MAX11131_device.ScanUpperExternalClock();
05517             //
05518             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05519             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05520             g_MAX11131_device.ReadAINcode();
05521             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05522             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05523             //
05524             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05525             return true; // command was handled by MAX11131
05526         }
05527         break;
05528         case '7':
05529         {
05530             // recommended for hex command codes 70..7F
05531             // VERIFY: console menu command 7 MAX11131_ScanCustomInternalClock(int16_t enabledChannelsMask, int average_0_4_8_16_32, int PowerManagement_0_2, int swcnv_0_1);
05532             // TODO: cmdLine.serial().printf("\r\n 7 enableMask=0xffff av=? pm=? swcnv=?  -- MAX11131_ScanCustomIntClock");
05533             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05534             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05535             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05536             if (cmdLine.parse_int16_hex("enableMask", g_MAX11131_device.enabledChannelsMask))
05537             {
05538                 // TODO1: get g_MAX11131_device.enabledChannelsMask from strCommandArgs
05539             }
05540             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05541             {
05542             }
05543             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05544             {
05545             }
05546             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05547             {
05548             }
05549             cmdLine.serial().printf(
05550                 "ScanCustomInternalClock enabledChannelsMask:0x%4.4x average_0_4_8_16_32:%d pm=%d swcnv=%d\r\n",
05551                 (g_MAX11131_device.enabledChannelsMask & 0xFFFF),
05552                 g_MAX11131_device.average_0_4_8_16_32,
05553                 g_MAX11131_device.PowerManagement_0_2,
05554                 g_MAX11131_device.swcnv_0_1
05555                 );
05556             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05557             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05558             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05559             // VERIFY: replace argument with driver global; g_MAX11131_device.enabledChannelsMask replaces enabledChannelsMask
05560             g_MAX11131_device.NumWords = g_MAX11131_device.ScanCustomInternalClock();
05561             //
05562             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05563             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05564             g_MAX11131_device.ReadAINcode();
05565             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05566             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05567             //
05568             AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05569             return true; // command was handled by MAX11131
05570         }
05571         break;
05572         case '8':
05573         {
05574             // recommended for hex command codes 80..8F
05575             // VERIFY: console menu command 8 MAX11131_ScanCustomExternalClock(int16_t enabledChannelsMask, int PowerManagement_0_2, int chan_id_0_1);
05576             // TODO: cmdLine.serial().printf("\r\n 8 enableMask=0xffff pm=0 id=1               -- MAX11131_ScanCustomExtClock");
05577             if (cmdLine.parse_int16_hex("enableMask", g_MAX11131_device.enabledChannelsMask))
05578             {
05579                 // TODO1: get g_MAX11131_device.enabledChannelsMask from strCommandArgs
05580             }
05581             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05582             {
05583             }
05584             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05585             {
05586             }
05587             cmdLine.serial().printf("ScanCustomExternalClock enabledChannelsMask:0x%4.4x pm=%d id=%d\r\n",
05588                                     (g_MAX11131_device.enabledChannelsMask & 0xFFFF),
05589                                     g_MAX11131_device.PowerManagement_0_2,
05590                                     g_MAX11131_device.chan_id_0_1
05591                                     );
05592             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05593             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05594             // VERIFY: replace argument with driver global; g_MAX11131_device.enabledChannelsMask replaces enabledChannelsMask
05595             g_MAX11131_device.NumWords = g_MAX11131_device.ScanCustomExternalClock();
05596             //
05597             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05598             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05599             g_MAX11131_device.ReadAINcode();
05600             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05601             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05602             //
05603             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05604             return true; // command was handled by MAX11131
05605         }
05606         break;
05607         case '9':
05608         {
05609             // recommended for hex command codes 90..9F
05610             // VERIFY: console menu command 9 MAX11131_ScanSampleSetExternalClock(uint8_t enabledChannelsPatternLength_1_256, int16_t enabledChannelsPattern[], int PowerManagement_0_2, int chan_id_0_1);
05611             // TODO: cmdLine.serial().printf("\r\n 9 channelsPattern... pm=? id=? | len=? -- MAX11131_ScanSampleSetExtClock");
05612             //
05613             // get MAX11131 Sampleset channel selection pattern parse_strCommandArgs(strCommandArgs);
05614             // cmdLine.parse_byteCount_byteList_dec(byteCount, mosiData, MAX_SPI_BYTE_COUNT)
05615             // into g_MAX11131_device.enabledChannelsPatternLength_1_256
05616             // into g_MAX11131_device.enabledChannelsPattern[0..255]
05617             size_t numValues;
05618             char valueList[256];
05619             if (cmdLine.parse_byteCount_byteList_dec( numValues, valueList, 256))
05620             {
05621                 // first value is the "9" command itself
05622                 g_MAX11131_device.enabledChannelsPatternLength_1_256 = numValues - 1;
05623                 // copy valueList[1, ...] into g_MAX11131_device.enabledChannelsPattern[0, ...]
05624                 for (size_t index = 0; index < (numValues - 1); index++)
05625                 {
05626                     g_MAX11131_device.enabledChannelsPattern[index] = valueList[1 + index];
05627                 }
05628             }
05629             //
05630             cmdLine.serial().printf("ScanSampleSetExternalClock enabledChannelsPattern:{ ");
05631             int index;
05632             for (index = 0; index < g_MAX11131_device.enabledChannelsPatternLength_1_256; index++)
05633             {
05634                 //~ Serial.print( ((g_enabledChannelsPattern[index] >> 4) & 0x000F), DEC);
05635                 //~ Serial.print(" ");
05636                 cmdLine.serial().printf("AIN%d ", ((g_MAX11131_device.enabledChannelsPattern[index]) & 0x000F));
05637             }
05638             cmdLine.serial().printf("}");
05639             cmdLine.serial().printf(" pm=%d id=%d\r\n", g_MAX11131_device.PowerManagement_0_2,
05640                                     g_MAX11131_device.chan_id_0_1);
05641             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05642             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05643             g_MAX11131_device.NumWords = g_MAX11131_device.ScanSampleSetExternalClock();
05644             //
05645             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05646             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05647             g_MAX11131_device.ReadAINcode();
05648             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05649             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05650             //
05651             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05652             return true; // command was handled by MAX11131
05653         }
05654         break;
05655         case 'a': case 'A':
05656         {
05657             // recommended for hex command codes A0..AF
05658             switch (cmdLine[1])
05659             {
05660                 case 't': case 'T':
05661 #if IGNORE_AT_COMMANDS
05662 # if HAS_DAPLINK_SERIAL
05663                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05664 # endif // HAS_DAPLINK_SERIAL
05665                     // AT command: skip the prompt to avoid confusing modem detector
05666                     return false; // command not handled
05667 #endif // IGNORE_AT_COMMANDS
05668             }
05669         }
05670         break;
05671         case 'b': case 'B':
05672         {
05673             // recommended for hex command codes B0..BF
05674         }
05675         break;
05676         case 'c': case 'C':
05677         {
05678             // recommended for hex command codes C0..CF
05679         }
05680         break;
05681         case 'd': case 'D':
05682         {
05683             // recommended for hex command codes D0..DF
05684         }
05685         break;
05686         case 'e': case 'E':
05687         {
05688             // recommended for hex command codes E0..EF
05689         }
05690         break;
05691         case 'f': case 'F':
05692         {
05693             // recommended for hex command codes F0..FF
05694         }
05695         break;
05696         case 'x': case 'X':
05697         {
05698         }
05699         break;
05700         case 'y': case 'Y':
05701         {
05702         }
05703         break;
05704         case 'i': case 'I':
05705         {
05706             // TODO: cmdLine.serial().printf("\r\n ISc) IUc) IBc) IRc) reconfigure channel single-ended/unipolar/bipolar/range");
05707             char strChannelId[3];
05708             strChannelId[0] = cmdLine[2];
05709             strChannelId[1] = cmdLine[3];
05710             strChannelId[2] = '\0';
05711             int channelId_0_15 = strtoul(strChannelId, NULL, 10);         // strtol(str, NULL, 10): get decimal value
05712             switch (cmdLine[1])
05713             {
05714                 case 's': case 'S':
05715                     g_MAX11131_device.Reconfigure_SingleEnded(channelId_0_15);
05716                     break;
05717                 case 'u': case 'U':
05718                     g_MAX11131_device.Reconfigure_DifferentialUnipolar(channelId_0_15);
05719                     break;
05720                 case 'b': case 'B':
05721                     g_MAX11131_device.Reconfigure_DifferentialBipolarFSVref(channelId_0_15);
05722                     break;
05723                 case 'r': case 'R':
05724                     g_MAX11131_device.Reconfigure_DifferentialBipolarFS2Vref(channelId_0_15);
05725                     break;
05726             }
05727             // char cmd1 = strCommandArgs[0];
05728             // strCommandArgs.remove(0, 1); // unsigned int index, unsigned int count
05729             // // get argument int channelId_0_15
05730             // // parse_strCommandArgs(strCommandArgs);
05731             // int channelId_0_15 = strtoul(strCommandArgs.c_str(), NULL, 10); // strtol(str, NULL, 10): get decimal value
05732             // if (cmd1 == 'S') {
05733             //     MAX11131_Reconfigure_SingleEnded(channelId_0_15);
05734             // }
05735             // else if (cmd1 == 'U') {
05736             //     MAX11131_Reconfigure_DifferentialUnipolar(channelId_0_15);
05737             // }
05738             // else if (cmd1 == 'B') {
05739             //     MAX11131_Reconfigure_DifferentialBipolarFSVref(channelId_0_15);
05740             // }
05741             // else if (cmd1 == 'R') {
05742             //     MAX11131_Reconfigure_DifferentialBipolarFS2Vref(channelId_0_15);
05743             // }
05744             return true; // command was handled by MAX11131
05745         }
05746         break;
05747         case '@':
05748         {
05749             // TODO: cmdLine.serial().printf("\r\n @                                      -- print MAX11131 configuration");
05750             // print shadow register configuration
05751             //
05752             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.ADC_MODE_CONTROL & 0xFFFF));
05753             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.ADC_MODE_CONTROL);
05754             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.ADC_CONFIGURATION & 0xFFFF));
05755             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.ADC_CONFIGURATION);
05756             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.UNIPOLAR & 0xFFFF));
05757             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.UNIPOLAR);
05758             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.BIPOLAR & 0xFFFF));
05759             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.BIPOLAR);
05760             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.RANGE & 0xFFFF));
05761             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.RANGE);
05762             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.CSCAN0 & 0xFFFF));
05763             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.CSCAN0);
05764             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.CSCAN1 & 0xFFFF));
05765             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.CSCAN1);
05766             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.SAMPLESET & 0xFFFF));
05767             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.SAMPLESET);
05768             //
05769             // VERIFY: print shadow SAMPLESET pattern entry
05770             int entryIndex;
05771             for (entryIndex = 0; entryIndex < g_MAX11131_device.enabledChannelsPatternLength_1_256;
05772                  entryIndex += 4)
05773             {
05774                 uint16_t pack4channels = 0;
05775                 pack4channels |= (((g_MAX11131_device.enabledChannelsPattern[entryIndex + 0]) & 0x0F) << 12);
05776                 if ((entryIndex + 1) < g_MAX11131_device.enabledChannelsPatternLength_1_256) {
05777                     pack4channels |= (((g_MAX11131_device.enabledChannelsPattern[entryIndex + 1]) & 0x0F) << 8);
05778                 }
05779                 if ((entryIndex + 2) < g_MAX11131_device.enabledChannelsPatternLength_1_256) {
05780                     pack4channels |= (((g_MAX11131_device.enabledChannelsPattern[entryIndex + 2]) & 0x0F) << 4);
05781                 }
05782                 if ((entryIndex + 3) < g_MAX11131_device.enabledChannelsPatternLength_1_256) {
05783                     pack4channels |= ((g_MAX11131_device.enabledChannelsPattern[entryIndex + 3]) & 0x0F);
05784                 }
05785                 //~ SPIwrite16bits(pack4channels);
05786                 cmdLine.serial().printf("       0x%4.4x", (pack4channels & 0xFFFF));
05787                 // decode SAMPLESET channel select pattern
05788                 cmdLine.serial().printf(" SampleSet Entry: AIN%d AIN%d AIN%d AIN%d\r\n",
05789                                         ((pack4channels >> 12) & 0x000F),
05790                                         ((pack4channels >> 8) & 0x000F),
05791                                         ((pack4channels >> 4) & 0x000F),
05792                                         ((pack4channels      ) & 0x000F)
05793                                         );
05794             }
05795             //cmdLine.serial().printf("  SAMPLESET enabledChannelsPattern:{ ");
05796             //int index;
05797             //for (index = 0; index < g_MAX11131_device.enabledChannelsPatternLength_1_256; index++)
05798             //{
05799             //  //~ cmdLine.serial().printf( ((g_enabledChannelsPattern[index] >> 4) & 0x000F), DEC);
05800             //  //~ cmdLine.serial().printf(" ");
05801             //  cmdLine.serial().printf("AIN");
05802             //  cmdLine.serial().printf( ((g_MAX11131_device.enabledChannelsPattern[index]) & 0x000F), DEC);
05803             //  cmdLine.serial().printf(" ");
05804             //}
05805             //cmdLine.serial().printf("}");
05806             //
05807             // Menu @) print MAX11131 configuration AND g_MAX11131_device globals
05808             //
05809             cmdLine.serial().printf("SPI_MOSI_Semantic=%d\r\n", (g_MAX11131_device.SPI_MOSI_Semantic & 0xFFFF));
05810             cmdLine.serial().printf("NumWords=%d\r\n", (g_MAX11131_device.NumWords & 0xFFFF));
05811             cmdLine.serial().printf("isExternalClock=%d\r\n", (g_MAX11131_device.isExternalClock & 0xFFFF));
05812             cmdLine.serial().printf("ScanMode=%d\r\n", (g_MAX11131_device.ScanMode & 0xFFFF));
05813             cmdLine.serial().printf("channelNumber_0_15=%d\r\n",
05814                                     (g_MAX11131_device.channelNumber_0_15 & 0xFFFF));
05815             cmdLine.serial().printf("PowerManagement_0_2=%d\r\n",
05816                                     (g_MAX11131_device.PowerManagement_0_2 & 0xFFFF));
05817             cmdLine.serial().printf("chan_id_0_1=%d\r\n", (g_MAX11131_device.chan_id_0_1 & 0xFFFF));
05818             cmdLine.serial().printf("average_0_4_8_16_32=%d\r\n",
05819                                     (g_MAX11131_device.average_0_4_8_16_32 & 0xFFFF));
05820             cmdLine.serial().printf("nscan_4_8_12_16=%d\r\n", (g_MAX11131_device.nscan_4_8_12_16 & 0xFFFF));
05821             cmdLine.serial().printf("swcnv_0_1=%d\r\n", (g_MAX11131_device.swcnv_0_1 & 0xFFFF));
05822             cmdLine.serial().printf("enabledChannelsMask=0x%4.4x\r\n",
05823                                     (g_MAX11131_device.enabledChannelsMask & 0xFFFF));
05824             //
05825             cmdLine.serial().printf("VRef=%5.3fV\r\n", g_MAX11131_device.VRef);
05826             // dtostrf width and precision: 3.3V / 1024 LSB = 0.00322265625 volts per LSB
05827             //
05828             return true; // command was handled by MAX11131
05829         }
05830             //case '&':
05831             //{
05832             //    // TODO: cmdLine.serial().printf("\r\n & -- MAX11131_Example_ScanManual");
05833             //}
05834             break;
05835         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
05836         {
05837             // TODO: '~' is not recommended for menu commands, interferes with ssh
05838 #if IGNORE_AT_COMMANDS
05839 # if HAS_DAPLINK_SERIAL
05840             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05841 # endif // HAS_DAPLINK_SERIAL
05842 #endif // IGNORE_AT_COMMANDS
05843         }
05844         break;
05845         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
05846         {
05847 #if IGNORE_AT_COMMANDS
05848 # if HAS_DAPLINK_SERIAL
05849             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05850 # endif // HAS_DAPLINK_SERIAL
05851 #endif // IGNORE_AT_COMMANDS
05852         }
05853         break;
05854     } // end switch (cmdLine[0])
05855     return false; // command not handled
05856 } // end bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine)
05857 #endif
05858 
05859 //--------------------------------------------------
05860 #if 0 // APPLICATION_MAX5171 // MAX5171_menu_onEOLcommandParser moved to Test_Menu_MAX5171.cpp
05861 bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine)
05862 {
05863     switch (cmdLine[0])
05864     {
05865         case '0':
05866         {
05867             // recommended for hex command codes 10..1F
05868             //~ cmdLine.serial().printf("\r\n 0 code=? -- CODE");
05869             uint16_t code;
05870             if (cmdLine.parse_uint16_dec("code", code))
05871             {
05872             }
05873             cmdLine.serial().printf("CODE code=%d", code);
05874             g_MAX5171_device.CODE(code);
05875             return true; // command was handled by MAX5171
05876         }
05877         break;
05878         case '4':
05879         {
05880             // recommended for hex command codes 10..1F
05881             //~ cmdLine.serial().printf("\r\n 4 code=? -- CODE_LOAD");
05882             uint16_t code;
05883             if (cmdLine.parse_uint16_dec("code", code))
05884             {
05885             }
05886             cmdLine.serial().printf("CODE_LOAD code=%d", code);
05887             g_MAX5171_device.CODE_LOAD(code);
05888             return true; // command was handled by MAX5171
05889         }
05890         break;
05891         case '8':
05892         {
05893             // recommended for hex command codes 10..1F
05894             //~ cmdLine.serial().printf("\r\n 8 -- LOAD");
05895             cmdLine.serial().printf("LOAD");
05896             g_MAX5171_device.LOAD();
05897             return true; // command was handled by MAX5171
05898         }
05899         break;
05900         case 'c': case 'C':
05901         {
05902             // recommended for hex command codes 10..1F
05903             //~ cmdLine.serial().printf("\r\n c -- NOP");
05904             cmdLine.serial().printf("NOP");
05905             g_MAX5171_device.NOP();
05906             return true; // command was handled by MAX5171
05907         }
05908         break;
05909         case 'd': case 'D':
05910         {
05911             // recommended for hex command codes 10..1F
05912             //~ cmdLine.serial().printf("\r\n d -- SHUTDOWN");
05913             cmdLine.serial().printf("SHUTDOWN");
05914             g_MAX5171_device.SHUTDOWN();
05915             return true; // command was handled by MAX5171
05916         }
05917         break;
05918         case 'e': case 'E':
05919         {
05920             switch (cmdLine[1])
05921             {
05922                 case '0':
05923                 {
05924                     // recommended for hex command codes 10..1F
05925                     //~ cmdLine.serial().printf("\r\n e0 -- UPO_LOW");
05926                     cmdLine.serial().printf("UPO_LOW");
05927                     g_MAX5171_device.UPO_LOW();
05928                     return true; // command was handled by MAX5171
05929                 }
05930                 break;
05931                 case '8':
05932                 {
05933                     // recommended for hex command codes 10..1F
05934                     //~ cmdLine.serial().printf("\r\n e8 -- UPO_HIGH");
05935                     cmdLine.serial().printf("UPO_HIGH");
05936                     g_MAX5171_device.UPO_HIGH();
05937                     return true; // command was handled by MAX5171
05938                 }
05939                 break;
05940             }
05941         }
05942         break;
05943         case 'f': case 'F':
05944         {
05945             switch (cmdLine[1])
05946             {
05947                 case '0':
05948                 {
05949                     // recommended for hex command codes 10..1F
05950                     //~ cmdLine.serial().printf("\r\n f0 -- MODE1_DOUT_SCLK_RISING_EDGE");
05951                     cmdLine.serial().printf("MODE1_DOUT_SCLK_RISING_EDGE");
05952                     g_MAX5171_device.MODE1_DOUT_SCLK_RISING_EDGE();
05953                     return true; // command was handled by MAX5171
05954                 }
05955                 break;
05956                 case '8':
05957                 {
05958                     // recommended for hex command codes 10..1F
05959                     //~ cmdLine.serial().printf("\r\n f8 -- MODE0_DOUT_SCLK_FALLING_EDGE");
05960                     cmdLine.serial().printf("MODE0_DOUT_SCLK_FALLING_EDGE");
05961                     g_MAX5171_device.MODE0_DOUT_SCLK_FALLING_EDGE();
05962                     return true; // command was handled by MAX5171
05963                 }
05964                 break;
05965             }
05966         }
05967         break;
05968         case 'a': case 'A':
05969         {
05970             // recommended for hex command codes A0..AF
05971             switch (cmdLine[1])
05972             {
05973                 case 't': case 'T':
05974 #if IGNORE_AT_COMMANDS
05975 # if HAS_DAPLINK_SERIAL
05976                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05977 # endif // HAS_DAPLINK_SERIAL
05978                     // AT command: skip the prompt to avoid confusing modem detector
05979                     return;
05980 #endif // IGNORE_AT_COMMANDS
05981             }
05982         }
05983         break;
05984         case 'x': case 'X':
05985         {
05986         }
05987         break;
05988         case 'y': case 'Y':
05989         {
05990         }
05991         break;
05992         case 'z': case 'Z':
05993         {
05994         }
05995         break;
05996         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
05997         {
05998             // TODO: '~' is not recommended for menu commands, interferes with ssh
05999 #if IGNORE_AT_COMMANDS
06000 # if HAS_DAPLINK_SERIAL
06001             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06002 # endif // HAS_DAPLINK_SERIAL
06003 #endif // IGNORE_AT_COMMANDS
06004         }
06005         break;
06006         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
06007         {
06008 #if IGNORE_AT_COMMANDS
06009 # if HAS_DAPLINK_SERIAL
06010             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06011 # endif // HAS_DAPLINK_SERIAL
06012 #endif // IGNORE_AT_COMMANDS
06013         }
06014         break;
06015     } // end switch (cmdLine[0])
06016     return false; // command not handled
06017 } // end bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine)
06018 #endif
06019 
06020 //--------------------------------------------------
06021 #if 0 // APPLICATION_MAX11410 // MAX11410_menu_onEOLcommandParser moved to Test_Menu_MAX11410.cpp
06022 bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine)
06023 {
06024     switch (cmdLine[0])
06025     {
06026         // TODO1: MAX11410 main_menu_onEOLcommandParser
06027         case '0':
06028         {
06029             // recommended for hex command codes 00..0F
06030             // placeholder: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
06031             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
06032             uint16_t code;
06033             if (cmdLine.parse_uint16_dec("ch", ch))
06034             {
06035             }
06036             if (cmdLine.parse_uint16_dec("code", code))
06037             {
06038             }
06039             if (cmdLine.parse_flag("xyzzy", g_xyzzy_flag, XYZZY_FLAG))
06040             {
06041                 isUpdatedSPIConfig = true;
06042             }
06043             cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
06044             MAX5715_CODEnLOADn(ch, code);
06045             cmdLine.serial().printf("\r\n placeholder");
06046             return true; // command was handled by MAX11410
06047         }
06048         break;
06049         case '1':
06050         {
06051             // recommended for hex command codes 10..1F
06052         }
06053         break;
06054         case '2':
06055         {
06056             // recommended for hex command codes 20..2F
06057         }
06058         break;
06059         case '3':
06060         {
06061             // recommended for hex command codes 30..3F
06062         }
06063         break;
06064         case '4':
06065         {
06066             // recommended for hex command codes 40..4F
06067         }
06068         break;
06069         case '5':
06070         {
06071             // recommended for hex command codes 50..5F
06072         }
06073         break;
06074         case '6':
06075         {
06076             // recommended for hex command codes 60..6F
06077         }
06078         break;
06079         case '7':
06080         {
06081             // recommended for hex command codes 70..7F
06082         }
06083         break;
06084         case '8':
06085         {
06086             // recommended for hex command codes 80..8F
06087         }
06088         break;
06089         case '9':
06090         {
06091             // recommended for hex command codes 90..9F
06092         }
06093         break;
06094         case 'a': case 'A':
06095         {
06096             // recommended for hex command codes A0..AF
06097             switch (cmdLine[1])
06098             {
06099                 case 't': case 'T':
06100 #if IGNORE_AT_COMMANDS
06101 # if HAS_DAPLINK_SERIAL
06102                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06103 # endif // HAS_DAPLINK_SERIAL
06104                     // AT command: skip the prompt to avoid confusing modem detector
06105                     return;
06106 #endif // IGNORE_AT_COMMANDS
06107             }
06108         }
06109         break;
06110         case 'b': case 'B':
06111         {
06112             // recommended for hex command codes B0..BF
06113         }
06114         break;
06115         case 'c': case 'C':
06116         {
06117             // recommended for hex command codes C0..CF
06118         }
06119         break;
06120         case 'd': case 'D':
06121         {
06122             // recommended for hex command codes D0..DF
06123         }
06124         break;
06125         case 'e': case 'E':
06126         {
06127             // recommended for hex command codes E0..EF
06128         }
06129         break;
06130         case 'f': case 'F':
06131         {
06132             // recommended for hex command codes F0..FF
06133         }
06134         break;
06135         case 'x': case 'X':
06136         {
06137         }
06138         break;
06139         case 'y': case 'Y':
06140         {
06141         }
06142         break;
06143         case 'z': case 'Z':
06144         {
06145         }
06146         break;
06147         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
06148         {
06149             // TODO: '~' is not recommended for menu commands, interferes with ssh
06150 #if IGNORE_AT_COMMANDS
06151 # if HAS_DAPLINK_SERIAL
06152             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06153 # endif // HAS_DAPLINK_SERIAL
06154 #endif // IGNORE_AT_COMMANDS
06155         }
06156         break;
06157         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
06158         {
06159 #if IGNORE_AT_COMMANDS
06160 # if HAS_DAPLINK_SERIAL
06161             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06162 # endif // HAS_DAPLINK_SERIAL
06163 #endif // IGNORE_AT_COMMANDS
06164         }
06165         break;
06166     } // end switch (cmdLine[0])
06167     return false; // command not handled
06168 } // end bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine)
06169 #endif
06170 
06171 
06172 //--------------------------------------------------
06173 #if APPLICATION_MAX12345 // MAX12345_menu_onEOLcommandParser see Test_Menu_MAX12345.cpp
06174 bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine)
06175 {
06176     switch (cmdLine[0])
06177     {
06178         // TODO1: MAX12345 main_menu_onEOLcommandParser
06179         case '0':
06180         {
06181             // recommended for hex command codes 00..0F
06182             // placeholder: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
06183             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
06184             uint16_t code;
06185             if (cmdLine.parse_uint16_dec("ch", ch))
06186             {
06187             }
06188             if (cmdLine.parse_uint16_dec("code", code))
06189             {
06190             }
06191             if (cmdLine.parse_flag("xyzzy", g_xyzzy_flag, XYZZY_FLAG))
06192             {
06193                 isUpdatedSPIConfig = true;
06194             }
06195             cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
06196             MAX5715_CODEnLOADn(ch, code);
06197             cmdLine.serial().printf("\r\n placeholder");
06198             return true; // command was handled by MAX12345
06199         }
06200         break;
06201         case '1':
06202         {
06203             // recommended for hex command codes 10..1F
06204         }
06205         break;
06206         case '2':
06207         {
06208             // recommended for hex command codes 20..2F
06209         }
06210         break;
06211         case '3':
06212         {
06213             // recommended for hex command codes 30..3F
06214         }
06215         break;
06216         case '4':
06217         {
06218             // recommended for hex command codes 40..4F
06219         }
06220         break;
06221         case '5':
06222         {
06223             // recommended for hex command codes 50..5F
06224         }
06225         break;
06226         case '6':
06227         {
06228             // recommended for hex command codes 60..6F
06229         }
06230         break;
06231         case '7':
06232         {
06233             // recommended for hex command codes 70..7F
06234         }
06235         break;
06236         case '8':
06237         {
06238             // recommended for hex command codes 80..8F
06239         }
06240         break;
06241         case '9':
06242         {
06243             // recommended for hex command codes 90..9F
06244         }
06245         break;
06246         case 'a': case 'A':
06247         {
06248             // recommended for hex command codes A0..AF
06249             switch (cmdLine[1])
06250             {
06251                 case 't': case 'T':
06252 #if IGNORE_AT_COMMANDS
06253 # if HAS_DAPLINK_SERIAL
06254                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06255 # endif // HAS_DAPLINK_SERIAL
06256                     // AT command: skip the prompt to avoid confusing modem detector
06257                     return;
06258 #endif // IGNORE_AT_COMMANDS
06259             }
06260         }
06261         break;
06262         case 'b': case 'B':
06263         {
06264             // recommended for hex command codes B0..BF
06265         }
06266         break;
06267         case 'c': case 'C':
06268         {
06269             // recommended for hex command codes C0..CF
06270         }
06271         break;
06272         case 'd': case 'D':
06273         {
06274             // recommended for hex command codes D0..DF
06275         }
06276         break;
06277         case 'e': case 'E':
06278         {
06279             // recommended for hex command codes E0..EF
06280         }
06281         break;
06282         case 'f': case 'F':
06283         {
06284             // recommended for hex command codes F0..FF
06285         }
06286         break;
06287         case 'x': case 'X':
06288         {
06289         }
06290         break;
06291         case 'y': case 'Y':
06292         {
06293         }
06294         break;
06295         case 'z': case 'Z':
06296         {
06297         }
06298         break;
06299         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
06300         {
06301             // TODO: '~' is not recommended for menu commands, interferes with ssh
06302 #if IGNORE_AT_COMMANDS
06303 # if HAS_DAPLINK_SERIAL
06304             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06305 # endif // HAS_DAPLINK_SERIAL
06306 #endif // IGNORE_AT_COMMANDS
06307         }
06308         break;
06309         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
06310         {
06311 #if IGNORE_AT_COMMANDS
06312 # if HAS_DAPLINK_SERIAL
06313             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06314 # endif // HAS_DAPLINK_SERIAL
06315 #endif // IGNORE_AT_COMMANDS
06316         }
06317         break;
06318     } // end switch (cmdLine[0])
06319     return false; // command not handled
06320 } // end bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine)
06321 #endif
06322 
06323 
06324 //--------------------------------------------------
06325 // main menu command-line parser
06326 // invoked by CmdLine::append(char ch) or CmdLine::idleAppendIfReadable()
06327 void main_menu_onEOLcommandParser(CmdLine & cmdLine)
06328 {
06329     // DIAGNOSTIC: print line buffer
06330     //~ cmdLine.serial().printf("\r\nmain_menu_onEOLcommandParser: ~%s~\r\n", cmdLine.str());
06331     //
06332     switch (cmdLine[0])
06333     {
06334         case '?':
06335             main_menu_status(cmdLine);
06336             main_menu_help(cmdLine);
06337             // print command prompt
06338             //cmdLine.serial().printf("\r\n>");
06339             break;
06340         case '\r': case '\n':     // ignore blank line
06341         case '\0':     // ignore empty line
06342         case '#':     // ignore comment line
06343             // # -- lines beginning with # are comments
06344             main_menu_status(cmdLine);
06345             //~ main_menu_help(cmdLine);
06346             // print command prompt
06347             //cmdLine.serial().printf("\r\n>");
06348             break;
06349 #if ECHO_EOF_ON_EOL
06350         case '\x04':     // Unicode (U+0004) EOT END OF TRANSMISSION = CTRL+D as EOF end of file
06351             cmdLine.serial().printf("\x04");     // immediately echo EOF for test scripting
06352             diagnostic_led_EOF();
06353             break;
06354         case '\x1a':     // Unicode (U+001A) SUB SUBSTITUTE = CTRL+Z as EOF end of file
06355             cmdLine.serial().printf("\x1a");     // immediately echo EOF for test scripting
06356             diagnostic_led_EOF();
06357             break;
06358 #endif
06359 #if APPLICATION_ArduinoPinsMonitor
06360         case '.':
06361         {
06362             // . -- SelfTest
06363             cmdLine.serial().printf("SelfTest()");
06364             SelfTest(cmdLine);
06365         }
06366         break;
06367         case '%':
06368         {
06369             pinsMonitor_submenu_onEOLcommandParser(cmdLine);
06370         }
06371         break;         // case '%'
06372 #endif // APPLICATION_ArduinoPinsMonitor
06373        //
06374        // Application-specific commands here
06375        // alphanumeric command codes A-Z,a-z,0-9 reserved for application use
06376        //
06377 #if APPLICATION_ArduinoPinsMonitor
06378 #endif // APPLICATION_ArduinoPinsMonitor
06379 
06380         //
06381         // TODO1: add new commands here
06382         //
06383         default:
06384 #if APPLICATION_MAX5715 // main_menu_onEOLcommandParser print command prompt
06385             extern bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX5715.cpp
06386             if (!MAX5715_menu_onEOLcommandParser(cmdLine))
06387 #elif APPLICATION_MAX11131 // main_menu_onEOLcommandParser print command prompt
06388             extern bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX11131.cpp
06389             if (!MAX11131_menu_onEOLcommandParser(cmdLine))
06390 #elif APPLICATION_MAX5171 // main_menu_onEOLcommandParser print command prompt
06391             extern bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX5171.cpp
06392             if (!MAX5171_menu_onEOLcommandParser(cmdLine))
06393 #elif APPLICATION_MAX11410 // main_menu_onEOLcommandParser print command prompt
06394             extern bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX11410.cpp
06395             if (!MAX11410_menu_onEOLcommandParser(cmdLine))
06396 #elif APPLICATION_MAX12345 // main_menu_onEOLcommandParser print command prompt
06397             extern bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX12345.cpp
06398             if (!MAX12345_menu_onEOLcommandParser(cmdLine))
06399 #else
06400             if (0) // not_handled_by_device_submenu
06401 #endif
06402             {
06403                 cmdLine.serial().printf("\r\n unknown command 0x%2.2x \"%s\"\r\n", cmdLine.str()[0], cmdLine.str());
06404 # if HAS_DAPLINK_SERIAL
06405                 cmdLine_DAPLINKserial.serial().printf("\r\n unknown command 0x%2.2x \"%s\"\r\n",
06406                                                       cmdLine.str()[0], cmdLine.str());
06407 # endif // HAS_DAPLINK_SERIAL
06408             }
06409     }     // switch (cmdLine[0])
06410 //
06411 // print command prompt
06412 #if APPLICATION_MAX5715 // main_menu_onEOLcommandParser print command prompt
06413     cmdLine.serial().printf("\r\nMAX5715 > ");
06414 #elif APPLICATION_MAX11131 // main_menu_onEOLcommandParser print command prompt
06415     cmdLine.serial().printf("\r\nMAX11131 > ");
06416 #elif APPLICATION_MAX5171 // main_menu_onEOLcommandParser print command prompt
06417     cmdLine.serial().printf("\r\nMAX5171 > ");
06418 #elif APPLICATION_MAX11410 // main_menu_onEOLcommandParser print command prompt
06419     cmdLine.serial().printf("\r\nMAX11410 > ");
06420 #elif APPLICATION_MAX12345 // main_menu_onEOLcommandParser print command prompt
06421     cmdLine.serial().printf("\r\nMAX12345 > ");
06422 #else
06423     cmdLine.serial().printf("\r\n> ");
06424 #endif
06425 } // end void main_menu_onEOLcommandParser(CmdLine & cmdLine)
06426 
06427 //--------------------------------------------------
06428 void InitializeConfiguration()
06429 {
06430 
06431 #if APPLICATION_MAX5715 // InitializeConfiguration
06432 # if HAS_DAPLINK_SERIAL
06433     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5715_Init()");
06434 # endif
06435     cmdLine_serial.serial().printf("\r\nMAX5715_Init()");
06436     int initResult = g_MAX5715_device.Init();     // defined in #include MAX5715.h
06437 # if HAS_DAPLINK_SERIAL
06438     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5715_Init() returned %d\r\n", initResult);
06439 # endif
06440     cmdLine_serial.serial().printf("\r\nMAX5715_Init() returned %d\r\n", initResult);
06441 #endif // APPLICATION_MAX5715
06442 
06443 #if APPLICATION_MAX11131 // InitializeConfiguration
06444 # if HAS_DAPLINK_SERIAL
06445     cmdLine_DAPLINKserial.serial().printf("\r\nMAX11131_Init()");
06446 # endif
06447     cmdLine_serial.serial().printf("\r\nMAX11131_Init()");
06448     g_MAX11131_device.Init();     // defined in #include MAX11131.h
06449 #endif // APPLICATION_MAX11131
06450 
06451 #if APPLICATION_MAX5171 // InitializeConfiguration
06452 # if HAS_DAPLINK_SERIAL
06453     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5171_Init()");
06454 # endif
06455     cmdLine_serial.serial().printf("\r\nMAX5171_Init()");
06456     int initResult = g_MAX5171_device.Init();     // defined in #include MAX5171.h
06457 # if HAS_DAPLINK_SERIAL
06458     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5171_Init() returned %d\r\n", initResult);
06459 # endif
06460     cmdLine_serial.serial().printf("\r\nMAX5171_Init() returned %d\r\n", initResult);
06461 #endif // APPLICATION_MAX5171
06462 
06463 #if APPLICATION_MAX11410 // InitializeConfiguration
06464 # if HAS_DAPLINK_SERIAL
06465     cmdLine_DAPLINKserial.serial().printf("\r\nMAX11410_Init()");
06466 # endif
06467     cmdLine_serial.serial().printf("\r\nMAX11410_Init()");
06468     int initResult = g_MAX11410_device.Init();     // defined in #include MAX11410.h
06469 # if HAS_DAPLINK_SERIAL
06470     cmdLine_DAPLINKserial.serial().printf("\r\nMAX11410_Init() returned %d\r\n", initResult);
06471 # endif
06472     cmdLine_serial.serial().printf("\r\nMAX11410_Init() returned %d\r\n", initResult);
06473 #endif // APPLICATION_MAX11410
06474 
06475 #if APPLICATION_MAX12345 // InitializeConfiguration
06476 # if HAS_DAPLINK_SERIAL
06477     cmdLine_DAPLINKserial.serial().printf("\r\nMAX12345_Init()");
06478 # endif
06479     cmdLine_serial.serial().printf("\r\nMAX12345_Init()");
06480     int initResult = g_MAX12345_device.Init();     // defined in #include MAX12345.h
06481 # if HAS_DAPLINK_SERIAL
06482     cmdLine_DAPLINKserial.serial().printf("\r\nMAX12345_Init() returned %d\r\n", initResult);
06483 # endif
06484     cmdLine_serial.serial().printf("\r\nMAX12345_Init() returned %d\r\n", initResult);
06485 #endif // APPLICATION_MAX12345
06486 
06487 }
06488 
06489 //--------------------------------------------------
06490 // diagnostic rbg led GREEN
06491 void diagnostic_led_EOF()
06492 {
06493 #if USE_LEDS
06494     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06495     // TODO1: mbed-os-5.11: [Warning] 'static osStatus rtos::Thread::wait(uint32_t)' is deprecated: Static methods only affecting current thread cause confusion. Replaced by ThisThread::sleep_for. [since mbed-os-5.10] [-Wdeprecated-declarations]
06496     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06497     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06498     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06499     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06500     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06501     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06502     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06503 #endif // USE_LEDS
06504 }
06505 
06506 //--------------------------------------------------
06507 // Support commands that get handled immediately w/o waiting for EOL
06508 // handled as immediate command, do not append to buffer
06509 void on_immediate_0x21() // Unicode (U+0021) ! EXCLAMATION MARK
06510 {
06511 #if USE_LEDS
06512     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
06513 #endif // USE_LEDS
06514     InitializeConfiguration();
06515     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06516 }
06517 
06518 //--------------------------------------------------
06519 // Support commands that get handled immediately w/o waiting for EOL
06520 // handled as immediate command, do not append to buffer
06521 void on_immediate_0x7b() // Unicode (U+007B) { LEFT CURLY BRACKET
06522 {
06523 #if HAS_BUTTON2_DEMO_INTERRUPT
06524     onButton2FallingEdge();
06525 #endif
06526 }
06527 
06528 //--------------------------------------------------
06529 // Support commands that get handled immediately w/o waiting for EOL
06530 // handled as immediate command, do not append to buffer
06531 void on_immediate_0x7d() // Unicode (U+007D) } RIGHT CURLY BRACKET
06532 {
06533 #if HAS_BUTTON1_DEMO_INTERRUPT
06534     onButton1FallingEdge();
06535 #endif
06536 }
06537 
06538 //--------------------------------------------------
06539 // based on example code: https://os.mbed.com/docs/v5.7/reference/pwmout.html
06540 int main()
06541 {
06542     // Configure serial ports
06543 #if defined(TARGET_MAX32630)
06544     // Note: DAPLINKserial interferes with the timer tick interrupt. Try faster baud rate?
06545     DAPLINKserial.baud(115200);     // default 9600 baud
06546     //serial.baud(9600); // class USBSerial has no baud function
06547 #  if HAS_DAPLINK_SERIAL
06548     DAPLINKserial.printf("\r\n\r\nDAPLINK_SERIAL: main() startup\r\n");
06549 #  endif
06550 //--------------------------------------------------
06551 #elif defined(TARGET_MAX32625MBED)
06552     // MAX32625MBED crash if DAPLINKserial.baud(anything other than 9600 baud)
06553     // xxx DAPLINKserial.baud(115200); // default 9600 baud
06554     //serial.baud(9600); // class USBSerial has no baud function
06555 #  if HAS_DAPLINK_SERIAL
06556     DAPLINKserial.printf("\r\n\r\nDAPLINK_SERIAL: main() startup\r\n");
06557 #  endif
06558 //--------------------------------------------------
06559 #elif defined(TARGET_LPC1768)
06560     serial.baud(115200);     // default 9600 baud
06561 #else
06562     // unknown target
06563 #endif
06564     cmdLine_serial.clear();
06565     //~ cmdLine_serial.serial().printf("\r\n cmdLine_serial.serial().printf test\r\n");
06566     cmdLine_serial.onEOLcommandParser = main_menu_onEOLcommandParser;
06567     /// @todo CmdLine::set_immediate_handler(char, functionPointer_void_void_on_immediate_0x21);
06568     cmdLine_serial.on_immediate_0x21 = on_immediate_0x21;
06569     cmdLine_serial.on_immediate_0x7b = on_immediate_0x7b;
06570     cmdLine_serial.on_immediate_0x7d = on_immediate_0x7d;
06571 # if HAS_DAPLINK_SERIAL
06572     cmdLine_DAPLINKserial.clear();
06573     //~ cmdLine_DAPLINKserial.serial().printf("\r\n cmdLine_DAPLINKserial.serial().printf test\r\n");
06574     cmdLine_DAPLINKserial.onEOLcommandParser = main_menu_onEOLcommandParser;
06575     /// @todo CmdLine::set_immediate_handler(char, functionPointer_void_void_on_immediate_0x21);
06576     cmdLine_DAPLINKserial.on_immediate_0x21 = on_immediate_0x21;
06577     cmdLine_DAPLINKserial.on_immediate_0x7b = on_immediate_0x7b;
06578     cmdLine_DAPLINKserial.on_immediate_0x7d = on_immediate_0x7d;
06579 # endif
06580 
06581 
06582     print_banner();
06583 
06584 //#ifdef SCOPE_TRIG_PIN
06585 //    scopePinP12 = 0;
06586 //    scopePinP12 = 1;
06587 //#endif // SCOPE_TRIG_PIN
06588 
06589 #if HAS_BUTTON1_DEMO_INTERRUPT
06590 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
06591 # else
06592     button1.fall(&onButton1FallingEdge);
06593 # endif
06594 #endif // HAS_BUTTON1_DEMO_INTERRUPT
06595 #if HAS_BUTTON2_DEMO_INTERRUPT
06596 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
06597 # else
06598     button2.fall(&onButton2FallingEdge);
06599 # endif
06600 #endif // HAS_BUTTON2_DEMO_INTERRUPT
06601 
06602 #if defined(TARGET_MAX32630)
06603     // Timer tick needs to be the highest priority (priority 0, the default).
06604     // DAPLINKserial interferes with the timer tick interrupt.
06605     // Lower the priority of the serial port interrupts to avoid disrupting onTimerTick() handler.
06606     NVIC_SetPriority(UART0_IRQn, 2); // reservedBlueToothSerial(P0_1, P0_0) // 0=highest priority; 1=lower
06607     NVIC_SetPriority(UART1_IRQn, 2); // DAPLINKserial(P2_1, P2_0) // 0=highest priority; 1=lower
06608     NVIC_SetPriority(UART2_IRQn, 2); // reservedSerial(P3_1, P3_0) // 0=highest priority; 1=lower
06609     NVIC_SetPriority(UART3_IRQn, 2); // reservedSerial(P5_4, P5_3) // 0=highest priority; 1=lower
06610     NVIC_SetPriority(GPIO_P0_IRQn, 2); // 0=highest priority; 1=lower
06611     NVIC_SetPriority(GPIO_P1_IRQn, 2); // 0=highest priority; 1=lower
06612     NVIC_SetPriority(GPIO_P2_IRQn, 2); // 0=highest priority; 1=lower
06613     NVIC_SetPriority(GPIO_P3_IRQn, 2); // 0=highest priority; 1=lower
06614     NVIC_SetPriority(GPIO_P4_IRQn, 2); // 0=highest priority; 1=lower
06615     NVIC_SetPriority(GPIO_P5_IRQn, 2); // 0=highest priority; 1=lower
06616     NVIC_SetPriority(GPIO_P6_IRQn, 2); // 0=highest priority; 1=lower
06617     NVIC_SetPriority(GPIO_P7_IRQn, 2); // 0=highest priority; 1=lower
06618     NVIC_SetPriority(GPIO_P8_IRQn, 2); // 0=highest priority; 1=lower
06619     //~ NVIC_SetPriority(RTC0_IRQn, 0); // 0=highest priority; 1=lower
06620     //~ NVIC_SetPriority(RTC3_IRQn, 0); // 0=highest priority; 1=lower
06621     //~ NVIC_SetPriority(US_TIMER_IRQn, 0); // 0=highest priority; 1=lower
06622 #endif
06623 
06624 #if HAS_SPI
06625     // spi init
06626     // mode | POL PHA
06627     // -----+--------
06628     //   0  |  0   0
06629     //   1  |  0   1
06630     //   2  |  1   0
06631     //   3  |  1   1
06632     //~ spi.format(8,0); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
06633     //~ spi.format(8,1); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=1 falling edge (initial default)
06634     //~ spi.format(8,2); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=0 falling edge (initial default)
06635     //~ spi.format(8,3); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=1 rising edge (initial default)
06636     //
06637     //~ spi.frequency(1000000); // int SCLK_Hz=1000000 = 1MHz (initial default)
06638     //~ spi.frequency(9600000); // int SCLK_Hz=9600000 = 9.6MHz = 96MHz/10
06639     //~ spi.frequency(10666666); // int SCLK_Hz=10666666 = 10.6MHz = 96MHz/9
06640     //~ spi.frequency(12000000); // int SCLK_Hz=12000000 = 12MHz = 96MHz/8
06641     //~ spi.frequency(13714286); // int SCLK_Hz=13714286 = 13.7MHz = 96MHz/7
06642     //~ spi.frequency(16000000); // int SCLK_Hz=16000000 = 16MHz = 96MHz/6
06643     //~ spi.frequency(19200000); // int SCLK_Hz=19200000 = 19.2MHz = 96MHz/5
06644     //~ spi.frequency(24000000); // int SCLK_Hz=24000000 = 24MHz = 96MHz/4
06645     //~ spi.frequency(32000000); // int SCLK_Hz=32000000 = 32MHz = 96MHz/3
06646     //~ spi.frequency(48000000); // int SCLK_Hz=48000000 = 48MHz = 96MHz/2
06647     // unspecified SPI device
06648     spi.format(8,g_SPI_dataMode);     // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
06649     spi.frequency(g_SPI_SCLK_Hz);     // int SCLK_Hz=1000000 = 1MHz (initial default)
06650     spi_cs = 1;
06651 #endif
06652 
06653 #if HAS_I2C
06654 // i2c init
06655 // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
06656 //    i2cMaster.frequency(g_I2C_SCL_Hz);
06657 #else
06658     // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
06659 #if HAS_digitalInOut14
06660     // DigitalInOut digitalInOut14(P1_6, PIN_INPUT, PullUp, 1); // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
06661     digitalInOut14.input();
06662 #endif
06663 #if HAS_digitalInOut15
06664     // DigitalInOut digitalInOut15(P1_7, PIN_INPUT, PullUp, 1); // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
06665     digitalInOut15.input();
06666 #endif
06667 #if HAS_digitalInOut16
06668     // DigitalInOut mode can be one of PullUp, PullDown, PullNone, OpenDrain
06669     // PullUp-->3.4V, PullDown-->1.7V, PullNone-->3.5V, OpenDrain-->0.00V
06670     //DigitalInOut digitalInOut16(P3_4, PIN_INPUT, OpenDrain, 0); // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
06671     digitalInOut16.input();
06672 #endif
06673 #if HAS_digitalInOut17
06674     //DigitalInOut digitalInOut17(P3_5, PIN_INPUT, OpenDrain, 0); // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
06675     digitalInOut17.input();
06676 #endif
06677 #endif
06678 
06679 #if USE_LEDS
06680 #if defined(TARGET_MAX32630)
06681     led1 = LED_ON; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led RED
06682     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06683     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06684     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06685     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
06686     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06687     led1 = LED_ON; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led RED+GREEN+BLUE=WHITE
06688     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06689     led1 = LED_OFF; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led GREEN+BLUE=CYAN
06690     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06691     led1 = LED_ON; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led RED+BLUE=MAGENTA
06692     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06693     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06694     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06695     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led BLACK
06696     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06697 #elif defined(TARGET_MAX32625MBED)
06698     led1 = LED_ON; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led RED
06699     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06700     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06701     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06702     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
06703     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06704     led1 = LED_ON; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led RED+GREEN+BLUE=WHITE
06705     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06706     led1 = LED_OFF; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led GREEN+BLUE=CYAN
06707     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06708     led1 = LED_ON; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led RED+BLUE=MAGENTA
06709     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06710     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06711     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06712     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led BLACK
06713     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06714 #else // not defined(TARGET_LPC1768 etc.)
06715     led1 = LED_ON;
06716     led2 = LED_OFF;
06717     led3 = LED_OFF;
06718     led4 = LED_OFF;
06719     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06720     //led1 = LED_ON;
06721     led2 = LED_ON;
06722     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06723     led1 = LED_OFF;
06724     //led2 = LED_ON;
06725     led3 = LED_ON;
06726     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06727     led2 = LED_OFF;
06728     //led3 = LED_ON;
06729     led4 = LED_ON;
06730     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06731     led3 = LED_OFF;
06732     led4 = LED_ON;
06733     //
06734 #endif // target definition
06735 #endif
06736 
06737     // cmd_TE();
06738 
06739 #if USE_LEDS
06740     rgb_led.white();     // diagnostic rbg led RED+GREEN+BLUE=WHITE
06741 #endif // USE_LEDS
06742     InitializeConfiguration();
06743 
06744     while (1) {
06745 #if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
06746         // avoid runtime error on button1 press [mbed-os-5.11]
06747         // instead of using InterruptIn, use DigitalIn and poll in main while(1)
06748 # if HAS_BUTTON1_DEMO_INTERRUPT
06749         static int button1_value_prev = 1;
06750         static int button1_value_now = 1;
06751         button1_value_prev = button1_value_now;
06752         button1_value_now = button1.read();
06753         if ((button1_value_prev - button1_value_now) == 1)
06754         {
06755             // on button1 falling edge (button1 press)
06756             onButton1FallingEdge();
06757         }
06758 # endif // HAS_BUTTON1_DEMO_INTERRUPT
06759 # if HAS_BUTTON2_DEMO_INTERRUPT
06760         static int button2_value_prev = 1;
06761         static int button2_value_now = 1;
06762         button2_value_prev = button2_value_now;
06763         button2_value_now = button2.read();
06764         if ((button2_value_prev - button2_value_now) == 1)
06765         {
06766             // on button2 falling edge (button2 press)
06767             onButton2FallingEdge();
06768         }
06769 # endif // HAS_BUTTON2_DEMO_INTERRUPT
06770 #endif
06771     # if HAS_DAPLINK_SERIAL
06772         if (DAPLINKserial.readable()) {
06773             cmdLine_DAPLINKserial.append(DAPLINKserial.getc());
06774         }
06775     # endif // HAS_DAPLINK_SERIAL
06776         if (serial.readable()) {
06777             int c = serial.getc();
06778             cmdLine_serial.append(c);
06779 #if IGNORE_AT_COMMANDS
06780 # if HAS_DAPLINK_SERIAL
06781             cmdLine_DAPLINKserial.serial().printf("%c", c);
06782 # endif // HAS_DAPLINK_SERIAL
06783 #endif // IGNORE_AT_COMMANDS
06784             //
06785         }
06786     }     // while(1)
06787 }