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 // USE_LEDS with some platform other than MAX32630, MAX32625MBED, LPC1768
01764 // bugfix for MAX32600MBED LED blink pattern: check if LED_ON/LED_OFF already defined
01765 # ifndef LED_ON
01766 #  define LED_ON  0
01767 # endif
01768 # ifndef LED_OFF
01769 #  define LED_OFF 1
01770 # endif
01771 //# define LED_ON  1
01772 //# define LED_OFF 0
01773 #endif // target definition
01774 DigitalOut led1(LED1, LED_OFF); // MAX32630FTHR: LED1 = LED_RED
01775 DigitalOut led2(LED2, LED_OFF); // MAX32630FTHR: LED2 = LED_GREEN
01776 DigitalOut led3(LED3, LED_OFF); // MAX32630FTHR: LED3 = LED_BLUE
01777 DigitalOut led4(LED4, LED_OFF);
01778 #else // USE_LEDS=0
01779 // issue #41 support Nucleo_F446RE
01780 // there are no LED indicators on the board, LED1 interferes with SPI;
01781 // but we still need placeholders led1 led2 led3 led4.
01782 // Declare DigitalOut led1 led2 led3 led4 targeting safe pins.
01783 // PinName NC means NOT_CONNECTED; DigitalOut::is_connected() returns false
01784 # define LED_ON  0
01785 # define LED_OFF 1
01786 DigitalOut led1(NC, LED_OFF);
01787 DigitalOut led2(NC, LED_OFF);
01788 DigitalOut led3(NC, LED_OFF);
01789 DigitalOut led4(NC, LED_OFF);
01790 #endif // USE_LEDS
01791 
01792 //--------------------------------------------------
01793 #if USE_LEDS
01794 class RGB_LED {
01795 public:
01796     RGB_LED(DigitalOut &led_red, DigitalOut &led_green, DigitalOut &led_blue)
01797         : m_red(led_red), m_green(led_green), m_blue(led_blue)
01798     {
01799     };
01800     DigitalOut &m_red;
01801     DigitalOut &m_green;
01802     DigitalOut &m_blue;
01803     ~RGB_LED()
01804     {
01805     };
01806     /* diagnostic rbg led RED
01807      */
01808     void red() {
01809         m_red = LED_ON; m_green = LED_OFF; m_blue = LED_OFF; // diagnostic rbg led RED
01810     };
01811     /* diagnostic rbg led GREEN
01812      */
01813     void green() {
01814         m_red = LED_OFF; m_green = LED_ON; m_blue = LED_OFF; // diagnostic rbg led GREEN
01815     };
01816     /* diagnostic rbg led BLUE
01817      */
01818     void blue() {
01819         m_red = LED_OFF; m_green = LED_OFF; m_blue = LED_ON; // diagnostic rbg led BLUE
01820     };
01821     /* diagnostic rbg led RED+GREEN+BLUE=WHITE
01822      */
01823     void white() {
01824         m_red = LED_ON; m_green = LED_ON; m_blue = LED_ON; // diagnostic rbg led RED+GREEN+BLUE=WHITE
01825     };
01826     /* diagnostic rbg led GREEN+BLUE=CYAN
01827      */
01828     void cyan() {
01829         m_red = LED_OFF; m_green = LED_ON; m_blue = LED_ON; // diagnostic rbg led GREEN+BLUE=CYAN
01830     };
01831     /* diagnostic rbg led RED+BLUE=MAGENTA
01832      */
01833     void magenta() {
01834         m_red = LED_ON; m_green = LED_OFF; m_blue = LED_ON; // diagnostic rbg led RED+BLUE=MAGENTA
01835     };
01836     /* diagnostic rbg led RED+GREEN=YELLOW
01837      */
01838     void yellow() {
01839         m_red = LED_ON; m_green = LED_ON; m_blue = LED_OFF; // diagnostic rbg led RED+GREEN=YELLOW
01840     };
01841     /* diagnostic rbg led BLACK
01842      */
01843     void black() {
01844         m_red = LED_OFF; m_green = LED_OFF; m_blue = LED_OFF; // diagnostic rbg led BLACK
01845     };
01846 };
01847 RGB_LED rgb_led(led1, led2, led3); // red, green, blue LEDs
01848 #endif // USE_LEDS
01849 
01850 //--------------------------------------------------
01851 // use BUTTON1 trigger some action
01852 #if defined(TARGET_MAX32630)
01853 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01854 #define HAS_BUTTON2_DEMO 0
01855 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01856 #elif defined(TARGET_MAX32625PICO)
01857 #warning "TARGET_MAX32625PICO not previously tested; need to define buttons..."
01858 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01859 #define HAS_BUTTON2_DEMO 0
01860 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01861 #elif defined(TARGET_MAX32625)
01862 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01863 #define HAS_BUTTON2_DEMO_INTERRUPT 1
01864 #elif defined(TARGET_MAX32620FTHR)
01865 #warning "TARGET_MAX32620FTHR not previously tested; need to define buttons..."
01866 #define BUTTON1 SW1
01867 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01868 #define HAS_BUTTON2_DEMO 0
01869 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01870 #elif defined(TARGET_NUCLEO_F446RE)
01871 #define HAS_BUTTON1_DEMO_INTERRUPT 0
01872 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01873 #elif defined(TARGET_NUCLEO_F401RE)
01874 #define HAS_BUTTON1_DEMO_INTERRUPT 0
01875 #define HAS_BUTTON2_DEMO_INTERRUPT 0
01876 #else
01877 #warning "target not previously tested; need to define buttons..."
01878 #endif
01879 //
01880 #ifndef HAS_BUTTON1_DEMO
01881 #define HAS_BUTTON1_DEMO 0
01882 #endif
01883 #ifndef HAS_BUTTON2_DEMO
01884 #define HAS_BUTTON2_DEMO 0
01885 #endif
01886 //
01887 // avoid runtime error on button1 press [mbed-os-5.11]
01888 // instead of using InterruptIn, use DigitalIn and poll in main while(1)
01889 #ifndef HAS_BUTTON1_DEMO_INTERRUPT_POLLING
01890 #define HAS_BUTTON1_DEMO_INTERRUPT_POLLING 1
01891 #endif
01892 //
01893 #ifndef HAS_BUTTON1_DEMO_INTERRUPT
01894 #define HAS_BUTTON1_DEMO_INTERRUPT 1
01895 #endif
01896 #ifndef HAS_BUTTON2_DEMO_INTERRUPT
01897 #define HAS_BUTTON2_DEMO_INTERRUPT 1
01898 #endif
01899 //
01900 #if HAS_BUTTON1_DEMO_INTERRUPT
01901 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
01902 // avoid runtime error on button1 press [mbed-os-5.11]
01903 // instead of using InterruptIn, use DigitalIn and poll in main while(1)
01904 DigitalIn button1(BUTTON1);
01905 # else
01906 InterruptIn button1(BUTTON1);
01907 # endif
01908 #elif HAS_BUTTON1_DEMO
01909 DigitalIn button1(BUTTON1);
01910 #endif
01911 #if HAS_BUTTON2_DEMO_INTERRUPT
01912 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
01913 // avoid runtime error on button1 press [mbed-os-5.11]
01914 // instead of using InterruptIn, use DigitalIn and poll in main while(1)
01915 DigitalIn button2(BUTTON2);
01916 # else
01917 InterruptIn button2(BUTTON2);
01918 # endif
01919 #elif HAS_BUTTON2_DEMO
01920 DigitalIn button2(BUTTON2);
01921 #endif
01922 
01923 //--------------------------------------------------
01924 // Ticker is the periodic interrupt timer itself
01925 #ifndef USE_PERIODIC_TIMER
01926 #define USE_PERIODIC_TIMER 0
01927 #endif
01928 #if USE_PERIODIC_TIMER
01929 Ticker periodicInterruptTimer;
01930 us_timestamp_t periodicInterruptTimer_interval_usec = 50;
01931 us_timestamp_t periodicInterruptTimer_interval_usec_MAX = 1000;
01932 us_timestamp_t periodicInterruptTimer_interval_usec_MIN = 20;
01933 #endif
01934 
01935 
01936 #if APPLICATION_MAX11131 // hardware interface functions
01937 //----------------------------------------
01938 void print_value(CmdLine& cmdLine, int16_t value_u12, int channelId)
01939 {
01940     int channelPairIndex = channelId / 2;
01941     // 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
01942     // unused variable: int UCHn = (g_MAX11131_device.UNIPOLAR >> (10 - channelPairIndex)) & 0x01;
01943     int BCHn = (g_MAX11131_device.BIPOLAR >> (10 - channelPairIndex)) & 0x01;
01944     // unused variable: int RANGEn = (g_MAX11131_device.RANGE >> (10 - channelPairIndex)) & 0x01;
01945     //
01946     cmdLine.serial().printf(" ch=");
01947     // TODO1: if CHANID=0 don't print ch=channelId
01948     if ((g_MAX11131_device.isExternalClock == 0) || (g_MAX11131_device.chan_id_0_1 == 1))
01949     {
01950         // Internal clock modes always use channel ID.
01951         // External clock modes use channel ID if ADC_MODE_CONTROL.CHAN_ID is 1.
01952         cmdLine.serial().printf("%d", channelId);
01953     } else {
01954         cmdLine.serial().printf("?");
01955     }
01956     if (BCHn)
01957     {
01958         cmdLine.serial().printf(" xb=%ld", g_MAX11131_device.TwosComplementValue(value_u12));
01959     }
01960     else
01961     {
01962         cmdLine.serial().printf(" xu=%d", value_u12);
01963     }
01964     cmdLine.serial().printf(" = 0x%4.4x = %6.4fV",
01965                             (value_u12 & 0xFFFF),
01966                             g_MAX11131_device.VoltageOfCode(value_u12, channelId)
01967                             );
01968     // dtostrf width and precision: 2.5v / 4096 LSB = 0.0006103515625 volts per LSB
01969 }
01970 
01971 //----------------------------------------
01972 // read data words
01973 // @pre RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
01974 // @pre AINcode[NUM_CHANNELS] contains the latest readings in LSBs
01975 // For internal clock modes, the data format always includes the channel address.
01976 //     misoData16 = CH[3:0] DATA[11:0]
01977 void AINcode_print_value_chanID(CmdLine& cmdLine, int nWords)
01978 {
01979     cmdLine.serial().printf("ScanRead_nWords_chanID nWords=%d\r\n", nWords);
01980     for (int index = 0; index < nWords; index++) {
01981         //~ int16_t misoData16 = MAX11131_ScanRead();
01982         // For internal clock modes, the data format always includes the channel address.
01983         //     misoData16 = CH[3:0] DATA[11:0]
01984         int16_t value_u12 = (g_MAX11131_device.RAW_misoData16[index] & 0x0FFF);
01985         int channelId = ((g_MAX11131_device.RAW_misoData16[index] >> 12) & 0x000F);
01986         // diagnostic: print raw MISO data
01987         cmdLine.serial().printf("      MAX11131.MISO[%u]=0x%4.4x:", index,
01988                                 (g_MAX11131_device.RAW_misoData16[index] & 0xFFFF));
01989         print_value(cmdLine, value_u12, channelId);
01990         cmdLine.serial().printf("\r\n");
01991     }
01992 }
01993 
01994 //----------------------------------------
01995 // read data words
01996 // @pre RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
01997 // @pre AINcode[NUM_CHANNELS] contains the latest readings in LSBs
01998 // For external clock modes, the data format returned depends on the CHAN_ID bit.
01999 //     when CHAN_ID = 0: misoData16 = 0 DATA[11:0] x x x
02000 //     when CHAN_ID = 1: misoData16 = CH[3:0] DATA[11:0]
02001 void AINcode_print_value_externalClock(CmdLine& cmdLine, int nWords)
02002 {
02003     // For external clock modes, the data format returned depends on the CHAN_ID bit.
02004     //     when CHAN_ID = 0: misoData16 = 0 DATA[11:0] x x x
02005     //     when CHAN_ID = 1: misoData16 = CH[3:0] DATA[11:0]
02006     // For internal clock modes, the data format always includes the channel address.
02007     //     misoData16 = CH[3:0] DATA[11:0]
02008     if (g_MAX11131_device.chan_id_0_1 != 0) {
02009         AINcode_print_value_chanID(cmdLine, nWords);
02010         return;
02011     }
02012     cmdLine.serial().printf("ScanRead_nWords_externalClock nWords=%d\r\n", nWords);
02013     for (int index = 0; index < nWords; index++) {
02014         // int16_t misoData16 = MAX11131_ScanRead();
02015         int16_t value_u12 = ((g_MAX11131_device.RAW_misoData16[index] >> 3) & 0x0FFF);
02016         int channelId = g_MAX11131_device.channelNumber_0_15;
02017         // diagnostic: print raw MISO data
02018         cmdLine.serial().printf("      MAX11131.MISO[%u]=0x%4.4x:", index,
02019                                 (g_MAX11131_device.RAW_misoData16[index] & 0xFFFF));
02020         print_value(cmdLine, value_u12, channelId);
02021         cmdLine.serial().printf("\r\n");
02022     }
02023 }
02024 
02025 //----------------------------------------
02026 // read data words and calculate mean, stddev
02027 // @pre RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
02028 // @pre AINcode[NUM_CHANNELS] contains the latest readings in LSBs
02029 void AINcode_print_value_chanID_mean(CmdLine& cmdLine, int nWords)
02030 {
02031     cmdLine.serial().printf("ScanRead_nWords_chanID_mean nWords=%d\r\n", nWords);
02032     double Sx = 0;
02033     double Sxx = 0;
02034     for (int index = 0; index < nWords; index++) {
02035         //~ int16_t misoData16 = MAX11131_ScanRead();
02036         // For internal clock modes, the data format always includes the channel address.
02037         //     misoData16 = CH[3:0] DATA[11:0]
02038         int16_t value_u12 = (g_MAX11131_device.RAW_misoData16[index] & 0x0FFF);
02039         int channelId = ((g_MAX11131_device.RAW_misoData16[index] >> 12) & 0x000F);
02040         // TODO: sign-extend value_s12 from value_u12
02041         //
02042         cmdLine.serial().printf("n=%d", index);
02043         print_value(cmdLine, value_u12, channelId);
02044         //
02045         Sx = Sx + value_u12;
02046         Sxx = Sxx + ((double)value_u12 * value_u12);
02047         cmdLine.serial().printf(" Sx=%f Sxx=%f\r\n", Sx, Sxx);
02048     }
02049     double mean = Sx / nWords;
02050     cmdLine.serial().printf("  mean=%f=0x%4.4x", mean, (int)mean);
02051     // calculate standard deviation from N, Sx, Sxx
02052     if (nWords >= 2)
02053     {
02054         double variance = (Sxx - ( Sx * Sx / nWords)) / (nWords - 1);
02055         // stddev = square root of variance
02056         double stddev = sqrt(variance);
02057         cmdLine.serial().printf("  variance=%f  stddev=%f", variance, stddev);
02058     }
02059     cmdLine.serial().printf("\r\n");
02060 }
02061 
02062 /* MAX11131_print_register_verbose
02063  *
02064  * TODO: document this function
02065  * This header was inserted by uncrustify; see uncrustify_func_header.txt.
02066  *
02067  */
02068 void MAX11131_print_register_verbose(CmdLine& cmdLine, int16_t registerData)
02069 {
02070     if (registerData & 0x8000)
02071     {
02072         switch (registerData & 0xF800)
02073         {
02074             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
02075                 cmdLine.serial().printf(" ADC_CONFIGURATION");
02076                 {
02077                     // define write-only register ADC_CONFIGURATION
02078                     //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
02079                     const int REFSEL_LSB = 10; const int REFSEL_BITS = 0x01; // ADC_CONFIGURATION.REFSEL
02080                     const int AVGON_LSB = 9; const int AVGON_BITS = 0x01; // ADC_CONFIGURATION.AVGON
02081                     const int NAVG_LSB = 7; const int NAVG_BITS = 0x03; // ADC_CONFIGURATION.NAVG[1:0]
02082                     const int NSCAN_LSB = 5; const int NSCAN_BITS = 0x03; // ADC_CONFIGURATION.NSCAN[1:0]
02083                     const int SPM_LSB = 3; const int SPM_BITS = 0x03; // ADC_CONFIGURATION.SPM[1:0]
02084                     const int ECHO_LSB = 2; const int ECHO_BITS = 0x01; // ADC_CONFIGURATION.ECHO
02085 
02086                     const int REFSEL = ((registerData >> REFSEL_LSB) & REFSEL_BITS);
02087                     const int AVGON = ((registerData >> AVGON_LSB) & AVGON_BITS);
02088                     const int NAVG = ((registerData >> NAVG_LSB) & NAVG_BITS);
02089                     const int NSCAN = ((registerData >> NSCAN_LSB) & NSCAN_BITS);
02090                     const int SPM = ((registerData >> SPM_LSB) & SPM_BITS);
02091                     const int ECHO = ((registerData >> ECHO_LSB) & ECHO_BITS);
02092 
02093                     if (REFSEL) {
02094                         cmdLine.serial().printf(" REFSEL=%d", REFSEL);
02095                     }
02096                     if (AVGON) {
02097                         cmdLine.serial().printf(" AVGON=%d", AVGON);
02098                     }
02099                     if (NAVG) {
02100                         cmdLine.serial().printf(" NAVG=%d", NAVG);
02101                     }
02102                     if (NSCAN) {
02103                         cmdLine.serial().printf(" NSCAN=%d", NSCAN);
02104                     }
02105                     if (SPM) {
02106                         cmdLine.serial().printf(" SPM=%d", SPM);
02107                     }
02108                     if (ECHO) {
02109                         cmdLine.serial().printf(" ECHO=%d", ECHO);
02110                     }
02111                 }
02112                 break;
02113             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
02114                 cmdLine.serial().printf(" UNIPOLAR 0x%4.4x", ((registerData >> 3) & 0xFF));
02115                 if ((registerData >> 2) & 0x01) {
02116                     cmdLine.serial().printf(" PDIFF_COM");
02117                 }
02118                 break;
02119             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
02120                 cmdLine.serial().printf(" BIPOLAR  0x%4.4x", ((registerData >> 3) & 0xFF));
02121                 break;
02122             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
02123                 cmdLine.serial().printf(" RANGE    0x%4.4x", ((registerData >> 3) & 0xFF));
02124                 break;
02125             case 0xA000: // CSCAN0 0xA000..0xA7FF format: 1 0 1 0 0 CHSCAN15 CHSCAN14 CHSCAN13 CHSCAN12 CHSCAN11 CHSCAN10 CHSCAN9 CHSCAN8 x x x
02126                 cmdLine.serial().printf(" CSCAN0 0x%4.4x", ((registerData >> 3) & 0xFF));
02127                 break;
02128             case 0xA800: // CSCAN1 0xA800..0xAFFF format: 1 0 1 0 1 CHSCAN7 CHSCAN6 CHSCAN5 CHSCAN4 CHSCAN3 CHSCAN2 CHSCAN1 CHSCAN0 x x x
02129                 cmdLine.serial().printf(" CSCAN1 0x%4.4x", ((registerData >> 3) & 0xFF));
02130                 break;
02131             case 0xB000: // SAMPLESET 0xB000..0xB7FF format: 1 0 1 1 0 SEQ_LENGTH[7:0] x x x
02132                 cmdLine.serial().printf(" SAMPLESET SEQ_LENGTH[7:0]=0x%4.4x", ((registerData >> 3) & 0xFF));
02133                 cmdLine.serial().printf(" so length=%d channels", (((registerData >> 3) & 0xFF) + 1));
02134                 break;
02135             default:
02136                 cmdLine.serial().printf(" ???");
02137                 break;
02138         }
02139     }
02140     else
02141     {
02142         // ADC_MODE_CONTROL 0x0000..0x7FFF format: 0 SCAN[3:0] CHSEL[3:0] RESET[1:0] PM[1:0] CHAN_ID SWCNV 0
02143         cmdLine.serial().printf(" ADC_MODE_CONTROL");
02144 
02145         // define write-only register ADC_MODE_CONTROL
02146         //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
02147         const int SCAN_LSB = 11; const int SCAN_BITS = 0x0F;   //!< ADC_MODE_CONTROL.SCAN[3:0] ADC Scan Control (command)
02148         const int CHSEL_LSB = 7; const int CHSEL_BITS = 0x0F;  //!< ADC_MODE_CONTROL.CHSEL[3:0] Analog Input Channel Select AIN0..AIN15
02149         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
02150         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
02151         const int CHAN_ID_LSB = 2; const int CHAN_ID_BITS = 0x01; //!< ADC_MODE_CONTROL.CHAN_ID
02152         const int SWCNV_LSB = 1; const int SWCNV_BITS = 0x01;  //!< ADC_MODE_CONTROL.SWCNV
02153 
02154         const int SCAN = ((registerData >> SCAN_LSB) & SCAN_BITS);
02155         const int CHSEL = ((registerData >> CHSEL_LSB) & CHSEL_BITS);
02156         const int RESET = ((registerData >> RESET_LSB) & RESET_BITS);
02157         const int PM = ((registerData >> PM_LSB) & PM_BITS);
02158         const int CHANID = ((registerData >> CHAN_ID_LSB) & CHAN_ID_BITS);
02159         const int SWCNV = ((registerData >> SWCNV_LSB) & SWCNV_BITS);
02160 
02161         switch (SCAN)
02162         {
02163             case MAX11131::SCAN_0000_NOP:
02164                 cmdLine.serial().printf(" SCAN_0000_NOP");
02165                 break;
02166             case MAX11131::SCAN_0001_Manual:
02167                 cmdLine.serial().printf(" SCAN_0001_Manual CHSEL=%d", CHSEL);
02168                 break;
02169             case MAX11131::SCAN_0010_Repeat:
02170                 cmdLine.serial().printf(" SCAN_0010_Repeat CHSEL=%d", CHSEL);
02171                 break;
02172             case MAX11131::SCAN_0011_StandardInternalClock:
02173                 cmdLine.serial().printf(" SCAN_0011_StandardInt CHSEL=%d", CHSEL);
02174                 break;
02175             case MAX11131::SCAN_0100_StandardExternalClock:
02176                 cmdLine.serial().printf(" SCAN_0100_StandardExt CHSEL=%d", CHSEL);
02177                 break;
02178             case MAX11131::SCAN_0101_UpperInternalClock:
02179                 cmdLine.serial().printf(" SCAN_0101_UpperInt CHSEL=%d", CHSEL);
02180                 break;
02181             case MAX11131::SCAN_0110_UpperExternalClock:
02182                 cmdLine.serial().printf(" SCAN_0110_UpperExt CHSEL=%d", CHSEL);
02183                 break;
02184             case MAX11131::SCAN_0111_CustomInternalClock:
02185                 cmdLine.serial().printf(" SCAN_0111_CustomInt");
02186                 break;
02187             case MAX11131::SCAN_1000_CustomExternalClock:
02188                 cmdLine.serial().printf(" SCAN_1000_CustomExt");
02189                 break;
02190             case MAX11131::SCAN_1001_SampleSetExternalClock:
02191                 cmdLine.serial().printf(" SCAN_1001_SampleSetExt");
02192                 break;
02193             default:
02194                 cmdLine.serial().printf(" SCAN=%d", SCAN);
02195                 cmdLine.serial().printf(" CHSEL=%d", CHSEL);
02196         }
02197         if (RESET) {
02198             cmdLine.serial().printf(" RESET=%d", RESET);
02199         }
02200         if (PM) {
02201             cmdLine.serial().printf(" PM=%d", PM);
02202         }
02203         if (SCAN != MAX11131::SCAN_0000_NOP)
02204         {
02205             if (g_MAX11131_device.isExternalClock)
02206             {
02207                 // if external clock mode, print CHANID
02208                 cmdLine.serial().printf(" CHANID=%d", CHANID);
02209             }
02210             else
02211             {
02212                 // if internal clock mode, print SWCNV
02213                 cmdLine.serial().printf(" SWCNV=%d", SWCNV);
02214             }
02215         }
02216     }
02217     cmdLine.serial().printf("\r\n");
02218 }
02219 #endif
02220 
02221 
02222 #if APPLICATION_MAX5171 // hardware interface functions
02223 #endif
02224 
02225 
02226 #if APPLICATION_MAX11410 // hardware interface functions
02227 #endif
02228 
02229 
02230 #if APPLICATION_MAX12345 // hardware interface functions
02231 #endif
02232 
02233 
02234 //--------------------------------------------------
02235 // print banner message to serial port
02236 void print_banner()
02237 {
02238 #if HAS_DAPLINK_SERIAL
02239     DAPLINKserial.printf("\r\n");
02240 # if defined(TARGET_MAX32630)
02241     DAPLINKserial.printf("MAX32630");
02242 # elif defined(TARGET_MAX32625MBED)
02243     DAPLINKserial.printf("MAX32625MBED");
02244 # elif defined(TARGET_NUCLEO_F446RE)
02245     DAPLINKserial.printf("NUCLEO_F446RE");
02246 # elif defined(TARGET_NUCLEO_F401RE)
02247     DAPLINKserial.printf("NUCLEO_F401RE");
02248 # elif defined(TARGET_LPC1768)
02249     DAPLINKserial.printf("LPC1768");
02250 # else
02251     // unknown target
02252     DAPLINKserial.printf("unknownTarget");
02253 # endif
02254     DAPLINKserial.printf(" DAPLINKserial\r\n");
02255 #endif // HAS_DAPLINK_SERIAL
02256 
02257     serial.printf("\r\n");
02258 # if defined(TARGET_MAX32630)
02259     serial.printf("MAX32630");
02260 # elif defined(TARGET_MAX32625MBED)
02261     serial.printf("MAX32625MBED");
02262 # elif defined(TARGET_NUCLEO_F446RE)
02263     serial.printf("NUCLEO_F446RE");
02264 # elif defined(TARGET_NUCLEO_F401RE)
02265     serial.printf("NUCLEO_F401RE");
02266 # elif defined(TARGET_LPC1768)
02267     serial.printf("LPC1768");
02268 # else
02269     // unknown target
02270     serial.printf("unknownTarget");
02271 # endif
02272     serial.printf(" Tester\r\n");
02273 }
02274 
02275 // DigitalInOut pin resource: print the pin index names to serial
02276 #if HAS_digitalInOuts
02277 void list_digitalInOutPins(Stream& serialStream)
02278 {
02279 #if HAS_digitalInOut0
02280     serialStream.printf(" 0");
02281 #endif
02282 #if HAS_digitalInOut1
02283     serialStream.printf(" 1");
02284 #endif
02285 #if HAS_digitalInOut2
02286     serialStream.printf(" 2");
02287 #endif
02288 #if HAS_digitalInOut3
02289     serialStream.printf(" 3");
02290 #endif
02291 #if HAS_digitalInOut4
02292     serialStream.printf(" 4");
02293 #endif
02294 #if HAS_digitalInOut5
02295     serialStream.printf(" 5");
02296 #endif
02297 #if HAS_digitalInOut6
02298     serialStream.printf(" 6");
02299 #endif
02300 #if HAS_digitalInOut7
02301     serialStream.printf(" 7");
02302 #endif
02303 #if HAS_digitalInOut8
02304     serialStream.printf(" 8");
02305 #endif
02306 #if HAS_digitalInOut9
02307     serialStream.printf(" 9");
02308 #endif
02309 #if HAS_digitalInOut10
02310     serialStream.printf(" 10");
02311 #endif
02312 #if HAS_digitalInOut11
02313     serialStream.printf(" 11");
02314 #endif
02315 #if HAS_digitalInOut12
02316     serialStream.printf(" 12");
02317 #endif
02318 #if HAS_digitalInOut13
02319     serialStream.printf(" 13");
02320 #endif
02321 #if HAS_digitalInOut14
02322     serialStream.printf(" 14");
02323 #endif
02324 #if HAS_digitalInOut15
02325     serialStream.printf(" 15");
02326 #endif
02327 #if HAS_digitalInOut16
02328     serialStream.printf(" 16");
02329 #endif
02330 #if HAS_digitalInOut17
02331     serialStream.printf(" 17");
02332 #endif
02333 }
02334 #endif
02335 
02336 // DigitalInOut pin resource: present?
02337 #if HAS_digitalInOuts
02338 bool has_digitalInOutPin(int cPinIndex)
02339 {
02340     switch (cPinIndex)
02341     {
02342 #if HAS_digitalInOut0
02343         case '0': case 0x00: return true;
02344 #endif
02345 #if HAS_digitalInOut1
02346         case '1': case 0x01: return true;
02347 #endif
02348 #if HAS_digitalInOut2
02349         case '2': case 0x02: return true;
02350 #endif
02351 #if HAS_digitalInOut3
02352         case '3': case 0x03: return true;
02353 #endif
02354 #if HAS_digitalInOut4
02355         case '4': case 0x04: return true;
02356 #endif
02357 #if HAS_digitalInOut5
02358         case '5': case 0x05: return true;
02359 #endif
02360 #if HAS_digitalInOut6
02361         case '6': case 0x06: return true;
02362 #endif
02363 #if HAS_digitalInOut7
02364         case '7': case 0x07: return true;
02365 #endif
02366 #if HAS_digitalInOut8
02367         case '8': case 0x08: return true;
02368 #endif
02369 #if HAS_digitalInOut9
02370         case '9': case 0x09: return true;
02371 #endif
02372 #if HAS_digitalInOut10
02373         case 'a': case 0x0a: return true;
02374 #endif
02375 #if HAS_digitalInOut11
02376         case 'b': case 0x0b: return true;
02377 #endif
02378 #if HAS_digitalInOut12
02379         case 'c': case 0x0c: return true;
02380 #endif
02381 #if HAS_digitalInOut13
02382         case 'd': case 0x0d: return true;
02383 #endif
02384 #if HAS_digitalInOut14
02385         case 'e': case 0x0e: return true;
02386 #endif
02387 #if HAS_digitalInOut15
02388         case 'f': case 0x0f: return true;
02389 #endif
02390         default:
02391             return false;
02392     }
02393 }
02394 #endif
02395 
02396 // DigitalInOut pin resource: search index
02397 #if HAS_digitalInOuts
02398 DigitalInOut& find_digitalInOutPin(int cPinIndex)
02399 {
02400     switch (cPinIndex)
02401     {
02402         default: // default to the first defined digitalInOut pin
02403 #if HAS_digitalInOut0
02404         case '0': case 0x00: return digitalInOut0;
02405 #endif
02406 #if HAS_digitalInOut1
02407         case '1': case 0x01: return digitalInOut1;
02408 #endif
02409 #if HAS_digitalInOut2
02410         case '2': case 0x02: return digitalInOut2;
02411 #endif
02412 #if HAS_digitalInOut3
02413         case '3': case 0x03: return digitalInOut3;
02414 #endif
02415 #if HAS_digitalInOut4
02416         case '4': case 0x04: return digitalInOut4;
02417 #endif
02418 #if HAS_digitalInOut5
02419         case '5': case 0x05: return digitalInOut5;
02420 #endif
02421 #if HAS_digitalInOut6
02422         case '6': case 0x06: return digitalInOut6;
02423 #endif
02424 #if HAS_digitalInOut7
02425         case '7': case 0x07: return digitalInOut7;
02426 #endif
02427 #if HAS_digitalInOut8
02428         case '8': case 0x08: return digitalInOut8;
02429 #endif
02430 #if HAS_digitalInOut9
02431         case '9': case 0x09: return digitalInOut9;
02432 #endif
02433 #if HAS_digitalInOut10
02434         case 'a': case 0x0a: return digitalInOut10;
02435 #endif
02436 #if HAS_digitalInOut11
02437         case 'b': case 0x0b: return digitalInOut11;
02438 #endif
02439 #if HAS_digitalInOut12
02440         case 'c': case 0x0c: return digitalInOut12;
02441 #endif
02442 #if HAS_digitalInOut13
02443         case 'd': case 0x0d: return digitalInOut13;
02444 #endif
02445 #if HAS_digitalInOut14
02446         case 'e': case 0x0e: return digitalInOut14;
02447 #endif
02448 #if HAS_digitalInOut15
02449         case 'f': case 0x0f: return digitalInOut15;
02450 #endif
02451 #if HAS_digitalInOut16
02452         case 'g': case 0x10: return digitalInOut16;
02453 #endif
02454 #if HAS_digitalInOut17
02455         case 'h': case 0x11: return digitalInOut17;
02456 #endif
02457     }
02458 }
02459 #endif
02460 
02461 // AnalogIn pin resource: print the pin index names to serial
02462 #if HAS_analogIns
02463 void list_analogInPins(Stream& serialStream)
02464 {
02465 #if HAS_analogIn0
02466     serialStream.printf(" 0");
02467 #endif
02468 #if HAS_analogIn1
02469     serialStream.printf(" 1");
02470 #endif
02471 #if HAS_analogIn2
02472     serialStream.printf(" 2");
02473 #endif
02474 #if HAS_analogIn3
02475     serialStream.printf(" 3");
02476 #endif
02477 #if HAS_analogIn4
02478     serialStream.printf(" 4");
02479 #endif
02480 #if HAS_analogIn5
02481     serialStream.printf(" 5");
02482 #endif
02483 #if HAS_analogIn6
02484     serialStream.printf(" 6");
02485 #endif
02486 #if HAS_analogIn7
02487     serialStream.printf(" 7");
02488 #endif
02489 #if HAS_analogIn8
02490     serialStream.printf(" 8");
02491 #endif
02492 #if HAS_analogIn9
02493     serialStream.printf(" 9");
02494 #endif
02495 #if HAS_analogIn10
02496     serialStream.printf(" a");
02497 #endif
02498 #if HAS_analogIn11
02499     serialStream.printf(" b");
02500 #endif
02501 #if HAS_analogIn12
02502     serialStream.printf(" c");
02503 #endif
02504 #if HAS_analogIn13
02505     serialStream.printf(" d");
02506 #endif
02507 #if HAS_analogIn14
02508     serialStream.printf(" e");
02509 #endif
02510 #if HAS_analogIn15
02511     serialStream.printf(" f");
02512 #endif
02513 }
02514 #endif
02515 
02516 // AnalogIn pin resource: present?
02517 #if HAS_analogIns
02518 bool has_analogInPin(int cPinIndex)
02519 {
02520     switch (cPinIndex)
02521     {
02522 #if HAS_analogIn0
02523         case '0': case 0x00: return true;
02524 #endif
02525 #if HAS_analogIn1
02526         case '1': case 0x01: return true;
02527 #endif
02528 #if HAS_analogIn2
02529         case '2': case 0x02: return true;
02530 #endif
02531 #if HAS_analogIn3
02532         case '3': case 0x03: return true;
02533 #endif
02534 #if HAS_analogIn4
02535         case '4': case 0x04: return true;
02536 #endif
02537 #if HAS_analogIn5
02538         case '5': case 0x05: return true;
02539 #endif
02540 #if HAS_analogIn6
02541         case '6': case 0x06: return true;
02542 #endif
02543 #if HAS_analogIn7
02544         case '7': case 0x07: return true;
02545 #endif
02546 #if HAS_analogIn8
02547         case '8': case 0x08: return true;
02548 #endif
02549 #if HAS_analogIn9
02550         case '9': case 0x09: return true;
02551 #endif
02552 #if HAS_analogIn10
02553         case 'a': case 0x0a: return true;
02554 #endif
02555 #if HAS_analogIn11
02556         case 'b': case 0x0b: return true;
02557 #endif
02558 #if HAS_analogIn12
02559         case 'c': case 0x0c: return true;
02560 #endif
02561 #if HAS_analogIn13
02562         case 'd': case 0x0d: return true;
02563 #endif
02564 #if HAS_analogIn14
02565         case 'e': case 0x0e: return true;
02566 #endif
02567 #if HAS_analogIn15
02568         case 'f': case 0x0f: return true;
02569 #endif
02570         default:
02571             return false;
02572     }
02573 }
02574 #endif
02575 
02576 // AnalogIn pin resource: search index
02577 #if HAS_analogIns
02578 AnalogIn& find_analogInPin(int cPinIndex)
02579 {
02580     switch (cPinIndex)
02581     {
02582         default: // default to the first defined analogIn pin
02583 #if HAS_analogIn0
02584         case '0': case 0x00: return analogIn0;
02585 #endif
02586 #if HAS_analogIn1
02587         case '1': case 0x01: return analogIn1;
02588 #endif
02589 #if HAS_analogIn2
02590         case '2': case 0x02: return analogIn2;
02591 #endif
02592 #if HAS_analogIn3
02593         case '3': case 0x03: return analogIn3;
02594 #endif
02595 #if HAS_analogIn4
02596         case '4': case 0x04: return analogIn4;
02597 #endif
02598 #if HAS_analogIn5
02599         case '5': case 0x05: return analogIn5;
02600 #endif
02601 #if HAS_analogIn6
02602         case '6': case 0x06: return analogIn6;
02603 #endif
02604 #if HAS_analogIn7
02605         case '7': case 0x07: return analogIn7;
02606 #endif
02607 #if HAS_analogIn8
02608         case '8': case 0x08: return analogIn8;
02609 #endif
02610 #if HAS_analogIn9
02611         case '9': case 0x09: return analogIn9;
02612 #endif
02613 #if HAS_analogIn10
02614         case 'a': case 0x0a: return analogIn10;
02615 #endif
02616 #if HAS_analogIn11
02617         case 'b': case 0x0b: return analogIn11;
02618 #endif
02619 #if HAS_analogIn12
02620         case 'c': case 0x0c: return analogIn12;
02621 #endif
02622 #if HAS_analogIn13
02623         case 'd': case 0x0d: return analogIn13;
02624 #endif
02625 #if HAS_analogIn14
02626         case 'e': case 0x0e: return analogIn14;
02627 #endif
02628 #if HAS_analogIn15
02629         case 'f': case 0x0f: return analogIn15;
02630 #endif
02631     }
02632 }
02633 #endif
02634 
02635 #if HAS_analogIns
02636 const float analogInPin_fullScaleVoltage[] = {
02637 # if defined(TARGET_MAX32630)
02638     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02639     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02640     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02641     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02642     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
02643     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
02644     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
02645     ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
02646     ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
02647     ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
02648     ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
02649     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
02650     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
02651     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02652     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02653     ADC_FULL_SCALE_VOLTAGE // analogIn15
02654 # elif defined(TARGET_MAX32620FTHR)
02655 #warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..."
02656     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02657     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02658     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02659     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02660     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
02661     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
02662     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
02663     ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
02664     ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
02665     ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
02666     ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
02667     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
02668     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
02669     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02670     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02671     ADC_FULL_SCALE_VOLTAGE // analogIn15
02672 #elif defined(TARGET_MAX32625MBED)
02673     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn0 // fullscale is 1.2V
02674     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn1 // fullscale is 1.2V
02675     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn2 // fullscale is 1.2V
02676     ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn3 // fullscale is 1.2V
02677     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0     fullscale is 6.0V
02678     ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0     fullscale is 6.0V
02679     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0     fullscale is 4.8V
02680     ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18          fullscale is 1.2V
02681     ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12          fullscale is 1.2V
02682     ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0     fullscale is 2.4V
02683     ADC_FULL_SCALE_VOLTAGE, // analogIn10  // AIN_10 = x undefined?
02684     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0   fullscale is 4.8V
02685     ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0  fullscale is 4.8V
02686     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02687     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02688     ADC_FULL_SCALE_VOLTAGE // analogIn15
02689 #elif defined(TARGET_NUCLEO_F446RE)
02690     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02691     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02692     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02693     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02694     ADC_FULL_SCALE_VOLTAGE, // analogIn4
02695     ADC_FULL_SCALE_VOLTAGE, // analogIn5
02696     ADC_FULL_SCALE_VOLTAGE, // analogIn6
02697     ADC_FULL_SCALE_VOLTAGE, // analogIn7
02698     ADC_FULL_SCALE_VOLTAGE, // analogIn8
02699     ADC_FULL_SCALE_VOLTAGE, // analogIn9
02700     ADC_FULL_SCALE_VOLTAGE, // analogIn10
02701     ADC_FULL_SCALE_VOLTAGE, // analogIn11
02702     ADC_FULL_SCALE_VOLTAGE, // analogIn12
02703     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02704     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02705     ADC_FULL_SCALE_VOLTAGE // analogIn15
02706 #elif defined(TARGET_NUCLEO_F401RE)
02707     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02708     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02709     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02710     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02711     ADC_FULL_SCALE_VOLTAGE, // analogIn4
02712     ADC_FULL_SCALE_VOLTAGE, // analogIn5
02713     ADC_FULL_SCALE_VOLTAGE, // analogIn6
02714     ADC_FULL_SCALE_VOLTAGE, // analogIn7
02715     ADC_FULL_SCALE_VOLTAGE, // analogIn8
02716     ADC_FULL_SCALE_VOLTAGE, // analogIn9
02717     ADC_FULL_SCALE_VOLTAGE, // analogIn10
02718     ADC_FULL_SCALE_VOLTAGE, // analogIn11
02719     ADC_FULL_SCALE_VOLTAGE, // analogIn12
02720     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02721     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02722     ADC_FULL_SCALE_VOLTAGE // analogIn15
02723 //#elif defined(TARGET_LPC1768)
02724 #else
02725     // unknown target
02726     ADC_FULL_SCALE_VOLTAGE, // analogIn0
02727     ADC_FULL_SCALE_VOLTAGE, // analogIn1
02728     ADC_FULL_SCALE_VOLTAGE, // analogIn2
02729     ADC_FULL_SCALE_VOLTAGE, // analogIn3
02730     ADC_FULL_SCALE_VOLTAGE, // analogIn4
02731     ADC_FULL_SCALE_VOLTAGE, // analogIn5
02732     ADC_FULL_SCALE_VOLTAGE, // analogIn6
02733     ADC_FULL_SCALE_VOLTAGE, // analogIn7
02734     ADC_FULL_SCALE_VOLTAGE, // analogIn8
02735     ADC_FULL_SCALE_VOLTAGE, // analogIn9
02736     ADC_FULL_SCALE_VOLTAGE, // analogIn10
02737     ADC_FULL_SCALE_VOLTAGE, // analogIn11
02738     ADC_FULL_SCALE_VOLTAGE, // analogIn12
02739     ADC_FULL_SCALE_VOLTAGE, // analogIn13
02740     ADC_FULL_SCALE_VOLTAGE, // analogIn14
02741     ADC_FULL_SCALE_VOLTAGE // analogIn15
02742 # endif
02743 };
02744 #endif
02745 
02746 #if HAS_I2C // SUPPORT_I2C
02747 //--------------------------------------------------
02748 // Search I2C device address list
02749 //
02750 // @param[in] deviceAddress7First = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified.
02751 // @param[in] deviceAddress7Last = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified.
02752 // @param[in] numDevicesFoundLimit = maximum number of devices to detect before halting search; in case SCL stuck low or pullups missing.
02753 // @returns deviceAddress on success; 0 on failure
02754 // @post g_I2C_deviceAddress7 is updated with any device that did ACK
02755 //
02756 void HuntAttachedI2CDevices(CmdLine& cmdLine, uint8_t deviceAddress7First, uint8_t deviceAddress7Last,
02757                             const uint8_t numDevicesFoundLimit = 20)
02758 {
02759     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
02760     I2C i2cMaster(I2C0_SDA, I2C0_SCL); // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
02761     i2cMaster.frequency(g_I2C_SCL_Hz);
02762 
02763     // %IP -- I2C probe
02764     // TODO: i2c transfer
02765     //const int addr7bit = 0x48;      // 7 bit I2C address
02766     //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
02767     // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
02768     // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
02769     // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
02770     // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
02771     // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
02772     // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
02773     // /* 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...
02774     // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
02775 
02776     //const char probeWriteData[] = { 0x00 };
02777     //int probeWriteDataLength = 1;
02778     //bool isRepeatedStart = false;
02779     cmdLine.serial().printf("I2C Probe {0x%2.2X (0x%2.2X >> 1) to 0x%2.2X (0x%2.2X >> 1)}, limit %d\r\n",
02780                             deviceAddress7First,
02781                             deviceAddress7First << 1,
02782                             deviceAddress7Last,
02783                             deviceAddress7Last << 1,
02784                             numDevicesFoundLimit); // HuntAttachedI2CDevices
02785     //~ const int i2cFileDescriptor = i2c_open_adapter(1);
02786     uint8_t numDevicesFound = 0;
02787     uint8_t last_valid_deviceAddress7 = 0;
02788     for (uint8_t deviceAddress7 = deviceAddress7First; deviceAddress7 <= deviceAddress7Last; deviceAddress7++)
02789     {
02790         //cmdLine.serial().printf(" (0x%2.2X >> 1) ", (deviceAddress7 << 1));
02791         //if (i2c_ioctl_I2C_SLAVE_i2cDeviceAddress7bits(i2cFileDescriptor, deviceAddress7) == 0)
02792         int addr8bit = deviceAddress7 * 2;
02793         //
02794         // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
02795         // Returns 0 on success (ack), nonzero on failure (nack)
02796         //bool gotACK = (i2cMaster.write (addr8bit, probeWriteData, probeWriteDataLength, isRepeatedStart) == 0);
02797         //
02798         // SMBusQuick test
02799         i2cMaster.start();
02800         // /** Write single byte out on the I2C bus
02801         //  *
02802         //  *  @param data data to write out on bus
02803         //  *
02804         //  *  @returns
02805         //  *    '0' - NAK was received
02806         //  *    '1' - ACK was received,
02807         //  *    '2' - timeout
02808         //  */
02809         // int write(int data);
02810         int writeStatus = i2cMaster.write(addr8bit);
02811         i2cMaster.stop();
02812         bool gotACK = (writeStatus == 1); // ACK was received
02813         if (writeStatus == 2) // timeout
02814         {
02815             cmdLine.serial().printf("- timeout\r\n");
02816         }
02817         //
02818         if (gotACK)
02819         {
02820             // @return status; error if (fileDescriptor < 0)
02821             cmdLine.serial().printf("+ ADDR=0x%2.2X (0x%2.2X >> 1) ACK\r\n", deviceAddress7, (deviceAddress7 << 1));
02822             numDevicesFound++;
02823             last_valid_deviceAddress7 = deviceAddress7;
02824             if (numDevicesFound > numDevicesFoundLimit)
02825             {
02826                 break;
02827             }
02828             continue;
02829         }
02830     }
02831     if (numDevicesFound == 0)
02832     {
02833         cmdLine.serial().printf("- No I2C devices found. Maybe SCL/SDA are swapped?\r\n");
02834     }
02835     else if (numDevicesFound > numDevicesFoundLimit)
02836     {
02837         cmdLine.serial().printf("- Many I2C devices found. SCL/SDA missing pullup resistors? SCL stuck low?\r\n");
02838     }
02839     else
02840     {
02841         //~ i2c_ioctl_I2C_SLAVE_i2cDeviceAddress7bits(i2cFileDescriptor, last_valid_deviceAddress7);
02842         g_I2C_deviceAddress7 = last_valid_deviceAddress7;
02843     }
02844     //~ i2c_close(i2cFileDescriptor);
02845 }
02846 #endif // SUPPORT_I2C
02847 
02848 //--------------------------------------------------
02849 // periodic interrupt timer onTimerTick handler triggered by Ticker
02850 // analogIn0 (MAX32630:AIN_4 = AIN0 / 5.0) controls angular speed
02851 // analogIn1 (MAX32630:AIN_5 = AIN1 / 5.0) controls PWM duty cycle
02852 // note: measured 500ns overhead for MAX32630FTHR digitalInOut1.write(0); digitalInOut1.write(1);
02853 #if USE_PERIODIC_TIMER
02854 void onTimerTick() {
02855 } // onTimerTick
02856 #endif
02857 
02858 #if USE_PERIODIC_TIMER
02859 // periodic interrupt timer command handlers -- enable timer
02860 void cmd_TE()
02861 {
02862     //us_timestamp_t interval_usec = 100000; // 100ms
02863     periodicInterruptTimer_interval_usec = 100000; // 100ms
02864 #  if HAS_DAPLINK_SERIAL
02865     DAPLINKserial.printf(" TE rate=%lluus -- Timer Enable\r\n", periodicInterruptTimer_interval_usec);
02866 #  endif
02867     serial.printf(" TE rate=%lluus -- Timer Enable", periodicInterruptTimer_interval_usec);
02868 #if 1
02869     // mbed shared event queue run onTimerTick() in Thread context not Interrupt context
02870     periodicInterruptTimer.attach_us(mbed_event_queue()->event(onTimerTick),
02871                                      periodicInterruptTimer_interval_usec);
02872     // Works if rate=620Hz or less, Fails if rate=750Hz
02873     // MbedOS Error Info Error Status 0x80FF0144 code 324 module 255
02874     // Assertion failed; id  location 0xBE6F  mbed-os.lib/events/Event.h+158
02875     // Current thread main id 0x200036f8 entry 0xc22f stacksize 0x1000 stackmem 0x200026f8 sp 0x2007ff60 
02876     // Seems not robust about overrun / sample rate too fast
02877 #else
02878     periodicInterruptTimer.attach_us(&onTimerTick, periodicInterruptTimer_interval_usec);
02879 #endif
02880     // -- periodicInterruptTimer.attach(&onTimerTick, interval_sec); // the address of the function to be attached (onTimerTick) and the interval (2 seconds)
02881     // -- periodicInterruptTimer.attach_us(&onTimerTick, interval_usec); // the address of the function to be attached (onTimerTick) and the interval (2 seconds)
02882     // -- periodicInterruptTimer.attach(Callback<void()> func, float t);
02883     // -- periodicInterruptTimer.attach_us(Callback<void()> func, us_timestamp_t t);
02884     // TODO1: cmd_T add cSubCommand to change interval of Ticker periodic interrupt timer
02885 }
02886 #endif
02887 
02888 #if USE_PERIODIC_TIMER
02889 // periodic interrupt timer command handlers -- disable timer
02890 void cmd_TD()
02891 {
02892 #  if HAS_DAPLINK_SERIAL
02893     DAPLINKserial.printf("  Timer Disable\r\n");
02894 #  endif
02895     serial.printf(" Timer Disable ");
02896     periodicInterruptTimer.detach(); // Detach the function
02897 }
02898 #endif
02899 
02900 //--------------------------------------------------
02901 // When user presses button BUTTON1, perform a demo configuration
02902 #if HAS_BUTTON1_DEMO_INTERRUPT
02903 void onButton1FallingEdge(void)
02904 {
02905     void SelfTest(CmdLine & cmdLine);
02906 
02907     SelfTest(cmdLine_serial);
02908 
02909 #if 0 // APPLICATION_MAX5715 // onButton1FallingEdge BUTTON1 demo configuration MAX5715BOB
02910     //~ cmdLine.serial().printf("MAX5715_REF(REF_AlwaysOn_2V500)");
02911     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500);
02912 
02913     uint16_t code = 4095;
02914     //~ cmdLine.serial().printf("CODEallLOADall code=%d", code);
02915     g_MAX5715_device.CODEallLOADall(code);
02916 #endif // APPLICATION_MAX5715
02917 
02918 }
02919 #endif // HAS_BUTTON1_DEMO_INTERRUPT
02920 
02921 //--------------------------------------------------
02922 // When user presses button BUTTON2, perform a demo configuration
02923 #if HAS_BUTTON2_DEMO_INTERRUPT
02924 void onButton2FallingEdge(void)
02925 {
02926     // TODO1: BUTTON2 demo configuration LED blink
02927 
02928 #if APPLICATION_MAX5715 // onButton2FallingEdge BUTTON2 demo configuration MAX5715BOB
02929     //~ cmdLine.serial().printf("MAX5715_REF(REF_AlwaysOn_2V048)");
02930     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048);
02931     //
02932     uint16_t ch = 0;
02933     uint16_t code = 0xccc;
02934     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02935     g_MAX5715_device.CODEnLOADn(ch, code);
02936     //
02937     ch = 1;
02938     code = 0x800;
02939     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02940     g_MAX5715_device.CODEnLOADn(ch, code);
02941     //
02942     ch = 2;
02943     code = 0x666;
02944     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02945     g_MAX5715_device.CODEnLOADn(ch, code);
02946     //
02947     ch = 3;
02948     code = 0xFFF;
02949     //~ cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
02950     g_MAX5715_device.CODEnLOADn(ch, code);
02951 #elif APPLICATION_MAX11131 // onButton2FallingEdge BUTTON2 demo configuration MAX11131BOB
02952     // TODO1: demo
02953     // MAX11131 > 4
02954     // ScanStandardExternalClock ch=9 pm=0 id=1
02955     // ScanRead_nWords_chanID nWords=10
02956     //  ch=0 xu=2964 = 0x0b94 = 1.8091V
02957     //  ch=1 xu=2227 = 0x08b3 = 1.3593V
02958     //  ch=2 xu=1570 = 0x0622 = 0.9583V
02959     //  ch=3 xu=865 = 0x0361 = 0.5280V
02960     //  ch=4 xu=630 = 0x0276 = 0.3845V
02961     //  ch=5 xu=594 = 0x0252 = 0.3625V
02962     //  ch=6 xu=461 = 0x01cd = 0.2814V
02963     //  ch=7 xu=364 = 0x016c = 0.2222V
02964     //  ch=8 xu=480 = 0x01e0 = 0.2930V
02965     //  ch=9 xu=616 = 0x0268 = 0.3760V
02966     g_MAX11131_device.channelNumber_0_15 = 9;
02967     g_MAX11131_device.PowerManagement_0_2 = 0;
02968     g_MAX11131_device.chan_id_0_1 = 1;
02969     g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
02970     //
02971     // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
02972     // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
02973     g_MAX11131_device.ReadAINcode();
02974     // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
02975     // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
02976     //
02977     // TODO: compare with mbed/Arduino AIN0-AIN3
02978     //
02979 #elif APPLICATION_MAX5171 // onButton2FallingEdge BUTTON2 demo configuration MAX5171BOB
02980     // TODO: demo
02981     uint16_t code = 0xccc;
02982     g_MAX5171_device.CODE(code);
02983 #elif APPLICATION_MAX11410 // onButton2FallingEdge BUTTON2 demo configuration MAX11410BOB
02984     // TODO: demo
02985     g_MAX11410_device.CODEnLOADn(ch, code);
02986 #elif APPLICATION_MAX12345 // onButton2FallingEdge BUTTON2 demo configuration MAX12345BOB
02987     // TODO: demo
02988     g_MAX12345_device.CODEnLOADn(ch, code);
02989 #endif // APPLICATION_MAX5715
02990     rgb_led.blue(); // diagnostic rbg led BLUE
02991 
02992 }
02993 #endif // HAS_BUTTON2_DEMO_INTERRUPT
02994 
02995 //--------------------------------------------------
02996 // TODO1: use MaximTinyTester encapsulate SelfTest support functions
02997 //--------------------------------------------------
02998 #if APPLICATION_MAX5715 // SelfTest
02999 //
03000 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03001 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03002 //
03003 // define function under test using C++11 lambda expression [](){}
03004 // uint8_t MAX5715::Init(void)
03005 // uint8_t (*fn_MAX5715_Init)() = [](){ return g_MAX5715_device.Init(); };
03006 uint8_t fn_MAX5715_Init() { return g_MAX5715_device.Init(); };
03007 //
03008 // define function under test using C++11 lambda expression [](){}
03009 // uint16_t MAX5715::DACCodeOfVoltage(double voltageV)
03010 // uint16_t (*fn_MAX5715_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5715_device.DACCodeOfVoltage(voltageV); };
03011 uint16_t fn_MAX5715_DACCodeOfVoltage(double voltageV) { return g_MAX5715_device.DACCodeOfVoltage(voltageV); };
03012 //
03013 // define function under test using C++11 lambda expression [](){}
03014 // double MAX5715::VoltageOfCode(uint16_t value_u14)
03015 //double (*fn_MAX5715_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5715_device.VoltageOfCode(value_u14); };
03016 double fn_MAX5715_VoltageOfCode(uint16_t value_u14) { return g_MAX5715_device.VoltageOfCode(value_u14); };
03017 //
03018 // define function under test using C++11 lambda expression [](){}
03019 // void MAX5715::CODEnLOADn(uint8_t channel_0_3, uint16_t dacCodeLsbs)
03020 // 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); };
03021 void fn_MAX5715_CODEnLOADn (uint8_t channel_0_3, uint16_t dacCodeLsbs) { return g_MAX5715_device.CODEnLOADn(channel_0_3, dacCodeLsbs); };
03022 //
03023 #endif // APPLICATION_MAX5715 // SelfTest
03024 //--------------------------------------------------
03025 #if APPLICATION_MAX11131 // SelfTest
03026 //
03027 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03028 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03029 //
03030 // define function under test using C++11 lambda expression [](){}
03031 //
03032 #endif // APPLICATION_MAX11131 // SelfTest
03033 //--------------------------------------------------
03034 #if APPLICATION_MAX5171 // SelfTest
03035 //
03036 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03037 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03038 //
03039 // define function under test using C++11 lambda expression [](){}
03040 // uint8_t MAX5171::Init(void)
03041 // uint8_t (*fn_MAX5171_Init)() = [](){ return g_MAX5171_device.Init(); };
03042 uint8_t fn_MAX5171_Init() { return g_MAX5171_device.Init(); };
03043 //
03044 // define function under test using C++11 lambda expression [](){}
03045 // uint16_t MAX5171::DACCodeOfVoltage(double voltageV)
03046 // uint16_t (*fn_MAX5171_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5171_device.DACCodeOfVoltage(voltageV); };
03047 uint16_t fn_MAX5171_DACCodeOfVoltage(double voltageV) { return g_MAX5171_device.DACCodeOfVoltage(voltageV); };
03048 //
03049 // define function under test using C++11 lambda expression [](){}
03050 // double MAX5171::VoltageOfCode(uint16_t value_u14)
03051 // double (*fn_MAX5171_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5171_device.VoltageOfCode(value_u14); };
03052 double fn_MAX5171_VoltageOfCode(uint16_t value_u14) { return g_MAX5171_device.VoltageOfCode(value_u14); };
03053 //
03054 // define function under test using C++11 lambda expression [](){}
03055 // uint8_t MAX5171::CODE_LOAD(uint16_t dacCodeLsbs)
03056 // uint8_t (*fn_MAX5171_CODE_LOAD)(uint16_t dacCodeLsbs) = [](uint16_t dacCodeLsbs){ return g_MAX5171_device.CODE_LOAD(dacCodeLsbs); };
03057 uint8_t fn_MAX5171_CODE_LOAD(uint16_t dacCodeLsbs) { return g_MAX5171_device.CODE_LOAD(dacCodeLsbs); };
03058 //
03059 //
03060 #endif // APPLICATION_MAX5171 // SelfTest
03061 //--------------------------------------------------
03062 #if APPLICATION_MAX11410 // SelfTest
03063 //
03064 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03065 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03066 //
03067 // define function under test using C++11 lambda expression [](){}
03068 //
03069 #endif // APPLICATION_MAX11410 // SelfTest
03070 //--------------------------------------------------
03071 #if APPLICATION_MAX12345 // SelfTest
03072 //
03073 // Note: ide.mbed.com does not support C++11 Lambda Expressions
03074 // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03075 //
03076 // define function under test using C++11 lambda expression [](){}
03077 //
03078 #endif // APPLICATION_MAX12345 // SelfTest
03079 //--------------------------------------------------
03080 void SelfTest_print_DACCodeOfVoltage(CmdLine& cmdLine, double voltageV)
03081 {
03082     cmdLine.serial().printf("DACCodeOfVoltage(%6.4fV)", voltageV);
03083     // For 12-bit DAC, dtostrf width, precision = 6, 4 i.e. 0.0001
03084     // For 14-bit DAC, dtostrf width, precision = 7, 5 i.e. 0.00001
03085     //~ dtostrf(voltageV, 6, 4, strOutLineBuffer); // value, width, precision, char* buffer
03086     //~ cmdLine.serial().printf(strOutLineBuffer);
03087     //~ cmdLine.serial().printf("V)");
03088 }
03089 //--------------------------------------------------
03090 #if APPLICATION_MAX5171 // SelfTest
03091 void SelfTest_print_VoltageOfCode(CmdLine& cmdLine, uint16_t value_u14)
03092 {
03093     cmdLine.serial().printf("VoltageOfCode(%d)", value_u14);
03094 }
03095 #endif // APPLICATION_MAX5171
03096 //--------------------------------------------------
03097 #if APPLICATION_MAX5715 // SelfTest
03098 void SelfTest_print_Vref(CmdLine & cmdLine)
03099 {
03100     cmdLine.serial().printf("VRef = %6.4fV  LSB=%6.4fV", g_MAX5715_device.VRef, (g_MAX5715_device.VRef / 4095));
03101     //~ dtostrf(g_MAX5715_device.VRef, 6, 4, strOutLineBuffer); // value, width, precision, char* buffer
03102     //~ cmdLine.serial().printf(strOutLineBuffer);
03103     //~ cmdLine.serial().printf("V  LSB=");
03104     // For 12-bit DAC, dtostrf width, precision = 6, 4 i.e. 0.0001
03105     // For 14-bit DAC, dtostrf width, precision = 7, 5 i.e. 0.00001
03106     //~ dtostrf( (g_MAX5715_device.VRef / 4095), 6, 4, strOutLineBuffer); // value, width, precision, char* buffer
03107     //~ cmdLine.serial().printf(strOutLineBuffer);
03108     //~ cmdLine.serial().printf("V");
03109 }
03110 #endif // APPLICATION_MAX5715
03111 //--------------------------------------------------
03112 #if APPLICATION_MAX5171 // SelfTest
03113 void SelfTest_print_Vref(CmdLine & cmdLine)
03114 {
03115     cmdLine.serial().printf("VRef = %7.5fV  LSB=%7.5fV", g_MAX5171_device.VRef, (g_MAX5171_device.VRef / 16383));
03116     // For 12-bit DAC, dtostrf width, precision = 6, 4 i.e. 0.0001
03117     // For 14-bit DAC, dtostrf width, precision = 7, 5 i.e. 0.00001
03118 }
03119 #endif // APPLICATION_MAX5171
03120 //--------------------------------------------------
03121 #if HAS_SPI2_MAX541
03122 MAX541 max541(spi2_max541, spi2_max541_cs);
03123 #endif
03124 //--------------------------------------------------
03125 bool SelfTest_MAX541_Voltage(CmdLine & cmdLine, MAX541 &max541, double voltageV)
03126 {
03127     max541.Set_Voltage(voltageV);
03128     // cmdLine.serial().printf("\r\n      Test Fixture: MAX541 set output to %1.3fV = code 0x%4.4x", max541.Get_Voltage(), max541.Get_Code());
03129     cmdLine.serial().printf("\r\n      Test Fixture: MAX541 set output to 0x%4.4x = %1.3fV",
03130                             max541.Get_Code(), max541.Get_Voltage());
03131 #if analogIn4_IS_HIGH_RANGE_OF_analogIn0
03132     // Platform board uses AIN4,AIN5,.. as high range of AIN0,AIN1,..
03133     MaximTinyTester tinyTester(cmdLine, analogIn4, analogIn5, analogIn2, analogIn3, analogIn0, analogIn4, led1, led2, led3);
03134     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[4]; // board support
03135     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[5]; // board support
03136     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03137     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03138     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[0]; // board support
03139     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[1]; // board support
03140     // low range channels AIN0, AIN1, AIN2, AIN3
03141 #else // analogIn4_IS_HIGH_RANGE_OF_analogIn0
03142     // Platform board uses simple analog inputs
03143     MaximTinyTester tinyTester(cmdLine, analogIn0, analogIn1, analogIn2, analogIn3, analogIn4, analogIn5, led1, led2, led3);
03144     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[0]; // board support
03145     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[1]; // board support
03146     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03147     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03148     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[4]; // board support
03149     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[5]; // board support
03150 #endif
03151     tinyTester.Wait_Output_Settling(); // wait for MAX541 to settle
03152     // TODO: tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03153     tinyTester.err_threshold = 0.100;
03154     return tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03155 }
03156 //--------------------------------------------------
03157 void SelfTest(CmdLine & cmdLine)
03158 {
03159     //--------------------------------------------------
03160 #if analogIn4_IS_HIGH_RANGE_OF_analogIn0
03161     // Platform board uses AIN4,AIN5,.. as high range of AIN0,AIN1,..
03162     MaximTinyTester tinyTester(cmdLine, analogIn4, analogIn5, analogIn2, analogIn3, analogIn0, analogIn4, led1, led2, led3);
03163     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[4]; // board support
03164     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[5]; // board support
03165     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03166     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03167     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[0]; // board support
03168     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[1]; // board support
03169     // low range channels AIN0, AIN1, AIN2, AIN3
03170 #else // analogIn4_IS_HIGH_RANGE_OF_analogIn0
03171     // Platform board uses simple analog inputs
03172     MaximTinyTester tinyTester(cmdLine, analogIn0, analogIn1, analogIn2, analogIn3, analogIn4, analogIn5, led1, led2, led3);
03173     tinyTester.analogInPin_fullScaleVoltage[0] = analogInPin_fullScaleVoltage[0]; // board support
03174     tinyTester.analogInPin_fullScaleVoltage[1] = analogInPin_fullScaleVoltage[1]; // board support
03175     tinyTester.analogInPin_fullScaleVoltage[2] = analogInPin_fullScaleVoltage[2]; // board support
03176     tinyTester.analogInPin_fullScaleVoltage[3] = analogInPin_fullScaleVoltage[3]; // board support
03177     tinyTester.analogInPin_fullScaleVoltage[4] = analogInPin_fullScaleVoltage[4]; // board support
03178     tinyTester.analogInPin_fullScaleVoltage[5] = analogInPin_fullScaleVoltage[5]; // board support
03179 #endif
03180     tinyTester.clear();
03181 #if APPLICATION_MAX5715 // SelfTest
03182     //
03183     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03184     //
03185     // Note: ide.mbed.com does not support C++11 Lambda Expressions
03186     // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03187     // define function under test using C++11 lambda expression [](){}
03188     // uint8_t MAX5715::Init(void)
03189     //uint8_t (*fn_MAX5715_Init)() = [](){ return g_MAX5715_device.Init(); };
03190     //
03191     // define function under test using C++11 lambda expression [](){}
03192     // uint16_t MAX5715::DACCodeOfVoltage(double voltageV)
03193     //uint16_t (*fn_MAX5715_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5715_device.DACCodeOfVoltage(voltageV); };
03194     //
03195     // define function under test using C++11 lambda expression [](){}
03196     // double MAX5715::VoltageOfCode(uint16_t value_u14)
03197     //double (*fn_MAX5715_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5715_device.VoltageOfCode(value_u14); };
03198     //
03199     // define function under test using C++11 lambda expression [](){}
03200     // void MAX5715::CODEnLOADn(uint8_t channel_0_3, uint16_t dacCodeLsbs)
03201     //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); };
03202     //
03203     //
03204     //
03205     //
03206     //
03207     //------------------------------------------------------------
03208     g_MAX5715_device.VRef = 4.096;     // MAX5715 12-bit LSB = 0.0010V
03209     SelfTest_print_Vref(cmdLine);
03210     //~ cmdLine.serial().printf("\r\n");
03211     //
03212     tinyTester.blink_time_msec = 20; // quickly speed through the software verification
03213     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03214     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 10.0, 0x0FFF);     // overrange FS
03215     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0950, 0x0FFF);
03216     //
03217     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0945, 0x0FFF);
03218     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0944, 0x0FFE);
03219     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0943, 0x0FFE);
03220     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0942, 0x0FFE);
03221     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0941, 0x0FFE);
03222     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0940, 0x0FFE);     // search for code transition
03223     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0939, 0x0FFE);
03224     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0938, 0x0FFE);
03225     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0937, 0x0FFE);
03226     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0936, 0x0FFE);
03227     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0935, 0x0FFD);
03228     //
03229     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 4.0930, 0x0FFD);
03230     //
03231     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0480, 0x0800);
03232     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0470, 0x07FF);
03233     //
03234     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0000, 0x03E8);     // 1.0 volt
03235     //
03236     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0030, 0x0003);
03237     //
03238     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0020, 0x0002);
03239     //
03240     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0010, 0x0001);
03241     //
03242     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0000, 0x0000);
03243     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0001, 0x0000);     // overrange ZS
03244     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0002, 0x0000);     // overrange ZS
03245     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -1.0, 0x0000);     // overrange ZS
03246     //
03247     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03248     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFF, 4.0950);
03249     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFE, 4.0940);
03250     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0800, 2.0480);
03251     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07FF, 2.0470);
03252     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x03E8, 1.0000);     // 1.0 volt
03253     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0001, 0.0010);
03254     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0000, 0.0000);
03255     //
03256     //------------------------------------------------------------
03257     cmdLine.serial().printf("\r\n");
03258     g_MAX5715_device.VRef = 2.048;     // 12-bit LSB = 0.0005V
03259     SelfTest_print_Vref(cmdLine);
03260     //~ cmdLine.serial().printf("\r\n");
03261     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03262     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 10.0, 0x0FFF);     // overrange FS
03263     //
03264     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0480, 0x0FFF);
03265     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0479, 0x0FFF);
03266     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0478, 0x0FFF);
03267     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0477, 0x0FFF);
03268     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0476, 0x0FFF);
03269     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0475, 0x0FFF);
03270     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0474, 0x0FFF);
03271     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0473, 0x0FFF);
03272     //
03273     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0472, 0x0FFE);
03274     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0471, 0x0FFE);
03275     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0470, 0x0FFE);
03276     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0469, 0x0FFE);
03277     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0468, 0x0FFE);
03278     //
03279     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0467, 0x0FFD);
03280     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0466, 0x0FFD);
03281     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0465, 0x0FFD);
03282     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0464, 0x0FFD);
03283     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.0463, 0x0FFD);
03284     //
03285     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0240, 0x0800);
03286     //
03287     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0235, 0x07FF);
03288     //
03289     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0000, 0x07D0);     // 1.0 volt
03290     //
03291     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0017, 0x0003);
03292     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0016, 0x0003);
03293     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0015, 0x0003);
03294     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0014, 0x0003);
03295     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0013, 0x0003);
03296     //
03297     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0012, 0x0002);
03298     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0011, 0x0002);
03299     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0010, 0x0002);
03300     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0009, 0x0002);
03301     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0008, 0x0002);
03302     //
03303     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0007, 0x0001);
03304     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0006, 0x0001);
03305     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0005, 0x0001);
03306     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0004, 0x0001);
03307     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0003, 0x0001);
03308     //
03309     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0002, 0x0000);
03310     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0001, 0x0000);
03311     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0000, 0x0000);
03312     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0001, 0x0000);     // overrange ZS
03313     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0002, 0x0000);     // overrange ZS
03314     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -1.0, 0x0000);     // overrange ZS
03315     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03316     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFF, 2.0475);
03317     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFE, 2.0470);
03318     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFD, 2.0465);
03319     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0800, 1.0240);
03320     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07FF, 1.0235);
03321     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07D0, 1.0000);     // 1.0 volt
03322     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0002, 0.0010);
03323     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0001, 0.0005);
03324     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0000, 0.0000);
03325     //
03326     //
03327     //------------------------------------------------------------
03328     cmdLine.serial().printf("\r\n");
03329     g_MAX5715_device.VRef = 2.500;     // 12-bit LSB = 0.0006105006105006105V
03330     SelfTest_print_Vref(cmdLine);
03331     //~ cmdLine.serial().printf("\r\n");
03332     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03333     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 10.0, 0x0FFF);     // overrange FS
03334     //
03335     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.5000, 0x0FFF);
03336     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4999, 0x0FFF);
03337     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4998, 0x0FFF);
03338     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4997, 0x0FFF);
03339     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4996, 0x0FFF);
03340     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4995, 0x0FFF);
03341     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4994, 0x0FFF);
03342     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4993, 0x0FFF);
03343     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4992, 0x0FFF);
03344     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4991, 0x0FFF);
03345     //
03346     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4990, 0x0FFE);     // search for code transitions
03347     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4989, 0x0FFE);
03348     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4988, 0x0FFE);
03349     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4987, 0x0FFE);
03350     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4986, 0x0FFE);
03351     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4985, 0x0FFE);
03352     //
03353     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4984, 0x0FFD);
03354     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4983, 0x0FFD);
03355     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4982, 0x0FFD);
03356     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4981, 0x0FFD);
03357     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4980, 0x0FFD);
03358     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4979, 0x0FFD);
03359     //
03360     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4978, 0x0FFC);
03361     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4977, 0x0FFC);
03362     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4976, 0x0FFC);
03363     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4975, 0x0FFC);
03364     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4974, 0x0FFC);
03365     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4973, 0x0FFC);
03366     //
03367     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4972, 0x0FFB);
03368     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4971, 0x0FFB);
03369     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 2.4970, 0x0FFB);
03370     //
03371     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.2500, 0x0800);
03372     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.2494, 0x07FF);
03373     //
03374     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 1.0000, 0x0666);     // 1.0 volt
03375     //
03376     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0019, 0x0003);     // search for code transitions
03377     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0018, 0x0003);
03378     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0017, 0x0003);
03379     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0016, 0x0003);
03380     //
03381     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0015, 0x0002);
03382     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0014, 0x0002);
03383     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0013, 0x0002);
03384     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0012, 0x0002);
03385     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0011, 0x0002);
03386     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0010, 0x0002);
03387     //
03388     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0009, 0x0001);
03389     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0008, 0x0001);
03390     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0007, 0x0001);
03391     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0006, 0x0001);
03392     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0005, 0x0001);
03393     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0004, 0x0001);
03394     //
03395     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0003, 0x0000);
03396     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0002, 0x0000);
03397     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0001, 0x0000);
03398     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, 0.0000, 0x0000);
03399     //
03400     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0001, 0x0000);     // overrange ZS
03401     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -0.0002, 0x0000);     // overrange ZS
03402     tinyTester.FunctionCall_Expect("MAX5715.DACCodeOfVoltage", fn_MAX5715_DACCodeOfVoltage, -1.0, 0x0000);     // overrange ZS
03403     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03404     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFF, 2.5000);
03405     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFE, 2.4988);
03406     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0FFD, 2.4976);
03407     //
03408     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0800, 1.2500);
03409     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x07FF, 1.2494);
03410     //
03411     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0667, 1.0000);     // 1.0 volt
03412     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0666, 1.0000);     // 1.0 volt
03413     //
03414     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0002, 0.0012);
03415     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0001, 0.0006);
03416     tinyTester.FunctionCall_Expect("MAX5715.VoltageOfCode", fn_MAX5715_VoltageOfCode, 0x0000, 0.0000);
03417     //
03418     //
03419     // Device Testing: DAC commands, verify using on-board ADC inputs
03420     //
03421     tinyTester.blink_time_msec = 75;
03422     cmdLine.serial().printf("\r\n      MAX5715.Init()");
03423     g_MAX5715_device.Init();
03424     //
03425     uint16_t ch = 0;
03426     uint16_t code = 0xfff;
03427     double voltageV = 0.5;
03428     //
03429     // full-scale output on ch0, test MAX5715 internal REF options
03430     ch = 0;
03431     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03432     g_MAX5715_device.CODEnLOADn(ch, code);
03433     //
03434     cmdLine.serial().printf("\r\n      MAX5715.REF(MAX5715::REF_AlwaysOn_2V048)");
03435     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048);
03436     // tinyTester.Wait_Output_Settling replaces wait_ms
03437     tinyTester.Wait_Output_Settling();
03438     //  tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03439     tinyTester.err_threshold = 0.030; // 30mV
03440     tinyTester.AnalogIn0_Read_Expect_voltageV(2.048);
03441     //
03442     cmdLine.serial().printf("\r\n      MAX5715.REF(MAX5715::REF_AlwaysOn_4V096)");
03443     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_4V096);
03444     // MAX32625MBED 4.096V may be as low as 3.3V supply
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.50; // 30mV
03449     tinyTester.AnalogIn0_Read_Expect_voltageV(3.750); // accept 3.25V to 4.25V
03450     //
03451     cmdLine.serial().printf("\r\n      MAX5715.REF(MAX5715::REF_AlwaysOn_2V500)");
03452     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500);
03453     // tinyTester.Wait_Output_Settling replaces wait_ms
03454     tinyTester.Wait_Output_Settling();
03455     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03456     tinyTester.err_threshold = 0.030; // 30mV
03457     tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
03458     //
03459     // test the individual channel outputs
03460     ch = 0;
03461     voltageV = 0.5;
03462     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03463     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03464     g_MAX5715_device.CODEnLOADn(ch, code);
03465     // tinyTester.Wait_Output_Settling replaces wait_ms
03466     tinyTester.Wait_Output_Settling();
03467     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03468     tinyTester.err_threshold = 0.030; // 30mV
03469     tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03470     //
03471     ch = 1;
03472     voltageV = 0.2;
03473     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03474     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03475     g_MAX5715_device.CODEnLOADn(ch, code);
03476     // tinyTester.Wait_Output_Settling replaces wait_ms
03477     tinyTester.Wait_Output_Settling();
03478     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03479     tinyTester.err_threshold = 0.030; // 30mV
03480     tinyTester.AnalogIn1_Read_Expect_voltageV(voltageV);
03481     //
03482     ch = 2;
03483     voltageV = 0.4;
03484     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03485     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03486     g_MAX5715_device.CODEnLOADn(ch, code);
03487     // tinyTester.Wait_Output_Settling replaces wait_ms
03488     tinyTester.Wait_Output_Settling();
03489     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03490     tinyTester.err_threshold = 0.030; // 30mV
03491     tinyTester.AnalogIn2_Read_Expect_voltageV(voltageV);
03492     //
03493     ch = 3;
03494     voltageV = 0.25;
03495     code = g_MAX5715_device.DACCodeOfVoltage(voltageV);
03496     cmdLine.serial().printf("\r\n      MAX5715.CODEnLOADn ch=%d code=%d", ch, code);
03497     g_MAX5715_device.CODEnLOADn(ch, code);
03498     // tinyTester.Wait_Output_Settling replaces wait_ms
03499     tinyTester.Wait_Output_Settling();
03500     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03501     tinyTester.err_threshold = 0.030; // 30mV
03502     tinyTester.AnalogIn3_Read_Expect_voltageV(voltageV);
03503     //
03504     // test that the channels are independent
03505     tinyTester.AnalogIn0_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[0]));
03506     tinyTester.AnalogIn1_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[1]));
03507     tinyTester.AnalogIn2_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[2]));
03508     tinyTester.AnalogIn3_Read_Expect_voltageV(g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[3]));
03509     //
03510 #elif APPLICATION_MAX11131
03511     //
03512     // MAX11131BOB self-test functions
03513     //~ SelfTest_FAIL(cmdLine);
03514     //~ cmdLine.serial().printf("test program not implemented yet");
03515     int16_t value_u12;
03516     int channelId;
03517     double voltageV = 0.5;
03518     //
03519     //cmdLine.serial().printf("\r\n      0.0: MAX11131.Init()");
03520     //g_MAX11131_device.Init();
03521     //
03522     // Device Testing: ADC commands, verify with on-board ADC and SPI framing
03523     //
03524     tinyTester.blink_time_msec = 75;
03525     // MAX11131 SelfTest: MAX11131 SPI connections (Power Supply and GND, SCLK, MOSI, MISO, CS)
03526     cmdLine.serial().printf("\r\n");
03527     cmdLine.serial().printf(
03528         "\r\n      1.0: Test SCAN_0100_StandardExt -- verify SPI (VDD, GND, SCLK, MOSI, MISO, CS)");
03529     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03530     g_MAX11131_device.Init();
03531     // Send MOSI data       Expect MISO data    Description
03532     // 1000_0000_0000_0000  xxxx_xxxx_xxxx_xxxx ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0
03533     // 0010_0111_1010_0100  xxxx_xxxx_xxxx_xxxx ADC_MODE_CONTROL SCAN_0100_StandardExt CHSEL=15 RESET=1 CHANID=1
03534     // 0000_0000_0000_0000  0000_xxxx_xxxx_xxxx Channel ID tag = AIN0 expect high nybble 0
03535     // 0000_0000_0000_0000  0001_xxxx_xxxx_xxxx Channel ID tag = AIN1 expect high nybble 1
03536     // 0000_0000_0000_0000  0010_xxxx_xxxx_xxxx Channel ID tag = AIN2 expect high nybble 2
03537     // 0000_0000_0000_0000  0011_xxxx_xxxx_xxxx Channel ID tag = AIN3 expect high nybble 3
03538     //
03539     cmdLine.serial().printf("\r\n      MOSI <-- 1000_0000_0000_0000  ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0");
03540     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03541     g_MAX11131_device.SPIwrite16bits(0x8000);
03542     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03543     //
03544     cmdLine.serial().printf(
03545         "\r\n      MOSI <-- 0010_0111_1010_0100  ADC_MODE_CONTROL SCAN_0100_StandardExt CHSEL=15 RESET=1 CHANID=1");
03546     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03547     g_MAX11131_device.SPIwrite16bits(0x27a4);
03548     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03549     //
03550     for (int channelIndex = 0; channelIndex < 16; channelIndex++) {
03551         //~ cmdLine.serial().printf("\r\n      MISO --> expect 0000_xxxx_xxxx_xxxx");
03552         g_MAX11131_device.SPIoutputCS(0); // drive CS low
03553         g_MAX11131_device.RAW_misoData16[channelIndex] = g_MAX11131_device.SPIread16bits();
03554         g_MAX11131_device.SPIoutputCS(1); // drive CS high
03555         int expect_channelId = channelIndex;
03556         int actual_channelId = (g_MAX11131_device.RAW_misoData16[channelIndex] >> 12) & 0x000F;
03557         if (actual_channelId != expect_channelId)
03558         {
03559             tinyTester.FAIL();
03560             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03561             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03562             cmdLine.serial().printf(" but got 0x%1.1xxxx", actual_channelId);
03563         }
03564         else
03565         {
03566             tinyTester.PASS();
03567             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03568             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03569         }
03570     }
03571     //
03572     // MAX11131 SelfTest: MAX11131 Supports Internal Clock Modes (CNVST, EOC)
03573     cmdLine.serial().printf("\r\n");
03574     cmdLine.serial().printf(
03575         "\r\n      1.1: Test SCAN_0011_StandardInt -- verify Internal Clock signals (CNVST, EOC)");
03576     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03577     g_MAX11131_device.Init();
03578     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03579     g_MAX11131_device.RAW_misoData16[0] = g_MAX11131_device.SPIread16bits();
03580     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03581 //
03582     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_MAX11131_EOC_expect
03583     tinyTester.DigitalIn_Read_Expect_WarnOnly(EOCb_pin, "EOC", 1, "initial value before sending commands");
03584 //
03585     // Send MOSI data       Expect MISO data    Description
03586     // 1000_0000_0000_0000  xxxx_xxxx_xxxx_xxxx ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0 No Averaging
03587     // 0001_1001_1010_0000  xxxx_xxxx_xxxx_xxxx ADC_MODE_CONTROL SCAN_0011_StandardInt CHSEL=3 RESET=1 SWCNV=0
03588     // 0000_0000_0000_0000  0000_xxxx_xxxx_xxxx Channel ID tag = AIN0 expect high nybble 0
03589     // 0000_0000_0000_0000  0001_xxxx_xxxx_xxxx Channel ID tag = AIN1 expect high nybble 1
03590     // 0000_0000_0000_0000  0010_xxxx_xxxx_xxxx Channel ID tag = AIN2 expect high nybble 2
03591     // 0000_0000_0000_0000  0011_xxxx_xxxx_xxxx Channel ID tag = AIN3 expect high nybble 3
03592     //
03593     cmdLine.serial().printf("\r\n      MOSI <-- 1000_0000_0000_0000  ADC_CONFIGURATION REFSEL=0 SPM[1:0]=0 ECHO=0");
03594     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03595     g_MAX11131_device.SPIwrite16bits(0x8000);
03596     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03597     //
03598     cmdLine.serial().printf(
03599         "\r\n      MOSI <-- 0001_1001_1010_0000  ADC_MODE_CONTROL SCAN_0011_StandardInt CHSEL=3 RESET=1 SWCNV=0");
03600     g_MAX11131_device.SPIoutputCS(0); // drive CS low
03601     g_MAX11131_device.SPIwrite16bits(0x19a0);
03602     g_MAX11131_device.SPIoutputCS(1); // drive CS high
03603     //
03604     for (int channelIndex = 0; channelIndex < 4; channelIndex++) {
03605         //~ cmdLine.serial().printf("\r\n      MISO --> expect 0000_xxxx_xxxx_xxxx");
03606         //~ wait_ms(200); // delay
03607         g_MAX11131_device.CNVSToutputPulseLow();
03608         //~ g_MAX11131_device.CNVSToutputValue(0);
03609         //~ wait_ms(100); // delay
03610         //~ g_MAX11131_device.CNVSToutputValue(1);
03611         // g_MAX11131_device.EOCinputWaitUntilLow(); // infinite wait hazard, need to fail if timeout exceeded
03612         // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_MAX11131_EOC_expect
03613         tinyTester.DigitalIn_Read_Expect_WarnOnly(EOCb_pin, "EOC", 0, "after CNVST pulse");
03614         g_MAX11131_device.SPIoutputCS(0); // drive CS low
03615         g_MAX11131_device.RAW_misoData16[channelIndex] = g_MAX11131_device.SPIread16bits();
03616         g_MAX11131_device.SPIoutputCS(1); // drive CS high
03617         // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_MAX11131_EOC_expect
03618         tinyTester.DigitalIn_Read_Expect_WarnOnly(EOCb_pin, "EOC", 1, "after SPI read");
03619         int expect_channelId = channelIndex;
03620         int actual_channelId = (g_MAX11131_device.RAW_misoData16[channelIndex] >> 12) & 0x000F;
03621         if (actual_channelId != expect_channelId)
03622         {
03623             tinyTester.FAIL();
03624             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03625             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03626             cmdLine.serial().printf(" but got 0x%1.1xxxx", actual_channelId);
03627         }
03628         else
03629         {
03630             tinyTester.PASS();
03631             cmdLine.serial().printf("MISO --> 0x%4.4x", (g_MAX11131_device.RAW_misoData16[channelIndex] & 0xFFFF));
03632             cmdLine.serial().printf(" expect 0x%1.1xxxx (channel ID %d)", expect_channelId, expect_channelId);
03633         }
03634     }
03635     //
03636     // MAX11131 SelfTest: Test Fixture: MAX541ACPA+ to MAX32625MBED.AIN0/AIN4
03637     // Test Fixture: MAX541 connected to spi2
03638     // 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
03639     // DigitalOut spi2_max541_cs(SPI2_SS); // TARGET_MAX32635MBED: P2_7 Arduino 2x3-pin header
03640     // Test Fixture: MAX541 spi2 init
03641     cmdLine.serial().printf("\r\n");
03642     cmdLine.serial().printf("\r\n      2.0: Test Fixture: MAX541 connected to spi2 (P2.4 P2.5 P2.7)?");
03643     bool SelfTest_has_max541 = false;
03644     // Check actual MAX541 reference voltage
03645     cmdLine.serial().printf("\r\n      Test Fixture: MAX541 midscale voltage measure with MAX32625MBED AIN0/4");
03646     max541.Set_Code(0x8000); // we don't know the fullscale voltage yet, so set code to midscale
03647     tinyTester.Wait_Output_Settling(); // wait for MAX541 to settle
03648     //
03649     double max541_midscale_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
03650     const int average_count = 100;
03651     const double average_K = 0.25;
03652     for (int count = 0; count < average_count; count++) {
03653         double measurement_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
03654         max541_midscale_V = ((1 - average_K) * max541_midscale_V) + (average_K * measurement_V);
03655     }
03656     if (max541_midscale_V > 1.0f) {
03657         max541.VRef = 2.0 * max541_midscale_V;
03658         cmdLine.serial().printf("\r\n      Test Fixture: MAX541 midscale = %1.3fV, so fullscale = %1.3fV",
03659                                 max541_midscale_V, max541.VRef);
03660         // Detect whether MAX541 is really connected to MAX32625MBED.AIN0/AIN4
03661         voltageV = 1.0f;
03662         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03663     }
03664     if (SelfTest_has_max541) {
03665         voltageV = 0.0f;
03666         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03667     }
03668     if (SelfTest_has_max541) {
03669         voltageV = 2.7f;
03670         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03671     }
03672     if (SelfTest_has_max541) {
03673         voltageV = 1.65f;
03674         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03675     }
03676     if (SelfTest_has_max541) {
03677         voltageV = 2.0f;
03678         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03679     }
03680     if (SelfTest_has_max541) {
03681         voltageV = 0.25f;
03682         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03683     }
03684     if (SelfTest_has_max541) {
03685         voltageV = 0.5f;
03686         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03687     }
03688     if (SelfTest_has_max541) {
03689         voltageV = 1.0f;
03690         SelfTest_has_max541 = SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03691     }
03692     if (SelfTest_has_max541 == false) {
03693         // don't fail just because we're missing the test fixture...
03694         cmdLine.serial().printf("\r\n      Test Fixture: MAX541 not present");
03695         //~ g_SelfTest_nFail--;
03696     }
03697     //
03698     // TODO1: MAX11131 SelfTest: if Test Fixture: drive MAX541, compare MAX32625MBED.AIN0/AIN4 and MAX11131 AIN0
03699     // indirectly verify the reference voltage by reading a known input voltage
03700     if (SelfTest_has_max541) {
03701         cmdLine.serial().printf("\r\n");
03702         cmdLine.serial().printf("\r\n      2.1: TODO1: Check MAX11131 reference voltage using SCAN_0001_Manual");
03703         voltageV = 1.0f;
03704         SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03705         cmdLine.serial().printf("\r\n      MAX11131.Init()");
03706         g_MAX11131_device.Init();
03707         // 1 ScanManual ch=0 pm=0 id=1
03708         g_MAX11131_device.channelNumber_0_15 = 0;
03709         g_MAX11131_device.PowerManagement_0_2 = 0;
03710         g_MAX11131_device.chan_id_0_1 = 1;
03711         cmdLine.serial().printf("\r\n      MAX11131.channelNumber_0_15=%d", g_MAX11131_device.channelNumber_0_15);
03712         cmdLine.serial().printf("\r\n      MAX11131.PowerManagement_0_2=%d", g_MAX11131_device.PowerManagement_0_2);
03713         cmdLine.serial().printf("\r\n      MAX11131.chan_id_0_1=%d", g_MAX11131_device.chan_id_0_1);
03714         g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
03715         cmdLine.serial().printf("\r\n      MAX11131.ScanManual -- NumWords = %d",
03716                                 g_MAX11131_device.NumWords);
03717         g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
03718         g_MAX11131_device.ReadAINcode();
03719         cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03720         AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03721         //
03722         //  2.1: TODO1: Check MAX11131 reference voltage -- why we read 0xffff 2.4999V here?
03723         //
03724         cmdLine.serial().printf("\r\n      MAX11131.ScanManual -- NumWords = %d",
03725                                 g_MAX11131_device.NumWords);
03726         // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
03727         // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
03728         g_MAX11131_device.ReadAINcode();
03729         cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03730         AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03731         //
03732         //  2.1: TODO1: Check MAX11131 reference voltage -- why we read 0xffff 2.4999V here?
03733         //
03734         // compare with mbed/Arduino AIN0-AIN3
03735         // MAX32625MBED.AIN4 = MAX11131.AIN0
03736         channelId = 0;
03737         value_u12 = g_MAX11131_device.AINcode[channelId];
03738         voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03739 //
03740         // tinyTester.Wait_Output_Settling replaces wait_ms
03741         tinyTester.Wait_Output_Settling();
03742         // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03743         tinyTester.err_threshold = 0.100;
03744         tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03745 //
03746     }
03747     //
03748     if (SelfTest_has_max541) {
03749         voltageV = 1.0f;
03750         SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
03751     }
03752     cmdLine.serial().printf("\r\n");
03753     cmdLine.serial().printf("\r\n      3.1: Test SCAN_0001_Manual");
03754     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03755     g_MAX11131_device.Init();
03756     // 1 ScanManual ch=0 pm=0 id=1
03757     g_MAX11131_device.channelNumber_0_15 = 0;
03758     g_MAX11131_device.PowerManagement_0_2 = 0;
03759     g_MAX11131_device.chan_id_0_1 = 1;
03760     cmdLine.serial().printf("\r\n      MAX11131.channelNumber_0_15=%d", g_MAX11131_device.channelNumber_0_15);
03761     cmdLine.serial().printf("\r\n      MAX11131.PowerManagement_0_2=%d", g_MAX11131_device.PowerManagement_0_2);
03762     cmdLine.serial().printf("\r\n      MAX11131.chan_id_0_1=%d", g_MAX11131_device.chan_id_0_1);
03763     g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
03764     cmdLine.serial().printf("\r\n      MAX11131.ScanManual -- NumWords = %d",
03765                             g_MAX11131_device.NumWords);
03766     // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
03767     // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
03768     g_MAX11131_device.ReadAINcode();
03769     cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03770     AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03771     // compare with mbed/Arduino AIN0-AIN3
03772     // MAX32625MBED.AIN4 = MAX11131.AIN0
03773     channelId = 0;
03774     value_u12 = g_MAX11131_device.AINcode[channelId];
03775     voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03776 //
03777     // tinyTester.Wait_Output_Settling replaces wait_ms
03778     tinyTester.Wait_Output_Settling();
03779     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03780     tinyTester.err_threshold = 0.100;
03781     tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03782 //
03783     //
03784     cmdLine.serial().printf("\r\n");
03785     cmdLine.serial().printf("\r\n      3.4: Test SCAN_0100_StandardExternalClock");
03786     cmdLine.serial().printf("\r\n      MAX11131.Init()");
03787     g_MAX11131_device.Init();
03788     // MAX11131 > 4
03789     // ScanStandardExternalClock ch=9 pm=0 id=1
03790     // ScanRead_nWords_chanID nWords=10
03791     //  ch=0 xu=2964 = 0x0b94 = 1.8091V
03792     //  ch=1 xu=2227 = 0x08b3 = 1.3593V
03793     //  ch=2 xu=1570 = 0x0622 = 0.9583V
03794     //  ch=3 xu=865 = 0x0361 = 0.5280V
03795     //  ch=4 xu=630 = 0x0276 = 0.3845V
03796     //  ch=5 xu=594 = 0x0252 = 0.3625V
03797     //  ch=6 xu=461 = 0x01cd = 0.2814V
03798     //  ch=7 xu=364 = 0x016c = 0.2222V
03799     //  ch=8 xu=480 = 0x01e0 = 0.2930V
03800     //  ch=9 xu=616 = 0x0268 = 0.3760V
03801     g_MAX11131_device.channelNumber_0_15 = 9;
03802     g_MAX11131_device.PowerManagement_0_2 = 0;
03803     g_MAX11131_device.chan_id_0_1 = 1;
03804     cmdLine.serial().printf("\r\n      MAX11131.channelNumber_0_15=%d", g_MAX11131_device.channelNumber_0_15);
03805     cmdLine.serial().printf("\r\n      MAX11131.PowerManagement_0_2=%d", g_MAX11131_device.PowerManagement_0_2);
03806     cmdLine.serial().printf("\r\n      MAX11131.chan_id_0_1=%d", g_MAX11131_device.chan_id_0_1);
03807     g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
03808     cmdLine.serial().printf("\r\n      MAX11131.ScanStandardExternalClock -- NumWords = %d",
03809                             g_MAX11131_device.NumWords);
03810     // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
03811     // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
03812     g_MAX11131_device.ReadAINcode();
03813     cmdLine.serial().printf("\r\n      MAX11131.ReadAINcode");
03814     // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
03815     // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
03816     // expect g_MAX11131_device.NumWords == g_MAX11131_device.channelNumber_0_15 + 1;
03817     // expect RAW_misoData16[index] msnybble 0,1,2,3,...
03818     AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
03819     // compare with mbed/Arduino AIN0-AIN3
03820     // MAX32625MBED.AIN4 = MAX11131.AIN0
03821     channelId = 0;
03822     value_u12 = g_MAX11131_device.AINcode[channelId];
03823     voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03824     // tinyTester.Wait_Output_Settling replaces wait_ms
03825     tinyTester.Wait_Output_Settling();
03826     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03827     tinyTester.err_threshold = 0.100;
03828     tinyTester.AnalogIn0_Read_Expect_voltageV(voltageV);
03829     // compare MAX32625MBED.AIN5 = MAX11131.AIN1
03830     //channelId = 1;
03831     //value_u12 = g_MAX11131_device.AINcode[channelId];
03832     //voltageV = g_MAX11131_device.VoltageOfCode(value_u12, channelId);
03833     //SelfTest_AnalogInput_Expect_ch_V(cmdLine, 5, voltageV, 0.100);
03834     //
03835 #elif APPLICATION_MAX5171
03836 
03837     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03838     //
03839     // Note: ide.mbed.com does not support C++11 Lambda Expressions
03840     // -- see https://os.mbed.com/questions/82580/Is-there-solution-for-defining-of-interr/
03841     // define function under test using C++11 lambda expression [](){}
03842     // uint8_t MAX5171::Init(void)
03843     //uint8_t (*fn_MAX5171_Init)() = [](){ return g_MAX5171_device.Init(); };
03844     //
03845     // define function under test using C++11 lambda expression [](){}
03846     // uint16_t MAX5171::DACCodeOfVoltage(double voltageV)
03847     //uint16_t (*fn_MAX5171_DACCodeOfVoltage)(double) = [](double voltageV){ return g_MAX5171_device.DACCodeOfVoltage(voltageV); };
03848     //
03849     // define function under test using C++11 lambda expression [](){}
03850     // double MAX5171::VoltageOfCode(uint16_t value_u14)
03851     //double (*fn_MAX5171_VoltageOfCode)(uint16_t) = [](uint16_t value_u14){ return g_MAX5171_device.VoltageOfCode(value_u14); };
03852     //
03853     // define function under test using C++11 lambda expression [](){}
03854     // uint8_t MAX5171::CODE_LOAD(uint16_t dacCodeLsbs)
03855     //uint8_t (*fn_MAX5171_CODE_LOAD)(uint16_t dacCodeLsbs) = [](uint16_t dacCodeLsbs){ return g_MAX5171_device.CODE_LOAD(dacCodeLsbs); };
03856     //
03857     //double one_LSB = (g_MAX5171_device.VRef / 16383); // 14-bit DAC FS
03858     // tinyTester.Wait_Output_Settling replaces wait_ms
03859     tinyTester.settle_time_msec = 250;
03860 
03861     g_MAX5171_device.VRef = 2.500;     // MAX5171 14-bit LSB = 0.00015V
03862     SelfTest_print_Vref(cmdLine);
03863     tinyTester.err_threshold = (g_MAX5171_device.VRef / 16383); // 14-bit DAC FS
03864     //
03865     // tinyTester.FunctionCall_Expect replaces SelfTest_DACCodeOfVoltage_Expect
03866     tinyTester.blink_time_msec = 20; // quickly speed through the software verification
03867     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.499847412109375, 0x3FFF);
03868     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.49969482421875, 0x3FFE);
03869     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.499542236328125, 0x3FFD);
03870     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 2.4993896484375, 0x3FFC);
03871     //
03872     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.250152587890625, 0x2001);
03873     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.25, 0x2000);
03874     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.249847412109375, 0x1FFF);
03875     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 1.24969482421875, 0x1FFE);
03876     //
03877     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.000457763671875, 0x0003);
03878     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.00030517578125, 0x0002);
03879     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.000152587890625, 0x0001);
03880     tinyTester.FunctionCall_Expect("MAX5171.DACCodeOfVoltage", fn_MAX5171_DACCodeOfVoltage, 0.00000, 0x0000);
03881     //
03882     // tinyTester.FunctionCall_Expect replaces SelfTest_VoltageOfCode_Expect
03883     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFF, 2.499847412109375);
03884     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFE, 2.49969482421875);
03885     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFD, 2.499542236328125);
03886     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x3FFC, 2.4993896484375);
03887     //
03888     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x2001, 1.250152587890625);
03889     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x2000, 1.25);
03890     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x1FFF, 1.249847412109375);
03891     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x1FFE, 1.24969482421875);
03892     //
03893     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0003, 0.000457763671875);
03894     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0002, 0.00030517578125);
03895     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0001, 0.000152587890625);
03896     tinyTester.FunctionCall_Expect("MAX5171.VoltageOfCode", fn_MAX5171_VoltageOfCode, 0x0000, 0.00000);
03897     //
03898     // Device Testing: DAC commands, verify using on-board ADC inputs
03899     //
03900     tinyTester.blink_time_msec = 75;
03901     cmdLine.serial().printf("\r\n      MAX5171.Init()");
03902     g_MAX5171_device.Init();
03903     //
03904     tinyTester.err_threshold = 0.030; // 30mV
03905     uint16_t code = 0x3FFF;
03906     //~ double voltageV = 0.5;
03907     //
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(2.500);
03914     //
03915     code = 0x0000;
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(0.0000);
03922     //
03923     code = 0x1FFF;
03924     cmdLine.serial().printf("\r\n      MAX5171.CODE_LOAD code=%d", code);
03925     g_MAX5171_device.CODE_LOAD(code);
03926     // tinyTester.Wait_Output_Settling replaces wait_ms
03927     tinyTester.Wait_Output_Settling();
03928     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
03929     tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
03930     //
03931     // test UPO User Programmable Output, verify using digital input D2
03932     //
03933     cmdLine.serial().printf("\r\n      MAX5171.UPO_HIGH");
03934     g_MAX5171_device.UPO_HIGH();
03935     tinyTester.Wait_Output_Settling();
03936     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
03937     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
03938     //
03939     cmdLine.serial().printf("\r\n      MAX5171.UPO_LOW");
03940     g_MAX5171_device.UPO_LOW();
03941     tinyTester.Wait_Output_Settling();
03942     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
03943     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
03944     //
03945     cmdLine.serial().printf("\r\n      MAX5171.UPO_HIGH");
03946     g_MAX5171_device.UPO_HIGH();
03947     tinyTester.Wait_Output_Settling(); // wait_ms(100); // delay
03948     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
03949     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
03950     //
03951 #elif APPLICATION_MAX11410
03952     //
03953     // TODO: placeholder for self-test functions
03954     tinyTester.FAIL();
03955     cmdLine.serial().printf("test program not implemented yet");
03956     //
03957 #elif APPLICATION_MAX12345
03958     //
03959     // TODO: placeholder for self-test functions
03960     tinyTester.FAIL();
03961     cmdLine.serial().printf("test program not implemented yet");
03962     //
03963 #else // APPLICATION_MAX5715
03964       // TODO: placeholder for self-test functions
03965 #endif // APPLICATION_MAX5715
03966        //
03967 #if INJECT_SELFTEST_FAIL
03968     // Test of the pass/fail report mechanism
03969     tinyTester.FAIL();
03970     cmdLine.serial().printf("injecting one false failure for test reporting");
03971 #endif
03972     //
03973     // Report number of pass and number of fail test results
03974     tinyTester.Report_Summary();
03975 }
03976 
03977 
03978 //--------------------------------------------------
03979 void main_menu_status(CmdLine & cmdLine)
03980 {
03981     cmdLine.serial().printf("\r\nMain menu");
03982 #if APPLICATION_MAX5715 // main_menu_status banner
03983     cmdLine.serial().printf(" MAX5715 12-bit 4-ch SPI VOUT DAC");
03984 #elif APPLICATION_MAX11131 // main_menu_status banner
03985     cmdLine.serial().printf(" MAX11131 12-bit 3MSps 16-ch ADC");
03986 #elif APPLICATION_MAX5171 // main_menu_status banner
03987     cmdLine.serial().printf(" MAX5171 14-bit Force/Sense VOUT DAC");
03988 #elif APPLICATION_MAX11410 // main_menu_status banner
03989     cmdLine.serial().printf(" MAX11410 24-bit 1.9ksps Delta-Sigma ADC");
03990 #elif APPLICATION_MAX12345 // main_menu_status banner
03991     cmdLine.serial().printf(" MAX12345");
03992 #else
03993     //cmdLine.serial().printf(" ");
03994 #endif
03995     cmdLine.serial().printf(" %s", TARGET_NAME);
03996     if (cmdLine.nameStr())
03997     {
03998         cmdLine.serial().printf(" [%s]", cmdLine.nameStr());
03999     }
04000 #if HAS_BUTTON1_DEMO_INTERRUPT
04001     cmdLine.serial().printf(" [Button1=DemoConfig1]");
04002 #endif
04003 #if HAS_BUTTON2_DEMO_INTERRUPT
04004     cmdLine.serial().printf(" [Button2=DemoConfig2]");
04005 #endif
04006 #if HAS_BUTTON1_DEMO
04007     // print BUTTON1 status
04008     cmdLine.serial().printf("\r\n BUTTON1 = %d", button1.read());
04009 #endif
04010 #if HAS_BUTTON2_DEMO
04011     // print BUTTON1 status
04012     cmdLine.serial().printf("\r\n BUTTON2 = %d", button2.read());
04013 #endif
04014     cmdLine.serial().printf("\r\n ? -- help");
04015 }
04016 
04017 //--------------------------------------------------
04018 void main_menu_help(CmdLine & cmdLine)
04019 {
04020     // ? -- help
04021     //~ cmdLine.serial().printf("\r\nMenu:");
04022     cmdLine.serial().printf("\r\n # -- lines beginning with # are comments");
04023     cmdLine.serial().printf("\r\n . -- SelfTest");
04024     //cmdLine.serial().printf("\r\n ! -- Initial Configuration");
04025     //
04026     // % standardize diagnostic commands
04027     // %Hpin -- digital output high
04028     // %Lpin -- digital output low
04029     // %?pin -- digital input
04030     // %A %Apin -- analog input
04031     // %Ppin df=xx -- pwm output
04032     // %Wpin -- measure high pulsewidth input in usec
04033     // %wpin -- measure low pulsewidth input in usec
04034     // %I... -- I2C diagnostics
04035     // %IP -- I2C probe
04036     // %IC scl=100khz ADDR=? -- I2C configure
04037     // %IW ADDR=? cmd=? data,data,data -- write
04038     // %IR ADDR=? RD=? -- read
04039     // %I^ cmd=? -- i2c_smbus_read_word_data
04040     // %S... -- SPI diagnostics
04041     // %SC sclk=1Mhz -- SPI configure
04042     // %SW -- write (write and read)
04043     // %SR -- read (alias for %SW because SPI always write and read)
04044     // A-Z,a-z,0-9 reserved for application use
04045     //
04046 #if HAS_digitalInOuts
04047     // %Hpin -- digital output high
04048     // %Lpin -- digital output low
04049     // %?pin -- digital input
04050     cmdLine.serial().printf("\r\n %%Hn {pin:");
04051     list_digitalInOutPins(cmdLine.serial());
04052     cmdLine.serial().printf("} -- High Output");
04053     cmdLine.serial().printf("\r\n %%Ln {pin:");
04054     list_digitalInOutPins(cmdLine.serial());
04055     cmdLine.serial().printf("} -- Low Output");
04056     cmdLine.serial().printf("\r\n %%?n {pin:");
04057     list_digitalInOutPins(cmdLine.serial());
04058     cmdLine.serial().printf("} -- Input");
04059 #endif
04060 
04061 #if HAS_analogIns
04062     // Menu A) analogRead A0..7
04063     // %A %Apin -- analog input
04064     // analogRead(pinIndex) // analog input pins A0, A1, A2, A3, A4, A5; float voltage = analogRead(A0) * (5.0 / 1023.0)
04065     cmdLine.serial().printf("\r\n %%A -- analogRead");
04066 #endif
04067 
04068 #if HAS_SPI2_MAX541
04069     // TODO1: MAX541 max541(spi2_max541, spi2_max541_cs);
04070     cmdLine.serial().printf("\r\n %%D -- DAC output MAX541 (SPI2)");
04071 #endif
04072 
04073 #if HAS_I2C // SUPPORT_I2C
04074     // TODO: support I2C HAS_I2C // SUPPORT_I2C
04075     // VERIFY: I2C utility commands SUPPORT_I2C
04076     // VERIFY: report g_I2C_SCL_Hz = (F_CPU / ((TWBR * 2) + 16)) from last Wire_Sr.setClock(I2C_SCL_Hz);
04077     // %I... -- I2C diagnostics
04078     // %IP -- I2C probe
04079     // %IC scl=100khz ADDR=? -- I2C configure
04080     // %IW byte byte ... byte RD=? ADDR=0x -- write
04081     // %IR ADDR=? RD=? -- read
04082     // %I^ cmd=? -- i2c_smbus_read_word_data
04083     //g_I2C_SCL_Hz = (F_CPU / ((TWBR * 2) + 16));   // 'F_CPU' 'TWBR' not declared in this scope
04084     cmdLine.serial().printf("\r\n %%IC ADDR=0x%2.2x=(0x%2.2x>>1) SCL=%d=%1.3fkHz -- I2C config",
04085                             g_I2C_deviceAddress7, (g_I2C_deviceAddress7 << 1), g_I2C_SCL_Hz,
04086                             (g_I2C_SCL_Hz / 1000.));
04087     cmdLine.serial().printf("\r\n %%IW byte byte ... byte RD=? ADDR=0x%2.2x -- I2C write/read",
04088                             g_I2C_deviceAddress7);
04089     //
04090 #if SUPPORT_I2C
04091     // Menu ^ cmd=?) i2c_smbus_read_word_data
04092     cmdLine.serial().printf("\r\n %%I^ cmd=? -- i2c_smbus_read_word_data");
04093     // test low-level I2C i2c_smbus_read_word_data
04094 #endif // SUPPORT_I2C
04095     //cmdLine.serial().printf(" H) Hunt for attached I2C devices");
04096     cmdLine.serial().printf("\r\n %%IP -- I2C Probe for attached devices");
04097     // cmdLine.serial().printf(" s) search i2c address");
04098 #endif // SUPPORT_I2C
04099 
04100 #if HAS_SPI // SUPPORT_SPI
04101     // TODO: support SPI HAS_SPI // SUPPORT_SPI
04102     // SPI test command  S (mosiData)+
04103     // %S... -- SPI diagnostics
04104     // %SC sclk=1Mhz -- SPI configure
04105     // %SW -- write (write and read)
04106     // %SR -- read (alias for %SW because SPI always write and read)
04107     // spi.format(8,0); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
04108     // spi.format(8,1); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=1 falling edge (initial default)
04109     // spi.format(8,2); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=0 falling edge (initial default)
04110     // spi.format(8,3); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=1 rising edge (initial default)
04111     // spi.frequency(1000000); // int SCLK_Hz=1000000 = 1MHz (initial default)
04112     // mode | POL PHA
04113     // -----+--------
04114     //   0  |  0   0
04115     //   1  |  0   1
04116     //   2  |  1   0
04117     //   3  |  1   1
04118     //cmdLine.serial().printf(" S) SPI mosi,mosi,...mosi hex bytes SCLK=1000000 CPOL=0 CPHA=0");
04119     // 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=]
04120     cmdLine.serial().printf("\r\n %%SC SCLK=%ld=%1.3fMHz CPOL=%d CPHA=%d -- SPI config",
04121                             g_SPI_SCLK_Hz, (g_SPI_SCLK_Hz / 1000000.),
04122                             ((g_SPI_dataMode & SPI_MODE2) ? 1 : 0),
04123                             ((g_SPI_dataMode & SPI_MODE1) ? 1 : 0));
04124     cmdLine.serial().printf("\r\n %%SW mosi,mosi,...mosi -- SPI write hex bytes");
04125     // VERIFY: parse new SPI settings parse_strCommandArgs() SCLK=1000000 CPOL=0 CPHA=0
04126 #endif // SUPPORT_SPI
04127        //
04128        // Application-specific commands (help text) here
04129        //
04130 #if APPLICATION_ArduinoPinsMonitor
04131 # if APPLICATION_MAX5715 // main_menu_help
04132 # elif APPLICATION_MAX11131 // main_menu_help
04133 # elif APPLICATION_MAX5171 // main_menu_help
04134 # elif APPLICATION_MAX11410 // main_menu_help
04135 # elif APPLICATION_MAX12345 // main_menu_help
04136 # else
04137     cmdLine.serial().printf("\r\n A-Z,a-z,0-9 -- reserved for application use");     // ArduinoPinsMonitor
04138 # endif
04139 #endif // APPLICATION_ArduinoPinsMonitor
04140        //
04141 #if APPLICATION_MAX5715 // main_menu_help
04142     cmdLine.serial().printf("\r\n 0 ch=? code=? -- CODEn");
04143     cmdLine.serial().printf("\r\n 1 ch=? -- LOADn");
04144     cmdLine.serial().printf("\r\n 2 ch=? code=? -- CODEnLOADall");
04145     cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
04146     cmdLine.serial().printf("\r\n 40 ch=? -- POWERn_Normal");
04147     cmdLine.serial().printf("\r\n 41 ch=? -- POWERn_PD1k");
04148     cmdLine.serial().printf("\r\n 42 ch=? -- POWERn_PD100k");
04149     cmdLine.serial().printf("\r\n 43 ch=? -- POWERn_PDHiZ");
04150     cmdLine.serial().printf("\r\n 50 -- SW_CLEAR");
04151     cmdLine.serial().printf("\r\n 51 -- SW_RESET");
04152     cmdLine.serial().printf("\r\n 60 ch=? -- CONFIGn_LATCHED");
04153     cmdLine.serial().printf("\r\n 61 ch=? -- CONFIGn_TRANSPARENT");
04154     cmdLine.serial().printf("\r\n 68 -- CONFIGall_LATCHED");
04155     cmdLine.serial().printf("\r\n 69 -- CONFIGall_TRANSPARENT");
04156     cmdLine.serial().printf("\r\n 70 -- REF_EXT");
04157     cmdLine.serial().printf("\r\n 71 -- REF_2V500");
04158     cmdLine.serial().printf("\r\n 72 -- REF_2V048");
04159     cmdLine.serial().printf("\r\n 73 -- REF_4V096");
04160     cmdLine.serial().printf("\r\n 74 -- REF_AlwaysOn_EXT");
04161     cmdLine.serial().printf("\r\n 75 -- REF_AlwaysOn_2V500");
04162     cmdLine.serial().printf("\r\n 76 -- REF_AlwaysOn_2V048");
04163     cmdLine.serial().printf("\r\n 77 -- REF_AlwaysOn_4V096");
04164     cmdLine.serial().printf("\r\n 80 code=? -- CODEall");
04165     cmdLine.serial().printf("\r\n 81 -- LOADall");
04166     cmdLine.serial().printf("\r\n 82 code=? -- CODEallLOADall");
04167     //cmdLine.serial().printf("\r\n 83 code=? -- CODEallLOADall");
04168     //
04169     // Menu @ -- print device configuration
04170     cmdLine.serial().printf("\r\n @ -- print MAX5715 configuration");
04171     //
04172     // MAX5717 menu function to drive MAX5717_LDACb_Pin LDAC#
04173     // Note: '~' is not recommended for menu commands, interferes with ssh
04174     cmdLine.serial().printf("\r\n L -- LDAC# pulse LH high LL low");
04175     // MAX5717 menu function to drive MAX5717_CLRb_Pin CLR#
04176     cmdLine.serial().printf("\r\n C -- CLR# pulse CH high CL low");
04177 #endif // APPLICATION_MAX5715
04178        //
04179 #if APPLICATION_MAX11131 // main_menu_help
04180     // VERIFY: console menu command 0 int16_t MAX11131_ScanRead(void);
04181     cmdLine.serial().printf("\r\n 0 n=?                                  -- MAX11131_ScanRead");
04182     // VERIFY: console menu command 1 MAX11131_ScanManual(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
04183     cmdLine.serial().printf("\r\n 1 ch=? pm=? id=?                       -- MAX11131_ScanManual");
04184     // 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);
04185     cmdLine.serial().printf("\r\n 2 ch=? av=? n=? pm=? swcnv=?           -- MAX11131_ScanRepeat");
04186     // 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);
04187     cmdLine.serial().printf("\r\n 3 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanStandardIntClock");
04188     // VERIFY: console menu command 4 MAX11131_ScanStandardExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
04189     cmdLine.serial().printf("\r\n 4 ch=? pm=? id=?                       -- MAX11131_ScanStandardExtClock");
04190     // 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);
04191     cmdLine.serial().printf("\r\n 5 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanUpperIntClock");
04192     // VERIFY: console menu command 6 MAX11131_ScanUpperExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
04193     cmdLine.serial().printf("\r\n 6 ch=? pm=? id=?                       -- MAX11131_ScanUpperExtClock");
04194     // 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);
04195     cmdLine.serial().printf("\r\n 7 enableMask=0xffff av=? pm=? swcnv=?  -- MAX11131_ScanCustomIntClock");
04196     // VERIFY: console menu command 8 MAX11131_ScanCustomExternalClock(int16_t enabledChannelsMask, int PowerManagement_0_2, int chan_id_0_1);
04197     cmdLine.serial().printf("\r\n 8 enableMask=0xffff pm=0 id=1          -- MAX11131_ScanCustomExtClock");
04198     // VERIFY: console menu command 9 MAX11131_ScanSampleSetExternalClock(uint8_t enabledChannelsPatternLength_1_256, int16_t enabledChannelsPattern[], int PowerManagement_0_2, int chan_id_0_1);
04199     cmdLine.serial().printf("\r\n 9 channelsPattern... pm=? id=? | len=? -- MAX11131_ScanSampleSetExtClock");
04200     cmdLine.serial().printf("\r\n @                                      -- print MAX11131 configuration");
04201     cmdLine.serial().printf("\r\n ISc) IUc) IBc) IRc) reconfigure channel single-ended/unipolar/bipolar/range");
04202     // cmdLine.serial().printf("\r\n & -- MAX11131_Example_ScanManual");
04203     // Note: '~' is not recommended for menu commands, interferes with ssh
04204 #endif // APPLICATION_MAX11131
04205        //
04206 #if APPLICATION_MAX5171 // main_menu_help
04207     // TODO1: MAX5171 main_menu_help
04208     cmdLine.serial().printf("\r\n 0 code=? -- CODE");
04209     cmdLine.serial().printf("\r\n 4 code=? -- CODE_LOAD");
04210     cmdLine.serial().printf("\r\n 8 -- LOAD");
04211     cmdLine.serial().printf("\r\n c -- NOP");
04212     cmdLine.serial().printf("\r\n d -- SHUTDOWN");
04213     cmdLine.serial().printf("\r\n e0 -- UPO_LOW");
04214     cmdLine.serial().printf("\r\n e8 -- UPO_HIGH");
04215     cmdLine.serial().printf("\r\n f0 -- MODE1_DOUT_SCLK_RISING_EDGE");
04216     cmdLine.serial().printf("\r\n f8 -- MODE0_DOUT_SCLK_FALLING_EDGE");
04217     // Note: '~' is not recommended for menu commands, interferes with ssh
04218 #endif // APPLICATION_MAX5171
04219        //
04220 #if APPLICATION_MAX11410 // main_menu_help
04221     // TODO1: MAX11410 main_menu_help
04222     cmdLine.serial().printf("\r\n w reg=? data=? -- write register");
04223     cmdLine.serial().printf("\r\n r reg=? -- read register");
04224     cmdLine.serial().printf("\r\n TC -- thermocouple config");
04225     cmdLine.serial().printf("\r\n T -- RTD measurement");
04226     cmdLine.serial().printf("\r\n RC -- thermocouple config");
04227     cmdLine.serial().printf("\r\n R -- RTD measurement");
04228     // Note: '~' is not recommended for menu commands, interferes with ssh
04229 #endif // APPLICATION_MAX11410
04230        //
04231 #if APPLICATION_MAX12345 // main_menu_help
04232     cmdLine.serial().printf("\r\n 0 -- something");
04233     cmdLine.serial().printf("\r\n 1 -- something");
04234     cmdLine.serial().printf("\r\n 2 -- something");
04235     cmdLine.serial().printf("\r\n A -- something");
04236     cmdLine.serial().printf("\r\n B -- something");
04237     cmdLine.serial().printf("\r\n C -- something");
04238     // Note: '~' is not recommended for menu commands, interferes with ssh
04239 #endif // APPLICATION_MAX12345
04240        //
04241 }
04242 
04243 //--------------------------------------------------
04244 // diagnostic commands submenu
04245 // invoked by main_menu_onEOLcommandParser case '%'
04246 void pinsMonitor_submenu_onEOLcommandParser(CmdLine & cmdLine)
04247 {
04248     // % diagnostic commands submenu
04249     // %Hpin -- digital output high
04250     // %Lpin -- digital output low
04251     // %?pin -- digital input
04252     // %A %Apin -- analog input
04253     // %Ppin df=xx -- pwm output
04254     // %Wpin -- measure high pulsewidth input in usec
04255     // %wpin -- measure low pulsewidth input in usec
04256     // %I... -- I2C diagnostics
04257     // %IP -- I2C probe
04258     // %IC scl=100khz ADDR=? -- I2C configure
04259     // %IW byte byte ... byte RD=? ADDR=0x -- write
04260     // %IR ADDR=? RD=? -- read
04261     // %I^ cmd=? -- i2c_smbus_read_word_data
04262     // %S... -- SPI diagnostics
04263     // %SC sclk=1Mhz -- SPI configure
04264     // %SW -- write (write and read)
04265     // %SR -- read (alias for %SW because SPI always write and read)
04266     // A-Z,a-z,0-9 reserved for application use
04267     //
04268     // get pinIndex from cmdLine[2]
04269     //int pinIndex = cmdLine[2];
04270     // *** warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
04271     //int pinIndex = strtoul((char *)((void *)(cmdLine.str()) + 2), NULL, 10); // strtol(str, NULL, 10): get decimal value
04272     //                                                        ^
04273     char strPinIndex[3];
04274     strPinIndex[0] = cmdLine[2];
04275     strPinIndex[1] = cmdLine[3];
04276     strPinIndex[2] = '\0';
04277     int pinIndex = strtoul(strPinIndex, NULL, 10);         // strtol(str, NULL, 10): get decimal value
04278     //cmdLine.serial().printf(" pinIndex=%d ", pinIndex);
04279     //
04280     // get next character
04281     switch (cmdLine[1])
04282     {
04283 #if HAS_digitalInOuts
04284         case 'H': case 'h':
04285         {
04286             // %Hpin -- digital output high
04287 #if ARDUINO_STYLE
04288             pinMode(pinIndex, OUTPUT);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04289             digitalWrite(pinIndex, HIGH);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04290 #else
04291             DigitalInOut& digitalInOutPin = find_digitalInOutPin(pinIndex);
04292             digitalInOutPin.output();
04293             digitalInOutPin.write(1);
04294 #endif
04295             cmdLine.serial().printf(" digitalInOutPin %d Output High ", pinIndex);
04296         }
04297         break;
04298         case 'L': case 'l':
04299         {
04300             // %Lpin -- digital output low
04301 #if ARDUINO_STYLE
04302             pinMode(pinIndex, OUTPUT);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04303             digitalWrite(pinIndex, LOW);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04304 #else
04305             DigitalInOut& digitalInOutPin = find_digitalInOutPin(pinIndex);
04306             digitalInOutPin.output();
04307             digitalInOutPin.write(0);
04308 #endif
04309             cmdLine.serial().printf(" digitalInOutPin %d Output Low ", pinIndex);
04310         }
04311         break;
04312         case '?':
04313         {
04314             // %?pin -- digital input
04315 #if ARDUINO_STYLE
04316             pinMode(pinIndex, INPUT);             // digital pins 0, 1, 2, .. 13, analog input pins A0, A1, .. A5
04317 #else
04318             DigitalInOut& digitalInOutPin = find_digitalInOutPin(pinIndex);
04319             digitalInOutPin.input();
04320 #endif
04321             serial.printf(" digitalInOutPin %d Input ", pinIndex);
04322 #if ARDUINO_STYLE
04323             int value = digitalRead(pinIndex);
04324 #else
04325             int value = digitalInOutPin.read();
04326 #endif
04327             cmdLine.serial().printf("%d ", value);
04328         }
04329         break;
04330 #endif
04331         //
04332 #if HAS_analogIns
04333         case 'A': case 'a':
04334         {
04335             // %A %Apin -- analog input
04336 #if analogIn4_IS_HIGH_RANGE_OF_analogIn0
04337             // Platform board uses AIN4,AIN5,.. as high range of AIN0,AIN1,..
04338             for (int pinIndex = 0; pinIndex < 2; pinIndex++)
04339             {
04340                 int cPinIndex = '0' + pinIndex;
04341                 AnalogIn& analogInPin = find_analogInPin(cPinIndex);
04342                 float adc_full_scale_voltage = analogInPin_fullScaleVoltage[pinIndex];
04343                 float normValue_0_1 = analogInPin.read();
04344                 //
04345                 int pinIndexH = pinIndex + 4;
04346                 int cPinIndexH = '0' + pinIndexH;
04347                 AnalogIn& analogInPinH = find_analogInPin(cPinIndexH);
04348                 float adc_full_scale_voltageH = analogInPin_fullScaleVoltage[pinIndexH];
04349                 float normValueH_0_1 = analogInPinH.read();
04350                 //
04351                 cmdLine.serial().printf("AIN%c = %7.3f%% = %1.3fV  AIN%c = %7.3f%% = %1.3fV  \r\n",
04352                                         cPinIndex,
04353                                         normValue_0_1 * 100.0,
04354                                         normValue_0_1 * adc_full_scale_voltage,
04355                                         cPinIndexH,
04356                                         normValueH_0_1 * 100.0,
04357                                         normValueH_0_1 * adc_full_scale_voltageH
04358                                         );
04359             }
04360             for (int pinIndex = 2; pinIndex < 4; pinIndex++)
04361             {
04362                 int cPinIndex = '0' + pinIndex;
04363                 AnalogIn& analogInPin = find_analogInPin(cPinIndex);
04364                 float adc_full_scale_voltage = analogInPin_fullScaleVoltage[pinIndex];
04365                 float normValue_0_1 = analogInPin.read();
04366                 //
04367                 cmdLine.serial().printf("AIN%c = %7.3f%% = %1.3fV\r\n",
04368                                         cPinIndex,
04369                                         normValue_0_1 * 100.0,
04370                                         normValue_0_1 * adc_full_scale_voltage
04371                                         );
04372             }
04373 #else // analogIn4_IS_HIGH_RANGE_OF_analogIn0
04374             // Platform board uses simple analog inputs
04375             // assume standard Arduino analog inputs A0-A5
04376             for (int pinIndex = 0; pinIndex < 6; pinIndex++)
04377             {
04378                 int cPinIndex = '0' + pinIndex;
04379                 AnalogIn& analogInPin = find_analogInPin(cPinIndex);
04380                 float adc_full_scale_voltage = analogInPin_fullScaleVoltage[pinIndex];
04381                 float normValue_0_1 = analogInPin.read();
04382                 //
04383                 cmdLine.serial().printf("AIN%c = %7.3f%% = %1.3fV\r\n",
04384                                         cPinIndex,
04385                                         normValue_0_1 * 100.0,
04386                                         normValue_0_1 * adc_full_scale_voltage
04387                                         );
04388             }
04389 #endif // analogIn4_IS_HIGH_RANGE_OF_analogIn0
04390         }
04391         break;
04392 #endif
04393         //
04394 #if HAS_SPI2_MAX541
04395         case 'D': case 'd':
04396         {
04397             // %D -- DAC output MAX541 (SPI2) -- need cmdLine.parse_float(voltageV)
04398             // MAX541 max541(spi2_max541, spi2_max541_cs);
04399             float voltageV = max541.Get_Voltage();
04400             // if (cmdLine[2] == '+') {
04401             //     // %D+
04402             //     voltageV = voltageV * 1.25f;
04403             //     if (voltageV >= max541.VRef) voltageV = max541.VRef;
04404             //     SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04405             // }
04406             // else if (cmdLine[2] == '-') {
04407             //     // %D-
04408             //     voltageV = voltageV * 0.75f;
04409             //     if (voltageV < 0.1f) voltageV = 0.1f;
04410             //     SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04411             // }
04412             if (cmdLine.parse_float("V", voltageV))
04413             {
04414                 // %D V=1.234 -- set voltage
04415                 max541.Set_Voltage(voltageV);
04416             }
04417             else if (cmdLine.parse_float("TEST", voltageV))
04418             {
04419                 // %D TEST=1.234 -- set voltage and compare with AIN0
04420                 SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04421             }
04422             else if (cmdLine.parse_float("CAL", voltageV))
04423             {
04424                 // %D CAL=1.234 -- calibrate VRef and compare with AIN0
04425 
04426                 max541.Set_Code(0x8000); // we don't know the fullscale voltage yet, so set code to midscale
04427                 double max541_midscale_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
04428                 const int average_count = 100;
04429                 const double average_K = 0.25;
04430                 for (int count = 0; count < average_count; count++) {
04431                     double measurement_V = analogInPin_fullScaleVoltage[4] * analogIn4.read(); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0     fullscale is 6.0V
04432                     max541_midscale_V = ((1 - average_K) * max541_midscale_V) + (average_K * measurement_V);
04433                 }
04434                 max541.VRef = 2.0 * max541_midscale_V;
04435                 cmdLine.serial().printf(
04436                     "\r\n      MAX541 midscale = %1.3fV, so fullscale = %1.3fV",
04437                     max541_midscale_V, max541.VRef);
04438                 // Detect whether MAX541 is really connected to MAX32625MBED.AIN0/AIN4
04439                 voltageV = 1.0f;
04440                 SelfTest_MAX541_Voltage(cmdLine, max541, voltageV);
04441             }
04442             else {
04443                 // %D -- print MAX541 DAC status
04444                 cmdLine.serial().printf("MAX541 code=0x%4.4x = %1.3fV  VRef=%1.3fV\r\n",
04445                                         max541.Get_Code(), max541.Get_Voltage(), max541.VRef);
04446             }
04447         }
04448         break;
04449 #endif
04450 
04451         //
04452 #if HAS_I2C // SUPPORT_I2C
04453         case 'I': case 'i':
04454             // %I... -- I2C diagnostics
04455             // %IP -- I2C probe
04456             // %IC scl=100khz ADDR=? -- I2C configure
04457             // %IW byte byte ... byte RD=? ADDR=0x -- write
04458             // %IR ADDR=? RD=? -- read
04459             // %I^ cmd=? -- i2c_smbus_read_word_data
04460             // get next character
04461             // TODO: parse cmdLine arg (ADDR=\d+)? --> g_I2C_deviceAddress7
04462             cmdLine.parse_byte_hex("ADDR", g_I2C_deviceAddress7);
04463             // TODO: parse cmdLine arg (RD=\d)? --> g_I2C_read_count
04464             g_I2C_read_count = 0;         // read count must be reset every command
04465             cmdLine.parse_byte_dec("RD", g_I2C_read_count);
04466             // TODO: parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
04467             cmdLine.parse_byte_hex("CMD", g_I2C_command_regAddress);
04468             switch (cmdLine[2])
04469             {
04470                 case 'P': case 'p':
04471                 {
04472                     // %IP -- I2C probe
04473                     HuntAttachedI2CDevices(cmdLine, 0x03, 0x77);
04474                 }
04475                 break;
04476                 case 'C': case 'c':
04477                 {
04478                     bool isUpdatedI2CConfig = false;
04479                     // %IC scl=100khz ADDR=? -- I2C configure
04480                     // parse cmdLine arg (SCL=\d+(kHZ|MHZ)?)? --> g_I2C_SCL_Hz
04481                     if (cmdLine.parse_frequency_Hz("SCL", g_I2C_SCL_Hz))
04482                     {
04483                         isUpdatedI2CConfig = true;
04484                         // TODO1: validate g_I2C_SCL_Hz against system clock frequency F_CPU
04485                         if (g_I2C_SCL_Hz > limit_max_I2C_SCL_Hz)
04486                         {
04487                             g_I2C_SCL_Hz = limit_max_I2C_SCL_Hz;
04488                         }
04489                         if (g_I2C_SCL_Hz < limit_min_I2C_SCL_Hz)
04490                         {
04491                             g_I2C_SCL_Hz = limit_min_I2C_SCL_Hz;
04492                         }
04493                     }
04494                     if (isUpdatedI2CConfig)
04495                     {
04496                         // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04497                         I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04498                         i2cMaster.frequency(g_I2C_SCL_Hz);
04499                         i2cMaster.start();
04500                         i2cMaster.stop();
04501                         i2cMaster.frequency(g_I2C_SCL_Hz);
04502                         cmdLine.serial().printf(
04503                             "\r\n %%IC ADDR=0x%2.2x=(0x%2.2x>>1) SCL=%d=%1.3fkHz -- I2C config",
04504                             g_I2C_deviceAddress7, (g_I2C_deviceAddress7 << 1), g_I2C_SCL_Hz,
04505                             (g_I2C_SCL_Hz / 1000.));
04506                         i2cMaster.start();
04507                         i2cMaster.stop();
04508                     }
04509                 }
04510                 break;
04511                 case 'W': case 'w':
04512                 {
04513                     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04514                     I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04515                     i2cMaster.frequency(g_I2C_SCL_Hz);
04516                     // %IW byte byte ... byte RD=? ADDR=0x -- write
04517                     // parse cmdLine byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
04518                     #define MAX_I2C_BYTE_COUNT 32
04519                     size_t byteCount = byteCount;
04520                     static char mosiData[MAX_I2C_BYTE_COUNT];
04521                     static char misoData[MAX_I2C_BYTE_COUNT];
04522                     if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData,
04523                                                              MAX_I2C_BYTE_COUNT))
04524                     {
04525                         // hex dump mosiData[0..byteCount-1]
04526                         cmdLine.serial().printf(
04527                             "\r\nADDR=0x%2.2x=(0x%2.2x>>1) byteCount:%d RD=%d\r\nI2C MOSI->",
04528                             g_I2C_deviceAddress7,
04529                             (g_I2C_deviceAddress7 << 1), byteCount, g_I2C_read_count);
04530                         for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
04531                         {
04532                             cmdLine.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
04533                         }
04534                         //
04535                         // TODO: i2c transfer
04536                         //const int addr7bit = 0x48;      // 7 bit I2C address
04537                         //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
04538                         // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
04539                         // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
04540                         // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
04541                         // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
04542                         // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
04543                         // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
04544                         // /* 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...
04545                         // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
04546                         const int addr8bit = g_I2C_deviceAddress7 << 1;             // 8bit I2C address, 0x90
04547                         unsigned int misoLength = 0;
04548                         bool repeated = (g_I2C_read_count > 0);
04549                         //
04550                         int writeStatus = i2cMaster.write (addr8bit, mosiData, byteCount, repeated);
04551                         switch (writeStatus)
04552                         {
04553                             case 0: cmdLine.serial().printf(" ack "); break;
04554                             case 1: cmdLine.serial().printf(" nack "); break;
04555                             default: cmdLine.serial().printf(" {writeStatus 0x%2.2X} ",
04556                                                              writeStatus);
04557                         }
04558                         if (repeated)
04559                         {
04560                             int readStatus =
04561                                 i2cMaster.read (addr8bit, misoData, g_I2C_read_count, false);
04562                             switch (readStatus)
04563                             {
04564                                 case 1: cmdLine.serial().printf(" nack "); break;
04565                                 case 0: cmdLine.serial().printf(" ack "); break;
04566                                 default: cmdLine.serial().printf(" {readStatus 0x%2.2X} ",
04567                                                                  readStatus);
04568                             }
04569                         }
04570                         //
04571                         if (misoLength > 0)
04572                         {
04573                             // hex dump misoData[0..byteCount-1]
04574                             cmdLine.serial().printf("  MISO<-");
04575                             for (unsigned int byteIndex = 0; byteIndex < g_I2C_read_count;
04576                                  byteIndex++)
04577                             {
04578                                 cmdLine.serial().printf(" 0x%2.2X", misoData[byteIndex]);
04579                             }
04580                         }
04581                         cmdLine.serial().printf(" ");
04582                     }
04583                 }
04584                 break;
04585                 case 'R': case 'r':
04586                 {
04587                     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04588                     I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04589                     i2cMaster.frequency(g_I2C_SCL_Hz);
04590                     // %IR ADDR=? RD=? -- read
04591                     // TODO: i2c transfer
04592                     //const int addr7bit = 0x48;      // 7 bit I2C address
04593                     //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
04594                     // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
04595                     // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
04596                     // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
04597                     // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
04598                     // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
04599                     // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
04600                     // /* 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...
04601                     // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
04602                 }
04603                 break;
04604                 case '^':
04605                 {
04606                     // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
04607                     I2C i2cMaster(I2C0_SDA, I2C0_SCL);             // sda scl TARGET_MAX32635MBED: P1_6, P1_7 Arduino 10-pin header
04608                     i2cMaster.frequency(g_I2C_SCL_Hz);
04609                     // %I^ cmd=? -- i2c_smbus_read_word_data
04610                     // TODO: i2c transfer
04611                     //const int addr7bit = 0x48;      // 7 bit I2C address
04612                     //const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
04613                     // /* int  */   i2cMaster.read (int addr8bit, char *data, int length, bool repeated=false) // Read from an I2C slave.
04614                     // /* int  */   i2cMaster.read (int ack) // Read a single byte from the I2C bus.
04615                     // /* int  */   i2cMaster.write (int addr8bit, const char *data, int length, bool repeated=false) // Write to an I2C slave.
04616                     // /* int  */   i2cMaster.write (int data) // Write single byte out on the I2C bus.
04617                     // /* void */   i2cMaster.start (void) // Creates a start condition on the I2C bus.
04618                     // /* void */   i2cMaster.stop (void) // Creates a stop condition on the I2C bus.
04619                     // /* 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...
04620                     // /* void */   i2cMaster.abort_transfer () // Abort the ongoing I2C transfer. More...
04621                 }
04622                 break;
04623             }         // switch(cmdLine[2])
04624             break;
04625 #endif
04626         //
04627 #if HAS_SPI // SUPPORT_SPI
04628         case 'S': case 's':
04629         {
04630             // %S... -- SPI diagnostics
04631             // %SC sclk=1Mhz -- SPI configure
04632             // %SW -- write (write and read)
04633             // %SR -- read (alias for %SW because SPI always write and read)
04634             //
04635             // Process arguments SCLK=\d+(kHZ|MHZ) CPOL=\d CPHA=\d
04636             bool isUpdatedSPIConfig = false;
04637             // parse cmdLine arg (CPOL=\d)? --> g_SPI_dataMode | SPI_MODE2
04638             // parse cmdLine arg (CPHA=\d)? --> g_SPI_dataMode | SPI_MODE1
04639             if (cmdLine.parse_flag("CPOL", g_SPI_dataMode, SPI_MODE2))
04640             {
04641                 isUpdatedSPIConfig = true;
04642             }
04643             if (cmdLine.parse_flag("CPHA", g_SPI_dataMode, SPI_MODE1))
04644             {
04645                 isUpdatedSPIConfig = true;
04646             }
04647             if (cmdLine.parse_flag("CS", g_SPI_cs_state, 1))
04648             {
04649                 isUpdatedSPIConfig = true;
04650             }
04651             // parse cmdLine arg (SCLK=\d+(kHZ|MHZ)?)? --> g_SPI_SCLK_Hz
04652             if (cmdLine.parse_frequency_Hz("SCLK", g_SPI_SCLK_Hz))
04653             {
04654                 isUpdatedSPIConfig = true;
04655                 // TODO1: validate g_SPI_SCLK_Hz against system clock frequency F_CPU
04656                 if (g_SPI_SCLK_Hz > limit_max_SPI_SCLK_Hz)
04657                 {
04658                     g_SPI_SCLK_Hz = limit_max_SPI_SCLK_Hz;
04659                 }
04660                 if (g_SPI_SCLK_Hz < limit_min_SPI_SCLK_Hz)
04661                 {
04662                     g_SPI_SCLK_Hz = limit_min_SPI_SCLK_Hz;
04663                 }
04664             }
04665             // Update SPI configuration
04666             if (isUpdatedSPIConfig)
04667             {
04668                 // %SC sclk=1Mhz -- SPI configure
04669                 spi_cs = g_SPI_cs_state;
04670                 spi.format(8,g_SPI_dataMode);             // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0
04671 #if APPLICATION_MAX5715
04672                 g_MAX5715_device.spi_frequency(g_SPI_SCLK_Hz);
04673 #elif APPLICATION_MAX11131
04674                 g_MAX11131_device.spi_frequency(g_SPI_SCLK_Hz);
04675 #elif APPLICATION_MAX5171
04676                 g_MAX5171_device.spi_frequency(g_SPI_SCLK_Hz);
04677 #elif APPLICATION_MAX11410
04678                 g_MAX11410_device.spi_frequency(g_SPI_SCLK_Hz);
04679 #elif APPLICATION_MAX12345
04680                 g_MAX12345_device.spi_frequency(g_SPI_SCLK_Hz);
04681 #else
04682                 spi.frequency(g_SPI_SCLK_Hz);             // int SCLK_Hz=1000000 = 1MHz (initial default)
04683 #endif
04684                 //
04685                 double ideal_divisor = ((double)SystemCoreClock) / g_SPI_SCLK_Hz;
04686                 int actual_divisor = (int)(ideal_divisor + 0.0);             // frequency divisor truncate
04687                 double actual_SCLK_Hz = SystemCoreClock / actual_divisor;
04688                 //
04689                 // 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=]
04690                 cmdLine.serial().printf(
04691                     "\r\n %%SC CPOL=%d CPHA=%d CS=%d SCLK=%ld=%1.3fMHz (%1.1fMHz/%1.2f = actual %1.3fMHz) -- SPI config",
04692                     ((g_SPI_dataMode & SPI_MODE2) ? 1 : 0),
04693                     ((g_SPI_dataMode & SPI_MODE1) ? 1 : 0),
04694                     g_SPI_cs_state,
04695                     g_SPI_SCLK_Hz,
04696                     (g_SPI_SCLK_Hz / 1000000.),
04697                     ((double)(SystemCoreClock / 1000000.)),
04698                     ideal_divisor,
04699                     (actual_SCLK_Hz / 1000000.)
04700                     );
04701             }
04702             // get next character
04703             switch (cmdLine[2])
04704             {
04705                 case 'C': case 's':
04706                     // %SC sclk=1Mhz -- SPI configure
04707                     break;
04708                 case 'W': case 'R': case 'w': case 'r':
04709                 {
04710                     // %SW -- write (write and read)
04711                     // %SR -- read (alias for %SW because SPI always write and read)
04712                     // parse cmdLine byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
04713                     #define MAX_SPI_BYTE_COUNT 32
04714                     size_t byteCount = byteCount;
04715                     static char mosiData[MAX_SPI_BYTE_COUNT];
04716                     static char misoData[MAX_SPI_BYTE_COUNT];
04717                     if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData,
04718                                                              MAX_SPI_BYTE_COUNT))
04719                     {
04720                         // hex dump mosiData[0..byteCount-1]
04721                         cmdLine.serial().printf("\r\nSPI");
04722                         if (byteCount > 7) {
04723                             cmdLine.serial().printf(" byteCount:%d", byteCount);
04724                         }
04725                         cmdLine.serial().printf(" MOSI->");
04726                         for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
04727                         {
04728                             cmdLine.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
04729                         }
04730                         spi_cs = 0;
04731                         unsigned int numBytesTransferred =
04732                             spi.write(mosiData, byteCount, misoData, byteCount);
04733                         spi_cs = 1;
04734                         // hex dump misoData[0..byteCount-1]
04735                         cmdLine.serial().printf("  MISO<-");
04736                         for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred;
04737                              byteIndex++)
04738                         {
04739                             cmdLine.serial().printf(" 0x%2.2X", misoData[byteIndex]);
04740                         }
04741                         cmdLine.serial().printf(" ");
04742                     }
04743                 }
04744                 break;
04745             }             // switch(cmdLine[2])
04746         }             // case 'S': // %S... -- SPI diagnostics
04747         break;
04748 #endif
04749         //
04750         // A-Z,a-z,0-9 reserved for application use
04751     }         // switch(cmdLine[1])
04752 } // end void pinsMonitor_submenu_onEOLcommandParser(CmdLine & cmdLine)
04753 
04754 
04755 //--------------------------------------------------
04756 #if 0 // APPLICATION_MAX5715 // MAX5715_menu_onEOLcommandParser moved to Test_Menu_MAX5715.cpp
04757 bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine)
04758 {
04759     switch (cmdLine[0])
04760     {
04761         case '0':
04762         {
04763             // recommended for hex command codes 00..0F
04764             // TODO: cmdLine.serial().printf("\r\n 0 ch=? code=? -- CODEn");
04765             // Menu 0 ch=? code=?) CODEn
04766             // MAX5715_CODEn(uint8_t channel, uint16_t dacCodeLsbs);
04767             // VERIFY: parse strCommandArgs for additional arguments including key=value pairs
04768             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04769             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04770             if (cmdLine.parse_uint16_dec("ch", ch))
04771             {
04772             }
04773             uint16_t code = g_MAX5715_device.CODE[ch];
04774             if (cmdLine.parse_uint16_dec("code", code))
04775             {
04776             }
04777             cmdLine.serial().printf("CODEn ch=%d code=%d", ch, code);
04778             g_MAX5715_device.CODEn(ch, code);
04779             return true; // command was handled by MAX5715
04780         }
04781         break;
04782         case '1':
04783         {
04784             // recommended for hex command codes 10..1F
04785             // TODO: cmdLine.serial().printf("\r\n 1 ch=? -- LOADn");
04786             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04787             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04788             if (cmdLine.parse_uint16_dec("ch", ch))
04789             {
04790             }
04791             cmdLine.serial().printf("LOADn ch=%d", ch);
04792             g_MAX5715_device.LOADn(ch);
04793             return true; // command was handled by MAX5715
04794         }
04795         break;
04796         case '2':
04797         {
04798             // recommended for hex command codes 20..2F
04799             // TODO: cmdLine.serial().printf("\r\n 2 ch=? code=? -- CODEnLOADall");
04800             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04801             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04802             if (cmdLine.parse_uint16_dec("ch", ch))
04803             {
04804             }
04805             uint16_t code = g_MAX5715_device.CODE[ch];
04806             if (cmdLine.parse_uint16_dec("code", code))
04807             {
04808             }
04809             cmdLine.serial().printf("CODEnLOADall ch=%d code=%d", ch, code);
04810             g_MAX5715_device.CODEnLOADall(ch, code);
04811             return true; // command was handled by MAX5715
04812         }
04813         break;
04814         case '3':
04815         {
04816             // recommended for hex command codes 30..3F
04817             // TODO: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
04818             // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
04819             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
04820             uint16_t code;
04821             if (cmdLine.parse_uint16_dec("ch", ch))
04822             {
04823             }
04824             if (cmdLine.parse_uint16_dec("code", code))
04825             {
04826             }
04827             cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
04828             g_MAX5715_device.CODEnLOADn(ch, code);
04829             return true; // command was handled by MAX5715
04830         }
04831         break;
04832         case '4':
04833         {
04834             // recommended for hex command codes 40..4F
04835             switch (cmdLine[1])
04836             {
04837                 case '0':
04838                 {
04839                     // cmdLine.serial().printf("\r\n 40 ch=? -- POWERn_Normal");
04840                     cmdLine.serial().printf(
04841                         "channel_dcba=%d, POWERn_Normal)",
04842                         g_MAX5715_device.channels_bitmask_DCBA);
04843                     g_MAX5715_device.POWER(g_MAX5715_device.
04844                                            channels_bitmask_DCBA,
04845                                            MAX5715::POWERn_Normal);
04846                     return true; // command was handled by MAX5715
04847                 }
04848                 break;
04849                 case '1':
04850                 {
04851                     // cmdLine.serial().printf("\r\n 41 ch=? -- POWERn_PD1k");
04852                     cmdLine.serial().printf(
04853                         "channel_dcba=%d, POWERn_PD1k)",
04854                         g_MAX5715_device.channels_bitmask_DCBA);
04855                     g_MAX5715_device.POWER(g_MAX5715_device.
04856                                            channels_bitmask_DCBA,
04857                                            MAX5715::POWERn_PD1k);
04858                     return true; // command was handled by MAX5715
04859                 }
04860                 break;
04861                 case '2':
04862                 {
04863                     // cmdLine.serial().printf("\r\n 42 ch=? -- POWERn_PD100k");
04864                     cmdLine.serial().printf(
04865                         "channel_dcba=%d, POWERn_PD100k)",
04866                         g_MAX5715_device.channels_bitmask_DCBA);
04867                     g_MAX5715_device.POWER(g_MAX5715_device.
04868                                            channels_bitmask_DCBA,
04869                                            MAX5715::POWERn_PD100k);
04870                     return true; // command was handled by MAX5715
04871                 }
04872                 break;
04873                 case '3':
04874                 {
04875                     // cmdLine.serial().printf("\r\n 43 ch=? -- POWERn_PDHiZ");
04876                     cmdLine.serial().printf(
04877                         "channel_dcba=%d, POWERn_PDHiZ)",
04878                         g_MAX5715_device.channels_bitmask_DCBA);
04879                     g_MAX5715_device.POWER(g_MAX5715_device.
04880                                            channels_bitmask_DCBA,
04881                                            MAX5715::POWERn_PDHiZ);
04882                     return true; // command was handled by MAX5715
04883                 }
04884                 break;
04885             }
04886             break;
04887         }
04888         break;
04889         case '5':
04890         {
04891             // recommended for hex command codes 50..5F
04892             switch (cmdLine[1])
04893             {
04894                 case '0':
04895                 {
04896                     // cmdLine.serial().printf("\r\n 50 -- SW_CLEAR");
04897                     cmdLine.serial().printf("SW_CLEAR");
04898                     g_MAX5715_device.SW_CLEAR();
04899                     return true; // command was handled by MAX5715
04900                 }
04901                 break;
04902                 case '1':
04903                 {
04904                     // cmdLine.serial().printf("\r\n 51 -- SW_RESET");
04905                     cmdLine.serial().printf("SW_RESET");
04906                     g_MAX5715_device.SW_RESET();
04907                     return true; // command was handled by MAX5715
04908                 }
04909                 break;
04910             }
04911         }
04912         break;
04913         case '6':
04914         {
04915             // recommended for hex command codes 60..6F
04916             switch (cmdLine[1])
04917             {
04918                 case '0':
04919                 {
04920                     // cmdLine.serial().printf("\r\n 60 ch=? -- CONFIGn_LATCHED");
04921                     cmdLine.serial().printf(
04922                         "MAX5715_CONFIGn_LATCHED(channel_dcba=%d)",
04923                         g_MAX5715_device.
04924                         channels_bitmask_DCBA);
04925                     g_MAX5715_device.CONFIGn_LATCHED(g_MAX5715_device.
04926                                                      channels_bitmask_DCBA);
04927                     return true; // command was handled by MAX5715
04928                 }
04929                 break;
04930                 case '1':
04931                 {
04932                     // cmdLine.serial().printf("\r\n 61 ch=? -- CONFIGn_TRANSPARENT");
04933                     cmdLine.serial().printf(
04934                         "MAX5715_CONFIGn_TRANSPARENT(channel_dcba=%d)",
04935                         g_MAX5715_device.
04936                         channels_bitmask_DCBA);
04937                     g_MAX5715_device.CONFIGn_TRANSPARENT(
04938                         g_MAX5715_device.channels_bitmask_DCBA);
04939                     return true; // command was handled by MAX5715
04940                 }
04941                 break;
04942                 case '8':
04943                 {
04944                     // cmdLine.serial().printf("\r\n 68 -- CONFIGall_LATCHED");
04945                     cmdLine.serial().printf(
04946                         "MAX5715_CONFIGall_LATCHED()");
04947                     g_MAX5715_device.CONFIGall_LATCHED();
04948                     return true; // command was handled by MAX5715
04949                 }
04950                 break;
04951                 case '9':
04952                 {
04953                     // cmdLine.serial().printf("\r\n 69 -- CONFIGall_TRANSPARENT");
04954                     cmdLine.serial().printf(
04955                         "MAX5715_CONFIGall_TRANSPARENT()");
04956                     g_MAX5715_device.CONFIGall_TRANSPARENT();
04957                     return true; // command was handled by MAX5715
04958                 }
04959                 break;
04960             }
04961         }
04962         break;
04963         case '7':
04964         {
04965             // recommended for hex command codes 70..7F
04966             switch (cmdLine[1])
04967             {
04968                 case '0':
04969                 {
04970                     // cmdLine.serial().printf("\r\n 70 -- REF_EXT");
04971                     cmdLine.serial().printf(
04972                         "MAX5715_REF(REF_EXT)");
04973                     g_MAX5715_device.REF(MAX5715::REF_EXT);
04974                     return true; // command was handled by MAX5715
04975                 }
04976                 break;
04977                 case '1':
04978                 {
04979                     // cmdLine.serial().printf("\r\n 71 -- REF_2V500");
04980                     cmdLine.serial().printf(
04981                         "MAX5715_REF(REF_2V500)");
04982                     g_MAX5715_device.REF(MAX5715::REF_2V500);
04983                     return true; // command was handled by MAX5715
04984                 }
04985                 break;
04986                 case '2':
04987                 {
04988                     // cmdLine.serial().printf("\r\n 72 -- REF_2V048");
04989                     cmdLine.serial().printf(
04990                         "MAX5715_REF(REF_2V048)");
04991                     g_MAX5715_device.REF(MAX5715::REF_2V048);
04992                     return true; // command was handled by MAX5715
04993                 }
04994                 break;
04995                 case '3':
04996                 {
04997                     // cmdLine.serial().printf("\r\n 73 -- REF_4V096");
04998                     cmdLine.serial().printf(
04999                         "MAX5715_REF(REF_4V096)");
05000                     g_MAX5715_device.REF(MAX5715::REF_4V096);
05001                     return true; // command was handled by MAX5715
05002                 }
05003                 break;
05004                 case '4':
05005                 {
05006                     // cmdLine.serial().printf("\r\n 74 -- REF_AlwaysOn_EXT");
05007                     cmdLine.serial().printf(
05008                         "MAX5715_REF(REF_AlwaysOn_EXT)");
05009                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_EXT);
05010                     return true; // command was handled by MAX5715
05011                 }
05012                 break;
05013                 case '5':
05014                 {
05015                     // cmdLine.serial().printf("\r\n 75 -- REF_AlwaysOn_2V500");
05016                     cmdLine.serial().printf(
05017                         "MAX5715_REF(REF_AlwaysOn_2V500)");
05018                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500);
05019                     return true; // command was handled by MAX5715
05020                 }
05021                 break;
05022                 case '6':
05023                 {
05024                     // cmdLine.serial().printf("\r\n 76 -- REF_AlwaysOn_2V048");
05025                     cmdLine.serial().printf(
05026                         "MAX5715_REF(REF_AlwaysOn_2V048)");
05027                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V048);
05028                     return true; // command was handled by MAX5715
05029                 }
05030                 break;
05031                 case '7':
05032                 {
05033                     // cmdLine.serial().printf("\r\n 77 -- REF_AlwaysOn_4V096");
05034                     cmdLine.serial().printf(
05035                         "MAX5715_REF(REF_AlwaysOn_4V096)");
05036                     g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_4V096);
05037                     return true; // command was handled by MAX5715
05038                 }
05039                 break;
05040             }
05041         }
05042         break;
05043         case '8':
05044         {
05045             // recommended for hex command codes 80..8F
05046             switch (cmdLine[1])
05047             {
05048                 case '0':
05049                 {
05050                     // TODO: cmdLine.serial().printf("\r\n 80 code=? -- CODEall");
05051                     // TODO: parse command arguments ~ parse_strCommandArgs(strCommandArgs);
05052                     g_MAX5715_device.channels_bitmask_DCBA = 0xFF;             // store g_MAX5715_device.CODE[allChannels]
05053                     uint16_t code = g_MAX5715_device.CODE[0];
05054                     if (cmdLine.parse_uint16_dec("code", code))
05055                     {
05056                     }
05057                     cmdLine.serial().printf("CODEall code=%d", code);
05058                     g_MAX5715_device.CODEall(code);
05059                     return true; // command was handled by MAX5715
05060                 }
05061                 break;
05062                 case '1':
05063                 {
05064                     // TODO: cmdLine.serial().printf("\r\n 81 -- LOADall");
05065                     cmdLine.serial().printf("LOADall");
05066                     g_MAX5715_device.LOADall();
05067                     return true; // command was handled by MAX5715
05068                 }
05069                 break;
05070                 case '2':
05071                 {
05072                     // TODO: cmdLine.serial().printf("\r\n 82 code=? -- CODEallLOADall");
05073                     uint16_t code = g_MAX5715_device.CODE[0];
05074                     if (cmdLine.parse_uint16_dec("code", code))
05075                     {
05076                     }
05077                     cmdLine.serial().printf("CODEallLOADall code=%d", code);
05078                     g_MAX5715_device.CODEallLOADall(code);
05079                     return true; // command was handled by MAX5715
05080                 }
05081                 break;
05082             }
05083         }
05084         break;
05085         case '9':
05086         {
05087             // recommended for hex command codes 90..9F
05088         }
05089         break;
05090         case 'a': case 'A':
05091         {
05092             // recommended for hex command codes A0..AF
05093             switch (cmdLine[1])
05094             {
05095                 case 't': case 'T':
05096 #if IGNORE_AT_COMMANDS
05097 # if HAS_DAPLINK_SERIAL
05098                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05099 # endif // HAS_DAPLINK_SERIAL
05100                     // AT command: skip the prompt to avoid confusing modem detector
05101                     return false; // command not handled
05102 #endif // IGNORE_AT_COMMANDS
05103             }
05104         }
05105         break;
05106         case 'b': case 'B':
05107         {
05108             // recommended for hex command codes B0..BF
05109         }
05110         break;
05111         case 'c': case 'C':
05112         {
05113             // recommended for hex command codes C0..CF
05114             // // MAX5717 menu function to drive MAX5717_CLRb_Pin CLR#
05115             // cmdLine.serial().printf("\r\n C -- CLR# pulse CH high CL low");
05116             switch (cmdLine[1])
05117             {
05118                 default:
05119                     // g_MAX5715_device.CLRboutputPulseLow();
05120                     g_MAX5715_device.CLRboutputValue(1);
05121                     g_MAX5715_device.CLRboutputValue(0);
05122                     g_MAX5715_device.CLRboutputValue(1);
05123                     break;
05124                 case 'H': case 'h': case '1':
05125                     g_MAX5715_device.CLRboutputValue(1);         // GPIOoutputCLRb(int isLogicHigh);
05126                     break;
05127                 case 'L': case 'l': case '0':
05128                     g_MAX5715_device.CLRboutputValue(0);         // GPIOoutputCLRb(int isLogicHigh);
05129                     break;
05130             }
05131             return true; // command was handled by MAX5715
05132         }
05133         break;
05134         case 'd': case 'D':
05135         {
05136             // recommended for hex command codes D0..DF
05137         }
05138         break;
05139         case 'e': case 'E':
05140         {
05141             // recommended for hex command codes E0..EF
05142         }
05143         break;
05144         case 'f': case 'F':
05145         {
05146             // recommended for hex command codes F0..FF
05147         }
05148         break;
05149         case 'l': case 'L':
05150         {
05151             // // MAX5717 menu function to drive MAX5717_LDACb_Pin LDAC#
05152             // cmdLine.serial().printf("\r\n L -- LDAC# pulse LH high LL low");
05153             switch (cmdLine[1])
05154             {
05155                 default:
05156                     // g_MAX5715_device.LDACboutputPulseLow();
05157                     g_MAX5715_device.LDACboutputValue(1);
05158                     g_MAX5715_device.LDACboutputValue(0);
05159                     g_MAX5715_device.LDACboutputValue(1);
05160                     break;
05161                 case 'H': case 'h': case '1':
05162                     g_MAX5715_device.LDACboutputValue(1);         // GPIOoutputLDACb(int isLogicHigh);
05163                     break;
05164                 case 'L': case 'l': case '0':
05165                     g_MAX5715_device.LDACboutputValue(0);         // GPIOoutputLDACb(int isLogicHigh);
05166                     break;
05167             }
05168             return true; // command was handled by MAX5715
05169         }
05170         break;
05171         case 'x': case 'X':
05172         {
05173         }
05174         break;
05175         case 'y': case 'Y':
05176         {
05177         }
05178         break;
05179         case 'z': case 'Z':
05180         {
05181         }
05182         break;
05183         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
05184         {
05185             // TODO: '~' is not recommended for menu commands, interferes with ssh
05186             switch (cmdLine[1])
05187             {
05188                 default:
05189                 {
05190 #if IGNORE_AT_COMMANDS
05191 # if HAS_DAPLINK_SERIAL
05192                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n",
05193                                                           cmdLine.str());
05194 # endif // HAS_DAPLINK_SERIAL
05195 #endif // IGNORE_AT_COMMANDS
05196                 }
05197             }
05198         }
05199         break;
05200         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
05201         {
05202 #if IGNORE_AT_COMMANDS
05203 # if HAS_DAPLINK_SERIAL
05204             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05205 # endif // HAS_DAPLINK_SERIAL
05206 #endif // IGNORE_AT_COMMANDS
05207         }
05208         break;
05209         case '@':
05210         {
05211             // //
05212             // // Menu @ -- print device configuration
05213             // TODO: cmdLine.serial().printf("\r\n @ -- print MAX5715 configuration");
05214             // //
05215             // print shadow register configuration
05216             //
05217             // shadow of write-only register CODE dddd_dddd_dddd_0000
05218             //~ int16_t CMD_1000_CODE;
05219             int index = 0;
05220             for (index = 0; index < 4; index++)
05221             {
05222                 cmdLine.serial().printf("CODE %c=0x%4.4x MAX5715_VoltageOfCode(%d)=%5.3fV\r\n",
05223                                         (char)('A' + index),
05224                                         (g_MAX5715_device.Shadow_0010_nnnn_CODE[index] & 0xFFFF),
05225                                         g_MAX5715_device.CODE[index],
05226                                         g_MAX5715_device.VoltageOfCode(g_MAX5715_device.CODE[index])
05227                                         );
05228             }
05229             //
05230             cmdLine.serial().printf("\r\n");
05231             //
05232             //
05233             // Menu @) print MAX5715 configuration AND g_MAX5715_device globals
05234             //
05235 #if 1 // SUPPORT_CHANNELS
05236             cmdLine.serial().printf("channelNumber_0_3=%d channels_bitmask_DCBA=%d\r\n",
05237                                     (g_MAX5715_device.channelNumber_0_3 & 0xFFFF),
05238                                     (g_MAX5715_device.channels_bitmask_DCBA & 0xFFFF));
05239 #endif // SUPPORT_CHANNELS
05240             //
05241             cmdLine.serial().printf("VRef=%5.3fV\r\n", g_MAX5715_device.VRef);
05242             // dtostrf width and precision: 3.3V / 1024 LSB = 0.00322265625 volts per LSB
05243             return true; // command was handled by MAX5715
05244         }
05245         break;
05246     } // end switch (cmdLine[0])
05247     return false; // command not handled by MAX5715
05248 } // end bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine)
05249 #endif
05250 
05251 //--------------------------------------------------
05252 #if 0 // APPLICATION_MAX11131 // MAX11131_menu_onEOLcommandParser moved to Test_Menu_MAX11131.cpp
05253 bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine)
05254 {
05255     switch (cmdLine[0])
05256     {
05257         case '0':
05258         {
05259             // recommended for hex command codes 00..0F
05260             // VERIFY: console menu command 0 int16_t MAX11131_ScanRead(void);
05261             // TODO: cmdLine.serial().printf("\r\n 0 n=?                                  -- MAX11131_ScanRead");
05262             if (cmdLine.parse_uint16_dec("n", g_MAX11131_device.NumWords))
05263             {
05264             }
05265             cmdLine.serial().printf("ScanRead NumWords=%d", g_MAX11131_device.NumWords);
05266             if (g_MAX11131_device.isExternalClock)
05267             {
05268                 cmdLine.serial().printf(" External Clock");
05269                 //
05270                 // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05271                 // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05272                 g_MAX11131_device.ReadAINcode();
05273                 // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05274                 // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05275                 //
05276                 AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05277             }
05278             else
05279             {
05280                 cmdLine.serial().printf(" Internal Clock");
05281                 //
05282                 // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05283                 // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05284                 g_MAX11131_device.ReadAINcode();
05285                 // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05286                 // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05287                 //
05288                 AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05289             }
05290             return true; // command was handled by MAX11131
05291         }
05292         break;
05293         case '1':
05294         {
05295             // recommended for hex command codes 10..1F
05296             // VERIFY: console menu command 1 MAX11131_ScanManual(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
05297             // TODO: cmdLine.serial().printf("\r\n 1 ch=? pm=? id=?                       -- MAX11131_ScanManual");
05298             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05299             {
05300             }
05301             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05302             {
05303             }
05304             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05305             {
05306             }
05307             cmdLine.serial().printf("ScanManual ch=%d pm=%d id=%d\r\n",
05308                                     g_MAX11131_device.channelNumber_0_15,
05309                                     g_MAX11131_device.PowerManagement_0_2,
05310                                     g_MAX11131_device.chan_id_0_1);
05311             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05312             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05313             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05314             g_MAX11131_device.NumWords = g_MAX11131_device.ScanManual();
05315             //
05316             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05317             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05318             g_MAX11131_device.ReadAINcode();
05319             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05320             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05321             //
05322             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05323             return true; // command was handled by MAX11131
05324         }
05325         break;
05326         case '2':
05327         {
05328             // recommended for hex command codes 20..2F
05329             // 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);
05330             // TODO: cmdLine.serial().printf("\r\n 2 ch=? av=? n=? pm=? swcnv=?           -- MAX11131_ScanRepeat");
05331             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05332             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05333             // VERIFY: update value of g_MAX11131_device.nscan_4_8_12_16 option from strCommandArgs
05334             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05335             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05336             // VERIFY: parse strCommandArgs for additional arguments including key=value pairs
05337             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05338             {
05339             }
05340             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05341             {
05342             }
05343             if (cmdLine.parse_byte_dec("n", g_MAX11131_device.nscan_4_8_12_16))
05344             {
05345             }
05346             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05347             {
05348             }
05349             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05350             {
05351             }
05352             cmdLine.serial().printf(
05353                 "ScanRepeat ch=%d average_0_4_8_16_32:%d nscan_4_8_12_16:%d swcnv=%d pm=%d\r\n",
05354                 g_MAX11131_device.channelNumber_0_15,
05355                 g_MAX11131_device.average_0_4_8_16_32,
05356                 g_MAX11131_device.nscan_4_8_12_16,
05357                 g_MAX11131_device.swcnv_0_1,
05358                 g_MAX11131_device.PowerManagement_0_2);
05359             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05360             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05361             // VERIFY: replace argument with driver global; g_MAX11131_device.nscan_4_8_12_16 replaces nscan_4_8_12_16
05362             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05363             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05364             g_MAX11131_device.NumWords = g_MAX11131_device.ScanRepeat();
05365             //
05366             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05367             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05368             g_MAX11131_device.ReadAINcode();
05369             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05370             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05371             //
05372             AINcode_print_value_chanID_mean(cmdLine, g_MAX11131_device.NumWords);
05373             return true; // command was handled by MAX11131
05374         }
05375         break;
05376         case '3':
05377         {
05378             // recommended for hex command codes 30..3F
05379             // 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);
05380             // TODO: cmdLine.serial().printf("\r\n 3 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanStandardIntClock");
05381             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05382             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05383             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05384             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05385             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05386             {
05387             }
05388             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05389             {
05390             }
05391             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05392             {
05393             }
05394             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05395             {
05396             }
05397             cmdLine.serial().printf("ScanStandardInternalClock ch=%d average_0_4_8_16_32:%d swcnv=%d pm=%d\r\n",
05398                                     g_MAX11131_device.channelNumber_0_15,
05399                                     g_MAX11131_device.average_0_4_8_16_32,
05400                                     g_MAX11131_device.swcnv_0_1,
05401                                     g_MAX11131_device.PowerManagement_0_2
05402                                     );
05403             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05404             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05405             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05406             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05407             g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardInternalClock();
05408             //
05409             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05410             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05411             g_MAX11131_device.ReadAINcode();
05412             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05413             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05414             //
05415             AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05416             return true; // command was handled by MAX11131
05417         }
05418         break;
05419         case '4':
05420         {
05421             // recommended for hex command codes 40..4F
05422             // VERIFY: console menu command 4 MAX11131_ScanStandardExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
05423             // TODO: cmdLine.serial().printf("\r\n 4 ch=? pm=? id=?                       -- MAX11131_ScanStandardExtClock");
05424             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05425             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05426             // VERIFY: update value of g_MAX11131_device.chan_id_0_1 option from strCommandArgs
05427             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05428             {
05429             }
05430             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05431             {
05432             }
05433             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05434             {
05435             }
05436             cmdLine.serial().printf("ScanStandardExternalClock ch=%d pm=%d id=%d\r\n",
05437                                     g_MAX11131_device.channelNumber_0_15,
05438                                     g_MAX11131_device.PowerManagement_0_2,
05439                                     g_MAX11131_device.chan_id_0_1
05440                                     );
05441             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05442             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05443             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05444             g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
05445             //
05446             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05447             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05448             g_MAX11131_device.ReadAINcode();
05449             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05450             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05451             //
05452             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05453             return true; // command was handled by MAX11131
05454         }
05455         break;
05456         case '5':
05457         {
05458             // recommended for hex command codes 50..5F
05459             // 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);
05460             // TODO: cmdLine.serial().printf("\r\n 5 ch=? av=? pm=? swcnv=?               -- MAX11131_ScanUpperIntClock");
05461             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05462             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05463             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05464             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05465             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05466             {
05467             }
05468             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05469             {
05470             }
05471             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05472             {
05473             }
05474             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05475             {
05476             }
05477             cmdLine.serial().printf("ScanUpperInternalClock ch=%d average_0_4_8_16_32:%d swcnv=%d pm=%d\r\n",
05478                                     g_MAX11131_device.channelNumber_0_15,
05479                                     g_MAX11131_device.average_0_4_8_16_32,
05480                                     g_MAX11131_device.swcnv_0_1,
05481                                     g_MAX11131_device.PowerManagement_0_2
05482                                     );
05483             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05484             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05485             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05486             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05487             g_MAX11131_device.NumWords = g_MAX11131_device.ScanUpperInternalClock();
05488             //
05489             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05490             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05491             g_MAX11131_device.ReadAINcode();
05492             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05493             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05494             //
05495             AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05496             return true; // command was handled by MAX11131
05497         }
05498         break;
05499         case '6':
05500         {
05501             // recommended for hex command codes 60..6F
05502             // VERIFY: console menu command 6 MAX11131_ScanUpperExternalClock(int channelNumber_0_15, int PowerManagement_0_2, int chan_id_0_1);
05503             // TODO: cmdLine.serial().printf("\r\n 6 ch=? pm=? id=?                       -- MAX11131_ScanUpperExtClock");
05504             // VERIFY: update value of g_MAX11131_device.channelNumber_0_15 from strCommandArgs
05505             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05506             // VERIFY: update value of g_MAX11131_device.chan_id_0_1 option from strCommandArgs
05507             if (cmdLine.parse_byte_dec("ch", g_MAX11131_device.channelNumber_0_15))
05508             {
05509             }
05510             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05511             {
05512             }
05513             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05514             {
05515             }
05516             cmdLine.serial().printf("ScanUpperExternalClock ch=%d pm=%d id=%d\r\n",
05517                                     g_MAX11131_device.channelNumber_0_15,
05518                                     g_MAX11131_device.PowerManagement_0_2,
05519                                     g_MAX11131_device.chan_id_0_1
05520                                     );
05521             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05522             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05523             // VERIFY: replace argument with driver global; g_MAX11131_device.channelNumber_0_15 replaces channelNumber_0_15
05524             g_MAX11131_device.NumWords = g_MAX11131_device.ScanUpperExternalClock();
05525             //
05526             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05527             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05528             g_MAX11131_device.ReadAINcode();
05529             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05530             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05531             //
05532             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05533             return true; // command was handled by MAX11131
05534         }
05535         break;
05536         case '7':
05537         {
05538             // recommended for hex command codes 70..7F
05539             // 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);
05540             // TODO: cmdLine.serial().printf("\r\n 7 enableMask=0xffff av=? pm=? swcnv=?  -- MAX11131_ScanCustomIntClock");
05541             // VERIFY: update value of g_MAX11131_device.average_0_4_8_16_32 option from strCommandArgs
05542             // VERIFY: update value of g_MAX11131_device.swcnv_0_1 option from strCommandArgs
05543             // VERIFY: update value of g_MAX11131_device.PowerManagement_0_2 option from strCommandArgs
05544             if (cmdLine.parse_int16_hex("enableMask", g_MAX11131_device.enabledChannelsMask))
05545             {
05546                 // TODO1: get g_MAX11131_device.enabledChannelsMask from strCommandArgs
05547             }
05548             if (cmdLine.parse_byte_dec("av", g_MAX11131_device.average_0_4_8_16_32))
05549             {
05550             }
05551             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05552             {
05553             }
05554             if (cmdLine.parse_byte_dec("swcnv", g_MAX11131_device.swcnv_0_1))
05555             {
05556             }
05557             cmdLine.serial().printf(
05558                 "ScanCustomInternalClock enabledChannelsMask:0x%4.4x average_0_4_8_16_32:%d pm=%d swcnv=%d\r\n",
05559                 (g_MAX11131_device.enabledChannelsMask & 0xFFFF),
05560                 g_MAX11131_device.average_0_4_8_16_32,
05561                 g_MAX11131_device.PowerManagement_0_2,
05562                 g_MAX11131_device.swcnv_0_1
05563                 );
05564             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05565             // VERIFY: replace argument with driver global; g_MAX11131_device.swcnv_0_1 replaces swcnv_0_1
05566             // VERIFY: replace argument with driver global; g_MAX11131_device.average_0_4_8_16_32 replaces average_0_4_8_16_32
05567             // VERIFY: replace argument with driver global; g_MAX11131_device.enabledChannelsMask replaces enabledChannelsMask
05568             g_MAX11131_device.NumWords = g_MAX11131_device.ScanCustomInternalClock();
05569             //
05570             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05571             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05572             g_MAX11131_device.ReadAINcode();
05573             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05574             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05575             //
05576             AINcode_print_value_chanID(cmdLine, g_MAX11131_device.NumWords);
05577             return true; // command was handled by MAX11131
05578         }
05579         break;
05580         case '8':
05581         {
05582             // recommended for hex command codes 80..8F
05583             // VERIFY: console menu command 8 MAX11131_ScanCustomExternalClock(int16_t enabledChannelsMask, int PowerManagement_0_2, int chan_id_0_1);
05584             // TODO: cmdLine.serial().printf("\r\n 8 enableMask=0xffff pm=0 id=1               -- MAX11131_ScanCustomExtClock");
05585             if (cmdLine.parse_int16_hex("enableMask", g_MAX11131_device.enabledChannelsMask))
05586             {
05587                 // TODO1: get g_MAX11131_device.enabledChannelsMask from strCommandArgs
05588             }
05589             if (cmdLine.parse_byte_dec("pm", g_MAX11131_device.PowerManagement_0_2))
05590             {
05591             }
05592             if (cmdLine.parse_byte_dec("id", g_MAX11131_device.chan_id_0_1))
05593             {
05594             }
05595             cmdLine.serial().printf("ScanCustomExternalClock enabledChannelsMask:0x%4.4x pm=%d id=%d\r\n",
05596                                     (g_MAX11131_device.enabledChannelsMask & 0xFFFF),
05597                                     g_MAX11131_device.PowerManagement_0_2,
05598                                     g_MAX11131_device.chan_id_0_1
05599                                     );
05600             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05601             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05602             // VERIFY: replace argument with driver global; g_MAX11131_device.enabledChannelsMask replaces enabledChannelsMask
05603             g_MAX11131_device.NumWords = g_MAX11131_device.ScanCustomExternalClock();
05604             //
05605             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05606             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05607             g_MAX11131_device.ReadAINcode();
05608             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05609             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05610             //
05611             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05612             return true; // command was handled by MAX11131
05613         }
05614         break;
05615         case '9':
05616         {
05617             // recommended for hex command codes 90..9F
05618             // VERIFY: console menu command 9 MAX11131_ScanSampleSetExternalClock(uint8_t enabledChannelsPatternLength_1_256, int16_t enabledChannelsPattern[], int PowerManagement_0_2, int chan_id_0_1);
05619             // TODO: cmdLine.serial().printf("\r\n 9 channelsPattern... pm=? id=? | len=? -- MAX11131_ScanSampleSetExtClock");
05620             //
05621             // get MAX11131 Sampleset channel selection pattern parse_strCommandArgs(strCommandArgs);
05622             // cmdLine.parse_byteCount_byteList_dec(byteCount, mosiData, MAX_SPI_BYTE_COUNT)
05623             // into g_MAX11131_device.enabledChannelsPatternLength_1_256
05624             // into g_MAX11131_device.enabledChannelsPattern[0..255]
05625             size_t numValues;
05626             char valueList[256];
05627             if (cmdLine.parse_byteCount_byteList_dec( numValues, valueList, 256))
05628             {
05629                 // first value is the "9" command itself
05630                 g_MAX11131_device.enabledChannelsPatternLength_1_256 = numValues - 1;
05631                 // copy valueList[1, ...] into g_MAX11131_device.enabledChannelsPattern[0, ...]
05632                 for (size_t index = 0; index < (numValues - 1); index++)
05633                 {
05634                     g_MAX11131_device.enabledChannelsPattern[index] = valueList[1 + index];
05635                 }
05636             }
05637             //
05638             cmdLine.serial().printf("ScanSampleSetExternalClock enabledChannelsPattern:{ ");
05639             int index;
05640             for (index = 0; index < g_MAX11131_device.enabledChannelsPatternLength_1_256; index++)
05641             {
05642                 //~ Serial.print( ((g_enabledChannelsPattern[index] >> 4) & 0x000F), DEC);
05643                 //~ Serial.print(" ");
05644                 cmdLine.serial().printf("AIN%d ", ((g_MAX11131_device.enabledChannelsPattern[index]) & 0x000F));
05645             }
05646             cmdLine.serial().printf("}");
05647             cmdLine.serial().printf(" pm=%d id=%d\r\n", g_MAX11131_device.PowerManagement_0_2,
05648                                     g_MAX11131_device.chan_id_0_1);
05649             // VERIFY: replace argument with driver global; g_MAX11131_device.PowerManagement_0_2 replaces PowerManagement_0_2
05650             // VERIFY: replace argument with driver global; g_MAX11131_device.chan_id_0_1 replaces chan_id_0_1
05651             g_MAX11131_device.NumWords = g_MAX11131_device.ScanSampleSetExternalClock();
05652             //
05653             // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
05654             // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
05655             g_MAX11131_device.ReadAINcode();
05656             // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
05657             // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
05658             //
05659             AINcode_print_value_externalClock(cmdLine, g_MAX11131_device.NumWords);
05660             return true; // command was handled by MAX11131
05661         }
05662         break;
05663         case 'a': case 'A':
05664         {
05665             // recommended for hex command codes A0..AF
05666             switch (cmdLine[1])
05667             {
05668                 case 't': case 'T':
05669 #if IGNORE_AT_COMMANDS
05670 # if HAS_DAPLINK_SERIAL
05671                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05672 # endif // HAS_DAPLINK_SERIAL
05673                     // AT command: skip the prompt to avoid confusing modem detector
05674                     return false; // command not handled
05675 #endif // IGNORE_AT_COMMANDS
05676             }
05677         }
05678         break;
05679         case 'b': case 'B':
05680         {
05681             // recommended for hex command codes B0..BF
05682         }
05683         break;
05684         case 'c': case 'C':
05685         {
05686             // recommended for hex command codes C0..CF
05687         }
05688         break;
05689         case 'd': case 'D':
05690         {
05691             // recommended for hex command codes D0..DF
05692         }
05693         break;
05694         case 'e': case 'E':
05695         {
05696             // recommended for hex command codes E0..EF
05697         }
05698         break;
05699         case 'f': case 'F':
05700         {
05701             // recommended for hex command codes F0..FF
05702         }
05703         break;
05704         case 'x': case 'X':
05705         {
05706         }
05707         break;
05708         case 'y': case 'Y':
05709         {
05710         }
05711         break;
05712         case 'i': case 'I':
05713         {
05714             // TODO: cmdLine.serial().printf("\r\n ISc) IUc) IBc) IRc) reconfigure channel single-ended/unipolar/bipolar/range");
05715             char strChannelId[3];
05716             strChannelId[0] = cmdLine[2];
05717             strChannelId[1] = cmdLine[3];
05718             strChannelId[2] = '\0';
05719             int channelId_0_15 = strtoul(strChannelId, NULL, 10);         // strtol(str, NULL, 10): get decimal value
05720             switch (cmdLine[1])
05721             {
05722                 case 's': case 'S':
05723                     g_MAX11131_device.Reconfigure_SingleEnded(channelId_0_15);
05724                     break;
05725                 case 'u': case 'U':
05726                     g_MAX11131_device.Reconfigure_DifferentialUnipolar(channelId_0_15);
05727                     break;
05728                 case 'b': case 'B':
05729                     g_MAX11131_device.Reconfigure_DifferentialBipolarFSVref(channelId_0_15);
05730                     break;
05731                 case 'r': case 'R':
05732                     g_MAX11131_device.Reconfigure_DifferentialBipolarFS2Vref(channelId_0_15);
05733                     break;
05734             }
05735             // char cmd1 = strCommandArgs[0];
05736             // strCommandArgs.remove(0, 1); // unsigned int index, unsigned int count
05737             // // get argument int channelId_0_15
05738             // // parse_strCommandArgs(strCommandArgs);
05739             // int channelId_0_15 = strtoul(strCommandArgs.c_str(), NULL, 10); // strtol(str, NULL, 10): get decimal value
05740             // if (cmd1 == 'S') {
05741             //     MAX11131_Reconfigure_SingleEnded(channelId_0_15);
05742             // }
05743             // else if (cmd1 == 'U') {
05744             //     MAX11131_Reconfigure_DifferentialUnipolar(channelId_0_15);
05745             // }
05746             // else if (cmd1 == 'B') {
05747             //     MAX11131_Reconfigure_DifferentialBipolarFSVref(channelId_0_15);
05748             // }
05749             // else if (cmd1 == 'R') {
05750             //     MAX11131_Reconfigure_DifferentialBipolarFS2Vref(channelId_0_15);
05751             // }
05752             return true; // command was handled by MAX11131
05753         }
05754         break;
05755         case '@':
05756         {
05757             // TODO: cmdLine.serial().printf("\r\n @                                      -- print MAX11131 configuration");
05758             // print shadow register configuration
05759             //
05760             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.ADC_MODE_CONTROL & 0xFFFF));
05761             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.ADC_MODE_CONTROL);
05762             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.ADC_CONFIGURATION & 0xFFFF));
05763             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.ADC_CONFIGURATION);
05764             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.UNIPOLAR & 0xFFFF));
05765             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.UNIPOLAR);
05766             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.BIPOLAR & 0xFFFF));
05767             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.BIPOLAR);
05768             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.RANGE & 0xFFFF));
05769             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.RANGE);
05770             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.CSCAN0 & 0xFFFF));
05771             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.CSCAN0);
05772             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.CSCAN1 & 0xFFFF));
05773             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.CSCAN1);
05774             cmdLine.serial().printf("0x%4.4x", (g_MAX11131_device.SAMPLESET & 0xFFFF));
05775             MAX11131_print_register_verbose(cmdLine, g_MAX11131_device.SAMPLESET);
05776             //
05777             // VERIFY: print shadow SAMPLESET pattern entry
05778             int entryIndex;
05779             for (entryIndex = 0; entryIndex < g_MAX11131_device.enabledChannelsPatternLength_1_256;
05780                  entryIndex += 4)
05781             {
05782                 uint16_t pack4channels = 0;
05783                 pack4channels |= (((g_MAX11131_device.enabledChannelsPattern[entryIndex + 0]) & 0x0F) << 12);
05784                 if ((entryIndex + 1) < g_MAX11131_device.enabledChannelsPatternLength_1_256) {
05785                     pack4channels |= (((g_MAX11131_device.enabledChannelsPattern[entryIndex + 1]) & 0x0F) << 8);
05786                 }
05787                 if ((entryIndex + 2) < g_MAX11131_device.enabledChannelsPatternLength_1_256) {
05788                     pack4channels |= (((g_MAX11131_device.enabledChannelsPattern[entryIndex + 2]) & 0x0F) << 4);
05789                 }
05790                 if ((entryIndex + 3) < g_MAX11131_device.enabledChannelsPatternLength_1_256) {
05791                     pack4channels |= ((g_MAX11131_device.enabledChannelsPattern[entryIndex + 3]) & 0x0F);
05792                 }
05793                 //~ SPIwrite16bits(pack4channels);
05794                 cmdLine.serial().printf("       0x%4.4x", (pack4channels & 0xFFFF));
05795                 // decode SAMPLESET channel select pattern
05796                 cmdLine.serial().printf(" SampleSet Entry: AIN%d AIN%d AIN%d AIN%d\r\n",
05797                                         ((pack4channels >> 12) & 0x000F),
05798                                         ((pack4channels >> 8) & 0x000F),
05799                                         ((pack4channels >> 4) & 0x000F),
05800                                         ((pack4channels      ) & 0x000F)
05801                                         );
05802             }
05803             //cmdLine.serial().printf("  SAMPLESET enabledChannelsPattern:{ ");
05804             //int index;
05805             //for (index = 0; index < g_MAX11131_device.enabledChannelsPatternLength_1_256; index++)
05806             //{
05807             //  //~ cmdLine.serial().printf( ((g_enabledChannelsPattern[index] >> 4) & 0x000F), DEC);
05808             //  //~ cmdLine.serial().printf(" ");
05809             //  cmdLine.serial().printf("AIN");
05810             //  cmdLine.serial().printf( ((g_MAX11131_device.enabledChannelsPattern[index]) & 0x000F), DEC);
05811             //  cmdLine.serial().printf(" ");
05812             //}
05813             //cmdLine.serial().printf("}");
05814             //
05815             // Menu @) print MAX11131 configuration AND g_MAX11131_device globals
05816             //
05817             cmdLine.serial().printf("SPI_MOSI_Semantic=%d\r\n", (g_MAX11131_device.SPI_MOSI_Semantic & 0xFFFF));
05818             cmdLine.serial().printf("NumWords=%d\r\n", (g_MAX11131_device.NumWords & 0xFFFF));
05819             cmdLine.serial().printf("isExternalClock=%d\r\n", (g_MAX11131_device.isExternalClock & 0xFFFF));
05820             cmdLine.serial().printf("ScanMode=%d\r\n", (g_MAX11131_device.ScanMode & 0xFFFF));
05821             cmdLine.serial().printf("channelNumber_0_15=%d\r\n",
05822                                     (g_MAX11131_device.channelNumber_0_15 & 0xFFFF));
05823             cmdLine.serial().printf("PowerManagement_0_2=%d\r\n",
05824                                     (g_MAX11131_device.PowerManagement_0_2 & 0xFFFF));
05825             cmdLine.serial().printf("chan_id_0_1=%d\r\n", (g_MAX11131_device.chan_id_0_1 & 0xFFFF));
05826             cmdLine.serial().printf("average_0_4_8_16_32=%d\r\n",
05827                                     (g_MAX11131_device.average_0_4_8_16_32 & 0xFFFF));
05828             cmdLine.serial().printf("nscan_4_8_12_16=%d\r\n", (g_MAX11131_device.nscan_4_8_12_16 & 0xFFFF));
05829             cmdLine.serial().printf("swcnv_0_1=%d\r\n", (g_MAX11131_device.swcnv_0_1 & 0xFFFF));
05830             cmdLine.serial().printf("enabledChannelsMask=0x%4.4x\r\n",
05831                                     (g_MAX11131_device.enabledChannelsMask & 0xFFFF));
05832             //
05833             cmdLine.serial().printf("VRef=%5.3fV\r\n", g_MAX11131_device.VRef);
05834             // dtostrf width and precision: 3.3V / 1024 LSB = 0.00322265625 volts per LSB
05835             //
05836             return true; // command was handled by MAX11131
05837         }
05838             //case '&':
05839             //{
05840             //    // TODO: cmdLine.serial().printf("\r\n & -- MAX11131_Example_ScanManual");
05841             //}
05842             break;
05843         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
05844         {
05845             // TODO: '~' is not recommended for menu commands, interferes with ssh
05846 #if IGNORE_AT_COMMANDS
05847 # if HAS_DAPLINK_SERIAL
05848             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05849 # endif // HAS_DAPLINK_SERIAL
05850 #endif // IGNORE_AT_COMMANDS
05851         }
05852         break;
05853         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
05854         {
05855 #if IGNORE_AT_COMMANDS
05856 # if HAS_DAPLINK_SERIAL
05857             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05858 # endif // HAS_DAPLINK_SERIAL
05859 #endif // IGNORE_AT_COMMANDS
05860         }
05861         break;
05862     } // end switch (cmdLine[0])
05863     return false; // command not handled
05864 } // end bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine)
05865 #endif
05866 
05867 //--------------------------------------------------
05868 #if 0 // APPLICATION_MAX5171 // MAX5171_menu_onEOLcommandParser moved to Test_Menu_MAX5171.cpp
05869 bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine)
05870 {
05871     switch (cmdLine[0])
05872     {
05873         case '0':
05874         {
05875             // recommended for hex command codes 10..1F
05876             //~ cmdLine.serial().printf("\r\n 0 code=? -- CODE");
05877             uint16_t code;
05878             if (cmdLine.parse_uint16_dec("code", code))
05879             {
05880             }
05881             cmdLine.serial().printf("CODE code=%d", code);
05882             g_MAX5171_device.CODE(code);
05883             return true; // command was handled by MAX5171
05884         }
05885         break;
05886         case '4':
05887         {
05888             // recommended for hex command codes 10..1F
05889             //~ cmdLine.serial().printf("\r\n 4 code=? -- CODE_LOAD");
05890             uint16_t code;
05891             if (cmdLine.parse_uint16_dec("code", code))
05892             {
05893             }
05894             cmdLine.serial().printf("CODE_LOAD code=%d", code);
05895             g_MAX5171_device.CODE_LOAD(code);
05896             return true; // command was handled by MAX5171
05897         }
05898         break;
05899         case '8':
05900         {
05901             // recommended for hex command codes 10..1F
05902             //~ cmdLine.serial().printf("\r\n 8 -- LOAD");
05903             cmdLine.serial().printf("LOAD");
05904             g_MAX5171_device.LOAD();
05905             return true; // command was handled by MAX5171
05906         }
05907         break;
05908         case 'c': case 'C':
05909         {
05910             // recommended for hex command codes 10..1F
05911             //~ cmdLine.serial().printf("\r\n c -- NOP");
05912             cmdLine.serial().printf("NOP");
05913             g_MAX5171_device.NOP();
05914             return true; // command was handled by MAX5171
05915         }
05916         break;
05917         case 'd': case 'D':
05918         {
05919             // recommended for hex command codes 10..1F
05920             //~ cmdLine.serial().printf("\r\n d -- SHUTDOWN");
05921             cmdLine.serial().printf("SHUTDOWN");
05922             g_MAX5171_device.SHUTDOWN();
05923             return true; // command was handled by MAX5171
05924         }
05925         break;
05926         case 'e': case 'E':
05927         {
05928             switch (cmdLine[1])
05929             {
05930                 case '0':
05931                 {
05932                     // recommended for hex command codes 10..1F
05933                     //~ cmdLine.serial().printf("\r\n e0 -- UPO_LOW");
05934                     cmdLine.serial().printf("UPO_LOW");
05935                     g_MAX5171_device.UPO_LOW();
05936                     return true; // command was handled by MAX5171
05937                 }
05938                 break;
05939                 case '8':
05940                 {
05941                     // recommended for hex command codes 10..1F
05942                     //~ cmdLine.serial().printf("\r\n e8 -- UPO_HIGH");
05943                     cmdLine.serial().printf("UPO_HIGH");
05944                     g_MAX5171_device.UPO_HIGH();
05945                     return true; // command was handled by MAX5171
05946                 }
05947                 break;
05948             }
05949         }
05950         break;
05951         case 'f': case 'F':
05952         {
05953             switch (cmdLine[1])
05954             {
05955                 case '0':
05956                 {
05957                     // recommended for hex command codes 10..1F
05958                     //~ cmdLine.serial().printf("\r\n f0 -- MODE1_DOUT_SCLK_RISING_EDGE");
05959                     cmdLine.serial().printf("MODE1_DOUT_SCLK_RISING_EDGE");
05960                     g_MAX5171_device.MODE1_DOUT_SCLK_RISING_EDGE();
05961                     return true; // command was handled by MAX5171
05962                 }
05963                 break;
05964                 case '8':
05965                 {
05966                     // recommended for hex command codes 10..1F
05967                     //~ cmdLine.serial().printf("\r\n f8 -- MODE0_DOUT_SCLK_FALLING_EDGE");
05968                     cmdLine.serial().printf("MODE0_DOUT_SCLK_FALLING_EDGE");
05969                     g_MAX5171_device.MODE0_DOUT_SCLK_FALLING_EDGE();
05970                     return true; // command was handled by MAX5171
05971                 }
05972                 break;
05973             }
05974         }
05975         break;
05976         case 'a': case 'A':
05977         {
05978             // recommended for hex command codes A0..AF
05979             switch (cmdLine[1])
05980             {
05981                 case 't': case 'T':
05982 #if IGNORE_AT_COMMANDS
05983 # if HAS_DAPLINK_SERIAL
05984                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
05985 # endif // HAS_DAPLINK_SERIAL
05986                     // AT command: skip the prompt to avoid confusing modem detector
05987                     return;
05988 #endif // IGNORE_AT_COMMANDS
05989             }
05990         }
05991         break;
05992         case 'x': case 'X':
05993         {
05994         }
05995         break;
05996         case 'y': case 'Y':
05997         {
05998         }
05999         break;
06000         case 'z': case 'Z':
06001         {
06002         }
06003         break;
06004         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
06005         {
06006             // TODO: '~' is not recommended for menu commands, interferes with ssh
06007 #if IGNORE_AT_COMMANDS
06008 # if HAS_DAPLINK_SERIAL
06009             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06010 # endif // HAS_DAPLINK_SERIAL
06011 #endif // IGNORE_AT_COMMANDS
06012         }
06013         break;
06014         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
06015         {
06016 #if IGNORE_AT_COMMANDS
06017 # if HAS_DAPLINK_SERIAL
06018             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06019 # endif // HAS_DAPLINK_SERIAL
06020 #endif // IGNORE_AT_COMMANDS
06021         }
06022         break;
06023     } // end switch (cmdLine[0])
06024     return false; // command not handled
06025 } // end bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine)
06026 #endif
06027 
06028 //--------------------------------------------------
06029 #if 0 // APPLICATION_MAX11410 // MAX11410_menu_onEOLcommandParser moved to Test_Menu_MAX11410.cpp
06030 bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine)
06031 {
06032     switch (cmdLine[0])
06033     {
06034         // TODO1: MAX11410 main_menu_onEOLcommandParser
06035         case '0':
06036         {
06037             // recommended for hex command codes 00..0F
06038             // placeholder: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
06039             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
06040             uint16_t code;
06041             if (cmdLine.parse_uint16_dec("ch", ch))
06042             {
06043             }
06044             if (cmdLine.parse_uint16_dec("code", code))
06045             {
06046             }
06047             if (cmdLine.parse_flag("xyzzy", g_xyzzy_flag, XYZZY_FLAG))
06048             {
06049                 isUpdatedSPIConfig = true;
06050             }
06051             cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
06052             MAX5715_CODEnLOADn(ch, code);
06053             cmdLine.serial().printf("\r\n placeholder");
06054             return true; // command was handled by MAX11410
06055         }
06056         break;
06057         case '1':
06058         {
06059             // recommended for hex command codes 10..1F
06060         }
06061         break;
06062         case '2':
06063         {
06064             // recommended for hex command codes 20..2F
06065         }
06066         break;
06067         case '3':
06068         {
06069             // recommended for hex command codes 30..3F
06070         }
06071         break;
06072         case '4':
06073         {
06074             // recommended for hex command codes 40..4F
06075         }
06076         break;
06077         case '5':
06078         {
06079             // recommended for hex command codes 50..5F
06080         }
06081         break;
06082         case '6':
06083         {
06084             // recommended for hex command codes 60..6F
06085         }
06086         break;
06087         case '7':
06088         {
06089             // recommended for hex command codes 70..7F
06090         }
06091         break;
06092         case '8':
06093         {
06094             // recommended for hex command codes 80..8F
06095         }
06096         break;
06097         case '9':
06098         {
06099             // recommended for hex command codes 90..9F
06100         }
06101         break;
06102         case 'a': case 'A':
06103         {
06104             // recommended for hex command codes A0..AF
06105             switch (cmdLine[1])
06106             {
06107                 case 't': case 'T':
06108 #if IGNORE_AT_COMMANDS
06109 # if HAS_DAPLINK_SERIAL
06110                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06111 # endif // HAS_DAPLINK_SERIAL
06112                     // AT command: skip the prompt to avoid confusing modem detector
06113                     return;
06114 #endif // IGNORE_AT_COMMANDS
06115             }
06116         }
06117         break;
06118         case 'b': case 'B':
06119         {
06120             // recommended for hex command codes B0..BF
06121         }
06122         break;
06123         case 'c': case 'C':
06124         {
06125             // recommended for hex command codes C0..CF
06126         }
06127         break;
06128         case 'd': case 'D':
06129         {
06130             // recommended for hex command codes D0..DF
06131         }
06132         break;
06133         case 'e': case 'E':
06134         {
06135             // recommended for hex command codes E0..EF
06136         }
06137         break;
06138         case 'f': case 'F':
06139         {
06140             // recommended for hex command codes F0..FF
06141         }
06142         break;
06143         case 'x': case 'X':
06144         {
06145         }
06146         break;
06147         case 'y': case 'Y':
06148         {
06149         }
06150         break;
06151         case 'z': case 'Z':
06152         {
06153         }
06154         break;
06155         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
06156         {
06157             // TODO: '~' is not recommended for menu commands, interferes with ssh
06158 #if IGNORE_AT_COMMANDS
06159 # if HAS_DAPLINK_SERIAL
06160             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06161 # endif // HAS_DAPLINK_SERIAL
06162 #endif // IGNORE_AT_COMMANDS
06163         }
06164         break;
06165         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
06166         {
06167 #if IGNORE_AT_COMMANDS
06168 # if HAS_DAPLINK_SERIAL
06169             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06170 # endif // HAS_DAPLINK_SERIAL
06171 #endif // IGNORE_AT_COMMANDS
06172         }
06173         break;
06174     } // end switch (cmdLine[0])
06175     return false; // command not handled
06176 } // end bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine)
06177 #endif
06178 
06179 
06180 //--------------------------------------------------
06181 #if APPLICATION_MAX12345 // MAX12345_menu_onEOLcommandParser see Test_Menu_MAX12345.cpp
06182 bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine)
06183 {
06184     switch (cmdLine[0])
06185     {
06186         // TODO1: MAX12345 main_menu_onEOLcommandParser
06187         case '0':
06188         {
06189             // recommended for hex command codes 00..0F
06190             // placeholder: cmdLine.serial().printf("\r\n 3 ch=? code=? -- CODEnLOADn");
06191             uint16_t ch = g_MAX5715_device.channelNumber_0_3;
06192             uint16_t code;
06193             if (cmdLine.parse_uint16_dec("ch", ch))
06194             {
06195             }
06196             if (cmdLine.parse_uint16_dec("code", code))
06197             {
06198             }
06199             if (cmdLine.parse_flag("xyzzy", g_xyzzy_flag, XYZZY_FLAG))
06200             {
06201                 isUpdatedSPIConfig = true;
06202             }
06203             cmdLine.serial().printf("CODEnLOADn ch=%d code=%d", ch, code);
06204             MAX5715_CODEnLOADn(ch, code);
06205             cmdLine.serial().printf("\r\n placeholder");
06206             return true; // command was handled by MAX12345
06207         }
06208         break;
06209         case '1':
06210         {
06211             // recommended for hex command codes 10..1F
06212         }
06213         break;
06214         case '2':
06215         {
06216             // recommended for hex command codes 20..2F
06217         }
06218         break;
06219         case '3':
06220         {
06221             // recommended for hex command codes 30..3F
06222         }
06223         break;
06224         case '4':
06225         {
06226             // recommended for hex command codes 40..4F
06227         }
06228         break;
06229         case '5':
06230         {
06231             // recommended for hex command codes 50..5F
06232         }
06233         break;
06234         case '6':
06235         {
06236             // recommended for hex command codes 60..6F
06237         }
06238         break;
06239         case '7':
06240         {
06241             // recommended for hex command codes 70..7F
06242         }
06243         break;
06244         case '8':
06245         {
06246             // recommended for hex command codes 80..8F
06247         }
06248         break;
06249         case '9':
06250         {
06251             // recommended for hex command codes 90..9F
06252         }
06253         break;
06254         case 'a': case 'A':
06255         {
06256             // recommended for hex command codes A0..AF
06257             switch (cmdLine[1])
06258             {
06259                 case 't': case 'T':
06260 #if IGNORE_AT_COMMANDS
06261 # if HAS_DAPLINK_SERIAL
06262                     cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06263 # endif // HAS_DAPLINK_SERIAL
06264                     // AT command: skip the prompt to avoid confusing modem detector
06265                     return;
06266 #endif // IGNORE_AT_COMMANDS
06267             }
06268         }
06269         break;
06270         case 'b': case 'B':
06271         {
06272             // recommended for hex command codes B0..BF
06273         }
06274         break;
06275         case 'c': case 'C':
06276         {
06277             // recommended for hex command codes C0..CF
06278         }
06279         break;
06280         case 'd': case 'D':
06281         {
06282             // recommended for hex command codes D0..DF
06283         }
06284         break;
06285         case 'e': case 'E':
06286         {
06287             // recommended for hex command codes E0..EF
06288         }
06289         break;
06290         case 'f': case 'F':
06291         {
06292             // recommended for hex command codes F0..FF
06293         }
06294         break;
06295         case 'x': case 'X':
06296         {
06297         }
06298         break;
06299         case 'y': case 'Y':
06300         {
06301         }
06302         break;
06303         case 'z': case 'Z':
06304         {
06305         }
06306         break;
06307         case '~':     // TODO: IGNORE_AT_COMMANDS -- ignore ~~~ modem command
06308         {
06309             // TODO: '~' is not recommended for menu commands, interferes with ssh
06310 #if IGNORE_AT_COMMANDS
06311 # if HAS_DAPLINK_SERIAL
06312             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06313 # endif // HAS_DAPLINK_SERIAL
06314 #endif // IGNORE_AT_COMMANDS
06315         }
06316         break;
06317         case '+':     // TODO: IGNORE_AT_COMMANDS -- ignore +++ modem command
06318         {
06319 #if IGNORE_AT_COMMANDS
06320 # if HAS_DAPLINK_SERIAL
06321             cmdLine_DAPLINKserial.serial().printf("\r\n ignore AT command \"%s\"\r\n", cmdLine.str());
06322 # endif // HAS_DAPLINK_SERIAL
06323 #endif // IGNORE_AT_COMMANDS
06324         }
06325         break;
06326     } // end switch (cmdLine[0])
06327     return false; // command not handled
06328 } // end bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine)
06329 #endif
06330 
06331 
06332 //--------------------------------------------------
06333 // main menu command-line parser
06334 // invoked by CmdLine::append(char ch) or CmdLine::idleAppendIfReadable()
06335 void main_menu_onEOLcommandParser(CmdLine & cmdLine)
06336 {
06337     // DIAGNOSTIC: print line buffer
06338     //~ cmdLine.serial().printf("\r\nmain_menu_onEOLcommandParser: ~%s~\r\n", cmdLine.str());
06339     //
06340     switch (cmdLine[0])
06341     {
06342         case '?':
06343             main_menu_status(cmdLine);
06344             main_menu_help(cmdLine);
06345             // print command prompt
06346             //cmdLine.serial().printf("\r\n>");
06347             break;
06348         case '\r': case '\n':     // ignore blank line
06349         case '\0':     // ignore empty line
06350         case '#':     // ignore comment line
06351             // # -- lines beginning with # are comments
06352             main_menu_status(cmdLine);
06353             //~ main_menu_help(cmdLine);
06354             // print command prompt
06355             //cmdLine.serial().printf("\r\n>");
06356             break;
06357 #if ECHO_EOF_ON_EOL
06358         case '\x04':     // Unicode (U+0004) EOT END OF TRANSMISSION = CTRL+D as EOF end of file
06359             cmdLine.serial().printf("\x04");     // immediately echo EOF for test scripting
06360             diagnostic_led_EOF();
06361             break;
06362         case '\x1a':     // Unicode (U+001A) SUB SUBSTITUTE = CTRL+Z as EOF end of file
06363             cmdLine.serial().printf("\x1a");     // immediately echo EOF for test scripting
06364             diagnostic_led_EOF();
06365             break;
06366 #endif
06367 #if APPLICATION_ArduinoPinsMonitor
06368         case '.':
06369         {
06370             // . -- SelfTest
06371             cmdLine.serial().printf("SelfTest()");
06372             SelfTest(cmdLine);
06373         }
06374         break;
06375         case '%':
06376         {
06377             pinsMonitor_submenu_onEOLcommandParser(cmdLine);
06378         }
06379         break;         // case '%'
06380 #endif // APPLICATION_ArduinoPinsMonitor
06381        //
06382        // Application-specific commands here
06383        // alphanumeric command codes A-Z,a-z,0-9 reserved for application use
06384        //
06385 #if APPLICATION_ArduinoPinsMonitor
06386 #endif // APPLICATION_ArduinoPinsMonitor
06387 
06388         //
06389         // TODO1: add new commands here
06390         //
06391         default:
06392 #if APPLICATION_MAX5715 // main_menu_onEOLcommandParser print command prompt
06393             extern bool MAX5715_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX5715.cpp
06394             if (!MAX5715_menu_onEOLcommandParser(cmdLine))
06395 #elif APPLICATION_MAX11131 // main_menu_onEOLcommandParser print command prompt
06396             extern bool MAX11131_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX11131.cpp
06397             if (!MAX11131_menu_onEOLcommandParser(cmdLine))
06398 #elif APPLICATION_MAX5171 // main_menu_onEOLcommandParser print command prompt
06399             extern bool MAX5171_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX5171.cpp
06400             if (!MAX5171_menu_onEOLcommandParser(cmdLine))
06401 #elif APPLICATION_MAX11410 // main_menu_onEOLcommandParser print command prompt
06402             extern bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX11410.cpp
06403             if (!MAX11410_menu_onEOLcommandParser(cmdLine))
06404 #elif APPLICATION_MAX12345 // main_menu_onEOLcommandParser print command prompt
06405             extern bool MAX12345_menu_onEOLcommandParser(CmdLine & cmdLine); // defined in Test_Menu_MAX12345.cpp
06406             if (!MAX12345_menu_onEOLcommandParser(cmdLine))
06407 #else
06408             if (0) // not_handled_by_device_submenu
06409 #endif
06410             {
06411                 cmdLine.serial().printf("\r\n unknown command 0x%2.2x \"%s\"\r\n", cmdLine.str()[0], cmdLine.str());
06412 # if HAS_DAPLINK_SERIAL
06413                 cmdLine_DAPLINKserial.serial().printf("\r\n unknown command 0x%2.2x \"%s\"\r\n",
06414                                                       cmdLine.str()[0], cmdLine.str());
06415 # endif // HAS_DAPLINK_SERIAL
06416             }
06417     }     // switch (cmdLine[0])
06418 //
06419 // print command prompt
06420 #if APPLICATION_MAX5715 // main_menu_onEOLcommandParser print command prompt
06421     cmdLine.serial().printf("\r\nMAX5715 > ");
06422 #elif APPLICATION_MAX11131 // main_menu_onEOLcommandParser print command prompt
06423     cmdLine.serial().printf("\r\nMAX11131 > ");
06424 #elif APPLICATION_MAX5171 // main_menu_onEOLcommandParser print command prompt
06425     cmdLine.serial().printf("\r\nMAX5171 > ");
06426 #elif APPLICATION_MAX11410 // main_menu_onEOLcommandParser print command prompt
06427     cmdLine.serial().printf("\r\nMAX11410 > ");
06428 #elif APPLICATION_MAX12345 // main_menu_onEOLcommandParser print command prompt
06429     cmdLine.serial().printf("\r\nMAX12345 > ");
06430 #else
06431     cmdLine.serial().printf("\r\n> ");
06432 #endif
06433 } // end void main_menu_onEOLcommandParser(CmdLine & cmdLine)
06434 
06435 //--------------------------------------------------
06436 void InitializeConfiguration()
06437 {
06438 
06439 #if APPLICATION_MAX5715 // InitializeConfiguration
06440 # if HAS_DAPLINK_SERIAL
06441     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5715_Init()");
06442 # endif
06443     cmdLine_serial.serial().printf("\r\nMAX5715_Init()");
06444     int initResult = g_MAX5715_device.Init();     // defined in #include MAX5715.h
06445 # if HAS_DAPLINK_SERIAL
06446     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5715_Init() returned %d\r\n", initResult);
06447 # endif
06448     cmdLine_serial.serial().printf("\r\nMAX5715_Init() returned %d\r\n", initResult);
06449 #endif // APPLICATION_MAX5715
06450 
06451 #if APPLICATION_MAX11131 // InitializeConfiguration
06452 # if HAS_DAPLINK_SERIAL
06453     cmdLine_DAPLINKserial.serial().printf("\r\nMAX11131_Init()");
06454 # endif
06455     cmdLine_serial.serial().printf("\r\nMAX11131_Init()");
06456     g_MAX11131_device.Init();     // defined in #include MAX11131.h
06457 #endif // APPLICATION_MAX11131
06458 
06459 #if APPLICATION_MAX5171 // InitializeConfiguration
06460 # if HAS_DAPLINK_SERIAL
06461     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5171_Init()");
06462 # endif
06463     cmdLine_serial.serial().printf("\r\nMAX5171_Init()");
06464     int initResult = g_MAX5171_device.Init();     // defined in #include MAX5171.h
06465 # if HAS_DAPLINK_SERIAL
06466     cmdLine_DAPLINKserial.serial().printf("\r\nMAX5171_Init() returned %d\r\n", initResult);
06467 # endif
06468     cmdLine_serial.serial().printf("\r\nMAX5171_Init() returned %d\r\n", initResult);
06469 #endif // APPLICATION_MAX5171
06470 
06471 #if APPLICATION_MAX11410 // InitializeConfiguration
06472 # if HAS_DAPLINK_SERIAL
06473     cmdLine_DAPLINKserial.serial().printf("\r\nMAX11410_Init()");
06474 # endif
06475     cmdLine_serial.serial().printf("\r\nMAX11410_Init()");
06476     int initResult = g_MAX11410_device.Init();     // defined in #include MAX11410.h
06477 # if HAS_DAPLINK_SERIAL
06478     cmdLine_DAPLINKserial.serial().printf("\r\nMAX11410_Init() returned %d\r\n", initResult);
06479 # endif
06480     cmdLine_serial.serial().printf("\r\nMAX11410_Init() returned %d\r\n", initResult);
06481 #endif // APPLICATION_MAX11410
06482 
06483 #if APPLICATION_MAX12345 // InitializeConfiguration
06484 # if HAS_DAPLINK_SERIAL
06485     cmdLine_DAPLINKserial.serial().printf("\r\nMAX12345_Init()");
06486 # endif
06487     cmdLine_serial.serial().printf("\r\nMAX12345_Init()");
06488     int initResult = g_MAX12345_device.Init();     // defined in #include MAX12345.h
06489 # if HAS_DAPLINK_SERIAL
06490     cmdLine_DAPLINKserial.serial().printf("\r\nMAX12345_Init() returned %d\r\n", initResult);
06491 # endif
06492     cmdLine_serial.serial().printf("\r\nMAX12345_Init() returned %d\r\n", initResult);
06493 #endif // APPLICATION_MAX12345
06494 
06495 }
06496 
06497 //--------------------------------------------------
06498 // diagnostic rbg led GREEN
06499 void diagnostic_led_EOF()
06500 {
06501 #if USE_LEDS
06502     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06503     // 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]
06504     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06505     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06506     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06507     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06508     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06509     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06510     ThisThread::sleep_for(250); // [since mbed-os-5.10] vs Thread::wait(250);
06511 #endif // USE_LEDS
06512 }
06513 
06514 //--------------------------------------------------
06515 // Support commands that get handled immediately w/o waiting for EOL
06516 // handled as immediate command, do not append to buffer
06517 void on_immediate_0x21() // Unicode (U+0021) ! EXCLAMATION MARK
06518 {
06519 #if USE_LEDS
06520     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
06521 #endif // USE_LEDS
06522     InitializeConfiguration();
06523     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06524 }
06525 
06526 //--------------------------------------------------
06527 // Support commands that get handled immediately w/o waiting for EOL
06528 // handled as immediate command, do not append to buffer
06529 void on_immediate_0x7b() // Unicode (U+007B) { LEFT CURLY BRACKET
06530 {
06531 #if HAS_BUTTON2_DEMO_INTERRUPT
06532     onButton2FallingEdge();
06533 #endif
06534 }
06535 
06536 //--------------------------------------------------
06537 // Support commands that get handled immediately w/o waiting for EOL
06538 // handled as immediate command, do not append to buffer
06539 void on_immediate_0x7d() // Unicode (U+007D) } RIGHT CURLY BRACKET
06540 {
06541 #if HAS_BUTTON1_DEMO_INTERRUPT
06542     onButton1FallingEdge();
06543 #endif
06544 }
06545 
06546 //--------------------------------------------------
06547 // based on example code: https://os.mbed.com/docs/v5.7/reference/pwmout.html
06548 int main()
06549 {
06550     // Configure serial ports
06551 #if defined(TARGET_MAX32630)
06552     // Note: DAPLINKserial interferes with the timer tick interrupt. Try faster baud rate?
06553     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_MAX32625MBED)
06560     // MAX32625MBED crash if DAPLINKserial.baud(anything other than 9600 baud)
06561     // xxx DAPLINKserial.baud(115200); // default 9600 baud
06562     //serial.baud(9600); // class USBSerial has no baud function
06563 #  if HAS_DAPLINK_SERIAL
06564     DAPLINKserial.printf("\r\n\r\nDAPLINK_SERIAL: main() startup\r\n");
06565 #  endif
06566 //--------------------------------------------------
06567 #elif defined(TARGET_LPC1768)
06568     serial.baud(115200);     // default 9600 baud
06569 #else
06570     // unknown target
06571 #endif
06572     cmdLine_serial.clear();
06573     //~ cmdLine_serial.serial().printf("\r\n cmdLine_serial.serial().printf test\r\n");
06574     cmdLine_serial.onEOLcommandParser = main_menu_onEOLcommandParser;
06575     cmdLine_serial.diagnostic_led_EOF = diagnostic_led_EOF;
06576     /// CmdLine::set_immediate_handler(char, functionPointer_void_void_on_immediate_0x21);
06577     cmdLine_serial.on_immediate_0x21 = on_immediate_0x21;
06578     cmdLine_serial.on_immediate_0x7b = on_immediate_0x7b;
06579     cmdLine_serial.on_immediate_0x7d = on_immediate_0x7d;
06580 # if HAS_DAPLINK_SERIAL
06581     cmdLine_DAPLINKserial.clear();
06582     //~ cmdLine_DAPLINKserial.serial().printf("\r\n cmdLine_DAPLINKserial.serial().printf test\r\n");
06583     cmdLine_DAPLINKserial.onEOLcommandParser = main_menu_onEOLcommandParser;
06584     /// @todo CmdLine::set_immediate_handler(char, functionPointer_void_void_on_immediate_0x21);
06585     cmdLine_DAPLINKserial.on_immediate_0x21 = on_immediate_0x21;
06586     cmdLine_DAPLINKserial.on_immediate_0x7b = on_immediate_0x7b;
06587     cmdLine_DAPLINKserial.on_immediate_0x7d = on_immediate_0x7d;
06588 # endif
06589 
06590 
06591     print_banner();
06592 
06593 //#ifdef SCOPE_TRIG_PIN
06594 //    scopePinP12 = 0;
06595 //    scopePinP12 = 1;
06596 //#endif // SCOPE_TRIG_PIN
06597 
06598 #if HAS_BUTTON1_DEMO_INTERRUPT
06599 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
06600 # else
06601     button1.fall(&onButton1FallingEdge);
06602 # endif
06603 #endif // HAS_BUTTON1_DEMO_INTERRUPT
06604 #if HAS_BUTTON2_DEMO_INTERRUPT
06605 # if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
06606 # else
06607     button2.fall(&onButton2FallingEdge);
06608 # endif
06609 #endif // HAS_BUTTON2_DEMO_INTERRUPT
06610 
06611 #if defined(TARGET_MAX32630)
06612     // Timer tick needs to be the highest priority (priority 0, the default).
06613     // DAPLINKserial interferes with the timer tick interrupt.
06614     // Lower the priority of the serial port interrupts to avoid disrupting onTimerTick() handler.
06615     NVIC_SetPriority(UART0_IRQn, 2); // reservedBlueToothSerial(P0_1, P0_0) // 0=highest priority; 1=lower
06616     NVIC_SetPriority(UART1_IRQn, 2); // DAPLINKserial(P2_1, P2_0) // 0=highest priority; 1=lower
06617     NVIC_SetPriority(UART2_IRQn, 2); // reservedSerial(P3_1, P3_0) // 0=highest priority; 1=lower
06618     NVIC_SetPriority(UART3_IRQn, 2); // reservedSerial(P5_4, P5_3) // 0=highest priority; 1=lower
06619     NVIC_SetPriority(GPIO_P0_IRQn, 2); // 0=highest priority; 1=lower
06620     NVIC_SetPriority(GPIO_P1_IRQn, 2); // 0=highest priority; 1=lower
06621     NVIC_SetPriority(GPIO_P2_IRQn, 2); // 0=highest priority; 1=lower
06622     NVIC_SetPriority(GPIO_P3_IRQn, 2); // 0=highest priority; 1=lower
06623     NVIC_SetPriority(GPIO_P4_IRQn, 2); // 0=highest priority; 1=lower
06624     NVIC_SetPriority(GPIO_P5_IRQn, 2); // 0=highest priority; 1=lower
06625     NVIC_SetPriority(GPIO_P6_IRQn, 2); // 0=highest priority; 1=lower
06626     NVIC_SetPriority(GPIO_P7_IRQn, 2); // 0=highest priority; 1=lower
06627     NVIC_SetPriority(GPIO_P8_IRQn, 2); // 0=highest priority; 1=lower
06628     //~ NVIC_SetPriority(RTC0_IRQn, 0); // 0=highest priority; 1=lower
06629     //~ NVIC_SetPriority(RTC3_IRQn, 0); // 0=highest priority; 1=lower
06630     //~ NVIC_SetPriority(US_TIMER_IRQn, 0); // 0=highest priority; 1=lower
06631 #endif
06632 
06633 #if HAS_SPI
06634     // spi init
06635     // mode | POL PHA
06636     // -----+--------
06637     //   0  |  0   0
06638     //   1  |  0   1
06639     //   2  |  1   0
06640     //   3  |  1   1
06641     //~ spi.format(8,0); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
06642     //~ spi.format(8,1); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=1 falling edge (initial default)
06643     //~ spi.format(8,2); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=0 falling edge (initial default)
06644     //~ spi.format(8,3); // int bits_must_be_8, int mode=0_3 CPOL=1,CPHA=1 rising edge (initial default)
06645     //
06646     //~ spi.frequency(1000000); // int SCLK_Hz=1000000 = 1MHz (initial default)
06647     //~ spi.frequency(9600000); // int SCLK_Hz=9600000 = 9.6MHz = 96MHz/10
06648     //~ spi.frequency(10666666); // int SCLK_Hz=10666666 = 10.6MHz = 96MHz/9
06649     //~ spi.frequency(12000000); // int SCLK_Hz=12000000 = 12MHz = 96MHz/8
06650     //~ spi.frequency(13714286); // int SCLK_Hz=13714286 = 13.7MHz = 96MHz/7
06651     //~ spi.frequency(16000000); // int SCLK_Hz=16000000 = 16MHz = 96MHz/6
06652     //~ spi.frequency(19200000); // int SCLK_Hz=19200000 = 19.2MHz = 96MHz/5
06653     //~ spi.frequency(24000000); // int SCLK_Hz=24000000 = 24MHz = 96MHz/4
06654     //~ spi.frequency(32000000); // int SCLK_Hz=32000000 = 32MHz = 96MHz/3
06655     //~ spi.frequency(48000000); // int SCLK_Hz=48000000 = 48MHz = 96MHz/2
06656     // unspecified SPI device
06657     spi.format(8,g_SPI_dataMode);     // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 rising edge (initial default)
06658     spi.frequency(g_SPI_SCLK_Hz);     // int SCLK_Hz=1000000 = 1MHz (initial default)
06659     spi_cs = 1;
06660 #endif
06661 
06662 #if HAS_I2C
06663 // i2c init
06664 // declare in narrower scope: MAX32625MBED I2C i2cMaster(...)
06665 //    i2cMaster.frequency(g_I2C_SCL_Hz);
06666 #else
06667     // Ensure that the unused I2C pins do not interfere with analog inputs A4 and A5
06668 #if HAS_digitalInOut14
06669     // DigitalInOut digitalInOut14(P1_6, PIN_INPUT, PullUp, 1); // P1_6 TARGET_MAX32635MBED A4/SDA (10pin digital connector)
06670     digitalInOut14.input();
06671 #endif
06672 #if HAS_digitalInOut15
06673     // DigitalInOut digitalInOut15(P1_7, PIN_INPUT, PullUp, 1); // P1_7 TARGET_MAX32635MBED A5/SCL (10pin digital connector)
06674     digitalInOut15.input();
06675 #endif
06676 #if HAS_digitalInOut16
06677     // DigitalInOut mode can be one of PullUp, PullDown, PullNone, OpenDrain
06678     // PullUp-->3.4V, PullDown-->1.7V, PullNone-->3.5V, OpenDrain-->0.00V
06679     //DigitalInOut digitalInOut16(P3_4, PIN_INPUT, OpenDrain, 0); // P3_4 TARGET_MAX32635MBED A4/SDA (6pin analog connector)
06680     digitalInOut16.input();
06681 #endif
06682 #if HAS_digitalInOut17
06683     //DigitalInOut digitalInOut17(P3_5, PIN_INPUT, OpenDrain, 0); // P3_5 TARGET_MAX32635MBED A5/SCL (6pin analog connector)
06684     digitalInOut17.input();
06685 #endif
06686 #endif
06687 
06688 #if USE_LEDS
06689 #if defined(TARGET_MAX32630)
06690     led1 = LED_ON; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led RED
06691     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06692     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06693     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06694     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
06695     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06696     led1 = LED_ON; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led RED+GREEN+BLUE=WHITE
06697     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06698     led1 = LED_OFF; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led GREEN+BLUE=CYAN
06699     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06700     led1 = LED_ON; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led RED+BLUE=MAGENTA
06701     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06702     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06703     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06704     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led BLACK
06705     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06706 #elif defined(TARGET_MAX32625MBED)
06707     led1 = LED_ON; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led RED
06708     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06709     led1 = LED_OFF; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led GREEN
06710     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06711     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
06712     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06713     led1 = LED_ON; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led RED+GREEN+BLUE=WHITE
06714     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06715     led1 = LED_OFF; led2 = LED_ON; led3 = LED_ON;     // diagnostic rbg led GREEN+BLUE=CYAN
06716     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06717     led1 = LED_ON; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led RED+BLUE=MAGENTA
06718     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06719     led1 = LED_ON; led2 = LED_ON; led3 = LED_OFF;     // diagnostic rbg led RED+GREEN=YELLOW
06720     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06721     led1 = LED_OFF; led2 = LED_OFF; led3 = LED_OFF;     // diagnostic rbg led BLACK
06722     ThisThread::sleep_for(125); // [since mbed-os-5.10] vs Thread::wait(125);
06723 #else // not defined(TARGET_LPC1768 etc.)
06724     led1 = LED_ON;
06725     led2 = LED_OFF;
06726     led3 = LED_OFF;
06727     led4 = LED_OFF;
06728     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06729     //led1 = LED_ON;
06730     led2 = LED_ON;
06731     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06732     led1 = LED_OFF;
06733     //led2 = LED_ON;
06734     led3 = LED_ON;
06735     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06736     led2 = LED_OFF;
06737     //led3 = LED_ON;
06738     led4 = LED_ON;
06739     ThisThread::sleep_for(75); // [since mbed-os-5.10] vs Thread::wait(75);
06740     led3 = LED_OFF;
06741     led4 = LED_ON;
06742     //
06743 #endif // target definition
06744 #endif
06745 
06746     // cmd_TE();
06747 
06748 #if USE_LEDS
06749     rgb_led.white();     // diagnostic rbg led RED+GREEN+BLUE=WHITE
06750 #endif // USE_LEDS
06751     InitializeConfiguration();
06752 
06753     while (1) {
06754 #if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
06755         // avoid runtime error on button1 press [mbed-os-5.11]
06756         // instead of using InterruptIn, use DigitalIn and poll in main while(1)
06757 # if HAS_BUTTON1_DEMO_INTERRUPT
06758         static int button1_value_prev = 1;
06759         static int button1_value_now = 1;
06760         button1_value_prev = button1_value_now;
06761         button1_value_now = button1.read();
06762         if ((button1_value_prev - button1_value_now) == 1)
06763         {
06764             // on button1 falling edge (button1 press)
06765             onButton1FallingEdge();
06766         }
06767 # endif // HAS_BUTTON1_DEMO_INTERRUPT
06768 # if HAS_BUTTON2_DEMO_INTERRUPT
06769         static int button2_value_prev = 1;
06770         static int button2_value_now = 1;
06771         button2_value_prev = button2_value_now;
06772         button2_value_now = button2.read();
06773         if ((button2_value_prev - button2_value_now) == 1)
06774         {
06775             // on button2 falling edge (button2 press)
06776             onButton2FallingEdge();
06777         }
06778 # endif // HAS_BUTTON2_DEMO_INTERRUPT
06779 #endif
06780     # if HAS_DAPLINK_SERIAL
06781         if (DAPLINKserial.readable()) {
06782             cmdLine_DAPLINKserial.append(DAPLINKserial.getc());
06783         }
06784     # endif // HAS_DAPLINK_SERIAL
06785         if (serial.readable()) {
06786             int c = serial.getc();
06787             cmdLine_serial.append(c);
06788 #if IGNORE_AT_COMMANDS
06789 # if HAS_DAPLINK_SERIAL
06790             cmdLine_DAPLINKserial.serial().printf("%c", c);
06791 # endif // HAS_DAPLINK_SERIAL
06792 #endif // IGNORE_AT_COMMANDS
06793             //
06794         }
06795     }     // while(1)
06796 }