Jerry Szczurak / X_NUCLEO_53L0A1

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   Display_53L0A1_IntSatelites Display_53L0A1_InterruptMode

Fork of X_NUCLEO_53L0A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers x_nucleo_53l0a1.h Source File

x_nucleo_53l0a1.h

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