stmpe811.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. ******************************************************************************
  3. * @file stmpe811.h
  4. * @author MCD Application Team
  5. * @version V2.0.0
  6. * @date 15-December-2014
  7. * @brief This file contains all the functions prototypes for the
  8. * stmpe811.c IO expander driver.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification,
  15. * are permitted provided that the following conditions are met:
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ******************************************************************************
  37. */
  38. /* Define to prevent recursive inclusion -------------------------------------*/
  39. #ifndef __STMPE811_H
  40. #define __STMPE811_H
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /* Includes ------------------------------------------------------------------*/
  45. #include "../Common/ts.h"
  46. #include "../Common/io.h"
  47. /** @addtogroup BSP
  48. * @{
  49. */
  50. /** @addtogroup Components
  51. * @{
  52. */
  53. /** @defgroup STMPE811
  54. * @{
  55. */
  56. /** @defgroup STMPE811_Exported_Types
  57. * @{
  58. */
  59. /**
  60. * @}
  61. */
  62. /** @defgroup STMPE811_Exported_Constants
  63. * @{
  64. */
  65. /* Chip IDs */
  66. #define STMPE811_ID 0x0811
  67. /* Identification registers & System Control */
  68. #define STMPE811_REG_CHP_ID_LSB 0x00
  69. #define STMPE811_REG_CHP_ID_MSB 0x01
  70. #define STMPE811_REG_ID_VER 0x02
  71. /* Global interrupt Enable bit */
  72. #define STMPE811_GIT_EN 0x01
  73. /* IO expander functionalities */
  74. #define STMPE811_ADC_FCT 0x01
  75. #define STMPE811_TS_FCT 0x02
  76. #define STMPE811_IO_FCT 0x04
  77. #define STMPE811_TEMPSENS_FCT 0x08
  78. /* Global Interrupts definitions */
  79. #define STMPE811_GIT_IO 0x80 /* IO interrupt */
  80. #define STMPE811_GIT_ADC 0x40 /* ADC interrupt */
  81. #define STMPE811_GIT_TEMP 0x20 /* Not implemented */
  82. #define STMPE811_GIT_FE 0x10 /* FIFO empty interrupt */
  83. #define STMPE811_GIT_FF 0x08 /* FIFO full interrupt */
  84. #define STMPE811_GIT_FOV 0x04 /* FIFO overflowed interrupt */
  85. #define STMPE811_GIT_FTH 0x02 /* FIFO above threshold interrupt */
  86. #define STMPE811_GIT_TOUCH 0x01 /* Touch is detected interrupt */
  87. #define STMPE811_ALL_GIT 0x1F /* All global interrupts */
  88. #define STMPE811_TS_IT (STMPE811_GIT_TOUCH | STMPE811_GIT_FTH | STMPE811_GIT_FOV | STMPE811_GIT_FF | STMPE811_GIT_FE) /* Touch screen interrupts */
  89. /* General Control Registers */
  90. #define STMPE811_REG_SYS_CTRL1 0x03
  91. #define STMPE811_REG_SYS_CTRL2 0x04
  92. #define STMPE811_REG_SPI_CFG 0x08
  93. /* Interrupt system Registers */
  94. #define STMPE811_REG_INT_CTRL 0x09
  95. #define STMPE811_REG_INT_EN 0x0A
  96. #define STMPE811_REG_INT_STA 0x0B
  97. #define STMPE811_REG_IO_INT_EN 0x0C
  98. #define STMPE811_REG_IO_INT_STA 0x0D
  99. /* IO Registers */
  100. #define STMPE811_REG_IO_SET_PIN 0x10
  101. #define STMPE811_REG_IO_CLR_PIN 0x11
  102. #define STMPE811_REG_IO_MP_STA 0x12
  103. #define STMPE811_REG_IO_DIR 0x13
  104. #define STMPE811_REG_IO_ED 0x14
  105. #define STMPE811_REG_IO_RE 0x15
  106. #define STMPE811_REG_IO_FE 0x16
  107. #define STMPE811_REG_IO_AF 0x17
  108. /* ADC Registers */
  109. #define STMPE811_REG_ADC_INT_EN 0x0E
  110. #define STMPE811_REG_ADC_INT_STA 0x0F
  111. #define STMPE811_REG_ADC_CTRL1 0x20
  112. #define STMPE811_REG_ADC_CTRL2 0x21
  113. #define STMPE811_REG_ADC_CAPT 0x22
  114. #define STMPE811_REG_ADC_DATA_CH0 0x30
  115. #define STMPE811_REG_ADC_DATA_CH1 0x32
  116. #define STMPE811_REG_ADC_DATA_CH2 0x34
  117. #define STMPE811_REG_ADC_DATA_CH3 0x36
  118. #define STMPE811_REG_ADC_DATA_CH4 0x38
  119. #define STMPE811_REG_ADC_DATA_CH5 0x3A
  120. #define STMPE811_REG_ADC_DATA_CH6 0x3B
  121. #define STMPE811_REG_ADC_DATA_CH7 0x3C
  122. /* Touch Screen Registers */
  123. #define STMPE811_REG_TSC_CTRL 0x40
  124. #define STMPE811_REG_TSC_CFG 0x41
  125. #define STMPE811_REG_WDM_TR_X 0x42
  126. #define STMPE811_REG_WDM_TR_Y 0x44
  127. #define STMPE811_REG_WDM_BL_X 0x46
  128. #define STMPE811_REG_WDM_BL_Y 0x48
  129. #define STMPE811_REG_FIFO_TH 0x4A
  130. #define STMPE811_REG_FIFO_STA 0x4B
  131. #define STMPE811_REG_FIFO_SIZE 0x4C
  132. #define STMPE811_REG_TSC_DATA_X 0x4D
  133. #define STMPE811_REG_TSC_DATA_Y 0x4F
  134. #define STMPE811_REG_TSC_DATA_Z 0x51
  135. #define STMPE811_REG_TSC_DATA_XYZ 0x52
  136. #define STMPE811_REG_TSC_FRACT_XYZ 0x56
  137. #define STMPE811_REG_TSC_DATA_INC 0x57
  138. #define STMPE811_REG_TSC_DATA_NON_INC 0xD7
  139. #define STMPE811_REG_TSC_I_DRIVE 0x58
  140. #define STMPE811_REG_TSC_SHIELD 0x59
  141. /* Touch Screen Pins definition */
  142. #define STMPE811_TOUCH_YD STMPE811_PIN_7
  143. #define STMPE811_TOUCH_XD STMPE811_PIN_6
  144. #define STMPE811_TOUCH_YU STMPE811_PIN_5
  145. #define STMPE811_TOUCH_XU STMPE811_PIN_4
  146. #define STMPE811_TOUCH_IO_ALL (uint32_t)(STMPE811_TOUCH_YD | STMPE811_TOUCH_XD | STMPE811_TOUCH_YU | STMPE811_TOUCH_XU)
  147. /* IO Pins definition */
  148. #define STMPE811_PIN_0 0x01
  149. #define STMPE811_PIN_1 0x02
  150. #define STMPE811_PIN_2 0x04
  151. #define STMPE811_PIN_3 0x08
  152. #define STMPE811_PIN_4 0x10
  153. #define STMPE811_PIN_5 0x20
  154. #define STMPE811_PIN_6 0x40
  155. #define STMPE811_PIN_7 0x80
  156. #define STMPE811_PIN_ALL 0xFF
  157. /* IO Pins directions */
  158. #define STMPE811_DIRECTION_IN 0x00
  159. #define STMPE811_DIRECTION_OUT 0x01
  160. /* IO IT types */
  161. #define STMPE811_TYPE_LEVEL 0x00
  162. #define STMPE811_TYPE_EDGE 0x02
  163. /* IO IT polarity */
  164. #define STMPE811_POLARITY_LOW 0x00
  165. #define STMPE811_POLARITY_HIGH 0x04
  166. /* IO Pin IT edge modes */
  167. #define STMPE811_EDGE_FALLING 0x01
  168. #define STMPE811_EDGE_RISING 0x02
  169. /* TS registers masks */
  170. #define STMPE811_TS_CTRL_ENABLE 0x01
  171. #define STMPE811_TS_CTRL_STATUS 0x80
  172. /**
  173. * @}
  174. */
  175. /** @defgroup STMPE811_Exported_Macros
  176. * @{
  177. */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup STMPE811_Exported_Functions
  182. * @{
  183. */
  184. /**
  185. * @brief STMPE811 Control functions
  186. */
  187. void stmpe811_Init(uint16_t DeviceAddr);
  188. void stmpe811_Reset(uint16_t DeviceAddr);
  189. uint16_t stmpe811_ReadID(uint16_t DeviceAddr);
  190. void stmpe811_EnableGlobalIT(uint16_t DeviceAddr);
  191. void stmpe811_DisableGlobalIT(uint16_t DeviceAddr);
  192. void stmpe811_EnableITSource(uint16_t DeviceAddr, uint8_t Source);
  193. void stmpe811_DisableITSource(uint16_t DeviceAddr, uint8_t Source);
  194. void stmpe811_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity);
  195. void stmpe811_SetITType(uint16_t DeviceAddr, uint8_t Type);
  196. uint8_t stmpe811_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source);
  197. uint8_t stmpe811_ReadGITStatus(uint16_t DeviceAddr, uint8_t Source);
  198. void stmpe811_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source);
  199. /**
  200. * @brief STMPE811 IO functionalities functions
  201. */
  202. void stmpe811_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin);
  203. uint8_t stmpe811_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode);
  204. void stmpe811_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction);
  205. void stmpe811_IO_EnableAF(uint16_t DeviceAddr, uint32_t IO_Pin);
  206. void stmpe811_IO_DisableAF(uint16_t DeviceAddr, uint32_t IO_Pin);
  207. void stmpe811_IO_SetEdgeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Edge);
  208. void stmpe811_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState);
  209. uint32_t stmpe811_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin);
  210. void stmpe811_IO_EnableIT(uint16_t DeviceAddr);
  211. void stmpe811_IO_DisableIT(uint16_t DeviceAddr);
  212. void stmpe811_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
  213. void stmpe811_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
  214. uint32_t stmpe811_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin);
  215. void stmpe811_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin);
  216. /**
  217. * @brief STMPE811 Touch screen functionalities functions
  218. */
  219. void stmpe811_TS_Start(uint16_t DeviceAddr);
  220. uint8_t stmpe811_TS_DetectTouch(uint16_t DeviceAddr);
  221. void stmpe811_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
  222. void stmpe811_TS_EnableIT(uint16_t DeviceAddr);
  223. void stmpe811_TS_DisableIT(uint16_t DeviceAddr);
  224. uint8_t stmpe811_TS_ITStatus (uint16_t DeviceAddr);
  225. void stmpe811_TS_ClearIT (uint16_t DeviceAddr);
  226. void IOE_Init(void);
  227. void IOE_ITConfig (void);
  228. void IOE_Delay(uint32_t delay);
  229. void IOE_Write(uint8_t addr, uint8_t reg, uint8_t value);
  230. uint8_t IOE_Read(uint8_t addr, uint8_t reg);
  231. uint16_t IOE_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
  232. /* Touch screen driver structure */
  233. extern TS_DrvTypeDef stmpe811_ts_drv;
  234. /* IO driver structure */
  235. extern IO_DrvTypeDef stmpe811_io_drv;
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif /* __STMPE811_H */
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @}
  245. */
  246. /**
  247. * @}
  248. */
  249. /**
  250. * @}
  251. */
  252. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/