/**
  * @brief  Clear all the IT pending bits if any. 
  * @param  DeviceAddr: Device address on communication Bus.            
  * @retval None
  */
void stmpe1600_IO_ClearIT(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
    
  /* Get the register value to clear all pending bits */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
}
/**
  * @brief  Configure the IO pin(s) according to IO mode structure value.
  * @param  DeviceAddr: Device address on communication Bus.  
  * @param  IO_Pin: The output pin to be set or reset. This parameter can be one 
  *         of the following values:   
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 7.
  * @param  IO_Mode: The IO pin mode to configure, could be one of the following values:
  *   @arg  IO_MODE_INPUT
  *   @arg  IO_MODE_OUTPUT
  *   @arg  IO_MODE_IT_RISING_EDGE
  *   @arg  IO_MODE_IT_FALLING_EDGE         
  * @retval None
  */
void stmpe1600_IO_Config(uint16_t DeviceAddr, uint16_t IO_Pin, IO_ModeTypedef IO_Mode)
{
    uint8_t buffer[2] = {0,0};  
    
  /* Configure IO pin according to selected IO mode */
  switch(IO_Mode)
  {
  case IO_MODE_INPUT: /* Input mode */
    stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin);
    stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
    break;
    
  case IO_MODE_OUTPUT: /* Output mode */
    stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin);
    stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_OUT);
    break;
  
  case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */
    stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_HIGH);
    stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin);
    stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN); 
    /* Clear all IO IT pending bits if any */
    stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin);
    
    /* Read GMPR to enable interrupt */
    IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2);
    break; 
    
  case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */
    stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_LOW);
    stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin);
    stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN); 
    
    /* Clear all IO IT pending bits if any */
    stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin);
    
    /* Read GMPR to enable interrupt */
    IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2);    
    break;

  default:
	break;
  } 
}
/**
  * @brief  Detect an IT pending bit from the selected IO pin(s).
  *         (clears all the pending bits if any).
  * @param  DeviceAddr: Device address on communication Bus.  
  * @param  IO_Pin: IO pin(s) to be checked.  
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15.           
  * @retval IT pending bit detection status.
  */
uint8_t stmpe1600_IO_ReadIT(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
  
  /* Return if there is an IT pending bit or not */
  return(tmp & IO_Pin);
}
/**
  * @brief  Read the IT status of the selected IO pin(s)
  *         (clears all the pending bits if any). 
  * @param  DeviceAddr: Device address on communication Bus.  
  * @param  IO_Pin: IO pin(s) to be checked.  
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15.           
  * @retval IT Status of the selected IO pin(s).
  */
uint8_t stmpe1600_IO_ITStatus(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
  
  /* Return the pin IT status */
  return((tmp & IO_Pin) == IO_Pin);  
}
/**
  * @brief  Read the state of the selected IO pin(s).
  * @param  DeviceAddr: Device address on communication Bus. 
  * @param  IO_Pin: IO pin(s) to be read.  
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15.
  * @retval State of the selected IO pin(s).
  */
uint16_t stmpe1600_IO_ReadPin(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
  
  /* Return the pin(s) state */
  return(tmp & IO_Pin);  
}
/**
  * @brief  Read the stmpe1600 device ID.
  * @param  DeviceAddr: Device address on communication Bus.  
  * @retval The Device ID (two bytes).
  */
uint16_t stmpe1600_ReadID(uint16_t DeviceAddr)
{
  uint8_t tmpData[2] = {0 , 0};

  /* Initialize IO BUS layer */
  IOE_Init(); 
  
  /* Read the stmpe1600 device ID */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_CHP_ID, tmpData, 2);
  
  /* Return the device ID value */
  return((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
}
/**
  * @brief  Return if there is touch detected or not.
  * @param  DeviceAddr: Device address on communication Bus.
  * @retval Touch detected state.
  */
uint8_t exc7200_TS_DetectTouch(uint16_t DeviceAddr)
{
  /* Read TS data : Send I2C Slave address + 1 Bit0=1 for:read */
  IOE_ReadMultiple(DeviceAddr | 1, EXC7200_READ_CMD, aBufferTS, 10);

  /* check for first byte */
  if (aBufferTS[1]==0x83)
  {
    return 1;
  }

  return 0;
}
/**
  * @brief  Disable the interrupt mode for the selected IO pin(s).
  * @param  DeviceAddr: Device address on communication Bus.    
  * @param  IO_Pin: IO pin(s) to be configured.  
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15. 
  * @retval None
  */
void stmpe1600_IO_DisablePinIT(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the current register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));  
  
  /* Disable the IT pin mode */
  tmp &= ~(uint16_t)IO_Pin;
    
  /* Set the new register value */
  IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2); 
}
/**
  * @brief  Disable polarity inversion of the selected IO pins.
  * @param  DeviceAddr: Device address on communication Bus.    
  * @param  IO_Pin: IO pin(s) to be configured. 
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15.
  * @retval None
  */ 
void stmpe1600_IO_PolarityInv_Disable(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the current register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));  

  /* Disable pin polarity inversion */
   tmp &= ~ (uint16_t)IO_Pin;
    
  /* Set the new register value */  
  IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2);  
}
Beispiel #10
0
/**
  * @brief  Disable the Global interrupt.
  * @param  DeviceAddr: Device address on communication Bus.        
  * @retval None
  */
void stmpe1600_DisableGlobalIT(uint16_t DeviceAddr)
{ 
  uint8_t tmpData[2] = {0 , 0};

  /* Get the current register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
  
  /* Set the global interrupts to be Enabled */    
  tmp &= ~(uint16_t)STMPE1600_IT_ENABLE;
  
  /* Write Back the Interrupt Control register */
  IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2); 
}
Beispiel #11
0
/**
  * @brief  Get the touch screen X and Y positions values
  * @param  DeviceAddr: Device address on communication Bus.
  * @param  X: Pointer to X position value
  * @param  Y: Pointer to Y position value   
  * @retval None.
  */
void ts3510_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
{
  uint8_t aBufferTS[11];
  uint8_t aTmpBuffer[2] = {TS3510_READ_CMD, TS3510_WRITE_CMD};
  
  /* Prepare for LCD read data */
  IOE_WriteMultiple(DeviceAddr, TS3510_SEND_CMD_REG, aTmpBuffer, 2);

  /* Read TS data from LCD */
  IOE_ReadMultiple(DeviceAddr, TS3510_READ_BLOCK_REG, aBufferTS, 11);  

  /* Calculate positions */
  *X = (((aBufferTS[1] << 8) | aBufferTS[2]) << 12) / 640;
  *Y = (((aBufferTS[3] << 8) | aBufferTS[4]) << 12) / 480;
  
  /* set position to be relative to 12bits resolution */
}
Beispiel #12
0
/**
  * @brief  Enable the interrupt mode for the selected IO pin(s).
  * @param  DeviceAddr: Device address on communication Bus.     
  * @param  IO_Pin: IO pin(s) to be configured.  
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15. 
  * @retval None
  */
void stmpe1600_IO_EnablePinIT(uint16_t DeviceAddr, uint16_t IO_Pin)
{
  uint8_t tmpData[2] = {0 , 0};
    
  /* Enable global interrupt */
  stmpe1600_EnableGlobalIT(DeviceAddr);

  /* Get the current register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));  
  
  /* Put pin in IT mode */
  tmp |= (uint16_t)IO_Pin;
    
  /* Write the new register value */
  IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2);
}
Beispiel #13
0
/**
  * @brief  Return if there is touch detected or not.
  * @param  DeviceAddr: Device address on communication Bus.
  * @retval Touch detected state.
  */
uint8_t ts3510_TS_DetectTouch(uint16_t DeviceAddr)
{
  uint8_t aBufferTS[11];
  uint8_t aTmpBuffer[2] = {TS3510_READ_CMD, TS3510_WRITE_CMD};
   
  /* Prepare for LCD read data */
  IOE_WriteMultiple(DeviceAddr, TS3510_SEND_CMD_REG, aTmpBuffer, 2);

  /* Read TS data from LCD */
  IOE_ReadMultiple(DeviceAddr, TS3510_READ_BLOCK_REG, aBufferTS, 11);  

  /* check for first byte */
  if((aBufferTS[1] == 0xFF) && (aBufferTS[2] == 0xFF) && (aBufferTS[3] == 0xFF) && (aBufferTS[4] == 0xFF))
  {
    return 0;
  }
  else
  {
    return 1;
  }
}
Beispiel #14
0
/**
  * @brief  Set the value of the selected IO pins.
  * @param  DeviceAddr: Device address on communication Bus.  
  * @param  IO_Pin: IO pin(s) to be set.
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15.
  * @param  PinState: The value to be set. 
  * @retval None
  */
void stmpe1600_IO_WritePin(uint16_t DeviceAddr, uint16_t IO_Pin, uint8_t PinState)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the current register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2);
  
  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));  
  
  /* Set the pin state */
  if(PinState != 0)
  {
    tmp |= (uint16_t)IO_Pin;
  }  
  else 
  {
    tmp &= ~(uint16_t)IO_Pin;
  }
    
  /* Set the new register value */  
  IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPSR, (uint8_t *)&tmp, 2);
}
Beispiel #15
0
/**
  * @brief  Initialize the selected pin(s) direction.
  * @param  DeviceAddr: Device address on communication Bus.   
  * @param  IO_Pin: IO pin(s) to be configured. 
  *         This parameter could be any combination of the following values:
  *   @arg  STMPE1600_PIN_x: where x can be from 0 to 15.  
  * @param  Direction: could be STMPE1600_DIRECTION_IN or STMPE1600_DIRECTION_OUT.      
  * @retval None
  */
void stmpe1600_IO_InitPin(uint16_t DeviceAddr, uint16_t IO_Pin, uint8_t Direction)
{
  uint8_t tmpData[2] = {0 , 0};
  
  /* Get the current register value */
  IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPDR, tmpData, 2);

  tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
  
  /* Set the Pin direction */
  if (Direction != STMPE1600_DIRECTION_IN)
  {
    tmp |= (uint16_t)IO_Pin;
  }  
  else 
  {
    tmp &= ~(uint16_t)IO_Pin;
  }
    
  /* Set the new register value */
  IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPDR, (uint8_t *)&tmp, 2);      
}