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@8:074d411a56f3, 2021-05-12 (annotated)
- Committer:
- johnAlexander
- Date:
- Wed May 12 08:34:21 2021 +0000
- Revision:
- 8:074d411a56f3
- Parent:
- 6:070884954aae
- Child:
- 10:19994200e31c
Add comment block about interrupt pin setup, for satellite boards.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:00a40f7a4114 | 1 | /** |
charlesmn | 0:00a40f7a4114 | 2 | ****************************************************************************** |
johnAlexander | 6:070884954aae | 3 | * @file XNucleo53L1A2.h |
charlesmn | 0:00a40f7a4114 | 4 | * @author JS |
charlesmn | 0:00a40f7a4114 | 5 | * @version V0.0.1 |
johnAlexander | 8:074d411a56f3 | 6 | * @date 15-January-2021 |
johnAlexander | 6:070884954aae | 7 | * @brief Header file for component XNucleo53L1A2 |
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 | ****************************************************************************** |
johnAlexander | 8:074d411a56f3 | 36 | * |
johnAlexander | 8:074d411a56f3 | 37 | * *** NOTE : By default hardlinks U10, U11, U15 & U18, on the underside of |
johnAlexander | 8:074d411a56f3 | 38 | * the X-NUCELO-53L1A1 expansion board are not made/OFF. |
johnAlexander | 8:074d411a56f3 | 39 | * These links must be made to allow interrupts from the Satellite boards |
johnAlexander | 8:074d411a56f3 | 40 | * to be received. |
johnAlexander | 8:074d411a56f3 | 41 | * U11 and U18 must be made/ON to allow interrupts to be received from the |
johnAlexander | 8:074d411a56f3 | 42 | * INT_L & INT_R positions; or |
johnAlexander | 8:074d411a56f3 | 43 | * U10 and U15 must be made/ON to allow interrupts to be received from the |
johnAlexander | 8:074d411a56f3 | 44 | * Alternate INT_L & INT_R positions. |
johnAlexander | 8:074d411a56f3 | 45 | * The X_NUCLEO_53L1A2 library defaults to use the INT_L/INT_R positions. |
johnAlexander | 8:074d411a56f3 | 46 | * INT_L is available on expansion board Arduino Connector CN5, pin 1 as D8. |
johnAlexander | 8:074d411a56f3 | 47 | * Alternate INT_L is on CN5 Connector pin 2 as D9. |
johnAlexander | 8:074d411a56f3 | 48 | * INT_R is available on expansion board Arduino Connector CN9, pin 3 as D2. |
johnAlexander | 8:074d411a56f3 | 49 | * Alternate INT_R is on CN9 Connector pin 5 as D4. |
johnAlexander | 8:074d411a56f3 | 50 | * The pinouts are shown here : https://developer.mbed.org/components/X-NUCLEO-53L1A2/ |
johnAlexander | 8:074d411a56f3 | 51 | */ |
charlesmn | 0:00a40f7a4114 | 52 | |
johnAlexander | 6:070884954aae | 53 | #ifndef __VL53L1_A2_NUCLEO_CLASS_H |
johnAlexander | 6:070884954aae | 54 | #define __VL53L1_A2_NUCLEO_CLASS_H |
charlesmn | 0:00a40f7a4114 | 55 | |
charlesmn | 0:00a40f7a4114 | 56 | |
charlesmn | 0:00a40f7a4114 | 57 | /* Includes ------------------------------------------------------------------*/ |
charlesmn | 5:25be5ff92db5 | 58 | #include "vl53l1.h" |
charlesmn | 0:00a40f7a4114 | 59 | #include "Stmpe1600.h" |
charlesmn | 0:00a40f7a4114 | 60 | //#include "DevI2C.h" |
charlesmn | 0:00a40f7a4114 | 61 | #include "ToF_I2C.h" |
charlesmn | 0:00a40f7a4114 | 62 | |
charlesmn | 0:00a40f7a4114 | 63 | |
charlesmn | 0:00a40f7a4114 | 64 | /** New device addresses */ |
charlesmn | 0:00a40f7a4114 | 65 | #define NEW_SENSOR_CENTRE_ADDRESS 0x56 |
charlesmn | 0:00a40f7a4114 | 66 | |
charlesmn | 0:00a40f7a4114 | 67 | #define NEW_SENSOR_LEFT_ADDRESS 0x58 |
charlesmn | 0:00a40f7a4114 | 68 | #define NEW_SENSOR_RIGHT_ADDRESS 0x5a |
charlesmn | 0:00a40f7a4114 | 69 | |
charlesmn | 0:00a40f7a4114 | 70 | |
charlesmn | 0:00a40f7a4114 | 71 | /* Classes--------------------------------------------------------------------*/ |
charlesmn | 0:00a40f7a4114 | 72 | |
charlesmn | 0:00a40f7a4114 | 73 | /* Classes -------------------------------------------------------------------*/ |
johnAlexander | 4:924dac74daed | 74 | /** Class representing the X-NUCLEO-VL53L1A2 expansion board |
charlesmn | 0:00a40f7a4114 | 75 | */ |
johnAlexander | 4:924dac74daed | 76 | class XNucleo53L1A2 |
charlesmn | 0:00a40f7a4114 | 77 | { |
charlesmn | 0:00a40f7a4114 | 78 | public: |
charlesmn | 0:00a40f7a4114 | 79 | /** Constructor 1 |
charlesmn | 0:00a40f7a4114 | 80 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:00a40f7a4114 | 81 | */ |
johnAlexander | 4:924dac74daed | 82 | XNucleo53L1A2(ToF_DevI2C *ext_i2c) : dev_i2c(ext_i2c) |
charlesmn | 0:00a40f7a4114 | 83 | { |
charlesmn | 0:00a40f7a4114 | 84 | |
johnAlexander | 4:924dac74daed | 85 | printf("XNucleo53L1A2 %d z\n",ext_i2c); |
charlesmn | 0:00a40f7a4114 | 86 | stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2)); // U21 |
charlesmn | 0:00a40f7a4114 | 87 | |
charlesmn | 0:00a40f7a4114 | 88 | stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2)); // U19 |
charlesmn | 0:00a40f7a4114 | 89 | |
charlesmn | 0:00a40f7a4114 | 90 | xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic |
charlesmn | 5:25be5ff92db5 | 91 | sensor_centre = new VL53L1(dev_i2c, xshutdown_centre, A2); |
charlesmn | 0:00a40f7a4114 | 92 | |
charlesmn | 0:00a40f7a4114 | 93 | xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic |
charlesmn | 5:25be5ff92db5 | 94 | sensor_left = new VL53L1(dev_i2c, xshutdown_left, D8); |
charlesmn | 0:00a40f7a4114 | 95 | |
charlesmn | 0:00a40f7a4114 | 96 | xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic |
charlesmn | 5:25be5ff92db5 | 97 | sensor_right = new VL53L1(dev_i2c, xshutdown_right, D2); |
charlesmn | 0:00a40f7a4114 | 98 | } |
charlesmn | 0:00a40f7a4114 | 99 | |
charlesmn | 0:00a40f7a4114 | 100 | /** Constructor 2 |
charlesmn | 0:00a40f7a4114 | 101 | * @param[in] &i2c device I2C to be used for communication |
johnAlexander | 6:070884954aae | 102 | * @param[in] PinName gpio1_centre Mbed DigitalOut pin name to be used as a centre sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 103 | * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 104 | * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT |
charlesmn | 0:00a40f7a4114 | 105 | */ |
johnAlexander | 4:924dac74daed | 106 | XNucleo53L1A2(ToF_DevI2C *ext_i2c, PinName gpio1_centre, |
charlesmn | 0:00a40f7a4114 | 107 | PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) |
charlesmn | 0:00a40f7a4114 | 108 | { |
charlesmn | 0:00a40f7a4114 | 109 | stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2)); // U21 |
charlesmn | 0:00a40f7a4114 | 110 | |
charlesmn | 0:00a40f7a4114 | 111 | stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2)); // U19 |
charlesmn | 0:00a40f7a4114 | 112 | // printf("ToF_DevI2C constructor %d %d %d %d\n",ext_i2c,gpio1_centre,gpio1_left,gpio1_right); |
charlesmn | 0:00a40f7a4114 | 113 | |
charlesmn | 0:00a40f7a4114 | 114 | xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic |
charlesmn | 5:25be5ff92db5 | 115 | sensor_centre = new VL53L1(dev_i2c, xshutdown_centre, gpio1_centre); |
charlesmn | 0:00a40f7a4114 | 116 | |
charlesmn | 0:00a40f7a4114 | 117 | xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic |
charlesmn | 5:25be5ff92db5 | 118 | sensor_left = new VL53L1(dev_i2c, xshutdown_left, gpio1_left); |
charlesmn | 0:00a40f7a4114 | 119 | |
charlesmn | 0:00a40f7a4114 | 120 | xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic |
charlesmn | 5:25be5ff92db5 | 121 | sensor_right = new VL53L1(dev_i2c, xshutdown_right, gpio1_right); |
charlesmn | 0:00a40f7a4114 | 122 | } |
charlesmn | 0:00a40f7a4114 | 123 | |
charlesmn | 0:00a40f7a4114 | 124 | |
charlesmn | 0:00a40f7a4114 | 125 | /** Destructor |
charlesmn | 0:00a40f7a4114 | 126 | */ |
johnAlexander | 4:924dac74daed | 127 | ~XNucleo53L1A2() |
charlesmn | 0:00a40f7a4114 | 128 | { |
johnAlexander | 4:924dac74daed | 129 | printf("XNucleo53L1A2 destructor \n"); |
charlesmn | 0:00a40f7a4114 | 130 | if (xshutdown_centre != NULL) { |
charlesmn | 0:00a40f7a4114 | 131 | delete xshutdown_centre; |
charlesmn | 0:00a40f7a4114 | 132 | xshutdown_centre = NULL; |
charlesmn | 0:00a40f7a4114 | 133 | } |
charlesmn | 0:00a40f7a4114 | 134 | if (sensor_centre != NULL) { |
charlesmn | 0:00a40f7a4114 | 135 | delete sensor_centre; |
charlesmn | 0:00a40f7a4114 | 136 | sensor_centre = NULL; |
charlesmn | 0:00a40f7a4114 | 137 | } |
charlesmn | 0:00a40f7a4114 | 138 | if (xshutdown_left != NULL) { |
charlesmn | 0:00a40f7a4114 | 139 | delete xshutdown_left; |
charlesmn | 0:00a40f7a4114 | 140 | xshutdown_left = NULL; |
charlesmn | 0:00a40f7a4114 | 141 | } |
charlesmn | 0:00a40f7a4114 | 142 | if (sensor_left != NULL) { |
charlesmn | 0:00a40f7a4114 | 143 | delete sensor_left; |
charlesmn | 0:00a40f7a4114 | 144 | sensor_left = NULL; |
charlesmn | 0:00a40f7a4114 | 145 | } |
charlesmn | 0:00a40f7a4114 | 146 | if (xshutdown_right != NULL) { |
charlesmn | 0:00a40f7a4114 | 147 | delete xshutdown_right; |
charlesmn | 0:00a40f7a4114 | 148 | xshutdown_right = NULL; |
charlesmn | 0:00a40f7a4114 | 149 | } |
charlesmn | 0:00a40f7a4114 | 150 | if (sensor_right != NULL) { |
charlesmn | 0:00a40f7a4114 | 151 | delete sensor_right; |
charlesmn | 0:00a40f7a4114 | 152 | sensor_right = NULL; |
charlesmn | 0:00a40f7a4114 | 153 | } |
charlesmn | 0:00a40f7a4114 | 154 | |
charlesmn | 0:00a40f7a4114 | 155 | delete stmpe1600_exp0; |
charlesmn | 0:00a40f7a4114 | 156 | stmpe1600_exp0 = NULL; |
charlesmn | 0:00a40f7a4114 | 157 | delete stmpe1600_exp1; |
charlesmn | 0:00a40f7a4114 | 158 | stmpe1600_exp1 = NULL; |
charlesmn | 0:00a40f7a4114 | 159 | _instance = NULL; |
charlesmn | 0:00a40f7a4114 | 160 | } |
charlesmn | 0:00a40f7a4114 | 161 | |
charlesmn | 0:00a40f7a4114 | 162 | |
charlesmn | 0:00a40f7a4114 | 163 | /** |
charlesmn | 0:00a40f7a4114 | 164 | * @brief Creates a singleton object instance |
charlesmn | 0:00a40f7a4114 | 165 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:00a40f7a4114 | 166 | * @return Pointer to the object instance |
charlesmn | 0:00a40f7a4114 | 167 | */ |
johnAlexander | 4:924dac74daed | 168 | static XNucleo53L1A2 *instance(ToF_DevI2C *ext_i2c); |
charlesmn | 0:00a40f7a4114 | 169 | |
charlesmn | 0:00a40f7a4114 | 170 | /** |
charlesmn | 0:00a40f7a4114 | 171 | * @brief Creates a singleton object instance |
charlesmn | 0:00a40f7a4114 | 172 | * @param[in] &i2c device I2C to be used for communication |
johnAlexander | 6:070884954aae | 173 | * @param[in] PinName gpio1_centre the pin connected to centre sensor INT |
charlesmn | 0:00a40f7a4114 | 174 | * @param[in] PinName gpio1_left the pin connected to left sensor INT |
charlesmn | 0:00a40f7a4114 | 175 | * @param[in] PinName gpio1_right the pin connected to right sensor INT |
charlesmn | 0:00a40f7a4114 | 176 | * @return Pointer to the object instance |
charlesmn | 0:00a40f7a4114 | 177 | */ |
johnAlexander | 4:924dac74daed | 178 | static XNucleo53L1A2 *instance(ToF_DevI2C *ext_i2c, PinName gpio1_centre, |
charlesmn | 0:00a40f7a4114 | 179 | PinName gpio1_left, PinName gpio1_right); |
charlesmn | 0:00a40f7a4114 | 180 | |
charlesmn | 0:00a40f7a4114 | 181 | /** |
charlesmn | 0:00a40f7a4114 | 182 | * @brief Initialize the board and sensors with deft values |
charlesmn | 0:00a40f7a4114 | 183 | * @return 0 on success |
charlesmn | 0:00a40f7a4114 | 184 | */ |
charlesmn | 0:00a40f7a4114 | 185 | int init_board(); |
charlesmn | 0:00a40f7a4114 | 186 | |
charlesmn | 0:00a40f7a4114 | 187 | ToF_DevI2C *dev_i2c; |
johnAlexander | 6:070884954aae | 188 | |
charlesmn | 5:25be5ff92db5 | 189 | VL53L1 *sensor_centre; |
charlesmn | 5:25be5ff92db5 | 190 | VL53L1 *sensor_left; |
charlesmn | 5:25be5ff92db5 | 191 | VL53L1 *sensor_right; |
johnAlexander | 6:070884954aae | 192 | |
charlesmn | 0:00a40f7a4114 | 193 | Stmpe1600 *stmpe1600_exp0; |
charlesmn | 0:00a40f7a4114 | 194 | Stmpe1600 *stmpe1600_exp1; |
johnAlexander | 6:070884954aae | 195 | |
charlesmn | 0:00a40f7a4114 | 196 | Stmpe1600DigiOut *xshutdown_centre; |
charlesmn | 0:00a40f7a4114 | 197 | Stmpe1600DigiOut *xshutdown_left; |
charlesmn | 0:00a40f7a4114 | 198 | Stmpe1600DigiOut *xshutdown_right; |
charlesmn | 0:00a40f7a4114 | 199 | |
charlesmn | 0:00a40f7a4114 | 200 | private: |
johnAlexander | 4:924dac74daed | 201 | static XNucleo53L1A2 *_instance; |
charlesmn | 0:00a40f7a4114 | 202 | }; |
charlesmn | 0:00a40f7a4114 | 203 | |
charlesmn | 0:00a40f7a4114 | 204 | |
johnAlexander | 6:070884954aae | 205 | #endif /* __VL53L1_A2_NUCLEO_CLASS_H */ |