Library for the NucleoVl53L1 shield and the Vl53L1
Dependencies: VL53L1
Dependents: VL53L1CB_shield_sensor_polling VL53L1CB_MB2_NoShield_3sensors_interrupt_ranging VL53L1CB_MB5_NoShield_3sensors_interrupt_ranging VL53L1CB_MB5_NoShield_3sensors_interrupt_ranging
XNucleo53L1A2.h@4:924dac74daed, 2020-11-09 (annotated)
- Committer:
- johnAlexander
- Date:
- Mon Nov 09 10:25:21 2020 +0000
- Revision:
- 4:924dac74daed
- Parent:
- XNucleo53L1A1.h@0:00a40f7a4114
- Child:
- 5:25be5ff92db5
Renaming board lib, to match marketing name.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:00a40f7a4114 | 1 | /** |
charlesmn | 0:00a40f7a4114 | 2 | ****************************************************************************** |
johnAlexander | 4:924dac74daed | 3 | * @file XNucleo53L1A2.h |
charlesmn | 0:00a40f7a4114 | 4 | * @author JS |
charlesmn | 0:00a40f7a4114 | 5 | * @version V0.0.1 |
charlesmn | 0:00a40f7a4114 | 6 | * @date 15-January-2019 |
charlesmn | 0:00a40f7a4114 | 7 | * @brief Header file for component XNucleo53L1A1 |
charlesmn | 0:00a40f7a4114 | 8 | ****************************************************************************** |
charlesmn | 0:00a40f7a4114 | 9 | * @attention |
charlesmn | 0:00a40f7a4114 | 10 | * |
charlesmn | 0:00a40f7a4114 | 11 | * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> |
charlesmn | 0:00a40f7a4114 | 12 | * |
charlesmn | 0:00a40f7a4114 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
charlesmn | 0:00a40f7a4114 | 14 | * are permitted provided that the following conditions are met: |
charlesmn | 0:00a40f7a4114 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
charlesmn | 0:00a40f7a4114 | 16 | * this list of conditions and the following disclaimer. |
charlesmn | 0:00a40f7a4114 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
charlesmn | 0:00a40f7a4114 | 18 | * this list of conditions and the following disclaimer in the documentation |
charlesmn | 0:00a40f7a4114 | 19 | * and/or other materials provided with the distribution. |
charlesmn | 0:00a40f7a4114 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
charlesmn | 0:00a40f7a4114 | 21 | * may be used to endorse or promote products derived from this software |
charlesmn | 0:00a40f7a4114 | 22 | * without specific prior written permission. |
charlesmn | 0:00a40f7a4114 | 23 | * |
charlesmn | 0:00a40f7a4114 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
charlesmn | 0:00a40f7a4114 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
charlesmn | 0:00a40f7a4114 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
charlesmn | 0:00a40f7a4114 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
charlesmn | 0:00a40f7a4114 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
charlesmn | 0:00a40f7a4114 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
charlesmn | 0:00a40f7a4114 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
charlesmn | 0:00a40f7a4114 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
charlesmn | 0:00a40f7a4114 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
charlesmn | 0:00a40f7a4114 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
charlesmn | 0:00a40f7a4114 | 34 | * |
charlesmn | 0:00a40f7a4114 | 35 | ****************************************************************************** |
charlesmn | 0:00a40f7a4114 | 36 | */ |
charlesmn | 0:00a40f7a4114 | 37 | |
charlesmn | 0:00a40f7a4114 | 38 | #ifndef __VL53L1_X_NUCLEO_CLASS_H |
charlesmn | 0:00a40f7a4114 | 39 | #define __VL53L1_X_NUCLEO_CLASS_H |
charlesmn | 0:00a40f7a4114 | 40 | |
charlesmn | 0:00a40f7a4114 | 41 | |
charlesmn | 0:00a40f7a4114 | 42 | /* Includes ------------------------------------------------------------------*/ |
charlesmn | 0:00a40f7a4114 | 43 | #include "vl53l1x.h" |
charlesmn | 0:00a40f7a4114 | 44 | #include "Stmpe1600.h" |
charlesmn | 0:00a40f7a4114 | 45 | //#include "DevI2C.h" |
charlesmn | 0:00a40f7a4114 | 46 | #include "ToF_I2C.h" |
charlesmn | 0:00a40f7a4114 | 47 | |
charlesmn | 0:00a40f7a4114 | 48 | |
charlesmn | 0:00a40f7a4114 | 49 | /** New device addresses */ |
charlesmn | 0:00a40f7a4114 | 50 | #define NEW_SENSOR_CENTRE_ADDRESS 0x56 |
charlesmn | 0:00a40f7a4114 | 51 | |
charlesmn | 0:00a40f7a4114 | 52 | #define NEW_SENSOR_LEFT_ADDRESS 0x58 |
charlesmn | 0:00a40f7a4114 | 53 | #define NEW_SENSOR_RIGHT_ADDRESS 0x5a |
charlesmn | 0:00a40f7a4114 | 54 | |
charlesmn | 0:00a40f7a4114 | 55 | |
charlesmn | 0:00a40f7a4114 | 56 | /* Classes--------------------------------------------------------------------*/ |
charlesmn | 0:00a40f7a4114 | 57 | |
charlesmn | 0:00a40f7a4114 | 58 | /* Classes -------------------------------------------------------------------*/ |
johnAlexander | 4:924dac74daed | 59 | /** Class representing the X-NUCLEO-VL53L1A2 expansion board |
charlesmn | 0:00a40f7a4114 | 60 | */ |
johnAlexander | 4:924dac74daed | 61 | class XNucleo53L1A2 |
charlesmn | 0:00a40f7a4114 | 62 | { |
charlesmn | 0:00a40f7a4114 | 63 | public: |
charlesmn | 0:00a40f7a4114 | 64 | /** Constructor 1 |
charlesmn | 0:00a40f7a4114 | 65 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:00a40f7a4114 | 66 | */ |
johnAlexander | 4:924dac74daed | 67 | XNucleo53L1A2(ToF_DevI2C *ext_i2c) : dev_i2c(ext_i2c) |
charlesmn | 0:00a40f7a4114 | 68 | { |
charlesmn | 0:00a40f7a4114 | 69 | |
johnAlexander | 4:924dac74daed | 70 | printf("XNucleo53L1A2 %d z\n",ext_i2c); |
charlesmn | 0:00a40f7a4114 | 71 | stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2)); // U21 |
charlesmn | 0:00a40f7a4114 | 72 | |
charlesmn | 0:00a40f7a4114 | 73 | stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2)); // U19 |
charlesmn | 0:00a40f7a4114 | 74 | |
charlesmn | 0:00a40f7a4114 | 75 | xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic |
charlesmn | 0:00a40f7a4114 | 76 | sensor_centre = new VL53L1X(dev_i2c, xshutdown_centre, A2); |
charlesmn | 0:00a40f7a4114 | 77 | |
charlesmn | 0:00a40f7a4114 | 78 | xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic |
charlesmn | 0:00a40f7a4114 | 79 | sensor_left = new VL53L1X(dev_i2c, xshutdown_left, D8); |
charlesmn | 0:00a40f7a4114 | 80 | |
charlesmn | 0:00a40f7a4114 | 81 | xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic |
charlesmn | 0:00a40f7a4114 | 82 | sensor_right = new VL53L1X(dev_i2c, xshutdown_right, D2); |
charlesmn | 0:00a40f7a4114 | 83 | } |
charlesmn | 0:00a40f7a4114 | 84 | |
charlesmn | 0:00a40f7a4114 | 85 | /** Constructor 2 |
charlesmn | 0:00a40f7a4114 | 86 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:00a40f7a4114 | 87 | * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 88 | * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 89 | * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 90 | * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 91 | */ |
johnAlexander | 4:924dac74daed | 92 | XNucleo53L1A2(ToF_DevI2C *ext_i2c, PinName gpio1_centre, |
charlesmn | 0:00a40f7a4114 | 93 | PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) |
charlesmn | 0:00a40f7a4114 | 94 | { |
charlesmn | 0:00a40f7a4114 | 95 | stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2)); // U21 |
charlesmn | 0:00a40f7a4114 | 96 | |
charlesmn | 0:00a40f7a4114 | 97 | stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2)); // U19 |
charlesmn | 0:00a40f7a4114 | 98 | // printf("ToF_DevI2C constructor %d %d %d %d\n",ext_i2c,gpio1_centre,gpio1_left,gpio1_right); |
charlesmn | 0:00a40f7a4114 | 99 | |
charlesmn | 0:00a40f7a4114 | 100 | xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic |
charlesmn | 0:00a40f7a4114 | 101 | sensor_centre = new VL53L1X(dev_i2c, xshutdown_centre, gpio1_centre); |
charlesmn | 0:00a40f7a4114 | 102 | |
charlesmn | 0:00a40f7a4114 | 103 | xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic |
charlesmn | 0:00a40f7a4114 | 104 | sensor_left = new VL53L1X(dev_i2c, xshutdown_left, gpio1_left); |
charlesmn | 0:00a40f7a4114 | 105 | |
charlesmn | 0:00a40f7a4114 | 106 | xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic |
charlesmn | 0:00a40f7a4114 | 107 | sensor_right = new VL53L1X(dev_i2c, xshutdown_right, gpio1_right); |
charlesmn | 0:00a40f7a4114 | 108 | } |
charlesmn | 0:00a40f7a4114 | 109 | |
charlesmn | 0:00a40f7a4114 | 110 | |
charlesmn | 0:00a40f7a4114 | 111 | /** Destructor |
charlesmn | 0:00a40f7a4114 | 112 | */ |
johnAlexander | 4:924dac74daed | 113 | ~XNucleo53L1A2() |
charlesmn | 0:00a40f7a4114 | 114 | { |
johnAlexander | 4:924dac74daed | 115 | printf("XNucleo53L1A2 destructor \n"); |
charlesmn | 0:00a40f7a4114 | 116 | if (xshutdown_centre != NULL) { |
charlesmn | 0:00a40f7a4114 | 117 | delete xshutdown_centre; |
charlesmn | 0:00a40f7a4114 | 118 | xshutdown_centre = NULL; |
charlesmn | 0:00a40f7a4114 | 119 | } |
charlesmn | 0:00a40f7a4114 | 120 | if (sensor_centre != NULL) { |
charlesmn | 0:00a40f7a4114 | 121 | delete sensor_centre; |
charlesmn | 0:00a40f7a4114 | 122 | sensor_centre = NULL; |
charlesmn | 0:00a40f7a4114 | 123 | } |
charlesmn | 0:00a40f7a4114 | 124 | if (xshutdown_left != NULL) { |
charlesmn | 0:00a40f7a4114 | 125 | delete xshutdown_left; |
charlesmn | 0:00a40f7a4114 | 126 | xshutdown_left = NULL; |
charlesmn | 0:00a40f7a4114 | 127 | } |
charlesmn | 0:00a40f7a4114 | 128 | if (sensor_left != NULL) { |
charlesmn | 0:00a40f7a4114 | 129 | delete sensor_left; |
charlesmn | 0:00a40f7a4114 | 130 | sensor_left = NULL; |
charlesmn | 0:00a40f7a4114 | 131 | } |
charlesmn | 0:00a40f7a4114 | 132 | if (xshutdown_right != NULL) { |
charlesmn | 0:00a40f7a4114 | 133 | delete xshutdown_right; |
charlesmn | 0:00a40f7a4114 | 134 | xshutdown_right = NULL; |
charlesmn | 0:00a40f7a4114 | 135 | } |
charlesmn | 0:00a40f7a4114 | 136 | if (sensor_right != NULL) { |
charlesmn | 0:00a40f7a4114 | 137 | delete sensor_right; |
charlesmn | 0:00a40f7a4114 | 138 | sensor_right = NULL; |
charlesmn | 0:00a40f7a4114 | 139 | } |
charlesmn | 0:00a40f7a4114 | 140 | |
charlesmn | 0:00a40f7a4114 | 141 | delete stmpe1600_exp0; |
charlesmn | 0:00a40f7a4114 | 142 | stmpe1600_exp0 = NULL; |
charlesmn | 0:00a40f7a4114 | 143 | delete stmpe1600_exp1; |
charlesmn | 0:00a40f7a4114 | 144 | stmpe1600_exp1 = NULL; |
charlesmn | 0:00a40f7a4114 | 145 | _instance = NULL; |
charlesmn | 0:00a40f7a4114 | 146 | } |
charlesmn | 0:00a40f7a4114 | 147 | |
charlesmn | 0:00a40f7a4114 | 148 | |
charlesmn | 0:00a40f7a4114 | 149 | /** |
charlesmn | 0:00a40f7a4114 | 150 | * @brief Creates a singleton object instance |
charlesmn | 0:00a40f7a4114 | 151 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:00a40f7a4114 | 152 | * @return Pointer to the object instance |
charlesmn | 0:00a40f7a4114 | 153 | */ |
johnAlexander | 4:924dac74daed | 154 | static XNucleo53L1A2 *instance(ToF_DevI2C *ext_i2c); |
charlesmn | 0:00a40f7a4114 | 155 | |
charlesmn | 0:00a40f7a4114 | 156 | /** |
charlesmn | 0:00a40f7a4114 | 157 | * @brief Creates a singleton object instance |
charlesmn | 0:00a40f7a4114 | 158 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:00a40f7a4114 | 159 | * @param[in] PinName gpio1_centre the pin connected to top sensor INT |
charlesmn | 0:00a40f7a4114 | 160 | * @param[in] PinName gpio1_left the pin connected to left sensor INT |
charlesmn | 0:00a40f7a4114 | 161 | * @param[in] PinName gpio1_right the pin connected to right sensor INT |
charlesmn | 0:00a40f7a4114 | 162 | * @return Pointer to the object instance |
charlesmn | 0:00a40f7a4114 | 163 | */ |
johnAlexander | 4:924dac74daed | 164 | static XNucleo53L1A2 *instance(ToF_DevI2C *ext_i2c, PinName gpio1_centre, |
charlesmn | 0:00a40f7a4114 | 165 | PinName gpio1_left, PinName gpio1_right); |
charlesmn | 0:00a40f7a4114 | 166 | |
charlesmn | 0:00a40f7a4114 | 167 | /** |
charlesmn | 0:00a40f7a4114 | 168 | * @brief Initialize the board and sensors with deft values |
charlesmn | 0:00a40f7a4114 | 169 | * @return 0 on success |
charlesmn | 0:00a40f7a4114 | 170 | */ |
charlesmn | 0:00a40f7a4114 | 171 | int init_board(); |
charlesmn | 0:00a40f7a4114 | 172 | |
charlesmn | 0:00a40f7a4114 | 173 | ToF_DevI2C *dev_i2c; |
charlesmn | 0:00a40f7a4114 | 174 | VL53L1X *sensor_centre; |
charlesmn | 0:00a40f7a4114 | 175 | VL53L1X *sensor_left; |
charlesmn | 0:00a40f7a4114 | 176 | VL53L1X *sensor_right; |
charlesmn | 0:00a40f7a4114 | 177 | Stmpe1600 *stmpe1600_exp0; |
charlesmn | 0:00a40f7a4114 | 178 | Stmpe1600 *stmpe1600_exp1; |
charlesmn | 0:00a40f7a4114 | 179 | Stmpe1600DigiOut *xshutdown_centre; |
charlesmn | 0:00a40f7a4114 | 180 | Stmpe1600DigiOut *xshutdown_left; |
charlesmn | 0:00a40f7a4114 | 181 | Stmpe1600DigiOut *xshutdown_right; |
charlesmn | 0:00a40f7a4114 | 182 | |
charlesmn | 0:00a40f7a4114 | 183 | private: |
johnAlexander | 4:924dac74daed | 184 | static XNucleo53L1A2 *_instance; |
charlesmn | 0:00a40f7a4114 | 185 | }; |
charlesmn | 0:00a40f7a4114 | 186 | |
charlesmn | 0:00a40f7a4114 | 187 | |
charlesmn | 0:00a40f7a4114 | 188 | #endif /* __VL53L1_X_NUCLEO_CLASS_H */ |