Initial release to ST Sw Expansion Team Repo.

Dependencies:   VL53L3CX_mbed

Dependents:   VL53L3CX_Shield_Polling VL53L3CX_Shield_Polling VL53L3CX_Shield_Polling_v5_15 VL53L3_shield_1sensor_polling_Mb515 ... more

Committer:
johnAlexander
Date:
Tue Nov 10 08:43:07 2020 +0000
Revision:
11:cccb5f470785
Parent:
10:12c0dd3cba9b
Child:
12:3596d0435199
Code tidy-up.

Who changed what in which revision?

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