template libraru
ADxxxx.h@3:ecb47ce6f212, 2019-07-29 (annotated)
- Committer:
- malavikasaji
- Date:
- Mon Jul 29 18:35:19 2019 +0000
- Revision:
- 3:ecb47ce6f212
- Parent:
- 2:1857aa1363ef
Adding license to ADxxxx library files.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
malavikasaji | 3:ecb47ce6f212 | 1 | /***************************************************************************//** |
malavikasaji | 3:ecb47ce6f212 | 2 | * @file AD1234.h |
malavikasaji | 3:ecb47ce6f212 | 3 | * @brief Header file of AD1234 Driver. This driver suppors the following |
malavikasaji | 3:ecb47ce6f212 | 4 | * devices: AD1234R, AD1235R, AD1236R |
malavikasaji | 3:ecb47ce6f212 | 5 | * |
malavikasaji | 3:ecb47ce6f212 | 6 | * @author FirstName LastName (email ID) |
malavikasaji | 3:ecb47ce6f212 | 7 | ******************************************************************************** |
malavikasaji | 3:ecb47ce6f212 | 8 | * Copyright 2013(c) Analog Devices, Inc. |
malavikasaji | 3:ecb47ce6f212 | 9 | * |
malavikasaji | 3:ecb47ce6f212 | 10 | * All rights reserved. |
malavikasaji | 3:ecb47ce6f212 | 11 | * |
malavikasaji | 3:ecb47ce6f212 | 12 | * Redistribution and use in source and binary forms, with or without |
malavikasaji | 3:ecb47ce6f212 | 13 | * modification, |
malavikasaji | 3:ecb47ce6f212 | 14 | * are permitted provided that the following conditions are met: |
malavikasaji | 3:ecb47ce6f212 | 15 | * - Redistributions of source code must retain the above copyright |
malavikasaji | 3:ecb47ce6f212 | 16 | * notice, this list of conditions and the following disclaimer. |
malavikasaji | 3:ecb47ce6f212 | 17 | * - Redistributions in binary form must reproduce the above copyright |
malavikasaji | 3:ecb47ce6f212 | 18 | * notice, this list of conditions and the following disclaimer in |
malavikasaji | 3:ecb47ce6f212 | 19 | * the documentation and/or other materials provided with the |
malavikasaji | 3:ecb47ce6f212 | 20 | * distribution. |
malavikasaji | 3:ecb47ce6f212 | 21 | * - Neither the name of Analog Devices, Inc. nor the names of its |
malavikasaji | 3:ecb47ce6f212 | 22 | * contributors may be used to endorse or promote products derived |
malavikasaji | 3:ecb47ce6f212 | 23 | * from this software without specific prior written permission. |
malavikasaji | 3:ecb47ce6f212 | 24 | * - The use of this software may or may not infringe the patent rights |
malavikasaji | 3:ecb47ce6f212 | 25 | * of one or more patent holders. This license does not release you |
malavikasaji | 3:ecb47ce6f212 | 26 | * from the requirement that you obtain separate licenses from these |
malavikasaji | 3:ecb47ce6f212 | 27 | * patent holders to use this software. |
malavikasaji | 3:ecb47ce6f212 | 28 | * - Use of the software either in source or binary form, must be run |
malavikasaji | 3:ecb47ce6f212 | 29 | * on or directly connected to an Analog Devices Inc. component. |
malavikasaji | 3:ecb47ce6f212 | 30 | * |
malavikasaji | 3:ecb47ce6f212 | 31 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
malavikasaji | 3:ecb47ce6f212 | 32 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
malavikasaji | 3:ecb47ce6f212 | 33 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
malavikasaji | 3:ecb47ce6f212 | 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
malavikasaji | 3:ecb47ce6f212 | 35 | * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
malavikasaji | 3:ecb47ce6f212 | 36 | * * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS |
malavikasaji | 3:ecb47ce6f212 | 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
malavikasaji | 3:ecb47ce6f212 | 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
malavikasaji | 3:ecb47ce6f212 | 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
malavikasaji | 3:ecb47ce6f212 | 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
malavikasaji | 3:ecb47ce6f212 | 41 | * DAMAGE. |
malavikasaji | 3:ecb47ce6f212 | 42 | * |
malavikasaji | 3:ecb47ce6f212 | 43 | *******************************************************************************/ |
MitchAD | 1:9524c69f480d | 44 | #include <stdint.h> |
MitchAD | 1:9524c69f480d | 45 | #include "platform_drivers.h" |
MitchAD | 1:9524c69f480d | 46 | |
MitchAD | 2:1857aa1363ef | 47 | /***Read Write Defines***/ |
MitchAD | 2:1857aa1363ef | 48 | #define ADxxxx_RW 1 /* Read and Write */ |
MitchAD | 2:1857aa1363ef | 49 | #define ADxxxx_R 2 /* Read only */ |
MitchAD | 2:1857aa1363ef | 50 | #define ADxxxx_W 3 /* Write only */ |
MitchAD | 2:1857aa1363ef | 51 | |
MitchAD | 2:1857aa1363ef | 52 | /***Register Defines***/ |
MitchAD | 2:1857aa1363ef | 53 | #define ADXXXX_POW_ON_REG 0x00 |
MitchAD | 2:1857aa1363ef | 54 | #define ADXXXX_POW_REG 0x01 |
MitchAD | 2:1857aa1363ef | 55 | #define ADXXXX_CALIBRATE_REG 0x02 |
MitchAD | 1:9524c69f480d | 56 | |
MitchAD | 2:1857aa1363ef | 57 | |
MitchAD | 2:1857aa1363ef | 58 | #define ADXXXX_REG_NUM 3 /*Number of registers*/ |
MitchAD | 2:1857aa1363ef | 59 | |
MitchAD | 2:1857aa1363ef | 60 | #define ADXXXX_POW_FULL 0x04 |
MitchAD | 2:1857aa1363ef | 61 | #define ADXXXX_POW_MED 0x03 |
MitchAD | 2:1857aa1363ef | 62 | #define ADXXXX_POW_LOW 0x02 |
MitchAD | 2:1857aa1363ef | 63 | #define ADXXXX_POW_IDLE 0x01 |
MitchAD | 2:1857aa1363ef | 64 | |
MitchAD | 2:1857aa1363ef | 65 | #define ADXXXX_CALIBRATED 1 |
MitchAD | 2:1857aa1363ef | 66 | #define ADXXXX_NOT_CALIBRATED 0 |
MitchAD | 1:9524c69f480d | 67 | |
MitchAD | 1:9524c69f480d | 68 | /***Struct Definitions***/ |
MitchAD | 1:9524c69f480d | 69 | |
MitchAD | 1:9524c69f480d | 70 | /*Struct to store values of the following |
MitchAD | 1:9524c69f480d | 71 | four fields of each register*/ |
MitchAD | 1:9524c69f480d | 72 | struct adxxxx_reg { |
MitchAD | 1:9524c69f480d | 73 | int32_t address; |
MitchAD | 1:9524c69f480d | 74 | int32_t value; |
MitchAD | 1:9524c69f480d | 75 | int32_t size; |
MitchAD | 1:9524c69f480d | 76 | int32_t rw; |
MitchAD | 1:9524c69f480d | 77 | }; |
MitchAD | 1:9524c69f480d | 78 | |
MitchAD | 2:1857aa1363ef | 79 | extern struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUM]; |
MitchAD | 1:9524c69f480d | 80 | |
MitchAD | 1:9524c69f480d | 81 | /*Struct to hold ADxxxx Specific Values*/ |
MitchAD | 1:9524c69f480d | 82 | struct adxxxx_descriptor { |
MitchAD | 1:9524c69f480d | 83 | spi_desc *spi_desc; /*SPI Descriptor*/ |
MitchAD | 1:9524c69f480d | 84 | i2c_desc *i2c_desc; /*I2C Descriptor*/ |
MitchAD | 1:9524c69f480d | 85 | struct adxxxx_reg *all_regs; /*Array of Register Structs*/ |
MitchAD | 1:9524c69f480d | 86 | /*Any other fields you want can go |
MitchAD | 1:9524c69f480d | 87 | below, some examples are provided*/ |
MitchAD | 2:1857aa1363ef | 88 | uint8_t is_calibrated; /*EXAMPLES*/ |
MitchAD | 2:1857aa1363ef | 89 | uint8_t power_level; |
MitchAD | 1:9524c69f480d | 90 | }; |
MitchAD | 1:9524c69f480d | 91 | |
MitchAD | 1:9524c69f480d | 92 | /*Struct to hold adxxxx communication info*/ |
MitchAD | 1:9524c69f480d | 93 | struct adxxxx_init_params { |
MitchAD | 1:9524c69f480d | 94 | spi_init_param spi_init; |
MitchAD | 1:9524c69f480d | 95 | i2c_init_param i2c_params; |
MitchAD | 1:9524c69f480d | 96 | /*Once again, you could put initial |
MitchAD | 1:9524c69f480d | 97 | values here, which the setup |
MitchAD | 1:9524c69f480d | 98 | function changes |
MitchAD | 1:9524c69f480d | 99 | */ |
MitchAD | 1:9524c69f480d | 100 | }; |
MitchAD | 1:9524c69f480d | 101 | |
MitchAD | 1:9524c69f480d | 102 | /***Function Prototypes***/ |
MitchAD | 1:9524c69f480d | 103 | |
MitchAD | 1:9524c69f480d | 104 | /*Function to setup the file descriptor and start serial communication*/ |
MitchAD | 2:1857aa1363ef | 105 | int adxxxx_setup(struct adxxxx_descriptor **device, struct adxxxx_init_params init_param); |
MitchAD | 1:9524c69f480d | 106 | |
MitchAD | 2:1857aa1363ef | 107 | /*Function to write all initial register values*/ |
MitchAD | 2:1857aa1363ef | 108 | int adxxxx_init_regs(struct adxxxx_descriptor *device); |
MitchAD | 1:9524c69f480d | 109 | |
MitchAD | 1:9524c69f480d | 110 | /*Function to read from a register*/ |
MitchAD | 1:9524c69f480d | 111 | int adxxx_read(struct adxxxx_descriptor *device, struct adxxxx_reg* reg); |
MitchAD | 2:1857aa1363ef | 112 | |
MitchAD | 2:1857aa1363ef | 113 | /*Function to write from a register*/ |
MitchAD | 2:1857aa1363ef | 114 | int adxxx_write(struct adxxxx_descriptor *device, struct adxxxx_reg* reg, uint32_t data); |