stm3210c_eval_ioe.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm3210c_eval_ioe.h
00004   * @author  MCD Application Team
00005   * @version V4.3.0
00006   * @date    10/15/2010
00007   * @brief   This file contains all the functions prototypes for the IO Expander
00008   *   firmware driver.
00009   ******************************************************************************
00010   * @copy
00011   *
00012   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00013   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00014   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00015   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00016   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00017   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00018   *
00019   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00020   */ 
00021 
00022   /* File Info : ---------------------------------------------------------------
00023     SUPPORTED FEATURES:
00024       - IO Read/write : Set/Reset and Read (Polling/Interrupt)
00025       - Joystick: config and Read (Polling/Interrupt)
00026       - Touch Screen Features: Single point mode (Polling/Interrupt)
00027       - TempSensor Feature: accuracy not determined (Polling).
00028 
00029     UNSUPPORTED FEATURES:
00030       - Row ADC Feature is not supported (not implemented on STM3210C-EVAL board)
00031   ----------------------------------------------------------------------------*/
00032 
00033 
00034 /* Define to prevent recursive inclusion -------------------------------------*/
00035 #ifndef __STM3210C_EVAL_IOE_H
00036 #define __STM3210C_EVAL_IOE_H
00037 
00038 #ifdef __cplusplus
00039  extern "C" {
00040 #endif   
00041    
00042 /* Includes ------------------------------------------------------------------*/
00043 #include "stm32f10x.h"
00044 
00045 /** @addtogroup Utilities
00046   * @{
00047   */
00048 
00049 /** @addtogroup STM32_EVAL
00050   * @{
00051   */ 
00052 
00053 /** @addtogroup STM3210C_EVAL
00054   * @{
00055   */
00056     
00057 /** @defgroup STM3210C_EVAL_IOE 
00058   * @{
00059   */ 
00060 
00061 /** @defgroup STM3210C_EVAL_IOE_Exported_Types
00062   * @{
00063   */ 
00064 
00065 /** 
00066   * @brief  Touch Screen Information structure  
00067   */ 
00068 typedef struct
00069 {
00070   uint16_t TouchDetected;
00071   uint16_t X;
00072   uint16_t Y;
00073   uint16_t Z;
00074 }TS_STATE; 
00075   
00076 /** 
00077   * @brief  Joystick State definitions  
00078   */ 
00079 #ifndef __STM32_EVAL_H
00080 typedef enum 
00081 { 
00082   JOY_NONE = 0,
00083   JOY_SEL = 1,
00084   JOY_DOWN = 2,
00085   JOY_LEFT = 3,
00086   JOY_RIGHT = 4,
00087   JOY_UP = 5
00088 } JOYState_TypeDef
00089 ;
00090 #endif /* __STM32_EVAL_H */
00091  
00092 /** 
00093   * @brief  IO_Expander Error codes  
00094   */ 
00095 typedef enum
00096 {
00097   IOE_OK = 0,
00098   IOE_FAILURE, 
00099   IOE_TIMEOUT,
00100   PARAM_ERROR,
00101   IOE1_NOT_OPERATIONAL, 
00102   IOE2_NOT_OPERATIONAL
00103 }IOE_Status_TypDef;
00104 
00105 /** 
00106   * @brief  IO bit values  
00107   */ 
00108 typedef enum
00109 {
00110   BitReset = 0,
00111   BitSet = 1
00112 }IOE_BitValue_TypeDef;
00113 
00114 /** 
00115   * @brief  IOE DMA Direction  
00116   */ 
00117 typedef enum
00118 {
00119   IOE_DMA_TX = 0,
00120   IOE_DMA_RX = 1
00121 }IOE_DMADirection_TypeDef;
00122 
00123 /**
00124   * @}
00125   */ 
00126 
00127 
00128 /** @defgroup STM3210C_EVAL_IOE_Exported_Constants
00129   * @{
00130   */ 
00131 
00132 /**
00133  * @brief Uncomment the line below to enable verfying each written byte in write
00134  *        operation. The I2C_WriteDeviceRegister() function will then compare the
00135  *        written and read data and return error status if a mismatch occurs.
00136  */
00137 /* #define VERIFY_WRITTENDATA */
00138 
00139 /**
00140  * @brief Uncomment the line below if you want to use user defined Delay function
00141  *        (for precise timing), otherwise default _delay_ function defined within
00142  *         this driver is used (less precise timing).  
00143  */
00144 /* #define USE_Delay */
00145 
00146 /**
00147  * @brief Uncomment the line below if you want to use user timeout callback.
00148  *        Function prototypes is declared in this file but function body may be
00149  *        implemented into user application.  
00150  */
00151 /* #define USE_TIMEOUT_USER_CALLBACK */
00152 
00153 #ifdef USE_Delay
00154 #include "main.h"
00155  
00156   #define _delay_     Delay  /* !< User can provide more timing precise _delay_ function
00157                                    (with 10ms time base), using SysTick for example */
00158 #else
00159   #define _delay_     delay      /* !< Default _delay_ function with less precise timing */
00160 #endif    
00161 
00162 /*------------------------------------------------------------------------------
00163     Hardware Configuration 
00164 ------------------------------------------------------------------------------*/
00165 /** 
00166   * @brief  I2C port definitions  
00167   */
00168 #define IOE_I2C                          I2C1
00169 #define IOE_I2C_CLK                      RCC_APB1Periph_I2C1
00170 #define IOE_I2C_SCL_PIN                  GPIO_Pin_6
00171 #define IOE_I2C_SCL_GPIO_PORT            GPIOB
00172 #define IOE_I2C_SCL_GPIO_CLK             RCC_APB2Periph_GPIOB
00173 #define IOE_I2C_SDA_PIN                  GPIO_Pin_7
00174 #define IOE_I2C_SDA_GPIO_PORT            GPIOB
00175 #define IOE_I2C_SDA_GPIO_CLK             RCC_APB2Periph_GPIOB
00176 #define IOE_I2C_DR                       ((uint32_t)0x40005410)
00177 #define IOE_I2C_SPEED                    300000  
00178 
00179 /** 
00180   * @brief  IOE DMA definitions  
00181   */
00182 #define IOE_DMA                          DMA1
00183 #define IOE_DMA_CLK                      RCC_AHBPeriph_DMA1
00184 #define IOE_DMA_TX_CHANNEL               DMA1_Channel6
00185 #define IOE_DMA_RX_CHANNEL               DMA1_Channel7
00186 #define IOE_DMA_TX_TCFLAG                DMA1_FLAG_TC6
00187 #define IOE_DMA_RX_TCFLAG                DMA1_FLAG_TC7
00188 
00189 
00190 /** 
00191   * @brief  IO Expander Interrupt line on EXTI  
00192   */ 
00193 #define IOE_IT_PIN                       GPIO_Pin_14
00194 #define IOE_IT_GPIO_PORT                 GPIOB
00195 #define IOE_IT_GPIO_CLK                  RCC_APB2Periph_GPIOB
00196 #define IOE_IT_EXTI_PORT_SOURCE          GPIO_PortSourceGPIOB
00197 #define IOE_IT_EXTI_PIN_SOURCE           GPIO_PinSource14
00198 #define IOE_IT_EXTI_LINE                 EXTI_Line14
00199 #define IOE_IT_EXTI_IRQn                 EXTI15_10_IRQn       
00200 
00201 /**
00202   * @brief Eval Board IO Pins definition 
00203   */ 
00204 #define AUDIO_RESET_PIN             IO_Pin_2 /* IO_Exapnader_2 */ /* Output */
00205 #define MII_INT_PIN                 IO_Pin_0 /* IO_Exapnader_2 */ /* Output */
00206 #define VBAT_DIV_PIN                IO_Pin_0 /* IO_Exapnader_1 */ /* Output */
00207 #define MEMS_INT1_PIN               IO_Pin_3 /* IO_Exapnader_1 */ /* Input */
00208 #define MEMS_INT2_PIN               IO_Pin_2 /* IO_Exapnader_1 */ /* Input */
00209 
00210  
00211 /**
00212   * @brief Eval Board both IO Exapanders Pins definition 
00213   */ 
00214 #define IO1_IN_ALL_PINS          (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN)
00215 #define IO2_IN_ALL_PINS          (uint32_t)(JOY_IO_PINS)
00216 #define IO1_OUT_ALL_PINS         (uint32_t)(VBAT_DIV_PIN)
00217 #define IO2_OUT_ALL_PINS         (uint32_t)(AUDIO_RESET_PIN | MII_INT_PIN)
00218 
00219 /** 
00220   * @brief  The 7 bits IO Expanders adresses and chip IDs  
00221   */ 
00222 #define IOE_1_ADDR                 0x82    
00223 #define IOE_2_ADDR                 0x88    
00224 #define STMPE811_ID                0x0811
00225 
00226 
00227 /*------------------------------------------------------------------------------
00228     Functional and Interrupt Management
00229 ------------------------------------------------------------------------------*/
00230 /** 
00231   * @brief  IO Expander Functionalities definitions  
00232   */ 
00233 #define IOE_ADC_FCT              0x01
00234 #define IOE_TS_FCT               0x02
00235 #define IOE_IO_FCT               0x04
00236 #define IOE_TEMPSENS_FCT         0x08
00237 
00238 /** 
00239   * @brief  Interrupt source configuration definitons  
00240   */ 
00241 #define IOE_ITSRC_TSC           0x01  /* IO_Exapnder 1 */
00242 #define IOE_ITSRC_INMEMS        0x02  /* IO_Exapnder 1 */
00243 #define IOE_ITSRC_JOYSTICK      0x04  /* IO_Exapnder 2 */
00244 #define IOE_ITSRC_TEMPSENS      0x08  /* IO_Exapnder 2 */
00245 
00246 /** 
00247   * @brief  Glaobal Interrupts definitions  
00248   */ 
00249 #define IOE_GIT_GPIO             0x80
00250 #define IOE_GIT_ADC              0x40
00251 #define IOE_GIT_TEMP             0x20
00252 #define IOE_GIT_FE               0x10
00253 #define IOE_GIT_FF               0x08
00254 #define IOE_GIT_FOV              0x04
00255 #define IOE_GIT_FTH              0x02
00256 #define IOE_GIT_TOUCH            0x01
00257 
00258 
00259 /*------------------------------------------------------------------------------
00260     STMPE811 device register definition
00261 ------------------------------------------------------------------------------*/
00262 /** 
00263   * @brief  Identification registers  
00264   */ 
00265 #define IOE_REG_CHP_ID             0x00
00266 #define IOE_REG_ID_VER             0x02
00267 
00268 /** 
00269   * @brief  General Control Registers  
00270   */ 
00271 #define IOE_REG_SYS_CTRL1          0x03
00272 #define IOE_REG_SYS_CTRL2          0x04
00273 #define IOE_REG_SPI_CFG            0x08 
00274 
00275 /** 
00276   * @brief  Interrupt Control register  
00277   */ 
00278 #define IOE_REG_INT_CTRL           0x09
00279 #define IOE_REG_INT_EN             0x0A
00280 #define IOE_REG_INT_STA            0x0B
00281 #define IOE_REG_GPIO_INT_EN        0x0C
00282 #define IOE_REG_GPIO_INT_STA       0x0D
00283 
00284 /** 
00285   * @brief  GPIO Registers  
00286   */ 
00287 #define IOE_REG_GPIO_SET_PIN       0x10
00288 #define IOE_REG_GPIO_CLR_PIN       0x11
00289 #define IOE_REG_GPIO_MP_STA        0x12
00290 #define IOE_REG_GPIO_DIR           0x13
00291 #define IOE_REG_GPIO_ED            0x14
00292 #define IOE_REG_GPIO_RE            0x15
00293 #define IOE_REG_GPIO_FE            0x16
00294 #define IOE_REG_GPIO_AF            0x17
00295 
00296 /** 
00297   * @brief  ADC Registers  
00298   */ 
00299 #define IOE_REG_ADC_INT_EN         0x0E
00300 #define IOE_REG_ADC_INT_STA        0x0F
00301 #define IOE_REG_ADC_CTRL1          0x20
00302 #define IOE_REG_ADC_CTRL2          0x21
00303 #define IOE_REG_ADC_CAPT           0x22
00304 #define IOE_REG_ADC_DATA_CH0       0x30 /* 16-Bit register */
00305 #define IOE_REG_ADC_DATA_CH1       0x32 /* 16-Bit register */
00306 #define IOE_REG_ADC_DATA_CH2       0x34 /* 16-Bit register */
00307 #define IOE_REG_ADC_DATA_CH3       0x36 /* 16-Bit register */
00308 #define IOE_REG_ADC_DATA_CH4       0x38 /* 16-Bit register */
00309 #define IOE_REG_ADC_DATA_CH5       0x3A /* 16-Bit register */
00310 #define IOE_REG_ADC_DATA_CH6       0x3B /* 16-Bit register */
00311 #define IOE_REG_ADC_DATA_CH7       0x3C /* 16-Bit register */ 
00312 
00313 /** 
00314   * @brief  TouchScreen Registers  
00315   */ 
00316 #define IOE_REG_TSC_CTRL           0x40
00317 #define IOE_REG_TSC_CFG            0x41
00318 #define IOE_REG_WDM_TR_X           0x42 
00319 #define IOE_REG_WDM_TR_Y           0x44
00320 #define IOE_REG_WDM_BL_X           0x46
00321 #define IOE_REG_WDM_BL_Y           0x48
00322 #define IOE_REG_FIFO_TH            0x4A
00323 #define IOE_REG_FIFO_STA           0x4B
00324 #define IOE_REG_FIFO_SIZE          0x4C
00325 #define IOE_REG_TSC_DATA_X         0x4D 
00326 #define IOE_REG_TSC_DATA_Y         0x4F
00327 #define IOE_REG_TSC_DATA_Z         0x51
00328 #define IOE_REG_TSC_DATA_XYZ       0x52 
00329 #define IOE_REG_TSC_FRACT_XYZ      0x56
00330 #define IOE_REG_TSC_DATA           0x57
00331 #define IOE_REG_TSC_I_DRIVE        0x58
00332 #define IOE_REG_TSC_SHIELD         0x59
00333 
00334 /** 
00335   * @brief  Temperature Sensor registers  
00336   */ 
00337 #define IOE_REG_TEMP_CTRL          0x60
00338 #define IOE_REG_TEMP_DATA          0x61
00339 #define IOE_REG_TEMP_TH            0x62
00340 
00341 
00342 /*------------------------------------------------------------------------------
00343     Functions parameters defines
00344 ------------------------------------------------------------------------------*/
00345 /**
00346   * @brief Touch Screen Pins definition 
00347   */ 
00348 #define TOUCH_YD                    IO_Pin_1 /* IO_Exapnader_1 */ /* Input */
00349 #define TOUCH_XD                    IO_Pin_2 /* IO_Exapnader_1 */ /* Input */
00350 #define TOUCH_YU                    IO_Pin_3 /* IO_Exapnader_1 */ /* Input */
00351 #define TOUCH_XU                    IO_Pin_4 /* IO_Exapnader_1 */ /* Input */
00352 #define TOUCH_IO_ALL                (uint32_t)(IO_Pin_1 | IO_Pin_2 | IO_Pin_3 | IO_Pin_4)
00353 
00354 /**
00355   * @brief  JOYSTICK Pins definition 
00356   */ 
00357 #define JOY_IO_SEL                   IO_Pin_7
00358 #define JOY_IO_DOWN                  IO_Pin_6
00359 #define JOY_IO_LEFT                  IO_Pin_5
00360 #define JOY_IO_RIGHT                 IO_Pin_4
00361 #define JOY_IO_UP                    IO_Pin_3
00362 #define JOY_IO_NONE                  JOY_IO_PINS
00363 #define JOY_IO_PINS                  (uint32_t)(IO_Pin_3 | IO_Pin_4 | IO_Pin_5 | IO_Pin_6 | IO_Pin_7)
00364 
00365 /** 
00366   * @brief  IO Pins  
00367   */ 
00368 #define IO_Pin_0                 0x01
00369 #define IO_Pin_1                 0x02
00370 #define IO_Pin_2                 0x04
00371 #define IO_Pin_3                 0x08
00372 #define IO_Pin_4                 0x10
00373 #define IO_Pin_5                 0x20
00374 #define IO_Pin_6                 0x40
00375 #define IO_Pin_7                 0x80
00376 #define IO_Pin_ALL               0xFF
00377 
00378 /** 
00379   * @brief  IO Pin directions  
00380   */ 
00381 #define Direction_IN             0x00
00382 #define Direction_OUT            0x01
00383 
00384 /** 
00385   * @brief  Interrupt Line output parameters  
00386   */ 
00387 #define Polarity_Low             0x00
00388 #define Polarity_High            0x04
00389 #define Type_Level               0x00
00390 #define Type_Edge                0x02
00391 
00392 /** 
00393   * @brief IO Interrupts  
00394   */ 
00395 #define IO_IT_0                  0x01
00396 #define IO_IT_1                  0x02
00397 #define IO_IT_2                  0x04
00398 #define IO_IT_3                  0x08
00399 #define IO_IT_4                  0x10
00400 #define IO_IT_5                  0x20
00401 #define IO_IT_6                  0x40
00402 #define IO_IT_7                  0x80
00403 #define ALL_IT                   0xFF
00404 #define IOE_JOY_IT               (uint8_t)(IO_IT_3 | IO_IT_4 | IO_IT_5 | IO_IT_6 | IO_IT_7)
00405 #define IOE_TS_IT                (uint8_t)(IO_IT_0 | IO_IT_1 | IO_IT_2)
00406 #define IOE_INMEMS_IT            (uint8_t)(IO_IT_2 | IO_IT_3)
00407 
00408 /** 
00409   * @brief  Edge detection value  
00410   */ 
00411 #define EDGE_FALLING              0x01
00412 #define EDGE_RISING               0x02
00413 
00414 /** 
00415   * @brief  Global interrupt Enable bit  
00416   */ 
00417 #define IOE_GIT_EN                0x01
00418 
00419 /**
00420   * @}
00421   */ 
00422 
00423 
00424 
00425 /** @defgroup STM3210C_EVAL_IOE_Exported_Macros
00426   * @{
00427   */ 
00428 /**
00429   * @}
00430   */ 
00431 
00432 
00433 
00434 /** @defgroup STM3210C_EVAL_IOE_Exported_Functions
00435   * @{
00436   */ 
00437 
00438 /** 
00439   * @brief  Configuration and initialization functions  
00440   */
00441 uint8_t IOE_Config(void);
00442 uint8_t IOE_ITConfig(uint32_t IOE_ITSRC_Source);
00443 
00444 /** 
00445   * @brief  Timeout user callback function. This function is called when a timeout
00446   *         condition occurs during communication with IO Expander. Only protoype
00447   *         of this function is decalred in IO Expander driver. Its implementation
00448   *         may be done into user application. This function may typically stop
00449   *         current operations and reset the I2C peripheral and IO Expander.
00450   *         To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK
00451   *         at the top of this file.          
00452   */
00453 #ifdef USE_TIMEOUT_USER_CALLBACK 
00454  uint8_t IOE_TimeoutUserCallback(void);
00455 #else
00456  #define IOE_TimeoutUserCallback()  IOE_TIMEOUT
00457 #endif /* USE_TIMEOUT_USER_CALLBACK */
00458 
00459 /** 
00460   * @brief IO pins control functions
00461   */
00462 uint8_t IOE_WriteIOPin(uint8_t IO_Pin, IOE_BitValue_TypeDef BitVal);
00463 uint8_t IOE_ReadIOPin(uint32_t IO_Pin);
00464 JOYState_TypeDef
00465  IOE_JoyStickGetState(void);
00466 
00467 /** 
00468   * @brief Touch Screen controller functions
00469   */
00470 TS_STATE* IOE_TS_GetState(void);
00471 
00472 /** 
00473   * @brief Interrupts Mangement functions
00474   */
00475 FlagStatus IOE_GetGITStatus(uint8_t DeviceAddr, uint8_t Global_IT);
00476 uint8_t IOE_ClearGITPending(uint8_t DeviceAddr, uint8_t IO_IT);
00477 FlagStatus IOE_GetIOITStatus(uint8_t DeviceAddr, uint8_t IO_IT);
00478 uint8_t IOE_ClearIOITPending(uint8_t DeviceAddr, uint8_t IO_IT);
00479 
00480 /** 
00481   * @brief Temperature Sensor functions
00482   */
00483 uint32_t IOE_TempSens_GetData(void);
00484 
00485 /** 
00486   * @brief IO-Expander Control functions
00487   */
00488 uint8_t IOE_IsOperational(uint8_t DeviceAddr);
00489 uint8_t IOE_Reset(uint8_t DeviceAddr);
00490 uint16_t IOE_ReadID(uint8_t DeviceAddr);
00491 
00492 uint8_t IOE_FnctCmd(uint8_t DeviceAddr, uint8_t Fct, FunctionalState NewState);
00493 uint8_t IOE_IOPinConfig(uint8_t DeviceAddr, uint8_t IO_Pin, uint8_t Direction);
00494 uint8_t IOE_GITCmd(uint8_t DeviceAddr, FunctionalState NewState);
00495 uint8_t IOE_GITConfig(uint8_t DeviceAddr, uint8_t Global_IT, FunctionalState NewState);
00496 uint8_t IOE_IOITConfig(uint8_t DeviceAddr, uint8_t IO_IT, FunctionalState NewState);
00497 
00498 /** 
00499   * @brief Low Layer functions
00500   */
00501 uint8_t IOE_TS_Config(void);
00502 uint8_t IOE_TempSens_Config(void);
00503 uint8_t IOE_IOAFConfig(uint8_t DeviceAddr, uint8_t IO_Pin, FunctionalState NewState);
00504 uint8_t IOE_IOEdgeConfig(uint8_t DeviceAddr, uint8_t IO_Pin, uint8_t Edge);
00505 uint8_t IOE_ITOutConfig(uint8_t Polarity, uint8_t Type);
00506 
00507 uint8_t I2C_WriteDeviceRegister(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t RegisterValue);
00508 uint8_t I2C_ReadDeviceRegister(uint8_t DeviceAddr, uint8_t RegisterAddr);
00509 uint16_t I2C_ReadDataBuffer(uint8_t DeviceAddr, uint32_t RegisterAddr);
00510 
00511 #ifdef __cplusplus
00512 }
00513 
00514 #endif
00515 #endif /* __STM3210C_EVAL_IOE_H */
00516 
00517 /**
00518   * @}
00519   */ 
00520 
00521 /**
00522   * @}
00523   */ 
00524 
00525 /**
00526   * @}
00527   */ 
00528 
00529 /**
00530   * @}
00531   */ 
00532 
00533 /**
00534   * @}
00535   */     
00536 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32