Analog Devices / mbed-drivers

For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all

Committer:
Adrian Suciu
Date:
Tue Apr 19 17:55:14 2016 +0300
Revision:
4:5c1b28aff7e1
Parent:
3:1a8c14043a4e
Driver and application redesign

Who changed what in which revision?

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