Fixed STMPE1600 writeSYS_CTRL, enabled multi sensors support

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_53L0A1 by ST

Committer:
mapellil
Date:
Mon Mar 27 12:37:57 2017 +0000
Revision:
9:992abcfb7ef5
Parent:
7:35ecf3e060c3
Fixed STMPE1600 writeSYS_CTRL(), enabled multi sensors support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:c523920bcc09 1 /**
johnAlexander 0:c523920bcc09 2 ******************************************************************************
johnAlexander 0:c523920bcc09 3 * @file x_nucleo_53L0A1.h
johnAlexander 0:c523920bcc09 4 * @author IMG
johnAlexander 1:01b8004bc0a7 5 * @version V1.0.0
johnAlexander 1:01b8004bc0a7 6 * @date 28-November-2016
johnAlexander 0:c523920bcc09 7 * @brief Header file for class X_NUCLEO_53L0A1 representing a X-NUCLEO-53L0A1
johnAlexander 0:c523920bcc09 8 * expansion board
johnAlexander 0:c523920bcc09 9 ******************************************************************************
johnAlexander 0:c523920bcc09 10 * @attention
johnAlexander 0:c523920bcc09 11 *
johnAlexander 0:c523920bcc09 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
johnAlexander 0:c523920bcc09 13 *
johnAlexander 0:c523920bcc09 14 * Redistribution and use in source and binary forms, with or without modification,
johnAlexander 0:c523920bcc09 15 * are permitted provided that the following conditions are met:
johnAlexander 0:c523920bcc09 16 * 1. Redistributions of source code must retain the above copyright notice,
johnAlexander 0:c523920bcc09 17 * this list of conditions and the following disclaimer.
johnAlexander 0:c523920bcc09 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
johnAlexander 0:c523920bcc09 19 * this list of conditions and the following disclaimer in the documentation
johnAlexander 0:c523920bcc09 20 * and/or other materials provided with the distribution.
johnAlexander 0:c523920bcc09 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
johnAlexander 0:c523920bcc09 22 * may be used to endorse or promote products derived from this software
johnAlexander 0:c523920bcc09 23 * without specific prior written permission.
johnAlexander 0:c523920bcc09 24 *
johnAlexander 0:c523920bcc09 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
johnAlexander 0:c523920bcc09 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
johnAlexander 0:c523920bcc09 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
johnAlexander 0:c523920bcc09 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
johnAlexander 0:c523920bcc09 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
johnAlexander 0:c523920bcc09 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
johnAlexander 0:c523920bcc09 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
johnAlexander 0:c523920bcc09 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
johnAlexander 0:c523920bcc09 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
johnAlexander 0:c523920bcc09 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
johnAlexander 0:c523920bcc09 35 *
johnAlexander 0:c523920bcc09 36 ******************************************************************************
johnAlexander 0:c523920bcc09 37 */
johnAlexander 0:c523920bcc09 38
johnAlexander 0:c523920bcc09 39 /* Define to prevent from recursive inclusion --------------------------------*/
johnAlexander 0:c523920bcc09 40 #ifndef __X_NUCLEO_53L0A1_H
johnAlexander 0:c523920bcc09 41 #define __X_NUCLEO_53L0A1_H
johnAlexander 0:c523920bcc09 42
johnAlexander 0:c523920bcc09 43 /* Includes ------------------------------------------------------------------*/
johnAlexander 0:c523920bcc09 44 #include "vl53l0x_class.h"
johnAlexander 0:c523920bcc09 45 #include "Display_class.h"
johnAlexander 0:c523920bcc09 46 #include "stmpe1600_class.h"
johnAlexander 0:c523920bcc09 47 #include "DevI2C.h"
johnAlexander 0:c523920bcc09 48
johnAlexander 0:c523920bcc09 49 /** New device addresses */
mapellil 9:992abcfb7ef5 50 #define NEW_SENSOR_CENTRE_ADDRESS 0x54
mapellil 9:992abcfb7ef5 51 //#define NEW_SENSOR_CENTRE_ADDRESS 0x52
johnAlexander 0:c523920bcc09 52 #define NEW_SENSOR_LEFT_ADDRESS 0x56
johnAlexander 0:c523920bcc09 53 #define NEW_SENSOR_RIGHT_ADDRESS 0x58
johnAlexander 0:c523920bcc09 54
johnAlexander 0:c523920bcc09 55 /* Classes--------------------------------------------------------------------*/
johnAlexander 0:c523920bcc09 56
johnAlexander 0:c523920bcc09 57 /* Classes -------------------------------------------------------------------*/
johnAlexander 0:c523920bcc09 58 /** Class representing the X-NUCLEO-VL53L0A1 expansion board
johnAlexander 0:c523920bcc09 59 */
johnAlexander 0:c523920bcc09 60 class X_NUCLEO_53L0A1
johnAlexander 0:c523920bcc09 61 {
johnAlexander 5:c82a48da3c9e 62 public:
johnAlexander 0:c523920bcc09 63 /** Constructor 1
johnAlexander 0:c523920bcc09 64 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 65 */
johnAlexander 0:c523920bcc09 66 X_NUCLEO_53L0A1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
johnAlexander 0:c523920bcc09 67 {
johnAlexander 0:c523920bcc09 68 stmpe1600_exp0 = new STMPE1600(*ext_i2c, (0x43 * 2)); // U21
johnAlexander 0:c523920bcc09 69
johnAlexander 0:c523920bcc09 70 stmpe1600_exp1 = new STMPE1600(*ext_i2c, (0x42 * 2)); // U19
johnAlexander 0:c523920bcc09 71
johnAlexander 0:c523920bcc09 72 display = new Display(*stmpe1600_exp0, *stmpe1600_exp1);
johnAlexander 0:c523920bcc09 73
johnAlexander 0:c523920bcc09 74 xshutdown_centre=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
johnAlexander 0:c523920bcc09 75 sensor_centre=new VL53L0X(*dev_i2c, *xshutdown_centre, A2);
johnAlexander 0:c523920bcc09 76
johnAlexander 1:01b8004bc0a7 77 xshutdown_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 78 sensor_left=new VL53L0X(*dev_i2c, *xshutdown_left, D8);
johnAlexander 0:c523920bcc09 79
johnAlexander 1:01b8004bc0a7 80 xshutdown_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 81 sensor_right=new VL53L0X(*dev_i2c, *xshutdown_right, D2);
johnAlexander 0:c523920bcc09 82 }
johnAlexander 0:c523920bcc09 83
johnAlexander 0:c523920bcc09 84 /** Constructor 2
johnAlexander 0:c523920bcc09 85 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 86 * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 87 * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 88 * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 89 * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 90 */
johnAlexander 0:c523920bcc09 91 X_NUCLEO_53L0A1(DevI2C *ext_i2c, PinName gpio1_centre,
johnAlexander 0:c523920bcc09 92 PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
johnAlexander 0:c523920bcc09 93 stmpe1600_exp0 = new STMPE1600(*ext_i2c, (0x43 * 2)); // U21
johnAlexander 0:c523920bcc09 94
johnAlexander 0:c523920bcc09 95 stmpe1600_exp1 = new STMPE1600(*ext_i2c, (0x42 * 2)); // U19
johnAlexander 0:c523920bcc09 96
johnAlexander 0:c523920bcc09 97 display = new Display(*stmpe1600_exp0, *stmpe1600_exp1);
johnAlexander 0:c523920bcc09 98
johnAlexander 0:c523920bcc09 99 xshutdown_centre=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
johnAlexander 0:c523920bcc09 100 sensor_centre=new VL53L0X(*dev_i2c, *xshutdown_centre, gpio1_centre);
johnAlexander 0:c523920bcc09 101
johnAlexander 1:01b8004bc0a7 102 xshutdown_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 103 sensor_left=new VL53L0X(*dev_i2c, *xshutdown_left, gpio1_left);
johnAlexander 0:c523920bcc09 104
johnAlexander 1:01b8004bc0a7 105 xshutdown_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 106 sensor_right=new VL53L0X(*dev_i2c, *xshutdown_right, gpio1_right);
johnAlexander 0:c523920bcc09 107 }
johnAlexander 0:c523920bcc09 108
johnAlexander 0:c523920bcc09 109 /** Destructor
johnAlexander 0:c523920bcc09 110 */
johnAlexander 0:c523920bcc09 111 ~X_NUCLEO_53L0A1()
johnAlexander 0:c523920bcc09 112 {
johnAlexander 0:c523920bcc09 113 if(xshutdown_centre!=NULL)
johnAlexander 0:c523920bcc09 114 {
johnAlexander 0:c523920bcc09 115 delete xshutdown_centre;
johnAlexander 0:c523920bcc09 116 xshutdown_centre=NULL;
johnAlexander 0:c523920bcc09 117 }
johnAlexander 0:c523920bcc09 118 if(sensor_centre!=NULL)
johnAlexander 0:c523920bcc09 119 {
johnAlexander 0:c523920bcc09 120 delete sensor_centre;
johnAlexander 0:c523920bcc09 121 sensor_centre=NULL;
johnAlexander 0:c523920bcc09 122 }
johnAlexander 1:01b8004bc0a7 123 if(xshutdown_left!=NULL)
johnAlexander 0:c523920bcc09 124 {
johnAlexander 0:c523920bcc09 125 delete xshutdown_left;
johnAlexander 0:c523920bcc09 126 xshutdown_left=NULL;
johnAlexander 0:c523920bcc09 127 }
johnAlexander 0:c523920bcc09 128 if(sensor_left!=NULL)
johnAlexander 0:c523920bcc09 129 {
johnAlexander 0:c523920bcc09 130 delete sensor_left;
johnAlexander 0:c523920bcc09 131 sensor_left=NULL;
johnAlexander 0:c523920bcc09 132 }
johnAlexander 0:c523920bcc09 133 if(xshutdown_right!=NULL)
johnAlexander 0:c523920bcc09 134 {
johnAlexander 0:c523920bcc09 135 delete xshutdown_right;
johnAlexander 0:c523920bcc09 136 xshutdown_right=NULL;
johnAlexander 0:c523920bcc09 137 }
johnAlexander 0:c523920bcc09 138 if(sensor_right!=NULL)
johnAlexander 0:c523920bcc09 139 {
johnAlexander 0:c523920bcc09 140 delete sensor_right;
johnAlexander 0:c523920bcc09 141 sensor_right=NULL;
johnAlexander 0:c523920bcc09 142 }
johnAlexander 1:01b8004bc0a7 143
johnAlexander 0:c523920bcc09 144 delete stmpe1600_exp0;
johnAlexander 0:c523920bcc09 145 stmpe1600_exp0 = NULL;
johnAlexander 0:c523920bcc09 146 delete stmpe1600_exp1;
johnAlexander 0:c523920bcc09 147 stmpe1600_exp1 = NULL;
johnAlexander 0:c523920bcc09 148 delete display;
johnAlexander 0:c523920bcc09 149 display = NULL;
johnAlexander 0:c523920bcc09 150 _instance=NULL;
johnAlexander 0:c523920bcc09 151 }
johnAlexander 0:c523920bcc09 152
johnAlexander 0:c523920bcc09 153 /**
johnAlexander 0:c523920bcc09 154 * @brief Creates a singleton object instance
johnAlexander 0:c523920bcc09 155 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 156 * @return Pointer to the object instance
johnAlexander 0:c523920bcc09 157 */
johnAlexander 0:c523920bcc09 158 static X_NUCLEO_53L0A1 *Instance(DevI2C *ext_i2c);
johnAlexander 0:c523920bcc09 159
johnAlexander 0:c523920bcc09 160 /**
johnAlexander 0:c523920bcc09 161 * @brief Creates a singleton object instance
johnAlexander 0:c523920bcc09 162 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 163 * @param[in] PinName gpio1_centre the pin connected to top sensor INT
johnAlexander 0:c523920bcc09 164 * @param[in] PinName gpio1_left the pin connected to left sensor INT
johnAlexander 0:c523920bcc09 165 * @param[in] PinName gpio1_right the pin connected to right sensor INT
johnAlexander 0:c523920bcc09 166 * @return Pointer to the object instance
johnAlexander 0:c523920bcc09 167 */
johnAlexander 0:c523920bcc09 168 static X_NUCLEO_53L0A1 *Instance(DevI2C *ext_i2c, PinName gpio1_centre,
johnAlexander 0:c523920bcc09 169 PinName gpio1_left, PinName gpio1_right);
johnAlexander 0:c523920bcc09 170
johnAlexander 0:c523920bcc09 171 /**
johnAlexander 0:c523920bcc09 172 * @brief Initialize the board and sensors with deft values
johnAlexander 0:c523920bcc09 173 * @return 0 on success
johnAlexander 0:c523920bcc09 174 */
johnAlexander 0:c523920bcc09 175 int InitBoard();
johnAlexander 0:c523920bcc09 176
johnAlexander 0:c523920bcc09 177 DevI2C *dev_i2c;
johnAlexander 0:c523920bcc09 178 VL53L0X *sensor_centre;
johnAlexander 1:01b8004bc0a7 179 VL53L0X *sensor_left;
johnAlexander 1:01b8004bc0a7 180 VL53L0X *sensor_right;
johnAlexander 0:c523920bcc09 181 STMPE1600 *stmpe1600_exp0;
johnAlexander 0:c523920bcc09 182 STMPE1600 *stmpe1600_exp1;
johnAlexander 0:c523920bcc09 183 STMPE1600DigiOut *xshutdown_centre;
johnAlexander 1:01b8004bc0a7 184 STMPE1600DigiOut *xshutdown_left;
johnAlexander 1:01b8004bc0a7 185 STMPE1600DigiOut *xshutdown_right;
johnAlexander 0:c523920bcc09 186 Display *display;
johnAlexander 0:c523920bcc09 187
johnAlexander 0:c523920bcc09 188 private:
johnAlexander 0:c523920bcc09 189 static X_NUCLEO_53L0A1 *_instance;
johnAlexander 0:c523920bcc09 190 };
johnAlexander 0:c523920bcc09 191
johnAlexander 0:c523920bcc09 192 #endif /* __X_NUCLEO_53L0A1_H */
johnAlexander 0:c523920bcc09 193
johnAlexander 0:c523920bcc09 194