Library 50- STemWin for STM32F429-Discovery
ST provides emWin library from Segger. It is professional GUI (Graphical User Interface), optimized for speed and performance for microcontrollers. ST has it’s own implementation, called STemWin. With this GUI, you can do many thing, of use simple buttons, dialogs, text boxes, to playing videos, displaying pictures, menus, etc. I suggest you that you go to segger’s website and read more about this very useful tool.
In my library, I’ve some changes from original ST’s example for STM32F429-Discovery board, because it has external ram (which is necessary for professional GUI) and LCD on board.
This library is just implementation (behind the scenes) to get emWin in working state on discovery board. How and what to do to use it is on you to take a look on emWin datasheet.
Library
Features
- Use GUI on STM32F429-Discovery board
- Compatibility with emWin professional GUI
- External ram is used
- 1 Layer
- Screen rotation supported
- Touch screen supported
Dependencies
- STM32F4xx
- STM32F4xx
- STM32F4xx RCC
- STM32F4xx GPIO
- STM32F4xx FMC
- STM32F4xx LTDC
- STM32F4xx DMA2D
- STM32F4xx SPI
- STM32F4xx I2C
- TM
- TM SPI
- TM I2C
- TM GPIO
- TM STMPE811
- TM ILI9341 LTDC
- TM SDRAM
- TM FONTS
- TM DELAY
- defines.h
- All files are in one packet at the end of this post
- TM SPI
Screen rotation
I’ve made support for screen rotation. You need more ram if you want screen rotation. By default this mode is disabled and if you want to use it, you have to open defines.h file, and add define like one below:
1 2 |
/* Enable screen rotation by emWin */ #define TM_EMWIN_ROTATE_LCD 1 |
Then look at my functions and enumeration section to see how to properly use function for rotate screen.
Functions and enumerations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
/** * Result enumeration * * Parameters: * - TM_EMWIN_Result_Ok: * Everything OK * - TM_EMWIN_Result_Error: * An error occured * - TM_EMWIN_Result_TouchError: * Error with touch controller * - TM_EMWIN_Result_GUIError: * Error with emWin GUI */ typedef enum { TM_EMWIN_Result_Ok = 0, TM_EMWIN_Result_Error, TM_EMWIN_Result_TouchError, TM_EMWIN_Result_GUIError } TM_EMWIN_Result_t; /** * Rotation enumeration * * Parameters: * - TM_EMWIN_Rotate_0: * Rotate LCD for 0 degrees, default state * - TM_EMWIN_Rotate_90: * Rotate LCD 90 degrees * - TM_EMWIN_Rotate_180: * Rotate LCD 180 degrees * - TM_EMWIN_Rotate_270: * Rotate LCD 170 degrees */ typedef enum { TM_EMWIN_Rotate_0 = 0, TM_EMWIN_Rotate_90, TM_EMWIN_Rotate_180, TM_EMWIN_Rotate_270, } TM_EMWIN_Rotate_t; /** * Initialize emWin peripheral * This function initialize LCD, SDRAM, STMPE811 touch and GUI * * Member of TM_EMWIN_Result_t is returned */ extern TM_EMWIN_Result_t TM_EMWIN_Init(void); /** * This function is used to rotate LCD * It does not have any sense, if you have disabled define TM_EMWIN_ROTATE_LCD. * By default, rotation is disabled for memory purpose. * * To rotate LCD you need additional RAM, but it is available on F429-Discovery board * * Parameters: * - TM_EMWIN_Rotate_t rotation: * Rotate direction * * Member of TM_EMWIN_Result_t is returned */ extern TM_EMWIN_Result_t TM_EMWIN_Rotate(TM_EMWIN_Rotate_t rotation); /** * This function is used to update touch for emWin * It must be called periodically every 1ms. * * It makes touch controller check every number of ms as defined in EMWIN_UPDATE_TOUCH_MILLIS define * * Member of TM_EMWIN_Result_t is returned */ extern TM_EMWIN_Result_t TM_EMWIN_UpdateTouch(void); |
Example
- Example below provides you one progress bar and 5 buttons
- first button is to activate other 4 buttons
- 4 buttons are for on/off 2 leds on discovery board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
/** * Keil project example for emWin * * Before you start, select your target, on the right of the "Load" button * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 * @packs STM32F4xx Keil packs version 2.2.0 or greater required * @stdperiph STM32F4xx Standard peripheral drivers version 1.4.0 or greater required */ /* Include core modules */ #include "stm32f4xx.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32f4_delay.h" #include "tm_stm32f4_disco.h" #include "tm_stm32f4_emwin.h" /* GUI modules */ #include "button.h" #include "DIALOG.h" int main(void) { BUTTON_Handle hButton, hB1, hB2, hB3, hB4; PROGBAR_Handle hProgbar; uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay functions */ TM_DELAY_Init(); /* Initialize LEDs */ TM_DISCO_LedInit(); /* Initialize emWin */ if (TM_EMWIN_Init() != TM_EMWIN_Result_Ok) { /* Initialization error */ while (1) { /* Toggle RED led */ TM_DISCO_LedToggle(LED_RED); /* Delay */ Delayms(100); } } /* Create progress bar at location x = 10, y = 10, length = 219, height = 30 */ hProgbar = PROGBAR_CreateEx(10, 10, 219, 30, 0, WM_CF_SHOW, 0, GUI_ID_PROGBAR0); /* Set progress bar font */ PROGBAR_SetFont(hProgbar, &GUI_Font8x16); /* Set progress bar text */ PROGBAR_SetText(hProgbar, "LOADING..Please wait.."); /* Imitate loading */ for (i = 1; i <= 100; i++) { /* Set bar */ PROGBAR_SetValue(hProgbar, i); /* Little delay, update value on LCD */ GUI_Delay(20); } /* Create button with GUI_ID_OK ID number */ hButton = BUTTON_CreateEx(10, 50, 219, 30, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON0); /* Set text and font */ BUTTON_SetText(hButton, "Click me to continue.."); BUTTON_SetFont(hButton, &GUI_Font8x15B_ASCII); /* Execute, show button */ GUI_Exec(); /* Wait till button pressed */ while (1) { /* Check if button was pressed */ if (GUI_GetKey() == GUI_ID_BUTTON0) { /* Led Off */ TM_DISCO_LedOff(LED_GREEN); /* Stop while loop */ break; } /* Toggle green led */ TM_DISCO_LedToggle(LED_GREEN); /* Delay 100ms */ GUI_Delay(100); } /* Delete button functionality */ BUTTON_Delete(hButton); /* Delete button from LCD */ GUI_ClearRect(10, 50, 269, 90); /* Create buttons for leds control */ hB1 = BUTTON_CreateEx(10, 90, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON1); hB2 = BUTTON_CreateEx(124, 90, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON2); hB3 = BUTTON_CreateEx(10, 150, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON3); hB4 = BUTTON_CreateEx(124, 150, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON4); /* Set font for buttons */ BUTTON_SetFont(hB1, &GUI_Font13HB_ASCII); BUTTON_SetFont(hB2, &GUI_Font13HB_ASCII); BUTTON_SetFont(hB3, &GUI_Font13HB_ASCII); BUTTON_SetFont(hB4, &GUI_Font13HB_ASCII); /* Set button text */ BUTTON_SetText(hB1, "GREEN on"); BUTTON_SetText(hB2, "GREEN off"); BUTTON_SetText(hB3, "RED on"); BUTTON_SetText(hB4, "RED off"); /* Button styling */ /* Background color when button is not pressed */ BUTTON_SetBkColor(hB1, BUTTON_CI_UNPRESSED, GUI_DARKGREEN); /* Background color when button is pressed */ BUTTON_SetBkColor(hB1, BUTTON_CI_PRESSED, GUI_GREEN); /* Background color when button is not pressed */ BUTTON_SetBkColor(hB3, BUTTON_CI_UNPRESSED, GUI_DARKRED); /* Background color when button is pressed */ BUTTON_SetBkColor(hB3, BUTTON_CI_PRESSED, GUI_RED); /* Show buttons */ GUI_Exec(); while (1) { /* Get pressed key */ switch (GUI_GetKey()) { case GUI_ID_BUTTON1: /* Button 1 pressed */ TM_DISCO_LedOn(LED_GREEN); break; case GUI_ID_BUTTON2: /* Button 2 pressed */ TM_DISCO_LedOff(LED_GREEN); break; case GUI_ID_BUTTON3: /* Button 3 pressed */ TM_DISCO_LedOn(LED_RED); break; case GUI_ID_BUTTON4: /* Button 4 pressed */ TM_DISCO_LedOff(LED_RED); break; default: break; } } } /* User handler for 1ms interrupts */ void TM_DELAY_1msHandler(void) { /* Call periodically each 1ms */ TM_EMWIN_UpdateTouch(); } |
Project available on Github, download library below.
Recent comments