VL53L3 Shield specific functions.

Dependents:   53L3A2_Ranging X_NUCLEO_53L3CX

Committer:
charlesmn
Date:
Fri Oct 16 15:11:45 2020 +0000
Revision:
0:ba15439f45dd
Child:
1:8afec488fa83
Change VL53L1 to VL53L3. Change name

Who changed what in which revision?

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