Senior Design: Sound Monitor / BSP

Dependencies:   CMSIS_STM32L4xx CMSIS_DSP_401 STM32L4xx_HAL_Driver

Dependents:   DiscoAudioRecord

Committer:
EricLew
Date:
Thu Nov 12 20:53:23 2015 +0000
Revision:
2:a9f205b30d61
Parent:
0:ad9dfc0179dc
commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricLew 0:ad9dfc0179dc 1 /**
EricLew 0:ad9dfc0179dc 2 ******************************************************************************
EricLew 0:ad9dfc0179dc 3 * @file stmpe811.c
EricLew 0:ad9dfc0179dc 4 * @author MCD Application Team
EricLew 0:ad9dfc0179dc 5 * @version V2.0.0
EricLew 0:ad9dfc0179dc 6 * @date 15-December-2014
EricLew 0:ad9dfc0179dc 7 * @brief This file provides a set of functions needed to manage the STMPE811
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>&copy; COPYRIGHT(c) 2014 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 "stmpe811.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 STMPE811
EricLew 0:ad9dfc0179dc 51 * @{
EricLew 0:ad9dfc0179dc 52 */
EricLew 0:ad9dfc0179dc 53
EricLew 0:ad9dfc0179dc 54 /** @defgroup STMPE811_Private_Types_Definitions
EricLew 0:ad9dfc0179dc 55 * @{
EricLew 0:ad9dfc0179dc 56 */
EricLew 0:ad9dfc0179dc 57
EricLew 0:ad9dfc0179dc 58 /** @defgroup STMPE811_Private_Defines
EricLew 0:ad9dfc0179dc 59 * @{
EricLew 0:ad9dfc0179dc 60 */
EricLew 0:ad9dfc0179dc 61 #define STMPE811_MAX_INSTANCE 2
EricLew 0:ad9dfc0179dc 62 /**
EricLew 0:ad9dfc0179dc 63 * @}
EricLew 0:ad9dfc0179dc 64 */
EricLew 0:ad9dfc0179dc 65
EricLew 0:ad9dfc0179dc 66 /** @defgroup STMPE811_Private_Macros
EricLew 0:ad9dfc0179dc 67 * @{
EricLew 0:ad9dfc0179dc 68 */
EricLew 0:ad9dfc0179dc 69 /**
EricLew 0:ad9dfc0179dc 70 * @}
EricLew 0:ad9dfc0179dc 71 */
EricLew 0:ad9dfc0179dc 72
EricLew 0:ad9dfc0179dc 73 /** @defgroup STMPE811_Private_Variables
EricLew 0:ad9dfc0179dc 74 * @{
EricLew 0:ad9dfc0179dc 75 */
EricLew 0:ad9dfc0179dc 76
EricLew 0:ad9dfc0179dc 77 /* Touch screen driver structure initialization */
EricLew 0:ad9dfc0179dc 78 TS_DrvTypeDef stmpe811_ts_drv =
EricLew 0:ad9dfc0179dc 79 {
EricLew 0:ad9dfc0179dc 80 stmpe811_Init,
EricLew 0:ad9dfc0179dc 81 stmpe811_ReadID,
EricLew 0:ad9dfc0179dc 82 stmpe811_Reset,
EricLew 0:ad9dfc0179dc 83 stmpe811_TS_Start,
EricLew 0:ad9dfc0179dc 84 stmpe811_TS_DetectTouch,
EricLew 0:ad9dfc0179dc 85 stmpe811_TS_GetXY,
EricLew 0:ad9dfc0179dc 86 stmpe811_TS_EnableIT,
EricLew 0:ad9dfc0179dc 87 stmpe811_TS_ClearIT,
EricLew 0:ad9dfc0179dc 88 stmpe811_TS_ITStatus,
EricLew 0:ad9dfc0179dc 89 stmpe811_TS_DisableIT,
EricLew 0:ad9dfc0179dc 90 };
EricLew 0:ad9dfc0179dc 91
EricLew 0:ad9dfc0179dc 92 /* IO driver structure initialization */
EricLew 0:ad9dfc0179dc 93 IO_DrvTypeDef stmpe811_io_drv =
EricLew 0:ad9dfc0179dc 94 {
EricLew 0:ad9dfc0179dc 95 stmpe811_Init,
EricLew 0:ad9dfc0179dc 96 stmpe811_ReadID,
EricLew 0:ad9dfc0179dc 97 stmpe811_Reset,
EricLew 0:ad9dfc0179dc 98 stmpe811_IO_Start,
EricLew 0:ad9dfc0179dc 99 stmpe811_IO_Config,
EricLew 0:ad9dfc0179dc 100 stmpe811_IO_WritePin,
EricLew 0:ad9dfc0179dc 101 stmpe811_IO_ReadPin,
EricLew 0:ad9dfc0179dc 102 stmpe811_IO_EnableIT,
EricLew 0:ad9dfc0179dc 103 stmpe811_IO_DisableIT,
EricLew 0:ad9dfc0179dc 104 stmpe811_IO_ITStatus,
EricLew 0:ad9dfc0179dc 105 stmpe811_IO_ClearIT,
EricLew 0:ad9dfc0179dc 106 };
EricLew 0:ad9dfc0179dc 107
EricLew 0:ad9dfc0179dc 108 /* stmpe811 instances by address */
EricLew 0:ad9dfc0179dc 109 uint8_t stmpe811[STMPE811_MAX_INSTANCE] = {0};
EricLew 0:ad9dfc0179dc 110 /**
EricLew 0:ad9dfc0179dc 111 * @}
EricLew 0:ad9dfc0179dc 112 */
EricLew 0:ad9dfc0179dc 113
EricLew 0:ad9dfc0179dc 114 /** @defgroup STMPE811_Private_Function_Prototypes
EricLew 0:ad9dfc0179dc 115 * @{
EricLew 0:ad9dfc0179dc 116 */
EricLew 0:ad9dfc0179dc 117 static uint8_t stmpe811_GetInstance(uint16_t DeviceAddr);
EricLew 0:ad9dfc0179dc 118 /**
EricLew 0:ad9dfc0179dc 119 * @}
EricLew 0:ad9dfc0179dc 120 */
EricLew 0:ad9dfc0179dc 121
EricLew 0:ad9dfc0179dc 122 /** @defgroup STMPE811_Private_Functions
EricLew 0:ad9dfc0179dc 123 * @{
EricLew 0:ad9dfc0179dc 124 */
EricLew 0:ad9dfc0179dc 125
EricLew 0:ad9dfc0179dc 126 /**
EricLew 0:ad9dfc0179dc 127 * @brief Initialize the stmpe811 and configure the needed hardware resources
EricLew 0:ad9dfc0179dc 128 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 129 * @retval None
EricLew 0:ad9dfc0179dc 130 */
EricLew 0:ad9dfc0179dc 131 void stmpe811_Init(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 132 {
EricLew 0:ad9dfc0179dc 133 uint8_t instance;
EricLew 0:ad9dfc0179dc 134 uint8_t empty;
EricLew 0:ad9dfc0179dc 135
EricLew 0:ad9dfc0179dc 136 /* Check if device instance already exists */
EricLew 0:ad9dfc0179dc 137 instance = stmpe811_GetInstance(DeviceAddr);
EricLew 0:ad9dfc0179dc 138
EricLew 0:ad9dfc0179dc 139 /* To prevent double initialization */
EricLew 0:ad9dfc0179dc 140 if(instance == 0xFF)
EricLew 0:ad9dfc0179dc 141 {
EricLew 0:ad9dfc0179dc 142 /* Look for empty instance */
EricLew 0:ad9dfc0179dc 143 empty = stmpe811_GetInstance(0);
EricLew 0:ad9dfc0179dc 144
EricLew 0:ad9dfc0179dc 145 if(empty < STMPE811_MAX_INSTANCE)
EricLew 0:ad9dfc0179dc 146 {
EricLew 0:ad9dfc0179dc 147 /* Register the current device instance */
EricLew 0:ad9dfc0179dc 148 stmpe811[empty] = DeviceAddr;
EricLew 0:ad9dfc0179dc 149
EricLew 0:ad9dfc0179dc 150 /* Initialize IO BUS layer */
EricLew 0:ad9dfc0179dc 151 IOE_Init();
EricLew 0:ad9dfc0179dc 152
EricLew 0:ad9dfc0179dc 153 /* Generate stmpe811 Software reset */
EricLew 0:ad9dfc0179dc 154 stmpe811_Reset(DeviceAddr);
EricLew 0:ad9dfc0179dc 155 }
EricLew 0:ad9dfc0179dc 156 }
EricLew 0:ad9dfc0179dc 157 }
EricLew 0:ad9dfc0179dc 158
EricLew 0:ad9dfc0179dc 159 /**
EricLew 0:ad9dfc0179dc 160 * @brief Reset the stmpe811 by Software.
EricLew 0:ad9dfc0179dc 161 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 162 * @retval None
EricLew 0:ad9dfc0179dc 163 */
EricLew 0:ad9dfc0179dc 164 void stmpe811_Reset(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 165 {
EricLew 0:ad9dfc0179dc 166 /* Power Down the stmpe811 */
EricLew 0:ad9dfc0179dc 167 IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL1, 2);
EricLew 0:ad9dfc0179dc 168
EricLew 0:ad9dfc0179dc 169 /* Wait for a delay to ensure registers erasing */
EricLew 0:ad9dfc0179dc 170 IOE_Delay(10);
EricLew 0:ad9dfc0179dc 171
EricLew 0:ad9dfc0179dc 172 /* Power On the Codec after the power off => all registers are reinitialized */
EricLew 0:ad9dfc0179dc 173 IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL1, 0);
EricLew 0:ad9dfc0179dc 174
EricLew 0:ad9dfc0179dc 175 /* Wait for a delay to ensure registers erasing */
EricLew 0:ad9dfc0179dc 176 IOE_Delay(2);
EricLew 0:ad9dfc0179dc 177 }
EricLew 0:ad9dfc0179dc 178
EricLew 0:ad9dfc0179dc 179 /**
EricLew 0:ad9dfc0179dc 180 * @brief Read the stmpe811 IO Expander device ID.
EricLew 0:ad9dfc0179dc 181 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 182 * @retval The Device ID (two bytes).
EricLew 0:ad9dfc0179dc 183 */
EricLew 0:ad9dfc0179dc 184 uint16_t stmpe811_ReadID(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 185 {
EricLew 0:ad9dfc0179dc 186 /* Initialize IO BUS layer */
EricLew 0:ad9dfc0179dc 187 IOE_Init();
EricLew 0:ad9dfc0179dc 188
EricLew 0:ad9dfc0179dc 189 /* Return the device ID value */
EricLew 0:ad9dfc0179dc 190 return ((IOE_Read(DeviceAddr, STMPE811_REG_CHP_ID_LSB) << 8) |\
EricLew 0:ad9dfc0179dc 191 (IOE_Read(DeviceAddr, STMPE811_REG_CHP_ID_MSB)));
EricLew 0:ad9dfc0179dc 192 }
EricLew 0:ad9dfc0179dc 193
EricLew 0:ad9dfc0179dc 194 /**
EricLew 0:ad9dfc0179dc 195 * @brief Enable the Global interrupt.
EricLew 0:ad9dfc0179dc 196 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 197 * @retval None
EricLew 0:ad9dfc0179dc 198 */
EricLew 0:ad9dfc0179dc 199 void stmpe811_EnableGlobalIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 200 {
EricLew 0:ad9dfc0179dc 201 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 202
EricLew 0:ad9dfc0179dc 203 /* Read the Interrupt Control register */
EricLew 0:ad9dfc0179dc 204 tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
EricLew 0:ad9dfc0179dc 205
EricLew 0:ad9dfc0179dc 206 /* Set the global interrupts to be Enabled */
EricLew 0:ad9dfc0179dc 207 tmp |= (uint8_t)STMPE811_GIT_EN;
EricLew 0:ad9dfc0179dc 208
EricLew 0:ad9dfc0179dc 209 /* Write Back the Interrupt Control register */
EricLew 0:ad9dfc0179dc 210 IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
EricLew 0:ad9dfc0179dc 211 }
EricLew 0:ad9dfc0179dc 212
EricLew 0:ad9dfc0179dc 213 /**
EricLew 0:ad9dfc0179dc 214 * @brief Disable the Global interrupt.
EricLew 0:ad9dfc0179dc 215 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 216 * @retval None
EricLew 0:ad9dfc0179dc 217 */
EricLew 0:ad9dfc0179dc 218 void stmpe811_DisableGlobalIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 219 {
EricLew 0:ad9dfc0179dc 220 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 221
EricLew 0:ad9dfc0179dc 222 /* Read the Interrupt Control register */
EricLew 0:ad9dfc0179dc 223 tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
EricLew 0:ad9dfc0179dc 224
EricLew 0:ad9dfc0179dc 225 /* Set the global interrupts to be Disabled */
EricLew 0:ad9dfc0179dc 226 tmp &= ~(uint8_t)STMPE811_GIT_EN;
EricLew 0:ad9dfc0179dc 227
EricLew 0:ad9dfc0179dc 228 /* Write Back the Interrupt Control register */
EricLew 0:ad9dfc0179dc 229 IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
EricLew 0:ad9dfc0179dc 230
EricLew 0:ad9dfc0179dc 231 }
EricLew 0:ad9dfc0179dc 232
EricLew 0:ad9dfc0179dc 233 /**
EricLew 0:ad9dfc0179dc 234 * @brief Enable the interrupt mode for the selected IT source
EricLew 0:ad9dfc0179dc 235 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 236 * @param Source: The interrupt source to be configured, could be:
EricLew 0:ad9dfc0179dc 237 * @arg STMPE811_GIT_IO: IO interrupt
EricLew 0:ad9dfc0179dc 238 * @arg STMPE811_GIT_ADC : ADC interrupt
EricLew 0:ad9dfc0179dc 239 * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
EricLew 0:ad9dfc0179dc 240 * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
EricLew 0:ad9dfc0179dc 241 * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
EricLew 0:ad9dfc0179dc 242 * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
EricLew 0:ad9dfc0179dc 243 * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
EricLew 0:ad9dfc0179dc 244 * @retval None
EricLew 0:ad9dfc0179dc 245 */
EricLew 0:ad9dfc0179dc 246 void stmpe811_EnableITSource(uint16_t DeviceAddr, uint8_t Source)
EricLew 0:ad9dfc0179dc 247 {
EricLew 0:ad9dfc0179dc 248 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 249
EricLew 0:ad9dfc0179dc 250 /* Get the current value of the INT_EN register */
EricLew 0:ad9dfc0179dc 251 tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_EN);
EricLew 0:ad9dfc0179dc 252
EricLew 0:ad9dfc0179dc 253 /* Set the interrupts to be Enabled */
EricLew 0:ad9dfc0179dc 254 tmp |= Source;
EricLew 0:ad9dfc0179dc 255
EricLew 0:ad9dfc0179dc 256 /* Set the register */
EricLew 0:ad9dfc0179dc 257 IOE_Write(DeviceAddr, STMPE811_REG_INT_EN, tmp);
EricLew 0:ad9dfc0179dc 258 }
EricLew 0:ad9dfc0179dc 259
EricLew 0:ad9dfc0179dc 260 /**
EricLew 0:ad9dfc0179dc 261 * @brief Disable the interrupt mode for the selected IT source
EricLew 0:ad9dfc0179dc 262 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 263 * @param Source: The interrupt source to be configured, could be:
EricLew 0:ad9dfc0179dc 264 * @arg STMPE811_GIT_IO: IO interrupt
EricLew 0:ad9dfc0179dc 265 * @arg STMPE811_GIT_ADC : ADC interrupt
EricLew 0:ad9dfc0179dc 266 * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
EricLew 0:ad9dfc0179dc 267 * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
EricLew 0:ad9dfc0179dc 268 * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
EricLew 0:ad9dfc0179dc 269 * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
EricLew 0:ad9dfc0179dc 270 * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
EricLew 0:ad9dfc0179dc 271 * @retval None
EricLew 0:ad9dfc0179dc 272 */
EricLew 0:ad9dfc0179dc 273 void stmpe811_DisableITSource(uint16_t DeviceAddr, uint8_t Source)
EricLew 0:ad9dfc0179dc 274 {
EricLew 0:ad9dfc0179dc 275 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 276
EricLew 0:ad9dfc0179dc 277 /* Get the current value of the INT_EN register */
EricLew 0:ad9dfc0179dc 278 tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_EN);
EricLew 0:ad9dfc0179dc 279
EricLew 0:ad9dfc0179dc 280 /* Set the interrupts to be Enabled */
EricLew 0:ad9dfc0179dc 281 tmp &= ~Source;
EricLew 0:ad9dfc0179dc 282
EricLew 0:ad9dfc0179dc 283 /* Set the register */
EricLew 0:ad9dfc0179dc 284 IOE_Write(DeviceAddr, STMPE811_REG_INT_EN, tmp);
EricLew 0:ad9dfc0179dc 285 }
EricLew 0:ad9dfc0179dc 286
EricLew 0:ad9dfc0179dc 287 /**
EricLew 0:ad9dfc0179dc 288 * @brief Set the global interrupt Polarity.
EricLew 0:ad9dfc0179dc 289 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 290 * @param Polarity: the IT mode polarity, could be one of the following values:
EricLew 0:ad9dfc0179dc 291 * @arg STMPE811_POLARITY_LOW: Interrupt line is active Low/Falling edge
EricLew 0:ad9dfc0179dc 292 * @arg STMPE811_POLARITY_HIGH: Interrupt line is active High/Rising edge
EricLew 0:ad9dfc0179dc 293 * @retval None
EricLew 0:ad9dfc0179dc 294 */
EricLew 0:ad9dfc0179dc 295 void stmpe811_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity)
EricLew 0:ad9dfc0179dc 296 {
EricLew 0:ad9dfc0179dc 297 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 298
EricLew 0:ad9dfc0179dc 299 /* Get the current register value */
EricLew 0:ad9dfc0179dc 300 tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
EricLew 0:ad9dfc0179dc 301
EricLew 0:ad9dfc0179dc 302 /* Mask the polarity bits */
EricLew 0:ad9dfc0179dc 303 tmp &= ~(uint8_t)0x04;
EricLew 0:ad9dfc0179dc 304
EricLew 0:ad9dfc0179dc 305 /* Modify the Interrupt Output line configuration */
EricLew 0:ad9dfc0179dc 306 tmp |= Polarity;
EricLew 0:ad9dfc0179dc 307
EricLew 0:ad9dfc0179dc 308 /* Set the new register value */
EricLew 0:ad9dfc0179dc 309 IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
EricLew 0:ad9dfc0179dc 310
EricLew 0:ad9dfc0179dc 311 }
EricLew 0:ad9dfc0179dc 312
EricLew 0:ad9dfc0179dc 313 /**
EricLew 0:ad9dfc0179dc 314 * @brief Set the global interrupt Type.
EricLew 0:ad9dfc0179dc 315 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 316 * @param Type: Interrupt line activity type, could be one of the following values:
EricLew 0:ad9dfc0179dc 317 * @arg STMPE811_TYPE_LEVEL: Interrupt line is active in level model
EricLew 0:ad9dfc0179dc 318 * @arg STMPE811_TYPE_EDGE: Interrupt line is active in edge model
EricLew 0:ad9dfc0179dc 319 * @retval None
EricLew 0:ad9dfc0179dc 320 */
EricLew 0:ad9dfc0179dc 321 void stmpe811_SetITType(uint16_t DeviceAddr, uint8_t Type)
EricLew 0:ad9dfc0179dc 322 {
EricLew 0:ad9dfc0179dc 323 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 324
EricLew 0:ad9dfc0179dc 325 /* Get the current register value */
EricLew 0:ad9dfc0179dc 326 tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
EricLew 0:ad9dfc0179dc 327
EricLew 0:ad9dfc0179dc 328 /* Mask the type bits */
EricLew 0:ad9dfc0179dc 329 tmp &= ~(uint8_t)0x02;
EricLew 0:ad9dfc0179dc 330
EricLew 0:ad9dfc0179dc 331 /* Modify the Interrupt Output line configuration */
EricLew 0:ad9dfc0179dc 332 tmp |= Type;
EricLew 0:ad9dfc0179dc 333
EricLew 0:ad9dfc0179dc 334 /* Set the new register value */
EricLew 0:ad9dfc0179dc 335 IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
EricLew 0:ad9dfc0179dc 336
EricLew 0:ad9dfc0179dc 337 }
EricLew 0:ad9dfc0179dc 338
EricLew 0:ad9dfc0179dc 339 /**
EricLew 0:ad9dfc0179dc 340 * @brief Check the selected Global interrupt source pending bit
EricLew 0:ad9dfc0179dc 341 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 342 * @param Source: the Global interrupt source to be checked, could be:
EricLew 0:ad9dfc0179dc 343 * @arg STMPE811_GIT_IO: IO interrupt
EricLew 0:ad9dfc0179dc 344 * @arg STMPE811_GIT_ADC : ADC interrupt
EricLew 0:ad9dfc0179dc 345 * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
EricLew 0:ad9dfc0179dc 346 * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
EricLew 0:ad9dfc0179dc 347 * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
EricLew 0:ad9dfc0179dc 348 * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
EricLew 0:ad9dfc0179dc 349 * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
EricLew 0:ad9dfc0179dc 350 * @retval The checked Global interrupt source status.
EricLew 0:ad9dfc0179dc 351 */
EricLew 0:ad9dfc0179dc 352 uint8_t stmpe811_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source)
EricLew 0:ad9dfc0179dc 353 {
EricLew 0:ad9dfc0179dc 354 /* Return the global IT source status */
EricLew 0:ad9dfc0179dc 355 return((IOE_Read(DeviceAddr, STMPE811_REG_INT_STA) & Source) == Source);
EricLew 0:ad9dfc0179dc 356 }
EricLew 0:ad9dfc0179dc 357
EricLew 0:ad9dfc0179dc 358 /**
EricLew 0:ad9dfc0179dc 359 * @brief Return the Global interrupts status
EricLew 0:ad9dfc0179dc 360 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 361 * @param Source: the Global interrupt source to be checked, could be:
EricLew 0:ad9dfc0179dc 362 * @arg STMPE811_GIT_IO: IO interrupt
EricLew 0:ad9dfc0179dc 363 * @arg STMPE811_GIT_ADC : ADC interrupt
EricLew 0:ad9dfc0179dc 364 * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
EricLew 0:ad9dfc0179dc 365 * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
EricLew 0:ad9dfc0179dc 366 * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
EricLew 0:ad9dfc0179dc 367 * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
EricLew 0:ad9dfc0179dc 368 * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
EricLew 0:ad9dfc0179dc 369 * @retval The checked Global interrupt source status.
EricLew 0:ad9dfc0179dc 370 */
EricLew 0:ad9dfc0179dc 371 uint8_t stmpe811_ReadGITStatus(uint16_t DeviceAddr, uint8_t Source)
EricLew 0:ad9dfc0179dc 372 {
EricLew 0:ad9dfc0179dc 373 /* Return the global IT source status */
EricLew 0:ad9dfc0179dc 374 return((IOE_Read(DeviceAddr, STMPE811_REG_INT_STA) & Source));
EricLew 0:ad9dfc0179dc 375 }
EricLew 0:ad9dfc0179dc 376
EricLew 0:ad9dfc0179dc 377 /**
EricLew 0:ad9dfc0179dc 378 * @brief Clear the selected Global interrupt pending bit(s)
EricLew 0:ad9dfc0179dc 379 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 380 * @param Source: the Global interrupt source to be cleared, could be any combination
EricLew 0:ad9dfc0179dc 381 * of the following values:
EricLew 0:ad9dfc0179dc 382 * @arg STMPE811_GIT_IO: IO interrupt
EricLew 0:ad9dfc0179dc 383 * @arg STMPE811_GIT_ADC : ADC interrupt
EricLew 0:ad9dfc0179dc 384 * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
EricLew 0:ad9dfc0179dc 385 * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
EricLew 0:ad9dfc0179dc 386 * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
EricLew 0:ad9dfc0179dc 387 * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
EricLew 0:ad9dfc0179dc 388 * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
EricLew 0:ad9dfc0179dc 389 * @retval None
EricLew 0:ad9dfc0179dc 390 */
EricLew 0:ad9dfc0179dc 391 void stmpe811_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source)
EricLew 0:ad9dfc0179dc 392 {
EricLew 0:ad9dfc0179dc 393 /* Write 1 to the bits that have to be cleared */
EricLew 0:ad9dfc0179dc 394 IOE_Write(DeviceAddr, STMPE811_REG_INT_STA, Source);
EricLew 0:ad9dfc0179dc 395 }
EricLew 0:ad9dfc0179dc 396
EricLew 0:ad9dfc0179dc 397 /**
EricLew 0:ad9dfc0179dc 398 * @brief Start the IO functionality use and disable the AF for selected IO pin(s).
EricLew 0:ad9dfc0179dc 399 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 400 * @param IO_Pin: The IO pin(s) to put in AF. This parameter can be one
EricLew 0:ad9dfc0179dc 401 * of the following values:
EricLew 0:ad9dfc0179dc 402 * @arg STMPE811_PIN_x: where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 403 * @retval None
EricLew 0:ad9dfc0179dc 404 */
EricLew 0:ad9dfc0179dc 405 void stmpe811_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 406 {
EricLew 0:ad9dfc0179dc 407 uint8_t mode;
EricLew 0:ad9dfc0179dc 408
EricLew 0:ad9dfc0179dc 409 /* Get the current register value */
EricLew 0:ad9dfc0179dc 410 mode = IOE_Read(DeviceAddr, STMPE811_REG_SYS_CTRL2);
EricLew 0:ad9dfc0179dc 411
EricLew 0:ad9dfc0179dc 412 /* Set the Functionalities to be Disabled */
EricLew 0:ad9dfc0179dc 413 mode &= ~(STMPE811_IO_FCT | STMPE811_ADC_FCT);
EricLew 0:ad9dfc0179dc 414
EricLew 0:ad9dfc0179dc 415 /* Write the new register value */
EricLew 0:ad9dfc0179dc 416 IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode);
EricLew 0:ad9dfc0179dc 417
EricLew 0:ad9dfc0179dc 418 /* Disable AF for the selected IO pin(s) */
EricLew 0:ad9dfc0179dc 419 stmpe811_IO_DisableAF(DeviceAddr, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 420 }
EricLew 0:ad9dfc0179dc 421
EricLew 0:ad9dfc0179dc 422 /**
EricLew 0:ad9dfc0179dc 423 * @brief Configures the IO pin(s) according to IO mode structure value.
EricLew 0:ad9dfc0179dc 424 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 425 * @param IO_Pin: The output pin to be set or reset. This parameter can be one
EricLew 0:ad9dfc0179dc 426 * of the following values:
EricLew 0:ad9dfc0179dc 427 * @arg STMPE811_PIN_x: where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 428 * @param IO_Mode: The IO pin mode to configure, could be one of the following values:
EricLew 0:ad9dfc0179dc 429 * @arg IO_MODE_INPUT
EricLew 0:ad9dfc0179dc 430 * @arg IO_MODE_OUTPUT
EricLew 0:ad9dfc0179dc 431 * @arg IO_MODE_IT_RISING_EDGE
EricLew 0:ad9dfc0179dc 432 * @arg IO_MODE_IT_FALLING_EDGE
EricLew 0:ad9dfc0179dc 433 * @arg IO_MODE_IT_LOW_LEVEL
EricLew 0:ad9dfc0179dc 434 * @arg IO_MODE_IT_HIGH_LEVEL
EricLew 0:ad9dfc0179dc 435 * @retval 0 if no error, IO_Mode if error
EricLew 0:ad9dfc0179dc 436 */
EricLew 0:ad9dfc0179dc 437 uint8_t stmpe811_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode)
EricLew 0:ad9dfc0179dc 438 {
EricLew 0:ad9dfc0179dc 439 uint8_t error_code = 0;
EricLew 0:ad9dfc0179dc 440
EricLew 0:ad9dfc0179dc 441 /* Configure IO pin according to selected IO mode */
EricLew 0:ad9dfc0179dc 442 switch(IO_Mode)
EricLew 0:ad9dfc0179dc 443 {
EricLew 0:ad9dfc0179dc 444 case IO_MODE_INPUT: /* Input mode */
EricLew 0:ad9dfc0179dc 445 stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
EricLew 0:ad9dfc0179dc 446 break;
EricLew 0:ad9dfc0179dc 447
EricLew 0:ad9dfc0179dc 448 case IO_MODE_OUTPUT: /* Output mode */
EricLew 0:ad9dfc0179dc 449 stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_OUT);
EricLew 0:ad9dfc0179dc 450 break;
EricLew 0:ad9dfc0179dc 451
EricLew 0:ad9dfc0179dc 452 case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */
EricLew 0:ad9dfc0179dc 453 stmpe811_IO_EnableIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 454 stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
EricLew 0:ad9dfc0179dc 455 stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
EricLew 0:ad9dfc0179dc 456 stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_EDGE);
EricLew 0:ad9dfc0179dc 457 stmpe811_IO_SetEdgeMode(DeviceAddr, IO_Pin, STMPE811_EDGE_RISING);
EricLew 0:ad9dfc0179dc 458 break;
EricLew 0:ad9dfc0179dc 459
EricLew 0:ad9dfc0179dc 460 case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */
EricLew 0:ad9dfc0179dc 461 stmpe811_IO_EnableIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 462 stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
EricLew 0:ad9dfc0179dc 463 stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
EricLew 0:ad9dfc0179dc 464 stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_EDGE);
EricLew 0:ad9dfc0179dc 465 stmpe811_IO_SetEdgeMode(DeviceAddr, IO_Pin, STMPE811_EDGE_FALLING);
EricLew 0:ad9dfc0179dc 466 break;
EricLew 0:ad9dfc0179dc 467
EricLew 0:ad9dfc0179dc 468 case IO_MODE_IT_LOW_LEVEL: /* Low level interrupt mode */
EricLew 0:ad9dfc0179dc 469 stmpe811_IO_EnableIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 470 stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
EricLew 0:ad9dfc0179dc 471 stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
EricLew 0:ad9dfc0179dc 472 stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_LEVEL);
EricLew 0:ad9dfc0179dc 473 stmpe811_SetITPolarity(DeviceAddr, STMPE811_POLARITY_LOW);
EricLew 0:ad9dfc0179dc 474 break;
EricLew 0:ad9dfc0179dc 475
EricLew 0:ad9dfc0179dc 476 case IO_MODE_IT_HIGH_LEVEL: /* High level interrupt mode */
EricLew 0:ad9dfc0179dc 477 stmpe811_IO_EnableIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 478 stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
EricLew 0:ad9dfc0179dc 479 stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
EricLew 0:ad9dfc0179dc 480 stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_LEVEL);
EricLew 0:ad9dfc0179dc 481 stmpe811_SetITPolarity(DeviceAddr, STMPE811_POLARITY_HIGH);
EricLew 0:ad9dfc0179dc 482 break;
EricLew 0:ad9dfc0179dc 483
EricLew 0:ad9dfc0179dc 484 default:
EricLew 0:ad9dfc0179dc 485 error_code = (uint8_t) IO_Mode;
EricLew 0:ad9dfc0179dc 486 break;
EricLew 0:ad9dfc0179dc 487 }
EricLew 0:ad9dfc0179dc 488 return error_code;
EricLew 0:ad9dfc0179dc 489 }
EricLew 0:ad9dfc0179dc 490
EricLew 0:ad9dfc0179dc 491 /**
EricLew 0:ad9dfc0179dc 492 * @brief Initialize the selected IO pin direction.
EricLew 0:ad9dfc0179dc 493 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 494 * @param IO_Pin: The IO pin to be configured. This parameter could be any
EricLew 0:ad9dfc0179dc 495 * combination of the following values:
EricLew 0:ad9dfc0179dc 496 * @arg STMPE811_PIN_x: Where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 497 * @param Direction: could be STMPE811_DIRECTION_IN or STMPE811_DIRECTION_OUT.
EricLew 0:ad9dfc0179dc 498 * @retval None
EricLew 0:ad9dfc0179dc 499 */
EricLew 0:ad9dfc0179dc 500 void stmpe811_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction)
EricLew 0:ad9dfc0179dc 501 {
EricLew 0:ad9dfc0179dc 502 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 503
EricLew 0:ad9dfc0179dc 504 /* Get all the Pins direction */
EricLew 0:ad9dfc0179dc 505 tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_DIR);
EricLew 0:ad9dfc0179dc 506
EricLew 0:ad9dfc0179dc 507 /* Set the selected pin direction */
EricLew 0:ad9dfc0179dc 508 if (Direction != STMPE811_DIRECTION_IN)
EricLew 0:ad9dfc0179dc 509 {
EricLew 0:ad9dfc0179dc 510 tmp |= (uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 511 }
EricLew 0:ad9dfc0179dc 512 else
EricLew 0:ad9dfc0179dc 513 {
EricLew 0:ad9dfc0179dc 514 tmp &= ~(uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 515 }
EricLew 0:ad9dfc0179dc 516
EricLew 0:ad9dfc0179dc 517 /* Write the register new value */
EricLew 0:ad9dfc0179dc 518 IOE_Write(DeviceAddr, STMPE811_REG_IO_DIR, tmp);
EricLew 0:ad9dfc0179dc 519 }
EricLew 0:ad9dfc0179dc 520
EricLew 0:ad9dfc0179dc 521 /**
EricLew 0:ad9dfc0179dc 522 * @brief Disable the AF for the selected IO pin(s).
EricLew 0:ad9dfc0179dc 523 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 524 * @param IO_Pin: The IO pin to be configured. This parameter could be any
EricLew 0:ad9dfc0179dc 525 * combination of the following values:
EricLew 0:ad9dfc0179dc 526 * @arg STMPE811_PIN_x: Where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 527 * @retval None
EricLew 0:ad9dfc0179dc 528 */
EricLew 0:ad9dfc0179dc 529 void stmpe811_IO_DisableAF(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 530 {
EricLew 0:ad9dfc0179dc 531 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 532
EricLew 0:ad9dfc0179dc 533 /* Get the current state of the IO_AF register */
EricLew 0:ad9dfc0179dc 534 tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_AF);
EricLew 0:ad9dfc0179dc 535
EricLew 0:ad9dfc0179dc 536 /* Enable the selected pins alternate function */
EricLew 0:ad9dfc0179dc 537 tmp |= (uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 538
EricLew 0:ad9dfc0179dc 539 /* Write back the new value in IO AF register */
EricLew 0:ad9dfc0179dc 540 IOE_Write(DeviceAddr, STMPE811_REG_IO_AF, tmp);
EricLew 0:ad9dfc0179dc 541
EricLew 0:ad9dfc0179dc 542 }
EricLew 0:ad9dfc0179dc 543
EricLew 0:ad9dfc0179dc 544 /**
EricLew 0:ad9dfc0179dc 545 * @brief Enable the AF for the selected IO pin(s).
EricLew 0:ad9dfc0179dc 546 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 547 * @param IO_Pin: The IO pin to be configured. This parameter could be any
EricLew 0:ad9dfc0179dc 548 * combination of the following values:
EricLew 0:ad9dfc0179dc 549 * @arg STMPE811_PIN_x: Where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 550 * @retval None
EricLew 0:ad9dfc0179dc 551 */
EricLew 0:ad9dfc0179dc 552 void stmpe811_IO_EnableAF(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 553 {
EricLew 0:ad9dfc0179dc 554 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 555
EricLew 0:ad9dfc0179dc 556 /* Get the current register value */
EricLew 0:ad9dfc0179dc 557 tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_AF);
EricLew 0:ad9dfc0179dc 558
EricLew 0:ad9dfc0179dc 559 /* Enable the selected pins alternate function */
EricLew 0:ad9dfc0179dc 560 tmp &= ~(uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 561
EricLew 0:ad9dfc0179dc 562 /* Write back the new register value */
EricLew 0:ad9dfc0179dc 563 IOE_Write(DeviceAddr, STMPE811_REG_IO_AF, tmp);
EricLew 0:ad9dfc0179dc 564 }
EricLew 0:ad9dfc0179dc 565
EricLew 0:ad9dfc0179dc 566 /**
EricLew 0:ad9dfc0179dc 567 * @brief Configure the Edge for which a transition is detectable for the
EricLew 0:ad9dfc0179dc 568 * selected pin.
EricLew 0:ad9dfc0179dc 569 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 570 * @param IO_Pin: The IO pin to be configured. This parameter could be any
EricLew 0:ad9dfc0179dc 571 * combination of the following values:
EricLew 0:ad9dfc0179dc 572 * @arg STMPE811_PIN_x: Where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 573 * @param Edge: The edge which will be detected. This parameter can be one or
EricLew 0:ad9dfc0179dc 574 * a combination of following values: STMPE811_EDGE_FALLING and STMPE811_EDGE_RISING .
EricLew 0:ad9dfc0179dc 575 * @retval None
EricLew 0:ad9dfc0179dc 576 */
EricLew 0:ad9dfc0179dc 577 void stmpe811_IO_SetEdgeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Edge)
EricLew 0:ad9dfc0179dc 578 {
EricLew 0:ad9dfc0179dc 579 uint8_t tmp1 = 0, tmp2 = 0;
EricLew 0:ad9dfc0179dc 580
EricLew 0:ad9dfc0179dc 581 /* Get the current registers values */
EricLew 0:ad9dfc0179dc 582 tmp1 = IOE_Read(DeviceAddr, STMPE811_REG_IO_FE);
EricLew 0:ad9dfc0179dc 583 tmp2 = IOE_Read(DeviceAddr, STMPE811_REG_IO_RE);
EricLew 0:ad9dfc0179dc 584
EricLew 0:ad9dfc0179dc 585 /* Disable the Falling Edge */
EricLew 0:ad9dfc0179dc 586 tmp1 &= ~(uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 587
EricLew 0:ad9dfc0179dc 588 /* Disable the Falling Edge */
EricLew 0:ad9dfc0179dc 589 tmp2 &= ~(uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 590
EricLew 0:ad9dfc0179dc 591 /* Enable the Falling edge if selected */
EricLew 0:ad9dfc0179dc 592 if (Edge & STMPE811_EDGE_FALLING)
EricLew 0:ad9dfc0179dc 593 {
EricLew 0:ad9dfc0179dc 594 tmp1 |= (uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 595 }
EricLew 0:ad9dfc0179dc 596
EricLew 0:ad9dfc0179dc 597 /* Enable the Rising edge if selected */
EricLew 0:ad9dfc0179dc 598 if (Edge & STMPE811_EDGE_RISING)
EricLew 0:ad9dfc0179dc 599 {
EricLew 0:ad9dfc0179dc 600 tmp2 |= (uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 601 }
EricLew 0:ad9dfc0179dc 602
EricLew 0:ad9dfc0179dc 603 /* Write back the new registers values */
EricLew 0:ad9dfc0179dc 604 IOE_Write(DeviceAddr, STMPE811_REG_IO_FE, tmp1);
EricLew 0:ad9dfc0179dc 605 IOE_Write(DeviceAddr, STMPE811_REG_IO_RE, tmp2);
EricLew 0:ad9dfc0179dc 606 }
EricLew 0:ad9dfc0179dc 607
EricLew 0:ad9dfc0179dc 608 /**
EricLew 0:ad9dfc0179dc 609 * @brief Write a new IO pin state.
EricLew 0:ad9dfc0179dc 610 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 611 * @param IO_Pin: The output pin to be set or reset. This parameter can be one
EricLew 0:ad9dfc0179dc 612 * of the following values:
EricLew 0:ad9dfc0179dc 613 * @arg STMPE811_PIN_x: where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 614 * @param PinState: The new IO pin state.
EricLew 0:ad9dfc0179dc 615 * @retval None
EricLew 0:ad9dfc0179dc 616 */
EricLew 0:ad9dfc0179dc 617 void stmpe811_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState)
EricLew 0:ad9dfc0179dc 618 {
EricLew 0:ad9dfc0179dc 619 /* Apply the bit value to the selected pin */
EricLew 0:ad9dfc0179dc 620 if (PinState != 0)
EricLew 0:ad9dfc0179dc 621 {
EricLew 0:ad9dfc0179dc 622 /* Set the register */
EricLew 0:ad9dfc0179dc 623 IOE_Write(DeviceAddr, STMPE811_REG_IO_SET_PIN, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 624 }
EricLew 0:ad9dfc0179dc 625 else
EricLew 0:ad9dfc0179dc 626 {
EricLew 0:ad9dfc0179dc 627 /* Set the register */
EricLew 0:ad9dfc0179dc 628 IOE_Write(DeviceAddr, STMPE811_REG_IO_CLR_PIN, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 629 }
EricLew 0:ad9dfc0179dc 630 }
EricLew 0:ad9dfc0179dc 631
EricLew 0:ad9dfc0179dc 632 /**
EricLew 0:ad9dfc0179dc 633 * @brief Return the state of the selected IO pin(s).
EricLew 0:ad9dfc0179dc 634 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 635 * @param IO_Pin: The output pin to be set or reset. This parameter can be one
EricLew 0:ad9dfc0179dc 636 * of the following values:
EricLew 0:ad9dfc0179dc 637 * @arg STMPE811_PIN_x: where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 638 * @retval IO pin(s) state.
EricLew 0:ad9dfc0179dc 639 */
EricLew 0:ad9dfc0179dc 640 uint32_t stmpe811_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 641 {
EricLew 0:ad9dfc0179dc 642 return((uint32_t)(IOE_Read(DeviceAddr, STMPE811_REG_IO_MP_STA) & (uint8_t)IO_Pin));
EricLew 0:ad9dfc0179dc 643 }
EricLew 0:ad9dfc0179dc 644
EricLew 0:ad9dfc0179dc 645 /**
EricLew 0:ad9dfc0179dc 646 * @brief Enable the global IO interrupt source.
EricLew 0:ad9dfc0179dc 647 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 648 * @retval None
EricLew 0:ad9dfc0179dc 649 */
EricLew 0:ad9dfc0179dc 650 void stmpe811_IO_EnableIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 651 {
EricLew 0:ad9dfc0179dc 652 IOE_ITConfig();
EricLew 0:ad9dfc0179dc 653
EricLew 0:ad9dfc0179dc 654 /* Enable global IO IT source */
EricLew 0:ad9dfc0179dc 655 stmpe811_EnableITSource(DeviceAddr, STMPE811_GIT_IO);
EricLew 0:ad9dfc0179dc 656
EricLew 0:ad9dfc0179dc 657 /* Enable global interrupt */
EricLew 0:ad9dfc0179dc 658 stmpe811_EnableGlobalIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 659 }
EricLew 0:ad9dfc0179dc 660
EricLew 0:ad9dfc0179dc 661 /**
EricLew 0:ad9dfc0179dc 662 * @brief Disable the global IO interrupt source.
EricLew 0:ad9dfc0179dc 663 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 664 * @retval None
EricLew 0:ad9dfc0179dc 665 */
EricLew 0:ad9dfc0179dc 666 void stmpe811_IO_DisableIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 667 {
EricLew 0:ad9dfc0179dc 668 /* Disable the global interrupt */
EricLew 0:ad9dfc0179dc 669 stmpe811_DisableGlobalIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 670
EricLew 0:ad9dfc0179dc 671 /* Disable global IO IT source */
EricLew 0:ad9dfc0179dc 672 stmpe811_DisableITSource(DeviceAddr, STMPE811_GIT_IO);
EricLew 0:ad9dfc0179dc 673 }
EricLew 0:ad9dfc0179dc 674
EricLew 0:ad9dfc0179dc 675 /**
EricLew 0:ad9dfc0179dc 676 * @brief Enable interrupt mode for the selected IO pin(s).
EricLew 0:ad9dfc0179dc 677 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 678 * @param IO_Pin: The IO interrupt to be enabled. This parameter could be any
EricLew 0:ad9dfc0179dc 679 * combination of the following values:
EricLew 0:ad9dfc0179dc 680 * @arg STMPE811_PIN_x: where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 681 * @retval None
EricLew 0:ad9dfc0179dc 682 */
EricLew 0:ad9dfc0179dc 683 void stmpe811_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 684 {
EricLew 0:ad9dfc0179dc 685 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 686
EricLew 0:ad9dfc0179dc 687 /* Get the IO interrupt state */
EricLew 0:ad9dfc0179dc 688 tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_EN);
EricLew 0:ad9dfc0179dc 689
EricLew 0:ad9dfc0179dc 690 /* Set the interrupts to be enabled */
EricLew 0:ad9dfc0179dc 691 tmp |= (uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 692
EricLew 0:ad9dfc0179dc 693 /* Write the register new value */
EricLew 0:ad9dfc0179dc 694 IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_EN, tmp);
EricLew 0:ad9dfc0179dc 695 }
EricLew 0:ad9dfc0179dc 696
EricLew 0:ad9dfc0179dc 697 /**
EricLew 0:ad9dfc0179dc 698 * @brief Disable interrupt mode for the selected IO pin(s).
EricLew 0:ad9dfc0179dc 699 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 700 * @param IO_Pin: The IO interrupt to be disabled. This parameter could be any
EricLew 0:ad9dfc0179dc 701 * combination of the following values:
EricLew 0:ad9dfc0179dc 702 * @arg STMPE811_PIN_x: where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 703 * @retval None
EricLew 0:ad9dfc0179dc 704 */
EricLew 0:ad9dfc0179dc 705 void stmpe811_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 706 {
EricLew 0:ad9dfc0179dc 707 uint8_t tmp = 0;
EricLew 0:ad9dfc0179dc 708
EricLew 0:ad9dfc0179dc 709 /* Get the IO interrupt state */
EricLew 0:ad9dfc0179dc 710 tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_EN);
EricLew 0:ad9dfc0179dc 711
EricLew 0:ad9dfc0179dc 712 /* Set the interrupts to be Disabled */
EricLew 0:ad9dfc0179dc 713 tmp &= ~(uint8_t)IO_Pin;
EricLew 0:ad9dfc0179dc 714
EricLew 0:ad9dfc0179dc 715 /* Write the register new value */
EricLew 0:ad9dfc0179dc 716 IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_EN, tmp);
EricLew 0:ad9dfc0179dc 717 }
EricLew 0:ad9dfc0179dc 718
EricLew 0:ad9dfc0179dc 719 /**
EricLew 0:ad9dfc0179dc 720 * @brief Check the status of the selected IO interrupt pending bit
EricLew 0:ad9dfc0179dc 721 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 722 * @param IO_Pin: The IO interrupt to be checked could be:
EricLew 0:ad9dfc0179dc 723 * @arg STMPE811_PIN_x Where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 724 * @retval Status of the checked IO pin(s).
EricLew 0:ad9dfc0179dc 725 */
EricLew 0:ad9dfc0179dc 726 uint32_t stmpe811_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 727 {
EricLew 0:ad9dfc0179dc 728 /* Get the Interrupt status */
EricLew 0:ad9dfc0179dc 729 return(IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_STA) & (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 730 }
EricLew 0:ad9dfc0179dc 731
EricLew 0:ad9dfc0179dc 732 /**
EricLew 0:ad9dfc0179dc 733 * @brief Clear the selected IO interrupt pending bit(s).
EricLew 0:ad9dfc0179dc 734 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 735 * @param IO_Pin: the IO interrupt to be cleared, could be:
EricLew 0:ad9dfc0179dc 736 * @arg STMPE811_PIN_x: Where x can be from 0 to 7.
EricLew 0:ad9dfc0179dc 737 * @retval None
EricLew 0:ad9dfc0179dc 738 */
EricLew 0:ad9dfc0179dc 739 void stmpe811_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin)
EricLew 0:ad9dfc0179dc 740 {
EricLew 0:ad9dfc0179dc 741 /* Clear the global IO IT pending bit */
EricLew 0:ad9dfc0179dc 742 stmpe811_ClearGlobalIT(DeviceAddr, STMPE811_GIT_IO);
EricLew 0:ad9dfc0179dc 743
EricLew 0:ad9dfc0179dc 744 /* Clear the IO IT pending bit(s) */
EricLew 0:ad9dfc0179dc 745 IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_STA, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 746
EricLew 0:ad9dfc0179dc 747 /* Clear the Edge detection pending bit*/
EricLew 0:ad9dfc0179dc 748 IOE_Write(DeviceAddr, STMPE811_REG_IO_ED, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 749
EricLew 0:ad9dfc0179dc 750 /* Clear the Rising edge pending bit */
EricLew 0:ad9dfc0179dc 751 IOE_Write(DeviceAddr, STMPE811_REG_IO_RE, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 752
EricLew 0:ad9dfc0179dc 753 /* Clear the Falling edge pending bit */
EricLew 0:ad9dfc0179dc 754 IOE_Write(DeviceAddr, STMPE811_REG_IO_FE, (uint8_t)IO_Pin);
EricLew 0:ad9dfc0179dc 755 }
EricLew 0:ad9dfc0179dc 756
EricLew 0:ad9dfc0179dc 757 /**
EricLew 0:ad9dfc0179dc 758 * @brief Configures the touch Screen Controller (Single point detection)
EricLew 0:ad9dfc0179dc 759 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 760 * @retval None.
EricLew 0:ad9dfc0179dc 761 */
EricLew 0:ad9dfc0179dc 762 void stmpe811_TS_Start(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 763 {
EricLew 0:ad9dfc0179dc 764 uint8_t mode;
EricLew 0:ad9dfc0179dc 765
EricLew 0:ad9dfc0179dc 766 /* Get the current register value */
EricLew 0:ad9dfc0179dc 767 mode = IOE_Read(DeviceAddr, STMPE811_REG_SYS_CTRL2);
EricLew 0:ad9dfc0179dc 768
EricLew 0:ad9dfc0179dc 769 /* Set the Functionalities to be Enabled */
EricLew 0:ad9dfc0179dc 770 mode &= ~(STMPE811_IO_FCT);
EricLew 0:ad9dfc0179dc 771
EricLew 0:ad9dfc0179dc 772 /* Write the new register value */
EricLew 0:ad9dfc0179dc 773 IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode);
EricLew 0:ad9dfc0179dc 774
EricLew 0:ad9dfc0179dc 775 /* Select TSC pins in TSC alternate mode */
EricLew 0:ad9dfc0179dc 776 stmpe811_IO_EnableAF(DeviceAddr, STMPE811_TOUCH_IO_ALL);
EricLew 0:ad9dfc0179dc 777
EricLew 0:ad9dfc0179dc 778 /* Set the Functionalities to be Enabled */
EricLew 0:ad9dfc0179dc 779 mode &= ~(STMPE811_TS_FCT | STMPE811_ADC_FCT);
EricLew 0:ad9dfc0179dc 780
EricLew 0:ad9dfc0179dc 781 /* Set the new register value */
EricLew 0:ad9dfc0179dc 782 IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode);
EricLew 0:ad9dfc0179dc 783
EricLew 0:ad9dfc0179dc 784 /* Select Sample Time, bit number and ADC Reference */
EricLew 0:ad9dfc0179dc 785 IOE_Write(DeviceAddr, STMPE811_REG_ADC_CTRL1, 0x49);
EricLew 0:ad9dfc0179dc 786
EricLew 0:ad9dfc0179dc 787 /* Wait for 2 ms */
EricLew 0:ad9dfc0179dc 788 IOE_Delay(2);
EricLew 0:ad9dfc0179dc 789
EricLew 0:ad9dfc0179dc 790 /* Select the ADC clock speed: 3.25 MHz */
EricLew 0:ad9dfc0179dc 791 IOE_Write(DeviceAddr, STMPE811_REG_ADC_CTRL2, 0x01);
EricLew 0:ad9dfc0179dc 792
EricLew 0:ad9dfc0179dc 793 /* Select 2 nF filter capacitor */
EricLew 0:ad9dfc0179dc 794 /* Configuration:
EricLew 0:ad9dfc0179dc 795 - Touch average control : 4 samples
EricLew 0:ad9dfc0179dc 796 - Touch delay time : 500 uS
EricLew 0:ad9dfc0179dc 797 - Panel driver setting time: 500 uS
EricLew 0:ad9dfc0179dc 798 */
EricLew 0:ad9dfc0179dc 799 IOE_Write(DeviceAddr, STMPE811_REG_TSC_CFG, 0x9A);
EricLew 0:ad9dfc0179dc 800
EricLew 0:ad9dfc0179dc 801 /* Configure the Touch FIFO threshold: single point reading */
EricLew 0:ad9dfc0179dc 802 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_TH, 0x01);
EricLew 0:ad9dfc0179dc 803
EricLew 0:ad9dfc0179dc 804 /* Clear the FIFO memory content. */
EricLew 0:ad9dfc0179dc 805 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01);
EricLew 0:ad9dfc0179dc 806
EricLew 0:ad9dfc0179dc 807 /* Put the FIFO back into operation mode */
EricLew 0:ad9dfc0179dc 808 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00);
EricLew 0:ad9dfc0179dc 809
EricLew 0:ad9dfc0179dc 810 /* Set the range and accuracy pf the pressure measurement (Z) :
EricLew 0:ad9dfc0179dc 811 - Fractional part :7
EricLew 0:ad9dfc0179dc 812 - Whole part :1
EricLew 0:ad9dfc0179dc 813 */
EricLew 0:ad9dfc0179dc 814 IOE_Write(DeviceAddr, STMPE811_REG_TSC_FRACT_XYZ, 0x01);
EricLew 0:ad9dfc0179dc 815
EricLew 0:ad9dfc0179dc 816 /* Set the driving capability (limit) of the device for TSC pins: 50mA */
EricLew 0:ad9dfc0179dc 817 IOE_Write(DeviceAddr, STMPE811_REG_TSC_I_DRIVE, 0x01);
EricLew 0:ad9dfc0179dc 818
EricLew 0:ad9dfc0179dc 819 /* Touch screen control configuration (enable TSC):
EricLew 0:ad9dfc0179dc 820 - No window tracking index
EricLew 0:ad9dfc0179dc 821 - XYZ acquisition mode
EricLew 0:ad9dfc0179dc 822 */
EricLew 0:ad9dfc0179dc 823 IOE_Write(DeviceAddr, STMPE811_REG_TSC_CTRL, 0x01);
EricLew 0:ad9dfc0179dc 824
EricLew 0:ad9dfc0179dc 825 /* Clear all the status pending bits if any */
EricLew 0:ad9dfc0179dc 826 IOE_Write(DeviceAddr, STMPE811_REG_INT_STA, 0xFF);
EricLew 0:ad9dfc0179dc 827
EricLew 0:ad9dfc0179dc 828 /* Wait for 2 ms delay */
EricLew 0:ad9dfc0179dc 829 IOE_Delay(2);
EricLew 0:ad9dfc0179dc 830 }
EricLew 0:ad9dfc0179dc 831
EricLew 0:ad9dfc0179dc 832 /**
EricLew 0:ad9dfc0179dc 833 * @brief Return if there is touch detected or not.
EricLew 0:ad9dfc0179dc 834 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 835 * @retval Touch detected state.
EricLew 0:ad9dfc0179dc 836 */
EricLew 0:ad9dfc0179dc 837 uint8_t stmpe811_TS_DetectTouch(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 838 {
EricLew 0:ad9dfc0179dc 839 uint8_t state;
EricLew 0:ad9dfc0179dc 840 uint8_t ret = 0;
EricLew 0:ad9dfc0179dc 841
EricLew 0:ad9dfc0179dc 842 state = ((IOE_Read(DeviceAddr, STMPE811_REG_TSC_CTRL) & (uint8_t)STMPE811_TS_CTRL_STATUS) == (uint8_t)0x80);
EricLew 0:ad9dfc0179dc 843
EricLew 0:ad9dfc0179dc 844 if(state > 0)
EricLew 0:ad9dfc0179dc 845 {
EricLew 0:ad9dfc0179dc 846 if(IOE_Read(DeviceAddr, STMPE811_REG_FIFO_SIZE) > 0)
EricLew 0:ad9dfc0179dc 847 {
EricLew 0:ad9dfc0179dc 848 ret = 1;
EricLew 0:ad9dfc0179dc 849 }
EricLew 0:ad9dfc0179dc 850 }
EricLew 0:ad9dfc0179dc 851 else
EricLew 0:ad9dfc0179dc 852 {
EricLew 0:ad9dfc0179dc 853 /* Reset FIFO */
EricLew 0:ad9dfc0179dc 854 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01);
EricLew 0:ad9dfc0179dc 855 /* Enable the FIFO again */
EricLew 0:ad9dfc0179dc 856 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00);
EricLew 0:ad9dfc0179dc 857 }
EricLew 0:ad9dfc0179dc 858
EricLew 0:ad9dfc0179dc 859 return ret;
EricLew 0:ad9dfc0179dc 860 }
EricLew 0:ad9dfc0179dc 861
EricLew 0:ad9dfc0179dc 862 /**
EricLew 0:ad9dfc0179dc 863 * @brief Get the touch screen X and Y positions values
EricLew 0:ad9dfc0179dc 864 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 865 * @param X: Pointer to X position value
EricLew 0:ad9dfc0179dc 866 * @param Y: Pointer to Y position value
EricLew 0:ad9dfc0179dc 867 * @retval None.
EricLew 0:ad9dfc0179dc 868 */
EricLew 0:ad9dfc0179dc 869 void stmpe811_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
EricLew 0:ad9dfc0179dc 870 {
EricLew 0:ad9dfc0179dc 871 uint8_t dataXYZ[4];
EricLew 0:ad9dfc0179dc 872 uint32_t uldataXYZ;
EricLew 0:ad9dfc0179dc 873
EricLew 0:ad9dfc0179dc 874 IOE_ReadMultiple(DeviceAddr, STMPE811_REG_TSC_DATA_NON_INC, dataXYZ, sizeof(dataXYZ)) ;
EricLew 0:ad9dfc0179dc 875
EricLew 0:ad9dfc0179dc 876 /* Calculate positions values */
EricLew 0:ad9dfc0179dc 877 uldataXYZ = (dataXYZ[0] << 24)|(dataXYZ[1] << 16)|(dataXYZ[2] << 8)|(dataXYZ[3] << 0);
EricLew 0:ad9dfc0179dc 878 *X = (uldataXYZ >> 20) & 0x00000FFF;
EricLew 0:ad9dfc0179dc 879 *Y = (uldataXYZ >> 8) & 0x00000FFF;
EricLew 0:ad9dfc0179dc 880
EricLew 0:ad9dfc0179dc 881 /* Reset FIFO */
EricLew 0:ad9dfc0179dc 882 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01);
EricLew 0:ad9dfc0179dc 883 /* Enable the FIFO again */
EricLew 0:ad9dfc0179dc 884 IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00);
EricLew 0:ad9dfc0179dc 885 }
EricLew 0:ad9dfc0179dc 886
EricLew 0:ad9dfc0179dc 887 /**
EricLew 0:ad9dfc0179dc 888 * @brief Configure the selected source to generate a global interrupt or not
EricLew 0:ad9dfc0179dc 889 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 890 * @retval None
EricLew 0:ad9dfc0179dc 891 */
EricLew 0:ad9dfc0179dc 892 void stmpe811_TS_EnableIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 893 {
EricLew 0:ad9dfc0179dc 894 IOE_ITConfig();
EricLew 0:ad9dfc0179dc 895
EricLew 0:ad9dfc0179dc 896 /* Enable global TS IT source */
EricLew 0:ad9dfc0179dc 897 stmpe811_EnableITSource(DeviceAddr, STMPE811_TS_IT);
EricLew 0:ad9dfc0179dc 898
EricLew 0:ad9dfc0179dc 899 /* Enable global interrupt */
EricLew 0:ad9dfc0179dc 900 stmpe811_EnableGlobalIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 901 }
EricLew 0:ad9dfc0179dc 902
EricLew 0:ad9dfc0179dc 903 /**
EricLew 0:ad9dfc0179dc 904 * @brief Configure the selected source to generate a global interrupt or not
EricLew 0:ad9dfc0179dc 905 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 906 * @retval None
EricLew 0:ad9dfc0179dc 907 */
EricLew 0:ad9dfc0179dc 908 void stmpe811_TS_DisableIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 909 {
EricLew 0:ad9dfc0179dc 910 /* Disable global interrupt */
EricLew 0:ad9dfc0179dc 911 stmpe811_DisableGlobalIT(DeviceAddr);
EricLew 0:ad9dfc0179dc 912
EricLew 0:ad9dfc0179dc 913 /* Disable global TS IT source */
EricLew 0:ad9dfc0179dc 914 stmpe811_DisableITSource(DeviceAddr, STMPE811_TS_IT);
EricLew 0:ad9dfc0179dc 915 }
EricLew 0:ad9dfc0179dc 916
EricLew 0:ad9dfc0179dc 917 /**
EricLew 0:ad9dfc0179dc 918 * @brief Configure the selected source to generate a global interrupt or not
EricLew 0:ad9dfc0179dc 919 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 920 * @retval TS interrupts status
EricLew 0:ad9dfc0179dc 921 */
EricLew 0:ad9dfc0179dc 922 uint8_t stmpe811_TS_ITStatus(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 923 {
EricLew 0:ad9dfc0179dc 924 /* Return TS interrupts status */
EricLew 0:ad9dfc0179dc 925 return(stmpe811_ReadGITStatus(DeviceAddr, STMPE811_TS_IT));
EricLew 0:ad9dfc0179dc 926 }
EricLew 0:ad9dfc0179dc 927
EricLew 0:ad9dfc0179dc 928 /**
EricLew 0:ad9dfc0179dc 929 * @brief Configure the selected source to generate a global interrupt or not
EricLew 0:ad9dfc0179dc 930 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 931 * @retval None
EricLew 0:ad9dfc0179dc 932 */
EricLew 0:ad9dfc0179dc 933 void stmpe811_TS_ClearIT(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 934 {
EricLew 0:ad9dfc0179dc 935 /* Clear the global TS IT source */
EricLew 0:ad9dfc0179dc 936 stmpe811_ClearGlobalIT(DeviceAddr, STMPE811_TS_IT);
EricLew 0:ad9dfc0179dc 937 }
EricLew 0:ad9dfc0179dc 938
EricLew 0:ad9dfc0179dc 939 /**
EricLew 0:ad9dfc0179dc 940 * @brief Check if the device instance of the selected address is already registered
EricLew 0:ad9dfc0179dc 941 * and return its index
EricLew 0:ad9dfc0179dc 942 * @param DeviceAddr: Device address on communication Bus.
EricLew 0:ad9dfc0179dc 943 * @retval Index of the device instance if registered, 0xFF if not.
EricLew 0:ad9dfc0179dc 944 */
EricLew 0:ad9dfc0179dc 945 static uint8_t stmpe811_GetInstance(uint16_t DeviceAddr)
EricLew 0:ad9dfc0179dc 946 {
EricLew 0:ad9dfc0179dc 947 uint8_t idx = 0;
EricLew 0:ad9dfc0179dc 948
EricLew 0:ad9dfc0179dc 949 /* Check all the registered instances */
EricLew 0:ad9dfc0179dc 950 for(idx = 0; idx < STMPE811_MAX_INSTANCE ; idx ++)
EricLew 0:ad9dfc0179dc 951 {
EricLew 0:ad9dfc0179dc 952 if(stmpe811[idx] == DeviceAddr)
EricLew 0:ad9dfc0179dc 953 {
EricLew 0:ad9dfc0179dc 954 return idx;
EricLew 0:ad9dfc0179dc 955 }
EricLew 0:ad9dfc0179dc 956 }
EricLew 0:ad9dfc0179dc 957
EricLew 0:ad9dfc0179dc 958 return 0xFF;
EricLew 0:ad9dfc0179dc 959 }
EricLew 0:ad9dfc0179dc 960
EricLew 0:ad9dfc0179dc 961 /**
EricLew 0:ad9dfc0179dc 962 * @}
EricLew 0:ad9dfc0179dc 963 */
EricLew 0:ad9dfc0179dc 964
EricLew 0:ad9dfc0179dc 965 /**
EricLew 0:ad9dfc0179dc 966 * @}
EricLew 0:ad9dfc0179dc 967 */
EricLew 0:ad9dfc0179dc 968
EricLew 0:ad9dfc0179dc 969 /**
EricLew 0:ad9dfc0179dc 970 * @}
EricLew 0:ad9dfc0179dc 971 */
EricLew 0:ad9dfc0179dc 972
EricLew 0:ad9dfc0179dc 973 /**
EricLew 0:ad9dfc0179dc 974 * @}
EricLew 0:ad9dfc0179dc 975 */
EricLew 0:ad9dfc0179dc 976
EricLew 0:ad9dfc0179dc 977 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
EricLew 0:ad9dfc0179dc 978