ST Expansion SW Team / X_NUCLEO_53L1A2

Dependencies:   VL53L1CB

Dependents:   VL53L1CB_NoShield_1sensor_polling_multizone_MB6 VL53L1CB_NoShield_3sensors_interrupt_ranging_MB6 VL53L1CB_NoShield_MB6_3sensors_interrupt_ranging VL53L1CB_shield_1sensor_interrupt_auton ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleo53L1A2.h Source File

XNucleo53L1A2.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleo53L1A2.h
00004  * @author  JS
00005  * @version V0.0.1
00006  * @date    15-January-2021
00007  * @brief   Header file for component XNucleo53L1A2
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2021 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *       without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  *
00037  * *** NOTE : By default hardlinks U10, U11, U15 & U18, on the underside of
00038  *            the X-NUCELO-53L1A1 expansion board are not made/OFF.
00039  *            These links must be made to allow interrupts from the Satellite boards
00040  *            to be received.
00041  *            U11 and U18 must be made/ON to allow interrupts to be received from the
00042  *            INT_L & INT_R positions; or
00043  *            U10 and U15 must be made/ON to allow interrupts to be received from the
00044  *            Alternate INT_L & INT_R positions.
00045  *            The X_NUCLEO_53L1A2 library defaults to use the INT_L/INT_R positions.
00046  *            INT_L is available on expansion board Arduino Connector CN5, pin 1 as D8.
00047  *            Alternate INT_L is on CN5 Connector pin 2 as D9.
00048  *            INT_R is available on expansion board Arduino Connector CN9, pin 3 as D2.
00049  *            Alternate INT_R is on CN9 Connector pin 5 as D4.
00050  *            The pinouts are shown here : https://developer.mbed.org/components/X-NUCLEO-53L1A2/
00051  */
00052 
00053 #ifndef __VL53L1_A2_NUCLEO_CLASS_H
00054 #define __VL53L1_A2_NUCLEO_CLASS_H
00055 
00056 
00057 /* Includes ------------------------------------------------------------------*/
00058 #include "VL53L1CB.h"
00059 #include "Stmpe1600.h"
00060 //#include "DevI2C.h"
00061 #include "ToF_I2C.h"
00062 
00063 
00064 /** New device addresses */
00065 #define NEW_SENSOR_CENTRE_ADDRESS   0x56
00066 
00067 #define NEW_SENSOR_LEFT_ADDRESS         0x58
00068 #define NEW_SENSOR_RIGHT_ADDRESS        0x5a
00069 
00070 
00071 /* Classes--------------------------------------------------------------------*/
00072 
00073 /* Classes -------------------------------------------------------------------*/
00074 /** Class representing the X-NUCLEO-VL53L1A2 expansion board
00075  */
00076 class XNucleo53L1A2
00077 {
00078 public:
00079     /** Constructor 1
00080     * @param[in] &i2c device I2C to be used for communication
00081     */
00082     XNucleo53L1A2(ToF_DevI2C *ext_i2c) : dev_i2c(ext_i2c)
00083     {
00084 
00085         stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2));     // U21
00086 
00087         stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2));     // U19
00088 
00089         xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2));     // U19 on schematic
00090         sensor_centre = new VL53L1CB(dev_i2c, xshutdown_centre, A2);
00091 
00092         xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2));     // U21 on schematic
00093         sensor_left = new VL53L1CB(dev_i2c, xshutdown_left, D8);
00094 
00095         xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2));     // U21 on schematic
00096         sensor_right = new VL53L1CB(dev_i2c, xshutdown_right, D2);
00097     }
00098 
00099     /** Constructor 2
00100      * @param[in] &i2c device I2C to be used for communication
00101      * @param[in] PinName gpio1_centre Mbed DigitalOut pin name to be used as a centre sensor GPIO_1 INT
00102      * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
00103      * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
00104      */
00105     XNucleo53L1A2(ToF_DevI2C *ext_i2c, PinName gpio1_centre,
00106                   PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c)
00107     {
00108         stmpe1600_exp0 = new Stmpe1600((DevI2C*)ext_i2c, (0x43 * 2));     // U21
00109 
00110         stmpe1600_exp1 = new Stmpe1600((DevI2C*)ext_i2c, (0x42 * 2));     // U19
00111 
00112         xshutdown_centre = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x42 * 2));     // U19 on schematic
00113         sensor_centre = new VL53L1CB(dev_i2c, xshutdown_centre, gpio1_centre);
00114 
00115         xshutdown_left = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_14, (0x43 * 2));     // U21 on schematic
00116         sensor_left = new VL53L1CB(dev_i2c, xshutdown_left, gpio1_left);
00117 
00118         xshutdown_right = new Stmpe1600DigiOut((DevI2C*)dev_i2c, GPIO_15, (0x43 * 2));     // U21 on schematic
00119         sensor_right = new VL53L1CB(dev_i2c, xshutdown_right, gpio1_right);
00120     }
00121 
00122 
00123     /** Destructor
00124      */
00125     ~XNucleo53L1A2()
00126     {
00127         if (xshutdown_centre != NULL) {
00128             delete xshutdown_centre;
00129             xshutdown_centre = NULL;
00130         }
00131         if (sensor_centre != NULL) {
00132             delete sensor_centre;
00133             sensor_centre = NULL;
00134         }
00135         if (xshutdown_left != NULL) {
00136             delete xshutdown_left;
00137             xshutdown_left = NULL;
00138         }
00139         if (sensor_left != NULL) {
00140             delete sensor_left;
00141             sensor_left = NULL;
00142         }
00143         if (xshutdown_right != NULL) {
00144             delete xshutdown_right;
00145             xshutdown_right = NULL;
00146         }
00147         if (sensor_right != NULL) {
00148             delete sensor_right;
00149             sensor_right = NULL;
00150         }
00151 
00152         delete stmpe1600_exp0;
00153         stmpe1600_exp0 = NULL;
00154         delete stmpe1600_exp1;
00155         stmpe1600_exp1 = NULL;
00156         _instance = NULL;
00157     }
00158 
00159 
00160     /**
00161      * @brief       Creates a singleton object instance
00162      * @param[in]   &i2c device I2C to be used for communication
00163      * @return      Pointer to the object instance
00164      */
00165     static XNucleo53L1A2 *instance(ToF_DevI2C *ext_i2c);
00166 
00167     /**
00168      * @brief       Creates a singleton object instance
00169      * @param[in]   &i2c device I2C to be used for communication
00170      * @param[in]   PinName gpio1_centre the pin connected to centre sensor INT
00171      * @param[in]   PinName gpio1_left the pin connected to left sensor INT
00172      * @param[in]   PinName gpio1_right the pin connected to right sensor INT
00173      * @return      Pointer to the object instance
00174      */
00175     static XNucleo53L1A2 *instance(ToF_DevI2C *ext_i2c, PinName gpio1_centre,
00176                                    PinName gpio1_left, PinName gpio1_right);
00177 
00178     /**
00179      * @brief       Initialize the board and sensors with deft values
00180      * @return      0 on success
00181      */
00182     int init_board();
00183 
00184     ToF_DevI2C *dev_i2c;
00185 
00186     VL53L1CB *sensor_centre;
00187     VL53L1CB *sensor_left;
00188     VL53L1CB *sensor_right;
00189 
00190     Stmpe1600 *stmpe1600_exp0;
00191     Stmpe1600 *stmpe1600_exp1;
00192 
00193     Stmpe1600DigiOut *xshutdown_centre;
00194     Stmpe1600DigiOut *xshutdown_left;
00195     Stmpe1600DigiOut *xshutdown_right;
00196 
00197 private:
00198     static XNucleo53L1A2 *_instance;
00199 };
00200 
00201 
00202 #endif /* __VL53L1_A2_NUCLEO_CLASS_H */