/** * @brief Updates the selected color * @param None * @retval None */ static void Update_Color(void) { static uint32_t color; /* Get the current text color */ color = BSP_LCD_GetTextColor(); /* Update the selected color icon */ BSP_LCD_SetTextColor(color); BSP_LCD_FillRect(450, (BSP_LCD_GetYSize() - 50), 30, 30); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawRect(450, (BSP_LCD_GetYSize() - 50), 30, 30); BSP_LCD_SetTextColor(color); }
/** * @brief Display calibration hint * @param None * @retval None */ static void TouchscreenCalibration_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Touchscreen Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 - 27, (uint8_t *)"Before using the Touchscreen", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 - 12, (uint8_t *)"you need to calibrate it.", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 3, (uint8_t *)"Press on the black circles", CENTER_MODE); }
/** * @brief Prepares the picture to be saved in microSD. * @param None * @retval None */ static void Prepare_Picture(void) { uint32_t addrSrc = LCD_FRAME_BUFFER; uint32_t addrDst = CONVERTED_FRAME_BUFFER; static DMA2D_HandleTypeDef hdma2d_eval; uint32_t lineCnt = 0; /* Configure the DMA2D Mode, Color Mode and output offset : used to convert ARGB8888 to RGB888 */ /* used in BMP file format */ hdma2d_eval.Init.Mode = DMA2D_M2M_PFC; hdma2d_eval.Init.ColorMode = DMA2D_RGB888; /* DMA2D Output format */ hdma2d_eval.Init.OutputOffset = 0; /* Foreground Configuration */ hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF; hdma2d_eval.LayerCfg[1].InputColorMode = DMA2D_ARGB8888; /* DMA2D input format */ hdma2d_eval.LayerCfg[1].InputOffset = 70; /* skip 70 pixels on left when reading addrSrc : the left margin */ hdma2d_eval.Instance = DMA2D; /* Go to start of last drawing pad useful line from LCD frame buffer */ addrSrc += ((BSP_LCD_GetYSize() - 70 - 1) * BSP_LCD_GetXSize() * ARGB8888_BYTE_PER_PIXEL); /* Copy and Convert picture from LCD frame buffer in ARGB8888 to Converted frame buffer in * RGB888 pixel format for all the useful lines of the drawing pad */ for(lineCnt=0; lineCnt < (BSP_LCD_GetYSize() - 80); lineCnt++) { /* DMA2D Initialization */ if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK) { if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK) { if (HAL_DMA2D_Start(&hdma2d_eval, addrSrc, addrDst, (BSP_LCD_GetXSize() - 80), 1) == HAL_OK) { /* Polling For DMA transfer */ HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10); } } } /* Increment the destination address by one line RGB888 */ addrDst += ((BSP_LCD_GetXSize() - 80) * RGB888_BYTE_PER_PIXEL); /* Decrement the source address by one line */ addrSrc -= (BSP_LCD_GetXSize() * ARGB8888_BYTE_PER_PIXEL); } }
/** * @brief Updates the selected size * @param size: Size to be updated * @retval None */ static void Update_Size(uint8_t size) { static uint32_t color; /* Get the current text color */ color = BSP_LCD_GetTextColor(); /* Update the selected size icon */ BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(450, (BSP_LCD_GetYSize()-24), 20); BSP_LCD_SetTextColor(color); BSP_LCD_FillCircle(450, (BSP_LCD_GetYSize()-24), size); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawCircle(450, (BSP_LCD_GetYSize()-24), size); BSP_LCD_SetTextColor(color); }
/** * @brief LCD configuration * @param None * @retval None */ static void LCD_Config(void) { /* LCD Initialization */ /* Two layers are used in this application but not simultaneously so "LCD_MAX_PCLK" is recommended to programme the maximum PCLK = 25,16 MHz */ BSP_LCD_Init(); /* LCD Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4)); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Select the LCD Background Layer */ BSP_LCD_SelectLayer(0); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Select the LCD Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Configure the transparency for foreground and background : Increase the transparency */ BSP_LCD_SetTransparency(0, 0); BSP_LCD_SetTransparency(1, 100); }
/** * @brief Display connected devices * @param None * @retval None */ static void HdmiCec_DisplayConnectedDevices(void) { uint8_t string[50] = {0}; uint8_t i, connected_devices = 0; for (i = 0; i < 12; i++) { if (strcmp((const char*)(HDMI_CEC_Follower_String[i][1]), "0")) { connected_devices++; } } BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillRect(20, 175, BSP_LCD_GetYSize() - 40, 30); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); if (connected_devices == 0) { BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"No devices connected", LEFT_MODE); } else { sprintf((char *) string, "%d device(s) connected", connected_devices); BSP_LCD_DisplayStringAt(20, 175, string, LEFT_MODE); } }
/** * @brief LCD configuration. * @param None * @retval None */ static void LCD_Config(void) { /* LCD Initialization */ /* Two layers are used in this application simultaneously so "LCD_MIN_PCLK" is recommended to programme the PCLK at 20 MHz */ BSP_LCD_InitEx(LCD_MIN_PCLK); /* LCD Layers Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_LayerDefaultInit(1, (LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4))); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Set LCD Background Layer */ BSP_LCD_SelectLayer(0); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Configure and enable the Color Keying feature */ BSP_LCD_SetColorKeying(1, 0); /* Configure the transparency for foreground: Increase the transparency */ BSP_LCD_SetTransparency(1, 100); }
/** * @brief Display audio file and control information * @param format : structure containing informations of the audio file * @retval None */ static void AudioPlay_DisplayInfos(WAVE_FormatTypeDef * format) { uint8_t string[50] = {0}; BSP_LCD_SetTextColor(LCD_COLOR_BLACK); sprintf((char *) string, "Sampling frequency : %lu Hz", format->SampleRate); BSP_LCD_DisplayStringAt(20, 115, string, LEFT_MODE); if (format->NbrChannels == 2) { sprintf((char *) string, "Format : %d bits stereo", format->BitPerSample); BSP_LCD_DisplayStringAt(20, 130, string, LEFT_MODE); } else if (format->NbrChannels == 1) { sprintf((char *) string, "Format : %d bits mono", format->BitPerSample); BSP_LCD_DisplayStringAt(20, 130, string, LEFT_MODE); } sprintf((char *) Volume_string, " Volume : %lu%% ", uwVolume); BSP_LCD_DisplayStringAt((uint16_t)(-6), BSP_LCD_GetYSize()-60, Volume_string, RIGHT_MODE); BSP_LCD_DisplayStringAt(20, 200, (uint8_t *)"Press KEY to Pause/Resume playback", LEFT_MODE); BSP_LCD_DisplayStringAt(20, 215, (uint8_t *)"Press UP/DOWN to change Volume", LEFT_MODE); }
/** * @brief Camera line event callback when camera image rotation of 90 degrees hour * direction is required. * @param None * @retval None */ static void Camera_LineEventCallbackRotation90(void) { uint32_t LcdResX = BSP_LCD_GetXSize(); uint32_t LcdResY = BSP_LCD_GetYSize(); if (refresh_authorized) { if ((offset_lcd == 0) && (CameraResY <= LcdResX) && (CameraResX <= LcdResY)) { /* If Camera resolution is lower than LCD resolution, set display in the middle of the screen */ offset_lcd = ((((LcdResY - CameraResX) / 2) * LcdResX) /* Middle of the screen on Y axis */ - ((LcdResX - CameraResY) / 2)) /* Middle of the screen on X axis */ * sizeof(uint32_t); if ((CameraResY == CAMERA_QQVGA_RES_Y) || (CameraResIndex == CAMERA_R480x272)) { /* Add offset for QQVGA : + 40 LCD lines */ offset_lcd += 40 * LcdResX * sizeof(uint32_t); } } /* Count the number of line rotated copied to be able to stop when limit reached */ if (display_rotated_line_counter < CameraResY) { /* if number of rotated line copied is reaching horizontal resolution of display LCD : stop copying also */ if (display_rotated_line_counter < LcdResX) { /* Depending on CameraResX versus LcdResY */ /* clamp the column size copied to LcdResY if (CameraResX > LcdResY) */ if (CameraResX <= LcdResY) { ConvertCameraLineRgb565ToLcdColumnARGB8888((uint32_t *)(CAMERA_FB_START_ADDR + offset_cam), (uint32_t *)(LCD_FB_START_ADDRESS + offset_lcd), CameraResX, (LcdResX - 1)); /* lineStridePixels for DMA is always one horizontal line LCD - 1 pixels */ } else { ConvertCameraLineRgb565ToLcdColumnARGB8888((uint32_t *)(CAMERA_FB_START_ADDR + offset_cam), (uint32_t *)(LCD_FB_START_ADDRESS + offset_lcd), LcdResY, (LcdResX - 1)); /* lineStridePixels for DMA is always one horizontal line LCD - 1 pixels */ } offset_cam = offset_cam + (CameraResX * sizeof(uint16_t)); /* uint16_t : because format camera data is RGB565 */ /* offset_lcd is decremented after each line rotated copied by one pixel of the LCD buffer = 4 bytes (ARGB8888) */ /* from 'offset_lcd' pre computed in first if statement of the current function */ offset_lcd = offset_lcd - sizeof(uint32_t); /* uint32_t : because format of LCD Frame buffer is ARGB8888 */ } display_rotated_line_counter++; } else { offset_cam = 0; offset_lcd = 0; display_rotated_line_counter = 0; } } }
/** * @brief LCD configuration. * @param None * @retval None */ static void LCD_Config(void) { /* LCD Initialization */ BSP_LCD_Init(); /* LCD Layers Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_LayerDefaultInit(1, (LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4))); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Set LCD Background Layer */ BSP_LCD_SelectLayer(0); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Configure and enable the Color Keying feature */ BSP_LCD_SetColorKeying(1, 0); /* Configure the transparency for foreground: Increase the transparency */ BSP_LCD_SetTransparency(1, 100); }
/** * @brief Display TS Demo Hint for all touchscreen demos depending on passed * demoIndex in parameter. * @param demoIndex : parameter of type @ref TouchScreenDemoTypeDef * @retval None */ static void Touchscreen_SetHint_Demo(TouchScreenDemoTypeDef demoIndex) { if(demoIndex <= TOUCHSCREEN_DEMO_MAX) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Touchscreen Demo1 description */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font24); if(demoIndex == TOUCHSCREEN_DEMO_1) { BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen basic polling", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"Please use the Touchscreen to", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"activate the colored circle", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"inside the rectangle. Then press TAMPER button", CENTER_MODE); } else if (demoIndex == TOUCHSCREEN_DEMO_2) { BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen dual touch polling", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"Please press the Touchscreen to", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"activate single and", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"dual touch", CENTER_MODE); } else /* demoIndex == TOUCHSCREEN_DEMO_3 */ { BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen dual touch interrupt", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"Please press the Touchscreen to", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"activate single and", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"dual touch", CENTER_MODE); } /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 90, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize() - 100); BSP_LCD_DrawRect(11, 91, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize() - 102); } /* of if(demoIndex <= TOUCHSCREEN_DEMO_MAX) */ }
/** * @brief Draws RGB Image (16 bpp). * @param Xpos: X position in the LCD * @param Ypos: Y position in the LCD * @param Xsize: X size in the LCD * @param Ysize: Y size in the LCD * @param pdata: Pointer to the RGB Image address. * @retval None */ void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata) { SetDisplayWindow(Xpos, Ypos, Xsize, Ysize); LCD_DrawRGBImage(Xpos, Ypos, Xsize, Ysize, pdata); SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); }
/** * @brief Saves the picture in microSD. * @param None * @retval None */ void Save_Picture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten = 0; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; /* Check if the SD card is plugged in the slot */ if(BSP_SD_IsDetected() != SD_PRESENT) { Error_Handler(); } else { /* Format the string */ sprintf((char *)str, "image_%lu.bmp", counter); /*##-1- Prepare the image to be saved ####################################*/ Prepare_Picture(); /*##-2- Create and Open a new bmp file object with write access ##########*/ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'image.bmp' file Open for write Error */ Error_Handler(); } else { /*##-3- Write data to the BMP file #####################################*/ /* Write the BMP header */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader, 54, (void *)&byteswritten); /* Write the BMP file */ res2 = f_write(&MyFile, (uint32_t *)CONVERTED_FRAME_BUFFER, ((BSP_LCD_GetYSize() - 80)*(BSP_LCD_GetXSize() - 80)*2), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { /* 'image.bmp' file Write or EOF Error */ Error_Handler(); } else { /*##-4- Close the open BMP file ######################################*/ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); /* Wait for 2s */ HAL_Delay(2000); /* Select Layer 1 */ BSP_LED_Off(LED1); counter++; } } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure the system clock to 168 MHz */ SystemClock_Config(); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /*##-1- LCD Initialization #################################################*/ /* Initialize the LCD */ BSP_LCD_Init(); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Clear the LCD Background layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /*##-2- Touch screen initialization ########################################*/ Touchscreen_Calibration(); BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); /*##-3- Link the SD Card disk I/O driver ###################################*/ if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0) { /* FatFs Initialization Error */ Error_Handler(); } /* Create a FAT file system (format) on the logical drive */ f_mkfs((TCHAR const*)SDPath, 0, 0); /*##-4- Register the file system object to the FatFs module ################*/ if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK) { /* FatFs Initialization Error */ Error_Handler(); } /*##-5- Draw the menu ######################################################*/ Draw_Menu(); /* Infinite loop */ while (1) { /*##-6- Configure the touch screen and Get the position ####################*/ GetPosition(); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint32_t i; uint32_t *ptrLcd; /* Enable the CPU Cache */ CPU_CACHE_Enable(); /* STM32F7xx HAL library initialization: - Configure the Flash ART accelerator on ITCM interface - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 200 MHz */ SystemClock_Config(); /*##-1- Initialise the LCD #################################################*/ BSP_LCD_Init(); /* Init LCD screen buffer */ ptrLcd = (uint32_t*)(LCD_FRAME_BUFFER); for (i=0; i<(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()); i++) { ptrLcd[i]=0; } BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Select the LCD Foreground layer */ BSP_LCD_SelectLayer(1); /* Set active window */ BSP_LCD_SetLayerWindow(1, xoffset, yoffset, xsize, ysize); /*##-2- Camera Initialisation and start capture ############################*/ /* Initialize the Camera */ BSP_CAMERA_Init(resolution); /* Wait 1s before Camera snapshot */ HAL_Delay(1000); /* Start the Camera Capture */ BSP_CAMERA_SnapshotStart((uint8_t *)CAMERA_FRAME_BUFFER); while (1) { } }
/** * @brief Performs the TS calibration * @param None * @retval None */ void Touchscreen_Calibration (void) { uint8_t status = 0; uint8_t i = 0; TouchscreenCalibration_SetHint(); status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); if (status != TS_OK) { BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t *)"ERROR", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE); } while (1) { if (status == TS_OK) { aLogX[0] = 15; aLogY[0] = 15; aLogX[1] = BSP_LCD_GetXSize() - 15; aLogY[1] = BSP_LCD_GetYSize() - 15; for (i = 0; i < 2; i++) { GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i]); } A1 = (TUNE_FACTOR_X * ( aLogX[1] - aLogX[0]))/ ( aPhysX[1] - aPhysX[0]); B1 = (TUNE_FACTOR_X * aLogX[0]) - A1 * aPhysX[0]; A2 = (TUNE_FACTOR_Y * ( aLogY[1] - aLogY[0]))/ ( aPhysY[1] - aPhysY[0]); B2 = (TUNE_FACTOR_Y * aLogY[0]) - A2 * aPhysY[0]; if (B2 > 0) B2 = 0; Calibration_Done = 1; return; } HAL_Delay(5); } }
/** * @brief Display the application footer on the LCD screen * @param footer: pointer to the string to be displayed * @retval None */ void LCD_LOG_SetFooter(uint8_t *footer) { /* Set the LCD Font */ BSP_LCD_SetFont (&LCD_LOG_FOOTER_FONT); BSP_LCD_SetTextColor(LCD_LOG_SOLID_BACKGROUND_COLOR); BSP_LCD_FillRect(0, BSP_LCD_GetYSize() - LCD_LOG_FOOTER_FONT.Height - 4, BSP_LCD_GetXSize(), LCD_LOG_FOOTER_FONT.Height + 4); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_LOG_SOLID_TEXT_COLOR); BSP_LCD_SetBackColor(LCD_LOG_SOLID_BACKGROUND_COLOR); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - LCD_LOG_FOOTER_FONT.Height, footer, CENTER_MODE); BSP_LCD_SetBackColor(LCD_LOG_BACKGROUND_COLOR); BSP_LCD_SetTextColor(LCD_LOG_TEXT_COLOR); BSP_LCD_SetFont (&LCD_LOG_TEXT_FONT); }
/** * @brief Show LCD Features * @param feature : feature index * @retval None */ static void LCD_Show_Feature(uint8_t feature) { Point Points[]= {{20, 70}, {60, 70}, {60, 100}}; Point Points2[]= {{80, 70}, {120, 70}, {120, 100}}; BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillRect(0, 60, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()- 40); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); switch (feature) { case 0: /* Text Feature */ BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(14, 80, (uint8_t *)"Font24", LEFT_MODE); BSP_LCD_SetFont(&Font20); BSP_LCD_DisplayStringAt(0, 105, (uint8_t *)"Font20", CENTER_MODE); BSP_LCD_SetFont(&Font16); BSP_LCD_DisplayStringAt(14, 130, (uint8_t *)"Font16", RIGHT_MODE); break; case 1: /* Draw misc. Shapes part 1*/ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawRect(20, 70, 40 , 20); BSP_LCD_FillRect(70, 70, 40 , 20); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawCircle(40, 120, 20); BSP_LCD_FillCircle(90, 120, 20); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DrawLine (20, 70, 20+40 , 70+20); BSP_LCD_DrawLine (20, 70+20, 20+40 , 70); BSP_LCD_DrawHLine(20, 120, 40); BSP_LCD_DrawVLine(40, 100, 40); break; case 2: /* Draw misc. Shapes part 2*/ BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DrawPolygon(Points, 3); BSP_LCD_FillPolygon(Points2, 3); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DrawEllipse(BSP_LCD_GetXSize() - 100, 110, 20, 30); BSP_LCD_FillEllipse(BSP_LCD_GetXSize() - 40, 110, 20, 30); break; case 3: /* Draw Bitmap */ BSP_LCD_DrawBitmap(20, 70, (uint8_t *)stlogo); HAL_Delay(200); break; } }
/** * @brief Updates the selected Color and Size * @param None * @retval None */ static void Update_ColorSize(void) { static uint32_t color; /* Clear the current circle */ color = BSP_LCD_GetTextColor(); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(220, (BSP_LCD_GetYSize()-24), 10); BSP_LCD_SetTextColor(color); /* Update the selected color icon */ BSP_LCD_FillCircle(220, (BSP_LCD_GetYSize()-24), radius); /* Draw black circle */ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawCircle(220, (BSP_LCD_GetYSize() - 24), radius); BSP_LCD_SetTextColor(color); }
/** * @brief Display calibration hint * @param None * @retval None */ static void TouchscreenCalibration_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Touchscreen Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetFont(&Font20); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() / 2 - 35, (uint8_t *)"Before using the Touchscreen", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() / 2 - 15, (uint8_t *)"you need to calibrate it.", CENTER_MODE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() / 2 + 7, (uint8_t *)"WAIT until the black circle appears", CENTER_MODE); BSP_LCD_SetFont(&Font20); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() / 2 + 30, (uint8_t *)"THEN Press precisly on the black circles", CENTER_MODE); BSP_LCD_SetFont(&Font12); }
/** * @brief Frame Event callback. * @param None * @retval None */ void BSP_CAMERA_FrameEventCallback(void) { uint32_t xsizeLCD, ysizeLCD; uint32_t xsizeCamera, ysizeCamera; uint32_t xoffset, yoffset; uint32_t line, column, i, j; uint16_t *ptrCamera, *ptrCameraCrop; xsizeLCD = BSP_LCD_GetXSize(); ysizeLCD = BSP_LCD_GetYSize(); BSP_CAMERA_Suspend(); /* Display on LCD */ switch (CameraResIndex) { case CAMERA_R160x120: xsizeCamera = CAMERA_QQVGA_RES_X; ysizeCamera = CAMERA_QQVGA_RES_Y; xoffset = 80; yoffset = 105; break; case CAMERA_R320x240: default: xsizeCamera = CAMERA_QVGA_RES_X; ysizeCamera = CAMERA_QVGA_RES_Y; xoffset = 0; yoffset = 0; break; } if ((xsizeCamera > xsizeLCD) || (ysizeCamera > ysizeLCD)) { /* As the camera output resolution is greater than display resolution, a cropped image has to be generated */ ptrCamera = (uint16_t *)(CAMERA_FRAME_BUFFER); ptrCameraCrop = (uint16_t *)(CAMERA_FRAME_BUFFER_CROP); xoffset = (xsizeCamera - xsizeLCD) / 2; yoffset = (ysizeCamera - ysizeLCD) / 2; i=0; j=xoffset; for (line = 0; line < ysizeLCD; line ++) { for (column = 0; column < xsizeLCD; column ++) { ptrCameraCrop[i++] = ptrCamera[j++]; } j += xsizeCamera - xsizeLCD; } BSP_LCD_DrawRGBImage(0, 0, xsizeLCD , ysizeLCD, (uint8_t *)ptrCameraCrop); } else { BSP_LCD_DrawRGBImage(xoffset, yoffset, xsizeCamera , ysizeCamera, (uint8_t *)CAMERA_FRAME_BUFFER); } BSP_CAMERA_Resume(); }
/** * @brief Prepares the picture to be Saved in USB Disk. * @param None * @retval None */ static void Prepare_Picture(void) { static DMA2D_HandleTypeDef hdma2d_eval; uint32_t address1 = CONVERTED_FRAME_BUFFER; uint32_t address2 = LCD_FRAME_BUFFER_LAYER0; uint32_t index = 0; /* Configure the DMA2D Mode, Color Mode and output offset */ hdma2d_eval.Init.Mode = DMA2D_M2M_PFC; hdma2d_eval.Init.ColorMode = DMA2D_RGB888; hdma2d_eval.Init.OutputOffset = 0; /* Foreground Configuration */ hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF; hdma2d_eval.LayerCfg[1].InputColorMode = DMA2D_ARGB8888; hdma2d_eval.LayerCfg[1].InputOffset = 60; hdma2d_eval.Instance = DMA2D; /* Bypass the bitmap header */ address2 += ((BSP_LCD_GetXSize() * (BSP_LCD_GetYSize() - 61) + 60) * 4); /* Convert picture to RGB888 pixel format */ for(index=0; index < (BSP_LCD_GetYSize() - 60); index++) { /* DMA2D Initialization */ if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK) { if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK) { if (HAL_DMA2D_Start(&hdma2d_eval, address2, address1, (BSP_LCD_GetXSize() - 60), 1) == HAL_OK) { /* Polling For DMA transfer */ HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10); } } } /* Increment the source and destination buffers */ address1 += ((BSP_LCD_GetXSize() - 60)*3); address2 -= BSP_LCD_GetXSize()*4; } }
/** * @brief EEPROM Demo * @param None * @retval None */ void TSENSOR_demo (void) { uint16_t TempValue = 0; uint8_t TsensorReady = 0; uint8_t RequestSample = 0; uint32_t Tick = 0; TSENSOR_SetHint(); /* Initialize the I2C TSENSOR driver ----------------------------------------*/ BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillRect(12, 92, BSP_LCD_GetXSize() - 24, BSP_LCD_GetYSize()- 104); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); if (BSP_TSENSOR_Init() != TSENSOR_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t*)"Initialization problem", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t*)"Temperature Sensor not detected", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 145, (uint8_t*)"Verify that jumper JP4 and JP5", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 160, (uint8_t*)"are well set to I2C2 position", CENTER_MODE); } else { TsensorReady = READY; RequestSample = SET; } while (1) { if((TsensorReady == READY) && (RequestSample == SET)) { TempValue = BSP_TSENSOR_ReadTemp(); TSENSOR_Display_Temperature(TempValue); Tick = HAL_GetTick(); RequestSample = RESET; } else { /* Request a Temperature sampling each 1s <-> 1000 ms */ if(HAL_GetTick() >= Tick + 1000) { RequestSample = SET; } } if(CheckForUserInput() > 0) { return; } HAL_Delay(5); } }
/** * @brief Display Animation demo hint * @param None * @retval None */ static void Animation_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Camera Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 90); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"ANIMATION EXAMPLE", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)" Press TAMPER button to start ", CENTER_MODE); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 100, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize() - 110); BSP_LCD_DrawRect(11, 101, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize() - 112); }
static void GeschwindigkeitAufLCD(uint32_t geschwindigkeit_zehntelkmh) { uint8_t desc[50]; /* Draw Bitmap */ // BSP_LCD_DrawBitmap((BSP_LCD_GetXSize() - 80)/2, 65, (uint8_t *)stlogo); BSP_LCD_SetFont(&Font8); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 20, (uint8_t*)"Copyright (c) vollmermen 2015", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, BSP_LCD_GetYSize()/2 + 15, BSP_LCD_GetXSize(), 60); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 30, (uint8_t*)"Blauen Taster druecken fuer Puls.", CENTER_MODE); BSP_LCD_SetFont(&Font16); sprintf((char *)desc, "%4.1f", (float) (geschwindigkeit_zehntelkmh/10)); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 45, (uint8_t *)desc, CENTER_MODE); }
/** * @brief Display Camera demo hint * @param None * @retval None */ static void Camera_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Camera Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 90); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"CAMERA EXAMPLE", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)" Press User button for next resolution ", CENTER_MODE); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 100, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 110); BSP_LCD_DrawRect(11, 101, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 112); }
/** * @brief Draws RGB Image (16 bpp). * @param Xpos: X position in the LCD * @param Ypos: Y position in the LCD * @param Xsize: X size in the LCD * @param Ysize: Y size in the LCD * @param pdata: Pointer to the RGB Image address. * @retval None */ void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata) { SetDisplayWindow(Xpos, Ypos, Xsize, Ysize); if(lcd_drv->DrawRGBImage != NULL) { lcd_drv->DrawRGBImage(Xpos, Ypos, Xsize, Ysize, pdata); } SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); }
/** * @brief Initializes the LCD. * @retval LCD state */ uint8_t BSP_LCD_Init(void) { /* Timing Configuration */ ltdc_handle.Init.HorizontalSync = (RK043FN48H_HSYNC - 1); ltdc_handle.Init.VerticalSync = (RK043FN48H_VSYNC - 1); ltdc_handle.Init.AccumulatedHBP = (RK043FN48H_HSYNC + RK043FN48H_HBP - 1); ltdc_handle.Init.AccumulatedVBP = (RK043FN48H_VSYNC + RK043FN48H_VBP - 1); ltdc_handle.Init.AccumulatedActiveH = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP - 1); ltdc_handle.Init.AccumulatedActiveW = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP - 1); ltdc_handle.Init.TotalHeigh = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP + RK043FN48H_VFP - 1); ltdc_handle.Init.TotalWidth = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP + RK043FN48H_HFP - 1); /* LCD clock configuration */ BSP_LCD_ClockConfig(<dc_handle, NULL); /* Initialize the LCD pixel width and pixel height */ ltdc_handle.LayerCfg->ImageWidth = RK043FN48H_WIDTH; ltdc_handle.LayerCfg->ImageHeight = RK043FN48H_HEIGHT; /* Background value */ ltdc_handle.Init.Backcolor.Blue = 0; ltdc_handle.Init.Backcolor.Green = 0; ltdc_handle.Init.Backcolor.Red = 0; /* Polarity */ ltdc_handle.Init.HSPolarity = LTDC_HSPOLARITY_AL; ltdc_handle.Init.VSPolarity = LTDC_VSPOLARITY_AL; ltdc_handle.Init.DEPolarity = LTDC_DEPOLARITY_AL; ltdc_handle.Init.PCPolarity = LTDC_PCPOLARITY_IPC; ltdc_handle.Instance = LTDC; if (HAL_LTDC_GetState(<dc_handle) == HAL_LTDC_STATE_RESET) { BSP_LCD_MspInit(<dc_handle, NULL); } HAL_LTDC_Init(<dc_handle); /* allocate the framebuffer */ size_t fb_size_pages = PAGE_ALIGN(RK043FN48H_WIDTH * RK043FN48H_HEIGHT * 4) / PAGE_SIZE; void *fb_address = novm_alloc_pages(fb_size_pages, NOVM_ARENA_SECONDARY); if (!fb_address) panic("failed to allocate framebuffer for LCD\n"); BSP_LCD_LayerDefaultInit(0, (uint32_t)fb_address); BSP_LCD_SelectLayer(0); /* clear framebuffer */ memset((void *)ltdc_handle.LayerCfg[active_layer].FBStartAdress, 0, BSP_LCD_GetXSize() * BSP_LCD_GetYSize() * BSP_LCD_PixelSize()); /* turn the display on */ BSP_LCD_DisplayOn(); return LCD_OK; }
/** * @brief Touchscreen Demo3 : test touchscreen single and dual touch in interrupt mode * @param None * @retval None */ void Touchscreen_demo3(void) { uint8_t exitTsUseCase = 0; uint32_t ts_status = TS_OK; /* Reset touch data information */ BSP_TEST_APPLI_ASSERT(BSP_TS_ResetTouchData(&TS_State)); /* If calibration is not yet done, this is an error : touchscreen demo 1 should have been run before anyway */ if (TouchScreen_IsCalibrationDone() == 0) { BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"ERROR : touchscreen not yet calibrated.", CENTER_MODE); ts_status = TS_ERROR; } if(ts_status == TS_OK) { /* Display touch screen demo3 description */ Touchscreen_SetHint_Demo(TOUCHSCREEN_DEMO_3); /* Set touchscreen in Interrupt mode and program MFX accordingly to receipt INT falling edge from MFX */ /* and generate EXTI when occurs */ ts_status = BSP_TS_ITConfig(); BSP_TEST_APPLI_ASSERT(ts_status != TS_OK); while (exitTsUseCase == 0) { /* In order to avoid using I2C to ask MFX when not need (e.g. BSP_TS_ITGetStatus) */ /* check first if EXTI occurred */ /* Note : variable 'ts_exti_received' is set to 1b1' by HAL_GPIO_EXTI_Callback() */ if(mfx_exti_received == 1) { mfx_exti_received = 0; if(BSP_TS_ITGetStatus() == TS_IRQ_PENDING) { /* Clear first BSP TS IRQ */ BSP_TS_ITClear(); /* Handle the new touch */ Touchscreen_Handle_NewTouch(); } } /* Wait for a key button press to switch to next test case of BSP validation application */ /* Otherwise stay in the test */ exitTsUseCase = CheckForUserInput(); HAL_Delay(10); } /* of while (exitTsUseCase == 0) */ } /* of if(status == TS_OK) */ }
/** * @brief Display TSENSOR Demo Hint * @param None * @retval None */ static void TSENSOR_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(0, 0, (uint8_t*)"TEMPERATURE SENSOR", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t*)"This example shows how to", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 45, (uint8_t*)"read a Temperature", CENTER_MODE); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 90, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 100); BSP_LCD_DrawRect(11, 91, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 102); }