/** * @brief Enable the Global interrupt. * @param DeviceAddr: Device address on communication Bus. * @retval None */ void stmpe1600_EnableGlobalIT(uint16_t DeviceAddr) { uint8_t tmpData[2] = {0 , 0}; /* Configure NVIC IT for IOE */ IOE_ITConfig(); /* 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); }
/** * @brief Initialize resources used for this demo. * @param None * @retval Digit value */ uint8_t Demo_Init(void) { __IO uint32_t tmpValue = 0; PressedKey = NOKEY; /* Configure the IO Expander */ if(IOE_Config() == IOE_OK) { LCD_DisplayStringLine(LINE(6), (uint8_t*)"IO Expander OK "); Delay(0xFF); } else { LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LINE(6), (uint8_t*)"IO Expander FAILED Please Reset the board"); while (1); } /* Enable the Joystick interrupt */ IOE_ITConfig(IOE_ITSRC_JOYSTICK); Demo_LCD_Clear(); LCD_DisplayStringLine(LINE(6), (uint8_t*)"Main Menu: "); LCD_DisplayStringLine(LINE(7), (uint8_t*)"=========="); LCD_DisplayStringLine(LINE(8), (uint8_t*)"Use UP and DOWN Buttons to Navigate"); LCD_DisplayStringLine(LINE(9), (uint8_t*)"Use SEL Button to Select Image Format"); LCD_DisplayStringLine(LINE(11), (uint8_t*)"Select the Image Format:"); Display_Menu(ValueMin, ValueMax); while (1) { /* If "UP" pushbutton is pressed */ if (PressedKey == UP) { PressedKey = NOKEY; /* Increase the value of the digit */ if (tmpValue == ValueMin) { tmpValue = ValueMax - 1; } else { tmpValue--; } /* Display new Menu */ Display_Menu(tmpValue, ValueMax); } /* If "DOWN" pushbutton is pressed */ if (PressedKey == DOWN) { PressedKey = NOKEY; /* Decrease the value of the digit */ if (tmpValue == (ValueMax - 1)) { tmpValue = ValueMin; } else { tmpValue++; } /* Display new Menu */ Display_Menu(tmpValue, ValueMax); } /* If "SEL" pushbutton is pressed */ if (PressedKey == SEL) { PressedKey = NOKEY; /* Return the digit value and exit */ return (ImageFormat_TypeDef)tmpValue; } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ #ifdef USE_STM3210C_EVAL STM3210C_LCD_Init(); #elif defined (USE_STM32100E_EVAL) STM32100E_LCD_Init(); #endif /* USE_STM3210C_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Display messages on the LCD */ LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); /* Configure the IO Expander */ if (IOE_Config() == IOE_OK) { /* Display "IO Expander OK" on the LCD */ LCD_DisplayStringLine(Line4, " IO Expander OK "); } else { LCD_DisplayStringLine(Line4, "IO Expander FAILED "); LCD_DisplayStringLine(Line5, " Please Reset the "); LCD_DisplayStringLine(Line6, " board and start "); LCD_DisplayStringLine(Line7, " again "); while(1); } /* Draw a rectangle with the specifies parameters and Blue Color */ LCD_SetTextColor(Blue); LCD_DrawRect(180, 310, 40, 60); /* Draw a rectangle with the specifies parameters and Red Color */ LCD_SetTextColor(Red); LCD_DrawRect(180, 230, 40, 60); /* Draw a rectangle with the specifies parameters and Yellow Color */ LCD_SetTextColor(Yellow); LCD_DrawRect(180, 150, 40, 60); /* Draw a rectangle with the specifies parameters and Black Color */ LCD_SetTextColor(Black); LCD_DrawRect(180, 70, 40, 60); #ifdef IOE_INTERRUPT_MODE #ifdef USE_STM32100E_EVAL /* Enable the Touch Screen interrupts */ IOE_ITConfig(IOE_ITSRC_TSC); #else /* Enable the Touch Screen and Joystick interrupts */ IOE_ITConfig(IOE_ITSRC_JOYSTICK | IOE_ITSRC_TSC); #endif /* USE_STM32100E_EVAL */ #endif /* IOE_INTERRUPT_MODE */ /* Loop infinitely */ while(1) { #ifdef IOE_POLLING_MODE static TS_STATE* TS_State; #ifdef USE_STM3210C_EVAL static JOY_State_TypeDef JoyState = JOY_NONE; /* Get the Joytick State */ JoyState = IOE_JoyStickGetState(); switch (JoyState) { /* None Joystick has been selected */ case JOY_NONE: LCD_DisplayStringLine(Line5, "JOY: ---- "); break; case JOY_UP: LCD_DisplayStringLine(Line5, "JOY: UP "); break; case JOY_DOWN: LCD_DisplayStringLine(Line5, "JOY: DOWN "); break; case JOY_LEFT: LCD_DisplayStringLine(Line5, "JOY: LEFT "); break; case JOY_RIGHT: LCD_DisplayStringLine(Line5, "JOY: RIGHT "); break; case JOY_CENTER: LCD_DisplayStringLine(Line5, "JOY: CENTER "); break; default: LCD_DisplayStringLine(Line5, "JOY: ERROR "); break; } #endif /* USE_STM3210C_EVAL */ /* Update the structure with the current position of the Touch screen */ TS_State = IOE_TS_GetState(); if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180)) { if ((TS_State->X > 10) && (TS_State->X < 70)) { /* Display LD4 on the LCD and turn on LED4 */ LCD_DisplayStringLine(Line6, " LD4 "); STM_EVAL_LEDOn(LED4); } else if ((TS_State->X > 90) && (TS_State->X < 150)) { /* Display LD3 on the LCD and turn on LED3 */ LCD_DisplayStringLine(Line6, " LD3 "); STM_EVAL_LEDOn(LED3); } else if ((TS_State->X > 170) && (TS_State->X < 230)) { /* Display LD2 on the LCD and turn on LED2 */ LCD_DisplayStringLine(Line6, " LD2 "); STM_EVAL_LEDOn(LED2); } else if ((TS_State->X > 250) && (TS_State->X < 310)) { /* Display LD1 on the LCD and turn on LED1 */ LCD_DisplayStringLine(Line6, " LD1 "); STM_EVAL_LEDOn(LED1); } } else { /* Turn off LED1..4 */ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } #endif /* IOE_POLLING_MODE */ } }
/** * @brief LCD & LEDs periodic handling * @param localtime: the current LocalTime value * @retval None */ void Display_Periodic_Handle(__IO uint32_t localtime) { /* 250 ms */ if (localtime - DisplayTimer >= LCD_TIMER_MSECS) { DisplayTimer = localtime; /* We have got a new IP address so update the display */ if (IPaddress != netif.ip_addr.addr) { __IO uint8_t iptab[4]; uint8_t iptxt[20]; /* Read the new IP address */ IPaddress = netif.ip_addr.addr; iptab[0] = (uint8_t)(IPaddress >> 24); iptab[1] = (uint8_t)(IPaddress >> 16); iptab[2] = (uint8_t)(IPaddress >> 8); iptab[3] = (uint8_t)(IPaddress); sprintf((char*)iptxt, " %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); /* Display the new IP address */ #if LWIP_DHCP if (netif.flags & NETIF_FLAG_DHCP) { /* Display the IP address */ LCD_DisplayStringLine(Line7, "IP address assigned "); LCD_DisplayStringLine(Line8, " by a DHCP server "); LCD_DisplayStringLine(Line9, iptxt); Delay(LCD_DELAY); /** Start the client/server application: only when a dynamic IP address has been obtained **/ /* Clear the LCD */ LCD_Clear(Black); LCD_SetBackColor(Black); LCD_SetTextColor(White); iptab[0] = (uint8_t)(IPaddress >> 24); iptab[1] = (uint8_t)(IPaddress >> 16); iptab[2] = (uint8_t)(IPaddress >> 8); iptab[3] = (uint8_t)(IPaddress); sprintf((char*)iptxt, "is: %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); LCD_DisplayStringLine(Line0, " You are configured "); LCD_DisplayStringLine(Line2, iptxt); if(Server) { LCD_DisplayStringLine(Line1, "as a server, your IP"); /* Initialize the server application */ server_init(); } else { LCD_DisplayStringLine(Line1, "as a client, your IP"); /* Configure the IO Expander */ IOE_Config(); /* Enable the Touch Screen and Joystick interrupts */ IOE_ITConfig(IOE_ITSRC_TSC); /* Initialize the client application */ client_init(); } }