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:03:50 2016 +0000
Revision:
4:4e1576541eed
Parent:
1:01b8004bc0a7
Child:
7:35ecf3e060c3
Minor code tidy-up.

Who changed what in which revision?

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