| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dualcore_emwin.c
Go to the documentation of this file.
1 /*
2 * @brief emWin graphics dual core example using emWin library
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 // FIXME - is this file needed? outside of norm
39 #include "lpc43xx_dualcore_config.h"
40 #include "ipc_example.h"
41 #include "ipc_msg.h"
42
43 #include "GUI.h"
44 #include "DIALOG.h"
45
46 #ifdef OS_FREE_RTOS
47 #include "FreeRTOS.h"
48 #include "task.h"
49 #define FREERTOS_LCD_STACK_SZ 512
50 #define FREERTOS_TSC_STACK_SZ 128
51 #endif
52
53 #ifdef OS_UCOS_III
54 #include "os.h"
55
56 #define UCOS_LCD_STACK_SZ 1024
57 #define UCOS_TSC_STACK_SZ 512
58
59 #define UCOS_LCD_TASK_PRIORITY (APP_CFG_TASK_START_PRIO + 1)
60 #define UCOS_TSC_TASK_PRIORITY (APP_CFG_TASK_START_PRIO - 1)
61 #endif
62
92 /*****************************************************************************
93 * Private types/enumerations/variables
94 ****************************************************************************/
98 volatile uint32_t host_ip_addr; /* Host IP address */
99 volatile uint32_t remote_ip_addr; /* Remote IP address */
100 static volatile int start = 0; /* Start flag for counter */
101 static volatile short counter = 0; /* Count value */
102 static WM_HWIN hWin; /* emWin Widget Frame Window structure */
103
104 #if (defined(OS_FREE_RTOS)) || (defined(OS_UCOS_III))
105
108 static int16_t old_tmp_x = -1, old_tmp_y = -1;
109 #endif
110
114 #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x0A)
115 #define ID_TEXT_0 (GUI_ID_USER + 0x0B)
116 #define ID_BUTTON_0 (GUI_ID_USER + 0x0C)
117 #define ID_BUTTON_1 (GUI_ID_USER + 0x0D)
118 #define ID_BUTTON_2 (GUI_ID_USER + 0x0E)
119 #define ID_TEXT_1 (GUI_ID_USER + 0x10)
120 #define ID_TEXT_2 (GUI_ID_USER + 0x11)
121 #define ID_TEXT_3 (GUI_ID_USER + 0x12)
122 #define ID_TEXT_4 (GUI_ID_USER + 0x13)
123 #define ID_TEXT_5 (GUI_ID_USER + 0x14)
124 #define ID_EDIT_0 (GUI_ID_USER + 0x15)
125 #define ID_EDIT_1 (GUI_ID_USER + 0x16)
126
130 #define TSC_CHECK_DELAY (20)
131
135 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
136 {FRAMEWIN_CreateIndirect, "emWin Demo", ID_FRAMEWIN_0, 8, 8, 310, 230, 0, 0, 0},
137 {TEXT_CreateIndirect, "NXP Semiconductors", ID_TEXT_0, 30, 10, 260, 100, TEXT_CF_HCENTER},
138 {TEXT_CreateIndirect, "0000", ID_TEXT_1, 100, 80, 100, 60, TEXT_CF_HCENTER},
139 {BUTTON_CreateIndirect, "START", ID_BUTTON_0, 36, 160, 70, 30, 0, 0, 0},
140 {BUTTON_CreateIndirect, "STOP", ID_BUTTON_1, 126, 160, 60, 30},
141 {BUTTON_CreateIndirect, "RESET", ID_BUTTON_2, 203, 160, 70, 30},
142 };
143
144 /*****************************************************************************
145 * Public types/enumerations/variables
146 ****************************************************************************/
147
151 volatile int tsc_init_done = 0;
156 #define GUI_BUF_ADDR 0x28050000
157 #define GUI_NUMBYTES ((1024 * 1024) * 2)
158 #define GUI_BLOCKSIZE (0x128)
159 #define GUI_BUF LOCATE_AT(GUI_BUF_ADDR)
161 GUI_BUF U32 GUI_Memory[GUI_NUMBYTES / sizeof(U32)];
162 U32 GUI_Memory_Size = GUI_NUMBYTES;
163 U32 GUI_Block_Size = GUI_BLOCKSIZE;
165 #define FRAME_BUF LOCATE_AT(FRAMEBUFFER_ADDR)
166 FRAME_BUF uint16_t Frame_Buf[C_GLCD_H_SIZE * C_GLCD_V_SIZE];
168 /*****************************************************************************
169 * Private functions
170 ****************************************************************************/
171 /* update the remote ip address in emwin window */
172 static void lcd_update_remoteip(uint32_t new_remote_ip)
173 {
174 remote_ip_addr = new_remote_ip;
175 }
176
180 static void lcd_update_values(WM_HWIN hWin_up)
181 {
182 WM_HWIN hItem;
183 char tbuff[16];
184 static uint32_t old_hostip = 1, old_remoteip = 1;
185
186 if (old_hostip != host_ip_addr) {
187 /* Set Host IP Address */
188 hItem = WM_GetDialogItem(hWin_up, ID_EDIT_0);
189 EDIT_SetTextAlign(hItem, GUI_TA_HCENTER);
190 EDIT_SetBkColor(hItem, EDIT_CI_DISABLED, GUI_GREEN);
191 EDIT_SetTextColor(hItem, EDIT_CI_DISABLED, GUI_GREEN);
192 snprintf(tbuff, sizeof(tbuff) - 1, "%d.%d.%d.%d",
193 host_ip_addr & 0xFF, (host_ip_addr >> 8) & 0xFF,
194 (host_ip_addr >> 16) & 0xFF, (host_ip_addr >> 24) & 0xFF);
195 EDIT_SetText(hItem, tbuff);
196 old_hostip = host_ip_addr;
197 }
198
199 if (old_remoteip != remote_ip_addr) {
200 /* Set Remote IP address */
201 hItem = WM_GetDialogItem(hWin_up, ID_EDIT_1);
202 EDIT_SetTextAlign(hItem, GUI_TA_HCENTER);
203 EDIT_SetBkColor(hItem, EDIT_CI_DISABLED, GUI_RED);
204 EDIT_SetTextColor(hItem, EDIT_CI_DISABLED, GUI_RED);
205 snprintf(tbuff, sizeof(tbuff)-1, "%d.%d.%d.%d",
206 remote_ip_addr & 0xFF, (remote_ip_addr >> 8) & 0xFF,
207 (remote_ip_addr >> 16) & 0xFF, (remote_ip_addr >> 24) & 0xFF);
208 EDIT_SetText(hItem, tbuff);
209 old_remoteip = remote_ip_addr;
210 }
211 }
212
213 /* Update the host IP address in Emwin Window */
214 static void lcd_update_hostip(uint32_t host_ip)
215 {
216 WM_HWIN hItem;
217 static char name[] = {"HTTP Server Address"};
218 static char remote_name[] = {"Remote IP address"};
219
220 if (host_ip != host_ip_addr) {
221 host_ip_addr = host_ip;
222 }
223
224 /* Create HTTP server address Text box */
225 hItem = TEXT_CreateEx(24, 40, 150, 100, WM_GetClientWindow(hWin), WM_CF_SHOW, 0, ID_TEXT_2, name);
226 TEXT_SetFont(hItem, &GUI_Font16B_ASCII);
227 TEXT_SetTextAlign(hItem, GUI_TA_HCENTER);
228 TEXT_SetTextColor(hItem, GUI_DARKCYAN);
229
230 /* Create Remote IP address Text box */
231 hItem = TEXT_CreateEx(24, 60, 150, 100, WM_GetClientWindow(hWin), WM_CF_SHOW, 0, ID_TEXT_3, remote_name);
232 TEXT_SetFont(hItem, &GUI_Font16B_ASCII);
233 TEXT_SetTextAlign(hItem, GUI_TA_HCENTER);
234 TEXT_SetTextColor(hItem, GUI_DARKGREEN);
235
236 /* Create Host IP edit box */
237 hItem = EDIT_CreateEx(170, 40, 100, 20, WM_GetClientWindow(hWin), WM_CF_SHOW, 0, ID_EDIT_0, 16);
238
239 /* Create Remote IP edit box */
240 hItem = EDIT_CreateEx(170, 60, 100, 20, WM_GetClientWindow(hWin), WM_CF_SHOW, 0, ID_EDIT_1, 16);
241
242 /* Update values on LCD */
243 lcd_update_values(hWin);
244 }
245
249 static void _cbCallback(WM_MESSAGE *pMsg)
250 {
251 int NCode, Id;
252 WM_HWIN hDlg;
253 WM_HWIN hItem;
254 int fdig, sdig, tdig, frdig;
255 BUTTON_Handle hButton;
256 char acText[5] = {0};
257
258 hDlg = pMsg->hWin;
259 switch (pMsg->MsgId) {
260 case WM_PAINT:
261 WM_DefaultProc(pMsg); /* Handle dialog items */
262 break;
263
264 case WM_INIT_DIALOG:
265 FRAMEWIN_SetTextAlign(hDlg, GUI_TA_HCENTER | GUI_TA_VCENTER);
266 FRAMEWIN_SetFont(hDlg, GUI_FONT_24_ASCII);
267
268 /* set the Text properties */
269 hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
270 TEXT_SetText(hItem, "NXP SEMICONDUCTORS");
271 TEXT_SetFont(hItem, &GUI_Font24B_ASCII);
272 TEXT_SetTextAlign(hItem, (GUI_TA_HCENTER));
273 TEXT_SetTextColor(hItem, GUI_YELLOW);
274
275 hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
276 counter = counter % 10000;
277 fdig = counter / 1000;
278 sdig = (counter - (fdig * 1000)) / 100;
279 tdig = (counter - ((fdig * 1000) + (sdig * 100))) / 10;
280 frdig = counter % 10;
281 acText[0] = '0' + fdig;
282 acText[1] = '0' + sdig;
283 acText[2] = '0' + tdig;
284 acText[3] = '0' + frdig;
285 TEXT_SetFont(hItem, &GUI_Font8x16x1x2);
286 TEXT_SetTextAlign(hItem, (GUI_TA_HCENTER));
287 TEXT_SetTextColor(hItem, GUI_RED);
288 TEXT_SetText(hItem, acText);
289 break;
290
291 case WM_KEY:
292 break;
293
294 case WM_NOTIFY_PARENT:
295
296 Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
297 NCode = pMsg->Data.v; /* Notification code */
298 switch (NCode) {
299 case WM_NOTIFICATION_RELEASED: /* React only if released */
300 if (Id == ID_BUTTON_0) { /* Start button */
301 hButton = WM_GetDialogItem(hDlg, ID_BUTTON_0);
302 start = 1;
303 WM_InvalidateWindow(hButton);
304 }
305
306 if (Id == ID_BUTTON_1) { /* Stop button */
307 hButton = WM_GetDialogItem(hDlg, ID_BUTTON_1);
308 start = 0;
309 WM_InvalidateWindow(hButton);
310 }
311
312 if (Id == ID_BUTTON_2) { /* Reset button */
313 hButton = WM_GetDialogItem(hDlg, ID_BUTTON_2);
314 counter = 0;
315 start = 0;
316 remote_ip_addr = 0;
317 WM_InvalidateWindow(hButton);
318 }
319 break;
320 }
321 break;
322
323 default:
324 WM_DefaultProc(pMsg);
325 }
326 }
327
331 #if (defined(OS_FREE_RTOS)) || (defined(OS_UCOS_III))
332
333 /* LCd Display thread */
334 #ifdef OS_FREE_RTOS
335 static portTASK_FUNCTION(vLcdTask, pvParameters)
336 #elif OS_UCOS_III
337 static void lcd_app_task(void *arg)
338 #endif
339 {
340 WM_HWIN hItem;
341 int fdig, sdig, tdig, frdig;
342 char acText[5] = {0};
343
344 GUI_Init();
345 WM_SetDesktopColor(GUI_GREEN);
346 WM_SetCreateFlags(WM_CF_MEMDEV);
347 hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
348
349 while (1) {
350 if (start) {
351 counter++;
352 if (counter > 9999) {
353 counter = 0;
354 }
355 }
356
357 /* Print Count value */
358 hItem = WM_GetDialogItem(hWin, ID_TEXT_1);
359 counter = counter % 10000;
360 fdig = counter / 1000;
361 sdig = (counter - (fdig * 1000)) / 100;
362 tdig = (counter - ((fdig * 1000) + (sdig * 100))) / 10;
363 frdig = counter % 10;
364 acText[0] = '0' + fdig;
365 acText[1] = '0' + sdig;
366 acText[2] = '0' + tdig;
367 acText[3] = '0' + frdig;
368 TEXT_SetFont(hItem, &GUI_Font8x16x3x3);
369 TEXT_SetTextAlign(hItem, (GUI_TA_HCENTER));
370 TEXT_SetTextColor(hItem, GUI_RED);
371 TEXT_SetText(hItem, acText);
372
373 lcd_update_values(hWin);
374
375 GUI_Delay(10);
376 }
377 }
378
382 #ifdef OS_FREE_RTOS
383 static portTASK_FUNCTION(vTSCTask, pvParameters)
384 #elif OS_UCOS_III
385 static void tsc_app_task(void *arg)
386 #endif
387 {
388 int16_t tmp_x = -1, tmp_y = -1;
389 int16_t tmp_x1 = -1, tmp_y1 = -1;
390 static uint8_t pressed = 0;
391 bool touched;
392 #ifdef OS_UCOS_III
393 OS_ERR ret;
394 #endif
395
396 while (1) {
397 /* Wait for TSC_CHECK_DELAY ms */
398 #ifdef OS_UCOS_III
399 OSTimeDlyHMSM(0, 0, TSC_CHECK_DELAY / 1000, TSC_CHECK_DELAY % 1000, OS_OPT_TIME_HMSM_STRICT, &ret);
400 #else
401 vTaskDelay(TSC_CHECK_DELAY);
402 #endif
403
404 /* Check any Touch screen events */
405 touched = Board_GetTouchPos((int16_t *) &tmp_x, (int16_t *) &tmp_y);
406 if (touched == true) {
407 if (pressed == 1) {
408 if ((tmp_x >= 0) && (tmp_y > 0) && ((tmp_x != old_tmp_x) || (tmp_y != old_tmp_y))) {
409 tmp_x1 = tmp_y;
410 tmp_y1 = tmp_x;
411 GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
412 old_tmp_x = tmp_x;
413 old_tmp_y = tmp_y;
414 }
415 }
416 else {
417 GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
418 old_tmp_x = tmp_x;
419 old_tmp_y = tmp_y;
420 pressed = 1;
421 }
422 }
423 else {
424 if (pressed == 1) {
425 GUI_TOUCH_StoreState(-1, -1);
426 pressed = 0;
427 }
428 }
429 }
430 }
431
432 #endif
433
434 /*****************************************************************************
435 * Public functions
436 ****************************************************************************/
437
438 extern void SysTick_Enable(uint32_t period);
439
440 /* Overrided event handler for http access info */
441 void EVENT_lwip_http_access(uint32_t addr)
442 {
443 remote_ip_addr = addr;
444 }
445
446 /* Overrided event handler for lwip IP addr change */
447 void EVENT_lwip_addr_changed(uint32_t new_addr)
448 {
449 lcd_update_hostip(new_addr);
450 }
451
452 /* emWin example initialization function */
453 void EMWIN_Init(void)
454 {
455 /* Initialise the LCD controller */
456 Board_LCD_Init();
457 Chip_LCD_Init(LPC_LCD, (LCD_Config_T *) &BOARD_LCD);
458 Board_InitTouchController();
459 Chip_LCD_SetUPFrameBuffer(LPC_LCD, (void *) Frame_Buf);
460 Chip_LCD_PowerOn(LPC_LCD);
461 Board_SetLCDBacklight(1);
462
463 /* Register callbacks for LCD updates in IPC */
464 ipcex_register_callback(IPCEX_ID_LWIP, lcd_update_remoteip);
465 ipcex_register_callback(IPCEX_ID_USER1, lcd_update_hostip);
466
467 #if !defined(OS_UCOS_III) && !defined(OS_FREE_RTOS)
468 /* Setup a 1mS sysTick for the primary time base */
469 SysTick_Enable(1);
470
471 GUI_Init();
472
473 WM_SetDesktopColor(GUI_GREEN);
474 WM_SetCreateFlags(WM_CF_MEMDEV);
475 hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
476 GUI_Delay(10);
477
478 #endif
479
480 tsc_init_done = 1;
481
482 }
483
484 #if (defined(OS_FREE_RTOS)) || (defined(OS_UCOS_III))
485 /* OS specific dualcore emWin tasks */
486 void emwin_tasks(void)
487 {
488 #ifdef OS_FREE_RTOS
489 xTaskCreate(vTSCTask, (signed char *) "vTSCTask",
490 FREERTOS_TSC_STACK_SZ, NULL, TASK_PRIO_TOUCHSCREEN,
491 (xTaskHandle *) NULL);
492 xTaskCreate(vLcdTask, (signed char *) "vLCDTask",
493 FREERTOS_LCD_STACK_SZ, NULL, TASK_PRIO_LCD,
494 (xTaskHandle *) NULL);
495 #elif OS_UCOS_III
496 OS_ERR os_err;
497 static OS_TCB lcd_app_taskTCB;
498 static CPU_STK lcd_app_taskSTK[UCOS_LCD_STACK_SZ];
499 static OS_TCB tsc_app_taskTCB;
500 static CPU_STK tsc_app_taskSTK[UCOS_TSC_STACK_SZ];
501
502 OSTaskCreate((OS_TCB *) &lcd_app_taskTCB,
503 (CPU_CHAR *) "vLCDTask",
504 (OS_TASK_PTR) lcd_app_task,
505 (void *) 0,
506 (OS_PRIO) TASK_PRIO_LCD,
507 (CPU_STK *) &lcd_app_taskSTK[0],
508 (CPU_STK_SIZE) 32,
509 (CPU_STK_SIZE) UCOS_LCD_STACK_SZ,
510 (OS_MSG_QTY) 0u,
511 (OS_TICK) 0u,
512 (void *) 0,
513 (OS_OPT) (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
514 (OS_ERR *) &os_err);
515 if (os_err != OS_ERR_NONE) {
516 printf("Unable to create vLCDTask task!\r\n");
517 while (1) ;
518 }
519 OSTaskCreate((OS_TCB *) &tsc_app_taskTCB,
520 (CPU_CHAR *) "vTSCTask",
521 (OS_TASK_PTR) tsc_app_task,
522 (void *) 0,
523 (OS_PRIO) TASK_PRIO_TOUCHSCREEN,
524 (CPU_STK *) &tsc_app_taskSTK[0],
525 (CPU_STK_SIZE) 32,
526 (CPU_STK_SIZE) UCOS_TSC_STACK_SZ,
527 (OS_MSG_QTY) 0u,
528 (OS_TICK) 0u,
529 (void *) 0,
530 (OS_OPT) (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
531 (OS_ERR *) &os_err);
532 if (os_err != OS_ERR_NONE) {
533 printf("Unable to create vTSCTask task!\r\n");
534 while (1) ;
535 }
536 #endif
537 }
538
539 #else
540 /* Standalone emWin dual core example task */
541 void emwin_tasks(void)
542 {
543 WM_HWIN hItem;
544 int fdig, sdig, tdig, frdig;
545 char acText[5] = {0};
546
547 do {
548 if (start) {
549 counter++;
550 if (counter > 9999) {
551 counter = 0;
552 }
553 }
554
555 /* Print Count value */
556 hItem = WM_GetDialogItem(hWin, ID_TEXT_1);
557 counter = counter % 10000;
558 fdig = counter / 1000;
559 sdig = (counter - (fdig * 1000)) / 100;
560 tdig = (counter - ((fdig * 1000) + (sdig * 100))) / 10;
561 frdig = counter % 10;
562 acText[0] = '0' + fdig;
563 acText[1] = '0' + sdig;
564 acText[2] = '0' + tdig;
565 acText[3] = '0' + frdig;
566 TEXT_SetFont(hItem, &GUI_Font8x16x3x3);
567 TEXT_SetTextAlign(hItem, (GUI_TA_HCENTER));
568 TEXT_SetTextColor(hItem, GUI_RED);
569 TEXT_SetText(hItem, acText);
570
571 lcd_update_values(hWin);
572 GUI_Exec();
573 } while (0);
574 }
575
576 #endif
577