stm3210c_eval_ioe.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /**
  2. ******************************************************************************
  3. * @file stm3210c_eval_ioe.h
  4. * @author MCD Application Team
  5. * @version V4.5.0
  6. * @date 07-March-2011
  7. * @brief This file contains all the functions prototypes for the IO Expander
  8. * firmware driver.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* File Info : ---------------------------------------------------------------
  23. SUPPORTED FEATURES:
  24. - IO Read/write : Set/Reset and Read (Polling/Interrupt)
  25. - Joystick: config and Read (Polling/Interrupt)
  26. - Touch Screen Features: Single point mode (Polling/Interrupt)
  27. - TempSensor Feature: accuracy not determined (Polling).
  28. UNSUPPORTED FEATURES:
  29. - Row ADC Feature is not supported (not implemented on STM3210C-EVAL board)
  30. ----------------------------------------------------------------------------*/
  31. /* Define to prevent recursive inclusion -------------------------------------*/
  32. #ifndef __STM3210C_EVAL_IOE_H
  33. #define __STM3210C_EVAL_IOE_H
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* Includes ------------------------------------------------------------------*/
  38. #include "stm32f10x.h"
  39. /** @addtogroup Utilities
  40. * @{
  41. */
  42. /** @addtogroup STM32_EVAL
  43. * @{
  44. */
  45. /** @addtogroup STM3210C_EVAL
  46. * @{
  47. */
  48. /** @defgroup STM3210C_EVAL_IOE
  49. * @{
  50. */
  51. /** @defgroup STM3210C_EVAL_IOE_Exported_Types
  52. * @{
  53. */
  54. /**
  55. * @brief Touch Screen Information structure
  56. */
  57. typedef struct
  58. {
  59. uint16_t TouchDetected;
  60. uint16_t X;
  61. uint16_t Y;
  62. uint16_t Z;
  63. }TS_STATE;
  64. /**
  65. * @brief Joystick State definitions
  66. */
  67. #ifndef __STM32_EVAL_H
  68. typedef enum
  69. {
  70. JOY_NONE = 0,
  71. JOY_SEL = 1,
  72. JOY_DOWN = 2,
  73. JOY_LEFT = 3,
  74. JOY_RIGHT = 4,
  75. JOY_UP = 5
  76. } JOYState_TypeDef
  77. ;
  78. #endif /* __STM32_EVAL_H */
  79. /**
  80. * @brief IO_Expander Error codes
  81. */
  82. typedef enum
  83. {
  84. IOE_OK = 0,
  85. IOE_FAILURE,
  86. IOE_TIMEOUT,
  87. PARAM_ERROR,
  88. IOE1_NOT_OPERATIONAL,
  89. IOE2_NOT_OPERATIONAL
  90. }IOE_Status_TypDef;
  91. /**
  92. * @brief IO bit values
  93. */
  94. typedef enum
  95. {
  96. BitReset = 0,
  97. BitSet = 1
  98. }IOE_BitValue_TypeDef;
  99. /**
  100. * @brief IOE DMA Direction
  101. */
  102. typedef enum
  103. {
  104. IOE_DMA_TX = 0,
  105. IOE_DMA_RX = 1
  106. }IOE_DMADirection_TypeDef;
  107. /**
  108. * @}
  109. */
  110. /** @defgroup STM3210C_EVAL_IOE_Exported_Constants
  111. * @{
  112. */
  113. /**
  114. * @brief Uncomment the line below to enable verfying each written byte in write
  115. * operation. The I2C_WriteDeviceRegister() function will then compare the
  116. * written and read data and return error status if a mismatch occurs.
  117. */
  118. /* #define VERIFY_WRITTENDATA */
  119. /**
  120. * @brief Uncomment the line below if you want to use user defined Delay function
  121. * (for precise timing), otherwise default _delay_ function defined within
  122. * this driver is used (less precise timing).
  123. */
  124. /* #define USE_Delay */
  125. /**
  126. * @brief Uncomment the line below if you want to use user timeout callback.
  127. * Function prototypes is declared in this file but function body may be
  128. * implemented into user application.
  129. */
  130. /* #define USE_TIMEOUT_USER_CALLBACK */
  131. #ifdef USE_Delay
  132. #include "main.h"
  133. #define _delay_ Delay /* !< User can provide more timing precise _delay_ function
  134. (with 10ms time base), using SysTick for example */
  135. #else
  136. #define _delay_ delay /* !< Default _delay_ function with less precise timing */
  137. #endif
  138. /*------------------------------------------------------------------------------
  139. Hardware Configuration
  140. ------------------------------------------------------------------------------*/
  141. /**
  142. * @brief I2C port definitions
  143. */
  144. #define IOE_I2C I2C1
  145. #define IOE_I2C_CLK RCC_APB1Periph_I2C1
  146. #define IOE_I2C_SCL_PIN GPIO_Pin_6
  147. #define IOE_I2C_SCL_GPIO_PORT GPIOB
  148. #define IOE_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB
  149. #define IOE_I2C_SDA_PIN GPIO_Pin_7
  150. #define IOE_I2C_SDA_GPIO_PORT GPIOB
  151. #define IOE_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB
  152. #define IOE_I2C_DR ((uint32_t)0x40005410)
  153. #define IOE_I2C_SPEED 300000
  154. /**
  155. * @brief IOE DMA definitions
  156. */
  157. #define IOE_DMA DMA1
  158. #define IOE_DMA_CLK RCC_AHBPeriph_DMA1
  159. #define IOE_DMA_TX_CHANNEL DMA1_Channel6
  160. #define IOE_DMA_RX_CHANNEL DMA1_Channel7
  161. #define IOE_DMA_TX_TCFLAG DMA1_FLAG_TC6
  162. #define IOE_DMA_RX_TCFLAG DMA1_FLAG_TC7
  163. /**
  164. * @brief IO Expander Interrupt line on EXTI
  165. */
  166. #define IOE_IT_PIN GPIO_Pin_14
  167. #define IOE_IT_GPIO_PORT GPIOB
  168. #define IOE_IT_GPIO_CLK RCC_APB2Periph_GPIOB
  169. #define IOE_IT_EXTI_PORT_SOURCE GPIO_PortSourceGPIOB
  170. #define IOE_IT_EXTI_PIN_SOURCE GPIO_PinSource14
  171. #define IOE_IT_EXTI_LINE EXTI_Line14
  172. #define IOE_IT_EXTI_IRQn EXTI15_10_IRQn
  173. /**
  174. * @brief Eval Board IO Pins definition
  175. */
  176. #define AUDIO_RESET_PIN IO_Pin_2 /* IO_Exapnader_2 */ /* Output */
  177. #define MII_INT_PIN IO_Pin_0 /* IO_Exapnader_2 */ /* Output */
  178. #define VBAT_DIV_PIN IO_Pin_0 /* IO_Exapnader_1 */ /* Output */
  179. #define MEMS_INT1_PIN IO_Pin_3 /* IO_Exapnader_1 */ /* Input */
  180. #define MEMS_INT2_PIN IO_Pin_2 /* IO_Exapnader_1 */ /* Input */
  181. /**
  182. * @brief Eval Board both IO Exapanders Pins definition
  183. */
  184. #define IO1_IN_ALL_PINS (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN)
  185. #define IO2_IN_ALL_PINS (uint32_t)(JOY_IO_PINS)
  186. #define IO1_OUT_ALL_PINS (uint32_t)(VBAT_DIV_PIN)
  187. #define IO2_OUT_ALL_PINS (uint32_t)(AUDIO_RESET_PIN | MII_INT_PIN)
  188. /**
  189. * @brief The 7 bits IO Expanders adresses and chip IDs
  190. */
  191. #define IOE_1_ADDR 0x82
  192. #define IOE_2_ADDR 0x88
  193. #define STMPE811_ID 0x0811
  194. /*------------------------------------------------------------------------------
  195. Functional and Interrupt Management
  196. ------------------------------------------------------------------------------*/
  197. /**
  198. * @brief IO Expander Functionalities definitions
  199. */
  200. #define IOE_ADC_FCT 0x01
  201. #define IOE_TS_FCT 0x02
  202. #define IOE_IO_FCT 0x04
  203. #define IOE_TEMPSENS_FCT 0x08
  204. /**
  205. * @brief Interrupt source configuration definitons
  206. */
  207. #define IOE_ITSRC_TSC 0x01 /* IO_Exapnder 1 */
  208. #define IOE_ITSRC_INMEMS 0x02 /* IO_Exapnder 1 */
  209. #define IOE_ITSRC_JOYSTICK 0x04 /* IO_Exapnder 2 */
  210. #define IOE_ITSRC_TEMPSENS 0x08 /* IO_Exapnder 2 */
  211. /**
  212. * @brief Glaobal Interrupts definitions
  213. */
  214. #define IOE_GIT_GPIO 0x80
  215. #define IOE_GIT_ADC 0x40
  216. #define IOE_GIT_TEMP 0x20
  217. #define IOE_GIT_FE 0x10
  218. #define IOE_GIT_FF 0x08
  219. #define IOE_GIT_FOV 0x04
  220. #define IOE_GIT_FTH 0x02
  221. #define IOE_GIT_TOUCH 0x01
  222. /*------------------------------------------------------------------------------
  223. STMPE811 device register definition
  224. ------------------------------------------------------------------------------*/
  225. /**
  226. * @brief Identification registers
  227. */
  228. #define IOE_REG_CHP_ID 0x00
  229. #define IOE_REG_ID_VER 0x02
  230. /**
  231. * @brief General Control Registers
  232. */
  233. #define IOE_REG_SYS_CTRL1 0x03
  234. #define IOE_REG_SYS_CTRL2 0x04
  235. #define IOE_REG_SPI_CFG 0x08
  236. /**
  237. * @brief Interrupt Control register
  238. */
  239. #define IOE_REG_INT_CTRL 0x09
  240. #define IOE_REG_INT_EN 0x0A
  241. #define IOE_REG_INT_STA 0x0B
  242. #define IOE_REG_GPIO_INT_EN 0x0C
  243. #define IOE_REG_GPIO_INT_STA 0x0D
  244. /**
  245. * @brief GPIO Registers
  246. */
  247. #define IOE_REG_GPIO_SET_PIN 0x10
  248. #define IOE_REG_GPIO_CLR_PIN 0x11
  249. #define IOE_REG_GPIO_MP_STA 0x12
  250. #define IOE_REG_GPIO_DIR 0x13
  251. #define IOE_REG_GPIO_ED 0x14
  252. #define IOE_REG_GPIO_RE 0x15
  253. #define IOE_REG_GPIO_FE 0x16
  254. #define IOE_REG_GPIO_AF 0x17
  255. /**
  256. * @brief ADC Registers
  257. */
  258. #define IOE_REG_ADC_INT_EN 0x0E
  259. #define IOE_REG_ADC_INT_STA 0x0F
  260. #define IOE_REG_ADC_CTRL1 0x20
  261. #define IOE_REG_ADC_CTRL2 0x21
  262. #define IOE_REG_ADC_CAPT 0x22
  263. #define IOE_REG_ADC_DATA_CH0 0x30 /* 16-Bit register */
  264. #define IOE_REG_ADC_DATA_CH1 0x32 /* 16-Bit register */
  265. #define IOE_REG_ADC_DATA_CH2 0x34 /* 16-Bit register */
  266. #define IOE_REG_ADC_DATA_CH3 0x36 /* 16-Bit register */
  267. #define IOE_REG_ADC_DATA_CH4 0x38 /* 16-Bit register */
  268. #define IOE_REG_ADC_DATA_CH5 0x3A /* 16-Bit register */
  269. #define IOE_REG_ADC_DATA_CH6 0x3B /* 16-Bit register */
  270. #define IOE_REG_ADC_DATA_CH7 0x3C /* 16-Bit register */
  271. /**
  272. * @brief TouchScreen Registers
  273. */
  274. #define IOE_REG_TSC_CTRL 0x40
  275. #define IOE_REG_TSC_CFG 0x41
  276. #define IOE_REG_WDM_TR_X 0x42
  277. #define IOE_REG_WDM_TR_Y 0x44
  278. #define IOE_REG_WDM_BL_X 0x46
  279. #define IOE_REG_WDM_BL_Y 0x48
  280. #define IOE_REG_FIFO_TH 0x4A
  281. #define IOE_REG_FIFO_STA 0x4B
  282. #define IOE_REG_FIFO_SIZE 0x4C
  283. #define IOE_REG_TSC_DATA_X 0x4D
  284. #define IOE_REG_TSC_DATA_Y 0x4F
  285. #define IOE_REG_TSC_DATA_Z 0x51
  286. #define IOE_REG_TSC_DATA_XYZ 0x52
  287. #define IOE_REG_TSC_FRACT_XYZ 0x56
  288. #define IOE_REG_TSC_DATA 0x57
  289. #define IOE_REG_TSC_I_DRIVE 0x58
  290. #define IOE_REG_TSC_SHIELD 0x59
  291. /**
  292. * @brief Temperature Sensor registers
  293. */
  294. #define IOE_REG_TEMP_CTRL 0x60
  295. #define IOE_REG_TEMP_DATA 0x61
  296. #define IOE_REG_TEMP_TH 0x62
  297. /*------------------------------------------------------------------------------
  298. Functions parameters defines
  299. ------------------------------------------------------------------------------*/
  300. /**
  301. * @brief Touch Screen Pins definition
  302. */
  303. #define TOUCH_YD IO_Pin_1 /* IO_Exapnader_1 */ /* Input */
  304. #define TOUCH_XD IO_Pin_2 /* IO_Exapnader_1 */ /* Input */
  305. #define TOUCH_YU IO_Pin_3 /* IO_Exapnader_1 */ /* Input */
  306. #define TOUCH_XU IO_Pin_4 /* IO_Exapnader_1 */ /* Input */
  307. #define TOUCH_IO_ALL (uint32_t)(IO_Pin_1 | IO_Pin_2 | IO_Pin_3 | IO_Pin_4)
  308. /**
  309. * @brief JOYSTICK Pins definition
  310. */
  311. #define JOY_IO_SEL IO_Pin_7
  312. #define JOY_IO_DOWN IO_Pin_6
  313. #define JOY_IO_LEFT IO_Pin_5
  314. #define JOY_IO_RIGHT IO_Pin_4
  315. #define JOY_IO_UP IO_Pin_3
  316. #define JOY_IO_NONE JOY_IO_PINS
  317. #define JOY_IO_PINS (uint32_t)(IO_Pin_3 | IO_Pin_4 | IO_Pin_5 | IO_Pin_6 | IO_Pin_7)
  318. /**
  319. * @brief IO Pins
  320. */
  321. #define IO_Pin_0 0x01
  322. #define IO_Pin_1 0x02
  323. #define IO_Pin_2 0x04
  324. #define IO_Pin_3 0x08
  325. #define IO_Pin_4 0x10
  326. #define IO_Pin_5 0x20
  327. #define IO_Pin_6 0x40
  328. #define IO_Pin_7 0x80
  329. #define IO_Pin_ALL 0xFF
  330. /**
  331. * @brief IO Pin directions
  332. */
  333. #define Direction_IN 0x00
  334. #define Direction_OUT 0x01
  335. /**
  336. * @brief Interrupt Line output parameters
  337. */
  338. #define Polarity_Low 0x00
  339. #define Polarity_High 0x04
  340. #define Type_Level 0x00
  341. #define Type_Edge 0x02
  342. /**
  343. * @brief IO Interrupts
  344. */
  345. #define IO_IT_0 0x01
  346. #define IO_IT_1 0x02
  347. #define IO_IT_2 0x04
  348. #define IO_IT_3 0x08
  349. #define IO_IT_4 0x10
  350. #define IO_IT_5 0x20
  351. #define IO_IT_6 0x40
  352. #define IO_IT_7 0x80
  353. #define ALL_IT 0xFF
  354. #define IOE_JOY_IT (uint8_t)(IO_IT_3 | IO_IT_4 | IO_IT_5 | IO_IT_6 | IO_IT_7)
  355. #define IOE_TS_IT (uint8_t)(IO_IT_0 | IO_IT_1 | IO_IT_2)
  356. #define IOE_INMEMS_IT (uint8_t)(IO_IT_2 | IO_IT_3)
  357. /**
  358. * @brief Edge detection value
  359. */
  360. #define EDGE_FALLING 0x01
  361. #define EDGE_RISING 0x02
  362. /**
  363. * @brief Global interrupt Enable bit
  364. */
  365. #define IOE_GIT_EN 0x01
  366. /**
  367. * @}
  368. */
  369. /** @defgroup STM3210C_EVAL_IOE_Exported_Macros
  370. * @{
  371. */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup STM3210C_EVAL_IOE_Exported_Functions
  376. * @{
  377. */
  378. /**
  379. * @brief Configuration and initialization functions
  380. */
  381. uint8_t IOE_Config(void);
  382. uint8_t IOE_ITConfig(uint32_t IOE_ITSRC_Source);
  383. /**
  384. * @brief Timeout user callback function. This function is called when a timeout
  385. * condition occurs during communication with IO Expander. Only protoype
  386. * of this function is decalred in IO Expander driver. Its implementation
  387. * may be done into user application. This function may typically stop
  388. * current operations and reset the I2C peripheral and IO Expander.
  389. * To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK
  390. * at the top of this file.
  391. */
  392. #ifdef USE_TIMEOUT_USER_CALLBACK
  393. uint8_t IOE_TimeoutUserCallback(void);
  394. #else
  395. #define IOE_TimeoutUserCallback() IOE_TIMEOUT
  396. #endif /* USE_TIMEOUT_USER_CALLBACK */
  397. /**
  398. * @brief IO pins control functions
  399. */
  400. uint8_t IOE_WriteIOPin(uint8_t IO_Pin, IOE_BitValue_TypeDef BitVal);
  401. uint8_t IOE_ReadIOPin(uint32_t IO_Pin);
  402. JOYState_TypeDef
  403. IOE_JoyStickGetState(void);
  404. /**
  405. * @brief Touch Screen controller functions
  406. */
  407. TS_STATE* IOE_TS_GetState(void);
  408. /**
  409. * @brief Interrupts Mangement functions
  410. */
  411. FlagStatus IOE_GetGITStatus(uint8_t DeviceAddr, uint8_t Global_IT);
  412. uint8_t IOE_ClearGITPending(uint8_t DeviceAddr, uint8_t IO_IT);
  413. FlagStatus IOE_GetIOITStatus(uint8_t DeviceAddr, uint8_t IO_IT);
  414. uint8_t IOE_ClearIOITPending(uint8_t DeviceAddr, uint8_t IO_IT);
  415. /**
  416. * @brief Temperature Sensor functions
  417. */
  418. uint32_t IOE_TempSens_GetData(void);
  419. /**
  420. * @brief IO-Expander Control functions
  421. */
  422. uint8_t IOE_IsOperational(uint8_t DeviceAddr);
  423. uint8_t IOE_Reset(uint8_t DeviceAddr);
  424. uint16_t IOE_ReadID(uint8_t DeviceAddr);
  425. uint8_t IOE_FnctCmd(uint8_t DeviceAddr, uint8_t Fct, FunctionalState NewState);
  426. uint8_t IOE_IOPinConfig(uint8_t DeviceAddr, uint8_t IO_Pin, uint8_t Direction);
  427. uint8_t IOE_GITCmd(uint8_t DeviceAddr, FunctionalState NewState);
  428. uint8_t IOE_GITConfig(uint8_t DeviceAddr, uint8_t Global_IT, FunctionalState NewState);
  429. uint8_t IOE_IOITConfig(uint8_t DeviceAddr, uint8_t IO_IT, FunctionalState NewState);
  430. /**
  431. * @brief Low Layer functions
  432. */
  433. uint8_t IOE_TS_Config(void);
  434. uint8_t IOE_TempSens_Config(void);
  435. uint8_t IOE_IOAFConfig(uint8_t DeviceAddr, uint8_t IO_Pin, FunctionalState NewState);
  436. uint8_t IOE_IOEdgeConfig(uint8_t DeviceAddr, uint8_t IO_Pin, uint8_t Edge);
  437. uint8_t IOE_ITOutConfig(uint8_t Polarity, uint8_t Type);
  438. uint8_t I2C_WriteDeviceRegister(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t RegisterValue);
  439. uint8_t I2C_ReadDeviceRegister(uint8_t DeviceAddr, uint8_t RegisterAddr);
  440. uint16_t I2C_ReadDataBuffer(uint8_t DeviceAddr, uint32_t RegisterAddr);
  441. #ifdef __cplusplus
  442. }
  443. #endif
  444. #endif /* __STM3210C_EVAL_IOE_H */
  445. /**
  446. * @}
  447. */
  448. /**
  449. * @}
  450. */
  451. /**
  452. * @}
  453. */
  454. /**
  455. * @}
  456. */
  457. /**
  458. * @}
  459. */
  460. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/