Library for use with VL53L1X, intended to represent the Proximity sensor expansion board with the same name.

Dependencies:   VL53L1X_mbed

Dependents:   HelloWorld_53L1A1 VL53L1A1_Simple_Ranging_With_One_Device VL53L1A1_Simple_Ranging_With_All_Devices VL53L1X_Ranging_With_Multiple_Devices_MbedOS ... more

Committer:
JerrySzczurak
Date:
Mon Jan 28 10:14:22 2019 +0000
Revision:
22:27f00d9b777b
Child:
24:77b414df8b6e
Initial release board class

Who changed what in which revision?

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