Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
mapellil
Date:
Tue Nov 24 16:04:41 2015 +0000
Revision:
36:f6278b3e7c82
Parent:
33:1573db91352c
Child:
37:837cffa6b530
Exposed GPIOs on constructor, code cleanup, doxy comment

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);
gallonm 16:0d4776564733 76 sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0);
gallonm 16:0d4776564733 77
gallonm 16:0d4776564733 78 gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
gallonm 16:0d4776564733 79 sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, PA_4);
gallonm 16:0d4776564733 80
gallonm 16:0d4776564733 81 gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
gallonm 16:0d4776564733 82 sensor_left=new VL6180X(*dev_i2c, *gpio0_left, PA_5);
gallonm 16:0d4776564733 83
gallonm 16:0d4776564733 84 gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
gallonm 16:0d4776564733 85 sensor_right=new VL6180X(*dev_i2c, *gpio0_right, PA_10);
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);
mapellil 36:f6278b3e7c82 98 Switch = new SWITCH (*stmpe1600, GPIO_11);
mapellil 36:f6278b3e7c82 99 display = new Display(*stmpe1600);
mapellil 36:f6278b3e7c82 100
mapellil 36:f6278b3e7c82 101 gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
mapellil 36:f6278b3e7c82 102 sensor_top=new VL6180X(*dev_i2c, *gpio0_top, gpio1_top);
mapellil 36:f6278b3e7c82 103
mapellil 36:f6278b3e7c82 104 gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
mapellil 36:f6278b3e7c82 105 sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, gpio1_bottom);
mapellil 36:f6278b3e7c82 106
mapellil 36:f6278b3e7c82 107 gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
mapellil 36:f6278b3e7c82 108 sensor_left=new VL6180X(*dev_i2c, *gpio0_left, gpio1_left);
mapellil 36:f6278b3e7c82 109
mapellil 36:f6278b3e7c82 110 gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
mapellil 36:f6278b3e7c82 111 sensor_right=new VL6180X(*dev_i2c, *gpio0_right, gpio1_right);
mapellil 36:f6278b3e7c82 112 }
mapellil 36:f6278b3e7c82 113
mapellil 36:f6278b3e7c82 114 /** Destructor
mapellil 36:f6278b3e7c82 115 */
gallonm 16:0d4776564733 116 ~X_NUCLEO_6180XA1()
gallonm 10:4954b09b72d8 117 {
gallonm 16:0d4776564733 118 if(gpio0_top!=NULL)
gallonm 16:0d4776564733 119 {
gallonm 16:0d4776564733 120 delete gpio0_top;
gallonm 16:0d4776564733 121 gpio0_top=NULL;
gallonm 16:0d4776564733 122 }
gallonm 16:0d4776564733 123 if(sensor_top!=NULL)
gallonm 16:0d4776564733 124 {
gallonm 16:0d4776564733 125 delete sensor_top;
licio.mapelli@st.com 33:1573db91352c 126 sensor_top=NULL;
gallonm 16:0d4776564733 127 }
gallonm 16:0d4776564733 128 if(gpio0_bottom!=NULL)
gallonm 16:0d4776564733 129 {
gallonm 16:0d4776564733 130 delete gpio0_bottom;
gallonm 16:0d4776564733 131 gpio0_bottom=NULL;
gallonm 16:0d4776564733 132 }
gallonm 16:0d4776564733 133 if(sensor_bottom!=NULL)
gallonm 16:0d4776564733 134 {
gallonm 16:0d4776564733 135 delete sensor_bottom;
licio.mapelli@st.com 33:1573db91352c 136 sensor_bottom=NULL;
gallonm 16:0d4776564733 137 }
gallonm 16:0d4776564733 138 if(gpio0_left!=NULL)
gallonm 16:0d4776564733 139 {
gallonm 16:0d4776564733 140 delete gpio0_left;
gallonm 16:0d4776564733 141 gpio0_left=NULL;
gallonm 16:0d4776564733 142 }
gallonm 16:0d4776564733 143 if(sensor_left!=NULL)
gallonm 16:0d4776564733 144 {
gallonm 16:0d4776564733 145 delete sensor_left;
licio.mapelli@st.com 33:1573db91352c 146 sensor_left=NULL;
gallonm 16:0d4776564733 147 }
gallonm 16:0d4776564733 148 if(gpio0_right!=NULL)
gallonm 16:0d4776564733 149 {
gallonm 16:0d4776564733 150 delete gpio0_right;
gallonm 16:0d4776564733 151 gpio0_right=NULL;
gallonm 16:0d4776564733 152 }
gallonm 16:0d4776564733 153 if(sensor_right!=NULL)
gallonm 16:0d4776564733 154 {
gallonm 16:0d4776564733 155 delete sensor_right;
licio.mapelli@st.com 33:1573db91352c 156 sensor_right=NULL;
gallonm 16:0d4776564733 157 }
mapellil 36:f6278b3e7c82 158 delete stmpe1600;
mapellil 36:f6278b3e7c82 159 stmpe1600 = NULL;
mapellil 36:f6278b3e7c82 160 delete Switch;
mapellil 36:f6278b3e7c82 161 Switch = NULL;
mapellil 36:f6278b3e7c82 162 delete display;
mapellil 36:f6278b3e7c82 163 display = NULL;
gallonm 27:22c6f69967d9 164 _instance=NULL;
gallonm 16:0d4776564733 165 }
licio.mapelli@st.com 33:1573db91352c 166
mapellil 36:f6278b3e7c82 167 /**
mapellil 36:f6278b3e7c82 168 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 169 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 170 * @return Pointer to the object instance
mapellil 36:f6278b3e7c82 171 */
mapellil 36:f6278b3e7c82 172 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
mapellil 36:f6278b3e7c82 173
mapellil 36:f6278b3e7c82 174 /**
mapellil 36:f6278b3e7c82 175 * @brief Creates a singleton object instance
mapellil 36:f6278b3e7c82 176 * @param[in] &i2c device I2C to be used for communication
mapellil 36:f6278b3e7c82 177 * @param[in] PinName gpio1_top the pin connected to top sensor INT
mapellil 36:f6278b3e7c82 178 * @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT
mapellil 36:f6278b3e7c82 179 * @param[in] PinName gpio1_left the pin connected to left sensor INT
mapellil 36:f6278b3e7c82 180 * @param[in] PinName gpio1_right the pin connected to right sensor INT
mapellil 36:f6278b3e7c82 181 * @return Pointer to the object instance
mapellil 36:f6278b3e7c82 182 */
mapellil 36:f6278b3e7c82 183 static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 184 PinName gpio1_left, PinName gpio1_right);
mapellil 36:f6278b3e7c82 185
mapellil 36:f6278b3e7c82 186 /**
mapellil 36:f6278b3e7c82 187 * @brief Initialize the board and sensors with deft values
mapellil 36:f6278b3e7c82 188 * @return 0 on success
mapellil 36:f6278b3e7c82 189 */
mapellil 36:f6278b3e7c82 190 int InitBoard();
mapellil 36:f6278b3e7c82 191
mapellil 36:f6278b3e7c82 192 /**
mapellil 36:f6278b3e7c82 193 * @brief Read the on board red slider switch
mapellil 36:f6278b3e7c82 194 * @return 0 or 1 according to switch position
mapellil 36:f6278b3e7c82 195 */
licio.mapelli@st.com 33:1573db91352c 196 bool RdSwitch () {
licio.mapelli@st.com 33:1573db91352c 197 return Switch->RdSwitch();
licio.mapelli@st.com 33:1573db91352c 198 }
mapellil 36:f6278b3e7c82 199
gallonm 16:0d4776564733 200 DevI2C *dev_i2c;
gallonm 16:0d4776564733 201 VL6180X *sensor_top;
gallonm 16:0d4776564733 202 VL6180X *sensor_bottom;
gallonm 16:0d4776564733 203 VL6180X *sensor_left;
gallonm 16:0d4776564733 204 VL6180X *sensor_right;
mapellil 36:f6278b3e7c82 205 STMPE1600 * stmpe1600;
mapellil 36:f6278b3e7c82 206 SWITCH * Switch;
gallonm 16:0d4776564733 207 STMPE1600DigiOut *gpio0_top;
gallonm 16:0d4776564733 208 STMPE1600DigiOut *gpio0_bottom;
gallonm 16:0d4776564733 209 STMPE1600DigiOut *gpio0_left;
mapellil 36:f6278b3e7c82 210 STMPE1600DigiOut *gpio0_right;
mapellil 36:f6278b3e7c82 211 Display *display;
gallonm 16:0d4776564733 212
mapellil 36:f6278b3e7c82 213 private:
gallonm 16:0d4776564733 214 static X_NUCLEO_6180XA1 *_instance;
gallonm 10:4954b09b72d8 215 };
gallonm 0:1fb1f010ac84 216
gallonm 7:2dc81120c917 217 #endif /* __X_NUCLEO_6180XA1_H */