Librairie adaptée au laboratoire 2

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleo6180XA1.h Source File

XNucleo6180XA1.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleo6180XA1.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 
00040 /* Define to prevent from recursive inclusion --------------------------------*/
00041 
00042 #ifndef __X_NUCLEO_6180XA1_H
00043 #define __X_NUCLEO_6180XA1_H
00044 
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 
00048 #include "mbed.h"
00049 #include "VL6180X.h"
00050 #include "Display.h"
00051 #include "STMPE1600.h"
00052 #include "DevI2C.h"
00053 #include "Switch.h"
00054 
00055 /** New device addresses */
00056 #define NEW_SENSOR_TOP_ADDRESS          0x10
00057 #define NEW_SENSOR_BOTTOM_ADDRESS       0x11
00058 #define NEW_SENSOR_LEFT_ADDRESS         0x12
00059 #define NEW_SENSOR_RIGHT_ADDRESS        0x13
00060 
00061 
00062 /* Classes--------------------------------------------------------------------*/
00063 
00064 /**
00065  * Class representing the X-NUCLEO-VL6180XA1 expansion board singleton obj
00066  */
00067 class XNucleo6180XA1
00068 {
00069 protected:
00070     /** Constructor 1
00071      * @brief       x_nucleo_6180xa1 board Constructor. Default the INT gpio \
00072      * configuration as the electrical schematic. Self sensing for optional \
00073      * expansion sensors (L/B/R). 
00074      * @param[in] &i2c device I2C to be used for communication
00075      */
00076     XNucleo6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
00077     {
00078         stmpe1600 = new STMPE1600(*ext_i2c);        
00079         stmpe1600->write_sys_ctrl (SOFT_RESET);     
00080         the_switch = new Switch (*stmpe1600, GPIO_11);  
00081         display = new Display(*stmpe1600);          
00082 
00083         _gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
00084         sensor_top=new VL6180X(*dev_i2c, *_gpio0_top, A3);
00085 
00086         _gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
00087         sensor_bottom=new VL6180X(*dev_i2c, *_gpio0_bottom, A2);
00088 
00089         _gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
00090         sensor_left=new VL6180X(*dev_i2c, *_gpio0_left, D13);
00091 
00092         _gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
00093         sensor_right=new VL6180X(*dev_i2c, *_gpio0_right, D2);
00094 
00095         if (init_board()) {   // init failed
00096             printf ("ERROR Init X-NUCLEO-6180XA1 Board\n\r");
00097         }      
00098     }
00099     
00100     /** Constructor 2
00101      * @param[in] &i2c device I2C to be used for communication
00102      * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
00103      * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
00104      * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
00105      * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT               
00106      */    
00107     XNucleo6180XA1(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
00108                                  PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
00109        stmpe1600 = new STMPE1600(*ext_i2c);                                             
00110        stmpe1600->write_sys_ctrl (SOFT_RESET);  
00111        the_switch = new Switch (*stmpe1600, GPIO_11);   
00112        display = new Display(*stmpe1600);           
00113 
00114        _gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);          
00115        sensor_top=new VL6180X(*dev_i2c, *_gpio0_top, gpio1_top);
00116        
00117        _gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);   
00118        sensor_bottom=new VL6180X(*dev_i2c, *_gpio0_bottom, gpio1_bottom);
00119  
00120        _gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);      
00121        sensor_left=new VL6180X(*dev_i2c, *_gpio0_left, gpio1_left);
00122        
00123        _gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
00124        sensor_right=new VL6180X(*dev_i2c, *_gpio0_right, gpio1_right);      
00125     }  
00126 
00127     /**
00128      * @brief       Override default copy constructor as empty
00129      * @param[in]   &XNucleo6180XA1 singleton object reference
00130      * @return     
00131      */         
00132     XNucleo6180XA1() {};
00133     
00134     /**
00135      * @brief       Override default assignement operator to avoid multiple singletons
00136      * @param[in]   &XNucleo6180XA1 singleton object reference
00137      * @return     
00138      */         
00139     void operator = (const XNucleo6180XA1&);
00140     
00141 public:
00142     /**
00143      * @brief       Creates a singleton object instance
00144      * @param[in]   &i2c device I2C to be used for communication
00145      * @return      Pointer to the object instance
00146      */                      
00147     static XNucleo6180XA1 *instance(DevI2C *ext_i2c);
00148     
00149     /**
00150      * @brief       Creates a singleton object instance
00151      * @param[in]   &i2c device I2C to be used for communication
00152      * @param[in]   PinName gpio1_top the pin connected to top sensor INT     
00153      * @param[in]   PinName gpio1_bottem the pin connected to bottom sensor INT          
00154      * @param[in]   PinName gpio1_left the pin connected to left sensor INT          
00155      * @param[in]   PinName gpio1_right the pin connected to right sensor INT          
00156      * @return      Pointer to the object instance
00157      */                          
00158     static XNucleo6180XA1 *instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
00159                                     PinName gpio1_left, PinName gpio1_right);
00160     
00161     /**
00162      * @brief       Initialize the board and sensors with deft values
00163      * @return      0 on success
00164      */     
00165     int init_board();
00166 
00167     /**
00168      * @brief       Read the on board red slider switch
00169      * @return      0 or 1 according to switch position
00170      */             
00171     bool rd_switch () {
00172          return the_switch->rd_switch();    
00173     }
00174     
00175     /**
00176      * @brief       Check the presence of sensor top. To be called after init_board
00177      * @return      true is present, false if absent
00178      */             
00179         bool is_sensor_top_present() {
00180             if (sensor_top) {
00181             return true;
00182         }
00183             return false;
00184     } 
00185 
00186     /**
00187      * @brief       Check the presence of sensor bottom.  To be called after init_board
00188      * @return      true is present, false if absent
00189      */             
00190     bool is_sensor_bottom_present() {
00191             if (sensor_bottom) {
00192             return true;
00193         }
00194             return false;
00195     } 
00196     
00197     /**
00198      * @brief       Check the presence of sensor left.  To be called after init_board
00199      * @return      true is present, false if absent
00200      */             
00201     bool is_sensor_left_present() {
00202             if (sensor_left) {
00203             return true;
00204         }
00205             return false;
00206     } 
00207     
00208     /**
00209      * @brief       Check the presence of sensor right.  To be called after init_board
00210      * @return      true is present, false if absent
00211      */             
00212     bool is_sensor_right_present() {
00213             if (sensor_right) {
00214             return true;
00215         }
00216             return false;
00217     }
00218 
00219     DevI2C *dev_i2c;
00220     VL6180X *sensor_top;
00221     VL6180X *sensor_bottom;
00222     VL6180X *sensor_left;
00223     VL6180X *sensor_right;
00224     STMPE1600 *stmpe1600;
00225     Switch *the_switch;     
00226     Display *display;
00227     
00228 private:
00229     STMPE1600DigiOut *_gpio0_top;
00230     STMPE1600DigiOut *_gpio0_bottom;
00231     STMPE1600DigiOut *_gpio0_left;
00232     STMPE1600DigiOut *_gpio0_right;    
00233     static XNucleo6180XA1 *_instance;
00234 };
00235 
00236 #endif /* __X_NUCLEO_6180XA1_H */