Restructure of expansion board lib, moving files & folders.
Dependents: J_53L3_shield_single_polling_Mb515
XNucleo53L3A2.h@7:c0e18dd78c42, 2020-11-04 (annotated)
- Committer:
- johnAlexander
- Date:
- Wed Nov 04 10:01:32 2020 +0000
- Revision:
- 7:c0e18dd78c42
- Parent:
- XNucleo53LX.h@3:4ed68a07058d
Rename board library, to match printed board, and repo, name.
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 | 3:4ed68a07058d | 45 | #include <vl53lx_class.h> |
johnAlexander | 3:4ed68a07058d | 46 | #include "Stmpe1600.h" |
johnAlexander | 3:4ed68a07058d | 47 | //#include "DevI2C.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 0x52 |
johnAlexander | 3:4ed68a07058d | 53 | //#define NEW_SENSOR_CENTRE_ADDRESS 0x54 |
johnAlexander | 3:4ed68a07058d | 54 | ///#define NEW_SENSOR_LEFT_ADDRESS 0x54 |
johnAlexander | 3:4ed68a07058d | 55 | ///#define NEW_SENSOR_RIGHT_ADDRESS 0x56 |
johnAlexander | 3:4ed68a07058d | 56 | |
johnAlexander | 3:4ed68a07058d | 57 | |
johnAlexander | 3:4ed68a07058d | 58 | #define NEW_SENSOR_CENTRE_ADDRESS 0x56 |
johnAlexander | 3:4ed68a07058d | 59 | |
johnAlexander | 3:4ed68a07058d | 60 | #define NEW_SENSOR_LEFT_ADDRESS 0x58 |
johnAlexander | 3:4ed68a07058d | 61 | #define NEW_SENSOR_RIGHT_ADDRESS 0x5a |
johnAlexander | 3:4ed68a07058d | 62 | |
johnAlexander | 3:4ed68a07058d | 63 | |
johnAlexander | 3:4ed68a07058d | 64 | /* Classes--------------------------------------------------------------------*/ |
johnAlexander | 3:4ed68a07058d | 65 | |
johnAlexander | 3:4ed68a07058d | 66 | /* Classes -------------------------------------------------------------------*/ |
johnAlexander | 3:4ed68a07058d | 67 | /** Class representing the X-NUCLEO-VL53L1A1 expansion board |
johnAlexander | 3:4ed68a07058d | 68 | */ |
johnAlexander | 7:c0e18dd78c42 | 69 | class XNucleo53L3A2 |
johnAlexander | 3:4ed68a07058d | 70 | { |
johnAlexander | 3:4ed68a07058d | 71 | public: |
johnAlexander | 3:4ed68a07058d | 72 | /** Constructor 1 |
johnAlexander | 3:4ed68a07058d | 73 | * @param[in] &i2c device I2C to be used for communication |
johnAlexander | 3:4ed68a07058d | 74 | */ |
johnAlexander | 7:c0e18dd78c42 | 75 | XNucleo53L3A2(vl53L3_DevI2C *ext_i2c) : dev_i2c(ext_i2c) |
johnAlexander | 3:4ed68a07058d | 76 | { |
johnAlexander | 3:4ed68a07058d | 77 | |
johnAlexander | 7:c0e18dd78c42 | 78 | printf("XNucleo53L3A2 %d z\n",ext_i2c); |
johnAlexander | 3:4ed68a07058d | 79 | stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2)); // U21 |
johnAlexander | 3:4ed68a07058d | 80 | |
johnAlexander | 3:4ed68a07058d | 81 | stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2)); // U19 |
johnAlexander | 3:4ed68a07058d | 82 | |
johnAlexander | 3:4ed68a07058d | 83 | xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic |
johnAlexander | 3:4ed68a07058d | 84 | sensor_centre = new VL53LX(ext_i2c, xshutdown_centre, A2); |
johnAlexander | 3:4ed68a07058d | 85 | |
johnAlexander | 3:4ed68a07058d | 86 | xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic |
johnAlexander | 3:4ed68a07058d | 87 | sensor_left = new VL53LX(dev_i2c, xshutdown_left, D8); |
johnAlexander | 3:4ed68a07058d | 88 | |
johnAlexander | 3:4ed68a07058d | 89 | xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic |
johnAlexander | 3:4ed68a07058d | 90 | sensor_right = new VL53LX(dev_i2c, xshutdown_right, D2); |
johnAlexander | 3:4ed68a07058d | 91 | } |
johnAlexander | 3:4ed68a07058d | 92 | |
johnAlexander | 3:4ed68a07058d | 93 | /** Constructor 2 |
johnAlexander | 3:4ed68a07058d | 94 | * @param[in] &i2c device I2C to be used for communication |
johnAlexander | 3:4ed68a07058d | 95 | * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT |
johnAlexander | 3:4ed68a07058d | 96 | * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT |
johnAlexander | 3:4ed68a07058d | 97 | * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT |
johnAlexander | 3:4ed68a07058d | 98 | * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT |
johnAlexander | 3:4ed68a07058d | 99 | */ |
johnAlexander | 7:c0e18dd78c42 | 100 | XNucleo53L3A2(vl53L3_DevI2C *ext_i2c, PinName gpio1_centre, |
johnAlexander | 3:4ed68a07058d | 101 | PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) |
johnAlexander | 3:4ed68a07058d | 102 | { |
johnAlexander | 3:4ed68a07058d | 103 | stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2)); // U21 |
johnAlexander | 3:4ed68a07058d | 104 | |
johnAlexander | 3:4ed68a07058d | 105 | stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2)); // U19 |
johnAlexander | 3:4ed68a07058d | 106 | printf("vl53L1X_DevI2C constructor %d %d %d %d\n",ext_i2c,gpio1_centre,gpio1_left,gpio1_right); |
johnAlexander | 3:4ed68a07058d | 107 | |
johnAlexander | 3:4ed68a07058d | 108 | xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic |
johnAlexander | 3:4ed68a07058d | 109 | sensor_centre = new VL53LX(dev_i2c, xshutdown_centre, gpio1_centre); |
johnAlexander | 3:4ed68a07058d | 110 | |
johnAlexander | 3:4ed68a07058d | 111 | xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic |
johnAlexander | 3:4ed68a07058d | 112 | sensor_left = new VL53LX(dev_i2c, xshutdown_left, gpio1_left); |
johnAlexander | 3:4ed68a07058d | 113 | |
johnAlexander | 3:4ed68a07058d | 114 | xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic |
johnAlexander | 3:4ed68a07058d | 115 | sensor_right = new VL53LX(dev_i2c, xshutdown_right, gpio1_right); |
johnAlexander | 3:4ed68a07058d | 116 | } |
johnAlexander | 3:4ed68a07058d | 117 | |
johnAlexander | 3:4ed68a07058d | 118 | |
johnAlexander | 3:4ed68a07058d | 119 | /** Destructor |
johnAlexander | 3:4ed68a07058d | 120 | */ |
johnAlexander | 7:c0e18dd78c42 | 121 | ~XNucleo53L3A2() |
johnAlexander | 3:4ed68a07058d | 122 | { |
johnAlexander | 7:c0e18dd78c42 | 123 | printf("XNucleo53L3A2 destructor \n"); |
johnAlexander | 3:4ed68a07058d | 124 | if (xshutdown_centre != NULL) { |
johnAlexander | 3:4ed68a07058d | 125 | delete xshutdown_centre; |
johnAlexander | 3:4ed68a07058d | 126 | xshutdown_centre = NULL; |
johnAlexander | 3:4ed68a07058d | 127 | } |
johnAlexander | 3:4ed68a07058d | 128 | if (sensor_centre != NULL) { |
johnAlexander | 3:4ed68a07058d | 129 | delete sensor_centre; |
johnAlexander | 3:4ed68a07058d | 130 | sensor_centre = NULL; |
johnAlexander | 3:4ed68a07058d | 131 | } |
johnAlexander | 3:4ed68a07058d | 132 | if (xshutdown_left != NULL) { |
johnAlexander | 3:4ed68a07058d | 133 | delete xshutdown_left; |
johnAlexander | 3:4ed68a07058d | 134 | xshutdown_left = NULL; |
johnAlexander | 3:4ed68a07058d | 135 | } |
johnAlexander | 3:4ed68a07058d | 136 | if (sensor_left != NULL) { |
johnAlexander | 3:4ed68a07058d | 137 | delete sensor_left; |
johnAlexander | 3:4ed68a07058d | 138 | sensor_left = NULL; |
johnAlexander | 3:4ed68a07058d | 139 | } |
johnAlexander | 3:4ed68a07058d | 140 | if (xshutdown_right != NULL) { |
johnAlexander | 3:4ed68a07058d | 141 | delete xshutdown_right; |
johnAlexander | 3:4ed68a07058d | 142 | xshutdown_right = NULL; |
johnAlexander | 3:4ed68a07058d | 143 | } |
johnAlexander | 3:4ed68a07058d | 144 | if (sensor_right != NULL) { |
johnAlexander | 3:4ed68a07058d | 145 | delete sensor_right; |
johnAlexander | 3:4ed68a07058d | 146 | sensor_right = NULL; |
johnAlexander | 3:4ed68a07058d | 147 | } |
johnAlexander | 3:4ed68a07058d | 148 | |
johnAlexander | 3:4ed68a07058d | 149 | delete stmpe1600_exp0; |
johnAlexander | 3:4ed68a07058d | 150 | stmpe1600_exp0 = NULL; |
johnAlexander | 3:4ed68a07058d | 151 | delete stmpe1600_exp1; |
johnAlexander | 3:4ed68a07058d | 152 | stmpe1600_exp1 = NULL; |
johnAlexander | 3:4ed68a07058d | 153 | _instance = NULL; |
johnAlexander | 3:4ed68a07058d | 154 | } |
johnAlexander | 3:4ed68a07058d | 155 | |
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 | * @return Pointer to the object instance |
johnAlexander | 3:4ed68a07058d | 161 | */ |
johnAlexander | 7:c0e18dd78c42 | 162 | static XNucleo53L3A2 *instance(vl53L3_DevI2C *ext_i2c); |
johnAlexander | 3:4ed68a07058d | 163 | |
johnAlexander | 3:4ed68a07058d | 164 | /** |
johnAlexander | 3:4ed68a07058d | 165 | * @brief Creates a singleton object instance |
johnAlexander | 3:4ed68a07058d | 166 | * @param[in] &i2c device I2C to be used for communication |
johnAlexander | 3:4ed68a07058d | 167 | * @param[in] PinName gpio1_centre the pin connected to top sensor INT |
johnAlexander | 3:4ed68a07058d | 168 | * @param[in] PinName gpio1_left the pin connected to left sensor INT |
johnAlexander | 3:4ed68a07058d | 169 | * @param[in] PinName gpio1_right the pin connected to right sensor INT |
johnAlexander | 3:4ed68a07058d | 170 | * @return Pointer to the object instance |
johnAlexander | 3:4ed68a07058d | 171 | */ |
johnAlexander | 7:c0e18dd78c42 | 172 | static XNucleo53L3A2 *instance(vl53L3_DevI2C *ext_i2c, PinName gpio1_centre, |
johnAlexander | 3:4ed68a07058d | 173 | PinName gpio1_left, PinName gpio1_right); |
johnAlexander | 3:4ed68a07058d | 174 | |
johnAlexander | 3:4ed68a07058d | 175 | /** |
johnAlexander | 3:4ed68a07058d | 176 | * @brief Initialize the board and sensors with deft values |
johnAlexander | 3:4ed68a07058d | 177 | * @return 0 on success |
johnAlexander | 3:4ed68a07058d | 178 | */ |
johnAlexander | 3:4ed68a07058d | 179 | int init_board(); |
johnAlexander | 3:4ed68a07058d | 180 | |
johnAlexander | 3:4ed68a07058d | 181 | vl53L3_DevI2C *dev_i2c; |
johnAlexander | 3:4ed68a07058d | 182 | VL53LX *sensor_centre; |
johnAlexander | 3:4ed68a07058d | 183 | VL53LX *sensor_left; |
johnAlexander | 3:4ed68a07058d | 184 | VL53LX *sensor_right; |
johnAlexander | 3:4ed68a07058d | 185 | Stmpe1600 *stmpe1600_exp0; |
johnAlexander | 3:4ed68a07058d | 186 | Stmpe1600 *stmpe1600_exp1; |
johnAlexander | 3:4ed68a07058d | 187 | Stmpe1600DigiOut *xshutdown_centre; |
johnAlexander | 3:4ed68a07058d | 188 | Stmpe1600DigiOut *xshutdown_left; |
johnAlexander | 3:4ed68a07058d | 189 | Stmpe1600DigiOut *xshutdown_right; |
johnAlexander | 3:4ed68a07058d | 190 | |
johnAlexander | 3:4ed68a07058d | 191 | private: |
johnAlexander | 7:c0e18dd78c42 | 192 | static XNucleo53L3A2 *_instance; |
johnAlexander | 3:4ed68a07058d | 193 | }; |
johnAlexander | 3:4ed68a07058d | 194 | |
johnAlexander | 3:4ed68a07058d | 195 | |
johnAlexander | 7:c0e18dd78c42 | 196 | #endif /* __VL53L3_NUCLEO_CLASS_H */ |