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:
JerrySzczurak
Date:
Wed Jun 28 12:23:03 2017 +0000
Revision:
21:627b65069e6d
Parent:
16:98ce55ddbb1a
Cosmetic changes to v53l0x class; wrWord and rdWord calls changed to write_word and read_word

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