请选择 进入手机版 | 继续访问电脑版
查看: 2296|回复: 0

[分享] 逐飞LPC55S69 IOT开发板之emwin移植及测试

[复制链接]
  • TA的每日心情

    2024-2-5 12:06
  • 签到天数: 627 天

    [LV.9]以坛为家II

    94

    主题

    1628

    帖子

    2

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    4429

    热心会员

    最后登录
    2024-2-5
    发表于 2020-12-18 08:31:43 | 显示全部楼层 |阅读模式
    今天,我们来移植下emwin,emwin还是比较好用的,它既有GUI生成工具,也有PC上位机的仿真软件。还是比较好评的,虽然不开源,只能用库,单对于
    我们普通用户来说根本无区别。
    下面讲讲怎样在MCUXpresso 上添加emwin。首先要确保emwin的文件添加到工程中。如果没有的话,打开SDK管理器,选择emwin添加。
    添加后:
    Q1.png
    有用的就是emwin开头的3个文件夹,记得老版本的时候,所以的配置都在config文件夹里面的gui_config.h 和lcd_config.h及gui_x.c等一堆文件完成,但是新版本的怎么也看不到,后来才知道它把这些配置的具体函数,集中到template下的emwin_support.c和emwin_support.h。我们匹配好这两个文件加上gui_config.h 就可以了(lcd_config.h里面啥也没有,是个空文件)。
    我们对emwin_support.h,进行修改,修改后代码:
    1. /*
    2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
    3. * Copyright 2016-2017 NXP
    4. * All rights reserved.
    5. *
    6. * SPDX-License-Identifier: BSD-3-Clause
    7. */

    8. #ifndef _EMWIN_SUPPORT_H_
    9. #define _EMWIN_SUPPORT_H_

    10. //
    11. // Color conversion TODO - choose appropriate color conversion here - see emWin documentation
    12. //
    13. //#define COLOR_CONVERSION GUICC_888
    14. #define COLOR_CONVERSION GUICC_M565

    15. //
    16. // Display driver TODO - choose appropriate LCD driver here - see emWin documentation
    17. //
    18. #define DISPLAY_DRIVER GUIDRV_FLEXCOLOR
    19. // TODO - specify the LCD dimensions

    20. #define BOARD_LCD_READABLE 0    //不允许读LCD

    21. #define LCD_WIDTH  320       
    22. #define LCD_HEIGHT 240

    23. // TODO - specify the memory assigned to emWin
    24. #define GUI_NUMBYTES 0x8000 /*! Amount of memory assigned to the emWin library */
    25. // TODO - specify the memory location for the frame buffers

    26. extern int BOARD_Touch_Poll(void);

    27. #endif
    复制代码
    其中要注意的:
    1、颜色编码格式(默认的888是不符合这个屏的,我们改成565)要对应;
    2、LCD的长宽要对应;
    3、关闭了LCD的读功能,我们LCD硬件上不支持读。
    3、指定的缓存位置(这里默认是MCU内部存储,很小,可以指向外部SRAM或者FLASH)。
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    下面对emwin_support.c就行修改,里面有具体的LCD底层实现函数的定义,修改后代码为:
    1. /*
    2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
    3. * Copyright 2016-2017 NXP
    4. * All rights reserved.
    5. *
    6. * SPDX-License-Identifier: BSD-3-Clause
    7. */

    8. #include <emwin_support.h>
    9. #include "GUI.h"
    10. #include "WM.h"
    11. #include "GUIDRV_FlexColor.h" // TODO - choose appropriate LCD driver here - see emWin documentation
    12. #include "fsl_debug_console.h"
    13. #include "fsl_gpio.h"
    14. #include "ili9341_lcd.h"                   //SPI_LCD 驱动头文件
    15. #include "ft6366_i2ctouch.h"           //IIC_touch 头文件


    16. #ifndef GUI_MEMORY_ADDR
    17. static uint32_t s_gui_memory[(GUI_NUMBYTES + 3) / 4]; /* needs to be word aligned */
    18. #define GUI_MEMORY_ADDR ((uint32_t)s_gui_memory)
    19. #endif

    20. /*******************************************************************************
    21. * Implementation of communication with the LCD controller
    22. ******************************************************************************/
    23. static void APP_pfWrite8_A0(U8 Data)
    24. {
    25.         ili9341_lcd_writ_cmd(Data);
    26. }

    27. static void APP_pfWrite8_A1(U8 Data)
    28. {
    29.         ili9341_lcd_writ_data(Data);
    30. }

    31. static void APP_pfWriteM8_A1(U8 *pData, int NumItems)
    32. {
    33.     ili9341_lcd_writ_databuf8(pData, NumItems);
    34. }

    35. static U8 APP_pfRead8_A1(void)
    36. {
    37.     uint8_t Data;
    38. #if defined(BOARD_LCD_READABLE) && (BOARD_LCD_READABLE == 0)
    39.     PRINTF("Warning: LCD does not support read operation, the image may get distorted.\r\n");
    40.     assert(0);
    41. #endif
    42.     //GPIO_PortSet(BOARD_LCD_DC_GPIO, BOARD_LCD_DC_GPIO_PORT, 1u << BOARD_LCD_DC_GPIO_PIN);
    43.     //BOARD_LCD_SPI.Receive(&Data, 1);
    44.     //SPI_WaitEvent();

    45.     Data=ili9341_lcd_read_data(0X00);

    46.     return Data;
    47. }

    48. static void APP_pfReadM8_A1(U8 *pData, int NumItems)
    49. {
    50. #if defined(BOARD_LCD_READABLE) && (BOARD_LCD_READABLE == 0)
    51.     PRINTF("Warning: LCD does not support read operation, the image may get distorted.\r\n");
    52.     assert(0);
    53. #endif
    54.     //GPIO_PortSet(BOARD_LCD_DC_GPIO, BOARD_LCD_DC_GPIO_PORT, 1u << BOARD_LCD_DC_GPIO_PIN);
    55.     //BOARD_LCD_SPI.Receive(pData, NumItems);
    56.     //SPI_WaitEvent();

    57.     ili9341_lcd_read_databuf8(pData,NumItems);
    58. }
    59.         // TODO - implement event handling
    60.        
    61. static void BOARD_LCD_InterfaceInit(void)
    62. {
    63.         // TODO - LCD interface initialization

    64.         ili9341_lcd_init();
    65. }

    66. void BOARD_LCD_InterfaceDeinit(void)
    67. {
    68.         // TODO - LCD interface deinitialization
    69. }

    70. /*******************************************************************************
    71. * Implementation of communication with the touch controller
    72. ******************************************************************************/

    73.         // TODO - implement event handling

    74. static void BOARD_Touch_InterfaceInit(void)
    75. {
    76.         // TODO - touch interface initialization

    77.         ft6366_i2ctouch_Init();
    78. }

    79. void BOARD_Touch_InterfaceDeinit(void)
    80. {
    81.         // TODO - touch interface deinitialization
    82. }

    83. int BOARD_Touch_Poll(void)
    84. {
    85.         // TODO - touch handling
    86.         GUI_PID_STATE pid_state;

    87.         ft6336_i2ctouch_scan(FLEXCOMM5_PERIPHERAL);
    88.         if(ftf6336_tpr_structure.touchsta.all & 0x01)//判断仅1点触摸 支持5点触摸
    89.         {


    90.                 //pid_state.x       = LCD_WIDTH - ftf6336_tpr_structure.y[0];
    91.                 //pid_state.y       = ftf6336_tpr_structure.x[0];

    92.                 pid_state.x       =  ftf6336_tpr_structure.y[0];
    93.                 pid_state.y       =  LCD_HEIGHT-ftf6336_tpr_structure.x[0];


    94.                 //按下或者被触摸
    95.                 pid_state.Pressed = ((ftf6336_tpr_structure.touchsta.bit.touch==1)||(ftf6336_tpr_structure.touchsta.bit.hold==1));
    96.                 pid_state.Layer   = 0;
    97.                 GUI_TOUCH_StoreStateEx(&pid_state);

    98.                 PRINTF("I touch the screen posion x: %d ,y:%d ,Press is %d.\r\n",pid_state.x,pid_state.y,pid_state.Pressed);

    99.                 return 1;
    100.         }
    101.         return 0;
    102. }

    103. /*******************************************************************************
    104. * Application implemented functions required by emWin library
    105. ******************************************************************************/

    106. void LCD_X_Config(void)
    107. {
    108.         GUI_DEVICE *pDevice;
    109.         GUI_PORT_API PortAPI;
    110.         CONFIG_FLEXCOLOR Config = {0, 0, GUI_SWAP_XY, 0, 1};

    111.     // Initialize the gui device with specified display driver and color conversion
    112.         pDevice =GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER, COLOR_CONVERSION, 0, 0);
    113.         GUIDRV_FlexColor_Config(pDevice, &Config);

    114.     LCD_SetSizeEx(0, LCD_WIDTH, LCD_HEIGHT);
    115.     LCD_SetVSizeEx(0, LCD_WIDTH, LCD_HEIGHT);

    116.     PortAPI.pfWrite8_A0  = APP_pfWrite8_A0;
    117.         PortAPI.pfWrite8_A1  = APP_pfWrite8_A1;
    118.         PortAPI.pfWriteM8_A1 = APP_pfWriteM8_A1;
    119.         PortAPI.pfRead8_A1   = APP_pfRead8_A1;
    120.         PortAPI.pfReadM8_A1  = APP_pfReadM8_A1;
    121.         GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B8);

    122.     // Initialize touch interface
    123.     BOARD_Touch_InterfaceInit();
    124. }

    125. int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void *pData)
    126. {
    127.     int result = 0;

    128.     switch (Cmd)
    129.     {
    130.         case LCD_X_INITCONTROLLER:
    131.                 BOARD_LCD_InterfaceInit();
    132.                 GUI_X_Delay(50); /* settle down delay after reset */
    133.                 FT9341_Init(APP_pfWrite8_A1, APP_pfWrite8_A0);
    134.             break;
    135.         default:
    136.             result = -1;
    137.             break;
    138.     }

    139.     return result;
    140. }

    141. void GUI_X_Config(void)
    142. {
    143.     /* Assign work memory area to emWin */
    144.     GUI_ALLOC_AssignMemory((void *)GUI_MEMORY_ADDR, GUI_NUMBYTES);

    145.     /* Select default font */
    146.     GUI_SetDefaultFont(GUI_FONT_6X8);
    147. }

    148. void GUI_X_Init(void)
    149. {
    150. }

    151. /* Dummy RTOS stub required by emWin */
    152. void GUI_X_InitOS(void)
    153. {
    154. }

    155. /* Dummy RTOS stub required by emWin */
    156. void GUI_X_Lock(void)
    157. {
    158. }

    159. /* Dummy RTOS stub required by emWin */
    160. void GUI_X_Unlock(void)
    161. {
    162. }

    163. /* Dummy RTOS stub required by emWin */
    164. U32 GUI_X_GetTaskId(void)
    165. {
    166.     return 0;
    167. }

    168. void GUI_X_ExecIdle(void)
    169. {
    170. }

    171. GUI_TIMER_TIME GUI_X_GetTime(void)
    172. {
    173.     return 0;
    174. }

    175. void GUI_X_Delay(int Period)
    176. {
    177.     volatile int per;
    178.     volatile int i;
    179.     for (per = Period; per > 0; per--)
    180.     {
    181.         for (i = 15000; i > 0; i--)
    182.             ;
    183.     }
    184. }
    复制代码
    把emwin里面对应的几个操作底层的函数与我们之前的LCD和触摸连接起来。其中要这样的是:
    1、本LCD硬件无读的功能,具体实现的函数可以不写
    2、触摸芯片读取的x,y位置与GUI里面元件的位置是否对应,不对应需要稍微转换一下,如果自己用GUI TOOL 生成,可在设置是指定整个画面的起始结束坐标位置。
    gui_config.h 里面内容默认,未做修改。
    好了,到此,我们就完成了emwin的移植。我们在mian.c里面添加一下代码测试一下:
    1. /**
    2. * @file    seekfreePrj_demo.c
    3. * @brief   Application entry point.
    4. */

    5. #include <stdio.h>
    6. #include "board.h"
    7. #include "peripherals.h"
    8. #include "pin_mux.h"
    9. #include "clock_config.h"
    10. #include "LPC55S69_cm33_core0.h"
    11. #include "fsl_debug_console.h"
    12. /* TODO: insert other include files here. */
    13. #include "sd.h"
    14. #include "ff.h"
    15. #include "diskio.h"
    16. #include "fsl_sd_disk.h"
    17. #include "semphr.h"
    18. #include "task.h"

    19. #include "delay.h"
    20. #include "led.h"
    21. #include "key.h"
    22. #include "ft6366_i2ctouch.h"
    23. #include "ili9341_lcd.h"


    24. #include <emwin_support.h>
    25. #include "GUI.h"
    26. #include "BUTTON.h"
    27. #include "CHECKBOX.h"
    28. #include "SLIDER.h"
    29. #include "DROPDOWN.h"
    30. #include "RADIO.h"
    31. #include "MULTIPAGE.h"
    32. #include <stdbool.h>


    33. /* TODO: insert other definitions and declarations here. */

    34. #ifndef GUI_NORMAL_FONT
    35. #define GUI_NORMAL_FONT (&GUI_Font16_ASCII)
    36. #endif

    37. #ifndef GUI_LARGE_FONT
    38. #define GUI_LARGE_FONT (&GUI_Font16B_ASCII)
    39. #endif

    40. #ifndef GUI_SCALE_FACTOR
    41. #define GUI_SCALE_FACTOR 1
    42. #endif

    43. #ifndef GUI_SCALE_FACTOR_X
    44. #define GUI_SCALE_FACTOR_X GUI_SCALE_FACTOR
    45. #endif

    46. #ifndef GUI_SCALE_FACTOR_Y
    47. #define GUI_SCALE_FACTOR_Y GUI_SCALE_FACTOR
    48. #endif

    49. #define GUI_SCALE(a) ((int)((a) * (GUI_SCALE_FACTOR)))
    50. #define GUI_SCALE_X(x) ((int)((x) * (GUI_SCALE_FACTOR_X)))
    51. #define GUI_SCALE_Y(y) ((int)((y) * (GUI_SCALE_FACTOR_Y)))
    52. #define GUI_SCALE_COORDS(x, y) GUI_SCALE_X(x), GUI_SCALE_Y(y)
    53. #define GUI_SCALE_RECT(x0, y0, xs, ys) GUI_SCALE_X(x0), GUI_SCALE_Y(y0), GUI_SCALE_X(xs), GUI_SCALE_Y(ys)

    54. #define GUI_ID_DRAWAREA (GUI_ID_USER + 0)
    55. #define GUI_ID_PAGEWIN1 (GUI_ID_USER + 1)
    56. #define GUI_ID_PAGEWIN2 (GUI_ID_USER + 2)


    57. static DROPDOWN_Handle hDropdown0;
    58. static RADIO_Handle hRadio0;
    59. static CHECKBOX_Handle hCheck0;
    60. static WM_HWIN hDrawArea;

    61. static SLIDER_Handle hSlider0;
    62. static SLIDER_Handle hSlider1;
    63. static SPINBOX_Handle hSpinbox0;
    64. static PROGBAR_Handle hProgbar0;

    65. static const GUI_COLOR color_list[]      = {GUI_BLACK,   GUI_YELLOW, GUI_ORANGE, GUI_RED,
    66.                                        GUI_MAGENTA, GUI_BLUE,   GUI_CYAN,   GUI_GREEN};
    67. static const GUI_POINT triangle_points[] = {
    68.     {GUI_SCALE(0), GUI_SCALE(0)}, {GUI_SCALE(-50), GUI_SCALE(100)}, {GUI_SCALE(50), GUI_SCALE(100)}};

    69. static void cbDrawArea(WM_MESSAGE *pMsg)
    70. {
    71.     switch (pMsg->MsgId)
    72.     {
    73.         case WM_PAINT:
    74.             GUI_SetColor(color_list[DROPDOWN_GetSel(hDropdown0)]);
    75.             switch (RADIO_GetValue(hRadio0))
    76.             {
    77.                 case 0:
    78.                     if (CHECKBOX_GetState(hCheck0))
    79.                     {
    80.                         GUI_FillRect(GUI_SCALE_X(70) - GUI_SCALE(50), GUI_SCALE_Y(70) - GUI_SCALE(50),
    81.                                      GUI_SCALE_X(70) + GUI_SCALE(50), GUI_SCALE_Y(70) + GUI_SCALE(50));
    82.                     }
    83.                     else
    84.                     {
    85.                         GUI_DrawRect(GUI_SCALE_X(70) - GUI_SCALE(50), GUI_SCALE_Y(70) - GUI_SCALE(50),
    86.                                      GUI_SCALE_X(70) + GUI_SCALE(50), GUI_SCALE_Y(70) + GUI_SCALE(50));
    87.                     }
    88.                     break;
    89.                 case 1:
    90.                     if (CHECKBOX_GetState(hCheck0))
    91.                     {
    92.                         GUI_FillPolygon(triangle_points, 3, GUI_SCALE_COORDS(70, 20));
    93.                     }
    94.                     else
    95.                     {
    96.                         GUI_DrawPolygon(triangle_points, 3, GUI_SCALE_COORDS(70, 20));
    97.                     }
    98.                     break;
    99.                 case 2:
    100.                     if (CHECKBOX_GetState(hCheck0))
    101.                     {
    102.                         GUI_FillEllipse(GUI_SCALE_COORDS(70, 70), GUI_SCALE(50), GUI_SCALE(50));
    103.                     }
    104.                     else
    105.                     {
    106.                         GUI_DrawEllipse(GUI_SCALE_COORDS(70, 70), GUI_SCALE(50), GUI_SCALE(50));
    107.                     }
    108.                     break;
    109.             }
    110.             break;
    111.         default:
    112.             WM_DefaultProc(pMsg);
    113.             break;
    114.     }
    115. }

    116. static void cbPageWin1(WM_MESSAGE *pMsg)
    117. {
    118.     int NCode;
    119.     int Id;

    120.     switch (pMsg->MsgId)
    121.     {
    122.         case WM_NOTIFY_PARENT:
    123.             Id    = WM_GetId(pMsg->hWinSrc);
    124.             NCode = pMsg->Data.v;

    125.             switch (Id)
    126.             {
    127.                 case GUI_ID_RADIO0:
    128.                     switch (NCode)
    129.                     {
    130.                         case WM_NOTIFICATION_VALUE_CHANGED:
    131.                             WM_InvalidateWindow(hDrawArea);
    132.                             break;
    133.                     }
    134.                     break;

    135.                 case GUI_ID_DROPDOWN0:
    136.                     switch (NCode)
    137.                     {
    138.                         case WM_NOTIFICATION_SEL_CHANGED:
    139.                             WM_InvalidateWindow(hDrawArea);
    140.                             break;
    141.                     }
    142.                     break;

    143.                 case GUI_ID_CHECK0:
    144.                     switch (NCode)
    145.                     {
    146.                         case WM_NOTIFICATION_VALUE_CHANGED:
    147.                             WM_InvalidateWindow(hDrawArea);
    148.                             break;
    149.                     }
    150.                     break;
    151.             }
    152.             break;

    153.         default:
    154.             WM_DefaultProc(pMsg);
    155.             break;
    156.     }
    157. }

    158. static void cbPageWin2(WM_MESSAGE *pMsg)
    159. {
    160.     int NCode;
    161.     int Id;

    162.     switch (pMsg->MsgId)
    163.     {
    164.         case WM_NOTIFY_PARENT:
    165.             Id    = WM_GetId(pMsg->hWinSrc);
    166.             NCode = pMsg->Data.v;

    167.             switch (Id)
    168.             {
    169.                 case GUI_ID_SLIDER0:
    170.                     switch (NCode)
    171.                     {
    172.                         case WM_NOTIFICATION_VALUE_CHANGED:
    173.                             PROGBAR_SetValue(hProgbar0, SLIDER_GetValue(hSlider0));
    174.                             break;
    175.                     }
    176.                     break;

    177.                 case GUI_ID_SLIDER1:
    178.                     switch (NCode)
    179.                     {
    180.                         case WM_NOTIFICATION_VALUE_CHANGED:
    181.                             SPINBOX_SetValue(hSpinbox0, SLIDER_GetValue(hSlider1));
    182.                             break;
    183.                     }
    184.                     break;

    185.                 case GUI_ID_SPINBOX0:
    186.                     switch (NCode)
    187.                     {
    188.                         case WM_NOTIFICATION_VALUE_CHANGED:
    189.                             SLIDER_SetValue(hSlider1, SPINBOX_GetValue(hSpinbox0));
    190.                             break;
    191.                     }
    192.                     break;
    193.             }
    194.             break;

    195.         default:
    196.             WM_DefaultProc(pMsg);
    197.             break;
    198.     }
    199. }

    200. /*
    201. * @brief   Application entry point.
    202. */
    203. int main(void) {

    204.           /* Init board hardware. */
    205.     BOARD_InitBootPins();
    206.     BOARD_InitBootClocks();
    207.     BOARD_InitBootPeripherals();
    208. #ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
    209.     /* Init FSL debug console. */
    210.     BOARD_InitDebugConsole();
    211. #endif

    212.     LED_Init();
    213.     KEY_Init();
    214.     //MySD_Init();

    215.     PRINTF("the systemclock is: %d Mhz\n",SystemCoreClock/1000000);
    216.     PRINTF("the for1mclock is: %d Mhz\n",CLOCK_GetFro1MFreq()/1000000);

    217.     PRINTF("FATFS SDCard example.\r\n");

    218.         fatfs_sdcard_init();
    219.         fatfs_sdcard_mkdir("/dir");
    220.         fatfs_sdcard_writetxt("/dir/test.txt",(char*)("Helloworld!\r\n"));
    221.         fatfs_sdcard_readtxt("/dir/test.txt",strlen("Helloworld!\r\n"));
    222.         PRINTF("THE SEND STR3 LEN IS %d.\r\n",strlen("Helloworld!\r\n"));
    223.         fatfs_sdcard_readMaxtxt("/dir/test.txt");
    224.         //fatfs_sdcard_readdir((char*)("2:/dir"));
    225.         fatfs_sdcard_readdir((char*)("2:/"));

    226.         ft6366_i2ctouch_Init();
    227.         ili9341_lcd_init();
    复制代码
    编译生成,下载,查看LCD输出:
    A1.jpg
    A2.jpg
    A3.jpg
    A4.jpg
    A5.jpg
    A6.jpg

    触摸,拖到,均可改变对应值,好了emwin的移植就到这里了。
    谢谢大家观看!


    哎...今天够累的,签到来了~
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-4-16 19:49 , Processed in 0.121115 second(s), 19 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表