211 lines
4.8 KiB
C
211 lines
4.8 KiB
C
/*
|
|
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
|
* Copyright 2016-2017 NXP
|
|
* All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
/* Standard C Included Files */
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "pin_mux.h"
|
|
#include "clock_config.h"
|
|
#include "board.h"
|
|
#include "fsl_debug_console.h"
|
|
#include "emwin_support.h"
|
|
|
|
#include "GUI.h"
|
|
#include "GUIDRV_Lin.h"
|
|
#include "BUTTON.h"
|
|
|
|
#include "fsl_gpio.h"
|
|
#include "fsl_gpt.h"
|
|
/*******************************************************************************
|
|
* Definitions
|
|
******************************************************************************/
|
|
|
|
/*******************************************************************************
|
|
* Prototypes
|
|
******************************************************************************/
|
|
void BOARD_EnableLcdInterrupt(void);
|
|
|
|
/*******************************************************************************
|
|
* Variables
|
|
******************************************************************************/
|
|
|
|
/*******************************************************************************
|
|
* Code
|
|
******************************************************************************/
|
|
|
|
/* Initialize the LCD_DISP. */
|
|
void BOARD_InitLcd(void)
|
|
{
|
|
volatile uint32_t i = 0x1000U;
|
|
|
|
gpio_pin_config_t config = {
|
|
kGPIO_DigitalOutput,
|
|
0,
|
|
kGPIO_NoIntmode,
|
|
};
|
|
|
|
/* Reset the LCD. */
|
|
GPIO_PinInit(LCD_DISP_GPIO, LCD_DISP_GPIO_PIN, &config);
|
|
|
|
GPIO_WritePinOutput(LCD_DISP_GPIO, LCD_DISP_GPIO_PIN, 0);
|
|
|
|
while (i--)
|
|
{
|
|
}
|
|
|
|
GPIO_WritePinOutput(LCD_DISP_GPIO, LCD_DISP_GPIO_PIN, 1);
|
|
|
|
/* Backlight. */
|
|
config.outputLogic = 1;
|
|
GPIO_PinInit(LCD_BL_GPIO, LCD_BL_GPIO_PIN, &config);
|
|
|
|
/*Clock setting for LPI2C*/
|
|
CLOCK_SetMux(kCLOCK_Lpi2cMux, LPI2C_CLOCK_SOURCE_SELECT);
|
|
CLOCK_SetDiv(kCLOCK_Lpi2cDiv, LPI2C_CLOCK_SOURCE_DIVIDER);
|
|
}
|
|
|
|
void BOARD_InitLcdifPixelClock(void)
|
|
{
|
|
/*
|
|
* The desired output frame rate is 60Hz. So the pixel clock frequency is:
|
|
* (480 + 41 + 4 + 18) * (272 + 10 + 4 + 2) * 60 = 9.2M.
|
|
* Here set the LCDIF pixel clock to 9.3M.
|
|
*/
|
|
|
|
/*
|
|
* Initialize the Video PLL.
|
|
* Video PLL output clock is OSC24M * (loopDivider + (denominator / numerator)) / postDivider = 93MHz.
|
|
*/
|
|
clock_video_pll_config_t config = {
|
|
.loopDivider = 31,
|
|
.postDivider = 8,
|
|
.numerator = 0,
|
|
.denominator = 0,
|
|
};
|
|
|
|
CLOCK_InitVideoPll(&config);
|
|
|
|
/*
|
|
* 000 derive clock from PLL2
|
|
* 001 derive clock from PLL3 PFD3
|
|
* 010 derive clock from PLL5
|
|
* 011 derive clock from PLL2 PFD0
|
|
* 100 derive clock from PLL2 PFD1
|
|
* 101 derive clock from PLL3 PFD1
|
|
*/
|
|
CLOCK_SetMux(kCLOCK_LcdifPreMux, 2);
|
|
|
|
CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 4);
|
|
|
|
CLOCK_SetDiv(kCLOCK_LcdifDiv, 1);
|
|
}
|
|
|
|
void BOARD_InitGPT(void)
|
|
{
|
|
gpt_config_t gptConfig;
|
|
|
|
GPT_GetDefaultConfig(&gptConfig);
|
|
|
|
gptConfig.enableFreeRun = true;
|
|
gptConfig.divider = 3000;
|
|
|
|
/* Initialize GPT module */
|
|
GPT_Init(EXAMPLE_GPT, &gptConfig);
|
|
GPT_StartTimer(EXAMPLE_GPT);
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
{
|
|
int termWidth;
|
|
int termHeight;
|
|
|
|
int charWidth;
|
|
int lineHeight;
|
|
|
|
int c = 0;
|
|
int c_prev = 0;
|
|
|
|
/* Board pin, clock, debug console init */
|
|
BOARD_ConfigMPU();
|
|
BOARD_InitBootPins();
|
|
BOARD_InitBootClocks();
|
|
BOARD_InitLcdifPixelClock();
|
|
BOARD_InitDebugConsole();
|
|
BOARD_InitLcd();
|
|
BOARD_InitGPT();
|
|
|
|
/* emWin start */
|
|
GUI_Init();
|
|
|
|
WM_SetSize(WM_HBKWIN, LCD_WIDTH, LCD_HEIGHT);
|
|
|
|
/* Solid color display */
|
|
GUI_SetBkColor(GUI_WHITE);
|
|
GUI_Clear();
|
|
|
|
GUI_MULTIBUF_Begin();
|
|
GUI_Exec();
|
|
GUI_MULTIBUF_End();
|
|
|
|
GUI_SetColor(GUI_BLACK);
|
|
|
|
termWidth = WM_GetWindowSizeX(0);
|
|
termHeight = WM_GetWindowSizeY(0);
|
|
|
|
GUI_SetFont(GUI_FONT_8X16);
|
|
lineHeight = GUI_GetFontDistY();
|
|
charWidth = GUI_GetCharDistX('_');
|
|
|
|
GUI_DispString("Waiting for data - connect using serial terminal\n>");
|
|
|
|
for (;;)
|
|
{
|
|
/* show cursor */
|
|
GUI_MULTIBUF_Begin();
|
|
GUI_DispChar('_');
|
|
GUI_GotoX(GUI_GetDispPosX() - charWidth);
|
|
GUI_MULTIBUF_End();
|
|
|
|
c = GETCHAR();
|
|
if (c == '\r')
|
|
{
|
|
/* translate CR to LF */
|
|
c_prev = c;
|
|
c = '\n';
|
|
}
|
|
else if (c == '\n' && c_prev == '\r')
|
|
{
|
|
/* ignore LF following CR */
|
|
c_prev = c;
|
|
continue;
|
|
}
|
|
c_prev = c;
|
|
|
|
/* hide cursor */
|
|
GUI_MULTIBUF_Begin();
|
|
GUI_DispChar(' ');
|
|
GUI_GotoX(GUI_GetDispPosX() - charWidth);
|
|
|
|
GUI_DispChar(c);
|
|
|
|
if (GUI_GetDispPosX() >= termWidth)
|
|
{
|
|
GUI_DispNextLine();
|
|
}
|
|
|
|
if (GUI_GetDispPosY() + lineHeight > termHeight)
|
|
{
|
|
GUI_Clear();
|
|
GUI_GotoY(0);
|
|
}
|
|
GUI_MULTIBUF_End();
|
|
}
|
|
}
|