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