Updates to follow mbed SDK coding style guidelines.

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   53L0A1_Satellites_with_Interrupts_OS5 Display_53L0A1_OS5

Fork of X_NUCLEO_53L0A1 by ST

Committer:
johnAlexander
Date:
Mon Dec 05 11:50:38 2016 +0000
Revision:
7:35ecf3e060c3
Parent:
5:c82a48da3c9e
Parent:
4:4e1576541eed
Child:
9:367d1f390cb2
Replace STM32 HAL_delay call with equivalent mbed wait_ms, for cross processor compatibility.; Import mbed.h in VL53L0X class to ease finding InterruptIn.; Minor code tidy up.

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 */
johnAlexander 0:c523920bcc09 50 //#define NEW_SENSOR_CENTRE_ADDRESS 0x54
johnAlexander 0:c523920bcc09 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 stmpe1600_exp0->writeSYS_CTRL (SOFT_RESET);
johnAlexander 0:c523920bcc09 70
johnAlexander 0:c523920bcc09 71 stmpe1600_exp1 = new STMPE1600(*ext_i2c, (0x42 * 2)); // U19
johnAlexander 0:c523920bcc09 72 stmpe1600_exp1->writeSYS_CTRL (SOFT_RESET);
johnAlexander 0:c523920bcc09 73
johnAlexander 0:c523920bcc09 74 display = new Display(*stmpe1600_exp0, *stmpe1600_exp1);
johnAlexander 0:c523920bcc09 75
johnAlexander 0:c523920bcc09 76 xshutdown_centre=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
johnAlexander 0:c523920bcc09 77 sensor_centre=new VL53L0X(*dev_i2c, *xshutdown_centre, A2);
johnAlexander 0:c523920bcc09 78
johnAlexander 1:01b8004bc0a7 79 xshutdown_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 80 sensor_left=new VL53L0X(*dev_i2c, *xshutdown_left, D8);
johnAlexander 0:c523920bcc09 81
johnAlexander 1:01b8004bc0a7 82 xshutdown_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 83 sensor_right=new VL53L0X(*dev_i2c, *xshutdown_right, D2);
johnAlexander 0:c523920bcc09 84 }
johnAlexander 0:c523920bcc09 85
johnAlexander 0:c523920bcc09 86 /** Constructor 2
johnAlexander 0:c523920bcc09 87 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 88 * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 89 * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 90 * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 91 * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
johnAlexander 0:c523920bcc09 92 */
johnAlexander 0:c523920bcc09 93 X_NUCLEO_53L0A1(DevI2C *ext_i2c, PinName gpio1_centre,
johnAlexander 0:c523920bcc09 94 PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
johnAlexander 0:c523920bcc09 95 stmpe1600_exp0 = new STMPE1600(*ext_i2c, (0x43 * 2)); // U21
johnAlexander 0:c523920bcc09 96 stmpe1600_exp0->writeSYS_CTRL(SOFT_RESET);
johnAlexander 0:c523920bcc09 97
johnAlexander 0:c523920bcc09 98 stmpe1600_exp1 = new STMPE1600(*ext_i2c, (0x42 * 2)); // U19
johnAlexander 0:c523920bcc09 99 stmpe1600_exp1->writeSYS_CTRL(SOFT_RESET);
johnAlexander 0:c523920bcc09 100
johnAlexander 0:c523920bcc09 101 display = new Display(*stmpe1600_exp0, *stmpe1600_exp1);
johnAlexander 0:c523920bcc09 102
johnAlexander 0:c523920bcc09 103 xshutdown_centre=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
johnAlexander 0:c523920bcc09 104 sensor_centre=new VL53L0X(*dev_i2c, *xshutdown_centre, gpio1_centre);
johnAlexander 0:c523920bcc09 105
johnAlexander 1:01b8004bc0a7 106 xshutdown_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 107 sensor_left=new VL53L0X(*dev_i2c, *xshutdown_left, gpio1_left);
johnAlexander 0:c523920bcc09 108
johnAlexander 1:01b8004bc0a7 109 xshutdown_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
johnAlexander 1:01b8004bc0a7 110 sensor_right=new VL53L0X(*dev_i2c, *xshutdown_right, gpio1_right);
johnAlexander 0:c523920bcc09 111 }
johnAlexander 0:c523920bcc09 112
johnAlexander 0:c523920bcc09 113 /** Destructor
johnAlexander 0:c523920bcc09 114 */
johnAlexander 0:c523920bcc09 115 ~X_NUCLEO_53L0A1()
johnAlexander 0:c523920bcc09 116 {
johnAlexander 0:c523920bcc09 117 if(xshutdown_centre!=NULL)
johnAlexander 0:c523920bcc09 118 {
johnAlexander 0:c523920bcc09 119 delete xshutdown_centre;
johnAlexander 0:c523920bcc09 120 xshutdown_centre=NULL;
johnAlexander 0:c523920bcc09 121 }
johnAlexander 0:c523920bcc09 122 if(sensor_centre!=NULL)
johnAlexander 0:c523920bcc09 123 {
johnAlexander 0:c523920bcc09 124 delete sensor_centre;
johnAlexander 0:c523920bcc09 125 sensor_centre=NULL;
johnAlexander 0:c523920bcc09 126 }
johnAlexander 1:01b8004bc0a7 127 if(xshutdown_left!=NULL)
johnAlexander 0:c523920bcc09 128 {
johnAlexander 0:c523920bcc09 129 delete xshutdown_left;
johnAlexander 0:c523920bcc09 130 xshutdown_left=NULL;
johnAlexander 0:c523920bcc09 131 }
johnAlexander 0:c523920bcc09 132 if(sensor_left!=NULL)
johnAlexander 0:c523920bcc09 133 {
johnAlexander 0:c523920bcc09 134 delete sensor_left;
johnAlexander 0:c523920bcc09 135 sensor_left=NULL;
johnAlexander 0:c523920bcc09 136 }
johnAlexander 0:c523920bcc09 137 if(xshutdown_right!=NULL)
johnAlexander 0:c523920bcc09 138 {
johnAlexander 0:c523920bcc09 139 delete xshutdown_right;
johnAlexander 0:c523920bcc09 140 xshutdown_right=NULL;
johnAlexander 0:c523920bcc09 141 }
johnAlexander 0:c523920bcc09 142 if(sensor_right!=NULL)
johnAlexander 0:c523920bcc09 143 {
johnAlexander 0:c523920bcc09 144 delete sensor_right;
johnAlexander 0:c523920bcc09 145 sensor_right=NULL;
johnAlexander 0:c523920bcc09 146 }
johnAlexander 1:01b8004bc0a7 147
johnAlexander 0:c523920bcc09 148 delete stmpe1600_exp0;
johnAlexander 0:c523920bcc09 149 stmpe1600_exp0 = NULL;
johnAlexander 0:c523920bcc09 150 delete stmpe1600_exp1;
johnAlexander 0:c523920bcc09 151 stmpe1600_exp1 = NULL;
johnAlexander 0:c523920bcc09 152 delete display;
johnAlexander 0:c523920bcc09 153 display = NULL;
johnAlexander 0:c523920bcc09 154 _instance=NULL;
johnAlexander 0:c523920bcc09 155 }
johnAlexander 0:c523920bcc09 156
johnAlexander 0:c523920bcc09 157 /**
johnAlexander 0:c523920bcc09 158 * @brief Creates a singleton object instance
johnAlexander 0:c523920bcc09 159 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 160 * @return Pointer to the object instance
johnAlexander 0:c523920bcc09 161 */
johnAlexander 0:c523920bcc09 162 static X_NUCLEO_53L0A1 *Instance(DevI2C *ext_i2c);
johnAlexander 0:c523920bcc09 163
johnAlexander 0:c523920bcc09 164 /**
johnAlexander 0:c523920bcc09 165 * @brief Creates a singleton object instance
johnAlexander 0:c523920bcc09 166 * @param[in] &i2c device I2C to be used for communication
johnAlexander 0:c523920bcc09 167 * @param[in] PinName gpio1_centre the pin connected to top sensor INT
johnAlexander 0:c523920bcc09 168 * @param[in] PinName gpio1_left the pin connected to left sensor INT
johnAlexander 0:c523920bcc09 169 * @param[in] PinName gpio1_right the pin connected to right sensor INT
johnAlexander 0:c523920bcc09 170 * @return Pointer to the object instance
johnAlexander 0:c523920bcc09 171 */
johnAlexander 0:c523920bcc09 172 static X_NUCLEO_53L0A1 *Instance(DevI2C *ext_i2c, PinName gpio1_centre,
johnAlexander 0:c523920bcc09 173 PinName gpio1_left, PinName gpio1_right);
johnAlexander 0:c523920bcc09 174
johnAlexander 0:c523920bcc09 175 /**
johnAlexander 0:c523920bcc09 176 * @brief Initialize the board and sensors with deft values
johnAlexander 0:c523920bcc09 177 * @return 0 on success
johnAlexander 0:c523920bcc09 178 */
johnAlexander 0:c523920bcc09 179 int InitBoard();
johnAlexander 0:c523920bcc09 180
johnAlexander 0:c523920bcc09 181 DevI2C *dev_i2c;
johnAlexander 0:c523920bcc09 182 VL53L0X *sensor_centre;
johnAlexander 1:01b8004bc0a7 183 VL53L0X *sensor_left;
johnAlexander 1:01b8004bc0a7 184 VL53L0X *sensor_right;
johnAlexander 0:c523920bcc09 185 STMPE1600 *stmpe1600_exp0;
johnAlexander 0:c523920bcc09 186 STMPE1600 *stmpe1600_exp1;
johnAlexander 0:c523920bcc09 187 STMPE1600DigiOut *xshutdown_centre;
johnAlexander 1:01b8004bc0a7 188 STMPE1600DigiOut *xshutdown_left;
johnAlexander 1:01b8004bc0a7 189 STMPE1600DigiOut *xshutdown_right;
johnAlexander 0:c523920bcc09 190 Display *display;
johnAlexander 0:c523920bcc09 191
johnAlexander 0:c523920bcc09 192 private:
johnAlexander 0:c523920bcc09 193 static X_NUCLEO_53L0A1 *_instance;
johnAlexander 0:c523920bcc09 194 };
johnAlexander 0:c523920bcc09 195
johnAlexander 0:c523920bcc09 196 #endif /* __X_NUCLEO_53L0A1_H */
johnAlexander 0:c523920bcc09 197
johnAlexander 0:c523920bcc09 198