commentata la ridefinizione di tipo bool_t in i2c

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   BSP_B-L475E-IOT01

Fork of VL53L0X by ST

Committer:
nikapov
Date:
Fri Sep 29 15:38:50 2017 +0000
Revision:
0:a1a69d32f310
First version.

Who changed what in which revision?

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