void userTask(void *param) { NetInterface* nif = param; //Endless loop while(1) { // was DHCP succesfull and is link up? if(nif->ipv4Config.addr != 0 && nif->linkState) { STM_EVAL_LEDOn(LED4); } else { STM_EVAL_LEDOff(LED4); } //User button pressed? if(STM_EVAL_PBGetState(BUTTON_USER)) { STM_EVAL_LEDOn(LED3); //HTTP client test routine httpClientTest(); STM_EVAL_LEDOff(LED3); //Wait for the user button to be released while(STM_EVAL_PBGetState(BUTTON_USER)); } //100ms delay osDelay(100); } }
/** * @brief This function configures the system to enter Stop mode for * current consumption measurement purpose. * STOP Mode * ========= * - Regulator in LP mode * - LSI, HSI and HSE OFF * - No IWDG * - Current Consumption ~0.5uA * - Wakeup using EXTI Line (Key Button PA.00) * @param None * @retval None */ void StopMode_Measure(void) { /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); /* Disable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE); /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Initialize LED1 on STM32L152-EVAL board */ STM_EVAL_LEDInit(LED1); /* Infinite loop */ while (1) { /* Toggle The LED1 */ STM_EVAL_LEDToggle(LED1); /* Inserted Delay */ for(index = 0; index < 0x5FF; index++); } }
/** * @brief This function configures the system to enter Standby mode for * current consumption measurement purpose. * STANDBY Mode * ============ * - IWDG and LSI OFF * - Current Consumption ~0.3uA * - Wakeup using WakeUp Pin 1 (PA.00) * @param None * @retval None */ void StandbyMode_Measure(void) { /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO); /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* Clear PWR WakeUp flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Enable WKUP pin 1 */ PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE); /* Request to enter STANDBY mode */ PWR_EnterSTANDBYMode(); /* Infinite loop */ while (1) { } }
void userTask(void *param) { char_t buffer[40]; //Point to the network interface NetInterface *interface = &netInterface[0]; //Initialize LCD display lcdSetCursor(2, 0); printf("IPv4 Addr\r\n"); lcdSetCursor(5, 0); printf("Press user button\r\nto run test\r\n"); //Endless loop while(1) { //Display IPv4 host address lcdSetCursor(3, 0); printf("%-16s\r\n", ipv4AddrToString(interface->ipv4Config.addr, buffer)); //User button pressed? if(!STM_EVAL_PBGetState(BUTTON_KEY)) { //FTP client test routine ftpClientTest(); //Wait for the user button to be released while(!STM_EVAL_PBGetState(BUTTON_KEY)); } //Loop delay osDelayTask(100); } }
/** * @brief configure linear touch sensor (LTS), * Leds On corresponding to the current LTS TouchKey pointed * @param None * @retval None */ void LTS_Test(void) { while ((STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET)) { /* Execute STMTouch Driver state machine */ if (TSL_user_Action() == TSL_STATUS_OK) { ProcessSensors(); // Execute sensors related tasks } } /* Wait for User button is released */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET) {} /* Turn Off Leds */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); /* SysTick time base was modified during TLS Test, for this we reconfigure the SysTick to have a time base of 1ms */ if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } }
/** * @brief JoyState * @param None * @retval The direction value */ uint8_t JoyState(void) { /* "right" key is pressed */ if (STM_EVAL_PBGetState(Button_RIGHT)) { return JOY_RIGHT; } /* "left" key is pressed */ if (STM_EVAL_PBGetState(Button_LEFT)) { return JOY_LEFT; } /* "up" key is pressed */ if (STM_EVAL_PBGetState(Button_UP)) { return JOY_UP; } /* "down" key is pressed */ if (STM_EVAL_PBGetState(Button_DOWN)) { return JOY_DOWN; } /* No key is pressed */ else { return 0; } }
/** * @brief USB recognized as a standard mouse * cursor moving according to discovery moving * @param None * @retval None */ void USB_Demo(void) { uint8_t *buf; STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOff(LED6); while ((STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET)) { buf = USBD_HID_GetPos(); if((buf[1] != 0) ||(buf[2] != 0)) { USBD_HID_SendReport (&USB_Device_dev, buf, 4); /* Insert 50ms delay */ Delay (5); } } /* Wait for User button is released */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET) {} /* Turn Off Leds */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); }
/** * @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 file (startup_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* Initialize Leds mounted on STM32L1xx-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the KEY and SEL buttons mounted on STM32L1xx-EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* TIM configuration -------------------------------------------------------*/ TIM_Config(); while (1) { /* Wait until KEY button is pressed. */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* This instruction raises the execution priority to 0. This prevents all exceptions with configurable priority from activating, other than through the HardFault fault escalation mechanism. */ __disable_irq(); /* Turn LED4 ON */ STM_EVAL_LEDOn(LED4); /* Wait until KEY button is pressed. */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* This instruction will allow all exceptions with configurable priority to be activated. */ __enable_irq(); /* Turn LED4 OFF */ STM_EVAL_LEDOff(LED4); } }
/** * @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 file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* NVIC configuration */ NVIC_Config(); /* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Configure Push button key */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* CAN configuration */ CAN_Config(); CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE); /* turn off all leds*/ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); /* Infinite loop */ while(1) { while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED) { if(KeyNumber == 0x4) { KeyNumber = 0x00; } else { LED_Display(++KeyNumber); TxMessage.Data[0] = KeyNumber; CAN_Transmit(CANx, &TxMessage); Delay(); while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED) { } } } } }
void GAME_EventHandler1() { if( STM_EVAL_PBGetState( BUTTON_USER ) ){ player1IsReversed = 0; while( STM_EVAL_PBGetState( BUTTON_USER ) ); player1IsReversed = 1; } }
static void ButtonEventTask(void *pvParameters) { while (1) { if( STM_EVAL_PBGetState( BUTTON_USER ) ){ while( STM_EVAL_PBGetState( BUTTON_USER ) ); xSemaphoreTake(t_mutex, portMAX_DELAY); button_change_traffic = 1; xSemaphoreGive(t_mutex); } } }
/** * @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. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* NVIC configuration */ NVIC_Config(); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize Key Button mounted on EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* CAN configuration */ CAN_Config(); while(1) { while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED) { if(ubKeyNumber == 0x4) { ubKeyNumber = 0x00; } else { LED_Display(++ubKeyNumber); TxMessage.Data[0] = ubKeyNumber; CAN_Transmit(CANx, &TxMessage); /* Wait until one of the mailboxes is empty */ while((CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP0) !=RESET) || \ (CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP1) !=RESET) || \ (CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP2) !=RESET)); while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED) { } } } } }
/******************************************************************************* * Function Name : ReadKey * Description : Reads key from demoboard. * Input : None * Output : None * Return : Return RIGHT, LEFT, SEL, UP, DOWN or NOKEY *******************************************************************************/ u8 ReadKey(void) { /* "right" key is pressed */ if(STM_EVAL_PBGetState(BUTTON_RIGHT)) { return RIGHT; } /* "left" key is pressed */ if(STM_EVAL_PBGetState(BUTTON_LEFT)) { return LEFT; } /* "up" key is pressed */ if(STM_EVAL_PBGetState(BUTTON_UP)) { return UP; } /* "down" key is pressed */ if(STM_EVAL_PBGetState(BUTTON_DOWN)) { return DOWN; } /* "sel" key is pressed */ if(STM_EVAL_PBGetState(BUTTON_SEL)) { return SEL; } /* "Tamper" key is pressed */ if(!STM_EVAL_PBGetState(BUTTON_TAMPER)) { GLCD_TextSetPos(0,6); GLCD_print("TAMPER Key pressed\n"); return Tamper ; } /* "Wake up" key is pressed */ if(STM_EVAL_PBGetState(BUTTON_WAKEUP)) { GLCD_TextSetPos(0,6); GLCD_print("Wakeup Key pressed\n"); return Wakeup ; } /* "User" key is pressed */ if(!STM_EVAL_PBGetState(BUTTON_USER)) { return User ; } else { return NOKEY; } }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint32_t random32bit = 0; uint32_t counter = 0; /*!< 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. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Display init (LCD or/and USART)*/ Display_Init(); /* Key Button configuration */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* RNG configuration */ RNG_Config(); while (1) { /* Wait until Key button is pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* Loop while Key button is maintained pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } for(counter = 0; counter < 8; counter++) { /* Wait until one RNG number is ready */ while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET) { } /* Get a 32bit Random number */ random32bit = RNG_GetRandomNumber(); /* Display the Random number value on the LCD or/and USART */ Display(random32bit, counter+1); } } }
/** * @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 file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* LCD Display init */ Display_Init(); /* Key button and Tamper button configuration */ #ifdef USE_STM320518_EVAL STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); #else STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); #endif /* USE_STM320518_EVAL */ /* Configures LED1 GPIO */ STM_EVAL_LEDInit(LED1); /* Configure ADC1 */ ADC_Config(); /* Configure TIM3 */ TIM_Config(); /* Infinite loop */ while (1) { /* Press Key button for STM320518_EVAL and Tamper button for STM32072B_EVAL to get the converted data */ #ifdef USE_STM320518_EVAL while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET); #else while(STM_EVAL_PBGetState(BUTTON_TAMPER) != RESET); #endif /* USE_STM320518_EVAL */ /* Get ADC1 converted data */ ADC1ConvertedValue =ADC_GetConversionValue(ADC1); /* Compute the voltage */ ADC1ConvertedVoltage = (ADC1ConvertedValue *3300)/0xFFF; /* Display converted data on the LCD */ Display(); } }
/** * @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 file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* I2S peripheral Configuration */ I2S_Config(); /* Enable the Tamper button */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); /* Initialize the LEDs */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED1); #if defined (I2S_MASTER_TRANSMITTER) while (STM_EVAL_PBGetState(BUTTON_TAMPER) != RESET) {} /* Enable the I2S1 TX Interrupt */ SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE); /* Enable the I2S */ I2S_Cmd(SPI1, ENABLE); while(TxIdx < 32); #elif defined (I2S_SLAVE_RECEIVER) /* Enable the I2S1 RXNE Interrupt */ SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE); /* Enable the I2S */ I2S_Cmd(SPI1, ENABLE); /* Wait the end of communication */ while (RxIdx < 32); /* Check if the data transmitted from Master Board and received by Slave Board are the same */ TransferStatus = Buffercmp(I2S_Buffer_Rx, (uint16_t*)I2S_Buffer_Tx, 32); if (TransferStatus == PASSED) /* successful transfer */ { /* Green Led On */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOff(LED3); } else /* unsuccessful transfer */ { /* Red Led On */ STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOff(LED1); } #endif /* Infinite loop */ while (1) {} }
void DebounceUserButton(void) // Called by SysTick_Handler() in file stm32f4xx_it.c { bool RawState; RawState = (bool)STM_EVAL_PBGetState(BUTTON_USER); if (RawState == DebouncedKeyPress) { // Set the timer which allows a change from current state. if (DebouncedKeyPress) Count = RELEASE_MSEC / CHECK_MSEC; else Count = PRESS_MSEC / CHECK_MSEC; } else { // Key has changed - wait for new state to become stable. if (--Count == 0) { // Timer expired - accept the change. DebouncedKeyPress = RawState; Key_changed = true; Key_pressed = DebouncedKeyPress; // And reset the timer. if (DebouncedKeyPress) // rising edge { Count = RELEASE_MSEC / CHECK_MSEC; ButtonPressed_action(); } else // falling edge { Count = PRESS_MSEC / CHECK_MSEC; ButtonReleased_action(); } } } }
/** * @brief Monitor the state of the push buttons and passes messages to AppTaskUserIF() * @param p_arg Argument passed to 'App_TaskKbd()' by 'OSTaskCreate()'. * @retval None */ static void App_TaskKbd (void *p_arg) { CPU_BOOLEAN b1_prev; CPU_BOOLEAN b1; (void)p_arg; b1_prev = DEF_TRUE; while (DEF_TRUE) { b1 = STM_EVAL_PBGetState(BUTTON_USER); if ((b1 == DEF_FALSE) && (b1_prev == DEF_TRUE)) { led_dly_cout += LED_DLYCOUNT_STEP; if (led_dly_cout >= LED_DLYCOUNT_MAX) { led_dly_cout = LED_DLYCOUNT_MIN; } b1_prev = b1; } if ((b1 == DEF_TRUE) && (b1_prev==DEF_FALSE)) { b1_prev = DEF_TRUE; } OSTimeDlyHMSM(0, 0, 0, 20); } }
/** * @brief main * Main routine for IAP application * @param None * @retval int */ int main(void) { /* STM32 evalboard user initialization */ BSP_Init(); /* Flash unlock */ FLASH_If_FlashUnlock(); /* Test if User button on the Discovery kit is pressed */ if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET) { /* Check Vector Table: Test if user code is programmed starting from address "APPLICATION_ADDRESS" */ if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); Jump_To_Application(); } } /* Init Host Library */ USBH_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USB_Host, &USBH_MSC_cb, &USR_Callbacks); while (1) { /* Host Task handler */ USBH_Process(&USB_OTG_Core, &USB_Host); } }
static void prvButtonPollTask( void *pvParameters ) { long lLastState = pdTRUE; long lState; xQueueMessage xMessage; /* This tasks performs the button polling functionality as described at the top of this file. */ for( ;; ) { /* Check the button state. */ lState = STM_EVAL_PBGetState( BUTTON_UP ); if( lState != lLastState ) { /* The state has changed, send a message to the LCD task. */ xMessage.cMessageID = mainMESSAGE_BUTTON_UP; xMessage.lMessageValue = lState; lLastState = lState; xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY ); } /* Block for 10 milliseconds so this task does not utilise all the CPU time and debouncing of the button is not necessary. */ vTaskDelay( 10 / portTICK_RATE_MS ); } }
/** * @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 file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Configure Systick */ SysTick_Configuration(); /* Configures the KEY button */ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO); /* Configure LED3 */ STM_EVAL_LEDInit(LED3); while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET); /* Configure RTC clock source and prescaler */ RTC_Config(); while(1) {} }
/** * @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 file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Configure LED3 */ STM_EVAL_LEDInit(LED3); /* Configure Systick */ SysTick_Configuration(); /* Turn ON LED3 */ STM_EVAL_LEDOn(LED3); /* Configures User button */ STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_GPIO); /* Configure RTC clock source and prescaler */ RTC_Config(); /* Wait till User button is pressed */ while(STM_EVAL_PBGetState(BUTTON_USER) == RESET); /* Enter STANDBY mode, RTC Alarm within 3 second or an external RESET will wake-up the system from STANDBY */ EnterSTANDBYMode(); while(1) {} }
/** * @brief This function return whether a button has been pressed and released * @param button * @retval BUTTON_clicked or BUTTON_IDLE */ uint8_t getButtonStatus(Button_TypeDef button) { if (STM_EVAL_PBGetState(button) == 0x00) { /* Indicate button pression detected */ STM_EVAL_LEDOn(LED1); /* Wait for release */ while (STM_EVAL_PBGetState(button) == 0x00); halCommonDelayMilliseconds(50); while (STM_EVAL_PBGetState(button) == 0x00); return BUTTON_CLICKED; } else { return BUTTON_IDLE; } }
/** * @brief This function handles EXTI0_IRQ Handler. * @param None * @retval None */ void EXTI0_IRQHandler(void) { if ((EXTI_GetITStatus(USER_BUTTON_EXTI_LINE) == SET)&&(STM_EVAL_PBGetState(BUTTON_USER) != RESET)) { /* Delay */ for(i=0; i<0x7FFFF; i++); /* Wait for SEL button to be pressed */ while(STM_EVAL_PBGetState(BUTTON_USER) != RESET); /* Delay */ for(i=0; i<0x7FFFF; i++); UserButtonPressed++; if (UserButtonPressed > 0x2) UserButtonPressed = 0x1; /* Clear the EXTI line pending bit */ EXTI_ClearITPendingBit(USER_BUTTON_EXTI_LINE); } }
/** * @brief Program entry point * @param None * @retval None */ int main(void) { /* Counter for the LED toggling delay */ __IO uint32_t i = 0; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32fxxx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32fxxx.c file */ /* Configure "DFU enter" button */ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* Check if the Key push-button on Devkit407 Board is pressed */ if (STM_EVAL_PBGetState(BUTTON_USER) != 0x00) { /* Test if user code is programmed starting from address 0x800C000 */ if (((*(__IO uint32_t*)APP_DEFAULT_ADD) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (APP_DEFAULT_ADD + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) APP_DEFAULT_ADD); Jump_To_Application(); } } /* Otherwise enters DFU mode to allow user to program his application */ USBD_Init(&USB_OTG_dev, #ifdef USE_USB_OTG_HS USB_OTG_HS_CORE_ID, #else USB_OTG_FS_CORE_ID, #endif &USR_desc, &DFU_cb, &USR_cb); /* Setup SysTick Timer for 10 msec interrupts This interrupt is used to display the current state of the DFU core */ if (SysTick_Config(SystemCoreClock / 100)) { /* Capture error */ while (1); } /* Main loop */ while (1) { if (i++ == 0x100000) { STM_EVAL_LEDToggle(LED4); i = 0; } } }
void GAME_EventHandler2() { const portTickType xDelay = 100; if(STM_EVAL_PBGetState(BUTTON_USER)) { shoot=1; vTaskDelay(100); } }
/** * @brief USB already configured, connect USB cable to the Host (PC) * Green LED is On and USB is detected and recognized as a standard mouse * @param None * @retval None */ void USB_Test(void) { while ((STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET)) { STM_EVAL_LEDOn(LED5); } /* Wait for User button is released */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET) {} /* Turn Off Leds */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); }
/** * @brief Reads key from evaluationboard. * @param None * @retval Return JOY_RIGHT, JOY_LEFT, JOY_SEL, JOY_UP, JOY_DOWN or JOY_NONE */ static JOYState_TypeDef Read_Joystick(void) { /* "JOY_RIGHT" key is pressed */ if (STM_EVAL_PBGetState(BUTTON_RIGHT)) { while (STM_EVAL_PBGetState(BUTTON_RIGHT) == RESET) {} return JOY_RIGHT; } /* "JOY_LEFT" key is pressed */ if (STM_EVAL_PBGetState(BUTTON_LEFT)) { while (STM_EVAL_PBGetState(BUTTON_LEFT) == RESET) {} return JOY_LEFT; } /* "JOY_UP" key is pressed */ if (STM_EVAL_PBGetState(BUTTON_UP)) { while (STM_EVAL_PBGetState(BUTTON_UP) == RESET) {} return JOY_UP; } /* "JOY_DOWN" key is pressed */ if (STM_EVAL_PBGetState(BUTTON_DOWN)) { while (STM_EVAL_PBGetState(BUTTON_DOWN) == RESET) {} return JOY_DOWN; } /* "JOY_SEL" key is pressed */ if (STM_EVAL_PBGetState(BUTTON_SEL)) { while (STM_EVAL_PBGetState(BUTTON_SEL) == RESET) {} return JOY_SEL; } /* No key is pressed */ else { return JOY_NONE; } }
/** * @brief Reads key from demoboard. * @param None * @retval Return JOY_RIGHT, JOY_LEFT, JOY_CENTER, JOY_UP, JOY_DOWN or JOY_NONE */ JOY_State_TypeDef ReadKey(void) { #ifndef USE_STM3210C_EVAL /* "right" key is pressed */ if(!STM_EVAL_PBGetState(Button_RIGHT)) { while(STM_EVAL_PBGetState(Button_RIGHT) == Bit_RESET); return JOY_RIGHT; } /* "left" key is pressed */ if(!STM_EVAL_PBGetState(Button_LEFT)) { while(STM_EVAL_PBGetState(Button_LEFT) == Bit_RESET); return JOY_LEFT; } /* "up" key is pressed */ if(!STM_EVAL_PBGetState(Button_UP)) { while(STM_EVAL_PBGetState(Button_UP) == Bit_RESET); return JOY_UP; } /* "down" key is pressed */ if(!STM_EVAL_PBGetState(Button_DOWN)) { while(STM_EVAL_PBGetState(Button_DOWN) == Bit_RESET); return JOY_DOWN; } /* "sel" key is pressed */ if(!STM_EVAL_PBGetState(Button_SEL)) { while(STM_EVAL_PBGetState(Button_SEL) == Bit_RESET); return JOY_CENTER; } /* No key is pressed */ else { return JOY_NONE; } #else return IOE_JoyStickGetState(); #endif }
/** * called buy interrupt */ void KeyPressGpioCheck(void) { int i; if ((EXTI_GetITStatus(USER_BUTTON_EXTI_LINE) == SET)&&(STM_EVAL_PBGetState(BUTTON_USER) != RESET)) { /* Delay */ for(i=0; i<0x7FFFF; i++); /* Wait for SEL button to be reelased */ while(STM_EVAL_PBGetState(BUTTON_USER) != RESET); /* Delay */ for(i=0; i<0x7FFFF; i++); UserButtonPressed++; /* Clear the EXTI line pending bit */ EXTI_ClearITPendingBit(USER_BUTTON_EXTI_LINE); } }