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

Committer:
Adrian Suciu
Date:
Fri Apr 29 16:19:00 2016 +0300
Revision:
13:66c8e4ce4ff1
Child:
15:0484cba838c8
Added driver for AD7791 and example for CN0216

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Adrian Suciu 13:66c8e4ce4ff1 1 /**
Adrian Suciu 13:66c8e4ce4ff1 2 * @file ad5270_diag.cpp
Adrian Suciu 13:66c8e4ce4ff1 3 * @brief Source file for the AD5270 wrapper used by the driver diag
Adrian Suciu 13:66c8e4ce4ff1 4 * @author Analog Devices Inc.
Adrian Suciu 13:66c8e4ce4ff1 5 *
Adrian Suciu 13:66c8e4ce4ff1 6 * For support please go to:
Adrian Suciu 13:66c8e4ce4ff1 7 * Github: https://github.com/analogdevicesinc/mbed-adi
Adrian Suciu 13:66c8e4ce4ff1 8 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
Adrian Suciu 13:66c8e4ce4ff1 9 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Adrian Suciu 13:66c8e4ce4ff1 10
Adrian Suciu 13:66c8e4ce4ff1 11 ********************************************************************************
Adrian Suciu 13:66c8e4ce4ff1 12 * Copyright 2016(c) Analog Devices, Inc.
Adrian Suciu 13:66c8e4ce4ff1 13 *
Adrian Suciu 13:66c8e4ce4ff1 14 * All rights reserved.
Adrian Suciu 13:66c8e4ce4ff1 15 *
Adrian Suciu 13:66c8e4ce4ff1 16 * Redistribution and use in source and binary forms, with or without
Adrian Suciu 13:66c8e4ce4ff1 17 * modification, are permitted provided that the following conditions are met:
Adrian Suciu 13:66c8e4ce4ff1 18 * - Redistributions of source code must retain the above copyright
Adrian Suciu 13:66c8e4ce4ff1 19 * notice, this list of conditions and the following disclaimer.
Adrian Suciu 13:66c8e4ce4ff1 20 * - Redistributions in binary form must reproduce the above copyright
Adrian Suciu 13:66c8e4ce4ff1 21 * notice, this list of conditions and the following disclaimer in
Adrian Suciu 13:66c8e4ce4ff1 22 * the documentation and/or other materials provided with the
Adrian Suciu 13:66c8e4ce4ff1 23 * distribution.
Adrian Suciu 13:66c8e4ce4ff1 24 * - Neither the name of Analog Devices, Inc. nor the names of its
Adrian Suciu 13:66c8e4ce4ff1 25 * contributors may be used to endorse or promote products derived
Adrian Suciu 13:66c8e4ce4ff1 26 * from this software without specific prior written permission.
Adrian Suciu 13:66c8e4ce4ff1 27 * - The use of this software may or may not infringe the patent rights
Adrian Suciu 13:66c8e4ce4ff1 28 * of one or more patent holders. This license does not release you
Adrian Suciu 13:66c8e4ce4ff1 29 * from the requirement that you obtain separate licenses from these
Adrian Suciu 13:66c8e4ce4ff1 30 * patent holders to use this software.
Adrian Suciu 13:66c8e4ce4ff1 31 * - Use of the software either in source or binary form, must be run
Adrian Suciu 13:66c8e4ce4ff1 32 * on or directly connected to an Analog Devices Inc. component.
Adrian Suciu 13:66c8e4ce4ff1 33 *
Adrian Suciu 13:66c8e4ce4ff1 34 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
Adrian Suciu 13:66c8e4ce4ff1 35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
Adrian Suciu 13:66c8e4ce4ff1 36 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Adrian Suciu 13:66c8e4ce4ff1 37 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
Adrian Suciu 13:66c8e4ce4ff1 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Adrian Suciu 13:66c8e4ce4ff1 39 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
Adrian Suciu 13:66c8e4ce4ff1 40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Adrian Suciu 13:66c8e4ce4ff1 41 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Adrian Suciu 13:66c8e4ce4ff1 42 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Adrian Suciu 13:66c8e4ce4ff1 43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Adrian Suciu 13:66c8e4ce4ff1 44 *
Adrian Suciu 13:66c8e4ce4ff1 45 ********************************************************************************/
Adrian Suciu 13:66c8e4ce4ff1 46
Adrian Suciu 13:66c8e4ce4ff1 47 #include "ad5270_diag.h"
Adrian Suciu 13:66c8e4ce4ff1 48
Adrian Suciu 13:66c8e4ce4ff1 49 #include "mbed.h"
Adrian Suciu 13:66c8e4ce4ff1 50 #include <stdio.h>
Adrian Suciu 13:66c8e4ce4ff1 51 #include <vector>
Adrian Suciu 13:66c8e4ce4ff1 52 #include <string>
Adrian Suciu 13:66c8e4ce4ff1 53
Adrian Suciu 13:66c8e4ce4ff1 54 extern Serial pc;
Adrian Suciu 13:66c8e4ce4ff1 55 extern vector<string> cmdbuffer;
Adrian Suciu 13:66c8e4ce4ff1 56
Adrian Suciu 13:66c8e4ce4ff1 57 AD5270_Diag::AD5270_Diag(AD5270& ad) : dut(ad)
Adrian Suciu 13:66c8e4ce4ff1 58 {
Adrian Suciu 13:66c8e4ce4ff1 59
Adrian Suciu 13:66c8e4ce4ff1 60 }
Adrian Suciu 13:66c8e4ce4ff1 61 void AD5270_Diag::enable_50TP_programming()
Adrian Suciu 13:66c8e4ce4ff1 62 {
Adrian Suciu 13:66c8e4ce4ff1 63 dut.enable_50TP_programming();
Adrian Suciu 13:66c8e4ce4ff1 64 pc.printf("Enabled 50TP prog");
Adrian Suciu 13:66c8e4ce4ff1 65
Adrian Suciu 13:66c8e4ce4ff1 66 }
Adrian Suciu 13:66c8e4ce4ff1 67 void AD5270_Diag::store_50TP()
Adrian Suciu 13:66c8e4ce4ff1 68 {
Adrian Suciu 13:66c8e4ce4ff1 69 dut.store_50TP();
Adrian Suciu 13:66c8e4ce4ff1 70 pc.printf("50TP stored");
Adrian Suciu 13:66c8e4ce4ff1 71 }
Adrian Suciu 13:66c8e4ce4ff1 72 void AD5270_Diag::disable_50TP_programming()
Adrian Suciu 13:66c8e4ce4ff1 73 {
Adrian Suciu 13:66c8e4ce4ff1 74 dut.disable_50TP_programming();
Adrian Suciu 13:66c8e4ce4ff1 75 pc.printf("Disabled 50TP prog");
Adrian Suciu 13:66c8e4ce4ff1 76 }
Adrian Suciu 13:66c8e4ce4ff1 77
Adrian Suciu 13:66c8e4ce4ff1 78 void AD5270_Diag::write_RDAC()
Adrian Suciu 13:66c8e4ce4ff1 79 {
Adrian Suciu 13:66c8e4ce4ff1 80 float res = strtof(cmdbuffer[1].c_str(), NULL);
Adrian Suciu 13:66c8e4ce4ff1 81 dut.write_RDAC(res);
Adrian Suciu 13:66c8e4ce4ff1 82 pc.printf("Wrote %f", res);
Adrian Suciu 13:66c8e4ce4ff1 83 }
Adrian Suciu 13:66c8e4ce4ff1 84 void AD5270_Diag::read_RDAC()
Adrian Suciu 13:66c8e4ce4ff1 85 {
Adrian Suciu 13:66c8e4ce4ff1 86 pc.printf("Read %f", dut.read_RDAC());
Adrian Suciu 13:66c8e4ce4ff1 87 }
Adrian Suciu 13:66c8e4ce4ff1 88 void AD5270_Diag::write_cmd()
Adrian Suciu 13:66c8e4ce4ff1 89 {
Adrian Suciu 13:66c8e4ce4ff1 90 uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 13:66c8e4ce4ff1 91 uint8_t regVal = strtol(cmdbuffer[2].c_str(), NULL, 16);
Adrian Suciu 13:66c8e4ce4ff1 92 pc.printf("Returned %x: ", dut.write_cmd(reg, regVal));
Adrian Suciu 13:66c8e4ce4ff1 93 }
Adrian Suciu 13:66c8e4ce4ff1 94
Adrian Suciu 13:66c8e4ce4ff1 95 void AD5270_Diag::set_HiZ()
Adrian Suciu 13:66c8e4ce4ff1 96 {
Adrian Suciu 13:66c8e4ce4ff1 97 pc.printf("SDO set to HiZ");
Adrian Suciu 13:66c8e4ce4ff1 98 dut.set_SDO_HiZ();
Adrian Suciu 13:66c8e4ce4ff1 99 }
Adrian Suciu 13:66c8e4ce4ff1 100
Adrian Suciu 13:66c8e4ce4ff1 101 void AD5270_Diag::read_50TP_last_address(void)
Adrian Suciu 13:66c8e4ce4ff1 102 {
Adrian Suciu 13:66c8e4ce4ff1 103 pc.printf("Returned %x:", dut.read_50TP_last_address());
Adrian Suciu 13:66c8e4ce4ff1 104 }
Adrian Suciu 13:66c8e4ce4ff1 105 void AD5270_Diag::read_50TP_memory(void)
Adrian Suciu 13:66c8e4ce4ff1 106 {
Adrian Suciu 13:66c8e4ce4ff1 107 uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 13:66c8e4ce4ff1 108 pc.printf("Returned %x", dut.read_50TP_memory(reg));
Adrian Suciu 13:66c8e4ce4ff1 109 }
Adrian Suciu 13:66c8e4ce4ff1 110
Adrian Suciu 13:66c8e4ce4ff1 111 void AD5270_Diag::write_ctrl_reg(void)
Adrian Suciu 13:66c8e4ce4ff1 112 {
Adrian Suciu 13:66c8e4ce4ff1 113 uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 13:66c8e4ce4ff1 114 dut.write_ctrl_reg(val);
Adrian Suciu 13:66c8e4ce4ff1 115 pc.printf("Wrote %x to ctrl_reg", val );
Adrian Suciu 13:66c8e4ce4ff1 116 }
Adrian Suciu 13:66c8e4ce4ff1 117 void AD5270_Diag::read_ctrl_reg(void)
Adrian Suciu 13:66c8e4ce4ff1 118 {
Adrian Suciu 13:66c8e4ce4ff1 119 pc.printf("Read %x from ctrl_reg", dut.read_ctrl_reg());
Adrian Suciu 13:66c8e4ce4ff1 120 }
Adrian Suciu 13:66c8e4ce4ff1 121
Adrian Suciu 13:66c8e4ce4ff1 122 void AD5270_Diag::reset_RDAC(void)
Adrian Suciu 13:66c8e4ce4ff1 123 {
Adrian Suciu 13:66c8e4ce4ff1 124 dut.reset_RDAC();
Adrian Suciu 13:66c8e4ce4ff1 125 pc.printf("Resetted rdac");
Adrian Suciu 13:66c8e4ce4ff1 126 }
Adrian Suciu 13:66c8e4ce4ff1 127 void AD5270_Diag::change_mode(void)
Adrian Suciu 13:66c8e4ce4ff1 128 {
Adrian Suciu 13:66c8e4ce4ff1 129 uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 13:66c8e4ce4ff1 130 dut.change_mode(static_cast<AD5270::AD5270Modes_t>(val));
Adrian Suciu 13:66c8e4ce4ff1 131 pc.printf("Changed mode to %x", val);
Adrian Suciu 13:66c8e4ce4ff1 132 }
Adrian Suciu 13:66c8e4ce4ff1 133
Adrian Suciu 13:66c8e4ce4ff1 134 void AD5270_Diag::write_wiper_reg(void)
Adrian Suciu 13:66c8e4ce4ff1 135 {
Adrian Suciu 13:66c8e4ce4ff1 136 uint16_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 13:66c8e4ce4ff1 137 dut.write_wiper_reg(val);
Adrian Suciu 13:66c8e4ce4ff1 138 pc.printf("Wrote %x to wiper", val);
Adrian Suciu 13:66c8e4ce4ff1 139 }
Adrian Suciu 13:66c8e4ce4ff1 140 void AD5270_Diag::read_wiper_reg(void)
Adrian Suciu 13:66c8e4ce4ff1 141 {
Adrian Suciu 13:66c8e4ce4ff1 142 pc.printf("Read %x from wiper", dut.read_wiper_reg());
Adrian Suciu 13:66c8e4ce4ff1 143 }