INSAT Mini Project
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_6180XA1 by
x_nucleo_6180xa1.h@48:e799ad44dab7, 2016-06-07 (annotated)
- Committer:
- licio.mapelli@st.com
- Date:
- Tue Jun 07 14:56:36 2016 +0200
- Revision:
- 48:e799ad44dab7
- Parent:
- 42:692c6223dc24
- Child:
- 49:f0dd44dd59c5
Fixed I2C address in component descriptor to default val after component PowerOn/Off.
Overridden singleton obj fake copy constructor and (=) assignement operator to avoid multiple singleton instances.
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 | { |
licio.mapelli@st.com | 48:e799ad44dab7 | 64 | private: |
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 | |
mapellil | 36:f6278b3e7c82 | 115 | /** Destructor |
mapellil | 36:f6278b3e7c82 | 116 | */ |
gallonm | 16:0d4776564733 | 117 | ~X_NUCLEO_6180XA1() |
gallonm | 10:4954b09b72d8 | 118 | { |
gallonm | 16:0d4776564733 | 119 | if(gpio0_top!=NULL) |
gallonm | 16:0d4776564733 | 120 | { |
gallonm | 16:0d4776564733 | 121 | delete gpio0_top; |
gallonm | 16:0d4776564733 | 122 | gpio0_top=NULL; |
gallonm | 16:0d4776564733 | 123 | } |
gallonm | 16:0d4776564733 | 124 | if(sensor_top!=NULL) |
gallonm | 16:0d4776564733 | 125 | { |
gallonm | 16:0d4776564733 | 126 | delete sensor_top; |
licio.mapelli@st.com | 48:e799ad44dab7 | 127 | sensor_top=NULL; |
gallonm | 16:0d4776564733 | 128 | } |
gallonm | 16:0d4776564733 | 129 | if(gpio0_bottom!=NULL) |
gallonm | 16:0d4776564733 | 130 | { |
gallonm | 16:0d4776564733 | 131 | delete gpio0_bottom; |
gallonm | 16:0d4776564733 | 132 | gpio0_bottom=NULL; |
gallonm | 16:0d4776564733 | 133 | } |
gallonm | 16:0d4776564733 | 134 | if(sensor_bottom!=NULL) |
gallonm | 16:0d4776564733 | 135 | { |
gallonm | 16:0d4776564733 | 136 | delete sensor_bottom; |
licio.mapelli@st.com | 48:e799ad44dab7 | 137 | sensor_bottom=NULL; |
gallonm | 16:0d4776564733 | 138 | } |
gallonm | 16:0d4776564733 | 139 | if(gpio0_left!=NULL) |
gallonm | 16:0d4776564733 | 140 | { |
gallonm | 16:0d4776564733 | 141 | delete gpio0_left; |
gallonm | 16:0d4776564733 | 142 | gpio0_left=NULL; |
gallonm | 16:0d4776564733 | 143 | } |
gallonm | 16:0d4776564733 | 144 | if(sensor_left!=NULL) |
gallonm | 16:0d4776564733 | 145 | { |
gallonm | 16:0d4776564733 | 146 | delete sensor_left; |
licio.mapelli@st.com | 48:e799ad44dab7 | 147 | sensor_left=NULL; |
gallonm | 16:0d4776564733 | 148 | } |
gallonm | 16:0d4776564733 | 149 | if(gpio0_right!=NULL) |
gallonm | 16:0d4776564733 | 150 | { |
gallonm | 16:0d4776564733 | 151 | delete gpio0_right; |
gallonm | 16:0d4776564733 | 152 | gpio0_right=NULL; |
gallonm | 16:0d4776564733 | 153 | } |
gallonm | 16:0d4776564733 | 154 | if(sensor_right!=NULL) |
gallonm | 16:0d4776564733 | 155 | { |
gallonm | 16:0d4776564733 | 156 | delete sensor_right; |
licio.mapelli@st.com | 48:e799ad44dab7 | 157 | sensor_right=NULL; |
gallonm | 16:0d4776564733 | 158 | } |
licio.mapelli@st.com | 48:e799ad44dab7 | 159 | delete stmpe1600; |
licio.mapelli@st.com | 48:e799ad44dab7 | 160 | stmpe1600 = NULL; |
licio.mapelli@st.com | 48:e799ad44dab7 | 161 | delete Switch; |
licio.mapelli@st.com | 48:e799ad44dab7 | 162 | Switch = NULL; |
licio.mapelli@st.com | 48:e799ad44dab7 | 163 | delete display; |
licio.mapelli@st.com | 48:e799ad44dab7 | 164 | display = NULL; |
gallonm | 27:22c6f69967d9 | 165 | _instance=NULL; |
gallonm | 16:0d4776564733 | 166 | } |
licio.mapelli@st.com | 33:1573db91352c | 167 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 168 | /** |
licio.mapelli@st.com | 48:e799ad44dab7 | 169 | * @brief Override default copy constructor as empty |
licio.mapelli@st.com | 48:e799ad44dab7 | 170 | * @param[in] &X_NUCLEO_6180XA1 singleton object reference |
licio.mapelli@st.com | 48:e799ad44dab7 | 171 | * @return |
licio.mapelli@st.com | 48:e799ad44dab7 | 172 | */ |
licio.mapelli@st.com | 48:e799ad44dab7 | 173 | X_NUCLEO_6180XA1() {}; |
licio.mapelli@st.com | 48:e799ad44dab7 | 174 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 175 | /** |
licio.mapelli@st.com | 48:e799ad44dab7 | 176 | * @brief Override default assignement operator to avoid multiple singletons |
licio.mapelli@st.com | 48:e799ad44dab7 | 177 | * @param[in] &X_NUCLEO_6180XA1 singleton object reference |
licio.mapelli@st.com | 48:e799ad44dab7 | 178 | * @return |
licio.mapelli@st.com | 48:e799ad44dab7 | 179 | */ |
licio.mapelli@st.com | 48:e799ad44dab7 | 180 | void operator = (const X_NUCLEO_6180XA1&); |
licio.mapelli@st.com | 48:e799ad44dab7 | 181 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 182 | public: |
licio.mapelli@st.com | 48:e799ad44dab7 | 183 | /** |
licio.mapelli@st.com | 48:e799ad44dab7 | 184 | * @brief Creates a singleton object instance |
mapellil | 36:f6278b3e7c82 | 185 | * @param[in] &i2c device I2C to be used for communication |
licio.mapelli@st.com | 48:e799ad44dab7 | 186 | * @return Pointer to the object instance |
licio.mapelli@st.com | 48:e799ad44dab7 | 187 | */ |
mapellil | 36:f6278b3e7c82 | 188 | static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c); |
mapellil | 36:f6278b3e7c82 | 189 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 190 | /** |
licio.mapelli@st.com | 48:e799ad44dab7 | 191 | * @brief Creates a singleton object instance |
mapellil | 36:f6278b3e7c82 | 192 | * @param[in] &i2c device I2C to be used for communication |
mapellil | 36:f6278b3e7c82 | 193 | * @param[in] PinName gpio1_top the pin connected to top sensor INT |
mapellil | 36:f6278b3e7c82 | 194 | * @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT |
mapellil | 36:f6278b3e7c82 | 195 | * @param[in] PinName gpio1_left the pin connected to left sensor INT |
mapellil | 36:f6278b3e7c82 | 196 | * @param[in] PinName gpio1_right the pin connected to right sensor INT |
mapellil | 36:f6278b3e7c82 | 197 | * @return Pointer to the object instance |
mapellil | 36:f6278b3e7c82 | 198 | */ |
mapellil | 36:f6278b3e7c82 | 199 | static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom, |
mapellil | 36:f6278b3e7c82 | 200 | PinName gpio1_left, PinName gpio1_right); |
mapellil | 36:f6278b3e7c82 | 201 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 202 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 203 | |
mapellil | 36:f6278b3e7c82 | 204 | /** |
mapellil | 36:f6278b3e7c82 | 205 | * @brief Initialize the board and sensors with deft values |
mapellil | 36:f6278b3e7c82 | 206 | * @return 0 on success |
mapellil | 36:f6278b3e7c82 | 207 | */ |
mapellil | 36:f6278b3e7c82 | 208 | int InitBoard(); |
mapellil | 36:f6278b3e7c82 | 209 | |
mapellil | 36:f6278b3e7c82 | 210 | /** |
mapellil | 36:f6278b3e7c82 | 211 | * @brief Read the on board red slider switch |
mapellil | 36:f6278b3e7c82 | 212 | * @return 0 or 1 according to switch position |
mapellil | 36:f6278b3e7c82 | 213 | */ |
licio.mapelli@st.com | 33:1573db91352c | 214 | bool RdSwitch () { |
licio.mapelli@st.com | 33:1573db91352c | 215 | return Switch->RdSwitch(); |
licio.mapelli@st.com | 33:1573db91352c | 216 | } |
mapellil | 36:f6278b3e7c82 | 217 | |
gallonm | 16:0d4776564733 | 218 | DevI2C *dev_i2c; |
gallonm | 16:0d4776564733 | 219 | VL6180X *sensor_top; |
gallonm | 16:0d4776564733 | 220 | VL6180X *sensor_bottom; |
gallonm | 16:0d4776564733 | 221 | VL6180X *sensor_left; |
gallonm | 16:0d4776564733 | 222 | VL6180X *sensor_right; |
licio.mapelli@st.com | 48:e799ad44dab7 | 223 | STMPE1600 * stmpe1600; |
licio.mapelli@st.com | 48:e799ad44dab7 | 224 | SWITCH * Switch; |
licio.mapelli@st.com | 48:e799ad44dab7 | 225 | Display *display; |
licio.mapelli@st.com | 48:e799ad44dab7 | 226 | |
licio.mapelli@st.com | 48:e799ad44dab7 | 227 | private: |
gallonm | 16:0d4776564733 | 228 | STMPE1600DigiOut *gpio0_top; |
gallonm | 16:0d4776564733 | 229 | STMPE1600DigiOut *gpio0_bottom; |
gallonm | 16:0d4776564733 | 230 | STMPE1600DigiOut *gpio0_left; |
mapellil | 36:f6278b3e7c82 | 231 | STMPE1600DigiOut *gpio0_right; |
gallonm | 16:0d4776564733 | 232 | static X_NUCLEO_6180XA1 *_instance; |
gallonm | 10:4954b09b72d8 | 233 | }; |
gallonm | 0:1fb1f010ac84 | 234 | |
gallonm | 7:2dc81120c917 | 235 | #endif /* __X_NUCLEO_6180XA1_H */ |