A collection of Analog Devices drivers for the mbed platform
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
libraries/AD5270/AD5270.h@33:c3ec596a29c2, 2016-11-07 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Mon Nov 07 16:27:12 2016 +0200
- Revision:
- 33:c3ec596a29c2
- Parent:
- 28:e24b911ddd7c
Added CN0391, CN0396 and CN0397 shields
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Adrian Suciu |
24:dae7123d432a | 1 | /** |
Adrian Suciu |
24:dae7123d432a | 2 | * @file AD5270.h |
Adrian Suciu |
24:dae7123d432a | 3 | * @brief Header file for AD5270 rheostat |
Adrian Suciu |
24:dae7123d432a | 4 | * @author Analog Devices Inc. |
Adrian Suciu |
24:dae7123d432a | 5 | * |
Adrian Suciu |
24:dae7123d432a | 6 | * For support please go to: |
Adrian Suciu |
24:dae7123d432a | 7 | * Github: https://github.com/analogdevicesinc/mbed-adi |
Adrian Suciu |
24:dae7123d432a | 8 | * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers |
Adrian Suciu |
24:dae7123d432a | 9 | * Product: http://www.analog.com/ad5270 |
Adrian Suciu |
24:dae7123d432a | 10 | * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all |
Adrian Suciu |
24:dae7123d432a | 11 | |
Adrian Suciu |
24:dae7123d432a | 12 | ******************************************************************************** |
Adrian Suciu |
24:dae7123d432a | 13 | * Copyright 2016(c) Analog Devices, Inc. |
Adrian Suciu |
24:dae7123d432a | 14 | * |
Adrian Suciu |
24:dae7123d432a | 15 | * All rights reserved. |
Adrian Suciu |
24:dae7123d432a | 16 | * |
Adrian Suciu |
24:dae7123d432a | 17 | * Redistribution and use in source and binary forms, with or without |
Adrian Suciu |
24:dae7123d432a | 18 | * modification, are permitted provided that the following conditions are met: |
Adrian Suciu |
24:dae7123d432a | 19 | * - Redistributions of source code must retain the above copyright |
Adrian Suciu |
24:dae7123d432a | 20 | * notice, this list of conditions and the following disclaimer. |
Adrian Suciu |
24:dae7123d432a | 21 | * - Redistributions in binary form must reproduce the above copyright |
Adrian Suciu |
24:dae7123d432a | 22 | * notice, this list of conditions and the following disclaimer in |
Adrian Suciu |
24:dae7123d432a | 23 | * the documentation and/or other materials provided with the |
Adrian Suciu |
24:dae7123d432a | 24 | * distribution. |
Adrian Suciu |
24:dae7123d432a | 25 | * - Neither the name of Analog Devices, Inc. nor the names of its |
Adrian Suciu |
24:dae7123d432a | 26 | * contributors may be used to endorse or promote products derived |
Adrian Suciu |
24:dae7123d432a | 27 | * from this software without specific prior written permission. |
Adrian Suciu |
24:dae7123d432a | 28 | * - The use of this software may or may not infringe the patent rights |
Adrian Suciu |
24:dae7123d432a | 29 | * of one or more patent holders. This license does not release you |
Adrian Suciu |
24:dae7123d432a | 30 | * from the requirement that you obtain separate licenses from these |
Adrian Suciu |
24:dae7123d432a | 31 | * patent holders to use this software. |
Adrian Suciu |
24:dae7123d432a | 32 | * - Use of the software either in source or binary form, must be run |
Adrian Suciu |
24:dae7123d432a | 33 | * on or directly connected to an Analog Devices Inc. component. |
Adrian Suciu |
24:dae7123d432a | 34 | * |
Adrian Suciu |
24:dae7123d432a | 35 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
Adrian Suciu |
24:dae7123d432a | 36 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
Adrian Suciu |
24:dae7123d432a | 37 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
Adrian Suciu |
24:dae7123d432a | 38 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
Adrian Suciu |
24:dae7123d432a | 39 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
Adrian Suciu |
24:dae7123d432a | 40 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
Adrian Suciu |
24:dae7123d432a | 41 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Adrian Suciu |
24:dae7123d432a | 42 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Adrian Suciu |
24:dae7123d432a | 43 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Adrian Suciu |
24:dae7123d432a | 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Adrian Suciu |
24:dae7123d432a | 45 | * |
Adrian Suciu |
24:dae7123d432a | 46 | ********************************************************************************/ |
Adrian Suciu |
24:dae7123d432a | 47 | |
Adrian Suciu |
24:dae7123d432a | 48 | #ifndef AD5270_H |
Adrian Suciu |
24:dae7123d432a | 49 | #define AD5270_H |
Adrian Suciu |
24:dae7123d432a | 50 | |
Adrian Suciu |
24:dae7123d432a | 51 | #include "mbed.h" |
Adrian Suciu |
24:dae7123d432a | 52 | |
Adrian Suciu |
24:dae7123d432a | 53 | /** |
Adrian Suciu |
24:dae7123d432a | 54 | * @brief Analog Devices AD5270 SPI Digital Rheostat class |
Adrian Suciu |
24:dae7123d432a | 55 | */ |
Adrian Suciu |
24:dae7123d432a | 56 | class AD5270 |
Adrian Suciu |
24:dae7123d432a | 57 | { |
Adrian Suciu |
24:dae7123d432a | 58 | public: |
Adrian Suciu |
24:dae7123d432a | 59 | |
Adrian Suciu |
24:dae7123d432a | 60 | /// AD5270 commands |
Adrian Suciu |
24:dae7123d432a | 61 | typedef enum { |
Adrian Suciu |
24:dae7123d432a | 62 | NO_OP = 0x00, ///< No data |
Adrian Suciu |
24:dae7123d432a | 63 | NO_OP_cmd = 0x0000, ///< 16 bit no data |
Adrian Suciu |
24:dae7123d432a | 64 | WRITE_RDAC = 0x04, ///< Write to the RDAC Register |
Adrian Suciu |
24:dae7123d432a | 65 | READ_RDAC = 0x08, ///< Read from the RDAC Register |
Adrian Suciu |
24:dae7123d432a | 66 | STORE_50TP = 0x0C, ///< Write from RDAC to memory |
Adrian Suciu |
24:dae7123d432a | 67 | SW_RST = 0x10, ///< Software reset to last memory location |
Adrian Suciu |
24:dae7123d432a | 68 | READ_50TP_CONTENTS = 0x14, ///< Read the last memory contents |
Adrian Suciu |
24:dae7123d432a | 69 | READ_50TP_ADDRESS = 0x18, ///< Read the last memory address |
Adrian Suciu |
24:dae7123d432a | 70 | WRITE_CTRL_REG = 0x1C, ///< Write to the control Register |
Adrian Suciu |
24:dae7123d432a | 71 | READ_CTRL_REG = 0x20, ///< Read from the control Register |
Adrian Suciu |
24:dae7123d432a | 72 | SW_SHUTDOWN = 0x24, ///< Software shutdown (0) - Normal, (1) - Shutdown |
Adrian Suciu |
24:dae7123d432a | 73 | HI_Zupper = 0x80, ///< Get the SDO line ready for High Z |
Adrian Suciu |
24:dae7123d432a | 74 | HI_Zlower = 0x01, ///< Puts AD5270 into High Z mode |
Adrian Suciu |
24:dae7123d432a | 75 | HI_Z_Cmd = 0x8001 ///< Puts AD5270 into High Z mode*/ |
Adrian Suciu |
24:dae7123d432a | 76 | } AD5270Commands_t; |
Adrian Suciu |
24:dae7123d432a | 77 | |
Adrian Suciu |
24:dae7123d432a | 78 | typedef enum { |
Adrian Suciu |
24:dae7123d432a | 79 | NORMAL_MODE = 0, |
Adrian Suciu |
24:dae7123d432a | 80 | SHUTDOWN_MODE = 1 |
Adrian Suciu |
24:dae7123d432a | 81 | } AD5270Modes_t; |
Adrian Suciu |
24:dae7123d432a | 82 | |
Adrian Suciu |
24:dae7123d432a | 83 | typedef enum { |
Adrian Suciu |
24:dae7123d432a | 84 | PROGRAM_50TP_ENABLE = 1, |
Adrian Suciu |
24:dae7123d432a | 85 | RDAC_WRITE_PROTECT = 2, |
Adrian Suciu |
24:dae7123d432a | 86 | R_PERFORMANCE_ENABLE = 4, |
Adrian Suciu |
24:dae7123d432a | 87 | MEMORY_PROGRAM_SUCCESFUL = 8 |
Adrian Suciu |
24:dae7123d432a | 88 | } AD5270ControlRegisterBits_t; |
Adrian Suciu |
24:dae7123d432a | 89 | |
Adrian Suciu |
24:dae7123d432a | 90 | // SPI configuration & constructor |
Adrian Suciu |
24:dae7123d432a | 91 | AD5270(PinName CS = SPI_CS, float max_resistance = 20000.0, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK); |
Adrian Suciu |
24:dae7123d432a | 92 | void frequency(int hz); |
Adrian Suciu |
24:dae7123d432a | 93 | |
Adrian Suciu |
24:dae7123d432a | 94 | /* RDAC commands */ |
Adrian Suciu |
24:dae7123d432a | 95 | void write_ctrl_reg(uint8_t data); |
Adrian Suciu |
24:dae7123d432a | 96 | uint8_t read_ctrl_reg(void); |
Adrian Suciu |
24:dae7123d432a | 97 | void change_mode(AD5270Modes_t mode); |
Adrian Suciu |
24:dae7123d432a | 98 | void set_SDO_HiZ(void); |
Adrian Suciu |
24:dae7123d432a | 99 | |
Adrian Suciu |
24:dae7123d432a | 100 | /* Wiper R/W methods*/ |
Adrian Suciu |
24:dae7123d432a | 101 | void reset_RDAC(void); |
Adrian Suciu |
24:dae7123d432a | 102 | void write_wiper_reg(uint16_t data); |
Adrian Suciu |
24:dae7123d432a | 103 | uint16_t read_wiper_reg(void); |
Adrian Suciu |
24:dae7123d432a | 104 | |
Adrian Suciu |
24:dae7123d432a | 105 | |
Adrian Suciu |
24:dae7123d432a | 106 | /* Low level methods */ |
Adrian Suciu |
28:e24b911ddd7c | 107 | uint16_t write_cmd(uint8_t command, uint16_t data = 0x00, bool toggle_cs = true); |
Adrian Suciu |
28:e24b911ddd7c | 108 | uint16_t write_reg(uint16_t data, bool toggle_cs = true); |
Adrian Suciu |
24:dae7123d432a | 109 | |
Adrian Suciu |
24:dae7123d432a | 110 | /* Methods that deal with resistance in float format*/ |
Adrian Suciu |
24:dae7123d432a | 111 | uint16_t calc_RDAC(float resistance); |
Adrian Suciu |
24:dae7123d432a | 112 | float write_RDAC(float resistance); |
Adrian Suciu |
24:dae7123d432a | 113 | float read_RDAC(void); |
Adrian Suciu |
24:dae7123d432a | 114 | float get_max_resistance(void); |
Adrian Suciu |
24:dae7123d432a | 115 | |
Adrian Suciu |
24:dae7123d432a | 116 | /* 50 TP methods */ |
Adrian Suciu |
24:dae7123d432a | 117 | void enable_50TP_programming(void); |
Adrian Suciu |
24:dae7123d432a | 118 | void store_50TP(void); |
Adrian Suciu |
24:dae7123d432a | 119 | void disable_50TP_programming(void); |
Adrian Suciu |
24:dae7123d432a | 120 | uint8_t read_50TP_last_address(void); |
Adrian Suciu |
24:dae7123d432a | 121 | uint16_t read_50TP_memory(uint8_t address); |
Adrian Suciu |
24:dae7123d432a | 122 | |
Adrian Suciu |
28:e24b911ddd7c | 123 | void daisy_chain(uint8_t *buffer, uint8_t size); |
Adrian Suciu |
28:e24b911ddd7c | 124 | |
Adrian Suciu |
24:dae7123d432a | 125 | SPI ad5270; ///< SPI instance of the AD5270 |
Adrian Suciu |
24:dae7123d432a | 126 | DigitalOut cs; ///< DigitalOut instance for the chip select of the AD5270 |
Adrian Suciu |
24:dae7123d432a | 127 | |
Adrian Suciu |
24:dae7123d432a | 128 | private: |
Adrian Suciu |
24:dae7123d432a | 129 | const static int _RESET = 0xff; |
Adrian Suciu |
24:dae7123d432a | 130 | const static int _REG_OPERATION_TIMEOUT = 2; |
Adrian Suciu |
24:dae7123d432a | 131 | const static int _MEMORY_OPERATION_TIMEOUT = 6; |
Adrian Suciu |
24:dae7123d432a | 132 | const static int _WRITE_OPERATION_50TP_TIMEOUT = 350; |
Adrian Suciu |
24:dae7123d432a | 133 | const static int _DUMMY_BYTE = 0xAA; |
Adrian Suciu |
24:dae7123d432a | 134 | const static uint8_t _SPI_MODE = 1; |
Adrian Suciu |
24:dae7123d432a | 135 | float _max_resistance; |
Adrian Suciu |
24:dae7123d432a | 136 | }; |
Adrian Suciu |
24:dae7123d432a | 137 | |
Adrian Suciu |
24:dae7123d432a | 138 | #endif |