Example program for EVAL-AD5770R

Dependencies:   adi_console_menu platform_drivers

Committer:
mahphalke
Date:
Wed Feb 24 12:18:35 2021 +0000
Revision:
4:ddef2e8cb4f7
Parent:
3:8a6aa77aba73
Child:
5:f3d7cf95cd8f
Changed Mbed-OS revision to 5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbradley 1:63c505e13da4 1 /*!
mbradley 1:63c505e13da4 2 *****************************************************************************
mbradley 1:63c505e13da4 3 @file: ad5770r_console_app.c
mbradley 1:63c505e13da4 4
mbradley 1:63c505e13da4 5 @brief: Implementation for the menu functions that handle the AD5770R
mbradley 1:63c505e13da4 6
mbradley 1:63c505e13da4 7 @details:
mbradley 1:63c505e13da4 8 -----------------------------------------------------------------------------
mbradley 1:63c505e13da4 9 *
mbradley 1:63c505e13da4 10 Copyright (c) 2020 Analog Devices, Inc. All Rights Reserved.
mbradley 1:63c505e13da4 11
mbradley 1:63c505e13da4 12 This software is proprietary to Analog Devices, Inc. and its licensors.
mbradley 1:63c505e13da4 13 By using this software you agree to the terms of the associated
mbradley 1:63c505e13da4 14 Analog Devices Software License Agreement.
mbradley 1:63c505e13da4 15 ******************************************************************************/
mbradley 1:63c505e13da4 16
mbradley 1:63c505e13da4 17 /* includes */
mbradley 1:63c505e13da4 18 #include <stdio.h>
mbradley 1:63c505e13da4 19 #include <stdlib.h>
mbradley 1:63c505e13da4 20 #include <string.h>
mbradley 1:63c505e13da4 21 #include <stdbool.h>
mbradley 1:63c505e13da4 22 #include <stdint.h>
mbradley 1:63c505e13da4 23 #include <assert.h>
mbradley 1:63c505e13da4 24
mbradley 1:63c505e13da4 25 #include "app_config.h"
mbradley 1:63c505e13da4 26
mbradley 1:63c505e13da4 27 #include "platform_drivers.h"
mbradley 1:63c505e13da4 28 #include "platform_support.h"
mbradley 1:63c505e13da4 29 #include "ad5770r.h"
mbradley 1:63c505e13da4 30
mbradley 1:63c505e13da4 31 #include "ad5770r_console_app.h"
mbradley 1:63c505e13da4 32 #include "ad5770r_user_config.h"
mbradley 1:63c505e13da4 33 #include "ad5770r_reset_config.h"
mbradley 1:63c505e13da4 34
mbradley 1:63c505e13da4 35 /* defines */
mbradley 1:63c505e13da4 36 #define TOGGLE_MUX_BUFFER 1000
mbradley 1:63c505e13da4 37 #define TOGGLE_DIODE_EXT_BIAS 1001
mbradley 1:63c505e13da4 38 #define MENU_CHANNEL_OFFSET 100
mbradley 1:63c505e13da4 39
mbradley 1:63c505e13da4 40 /* Private Variables */
mbradley 1:63c505e13da4 41 static struct ad5770r_dev * pAd5770r_dev = NULL;
mbradley 1:63c505e13da4 42
mbradley 1:63c505e13da4 43 static struct ad5770r_channel_switches sw_ldac_shadow;
mbradley 1:63c505e13da4 44
mbradley 1:63c505e13da4 45 // GPIO descriptor and init parameters for the HW LDACB pin
mbradley 1:63c505e13da4 46 static gpio_desc * hw_ldacb_desc = NULL;
mbradley 1:63c505e13da4 47 static gpio_init_param hw_ldacb_init_param = { HW_LDACB, NULL };
mbradley 1:63c505e13da4 48
mbradley 1:63c505e13da4 49
mbradley 1:63c505e13da4 50 // Forward Declaration
mbradley 1:63c505e13da4 51 static console_menu general_configuration_menu;
mbradley 1:63c505e13da4 52 static console_menu monitor_setup_menu;
mbradley 1:63c505e13da4 53 static console_menu dac_channel_configuration_menu;
mbradley 1:63c505e13da4 54 static console_menu dac_operations_menu;
mbradley 1:63c505e13da4 55
mbradley 1:63c505e13da4 56 // Public Functions
mbradley 1:63c505e13da4 57
mbradley 1:63c505e13da4 58 /*!
mbradley 1:63c505e13da4 59 * @brief Initialize the AD7124 device and the SPI port as required
mbradley 1:63c505e13da4 60 *
mbradley 1:63c505e13da4 61 * @details This resets and then writes the default register map value to
mbradley 1:63c505e13da4 62 * the device. A call to init the SPI port is made, but may not
mbradley 1:63c505e13da4 63 * actually do very much, depending on the platform
mbradley 1:63c505e13da4 64 */
mbradley 1:63c505e13da4 65 int32_t ad5770r_app_initialize(void)
mbradley 1:63c505e13da4 66 {
mbradley 1:63c505e13da4 67
mbradley 1:63c505e13da4 68 // Create a new descriptor for HW LDACB
mbradley 1:63c505e13da4 69 if(gpio_get(&hw_ldacb_desc, &hw_ldacb_init_param) == FAILURE) {
mbradley 1:63c505e13da4 70 return FAILURE;
mbradley 1:63c505e13da4 71 }
mbradley 1:63c505e13da4 72
mbradley 1:63c505e13da4 73 // Set the direction of HW LDACB
mbradley 1:63c505e13da4 74 if((gpio_direction_output(hw_ldacb_desc, GPIO_OUT)) == FAILURE) {
mbradley 1:63c505e13da4 75 return FAILURE;
mbradley 1:63c505e13da4 76 }
mbradley 1:63c505e13da4 77
mbradley 1:63c505e13da4 78 // Set the default output state of HW LDACB
mbradley 1:63c505e13da4 79 if((gpio_set_value(hw_ldacb_desc, GPIO_HIGH)) == FAILURE) {
mbradley 1:63c505e13da4 80 return FAILURE;
mbradley 1:63c505e13da4 81 }
mbradley 1:63c505e13da4 82
mbradley 1:63c505e13da4 83 return(ad5770r_init(&pAd5770r_dev, &ad5770r_user_param));
mbradley 1:63c505e13da4 84 }
mbradley 1:63c505e13da4 85
mbradley 1:63c505e13da4 86 // Private Functions
mbradley 1:63c505e13da4 87
mbradley 1:63c505e13da4 88 /**
mbradley 1:63c505e13da4 89 * Performs a software reset.
mbradley 1:63c505e13da4 90 * @param dev - The device structure.
mbradley 1:63c505e13da4 91 * @return SUCCESS in case of success, negative error code otherwise.
mbradley 1:63c505e13da4 92 */
mbradley 1:63c505e13da4 93 int32_t ad5770r_software_reset(struct ad5770r_dev *dev)
mbradley 1:63c505e13da4 94 {
mbradley 1:63c505e13da4 95 int32_t ret;
mbradley 1:63c505e13da4 96
mbradley 1:63c505e13da4 97 if (!dev)
mbradley 1:63c505e13da4 98 return FAILURE;
mbradley 1:63c505e13da4 99
mbradley 1:63c505e13da4 100 ret = ad5770r_spi_reg_write(dev,
mbradley 1:63c505e13da4 101 AD5770R_INTERFACE_CONFIG_A,
mbradley 1:63c505e13da4 102 AD5770R_INTERFACE_CONFIG_A_SW_RESET_MSK |
mbradley 1:63c505e13da4 103 AD5770R_INTERFACE_CONFIG_A_ADDR_ASCENSION_MSB(
mbradley 1:63c505e13da4 104 dev->dev_spi_settings.addr_ascension));
mbradley 1:63c505e13da4 105
mbradley 1:63c505e13da4 106 if (ret)
mbradley 1:63c505e13da4 107 return ret;
mbradley 1:63c505e13da4 108
mbradley 1:63c505e13da4 109 // Save the spi_desc pointer field
mbradley 1:63c505e13da4 110 spi_desc * spi_interface = dev->spi_desc;
mbradley 1:63c505e13da4 111 // Copy over the reset state of the device
mbradley 1:63c505e13da4 112 memcpy(dev, &ad5770r_dev_reset, sizeof(ad5770r_dev_reset));
mbradley 1:63c505e13da4 113 // Restore the spi_desc pointer field
mbradley 1:63c505e13da4 114 dev->spi_desc = spi_interface;
mbradley 1:63c505e13da4 115
mbradley 1:63c505e13da4 116 return ret;
mbradley 1:63c505e13da4 117 }
mbradley 1:63c505e13da4 118
mbradley 1:63c505e13da4 119 /*
mbradley 1:63c505e13da4 120 * @brief Sends a reset command on the SPI to reset the device
mbradley 1:63c505e13da4 121 *
mbradley 1:63c505e13da4 122 * @details
mbradley 1:63c505e13da4 123 */
mbradley 1:63c505e13da4 124 static int32_t do_software_reset(uint32_t id)
mbradley 1:63c505e13da4 125 {
mbradley 1:63c505e13da4 126 int32_t ret;
mbradley 1:63c505e13da4 127
mbradley 1:63c505e13da4 128 if ((ret = ad5770r_software_reset(pAd5770r_dev)) == SUCCESS) {
mbradley 1:63c505e13da4 129 printf(EOL " --- Software Reset Succeeded ---" EOL);
mbradley 1:63c505e13da4 130 } else {
mbradley 1:63c505e13da4 131 printf(EOL " *** Software Reset Failure: %d ***" EOL, ret);
mbradley 1:63c505e13da4 132 }
mbradley 1:63c505e13da4 133 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 134 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 135 }
mbradley 1:63c505e13da4 136
mbradley 1:63c505e13da4 137 /*
mbradley 1:63c505e13da4 138 * @brief Creates and initializes a device with user configuration
mbradley 1:63c505e13da4 139 *
mbradley 1:63c505e13da4 140 * @details
mbradley 1:63c505e13da4 141 */
mbradley 1:63c505e13da4 142 static int32_t do_device_init(uint32_t id)
mbradley 1:63c505e13da4 143 {
mbradley 1:63c505e13da4 144
mbradley 1:63c505e13da4 145 if (ad5770r_init(&pAd5770r_dev, &ad5770r_user_param) == SUCCESS) {
mbradley 1:63c505e13da4 146 } else {
mbradley 1:63c505e13da4 147 printf("\n\r *** Error device init ***\n\r");
mbradley 1:63c505e13da4 148 }
mbradley 1:63c505e13da4 149
mbradley 1:63c505e13da4 150 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 151 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 152 }
mbradley 1:63c505e13da4 153
mbradley 1:63c505e13da4 154 /*
mbradley 1:63c505e13da4 155 * @brief Removes the device from memory
mbradley 1:63c505e13da4 156 *
mbradley 1:63c505e13da4 157 * @details
mbradley 1:63c505e13da4 158 */
mbradley 1:63c505e13da4 159 static int32_t do_device_remove(uint32_t id)
mbradley 1:63c505e13da4 160 {
mbradley 3:8a6aa77aba73 161 if (ad5770r_remove(pAd5770r_dev) != SUCCESS) {
mbradley 1:63c505e13da4 162 printf("\n\r *** Error doing device remove ***\n\r");
mbradley 1:63c505e13da4 163 }
mbradley 1:63c505e13da4 164
mbradley 3:8a6aa77aba73 165 pAd5770r_dev = NULL;
mbradley 3:8a6aa77aba73 166
mbradley 1:63c505e13da4 167 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 168 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 169 }
mbradley 1:63c505e13da4 170
mbradley 1:63c505e13da4 171 /*!
mbradley 1:63c505e13da4 172 * @brief toggles the int/ext ref resistor option
mbradley 1:63c505e13da4 173 *
mbradley 1:63c505e13da4 174 * @details
mbradley 1:63c505e13da4 175 */
mbradley 1:63c505e13da4 176 static int32_t do_toggle_ref_resistor(uint32_t id)
mbradley 1:63c505e13da4 177 {
mbradley 1:63c505e13da4 178 int32_t status;
mbradley 1:63c505e13da4 179
mbradley 1:63c505e13da4 180 if ((status = ad5770r_set_reference(pAd5770r_dev,
mbradley 1:63c505e13da4 181 !pAd5770r_dev->external_reference,
mbradley 1:63c505e13da4 182 pAd5770r_dev->reference_selector)) != SUCCESS) {
mbradley 1:63c505e13da4 183 printf(EOL " *** Error toggling ref resistor setting: %d" EOL, status);
mbradley 1:63c505e13da4 184 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 185 }
mbradley 1:63c505e13da4 186
mbradley 1:63c505e13da4 187 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 188 }
mbradley 1:63c505e13da4 189
mbradley 1:63c505e13da4 190
mbradley 1:63c505e13da4 191 /*!
mbradley 1:63c505e13da4 192 * @brief sets the int/ext refer configuration options
mbradley 1:63c505e13da4 193 *
mbradley 1:63c505e13da4 194 * @details
mbradley 1:63c505e13da4 195 */
mbradley 1:63c505e13da4 196 static int32_t do_set_reference(uint32_t ref_option)
mbradley 1:63c505e13da4 197 {
mbradley 1:63c505e13da4 198 int32_t status;
mbradley 1:63c505e13da4 199
mbradley 1:63c505e13da4 200 if ((status = ad5770r_set_reference(pAd5770r_dev,
mbradley 1:63c505e13da4 201 pAd5770r_dev->external_reference,
mbradley 1:63c505e13da4 202 (enum ad5770r_reference_voltage)ref_option)) != SUCCESS) {
mbradley 1:63c505e13da4 203 printf(EOL " *** Error toggling ref resistor setting: %d" EOL, status);
mbradley 1:63c505e13da4 204 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 205 }
mbradley 1:63c505e13da4 206
mbradley 1:63c505e13da4 207 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 208 }
mbradley 1:63c505e13da4 209
mbradley 1:63c505e13da4 210 /*!
mbradley 1:63c505e13da4 211 * @brief Sets the Alarm Menu option bits
mbradley 1:63c505e13da4 212 *
mbradley 1:63c505e13da4 213 * @details
mbradley 1:63c505e13da4 214 */
mbradley 1:63c505e13da4 215 static int32_t do_set_alarm(uint32_t alarm_id)
mbradley 1:63c505e13da4 216 {
mbradley 1:63c505e13da4 217 int32_t status;
mbradley 1:63c505e13da4 218 struct ad5770r_alarm_cfg alarm_config;
mbradley 1:63c505e13da4 219
mbradley 1:63c505e13da4 220 alarm_config = pAd5770r_dev->alarm_config;
mbradley 1:63c505e13da4 221
mbradley 1:63c505e13da4 222 switch(alarm_id) {
mbradley 1:63c505e13da4 223 case AD5770R_ALARM_CONFIG_OPEN_DRAIN_EN(1):
mbradley 1:63c505e13da4 224 alarm_config.open_drain_en = !alarm_config.open_drain_en;
mbradley 1:63c505e13da4 225 break;
mbradley 1:63c505e13da4 226 case AD5770R_ALARM_CONFIG_THERMAL_SHUTDOWN_EN(1):
mbradley 1:63c505e13da4 227 alarm_config.thermal_shutdown_en = !alarm_config.thermal_shutdown_en;
mbradley 1:63c505e13da4 228 break;
mbradley 1:63c505e13da4 229 case AD5770R_ALARM_CONFIG_BACKGROUND_CRC_EN(1):
mbradley 1:63c505e13da4 230 alarm_config.background_crc_en = !alarm_config.background_crc_en;
mbradley 1:63c505e13da4 231 break;
mbradley 1:63c505e13da4 232 case AD5770R_ALARM_CONFIG_TEMP_WARNING_ALARM_MASK(1):
mbradley 1:63c505e13da4 233 alarm_config.temp_warning_msk = !alarm_config.temp_warning_msk;
mbradley 1:63c505e13da4 234 break;
mbradley 1:63c505e13da4 235 case AD5770R_ALARM_CONFIG_OVER_TEMP_ALARM_MASK(1):
mbradley 1:63c505e13da4 236 alarm_config.over_temp_msk = !alarm_config.over_temp_msk;
mbradley 1:63c505e13da4 237 break;
mbradley 1:63c505e13da4 238 case AD5770R_ALARM_CONFIG_NEGATIVE_CHANNEL0_ALARM_MASK(1):
mbradley 1:63c505e13da4 239 alarm_config.neg_ch0_msk = !alarm_config.neg_ch0_msk;
mbradley 1:63c505e13da4 240 break;
mbradley 1:63c505e13da4 241 case AD5770R_ALARM_CONFIG_IREF_FAULT_ALARM_MASK(1):
mbradley 1:63c505e13da4 242 alarm_config.iref_fault_msk = !alarm_config.iref_fault_msk;
mbradley 1:63c505e13da4 243 break;
mbradley 1:63c505e13da4 244 case AD5770R_ALARM_CONFIG_BACKGROUND_CRC_ALARM_MASK(1):
mbradley 1:63c505e13da4 245 alarm_config.background_crc_msk = !alarm_config.background_crc_msk;
mbradley 1:63c505e13da4 246 break;
mbradley 1:63c505e13da4 247 default:
mbradley 1:63c505e13da4 248 // not a supported menu option
mbradley 1:63c505e13da4 249 assert(false);
mbradley 1:63c505e13da4 250 }
mbradley 1:63c505e13da4 251
mbradley 1:63c505e13da4 252 if ((status = ad5770r_set_alarm(pAd5770r_dev,
mbradley 1:63c505e13da4 253 &alarm_config)) != SUCCESS) {
mbradley 1:63c505e13da4 254 printf(EOL " *** Error setting alarm config: %d" EOL, status);
mbradley 1:63c505e13da4 255 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 256 }
mbradley 1:63c505e13da4 257
mbradley 1:63c505e13da4 258 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 259 }
mbradley 1:63c505e13da4 260
mbradley 1:63c505e13da4 261 /*!
mbradley 1:63c505e13da4 262 * @brief Sets the Channel Configuration option bits
mbradley 1:63c505e13da4 263 *
mbradley 1:63c505e13da4 264 * @details
mbradley 1:63c505e13da4 265 */
mbradley 1:63c505e13da4 266 static void ch_switches_toggle(struct ad5770r_channel_switches *ch_switches,
mbradley 1:63c505e13da4 267 uint32_t channel_id)
mbradley 1:63c505e13da4 268 {
mbradley 1:63c505e13da4 269 switch(channel_id) {
mbradley 1:63c505e13da4 270 case AD5770R_CHANNEL_CONFIG_CH0_SHUTDOWN_B(1):
mbradley 1:63c505e13da4 271 ch_switches->en0 = !ch_switches->en0;
mbradley 1:63c505e13da4 272 break;
mbradley 1:63c505e13da4 273 case AD5770R_CHANNEL_CONFIG_CH1_SHUTDOWN_B(1):
mbradley 1:63c505e13da4 274 ch_switches->en1 = !ch_switches->en1;
mbradley 1:63c505e13da4 275 break;
mbradley 1:63c505e13da4 276 case AD5770R_CHANNEL_CONFIG_CH2_SHUTDOWN_B(1):
mbradley 1:63c505e13da4 277 ch_switches->en2 = !ch_switches->en2;
mbradley 1:63c505e13da4 278 break;
mbradley 1:63c505e13da4 279 case AD5770R_CHANNEL_CONFIG_CH3_SHUTDOWN_B(1):
mbradley 1:63c505e13da4 280 ch_switches->en3 = !ch_switches->en3;
mbradley 1:63c505e13da4 281 break;
mbradley 1:63c505e13da4 282 case AD5770R_CHANNEL_CONFIG_CH4_SHUTDOWN_B(1):
mbradley 1:63c505e13da4 283 ch_switches->en4 = !ch_switches->en4;
mbradley 1:63c505e13da4 284 break;
mbradley 1:63c505e13da4 285 case AD5770R_CHANNEL_CONFIG_CH5_SHUTDOWN_B(1):
mbradley 1:63c505e13da4 286 ch_switches->en5 = !ch_switches->en5;
mbradley 1:63c505e13da4 287 break;
mbradley 1:63c505e13da4 288 case AD5770R_CHANNEL_CONFIG_CH0_SINK_EN(1):
mbradley 1:63c505e13da4 289 ch_switches->sink0 = !ch_switches->sink0;
mbradley 1:63c505e13da4 290 break;
mbradley 1:63c505e13da4 291 default:
mbradley 1:63c505e13da4 292 // not a supported menu option
mbradley 1:63c505e13da4 293 assert(false);
mbradley 1:63c505e13da4 294 }
mbradley 1:63c505e13da4 295 }
mbradley 1:63c505e13da4 296
mbradley 1:63c505e13da4 297 /*!
mbradley 1:63c505e13da4 298 * @brief Sets the Channel Configuration option bits
mbradley 1:63c505e13da4 299 *
mbradley 1:63c505e13da4 300 * @details
mbradley 1:63c505e13da4 301 */
mbradley 1:63c505e13da4 302 static int32_t do_channel_config(uint32_t channel_id)
mbradley 1:63c505e13da4 303 {
mbradley 1:63c505e13da4 304 int32_t status;
mbradley 1:63c505e13da4 305 struct ad5770r_channel_switches channel_config;
mbradley 1:63c505e13da4 306
mbradley 1:63c505e13da4 307 channel_config = pAd5770r_dev->channel_config;
mbradley 1:63c505e13da4 308
mbradley 1:63c505e13da4 309 ch_switches_toggle(&channel_config, channel_id);
mbradley 1:63c505e13da4 310
mbradley 1:63c505e13da4 311 if ((status = ad5770r_channel_config(pAd5770r_dev,
mbradley 1:63c505e13da4 312 &channel_config)) != SUCCESS) {
mbradley 1:63c505e13da4 313 printf(EOL " *** Error setting channel config: %d" EOL, status);
mbradley 1:63c505e13da4 314 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 315 }
mbradley 1:63c505e13da4 316
mbradley 1:63c505e13da4 317 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 318 }
mbradley 1:63c505e13da4 319
mbradley 1:63c505e13da4 320 /*!
mbradley 1:63c505e13da4 321 * @brief prompts user for value to write to input register on channel
mbradley 1:63c505e13da4 322 *
mbradley 1:63c505e13da4 323 * @details
mbradley 1:63c505e13da4 324 */
mbradley 1:63c505e13da4 325 static int32_t do_input_value(uint32_t channel_id)
mbradley 1:63c505e13da4 326 {
mbradley 1:63c505e13da4 327 int32_t status;
mbradley 1:63c505e13da4 328 uint16_t value;
mbradley 1:63c505e13da4 329
mbradley 1:63c505e13da4 330 printf(EOL "Enter Input register value (hex) for channel %d: " EOL,
mbradley 1:63c505e13da4 331 channel_id);
mbradley 1:63c505e13da4 332 value = adi_get_hex_integer(4);
mbradley 1:63c505e13da4 333
mbradley 1:63c505e13da4 334 /* Channels are 14-bits, mask off top 2 bits*/
mbradley 1:63c505e13da4 335 value &= 0x3FFF;
mbradley 1:63c505e13da4 336
mbradley 1:63c505e13da4 337 if ((status =
mbradley 1:63c505e13da4 338 ad5770r_set_dac_input(pAd5770r_dev, value,
mbradley 1:63c505e13da4 339 (enum ad5770r_channels) channel_id)) != SUCCESS) {
mbradley 1:63c505e13da4 340 printf(EOL " *** Error writing DAC Input register: %d" EOL, status);
mbradley 1:63c505e13da4 341 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 342 }
mbradley 1:63c505e13da4 343
mbradley 1:63c505e13da4 344 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 345 }
mbradley 1:63c505e13da4 346
mbradley 1:63c505e13da4 347 /*!
mbradley 1:63c505e13da4 348 * @brief prompts user for value to write to input register on channel
mbradley 1:63c505e13da4 349 *
mbradley 1:63c505e13da4 350 * @details
mbradley 1:63c505e13da4 351 */
mbradley 1:63c505e13da4 352 static int32_t do_dac_value(uint32_t channel_id)
mbradley 1:63c505e13da4 353 {
mbradley 1:63c505e13da4 354 int32_t status;
mbradley 1:63c505e13da4 355 uint16_t value;
mbradley 1:63c505e13da4 356
mbradley 1:63c505e13da4 357 printf(EOL "Enter DAC register value (hex) for channel %d: " EOL, channel_id);
mbradley 1:63c505e13da4 358 value = adi_get_hex_integer(4);
mbradley 1:63c505e13da4 359
mbradley 1:63c505e13da4 360 /* Channels are 14-bits, mask off top 2 bits*/
mbradley 1:63c505e13da4 361 value &= 0x3FFF;
mbradley 1:63c505e13da4 362
mbradley 1:63c505e13da4 363 if ((status =
mbradley 1:63c505e13da4 364 ad5770r_set_dac_value(pAd5770r_dev, value,
mbradley 1:63c505e13da4 365 (enum ad5770r_channels) channel_id)) != SUCCESS) {
mbradley 1:63c505e13da4 366 printf(EOL " *** Error writing DAC value register: %d" EOL, status);
mbradley 1:63c505e13da4 367 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 368 }
mbradley 1:63c505e13da4 369
mbradley 1:63c505e13da4 370 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 371 }
mbradley 1:63c505e13da4 372
mbradley 1:63c505e13da4 373 /*!
mbradley 1:63c505e13da4 374 * @brief updating shadow SW LDAC, by toggling the channel bit
mbradley 1:63c505e13da4 375 *
mbradley 1:63c505e13da4 376 * @details
mbradley 1:63c505e13da4 377 */
mbradley 1:63c505e13da4 378 static int32_t do_sw_ldac(uint32_t channel_id)
mbradley 1:63c505e13da4 379 {
mbradley 1:63c505e13da4 380 ch_switches_toggle(&sw_ldac_shadow, channel_id);
mbradley 1:63c505e13da4 381
mbradley 1:63c505e13da4 382 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 383 }
mbradley 1:63c505e13da4 384
mbradley 1:63c505e13da4 385 /*!
mbradley 1:63c505e13da4 386 * @brief Writing SW LDAC to device
mbradley 1:63c505e13da4 387 *
mbradley 1:63c505e13da4 388 * @details
mbradley 1:63c505e13da4 389 */
mbradley 1:63c505e13da4 390 static int32_t do_sw_ldac_write(uint32_t id)
mbradley 1:63c505e13da4 391 {
mbradley 1:63c505e13da4 392 int32_t status;
mbradley 1:63c505e13da4 393
mbradley 1:63c505e13da4 394 if ((status = ad5770r_set_sw_ldac(pAd5770r_dev,
mbradley 1:63c505e13da4 395 &sw_ldac_shadow)) != SUCCESS) {
mbradley 1:63c505e13da4 396 printf(EOL " *** Error writing SW LDAC: %d" EOL, status);
mbradley 1:63c505e13da4 397 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 398 }
mbradley 1:63c505e13da4 399
mbradley 1:63c505e13da4 400 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 401 }
mbradley 1:63c505e13da4 402
mbradley 1:63c505e13da4 403 /*!
mbradley 1:63c505e13da4 404 * @brief Toggles HW LDAC
mbradley 1:63c505e13da4 405 *
mbradley 1:63c505e13da4 406 * @details This toggles the LDAC pin on the device, but is independent to the driver
mbradley 1:63c505e13da4 407 * Therefore this does not update dac_values from input values.
mbradley 1:63c505e13da4 408 */
mbradley 1:63c505e13da4 409 static int32_t do_hw_ldac_toggle(uint32_t id)
mbradley 1:63c505e13da4 410 {
mbradley 1:63c505e13da4 411 int32_t status;
mbradley 1:63c505e13da4 412
mbradley 1:63c505e13da4 413 do {
mbradley 1:63c505e13da4 414 if ((status = gpio_set_value(hw_ldacb_desc, GPIO_LOW)) == FAILURE) {
mbradley 1:63c505e13da4 415 break;
mbradley 1:63c505e13da4 416 }
mbradley 1:63c505e13da4 417 mdelay(1);
mbradley 1:63c505e13da4 418 if ((status = gpio_set_value(hw_ldacb_desc, GPIO_HIGH)) == FAILURE) {
mbradley 1:63c505e13da4 419 break;
mbradley 1:63c505e13da4 420 }
mbradley 1:63c505e13da4 421 } while (0);
mbradley 1:63c505e13da4 422
mbradley 1:63c505e13da4 423 if (status == SUCCESS) {
mbradley 1:63c505e13da4 424 printf(EOL " --- HW LDAC toggled ---" EOL);
mbradley 1:63c505e13da4 425 } else {
mbradley 1:63c505e13da4 426 printf(EOL " *** Error toggling HW LDACB ***" EOL);
mbradley 1:63c505e13da4 427 }
mbradley 1:63c505e13da4 428
mbradley 1:63c505e13da4 429
mbradley 1:63c505e13da4 430 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 431
mbradley 1:63c505e13da4 432 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 433 }
mbradley 1:63c505e13da4 434
mbradley 1:63c505e13da4 435 /*!
mbradley 1:63c505e13da4 436 * @brief displays general device configuration state
mbradley 1:63c505e13da4 437 *
mbradley 1:63c505e13da4 438 * @details
mbradley 1:63c505e13da4 439 */
mbradley 1:63c505e13da4 440 static void display_gen_config(void)
mbradley 1:63c505e13da4 441 {
mbradley 1:63c505e13da4 442 printf("\tRef Resistor: %s\t\tRef Voltage: %d" EOL,
mbradley 1:63c505e13da4 443 pAd5770r_dev->external_reference == true ? "External" : "Internal",
mbradley 1:63c505e13da4 444 pAd5770r_dev->reference_selector);
mbradley 1:63c505e13da4 445
mbradley 1:63c505e13da4 446 printf("\tAlarms\tBgCRC Msk: %d\tIRef: %d\tneg: %d\tOT: %d " EOL \
mbradley 1:63c505e13da4 447 "\t\tT Warn: %d\tBgCRC En: %d\tT Shdn: %d\tOD: %d" EOL,
mbradley 1:63c505e13da4 448 pAd5770r_dev->alarm_config.background_crc_msk,
mbradley 1:63c505e13da4 449 pAd5770r_dev->alarm_config.iref_fault_msk,
mbradley 1:63c505e13da4 450 pAd5770r_dev->alarm_config.neg_ch0_msk,
mbradley 1:63c505e13da4 451 pAd5770r_dev->alarm_config.over_temp_msk,
mbradley 1:63c505e13da4 452 pAd5770r_dev->alarm_config.temp_warning_msk,
mbradley 1:63c505e13da4 453 pAd5770r_dev->alarm_config.background_crc_en,
mbradley 1:63c505e13da4 454 pAd5770r_dev->alarm_config.thermal_shutdown_en,
mbradley 1:63c505e13da4 455 pAd5770r_dev->alarm_config.open_drain_en);
mbradley 1:63c505e13da4 456 }
mbradley 1:63c505e13da4 457
mbradley 1:63c505e13da4 458 /*!
mbradley 1:63c505e13da4 459 * @brief displays general device configuration state
mbradley 1:63c505e13da4 460 *
mbradley 1:63c505e13da4 461 * @details
mbradley 1:63c505e13da4 462 */
mbradley 1:63c505e13da4 463 static void print_channel_switches(struct ad5770r_channel_switches *ch_switches,
mbradley 1:63c505e13da4 464 char * prefix, bool include_sink)
mbradley 1:63c505e13da4 465 {
mbradley 1:63c505e13da4 466 if (include_sink) {
mbradley 1:63c505e13da4 467 printf("\t%s - en0: %d sink0: %d en1: %d en2: %d " \
mbradley 1:63c505e13da4 468 "en3: %d en4: %d en5: %d" EOL, prefix,
mbradley 1:63c505e13da4 469 ch_switches->en0, ch_switches->sink0, ch_switches->en1,
mbradley 1:63c505e13da4 470 ch_switches->en2, ch_switches->en3, ch_switches->en4,
mbradley 1:63c505e13da4 471 ch_switches->en5);
mbradley 1:63c505e13da4 472 } else {
mbradley 1:63c505e13da4 473 printf("\t%s - ch0: %d ch1: %d ch2: %d " \
mbradley 1:63c505e13da4 474 "ch3: %d ch4: %d ch5: %d" EOL, prefix,
mbradley 1:63c505e13da4 475 ch_switches->en0, ch_switches->en1, ch_switches->en2,
mbradley 1:63c505e13da4 476 ch_switches->en3, ch_switches->en4, ch_switches->en5);
mbradley 1:63c505e13da4 477 }
mbradley 1:63c505e13da4 478 }
mbradley 1:63c505e13da4 479
mbradley 1:63c505e13da4 480 /*!
mbradley 1:63c505e13da4 481 * @brief displays general device configuration state
mbradley 1:63c505e13da4 482 *
mbradley 1:63c505e13da4 483 * @details
mbradley 1:63c505e13da4 484 */
mbradley 1:63c505e13da4 485 static void display_dac_channel_configuration_header(void)
mbradley 1:63c505e13da4 486 {
mbradley 1:63c505e13da4 487 print_channel_switches(&pAd5770r_dev->channel_config, "Ch Configs", true);
mbradley 1:63c505e13da4 488 }
mbradley 1:63c505e13da4 489
mbradley 1:63c505e13da4 490 /*!
mbradley 1:63c505e13da4 491 * @brief displays the SW LDAC shadown and other channel output values
mbradley 1:63c505e13da4 492 *
mbradley 1:63c505e13da4 493 * @details
mbradley 1:63c505e13da4 494 */
mbradley 1:63c505e13da4 495 static void display_dac_operations_header(void)
mbradley 1:63c505e13da4 496 {
mbradley 1:63c505e13da4 497 for (uint8_t i = 0; i < 6 ; i++) {
mbradley 1:63c505e13da4 498 printf("\tCh %i - Input: 0x%04X \t\tDAC: 0x%04X" EOL, i,
mbradley 1:63c505e13da4 499 pAd5770r_dev->input_value[i], pAd5770r_dev->dac_value[i]);
mbradley 1:63c505e13da4 500 }
mbradley 1:63c505e13da4 501
mbradley 1:63c505e13da4 502 printf(EOL);
mbradley 1:63c505e13da4 503 print_channel_switches(&sw_ldac_shadow, "SW LDAC shadow", false);
mbradley 1:63c505e13da4 504 }
mbradley 1:63c505e13da4 505 /*!
mbradley 1:63c505e13da4 506 * @brief prints the provided monitor config to the terminal
mbradley 1:63c505e13da4 507 *
mbradley 1:63c505e13da4 508 * @details
mbradley 1:63c505e13da4 509 * @param ad5770R_monitor_config monitor_config - struct for the monitor config to be displayed
mbradley 1:63c505e13da4 510 * @return SUCCESS in case of success, negative error otherwise
mbradley 1:63c505e13da4 511 */
mbradley 1:63c505e13da4 512 static void print_monitor_setup(const struct ad5770r_monitor_setup * mon_setup)
mbradley 1:63c505e13da4 513 {
mbradley 1:63c505e13da4 514 printf("\tMonitor: ");
mbradley 1:63c505e13da4 515 switch (mon_setup->monitor_function) {
mbradley 1:63c505e13da4 516 case AD5770R_DISABLE: {
mbradley 1:63c505e13da4 517 printf("Disabled ");
mbradley 1:63c505e13da4 518 break;
mbradley 1:63c505e13da4 519 }
mbradley 1:63c505e13da4 520 case AD5770R_VOLTAGE_MONITORING: {
mbradley 1:63c505e13da4 521 printf("Voltage Ch %d", mon_setup->monitor_channel);
mbradley 1:63c505e13da4 522 break;
mbradley 1:63c505e13da4 523 }
mbradley 1:63c505e13da4 524 case AD5770R_CURRENT_MONITORING: {
mbradley 1:63c505e13da4 525 printf("Current Ch %d", mon_setup->monitor_channel);
mbradley 1:63c505e13da4 526 break;
mbradley 1:63c505e13da4 527 }
mbradley 1:63c505e13da4 528 case AD5770R_TEMPERATURE_MONITORING: {
mbradley 1:63c505e13da4 529 printf("Temperature");
mbradley 1:63c505e13da4 530 break;
mbradley 1:63c505e13da4 531 }
mbradley 1:63c505e13da4 532 }
mbradley 1:63c505e13da4 533
mbradley 1:63c505e13da4 534 printf("\tBuffer: ");
mbradley 1:63c505e13da4 535 if (mon_setup->mux_buffer == true) {
mbradley 1:63c505e13da4 536 printf("On");
mbradley 1:63c505e13da4 537 } else {
mbradley 1:63c505e13da4 538 printf("Off");
mbradley 1:63c505e13da4 539 }
mbradley 1:63c505e13da4 540
mbradley 1:63c505e13da4 541 printf("\tIB_Ext: ");
mbradley 1:63c505e13da4 542 if (mon_setup->ib_ext_en == true) {
mbradley 1:63c505e13da4 543 printf("On");
mbradley 1:63c505e13da4 544 } else {
mbradley 1:63c505e13da4 545 printf("Off");
mbradley 1:63c505e13da4 546 }
mbradley 1:63c505e13da4 547 printf(EOL);
mbradley 1:63c505e13da4 548 }
mbradley 1:63c505e13da4 549
mbradley 1:63c505e13da4 550 /*!
mbradley 1:63c505e13da4 551 * @brief configure the Mux Monitor setup
mbradley 1:63c505e13da4 552 *
mbradley 1:63c505e13da4 553 * @details
mbradley 1:63c505e13da4 554 */
mbradley 1:63c505e13da4 555 static void display_monitor_setup_header(void)
mbradley 1:63c505e13da4 556 {
mbradley 1:63c505e13da4 557 print_monitor_setup(&pAd5770r_dev->mon_setup);
mbradley 1:63c505e13da4 558 }
mbradley 1:63c505e13da4 559
mbradley 1:63c505e13da4 560 /*!
mbradley 1:63c505e13da4 561 * @brief configure the Mux Monitor setup
mbradley 1:63c505e13da4 562 *
mbradley 1:63c505e13da4 563 * @details
mbradley 1:63c505e13da4 564 */
mbradley 1:63c505e13da4 565 static int32_t do_monitor_setup(uint32_t id)
mbradley 1:63c505e13da4 566 {
mbradley 1:63c505e13da4 567 int32_t status;
mbradley 1:63c505e13da4 568 struct ad5770r_monitor_setup monitor_setup;
mbradley 1:63c505e13da4 569
mbradley 1:63c505e13da4 570 monitor_setup = pAd5770r_dev->mon_setup;
mbradley 1:63c505e13da4 571
mbradley 1:63c505e13da4 572 switch(id) {
mbradley 1:63c505e13da4 573 case AD5770R_DISABLE:
mbradley 1:63c505e13da4 574 monitor_setup.monitor_function = AD5770R_DISABLE;
mbradley 1:63c505e13da4 575 break;
mbradley 1:63c505e13da4 576 case AD5770R_VOLTAGE_MONITORING:
mbradley 1:63c505e13da4 577 monitor_setup.monitor_function = AD5770R_VOLTAGE_MONITORING;
mbradley 1:63c505e13da4 578 break;
mbradley 1:63c505e13da4 579 case AD5770R_CURRENT_MONITORING:
mbradley 1:63c505e13da4 580 monitor_setup.monitor_function = AD5770R_CURRENT_MONITORING;
mbradley 1:63c505e13da4 581 break;
mbradley 1:63c505e13da4 582 case AD5770R_TEMPERATURE_MONITORING:
mbradley 1:63c505e13da4 583 monitor_setup.monitor_function = AD5770R_TEMPERATURE_MONITORING;
mbradley 1:63c505e13da4 584 break;
mbradley 1:63c505e13da4 585 case TOGGLE_MUX_BUFFER:
mbradley 1:63c505e13da4 586 monitor_setup.mux_buffer = !monitor_setup.mux_buffer;
mbradley 1:63c505e13da4 587 break;
mbradley 1:63c505e13da4 588 case TOGGLE_DIODE_EXT_BIAS:
mbradley 1:63c505e13da4 589 monitor_setup.ib_ext_en = !monitor_setup.ib_ext_en;
mbradley 1:63c505e13da4 590 break;
mbradley 1:63c505e13da4 591 default:
mbradley 1:63c505e13da4 592 // ensure the id is valid.
mbradley 1:63c505e13da4 593 assert(( id >= AD5770R_CH0 + MENU_CHANNEL_OFFSET )
mbradley 1:63c505e13da4 594 && (id <= AD5770R_CH5 + MENU_CHANNEL_OFFSET));
mbradley 1:63c505e13da4 595 monitor_setup.monitor_channel = (enum ad5770r_channels)(
mbradley 1:63c505e13da4 596 id - MENU_CHANNEL_OFFSET);
mbradley 1:63c505e13da4 597 }
mbradley 1:63c505e13da4 598
mbradley 1:63c505e13da4 599 if ((status = ad5770r_set_monitor_setup(pAd5770r_dev,
mbradley 1:63c505e13da4 600 &monitor_setup)) != SUCCESS) {
mbradley 1:63c505e13da4 601 printf(EOL " *** Error setting monitor setup: %d" EOL, status);
mbradley 1:63c505e13da4 602 adi_press_any_key_to_continue();
mbradley 1:63c505e13da4 603 }
mbradley 1:63c505e13da4 604
mbradley 1:63c505e13da4 605 return(MENU_CONTINUE);
mbradley 1:63c505e13da4 606 }
mbradley 1:63c505e13da4 607
mbradley 1:63c505e13da4 608 /*!
mbradley 1:63c505e13da4 609 * @brief displays several pieces of status information above main menu
mbradley 1:63c505e13da4 610 *
mbradley 1:63c505e13da4 611 * @details
mbradley 1:63c505e13da4 612 */
mbradley 1:63c505e13da4 613 static void display_main_menu_header(void)
mbradley 1:63c505e13da4 614 {
mbradley 1:63c505e13da4 615 int32_t ret;
mbradley 1:63c505e13da4 616 uint8_t device_status = 0, interface_status = 0, scratchpad = 0;
mbradley 1:63c505e13da4 617
mbradley 1:63c505e13da4 618 if (pAd5770r_dev == NULL) {
mbradley 1:63c505e13da4 619 printf(EOL " *** Device Not Initialized ***" EOL);
mbradley 1:63c505e13da4 620 return;
mbradley 1:63c505e13da4 621 }
mbradley 1:63c505e13da4 622
mbradley 1:63c505e13da4 623 do {
mbradley 1:63c505e13da4 624 if ((ret = ad5770r_get_status(pAd5770r_dev, &device_status)) != SUCCESS) {
mbradley 1:63c505e13da4 625 break;
mbradley 1:63c505e13da4 626 }
mbradley 1:63c505e13da4 627 if ((ret = ad5770r_get_interface_status(pAd5770r_dev,
mbradley 1:63c505e13da4 628 &interface_status)) != SUCCESS) {
mbradley 1:63c505e13da4 629 break;
mbradley 1:63c505e13da4 630 }
mbradley 1:63c505e13da4 631 if ((ret = ad5770r_spi_reg_read(pAd5770r_dev, AD5770R_SCRATCH_PAD,
mbradley 1:63c505e13da4 632 &scratchpad)) != SUCCESS) {
mbradley 1:63c505e13da4 633 break;
mbradley 1:63c505e13da4 634 }
mbradley 1:63c505e13da4 635
mbradley 1:63c505e13da4 636 } while(0);
mbradley 1:63c505e13da4 637
mbradley 1:63c505e13da4 638 if (ret != SUCCESS) {
mbradley 1:63c505e13da4 639 printf(EOL " *** Error in display state: %d **" EOL, ret);
mbradley 1:63c505e13da4 640 }
mbradley 1:63c505e13da4 641
mbradley 1:63c505e13da4 642 printf(EOL "\tInterface Status = 0x%02X\t\tDevice Status = 0x%02X"
mbradley 1:63c505e13da4 643 EOL "\tScratchpad = 0x%02X" EOL,
mbradley 1:63c505e13da4 644 interface_status, device_status, scratchpad);
mbradley 1:63c505e13da4 645 print_monitor_setup(&pAd5770r_dev->mon_setup);
mbradley 1:63c505e13da4 646
mbradley 1:63c505e13da4 647 // Increment the scratchpad by 1 to show a +1 delta in footer
mbradley 1:63c505e13da4 648 if((ret = ad5770r_spi_reg_write(pAd5770r_dev, AD5770R_SCRATCH_PAD,
mbradley 1:63c505e13da4 649 scratchpad + 1)) != SUCCESS) {
mbradley 1:63c505e13da4 650 printf(EOL " *** Error writing scratchpad + 1 : %d **" EOL, ret);
mbradley 1:63c505e13da4 651 }
mbradley 1:63c505e13da4 652 }
mbradley 1:63c505e13da4 653
mbradley 1:63c505e13da4 654 /*!
mbradley 1:63c505e13da4 655 * @brief displays several pieces of status information below main menu
mbradley 1:63c505e13da4 656 *
mbradley 1:63c505e13da4 657 * @details
mbradley 1:63c505e13da4 658 */
mbradley 1:63c505e13da4 659 static void display_main_menu_footer(void)
mbradley 1:63c505e13da4 660 {
mbradley 1:63c505e13da4 661 int32_t ret;
mbradley 1:63c505e13da4 662 uint8_t scratchpad;
mbradley 1:63c505e13da4 663
mbradley 1:63c505e13da4 664 if (pAd5770r_dev == NULL) {
mbradley 1:63c505e13da4 665 printf(EOL " *** Device Not Initialized ***" EOL);
mbradley 1:63c505e13da4 666 return;
mbradley 1:63c505e13da4 667 }
mbradley 1:63c505e13da4 668
mbradley 1:63c505e13da4 669 if ((ret = ad5770r_spi_reg_read(pAd5770r_dev, AD5770R_SCRATCH_PAD,
mbradley 1:63c505e13da4 670 &scratchpad)) != SUCCESS) {
mbradley 1:63c505e13da4 671 printf(EOL " *** Error reading scratchpad: %d **" EOL, ret);
mbradley 1:63c505e13da4 672 }
mbradley 1:63c505e13da4 673
mbradley 1:63c505e13da4 674 printf(EOL "\tScratchpad = 0x%02X" EOL, scratchpad);
mbradley 1:63c505e13da4 675 }
mbradley 1:63c505e13da4 676
mbradley 1:63c505e13da4 677 /*!
mbradley 1:63c505e13da4 678 * @brief calls the general configuration menu
mbradley 1:63c505e13da4 679 */
mbradley 1:63c505e13da4 680 static int32_t do_general_configuration_menu(uint32_t id)
mbradley 1:63c505e13da4 681 {
mbradley 1:63c505e13da4 682 return adi_do_console_menu(&general_configuration_menu);
mbradley 1:63c505e13da4 683 }
mbradley 1:63c505e13da4 684
mbradley 1:63c505e13da4 685 /*!
mbradley 1:63c505e13da4 686 * @brief calls the monitor setup menu
mbradley 1:63c505e13da4 687 */
mbradley 1:63c505e13da4 688 static int32_t do_monitor_setup_menu(uint32_t id)
mbradley 1:63c505e13da4 689 {
mbradley 1:63c505e13da4 690 return adi_do_console_menu(&monitor_setup_menu);
mbradley 1:63c505e13da4 691 }
mbradley 1:63c505e13da4 692
mbradley 1:63c505e13da4 693 /*!
mbradley 1:63c505e13da4 694 * @brief calls the DAC channel confguration menu
mbradley 1:63c505e13da4 695 */
mbradley 1:63c505e13da4 696 static int32_t do_dac_channel_configuration_menu(uint32_t id)
mbradley 1:63c505e13da4 697 {
mbradley 1:63c505e13da4 698 return adi_do_console_menu(&dac_channel_configuration_menu);
mbradley 1:63c505e13da4 699 }
mbradley 1:63c505e13da4 700
mbradley 1:63c505e13da4 701 /*!
mbradley 1:63c505e13da4 702 * @brief calls the DAC channel confguration menu
mbradley 1:63c505e13da4 703 */
mbradley 1:63c505e13da4 704 static int32_t do_dac_operations_menu(uint32_t id)
mbradley 1:63c505e13da4 705 {
mbradley 1:63c505e13da4 706 return adi_do_console_menu(&dac_operations_menu);
mbradley 1:63c505e13da4 707 }
mbradley 1:63c505e13da4 708
mbradley 1:63c505e13da4 709 /*
mbradley 1:63c505e13da4 710 * DAC Operations Menu
mbradley 1:63c505e13da4 711 */
mbradley 1:63c505e13da4 712 static console_menu_item dac_operations_menu_items[] = {
mbradley 1:63c505e13da4 713 {"\tSet Input Channel 0", 'Q', do_input_value, 0},
mbradley 1:63c505e13da4 714 {"\tSet Input Channel 1", 'W', do_input_value, 1},
mbradley 1:63c505e13da4 715 {"\tSet Input Channel 2", 'E', do_input_value, 2},
mbradley 1:63c505e13da4 716 {"\tSet Input Channel 3", 'R', do_input_value, 3},
mbradley 1:63c505e13da4 717 {"\tSet Input Channel 4", 'T', do_input_value, 4},
mbradley 1:63c505e13da4 718 {"\tSet Input Channel 5", 'Y', do_input_value, 5},
mbradley 1:63c505e13da4 719 {""},
mbradley 1:63c505e13da4 720 {"\tToggle Channel 0 SW LDAC Shadow", '0', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 0)},
mbradley 1:63c505e13da4 721 {"\tToggle Channel 1 SW LDAC Shadow", '1', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 1)},
mbradley 1:63c505e13da4 722 {"\tToggle Channel 2 SW LDAC Shadow", '2', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 2)},
mbradley 1:63c505e13da4 723 {"\tToggle Channel 3 SW LDAC Shadow", '3', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 3)},
mbradley 1:63c505e13da4 724 {"\tToggle Channel 4 SW LDAC Shadow", '4', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 4)},
mbradley 1:63c505e13da4 725 {"\tToggle Channel 5 SW LDAC Shadow", '5', do_sw_ldac, AD5770R_HW_LDAC_MASK_CH(1, 5)},
mbradley 1:63c505e13da4 726 {"\tWrite SW LDAC Shadow ", 'U', do_sw_ldac_write},
mbradley 1:63c505e13da4 727 {""},
mbradley 1:63c505e13da4 728 {"\tToggle HW LDAC digital input", 'J', do_hw_ldac_toggle},
mbradley 1:63c505e13da4 729 {""},
mbradley 1:63c505e13da4 730 {"\tSet DAC Channel 0", 'A', do_dac_value, 0},
mbradley 1:63c505e13da4 731 {"\tSet DAC Channel 1", 'S', do_dac_value, 1},
mbradley 1:63c505e13da4 732 {"\tSet DAC Channel 2", 'D', do_dac_value, 2},
mbradley 1:63c505e13da4 733 {"\tSet DAC Channel 3", 'F', do_dac_value, 3},
mbradley 1:63c505e13da4 734 {"\tSet DAC Channel 4", 'G', do_dac_value, 4},
mbradley 1:63c505e13da4 735 {"\tSet DAC Channel 5", 'H', do_dac_value, 5},
mbradley 1:63c505e13da4 736 };
mbradley 1:63c505e13da4 737
mbradley 1:63c505e13da4 738 static console_menu dac_operations_menu = {
mbradley 1:63c505e13da4 739 .title = "DAC Operations",
mbradley 1:63c505e13da4 740 .items = dac_operations_menu_items,
mbradley 1:63c505e13da4 741 .itemCount = ARRAY_SIZE(dac_operations_menu_items),
mbradley 1:63c505e13da4 742 .headerItem = display_dac_operations_header,
mbradley 1:63c505e13da4 743 .footerItem = NULL,
mbradley 1:63c505e13da4 744 .enableEscapeKey = true
mbradley 1:63c505e13da4 745 };
mbradley 1:63c505e13da4 746
mbradley 1:63c505e13da4 747 /*
mbradley 1:63c505e13da4 748 * Monitor Setup Menu
mbradley 1:63c505e13da4 749 */
mbradley 1:63c505e13da4 750 static console_menu_item dac_channel_configuration_menu_items[] = {
mbradley 1:63c505e13da4 751 {"\tToggle Channel 0 Enable", '0', do_channel_config, AD5770R_CHANNEL_CONFIG_CH0_SHUTDOWN_B(1)},
mbradley 1:63c505e13da4 752 {"\tToggle Channel 0 Sink Enable", 'S', do_channel_config, AD5770R_CHANNEL_CONFIG_CH0_SINK_EN(1)},
mbradley 1:63c505e13da4 753 {"\tToggle Channel 1 Enable", '1', do_channel_config, AD5770R_CHANNEL_CONFIG_CH1_SHUTDOWN_B(1)},
mbradley 1:63c505e13da4 754 {"\tToggle Channel 2 Enable", '2', do_channel_config, AD5770R_CHANNEL_CONFIG_CH2_SHUTDOWN_B(1)},
mbradley 1:63c505e13da4 755 {"\tToggle Channel 3 Enable", '3', do_channel_config, AD5770R_CHANNEL_CONFIG_CH3_SHUTDOWN_B(1)},
mbradley 1:63c505e13da4 756 {"\tToggle Channel 4 Enable", '4', do_channel_config, AD5770R_CHANNEL_CONFIG_CH4_SHUTDOWN_B(1)},
mbradley 1:63c505e13da4 757 {"\tToggle Channel 5 Enable", '5', do_channel_config, AD5770R_CHANNEL_CONFIG_CH5_SHUTDOWN_B(1)}
mbradley 1:63c505e13da4 758 };
mbradley 1:63c505e13da4 759
mbradley 1:63c505e13da4 760 static console_menu dac_channel_configuration_menu = {
mbradley 1:63c505e13da4 761 .title = "DAC Channel Configuration",
mbradley 1:63c505e13da4 762 .items = dac_channel_configuration_menu_items,
mbradley 1:63c505e13da4 763 .itemCount = ARRAY_SIZE(dac_channel_configuration_menu_items),
mbradley 1:63c505e13da4 764 .headerItem = display_dac_channel_configuration_header,
mbradley 1:63c505e13da4 765 .footerItem = NULL,
mbradley 1:63c505e13da4 766 .enableEscapeKey = true
mbradley 1:63c505e13da4 767 };
mbradley 1:63c505e13da4 768
mbradley 1:63c505e13da4 769 /*
mbradley 1:63c505e13da4 770 * Monitor Setup Menu
mbradley 1:63c505e13da4 771 */
mbradley 1:63c505e13da4 772 static console_menu_item monitor_setup_menu_items[] = {
mbradley 1:63c505e13da4 773 {"Disable Monitoring", 'Q', do_monitor_setup, AD5770R_DISABLE},
mbradley 1:63c505e13da4 774 {"Enable Voltage Monitoring", 'W', do_monitor_setup, AD5770R_VOLTAGE_MONITORING},
mbradley 1:63c505e13da4 775 {"Enable Current Monitoring", 'E', do_monitor_setup, AD5770R_CURRENT_MONITORING},
mbradley 1:63c505e13da4 776 {"Enable Temperature Monitoring", 'R', do_monitor_setup, AD5770R_TEMPERATURE_MONITORING},
mbradley 1:63c505e13da4 777 {"", '\00', NULL},
mbradley 1:63c505e13da4 778 {"Toggle Mux Buffer", 'M', do_monitor_setup, TOGGLE_MUX_BUFFER},
mbradley 1:63c505e13da4 779 {"Toggle Diode External Bias", 'X', do_monitor_setup, TOGGLE_DIODE_EXT_BIAS},
mbradley 1:63c505e13da4 780 {"", '\00', NULL},
mbradley 1:63c505e13da4 781 {"\tSelect Channel 0", '0', do_monitor_setup, AD5770R_CH0 + MENU_CHANNEL_OFFSET},
mbradley 1:63c505e13da4 782 {"\tSelect Channel 1", '1', do_monitor_setup, AD5770R_CH1 + MENU_CHANNEL_OFFSET},
mbradley 1:63c505e13da4 783 {"\tSelect Channel 2", '2', do_monitor_setup, AD5770R_CH2 + MENU_CHANNEL_OFFSET},
mbradley 1:63c505e13da4 784 {"\tSelect Channel 3", '3', do_monitor_setup, AD5770R_CH3 + MENU_CHANNEL_OFFSET},
mbradley 1:63c505e13da4 785 {"\tSelect Channel 4", '4', do_monitor_setup, AD5770R_CH4 + MENU_CHANNEL_OFFSET},
mbradley 1:63c505e13da4 786 {"\tSelect Channel 5", '5', do_monitor_setup, AD5770R_CH5 + MENU_CHANNEL_OFFSET},
mbradley 1:63c505e13da4 787 };
mbradley 1:63c505e13da4 788
mbradley 1:63c505e13da4 789 static console_menu monitor_setup_menu = {
mbradley 1:63c505e13da4 790 .title = "Monitor Setup",
mbradley 1:63c505e13da4 791 .items = monitor_setup_menu_items,
mbradley 1:63c505e13da4 792 .itemCount = ARRAY_SIZE(monitor_setup_menu_items),
mbradley 1:63c505e13da4 793 .headerItem = display_monitor_setup_header,
mbradley 1:63c505e13da4 794 .footerItem = NULL,
mbradley 1:63c505e13da4 795 .enableEscapeKey = true
mbradley 1:63c505e13da4 796 };
mbradley 1:63c505e13da4 797
mbradley 1:63c505e13da4 798 /*
mbradley 1:63c505e13da4 799 * General Configuration Menu
mbradley 1:63c505e13da4 800 */
mbradley 1:63c505e13da4 801 static console_menu_item general_configuration_menu_items[] = {
mbradley 1:63c505e13da4 802 {"Select Int/External Reference Resistor", 'R', do_toggle_ref_resistor},
mbradley 1:63c505e13da4 803 {""},
mbradley 1:63c505e13da4 804 {"Set Ext 2.50V Reference", 'A', do_set_reference, AD5770R_EXT_REF_2_5_V},
mbradley 1:63c505e13da4 805 {"Set Int 1.25V Reference, Vout: ON", 'S', do_set_reference, AD5770R_INT_REF_1_25_V_OUT_ON},
mbradley 1:63c505e13da4 806 {"Set Ext 1.25V Reference", 'D', do_set_reference, AD5770R_EXT_REF_1_25_V},
mbradley 1:63c505e13da4 807 {"Set Int 1.25V Reference, Vout: OFF", 'F', do_set_reference, AD5770R_INT_REF_1_25_V_OUT_OFF},
mbradley 1:63c505e13da4 808 {""},
mbradley 1:63c505e13da4 809 {" --Toggle Alarm Configuration bits --"},
mbradley 1:63c505e13da4 810 {"\tOpen Drain Enable", '0', do_set_alarm, AD5770R_ALARM_CONFIG_OPEN_DRAIN_EN(1)},
mbradley 1:63c505e13da4 811 {"\tThermal Shutdown Enable", '1', do_set_alarm, AD5770R_ALARM_CONFIG_THERMAL_SHUTDOWN_EN(1)},
mbradley 1:63c505e13da4 812 {"\tBackground CRC Enable", '2', do_set_alarm, AD5770R_ALARM_CONFIG_BACKGROUND_CRC_EN(1)},
mbradley 1:63c505e13da4 813 {"\tTemperature Warning Alarm Mask", '3', do_set_alarm, AD5770R_ALARM_CONFIG_TEMP_WARNING_ALARM_MASK(1)},
mbradley 1:63c505e13da4 814 {"\tOver Temperature Alarm Mask", '4', do_set_alarm, AD5770R_ALARM_CONFIG_OVER_TEMP_ALARM_MASK(1)},
mbradley 1:63c505e13da4 815 {"\tNegative Channel 0 Mask", '5', do_set_alarm, AD5770R_ALARM_CONFIG_NEGATIVE_CHANNEL0_ALARM_MASK(1)},
mbradley 1:63c505e13da4 816 {"\tIREF Fault Alarm Mask", '6', do_set_alarm, AD5770R_ALARM_CONFIG_IREF_FAULT_ALARM_MASK(1)},
mbradley 1:63c505e13da4 817 {"\tBackground CRC Alarm Mask", '7', do_set_alarm, AD5770R_ALARM_CONFIG_BACKGROUND_CRC_ALARM_MASK(1)},
mbradley 1:63c505e13da4 818 };
mbradley 1:63c505e13da4 819
mbradley 1:63c505e13da4 820 static console_menu general_configuration_menu = {
mbradley 1:63c505e13da4 821 .title = "General Configuration",
mbradley 1:63c505e13da4 822 .items = general_configuration_menu_items,
mbradley 1:63c505e13da4 823 .itemCount = ARRAY_SIZE(general_configuration_menu_items),
mbradley 1:63c505e13da4 824 .headerItem = display_gen_config,
mbradley 1:63c505e13da4 825 .footerItem = NULL,
mbradley 1:63c505e13da4 826 .enableEscapeKey = true
mbradley 1:63c505e13da4 827 };
mbradley 1:63c505e13da4 828
mbradley 1:63c505e13da4 829 /*
mbradley 1:63c505e13da4 830 * Definition of the Main Menu Items and menu itself
mbradley 1:63c505e13da4 831 */
mbradley 1:63c505e13da4 832 static console_menu_item main_menu_items[] = {
mbradley 1:63c505e13da4 833 {"Initialize Device to User Configuration", 'I', do_device_init},
mbradley 1:63c505e13da4 834 {"Remove Device", 'X', do_device_remove},
mbradley 1:63c505e13da4 835 {""},
mbradley 1:63c505e13da4 836 {"Do Software Reset", 'R', do_software_reset},
mbradley 1:63c505e13da4 837 {""},
mbradley 1:63c505e13da4 838 {"General Configuration...", 'G', do_general_configuration_menu},
mbradley 1:63c505e13da4 839 {"Monitor Setup...", 'M', do_monitor_setup_menu},
mbradley 1:63c505e13da4 840 {""},
mbradley 1:63c505e13da4 841 {"DAC Channel Configuration...", 'C', do_dac_channel_configuration_menu},
mbradley 1:63c505e13da4 842 {"DAC Operations...", 'D', do_dac_operations_menu},
mbradley 1:63c505e13da4 843 };
mbradley 1:63c505e13da4 844
mbradley 1:63c505e13da4 845 console_menu ad5770r_main_menu = {
mbradley 1:63c505e13da4 846 #if ACTIVE_DEVICE==GENERIC_AD5770R
mbradley 1:63c505e13da4 847 .title = "AD5770R Console App",
mbradley 1:63c505e13da4 848 #elif ACTIVE_DEVICE==GENERIC_AD5772R
mbradley 1:63c505e13da4 849 .title = "AD5772R Terminal App",
mbradley 1:63c505e13da4 850 #else
mbradley 1:63c505e13da4 851 #error "Unsupported device"
mbradley 1:63c505e13da4 852 #endif
mbradley 1:63c505e13da4 853 .items = main_menu_items,
mbradley 1:63c505e13da4 854 .itemCount = ARRAY_SIZE(main_menu_items),
mbradley 1:63c505e13da4 855 .headerItem = display_main_menu_header,
mbradley 1:63c505e13da4 856 .footerItem = display_main_menu_footer,
mbradley 1:63c505e13da4 857 .enableEscapeKey = false
mbradley 1:63c505e13da4 858 };