Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 USBDevice
Diff: Test_Menu_MAX11043.cpp
- Revision:
- 57:1c9da8e90737
- Parent:
- 53:3d5a3d241a5e
- Child:
- 59:47538bcf6cda
--- a/Test_Menu_MAX11043.cpp Wed Feb 12 00:37:04 2020 +0000 +++ b/Test_Menu_MAX11043.cpp Thu Feb 13 22:52:57 2020 +0000 @@ -98,14 +98,12 @@ // CODE GENERATOR: CommandReturn '@return 1 on success; 0 on failure' // CODE GENERATOR: MAX11043 Command Name = RegWrite (MAX11043_CMD_enum_t commandByte, uint32_t regData) --> uint8_t // CODE GENERATOR: no Menu item hint in description -// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ -// CODE GENERATOR: MAX11043 Command Name = RegWrite CMD_1aaa_aaaa_REGISTER_READ (MAX11043_CMD_enum_t commandByte, uint32_t regData) --> uint8_t // CODE GENERATOR: MAX11043 Command Name = RegRead (MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t // CODE GENERATOR: no Menu item hint in description -// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ -// CODE GENERATOR: MAX11043 Command Name = RegRead CMD_1aaa_aaaa_REGISTER_READ (MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t // CODE GENERATOR: MAX11043 Command Name = RegSize (MAX11043_CMD_enum_t commandByte) --> uint8_t // CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: MAX11043 Command Name = DecodeCommand (MAX11043_CMD_enum_t commandByte) --> MAX11043::MAX11043_CMDOP_enum_t +// CODE GENERATOR: no Menu item hint in description // CODE GENERATOR: MAX11043 Command Name = RegAddrOfCommand (MAX11043_CMD_enum_t commandByte) --> uint8_t // CODE GENERATOR: no Menu item hint in description // CODE GENERATOR: MAX11043 Command Name = IsRegReadCommand (MAX11043_CMD_enum_t commandByte) --> uint8_t @@ -353,17 +351,37 @@ } } // end for regAddr // not a valid register name + Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11043_device.onSPIprint; + g_MAX11043_device.onSPIprint = NULL; // temporarily suppress SPI diagnostic messages // read "all" registers by name - const uint8_t readAllRegFirst = 0x00; // first MAX11043 register address for read-all block - const uint8_t readAllRegLast = 0x39; // last MAX11043 register address for read-all block - Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11043_device.onSPIprint; - g_MAX11043_device.onSPIprint = NULL; - for (uint8_t regAddress = readAllRegFirst; regAddress <= readAllRegLast; regAddress++) + // TODO: KLUDGE: this constant array should live in the device driver, not the menu + const MAX11043::MAX11043_CMD_enum_t readAllStatusList[] = { + MAX11043::CMD_0000_0010_d24_Rd00_ADCa, + MAX11043::CMD_0000_0110_d24_Rd01_ADCb, + MAX11043::CMD_0000_1010_d24_Rd02_ADCc, + MAX11043::CMD_0000_1110_d24_Rd03_ADCd, + MAX11043::CMD_0001_1110_d8_Rd07_Status, + MAX11043::CMD_0010_0010_d16_Rd08_Configuration, + MAX11043::CMD_0010_0110_d16_Rd09_DAC, + MAX11043::CMD_0010_1010_d16_Rd0A_DACStep, + MAX11043::CMD_0010_1110_d16_Rd0B_DACHDACL, + MAX11043::CMD_0011_0010_d16_Rd0C_ConfigA, + MAX11043::CMD_0011_0110_d16_Rd0D_ConfigB, + MAX11043::CMD_0011_1010_d16_Rd0E_ConfigC, + MAX11043::CMD_0011_1110_d16_Rd0F_ConfigD, + MAX11043::CMD_0100_0010_d16_Rd10_Reference, + MAX11043::CMD_0100_0110_d16_Rd11_AGain, + MAX11043::CMD_0100_1010_d16_Rd12_BGain, + MAX11043::CMD_0100_1110_d16_Rd13_CGain, + MAX11043::CMD_0101_0010_d16_Rd14_DGain, + }; + for (uint8_t readAllStatusIndex = 0; readAllStatusIndex < (sizeof(readAllStatusList)/sizeof(MAX11043::MAX11043_CMD_enum_t)); readAllStatusIndex++) { + MAX11043::MAX11043_CMD_enum_t regAddress = readAllStatusList[readAllStatusIndex]; uint32_t regData = 0; - if (g_MAX11043_device.RegSize((MAX11043::MAX11043_CMD_enum_t)regAddress) == 0) continue; // skip undefined regs - if (g_MAX11043_device.RegRead((MAX11043::MAX11043_CMD_enum_t)regAddress, ®Data) == 0) continue; // skip unreadable regs - cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11043_device.RegName((MAX11043::MAX11043_CMD_enum_t)regAddress), regData); + if (g_MAX11043_device.RegSize(regAddress) == 0) continue; // skip undefined regs + if (g_MAX11043_device.RegRead(regAddress, ®Data) == 0) continue; // skip unreadable regs + cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11043_device.RegName(regAddress), regData); } // end for regAddr g_MAX11043_device.onSPIprint = saved_onSPIprint_handler; return true; // command handled by MAX11043 @@ -577,14 +595,16 @@ if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData, MAX_SPI_BYTE_COUNT)) { - // if length is 1 byte then operation is RegRead, otherwise RegWrite + // TODO: decode operation from commandByte + // TODO: OVERSIMPLIFICATION: if length is 1 byte then operation is RegRead, otherwise RegWrite // register_read_function 'IsRegReadCommand' // register_write_function 'RegWrite' // register_name_function 'RegName' // register_size_function 'RegSize' -// CODE GENERATOR: does the chip have a defined CMD_1aaa_aaaa_REGISTER_READ bit? - // MAX11043::MAX11043_CMD_enum_t regAddress = (MAX11043::MAX11043_CMD_enum_t)((mosiData[0] &~ MAX11043::CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); +// CODE GENERATOR: does the chip have a defined CMDOP_1aaa_aaaa_ReadRegister bit? + // MAX11043::MAX11043_CMD_enum_t regAddress = (MAX11043::MAX11043_CMD_enum_t)((mosiData[0] &~ MAX11043::CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); MAX11043::MAX11043_CMD_enum_t commandByte = (MAX11043::MAX11043_CMD_enum_t)(mosiData[0]); + MAX11043::MAX11043_CMDOP_enum_t commandOp = g_MAX11043_device.DecodeCommand(commandByte); int regAddress = g_MAX11043_device.RegAddrOfCommand(commandByte); cmdLine.serial().printf(" regAddress=0x%2.2x\r\n", (regAddress & 0xFF)); cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11043_device.RegName(commandByte)); @@ -603,8 +623,8 @@ regData = (((uint32_t)mosiData[1] & 0xFF) << 16) + (((uint32_t)mosiData[2] & 0xFF) << 8) + ((uint32_t)mosiData[3] & 0xFF); break; } -// CODE GENERATOR: does the chip have a defined CMD_1aaa_aaaa_REGISTER_READ bit? - // if ((byteCount == 1) || (regAddress & MAX11043::CMD_1aaa_aaaa_REGISTER_READ)) +// CODE GENERATOR: does the chip have a defined CMDOP_1aaa_aaaa_ReadRegister bit? + // if ((byteCount == 1) || (regAddress & MAX11043::CMDOP_1aaa_aaaa_ReadRegister)) if ((byteCount == 1) || g_MAX11043_device.IsRegReadCommand(commandByte)) { cmdLine.serial().printf(" RegRead");