Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CMSIS_STM32L4xx CMSIS_DSP_401 STM32L4xx_HAL_Driver
Components/stmpe1600/stmpe1600.c@0:ad9dfc0179dc, 2015-11-02 (annotated)
- Committer:
- EricLew
- Date:
- Mon Nov 02 19:38:36 2015 +0000
- Revision:
- 0:ad9dfc0179dc
commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricLew | 0:ad9dfc0179dc | 1 | /** |
EricLew | 0:ad9dfc0179dc | 2 | ****************************************************************************** |
EricLew | 0:ad9dfc0179dc | 3 | * @file stmpe1600.c |
EricLew | 0:ad9dfc0179dc | 4 | * @author MCD Application Team |
EricLew | 0:ad9dfc0179dc | 5 | * @version V1.1.0 |
EricLew | 0:ad9dfc0179dc | 6 | * @date 10-February-2015 |
EricLew | 0:ad9dfc0179dc | 7 | * @brief This file provides a set of functions needed to manage the STMPE1600 |
EricLew | 0:ad9dfc0179dc | 8 | * IO Expander devices. |
EricLew | 0:ad9dfc0179dc | 9 | ****************************************************************************** |
EricLew | 0:ad9dfc0179dc | 10 | * @attention |
EricLew | 0:ad9dfc0179dc | 11 | * |
EricLew | 0:ad9dfc0179dc | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
EricLew | 0:ad9dfc0179dc | 13 | * |
EricLew | 0:ad9dfc0179dc | 14 | * Redistribution and use in source and binary forms, with or without modification, |
EricLew | 0:ad9dfc0179dc | 15 | * are permitted provided that the following conditions are met: |
EricLew | 0:ad9dfc0179dc | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
EricLew | 0:ad9dfc0179dc | 17 | * this list of conditions and the following disclaimer. |
EricLew | 0:ad9dfc0179dc | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
EricLew | 0:ad9dfc0179dc | 19 | * this list of conditions and the following disclaimer in the documentation |
EricLew | 0:ad9dfc0179dc | 20 | * and/or other materials provided with the distribution. |
EricLew | 0:ad9dfc0179dc | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
EricLew | 0:ad9dfc0179dc | 22 | * may be used to endorse or promote products derived from this software |
EricLew | 0:ad9dfc0179dc | 23 | * without specific prior written permission. |
EricLew | 0:ad9dfc0179dc | 24 | * |
EricLew | 0:ad9dfc0179dc | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
EricLew | 0:ad9dfc0179dc | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
EricLew | 0:ad9dfc0179dc | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
EricLew | 0:ad9dfc0179dc | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
EricLew | 0:ad9dfc0179dc | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
EricLew | 0:ad9dfc0179dc | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
EricLew | 0:ad9dfc0179dc | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
EricLew | 0:ad9dfc0179dc | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
EricLew | 0:ad9dfc0179dc | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
EricLew | 0:ad9dfc0179dc | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
EricLew | 0:ad9dfc0179dc | 35 | * |
EricLew | 0:ad9dfc0179dc | 36 | ****************************************************************************** |
EricLew | 0:ad9dfc0179dc | 37 | */ |
EricLew | 0:ad9dfc0179dc | 38 | |
EricLew | 0:ad9dfc0179dc | 39 | /* Includes ------------------------------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 40 | #include "stmpe1600.h" |
EricLew | 0:ad9dfc0179dc | 41 | |
EricLew | 0:ad9dfc0179dc | 42 | /** @addtogroup BSP |
EricLew | 0:ad9dfc0179dc | 43 | * @{ |
EricLew | 0:ad9dfc0179dc | 44 | */ |
EricLew | 0:ad9dfc0179dc | 45 | |
EricLew | 0:ad9dfc0179dc | 46 | /** @addtogroup Components |
EricLew | 0:ad9dfc0179dc | 47 | * @{ |
EricLew | 0:ad9dfc0179dc | 48 | */ |
EricLew | 0:ad9dfc0179dc | 49 | |
EricLew | 0:ad9dfc0179dc | 50 | /** @defgroup STMPE1600 |
EricLew | 0:ad9dfc0179dc | 51 | * @{ |
EricLew | 0:ad9dfc0179dc | 52 | */ |
EricLew | 0:ad9dfc0179dc | 53 | |
EricLew | 0:ad9dfc0179dc | 54 | /* Private typedef -----------------------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 55 | |
EricLew | 0:ad9dfc0179dc | 56 | /** @defgroup STMPE1600_Private_Types_Definitions |
EricLew | 0:ad9dfc0179dc | 57 | * @{ |
EricLew | 0:ad9dfc0179dc | 58 | */ |
EricLew | 0:ad9dfc0179dc | 59 | |
EricLew | 0:ad9dfc0179dc | 60 | /* Private define ------------------------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 61 | |
EricLew | 0:ad9dfc0179dc | 62 | /** @defgroup STMPE1600_Private_Defines |
EricLew | 0:ad9dfc0179dc | 63 | * @{ |
EricLew | 0:ad9dfc0179dc | 64 | */ |
EricLew | 0:ad9dfc0179dc | 65 | #define STMPE1600_MAX_INSTANCE 2 |
EricLew | 0:ad9dfc0179dc | 66 | |
EricLew | 0:ad9dfc0179dc | 67 | /* Private macro -------------------------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 68 | |
EricLew | 0:ad9dfc0179dc | 69 | /** @defgroup STMPE1600_Private_Macros |
EricLew | 0:ad9dfc0179dc | 70 | * @{ |
EricLew | 0:ad9dfc0179dc | 71 | */ |
EricLew | 0:ad9dfc0179dc | 72 | |
EricLew | 0:ad9dfc0179dc | 73 | /* Private variables ---------------------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 74 | static uint16_t tmp = 0; |
EricLew | 0:ad9dfc0179dc | 75 | |
EricLew | 0:ad9dfc0179dc | 76 | /** @defgroup STMPE1600_Private_Variables |
EricLew | 0:ad9dfc0179dc | 77 | * @{ |
EricLew | 0:ad9dfc0179dc | 78 | */ |
EricLew | 0:ad9dfc0179dc | 79 | /* IO driver structure initialization */ |
EricLew | 0:ad9dfc0179dc | 80 | IO_DrvTypeDef stmpe1600_io_drv = |
EricLew | 0:ad9dfc0179dc | 81 | { |
EricLew | 0:ad9dfc0179dc | 82 | stmpe1600_Init, |
EricLew | 0:ad9dfc0179dc | 83 | stmpe1600_ReadID, |
EricLew | 0:ad9dfc0179dc | 84 | stmpe1600_Reset, |
EricLew | 0:ad9dfc0179dc | 85 | stmpe1600_Start, |
EricLew | 0:ad9dfc0179dc | 86 | stmpe1600_IO_Config, |
EricLew | 0:ad9dfc0179dc | 87 | stmpe1600_IO_WritePin, |
EricLew | 0:ad9dfc0179dc | 88 | stmpe1600_IO_ReadPin, |
EricLew | 0:ad9dfc0179dc | 89 | 0, |
EricLew | 0:ad9dfc0179dc | 90 | 0, |
EricLew | 0:ad9dfc0179dc | 91 | stmpe1600_IO_ITStatus, |
EricLew | 0:ad9dfc0179dc | 92 | stmpe1600_IO_ClearIT, |
EricLew | 0:ad9dfc0179dc | 93 | }; |
EricLew | 0:ad9dfc0179dc | 94 | |
EricLew | 0:ad9dfc0179dc | 95 | uint8_t stmpe1600[STMPE1600_MAX_INSTANCE] = {0}; |
EricLew | 0:ad9dfc0179dc | 96 | /** |
EricLew | 0:ad9dfc0179dc | 97 | * @} |
EricLew | 0:ad9dfc0179dc | 98 | */ |
EricLew | 0:ad9dfc0179dc | 99 | |
EricLew | 0:ad9dfc0179dc | 100 | /* Private function prototypes -----------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 101 | |
EricLew | 0:ad9dfc0179dc | 102 | /** @defgroup STMPE1600_Private_Function_Prototypes |
EricLew | 0:ad9dfc0179dc | 103 | * @{ |
EricLew | 0:ad9dfc0179dc | 104 | */ |
EricLew | 0:ad9dfc0179dc | 105 | static uint8_t stmpe1600_GetInstance(uint16_t DeviceAddr); |
EricLew | 0:ad9dfc0179dc | 106 | |
EricLew | 0:ad9dfc0179dc | 107 | /* Private functions ---------------------------------------------------------*/ |
EricLew | 0:ad9dfc0179dc | 108 | |
EricLew | 0:ad9dfc0179dc | 109 | /** @defgroup STMPE1600_Private_Functions |
EricLew | 0:ad9dfc0179dc | 110 | * @{ |
EricLew | 0:ad9dfc0179dc | 111 | */ |
EricLew | 0:ad9dfc0179dc | 112 | |
EricLew | 0:ad9dfc0179dc | 113 | /** |
EricLew | 0:ad9dfc0179dc | 114 | * @brief Initialize the stmpe1600 and configure the needed hardware resources |
EricLew | 0:ad9dfc0179dc | 115 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 116 | * @retval None |
EricLew | 0:ad9dfc0179dc | 117 | */ |
EricLew | 0:ad9dfc0179dc | 118 | void stmpe1600_Init(uint16_t DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 119 | { |
EricLew | 0:ad9dfc0179dc | 120 | uint8_t instance; |
EricLew | 0:ad9dfc0179dc | 121 | uint8_t empty; |
EricLew | 0:ad9dfc0179dc | 122 | |
EricLew | 0:ad9dfc0179dc | 123 | /* Check if device instance already exists */ |
EricLew | 0:ad9dfc0179dc | 124 | instance = stmpe1600_GetInstance(DeviceAddr); |
EricLew | 0:ad9dfc0179dc | 125 | |
EricLew | 0:ad9dfc0179dc | 126 | if(instance == 0xFF) |
EricLew | 0:ad9dfc0179dc | 127 | { |
EricLew | 0:ad9dfc0179dc | 128 | /* Look for empty instance */ |
EricLew | 0:ad9dfc0179dc | 129 | empty = stmpe1600_GetInstance(0); |
EricLew | 0:ad9dfc0179dc | 130 | |
EricLew | 0:ad9dfc0179dc | 131 | if(empty < STMPE1600_MAX_INSTANCE) |
EricLew | 0:ad9dfc0179dc | 132 | { |
EricLew | 0:ad9dfc0179dc | 133 | /* Register the current device instance */ |
EricLew | 0:ad9dfc0179dc | 134 | stmpe1600[empty] = DeviceAddr; |
EricLew | 0:ad9dfc0179dc | 135 | |
EricLew | 0:ad9dfc0179dc | 136 | /* Initialize IO BUS layer */ |
EricLew | 0:ad9dfc0179dc | 137 | IOE_Init(); |
EricLew | 0:ad9dfc0179dc | 138 | |
EricLew | 0:ad9dfc0179dc | 139 | /* Generate stmpe1600 Software reset */ |
EricLew | 0:ad9dfc0179dc | 140 | stmpe1600_Reset(DeviceAddr); |
EricLew | 0:ad9dfc0179dc | 141 | } |
EricLew | 0:ad9dfc0179dc | 142 | } |
EricLew | 0:ad9dfc0179dc | 143 | } |
EricLew | 0:ad9dfc0179dc | 144 | |
EricLew | 0:ad9dfc0179dc | 145 | /** |
EricLew | 0:ad9dfc0179dc | 146 | * @brief Configures the touch Screen Controller (Single point detection) |
EricLew | 0:ad9dfc0179dc | 147 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 148 | * @retval None. |
EricLew | 0:ad9dfc0179dc | 149 | */ |
EricLew | 0:ad9dfc0179dc | 150 | void stmpe1600_Start(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 151 | { |
EricLew | 0:ad9dfc0179dc | 152 | /*Configuration already done during the initialization */ |
EricLew | 0:ad9dfc0179dc | 153 | } |
EricLew | 0:ad9dfc0179dc | 154 | |
EricLew | 0:ad9dfc0179dc | 155 | /** |
EricLew | 0:ad9dfc0179dc | 156 | * @brief Reset the stmpe1600 by Software. |
EricLew | 0:ad9dfc0179dc | 157 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 158 | * @retval None |
EricLew | 0:ad9dfc0179dc | 159 | */ |
EricLew | 0:ad9dfc0179dc | 160 | void stmpe1600_Reset(uint16_t DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 161 | { |
EricLew | 0:ad9dfc0179dc | 162 | /* Power Down the stmpe1600 */ |
EricLew | 0:ad9dfc0179dc | 163 | IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint16_t)0x80); |
EricLew | 0:ad9dfc0179dc | 164 | |
EricLew | 0:ad9dfc0179dc | 165 | /* Wait for a delay to ensure registers erasing */ |
EricLew | 0:ad9dfc0179dc | 166 | IOE_Delay(2); |
EricLew | 0:ad9dfc0179dc | 167 | |
EricLew | 0:ad9dfc0179dc | 168 | /* Power On the Codec after the power off: all registers are reinitialized */ |
EricLew | 0:ad9dfc0179dc | 169 | IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint16_t)0x00); |
EricLew | 0:ad9dfc0179dc | 170 | |
EricLew | 0:ad9dfc0179dc | 171 | /* Wait for a delay to ensure registers erasing */ |
EricLew | 0:ad9dfc0179dc | 172 | IOE_Delay(2); |
EricLew | 0:ad9dfc0179dc | 173 | } |
EricLew | 0:ad9dfc0179dc | 174 | |
EricLew | 0:ad9dfc0179dc | 175 | /** |
EricLew | 0:ad9dfc0179dc | 176 | * @brief Read the stmpe1600 device ID. |
EricLew | 0:ad9dfc0179dc | 177 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 178 | * @retval The Device ID (two bytes). |
EricLew | 0:ad9dfc0179dc | 179 | */ |
EricLew | 0:ad9dfc0179dc | 180 | uint16_t stmpe1600_ReadID(uint16_t DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 181 | { |
EricLew | 0:ad9dfc0179dc | 182 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 183 | |
EricLew | 0:ad9dfc0179dc | 184 | /* Initialize IO BUS layer */ |
EricLew | 0:ad9dfc0179dc | 185 | IOE_Init(); |
EricLew | 0:ad9dfc0179dc | 186 | |
EricLew | 0:ad9dfc0179dc | 187 | /* Read the stmpe1600 device ID */ |
EricLew | 0:ad9dfc0179dc | 188 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_CHP_ID, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 189 | |
EricLew | 0:ad9dfc0179dc | 190 | /* Return the device ID value */ |
EricLew | 0:ad9dfc0179dc | 191 | return((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 192 | } |
EricLew | 0:ad9dfc0179dc | 193 | |
EricLew | 0:ad9dfc0179dc | 194 | /** |
EricLew | 0:ad9dfc0179dc | 195 | * @brief Set the global interrupt Polarity. |
EricLew | 0:ad9dfc0179dc | 196 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 197 | * @param Polarity: could be one of these values; |
EricLew | 0:ad9dfc0179dc | 198 | * @arg STMPE1600_POLARITY_LOW: Interrupt line is active Low/Falling edge |
EricLew | 0:ad9dfc0179dc | 199 | * @arg STMPE1600_POLARITY_HIGH: Interrupt line is active High/Rising edge |
EricLew | 0:ad9dfc0179dc | 200 | * @retval None |
EricLew | 0:ad9dfc0179dc | 201 | */ |
EricLew | 0:ad9dfc0179dc | 202 | void stmpe1600_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity) |
EricLew | 0:ad9dfc0179dc | 203 | { |
EricLew | 0:ad9dfc0179dc | 204 | uint8_t tmp = 0; |
EricLew | 0:ad9dfc0179dc | 205 | |
EricLew | 0:ad9dfc0179dc | 206 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 207 | tmp = IOE_Read(DeviceAddr, STMPE1600_REG_SYS_CTRL); |
EricLew | 0:ad9dfc0179dc | 208 | |
EricLew | 0:ad9dfc0179dc | 209 | /* Mask the polarity bit */ |
EricLew | 0:ad9dfc0179dc | 210 | tmp &= ~(uint16_t)0x01; |
EricLew | 0:ad9dfc0179dc | 211 | |
EricLew | 0:ad9dfc0179dc | 212 | /* Set the Interrupt Output line polarity */ |
EricLew | 0:ad9dfc0179dc | 213 | tmp |= (uint8_t)Polarity; |
EricLew | 0:ad9dfc0179dc | 214 | |
EricLew | 0:ad9dfc0179dc | 215 | /* Set the new register value */ |
EricLew | 0:ad9dfc0179dc | 216 | IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmp); |
EricLew | 0:ad9dfc0179dc | 217 | } |
EricLew | 0:ad9dfc0179dc | 218 | |
EricLew | 0:ad9dfc0179dc | 219 | /** |
EricLew | 0:ad9dfc0179dc | 220 | * @brief Enable the Global interrupt. |
EricLew | 0:ad9dfc0179dc | 221 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 222 | * @retval None |
EricLew | 0:ad9dfc0179dc | 223 | */ |
EricLew | 0:ad9dfc0179dc | 224 | void stmpe1600_EnableGlobalIT(uint16_t DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 225 | { |
EricLew | 0:ad9dfc0179dc | 226 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 227 | |
EricLew | 0:ad9dfc0179dc | 228 | /* Configure NVIC IT for IOE */ |
EricLew | 0:ad9dfc0179dc | 229 | IOE_ITConfig(); |
EricLew | 0:ad9dfc0179dc | 230 | |
EricLew | 0:ad9dfc0179dc | 231 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 232 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 233 | |
EricLew | 0:ad9dfc0179dc | 234 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 235 | |
EricLew | 0:ad9dfc0179dc | 236 | /* Set the global interrupts to be Enabled */ |
EricLew | 0:ad9dfc0179dc | 237 | tmp |= (uint16_t)STMPE1600_IT_ENABLE; |
EricLew | 0:ad9dfc0179dc | 238 | |
EricLew | 0:ad9dfc0179dc | 239 | /* Write Back the Interrupt Control register */ |
EricLew | 0:ad9dfc0179dc | 240 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 241 | } |
EricLew | 0:ad9dfc0179dc | 242 | |
EricLew | 0:ad9dfc0179dc | 243 | /** |
EricLew | 0:ad9dfc0179dc | 244 | * @brief Disable the Global interrupt. |
EricLew | 0:ad9dfc0179dc | 245 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 246 | * @retval None |
EricLew | 0:ad9dfc0179dc | 247 | */ |
EricLew | 0:ad9dfc0179dc | 248 | void stmpe1600_DisableGlobalIT(uint16_t DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 249 | { |
EricLew | 0:ad9dfc0179dc | 250 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 251 | |
EricLew | 0:ad9dfc0179dc | 252 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 253 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 254 | |
EricLew | 0:ad9dfc0179dc | 255 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 256 | |
EricLew | 0:ad9dfc0179dc | 257 | /* Set the global interrupts to be Enabled */ |
EricLew | 0:ad9dfc0179dc | 258 | tmp &= ~(uint16_t)STMPE1600_IT_ENABLE; |
EricLew | 0:ad9dfc0179dc | 259 | |
EricLew | 0:ad9dfc0179dc | 260 | /* Write Back the Interrupt Control register */ |
EricLew | 0:ad9dfc0179dc | 261 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 262 | } |
EricLew | 0:ad9dfc0179dc | 263 | |
EricLew | 0:ad9dfc0179dc | 264 | /** |
EricLew | 0:ad9dfc0179dc | 265 | * @brief Initialize the selected pin(s) direction. |
EricLew | 0:ad9dfc0179dc | 266 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 267 | * @param IO_Pin: IO pin(s) to be configured. |
EricLew | 0:ad9dfc0179dc | 268 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 269 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 270 | * @param Direction: could be STMPE1600_DIRECTION_IN or STMPE1600_DIRECTION_OUT. |
EricLew | 0:ad9dfc0179dc | 271 | * @retval None |
EricLew | 0:ad9dfc0179dc | 272 | */ |
EricLew | 0:ad9dfc0179dc | 273 | void stmpe1600_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction) |
EricLew | 0:ad9dfc0179dc | 274 | { |
EricLew | 0:ad9dfc0179dc | 275 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 276 | |
EricLew | 0:ad9dfc0179dc | 277 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 278 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPDR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 279 | |
EricLew | 0:ad9dfc0179dc | 280 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 281 | |
EricLew | 0:ad9dfc0179dc | 282 | /* Set the Pin direction */ |
EricLew | 0:ad9dfc0179dc | 283 | if (Direction != STMPE1600_DIRECTION_IN) |
EricLew | 0:ad9dfc0179dc | 284 | { |
EricLew | 0:ad9dfc0179dc | 285 | tmp |= (uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 286 | } |
EricLew | 0:ad9dfc0179dc | 287 | else |
EricLew | 0:ad9dfc0179dc | 288 | { |
EricLew | 0:ad9dfc0179dc | 289 | tmp &= ~(uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 290 | } |
EricLew | 0:ad9dfc0179dc | 291 | |
EricLew | 0:ad9dfc0179dc | 292 | /* Set the new register value */ |
EricLew | 0:ad9dfc0179dc | 293 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPDR, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 294 | } |
EricLew | 0:ad9dfc0179dc | 295 | |
EricLew | 0:ad9dfc0179dc | 296 | /** |
EricLew | 0:ad9dfc0179dc | 297 | * @brief Configure the IO pin(s) according to IO mode structure value. |
EricLew | 0:ad9dfc0179dc | 298 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 299 | * @param IO_Pin: The output pin to be set or reset. This parameter can be one |
EricLew | 0:ad9dfc0179dc | 300 | * of the following values: |
EricLew | 0:ad9dfc0179dc | 301 | * @arg STMPE1600_PIN_x: where x can be from 0 to 7. |
EricLew | 0:ad9dfc0179dc | 302 | * @param IO_Mode: The IO pin mode to configure, could be one of the following values: |
EricLew | 0:ad9dfc0179dc | 303 | * @arg IO_MODE_INPUT |
EricLew | 0:ad9dfc0179dc | 304 | * @arg IO_MODE_OUTPUT |
EricLew | 0:ad9dfc0179dc | 305 | * @arg IO_MODE_IT_RISING_EDGE |
EricLew | 0:ad9dfc0179dc | 306 | * @arg IO_MODE_IT_FALLING_EDGE |
EricLew | 0:ad9dfc0179dc | 307 | * @retval 0 if no error, IO_Mode if error |
EricLew | 0:ad9dfc0179dc | 308 | */ |
EricLew | 0:ad9dfc0179dc | 309 | uint8_t stmpe1600_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode) |
EricLew | 0:ad9dfc0179dc | 310 | { |
EricLew | 0:ad9dfc0179dc | 311 | uint8_t error_code = 0; |
EricLew | 0:ad9dfc0179dc | 312 | uint8_t buffer[2] = {0,0}; |
EricLew | 0:ad9dfc0179dc | 313 | |
EricLew | 0:ad9dfc0179dc | 314 | /* Configure IO pin according to selected IO mode */ |
EricLew | 0:ad9dfc0179dc | 315 | switch(IO_Mode) |
EricLew | 0:ad9dfc0179dc | 316 | { |
EricLew | 0:ad9dfc0179dc | 317 | case IO_MODE_INPUT: /* Input mode */ |
EricLew | 0:ad9dfc0179dc | 318 | stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin); |
EricLew | 0:ad9dfc0179dc | 319 | stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN); |
EricLew | 0:ad9dfc0179dc | 320 | break; |
EricLew | 0:ad9dfc0179dc | 321 | |
EricLew | 0:ad9dfc0179dc | 322 | case IO_MODE_OUTPUT: /* Output mode */ |
EricLew | 0:ad9dfc0179dc | 323 | stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin); |
EricLew | 0:ad9dfc0179dc | 324 | stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_OUT); |
EricLew | 0:ad9dfc0179dc | 325 | break; |
EricLew | 0:ad9dfc0179dc | 326 | |
EricLew | 0:ad9dfc0179dc | 327 | case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */ |
EricLew | 0:ad9dfc0179dc | 328 | stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_HIGH); |
EricLew | 0:ad9dfc0179dc | 329 | stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin); |
EricLew | 0:ad9dfc0179dc | 330 | stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN); |
EricLew | 0:ad9dfc0179dc | 331 | /* Clear all IO IT pending bits if any */ |
EricLew | 0:ad9dfc0179dc | 332 | stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin); |
EricLew | 0:ad9dfc0179dc | 333 | |
EricLew | 0:ad9dfc0179dc | 334 | /* Read GMPR to enable interrupt */ |
EricLew | 0:ad9dfc0179dc | 335 | IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2); |
EricLew | 0:ad9dfc0179dc | 336 | break; |
EricLew | 0:ad9dfc0179dc | 337 | |
EricLew | 0:ad9dfc0179dc | 338 | case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */ |
EricLew | 0:ad9dfc0179dc | 339 | stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_LOW); |
EricLew | 0:ad9dfc0179dc | 340 | stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin); |
EricLew | 0:ad9dfc0179dc | 341 | stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN); |
EricLew | 0:ad9dfc0179dc | 342 | |
EricLew | 0:ad9dfc0179dc | 343 | /* Clear all IO IT pending bits if any */ |
EricLew | 0:ad9dfc0179dc | 344 | stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin); |
EricLew | 0:ad9dfc0179dc | 345 | |
EricLew | 0:ad9dfc0179dc | 346 | /* Read GMPR to enable interrupt */ |
EricLew | 0:ad9dfc0179dc | 347 | IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2); |
EricLew | 0:ad9dfc0179dc | 348 | break; |
EricLew | 0:ad9dfc0179dc | 349 | |
EricLew | 0:ad9dfc0179dc | 350 | default: |
EricLew | 0:ad9dfc0179dc | 351 | error_code = (uint8_t) IO_Mode; |
EricLew | 0:ad9dfc0179dc | 352 | break; |
EricLew | 0:ad9dfc0179dc | 353 | } |
EricLew | 0:ad9dfc0179dc | 354 | return error_code; |
EricLew | 0:ad9dfc0179dc | 355 | } |
EricLew | 0:ad9dfc0179dc | 356 | |
EricLew | 0:ad9dfc0179dc | 357 | /** |
EricLew | 0:ad9dfc0179dc | 358 | * @brief Enable polarity inversion of the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 359 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 360 | * @param IO_Pin: IO pin(s) to be configured. |
EricLew | 0:ad9dfc0179dc | 361 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 362 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 363 | * @retval None |
EricLew | 0:ad9dfc0179dc | 364 | */ |
EricLew | 0:ad9dfc0179dc | 365 | void stmpe1600_IO_PolarityInv_Enable(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 366 | { |
EricLew | 0:ad9dfc0179dc | 367 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 368 | |
EricLew | 0:ad9dfc0179dc | 369 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 370 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 371 | |
EricLew | 0:ad9dfc0179dc | 372 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 373 | |
EricLew | 0:ad9dfc0179dc | 374 | /* Enable pin polarity inversion */ |
EricLew | 0:ad9dfc0179dc | 375 | tmp |= (uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 376 | |
EricLew | 0:ad9dfc0179dc | 377 | /* Set the new register value */ |
EricLew | 0:ad9dfc0179dc | 378 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 379 | } |
EricLew | 0:ad9dfc0179dc | 380 | |
EricLew | 0:ad9dfc0179dc | 381 | /** |
EricLew | 0:ad9dfc0179dc | 382 | * @brief Disable polarity inversion of the selected IO pins. |
EricLew | 0:ad9dfc0179dc | 383 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 384 | * @param IO_Pin: IO pin(s) to be configured. |
EricLew | 0:ad9dfc0179dc | 385 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 386 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 387 | * @retval None |
EricLew | 0:ad9dfc0179dc | 388 | */ |
EricLew | 0:ad9dfc0179dc | 389 | void stmpe1600_IO_PolarityInv_Disable(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 390 | { |
EricLew | 0:ad9dfc0179dc | 391 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 392 | |
EricLew | 0:ad9dfc0179dc | 393 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 394 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 395 | |
EricLew | 0:ad9dfc0179dc | 396 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 397 | |
EricLew | 0:ad9dfc0179dc | 398 | /* Disable pin polarity inversion */ |
EricLew | 0:ad9dfc0179dc | 399 | tmp &= ~ (uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 400 | |
EricLew | 0:ad9dfc0179dc | 401 | /* Set the new register value */ |
EricLew | 0:ad9dfc0179dc | 402 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 403 | } |
EricLew | 0:ad9dfc0179dc | 404 | |
EricLew | 0:ad9dfc0179dc | 405 | /** |
EricLew | 0:ad9dfc0179dc | 406 | * @brief Set the value of the selected IO pins. |
EricLew | 0:ad9dfc0179dc | 407 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 408 | * @param IO_Pin: IO pin(s) to be set. |
EricLew | 0:ad9dfc0179dc | 409 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 410 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 411 | * @param PinState: The value to be set. |
EricLew | 0:ad9dfc0179dc | 412 | * @retval None |
EricLew | 0:ad9dfc0179dc | 413 | */ |
EricLew | 0:ad9dfc0179dc | 414 | void stmpe1600_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState) |
EricLew | 0:ad9dfc0179dc | 415 | { |
EricLew | 0:ad9dfc0179dc | 416 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 417 | |
EricLew | 0:ad9dfc0179dc | 418 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 419 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 420 | |
EricLew | 0:ad9dfc0179dc | 421 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 422 | |
EricLew | 0:ad9dfc0179dc | 423 | /* Set the pin state */ |
EricLew | 0:ad9dfc0179dc | 424 | if(PinState != 0) |
EricLew | 0:ad9dfc0179dc | 425 | { |
EricLew | 0:ad9dfc0179dc | 426 | tmp |= (uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 427 | } |
EricLew | 0:ad9dfc0179dc | 428 | else |
EricLew | 0:ad9dfc0179dc | 429 | { |
EricLew | 0:ad9dfc0179dc | 430 | tmp &= ~(uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 431 | } |
EricLew | 0:ad9dfc0179dc | 432 | |
EricLew | 0:ad9dfc0179dc | 433 | /* Set the new register value */ |
EricLew | 0:ad9dfc0179dc | 434 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPSR, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 435 | } |
EricLew | 0:ad9dfc0179dc | 436 | |
EricLew | 0:ad9dfc0179dc | 437 | /** |
EricLew | 0:ad9dfc0179dc | 438 | * @brief Read the state of the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 439 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 440 | * @param IO_Pin: IO pin(s) to be read. |
EricLew | 0:ad9dfc0179dc | 441 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 442 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 443 | * @retval State of the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 444 | */ |
EricLew | 0:ad9dfc0179dc | 445 | uint32_t stmpe1600_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 446 | { |
EricLew | 0:ad9dfc0179dc | 447 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 448 | |
EricLew | 0:ad9dfc0179dc | 449 | /* Get the register value */ |
EricLew | 0:ad9dfc0179dc | 450 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 451 | |
EricLew | 0:ad9dfc0179dc | 452 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 453 | |
EricLew | 0:ad9dfc0179dc | 454 | /* Return the pin(s) state */ |
EricLew | 0:ad9dfc0179dc | 455 | return(tmp & IO_Pin); |
EricLew | 0:ad9dfc0179dc | 456 | } |
EricLew | 0:ad9dfc0179dc | 457 | |
EricLew | 0:ad9dfc0179dc | 458 | /** |
EricLew | 0:ad9dfc0179dc | 459 | * @brief Enable the interrupt mode for the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 460 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 461 | * @param IO_Pin: IO pin(s) to be configured. |
EricLew | 0:ad9dfc0179dc | 462 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 463 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 464 | * @retval None |
EricLew | 0:ad9dfc0179dc | 465 | */ |
EricLew | 0:ad9dfc0179dc | 466 | void stmpe1600_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 467 | { |
EricLew | 0:ad9dfc0179dc | 468 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 469 | |
EricLew | 0:ad9dfc0179dc | 470 | /* Enable global interrupt */ |
EricLew | 0:ad9dfc0179dc | 471 | stmpe1600_EnableGlobalIT(DeviceAddr); |
EricLew | 0:ad9dfc0179dc | 472 | |
EricLew | 0:ad9dfc0179dc | 473 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 474 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 475 | |
EricLew | 0:ad9dfc0179dc | 476 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 477 | |
EricLew | 0:ad9dfc0179dc | 478 | /* Put pin in IT mode */ |
EricLew | 0:ad9dfc0179dc | 479 | tmp |= (uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 480 | |
EricLew | 0:ad9dfc0179dc | 481 | /* Write the new register value */ |
EricLew | 0:ad9dfc0179dc | 482 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 483 | } |
EricLew | 0:ad9dfc0179dc | 484 | |
EricLew | 0:ad9dfc0179dc | 485 | /** |
EricLew | 0:ad9dfc0179dc | 486 | * @brief Disable the interrupt mode for the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 487 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 488 | * @param IO_Pin: IO pin(s) to be configured. |
EricLew | 0:ad9dfc0179dc | 489 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 490 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 491 | * @retval None |
EricLew | 0:ad9dfc0179dc | 492 | */ |
EricLew | 0:ad9dfc0179dc | 493 | void stmpe1600_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 494 | { |
EricLew | 0:ad9dfc0179dc | 495 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 496 | |
EricLew | 0:ad9dfc0179dc | 497 | /* Get the current register value */ |
EricLew | 0:ad9dfc0179dc | 498 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 499 | |
EricLew | 0:ad9dfc0179dc | 500 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 501 | |
EricLew | 0:ad9dfc0179dc | 502 | /* Disable the IT pin mode */ |
EricLew | 0:ad9dfc0179dc | 503 | tmp &= ~(uint16_t)IO_Pin; |
EricLew | 0:ad9dfc0179dc | 504 | |
EricLew | 0:ad9dfc0179dc | 505 | /* Set the new register value */ |
EricLew | 0:ad9dfc0179dc | 506 | IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2); |
EricLew | 0:ad9dfc0179dc | 507 | } |
EricLew | 0:ad9dfc0179dc | 508 | |
EricLew | 0:ad9dfc0179dc | 509 | /** |
EricLew | 0:ad9dfc0179dc | 510 | * @brief Read the IT status of the selected IO pin(s) |
EricLew | 0:ad9dfc0179dc | 511 | * (clears all the pending bits if any). |
EricLew | 0:ad9dfc0179dc | 512 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 513 | * @param IO_Pin: IO pin(s) to be checked. |
EricLew | 0:ad9dfc0179dc | 514 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 515 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 516 | * @retval IT Status of the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 517 | */ |
EricLew | 0:ad9dfc0179dc | 518 | uint32_t stmpe1600_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 519 | { |
EricLew | 0:ad9dfc0179dc | 520 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 521 | |
EricLew | 0:ad9dfc0179dc | 522 | /* Get the register value */ |
EricLew | 0:ad9dfc0179dc | 523 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 524 | |
EricLew | 0:ad9dfc0179dc | 525 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 526 | |
EricLew | 0:ad9dfc0179dc | 527 | /* Return the pin IT status */ |
EricLew | 0:ad9dfc0179dc | 528 | return((tmp & IO_Pin) == IO_Pin); |
EricLew | 0:ad9dfc0179dc | 529 | } |
EricLew | 0:ad9dfc0179dc | 530 | |
EricLew | 0:ad9dfc0179dc | 531 | /** |
EricLew | 0:ad9dfc0179dc | 532 | * @brief Detect an IT pending bit from the selected IO pin(s). |
EricLew | 0:ad9dfc0179dc | 533 | * (clears all the pending bits if any). |
EricLew | 0:ad9dfc0179dc | 534 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 535 | * @param IO_Pin: IO pin(s) to be checked. |
EricLew | 0:ad9dfc0179dc | 536 | * This parameter could be any combination of the following values: |
EricLew | 0:ad9dfc0179dc | 537 | * @arg STMPE1600_PIN_x: where x can be from 0 to 15. |
EricLew | 0:ad9dfc0179dc | 538 | * @retval IT pending bit detection status. |
EricLew | 0:ad9dfc0179dc | 539 | */ |
EricLew | 0:ad9dfc0179dc | 540 | uint8_t stmpe1600_IO_ReadIT(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 541 | { |
EricLew | 0:ad9dfc0179dc | 542 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 543 | |
EricLew | 0:ad9dfc0179dc | 544 | /* Get the register value */ |
EricLew | 0:ad9dfc0179dc | 545 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 546 | |
EricLew | 0:ad9dfc0179dc | 547 | tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8)); |
EricLew | 0:ad9dfc0179dc | 548 | |
EricLew | 0:ad9dfc0179dc | 549 | /* Return if there is an IT pending bit or not */ |
EricLew | 0:ad9dfc0179dc | 550 | return(tmp & IO_Pin); |
EricLew | 0:ad9dfc0179dc | 551 | } |
EricLew | 0:ad9dfc0179dc | 552 | |
EricLew | 0:ad9dfc0179dc | 553 | /** |
EricLew | 0:ad9dfc0179dc | 554 | * @brief Clear all the IT pending bits if any. |
EricLew | 0:ad9dfc0179dc | 555 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 556 | * @retval None |
EricLew | 0:ad9dfc0179dc | 557 | */ |
EricLew | 0:ad9dfc0179dc | 558 | void stmpe1600_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin) |
EricLew | 0:ad9dfc0179dc | 559 | { |
EricLew | 0:ad9dfc0179dc | 560 | uint8_t tmpData[2] = {0 , 0}; |
EricLew | 0:ad9dfc0179dc | 561 | |
EricLew | 0:ad9dfc0179dc | 562 | /* Get the register value to clear all pending bits */ |
EricLew | 0:ad9dfc0179dc | 563 | IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2); |
EricLew | 0:ad9dfc0179dc | 564 | } |
EricLew | 0:ad9dfc0179dc | 565 | |
EricLew | 0:ad9dfc0179dc | 566 | /** |
EricLew | 0:ad9dfc0179dc | 567 | * @brief Check if the device instance of the selected address is already registered |
EricLew | 0:ad9dfc0179dc | 568 | * and return its index |
EricLew | 0:ad9dfc0179dc | 569 | * @param DeviceAddr: Device address on communication Bus. |
EricLew | 0:ad9dfc0179dc | 570 | * @retval Index of the device instance if registered, 0xFF if not. |
EricLew | 0:ad9dfc0179dc | 571 | */ |
EricLew | 0:ad9dfc0179dc | 572 | static uint8_t stmpe1600_GetInstance(uint16_t DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 573 | { |
EricLew | 0:ad9dfc0179dc | 574 | uint8_t idx = 0; |
EricLew | 0:ad9dfc0179dc | 575 | |
EricLew | 0:ad9dfc0179dc | 576 | /* Check all the registered instances */ |
EricLew | 0:ad9dfc0179dc | 577 | for(idx = 0; idx < STMPE1600_MAX_INSTANCE ; idx ++) |
EricLew | 0:ad9dfc0179dc | 578 | { |
EricLew | 0:ad9dfc0179dc | 579 | /* Return index if there is address match */ |
EricLew | 0:ad9dfc0179dc | 580 | if(stmpe1600[idx] == DeviceAddr) |
EricLew | 0:ad9dfc0179dc | 581 | { |
EricLew | 0:ad9dfc0179dc | 582 | return idx; |
EricLew | 0:ad9dfc0179dc | 583 | } |
EricLew | 0:ad9dfc0179dc | 584 | } |
EricLew | 0:ad9dfc0179dc | 585 | |
EricLew | 0:ad9dfc0179dc | 586 | return 0xFF; |
EricLew | 0:ad9dfc0179dc | 587 | } |
EricLew | 0:ad9dfc0179dc | 588 | |
EricLew | 0:ad9dfc0179dc | 589 | /** |
EricLew | 0:ad9dfc0179dc | 590 | * @} |
EricLew | 0:ad9dfc0179dc | 591 | */ |
EricLew | 0:ad9dfc0179dc | 592 | |
EricLew | 0:ad9dfc0179dc | 593 | /** |
EricLew | 0:ad9dfc0179dc | 594 | * @} |
EricLew | 0:ad9dfc0179dc | 595 | */ |
EricLew | 0:ad9dfc0179dc | 596 | |
EricLew | 0:ad9dfc0179dc | 597 | /** |
EricLew | 0:ad9dfc0179dc | 598 | * @} |
EricLew | 0:ad9dfc0179dc | 599 | */ |
EricLew | 0:ad9dfc0179dc | 600 | |
EricLew | 0:ad9dfc0179dc | 601 | /** |
EricLew | 0:ad9dfc0179dc | 602 | * @} |
EricLew | 0:ad9dfc0179dc | 603 | */ |
EricLew | 0:ad9dfc0179dc | 604 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
EricLew | 0:ad9dfc0179dc | 605 |