Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM32100E_EVAL/stm32100e_eval_ioe.h @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32100e_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>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
20 ****************************************************************************** | |
21 */ | |
22 | |
23 /* File Info : --------------------------------------------------------------- | |
24 SUPPORTED FEATURES: | |
25 - Touch Screen Features: Single point mode (Polling/Interrupt). | |
26 - TempSensor Feature: accuracy not determined (Polling). | |
27 - IO Read/write : Set/Reset and Read (Polling/Interrupt). | |
28 | |
29 UNSUPPORTED FEATURES: | |
30 - Row ADC Feature is not supported (not implemented on STM32100E-EVAL board) | |
31 - Joystick: config and Read (Polling/Interrupt) | |
32 ----------------------------------------------------------------------------*/ | |
33 | |
34 | |
35 /* Define to prevent recursive inclusion -------------------------------------*/ | |
36 #ifndef __STM32100E_EVAL_IOE_H | |
37 #define __STM32100E_EVAL_IOE_H | |
38 | |
39 #ifdef __cplusplus | |
40 extern "C" { | |
41 #endif | |
42 | |
43 /* Includes ------------------------------------------------------------------*/ | |
44 #include "stm32f10x.h" | |
45 | |
46 /** @addtogroup Utilities | |
47 * @{ | |
48 */ | |
49 | |
50 /** @addtogroup STM32_EVAL | |
51 * @{ | |
52 */ | |
53 | |
54 /** @addtogroup STM32100E_EVAL | |
55 * @{ | |
56 */ | |
57 | |
58 /** @defgroup STM32100E_EVAL_IOE | |
59 * @{ | |
60 */ | |
61 | |
62 /** @defgroup STM32100E_EVAL_IOE_Exported_Types | |
63 * @{ | |
64 */ | |
65 | |
66 /** | |
67 * @brief Touch Screen Information structure | |
68 */ | |
69 typedef struct | |
70 { | |
71 uint16_t TouchDetected; | |
72 uint16_t X; | |
73 uint16_t Y; | |
74 uint16_t Z; | |
75 }TS_STATE; | |
76 | |
77 | |
78 /** | |
79 * @brief IO_Expander Error codes | |
80 */ | |
81 typedef enum | |
82 { | |
83 IOE_OK = 0, | |
84 IOE_FAILURE, | |
85 IOE_TIMEOUT, | |
86 PARAM_ERROR, | |
87 IOE1_NOT_OPERATIONAL | |
88 }IOE_Status_TypDef; | |
89 | |
90 /** | |
91 * @brief IO bit values | |
92 */ | |
93 typedef enum | |
94 { | |
95 BitReset = 0, | |
96 BitSet = 1 | |
97 }IOE_BitValue_TypeDef; | |
98 | |
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 */ | |
111 | |
112 /** @defgroup STM32100E_EVAL_IOE_Exported_Constants | |
113 * @{ | |
114 */ | |
115 | |
116 /** | |
117 * @brief Uncomment the line below to enable verfying each written byte in write | |
118 * operation. The I2C_WriteDeviceRegister() function will then compare the | |
119 * written and read data and return error status if a mismatch occurs. | |
120 */ | |
121 /* #define VERIFY_WRITTENDATA */ | |
122 | |
123 /** | |
124 * @brief Uncomment the line below if you want to use user defined Delay function | |
125 * (for precise timing), otherwise default _delay_ function defined within | |
126 * this driver is used (less precise timing). | |
127 */ | |
128 /* #define USE_Delay */ | |
129 | |
130 /** | |
131 * @brief Uncomment the line below if you want to use user timeout callback. | |
132 * Function prototypes is declared in this file but function body may be | |
133 * implemented into user application. | |
134 */ | |
135 /* #define USE_TIMEOUT_USER_CALLBACK */ | |
136 | |
137 #ifdef USE_Delay | |
138 #include "main.h" | |
139 | |
140 #define _delay_ Delay /* !< User can provide more timing precise _delay_ function | |
141 (with 10ms time base), using SysTick for example */ | |
142 #else | |
143 #define _delay_ delay /* !< Default _delay_ function with less precise timing */ | |
144 #endif | |
145 | |
146 /*------------------------------------------------------------------------------ | |
147 Hardware Configuration | |
148 ------------------------------------------------------------------------------*/ | |
149 /** | |
150 * @brief I2C port definitions | |
151 */ | |
152 #define IOE_I2C I2C2 | |
153 #define IOE_I2C_CLK RCC_APB1Periph_I2C2 | |
154 #define IOE_I2C_SCL_PIN GPIO_Pin_10 | |
155 #define IOE_I2C_SCL_GPIO_PORT GPIOB | |
156 #define IOE_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB | |
157 #define IOE_I2C_SDA_PIN GPIO_Pin_11 | |
158 #define IOE_I2C_SDA_GPIO_PORT GPIOB | |
159 #define IOE_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB | |
160 #define IOE_I2C_DR ((uint32_t)0x40005810) | |
161 #define IOE_I2C_SPEED 300000 | |
162 | |
163 /** | |
164 * @brief IOE DMA definitions | |
165 */ | |
166 #define IOE_DMA DMA1 | |
167 #define IOE_DMA_CLK RCC_AHBPeriph_DMA1 | |
168 #define IOE_DMA_TX_CHANNEL DMA1_Channel4 | |
169 #define IOE_DMA_RX_CHANNEL DMA1_Channel5 | |
170 #define IOE_DMA_TX_TCFLAG DMA1_FLAG_TC4 | |
171 #define IOE_DMA_RX_TCFLAG DMA1_FLAG_TC5 | |
172 | |
173 | |
174 /** | |
175 * @brief IO Expander Interrupt line on EXTI | |
176 */ | |
177 #define IOE_IT_PIN GPIO_Pin_12 | |
178 #define IOE_IT_GPIO_PORT GPIOA | |
179 #define IOE_IT_GPIO_CLK RCC_APB2Periph_GPIOA | |
180 #define IOE_IT_EXTI_PORT_SOURCE GPIO_PortSourceGPIOA | |
181 #define IOE_IT_EXTI_PIN_SOURCE GPIO_PinSource12 | |
182 #define IOE_IT_EXTI_LINE EXTI_Line12 | |
183 #define IOE_IT_EXTI_IRQn EXTI15_10_IRQn | |
184 | |
185 | |
186 /** | |
187 * @brief The 7 bits IO Expanders adresses and chip IDs | |
188 */ | |
189 #define IOE_1_ADDR 0x82 | |
190 #define STMPE811_ID 0x0811 | |
191 | |
192 | |
193 /*------------------------------------------------------------------------------ | |
194 Functional and Interrupt Management | |
195 ------------------------------------------------------------------------------*/ | |
196 /** | |
197 * @brief IO Expander Functionalities definitions | |
198 */ | |
199 #define IOE_ADC_FCT 0x01 | |
200 #define IOE_TS_FCT 0x02 | |
201 #define IOE_IO_FCT 0x04 | |
202 #define IOE_TEMPSENS_FCT 0x08 | |
203 | |
204 /** | |
205 * @brief Interrupt source configuration definitons | |
206 */ | |
207 #define IOE_ITSRC_TSC 0x01 /* IO_Exapnder 1 */ | |
208 #define IOE_ITSRC_TEMPSENS 0x08 /* IO_Exapnder 1 */ | |
209 | |
210 /** | |
211 * @brief Glaobal Interrupts definitions | |
212 */ | |
213 #define IOE_GIT_GPIO 0x80 | |
214 #define IOE_GIT_ADC 0x40 | |
215 #define IOE_GIT_TEMP 0x20 | |
216 #define IOE_GIT_FE 0x10 | |
217 #define IOE_GIT_FF 0x08 | |
218 #define IOE_GIT_FOV 0x04 | |
219 #define IOE_GIT_FTH 0x02 | |
220 #define IOE_GIT_TOUCH 0x01 | |
221 | |
222 /** | |
223 * @brief IO Exapanders Pins definition | |
224 */ | |
225 #define IO1_IN_ALL_PINS (uint32_t)(IO_Pin_ALL) | |
226 #define IO1_OUT_ALL_PINS (uint32_t)(IO_Pin_ALL) | |
227 | |
228 | |
229 /*------------------------------------------------------------------------------ | |
230 STMPE811 device register definition | |
231 ------------------------------------------------------------------------------*/ | |
232 /** | |
233 * @brief Identification registers | |
234 */ | |
235 #define IOE_REG_CHP_ID 0x00 | |
236 #define IOE_REG_ID_VER 0x02 | |
237 | |
238 /** | |
239 * @brief General Control Registers | |
240 */ | |
241 #define IOE_REG_SYS_CTRL1 0x03 | |
242 #define IOE_REG_SYS_CTRL2 0x04 | |
243 #define IOE_REG_SPI_CFG 0x08 | |
244 | |
245 /** | |
246 * @brief Interrupt Control register | |
247 */ | |
248 #define IOE_REG_INT_CTRL 0x09 | |
249 #define IOE_REG_INT_EN 0x0A | |
250 #define IOE_REG_INT_STA 0x0B | |
251 #define IOE_REG_GPIO_INT_EN 0x0C | |
252 #define IOE_REG_GPIO_INT_STA 0x0D | |
253 | |
254 /** | |
255 * @brief GPIO Registers | |
256 */ | |
257 #define IOE_REG_GPIO_SET_PIN 0x10 | |
258 #define IOE_REG_GPIO_CLR_PIN 0x11 | |
259 #define IOE_REG_GPIO_MP_STA 0x12 | |
260 #define IOE_REG_GPIO_DIR 0x13 | |
261 #define IOE_REG_GPIO_ED 0x14 | |
262 #define IOE_REG_GPIO_RE 0x15 | |
263 #define IOE_REG_GPIO_FE 0x16 | |
264 #define IOE_REG_GPIO_AF 0x17 | |
265 | |
266 /** | |
267 * @brief ADC Registers | |
268 */ | |
269 #define IOE_REG_ADC_INT_EN 0x0E | |
270 #define IOE_REG_ADC_INT_STA 0x0F | |
271 #define IOE_REG_ADC_CTRL1 0x20 | |
272 #define IOE_REG_ADC_CTRL2 0x21 | |
273 #define IOE_REG_ADC_CAPT 0x22 | |
274 #define IOE_REG_ADC_DATA_CH0 0x30 /* 16-Bit register */ | |
275 #define IOE_REG_ADC_DATA_CH1 0x32 /* 16-Bit register */ | |
276 #define IOE_REG_ADC_DATA_CH2 0x34 /* 16-Bit register */ | |
277 #define IOE_REG_ADC_DATA_CH3 0x36 /* 16-Bit register */ | |
278 #define IOE_REG_ADC_DATA_CH4 0x38 /* 16-Bit register */ | |
279 #define IOE_REG_ADC_DATA_CH5 0x3A /* 16-Bit register */ | |
280 #define IOE_REG_ADC_DATA_CH6 0x3B /* 16-Bit register */ | |
281 #define IOE_REG_ADC_DATA_CH7 0x3C /* 16-Bit register */ | |
282 | |
283 /** | |
284 * @brief TouchScreen Registers | |
285 */ | |
286 #define IOE_REG_TSC_CTRL 0x40 | |
287 #define IOE_REG_TSC_CFG 0x41 | |
288 #define IOE_REG_WDM_TR_X 0x42 | |
289 #define IOE_REG_WDM_TR_Y 0x44 | |
290 #define IOE_REG_WDM_BL_X 0x46 | |
291 #define IOE_REG_WDM_BL_Y 0x48 | |
292 #define IOE_REG_FIFO_TH 0x4A | |
293 #define IOE_REG_FIFO_STA 0x4B | |
294 #define IOE_REG_FIFO_SIZE 0x4C | |
295 #define IOE_REG_TSC_DATA_X 0x4D | |
296 #define IOE_REG_TSC_DATA_Y 0x4F | |
297 #define IOE_REG_TSC_DATA_Z 0x51 | |
298 #define IOE_REG_TSC_DATA_XYZ 0x52 | |
299 #define IOE_REG_TSC_FRACT_XYZ 0x56 | |
300 #define IOE_REG_TSC_DATA 0x57 | |
301 #define IOE_REG_TSC_I_DRIVE 0x58 | |
302 #define IOE_REG_TSC_SHIELD 0x59 | |
303 | |
304 /** | |
305 * @brief Temperature Sensor registers | |
306 */ | |
307 #define IOE_REG_TEMP_CTRL 0x60 | |
308 #define IOE_REG_TEMP_DATA 0x61 | |
309 #define IOE_REG_TEMP_TH 0x62 | |
310 | |
311 /*------------------------------------------------------------------------------ | |
312 Functions parameters defines | |
313 ------------------------------------------------------------------------------*/ | |
314 /** | |
315 * @brief Touch Screen Pins definition | |
316 */ | |
317 #define TOUCH_YD IO_Pin_1 /* IO_Exapnader_1 */ /* Input */ | |
318 #define TOUCH_XD IO_Pin_2 /* IO_Exapnader_1 */ /* Input */ | |
319 #define TOUCH_YU IO_Pin_3 /* IO_Exapnader_1 */ /* Input */ | |
320 #define TOUCH_XU IO_Pin_4 /* IO_Exapnader_1 */ /* Input */ | |
321 #define TOUCH_IO_ALL (uint32_t)(IO_Pin_1 | IO_Pin_2 | IO_Pin_3 | IO_Pin_4) | |
322 | |
323 /** | |
324 * @brief IO Pins | |
325 */ | |
326 #define IO_Pin_0 0x01 | |
327 #define IO_Pin_1 0x02 | |
328 #define IO_Pin_2 0x04 | |
329 #define IO_Pin_3 0x08 | |
330 #define IO_Pin_4 0x10 | |
331 #define IO_Pin_5 0x20 | |
332 #define IO_Pin_6 0x40 | |
333 #define IO_Pin_7 0x80 | |
334 #define IO_Pin_ALL 0xFF | |
335 | |
336 /** | |
337 * @brief IO Pin directions | |
338 */ | |
339 #define Direction_IN 0x00 | |
340 #define Direction_OUT 0x01 | |
341 | |
342 /** | |
343 * @brief Interrupt Line output parameters | |
344 */ | |
345 #define Polarity_Low 0x00 | |
346 #define Polarity_High 0x04 | |
347 #define Type_Level 0x00 | |
348 #define Type_Edge 0x02 | |
349 | |
350 /** | |
351 * @brief IO Interrupts | |
352 */ | |
353 #define IO_IT_0 0x01 | |
354 #define IO_IT_1 0x02 | |
355 #define IO_IT_2 0x04 | |
356 #define IO_IT_3 0x08 | |
357 #define IO_IT_4 0x10 | |
358 #define IO_IT_5 0x20 | |
359 #define IO_IT_6 0x40 | |
360 #define IO_IT_7 0x80 | |
361 #define ALL_IT 0xFF | |
362 #define IOE_TS_IT (uint8_t)(IO_IT_0 | IO_IT_1 | IO_IT_2) | |
363 | |
364 /** | |
365 * @brief Edge detection value | |
366 */ | |
367 #define EDGE_FALLING 0x01 | |
368 #define EDGE_RISING 0x02 | |
369 | |
370 /** | |
371 * @brief Global interrupt Enable bit | |
372 */ | |
373 #define IOE_GIT_EN 0x01 | |
374 | |
375 /** | |
376 * @} | |
377 */ | |
378 | |
379 | |
380 | |
381 /** @defgroup STM32100E_EVAL_IOE_Exported_Macros | |
382 * @{ | |
383 */ | |
384 /** | |
385 * @} | |
386 */ | |
387 | |
388 | |
389 | |
390 /** @defgroup STM32100E_EVAL_IOE_Exported_Functions | |
391 * @{ | |
392 */ | |
393 | |
394 /** | |
395 * @brief Configuration and initialization functions | |
396 */ | |
397 uint8_t IOE_Config(void); | |
398 uint8_t IOE_ITConfig(uint32_t IOE_ITSRC_Source); | |
399 | |
400 /** | |
401 * @brief Timeout user callback function. This function is called when a timeout | |
402 * condition occurs during communication with IO Expander. Only protoype | |
403 * of this function is decalred in IO Expander driver. Its implementation | |
404 * may be done into user application. This function may typically stop | |
405 * current operations and reset the I2C peripheral and IO Expander. | |
406 * To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK | |
407 * at the top of this file. | |
408 */ | |
409 #ifdef USE_TIMEOUT_USER_CALLBACK | |
410 uint8_t IOE_TimeoutUserCallback(void); | |
411 #else | |
412 #define IOE_TimeoutUserCallback() IOE_TIMEOUT | |
413 #endif /* USE_TIMEOUT_USER_CALLBACK */ | |
414 | |
415 /** | |
416 * @brief IO pins control functions | |
417 */ | |
418 uint8_t IOE_WriteIOPin(uint8_t IO_Pin, IOE_BitValue_TypeDef BitVal); | |
419 uint8_t IOE_ReadIOPin(uint32_t IO_Pin); | |
420 | |
421 /** | |
422 * @brief Touch Screen controller functions | |
423 */ | |
424 TS_STATE* IOE_TS_GetState(void); | |
425 | |
426 /** | |
427 * @brief Interrupts Mangement functions | |
428 */ | |
429 FlagStatus IOE_GetGITStatus(uint8_t DeviceAddr, uint8_t Global_IT); | |
430 uint8_t IOE_ClearGITPending(uint8_t DeviceAddr, uint8_t IO_IT); | |
431 FlagStatus IOE_GetIOITStatus(uint8_t DeviceAddr, uint8_t IO_IT); | |
432 uint8_t IOE_ClearIOITPending(uint8_t DeviceAddr, uint8_t IO_IT); | |
433 | |
434 | |
435 /** | |
436 * @brief Temperature Sensor functions | |
437 */ | |
438 uint32_t IOE_TempSens_GetData(void); | |
439 | |
440 | |
441 /** | |
442 * @brief IO-Expander Control functions | |
443 */ | |
444 uint8_t IOE_IsOperational(uint8_t DeviceAddr); | |
445 uint8_t IOE_Reset(uint8_t DeviceAddr); | |
446 uint16_t IOE_ReadID(uint8_t DeviceAddr); | |
447 | |
448 uint8_t IOE_FnctCmd(uint8_t DeviceAddr, uint8_t Fct, FunctionalState NewState); | |
449 uint8_t IOE_IOPinConfig(uint8_t DeviceAddr, uint8_t IO_Pin, uint8_t Direction); | |
450 uint8_t IOE_GITCmd(uint8_t DeviceAddr, FunctionalState NewState); | |
451 uint8_t IOE_GITConfig(uint8_t DeviceAddr, uint8_t Global_IT, FunctionalState NewState); | |
452 uint8_t IOE_IOITConfig(uint8_t DeviceAddr, uint8_t IO_IT, FunctionalState NewState); | |
453 | |
454 /** | |
455 * @brief Low Layer functions | |
456 */ | |
457 uint8_t IOE_TS_Config(void); | |
458 uint8_t IOE_TempSens_Config(void); | |
459 uint8_t IOE_IOAFConfig(uint8_t DeviceAddr, uint8_t IO_Pin, FunctionalState NewState); | |
460 uint8_t IOE_IOEdgeConfig(uint8_t DeviceAddr, uint8_t IO_Pin, uint8_t Edge); | |
461 uint8_t IOE_ITOutConfig(uint8_t Polarity, uint8_t Type); | |
462 | |
463 uint8_t I2C_WriteDeviceRegister(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t RegisterValue); | |
464 uint8_t I2C_ReadDeviceRegister(uint8_t DeviceAddr, uint8_t RegisterAddr); | |
465 uint16_t I2C_ReadDataBuffer(uint8_t DeviceAddr, uint32_t RegisterAddr); | |
466 #ifdef __cplusplus | |
467 } | |
468 | |
469 #endif | |
470 #endif /* __STM32100E_EVAL_IOE_H */ | |
471 | |
472 /** | |
473 * @} | |
474 */ | |
475 | |
476 /** | |
477 * @} | |
478 */ | |
479 | |
480 /** | |
481 * @} | |
482 */ | |
483 | |
484 /** | |
485 * @} | |
486 */ | |
487 | |
488 /** | |
489 * @} | |
490 */ | |
491 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |