Esempio n. 1
0
/**
  * @brief  Configures The selected IOs in interrupt mode.
  * @param  IOE16_ITSRC_Source: the source of the interrupts. Could be one or a 
  *         combination of IT pins.
  * @retval IOE16_OK: if configuration is OK. Other value if error.
  */
uint8_t IOE16_ITConfig(uint32_t IOE16_ITSRC_Source)
{   
	
  /* Configure the Interrupt output pin to generate low level */
  IOE16_ITOutConfig(IOE16_Polarity_Low);     
   
  /* Enable the Global interrupt */  
  IOE16_GITCmd(ENABLE);  

  /* Put IO pins in input mode */
  IOE16_IOPinConfig(IOE16_ITSRC_Source, Direction_IN);
	
  /* Read the GPIO interrupt status to clear all pending bits if any */
  IOE16_I2C_ReadDeviceRegister(IOE16_REG_ISGPIOR_LSB);  	
  

  /* Enable the pins to generate interrupt */
  IOE16_IOITConfig(IOE16_ITSRC_Source, ENABLE);
	
	// clear interrupt status - INT_STA_LOW(0x0A), Io_Expander's INT pin output also cleared
	IOE16_I2C_ReadDeviceRegister(0x0A );	 

	/* Read IOs state to let IO interrupt occur */
  IOE16_I2C_ReadDeviceRegister(IOE16_REG_GPMR_LSB);
  IOE16_I2C_ReadDeviceRegister(IOE16_REG_GPMR_MSB);
	
 	/* Configure the Interrupt line as EXTI source */
  //phv 2102IOE16_EXTI_Config(); 
	
  /* If all OK return IOE16_OK */
  return IOE16_OK;
}
Esempio n. 2
0
/**
  * @brief  SD Card Configuration.
  * @param  None
  * @retval None
  */
static void SDCard_Config(void)
{
  uint32_t error = 0;
  uint32_t counter = 0x100;

  /* Configure the IO Expander */
  if (IOE16_Config() != IOE16_OK)
  {
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LCD_LINE_6, (uint8_t*)"    IO Expander FAILED         ");
    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t*)"    Please Reset the board and ");
    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)"    Start again...             ");
    while(1)
    {
    }
  }

  /* SDCard initialisation */
  SD_Init();

  /* Configure the SD detect pin */
  IOE16_IOPinConfig(SD_DETECT_PIN, Direction_IN);

  if (SD_Detect() == SD_NOT_PRESENT)
  {
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)"    Please insert SD Card.     ");

    while (SD_Detect() == SD_NOT_PRESENT)
    {
    }
  }

  /* FAT Initialization */
  do
  {
    /* SDCARD Initialisation */
    error = Storage_Init();
  }
  while ((error != 0) && (counter-- != 0));

  /* SD Card not formatted */
  if (counter == 0)
  {
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t*)"    SD Card not formatted.  ");
    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)"    Reprogram your card.    ");
    while (1)
    {
    }
  }
}
Esempio n. 3
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main.
     */     

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
         
  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Select the Button test mode (polling or interrupt) BUTTON_MODE in main.h */
  STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE);
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE);

  /* Initialize the LCD */
  LCD_Init();

  /* Initialize the LCD Layers */
  LCD_LayerInit();  
  
  /* Enable LCD display */
  LCD_DisplayOn();
  
  /* Set foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
  
  /* Clear the LCD */ 
  LCD_Clear(White);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);    
 
  LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)"        STM324x9I-EVAL       ");
  LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)"      Example on how to      ");
  LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)"     use the IO Expander     ");
  
  /* Configure the IO Expander */
  if (IOE_Config() == IOE_OK && IOE16_Config() == IOE16_OK)
  {
    LCD_DisplayStringLine(LCD_LINE_3, (uint8_t *)"      IO Expander OK       ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"IO Expander FAILED    ");
    LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)" Please Reset the     ");
    LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *)"   board and start    ");
    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"    again             ");
    while(1);
  }

  /* LEDs Control blocks */
  LCD_SetTextColor(Blue);
  LCD_DrawRect(310, 180,  40, 60);
  LCD_SetTextColor(Red);
  LCD_DrawRect(230, 180, 40, 60);
  LCD_SetTextColor(Yellow);
  LCD_DrawRect(150, 180, 40, 60);
  LCD_SetTextColor(Green);
  LCD_DrawRect(70, 180, 40, 60);

#ifdef IOE_INTERRUPT_MODE
  /* Configure motherboard interrupt source IO_EXP4 */ 
  IOE16_IOPinConfig(IOE16_TS_IT,Direction_IN);
  IOE16_ITConfig(IOE16_TS_IT);
  
  /* Enable joystick interrupt */
  IOE16_ITConfig(JOY_IO16_PINS);
  
  /* Enable the Touch Screen interrupt */
  IOE_TSITConfig(); 
  
  /* Read IOs state to let IO interrupt occur */
  IOE16_I2C_ReadDeviceRegister(IOE16_REG_GPMR_LSB);
  IOE16_I2C_ReadDeviceRegister(IOE16_REG_GPMR_MSB);
#endif /* IOE_INTERRUPT_MODE */
  
  
  while(1)
  {
#ifdef IOE_POLLING_MODE
    static JOY_State_TypeDef JoyState = JOY_NONE;
    static TS_STATE* TS_State;
    
    /* Get the Joystick State */
    JoyState = IOE16_JoyStickGetState();
    
    /* Set the LCD Text Color */
    LCD_SetTextColor(Blue); 
   
    switch (JoyState)
    {
      case JOY_NONE:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:     ----        ");
        break;
      case JOY_UP:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:     UP         ");
        break;     
      case JOY_DOWN:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:    DOWN        ");
        break;          
      case JOY_LEFT:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:    LEFT        ");
        break;         
      case JOY_RIGHT:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:    RIGHT        ");
        break;                 
      case JOY_CENTER:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:   CENTER       ");
        break; 
      default:
        LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY:   ERROR      ");
        break;         
    }

    /* Update the structure with the current position */
    TS_State = IOE_TS_GetState();  
    
    if ((TS_State->TouchDetected) && (TS_State->Y < 92) && (TS_State->Y > 52))
    {
      if ((TS_State->X > 60) && (TS_State->X < 120))
      {
        LCD_SetTextColor(LCD_COLOR_GREEN);   
        LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)"     LD1                ");
        STM_EVAL_LEDOn(LED1);
      }
      else if ((TS_State->X > 140) && (TS_State->X < 200))
      {
        LCD_SetTextColor(LCD_COLOR_YELLOW); 
        LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)"          LD2           ");
        STM_EVAL_LEDOn(LED2);
      }
      else if ((TS_State->X > 220) && (TS_State->X < 280))
      {
        LCD_SetTextColor(LCD_COLOR_RED); 
        LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)"               LD3      ");
        STM_EVAL_LEDOn(LED3);
      }     
      else if ((TS_State->X > 300) && (TS_State->X < 360))
      {
        LCD_SetTextColor(LCD_COLOR_BLUE); 
        LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)"                    LD4 ");
        STM_EVAL_LEDOn(LED4);
      }
    }
    else
    {
      STM_EVAL_LEDOff(LED1);
      STM_EVAL_LEDOff(LED2);
      STM_EVAL_LEDOff(LED3);
      STM_EVAL_LEDOff(LED4);
    }
#endif /* IOE_POLLING_MODE */  
    
#ifdef BUTTON_POLLING_MODE
    /* Insert 10 ms delay */
    Delay(1);
    
    /* Set the LCD Text Color */
    LCD_SetTextColor(Blue); 

    if (STM_EVAL_PBGetState(BUTTON_TAMPER) == 0)
    {
      /* Toggle LD2 */
      STM_EVAL_LEDToggle(LED2);

      LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"Pol: TAMPER/KEY Pressed  ");
    }

    if (STM_EVAL_PBGetState(BUTTON_WAKEUP) != 0)
    {
      /* Toggle LD3 */
      STM_EVAL_LEDToggle(LED3);
      LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"Pol: WAKEUP Pressed      ");
    }
#endif
  }
}