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
examples/drvdiag/driver_wrapper/adxl362_diag.cpp@21:a8023e5e97be, 2016-05-17 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Tue May 17 18:15:28 2016 +0300
- Revision:
- 21:a8023e5e97be
- Parent:
- 19:fb92949e59c9
Created EVAL_ADXL362_ARDZ component and restructured code around it
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Adrian Suciu |
19:fb92949e59c9 | 1 | /** |
Adrian Suciu |
19:fb92949e59c9 | 2 | * @file ADXL362_diag.cpp |
Adrian Suciu |
19:fb92949e59c9 | 3 | * @brief Source file for the ADXL362 wrapper used by the driver diag |
Adrian Suciu |
19:fb92949e59c9 | 4 | * @author Analog Devices Inc. |
Adrian Suciu |
19:fb92949e59c9 | 5 | * |
Adrian Suciu |
19:fb92949e59c9 | 6 | * For support please go to: |
Adrian Suciu |
19:fb92949e59c9 | 7 | * Github: https://github.com/analogdevicesinc/mbed-adi |
Adrian Suciu |
19:fb92949e59c9 | 8 | * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers |
Adrian Suciu |
19:fb92949e59c9 | 9 | * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all |
Adrian Suciu |
19:fb92949e59c9 | 10 | |
Adrian Suciu |
19:fb92949e59c9 | 11 | ******************************************************************************** |
Adrian Suciu |
19:fb92949e59c9 | 12 | * Copyright 2016(c) Analog Devices, Inc. |
Adrian Suciu |
19:fb92949e59c9 | 13 | * |
Adrian Suciu |
19:fb92949e59c9 | 14 | * All rights reserved. |
Adrian Suciu |
19:fb92949e59c9 | 15 | * |
Adrian Suciu |
19:fb92949e59c9 | 16 | * Redistribution and use in source and binary forms, with or without |
Adrian Suciu |
19:fb92949e59c9 | 17 | * modification, are permitted provided that the following conditions are met: |
Adrian Suciu |
19:fb92949e59c9 | 18 | * - Redistributions of source code must retain the above copyright |
Adrian Suciu |
19:fb92949e59c9 | 19 | * notice, this list of conditions and the following disclaimer. |
Adrian Suciu |
19:fb92949e59c9 | 20 | * - Redistributions in binary form must reproduce the above copyright |
Adrian Suciu |
19:fb92949e59c9 | 21 | * notice, this list of conditions and the following disclaimer in |
Adrian Suciu |
19:fb92949e59c9 | 22 | * the documentation and/or other materials provided with the |
Adrian Suciu |
19:fb92949e59c9 | 23 | * distribution. |
Adrian Suciu |
19:fb92949e59c9 | 24 | * - Neither the name of Analog Devices, Inc. nor the names of its |
Adrian Suciu |
19:fb92949e59c9 | 25 | * contributors may be used to endorse or promote products derived |
Adrian Suciu |
19:fb92949e59c9 | 26 | * from this software without specific prior written permission. |
Adrian Suciu |
19:fb92949e59c9 | 27 | * - The use of this software may or may not infringe the patent rights |
Adrian Suciu |
19:fb92949e59c9 | 28 | * of one or more patent holders. This license does not release you |
Adrian Suciu |
19:fb92949e59c9 | 29 | * from the requirement that you obtain separate licenses from these |
Adrian Suciu |
19:fb92949e59c9 | 30 | * patent holders to use this software. |
Adrian Suciu |
19:fb92949e59c9 | 31 | * - Use of the software either in source or binary form, must be run |
Adrian Suciu |
19:fb92949e59c9 | 32 | * on or directly connected to an Analog Devices Inc. component. |
Adrian Suciu |
19:fb92949e59c9 | 33 | * |
Adrian Suciu |
19:fb92949e59c9 | 34 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
Adrian Suciu |
19:fb92949e59c9 | 35 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
Adrian Suciu |
19:fb92949e59c9 | 36 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
Adrian Suciu |
19:fb92949e59c9 | 37 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
Adrian Suciu |
19:fb92949e59c9 | 38 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
Adrian Suciu |
19:fb92949e59c9 | 39 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
Adrian Suciu |
19:fb92949e59c9 | 40 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Adrian Suciu |
19:fb92949e59c9 | 41 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Adrian Suciu |
19:fb92949e59c9 | 42 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Adrian Suciu |
19:fb92949e59c9 | 43 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Adrian Suciu |
19:fb92949e59c9 | 44 | * |
Adrian Suciu |
19:fb92949e59c9 | 45 | ********************************************************************************/ |
Adrian Suciu |
19:fb92949e59c9 | 46 | |
Adrian Suciu |
19:fb92949e59c9 | 47 | #include "mbed.h" |
Adrian Suciu |
19:fb92949e59c9 | 48 | #include <stdio.h> |
Adrian Suciu |
19:fb92949e59c9 | 49 | #include <vector> |
Adrian Suciu |
19:fb92949e59c9 | 50 | #include <string> |
Adrian Suciu |
19:fb92949e59c9 | 51 | #include "ADXL362.h" |
Adrian Suciu |
19:fb92949e59c9 | 52 | #include "ADXL362_diag.h" |
Adrian Suciu |
19:fb92949e59c9 | 53 | |
Adrian Suciu |
19:fb92949e59c9 | 54 | extern Serial pc; |
Adrian Suciu |
19:fb92949e59c9 | 55 | extern vector<string> cmdbuffer; |
Adrian Suciu |
19:fb92949e59c9 | 56 | volatile bool awake; |
Adrian Suciu |
19:fb92949e59c9 | 57 | |
Adrian Suciu |
19:fb92949e59c9 | 58 | ADXL362_Diag::ADXL362_Diag(ADXL362& ad) : |
Adrian Suciu |
19:fb92949e59c9 | 59 | dut(ad) |
Adrian Suciu |
19:fb92949e59c9 | 60 | { |
Adrian Suciu |
19:fb92949e59c9 | 61 | |
Adrian Suciu |
19:fb92949e59c9 | 62 | } |
Adrian Suciu |
19:fb92949e59c9 | 63 | |
Adrian Suciu |
19:fb92949e59c9 | 64 | /** Low level SPI bus comm methods */ |
Adrian Suciu |
19:fb92949e59c9 | 65 | void ADXL362_Diag::reset(void) |
Adrian Suciu |
19:fb92949e59c9 | 66 | { |
Adrian Suciu |
19:fb92949e59c9 | 67 | dut.reset(); |
Adrian Suciu |
19:fb92949e59c9 | 68 | pc.printf("Reseted ADXL362"); |
Adrian Suciu |
19:fb92949e59c9 | 69 | } |
Adrian Suciu |
19:fb92949e59c9 | 70 | |
Adrian Suciu |
19:fb92949e59c9 | 71 | void ADXL362_Diag::write_reg(void) |
Adrian Suciu |
19:fb92949e59c9 | 72 | { |
Adrian Suciu |
19:fb92949e59c9 | 73 | uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16); |
Adrian Suciu |
19:fb92949e59c9 | 74 | uint8_t data = strtol(cmdbuffer[2].c_str(), NULL, 16); |
Adrian Suciu |
19:fb92949e59c9 | 75 | dut.write_reg(static_cast<ADXL362::ADXL362_register_t>(reg), data); |
Adrian Suciu |
19:fb92949e59c9 | 76 | pc.printf("Wrote reg"); |
Adrian Suciu |
19:fb92949e59c9 | 77 | } |
Adrian Suciu |
19:fb92949e59c9 | 78 | |
Adrian Suciu |
19:fb92949e59c9 | 79 | void ADXL362_Diag::read_reg(void) |
Adrian Suciu |
19:fb92949e59c9 | 80 | { |
Adrian Suciu |
19:fb92949e59c9 | 81 | uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16); |
Adrian Suciu |
19:fb92949e59c9 | 82 | uint8_t data = dut.read_reg(static_cast<ADXL362::ADXL362_register_t>(reg)); |
Adrian Suciu |
19:fb92949e59c9 | 83 | pc.printf("Read %x ", data); |
Adrian Suciu |
19:fb92949e59c9 | 84 | } |
Adrian Suciu |
19:fb92949e59c9 | 85 | |
Adrian Suciu |
19:fb92949e59c9 | 86 | void ADXL362_Diag::scan(void) |
Adrian Suciu |
19:fb92949e59c9 | 87 | { |
Adrian Suciu |
19:fb92949e59c9 | 88 | uint64_t data; |
Adrian Suciu |
19:fb92949e59c9 | 89 | data = dut.scan(); |
Adrian Suciu |
19:fb92949e59c9 | 90 | pc.printf("Data: %x", data); |
Adrian Suciu |
19:fb92949e59c9 | 91 | } |
Adrian Suciu |
19:fb92949e59c9 | 92 | |
Adrian Suciu |
19:fb92949e59c9 | 93 | void ADXL362_Diag::read_status(void) |
Adrian Suciu |
19:fb92949e59c9 | 94 | { |
Adrian Suciu |
19:fb92949e59c9 | 95 | uint8_t data = dut.read_status(); |
Adrian Suciu |
19:fb92949e59c9 | 96 | pc.printf("Status - %x reg", data); |
Adrian Suciu |
19:fb92949e59c9 | 97 | } |
Adrian Suciu |
19:fb92949e59c9 | 98 | |
Adrian Suciu |
19:fb92949e59c9 | 99 | void ADXL362_Diag::write_ctl(void) |
Adrian Suciu |
19:fb92949e59c9 | 100 | { |
Adrian Suciu |
19:fb92949e59c9 | 101 | uint8_t data = strtol(cmdbuffer[1].c_str(), NULL, 16); |
Adrian Suciu |
19:fb92949e59c9 | 102 | |
Adrian Suciu |
19:fb92949e59c9 | 103 | dut.set_power_ctl_reg(data); |
Adrian Suciu |
19:fb92949e59c9 | 104 | pc.printf("Wrote reg %x", data); |
Adrian Suciu |
19:fb92949e59c9 | 105 | } |
Adrian Suciu |
19:fb92949e59c9 | 106 | |
Adrian Suciu |
19:fb92949e59c9 | 107 | void ADXL362_Diag::write_ftl(void) |
Adrian Suciu |
19:fb92949e59c9 | 108 | { |
Adrian Suciu |
19:fb92949e59c9 | 109 | uint8_t data = strtol(cmdbuffer[1].c_str(), NULL, 16); |
Adrian Suciu |
19:fb92949e59c9 | 110 | |
Adrian Suciu |
19:fb92949e59c9 | 111 | dut.set_filter_ctl_reg(data); |
Adrian Suciu |
19:fb92949e59c9 | 112 | pc.printf("Wrote reg %x", data); |
Adrian Suciu |
19:fb92949e59c9 | 113 | } |
Adrian Suciu |
19:fb92949e59c9 | 114 | |
Adrian Suciu |
19:fb92949e59c9 | 115 | void ADXL362_Diag::fifo_read_nr_of_entries(void) |
Adrian Suciu |
19:fb92949e59c9 | 116 | { |
Adrian Suciu |
19:fb92949e59c9 | 117 | uint16_t data = dut.fifo_read_nr_of_entries(); |
Adrian Suciu |
19:fb92949e59c9 | 118 | pc.printf("fifo entries - %d ", data); |
Adrian Suciu |
19:fb92949e59c9 | 119 | } |
Adrian Suciu |
19:fb92949e59c9 | 120 | void ADXL362_Diag::fifo_setup(void) |
Adrian Suciu |
19:fb92949e59c9 | 121 | { |
Adrian Suciu |
19:fb92949e59c9 | 122 | uint8_t data = strtol(cmdbuffer[1].c_str(), NULL, 10); |
Adrian Suciu |
19:fb92949e59c9 | 123 | uint16_t entry = strtol(cmdbuffer[2].c_str(), NULL, 10); |
Adrian Suciu |
19:fb92949e59c9 | 124 | dut.fifo_setup(static_cast<bool>(data & 0x04), |
Adrian Suciu |
19:fb92949e59c9 | 125 | static_cast<ADXL362::ADXL362_FIFO_modes_t>(data & 0x03), entry); |
Adrian Suciu |
19:fb92949e59c9 | 126 | pc.printf("Wrote reg"); |
Adrian Suciu |
19:fb92949e59c9 | 127 | } |
Adrian Suciu |
19:fb92949e59c9 | 128 | void ADXL362_Diag::fifo_read_u16(void) |
Adrian Suciu |
19:fb92949e59c9 | 129 | { |
Adrian Suciu |
19:fb92949e59c9 | 130 | uint16_t data = dut.fifo_read_u16(); |
Adrian Suciu |
19:fb92949e59c9 | 131 | pc.printf("fifo entry - %x ", data); |
Adrian Suciu |
19:fb92949e59c9 | 132 | } |
Adrian Suciu |
19:fb92949e59c9 | 133 | void ADXL362_Diag::fifo_scan(void) |
Adrian Suciu |
19:fb92949e59c9 | 134 | { |
Adrian Suciu |
19:fb92949e59c9 | 135 | uint64_t data = dut.fifo_scan(); |
Adrian Suciu |
19:fb92949e59c9 | 136 | pc.printf("fifo scan - %x ", data); |
Adrian Suciu |
19:fb92949e59c9 | 137 | } |
Adrian Suciu |
19:fb92949e59c9 | 138 | |
Adrian Suciu |
21:a8023e5e97be | 139 | void ADXL362_Diag::intinit(void) |
Adrian Suciu |
21:a8023e5e97be | 140 | { |
Adrian Suciu |
21:a8023e5e97be | 141 | |
Adrian Suciu |
21:a8023e5e97be | 142 | dut.reset(); |
Adrian Suciu |
21:a8023e5e97be | 143 | pc.printf("adxl362 reset\r\n"); |
Adrian Suciu |
21:a8023e5e97be | 144 | wait_ms(500); |
Adrian Suciu |
21:a8023e5e97be | 145 | dut.set_activity_threshold(ACT_VAL); |
Adrian Suciu |
21:a8023e5e97be | 146 | dut.set_activity_time(ACT_TIMER / 10); |
Adrian Suciu |
21:a8023e5e97be | 147 | |
Adrian Suciu |
21:a8023e5e97be | 148 | dut.set_inactivity_threshold(INACT_VAL); |
Adrian Suciu |
21:a8023e5e97be | 149 | dut.set_inactivity_time(INACT_TIMER); |
Adrian Suciu |
21:a8023e5e97be | 150 | dut.set_act_inact_ctl_reg(0x3f); |
Adrian Suciu |
21:a8023e5e97be | 151 | |
Adrian Suciu |
21:a8023e5e97be | 152 | pc.printf("adxl362 set activity/inactivity\r\n"); |
Adrian Suciu |
21:a8023e5e97be | 153 | |
Adrian Suciu |
21:a8023e5e97be | 154 | dut.disable_interrupt1(); |
Adrian Suciu |
21:a8023e5e97be | 155 | dut.set_interrupt1_pin(D2, 0x40, &rising_adxl362, &falling_adxl362); |
Adrian Suciu |
21:a8023e5e97be | 156 | |
Adrian Suciu |
21:a8023e5e97be | 157 | awake = true; |
Adrian Suciu |
21:a8023e5e97be | 158 | |
Adrian Suciu |
21:a8023e5e97be | 159 | pc.printf("adxl362 set interrupt\r\n"); |
Adrian Suciu |
21:a8023e5e97be | 160 | dut.enable_interrupt1(); |
Adrian Suciu |
21:a8023e5e97be | 161 | dut.set_mode(ADXL362::MEASUREMENT); |
Adrian Suciu |
21:a8023e5e97be | 162 | pc.printf("adxl362 measurement started\r\n"); |
Adrian Suciu |
21:a8023e5e97be | 163 | } |
Adrian Suciu |
21:a8023e5e97be | 164 | |
Adrian Suciu |
21:a8023e5e97be | 165 | void ADXL362_Diag::checkawake(void) |
Adrian Suciu |
21:a8023e5e97be | 166 | { |
Adrian Suciu |
21:a8023e5e97be | 167 | if(awake) pc.printf("awaken"); |
Adrian Suciu |
21:a8023e5e97be | 168 | else pc.printf("asleep"); |
Adrian Suciu |
21:a8023e5e97be | 169 | } |
Adrian Suciu |
21:a8023e5e97be | 170 | |
Adrian Suciu |
19:fb92949e59c9 | 171 | void rising_adxl362() |
Adrian Suciu |
19:fb92949e59c9 | 172 | { |
Adrian Suciu |
19:fb92949e59c9 | 173 | awake = true; |
Adrian Suciu |
19:fb92949e59c9 | 174 | } |
Adrian Suciu |
19:fb92949e59c9 | 175 | void falling_adxl362() |
Adrian Suciu |
19:fb92949e59c9 | 176 | { |
Adrian Suciu |
19:fb92949e59c9 | 177 | awake = false; |
Adrian Suciu |
19:fb92949e59c9 | 178 | |
Adrian Suciu |
19:fb92949e59c9 | 179 | } |
Adrian Suciu |
19:fb92949e59c9 | 180 |