Additional font macro

Dependents:   EspSerial

Committer:
SomeRandomBloke
Date:
Fri Feb 05 09:20:30 2016 +0000
Revision:
1:a6fd0931a9e9
Parent:
0:e1d164542663
Added additional font macro

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:e1d164542663 1 /**
bcostm 0:e1d164542663 2 ******************************************************************************
bcostm 0:e1d164542663 3 * @file stm32f429i_discovery_ts.c
bcostm 0:e1d164542663 4 * @author MCD Application Team
bcostm 0:e1d164542663 5 * @version V2.1.2
bcostm 0:e1d164542663 6 * @date 02-March-2015
bcostm 0:e1d164542663 7 * @brief This file provides a set of functions needed to manage Touch
bcostm 0:e1d164542663 8 * screen available with STMPE811 IO Expander device mounted on
bcostm 0:e1d164542663 9 * STM32F429I-Discovery Kit.
bcostm 0:e1d164542663 10 ******************************************************************************
bcostm 0:e1d164542663 11 * @attention
bcostm 0:e1d164542663 12 *
bcostm 0:e1d164542663 13 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
bcostm 0:e1d164542663 14 *
bcostm 0:e1d164542663 15 * Redistribution and use in source and binary forms, with or without modification,
bcostm 0:e1d164542663 16 * are permitted provided that the following conditions are met:
bcostm 0:e1d164542663 17 * 1. Redistributions of source code must retain the above copyright notice,
bcostm 0:e1d164542663 18 * this list of conditions and the following disclaimer.
bcostm 0:e1d164542663 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 0:e1d164542663 20 * this list of conditions and the following disclaimer in the documentation
bcostm 0:e1d164542663 21 * and/or other materials provided with the distribution.
bcostm 0:e1d164542663 22 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bcostm 0:e1d164542663 23 * may be used to endorse or promote products derived from this software
bcostm 0:e1d164542663 24 * without specific prior written permission.
bcostm 0:e1d164542663 25 *
bcostm 0:e1d164542663 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bcostm 0:e1d164542663 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bcostm 0:e1d164542663 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bcostm 0:e1d164542663 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bcostm 0:e1d164542663 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bcostm 0:e1d164542663 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bcostm 0:e1d164542663 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bcostm 0:e1d164542663 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bcostm 0:e1d164542663 34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bcostm 0:e1d164542663 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 0:e1d164542663 36 *
bcostm 0:e1d164542663 37 ******************************************************************************
bcostm 0:e1d164542663 38 */
bcostm 0:e1d164542663 39
bcostm 0:e1d164542663 40 /* Includes ------------------------------------------------------------------*/
bcostm 0:e1d164542663 41 #include "stm32f429i_discovery_ts.h"
bcostm 0:e1d164542663 42 #include "stm32f429i_discovery_io.h"
bcostm 0:e1d164542663 43
bcostm 0:e1d164542663 44 /** @addtogroup BSP
bcostm 0:e1d164542663 45 * @{
bcostm 0:e1d164542663 46 */
bcostm 0:e1d164542663 47
bcostm 0:e1d164542663 48 /** @addtogroup STM32F429I_DISCOVERY
bcostm 0:e1d164542663 49 * @{
bcostm 0:e1d164542663 50 */
bcostm 0:e1d164542663 51
bcostm 0:e1d164542663 52 /** @defgroup STM32F429I_DISCOVERY_TS
bcostm 0:e1d164542663 53 * @{
bcostm 0:e1d164542663 54 */
bcostm 0:e1d164542663 55
bcostm 0:e1d164542663 56 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Types_Definitions
bcostm 0:e1d164542663 57 * @{
bcostm 0:e1d164542663 58 */
bcostm 0:e1d164542663 59 /**
bcostm 0:e1d164542663 60 * @}
bcostm 0:e1d164542663 61 */
bcostm 0:e1d164542663 62
bcostm 0:e1d164542663 63 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Defines
bcostm 0:e1d164542663 64 * @{
bcostm 0:e1d164542663 65 */
bcostm 0:e1d164542663 66 /**
bcostm 0:e1d164542663 67 * @}
bcostm 0:e1d164542663 68 */
bcostm 0:e1d164542663 69
bcostm 0:e1d164542663 70 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Macros
bcostm 0:e1d164542663 71 * @{
bcostm 0:e1d164542663 72 */
bcostm 0:e1d164542663 73 /**
bcostm 0:e1d164542663 74 * @}
bcostm 0:e1d164542663 75 */
bcostm 0:e1d164542663 76
bcostm 0:e1d164542663 77 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Variables
bcostm 0:e1d164542663 78 * @{
bcostm 0:e1d164542663 79 */
bcostm 0:e1d164542663 80 static TS_DrvTypeDef *TsDrv;
bcostm 0:e1d164542663 81 static uint16_t TsXBoundary, TsYBoundary;
bcostm 0:e1d164542663 82 /**
bcostm 0:e1d164542663 83 * @}
bcostm 0:e1d164542663 84 */
bcostm 0:e1d164542663 85
bcostm 0:e1d164542663 86 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Function_Prototypes
bcostm 0:e1d164542663 87 * @{
bcostm 0:e1d164542663 88 */
bcostm 0:e1d164542663 89 /**
bcostm 0:e1d164542663 90 * @}
bcostm 0:e1d164542663 91 */
bcostm 0:e1d164542663 92
bcostm 0:e1d164542663 93 /** @defgroup STM32F429I_DISCOVERY_TS_Private_Functions
bcostm 0:e1d164542663 94 * @{
bcostm 0:e1d164542663 95 */
bcostm 0:e1d164542663 96
bcostm 0:e1d164542663 97 /**
bcostm 0:e1d164542663 98 * @brief Initializes and configures the touch screen functionalities and
bcostm 0:e1d164542663 99 * configures all necessary hardware resources (GPIOs, clocks..).
bcostm 0:e1d164542663 100 * @param XSize: The maximum X size of the TS area on LCD
bcostm 0:e1d164542663 101 * @param YSize: The maximum Y size of the TS area on LCD
bcostm 0:e1d164542663 102 * @retval TS_OK: if all initializations are OK. Other value if error.
bcostm 0:e1d164542663 103 */
bcostm 0:e1d164542663 104 uint8_t BSP_TS_Init(uint16_t XSize, uint16_t YSize)
bcostm 0:e1d164542663 105 {
bcostm 0:e1d164542663 106 uint8_t ret = TS_ERROR;
bcostm 0:e1d164542663 107
bcostm 0:e1d164542663 108 /* Initialize x and y positions boundaries */
bcostm 0:e1d164542663 109 TsXBoundary = XSize;
bcostm 0:e1d164542663 110 TsYBoundary = YSize;
bcostm 0:e1d164542663 111
bcostm 0:e1d164542663 112 /* Read ID and verify if the IO expander is ready */
bcostm 0:e1d164542663 113 if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
bcostm 0:e1d164542663 114 {
bcostm 0:e1d164542663 115 /* Initialize the TS driver structure */
bcostm 0:e1d164542663 116 TsDrv = &stmpe811_ts_drv;
bcostm 0:e1d164542663 117
bcostm 0:e1d164542663 118 ret = TS_OK;
bcostm 0:e1d164542663 119 }
bcostm 0:e1d164542663 120
bcostm 0:e1d164542663 121 if(ret == TS_OK)
bcostm 0:e1d164542663 122 {
bcostm 0:e1d164542663 123 /* Initialize the LL TS Driver */
bcostm 0:e1d164542663 124 TsDrv->Init(TS_I2C_ADDRESS);
bcostm 0:e1d164542663 125 TsDrv->Start(TS_I2C_ADDRESS);
bcostm 0:e1d164542663 126 }
bcostm 0:e1d164542663 127
bcostm 0:e1d164542663 128 return ret;
bcostm 0:e1d164542663 129 }
bcostm 0:e1d164542663 130
bcostm 0:e1d164542663 131 /**
bcostm 0:e1d164542663 132 * @brief Configures and enables the touch screen interrupts.
bcostm 0:e1d164542663 133 * @param None
bcostm 0:e1d164542663 134 * @retval TS_OK: if ITconfig is OK. Other value if error.
bcostm 0:e1d164542663 135 */
bcostm 0:e1d164542663 136 uint8_t BSP_TS_ITConfig(void)
bcostm 0:e1d164542663 137 {
bcostm 0:e1d164542663 138 /* Enable the TS ITs */
bcostm 0:e1d164542663 139 TsDrv->EnableIT(TS_I2C_ADDRESS);
bcostm 0:e1d164542663 140
bcostm 0:e1d164542663 141 return TS_OK;
bcostm 0:e1d164542663 142 }
bcostm 0:e1d164542663 143
bcostm 0:e1d164542663 144 /**
bcostm 0:e1d164542663 145 * @brief Gets the TS IT status.
bcostm 0:e1d164542663 146 * @param None
bcostm 0:e1d164542663 147 * @retval Interrupt status.
bcostm 0:e1d164542663 148 */
bcostm 0:e1d164542663 149 uint8_t BSP_TS_ITGetStatus(void)
bcostm 0:e1d164542663 150 {
bcostm 0:e1d164542663 151 /* Return the TS IT status */
bcostm 0:e1d164542663 152 return (TsDrv->GetITStatus(TS_I2C_ADDRESS));
bcostm 0:e1d164542663 153 }
bcostm 0:e1d164542663 154
bcostm 0:e1d164542663 155 /**
bcostm 0:e1d164542663 156 * @brief Returns status and positions of the touch screen.
bcostm 0:e1d164542663 157 * @param TsState: Pointer to touch screen current state structure
bcostm 0:e1d164542663 158 * @retval None.
bcostm 0:e1d164542663 159 */
bcostm 0:e1d164542663 160 void BSP_TS_GetState(TS_StateTypeDef* TsState)
bcostm 0:e1d164542663 161 {
bcostm 0:e1d164542663 162 static uint32_t _x = 0, _y = 0;
bcostm 0:e1d164542663 163 uint16_t xDiff, yDiff , x , y, xr, yr;
bcostm 0:e1d164542663 164
bcostm 0:e1d164542663 165 TsState->TouchDetected = TsDrv->DetectTouch(TS_I2C_ADDRESS);
bcostm 0:e1d164542663 166
bcostm 0:e1d164542663 167 if(TsState->TouchDetected)
bcostm 0:e1d164542663 168 {
bcostm 0:e1d164542663 169 TsDrv->GetXY(TS_I2C_ADDRESS, &x, &y);
bcostm 0:e1d164542663 170
bcostm 0:e1d164542663 171 /* Y value first correction */
bcostm 0:e1d164542663 172 y -= 360;
bcostm 0:e1d164542663 173
bcostm 0:e1d164542663 174 /* Y value second correction */
bcostm 0:e1d164542663 175 yr = y / 11;
bcostm 0:e1d164542663 176
bcostm 0:e1d164542663 177 /* Return y position value */
bcostm 0:e1d164542663 178 if(yr <= 0)
bcostm 0:e1d164542663 179 {
bcostm 0:e1d164542663 180 yr = 0;
bcostm 0:e1d164542663 181 }
bcostm 0:e1d164542663 182 else if (yr > TsYBoundary)
bcostm 0:e1d164542663 183 {
bcostm 0:e1d164542663 184 yr = TsYBoundary - 1;
bcostm 0:e1d164542663 185 }
bcostm 0:e1d164542663 186 else
bcostm 0:e1d164542663 187 {}
bcostm 0:e1d164542663 188 y = yr;
bcostm 0:e1d164542663 189
bcostm 0:e1d164542663 190 /* X value first correction */
bcostm 0:e1d164542663 191 if(x <= 3000)
bcostm 0:e1d164542663 192 {
bcostm 0:e1d164542663 193 x = 3870 - x;
bcostm 0:e1d164542663 194 }
bcostm 0:e1d164542663 195 else
bcostm 0:e1d164542663 196 {
bcostm 0:e1d164542663 197 x = 3800 - x;
bcostm 0:e1d164542663 198 }
bcostm 0:e1d164542663 199
bcostm 0:e1d164542663 200 /* X value second correction */
bcostm 0:e1d164542663 201 xr = x / 15;
bcostm 0:e1d164542663 202
bcostm 0:e1d164542663 203 /* Return X position value */
bcostm 0:e1d164542663 204 if(xr <= 0)
bcostm 0:e1d164542663 205 {
bcostm 0:e1d164542663 206 xr = 0;
bcostm 0:e1d164542663 207 }
bcostm 0:e1d164542663 208 else if (xr > TsXBoundary)
bcostm 0:e1d164542663 209 {
bcostm 0:e1d164542663 210 xr = TsXBoundary - 1;
bcostm 0:e1d164542663 211 }
bcostm 0:e1d164542663 212 else
bcostm 0:e1d164542663 213 {}
bcostm 0:e1d164542663 214
bcostm 0:e1d164542663 215 x = xr;
bcostm 0:e1d164542663 216 xDiff = x > _x? (x - _x): (_x - x);
bcostm 0:e1d164542663 217 yDiff = y > _y? (y - _y): (_y - y);
bcostm 0:e1d164542663 218
bcostm 0:e1d164542663 219 if (xDiff + yDiff > 5)
bcostm 0:e1d164542663 220 {
bcostm 0:e1d164542663 221 _x = x;
bcostm 0:e1d164542663 222 _y = y;
bcostm 0:e1d164542663 223 }
bcostm 0:e1d164542663 224
bcostm 0:e1d164542663 225 /* Update the X position */
bcostm 0:e1d164542663 226 TsState->X = _x;
bcostm 0:e1d164542663 227
bcostm 0:e1d164542663 228 /* Update the Y position */
bcostm 0:e1d164542663 229 TsState->Y = _y;
bcostm 0:e1d164542663 230 }
bcostm 0:e1d164542663 231 }
bcostm 0:e1d164542663 232
bcostm 0:e1d164542663 233 /**
bcostm 0:e1d164542663 234 * @brief Clears all touch screen interrupts.
bcostm 0:e1d164542663 235 * @param None
bcostm 0:e1d164542663 236 * @retval None
bcostm 0:e1d164542663 237 */
bcostm 0:e1d164542663 238 void BSP_TS_ITClear(void)
bcostm 0:e1d164542663 239 {
bcostm 0:e1d164542663 240 /* Clear TS IT pending bits */
bcostm 0:e1d164542663 241 TsDrv->ClearIT(TS_I2C_ADDRESS);
bcostm 0:e1d164542663 242 }
bcostm 0:e1d164542663 243
bcostm 0:e1d164542663 244 /**
bcostm 0:e1d164542663 245 * @}
bcostm 0:e1d164542663 246 */
bcostm 0:e1d164542663 247
bcostm 0:e1d164542663 248 /**
bcostm 0:e1d164542663 249 * @}
bcostm 0:e1d164542663 250 */
bcostm 0:e1d164542663 251
bcostm 0:e1d164542663 252 /**
bcostm 0:e1d164542663 253 * @}
bcostm 0:e1d164542663 254 */
bcostm 0:e1d164542663 255
bcostm 0:e1d164542663 256 /**
bcostm 0:e1d164542663 257 * @}
bcostm 0:e1d164542663 258 */
bcostm 0:e1d164542663 259
bcostm 0:e1d164542663 260 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/