Mustapha hamdi / Light_Sensor_Nucleo

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
Davidroid
Date:
Tue Sep 27 12:18:09 2016 +0000
Revision:
53:663a22f7c44d
Parent:
49:f0dd44dd59c5
Child:
54:17f3bb228b13
ST_INTERFACES added.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gallonm 0:1fb1f010ac84 1 /**
gallonm 0:1fb1f010ac84 2 ******************************************************************************
gallonm 0:1fb1f010ac84 3 * @file x_nucleo_6180xa1.h
gallonm 0:1fb1f010ac84 4 * @author AST / EST
gallonm 0:1fb1f010ac84 5 * @version V0.0.1
gallonm 0:1fb1f010ac84 6 * @date 13-April-2015
gallonm 0:1fb1f010ac84 7 * @brief Header file for class X_NUCLEO_6180XA1 representing a X-NUCLEO-6180XA1
gallonm 0:1fb1f010ac84 8 * expansion board
gallonm 0:1fb1f010ac84 9 ******************************************************************************
gallonm 0:1fb1f010ac84 10 * @attention
gallonm 0:1fb1f010ac84 11 *
gallonm 0:1fb1f010ac84 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
gallonm 0:1fb1f010ac84 13 *
gallonm 0:1fb1f010ac84 14 * Redistribution and use in source and binary forms, with or without modification,
gallonm 0:1fb1f010ac84 15 * are permitted provided that the following conditions are met:
gallonm 0:1fb1f010ac84 16 * 1. Redistributions of source code must retain the above copyright notice,
gallonm 0:1fb1f010ac84 17 * this list of conditions and the following disclaimer.
gallonm 0:1fb1f010ac84 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
gallonm 0:1fb1f010ac84 19 * this list of conditions and the following disclaimer in the documentation
gallonm 0:1fb1f010ac84 20 * and/or other materials provided with the distribution.
gallonm 0:1fb1f010ac84 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gallonm 0:1fb1f010ac84 22 * may be used to endorse or promote products derived from this software
gallonm 0:1fb1f010ac84 23 * without specific prior written permission.
gallonm 0:1fb1f010ac84 24 *
gallonm 0:1fb1f010ac84 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gallonm 0:1fb1f010ac84 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gallonm 0:1fb1f010ac84 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gallonm 0:1fb1f010ac84 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gallonm 0:1fb1f010ac84 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gallonm 0:1fb1f010ac84 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gallonm 0:1fb1f010ac84 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gallonm 0:1fb1f010ac84 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gallonm 0:1fb1f010ac84 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gallonm 0:1fb1f010ac84 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gallonm 0:1fb1f010ac84 35 *
gallonm 0:1fb1f010ac84 36 ******************************************************************************
gallonm 0:1fb1f010ac84 37 */
gallonm 0:1fb1f010ac84 38
gallonm 0:1fb1f010ac84 39 /* Define to prevent from recursive inclusion --------------------------------*/
gallonm 0:1fb1f010ac84 40 #ifndef __X_NUCLEO_6180XA1_H
gallonm 0:1fb1f010ac84 41 #define __X_NUCLEO_6180XA1_H
gallonm 0:1fb1f010ac84 42
gallonm 0:1fb1f010ac84 43 /* Includes ------------------------------------------------------------------*/
gallonm 0:1fb1f010ac84 44 #include "mbed.h"
gallonm 0:1fb1f010ac84 45 #include "vl6180x_class.h"
gallonm 16:0d4776564733 46 #include "Display_class.h"
gallonm 18:c98aa73dc4a5 47 #include "stmpe1600_class.h"
gallonm 0:1fb1f010ac84 48 #include "DevI2C.h"
licio.mapelli@st.com 33:1573db91352c 49 #include "Switch_class.h"
gallonm 0:1fb1f010ac84 50
gallonm 15:454710d17358 51 /** New device addresses */
gallonm 10:4954b09b72d8 52 #define NEW_SENSOR_TOP_ADDRESS 0x10
gallonm 15:454710d17358 53 #define NEW_SENSOR_BOTTOM_ADDRESS 0x11
gallonm 15:454710d17358 54 #define NEW_SENSOR_LEFT_ADDRESS 0x12
gallonm 15:454710d17358 55 #define NEW_SENSOR_RIGHT_ADDRESS 0x13
gallonm 10:4954b09b72d8 56
gallonm 4:a5abf7757947 57 /* Classes--------------------------------------------------------------------*/
gallonm 0:1fb1f010ac84 58
mapellil 36:f6278b3e7c82 59 /* Classes -------------------------------------------------------------------*/
licio.mapelli@st.com 48:e799ad44dab7 60 /** Class representing the X-NUCLEO-VL6180XA1 expansion board singleton obj
mapellil 36:f6278b3e7c82 61 */
gallonm 10:4954b09b72d8 62 class X_NUCLEO_6180XA1
gallonm 4:a5abf7757947 63 {
mapellil 49:f0dd44dd59c5 64 protected:
mapellil 36:f6278b3e7c82 65 /** Constructor 1
mapellil 36:f6278b3e7c82 66 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 67 */
gallonm 16:0d4776564733 68 X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
gallonm 10:4954b09b72d8 69 {
mapellil 36:f6278b3e7c82 70 stmpe1600 = new STMPE1600(*ext_i2c);
mapellil 36:f6278b3e7c82 71 stmpe1600->writeSYS_CTRL (SOFT_RESET);
licio.mapelli@st.com 33:1573db91352c 72 Switch = new SWITCH (*stmpe1600, GPIO_11);
mapellil 36:f6278b3e7c82 73 display = new Display(*stmpe1600);
gallonm 16:0d4776564733 74
gallonm 16:0d4776564733 75 gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
mapellil 37:837cffa6b530 76 sensor_top=new VL6180X(*dev_i2c, *gpio0_top, A3);
gallonm 16:0d4776564733 77
gallonm 16:0d4776564733 78 gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
mapellil 37:837cffa6b530 79 sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, A2);
gallonm 16:0d4776564733 80
gallonm 16:0d4776564733 81 gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
mapellil 37:837cffa6b530 82 sensor_left=new VL6180X(*dev_i2c, *gpio0_left, D13);
gallonm 16:0d4776564733 83
gallonm 16:0d4776564733 84 gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
mapellil 37:837cffa6b530 85 sensor_right=new VL6180X(*dev_i2c, *gpio0_right, D2);
gallonm 16:0d4776564733 86 }
mapellil 36:f6278b3e7c82 87
mapellil 36:f6278b3e7c82 88 /** Constructor 2
mapellil 36:f6278b3e7c82 89 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 90 * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 91 * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 92 * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 93 * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 94 */
mapellil 36:f6278b3e7c82 95 X_NUCLEO_6180XA1(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 96 PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
mapellil 36:f6278b3e7c82 97 stmpe1600 = new STMPE1600(*ext_i2c);
fabiombed 42:692c6223dc24 98 stmpe1600->writeSYS_CTRL (SOFT_RESET);
mapellil 36:f6278b3e7c82 99 Switch = new SWITCH (*stmpe1600, GPIO_11);
mapellil 36:f6278b3e7c82 100 display = new Display(*stmpe1600);
mapellil 36:f6278b3e7c82 101
mapellil 36:f6278b3e7c82 102 gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
mapellil 36:f6278b3e7c82 103 sensor_top=new VL6180X(*dev_i2c, *gpio0_top, gpio1_top);
mapellil 36:f6278b3e7c82 104
mapellil 36:f6278b3e7c82 105 gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
mapellil 36:f6278b3e7c82 106 sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, gpio1_bottom);
mapellil 36:f6278b3e7c82 107
mapellil 36:f6278b3e7c82 108 gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
mapellil 36:f6278b3e7c82 109 sensor_left=new VL6180X(*dev_i2c, *gpio0_left, gpio1_left);
mapellil 36:f6278b3e7c82 110
mapellil 36:f6278b3e7c82 111 gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
mapellil 36:f6278b3e7c82 112 sensor_right=new VL6180X(*dev_i2c, *gpio0_right, gpio1_right);
mapellil 36:f6278b3e7c82 113 }
mapellil 36:f6278b3e7c82 114
licio.mapelli@st.com 48:e799ad44dab7 115 /**
licio.mapelli@st.com 48:e799ad44dab7 116 * @brief Override default copy constructor as empty
licio.mapelli@st.com 48:e799ad44dab7 117 * @param[in] &X_NUCLEO_6180XA1 singleton object reference
licio.mapelli@st.com 48:e799ad44dab7 118 * @return
licio.mapelli@st.com 48:e799ad44dab7 119 */
licio.mapelli@st.com 48:e799ad44dab7 120 X_NUCLEO_6180XA1() {};
licio.mapelli@st.com 48:e799ad44dab7 121
licio.mapelli@st.com 48:e799ad44dab7 122 /**
licio.mapelli@st.com 48:e799ad44dab7 123 * @brief Override default assignement operator to avoid multiple singletons
licio.mapelli@st.com 48:e799ad44dab7 124 * @param[in] &X_NUCLEO_6180XA1 singleton object reference
licio.mapelli@st.com 48:e799ad44dab7 125 * @return
licio.mapelli@st.com 48:e799ad44dab7 126 */
licio.mapelli@st.com 48:e799ad44dab7 127 void operator = (const X_NUCLEO_6180XA1&);
licio.mapelli@st.com 48:e799ad44dab7 128
licio.mapelli@st.com 48:e799ad44dab7 129 public:
licio.mapelli@st.com 48:e799ad44dab7 130 /**
licio.mapelli@st.com 48:e799ad44dab7 131 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 132 * @param[in] &i2c device I2C to be used for communication
licio.mapelli@st.com 48:e799ad44dab7 133 * @return Pointer to the object instance
licio.mapelli@st.com 48:e799ad44dab7 134 */
mapellil 36:f6278b3e7c82 135 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
mapellil 36:f6278b3e7c82 136
licio.mapelli@st.com 48:e799ad44dab7 137 /**
licio.mapelli@st.com 48:e799ad44dab7 138 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 139 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 140 * @param[in] PinName gpio1_top the pin connected to top sensor INT
mapellil 36:f6278b3e7c82 141 * @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT
mapellil 36:f6278b3e7c82 142 * @param[in] PinName gpio1_left the pin connected to left sensor INT
mapellil 36:f6278b3e7c82 143 * @param[in] PinName gpio1_right the pin connected to right sensor INT
mapellil 36:f6278b3e7c82 144 * @return Pointer to the object instance
mapellil 36:f6278b3e7c82 145 */
mapellil 36:f6278b3e7c82 146 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 147 PinName gpio1_left, PinName gpio1_right);
mapellil 36:f6278b3e7c82 148
licio.mapelli@st.com 48:e799ad44dab7 149
mapellil 36:f6278b3e7c82 150 /**
mapellil 36:f6278b3e7c82 151 * @brief Initialize the board and sensors with deft values
mapellil 36:f6278b3e7c82 152 * @return 0 on success
mapellil 36:f6278b3e7c82 153 */
mapellil 36:f6278b3e7c82 154 int InitBoard();
mapellil 36:f6278b3e7c82 155
mapellil 36:f6278b3e7c82 156 /**
mapellil 36:f6278b3e7c82 157 * @brief Read the on board red slider switch
mapellil 36:f6278b3e7c82 158 * @return 0 or 1 according to switch position
mapellil 36:f6278b3e7c82 159 */
licio.mapelli@st.com 33:1573db91352c 160 bool RdSwitch () {
licio.mapelli@st.com 33:1573db91352c 161 return Switch->RdSwitch();
licio.mapelli@st.com 33:1573db91352c 162 }
mapellil 36:f6278b3e7c82 163
gallonm 16:0d4776564733 164 DevI2C *dev_i2c;
gallonm 16:0d4776564733 165 VL6180X *sensor_top;
gallonm 16:0d4776564733 166 VL6180X *sensor_bottom;
gallonm 16:0d4776564733 167 VL6180X *sensor_left;
gallonm 16:0d4776564733 168 VL6180X *sensor_right;
licio.mapelli@st.com 48:e799ad44dab7 169 STMPE1600 * stmpe1600;
licio.mapelli@st.com 48:e799ad44dab7 170 SWITCH * Switch;
licio.mapelli@st.com 48:e799ad44dab7 171 Display *display;
licio.mapelli@st.com 48:e799ad44dab7 172
licio.mapelli@st.com 48:e799ad44dab7 173 private:
gallonm 16:0d4776564733 174 STMPE1600DigiOut *gpio0_top;
gallonm 16:0d4776564733 175 STMPE1600DigiOut *gpio0_bottom;
gallonm 16:0d4776564733 176 STMPE1600DigiOut *gpio0_left;
mapellil 36:f6278b3e7c82 177 STMPE1600DigiOut *gpio0_right;
gallonm 16:0d4776564733 178 static X_NUCLEO_6180XA1 *_instance;
gallonm 10:4954b09b72d8 179 };
gallonm 0:1fb1f010ac84 180
gallonm 7:2dc81120c917 181 #endif /* __X_NUCLEO_6180XA1_H */