AnsweredAssumed Answered

NXP 54628 emwin problem

Question asked by Mateusz Kiełbasa on Feb 2, 2019
Latest reply on Feb 6, 2019 by Mateusz Kiełbasa

Hi!

 

I'm a newbie in NXP 546XX boards. I have a NXP 54628 development board with built in LCD and touch screen. I'm running SDK examples called touch and draw and it's my "source point" for own modifications. I'd like to create slider and handle touch only. There is modificated sdk example:

 

 

/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2018 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/* Standard C Included Files */
#include <stdio.h>
#include <string.h>
#include "board.h"
#include "fsl_debug_console.h"
#include "emwin_support.h"

#include "GUI.h"
#include "GUIDRV_Lin.h"
#include "BUTTON.h"
#include "SLIDER.h"

#include "pin_mux.h"
#include "fsl_sctimer.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define EXAMPLE_I2C_MASTER_BASE (I2C2_BASE)
#define I2C_MASTER_CLOCK_FREQUENCY (12000000)

#define SDRAM_BASE_ADDR 0xa0000000
#define SDRAM_SIZE_BYTES (8 * 1024 * 1024)

#define APP_LCD LCD
#define APP_LCD_IRQHandler LCD_IRQHandler
#define APP_LCD_IRQn LCD_IRQn

#define LCD_PANEL_CLK 9000000
#define LCD_PPL 480
#define LCD_HSW 2
#define LCD_HFP 8
#define LCD_HBP 43
#define LCD_LPP 272
#define LCD_VSW 10
#define LCD_VFP 4
#define LCD_VBP 12
#define LCD_POL_FLAGS kLCDC_InvertVsyncPolarity | kLCDC_InvertHsyncPolarity
#define LCD_INPUT_CLK_FREQ CLOCK_GetFreq(kCLOCK_LCD)
#define LCD_WIDTH 480
#define LCD_HEIGHT 272
#define LCD_BITS_PER_PIXEL 16

/* Work memory for emWin */
#define GUI_NUMBYTES 0x20000
#define GUI_MEMORY_ADDR (SDRAM_BASE_ADDR)

/* Display framebuffer */
#define GUI_BUFFERS 2
#define VRAM_ADDR (GUI_MEMORY_ADDR + GUI_NUMBYTES)
#define VRAM_SIZE (LCD_HEIGHT * LCD_WIDTH * LCD_BITS_PER_PIXEL / 8)

/*******************************************************************************
* Prototypes
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/
#define CLEAR_BUTTON_ID (GUI_ID_BUTTON0)

#define COLOR_BUTTONS 8
#define COLOR_BUTTON_FIRST_ID (GUI_ID_USER)
#define COLOR_BUTTON_LAST_ID (COLOR_BUTTON_FIRST_ID + COLOR_BUTTONS - 1)

static GUI_COLOR button_color[COLOR_BUTTONS] = {GUI_WHITE, GUI_YELLOW, GUI_ORANGE, GUI_RED,
GUI_MAGENTA, GUI_BLUE, GUI_GREEN, GUI_BLACK};

/*******************************************************************************
* Code
******************************************************************************/
void BOARD_InitPWM(void)
{
sctimer_config_t config;
sctimer_pwm_signal_param_t pwmParam;
uint32_t event;

CLOCK_AttachClk(kMAIN_CLK_to_SCT_CLK);

CLOCK_SetClkDiv(kCLOCK_DivSctClk, 2, true);

SCTIMER_GetDefaultConfig(&config);

SCTIMER_Init(SCT0, &config);

pwmParam.output = kSCTIMER_Out_5;
pwmParam.level = kSCTIMER_HighTrue;
pwmParam.dutyCyclePercent = 5;

SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 1000U, CLOCK_GetFreq(kCLOCK_Sct), &event);
}


static void cbBackgroundWin(WM_MESSAGE *pMsg)
{
int widget_id;

switch (pMsg->MsgId)
{
case WM_NOTIFY_PARENT:
widget_id = WM_GetId(pMsg->hWinSrc);
if (widget_id >= COLOR_BUTTON_FIRST_ID && widget_id <= COLOR_BUTTON_LAST_ID)
{
GUI_SetColor(button_color[widget_id - COLOR_BUTTON_FIRST_ID]);
}
else if (widget_id == CLEAR_BUTTON_ID && pMsg->Data.v == WM_NOTIFICATION_CLICKED)
{
GUI_Clear();
}
break;
default:
WM_DefaultProc(pMsg);
}
}

static void cbCanvasWin(WM_MESSAGE *pMsg)
{
GUI_PID_STATE *pid_state;
static GUI_PID_STATE pid_state_0;

switch (pMsg->MsgId)
{
case WM_PID_STATE_CHANGED:
pid_state = (GUI_PID_STATE *)pMsg->Data.p;
if (pid_state->Pressed)
{
GUI_DrawPoint(pid_state->x, pid_state->y);
}
pid_state_0 = *pid_state;
break;
case WM_TOUCH:
pid_state = (GUI_PID_STATE *)pMsg->Data.p;
if (pid_state->Pressed)
{
if (pid_state_0.Pressed)
{
GUI_DrawLine(pid_state_0.x, pid_state_0.y, pid_state->x, pid_state->y);
}
}
pid_state_0 = *pid_state;
break;
case WM_MOUSEOVER_END:
pid_state = (GUI_PID_STATE *)pMsg->Data.p;
pid_state_0 = *pid_state;
break;
default:
WM_DefaultProc(pMsg);
}
}

int main(void)
{
int i;

/* Board pin, clock, debug console init */
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

/* Route Main clock to LCD. */
CLOCK_AttachClk(kMAIN_CLK_to_LCD_CLK);

/* attach 12 MHz clock to FLEXCOMM2 (I2C master for touch controller) */
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);

CLOCK_EnableClock(kCLOCK_Gpio2);

CLOCK_SetClkDiv(kCLOCK_DivLcdClk, 1, true);

BOARD_InitPins();
BOARD_BootClockPLL220M();
BOARD_InitDebugConsole();
BOARD_InitSDRAM();

/* Set the back light PWM. */
BOARD_InitPWM();

 

/* emWin start */
GUI_Init();
GUI_Clear();
SLIDER_Handle handle;
handle = SLIDER_Create(20, 20, 200, 40, 0, 10, WM_CF_SHOW, 0);

while (1)
{
/* Poll touch controller for update */
if (BOARD_Touch_Poll())
{
GUI_MULTIBUF_Begin();
WM_Exec();
GUI_MULTIBUF_End();
}
}
}

 

When I flash the program the slider appears and touch is detected (I can move it) but there is a huge problem with it. It's hard to say but it is not "clearing" it's previous states. What I am doing wrong? Should I have reload it or something?

 

The other problem is with GUI_Delay(). It also simply doesn't work. When I use it everything stuck (checked in debbugger. I cannot step over GUI_Delay function). When I use simple loop with incrementing value as pseudo delay everythink work fine. Every help will be appreciated

Best regards!

Outcomes