【M4开发板Hanker试用狂】ddllxxrr之四:触摸屏
[复制链接]
触摸屏分为电阻电容的,现用最广的是电阻的,电容的反应迅速准确。比电阻的造价高。
开发板用的是电阻的。从网上找到几个原理图,觉得说得不错特发下:
这款开发板用的就是AD转换原理的触摸屏。用TI的图形库十分方便。
响应用户输入事件用的硬件驱动(如触摸屏幕驱动),也算作显示的驱动的一部分,归在显示驱动层。图形库提供了触摸屏的驱动: touch.c 里面的凼数不Stellaris图形库直接相关,用户需要用到的主要是: TouchScreenCallbackSet
在触摸功能初始化的时候,这个凼数通过回调,将用户动作事件和Stellaris图形库的事件响应凼数连接在一起。 当用户动作时,输入驱动可以调用Stellaris图形库的WidgetPointerMessage凼数,传入动作的信息(如动作的x、y坐标,动作方式等)。图形库会处理这些信息,迚行画面更新,响应用户的动作。
以下是调通的程序:
//***************************************************************************** // // Forward reference to various widget structures. // //***************************************************************************** extern tCanvasWidget g_sBackground; extern tPushButtonWidget g_sPushBtn;
//***************************************************************************** // // Forward reference to the button press handler. // //***************************************************************************** void OnButtonPress(tWidget *pWidget);
//***************************************************************************** // // The heading containing the application title. // //***************************************************************************** Canvas(g_sHeading, &g_sBackground, 0, &g_sPushBtn, &g_slcd_320x240_ili932x, 0, 0, 240, 23, (CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT), ClrDarkBlue, ClrWhite, ClrWhite, &g_sFontCm20, "hello-widget", 0, 0);
//***************************************************************************** // // The canvas widget acting as the background to the display. // //***************************************************************************** Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sHeading, &g_slcd_320x240_ili932x, 0, 0, 240, 320, CANVAS_STYLE_FILL, ClrWhite, 0, 0, 0, 0, 0, 0);
//***************************************************************************** // // The button used to hide or display the "Hello World" message. // //***************************************************************************** RectangularButton(g_sPushBtn, &g_sHeading, 0, 0, &g_slcd_320x240_ili932x, 20, 60, 200, 40, (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT | PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY), ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite, &g_sFontCmss22b, "Welcome!Welcome!", 0, 0, 0, 0, OnButtonPress);
//***************************************************************************** // // The canvas widget used to display the "Hello!" string. Note that this // is NOT hooked into the active widget tree (by making it a child of the // g_sPushBtn widget above) yet since we do not want the widget to be displayed // until the button is pressed. // //***************************************************************************** Canvas(g_sHello, &g_sPushBtn, 0, 0, &g_slcd_320x240_ili932x, 10, 180, 200, 40, (CANVAS_STYLE_FILL | CANVAS_STYLE_TEXT), ClrBlack, 0, ClrWhite, &g_sFontCm40, " Hello World! ", 0, 0);
//***************************************************************************** // // A global we use to keep track of whether or not the "Hello" widget is // currently visible. // //***************************************************************************** tBoolean g_bHelloVisible = false; //tBoolean g_bHelloVisible = true; //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif
//***************************************************************************** // // This function is called by the graphics library widget manager in the // context of WidgetMessageQueueProcess whenever the user releases the // "Press Me!" button. We use this notification to display or hide the // "Hello!" widget. // // This is actually a rather inefficient way to accomplish this but it's // a good example of how to add and remove widgets dynamically. In // normal circumstances, you would likely leave the g_sHello widget // linked into the tree and merely add or remove the text by changing // its style then repainting. // // If using this dynamic add/remove strategy, another useful optimization // is to use a black canvas widget that covers the same area of the screen // as the widgets that you will be adding and removing. If this is the used // as the point in the tree where the subtree is added or removed, you can // repaint just the desired area by repainting the black canvas rather than // repainting the whole tree. // //***************************************************************************** void OnButtonPress(tWidget *pWidget) { g_bHelloVisible = !g_bHelloVisible; //g_bHelloVisible = 1; //ddllxxrr test if(g_bHelloVisible) { // // Add the Hello widget to the tree as a child of the push // button. We could add it elsewhere but this seems as good a // place as any. It also means we can repaint from g_sPushBtn and // this will paint both the button and the welcome message. // WidgetAdd((tWidget *)&g_sPushBtn, (tWidget *)&g_sHello);
// // Change the button text to indicate the new function. // PushButtonTextSet(&g_sPushBtn, "Hide Welcome");
// // Repaint the pushbutton and all widgets beneath it (in this case, // the welcome message). // WidgetPaint((tWidget *)&g_sPushBtn); } else { // // Remove the Hello widget from the tree. // WidgetRemove((tWidget *)&g_sHello);
// // Change the button text to indicate the new function. // PushButtonTextSet(&g_sPushBtn, "Show Welcome");
// // Repaint the widget tree to remove the Hello widget from the // display. This is rather inefficient but saves having to use // additional widgets to overpaint the area of the Hello text (since // disabling a widget does not automatically erase whatever it // previously displayed on the screen). // WidgetPaint(WIDGET_ROOT); } }
//***************************************************************************** // // The graphics context used by the application. // //***************************************************************************** tContext g_sContext;
//***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif
//***************************************************************************** // // Performs calibration of the touch screen. // //***************************************************************************** int main(void) {
FPUEnable(); FPULazyStackingEnable(); // // Enable the PLL and clock the part at 50 MHz. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // lcd_ili932x_init(); //初始化LCD驱动 GrContextInit(&g_sContext, &g_sLcdDisplay);//初始化图形库 lcd_backlight_on(); lcd_ili932x_flush(&g_sContext); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage);
// // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);
// // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT);
// // Loop forever, processing widget messages. // while(1) { // // Process any messages from or for the widgets. // WidgetMessageQueueProcess();
}
}
这个用TI图形库很方便,只要设好各种要显示的小控件后
调用 WidgetPaint(WIDGET_ROOT);显示。
而检测用户的触摸,只要调函数就可:
while(1) { // // Process any messages from or for the widgets. // WidgetMessageQueueProcess();
}
也就是说,小控件的触摸,图形库都集成在里边了。
我下面的程序可以运行,但得点右下的的很小的区域才行,究竟为什么。
我想同回调函数有关系。而这个回调函数是TI库提供的。所以以后慢慢探讨吧。
大家也可下载运行下,告诉我为什么就那么一小区域可点。
上图:
程序打包
:
k4.rar
(511.72 KB, 下载次数: 30)
[ 本帖最后由 ddllxxrr 于 2012-6-9 17:53 编辑 ]
|