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