STM32F429ZI Discovery board drivers

Dependents:   2a 2b 2c 2d1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stmpe811.h Source File

stmpe811.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stmpe811.h
00004   * @author  MCD Application Team
00005   * @version V2.0.0
00006   * @date    15-December-2014
00007   * @brief   This file contains all the functions prototypes for the
00008   *          stmpe811.c IO expander driver.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */ 
00038 
00039 /* Define to prevent recursive inclusion -------------------------------------*/
00040 #ifndef __STMPE811_H
00041 #define __STMPE811_H
00042 
00043 #ifdef __cplusplus
00044  extern "C" {
00045 #endif   
00046    
00047 /* Includes ------------------------------------------------------------------*/
00048 #include "../Common/ts.h"
00049 #include "../Common/io.h"
00050 
00051 /** @addtogroup BSP
00052   * @{
00053   */ 
00054 
00055 /** @addtogroup Components
00056   * @{
00057   */
00058     
00059 /** @defgroup STMPE811
00060   * @{
00061   */    
00062 
00063 /** @defgroup STMPE811_Exported_Types
00064   * @{
00065   */ 
00066 /**
00067   * @}
00068   */ 
00069    
00070 /** @defgroup STMPE811_Exported_Constants
00071   * @{
00072   */ 
00073 
00074 /* Chip IDs */   
00075 #define STMPE811_ID                     0x0811
00076     
00077 /* Identification registers & System Control */ 
00078 #define STMPE811_REG_CHP_ID_LSB         0x00
00079 #define STMPE811_REG_CHP_ID_MSB         0x01
00080 #define STMPE811_REG_ID_VER             0x02
00081 
00082 /* Global interrupt Enable bit */ 
00083 #define STMPE811_GIT_EN                 0x01   
00084 
00085 /* IO expander functionalities */        
00086 #define STMPE811_ADC_FCT                0x01
00087 #define STMPE811_TS_FCT                 0x02
00088 #define STMPE811_IO_FCT                 0x04
00089 #define STMPE811_TEMPSENS_FCT           0x08
00090 
00091 /* Global Interrupts definitions */ 
00092 #define STMPE811_GIT_IO                 0x80  /* IO interrupt                   */
00093 #define STMPE811_GIT_ADC                0x40  /* ADC interrupt                  */
00094 #define STMPE811_GIT_TEMP               0x20  /* Not implemented                */
00095 #define STMPE811_GIT_FE                 0x10  /* FIFO empty interrupt           */
00096 #define STMPE811_GIT_FF                 0x08  /* FIFO full interrupt            */
00097 #define STMPE811_GIT_FOV                0x04  /* FIFO overflowed interrupt      */
00098 #define STMPE811_GIT_FTH                0x02  /* FIFO above threshold interrupt */
00099 #define STMPE811_GIT_TOUCH              0x01  /* Touch is detected interrupt    */      
00100 #define STMPE811_ALL_GIT                0x1F  /* All global interrupts          */
00101 #define STMPE811_TS_IT                  (STMPE811_GIT_TOUCH | STMPE811_GIT_FTH |  STMPE811_GIT_FOV | STMPE811_GIT_FF | STMPE811_GIT_FE) /* Touch screen interrupts */
00102     
00103 /* General Control Registers */ 
00104 #define STMPE811_REG_SYS_CTRL1          0x03
00105 #define STMPE811_REG_SYS_CTRL2          0x04
00106 #define STMPE811_REG_SPI_CFG            0x08 
00107 
00108 /* Interrupt system Registers */ 
00109 #define STMPE811_REG_INT_CTRL           0x09
00110 #define STMPE811_REG_INT_EN             0x0A
00111 #define STMPE811_REG_INT_STA            0x0B
00112 #define STMPE811_REG_IO_INT_EN          0x0C
00113 #define STMPE811_REG_IO_INT_STA         0x0D
00114 
00115 /* IO Registers */ 
00116 #define STMPE811_REG_IO_SET_PIN         0x10
00117 #define STMPE811_REG_IO_CLR_PIN         0x11
00118 #define STMPE811_REG_IO_MP_STA          0x12
00119 #define STMPE811_REG_IO_DIR             0x13
00120 #define STMPE811_REG_IO_ED              0x14
00121 #define STMPE811_REG_IO_RE              0x15
00122 #define STMPE811_REG_IO_FE              0x16
00123 #define STMPE811_REG_IO_AF              0x17
00124 
00125 /* ADC Registers */ 
00126 #define STMPE811_REG_ADC_INT_EN         0x0E
00127 #define STMPE811_REG_ADC_INT_STA        0x0F
00128 #define STMPE811_REG_ADC_CTRL1          0x20
00129 #define STMPE811_REG_ADC_CTRL2          0x21
00130 #define STMPE811_REG_ADC_CAPT           0x22
00131 #define STMPE811_REG_ADC_DATA_CH0       0x30 
00132 #define STMPE811_REG_ADC_DATA_CH1       0x32 
00133 #define STMPE811_REG_ADC_DATA_CH2       0x34 
00134 #define STMPE811_REG_ADC_DATA_CH3       0x36 
00135 #define STMPE811_REG_ADC_DATA_CH4       0x38 
00136 #define STMPE811_REG_ADC_DATA_CH5       0x3A 
00137 #define STMPE811_REG_ADC_DATA_CH6       0x3B 
00138 #define STMPE811_REG_ADC_DATA_CH7       0x3C 
00139 
00140 /* Touch Screen Registers */ 
00141 #define STMPE811_REG_TSC_CTRL           0x40
00142 #define STMPE811_REG_TSC_CFG            0x41
00143 #define STMPE811_REG_WDM_TR_X           0x42 
00144 #define STMPE811_REG_WDM_TR_Y           0x44
00145 #define STMPE811_REG_WDM_BL_X           0x46
00146 #define STMPE811_REG_WDM_BL_Y           0x48
00147 #define STMPE811_REG_FIFO_TH            0x4A
00148 #define STMPE811_REG_FIFO_STA           0x4B
00149 #define STMPE811_REG_FIFO_SIZE          0x4C
00150 #define STMPE811_REG_TSC_DATA_X         0x4D 
00151 #define STMPE811_REG_TSC_DATA_Y         0x4F
00152 #define STMPE811_REG_TSC_DATA_Z         0x51
00153 #define STMPE811_REG_TSC_DATA_XYZ       0x52 
00154 #define STMPE811_REG_TSC_FRACT_XYZ      0x56
00155 #define STMPE811_REG_TSC_DATA_INC       0x57
00156 #define STMPE811_REG_TSC_DATA_NON_INC   0xD7
00157 #define STMPE811_REG_TSC_I_DRIVE        0x58
00158 #define STMPE811_REG_TSC_SHIELD         0x59
00159 
00160 /* Touch Screen Pins definition */ 
00161 #define STMPE811_TOUCH_YD               STMPE811_PIN_7 
00162 #define STMPE811_TOUCH_XD               STMPE811_PIN_6
00163 #define STMPE811_TOUCH_YU               STMPE811_PIN_5
00164 #define STMPE811_TOUCH_XU               STMPE811_PIN_4
00165 #define STMPE811_TOUCH_IO_ALL           (uint32_t)(STMPE811_TOUCH_YD | STMPE811_TOUCH_XD | STMPE811_TOUCH_YU | STMPE811_TOUCH_XU)
00166 
00167 /* IO Pins definition */ 
00168 #define STMPE811_PIN_0                  0x01
00169 #define STMPE811_PIN_1                  0x02
00170 #define STMPE811_PIN_2                  0x04
00171 #define STMPE811_PIN_3                  0x08
00172 #define STMPE811_PIN_4                  0x10
00173 #define STMPE811_PIN_5                  0x20
00174 #define STMPE811_PIN_6                  0x40
00175 #define STMPE811_PIN_7                  0x80
00176 #define STMPE811_PIN_ALL                0xFF
00177 
00178 /* IO Pins directions */ 
00179 #define STMPE811_DIRECTION_IN           0x00
00180 #define STMPE811_DIRECTION_OUT          0x01
00181 
00182 /* IO IT types */   
00183 #define STMPE811_TYPE_LEVEL             0x00
00184 #define STMPE811_TYPE_EDGE              0x02
00185 
00186 /* IO IT polarity */   
00187 #define STMPE811_POLARITY_LOW           0x00
00188 #define STMPE811_POLARITY_HIGH          0x04
00189 
00190 /* IO Pin IT edge modes */
00191 #define STMPE811_EDGE_FALLING           0x01
00192 #define STMPE811_EDGE_RISING            0x02
00193 
00194 /* TS registers masks */
00195 #define STMPE811_TS_CTRL_ENABLE         0x01  
00196 #define STMPE811_TS_CTRL_STATUS         0x80
00197 /**
00198   * @}
00199   */ 
00200    
00201 /** @defgroup STMPE811_Exported_Macros
00202   * @{
00203   */ 
00204 /**
00205   * @}
00206   */ 
00207    
00208 /** @defgroup STMPE811_Exported_Functions
00209   * @{
00210   */
00211 
00212 /** 
00213   * @brief STMPE811 Control functions
00214   */
00215 void     stmpe811_Init(uint16_t DeviceAddr);
00216 void     stmpe811_Reset(uint16_t DeviceAddr);
00217 uint16_t stmpe811_ReadID(uint16_t DeviceAddr);
00218 void     stmpe811_EnableGlobalIT(uint16_t DeviceAddr);
00219 void     stmpe811_DisableGlobalIT(uint16_t DeviceAddr);
00220 void     stmpe811_EnableITSource(uint16_t DeviceAddr, uint8_t Source);
00221 void     stmpe811_DisableITSource(uint16_t DeviceAddr, uint8_t Source);
00222 void     stmpe811_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity);
00223 void     stmpe811_SetITType(uint16_t DeviceAddr, uint8_t Type);
00224 uint8_t  stmpe811_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source);
00225 uint8_t  stmpe811_ReadGITStatus(uint16_t DeviceAddr, uint8_t Source);
00226 void     stmpe811_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source);
00227 
00228 /** 
00229   * @brief STMPE811 IO functionalities functions
00230   */
00231 void     stmpe811_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin);
00232 uint8_t  stmpe811_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode);
00233 void     stmpe811_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction);
00234 void     stmpe811_IO_EnableAF(uint16_t DeviceAddr, uint32_t IO_Pin);
00235 void     stmpe811_IO_DisableAF(uint16_t DeviceAddr, uint32_t IO_Pin);
00236 void     stmpe811_IO_SetEdgeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Edge);
00237 void     stmpe811_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState);
00238 uint32_t stmpe811_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin);
00239 void     stmpe811_IO_EnableIT(uint16_t DeviceAddr);
00240 void     stmpe811_IO_DisableIT(uint16_t DeviceAddr);
00241 void     stmpe811_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
00242 void     stmpe811_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
00243 uint32_t stmpe811_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin);
00244 void     stmpe811_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin);
00245 
00246 /** 
00247   * @brief STMPE811 Touch screen functionalities functions
00248   */
00249 void     stmpe811_TS_Start(uint16_t DeviceAddr);
00250 uint8_t  stmpe811_TS_DetectTouch(uint16_t DeviceAddr);
00251 void     stmpe811_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
00252 void     stmpe811_TS_EnableIT(uint16_t DeviceAddr);
00253 void     stmpe811_TS_DisableIT(uint16_t DeviceAddr);
00254 uint8_t  stmpe811_TS_ITStatus (uint16_t DeviceAddr);
00255 void     stmpe811_TS_ClearIT (uint16_t DeviceAddr);
00256 
00257 void     IOE_Init(void);
00258 void     IOE_ITConfig (void);
00259 void     IOE_Delay(uint32_t delay);
00260 void     IOE_Write(uint8_t addr, uint8_t reg, uint8_t value);
00261 uint8_t  IOE_Read(uint8_t addr, uint8_t reg);
00262 uint16_t IOE_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
00263 
00264 /* Touch screen driver structure */
00265 extern TS_DrvTypeDef stmpe811_ts_drv;
00266 
00267 /* IO driver structure */
00268 extern IO_DrvTypeDef stmpe811_io_drv;
00269 
00270 #ifdef __cplusplus
00271 }
00272 #endif
00273 #endif /* __STMPE811_H */
00274 
00275 /**
00276   * @}
00277   */ 
00278 
00279 /**
00280   * @}
00281   */
00282 
00283 /**
00284   * @}
00285   */ 
00286 
00287 /**
00288   * @}
00289   */
00290 
00291 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/