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:
Thu Apr 21 18:01:41 2016 +0300
Revision:
11:2e67c719ce37
Fixed filename case sensitivity issues

Who changed what in which revision?

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