A collection of Analog Devices drivers for the mbed platform
Embed:
(wiki syntax)
Show/hide line numbers
EVAL_ADXL362_ARDZ.cpp
Go to the documentation of this file.
00001 /** 00002 * @file EVAL_ADXL362_ARDZ.cpp 00003 * @brief Source file for the EVAL-ADXL362-ARDZ board 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 * Product: www.analog.com/EVAL-ADXL362-ARDZ 00010 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all 00011 00012 ******************************************************************************** 00013 * Copyright 2016(c) Analog Devices, Inc. 00014 * 00015 * All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * - Redistributions of source code must retain the above copyright 00020 * notice, this list of conditions and the following disclaimer. 00021 * - Redistributions in binary form must reproduce the above copyright 00022 * notice, this list of conditions and the following disclaimer in 00023 * the documentation and/or other materials provided with the 00024 * distribution. 00025 * - Neither the name of Analog Devices, Inc. nor the names of its 00026 * contributors may be used to endorse or promote products derived 00027 * from this software without specific prior written permission. 00028 * - The use of this software may or may not infringe the patent rights 00029 * of one or more patent holders. This license does not release you 00030 * from the requirement that you obtain separate licenses from these 00031 * patent holders to use this software. 00032 * - Use of the software either in source or binary form, must be run 00033 * on or directly connected to an Analog Devices Inc. component. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00036 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00037 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00038 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00039 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00040 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00041 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00042 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00043 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00044 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00045 * 00046 ********************************************************************************/ 00047 00048 #include "EVAL_ADXL362_ARDZ.h" 00049 00050 /** 00051 * Constructor for the EVAL_ADXL362_ARDZ 00052 * @param _lcd reference to an LCD object 00053 * @param _adxl362 reference to an ADXL362 object 00054 */ 00055 EVAL_ADXL362_ARDZ::EVAL_ADXL362_ARDZ(Lcd& _lcd, ADXL362& _adxl362) : lcd(_lcd) , adxl362(_adxl362) 00056 { 00057 _x_axis_data = 0; 00058 _y_axis_data = 0; 00059 _z_axis_data = 0; 00060 _t_data = 0; 00061 _lcd_on = 0; 00062 } 00063 00064 /** 00065 * Initial setup of the LCD 00066 */ 00067 void EVAL_ADXL362_ARDZ::LCD_setup() 00068 { 00069 lcd.init(); 00070 } 00071 00072 /** 00073 * Initial setup of the ADXL 00074 */ 00075 void EVAL_ADXL362_ARDZ::ADXL_setup() 00076 { 00077 adxl362.reset(); 00078 wait_us(500); 00079 adxl362.set_activity_threshold(ACT_VAL); 00080 adxl362.set_activity_time(ACT_TIMER / 10); 00081 00082 adxl362.set_inactivity_threshold(INACT_VAL); 00083 adxl362.set_inactivity_time(INACT_TIMER); 00084 adxl362.set_act_inact_ctl_reg(0x3f); 00085 #if(ADXL_INT_SEL == INTACC_PIN_1) 00086 adxl362.set_polling_interrupt1_pin(D2, 0x40); 00087 #elif(ADXL_INT_SEL == INTACC_PIN_2) 00088 adxl362.set_polling_interrupt2_pin(D2, 0x40); /* Map the awake status to INT2 pin */ 00089 #endif 00090 adxl362.set_mode(ADXL362::MEASUREMENT); 00091 _lcd_on = 0; 00092 00093 } 00094 00095 /** 00096 * Method used to scan the ADXL axis data to the internal members 00097 */ 00098 void EVAL_ADXL362_ARDZ::ADXL_scan_xyzt() 00099 { 00100 uint64_t acc = adxl362.scan(); 00101 _x_axis_data = static_cast<uint16_t>((acc & 0xffff000000000000) >> 48); 00102 _y_axis_data = static_cast<uint16_t>((acc & 0x0000ffff00000000) >> 32); 00103 _z_axis_data = static_cast<uint16_t>((acc & 0x00000000ffff0000) >> 16); 00104 _t_data = static_cast<uint16_t> (acc & 0x000000000000ffff); 00105 } 00106 00107 /** 00108 * Gets the status of the interrupt 00109 * @return true if interrupt is active 00110 */ 00111 bool EVAL_ADXL362_ARDZ::ADXL_get_int() 00112 { 00113 #if(ADXL_INT_SEL == INTACC_PIN_1) 00114 return adxl362.get_int1(); 00115 #elif(ADXL_INT_SEL == INTACC_PIN_2) 00116 return adxl362.get_int2(); 00117 #endif 00118 return false; 00119 } 00120 00121 /** 00122 * Displays numeric values on the LCD 00123 */ 00124 void EVAL_ADXL362_ARDZ::LCD_display_values() 00125 { 00126 uint8_t string[22]; 00127 sprintf((char *) string, "x = % 5d", _x_axis_data); 00128 lcd.display_string(0, 0, (int8_t *) string); 00129 00130 sprintf((char *) string, "y = % 5d", _y_axis_data); 00131 lcd.display_string(1, 0, (int8_t *) string); 00132 00133 sprintf((char *) string, "z = % 5d", _z_axis_data); 00134 lcd.display_string(2, 0, (int8_t *) string); 00135 00136 #if TEMP_ADC == 1 00137 sprintf((char *)string, "t = % 5d", _t_data); 00138 lcd.display_string(3, 0, (int8_t *)string); 00139 #else 00140 float f32temp = ((float) _t_data + Lcd::ACC_TEMP_BIAS) 00141 / (1 / Lcd::ACC_TEMP_SENSITIVITY); // -34.625 00142 sprintf((char *) string, "t = % 4.1f", f32temp); 00143 lcd.display_string(3, 0, (int8_t *) string); 00144 #endif 00145 } 00146 00147 /** 00148 * Displays the level meter on the LCD 00149 */ 00150 void EVAL_ADXL362_ARDZ::LCD_display_level() 00151 { 00152 bool any_direction = false; 00153 lcd.display_symbol(0, Lcd::UP_X, 8, Lcd::pui8RecInv8x8); 00154 lcd.display_symbol(2, Lcd::DOWN_X, 8, Lcd::pui8RecInv8x8); 00155 lcd.display_symbol(1, Lcd::LEFT_X, 8, Lcd::pui8RecInv8x8); 00156 lcd.display_symbol(1, Lcd::RIGHT_X, 8, Lcd::pui8RecInv8x8); 00157 00158 if(_x_axis_data > Lcd::ACC_LIMIT) { 00159 lcd.display_symbol(1, Lcd::RIGHT_X, 8, Lcd::pui8Rec8x8); 00160 any_direction = true; 00161 } 00162 if(_x_axis_data < -Lcd::ACC_LIMIT) { 00163 lcd.display_symbol(1, Lcd::LEFT_X, 8, Lcd::pui8Rec8x8); 00164 any_direction = true; 00165 } 00166 if(_y_axis_data > Lcd::ACC_LIMIT) { 00167 lcd.display_symbol(0, Lcd::DOWN_X, 8, Lcd::pui8Rec8x8); 00168 any_direction = true; 00169 } 00170 if(_y_axis_data < -Lcd::ACC_LIMIT) { 00171 lcd.display_symbol(2, Lcd::UP_X, 8, Lcd::pui8Rec8x8); 00172 any_direction = true; 00173 } 00174 if( any_direction ) lcd.display_symbol(1, Lcd::CENTER_X, 8, Lcd::pui8RecInv8x8); 00175 else lcd.display_symbol(1, Lcd::CENTER_X, 8, Lcd::pui8Rec8x8); 00176 00177 } 00178 00179 /** 00180 * Turns on the backlight and draws the static data to the LCD 00181 */ 00182 void EVAL_ADXL362_ARDZ::LCD_init_display() 00183 { 00184 /* Set BLLCD pin - turn on LCD backlight */ 00185 if(_lcd_on == true) return; 00186 lcd.bl_enable(); 00187 00188 lcd.display_string(0, 60, (int8_t *) "[mG]"); 00189 lcd.display_string(1, 60, (int8_t *) "[mG]"); 00190 lcd.display_string(2, 60, (int8_t *) "[mG]"); 00191 00192 #if (TEMP_ADC == 1) 00193 lcd.display_string(3, 60, (int8_t *)"[ADC]"); 00194 #else 00195 lcd.display_string(3, 60, (int8_t *) "[C]"); 00196 #endif 00197 00198 lcd.display_symbol(0, Lcd::UP_X, 8, Lcd::pui8RecInv8x8); 00199 lcd.display_symbol(1, Lcd::LEFT_X, 8, Lcd::pui8RecInv8x8); 00200 lcd.display_symbol(1, Lcd::RIGHT_X, 8, Lcd::pui8RecInv8x8); 00201 lcd.display_symbol(2, Lcd::DOWN_X, 8, Lcd::pui8RecInv8x8); 00202 lcd.display_symbol(1, Lcd::CENTER_X, 8, Lcd::pui8RecInv8x8); 00203 _lcd_on = true; 00204 } 00205 00206 /** 00207 * Turns off the backlight and clears the LCD 00208 */ 00209 void EVAL_ADXL362_ARDZ::LCD_deinit_display() 00210 { 00211 if(_lcd_on == false) return; 00212 /* Clear BLLCD pin - turn off LCD backlight */ 00213 lcd.bl_disable(); 00214 00215 /* Clear screen */ 00216 lcd.fill_pages(0, 4, 0x00); 00217 _lcd_on = false; 00218 } 00219 00220
Generated on Tue Jul 12 2022 17:59:52 by 1.7.2