Introduction: STM32F4 Discovery Part1 - Touch Buttons

Picture of STM32F4 Discovery Part1 - Touch Buttons

Hi !

Today I want to show you simple application using touch screen. The idea of the programme is quite easy, but it will be great start for bigger apps. I was programming AVR for over 1 year and I didn't realize how great the ARMs could be. When I bought the Discovery board I did my best to start using touch LCD. In step 1 I'll give You links which really helped me to get start with stm32.

Step 1: CoIDE, HalCube, Segger

Picture of CoIDE, HalCube, Segger

Download and install CoIDE http://www.coocox.org/

Download the HALCube (on the bottom of the page) http://www.st.com/web/en/catalog/tools/PF259243

Segger will help you in creating widgets https://segger.com/index.html

In HalCube pack you have examples for all peripherials of stm32 Discovery. There ale also datasheets for discovery board, stm32, segger, and everything You need. Check out these files !

Step 2: Writting a Programme Buttons.h

Writting a programme on ARM microcontrollers are quite harder then AVR. I will show you how to create your first widget in easy way.

buttons.h

As you see, firstly you have to define elements you will need. In this case it is Framewin, Button1 and Button2.

In static const GUI_WIDGET_CREATE_INFO _MainWindow[] you create your widget. We have to write the type of the widget to create (FRAMEWIN_CreateIndirect), Text to be visibled on it ("Instructables !"), X-start(10) Y-start(10), X-end(220), Y-end(180).

The Buttons() function is the main function for touch screen routine.

#ifndef __BUTTONS_H
#define __BUTTONS_H

#include "WM.h" #include "BUTTON.h" #include "TEXT.h" #include "FRAMEWIN.h" #include "PROGBAR.h" #include "GRAPH.h" #include "GUIDEMO.h"

#define ID_W1 (GUI_ID_USER + 1) #define ID_W1_BUTTON0 (GUI_ID_USER + 2) #define ID_W1_BUTTON1 (GUI_ID_USER + 3) // // Dialog resource // static const GUI_WIDGET_CREATE_INFO _MainWindow[] = { {FRAMEWIN_CreateIndirect , "Instructables !", ID_W1 , 10 , 10 , 220 , 180 , 0 , 0 , 0 }, {BUTTON_CreateIndirect , "LIGHT ON" , ID_W1_BUTTON0 , 10 , 10 , 190 , 40 , 0 , 0 , 0 }, {BUTTON_CreateIndirect , "LIGHT OFF" , ID_W1_BUTTON1 , 10 , 70 , 190 , 40 , 0 , 0 , 0 }, };

void Buttons(void);

#endif /* __BUTTONS_H */

Step 3: Writting a Programme Buttons.c


buttons.c

The buttons() is called in main before infinite loop ! Using GUI_Exec() provides staying in the buttons() function. If you want to create more windows just add a global flag.

#include <stdio.h>
#include "buttons.h"
#include "stm32f429i_discovery.h"
#include "WM.h"
/*********************************************************************
*
*       _cbMainWindow
*
*   Callback function of the WELCOME dialog
*/
static void _cbMainWindow(WM_MESSAGE * pMsg)
{
	WM_HWIN hItem; 					// Universal handler for all widgets
	int Id; 						// Id of source widget
	int NCode = pMsg -> Data.v; 	// Code of message
	WM_HWIN hDlg = pMsg -> hWin;
	switch (pMsg->MsgId)
	{
		case WM_INIT_DIALOG:
		hItem = WM_GetDialogItem(hDlg, ID_W1_BUTTON0);	// LIGHT ON button
		BUTTON_SetFont(hItem, GUI_FONT_24_ASCII);	// set button text size
		hItem = WM_GetDialogItem(hDlg, ID_W1_BUTTON1);	// LIGHT OFF button
		BUTTON_SetFont(hItem, GUI_FONT_24_ASCII);	// set button text size
		FRAMEWIN_SetTitleHeight(hDlg, 30);		// set title bar height
		FRAMEWIN_SetTextColor(hDlg, GUI_DARKRED);	// set framewin text color
		FRAMEWIN_SetFont(hDlg, GUI_FONT_20_ASCII);	// set framewin text size
		FRAMEWIN_SetTextAlign(hDlg, GUI_TA_CENTER);	// set framewin text align
		WM_SetDesktopColor(GUI_DARKRED);		// background color
	break;
	case WM_NOTIFY_PARENT:
	Id = WM_GetId(pMsg -> hWinSrc);
	switch (Id)
	{
		case ID_W1_BUTTON0:
			switch (NCode)
			{
				case WM_NOTIFICATION_RELEASED:  //button released reaction
				{
					BSP_LED_On(LED3);	// leds on
					BSP_LED_On(LED4);
				}
				break;
			}
			break;
		case ID_W1_BUTTON1:
			switch (NCode)
			{
				case WM_NOTIFICATION_RELEASED:	//button released reaction
				{
					BSP_LED_Off(LED3);	// leds off
					BSP_LED_Off(LED4);
				}
				break;
			}
			break;
	}
	break;
	default:
		WM_DefaultProc(pMsg);
		break;
 	}
}
/*********************************************************************
*
*       WelcomeButtons();
*
*   Main Window of this file
*/
void Buttons(void)
{
     BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);	// create buttons with default skin
     FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);    // create framewin with default skin
GUI_CreateDialogBox(_MainWindow, GUI_COUNTOF(_MainWindow), &_cbMainWindow, WM_HBKWIN, 0, 0);
     while (1)
     {
	   GUI_Exec();
     }
}

Step 4: Watch the Results !

Picture of Watch the Results !

Now You can see how it works.

GUI_CURSOR_Show() called in main will show the cursor.

That's quite simple programme.

P.S. Enjoy and Sorry for my english :)

Comments

天懋馮 (author)2017-04-12

HI,i'm a begginger for the LCD control the LED light ,when i compiler the code,the question is occurred, the WM.h I can't not found anywhere

ldietz1 (author)2015-07-05

where do I get one of those

earlvanze (author)ldietz12015-09-23

http://www.digikey.com/product-detail/en/STM32F4DISCOVERY/497-11455-ND/2711743

kubavit (author)ldietz12015-07-05

Are you asking about discovery board ?

About This Instructable

6,230views

33favorites

License:

More by kubavit:STM32F4 Discovery part2 - ADC GraphSTM32F4 Discovery part1 - Touch ButtonsGetting started with FRDM kl46z part 4 - ADC & DAC
Add instructable to: