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
libraries/EVAL_ADXL362_ARDZ/EVAL_ADXL362_ARDZ.cpp@24:dae7123d432a, 2016-05-18 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Wed May 18 16:57:57 2016 +0300
- Revision:
- 24:dae7123d432a
Improved compatibility with Linux systems
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Adrian Suciu |
24:dae7123d432a | 1 | /** |
Adrian Suciu |
24:dae7123d432a | 2 | * @file EVAL_ADXL362_ARDZ.cpp |
Adrian Suciu |
24:dae7123d432a | 3 | * @brief Source file for the EVAL-ADXL362-ARDZ board |
Adrian Suciu |
24:dae7123d432a | 4 | * @author Analog Devices Inc. |
Adrian Suciu |
24:dae7123d432a | 5 | * |
Adrian Suciu |
24:dae7123d432a | 6 | * For support please go to: |
Adrian Suciu |
24:dae7123d432a | 7 | * Github: https://github.com/analogdevicesinc/mbed-adi |
Adrian Suciu |
24:dae7123d432a | 8 | * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers |
Adrian Suciu |
24:dae7123d432a | 9 | * Product: www.analog.com/EVAL-ADXL362-ARDZ |
Adrian Suciu |
24:dae7123d432a | 10 | * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all |
Adrian Suciu |
24:dae7123d432a | 11 | |
Adrian Suciu |
24:dae7123d432a | 12 | ******************************************************************************** |
Adrian Suciu |
24:dae7123d432a | 13 | * Copyright 2016(c) Analog Devices, Inc. |
Adrian Suciu |
24:dae7123d432a | 14 | * |
Adrian Suciu |
24:dae7123d432a | 15 | * All rights reserved. |
Adrian Suciu |
24:dae7123d432a | 16 | * |
Adrian Suciu |
24:dae7123d432a | 17 | * Redistribution and use in source and binary forms, with or without |
Adrian Suciu |
24:dae7123d432a | 18 | * modification, are permitted provided that the following conditions are met: |
Adrian Suciu |
24:dae7123d432a | 19 | * - Redistributions of source code must retain the above copyright |
Adrian Suciu |
24:dae7123d432a | 20 | * notice, this list of conditions and the following disclaimer. |
Adrian Suciu |
24:dae7123d432a | 21 | * - Redistributions in binary form must reproduce the above copyright |
Adrian Suciu |
24:dae7123d432a | 22 | * notice, this list of conditions and the following disclaimer in |
Adrian Suciu |
24:dae7123d432a | 23 | * the documentation and/or other materials provided with the |
Adrian Suciu |
24:dae7123d432a | 24 | * distribution. |
Adrian Suciu |
24:dae7123d432a | 25 | * - Neither the name of Analog Devices, Inc. nor the names of its |
Adrian Suciu |
24:dae7123d432a | 26 | * contributors may be used to endorse or promote products derived |
Adrian Suciu |
24:dae7123d432a | 27 | * from this software without specific prior written permission. |
Adrian Suciu |
24:dae7123d432a | 28 | * - The use of this software may or may not infringe the patent rights |
Adrian Suciu |
24:dae7123d432a | 29 | * of one or more patent holders. This license does not release you |
Adrian Suciu |
24:dae7123d432a | 30 | * from the requirement that you obtain separate licenses from these |
Adrian Suciu |
24:dae7123d432a | 31 | * patent holders to use this software. |
Adrian Suciu |
24:dae7123d432a | 32 | * - Use of the software either in source or binary form, must be run |
Adrian Suciu |
24:dae7123d432a | 33 | * on or directly connected to an Analog Devices Inc. component. |
Adrian Suciu |
24:dae7123d432a | 34 | * |
Adrian Suciu |
24:dae7123d432a | 35 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
Adrian Suciu |
24:dae7123d432a | 36 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
Adrian Suciu |
24:dae7123d432a | 37 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
Adrian Suciu |
24:dae7123d432a | 38 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
Adrian Suciu |
24:dae7123d432a | 39 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
Adrian Suciu |
24:dae7123d432a | 40 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
Adrian Suciu |
24:dae7123d432a | 41 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Adrian Suciu |
24:dae7123d432a | 42 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Adrian Suciu |
24:dae7123d432a | 43 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Adrian Suciu |
24:dae7123d432a | 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Adrian Suciu |
24:dae7123d432a | 45 | * |
Adrian Suciu |
24:dae7123d432a | 46 | ********************************************************************************/ |
Adrian Suciu |
24:dae7123d432a | 47 | |
Adrian Suciu |
24:dae7123d432a | 48 | #include "EVAL_ADXL362_ARDZ.h" |
Adrian Suciu |
24:dae7123d432a | 49 | |
Adrian Suciu |
24:dae7123d432a | 50 | /** |
Adrian Suciu |
24:dae7123d432a | 51 | * Constructor for the EVAL_ADXL362_ARDZ |
Adrian Suciu |
24:dae7123d432a | 52 | * @param _lcd reference to an LCD object |
Adrian Suciu |
24:dae7123d432a | 53 | * @param _adxl362 reference to an ADXL362 object |
Adrian Suciu |
24:dae7123d432a | 54 | */ |
Adrian Suciu |
24:dae7123d432a | 55 | EVAL_ADXL362_ARDZ::EVAL_ADXL362_ARDZ(Lcd& _lcd, ADXL362& _adxl362) : lcd(_lcd) , adxl362(_adxl362) |
Adrian Suciu |
24:dae7123d432a | 56 | { |
Adrian Suciu |
24:dae7123d432a | 57 | _x_axis_data = 0; |
Adrian Suciu |
24:dae7123d432a | 58 | _y_axis_data = 0; |
Adrian Suciu |
24:dae7123d432a | 59 | _z_axis_data = 0; |
Adrian Suciu |
24:dae7123d432a | 60 | _t_data = 0; |
Adrian Suciu |
24:dae7123d432a | 61 | _lcd_on = 0; |
Adrian Suciu |
24:dae7123d432a | 62 | } |
Adrian Suciu |
24:dae7123d432a | 63 | |
Adrian Suciu |
24:dae7123d432a | 64 | /** |
Adrian Suciu |
24:dae7123d432a | 65 | * Initial setup of the LCD |
Adrian Suciu |
24:dae7123d432a | 66 | */ |
Adrian Suciu |
24:dae7123d432a | 67 | void EVAL_ADXL362_ARDZ::LCD_setup() |
Adrian Suciu |
24:dae7123d432a | 68 | { |
Adrian Suciu |
24:dae7123d432a | 69 | lcd.init(); |
Adrian Suciu |
24:dae7123d432a | 70 | } |
Adrian Suciu |
24:dae7123d432a | 71 | |
Adrian Suciu |
24:dae7123d432a | 72 | /** |
Adrian Suciu |
24:dae7123d432a | 73 | * Initial setup of the ADXL |
Adrian Suciu |
24:dae7123d432a | 74 | */ |
Adrian Suciu |
24:dae7123d432a | 75 | void EVAL_ADXL362_ARDZ::ADXL_setup() |
Adrian Suciu |
24:dae7123d432a | 76 | { |
Adrian Suciu |
24:dae7123d432a | 77 | adxl362.reset(); |
Adrian Suciu |
24:dae7123d432a | 78 | wait_us(500); |
Adrian Suciu |
24:dae7123d432a | 79 | adxl362.set_activity_threshold(ACT_VAL); |
Adrian Suciu |
24:dae7123d432a | 80 | adxl362.set_activity_time(ACT_TIMER / 10); |
Adrian Suciu |
24:dae7123d432a | 81 | |
Adrian Suciu |
24:dae7123d432a | 82 | adxl362.set_inactivity_threshold(INACT_VAL); |
Adrian Suciu |
24:dae7123d432a | 83 | adxl362.set_inactivity_time(INACT_TIMER); |
Adrian Suciu |
24:dae7123d432a | 84 | adxl362.set_act_inact_ctl_reg(0x3f); |
Adrian Suciu |
24:dae7123d432a | 85 | #if(ADXL_INT_SEL == INTACC_PIN_1) |
Adrian Suciu |
24:dae7123d432a | 86 | adxl362.set_polling_interrupt1_pin(D2, 0x40); |
Adrian Suciu |
24:dae7123d432a | 87 | #elif(ADXL_INT_SEL == INTACC_PIN_2) |
Adrian Suciu |
24:dae7123d432a | 88 | adxl362.set_polling_interrupt2_pin(D2, 0x40); /* Map the awake status to INT2 pin */ |
Adrian Suciu |
24:dae7123d432a | 89 | #endif |
Adrian Suciu |
24:dae7123d432a | 90 | adxl362.set_mode(ADXL362::MEASUREMENT); |
Adrian Suciu |
24:dae7123d432a | 91 | _lcd_on = 0; |
Adrian Suciu |
24:dae7123d432a | 92 | |
Adrian Suciu |
24:dae7123d432a | 93 | } |
Adrian Suciu |
24:dae7123d432a | 94 | |
Adrian Suciu |
24:dae7123d432a | 95 | /** |
Adrian Suciu |
24:dae7123d432a | 96 | * Method used to scan the ADXL axis data to the internal members |
Adrian Suciu |
24:dae7123d432a | 97 | */ |
Adrian Suciu |
24:dae7123d432a | 98 | void EVAL_ADXL362_ARDZ::ADXL_scan_xyzt() |
Adrian Suciu |
24:dae7123d432a | 99 | { |
Adrian Suciu |
24:dae7123d432a | 100 | uint64_t acc = adxl362.scan(); |
Adrian Suciu |
24:dae7123d432a | 101 | _x_axis_data = static_cast<uint16_t>((acc & 0xffff000000000000) >> 48); |
Adrian Suciu |
24:dae7123d432a | 102 | _y_axis_data = static_cast<uint16_t>((acc & 0x0000ffff00000000) >> 32); |
Adrian Suciu |
24:dae7123d432a | 103 | _z_axis_data = static_cast<uint16_t>((acc & 0x00000000ffff0000) >> 16); |
Adrian Suciu |
24:dae7123d432a | 104 | _t_data = static_cast<uint16_t> (acc & 0x000000000000ffff); |
Adrian Suciu |
24:dae7123d432a | 105 | } |
Adrian Suciu |
24:dae7123d432a | 106 | |
Adrian Suciu |
24:dae7123d432a | 107 | /** |
Adrian Suciu |
24:dae7123d432a | 108 | * Gets the status of the interrupt |
Adrian Suciu |
24:dae7123d432a | 109 | * @return true if interrupt is active |
Adrian Suciu |
24:dae7123d432a | 110 | */ |
Adrian Suciu |
24:dae7123d432a | 111 | bool EVAL_ADXL362_ARDZ::ADXL_get_int() |
Adrian Suciu |
24:dae7123d432a | 112 | { |
Adrian Suciu |
24:dae7123d432a | 113 | #if(ADXL_INT_SEL == INTACC_PIN_1) |
Adrian Suciu |
24:dae7123d432a | 114 | return adxl362.get_int1(); |
Adrian Suciu |
24:dae7123d432a | 115 | #elif(ADXL_INT_SEL == INTACC_PIN_2) |
Adrian Suciu |
24:dae7123d432a | 116 | return adxl362.get_int2(); |
Adrian Suciu |
24:dae7123d432a | 117 | #endif |
Adrian Suciu |
24:dae7123d432a | 118 | return false; |
Adrian Suciu |
24:dae7123d432a | 119 | } |
Adrian Suciu |
24:dae7123d432a | 120 | |
Adrian Suciu |
24:dae7123d432a | 121 | /** |
Adrian Suciu |
24:dae7123d432a | 122 | * Displays numeric values on the LCD |
Adrian Suciu |
24:dae7123d432a | 123 | */ |
Adrian Suciu |
24:dae7123d432a | 124 | void EVAL_ADXL362_ARDZ::LCD_display_values() |
Adrian Suciu |
24:dae7123d432a | 125 | { |
Adrian Suciu |
24:dae7123d432a | 126 | uint8_t string[22]; |
Adrian Suciu |
24:dae7123d432a | 127 | sprintf((char *) string, "x = % 5d", _x_axis_data); |
Adrian Suciu |
24:dae7123d432a | 128 | lcd.display_string(0, 0, (int8_t *) string); |
Adrian Suciu |
24:dae7123d432a | 129 | |
Adrian Suciu |
24:dae7123d432a | 130 | sprintf((char *) string, "y = % 5d", _y_axis_data); |
Adrian Suciu |
24:dae7123d432a | 131 | lcd.display_string(1, 0, (int8_t *) string); |
Adrian Suciu |
24:dae7123d432a | 132 | |
Adrian Suciu |
24:dae7123d432a | 133 | sprintf((char *) string, "z = % 5d", _z_axis_data); |
Adrian Suciu |
24:dae7123d432a | 134 | lcd.display_string(2, 0, (int8_t *) string); |
Adrian Suciu |
24:dae7123d432a | 135 | |
Adrian Suciu |
24:dae7123d432a | 136 | #if TEMP_ADC == 1 |
Adrian Suciu |
24:dae7123d432a | 137 | sprintf((char *)string, "t = % 5d", _t_data); |
Adrian Suciu |
24:dae7123d432a | 138 | lcd.display_string(3, 0, (int8_t *)string); |
Adrian Suciu |
24:dae7123d432a | 139 | #else |
Adrian Suciu |
24:dae7123d432a | 140 | float f32temp = ((float) _t_data + Lcd::ACC_TEMP_BIAS) |
Adrian Suciu |
24:dae7123d432a | 141 | / (1 / Lcd::ACC_TEMP_SENSITIVITY); // -34.625 |
Adrian Suciu |
24:dae7123d432a | 142 | sprintf((char *) string, "t = % 4.1f", f32temp); |
Adrian Suciu |
24:dae7123d432a | 143 | lcd.display_string(3, 0, (int8_t *) string); |
Adrian Suciu |
24:dae7123d432a | 144 | #endif |
Adrian Suciu |
24:dae7123d432a | 145 | } |
Adrian Suciu |
24:dae7123d432a | 146 | |
Adrian Suciu |
24:dae7123d432a | 147 | /** |
Adrian Suciu |
24:dae7123d432a | 148 | * Displays the level meter on the LCD |
Adrian Suciu |
24:dae7123d432a | 149 | */ |
Adrian Suciu |
24:dae7123d432a | 150 | void EVAL_ADXL362_ARDZ::LCD_display_level() |
Adrian Suciu |
24:dae7123d432a | 151 | { |
Adrian Suciu |
24:dae7123d432a | 152 | bool any_direction = false; |
Adrian Suciu |
24:dae7123d432a | 153 | lcd.display_symbol(0, Lcd::UP_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 154 | lcd.display_symbol(2, Lcd::DOWN_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 155 | lcd.display_symbol(1, Lcd::LEFT_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 156 | lcd.display_symbol(1, Lcd::RIGHT_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 157 | |
Adrian Suciu |
24:dae7123d432a | 158 | if(_x_axis_data > Lcd::ACC_LIMIT) { |
Adrian Suciu |
24:dae7123d432a | 159 | lcd.display_symbol(1, Lcd::RIGHT_X, 8, Lcd::pui8Rec8x8); |
Adrian Suciu |
24:dae7123d432a | 160 | any_direction = true; |
Adrian Suciu |
24:dae7123d432a | 161 | } |
Adrian Suciu |
24:dae7123d432a | 162 | if(_x_axis_data < -Lcd::ACC_LIMIT) { |
Adrian Suciu |
24:dae7123d432a | 163 | lcd.display_symbol(1, Lcd::LEFT_X, 8, Lcd::pui8Rec8x8); |
Adrian Suciu |
24:dae7123d432a | 164 | any_direction = true; |
Adrian Suciu |
24:dae7123d432a | 165 | } |
Adrian Suciu |
24:dae7123d432a | 166 | if(_y_axis_data > Lcd::ACC_LIMIT) { |
Adrian Suciu |
24:dae7123d432a | 167 | lcd.display_symbol(0, Lcd::DOWN_X, 8, Lcd::pui8Rec8x8); |
Adrian Suciu |
24:dae7123d432a | 168 | any_direction = true; |
Adrian Suciu |
24:dae7123d432a | 169 | } |
Adrian Suciu |
24:dae7123d432a | 170 | if(_y_axis_data < -Lcd::ACC_LIMIT) { |
Adrian Suciu |
24:dae7123d432a | 171 | lcd.display_symbol(2, Lcd::UP_X, 8, Lcd::pui8Rec8x8); |
Adrian Suciu |
24:dae7123d432a | 172 | any_direction = true; |
Adrian Suciu |
24:dae7123d432a | 173 | } |
Adrian Suciu |
24:dae7123d432a | 174 | if( any_direction ) lcd.display_symbol(1, Lcd::CENTER_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 175 | else lcd.display_symbol(1, Lcd::CENTER_X, 8, Lcd::pui8Rec8x8); |
Adrian Suciu |
24:dae7123d432a | 176 | |
Adrian Suciu |
24:dae7123d432a | 177 | } |
Adrian Suciu |
24:dae7123d432a | 178 | |
Adrian Suciu |
24:dae7123d432a | 179 | /** |
Adrian Suciu |
24:dae7123d432a | 180 | * Turns on the backlight and draws the static data to the LCD |
Adrian Suciu |
24:dae7123d432a | 181 | */ |
Adrian Suciu |
24:dae7123d432a | 182 | void EVAL_ADXL362_ARDZ::LCD_init_display() |
Adrian Suciu |
24:dae7123d432a | 183 | { |
Adrian Suciu |
24:dae7123d432a | 184 | /* Set BLLCD pin - turn on LCD backlight */ |
Adrian Suciu |
24:dae7123d432a | 185 | if(_lcd_on == true) return; |
Adrian Suciu |
24:dae7123d432a | 186 | lcd.bl_enable(); |
Adrian Suciu |
24:dae7123d432a | 187 | |
Adrian Suciu |
24:dae7123d432a | 188 | lcd.display_string(0, 60, (int8_t *) "[mG]"); |
Adrian Suciu |
24:dae7123d432a | 189 | lcd.display_string(1, 60, (int8_t *) "[mG]"); |
Adrian Suciu |
24:dae7123d432a | 190 | lcd.display_string(2, 60, (int8_t *) "[mG]"); |
Adrian Suciu |
24:dae7123d432a | 191 | |
Adrian Suciu |
24:dae7123d432a | 192 | #if (TEMP_ADC == 1) |
Adrian Suciu |
24:dae7123d432a | 193 | lcd.display_string(3, 60, (int8_t *)"[ADC]"); |
Adrian Suciu |
24:dae7123d432a | 194 | #else |
Adrian Suciu |
24:dae7123d432a | 195 | lcd.display_string(3, 60, (int8_t *) "[C]"); |
Adrian Suciu |
24:dae7123d432a | 196 | #endif |
Adrian Suciu |
24:dae7123d432a | 197 | |
Adrian Suciu |
24:dae7123d432a | 198 | lcd.display_symbol(0, Lcd::UP_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 199 | lcd.display_symbol(1, Lcd::LEFT_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 200 | lcd.display_symbol(1, Lcd::RIGHT_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 201 | lcd.display_symbol(2, Lcd::DOWN_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 202 | lcd.display_symbol(1, Lcd::CENTER_X, 8, Lcd::pui8RecInv8x8); |
Adrian Suciu |
24:dae7123d432a | 203 | _lcd_on = true; |
Adrian Suciu |
24:dae7123d432a | 204 | } |
Adrian Suciu |
24:dae7123d432a | 205 | |
Adrian Suciu |
24:dae7123d432a | 206 | /** |
Adrian Suciu |
24:dae7123d432a | 207 | * Turns off the backlight and clears the LCD |
Adrian Suciu |
24:dae7123d432a | 208 | */ |
Adrian Suciu |
24:dae7123d432a | 209 | void EVAL_ADXL362_ARDZ::LCD_deinit_display() |
Adrian Suciu |
24:dae7123d432a | 210 | { |
Adrian Suciu |
24:dae7123d432a | 211 | if(_lcd_on == false) return; |
Adrian Suciu |
24:dae7123d432a | 212 | /* Clear BLLCD pin - turn off LCD backlight */ |
Adrian Suciu |
24:dae7123d432a | 213 | lcd.bl_disable(); |
Adrian Suciu |
24:dae7123d432a | 214 | |
Adrian Suciu |
24:dae7123d432a | 215 | /* Clear screen */ |
Adrian Suciu |
24:dae7123d432a | 216 | lcd.fill_pages(0, 4, 0x00); |
Adrian Suciu |
24:dae7123d432a | 217 | _lcd_on = false; |
Adrian Suciu |
24:dae7123d432a | 218 | } |
Adrian Suciu |
24:dae7123d432a | 219 | |
Adrian Suciu |
24:dae7123d432a | 220 |