Pratyush Mallick
/
testing
this is testing
app/src/ad7606_support.c@0:3afcd581558d, 2021-01-14 (annotated)
- Committer:
- pmallick
- Date:
- Thu Jan 14 18:54:16 2021 +0530
- Revision:
- 0:3afcd581558d
this is testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmallick | 0:3afcd581558d | 1 | /*************************************************************************//** |
pmallick | 0:3afcd581558d | 2 | * @file ad7606_support.c |
pmallick | 0:3afcd581558d | 3 | * @brief AD7606 device No-OS driver supports |
pmallick | 0:3afcd581558d | 4 | ****************************************************************************** |
pmallick | 0:3afcd581558d | 5 | * Copyright (c) 2020 Analog Devices, Inc. |
pmallick | 0:3afcd581558d | 6 | * |
pmallick | 0:3afcd581558d | 7 | * All rights reserved. |
pmallick | 0:3afcd581558d | 8 | * |
pmallick | 0:3afcd581558d | 9 | * This software is proprietary to Analog Devices, Inc. and its licensors. |
pmallick | 0:3afcd581558d | 10 | * By using this software you agree to the terms of the associated |
pmallick | 0:3afcd581558d | 11 | * Analog Devices Software License Agreement. |
pmallick | 0:3afcd581558d | 12 | *****************************************************************************/ |
pmallick | 0:3afcd581558d | 13 | |
pmallick | 0:3afcd581558d | 14 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 15 | /***************************** Include Files **********************************/ |
pmallick | 0:3afcd581558d | 16 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 17 | |
pmallick | 0:3afcd581558d | 18 | #include <stdint.h> |
pmallick | 0:3afcd581558d | 19 | #include "app_config.h" |
pmallick | 0:3afcd581558d | 20 | #include "ad7606_support.h" |
pmallick | 0:3afcd581558d | 21 | #include "ad7606_data_capture.h" |
pmallick | 0:3afcd581558d | 22 | |
pmallick | 0:3afcd581558d | 23 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 24 | /********************** Macros and Constants Definition ***********************/ |
pmallick | 0:3afcd581558d | 25 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 26 | |
pmallick | 0:3afcd581558d | 27 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 28 | /********************** Variables and User Defined Data Types *****************/ |
pmallick | 0:3afcd581558d | 29 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 30 | |
pmallick | 0:3afcd581558d | 31 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 32 | /************************ Functions Definitions *******************************/ |
pmallick | 0:3afcd581558d | 33 | /******************************************************************************/ |
pmallick | 0:3afcd581558d | 34 | |
pmallick | 0:3afcd581558d | 35 | /*! |
pmallick | 0:3afcd581558d | 36 | * @brief Function to convert adc raw data into equivalent voltage |
pmallick | 0:3afcd581558d | 37 | * @param adc_raw[in] - ADC raw data |
pmallick | 0:3afcd581558d | 38 | * @param scale[in] - ADC raw to voltage conversion scale |
pmallick | 0:3afcd581558d | 39 | * @return equivalent voltage |
pmallick | 0:3afcd581558d | 40 | */ |
pmallick | 0:3afcd581558d | 41 | float convert_adc_raw_to_voltage(int32_t adc_raw, float scale) |
pmallick | 0:3afcd581558d | 42 | { |
pmallick | 0:3afcd581558d | 43 | float voltage; |
pmallick | 0:3afcd581558d | 44 | |
pmallick | 0:3afcd581558d | 45 | /* Convert adc data into equivalent voltage. |
pmallick | 0:3afcd581558d | 46 | * scale = (chn_range / MAX_ADC_CNT * 1000) as defined in iio_ad7606.c |
pmallick | 0:3afcd581558d | 47 | * */ |
pmallick | 0:3afcd581558d | 48 | voltage = (adc_raw * (scale / 1000)); |
pmallick | 0:3afcd581558d | 49 | |
pmallick | 0:3afcd581558d | 50 | return voltage; |
pmallick | 0:3afcd581558d | 51 | } |
pmallick | 0:3afcd581558d | 52 | |
pmallick | 0:3afcd581558d | 53 | |
pmallick | 0:3afcd581558d | 54 | /*! |
pmallick | 0:3afcd581558d | 55 | * @brief Function to get the polarity of analog input |
pmallick | 0:3afcd581558d | 56 | * @param chn_range_bits[in] - Bits from the channel range register |
pmallick | 0:3afcd581558d | 57 | * @return UNIPOLAR or BIPOLAR |
pmallick | 0:3afcd581558d | 58 | */ |
pmallick | 0:3afcd581558d | 59 | polarity_e ad7606_get_input_polarity(uint8_t chn_range_bits) |
pmallick | 0:3afcd581558d | 60 | { |
pmallick | 0:3afcd581558d | 61 | polarity_e polarity; |
pmallick | 0:3afcd581558d | 62 | |
pmallick | 0:3afcd581558d | 63 | if (chn_range_bits >= AD7606C_UNIPOLAR_RANGE_MIN |
pmallick | 0:3afcd581558d | 64 | && chn_range_bits <= AD7606C_UNIPOLAR_RANGE_MAX) { |
pmallick | 0:3afcd581558d | 65 | polarity = UNIPOLAR; |
pmallick | 0:3afcd581558d | 66 | } else { |
pmallick | 0:3afcd581558d | 67 | polarity = BIPOLAR; |
pmallick | 0:3afcd581558d | 68 | } |
pmallick | 0:3afcd581558d | 69 | |
pmallick | 0:3afcd581558d | 70 | return polarity; |
pmallick | 0:3afcd581558d | 71 | } |
pmallick | 0:3afcd581558d | 72 | |
pmallick | 0:3afcd581558d | 73 | |
pmallick | 0:3afcd581558d | 74 | /*! |
pmallick | 0:3afcd581558d | 75 | * @brief Read the num_of_bytes from previous conversion |
pmallick | 0:3afcd581558d | 76 | * @param dev[in]- Device instance |
pmallick | 0:3afcd581558d | 77 | * @param num_of_bytes[in] - Number of bytes to read from previous conversion |
pmallick | 0:3afcd581558d | 78 | * @return SUCCESS in case of success, FAILURE otherwise |
pmallick | 0:3afcd581558d | 79 | */ |
pmallick | 0:3afcd581558d | 80 | int32_t ad7606_read_conversion_data(struct ad7606_dev *dev, |
pmallick | 0:3afcd581558d | 81 | uint8_t num_of_bytes) |
pmallick | 0:3afcd581558d | 82 | { |
pmallick | 0:3afcd581558d | 83 | memset(dev->data, 0, sizeof(dev->data)); |
pmallick | 0:3afcd581558d | 84 | return spi_write_and_read(dev->spi_desc, dev->data, num_of_bytes); |
pmallick | 0:3afcd581558d | 85 | } |