initial release

Dependencies:   VL53L1X_mbed

Committer:
johnAlexander
Date:
Wed Jul 24 10:38:21 2019 +0000
Revision:
27:afcf740eb7b8
Parent:
24:77b414df8b6e
Updated for mbed coding style guidelines.

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 ------------------------------------------------------------------*/
johnAlexander 27:afcf740eb7b8 43 #include "VL53L1X_Class.h"
JerrySzczurak 22:27f00d9b777b 44 #include "Stmpe1600.h"
JerrySzczurak 22:27f00d9b777b 45 //#include "DevI2C.h"
johnAlexander 27:afcf740eb7b8 46 #include "VL53L1X_I2C.h"
JerrySzczurak 22:27f00d9b777b 47
JerrySzczurak 22:27f00d9b777b 48
JerrySzczurak 22:27f00d9b777b 49 /** New device addresses */
dmathew 24:77b414df8b6e 50 //#define NEW_SENSOR_CENTRE_ADDRESS 0x52
dmathew 24:77b414df8b6e 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 */
johnAlexander 27:afcf740eb7b8 67 XNucleo53L1A1(VL53L1X_DevI2C *ext_i2c) : dev_i2c(ext_i2c)
JerrySzczurak 22:27f00d9b777b 68 {
johnAlexander 27:afcf740eb7b8 69 stmpe1600_exp0 = new Stmpe1600((DevI2C *)ext_i2c, (0x43 * 2)); // U21
JerrySzczurak 22:27f00d9b777b 70
johnAlexander 27:afcf740eb7b8 71 stmpe1600_exp1 = new Stmpe1600((DevI2C *)ext_i2c, (0x42 * 2)); // U19
JerrySzczurak 22:27f00d9b777b 72
johnAlexander 27:afcf740eb7b8 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
johnAlexander 27:afcf740eb7b8 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
johnAlexander 27:afcf740eb7b8 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);
johnAlexander 27:afcf740eb7b8 81 }
johnAlexander 27:afcf740eb7b8 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 */
johnAlexander 27:afcf740eb7b8 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 {
johnAlexander 27:afcf740eb7b8 93 stmpe1600_exp0 = new Stmpe1600((DevI2C *)ext_i2c, (0x43 * 2)); // U21
JerrySzczurak 22:27f00d9b777b 94
johnAlexander 27:afcf740eb7b8 95 stmpe1600_exp1 = new Stmpe1600((DevI2C *)ext_i2c, (0x42 * 2)); // U19
JerrySzczurak 22:27f00d9b777b 96
johnAlexander 27:afcf740eb7b8 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
johnAlexander 27:afcf740eb7b8 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
johnAlexander 27:afcf740eb7b8 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);
johnAlexander 27:afcf740eb7b8 105 }
johnAlexander 27:afcf740eb7b8 106
johnAlexander 27:afcf740eb7b8 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 */
johnAlexander 27:afcf740eb7b8 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 */
johnAlexander 27:afcf740eb7b8 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();
johnAlexander 27:afcf740eb7b8 168
johnAlexander 27:afcf740eb7b8 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;
johnAlexander 27:afcf740eb7b8 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
dmathew 24:77b414df8b6e 184 #endif /* __VL53L1_X_NUCLEO_CLASS_H */