/**
  * @brief  Initialize and Configures the IO_Expanders Functionalities 
  *         (Touch Screen ..) and configures all STM32100E-EVAL necessary
  *         hardware (GPIOs, APB clocks ..).
  * @param  None
  * @retval IOE_OK if all initializations done correctly. Other value if error.
  */
uint8_t IOE_Config(void)
{
  IOE_StructInit();
  IOE_Init();
  
  /* Read IO Expander 1 ID  */
  if(IOE_IsOperational(IOE_1_ADDR))
  {
    return IOE1_NOT_OPERATIONAL;
  } 
  
  /* Generate IOExpander Software reset */
  IOE_Reset(IOE_1_ADDR); 
  
  /* ---------------------- IO Expander configuration --------------------- */
  /* Enable the GPIO, Touch Screen and ADC functionalities */
  IOE_FnctCmd(IOE_1_ADDR, IOE_ADC_FCT | IOE_IO_FCT , ENABLE);
   
  /* Touch Screen controller configuration */
  IOE_TS_Config();
  
  /* Temperature Sensor configuration */
  IOE_TempSens_Config();
  
  /* Configuration is OK */
  return IOE_OK; 
}
/**
  * @brief  User callback that manages the IOE errors.
  * @param  None
  * @retval None
  */ 
void IOE_TimeoutUserCallback(void)
{
  /* Configure the needed pins */
  IOE_EXTI_Config(); 
  
  /* Configure I2C device */
  IOE_StructInit();
  IOE_Init();
}  
/**
  * @brief  Initialize and Configures the two IO_Expanders Functionalities
  *         (IOs, Touch Screen ..) and configures all STM3210C-EVAL necessary
  *         hardware (GPIOs, APB clocks ..).
  * @param  None
  * @retval IOE_OK if all initializations done correctly. Other value if error.
  */
uint8_t IOE_Config(void)
{
    IOE_StructInit();
    IOE_Init();

    /* Read IO Expander 1 ID  */
    if(IOE_IsOperational(IOE_1_ADDR))
    {
        return IOE1_NOT_OPERATIONAL;
    }

    /* Read IO Expander 2 ID  */
    if(IOE_IsOperational(IOE_2_ADDR))
    {
        return IOE2_NOT_OPERATIONAL;
    }

    /* Generate IOExpander Software reset */
    IOE_Reset(IOE_1_ADDR);
    IOE_Reset(IOE_2_ADDR);

    /* ---------------------- IO Expander 1 configuration --------------------- */
    /* Enable the GPIO, Touch Screen and ADC functionalities */
    IOE_FnctCmd(IOE_1_ADDR, IOE_IO_FCT | IOE_ADC_FCT, ENABLE);

    /* Configure the VBAT pin in output mode pin*/
    IOE_IOPinConfig(IOE_1_ADDR, VBAT_DIV_PIN , Direction_OUT);

    /* ENABLE the alternate function for IN1 pin */
    IOE_IOAFConfig(IOE_1_ADDR, VBAT_DIV_PIN, ENABLE);

    /* Apply the default state for the out pins */
    IOE_WriteIOPin(VBAT_DIV_PIN, BitReset);

    /* Touch Screen controller configuration */
    IOE_TS_Config();

    /* ---------------------- IO Expander 2 configuration --------------------- */
    /* Enable the GPIO, Temperature Sensor and ADC functionalities */
    IOE_FnctCmd(IOE_2_ADDR, IOE_IO_FCT | IOE_ADC_FCT, ENABLE);

    /* Configure the Audio Codec Reset pin in output mode pin*/
    IOE_IOPinConfig(IOE_2_ADDR, (uint32_t)(AUDIO_RESET_PIN), Direction_OUT);
    IOE_IOPinConfig(IOE_2_ADDR, (uint32_t)(MII_INT_PIN), Direction_IN);

    /* ENABLE the alternate function for IN1 pin */
    IOE_IOAFConfig(IOE_2_ADDR, (uint32_t)(AUDIO_RESET_PIN | MII_INT_PIN), ENABLE);

    /* Apply the default state for the out pins */
    IOE_WriteIOPin(AUDIO_RESET_PIN, BitReset);
    IOE_WriteIOPin(MII_INT_PIN, BitReset);

    /* Configure the Joystick pins in Input mode */
    IOE_IOPinConfig(IOE_2_ADDR, JOY_IO_PINS , Direction_IN);

    /* ENABLE the alternate function for the Joystick pins */
    IOE_IOAFConfig(IOE_2_ADDR, JOY_IO_PINS, ENABLE);

    /* Configure the IOs to detect Falling and Rising Edges */
    IOE_IOEdgeConfig(IOE_2_ADDR, JOY_IO_PINS, (uint8_t)(EDGE_FALLING | EDGE_RISING));

    /* Configure the MEMS interrupt pins in Input mode */
    IOE_IOPinConfig(IOE_2_ADDR, (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN), Direction_IN);

    /* ENABLE the alternate function for the Joystick pins */
    IOE_IOAFConfig(IOE_2_ADDR, (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN), ENABLE);

    /* Configure the IOs to detect Falling and Rising Edges */
    IOE_IOEdgeConfig(IOE_2_ADDR, (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN), (uint32_t)(EDGE_FALLING | EDGE_RISING));

    /* Temperature Sensor module configuration */
    IOE_TempSens_Config();

    /* Configuration is OK */
    return IOE_OK;
}