School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
lcd_functions.h@3:02e7aac23ff9, 2021-01-13 (annotated)
- Committer:
- tuxx0046
- Date:
- Wed Jan 13 12:11:54 2021 +0000
- Revision:
- 3:02e7aac23ff9
- Child:
- 4:1a12157689a7
Started working on basic LCD functionalities, using code from a previous project.; Changed some minor things in comments.; Renamed filename.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 3:02e7aac23ff9 | 1 | /** |
tuxx0046 | 3:02e7aac23ff9 | 2 | @file lcd_functions.h |
tuxx0046 | 3:02e7aac23ff9 | 3 | |
tuxx0046 | 3:02e7aac23ff9 | 4 | @brief This file contains functions for graphicall dividing screen and outputting specific information to the display. |
tuxx0046 | 3:02e7aac23ff9 | 5 | LCD size is (480, 272) |
tuxx0046 | 3:02e7aac23ff9 | 6 | Available font sizes Font8, Font12, Font16, Font20 or Font24 |
tuxx0046 | 3:02e7aac23ff9 | 7 | |
tuxx0046 | 3:02e7aac23ff9 | 8 | @author Tu Tri Huynh |
tuxx0046 | 3:02e7aac23ff9 | 9 | |
tuxx0046 | 3:02e7aac23ff9 | 10 | @date 1/13/2021 |
tuxx0046 | 3:02e7aac23ff9 | 11 | */ |
tuxx0046 | 3:02e7aac23ff9 | 12 | #include "stm32746g_discovery_lcd.h" |
tuxx0046 | 3:02e7aac23ff9 | 13 | |
tuxx0046 | 3:02e7aac23ff9 | 14 | // Initializes the LCD for use |
tuxx0046 | 3:02e7aac23ff9 | 15 | void lcd_initialize() |
tuxx0046 | 3:02e7aac23ff9 | 16 | { |
tuxx0046 | 3:02e7aac23ff9 | 17 | BSP_LCD_Init(); |
tuxx0046 | 3:02e7aac23ff9 | 18 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); // Initialize LCD layers |
tuxx0046 | 3:02e7aac23ff9 | 19 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); // Select the LCD Layer |
tuxx0046 | 3:02e7aac23ff9 | 20 | } |
tuxx0046 | 3:02e7aac23ff9 | 21 | |
tuxx0046 | 3:02e7aac23ff9 | 22 | // Runs the startup screen with name and project name |
tuxx0046 | 3:02e7aac23ff9 | 23 | void lcd_show_startup_screen() |
tuxx0046 | 3:02e7aac23ff9 | 24 | { |
tuxx0046 | 3:02e7aac23ff9 | 25 | // Startup screen |
tuxx0046 | 3:02e7aac23ff9 | 26 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 27 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 28 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
tuxx0046 | 3:02e7aac23ff9 | 29 | BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"Light Control System", CENTER_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 30 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 31 | BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"by Tu Tri Huynh", CENTER_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 32 | HAL_Delay(3000); |
tuxx0046 | 3:02e7aac23ff9 | 33 | } |
tuxx0046 | 3:02e7aac23ff9 | 34 | |
tuxx0046 | 3:02e7aac23ff9 | 35 | /* |
tuxx0046 | 3:02e7aac23ff9 | 36 | Screen is divided into four parts equal in size |
tuxx0046 | 3:02e7aac23ff9 | 37 | */ |
tuxx0046 | 3:02e7aac23ff9 | 38 | |
tuxx0046 | 3:02e7aac23ff9 | 39 | // Sets up the upper left part of screen |
tuxx0046 | 3:02e7aac23ff9 | 40 | |
tuxx0046 | 3:02e7aac23ff9 | 41 | void lcd_upper_left() |
tuxx0046 | 3:02e7aac23ff9 | 42 | { |
tuxx0046 | 3:02e7aac23ff9 | 43 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
tuxx0046 | 3:02e7aac23ff9 | 44 | BSP_LCD_FillRect(0, 0, 240, 136); |
tuxx0046 | 3:02e7aac23ff9 | 45 | } |
tuxx0046 | 3:02e7aac23ff9 | 46 | |
tuxx0046 | 3:02e7aac23ff9 | 47 | void lcd_upper_left_smiley() |
tuxx0046 | 3:02e7aac23ff9 | 48 | { |
tuxx0046 | 3:02e7aac23ff9 | 49 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
tuxx0046 | 3:02e7aac23ff9 | 50 | BSP_LCD_FillRect(0, 0, 240, 136); |
tuxx0046 | 3:02e7aac23ff9 | 51 | BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); |
tuxx0046 | 3:02e7aac23ff9 | 52 | // Create yellow circle in the middle of field |
tuxx0046 | 3:02e7aac23ff9 | 53 | BSP_LCD_FillCircle(120, 68, 50); |
tuxx0046 | 3:02e7aac23ff9 | 54 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 55 | BSP_LCD_FillCircle(120, 90, 15); |
tuxx0046 | 3:02e7aac23ff9 | 56 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 57 | BSP_LCD_FillCircle(100, 58, 10); |
tuxx0046 | 3:02e7aac23ff9 | 58 | BSP_LCD_FillCircle(140, 58, 10); |
tuxx0046 | 3:02e7aac23ff9 | 59 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 60 | BSP_LCD_FillCircle(100, 58, 3); |
tuxx0046 | 3:02e7aac23ff9 | 61 | BSP_LCD_FillCircle(140, 58, 3); |
tuxx0046 | 3:02e7aac23ff9 | 62 | } |
tuxx0046 | 3:02e7aac23ff9 | 63 | |
tuxx0046 | 3:02e7aac23ff9 | 64 | // Sets up the upper right part of screen |
tuxx0046 | 3:02e7aac23ff9 | 65 | void lcd_upper_right() |
tuxx0046 | 3:02e7aac23ff9 | 66 | { |
tuxx0046 | 3:02e7aac23ff9 | 67 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 68 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 69 | BSP_LCD_FillRect(240, 0, 240, 136); |
tuxx0046 | 3:02e7aac23ff9 | 70 | } |
tuxx0046 | 3:02e7aac23ff9 | 71 | |
tuxx0046 | 3:02e7aac23ff9 | 72 | // Sets up the lower left part of screen |
tuxx0046 | 3:02e7aac23ff9 | 73 | void lcd_lower_left() |
tuxx0046 | 3:02e7aac23ff9 | 74 | { |
tuxx0046 | 3:02e7aac23ff9 | 75 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 76 | BSP_LCD_FillRect(0, 136, 240, 136); |
tuxx0046 | 3:02e7aac23ff9 | 77 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 78 | // Set font to be smaller for this part |
tuxx0046 | 3:02e7aac23ff9 | 79 | BSP_LCD_SetFont(&Font12); |
tuxx0046 | 3:02e7aac23ff9 | 80 | BSP_LCD_DisplayStringAt(5, 160, (uint8_t *)"Tu Tri Huynh", LEFT_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 81 | BSP_LCD_DisplayStringAt(5, 180, (uint8_t *)"Embedded Programming", LEFT_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 82 | BSP_LCD_DisplayStringAt(5, 200, (uint8_t *)"Light Control System", LEFT_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 83 | // Reset fontsize |
tuxx0046 | 3:02e7aac23ff9 | 84 | BSP_LCD_SetFont(&Font16); |
tuxx0046 | 3:02e7aac23ff9 | 85 | } |
tuxx0046 | 3:02e7aac23ff9 | 86 | |
tuxx0046 | 3:02e7aac23ff9 | 87 | // Sets up the upper right part of screen |
tuxx0046 | 3:02e7aac23ff9 | 88 | void lcd_lower_right() |
tuxx0046 | 3:02e7aac23ff9 | 89 | { |
tuxx0046 | 3:02e7aac23ff9 | 90 | BSP_LCD_SetTextColor(LCD_COLOR_CYAN); |
tuxx0046 | 3:02e7aac23ff9 | 91 | BSP_LCD_FillRect(240, 136, 240, 136); |
tuxx0046 | 3:02e7aac23ff9 | 92 | } |
tuxx0046 | 3:02e7aac23ff9 | 93 | |
tuxx0046 | 3:02e7aac23ff9 | 94 | // Shows the main screen |
tuxx0046 | 3:02e7aac23ff9 | 95 | void lcd_show_main_screen() |
tuxx0046 | 3:02e7aac23ff9 | 96 | { |
tuxx0046 | 3:02e7aac23ff9 | 97 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // Clear with color |
tuxx0046 | 3:02e7aac23ff9 | 98 | lcd_upper_left(); |
tuxx0046 | 3:02e7aac23ff9 | 99 | lcd_lower_left(); |
tuxx0046 | 3:02e7aac23ff9 | 100 | lcd_upper_right(); |
tuxx0046 | 3:02e7aac23ff9 | 101 | lcd_lower_right(); |
tuxx0046 | 3:02e7aac23ff9 | 102 | |
tuxx0046 | 3:02e7aac23ff9 | 103 | |
tuxx0046 | 3:02e7aac23ff9 | 104 | /******** DEMO CODE EXAMPLE *****/ |
tuxx0046 | 3:02e7aac23ff9 | 105 | /* |
tuxx0046 | 3:02e7aac23ff9 | 106 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // Clear and set color |
tuxx0046 | 3:02e7aac23ff9 | 107 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
tuxx0046 | 3:02e7aac23ff9 | 108 | BSP_LCD_DrawRect(10, 20, 50, 50); |
tuxx0046 | 3:02e7aac23ff9 | 109 | BSP_LCD_SetTextColor(LCD_COLOR_BROWN); |
tuxx0046 | 3:02e7aac23ff9 | 110 | BSP_LCD_FillCircle(80, 80, 50); |
tuxx0046 | 3:02e7aac23ff9 | 111 | BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); |
tuxx0046 | 3:02e7aac23ff9 | 112 | BSP_LCD_DrawEllipse(150, 150, 50, 100); |
tuxx0046 | 3:02e7aac23ff9 | 113 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
tuxx0046 | 3:02e7aac23ff9 | 114 | BSP_LCD_FillCircle(200, 200, 40); |
tuxx0046 | 3:02e7aac23ff9 | 115 | HAL_Delay(2000); |
tuxx0046 | 3:02e7aac23ff9 | 116 | |
tuxx0046 | 3:02e7aac23ff9 | 117 | |
tuxx0046 | 3:02e7aac23ff9 | 118 | BSP_LCD_SetBackColor(LCD_COLOR_DARKBLUE); |
tuxx0046 | 3:02e7aac23ff9 | 119 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
tuxx0046 | 3:02e7aac23ff9 | 120 | //BSP_LCD_DisplayStringAt(0, 6, (uint8_t *)output, RIGHT_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 121 | //HAL_Delay(2000); |
tuxx0046 | 3:02e7aac23ff9 | 122 | */ |
tuxx0046 | 3:02e7aac23ff9 | 123 | } |