void r3dfb_swap_buffers(void) { uint32_t tmp = r3dfb_front_buffer; r3dfb_front_buffer = r3dfb_back_buffer; r3dfb_back_buffer = tmp; // hack for font rendering LCD_SetLayer(r3dfb_back_buffer == R3DFB_BUFFER0 ? LCD_BACKGROUND_LAYER : LCD_FOREGROUND_LAYER); LTDC_Cmd(DISABLE); LTDC_LayerAddress(LTDC_Layer1, r3dfb_front_buffer); LTDC_ReloadConfig(LTDC_IMReload); LTDC_Cmd(ENABLE); }
/* ****************************************************************************** *函数:void LCD_DisplayOff(void) *输入:void *输出:void *描述:LCD显示关闭,失能背光,失能电源 ****************************************************************************** */ void LCD_DisplayOff(void) { /* Enable LCD Backlight */ GPIO_ResetBits(GPIOG, GPIO_Pin_13); /* Display Off */ LTDC_Cmd(DISABLE); }
void r3dfb_init(void) { LCD_Init(); LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; LTDC_Layer_InitStruct.LTDC_HorizontalStop = (R3DFB_PIXEL_WIDTH + 30 - 1); LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; LTDC_Layer_InitStruct.LTDC_VerticalStop = (R3DFB_PIXEL_HEIGHT + 4 - 1); LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0; LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((R3DFB_PIXEL_WIDTH * 2) + 3); LTDC_Layer_InitStruct.LTDC_CFBPitch = (R3DFB_PIXEL_WIDTH * 2); LTDC_Layer_InitStruct.LTDC_CFBLineNumber = R3DFB_PIXEL_HEIGHT; LTDC_Layer_InitStruct.LTDC_CFBStartAdress = r3dfb_front_buffer; LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct); LTDC_LayerCmd(LTDC_Layer1, ENABLE); LTDC_LayerCmd(LTDC_Layer2, DISABLE); LTDC_ReloadConfig(LTDC_IMReload); LTDC_Cmd(ENABLE); }
/* * Main function: initializes all system values and components, then starts * operation of the two threads. * * @author HP Truong, Jacob Barnett * * @param void * @return void */ int main (void) { CC2500_LowLevel_Init(); CC2500_Reset(); osKernelInitialize (); // initialize CMSIS-RTOS // initialize peripherals here /* LCD initiatization */ LCD_Init(); /* LCD Layer initiatization */ LCD_LayerInit(); /* Enable the LTDC controler */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer as the current layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); LCD_SetFont(&Font16x24); LCD_Clear(LCD_COLOR_WHITE); receive_and_plot_thread = osThreadCreate(osThread(receive_and_plot), NULL); print_lcd_debug_thread = osThreadCreate(osThread(print_lcd_debug), NULL); osKernelStart (); // start thread execution }
int main(void) { LCD_Init(); LCD_LayerInit(); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); LCD_SetTransparency(0); /* Set LCD background layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* LCD display message */ LCD_Clear(LCD_COLOR_RED); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t*)" YOU'LL "); LCD_DisplayStringLine(LCD_LINE_4,(uint8_t*)" NEVER "); LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" TAKE "); LCD_DisplayStringLine(LCD_LINE_8,(uint8_t*)" ME "); LCD_DisplayStringLine(LCD_LINE_10,(uint8_t*)" ALIVE "); 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 files (startup_stm32f429_439xx.s) before to branch to application main. */ /* Configure LCD : Configure 2 layers w/ Blending and CLUT loading for layer 1 */ LCD_Config(); /* Enable CLUT for Layer 1 */ LTDC_CLUTCmd(LTDC_Layer1, ENABLE); /* Enable Layer 1 */ LTDC_LayerCmd(LTDC_Layer1, ENABLE); /* Enable Layer 2 */ LTDC_LayerCmd(LTDC_Layer2, ENABLE); /* Reload LTDC configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable The LCD */ LTDC_Cmd(ENABLE); while (1) { } }
/* ****************************************************************************** *函数:void LCD_DisplayOn(void) *输入:void *输出:void *描述:LCD显示开启,使能背光,使能电源 ****************************************************************************** */ void LCD_DisplayOn(void) { /* Enable LCD Backlight */ GPIO_SetBits(GPIOG, GPIO_Pin_13); /* Display On */ LTDC_Cmd(ENABLE); /* display ON */ }
void ui_init() { LCD_Init(); LCD_LayerInit(); LTDC_Cmd(ENABLE); LCD_DisplayOn(); }
void LCDinit(){ LCD_Init(); LCD_LayerInit(); LCD_SetLayer(LCD_BACKGROUND_LAYER); LCD_SetTransparency(0); LCD_SetLayer(LCD_FOREGROUND_LAYER); LTDC_ReloadConfig(LTDC_IMReload); LTDC_Cmd(ENABLE); LCD_Clear(LCD_COLOR_BLACK); }
/*===========================================================================*/ static inline void init_board(GDisplay *g) { g->board = 0; /* Init LCD and LTCD. Enable layer1 only. */ LCD_Init(); LCD_LayerInit(); LTDC_LayerCmd(LTDC_Layer1, ENABLE); LTDC_LayerCmd(LTDC_Layer2, DISABLE); LTDC_ReloadConfig(LTDC_IMReload); LTDC_Cmd(ENABLE); LCD_SetLayer(LCD_BACKGROUND_LAYER); }
/** * @brief Display Init (LCD) * @param None * @retval None */ static void Display_Init(void) { /* Initialize the LCD */ LCD_Init(); LCD_LayerInit(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD Background Layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* Clear the Background Layer */ LCD_Clear(LCD_COLOR_WHITE); /* Configure the transparency for background */ LCD_SetTransparency(0); /* Set LCD Foreground Layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* Configure the transparency for foreground */ LCD_SetTransparency(200); /* Clear the Foreground Layer */ LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); /* Set the LCD Text size */ LCD_SetFont(&FONTSIZE); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LINE(LINENUM), (uint8_t*)MESSAGE1); LCD_DisplayStringLine(LINE(LINENUM + 1), (uint8_t*)MESSAGE1_1); LCD_DisplayStringLine(LINE(0x17), (uint8_t*)" "); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_DisplayStringLine(LCD_LINE_0, (uint8_t*)MESSAGE2); LCD_DisplayStringLine(LCD_LINE_1, (uint8_t*)MESSAGE2_1); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(LCD_COLOR_WHITE); LCD_SetTextColor(LCD_COLOR_BLUE); }
/** * @brief Main Function * @param * @retval int 0 */ int main (void) { osKernelInitialize (); // initialize CMSIS-RTOS wireless_init(); //Initialize wireless LCD_Init(); //Initialize LCD LCD_LayerInit(); //Initialize Layer /* Enable the LTDC controler */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer as the current layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); DisplayLCD_thread = osThreadCreate(osThread(DisplayLCD), NULL); Rx_thread = osThreadCreate(osThread(RxPacket), NULL); osKernelStart(); }
void ILI9341_Configuration() { /** * @brief ILI9341 Configuration * Do not change the following except you had known all * configurations. */ LCD_Init(); LTDC_Cmd( ENABLE ); LCD_LayerInit(); LCD_SetLayer(LCD_FOREGROUND_LAYER ); LCD_Clear(LCD_COLOR_BLACK ); LCD_SetTextColor(LCD_COLOR_BLACK ); }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if(startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* Initialize the LCD */ LCD_Init(); LCD_LayerInit(); /* Set LCD background layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* Set LCD transparency */ LCD_SetTransparency(0); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* LCD Log initialization */ LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader("PDF Create"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.1.0" ); } }
void prvInit() { //LCD init LCD_Init(); IOE_Config(); LTDC_Cmd( ENABLE ); LCD_LayerInit(); LCD_SetLayer( LCD_FOREGROUND_LAYER ); LCD_Clear( LCD_COLOR_BLACK ); LCD_SetTextColor( LCD_COLOR_WHITE ); //Button STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_GPIO ); //LED STM_EVAL_LEDInit( LED3 ); }
/* * initialize both layers to full screen */ static void lcd_layer_fullscreen (void) { LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; // background layer LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; LTDC_Layer_InitStruct.LTDC_HorizontalStop = LCD_MAX_X + 30 - 1; LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; LTDC_Layer_InitStruct.LTDC_VerticalStop = LCD_MAX_Y + 4 - 1; LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 0xFF; // opaque LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0; LTDC_Layer_InitStruct.LTDC_CFBLineLength = (LCD_MAX_X * 2) + 3; LTDC_Layer_InitStruct.LTDC_CFBPitch = LCD_MAX_X * 2; LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_MAX_Y; LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER; LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; LTDC_LayerInit (LTDC_Layer1, <DC_Layer_InitStruct); // foreground layer LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER + LCD_FRAME_SIZE; LTDC_LayerInit (LTDC_Layer2, <DC_Layer_InitStruct); LTDC_ReloadConfig (LTDC_IMReload); LTDC_LayerCmd (LTDC_Layer1, ENABLE); LTDC_LayerCmd (LTDC_Layer2, ENABLE); LTDC_ReloadConfig (LTDC_IMReload); LTDC_DitherCmd (DISABLE); LTDC_Cmd (ENABLE); }
/** * @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_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize the LCD */ LCD_Init(); /* Initialize the LCD Layers*/ LCD_LayerInit(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD Background Layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* Clear the Background Layer */ LCD_Clear(LCD_COLOR_WHITE); /* Gyroscope configuration */ Demo_GyroConfig(); /* Gyroscope calibration */ Gyro_SimpleCalibration(Gyro); /* Infinite loop */ while (1) { Demo_MEMS(); } }
/** * @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_stm32f429_439xx.s) before to branch to application main. */ /* Configure LCD : Only one layer is used */ LCD_Config(); /* Enable Layer 1 */ LTDC_LayerCmd(LTDC_Layer1, ENABLE); /* Reload configuration of Layer 1 */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable The LCD */ LTDC_Cmd(ENABLE); while (1) { } }
void lcd_init(void) { LCD_Init(); LCD_LayerInit(); SysTick_init (); pushbutton_init(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); LCD_SetTransparency(0); /* Set LCD background layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* LCD display message */ LCD_Clear(LCD_COLOR_BLACK); LCD_SetBackColor(LCD_COLOR_BLACK); LCD_SetTextColor(LCD_COLOR_WHITE); }
int main(void) { LCD_Init(); LCD_LayerInit(); SysTick_init (); pushbutton_init(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); LCD_SetTransparency(0); /* Set LCD background layer */ LCD_SetLayer(LCD_BACKGROUND_LAYER); /* LCD display message */ LCD_Clear(LCD_COLOR_BLUE); LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); std::stringstream output; std::string outputstring; const char * chararray; Timer mytimerobject(12,34,56); LCD_DisplayStringLine(LCD_LINE_0,(uint8_t*)"h_da "); LCD_DisplayStringLine(LCD_LINE_1,(uint8_t*)"RZS "); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t*)"WS 15/16 "); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); // Super loop while(1) { switch(get_event()){ case TICK: if(mystate==RUNNING) systick_count++; output.str(std::string()); mytimerobject.setMin(systick_count/100/60); mytimerobject.setSec(systick_count/100); mytimerobject.setHun(systick_count/1); output << "Time " << mytimerobject.printtime(); outputstring = ""; outputstring = output.str(); chararray = ""; chararray = outputstring.c_str(); LCD_DisplayStringLine(LCD_LINE_3,(uint8_t*) chararray); LCD_ClearLine(LCD_LINE_4); break; case START_STOP: LCD_DisplayStringLine(LCD_LINE_4,(uint8_t*) "START_STOP"); if(mystate == RUNNING) { mystate = HALTED; LCD_ClearLine(LCD_LINE_5); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*) "HALTED"); } else if(mystate == HALTED) { mystate = RUNNING; LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*) "RUNNING"); } break; default: break; } } }
int main(void){ //configure push-button interrupts PB_Config(); /* LCD initiatization */ LCD_Init(); /* LCD Layer initiatization */ LCD_LayerInit(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); //======You need to develop the following functions====== //Note: these are just placeholders; function definitions are at bottom of this file //configure real-time clock RTC_Config(); //configure external push-buttons and interrupts ExtPB_Config(); ExtPBNum2(); //main program LCD_Clear(LCD_COLOR_WHITE); //line=0; //Display a string in one line, on the first line (line=0) //LCD_DisplayStringLine(LINE(line), (uint8_t *) "Init EEPROM..."); //line++; //i2c_init(); //initialize the i2c chip sEE_Init(); //LCD_DisplayStringLine(LINE(line), (uint8_t *) "done..."); //line++; //LCD_DisplayStringLine(LINE(line), (uint8_t *) "Writing..."); //line++; /* First write in the memory followed by a read of the written data --------*/ /* Write on I2C EEPROM from memLocation */ //sEE_WriteBuffer(&Tx1_Buffer, memLocation,1); /* Wait for EEPROM standby state */ //sEE_WaitEepromStandbyState(); //LCD_DisplayStringLine(LINE(line), (uint8_t *) "Reading..."); /* Read from I2C EEPROM from memLocation */ //sEE_ReadBuffer(&Rx1_Buffer, memLocation, (uint16_t *)(&NumDataRead)); //line++; //LCD_DisplayStringLine(LINE(line), (uint8_t *) "Comparing..."); //line++; //if(Tx1_Buffer== Rx1_Buffer){ //LCD_DisplayStringLine(LINE(line), (uint8_t *) "Success!"); //}else{ //LCD_DisplayStringLine(LINE(line), (uint8_t *) "Mismatch!"); //} //main loop while(1){ RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure); hours = RTC_TimeStructure.RTC_Hours; minutes = RTC_TimeStructure.RTC_Minutes; seconds = RTC_TimeStructure.RTC_Seconds; sprintf(time,"%0.2d:%0.2d:%0.2d",hours,minutes,seconds); LCD_DisplayStringLine(LINE(6), (uint8_t *) time); if(UBPressed == 1){ toBeSaved = time[7]; sEE_WriteBuffer(&toBeSaved, memLocation+1,1); sEE_WaitEepromStandbyState(); sEE_ReadBuffer(&Rx1_Buffer, memLocation+1, (uint16_t *)(&NumDataRead)); saved[0] = Rx1_Buffer; LCD_DisplayStringLine(LINE(7), (uint8_t *) saved); UBPressed = 0; PB_Config(); } if(EB1Pressed == 1 && state == 0){ state = 1; EB1Pressed = 0; ExtPB_Config(); } if(EB1Pressed == 1 && state == 1){ state = 2; EB1Pressed = 0; ExtPB_Config(); } if(EB1Pressed == 1 && state == 2){ state = 3; EB1Pressed = 0; ExtPB_Config(); } if(EB1Pressed == 1 && state == 3){ state = 0; EB1Pressed = 0; ExtPB_Config(); } if(EB2Pressed == 1 && state == 1){ RTC_TimeStructure.RTC_Hours = hours + 1; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); EB2Pressed = 0; ExtPBNum2(); } if(EB2Pressed == 1 && state == 2){ RTC_TimeStructure.RTC_Minutes = minutes + 1; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); EB2Pressed = 0; ExtPBNum2(); } if(EB2Pressed == 1 && state == 3){ RTC_TimeStructure.RTC_Seconds = seconds + 1; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); EB2Pressed = 0; ExtPBNum2(); } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { SysTick_Config(SystemCoreClock / 1000); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_ResetBits(GPIOE, GPIO_Pin_2); //start with gps off to make sure it activates when wanted GPIO_Start(); ADC_Start(); Flash_Start(); unsigned long tickey = getSysTick()+1000; GPIO_ResetBits(GPIOA, GPIO_Pin_10); //LCD Reset must be held 10us GPIO_SetBits(GPIOG, GPIO_Pin_3); //flash deselect GPIO_SetBits(GPIOC, GPIO_Pin_8); //flash #hold off, we have dedicated pins GPIO_SetBits(GPIOC, GPIO_Pin_1); //osc enable GPIO_ResetBits(GPIOC, GPIO_Pin_11); //xbee reset GPIO_SetBits(GPIOE, GPIO_Pin_6); //buck enable while(getSysTick()<tickey); GPIO_SetBits(GPIOE, GPIO_Pin_2); //gps on/off GPIO_SetBits(GPIOC, GPIO_Pin_11); //xbee reset GPIO_SetBits(GPIOA, GPIO_Pin_10); //LCD unreset UART4_Start(); UART5_Start(); MPU_Start(); //========================BUTTONS==================== InitButton(&button1, GPIOE, GPIO_Pin_4); #ifdef BOARD_V1 InitButton(&button2, GPIOE, GPIO_Pin_5); #else InitButton(&button2, GPIOA, GPIO_Pin_9); #endif //=======================END BUTTONS================== /* LCD Configuration */ LCD_Config(); /* Enable The LCD */ LTDC_Cmd(ENABLE); LCD_SetLayer(LCD_FOREGROUND_LAYER); GUI_ClearBackground(); int count = 0; delay(20000); #ifndef ORIGIN GUI_InitNode(1, 72, 83, 0xe8ec); GUI_InitNode(2, 86, 72, 0xfd20); GUI_InitNode(3, 'R', 'F', 0x001f); #endif int screencount = 0; #ifdef INSIDE origin_state.lati=KRESGE_LAT; origin_state.longi=KRESGE_LONG; origin_state.gpslock=1; #endif unsigned long tickey2 = getSysTick()+2000; //2 second counter unsigned long tickey3 = getSysTick()+4000; //4 second delay to check gps state /* Infinite loop */ while (1) { UpdateButton(&button1); UpdateButton(&button2); if( buttonRisingEdge(&button1)){//right GPIO_ToggleBits(GPIOC, GPIO_Pin_3);//yellow //UART_Transmit(&huart4, gps_init_msg, cmdData1Len, 500); origin_state.pingnum+=1; origin_state.pingactive=1; origin_state.whodunnit = origin_state.id; origin_state.pingclearedby = 0; } if(buttonRisingEdge(&button2)){//left //UART_Transmit(&huart4, gps_get_time_msg, cmdData2Len, 500); GPIO_ToggleBits(GPIOA, GPIO_Pin_2); //green if(origin_state.pingactive&&(origin_state.whodunnit != origin_state.id)){ origin_state.pingactive=0; } } if(origin_state.gpson>2 &&(getSysTick()>tickey3)){ GPIO_ResetBits(GPIOE, GPIO_Pin_2); delay(20000); GPIO_SetBits(GPIOE, GPIO_Pin_2); delay(20000); char setme[80]; sprintf(setme, "%s%c%c", gps_init_msg, 0x0D, 0x0A); UART_Transmit(UART4, setme, sizeof(setme)/sizeof(setme[0]), 5000); origin_state.gpson=0; tickey3+=4000; } if(getReset()){ NVIC_SystemReset(); } #ifdef ORIGIN // long actHeading=0; // inv_get_sensor_type_heading(&actHeading, &headingAcc, &headingTime); // degrees=((double)actHeading)/((double)65536.0); // origin_state.heading=degrees; long actHeading[3] = {0,0,0}; inv_get_sensor_type_euler(actHeading, &headingAcc, &headingTime); degrees=((double)actHeading[2])/((double)65536.0); //origin_state.heading=degrees; long tempyraiture; mpu_get_temperature(&tempyraiture, NULL); // short garbage[3]; // mpu_get_compass_reg(garbage, NULL); // double compass_angle = atan2(-garbage[0], -garbage[1])*180/3.1415; // //origin_state.heading = .9*degrees + .1*compass_angle; // origin_state.heading = compass_angle; #endif if(getSysTick()>tickey2){ tickey2 +=2000; sendMessage(); } processGPS(); processXbee(); if(getSysTick()>tickey){ tickey +=53; GPIO_ToggleBits(GPIOC, GPIO_Pin_3); #ifndef ORIGIN GUI_UpdateNode(1, degrees*3.1415/180.0+3.14*1.25, screencount, (screencount>10), 0); GUI_UpdateNode(2, degrees*3.1415/180.0+3.14, screencount, (screencount>30), 0); GUI_UpdateNode(3, degrees*3.1415/180.0+0, screencount, (screencount>50), 0); #else GUI_UpdateNodes(); #endif GUI_UpdateArrow(-degrees*3.1415/180.0); GUI_UpdateBattery(getBatteryStatus()); GUI_DrawTime(); if (count > 50){ GUI_UpdateBottomButton(1, 0xe8ec); } else { GUI_UpdateBottomButton(0, 0); } GUI_Redraw(); screencount += 1; #ifndef ORIGIN degrees += 3.6; if (screencount%100 == 0){ screencount = 0; degrees = 0; } #else if (screencount%100 == 0){ screencount = 0; } #endif } //Sensors_I2C_ReadRegister((unsigned char)0x68, (unsigned char)MPU_WHOAMI, 1, inImu); //==================================IMU================================ unsigned long sensor_timestamp; int new_data = 0; get_tick_count(×tamp); #ifdef COMPASS_ENABLED /* We're not using a data ready interrupt for the compass, so we'll * make our compass reads timer-based instead. */ if ((timestamp > hal.next_compass_ms) && !hal.lp_accel_mode && hal.new_gyro && (hal.sensors & COMPASS_ON)) { hal.next_compass_ms = timestamp + COMPASS_READ_MS; new_compass = 1; } #endif /* Temperature data doesn't need to be read with every gyro sample. * Let's make them timer-based like the compass reads. */ if (timestamp > hal.next_temp_ms) { hal.next_temp_ms = timestamp + TEMP_READ_MS; new_temp = 1; } if (hal.motion_int_mode) { /* Enable motion interrupt. */ mpu_lp_motion_interrupt(500, 1, 5); /* Notify the MPL that contiguity was broken. */ inv_accel_was_turned_off(); inv_gyro_was_turned_off(); inv_compass_was_turned_off(); inv_quaternion_sensor_was_turned_off(); /* Wait for the MPU interrupt. */ while (!hal.new_gyro) {} /* Restore the previous sensor configuration. */ mpu_lp_motion_interrupt(0, 0, 0); hal.motion_int_mode = 0; } if (!hal.sensors || !hal.new_gyro) { continue; } if (hal.new_gyro && hal.lp_accel_mode) { short accel_short[3]; long accel[3]; mpu_get_accel_reg(accel_short, &sensor_timestamp); accel[0] = (long)accel_short[0]; accel[1] = (long)accel_short[1]; accel[2] = (long)accel_short[2]; inv_build_accel(accel, 0, sensor_timestamp); new_data = 1; hal.new_gyro = 0; } else if (hal.new_gyro && hal.dmp_on) { short gyro[3], accel_short[3], sensors; unsigned char more; long accel[3], quat[4], temperature; /* This function gets new data from the FIFO when the DMP is in * use. The FIFO can contain any combination of gyro, accel, * quaternion, and gesture data. The sensors parameter tells the * caller which data fields were actually populated with new data. * For example, if sensors == (INV_XYZ_GYRO | INV_WXYZ_QUAT), then * the FIFO isn't being filled with accel data. * The driver parses the gesture data to determine if a gesture * event has occurred; on an event, the application will be notified * via a callback (assuming that a callback function was properly * registered). The more parameter is non-zero if there are * leftover packets in the FIFO. */ dmp_read_fifo(gyro, accel_short, quat, &sensor_timestamp, &sensors, &more); if (!more) hal.new_gyro = 0; if (sensors & INV_XYZ_GYRO) { /* Push the new data to the MPL. */ inv_build_gyro(gyro, sensor_timestamp); new_data = 1; if (new_temp) { new_temp = 0; /* Temperature only used for gyro temp comp. */ mpu_get_temperature(&temperature, &sensor_timestamp); inv_build_temp(temperature, sensor_timestamp); } } if (sensors & INV_XYZ_ACCEL) { accel[0] = (long)accel_short[0]; accel[1] = (long)accel_short[1]; accel[2] = (long)accel_short[2]; inv_build_accel(accel, 0, sensor_timestamp); new_data = 1; } if (sensors & INV_WXYZ_QUAT) { inv_build_quat(quat, 0, sensor_timestamp); new_data = 1; } } else if (hal.new_gyro) { short gyro[3], accel_short[3]; unsigned char sensors, more; long accel[3], temperature; /* This function gets new data from the FIFO. The FIFO can contain * gyro, accel, both, or neither. The sensors parameter tells the * caller which data fields were actually populated with new data. * For example, if sensors == INV_XYZ_GYRO, then the FIFO isn't * being filled with accel data. The more parameter is non-zero if * there are leftover packets in the FIFO. The HAL can use this * information to increase the frequency at which this function is * called. */ hal.new_gyro = 0; mpu_read_fifo(gyro, accel_short, &sensor_timestamp, &sensors, &more); if (more) hal.new_gyro = 1; if (sensors & INV_XYZ_GYRO) { /* Push the new data to the MPL. */ inv_build_gyro(gyro, sensor_timestamp); new_data = 1; if (new_temp) { new_temp = 0; /* Temperature only used for gyro temp comp. */ mpu_get_temperature(&temperature, &sensor_timestamp); inv_build_temp(temperature, sensor_timestamp); } } if (sensors & INV_XYZ_ACCEL) { accel[0] = (long)accel_short[0]; accel[1] = (long)accel_short[1]; accel[2] = (long)accel_short[2]; inv_build_accel(accel, 0, sensor_timestamp); new_data = 1; } } #ifdef COMPASS_ENABLED if (new_compass) { short compass_short[3]; long compass[3]; new_compass = 0; /* For any MPU device with an AKM on the auxiliary I2C bus, the raw * magnetometer registers are copied to special gyro registers. */ if (!mpu_get_compass_reg(compass_short, &sensor_timestamp)) { compass[0] = (long)compass_short[0]; compass[1] = (long)compass_short[1]; compass[2] = (long)compass_short[2]; /* NOTE: If using a third-party compass calibration library, * pass in the compass data in uT * 2^16 and set the second * parameter to INV_CALIBRATED | acc, where acc is the * accuracy from 0 to 3. */ inv_build_compass(compass, 0, sensor_timestamp); } new_data = 1; } #endif if (new_data) { inv_execute_on_data(); /* This function reads bias-compensated sensor data and sensor * fusion outputs from the MPL. The outputs are formatted as seen * in eMPL_outputs.c. This function only needs to be called at the * rate requested by the host. */ read_from_mpl(); } //========================================IMU================================== } }
/** * @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_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* LCD initiatization */ LCD_Init(); LCD_LayerInit(); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* Initialize LEDs mounted on STM32F429I-DISCO */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize User Button mounted on STM32F429I-DISCO */ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* Display tset name on LCD */ LCD_Clear(LCD_COLOR_WHITE); LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_4,(uint8_t*)" Flash Write "); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*)"protection test"); LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)" Press User "); LCD_DisplayStringLine(LCD_LINE_8,(uint8_t*)" push-button "); while (1) { /* Wait for User push-button is pressed */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET) { } /* Wait for User push-button is released */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET) { } /* Get FLASH_WRP_SECTORS write protection status */ SectorsWRPStatus = FLASH_OB_GetWRP() & FLASH_WRP_SECTORS; if (SectorsWRPStatus == 0x00) { /* If FLASH_WRP_SECTORS are write protected, disable the write protection */ /* Enable the Flash option control register access */ FLASH_OB_Unlock(); /* Disable FLASH_WRP_SECTORS write protection */ FLASH_OB_WRPConfig(FLASH_WRP_SECTORS, DISABLE); /* Start the Option Bytes programming process */ if (FLASH_OB_Launch() != FLASH_COMPLETE) { /* User can add here some code to deal with this error */ while (1) { } } /* Disable the Flash option control register access (recommended to protect the option Bytes against possible unwanted operations) */ FLASH_OB_Lock(); /* Get FLASH_WRP_SECTORS write protection status */ SectorsWRPStatus = FLASH_OB_GetWRP() & FLASH_WRP_SECTORS; /* Check if FLASH_WRP_SECTORS write protection is disabled */ if (SectorsWRPStatus == FLASH_WRP_SECTORS) { LCD_Clear(LCD_COLOR_GREEN); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*)" Write "); LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" protection is "); LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)" disabled "); } else { LCD_Clear(LCD_COLOR_RED); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*)" Write "); LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" protection is "); LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)" not disabled "); } } else { /* If FLASH_WRP_SECTORS are not write protected, enable the write protection */ /* Enable the Flash option control register access */ FLASH_OB_Unlock(); /* Enable FLASH_WRP_SECTORS write protection */ FLASH_OB_WRPConfig(FLASH_WRP_SECTORS, ENABLE); /* Start the Option Bytes programming process */ if (FLASH_OB_Launch() != FLASH_COMPLETE) { /* User can add here some code to deal with this error */ while (1) { } } /* Disable the Flash option control register access (recommended to protect the option Bytes against possible unwanted operations) */ FLASH_OB_Lock(); /* Get FLASH_WRP_SECTORS write protection status */ SectorsWRPStatus = FLASH_OB_GetWRP() & FLASH_WRP_SECTORS; /* Check if FLASH_WRP_SECTORS are write protected */ if (SectorsWRPStatus == 0x00) { LCD_Clear(LCD_COLOR_GREEN); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*)" Write "); LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" protection is "); LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)" enabled "); } else { LCD_Clear(LCD_COLOR_RED); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*)" Write "); LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" protection is "); LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)" not enabled "); } } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint16_t linenum = 0; static TP_STATE* TP_State; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* LCD initialization */ LCD_Init(); /* LCD Layer initialization */ LCD_LayerInit(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* Touch Panel configuration */ TP_Config(); while (1) { TP_State = IOE_TP_GetState(); if((TP_State->TouchDetected) && ((TP_State->Y < 245) && (TP_State->Y >= 3))) { if((TP_State->X >= 237) || (TP_State->X < 3)) {} else { LCD_DrawFullCircle(TP_State->X, TP_State->Y, 3); } } else if ((TP_State->TouchDetected) && (TP_State->Y <= 280) && (TP_State->Y >= 250) && (TP_State->X >= 5) && (TP_State->X <= 35)) { LCD_SetTextColor(LCD_COLOR_BLUE2); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 280) && (TP_State->Y >= 250) && (TP_State->X >= 40) && (TP_State->X <= 70)) { LCD_SetTextColor(LCD_COLOR_CYAN); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 280) && (TP_State->Y >= 250) && (TP_State->X >= 75) && (TP_State->X <= 105)) { LCD_SetTextColor(LCD_COLOR_YELLOW); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 318) && (TP_State->Y >= 288) && (TP_State->X >= 5) && (TP_State->X <= 35)) { LCD_SetTextColor(LCD_COLOR_RED); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 318) && (TP_State->Y >= 288) && (TP_State->X >= 40) && (TP_State->X <= 70)) { LCD_SetTextColor(LCD_COLOR_BLUE); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 318) && (TP_State->Y >= 288) && (TP_State->X >= 75) && (TP_State->X <= 105)) { LCD_SetTextColor(LCD_COLOR_GREEN); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 318) && (TP_State->Y >= 288) && (TP_State->X >= 110) && (TP_State->X <= 140)) { LCD_SetTextColor(LCD_COLOR_BLACK); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 318) && (TP_State->Y >= 288) && (TP_State->X >= 145) && (TP_State->X <= 175)) { LCD_SetTextColor(LCD_COLOR_MAGENTA); } else if ((TP_State->TouchDetected) && (TP_State->Y <= 318) && (TP_State->Y >= 270) && (TP_State->X >= 180) && (TP_State->X <= 230)) { LCD_SetFont(&Font8x8); for(linenum = 0; linenum < 31; linenum++) { LCD_ClearLine(LINE(linenum)); } } else { } } }
LCDTFTConf::LCDTFTConf() { CurrentFrameBuffer = LCD_FRAME_BUFFER; CurrentLayer = LCD_BACKGROUND_LAYER; LTDC_InitTypeDef LTDC_InitStruct; /* Configure the LCD Control pins ------------------------------------------*/ LCD_CtrlLinesConfig(); LCD_ChipSelect(DISABLE); LCD_ChipSelect(ENABLE); /* Configure the LCD_SPI interface -----------------------------------------*/ LCD_SPIConfig(); /* Power on the LCD --------------------------------------------------------*/ LCD_PowerOn(); /* Enable the LTDC Clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE); /* Enable the DMA2D Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE); /* Configure the LCD Control pins */ LCD_AF_GPIOConfig(); /* Configure the FMC Parallel interface : SDRAM is used as Frame Buffer for LCD */ SDRAM_Init(); /* LTDC Configuration *********************************************************/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL; /* Initialize the vertical synchronization polarity as active low */ LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL; /* Initialize the data enable polarity as active low */ LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL; /* Initialize the pixel clock polarity as input pixel clock */ LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC; /* Configure R,G,B component values for LCD background color */ LTDC_InitStruct.LTDC_BackgroundRedValue = 0; LTDC_InitStruct.LTDC_BackgroundGreenValue = 0; LTDC_InitStruct.LTDC_BackgroundBlueValue = 0; /* Configure PLLSAI prescalers for LCD */ /* Enable Pixel Clock */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/4 = 48 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 48/8 = 6 Mhz */ RCC_PLLSAIConfig(192, 7, 4); RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8); /* Enable PLLSAI Clock */ RCC_PLLSAICmd(ENABLE); /* Wait for PLLSAI activation */ while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET); /* Timing configuration */ /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = 9; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = 1; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = 29; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = 3; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = 269; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = 323; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = 279; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = 327; LTDC_Init(<DC_InitStruct); LCD_LayerInit(); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); }
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_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ //initiate user button PB_Config(); //initiate LEDs and turn them on LED_Config(); /* ----------------------------------------------------------------------- TIM3 Configuration: Output Compare Timing Mode: In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1. TIM3CLK = 2 * PCLK1 PCLK1 = HCLK / 4 => TIM3CLK = HCLK / 2 = SystemCoreClock /2 To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows: Prescaler = (TIM3CLK / TIM3 counter clock) - 1 Prescaler = ((SystemCoreClock /2) /0.5 MHz) - 1 CC1 update rate = TIM3 counter clock / CCR1_Val = 10.0 Hz ==> Toggling frequency = 5 Hz Note: SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() function to update SystemCoreClock variable value. Otherwise, any configuration based on this variable will be incorrect. ----------------------------------------------------------------------- */ //=======================Configure and init Timer====================== /* Compute the prescaler value */ PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1; /* TIM Configuration */ TIM3_Config(); // configure the output compare TIM3_OCConfig(); /* TIM Interrupts enable */ TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); /* TIM3 enable counter */ TIM_Cmd(TIM3, ENABLE); //======================================configure and init LCD ====================== /* LCD initiatization */ LCD_Init(); /* LCD Layer initiatization */ LCD_LayerInit(); /* Enable the LTDC */ LTDC_Cmd(ENABLE); /* Set LCD foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); //================EEPROM init==================================== /* Unlock the Flash Program Erase controller */ FLASH_Unlock(); /* EEPROM Init */ EE_Init(); //============ Set up for random number generation============== RNG_Config(); //with the default font, LCD can display 12 lines of chars, they are LINE(0), LINE(1)...LINE(11) //with the default font, LCD can display 15 columns, they are COLUMN(0)....COLUMN(14) LCD_Clear(LCD_COLOR_WHITE); LCD_DisplayStringLine(LINE(0), (uint8_t *) "Attempt"); LCD_DisplayStringLine(LINE(2), (uint8_t *) "Record"); EE_WriteVariable(VirtAddVarTab[0],VarValue); EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]); sprintf(str, "%d", VarDataTab[0]); //LCD_DisplayStringLine(LINE(3), (uint8_t *) str); //randomNumber = RNG_GetRandomNumber()/100000; //sprintf(str, "%d", randomNumber()); //LCD_DisplayStringLine(LINE(5), (uint8_t *) str); resetTimer(); /*the following while loop is where the main part of the code is * it currently uses the userbutton on board since Mario forgot to bring along his * jumper cables to test out the push button part */ //if toggle = 0 lights are blinking //if toggle = 1 2 second wait //if toggle = 2 LED toggle off, the lights stay on //@TODO add external push button to code externalButton(); while (1){ int num = TIM_GetCounter(TIM3); //This is for the start of the procedure if(toggle==0){ if(num == 3000){ STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } else if(num == 6000){ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); resetTimer(); } } //if the user button has been pressed and the lights are blinking if (UBPressed==1 && toggle==0) { STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); UBPressed=0; PB_Config(); resetTimerLong(); toggle = 1; rand = randomNumber();//generate a random number } //this is the to get the wait time for the reaction test. if(toggle==1){ if(num == rand){ //if num is equal to the ramdom gened number turn on the LEDs and reset the timer STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); resetTimerLong(); } } //this is the code for when the reaction timer has gone off if (UBPressed==1 && toggle==1) { //this if statement is to prevent cheating //if the number = 0 it means that the user cheated as someone should not be able to get 0 if(num == 0){ ExtButtonPressed=0; PB_Config(); externalButton(); resetTimer(); toggle = 0; }else{ sprintf(str, "%d", num); //this block of code writes to the LCD the lastest user reaction time. LCD_DisplayStringLine(LINE(1), (uint8_t *) " "); LCD_DisplayStringLine(LINE(1), (uint8_t *) str); EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]); //this if statement determines wheter the user has beat their best reaction time if(num < VarDataTab[0]){ VarValue = num; EE_WriteVariable(VirtAddVarTab[0],VarValue); } /*the following block of code writes to the LCD the record reaction time*/ EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]); sprintf(str, "%d", VarDataTab[0]); LCD_DisplayStringLine(LINE(3), (uint8_t *) " "); LCD_DisplayStringLine(LINE(3), (uint8_t *) str); UBPressed=0; PB_Config(); resetTimerLong(); toggle = 2; } } //the user needs to press the button to get the reaction time game going again. //to reset the reaction timer if (ExtButtonPressed==1) { ExtButtonPressed=0; PB_Config(); externalButton(); resetTimer(); toggle = 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 file (startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* User button will be used */ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* LCD Configuration */ LCD_Config(); /* Enable Layer1 */ LTDC_LayerCmd(LTDC_Layer1, ENABLE); /* Reload configuration of Layer1 */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable The LCD */ LTDC_Cmd(ENABLE); while (1) { /* Wait for User push-button is pressed */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET) { } /* Wait for User push-button is released */ while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET) { } if(ubPressedButton == PRESSED_1) { /* Set Color Keying to red (RGB = 0xFF0000) */ LCD_SetColorKeying(0xFF0000); ubPressedButton = PRESSED_2; } else if(ubPressedButton == PRESSED_2) { /* Set Color Keying to blue (RGB = 0x0000FF) */ LCD_SetColorKeying(0xFF); ubPressedButton = PRESSED_3; } else if(ubPressedButton == PRESSED_3) { /* Set Color Keying to green (RGB = 0x00FF00) */ LCD_SetColorKeying(0xFF00); ubPressedButton = PRESSED_4; } else if(ubPressedButton == PRESSED_4) { /* Set Color Keying to blue and green (RGB = 0x00FFFF) */ LCD_SetColorKeying(0xFFFF); ubPressedButton = PRESSED_5; } else if(ubPressedButton == PRESSED_5) { /* Set Color Keying to red and green (RGB = 0x00FFFF) */ LCD_SetColorKeying(0xFFFF00); ubPressedButton = PRESSED_6; } else { /* Set Color Keying to blue and red (RGB = 0x00FFFF) */ LCD_SetColorKeying(0xFF00FF); ubPressedButton = PRESSED_1; } } }
void TM_LCD_DisplayOn(void) { /* Enable LTDC peripheral */ LTDC_Cmd(ENABLE); }
void TM_ILI9341_InitLayers(void) { LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; /* Windowing configuration */ /* Horizontal start = horizontal synchronization + Horizontal back porch = 43 Vertical start = vertical synchronization + vertical back porch = 12 Horizontal stop = Horizontal start + LCD_PIXEL_WIDTH - 1 Vertical stop = Vertical start + LCD_PIXEL_HEIGHT - 1 */ LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; LTDC_Layer_InitStruct.LTDC_HorizontalStop = 269; LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; LTDC_Layer_InitStruct.LTDC_VerticalStop = 323; /* Pixel Format configuration*/ LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; /* Alpha constant (255 totally opaque) */ LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; /* Default Color configuration (configure A,R,G,B component values) */ LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0; /* Configure blending factors */ LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; /* the length of one line of pixels in bytes + 3 then : Line Lenth = Active high width x number of bytes per pixel + 3 Active high width = LCD_PIXEL_WIDTH number of bytes per pixel = 2 (pixel_format : RGB565) */ LTDC_Layer_InitStruct.LTDC_CFBLineLength = 240 * 2 + 3; /* the pitch is the increment from the start of one line of pixels to the start of the next line in bytes, then : Pitch = Active high width x number of bytes per pixel */ LTDC_Layer_InitStruct.LTDC_CFBPitch = 240 * 2; /* Configure the number of lines */ LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320; /* Start Address configuration : the LCD Frame buffer is defined on SDRAM */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = ILI9341_FRAME_BUFFER; /* Initialize Layer 1 */ LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct); /* Configure Layer2 */ /* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = ILI9341_FRAME_BUFFER + ILI9341_FRAME_OFFSET; /* Configure blending factors */ LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA; /* Initialize Layer 2 */ LTDC_LayerInit(LTDC_Layer2, <DC_Layer_InitStruct); LTDC_ReloadConfig(LTDC_IMReload); /* Enable foreground & background Layers */ LTDC_LayerCmd(LTDC_Layer1, ENABLE); LTDC_LayerCmd(LTDC_Layer2, ENABLE); LTDC_ReloadConfig(LTDC_IMReload); LTDC_DitherCmd(ENABLE); /* Display On */ LTDC_Cmd(ENABLE); LTDC_LayerAlpha(LTDC_Layer1, 255); LTDC_LayerAlpha(LTDC_Layer2, 0); LTDC_ReloadConfig(LTDC_IMReload); }
void TM_LCD_DisplayOff(void) { /* Disable LTDC peripheral */ LTDC_Cmd(DISABLE); }