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

Dependencies:   MaximTinyTester MAX11410 CmdLine USBDevice

Test_Menu_MAX11410.cpp

Committer:
whismanoid
Date:
2019-11-11
Revision:
35:8aa5dffe523d
Parent:
32:ad00de965151
Child:
37:74aa97afa030

File content as of revision 35:8aa5dffe523d:

// /*******************************************************************************
// * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
// *
// * Permission is hereby granted, free of charge, to any person obtaining a
// * copy of this software and associated documentation files (the "Software"),
// * to deal in the Software without restriction, including without limitation
// * the rights to use, copy, modify, merge, publish, distribute, sublicense,
// * and/or sell copies of the Software, and to permit persons to whom the
// * Software is furnished to do so, subject to the following conditions:
// *
// * The above copyright notice and this permission notice shall be included
// * in all copies or substantial portions of the Software.
// *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
// * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// * OTHER DEALINGS IN THE SOFTWARE.
// *
// * Except as contained in this notice, the name of Maxim Integrated
// * Products, Inc. shall not be used except as stated in the Maxim Integrated
// * Products, Inc. Branding Policy.
// *
// * The mere transfer of this software does not imply any licenses
// * of trade secrets, proprietary technology, copyrights, patents,
// * trademarks, maskwork rights, or any other form of intellectual
// * property whatsoever. Maxim Integrated Products, Inc. retains all
// * ownership rights.
// *******************************************************************************
// */
#include "CmdLine.h"
// CODE GENERATOR: class declaration and docstrings
// CODE GENERATOR: example code includes
// example code includes
// standard include for target platform -- Platform_Include_Boilerplate
#include "mbed.h"
// Platforms:
//   - MAX32625MBED
//      - supports mbed-os-5.11, requires USBDevice library
//      - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
//      - remove max32630fthr library (if present)
//      - remove MAX32620FTHR library (if present)
//   - MAX32600MBED
//      - remove max32630fthr library (if present)
//      - remove MAX32620FTHR library (if present)
//      - Windows 10 note:  Don't connect HDK until you are ready to load new firmware into the board.
//   - NUCLEO_F446RE
//      - remove USBDevice library
//      - remove max32630fthr library (if present)
//      - remove MAX32620FTHR library (if present)
//   - NUCLEO_F401RE
//      - remove USBDevice library
//      - remove max32630fthr library (if present)
//      - remove MAX32620FTHR library (if present)
//   - MAX32630FTHR
//      - #include "max32630fthr.h"
//      - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
//      - remove MAX32620FTHR library (if present)
//   - MAX32620FTHR
//      - #include "MAX32620FTHR.h"
//      - remove max32630fthr library (if present)
//      - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
//      - not tested yet
//   - MAX32625PICO
//      - remove max32630fthr library (if present)
//      - remove MAX32620FTHR library (if present)
//      - not tested yet
//
// end Platform_Include_Boilerplate
#include "MAX11410.h"
#include "CmdLine.h"
// CODE GENERATOR: class declaration statement open

// CODE GENERATOR: Test_Menu externs
#include "MAX11410.h"
extern MAX11410 g_MAX11410_device; // defined in main.cpp

// CODE GENERATOR: build testMenuCommand list
// CODE GENERATOR: build testMenuGlobalArgsDict common/global argument list
// CODE GENERATOR: class member function declarations
// CODE GENERATOR: MAX11410 Command Name = Init (void) --> uint8_t
// CODE GENERATOR: Menu item hint description Menu item '!'
// CODE GENERATOR: Menu item '!' -- Menu item !
// CODE GENERATOR: test menu case '!':
// CODE GENERATOR:           helpString '! -- Init'
// CODE GENERATOR:           CMD_ 'None'
// CODE GENERATOR:           CommandName 'Init'
// CODE GENERATOR:           CommandParamIn 'void'
// CODE GENERATOR:           CommandReturnType 'uint8_t'
// CODE GENERATOR:           CommandPre ''
// CODE GENERATOR:           CommandPost ''
// CODE GENERATOR:           CommandReturn '@return 1 on success; 0 on failure'
// CODE GENERATOR: MAX11410 Command Name = VoltageOfCode (uint16_t value_u24) --> double
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = RegWrite (MAX11410_CMD_enum_t regAddress, uint32_t regData) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ
// CODE GENERATOR: MAX11410 Command Name = RegWrite CMD_1aaa_aaaa_REGISTER_READ (MAX11410_CMD_enum_t regAddress, uint32_t regData) --> uint8_t
// CODE GENERATOR: MAX11410 Command Name = RegRead (MAX11410_CMD_enum_t regAddress, uint32_t* ptrRegData) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ
// CODE GENERATOR: MAX11410 Command Name = RegRead CMD_1aaa_aaaa_REGISTER_READ (MAX11410_CMD_enum_t regAddress, uint32_t* ptrRegData) --> uint8_t
// CODE GENERATOR: MAX11410 Command Name = RegSize (MAX11410_CMD_enum_t regAddress) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = RegName (MAX11410_CMD_enum_t regAddress) --> const char*
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = Configure_Voltage (MAX11410_AINP_SEL_enum_t channel_hi, MAX11410_AINN_SEL_enum_t channel_lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = _TODO_MAX11410_Read_All_Voltages_ (MAX11410_AINP_SEL_enum_t channel_hi, MAX11410_AINN_SEL_enum_t channel_lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = Measure_Voltage (MAX11410_AINP_SEL_enum_t channel_hi, MAX11410_AINN_SEL_enum_t channel_lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = Configure_RTD (MAX11410_AINP_SEL_enum_t channel_RTD_Force, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINN_SEL_enum_t channel_RTD_Lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = Measure_RTD (MAX11410_AINP_SEL_enum_t channel_RTD_Force, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINN_SEL_enum_t channel_RTD_Lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = Configure_Thermocouple (MAX11410_AINP_SEL_enum_t channel_TC_Hi, MAX11410_AINN_SEL_enum_t channel_TC_Lo, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINP_SEL_enum_t channel_RTD_Lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: MAX11410 Command Name = Measure_Thermocouple (MAX11410_AINP_SEL_enum_t channel_TC_Hi, MAX11410_AINN_SEL_enum_t channel_TC_Lo, MAX11410_AINP_SEL_enum_t channel_RTD_Hi, MAX11410_AINP_SEL_enum_t channel_RTD_Lo) --> uint8_t
// CODE GENERATOR: no Menu item hint in description
// CODE GENERATOR: testMenuGlobalArgsDict scan global property list g_MAX11410_device

// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.VRef
// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.VRef argname = VRef
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['alias'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['argtype'] = 'double'
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['usedByCommandName'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['usedBytestMenuItemName'] = 'None'

// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.status
// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.status shadow of argname = status
// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.status argname = status
// CODE GENERATOR: testMenuGlobalArgsDict['status']['alias'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['status']['argtype'] = 'uint32_t'
// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedByCommandName'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedBytestMenuItemName'] = 'None'

// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.data0
// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.data0 shadow of argname = data0
// CODE GENERATOR: testMenuGlobalArgsDict add global property g_MAX11410_device.data0 argname = data0
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['alias'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['argtype'] = 'uint32_t'
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedByCommandName'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedBytestMenuItemName'] = 'None'


// CODE GENERATOR: scan testMenuCommand list for items that can be shortened to single character
// CODE GENERATOR: shorten testMenuCommand to single character if unambiguous
// CODE GENERATOR: testMenuCommand '!' already single character

// CODE GENERATOR: help menu
bool MAX11410_menu_help(CmdLine & cmdLine)
{
    // CODE GENERATOR: command: !
    // CODE GENERATOR: help: ! -- Init
    cmdLine.serial().printf("\r\n ! -- Init");
    //
    cmdLine.serial().printf("\r\n @ -- print MAX11410 configuration");
    //
}

bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine)
{

// CODE GENERATOR: before switch (cmdLine[0]), test if buffer starts with a regName
    // TODO: if buffer starts with a regName:
    // for each reg value (0..n) if(cmdLine.has_keyword(device.regName(r))):
    cmdLine.serial().printf(" scan RegName... ");
    for (uint8_t regAddress = 0; regAddress < 0x80; regAddress++)
    {
        uint32_t regData = 0;
        bool is_regname_query = false;
        bool is_regname_assignment = false;
        if (cmdLine.parse_uint32_dec(g_MAX11410_device.RegName((MAX11410::MAX11410_CMD_enum_t)regAddress), regData))
        {
            cmdLine.serial().printf(" regAddress=0x%2.2X\r\n", (regAddress & 0xFF));
            cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11410_device.RegName((MAX11410::MAX11410_CMD_enum_t)regAddress));
            // TODO: accept regName ’?’ as ‘RegRead‘ by name
            is_regname_query = (cmdLine.chSeparator == '?');
            is_regname_assignment = (cmdLine.chSeparator == '=');
            if (is_regname_query)
            {
                cmdLine.serial().printf(" RegRead");
                g_MAX11410_device.RegRead((MAX11410::MAX11410_CMD_enum_t)regAddress, &regData);
                cmdLine.serial().printf("regData=0x%6.6x\r\n", (regData & 0x00FFFFFF));
            }
            // TODO: accept regName ’=0x123456’ as ‘RegWrite’ by name
            if (is_regname_assignment)
            {
                cmdLine.serial().printf(" RegWrite");
                cmdLine.serial().printf("regData=0x%6.6x\r\n", (regData & 0x00FFFFFF));
                g_MAX11410_device.RegWrite((MAX11410::MAX11410_CMD_enum_t)regAddress, regData);
            }
        }
    } // end for regAddr

// CODE GENERATOR: testMenuGlobalArgsDict Consolidate common/global argument parsing

// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['alias'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['argtype'] = 'double'
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['usedByCommandName'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['VRef']['usedBytestMenuItemName'] = 'None'
                    // parse argument double VRef
        double VRef = g_MAX11410_device.VRef; // default to global property value
        if (cmdLine.parse_double("VRef", VRef))
        {
            g_MAX11410_device.VRef = VRef; // update global property value
        }

// CODE GENERATOR: testMenuGlobalArgsDict['data0']['alias'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['argtype'] = 'uint32_t'
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedByCommandName'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['data0']['usedBytestMenuItemName'] = 'None'
                    // parse argument uint32_t data0
        uint32_t data0 = g_MAX11410_device.data0; // default to global property value
        if (cmdLine.parse_uint32_dec("data0", data0))
        {
            g_MAX11410_device.data0 = data0; // update global property value
        }

// CODE GENERATOR: testMenuGlobalArgsDict['status']['alias'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['status']['argtype'] = 'uint32_t'
// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedByCommandName'] = 'None'
// CODE GENERATOR: testMenuGlobalArgsDict['status']['usedBytestMenuItemName'] = 'None'
                    // parse argument uint32_t status
        uint32_t status = g_MAX11410_device.status; // default to global property value
        if (cmdLine.parse_uint32_dec("status", status))
        {
            g_MAX11410_device.status = status; // update global property value
        }

    switch (cmdLine[0])
    {
// CODE GENERATOR: generate @ command print global property values of  g_MAX11410_device
        case '@':
        {
// CODE GENERATOR: @ command print double g_MAX11410_device.VRef
                    cmdLine.serial().printf("VRef = ");
                    cmdLine.serial().printf("%f\n", g_MAX11410_device.VRef);
// CODE GENERATOR: @ command print uint32_t g_MAX11410_device.status
                    cmdLine.serial().printf("status = ");
                    cmdLine.serial().printf("%d = 0x%8.8x\n", g_MAX11410_device.status, g_MAX11410_device.status);
// CODE GENERATOR: @ command print uint32_t g_MAX11410_device.data0
                    cmdLine.serial().printf("data0 = ");
                    cmdLine.serial().printf("%d = 0x%8.8x\n", g_MAX11410_device.data0, g_MAX11410_device.data0);
                    return true; // command handled by MAX11410
            break;
        }
// CODE GENERATOR: TODO1: generate GPIO commands for LDAC, CLR, etc. based on device driver function names
        // case 'G'..'Z','g'..'z' are reserved for GPIO commands
        // case 'A'..'F','a'..'f' may be available if not claimed by bitstream commands

// CODE GENERATOR: test menu
        // case '0'..'9','A'..'F','a'..'f' letters are reserved for bitstream commands
        // has_register_write_command: case '0'..'9','A'..'F','a'..'f' letters are reserved for bitstream commands
// CODE GENERATOR: test menu case '!':
// CODE GENERATOR:           helpString '! -- Init'
// CODE GENERATOR:           CMD_ 'None'
// CODE GENERATOR:           CommandName 'Init'
// CODE GENERATOR:           CommandParamIn 'void'
// CODE GENERATOR:           CommandReturnType 'uint8_t'
// CODE GENERATOR:           CommandPre ''
// CODE GENERATOR:           CommandPost ''
// CODE GENERATOR:           CommandReturn '@return 1 on success; 0 on failure'
        case '!':
        {
                    // test menu command '!' handler:
                    // helpString='! -- Init'
                    // CMD_='None'
                    // CommandName='Init'
                    // CommandParamIn='void'
                    // CommandReturnType='uint8_t'
                    // @Pre=''
                    // @Post=''
                    // @Return='@return 1 on success; 0 on failure'
                    cmdLine.serial().printf("Init");
                    // call function Init
                    uint8_t result = g_MAX11410_device.Init();
                    cmdLine.serial().printf(" =%d", result);
                    return true; // command handled by MAX11410
        } // end case '!'
        break;

        // has_register_write_command: case '0'..'9','A'..'F','a'..'f' letters are reserved for bitstream commands
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
        case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
        case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
        {
            // hexadecimal codes get parsed as bytecodes
            //
            // parse_byteCount_byteList_dec() assumes all keyword args have already been removed from the buffer
                    // parse cmdLine byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
                    #define MAX_SPI_BYTE_COUNT 32
                    size_t byteCount = byteCount;
                    static char mosiData[MAX_SPI_BYTE_COUNT];
                    static char misoData[MAX_SPI_BYTE_COUNT];
                    if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData,
                                                             MAX_SPI_BYTE_COUNT))
                    {
                        // if length is 1 byte then operation is RegRead, otherwise RegWrite
                        // register_read_function 'RegRead'
                        // register_write_function 'RegWrite'
                        // register_name_function 'RegName'
                        // register_size_function 'RegSize'
                        MAX11410::MAX11410_CMD_enum_t regAddress = (MAX11410::MAX11410_CMD_enum_t)((mosiData[0] &~ MAX11410::CMD_1aaa_aaaa_REGISTER_READ) & 0xFF);
                        cmdLine.serial().printf(" regAddress=0x%2.2x\r\n", (regAddress & 0xFF));
                        cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11410_device.RegName(regAddress));
                        uint32_t regData = 0;
                        int regSize = g_MAX11410_device.RegSize(regAddress);
                        cmdLine.serial().printf(" RegSize=%d\r\n", regSize);
                        switch(regSize)
                        {
                        case 8:
                            regData = ((uint32_t)mosiData[1] & 0xFF);
                            break;
                        case 16:
                            regData = (((uint32_t)mosiData[1] & 0xFF) << 8) + ((uint32_t)mosiData[2] & 0xFF);
                            break;
                        case 24:
                            regData = (((uint32_t)mosiData[1] & 0xFF) << 16) + (((uint32_t)mosiData[2] & 0xFF) << 8) + ((uint32_t)mosiData[3] & 0xFF);
                            break;
                        }
                        if ((byteCount == 1) || (regAddress & MAX11410::CMD_1aaa_aaaa_REGISTER_READ))
                        {
                            cmdLine.serial().printf(" RegRead");
                            g_MAX11410_device.RegRead(regAddress, &regData);
                            cmdLine.serial().printf("regData=0x%6.6x\r\n", (regData & 0x00FFFFFF));
                        }
                        else
                        {
                            cmdLine.serial().printf(" RegWrite regData=0x%6.6X\r\n", (regData & 0x00FFFFFF));
                            g_MAX11410_device.RegWrite(regAddress, regData);
                        }
                        // is there support function shadow regValue of regAddr?
                    }
                    return true; // command handled by MAX11410
            //
        } // end case '0'..'9','A'..'F','a'..'f'
        break;
    } // end switch (cmdLine[0])
    return false; // command not handled by MAX11410
} // end bool MAX11410_menu_onEOLcommandParser(CmdLine & cmdLine)

// CODE GENERATOR: class declaration statement close