VL53L3 Shield specific functions.

Dependents:   53L3A2_Ranging X_NUCLEO_53L3CX

Committer:
charlesmn
Date:
Fri Oct 16 15:11:45 2020 +0000
Revision:
0:ba15439f45dd
Change VL53L1 to VL53L3. Change name

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:ba15439f45dd 1 /**
charlesmn 0:ba15439f45dd 2 ******************************************************************************
charlesmn 0:ba15439f45dd 3 * @file stmpe1600_class.h
charlesmn 0:ba15439f45dd 4 * @author AST / EST
charlesmn 0:ba15439f45dd 5 * @version V0.0.1
charlesmn 0:ba15439f45dd 6 * @date 14-April-2015
charlesmn 0:ba15439f45dd 7 * @brief Header file for component stmpe1600
charlesmn 0:ba15439f45dd 8 ******************************************************************************
charlesmn 0:ba15439f45dd 9 * @attention
charlesmn 0:ba15439f45dd 10 *
charlesmn 0:ba15439f45dd 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
charlesmn 0:ba15439f45dd 12 *
charlesmn 0:ba15439f45dd 13 * Redistribution and use in source and binary forms, with or without modification,
charlesmn 0:ba15439f45dd 14 * are permitted provided that the following conditions are met:
charlesmn 0:ba15439f45dd 15 * 1. Redistributions of source code must retain the above copyright notice,
charlesmn 0:ba15439f45dd 16 * this list of conditions and the following disclaimer.
charlesmn 0:ba15439f45dd 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
charlesmn 0:ba15439f45dd 18 * this list of conditions and the following disclaimer in the documentation
charlesmn 0:ba15439f45dd 19 * and/or other materials provided with the distribution.
charlesmn 0:ba15439f45dd 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
charlesmn 0:ba15439f45dd 21 * may be used to endorse or promote products derived from this software
charlesmn 0:ba15439f45dd 22 * without specific prior written permission.
charlesmn 0:ba15439f45dd 23 *
charlesmn 0:ba15439f45dd 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
charlesmn 0:ba15439f45dd 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
charlesmn 0:ba15439f45dd 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
charlesmn 0:ba15439f45dd 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
charlesmn 0:ba15439f45dd 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
charlesmn 0:ba15439f45dd 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
charlesmn 0:ba15439f45dd 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
charlesmn 0:ba15439f45dd 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
charlesmn 0:ba15439f45dd 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
charlesmn 0:ba15439f45dd 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
charlesmn 0:ba15439f45dd 34 *
charlesmn 0:ba15439f45dd 35 ******************************************************************************
charlesmn 0:ba15439f45dd 36 */
charlesmn 0:ba15439f45dd 37 #ifndef __STMPE1600_CLASS
charlesmn 0:ba15439f45dd 38 #define __STMPE1600_CLASS
charlesmn 0:ba15439f45dd 39 /* Includes ------------------------------------------------------------------*/
charlesmn 0:ba15439f45dd 40 #include "DevI2C.h"
charlesmn 0:ba15439f45dd 41
charlesmn 0:ba15439f45dd 42 #define STMPE1600_DEF_DEVICE_ADDRESS (uint8_t)0x42*2
charlesmn 0:ba15439f45dd 43 #define STMPE1600_DEF_DIGIOUT_LVL 1
charlesmn 0:ba15439f45dd 44
charlesmn 0:ba15439f45dd 45 /** STMPE1600 registr map **/
charlesmn 0:ba15439f45dd 46 #define CHIP_ID_0_7 (uint8_t)0x00
charlesmn 0:ba15439f45dd 47 #define CHIP_ID_8_15 (uint8_t)0x01
charlesmn 0:ba15439f45dd 48 #define VERSION_ID (uint8_t)0x02
charlesmn 0:ba15439f45dd 49 #define SYS_CTRL (uint8_t)0x03
charlesmn 0:ba15439f45dd 50 #define IEGPIOR_0_7 (uint8_t)0x08
charlesmn 0:ba15439f45dd 51 #define IEGPIOR_8_15 (uint8_t)0x09
charlesmn 0:ba15439f45dd 52 #define ISGPIOR_0_7 (uint8_t)0x0A
charlesmn 0:ba15439f45dd 53 #define ISGPIOR_8_15 (uint8_t)0x0B
charlesmn 0:ba15439f45dd 54 #define GPMR_0_7 (uint8_t)0x10
charlesmn 0:ba15439f45dd 55 #define GPMR_8_15 (uint8_t)0x11
charlesmn 0:ba15439f45dd 56 #define GPSR_0_7 (uint8_t)0x12
charlesmn 0:ba15439f45dd 57 #define GPSR_8_15 (uint8_t)0x13
charlesmn 0:ba15439f45dd 58 #define GPDR_0_7 (uint8_t)0x14
charlesmn 0:ba15439f45dd 59 #define GPDR_8_15 (uint8_t)0x15
charlesmn 0:ba15439f45dd 60 #define GPIR_0_7 (uint8_t)0x16
charlesmn 0:ba15439f45dd 61 #define GPIR_8_15 (uint8_t)0x17
charlesmn 0:ba15439f45dd 62
charlesmn 0:ba15439f45dd 63 #define SOFT_RESET (uint8_t)0x80
charlesmn 0:ba15439f45dd 64
charlesmn 0:ba15439f45dd 65 typedef enum {
charlesmn 0:ba15439f45dd 66 // GPIO Expander pin names
charlesmn 0:ba15439f45dd 67 GPIO_0 = 0,
charlesmn 0:ba15439f45dd 68 GPIO_1,
charlesmn 0:ba15439f45dd 69 GPIO_2,
charlesmn 0:ba15439f45dd 70 GPIO_3,
charlesmn 0:ba15439f45dd 71 GPIO_4,
charlesmn 0:ba15439f45dd 72 GPIO_5,
charlesmn 0:ba15439f45dd 73 GPIO_6,
charlesmn 0:ba15439f45dd 74 GPIO_7,
charlesmn 0:ba15439f45dd 75 GPIO_8,
charlesmn 0:ba15439f45dd 76 GPIO_9,
charlesmn 0:ba15439f45dd 77 GPIO_10,
charlesmn 0:ba15439f45dd 78 GPIO_11,
charlesmn 0:ba15439f45dd 79 GPIO_12,
charlesmn 0:ba15439f45dd 80 GPIO_13,
charlesmn 0:ba15439f45dd 81 GPIO_14,
charlesmn 0:ba15439f45dd 82 GPIO_15,
charlesmn 0:ba15439f45dd 83 NOT_CON
charlesmn 0:ba15439f45dd 84 } ExpGpioPinName;
charlesmn 0:ba15439f45dd 85
charlesmn 0:ba15439f45dd 86 typedef enum {
charlesmn 0:ba15439f45dd 87 INPUT = 0,
charlesmn 0:ba15439f45dd 88 OUTPUT,
charlesmn 0:ba15439f45dd 89 NOT_CONNECTED
charlesmn 0:ba15439f45dd 90 } ExpGpioPinDirection;
charlesmn 0:ba15439f45dd 91
charlesmn 0:ba15439f45dd 92 /* Classes -------------------------------------------------------------------*/
charlesmn 0:ba15439f45dd 93 /** Class representing a single stmpe1600 GPIO expander output pin
charlesmn 0:ba15439f45dd 94 */
charlesmn 0:ba15439f45dd 95 class Stmpe1600DigiOut
charlesmn 0:ba15439f45dd 96 {
charlesmn 0:ba15439f45dd 97
charlesmn 0:ba15439f45dd 98 public:
charlesmn 0:ba15439f45dd 99 /** Constructor
charlesmn 0:ba15439f45dd 100 * @param[in] &i2c device I2C to be used for communication
charlesmn 0:ba15439f45dd 101 * @param[in] outpinname the desired out pin name to be created
charlesmn 0:ba15439f45dd 102 * @param[in] DevAddr the stmpe1600 I2C device address (deft STMPE1600_DEF_DEVICE_ADDRESS)
charlesmn 0:ba15439f45dd 103 * @param[in] lvl the default ot pin level
charlesmn 0:ba15439f45dd 104 */
charlesmn 0:ba15439f45dd 105 Stmpe1600DigiOut(DevI2C &i2c, ExpGpioPinName out_pin_name, uint8_t dev_addr = STMPE1600_DEF_DEVICE_ADDRESS,
charlesmn 0:ba15439f45dd 106 bool lvl = STMPE1600_DEF_DIGIOUT_LVL) : dev_i2c(&i2c), exp_dev_addr(dev_addr), exp_pin_name(out_pin_name)
charlesmn 0:ba15439f45dd 107 {
charlesmn 0:ba15439f45dd 108 uint8_t data[2];
charlesmn 0:ba15439f45dd 109
charlesmn 0:ba15439f45dd 110 if (exp_pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 111 return;
charlesmn 0:ba15439f45dd 112 /* set the exp_pin_name as output */
charlesmn 0:ba15439f45dd 113 dev_i2c->i2c_read(data, exp_dev_addr, GPDR_0_7, 1);
charlesmn 0:ba15439f45dd 114 dev_i2c->i2c_read(&data[1], exp_dev_addr, GPDR_8_15, 1);
charlesmn 0:ba15439f45dd 115 *(uint16_t *)data = *(uint16_t *)data | (1 << (uint16_t)exp_pin_name); // set gpio as out
charlesmn 0:ba15439f45dd 116 dev_i2c->i2c_write(data, exp_dev_addr, GPDR_0_7, 1);
charlesmn 0:ba15439f45dd 117 dev_i2c->i2c_write(&data[1], exp_dev_addr, GPDR_8_15, 1);
charlesmn 0:ba15439f45dd 118 write(lvl);
charlesmn 0:ba15439f45dd 119 }
charlesmn 0:ba15439f45dd 120
charlesmn 0:ba15439f45dd 121 /**
charlesmn 0:ba15439f45dd 122 * @brief Write on the out pin
charlesmn 0:ba15439f45dd 123 * @param[in] lvl level to write
charlesmn 0:ba15439f45dd 124 * @return 0 on Success
charlesmn 0:ba15439f45dd 125 */
charlesmn 0:ba15439f45dd 126 void write(int lvl)
charlesmn 0:ba15439f45dd 127 {
charlesmn 0:ba15439f45dd 128 uint8_t data[2];
charlesmn 0:ba15439f45dd 129
charlesmn 0:ba15439f45dd 130 if (exp_pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 131 return;
charlesmn 0:ba15439f45dd 132 /* set the exp_pin_name state to lvl */
charlesmn 0:ba15439f45dd 133 dev_i2c->i2c_read(data, exp_dev_addr, GPSR_0_7, 2);
charlesmn 0:ba15439f45dd 134 *(uint16_t *)data = *(uint16_t *)data & (uint16_t)(~(1 << (uint16_t)exp_pin_name)); // set pin mask
charlesmn 0:ba15439f45dd 135 if (lvl)
charlesmn 0:ba15439f45dd 136 *(uint16_t *)data = *(uint16_t *)data | (uint16_t)(1 << (uint16_t)exp_pin_name);
charlesmn 0:ba15439f45dd 137 dev_i2c->i2c_write(data, exp_dev_addr, GPSR_0_7, 2);
charlesmn 0:ba15439f45dd 138 }
charlesmn 0:ba15439f45dd 139
charlesmn 0:ba15439f45dd 140 /**
charlesmn 0:ba15439f45dd 141 * @brief Overload assignement operator
charlesmn 0:ba15439f45dd 142 */
charlesmn 0:ba15439f45dd 143 Stmpe1600DigiOut &operator= (int lvl)
charlesmn 0:ba15439f45dd 144 {
charlesmn 0:ba15439f45dd 145 write(lvl);
charlesmn 0:ba15439f45dd 146 return *this;
charlesmn 0:ba15439f45dd 147 }
charlesmn 0:ba15439f45dd 148
charlesmn 0:ba15439f45dd 149 private:
charlesmn 0:ba15439f45dd 150 DevI2C *dev_i2c;
charlesmn 0:ba15439f45dd 151 uint8_t exp_dev_addr;
charlesmn 0:ba15439f45dd 152 ExpGpioPinName exp_pin_name;
charlesmn 0:ba15439f45dd 153 };
charlesmn 0:ba15439f45dd 154
charlesmn 0:ba15439f45dd 155 /* Classes -------------------------------------------------------------------*/
charlesmn 0:ba15439f45dd 156 /** Class representing a single stmpe1600 GPIO expander input pin
charlesmn 0:ba15439f45dd 157 */
charlesmn 0:ba15439f45dd 158 class Stmpe1600DigiIn
charlesmn 0:ba15439f45dd 159 {
charlesmn 0:ba15439f45dd 160 public:
charlesmn 0:ba15439f45dd 161 /** Constructor
charlesmn 0:ba15439f45dd 162 * @param[in] &i2c device I2C to be used for communication
charlesmn 0:ba15439f45dd 163 * @param[in] inpinname the desired input pin name to be created
charlesmn 0:ba15439f45dd 164 * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
charlesmn 0:ba15439f45dd 165 */
charlesmn 0:ba15439f45dd 166 Stmpe1600DigiIn(DevI2C &i2c, ExpGpioPinName in_pin_name,
charlesmn 0:ba15439f45dd 167 uint8_t dev_addr = STMPE1600_DEF_DEVICE_ADDRESS) : dev_i2c(&i2c), exp_dev_addr(dev_addr),
charlesmn 0:ba15439f45dd 168 exp_pin_name(in_pin_name)
charlesmn 0:ba15439f45dd 169 {
charlesmn 0:ba15439f45dd 170 uint8_t data[2];
charlesmn 0:ba15439f45dd 171
charlesmn 0:ba15439f45dd 172 if (exp_pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 173 return;
charlesmn 0:ba15439f45dd 174 /* set the exp_pin_name as input pin direction */
charlesmn 0:ba15439f45dd 175 dev_i2c->i2c_read(data, exp_dev_addr, GPDR_0_7, 2);
charlesmn 0:ba15439f45dd 176 *(uint16_t *)data = *(uint16_t *)data & (uint16_t)(~(1 << (uint16_t)exp_pin_name)); // set gpio as in
charlesmn 0:ba15439f45dd 177 dev_i2c->i2c_write(data, exp_dev_addr, GPDR_0_7, 2);
charlesmn 0:ba15439f45dd 178 }
charlesmn 0:ba15439f45dd 179
charlesmn 0:ba15439f45dd 180 /**
charlesmn 0:ba15439f45dd 181 * @brief Read the input pin
charlesmn 0:ba15439f45dd 182 * @return The pin logical state 0 or 1
charlesmn 0:ba15439f45dd 183 */
charlesmn 0:ba15439f45dd 184 bool read()
charlesmn 0:ba15439f45dd 185 {
charlesmn 0:ba15439f45dd 186 uint8_t data[2];
charlesmn 0:ba15439f45dd 187
charlesmn 0:ba15439f45dd 188 if (exp_pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 189 return false;
charlesmn 0:ba15439f45dd 190 /* read the exp_pin_name */
charlesmn 0:ba15439f45dd 191 dev_i2c->i2c_read(data, exp_dev_addr, GPMR_0_7, 2);
charlesmn 0:ba15439f45dd 192 *(uint16_t *)data = *(uint16_t *)data & (uint16_t)(1 << (uint16_t)exp_pin_name); // mask the in gpio
charlesmn 0:ba15439f45dd 193 if (data[0] || data[1])
charlesmn 0:ba15439f45dd 194 return true;
charlesmn 0:ba15439f45dd 195 return false;
charlesmn 0:ba15439f45dd 196 }
charlesmn 0:ba15439f45dd 197
charlesmn 0:ba15439f45dd 198 operator int()
charlesmn 0:ba15439f45dd 199 {
charlesmn 0:ba15439f45dd 200 return read();
charlesmn 0:ba15439f45dd 201 }
charlesmn 0:ba15439f45dd 202
charlesmn 0:ba15439f45dd 203 private:
charlesmn 0:ba15439f45dd 204 DevI2C *dev_i2c;
charlesmn 0:ba15439f45dd 205 uint8_t exp_dev_addr;
charlesmn 0:ba15439f45dd 206 ExpGpioPinName exp_pin_name;
charlesmn 0:ba15439f45dd 207 };
charlesmn 0:ba15439f45dd 208
charlesmn 0:ba15439f45dd 209 /* Classes -------------------------------------------------------------------*/
charlesmn 0:ba15439f45dd 210 /** Class representing a whole stmpe1600 component (16 gpio)
charlesmn 0:ba15439f45dd 211 */
charlesmn 0:ba15439f45dd 212 class Stmpe1600
charlesmn 0:ba15439f45dd 213 {
charlesmn 0:ba15439f45dd 214
charlesmn 0:ba15439f45dd 215 public:
charlesmn 0:ba15439f45dd 216 /** Constructor
charlesmn 0:ba15439f45dd 217 * @param[in] &i2c device I2C to be used for communication
charlesmn 0:ba15439f45dd 218 * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
charlesmn 0:ba15439f45dd 219 */
charlesmn 0:ba15439f45dd 220 Stmpe1600(DevI2C &i2c, uint8_t dev_addr = STMPE1600_DEF_DEVICE_ADDRESS) : dev_i2c(&i2c)
charlesmn 0:ba15439f45dd 221 {
charlesmn 0:ba15439f45dd 222 exp_dev_addr = dev_addr;
charlesmn 0:ba15439f45dd 223 write_sys_ctrl(SOFT_RESET);
charlesmn 0:ba15439f45dd 224
charlesmn 0:ba15439f45dd 225 gpdr0_15 = (uint16_t) 0; // gpio dir all IN
charlesmn 0:ba15439f45dd 226 write_16bit_reg(GPDR_0_7, &gpdr0_15);
charlesmn 0:ba15439f45dd 227 gpsr0_15 = (uint16_t) 0x0ffff; // gpio status all 1
charlesmn 0:ba15439f45dd 228 write_16bit_reg(GPSR_0_7, &gpsr0_15);
charlesmn 0:ba15439f45dd 229 }
charlesmn 0:ba15439f45dd 230
charlesmn 0:ba15439f45dd 231 /**
charlesmn 0:ba15439f45dd 232 * @brief Write the SYS_CTRL register
charlesmn 0:ba15439f45dd 233 * @param[in] Data to be written (bit fields)
charlesmn 0:ba15439f45dd 234 */
charlesmn 0:ba15439f45dd 235 void write_sys_ctrl(uint8_t data) // data = SOFT_RESET reset the device
charlesmn 0:ba15439f45dd 236 {
charlesmn 0:ba15439f45dd 237 dev_i2c->i2c_write(&data, exp_dev_addr, SYS_CTRL, 1);
charlesmn 0:ba15439f45dd 238 }
charlesmn 0:ba15439f45dd 239
charlesmn 0:ba15439f45dd 240 /**
charlesmn 0:ba15439f45dd 241 * @brief Set the out pin
charlesmn 0:ba15439f45dd 242 * @param[in] The pin name
charlesmn 0:ba15439f45dd 243 * @return 0 on Success
charlesmn 0:ba15439f45dd 244 */
charlesmn 0:ba15439f45dd 245 bool set_gpio(ExpGpioPinName pin_name)
charlesmn 0:ba15439f45dd 246 {
charlesmn 0:ba15439f45dd 247 if (pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 248 return true;
charlesmn 0:ba15439f45dd 249 gpsr0_15 = gpsr0_15 | ((uint16_t) 0x0001 << pin_name);
charlesmn 0:ba15439f45dd 250 write_16bit_reg(GPSR_0_7, &gpsr0_15);
charlesmn 0:ba15439f45dd 251 return false;
charlesmn 0:ba15439f45dd 252 }
charlesmn 0:ba15439f45dd 253
charlesmn 0:ba15439f45dd 254 /**
charlesmn 0:ba15439f45dd 255 * @brief Clear the out pin
charlesmn 0:ba15439f45dd 256 * @param[in] The pin name
charlesmn 0:ba15439f45dd 257 * @return 0 on Success
charlesmn 0:ba15439f45dd 258 */
charlesmn 0:ba15439f45dd 259 bool clear_gpio(ExpGpioPinName pin_name)
charlesmn 0:ba15439f45dd 260 {
charlesmn 0:ba15439f45dd 261 if (pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 262 return true;
charlesmn 0:ba15439f45dd 263 gpsr0_15 = gpsr0_15 & (~((uint16_t) 0x0001 << pin_name));
charlesmn 0:ba15439f45dd 264 write_16bit_reg(GPSR_0_7, &gpsr0_15);
charlesmn 0:ba15439f45dd 265 return false;
charlesmn 0:ba15439f45dd 266 }
charlesmn 0:ba15439f45dd 267
charlesmn 0:ba15439f45dd 268 /**
charlesmn 0:ba15439f45dd 269 * @brief Read the input pin
charlesmn 0:ba15439f45dd 270 * @param[in] The pin name
charlesmn 0:ba15439f45dd 271 * @return The logical pin level
charlesmn 0:ba15439f45dd 272 */
charlesmn 0:ba15439f45dd 273 bool read_gpio(ExpGpioPinName pin_name)
charlesmn 0:ba15439f45dd 274 {
charlesmn 0:ba15439f45dd 275
charlesmn 0:ba15439f45dd 276 uint16_t gpmr0_15;
charlesmn 0:ba15439f45dd 277 if (pin_name == NOT_CON)
charlesmn 0:ba15439f45dd 278 return true;
charlesmn 0:ba15439f45dd 279 read_16bit_reg(GPMR_0_7, &gpmr0_15);
charlesmn 0:ba15439f45dd 280 gpmr0_15 = gpmr0_15 & ((uint16_t) 0x0001 << pin_name);
charlesmn 0:ba15439f45dd 281 if (gpmr0_15)
charlesmn 0:ba15439f45dd 282 return true;
charlesmn 0:ba15439f45dd 283 return false;
charlesmn 0:ba15439f45dd 284 }
charlesmn 0:ba15439f45dd 285
charlesmn 0:ba15439f45dd 286 /**
charlesmn 0:ba15439f45dd 287 * @brief Set the pin direction
charlesmn 0:ba15439f45dd 288 * @param[in] The pin name
charlesmn 0:ba15439f45dd 289 * @param[in] The pin direction
charlesmn 0:ba15439f45dd 290 * @return 0 on success
charlesmn 0:ba15439f45dd 291 */
charlesmn 0:ba15439f45dd 292 bool set_gpio_dir(ExpGpioPinName pin_name, ExpGpioPinDirection pin_dir)
charlesmn 0:ba15439f45dd 293 {
charlesmn 0:ba15439f45dd 294
charlesmn 0:ba15439f45dd 295 if (pin_name == NOT_CON || pin_dir == NOT_CONNECTED)
charlesmn 0:ba15439f45dd 296 return true;
charlesmn 0:ba15439f45dd 297 gpdr0_15 = gpdr0_15 & (~((uint16_t) 0x0001 << pin_name)); // clear the Pin
charlesmn 0:ba15439f45dd 298 gpdr0_15 = gpdr0_15 | ((uint16_t) pin_dir << pin_name);
charlesmn 0:ba15439f45dd 299 write_16bit_reg(GPDR_0_7, &gpdr0_15);
charlesmn 0:ba15439f45dd 300 return false;
charlesmn 0:ba15439f45dd 301 }
charlesmn 0:ba15439f45dd 302
charlesmn 0:ba15439f45dd 303 /**
charlesmn 0:ba15439f45dd 304 * @brief Read a 16 bits register
charlesmn 0:ba15439f45dd 305 * @param[in] The register address
charlesmn 0:ba15439f45dd 306 * @param[in] The pointer to the read data
charlesmn 0:ba15439f45dd 307 */
charlesmn 0:ba15439f45dd 308 void read_16bit_reg(uint8_t reg16_addr, uint16_t *reg16_data)
charlesmn 0:ba15439f45dd 309 {
charlesmn 0:ba15439f45dd 310 dev_i2c->i2c_read((uint8_t *) reg16_data, exp_dev_addr, reg16_addr, 2);
charlesmn 0:ba15439f45dd 311 }
charlesmn 0:ba15439f45dd 312
charlesmn 0:ba15439f45dd 313 /**
charlesmn 0:ba15439f45dd 314 * @brief Write a 16 bits register
charlesmn 0:ba15439f45dd 315 * @param[in] The register address
charlesmn 0:ba15439f45dd 316 * @param[in] The pointer to the data to be written
charlesmn 0:ba15439f45dd 317 */
charlesmn 0:ba15439f45dd 318 void write_16bit_reg(uint8_t reg16_addr, uint16_t *reg16_data)
charlesmn 0:ba15439f45dd 319 {
charlesmn 0:ba15439f45dd 320 dev_i2c->i2c_write((uint8_t *) reg16_data, exp_dev_addr, reg16_addr, 2);
charlesmn 0:ba15439f45dd 321 printf("##################################write_16bit_reg %d %d %d \n",reg16_addr,exp_dev_addr);
charlesmn 0:ba15439f45dd 322 }
charlesmn 0:ba15439f45dd 323
charlesmn 0:ba15439f45dd 324 private:
charlesmn 0:ba15439f45dd 325 DevI2C *dev_i2c;
charlesmn 0:ba15439f45dd 326 uint16_t gpdr0_15; // local copy of bit direction reg
charlesmn 0:ba15439f45dd 327 uint16_t gpsr0_15; // local copy of bit status reg
charlesmn 0:ba15439f45dd 328 uint8_t exp_dev_addr; // expander device i2c addr
charlesmn 0:ba15439f45dd 329 };
charlesmn 0:ba15439f45dd 330
charlesmn 0:ba15439f45dd 331 #endif // __STMPE1600_CLASS
charlesmn 0:ba15439f45dd 332
charlesmn 0:ba15439f45dd 333