Fabio Brembilla / X_NUCLEO_6180XA1

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers x_nucleo_6180xa1.h Source File

x_nucleo_6180xa1.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    x_nucleo_6180xa1.h
00004  * @author  AST / EST
00005  * @version V0.0.1
00006  * @date    13-April-2015
00007  * @brief   Header file for class X_NUCLEO_6180XA1 representing a X-NUCLEO-6180XA1
00008  *          expansion board
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2015 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_6180XA1_H
00041 #define __X_NUCLEO_6180XA1_H
00042 
00043 /* Includes ------------------------------------------------------------------*/
00044 #include "mbed.h"
00045 #include "vl6180x_class.h"
00046 #include "Display_class.h"
00047 #include "stmpe1600_class.h"
00048 #include "DevI2C.h"
00049 #include "Switch_class.h"
00050 
00051 /** New device addresses */
00052 #define NEW_SENSOR_TOP_ADDRESS          0x10
00053 #define NEW_SENSOR_BOTTOM_ADDRESS       0x11
00054 #define NEW_SENSOR_LEFT_ADDRESS         0x12
00055 #define NEW_SENSOR_RIGHT_ADDRESS        0x13
00056 
00057 /* Classes--------------------------------------------------------------------*/
00058 
00059 /* Classes -------------------------------------------------------------------*/
00060 /** Class representing the X-NUCLEO-VL6180XA1 expansion board
00061  */
00062 class X_NUCLEO_6180XA1
00063 {
00064  public:
00065      /** Constructor 1
00066      * @param[in] &i2c device I2C to be used for communication
00067      */
00068     X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
00069     {
00070        stmpe1600 = new STMPE1600(*ext_i2c);     
00071        stmpe1600->writeSYS_CTRL (SOFT_RESET);       
00072        Switch = new SWITCH (*stmpe1600, GPIO_11);   
00073        display = new Display(*stmpe1600);           
00074             
00075        gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
00076        sensor_top=new VL6180X(*dev_i2c, *gpio0_top, A3);
00077        
00078        gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
00079        sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, A2);
00080        
00081        gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
00082        sensor_left=new VL6180X(*dev_i2c, *gpio0_left, D13);
00083        
00084        gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
00085        sensor_right=new VL6180X(*dev_i2c, *gpio0_right, D2);
00086     }
00087     
00088     /** Constructor 2
00089      * @param[in] &i2c device I2C to be used for communication
00090      * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
00091      * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
00092      * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
00093      * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT               
00094      */    
00095     X_NUCLEO_6180XA1(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
00096                                       PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
00097        stmpe1600 = new STMPE1600(*ext_i2c);                                             
00098        stmpe1600->writeSYS_CTRL (SOFT_RESET);   
00099        Switch = new SWITCH (*stmpe1600, GPIO_11);   
00100        display = new Display(*stmpe1600);           
00101 
00102        gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);           
00103        sensor_top=new VL6180X(*dev_i2c, *gpio0_top, gpio1_top);
00104        
00105        gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);   
00106        sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, gpio1_bottom);
00107  
00108        gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);      
00109        sensor_left=new VL6180X(*dev_i2c, *gpio0_left, gpio1_left);
00110        
00111        gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
00112        sensor_right=new VL6180X(*dev_i2c, *gpio0_right, gpio1_right);       
00113     }  
00114 
00115    /** Destructor
00116     */      
00117     ~X_NUCLEO_6180XA1()
00118     {
00119        if(gpio0_top!=NULL)
00120        {
00121           delete gpio0_top;
00122           gpio0_top=NULL;
00123        }
00124        if(sensor_top!=NULL)
00125        {
00126           delete sensor_top;
00127             sensor_top=NULL;
00128        }
00129        if(gpio0_bottom!=NULL)
00130        {
00131           delete gpio0_bottom;
00132           gpio0_bottom=NULL;
00133        }
00134        if(sensor_bottom!=NULL)
00135        {
00136           delete sensor_bottom;
00137             sensor_bottom=NULL;
00138        }
00139        if(gpio0_left!=NULL)
00140        {
00141           delete gpio0_left;
00142           gpio0_left=NULL;
00143        }
00144        if(sensor_left!=NULL)
00145        {
00146           delete sensor_left;
00147             sensor_left=NULL;
00148        }
00149        if(gpio0_right!=NULL)
00150        {
00151           delete gpio0_right;
00152           gpio0_right=NULL;
00153        }
00154        if(sensor_right!=NULL)
00155        {
00156           delete sensor_right;
00157             sensor_right=NULL;
00158        }
00159        delete stmpe1600;
00160        stmpe1600 = NULL;
00161        delete Switch;
00162        Switch = NULL;
00163        delete display;
00164        display = NULL;
00165        _instance=NULL;
00166     }
00167 
00168     /**
00169      * @brief       Creates a singleton object instance
00170      * @param[in]   &i2c device I2C to be used for communication
00171      * @return      Pointer to the object instance
00172      */                      
00173     static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
00174     
00175     /**
00176      * @brief       Creates a singleton object instance
00177      * @param[in]   &i2c device I2C to be used for communication
00178      * @param[in]   PinName gpio1_top the pin connected to top sensor INT     
00179      * @param[in]   PinName gpio1_bottem the pin connected to bottom sensor INT          
00180      * @param[in]   PinName gpio1_left the pin connected to left sensor INT          
00181      * @param[in]   PinName gpio1_right the pin connected to right sensor INT          
00182      * @return      Pointer to the object instance
00183      */                          
00184     static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
00185                                              PinName gpio1_left, PinName gpio1_right);
00186 
00187     /**
00188      * @brief       Initialize the board and sensors with deft values
00189      * @return      0 on success
00190      */     
00191     int InitBoard();
00192 
00193     /**
00194      * @brief       Read the on board red slider switch
00195      * @return      0 or 1 according to switch position
00196      */             
00197     bool RdSwitch () {
00198          return Switch->RdSwitch(); 
00199     }
00200 
00201     DevI2C *dev_i2c;
00202     VL6180X *sensor_top;
00203     VL6180X *sensor_bottom;
00204     VL6180X *sensor_left;
00205     VL6180X *sensor_right;
00206     STMPE1600 * stmpe1600;
00207     SWITCH * Switch;        
00208     STMPE1600DigiOut *gpio0_top;
00209     STMPE1600DigiOut *gpio0_bottom;
00210     STMPE1600DigiOut *gpio0_left;
00211     STMPE1600DigiOut *gpio0_right;    
00212     Display *display;
00213     
00214  private:               
00215     static X_NUCLEO_6180XA1 *_instance;
00216 };
00217 
00218 #endif /* __X_NUCLEO_6180XA1_H */