mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-19 05:51:24 +08:00
Merge pull request #1529 from TanekLiang/imxrt-lcd-update
[bsp][imxrt1052] update lcd driver and add lcd init code
This commit is contained in:
commit
35a0e8e8c9
42
bsp/imxrt1052-evk/applications/lcd_init.c
Normal file
42
bsp/imxrt1052-evk/applications/lcd_init.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* File : lcd_init.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2018-06-12 Tanek first version
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
#if defined(PKG_USING_GUIENGINE)
|
||||||
|
|
||||||
|
#include <rtgui/driver.h>
|
||||||
|
int lcd_init(void)
|
||||||
|
{
|
||||||
|
struct rt_device *device;
|
||||||
|
device = rt_device_find("lcd");
|
||||||
|
if (device)
|
||||||
|
{
|
||||||
|
rtgui_graphic_set_device(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
INIT_APP_EXPORT(lcd_init);
|
||||||
|
#endif
|
@ -20,16 +20,16 @@
|
|||||||
#include "fsl_elcdif.h"
|
#include "fsl_elcdif.h"
|
||||||
|
|
||||||
#if !defined(LCD_WIDTH) || !defined(LCD_HEIGHT)
|
#if !defined(LCD_WIDTH) || !defined(LCD_HEIGHT)
|
||||||
#error "Please config lcd pixel parameters."
|
#error "Please config lcd pixel parameters."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(LCD_HFP) || !defined(LCD_HBP) || !defined(LCD_HSW) || \
|
#if !defined(LCD_HFP) || !defined(LCD_HBP) || !defined(LCD_HSW) || \
|
||||||
!defined(LCD_VFP) || !defined(LCD_VBP) || !defined(LCD_VSW)
|
!defined(LCD_VFP) || !defined(LCD_VBP) || !defined(LCD_VSW)
|
||||||
#error "Please config lcd timing parameters."
|
#error "Please config lcd timing parameters."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(LCD_BL_PIN) || !defined(LCD_RST_PIN)
|
#if !defined(LCD_BL_PIN) || !defined(LCD_RST_PIN)
|
||||||
#error "Please config lcd backlight or reset pin."
|
#error "Please config lcd backlight or reset pin."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct rt1050_lcd
|
struct rt1050_lcd
|
||||||
@ -47,69 +47,87 @@ static rt_err_t rt1050_lcd_init(rt_device_t device)
|
|||||||
|
|
||||||
rt_memset(frame_buffer, 0x00, sizeof(frame_buffer));
|
rt_memset(frame_buffer, 0x00, sizeof(frame_buffer));
|
||||||
|
|
||||||
|
|
||||||
/* DeInit Video PLL. */
|
/* DeInit Video PLL. */
|
||||||
CLOCK_DeinitVideoPll();
|
CLOCK_DeinitVideoPll();
|
||||||
/* Bypass Video PLL. */
|
|
||||||
CCM_ANALOG->PLL_VIDEO |= CCM_ANALOG_PLL_VIDEO_BYPASS_MASK;
|
/*
|
||||||
/* Set divider for Video PLL. */
|
* Initialize the Video PLL.
|
||||||
CCM_ANALOG->MISC2 = (CCM_ANALOG->MISC2 & (~CCM_ANALOG_MISC2_VIDEO_DIV_MASK)) | CCM_ANALOG_MISC2_VIDEO_DIV(0);
|
* Video PLL output clock is OSC24M * (loopDivider + (denominator / numerator)) / postDivider = 93MHz.
|
||||||
/* Enable Video PLL output. */
|
*/
|
||||||
CCM_ANALOG->PLL_VIDEO |= CCM_ANALOG_PLL_VIDEO_ENABLE_MASK;
|
clock_video_pll_config_t config =
|
||||||
|
{
|
||||||
|
.loopDivider = 31, .postDivider = 8, .numerator = 0, .denominator = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
/* GPIO */
|
/* GPIO */
|
||||||
CLOCK_EnableClock(kCLOCK_Iomuxc);
|
CLOCK_EnableClock(kCLOCK_Iomuxc);
|
||||||
|
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_04_LCD_DATA00, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_04_LCD_DATA00, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_04_LCD_DATA00, 0x01B0B0U); /* LCD_B3 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_04_LCD_DATA00, 0x01B0B0U); /* LCD_B3 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_05_LCD_DATA01, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_05_LCD_DATA01, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_05_LCD_DATA01, 0x01B0B0U); /* LCD_B4 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_05_LCD_DATA01, 0x01B0B0U); /* LCD_B4 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_06_LCD_DATA02, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_06_LCD_DATA02, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_06_LCD_DATA02, 0x01B0B0U); /* LCD_B5 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_06_LCD_DATA02, 0x01B0B0U); /* LCD_B5 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_07_LCD_DATA03, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_07_LCD_DATA03, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_07_LCD_DATA03, 0x01B0B0U); /* LCD_B6 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_07_LCD_DATA03, 0x01B0B0U); /* LCD_B6 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_08_LCD_DATA04, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_08_LCD_DATA04, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_08_LCD_DATA04, 0x01B0B0U); /* LCD_B7 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_08_LCD_DATA04, 0x01B0B0U); /* LCD_B7 */
|
||||||
|
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_09_LCD_DATA05, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_09_LCD_DATA05, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_09_LCD_DATA05, 0x01B0B0U); /* LCD_G2 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_09_LCD_DATA05, 0x01B0B0U); /* LCD_G2 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_10_LCD_DATA06, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_10_LCD_DATA06, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_10_LCD_DATA06, 0x01B0B0U); /* LCD_G3 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_10_LCD_DATA06, 0x01B0B0U); /* LCD_G3 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_11_LCD_DATA07, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_11_LCD_DATA07, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_11_LCD_DATA07, 0x01B0B0U); /* LCD_G4 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_11_LCD_DATA07, 0x01B0B0U); /* LCD_G4 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_12_LCD_DATA08, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_12_LCD_DATA08, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_12_LCD_DATA08, 0x01B0B0U); /* LCD_G5 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_12_LCD_DATA08, 0x01B0B0U); /* LCD_G5 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_13_LCD_DATA09, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_13_LCD_DATA09, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_13_LCD_DATA09, 0x01B0B0U); /* LCD_G6 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_13_LCD_DATA09, 0x01B0B0U); /* LCD_G6 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_14_LCD_DATA10, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_14_LCD_DATA10, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_14_LCD_DATA10, 0x01B0B0U); /* LCD_G7 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_14_LCD_DATA10, 0x01B0B0U); /* LCD_G7 */
|
||||||
|
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_15_LCD_DATA11, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_15_LCD_DATA11, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_15_LCD_DATA11, 0x01B0B0U); /* LCD_R3 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_15_LCD_DATA11, 0x01B0B0U); /* LCD_R3 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B1_00_LCD_DATA12, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_00_LCD_DATA12, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_00_LCD_DATA12, 0x01B0B0U); /* LCD_R4 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_00_LCD_DATA12, 0x01B0B0U); /* LCD_R4 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B1_01_LCD_DATA13, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_01_LCD_DATA13, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_01_LCD_DATA13, 0x01B0B0U); /* LCD_R5 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_01_LCD_DATA13, 0x01B0B0U); /* LCD_R5 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B1_02_LCD_DATA14, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_02_LCD_DATA14, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_02_LCD_DATA14, 0x01B0B0U); /* LCD_R6 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_02_LCD_DATA14, 0x01B0B0U); /* LCD_R6 */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B1_03_LCD_DATA15, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_03_LCD_DATA15, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_03_LCD_DATA15, 0x01B0B0U); /* LCD_R7 */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_03_LCD_DATA15, 0x01B0B0U); /* LCD_R7 */
|
||||||
|
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_00_LCD_CLK, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_00_LCD_CLK, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_00_LCD_CLK, 0x01B0B0u); /* LCD_CLK */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_00_LCD_CLK, 0x01B0B0u); /* LCD_CLK */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_02_LCD_HSYNC, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_02_LCD_HSYNC, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_02_LCD_HSYNC, 0x01B0B0u); /* LCD_HSYNC */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_02_LCD_HSYNC, 0x01B0B0u); /* LCD_HSYNC */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_03_LCD_VSYNC, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_03_LCD_VSYNC, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_03_LCD_VSYNC, 0x01B0B0u); /* LCD_VSYNC */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_03_LCD_VSYNC, 0x01B0B0u); /* LCD_VSYNC */
|
||||||
IOMUXC_SetPinMux (IOMUXC_GPIO_B0_01_LCD_ENABLE, 0U);
|
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_01_LCD_ENABLE, 0U);
|
||||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_01_LCD_ENABLE, 0x01B0B0u); /* LCD_ENABLE */
|
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_01_LCD_ENABLE, 0x01B0B0u); /* LCD_ENABLE */
|
||||||
|
|
||||||
rt_pin_mode(LCD_RST_PIN, PIN_MODE_OUTPUT); /* LCD_RESET */
|
rt_pin_mode(LCD_RST_PIN, PIN_MODE_OUTPUT); /* LCD_RESET */
|
||||||
rt_pin_write(LCD_RST_PIN, PIN_LOW);
|
rt_pin_write(LCD_RST_PIN, PIN_LOW);
|
||||||
rt_thread_delay(RT_TICK_PER_SECOND/100);
|
rt_thread_delay(RT_TICK_PER_SECOND / 100);
|
||||||
rt_pin_write(LCD_RST_PIN, PIN_HIGH);
|
rt_pin_write(LCD_RST_PIN, PIN_HIGH);
|
||||||
|
|
||||||
rt_pin_mode (LCD_BL_PIN, PIN_MODE_OUTPUT); /* LCD_BL */
|
rt_pin_mode(LCD_BL_PIN, PIN_MODE_OUTPUT); /* LCD_BL */
|
||||||
rt_pin_write(LCD_BL_PIN, PIN_HIGH);
|
rt_pin_write(LCD_BL_PIN, PIN_HIGH);
|
||||||
|
|
||||||
/* LCD */
|
/* LCD */
|
||||||
@ -133,7 +151,7 @@ static rt_err_t rt1050_lcd_init(rt_device_t device)
|
|||||||
lcd_config.dataBus = kELCDIF_DataBus16Bit;
|
lcd_config.dataBus = kELCDIF_DataBus16Bit;
|
||||||
lcd_config.bufferAddr = (uint32_t)frame_buffer;
|
lcd_config.bufferAddr = (uint32_t)frame_buffer;
|
||||||
|
|
||||||
ELCDIF_RgbModeInit (LCDIF, &lcd_config);
|
ELCDIF_RgbModeInit(LCDIF, &lcd_config);
|
||||||
ELCDIF_RgbModeStart(LCDIF);
|
ELCDIF_RgbModeStart(LCDIF);
|
||||||
|
|
||||||
/* LCD DEVICE */
|
/* LCD DEVICE */
|
||||||
@ -148,7 +166,7 @@ static rt_err_t rt1050_lcd_init(rt_device_t device)
|
|||||||
|
|
||||||
static rt_err_t rt1050_lcd_control(rt_device_t device, int cmd, void *args)
|
static rt_err_t rt1050_lcd_control(rt_device_t device, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch(cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||||
break;
|
break;
|
||||||
@ -186,10 +204,8 @@ int rt_hw_lcd_init(void)
|
|||||||
|
|
||||||
lcd.device.user_data = (void *)&lcd.info;
|
lcd.device.user_data = (void *)&lcd.info;
|
||||||
|
|
||||||
rt1050_lcd_init(&lcd.device);
|
|
||||||
|
|
||||||
ret = rt_device_register(&lcd.device, "lcd", RT_DEVICE_FLAG_RDWR);
|
ret = rt_device_register(&lcd.device, "lcd", RT_DEVICE_FLAG_RDWR);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//INIT_DEVICE_EXPORT(rt_hw_lcd_init);
|
INIT_DEVICE_EXPORT(rt_hw_lcd_init);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user