Mustapha hamdi / Light_Sensor_Nucleo

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
mapellil
Date:
Wed Nov 30 08:25:04 2016 +0000
Revision:
54:17f3bb228b13
Parent:
49:f0dd44dd59c5
Aligned GetLux and GetDistance API with ST_INTERFACES, added isSensorxxPresentAPI, other minor fix.

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 54:17f3bb228b13 66 * @brief x_nucleo_6180xa1 board Constructor. Default the INT gpio \
mapellil 54:17f3bb228b13 67 * configuration as the electrical schematic. Self sensing for optional \
mapellil 54:17f3bb228b13 68 * expansion sensors (L/B/R).
mapellil 36:f6278b3e7c82 69 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 70 */
gallonm 16:0d4776564733 71 X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
gallonm 10:4954b09b72d8 72 {
mapellil 36:f6278b3e7c82 73 stmpe1600 = new STMPE1600(*ext_i2c);
mapellil 36:f6278b3e7c82 74 stmpe1600->writeSYS_CTRL (SOFT_RESET);
licio.mapelli@st.com 33:1573db91352c 75 Switch = new SWITCH (*stmpe1600, GPIO_11);
mapellil 36:f6278b3e7c82 76 display = new Display(*stmpe1600);
gallonm 16:0d4776564733 77
gallonm 16:0d4776564733 78 gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
mapellil 37:837cffa6b530 79 sensor_top=new VL6180X(*dev_i2c, *gpio0_top, A3);
gallonm 16:0d4776564733 80
gallonm 16:0d4776564733 81 gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
mapellil 37:837cffa6b530 82 sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, A2);
gallonm 16:0d4776564733 83
gallonm 16:0d4776564733 84 gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
mapellil 37:837cffa6b530 85 sensor_left=new VL6180X(*dev_i2c, *gpio0_left, D13);
gallonm 16:0d4776564733 86
gallonm 16:0d4776564733 87 gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
mapellil 37:837cffa6b530 88 sensor_right=new VL6180X(*dev_i2c, *gpio0_right, D2);
mapellil 54:17f3bb228b13 89
mapellil 54:17f3bb228b13 90 if (InitBoard()) { // init failed
mapellil 54:17f3bb228b13 91 printf ("ERROR Init X-NUCLEO-6180XA1 Board\n\r");
mapellil 54:17f3bb228b13 92 }
gallonm 16:0d4776564733 93 }
mapellil 36:f6278b3e7c82 94
mapellil 36:f6278b3e7c82 95 /** Constructor 2
mapellil 36:f6278b3e7c82 96 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 97 * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 98 * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 99 * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 100 * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
mapellil 36:f6278b3e7c82 101 */
mapellil 36:f6278b3e7c82 102 X_NUCLEO_6180XA1(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 103 PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
mapellil 36:f6278b3e7c82 104 stmpe1600 = new STMPE1600(*ext_i2c);
fabiombed 42:692c6223dc24 105 stmpe1600->writeSYS_CTRL (SOFT_RESET);
mapellil 36:f6278b3e7c82 106 Switch = new SWITCH (*stmpe1600, GPIO_11);
mapellil 36:f6278b3e7c82 107 display = new Display(*stmpe1600);
mapellil 36:f6278b3e7c82 108
mapellil 36:f6278b3e7c82 109 gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
mapellil 36:f6278b3e7c82 110 sensor_top=new VL6180X(*dev_i2c, *gpio0_top, gpio1_top);
mapellil 36:f6278b3e7c82 111
mapellil 36:f6278b3e7c82 112 gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
mapellil 36:f6278b3e7c82 113 sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, gpio1_bottom);
mapellil 36:f6278b3e7c82 114
mapellil 36:f6278b3e7c82 115 gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
mapellil 36:f6278b3e7c82 116 sensor_left=new VL6180X(*dev_i2c, *gpio0_left, gpio1_left);
mapellil 36:f6278b3e7c82 117
mapellil 36:f6278b3e7c82 118 gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
mapellil 36:f6278b3e7c82 119 sensor_right=new VL6180X(*dev_i2c, *gpio0_right, gpio1_right);
mapellil 36:f6278b3e7c82 120 }
mapellil 36:f6278b3e7c82 121
licio.mapelli@st.com 48:e799ad44dab7 122 /**
licio.mapelli@st.com 48:e799ad44dab7 123 * @brief Override default copy constructor as empty
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 X_NUCLEO_6180XA1() {};
licio.mapelli@st.com 48:e799ad44dab7 128
licio.mapelli@st.com 48:e799ad44dab7 129 /**
licio.mapelli@st.com 48:e799ad44dab7 130 * @brief Override default assignement operator to avoid multiple singletons
licio.mapelli@st.com 48:e799ad44dab7 131 * @param[in] &X_NUCLEO_6180XA1 singleton object reference
licio.mapelli@st.com 48:e799ad44dab7 132 * @return
licio.mapelli@st.com 48:e799ad44dab7 133 */
licio.mapelli@st.com 48:e799ad44dab7 134 void operator = (const X_NUCLEO_6180XA1&);
licio.mapelli@st.com 48:e799ad44dab7 135
licio.mapelli@st.com 48:e799ad44dab7 136 public:
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
licio.mapelli@st.com 48:e799ad44dab7 140 * @return Pointer to the object instance
licio.mapelli@st.com 48:e799ad44dab7 141 */
mapellil 36:f6278b3e7c82 142 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
mapellil 36:f6278b3e7c82 143
licio.mapelli@st.com 48:e799ad44dab7 144 /**
licio.mapelli@st.com 48:e799ad44dab7 145 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 146 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 147 * @param[in] PinName gpio1_top the pin connected to top sensor INT
mapellil 36:f6278b3e7c82 148 * @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT
mapellil 36:f6278b3e7c82 149 * @param[in] PinName gpio1_left the pin connected to left sensor INT
mapellil 36:f6278b3e7c82 150 * @param[in] PinName gpio1_right the pin connected to right sensor INT
mapellil 36:f6278b3e7c82 151 * @return Pointer to the object instance
mapellil 36:f6278b3e7c82 152 */
mapellil 36:f6278b3e7c82 153 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 154 PinName gpio1_left, PinName gpio1_right);
licio.mapelli@st.com 48:e799ad44dab7 155
mapellil 36:f6278b3e7c82 156 /**
mapellil 36:f6278b3e7c82 157 * @brief Initialize the board and sensors with deft values
mapellil 36:f6278b3e7c82 158 * @return 0 on success
mapellil 36:f6278b3e7c82 159 */
mapellil 36:f6278b3e7c82 160 int InitBoard();
mapellil 36:f6278b3e7c82 161
mapellil 36:f6278b3e7c82 162 /**
mapellil 36:f6278b3e7c82 163 * @brief Read the on board red slider switch
mapellil 36:f6278b3e7c82 164 * @return 0 or 1 according to switch position
mapellil 36:f6278b3e7c82 165 */
licio.mapelli@st.com 33:1573db91352c 166 bool RdSwitch () {
licio.mapelli@st.com 33:1573db91352c 167 return Switch->RdSwitch();
licio.mapelli@st.com 33:1573db91352c 168 }
mapellil 54:17f3bb228b13 169
mapellil 54:17f3bb228b13 170 /**
mapellil 54:17f3bb228b13 171 * @brief Check the presence of sensor top. To be called after InitBoard
mapellil 54:17f3bb228b13 172 * @return true is present, false if absent
mapellil 54:17f3bb228b13 173 */
mapellil 54:17f3bb228b13 174 bool isSensorTopPresent() {
mapellil 54:17f3bb228b13 175 if (sensor_top) return true;
mapellil 54:17f3bb228b13 176 return false;
mapellil 54:17f3bb228b13 177 }
mapellil 54:17f3bb228b13 178
mapellil 54:17f3bb228b13 179 /**
mapellil 54:17f3bb228b13 180 * @brief Check the presence of sensor bottom. To be called after InitBoard
mapellil 54:17f3bb228b13 181 * @return true is present, false if absent
mapellil 54:17f3bb228b13 182 */
mapellil 54:17f3bb228b13 183 bool isSensorBottomPresent() {
mapellil 54:17f3bb228b13 184 if (sensor_bottom) return true;
mapellil 54:17f3bb228b13 185 return false;
mapellil 54:17f3bb228b13 186 }
mapellil 54:17f3bb228b13 187
mapellil 54:17f3bb228b13 188 /**
mapellil 54:17f3bb228b13 189 * @brief Check the presence of sensor left. To be called after InitBoard
mapellil 54:17f3bb228b13 190 * @return true is present, false if absent
mapellil 54:17f3bb228b13 191 */
mapellil 54:17f3bb228b13 192 bool isSensorLeftPresent() {
mapellil 54:17f3bb228b13 193 if (sensor_left) return true;
mapellil 54:17f3bb228b13 194 return false;
mapellil 54:17f3bb228b13 195 }
mapellil 54:17f3bb228b13 196
mapellil 54:17f3bb228b13 197 /**
mapellil 54:17f3bb228b13 198 * @brief Check the presence of sensor right. To be called after InitBoard
mapellil 54:17f3bb228b13 199 * @return true is present, false if absent
mapellil 54:17f3bb228b13 200 */
mapellil 54:17f3bb228b13 201 bool isSensorRightPresent() {
mapellil 54:17f3bb228b13 202 if (sensor_right) return true;
mapellil 54:17f3bb228b13 203 return false;
mapellil 54:17f3bb228b13 204 }
mapellil 36:f6278b3e7c82 205
gallonm 16:0d4776564733 206 DevI2C *dev_i2c;
gallonm 16:0d4776564733 207 VL6180X *sensor_top;
gallonm 16:0d4776564733 208 VL6180X *sensor_bottom;
gallonm 16:0d4776564733 209 VL6180X *sensor_left;
gallonm 16:0d4776564733 210 VL6180X *sensor_right;
licio.mapelli@st.com 48:e799ad44dab7 211 STMPE1600 * stmpe1600;
licio.mapelli@st.com 48:e799ad44dab7 212 SWITCH * Switch;
licio.mapelli@st.com 48:e799ad44dab7 213 Display *display;
licio.mapelli@st.com 48:e799ad44dab7 214
licio.mapelli@st.com 48:e799ad44dab7 215 private:
gallonm 16:0d4776564733 216 STMPE1600DigiOut *gpio0_top;
gallonm 16:0d4776564733 217 STMPE1600DigiOut *gpio0_bottom;
gallonm 16:0d4776564733 218 STMPE1600DigiOut *gpio0_left;
mapellil 36:f6278b3e7c82 219 STMPE1600DigiOut *gpio0_right;
gallonm 16:0d4776564733 220 static X_NUCLEO_6180XA1 *_instance;
gallonm 10:4954b09b72d8 221 };
gallonm 0:1fb1f010ac84 222
gallonm 7:2dc81120c917 223 #endif /* __X_NUCLEO_6180XA1_H */