Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
fabiombed
Date:
Fri Mar 11 09:47:43 2016 +0000
Revision:
42:692c6223dc24
Parent:
37:837cffa6b530
Now you can use NC as InterruptIn

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 -------------------------------------------------------------------*/
mapellil 36:f6278b3e7c82 60 /** Class representing the X-NUCLEO-VL6180XA1 expansion board
mapellil 36:f6278b3e7c82 61 */
gallonm 10:4954b09b72d8 62 class X_NUCLEO_6180XA1
gallonm 4:a5abf7757947 63 {
gallonm 16:0d4776564733 64 public:
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 33:1573db91352c 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 33:1573db91352c 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 33:1573db91352c 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 33:1573db91352c 157 sensor_right=NULL;
gallonm 16:0d4776564733 158 }
mapellil 36:f6278b3e7c82 159 delete stmpe1600;
mapellil 36:f6278b3e7c82 160 stmpe1600 = NULL;
mapellil 36:f6278b3e7c82 161 delete Switch;
mapellil 36:f6278b3e7c82 162 Switch = NULL;
mapellil 36:f6278b3e7c82 163 delete display;
mapellil 36:f6278b3e7c82 164 display = NULL;
gallonm 27:22c6f69967d9 165 _instance=NULL;
gallonm 16:0d4776564733 166 }
licio.mapelli@st.com 33:1573db91352c 167
mapellil 36:f6278b3e7c82 168 /**
mapellil 36:f6278b3e7c82 169 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 170 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 171 * @return Pointer to the object instance
mapellil 36:f6278b3e7c82 172 */
mapellil 36:f6278b3e7c82 173 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
mapellil 36:f6278b3e7c82 174
mapellil 36:f6278b3e7c82 175 /**
mapellil 36:f6278b3e7c82 176 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 177 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 178 * @param[in] PinName gpio1_top the pin connected to top sensor INT
mapellil 36:f6278b3e7c82 179 * @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT
mapellil 36:f6278b3e7c82 180 * @param[in] PinName gpio1_left the pin connected to left sensor INT
mapellil 36:f6278b3e7c82 181 * @param[in] PinName gpio1_right the pin connected to right sensor INT
mapellil 36:f6278b3e7c82 182 * @return Pointer to the object instance
mapellil 36:f6278b3e7c82 183 */
mapellil 36:f6278b3e7c82 184 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 185 PinName gpio1_left, PinName gpio1_right);
mapellil 36:f6278b3e7c82 186
mapellil 36:f6278b3e7c82 187 /**
mapellil 36:f6278b3e7c82 188 * @brief Initialize the board and sensors with deft values
mapellil 36:f6278b3e7c82 189 * @return 0 on success
mapellil 36:f6278b3e7c82 190 */
mapellil 36:f6278b3e7c82 191 int InitBoard();
mapellil 36:f6278b3e7c82 192
mapellil 36:f6278b3e7c82 193 /**
mapellil 36:f6278b3e7c82 194 * @brief Read the on board red slider switch
mapellil 36:f6278b3e7c82 195 * @return 0 or 1 according to switch position
mapellil 36:f6278b3e7c82 196 */
licio.mapelli@st.com 33:1573db91352c 197 bool RdSwitch () {
licio.mapelli@st.com 33:1573db91352c 198 return Switch->RdSwitch();
licio.mapelli@st.com 33:1573db91352c 199 }
mapellil 36:f6278b3e7c82 200
gallonm 16:0d4776564733 201 DevI2C *dev_i2c;
gallonm 16:0d4776564733 202 VL6180X *sensor_top;
gallonm 16:0d4776564733 203 VL6180X *sensor_bottom;
gallonm 16:0d4776564733 204 VL6180X *sensor_left;
gallonm 16:0d4776564733 205 VL6180X *sensor_right;
mapellil 36:f6278b3e7c82 206 STMPE1600 * stmpe1600;
mapellil 36:f6278b3e7c82 207 SWITCH * Switch;
gallonm 16:0d4776564733 208 STMPE1600DigiOut *gpio0_top;
gallonm 16:0d4776564733 209 STMPE1600DigiOut *gpio0_bottom;
gallonm 16:0d4776564733 210 STMPE1600DigiOut *gpio0_left;
mapellil 36:f6278b3e7c82 211 STMPE1600DigiOut *gpio0_right;
mapellil 36:f6278b3e7c82 212 Display *display;
gallonm 16:0d4776564733 213
mapellil 36:f6278b3e7c82 214 private:
gallonm 16:0d4776564733 215 static X_NUCLEO_6180XA1 *_instance;
gallonm 10:4954b09b72d8 216 };
gallonm 0:1fb1f010ac84 217
gallonm 7:2dc81120c917 218 #endif /* __X_NUCLEO_6180XA1_H */