A collection of Analog Devices drivers for the mbed platform
Embed:
(wiki syntax)
Show/hide line numbers
ADXL362_Diag.cpp
00001 /** 00002 * @file ADXL362_diag.cpp 00003 * @brief Source file for the ADXL362 wrapper used by the driver diag 00004 * @author Analog Devices Inc. 00005 * 00006 * For support please go to: 00007 * Github: https://github.com/analogdevicesinc/mbed-adi 00008 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers 00009 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all 00010 00011 ******************************************************************************** 00012 * Copyright 2016(c) Analog Devices, Inc. 00013 * 00014 * All rights reserved. 00015 * 00016 * Redistribution and use in source and binary forms, with or without 00017 * modification, are permitted provided that the following conditions are met: 00018 * - Redistributions of source code must retain the above copyright 00019 * notice, this list of conditions and the following disclaimer. 00020 * - Redistributions in binary form must reproduce the above copyright 00021 * notice, this list of conditions and the following disclaimer in 00022 * the documentation and/or other materials provided with the 00023 * distribution. 00024 * - Neither the name of Analog Devices, Inc. nor the names of its 00025 * contributors may be used to endorse or promote products derived 00026 * from this software without specific prior written permission. 00027 * - The use of this software may or may not infringe the patent rights 00028 * of one or more patent holders. This license does not release you 00029 * from the requirement that you obtain separate licenses from these 00030 * patent holders to use this software. 00031 * - Use of the software either in source or binary form, must be run 00032 * on or directly connected to an Analog Devices Inc. component. 00033 * 00034 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00035 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00036 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00037 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00038 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00039 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00040 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00041 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00042 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00043 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00044 * 00045 ********************************************************************************/ 00046 00047 #include "mbed.h" 00048 #include <stdio.h> 00049 #include <vector> 00050 #include <string> 00051 #include "ADXL362.h" 00052 #include "ADXL362_Diag.h" 00053 00054 extern Serial pc; 00055 extern vector<string> cmdbuffer; 00056 volatile bool awake; 00057 00058 ADXL362_Diag::ADXL362_Diag(ADXL362& ad) : 00059 dut(ad) 00060 { 00061 00062 } 00063 00064 /** Low level SPI bus comm methods */ 00065 void ADXL362_Diag::reset(void) 00066 { 00067 dut.reset(); 00068 pc.printf("Reseted ADXL362"); 00069 } 00070 00071 void ADXL362_Diag::write_reg(void) 00072 { 00073 uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16); 00074 uint8_t data = strtol(cmdbuffer[2].c_str(), NULL, 16); 00075 dut.write_reg(static_cast<ADXL362::ADXL362_register_t>(reg), data); 00076 pc.printf("Wrote reg"); 00077 } 00078 00079 void ADXL362_Diag::read_reg(void) 00080 { 00081 uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16); 00082 uint8_t data = dut.read_reg(static_cast<ADXL362::ADXL362_register_t>(reg)); 00083 pc.printf("Read %x ", data); 00084 } 00085 00086 void ADXL362_Diag::scan(void) 00087 { 00088 uint64_t data; 00089 data = dut.scan(); 00090 pc.printf("Data: %x", data); 00091 } 00092 00093 void ADXL362_Diag::read_status(void) 00094 { 00095 uint8_t data = dut.read_status(); 00096 pc.printf("Status - %x reg", data); 00097 } 00098 00099 void ADXL362_Diag::write_ctl(void) 00100 { 00101 uint8_t data = strtol(cmdbuffer[1].c_str(), NULL, 16); 00102 00103 dut.set_power_ctl_reg(data); 00104 pc.printf("Wrote reg %x", data); 00105 } 00106 00107 void ADXL362_Diag::write_ftl(void) 00108 { 00109 uint8_t data = strtol(cmdbuffer[1].c_str(), NULL, 16); 00110 00111 dut.set_filter_ctl_reg(data); 00112 pc.printf("Wrote reg %x", data); 00113 } 00114 00115 void ADXL362_Diag::fifo_read_nr_of_entries(void) 00116 { 00117 uint16_t data = dut.fifo_read_nr_of_entries(); 00118 pc.printf("fifo entries - %d ", data); 00119 } 00120 void ADXL362_Diag::fifo_setup(void) 00121 { 00122 uint8_t data = strtol(cmdbuffer[1].c_str(), NULL, 10); 00123 uint16_t entry = strtol(cmdbuffer[2].c_str(), NULL, 10); 00124 dut.fifo_setup(static_cast<bool>(data & 0x04), 00125 static_cast<ADXL362::ADXL362_FIFO_modes_t>(data & 0x03), entry); 00126 pc.printf("Wrote reg"); 00127 } 00128 void ADXL362_Diag::fifo_read_u16(void) 00129 { 00130 uint16_t data = dut.fifo_read_u16(); 00131 pc.printf("fifo entry - %x ", data); 00132 } 00133 void ADXL362_Diag::fifo_scan(void) 00134 { 00135 uint64_t data = dut.fifo_scan(); 00136 pc.printf("fifo scan - %x ", data); 00137 } 00138 00139 void ADXL362_Diag::intinit(void) 00140 { 00141 00142 dut.reset(); 00143 pc.printf("adxl362 reset\r\n"); 00144 wait_ms(500); 00145 dut.set_activity_threshold(ACT_VAL); 00146 dut.set_activity_time(ACT_TIMER / 10); 00147 00148 dut.set_inactivity_threshold(INACT_VAL); 00149 dut.set_inactivity_time(INACT_TIMER); 00150 dut.set_act_inact_ctl_reg(0x3f); 00151 00152 pc.printf("adxl362 set activity/inactivity\r\n"); 00153 00154 dut.disable_interrupt1(); 00155 dut.set_interrupt1_pin(D2, 0x40, &rising_adxl362, &falling_adxl362); 00156 00157 awake = true; 00158 00159 pc.printf("adxl362 set interrupt\r\n"); 00160 dut.enable_interrupt1(); 00161 dut.set_mode(ADXL362::MEASUREMENT); 00162 pc.printf("adxl362 measurement started\r\n"); 00163 } 00164 00165 void ADXL362_Diag::checkawake(void) 00166 { 00167 if(awake) pc.printf("awaken"); 00168 else pc.printf("asleep"); 00169 } 00170 00171 void rising_adxl362() 00172 { 00173 awake = true; 00174 } 00175 void falling_adxl362() 00176 { 00177 awake = false; 00178 00179 } 00180
Generated on Tue Jul 12 2022 17:59:52 by 1.7.2