Pratyush Mallick
/
nano_dac
this is testing
app/nanodac_console_app.c@0:e8a1ba50c46b, 2021-01-14 (annotated)
- Committer:
- pmallick
- Date:
- Thu Jan 14 19:12:57 2021 +0530
- Revision:
- 0:e8a1ba50c46b
this is testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmallick | 0:e8a1ba50c46b | 1 | /*! |
pmallick | 0:e8a1ba50c46b | 2 | ***************************************************************************** |
pmallick | 0:e8a1ba50c46b | 3 | @file: nanodac_console_app.c |
pmallick | 0:e8a1ba50c46b | 4 | |
pmallick | 0:e8a1ba50c46b | 5 | @brief: Implementation for the menu functions that handles the nanodac |
pmallick | 0:e8a1ba50c46b | 6 | functionality |
pmallick | 0:e8a1ba50c46b | 7 | |
pmallick | 0:e8a1ba50c46b | 8 | @details: This file is specific to nanodac console menu application handle. |
pmallick | 0:e8a1ba50c46b | 9 | The functions defined in this file performs the action |
pmallick | 0:e8a1ba50c46b | 10 | based on user selected console menu. |
pmallick | 0:e8a1ba50c46b | 11 | ----------------------------------------------------------------------------- |
pmallick | 0:e8a1ba50c46b | 12 | Copyright (c) 2020 Analog Devices, Inc. |
pmallick | 0:e8a1ba50c46b | 13 | All rights reserved. |
pmallick | 0:e8a1ba50c46b | 14 | |
pmallick | 0:e8a1ba50c46b | 15 | This software is proprietary to Analog Devices, Inc. and its licensors. |
pmallick | 0:e8a1ba50c46b | 16 | By using this software you agree to the terms of the associated |
pmallick | 0:e8a1ba50c46b | 17 | Analog Devices Software License Agreement. |
pmallick | 0:e8a1ba50c46b | 18 | *****************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 19 | |
pmallick | 0:e8a1ba50c46b | 20 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 21 | /***************************** Include Files **********************************/ |
pmallick | 0:e8a1ba50c46b | 22 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 23 | |
pmallick | 0:e8a1ba50c46b | 24 | #include <stdio.h> |
pmallick | 0:e8a1ba50c46b | 25 | #include <string.h> |
pmallick | 0:e8a1ba50c46b | 26 | #include <stdbool.h> |
pmallick | 0:e8a1ba50c46b | 27 | |
pmallick | 0:e8a1ba50c46b | 28 | #include "app_config.h" |
pmallick | 0:e8a1ba50c46b | 29 | |
pmallick | 0:e8a1ba50c46b | 30 | #include "ad5686.h" |
pmallick | 0:e8a1ba50c46b | 31 | #include "platform_support.h" |
pmallick | 0:e8a1ba50c46b | 32 | #include "platform_drivers.h" |
pmallick | 0:e8a1ba50c46b | 33 | #include "i2c_extra.h" |
pmallick | 0:e8a1ba50c46b | 34 | #include "spi_extra.h" |
pmallick | 0:e8a1ba50c46b | 35 | |
pmallick | 0:e8a1ba50c46b | 36 | #include "nanodac_console_app.h" |
pmallick | 0:e8a1ba50c46b | 37 | |
pmallick | 0:e8a1ba50c46b | 38 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 39 | /********************** Macros and Constants Definitions **********************/ |
pmallick | 0:e8a1ba50c46b | 40 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 41 | |
pmallick | 0:e8a1ba50c46b | 42 | #if !defined(I2C_SLAVE_ADDRESS) |
pmallick | 0:e8a1ba50c46b | 43 | #define I2C_SLAVE_ADDRESS 0 // For non I2C devices |
pmallick | 0:e8a1ba50c46b | 44 | #endif |
pmallick | 0:e8a1ba50c46b | 45 | |
pmallick | 0:e8a1ba50c46b | 46 | #define INTERNAL_VREF_VOLTAGE 2.5 |
pmallick | 0:e8a1ba50c46b | 47 | #define INTERNAL_VREF_SOURCE 0U |
pmallick | 0:e8a1ba50c46b | 48 | #define EXTERNAL_VREF_SOURCE 1U |
pmallick | 0:e8a1ba50c46b | 49 | |
pmallick | 0:e8a1ba50c46b | 50 | #define GAIN_LOW 1 |
pmallick | 0:e8a1ba50c46b | 51 | #define GAIN_HIGH 2 |
pmallick | 0:e8a1ba50c46b | 52 | |
pmallick | 0:e8a1ba50c46b | 53 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 54 | /********************** Variables and User Defined Data Types *****************/ |
pmallick | 0:e8a1ba50c46b | 55 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 56 | |
pmallick | 0:e8a1ba50c46b | 57 | // Pointer to a nanodac device structure |
pmallick | 0:e8a1ba50c46b | 58 | static struct ad5686_dev *nanodac_dev = NULL; |
pmallick | 0:e8a1ba50c46b | 59 | |
pmallick | 0:e8a1ba50c46b | 60 | // Current DAC channel (default value is channel 0) |
pmallick | 0:e8a1ba50c46b | 61 | static enum ad5686_dac_channels current_dac_channel = AD5686_CH_0; |
pmallick | 0:e8a1ba50c46b | 62 | |
pmallick | 0:e8a1ba50c46b | 63 | // Define the Vref source and voltage |
pmallick | 0:e8a1ba50c46b | 64 | #if !defined(EXT_VREF_SOURCE_ONLY) |
pmallick | 0:e8a1ba50c46b | 65 | // Default Vref voltage is 2.5v for internal reference source |
pmallick | 0:e8a1ba50c46b | 66 | static uint32_t vref_source = INTERNAL_VREF_SOURCE; |
pmallick | 0:e8a1ba50c46b | 67 | static float vref_voltage = INTERNAL_VREF_VOLTAGE; |
pmallick | 0:e8a1ba50c46b | 68 | #else |
pmallick | 0:e8a1ba50c46b | 69 | // Vref voltage for external reference source is user selectable |
pmallick | 0:e8a1ba50c46b | 70 | static uint32_t vref_source = EXTERNAL_VREF_SOURCE; |
pmallick | 0:e8a1ba50c46b | 71 | static float vref_voltage = 0; |
pmallick | 0:e8a1ba50c46b | 72 | #endif |
pmallick | 0:e8a1ba50c46b | 73 | |
pmallick | 0:e8a1ba50c46b | 74 | // Gain value (default is 1) |
pmallick | 0:e8a1ba50c46b | 75 | static uint32_t gain = GAIN_LOW; |
pmallick | 0:e8a1ba50c46b | 76 | |
pmallick | 0:e8a1ba50c46b | 77 | // LDAC pin state (default is High/Vlogic) |
pmallick | 0:e8a1ba50c46b | 78 | static uint32_t ldac_pin_state = GPIO_HIGH; |
pmallick | 0:e8a1ba50c46b | 79 | |
pmallick | 0:e8a1ba50c46b | 80 | // LDAC mask status (default is False/Disable) |
pmallick | 0:e8a1ba50c46b | 81 | static bool ldac_mask_status = false; |
pmallick | 0:e8a1ba50c46b | 82 | |
pmallick | 0:e8a1ba50c46b | 83 | |
pmallick | 0:e8a1ba50c46b | 84 | // Vref sources string |
pmallick | 0:e8a1ba50c46b | 85 | static const char *vref_source_str[] = { |
pmallick | 0:e8a1ba50c46b | 86 | "Internal", |
pmallick | 0:e8a1ba50c46b | 87 | "External" |
pmallick | 0:e8a1ba50c46b | 88 | }; |
pmallick | 0:e8a1ba50c46b | 89 | |
pmallick | 0:e8a1ba50c46b | 90 | // Operating mode string |
pmallick | 0:e8a1ba50c46b | 91 | static const char *operating_mode_str[] = { |
pmallick | 0:e8a1ba50c46b | 92 | "Normal Power-Up", |
pmallick | 0:e8a1ba50c46b | 93 | "1K to GND", |
pmallick | 0:e8a1ba50c46b | 94 | "100K to GND", |
pmallick | 0:e8a1ba50c46b | 95 | "Three State" |
pmallick | 0:e8a1ba50c46b | 96 | }; |
pmallick | 0:e8a1ba50c46b | 97 | |
pmallick | 0:e8a1ba50c46b | 98 | // Menu pre-declarations |
pmallick | 0:e8a1ba50c46b | 99 | extern console_menu dac_channel_select_menu; |
pmallick | 0:e8a1ba50c46b | 100 | extern console_menu vref_select_menu; |
pmallick | 0:e8a1ba50c46b | 101 | extern console_menu gain_select_menu; |
pmallick | 0:e8a1ba50c46b | 102 | extern console_menu dac_readback_select_menu; |
pmallick | 0:e8a1ba50c46b | 103 | extern console_menu ldac_mask_select_menu; |
pmallick | 0:e8a1ba50c46b | 104 | extern console_menu operating_mode_select_menu; |
pmallick | 0:e8a1ba50c46b | 105 | extern console_menu ldac_pin_select_menu; |
pmallick | 0:e8a1ba50c46b | 106 | |
pmallick | 0:e8a1ba50c46b | 107 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 108 | /************************ Functions Declarations ******************************/ |
pmallick | 0:e8a1ba50c46b | 109 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 110 | |
pmallick | 0:e8a1ba50c46b | 111 | static void gpio_power_up_configuration(void); |
pmallick | 0:e8a1ba50c46b | 112 | |
pmallick | 0:e8a1ba50c46b | 113 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 114 | /************************ Functions Definitions *******************************/ |
pmallick | 0:e8a1ba50c46b | 115 | /******************************************************************************/ |
pmallick | 0:e8a1ba50c46b | 116 | |
pmallick | 0:e8a1ba50c46b | 117 | /* @brief Initialize the nanodac device |
pmallick | 0:e8a1ba50c46b | 118 | * @param none |
pmallick | 0:e8a1ba50c46b | 119 | * @return SUCCESS(0), FAILURE(negative) |
pmallick | 0:e8a1ba50c46b | 120 | **/ |
pmallick | 0:e8a1ba50c46b | 121 | int32_t nanodac_app_initialize(void) |
pmallick | 0:e8a1ba50c46b | 122 | { |
pmallick | 0:e8a1ba50c46b | 123 | int32_t device_init_status; // Init status of device |
pmallick | 0:e8a1ba50c46b | 124 | |
pmallick | 0:e8a1ba50c46b | 125 | // Initialize the exra parameters for I2C initialization |
pmallick | 0:e8a1ba50c46b | 126 | mbed_i2c_init_param i2c_init_extra_params = { |
pmallick | 0:e8a1ba50c46b | 127 | .i2c_sda_pin = I2C_SDA, |
pmallick | 0:e8a1ba50c46b | 128 | .i2c_scl_pin = I2C_SCL |
pmallick | 0:e8a1ba50c46b | 129 | }; |
pmallick | 0:e8a1ba50c46b | 130 | |
pmallick | 0:e8a1ba50c46b | 131 | // Initialize the exra parameters for SPI initialization |
pmallick | 0:e8a1ba50c46b | 132 | mbed_spi_init_param spi_init_extra_params = { |
pmallick | 0:e8a1ba50c46b | 133 | .spi_miso_pin = SPI_MISO, |
pmallick | 0:e8a1ba50c46b | 134 | .spi_mosi_pin = SPI_MOSI, |
pmallick | 0:e8a1ba50c46b | 135 | .spi_clk_pin = SPI_SCK |
pmallick | 0:e8a1ba50c46b | 136 | }; |
pmallick | 0:e8a1ba50c46b | 137 | |
pmallick | 0:e8a1ba50c46b | 138 | // Initialize the device structure |
pmallick | 0:e8a1ba50c46b | 139 | struct ad5686_init_param nanodac_init_params = { |
pmallick | 0:e8a1ba50c46b | 140 | // i2c_init_param |
pmallick | 0:e8a1ba50c46b | 141 | { |
pmallick | 0:e8a1ba50c46b | 142 | 100000, // I2C max speed (Hz) |
pmallick | 0:e8a1ba50c46b | 143 | I2C_SLAVE_ADDRESS, // I2C slave address |
pmallick | 0:e8a1ba50c46b | 144 | &i2c_init_extra_params // I2C extra init parameters |
pmallick | 0:e8a1ba50c46b | 145 | }, |
pmallick | 0:e8a1ba50c46b | 146 | |
pmallick | 0:e8a1ba50c46b | 147 | // spi_init_param |
pmallick | 0:e8a1ba50c46b | 148 | { |
pmallick | 0:e8a1ba50c46b | 149 | 2000000, // SPI max speed (Hz) |
pmallick | 0:e8a1ba50c46b | 150 | SPI_SS, // Chip select |
pmallick | 0:e8a1ba50c46b | 151 | SPI_MODE_2, // SPI Mode |
pmallick | 0:e8a1ba50c46b | 152 | &spi_init_extra_params // SPI extra init parameters |
pmallick | 0:e8a1ba50c46b | 153 | }, |
pmallick | 0:e8a1ba50c46b | 154 | |
pmallick | 0:e8a1ba50c46b | 155 | // gpio_init_param |
pmallick | 0:e8a1ba50c46b | 156 | { RESET_PIN, NULL }, // gpio_reset |
pmallick | 0:e8a1ba50c46b | 157 | { LDAC_PIN, NULL }, // gpio_ldac |
pmallick | 0:e8a1ba50c46b | 158 | { GAIN_PIN, NULL }, // gpio_gain |
pmallick | 0:e8a1ba50c46b | 159 | |
pmallick | 0:e8a1ba50c46b | 160 | ACTIVE_DEVICE // Active device |
pmallick | 0:e8a1ba50c46b | 161 | }; |
pmallick | 0:e8a1ba50c46b | 162 | |
pmallick | 0:e8a1ba50c46b | 163 | // Initialize the device |
pmallick | 0:e8a1ba50c46b | 164 | device_init_status = ad5686_init(&nanodac_dev, nanodac_init_params); |
pmallick | 0:e8a1ba50c46b | 165 | |
pmallick | 0:e8a1ba50c46b | 166 | // Configure the GPIOs specific to application upon power-up |
pmallick | 0:e8a1ba50c46b | 167 | gpio_power_up_configuration(); |
pmallick | 0:e8a1ba50c46b | 168 | |
pmallick | 0:e8a1ba50c46b | 169 | return device_init_status; |
pmallick | 0:e8a1ba50c46b | 170 | } |
pmallick | 0:e8a1ba50c46b | 171 | |
pmallick | 0:e8a1ba50c46b | 172 | |
pmallick | 0:e8a1ba50c46b | 173 | /*! |
pmallick | 0:e8a1ba50c46b | 174 | * @brief Set the power-up GPIO configurations |
pmallick | 0:e8a1ba50c46b | 175 | * @return None |
pmallick | 0:e8a1ba50c46b | 176 | */ |
pmallick | 0:e8a1ba50c46b | 177 | static void gpio_power_up_configuration(void) |
pmallick | 0:e8a1ba50c46b | 178 | { |
pmallick | 0:e8a1ba50c46b | 179 | // Set the directions for GPIO pins |
pmallick | 0:e8a1ba50c46b | 180 | (void)gpio_direction_output(nanodac_dev->gpio_gain, GPIO_OUT); |
pmallick | 0:e8a1ba50c46b | 181 | (void)gpio_direction_output(nanodac_dev->gpio_ldac, GPIO_OUT); |
pmallick | 0:e8a1ba50c46b | 182 | (void)gpio_direction_output(nanodac_dev->gpio_reset, GPIO_OUT); |
pmallick | 0:e8a1ba50c46b | 183 | |
pmallick | 0:e8a1ba50c46b | 184 | // Set the GPIO values |
pmallick | 0:e8a1ba50c46b | 185 | gpio_set_value(nanodac_dev->gpio_reset, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 186 | gpio_set_value(nanodac_dev->gpio_gain, GPIO_LOW); |
pmallick | 0:e8a1ba50c46b | 187 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 188 | } |
pmallick | 0:e8a1ba50c46b | 189 | |
pmallick | 0:e8a1ba50c46b | 190 | |
pmallick | 0:e8a1ba50c46b | 191 | /*! |
pmallick | 0:e8a1ba50c46b | 192 | * @brief Display the header info for menu |
pmallick | 0:e8a1ba50c46b | 193 | * @return None |
pmallick | 0:e8a1ba50c46b | 194 | */ |
pmallick | 0:e8a1ba50c46b | 195 | static void display_menu_header(void) |
pmallick | 0:e8a1ba50c46b | 196 | { |
pmallick | 0:e8a1ba50c46b | 197 | printf("\t%s (nanodac) | ", ACTIVE_DEVICE_NAME); |
pmallick | 0:e8a1ba50c46b | 198 | printf("Vref:%s (%.1fV) | ", vref_source_str[vref_source], vref_voltage); |
pmallick | 0:e8a1ba50c46b | 199 | printf("Gain:%ld"EOL, gain); |
pmallick | 0:e8a1ba50c46b | 200 | } |
pmallick | 0:e8a1ba50c46b | 201 | |
pmallick | 0:e8a1ba50c46b | 202 | |
pmallick | 0:e8a1ba50c46b | 203 | /*! |
pmallick | 0:e8a1ba50c46b | 204 | * @brief Display the footer info for menu |
pmallick | 0:e8a1ba50c46b | 205 | * @return None |
pmallick | 0:e8a1ba50c46b | 206 | */ |
pmallick | 0:e8a1ba50c46b | 207 | static void display_menu_footer(void) |
pmallick | 0:e8a1ba50c46b | 208 | { |
pmallick | 0:e8a1ba50c46b | 209 | // Display the device name |
pmallick | 0:e8a1ba50c46b | 210 | printf("\tActive Channel: %d | ", current_dac_channel); |
pmallick | 0:e8a1ba50c46b | 211 | printf("LDAC Pin: %ld | ", ldac_pin_state); |
pmallick | 0:e8a1ba50c46b | 212 | printf("LDAC Mask: %d"EOL, ldac_mask_status); |
pmallick | 0:e8a1ba50c46b | 213 | } |
pmallick | 0:e8a1ba50c46b | 214 | |
pmallick | 0:e8a1ba50c46b | 215 | |
pmallick | 0:e8a1ba50c46b | 216 | /*! |
pmallick | 0:e8a1ba50c46b | 217 | * @brief Handle the DAC channel selection menu |
pmallick | 0:e8a1ba50c46b | 218 | * @param uint32_t channel_id- Selected DAC channel number |
pmallick | 0:e8a1ba50c46b | 219 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 220 | */ |
pmallick | 0:e8a1ba50c46b | 221 | static int32_t menu_select_dac_channel(uint32_t channel_id) |
pmallick | 0:e8a1ba50c46b | 222 | { |
pmallick | 0:e8a1ba50c46b | 223 | // Store the dac channel for future read/write operations |
pmallick | 0:e8a1ba50c46b | 224 | current_dac_channel = (enum ad5686_dac_channels)channel_id; |
pmallick | 0:e8a1ba50c46b | 225 | |
pmallick | 0:e8a1ba50c46b | 226 | printf(EOL EOL"\tDAC Channel %ld is selected..."EOL, channel_id); |
pmallick | 0:e8a1ba50c46b | 227 | |
pmallick | 0:e8a1ba50c46b | 228 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 229 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 230 | } |
pmallick | 0:e8a1ba50c46b | 231 | |
pmallick | 0:e8a1ba50c46b | 232 | |
pmallick | 0:e8a1ba50c46b | 233 | /*! |
pmallick | 0:e8a1ba50c46b | 234 | * @brief Handle the menu to display DAC channel selection |
pmallick | 0:e8a1ba50c46b | 235 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 236 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 237 | */ |
pmallick | 0:e8a1ba50c46b | 238 | static int32_t menu_dac_channels(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 239 | { |
pmallick | 0:e8a1ba50c46b | 240 | // Display the dac channel selection menu |
pmallick | 0:e8a1ba50c46b | 241 | adi_do_console_menu(&dac_channel_select_menu); |
pmallick | 0:e8a1ba50c46b | 242 | |
pmallick | 0:e8a1ba50c46b | 243 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 244 | } |
pmallick | 0:e8a1ba50c46b | 245 | |
pmallick | 0:e8a1ba50c46b | 246 | |
pmallick | 0:e8a1ba50c46b | 247 | /*! |
pmallick | 0:e8a1ba50c46b | 248 | * @brief Handle the menu to write DAC input register |
pmallick | 0:e8a1ba50c46b | 249 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 250 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 251 | */ |
pmallick | 0:e8a1ba50c46b | 252 | static int32_t menu_write_to_input_register(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 253 | { |
pmallick | 0:e8a1ba50c46b | 254 | uint16_t dac_data_input; // Data to be written to DAC |
pmallick | 0:e8a1ba50c46b | 255 | |
pmallick | 0:e8a1ba50c46b | 256 | printf(EOL"\tEnter the Data/Code (in decimal): "); |
pmallick | 0:e8a1ba50c46b | 257 | dac_data_input = (uint16_t)adi_get_decimal_int(5); |
pmallick | 0:e8a1ba50c46b | 258 | |
pmallick | 0:e8a1ba50c46b | 259 | // Write DAC input register for current selected channel |
pmallick | 0:e8a1ba50c46b | 260 | ad5686_write_register(nanodac_dev, current_dac_channel, dac_data_input); |
pmallick | 0:e8a1ba50c46b | 261 | |
pmallick | 0:e8a1ba50c46b | 262 | printf(EOL EOL"\tData %d written to DAC input register..."EOL, dac_data_input); |
pmallick | 0:e8a1ba50c46b | 263 | |
pmallick | 0:e8a1ba50c46b | 264 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 265 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 266 | } |
pmallick | 0:e8a1ba50c46b | 267 | |
pmallick | 0:e8a1ba50c46b | 268 | |
pmallick | 0:e8a1ba50c46b | 269 | /*! |
pmallick | 0:e8a1ba50c46b | 270 | * @brief Handle the menu to update DAC register with value from input register |
pmallick | 0:e8a1ba50c46b | 271 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 272 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 273 | */ |
pmallick | 0:e8a1ba50c46b | 274 | static int32_t menu_update_dac_from_input(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 275 | { |
pmallick | 0:e8a1ba50c46b | 276 | // Update the DAC with input register data for current selected channel |
pmallick | 0:e8a1ba50c46b | 277 | ad5686_update_register(nanodac_dev, current_dac_channel); |
pmallick | 0:e8a1ba50c46b | 278 | |
pmallick | 0:e8a1ba50c46b | 279 | printf(EOL EOL"\tUpdated DAC register with contents of input register..."EOL); |
pmallick | 0:e8a1ba50c46b | 280 | |
pmallick | 0:e8a1ba50c46b | 281 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 282 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 283 | } |
pmallick | 0:e8a1ba50c46b | 284 | |
pmallick | 0:e8a1ba50c46b | 285 | |
pmallick | 0:e8a1ba50c46b | 286 | /*! |
pmallick | 0:e8a1ba50c46b | 287 | * @brief Handle the menu to update DAC register by asserting LDAC pin |
pmallick | 0:e8a1ba50c46b | 288 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 289 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 290 | */ |
pmallick | 0:e8a1ba50c46b | 291 | static int32_t menu_update_dac_by_ldac_assert(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 292 | { |
pmallick | 0:e8a1ba50c46b | 293 | // Update DAC registers by asserting LDAC pin High to Low |
pmallick | 0:e8a1ba50c46b | 294 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 295 | mdelay(1); |
pmallick | 0:e8a1ba50c46b | 296 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_LOW); |
pmallick | 0:e8a1ba50c46b | 297 | mdelay(1); |
pmallick | 0:e8a1ba50c46b | 298 | |
pmallick | 0:e8a1ba50c46b | 299 | // Restore the previous state of LDAC pin |
pmallick | 0:e8a1ba50c46b | 300 | if (ldac_pin_state == GPIO_HIGH) { |
pmallick | 0:e8a1ba50c46b | 301 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 302 | } |
pmallick | 0:e8a1ba50c46b | 303 | |
pmallick | 0:e8a1ba50c46b | 304 | printf(EOL EOL"\tUpdated DAC register with contents of input register..."EOL); |
pmallick | 0:e8a1ba50c46b | 305 | |
pmallick | 0:e8a1ba50c46b | 306 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 307 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 308 | } |
pmallick | 0:e8a1ba50c46b | 309 | |
pmallick | 0:e8a1ba50c46b | 310 | |
pmallick | 0:e8a1ba50c46b | 311 | /*! |
pmallick | 0:e8a1ba50c46b | 312 | * @brief Handle the menu to write and update DAC register directly |
pmallick | 0:e8a1ba50c46b | 313 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 314 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 315 | */ |
pmallick | 0:e8a1ba50c46b | 316 | static int32_t menu_write_and_update_dac(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 317 | { |
pmallick | 0:e8a1ba50c46b | 318 | uint16_t dac_data_input; // Data to be written to DAC |
pmallick | 0:e8a1ba50c46b | 319 | |
pmallick | 0:e8a1ba50c46b | 320 | printf(EOL"\tEnter the Data/Code (in decimal): "); |
pmallick | 0:e8a1ba50c46b | 321 | dac_data_input = (uint16_t)adi_get_decimal_int(5); |
pmallick | 0:e8a1ba50c46b | 322 | |
pmallick | 0:e8a1ba50c46b | 323 | // Update DAC data register for current selected channel |
pmallick | 0:e8a1ba50c46b | 324 | ad5686_write_update_register(nanodac_dev, current_dac_channel, dac_data_input); |
pmallick | 0:e8a1ba50c46b | 325 | |
pmallick | 0:e8a1ba50c46b | 326 | printf(EOL EOL"\tDAC updated with Data %d"EOL, dac_data_input); |
pmallick | 0:e8a1ba50c46b | 327 | |
pmallick | 0:e8a1ba50c46b | 328 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 329 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 330 | } |
pmallick | 0:e8a1ba50c46b | 331 | |
pmallick | 0:e8a1ba50c46b | 332 | |
pmallick | 0:e8a1ba50c46b | 333 | /*! |
pmallick | 0:e8a1ba50c46b | 334 | * @brief Handle the menu to select operating mode of DAC |
pmallick | 0:e8a1ba50c46b | 335 | * @param uint32_t operating_mode_input- User input operating mode |
pmallick | 0:e8a1ba50c46b | 336 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 337 | */ |
pmallick | 0:e8a1ba50c46b | 338 | static int32_t menu_select_operating_mode(uint32_t operating_mode_input) |
pmallick | 0:e8a1ba50c46b | 339 | { |
pmallick | 0:e8a1ba50c46b | 340 | // Select the operating mode of DAC |
pmallick | 0:e8a1ba50c46b | 341 | ad5686_power_mode(nanodac_dev, current_dac_channel, operating_mode_input); |
pmallick | 0:e8a1ba50c46b | 342 | |
pmallick | 0:e8a1ba50c46b | 343 | printf(EOL EOL"\tSelected operating mode as %s"EOL, |
pmallick | 0:e8a1ba50c46b | 344 | operating_mode_str[operating_mode_input]); |
pmallick | 0:e8a1ba50c46b | 345 | |
pmallick | 0:e8a1ba50c46b | 346 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 347 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 348 | } |
pmallick | 0:e8a1ba50c46b | 349 | |
pmallick | 0:e8a1ba50c46b | 350 | |
pmallick | 0:e8a1ba50c46b | 351 | /*! |
pmallick | 0:e8a1ba50c46b | 352 | * @brief Handle the menu to display operating modes of DAC |
pmallick | 0:e8a1ba50c46b | 353 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 354 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 355 | */ |
pmallick | 0:e8a1ba50c46b | 356 | static int32_t menu_dac_operating_modes(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 357 | { |
pmallick | 0:e8a1ba50c46b | 358 | // Display the operating mode select menu |
pmallick | 0:e8a1ba50c46b | 359 | adi_do_console_menu(&operating_mode_select_menu); |
pmallick | 0:e8a1ba50c46b | 360 | |
pmallick | 0:e8a1ba50c46b | 361 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 362 | } |
pmallick | 0:e8a1ba50c46b | 363 | |
pmallick | 0:e8a1ba50c46b | 364 | |
pmallick | 0:e8a1ba50c46b | 365 | /*! |
pmallick | 0:e8a1ba50c46b | 366 | * @brief Handle the menu to select the reference source for DAC |
pmallick | 0:e8a1ba50c46b | 367 | * @param uint32_t ref_source_input- user selected reference source |
pmallick | 0:e8a1ba50c46b | 368 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 369 | */ |
pmallick | 0:e8a1ba50c46b | 370 | static int32_t menu_select_vref_source(uint32_t ref_source_input) |
pmallick | 0:e8a1ba50c46b | 371 | { |
pmallick | 0:e8a1ba50c46b | 372 | float user_vref_value = INTERNAL_VREF_VOLTAGE; // user input reference |
pmallick | 0:e8a1ba50c46b | 373 | // voltage value |
pmallick | 0:e8a1ba50c46b | 374 | |
pmallick | 0:e8a1ba50c46b | 375 | if (ref_source_input == INTERNAL_VREF_SOURCE) { |
pmallick | 0:e8a1ba50c46b | 376 | // Enable the internal reference source |
pmallick | 0:e8a1ba50c46b | 377 | ad5686_internal_reference(nanodac_dev, AD5686_INTREF_EN); |
pmallick | 0:e8a1ba50c46b | 378 | vref_source = INTERNAL_VREF_SOURCE; |
pmallick | 0:e8a1ba50c46b | 379 | vref_voltage = INTERNAL_VREF_VOLTAGE; |
pmallick | 0:e8a1ba50c46b | 380 | |
pmallick | 0:e8a1ba50c46b | 381 | // Display the vref selections on console window |
pmallick | 0:e8a1ba50c46b | 382 | printf(EOL"\tVref Source: %s"EOL, vref_source_str[vref_source]); |
pmallick | 0:e8a1ba50c46b | 383 | printf("\tVref Voltage: %f"EOL, vref_voltage); |
pmallick | 0:e8a1ba50c46b | 384 | } else if (ref_source_input == EXTERNAL_VREF_SOURCE) { |
pmallick | 0:e8a1ba50c46b | 385 | printf(EOL EOL"\tEnter the external reference voltage"EOL); |
pmallick | 0:e8a1ba50c46b | 386 | user_vref_value = adi_get_decimal_float(5); |
pmallick | 0:e8a1ba50c46b | 387 | |
pmallick | 0:e8a1ba50c46b | 388 | // Disable the internal reference source |
pmallick | 0:e8a1ba50c46b | 389 | ad5686_internal_reference(nanodac_dev, AD5686_INTREF_DIS); |
pmallick | 0:e8a1ba50c46b | 390 | vref_source = EXTERNAL_VREF_SOURCE; |
pmallick | 0:e8a1ba50c46b | 391 | vref_voltage = user_vref_value; |
pmallick | 0:e8a1ba50c46b | 392 | |
pmallick | 0:e8a1ba50c46b | 393 | // Display the vref selections on console window |
pmallick | 0:e8a1ba50c46b | 394 | printf(EOL"\tVref Source: %s"EOL, vref_source_str[vref_source]); |
pmallick | 0:e8a1ba50c46b | 395 | printf("\tVref Voltage: %f"EOL, vref_voltage); |
pmallick | 0:e8a1ba50c46b | 396 | } else { |
pmallick | 0:e8a1ba50c46b | 397 | printf(EOL EOL"\tInvalid Vref Source selection"EOL); |
pmallick | 0:e8a1ba50c46b | 398 | } |
pmallick | 0:e8a1ba50c46b | 399 | |
pmallick | 0:e8a1ba50c46b | 400 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 401 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 402 | } |
pmallick | 0:e8a1ba50c46b | 403 | |
pmallick | 0:e8a1ba50c46b | 404 | |
pmallick | 0:e8a1ba50c46b | 405 | /*! |
pmallick | 0:e8a1ba50c46b | 406 | * @brief Handle the menu to display the reference source for DAC |
pmallick | 0:e8a1ba50c46b | 407 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 408 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 409 | */ |
pmallick | 0:e8a1ba50c46b | 410 | static int32_t menu_vref_sources(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 411 | { |
pmallick | 0:e8a1ba50c46b | 412 | // Display the Vref selection menu |
pmallick | 0:e8a1ba50c46b | 413 | adi_do_console_menu(&vref_select_menu); |
pmallick | 0:e8a1ba50c46b | 414 | |
pmallick | 0:e8a1ba50c46b | 415 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 416 | } |
pmallick | 0:e8a1ba50c46b | 417 | |
pmallick | 0:e8a1ba50c46b | 418 | |
pmallick | 0:e8a1ba50c46b | 419 | /*! |
pmallick | 0:e8a1ba50c46b | 420 | * @brief Handle the menu to readback DAC register for selected channel |
pmallick | 0:e8a1ba50c46b | 421 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 422 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 423 | */ |
pmallick | 0:e8a1ba50c46b | 424 | static int32_t menu_dac_readback(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 425 | { |
pmallick | 0:e8a1ba50c46b | 426 | uint16_t dac_data; // Readback DAC data |
pmallick | 0:e8a1ba50c46b | 427 | float output_voltage; // Output voltage of DAC channel |
pmallick | 0:e8a1ba50c46b | 428 | |
pmallick | 0:e8a1ba50c46b | 429 | // Readback data for current selected DAC channel |
pmallick | 0:e8a1ba50c46b | 430 | dac_data = ad5686_read_back_register(nanodac_dev, current_dac_channel); |
pmallick | 0:e8a1ba50c46b | 431 | |
pmallick | 0:e8a1ba50c46b | 432 | // Calculate equivalent output voltage |
pmallick | 0:e8a1ba50c46b | 433 | output_voltage = (vref_voltage * gain * ((float)dac_data / TOTAL_OUTPUT_CODES)); |
pmallick | 0:e8a1ba50c46b | 434 | |
pmallick | 0:e8a1ba50c46b | 435 | printf(EOL EOL"\tDAC Channel %d Data: %d"EOL, current_dac_channel, dac_data); |
pmallick | 0:e8a1ba50c46b | 436 | printf(EOL"\tVoltage: %.3f V"EOL EOL, output_voltage); |
pmallick | 0:e8a1ba50c46b | 437 | |
pmallick | 0:e8a1ba50c46b | 438 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 439 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 440 | } |
pmallick | 0:e8a1ba50c46b | 441 | |
pmallick | 0:e8a1ba50c46b | 442 | |
pmallick | 0:e8a1ba50c46b | 443 | /*! |
pmallick | 0:e8a1ba50c46b | 444 | * @brief Handle the menu to select LDACx mask (x:DAC channel) |
pmallick | 0:e8a1ba50c46b | 445 | * @param uint32_t mask_status- user input LDAC mask |
pmallick | 0:e8a1ba50c46b | 446 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 447 | */ |
pmallick | 0:e8a1ba50c46b | 448 | static int32_t menu_set_ldac_mask(uint32_t mask_status) |
pmallick | 0:e8a1ba50c46b | 449 | { |
pmallick | 0:e8a1ba50c46b | 450 | // Set the LDAC mask (0/1) |
pmallick | 0:e8a1ba50c46b | 451 | ad5686_ldac_mask(nanodac_dev, current_dac_channel, mask_status); |
pmallick | 0:e8a1ba50c46b | 452 | |
pmallick | 0:e8a1ba50c46b | 453 | ldac_mask_status = mask_status; |
pmallick | 0:e8a1ba50c46b | 454 | printf(EOL EOL"\tLDAC Mask for Channel %d: %ld"EOL, current_dac_channel, |
pmallick | 0:e8a1ba50c46b | 455 | mask_status); |
pmallick | 0:e8a1ba50c46b | 456 | |
pmallick | 0:e8a1ba50c46b | 457 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 458 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 459 | } |
pmallick | 0:e8a1ba50c46b | 460 | |
pmallick | 0:e8a1ba50c46b | 461 | |
pmallick | 0:e8a1ba50c46b | 462 | /*! |
pmallick | 0:e8a1ba50c46b | 463 | * @brief Handle the menu to display LDACx mask menu selections |
pmallick | 0:e8a1ba50c46b | 464 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 465 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 466 | */ |
pmallick | 0:e8a1ba50c46b | 467 | static int32_t menu_ldac_masks(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 468 | { |
pmallick | 0:e8a1ba50c46b | 469 | // Display the LDAC mask selection menu |
pmallick | 0:e8a1ba50c46b | 470 | adi_do_console_menu(&ldac_mask_select_menu); |
pmallick | 0:e8a1ba50c46b | 471 | |
pmallick | 0:e8a1ba50c46b | 472 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 473 | } |
pmallick | 0:e8a1ba50c46b | 474 | |
pmallick | 0:e8a1ba50c46b | 475 | |
pmallick | 0:e8a1ba50c46b | 476 | /*! |
pmallick | 0:e8a1ba50c46b | 477 | * @brief Handle the menu to set LDAC pin state |
pmallick | 0:e8a1ba50c46b | 478 | * @param uint32_t pin_state- user input pin state (HIGH/LOW) |
pmallick | 0:e8a1ba50c46b | 479 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 480 | */ |
pmallick | 0:e8a1ba50c46b | 481 | static int32_t menu_set_ldac_pin(uint32_t pin_state) |
pmallick | 0:e8a1ba50c46b | 482 | { |
pmallick | 0:e8a1ba50c46b | 483 | if (pin_state == GPIO_HIGH) { |
pmallick | 0:e8a1ba50c46b | 484 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 485 | } else { |
pmallick | 0:e8a1ba50c46b | 486 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_LOW); |
pmallick | 0:e8a1ba50c46b | 487 | } |
pmallick | 0:e8a1ba50c46b | 488 | |
pmallick | 0:e8a1ba50c46b | 489 | ldac_pin_state = pin_state; |
pmallick | 0:e8a1ba50c46b | 490 | printf(EOL EOL"\tLDAC pin set to %ld"EOL, ldac_pin_state); |
pmallick | 0:e8a1ba50c46b | 491 | |
pmallick | 0:e8a1ba50c46b | 492 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 493 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 494 | } |
pmallick | 0:e8a1ba50c46b | 495 | |
pmallick | 0:e8a1ba50c46b | 496 | |
pmallick | 0:e8a1ba50c46b | 497 | /*! |
pmallick | 0:e8a1ba50c46b | 498 | * @brief Handle the menu to assert LDAC pin to update DAC |
pmallick | 0:e8a1ba50c46b | 499 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 500 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 501 | */ |
pmallick | 0:e8a1ba50c46b | 502 | static int32_t menu_select_ldac_pin_state(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 503 | { |
pmallick | 0:e8a1ba50c46b | 504 | // Display the LDAC pin selection menu |
pmallick | 0:e8a1ba50c46b | 505 | adi_do_console_menu(&ldac_pin_select_menu); |
pmallick | 0:e8a1ba50c46b | 506 | |
pmallick | 0:e8a1ba50c46b | 507 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 508 | } |
pmallick | 0:e8a1ba50c46b | 509 | |
pmallick | 0:e8a1ba50c46b | 510 | |
pmallick | 0:e8a1ba50c46b | 511 | /*! |
pmallick | 0:e8a1ba50c46b | 512 | * @brief Handle the menu to set the DAC gain |
pmallick | 0:e8a1ba50c46b | 513 | * @param uint32_t gain_input- Gain input value |
pmallick | 0:e8a1ba50c46b | 514 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 515 | */ |
pmallick | 0:e8a1ba50c46b | 516 | static int32_t menu_set_gain(uint32_t gain_input) |
pmallick | 0:e8a1ba50c46b | 517 | { |
pmallick | 0:e8a1ba50c46b | 518 | // Set the device gain |
pmallick | 0:e8a1ba50c46b | 519 | gain = gain_input; |
pmallick | 0:e8a1ba50c46b | 520 | |
pmallick | 0:e8a1ba50c46b | 521 | #if defined (SOFTWARE_CONTROLLED_GAIN) |
pmallick | 0:e8a1ba50c46b | 522 | ad5686_gain_mode(nanodac_dev, gain); |
pmallick | 0:e8a1ba50c46b | 523 | #else |
pmallick | 0:e8a1ba50c46b | 524 | if (gain == GAIN_LOW) { |
pmallick | 0:e8a1ba50c46b | 525 | gpio_set_value(nanodac_dev->gpio_gain, GPIO_LOW); |
pmallick | 0:e8a1ba50c46b | 526 | } else { |
pmallick | 0:e8a1ba50c46b | 527 | gpio_set_value(nanodac_dev->gpio_gain, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 528 | } |
pmallick | 0:e8a1ba50c46b | 529 | #endif |
pmallick | 0:e8a1ba50c46b | 530 | |
pmallick | 0:e8a1ba50c46b | 531 | printf(EOL EOL"\tGain set to %ld"EOL,gain); |
pmallick | 0:e8a1ba50c46b | 532 | |
pmallick | 0:e8a1ba50c46b | 533 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 534 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 535 | } |
pmallick | 0:e8a1ba50c46b | 536 | |
pmallick | 0:e8a1ba50c46b | 537 | |
pmallick | 0:e8a1ba50c46b | 538 | /*! |
pmallick | 0:e8a1ba50c46b | 539 | * @brief Handle the menu to display DAC gain selections |
pmallick | 0:e8a1ba50c46b | 540 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 541 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 542 | */ |
pmallick | 0:e8a1ba50c46b | 543 | static int32_t menu_gain_selection(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 544 | { |
pmallick | 0:e8a1ba50c46b | 545 | // Display the DAC gain selection menu |
pmallick | 0:e8a1ba50c46b | 546 | adi_do_console_menu(&gain_select_menu); |
pmallick | 0:e8a1ba50c46b | 547 | |
pmallick | 0:e8a1ba50c46b | 548 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 549 | } |
pmallick | 0:e8a1ba50c46b | 550 | |
pmallick | 0:e8a1ba50c46b | 551 | |
pmallick | 0:e8a1ba50c46b | 552 | /*! |
pmallick | 0:e8a1ba50c46b | 553 | * @brief Handle the menu to perform DAC software reset |
pmallick | 0:e8a1ba50c46b | 554 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 555 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 556 | */ |
pmallick | 0:e8a1ba50c46b | 557 | static int32_t menu_assert_software_reset(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 558 | { |
pmallick | 0:e8a1ba50c46b | 559 | // Do device software reset |
pmallick | 0:e8a1ba50c46b | 560 | ad5686_software_reset(nanodac_dev); |
pmallick | 0:e8a1ba50c46b | 561 | |
pmallick | 0:e8a1ba50c46b | 562 | printf(EOL"\tSoftware Reset Complete..."EOL); |
pmallick | 0:e8a1ba50c46b | 563 | |
pmallick | 0:e8a1ba50c46b | 564 | // Device reset disables the LDAC mask through hardware. |
pmallick | 0:e8a1ba50c46b | 565 | // This needs to be synched with software. |
pmallick | 0:e8a1ba50c46b | 566 | ldac_mask_status = false; |
pmallick | 0:e8a1ba50c46b | 567 | |
pmallick | 0:e8a1ba50c46b | 568 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 569 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 570 | } |
pmallick | 0:e8a1ba50c46b | 571 | |
pmallick | 0:e8a1ba50c46b | 572 | |
pmallick | 0:e8a1ba50c46b | 573 | /*! |
pmallick | 0:e8a1ba50c46b | 574 | * @brief Handle the menu to perform DAC hardware reset |
pmallick | 0:e8a1ba50c46b | 575 | * @param uint32_t menu_id- (Optional parameter) |
pmallick | 0:e8a1ba50c46b | 576 | * @return MENU_CONTINUE |
pmallick | 0:e8a1ba50c46b | 577 | */ |
pmallick | 0:e8a1ba50c46b | 578 | static int32_t menu_assert_hardware_reset(uint32_t menu_id) |
pmallick | 0:e8a1ba50c46b | 579 | { |
pmallick | 0:e8a1ba50c46b | 580 | // Do device hardware reset |
pmallick | 0:e8a1ba50c46b | 581 | gpio_set_value(nanodac_dev->gpio_reset, GPIO_LOW); |
pmallick | 0:e8a1ba50c46b | 582 | mdelay(1); |
pmallick | 0:e8a1ba50c46b | 583 | gpio_set_value(nanodac_dev->gpio_reset, GPIO_HIGH); |
pmallick | 0:e8a1ba50c46b | 584 | |
pmallick | 0:e8a1ba50c46b | 585 | printf(EOL"\tHardware Reset Complete..."EOL); |
pmallick | 0:e8a1ba50c46b | 586 | |
pmallick | 0:e8a1ba50c46b | 587 | // Device reset disables the LDAC mask through hardware. |
pmallick | 0:e8a1ba50c46b | 588 | // This needs to be synched with software. |
pmallick | 0:e8a1ba50c46b | 589 | ldac_mask_status = false; |
pmallick | 0:e8a1ba50c46b | 590 | |
pmallick | 0:e8a1ba50c46b | 591 | adi_press_any_key_to_continue(); |
pmallick | 0:e8a1ba50c46b | 592 | return MENU_CONTINUE; |
pmallick | 0:e8a1ba50c46b | 593 | } |
pmallick | 0:e8a1ba50c46b | 594 | |
pmallick | 0:e8a1ba50c46b | 595 | |
pmallick | 0:e8a1ba50c46b | 596 | // Operating mode menu for DAC |
pmallick | 0:e8a1ba50c46b | 597 | static console_menu_item operating_mode_select_items[] = { |
pmallick | 0:e8a1ba50c46b | 598 | { "Normal Power-Up", 'A', menu_select_operating_mode, AD5686_PWRM_NORMAL }, |
pmallick | 0:e8a1ba50c46b | 599 | |
pmallick | 0:e8a1ba50c46b | 600 | #if defined(_1K_TO_GND_POWER_DOWN) |
pmallick | 0:e8a1ba50c46b | 601 | { "1K to GND (Power-Down)", 'B', menu_select_operating_mode, AD5686_PWRM_1K }, |
pmallick | 0:e8a1ba50c46b | 602 | #endif |
pmallick | 0:e8a1ba50c46b | 603 | #if defined(_100K_TO_GND_POWER_DOWN) |
pmallick | 0:e8a1ba50c46b | 604 | { "100K to GND (Power-Down)", 'C', menu_select_operating_mode, AD5686_PWRM_100K }, |
pmallick | 0:e8a1ba50c46b | 605 | #endif |
pmallick | 0:e8a1ba50c46b | 606 | #if defined(THREE_STATE_POWER_DOWN) |
pmallick | 0:e8a1ba50c46b | 607 | { "Three-State (Power-Down)", 'D', menu_select_operating_mode, AD5686_PWRM_THREESTATE }, |
pmallick | 0:e8a1ba50c46b | 608 | #endif |
pmallick | 0:e8a1ba50c46b | 609 | }; |
pmallick | 0:e8a1ba50c46b | 610 | |
pmallick | 0:e8a1ba50c46b | 611 | console_menu operating_mode_select_menu = { |
pmallick | 0:e8a1ba50c46b | 612 | .title = "Select Operating Mode", |
pmallick | 0:e8a1ba50c46b | 613 | .items = operating_mode_select_items, |
pmallick | 0:e8a1ba50c46b | 614 | .itemCount = ARRAY_SIZE(operating_mode_select_items), |
pmallick | 0:e8a1ba50c46b | 615 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 616 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 617 | .enableEscapeKey = true |
pmallick | 0:e8a1ba50c46b | 618 | }; |
pmallick | 0:e8a1ba50c46b | 619 | |
pmallick | 0:e8a1ba50c46b | 620 | |
pmallick | 0:e8a1ba50c46b | 621 | // LDAC pin set menu for DAC |
pmallick | 0:e8a1ba50c46b | 622 | static console_menu_item ldac_pin_select_items[] = { |
pmallick | 0:e8a1ba50c46b | 623 | { "High (VLogic)", 'H', menu_set_ldac_pin, GPIO_HIGH }, |
pmallick | 0:e8a1ba50c46b | 624 | { "Low (GND)", 'L', menu_set_ldac_pin, GPIO_LOW } |
pmallick | 0:e8a1ba50c46b | 625 | }; |
pmallick | 0:e8a1ba50c46b | 626 | |
pmallick | 0:e8a1ba50c46b | 627 | console_menu ldac_pin_select_menu = { |
pmallick | 0:e8a1ba50c46b | 628 | .title = "Select LDAC Mask", |
pmallick | 0:e8a1ba50c46b | 629 | .items = ldac_pin_select_items, |
pmallick | 0:e8a1ba50c46b | 630 | .itemCount = ARRAY_SIZE(ldac_pin_select_items), |
pmallick | 0:e8a1ba50c46b | 631 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 632 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 633 | .enableEscapeKey = true |
pmallick | 0:e8a1ba50c46b | 634 | }; |
pmallick | 0:e8a1ba50c46b | 635 | |
pmallick | 0:e8a1ba50c46b | 636 | |
pmallick | 0:e8a1ba50c46b | 637 | // LDAC mask menu for DAC |
pmallick | 0:e8a1ba50c46b | 638 | static console_menu_item ldac_mask_select_items[] = { |
pmallick | 0:e8a1ba50c46b | 639 | { "Disable (LDAC Pin Controlled)", 'D', menu_set_ldac_mask, 0 }, |
pmallick | 0:e8a1ba50c46b | 640 | { "Enable (LDAC Pin Ignored)", 'E', menu_set_ldac_mask, 1 } |
pmallick | 0:e8a1ba50c46b | 641 | }; |
pmallick | 0:e8a1ba50c46b | 642 | |
pmallick | 0:e8a1ba50c46b | 643 | console_menu ldac_mask_select_menu = { |
pmallick | 0:e8a1ba50c46b | 644 | .title = "Select LDAC Mask", |
pmallick | 0:e8a1ba50c46b | 645 | .items = ldac_mask_select_items, |
pmallick | 0:e8a1ba50c46b | 646 | .itemCount = ARRAY_SIZE(ldac_mask_select_items), |
pmallick | 0:e8a1ba50c46b | 647 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 648 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 649 | .enableEscapeKey = true |
pmallick | 0:e8a1ba50c46b | 650 | }; |
pmallick | 0:e8a1ba50c46b | 651 | |
pmallick | 0:e8a1ba50c46b | 652 | |
pmallick | 0:e8a1ba50c46b | 653 | // Gain select menu for DAC |
pmallick | 0:e8a1ba50c46b | 654 | static console_menu_item gain_select_items[] = { |
pmallick | 0:e8a1ba50c46b | 655 | { "Gain= 1 (Vout: 0-Vref)", '1', menu_set_gain, GAIN_LOW }, |
pmallick | 0:e8a1ba50c46b | 656 | { "Gain= 2 (Vout: 0-2*Vref)", '2', menu_set_gain, GAIN_HIGH } |
pmallick | 0:e8a1ba50c46b | 657 | }; |
pmallick | 0:e8a1ba50c46b | 658 | |
pmallick | 0:e8a1ba50c46b | 659 | console_menu gain_select_menu = { |
pmallick | 0:e8a1ba50c46b | 660 | .title = "Select Gain", |
pmallick | 0:e8a1ba50c46b | 661 | .items = gain_select_items, |
pmallick | 0:e8a1ba50c46b | 662 | .itemCount = ARRAY_SIZE(gain_select_items), |
pmallick | 0:e8a1ba50c46b | 663 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 664 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 665 | .enableEscapeKey = true |
pmallick | 0:e8a1ba50c46b | 666 | }; |
pmallick | 0:e8a1ba50c46b | 667 | |
pmallick | 0:e8a1ba50c46b | 668 | |
pmallick | 0:e8a1ba50c46b | 669 | // Vref select menu for DAC |
pmallick | 0:e8a1ba50c46b | 670 | static console_menu_item vref_select_items[] = { |
pmallick | 0:e8a1ba50c46b | 671 | #if !defined(EXT_VREF_SOURCE_ONLY) |
pmallick | 0:e8a1ba50c46b | 672 | { "Internal Vref", 'I', menu_select_vref_source, INTERNAL_VREF_SOURCE }, |
pmallick | 0:e8a1ba50c46b | 673 | #endif |
pmallick | 0:e8a1ba50c46b | 674 | { "External Vref", 'E', menu_select_vref_source, EXTERNAL_VREF_SOURCE } |
pmallick | 0:e8a1ba50c46b | 675 | }; |
pmallick | 0:e8a1ba50c46b | 676 | |
pmallick | 0:e8a1ba50c46b | 677 | console_menu vref_select_menu = { |
pmallick | 0:e8a1ba50c46b | 678 | .title = "Select Vref Source", |
pmallick | 0:e8a1ba50c46b | 679 | .items = vref_select_items, |
pmallick | 0:e8a1ba50c46b | 680 | .itemCount = ARRAY_SIZE(vref_select_items), |
pmallick | 0:e8a1ba50c46b | 681 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 682 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 683 | .enableEscapeKey = true |
pmallick | 0:e8a1ba50c46b | 684 | }; |
pmallick | 0:e8a1ba50c46b | 685 | |
pmallick | 0:e8a1ba50c46b | 686 | |
pmallick | 0:e8a1ba50c46b | 687 | // Channel selection menu for DAC |
pmallick | 0:e8a1ba50c46b | 688 | static console_menu_item dac_channel_select_items[] = { |
pmallick | 0:e8a1ba50c46b | 689 | { "Channel 0", 'A', menu_select_dac_channel, (uint32_t)AD5686_CH_0 }, |
pmallick | 0:e8a1ba50c46b | 690 | { "Channel 1", 'B', menu_select_dac_channel, (uint32_t)AD5686_CH_1 }, |
pmallick | 0:e8a1ba50c46b | 691 | #if DAC_CHANNEL_COUNT > 2 |
pmallick | 0:e8a1ba50c46b | 692 | { "Channel 2", 'C', menu_select_dac_channel, (uint32_t)AD5686_CH_2 }, |
pmallick | 0:e8a1ba50c46b | 693 | { "Channel 3", 'D', menu_select_dac_channel, (uint32_t)AD5686_CH_3 }, |
pmallick | 0:e8a1ba50c46b | 694 | #endif |
pmallick | 0:e8a1ba50c46b | 695 | #if DAC_CHANNEL_COUNT > 4 |
pmallick | 0:e8a1ba50c46b | 696 | { "Channel 4", 'E', menu_select_dac_channel, (uint32_t)AD5686_CH_4 }, |
pmallick | 0:e8a1ba50c46b | 697 | { "Channel 5", 'F', menu_select_dac_channel, (uint32_t)AD5686_CH_5 }, |
pmallick | 0:e8a1ba50c46b | 698 | { "Channel 6", 'G', menu_select_dac_channel, (uint32_t)AD5686_CH_6 }, |
pmallick | 0:e8a1ba50c46b | 699 | { "Channel 7", 'H', menu_select_dac_channel, (uint32_t)AD5686_CH_7 }, |
pmallick | 0:e8a1ba50c46b | 700 | #endif |
pmallick | 0:e8a1ba50c46b | 701 | #if DAC_CHANNEL_COUNT > 8 |
pmallick | 0:e8a1ba50c46b | 702 | { "Channel 8", 'I', menu_select_dac_channel, (uint32_t)AD5686_CH_8 }, |
pmallick | 0:e8a1ba50c46b | 703 | { "Channel 9", 'J', menu_select_dac_channel, (uint32_t)AD5686_CH_9 }, |
pmallick | 0:e8a1ba50c46b | 704 | { "Channel 10", 'K', menu_select_dac_channel, (uint32_t)AD5686_CH_10 }, |
pmallick | 0:e8a1ba50c46b | 705 | { "Channel 11", 'L', menu_select_dac_channel, (uint32_t)AD5686_CH_11 }, |
pmallick | 0:e8a1ba50c46b | 706 | { "Channel 12", 'M', menu_select_dac_channel, (uint32_t)AD5686_CH_12 }, |
pmallick | 0:e8a1ba50c46b | 707 | { "Channel 13", 'N', menu_select_dac_channel, (uint32_t)AD5686_CH_13 }, |
pmallick | 0:e8a1ba50c46b | 708 | { "Channel 14", 'O', menu_select_dac_channel, (uint32_t)AD5686_CH_14 }, |
pmallick | 0:e8a1ba50c46b | 709 | { "Channel 15", 'P', menu_select_dac_channel, (uint32_t)AD5686_CH_15 }, |
pmallick | 0:e8a1ba50c46b | 710 | #endif |
pmallick | 0:e8a1ba50c46b | 711 | }; |
pmallick | 0:e8a1ba50c46b | 712 | |
pmallick | 0:e8a1ba50c46b | 713 | console_menu dac_channel_select_menu = { |
pmallick | 0:e8a1ba50c46b | 714 | .title = "Select DAC Channel", |
pmallick | 0:e8a1ba50c46b | 715 | .items = dac_channel_select_items, |
pmallick | 0:e8a1ba50c46b | 716 | .itemCount = ARRAY_SIZE(dac_channel_select_items), |
pmallick | 0:e8a1ba50c46b | 717 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 718 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 719 | .enableEscapeKey = true |
pmallick | 0:e8a1ba50c46b | 720 | }; |
pmallick | 0:e8a1ba50c46b | 721 | |
pmallick | 0:e8a1ba50c46b | 722 | |
pmallick | 0:e8a1ba50c46b | 723 | /* |
pmallick | 0:e8a1ba50c46b | 724 | * Definition of the Main Menu Items and menu itself |
pmallick | 0:e8a1ba50c46b | 725 | */ |
pmallick | 0:e8a1ba50c46b | 726 | static console_menu_item main_menu_items[] = { |
pmallick | 0:e8a1ba50c46b | 727 | #ifdef DISPLAY_DAC_CHANNEL_SELECT_MENU |
pmallick | 0:e8a1ba50c46b | 728 | { "Select DAC Channel", 'A', menu_dac_channels }, |
pmallick | 0:e8a1ba50c46b | 729 | {""}, |
pmallick | 0:e8a1ba50c46b | 730 | #endif |
pmallick | 0:e8a1ba50c46b | 731 | { "Write to Input Register (LDAC Dependent)", 'B',menu_write_to_input_register }, |
pmallick | 0:e8a1ba50c46b | 732 | {""}, |
pmallick | 0:e8a1ba50c46b | 733 | { "Update DAC from Input Register", 'C', menu_update_dac_from_input }, |
pmallick | 0:e8a1ba50c46b | 734 | {""}, |
pmallick | 0:e8a1ba50c46b | 735 | { "Update DAC by LDAC Assert (H->L)", 'D', menu_update_dac_by_ldac_assert }, |
pmallick | 0:e8a1ba50c46b | 736 | {""}, |
pmallick | 0:e8a1ba50c46b | 737 | { "Write and Update DAC (Direct Update)", 'E', menu_write_and_update_dac }, |
pmallick | 0:e8a1ba50c46b | 738 | {""}, |
pmallick | 0:e8a1ba50c46b | 739 | { "Read Back DAC Channel", 'F', menu_dac_readback }, |
pmallick | 0:e8a1ba50c46b | 740 | {""}, |
pmallick | 0:e8a1ba50c46b | 741 | #ifdef DISPLAY_LDAC_MASK_SELECT_MENU |
pmallick | 0:e8a1ba50c46b | 742 | { "Set LDAC# Mask", 'G', menu_ldac_masks }, |
pmallick | 0:e8a1ba50c46b | 743 | {""}, |
pmallick | 0:e8a1ba50c46b | 744 | #endif |
pmallick | 0:e8a1ba50c46b | 745 | { "Select LDAC Pin State", 'H', menu_select_ldac_pin_state }, |
pmallick | 0:e8a1ba50c46b | 746 | {""}, |
pmallick | 0:e8a1ba50c46b | 747 | { "Select Operating Mode", 'I', menu_dac_operating_modes }, |
pmallick | 0:e8a1ba50c46b | 748 | {""}, |
pmallick | 0:e8a1ba50c46b | 749 | { "Select Reference Source (Vref)", 'J', menu_vref_sources }, |
pmallick | 0:e8a1ba50c46b | 750 | {""}, |
pmallick | 0:e8a1ba50c46b | 751 | { "Set Gain", 'K', menu_gain_selection }, |
pmallick | 0:e8a1ba50c46b | 752 | {""}, |
pmallick | 0:e8a1ba50c46b | 753 | { "Assert Software Reset", 'L', menu_assert_software_reset }, |
pmallick | 0:e8a1ba50c46b | 754 | {""}, |
pmallick | 0:e8a1ba50c46b | 755 | { "Assert Hardware Reset", 'M', menu_assert_hardware_reset }, |
pmallick | 0:e8a1ba50c46b | 756 | {""}, |
pmallick | 0:e8a1ba50c46b | 757 | }; |
pmallick | 0:e8a1ba50c46b | 758 | |
pmallick | 0:e8a1ba50c46b | 759 | console_menu nanodac_main_menu = { |
pmallick | 0:e8a1ba50c46b | 760 | .title = "Main Menu", |
pmallick | 0:e8a1ba50c46b | 761 | .items = main_menu_items, |
pmallick | 0:e8a1ba50c46b | 762 | .itemCount = ARRAY_SIZE(main_menu_items), |
pmallick | 0:e8a1ba50c46b | 763 | .headerItem = display_menu_header, |
pmallick | 0:e8a1ba50c46b | 764 | .footerItem = display_menu_footer, |
pmallick | 0:e8a1ba50c46b | 765 | .enableEscapeKey = false |
pmallick | 0:e8a1ba50c46b | 766 | }; |