diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/Kconfig b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/Kconfig index ad117f52c..76703a16e 100644 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/Kconfig +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/Kconfig @@ -301,7 +301,41 @@ menu "Onboard Peripheral Drivers" endif endif - + menuconfig BSP_USING_LCD_XIDATONG + bool "Enable LCD" + default n + if BSP_USING_LCD_XIDATONG + config LCD_WIDTH + int "display panel width, pixels per line" + default 480 + config LCD_HEIGHT + int "display panel height, how many lines per panel" + default 272 + config LCD_HFP + int "horizontal front porch" + default 4 + config LCD_HBP + int "horizontal back porch." + default 8 + config LCD_HSW + int " HSYNC pulse width" + default 41 + config LCD_VFP + int "Vrtical front porch" + default 4 + config LCD_VBP + int "Vertical back porch" + default 2 + config LCD_VSW + int "VSYNC pulse width" + default 10 + config LCD_BL_PIN + int "lcd backlight control pin number" + default 63 + config LCD_RST_PIN + int "lcd reset pin" + default 999 + endif endmenu diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript index 9592fcf7f..470f1ed26 100644 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/SConscript @@ -20,6 +20,10 @@ if GetDepend(['RT_USING_DFS_ROMFS']): src += ['ports/mnt_romfs.c'] if GetDepend('RT_USING_USB_HOST'): src += ['usb/drv_usbh.c'] +if GetDepend('BSP_USING_LCD_XIDATONG'): + src += ['ports/ok1052lcd.c'] + src += ['ports/drv_lcd.c'] + src += ['../../../../rt-thread/bsp/imxrt/libraries/MIMXRT1050/MIMXRT1052/drivers/fsl_elcdif.c'] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES) Return('group') diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c index 032c6b45a..be037421a 100644 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/board.c @@ -1081,6 +1081,286 @@ void imxrt_can2_pins_init(void) } #endif +#ifdef BSP_USING_LCD_XIDATONG +void imxrt_lcd_pins_init(void) +{ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_00_LCD_CLK, /* GPIO_B0_00 is configured as LCD_CLK */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_01_LCD_ENABLE, /* GPIO_B0_01 is configured as LCD_ENABLE */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_02_LCD_HSYNC, /* GPIO_B0_02 is configured as LCD_HSYNC */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_03_LCD_VSYNC, /* GPIO_B0_03 is configured as LCD_VSYNC */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_04_LCD_DATA00, /* GPIO_B0_04 is configured as LCD_DATA00 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_05_LCD_DATA01, /* GPIO_B0_05 is configured as LCD_DATA01 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_06_LCD_DATA02, /* GPIO_B0_06 is configured as LCD_DATA02 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_07_LCD_DATA03, /* GPIO_B0_07 is configured as LCD_DATA03 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_08_LCD_DATA04, /* GPIO_B0_08 is configured as LCD_DATA04 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_09_LCD_DATA05, /* GPIO_B0_09 is configured as LCD_DATA05 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_10_LCD_DATA06, /* GPIO_B0_10 is configured as LCD_DATA06 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_11_LCD_DATA07, /* GPIO_B0_11 is configured as LCD_DATA07 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_12_LCD_DATA08, /* GPIO_B0_12 is configured as LCD_DATA08 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_13_LCD_DATA09, /* GPIO_B0_13 is configured as LCD_DATA09 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_14_LCD_DATA10, /* GPIO_B0_14 is configured as LCD_DATA10 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B0_15_LCD_DATA11, /* GPIO_B0_15 is configured as LCD_DATA11 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B1_00_LCD_DATA12, /* GPIO_B1_00 is configured as LCD_DATA12 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B1_01_LCD_DATA13, /* GPIO_B1_01 is configured as LCD_DATA13 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B1_02_LCD_DATA14, /* GPIO_B1_02 is configured as LCD_DATA14 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B1_03_LCD_DATA15, /* GPIO_B1_03 is configured as LCD_DATA15 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinMux( + IOMUXC_GPIO_B1_15_GPIO2_IO31, /* GPIO_B1_15 is configured as GPIO2_IO31 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_00_LCD_CLK, /* GPIO_B0_00 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_01_LCD_ENABLE, /* GPIO_B0_01 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_02_LCD_HSYNC, /* GPIO_B0_02 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_03_LCD_VSYNC, /* GPIO_B0_03 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_04_LCD_DATA00, /* GPIO_B0_04 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_05_LCD_DATA01, /* GPIO_B0_05 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_06_LCD_DATA02, /* GPIO_B0_06 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_07_LCD_DATA03, /* GPIO_B0_07 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_08_LCD_DATA04, /* GPIO_B0_08 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_09_LCD_DATA05, /* GPIO_B0_09 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_10_LCD_DATA06, /* GPIO_B0_10 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_11_LCD_DATA07, /* GPIO_B0_11 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_12_LCD_DATA08, /* GPIO_B0_12 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_13_LCD_DATA09, /* GPIO_B0_13 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_14_LCD_DATA10, /* GPIO_B0_14 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B0_15_LCD_DATA11, /* GPIO_B0_15 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B1_00_LCD_DATA12, /* GPIO_B1_00 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B1_01_LCD_DATA13, /* GPIO_B1_01 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B1_02_LCD_DATA14, /* GPIO_B1_02 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B1_03_LCD_DATA15, /* GPIO_B1_03 PAD functional properties : */ + 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Pull + Pull Up / Down Config. Field: 100K Ohm Pull Up + Hyst. Enable Field: Hysteresis Enabled */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_B1_15_GPIO2_IO31, /* GPIO_B1_15 PAD functional properties : */ + 0x10B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Keeper + Pull Up / Down Config. Field: 100K Ohm Pull Down + Hyst. Enable Field: Hysteresis Disabled */ + +} +#endif + void rt_hw_board_init() { BOARD_ConfigMPU(); @@ -1121,6 +1401,10 @@ void rt_hw_board_init() imxrt_can2_pins_init(); #endif +#ifdef BSP_USING_LCD_XIDATONG + imxrt_lcd_pins_init(); +#endif + #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_lcd.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_lcd.c new file mode 100644 index 000000000..12e5e58d6 --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_lcd.c @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017-10-30 Tanek the first version + * 2018-04-05 Liu2guang export LCD config parameters. + */ + +#include + +#ifdef BSP_USING_LCD_XIDATONG +#ifdef RT_USING_POSIX +#include +#include +#ifdef RT_USING_POSIX_TERMIOS +#include +#endif +#endif +#include "drv_lcd.h" +#include "fsl_common.h" +#include "fsl_iomuxc.h" +#include "fsl_elcdif.h" +#include "drv_gpio.h" +#if !defined(LCD_WIDTH) || !defined(LCD_HEIGHT) +#error "Please config lcd pixel parameters." +#endif + +#if !defined(LCD_HFP) || !defined(LCD_HBP) || !defined(LCD_HSW) || \ + !defined(LCD_VFP) || !defined(LCD_VBP) || !defined(LCD_VSW) +#error "Please config lcd timing parameters." +#endif + +#if !defined(LCD_BL_PIN) || !defined(LCD_RST_PIN) +#error "Please config lcd backlight or reset pin." +#endif +#define DRV_DEBUG +#define LOG_TAG "drv.lcd" +#define DBG_LVL DBG_LOG +#include + +struct imxrt_lcd +{ + struct rt_device device; + struct rt_device_graphic_info info; +}; + +static struct imxrt_lcd lcd; +AT_NONCACHEABLE_SECTION_ALIGN(static uint16_t frame_buffer[LCD_HEIGHT][LCD_WIDTH], 64); + +static rt_err_t imxrt_lcd_init(rt_device_t device) +{ + RT_ASSERT(device != RT_NULL); + + rt_memset(frame_buffer, 0x00, sizeof(frame_buffer)); + clock_video_pll_config_t pll_config; + + pll_config.loopDivider = 43; + pll_config.postDivider = 4; + pll_config.numerator = 0; + pll_config.denominator = 0; + + CLOCK_InitVideoPll(&pll_config); + + rt_pin_mode(LCD_RST_PIN, PIN_MODE_OUTPUT); /* LCD_RESET */ + rt_pin_write(LCD_RST_PIN, PIN_LOW); + rt_thread_delay(RT_TICK_PER_SECOND / 100); + rt_pin_write(LCD_RST_PIN, PIN_HIGH); + + rt_pin_mode (LCD_BL_PIN, PIN_MODE_OUTPUT); /* LCD_BL */ + rt_pin_write(LCD_BL_PIN, PIN_HIGH); + + /* LCD */ + elcdif_rgb_mode_config_t lcd_config; + + lcd_config.hfp = LCD_HFP; + lcd_config.vfp = LCD_VFP; + lcd_config.hbp = LCD_HBP; + lcd_config.vbp = LCD_VBP; + lcd_config.hsw = LCD_HSW; + lcd_config.vsw = LCD_VSW; + + lcd_config.polarityFlags = kELCDIF_DataEnableActiveHigh | + kELCDIF_VsyncActiveHigh | + kELCDIF_HsyncActiveLow | + kELCDIF_DriveDataOnRisingClkEdge; + + lcd_config.panelWidth = LCD_WIDTH; + lcd_config.panelHeight = LCD_HEIGHT; + lcd_config.pixelFormat = kELCDIF_PixelFormatRGB565; + lcd_config.dataBus = kELCDIF_DataBus16Bit; + lcd_config.bufferAddr = (uint32_t)frame_buffer; + ELCDIF_RgbModeInit (LCDIF, &lcd_config); + ELCDIF_RgbModeStart(LCDIF); + + /* LCD DEVICE */ + lcd.info.width = LCD_WIDTH; + lcd.info.height = LCD_HEIGHT; + lcd.info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; + lcd.info.bits_per_pixel = 16; + lcd.info.framebuffer = (void *)frame_buffer; + LOG_I("imxrt lcd init success!!\n\r"); + return RT_EOK; +} + +static rt_err_t imxrt_lcd_control(rt_device_t device, int cmd, void *args) +{ + switch(cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + break; + + case RTGRAPHIC_CTRL_POWERON: + rt_pin_write(LCD_BL_PIN, PIN_HIGH); + break; + + case RTGRAPHIC_CTRL_POWEROFF: + rt_pin_write(LCD_BL_PIN, PIN_LOW); + break; + + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &lcd.info, sizeof(lcd.info)); + break; + + case RTGRAPHIC_CTRL_SET_MODE: + break; + } + + return RT_EOK; +} + + +static void drv_lcd_set_pixel_dot(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2, void* color) +{ + rt_uint16_t i = 0; + rt_uint16_t j = 0; + + for(i = y1; i <= y2; i++) + { + for(j = x1; j <= x2; j++) + { + frame_buffer[i][j] =(*(rt_uint16_t*)color); + (rt_uint16_t*)color += 1; + } + } +} + + + + +#ifdef RT_USING_POSIX +static int lcd_fops_open(struct dfs_fd *fd) +{ + rt_err_t ret = RT_EOK; + rt_uint16_t flags = 0; + rt_device_t device; + device = (rt_device_t)fd->data; + RT_ASSERT(device != RT_NULL); + flags = RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_RDWR; + ret = rt_device_open(device, flags); + if (ret == RT_EOK) + { + return RT_EOK; + } + else + { + return ret; + } +} + +static int lcd_fops_close(struct dfs_fd *fd) +{ + rt_device_t device; + device = (rt_device_t)fd->data; + rt_device_close(device); + return RT_EOK; +} + +static int lcd_fops_ioctl(struct dfs_fd *fd, int cmd, void *args) +{ + rt_device_t device; + device = (rt_device_t)fd->data; + return rt_device_control(device, cmd, args); +} + +static int lcd_fops_read(struct dfs_fd *fd, void *buf, size_t count) +{ + return count; +} + +static int lcd_fops_write(struct dfs_fd *fd, const void *buf, size_t count) +{ + rt_err_t ret = RT_EOK; + if (buf) + { + lcdwriteparam *show = (lcdwriteparam *)buf; + //output string + if(0 == show->type) + { + + } + //output dot + else if (1 == show->type) + { + drv_lcd_set_pixel_dot(show->pixel_info.x_startpos,show->pixel_info.y_startpos, show->pixel_info.x_endpos, show->pixel_info.y_endpos,show->pixel_info.pixel_color); + } else + { + rt_kprintf("LcdWrite donnot support show type(0 string; 1 dot) %u\n", show->type); + ret = -RT_ERROR; + } + } + + return ret; +} +const static struct dfs_file_ops lcd_fops = +{ + lcd_fops_open, + lcd_fops_close, + lcd_fops_ioctl, + lcd_fops_read, + lcd_fops_write, + RT_NULL, /* flush */ + RT_NULL, /* lseek */ + RT_NULL, /* getdents */ + RT_NULL,/*poll*/ +}; +#endif + +int rt_hw_lcd_init(void) +{ + rt_err_t ret; + + lcd.device.type = RT_Device_Class_Graphic; + lcd.device.init = imxrt_lcd_init; + lcd.device.open = RT_NULL; + lcd.device.close = RT_NULL; + lcd.device.read = RT_NULL; + lcd.device.write = RT_NULL; + lcd.device.control = imxrt_lcd_control; + + lcd.device.user_data = (void *)&lcd.info; + + ret = rt_device_register(&lcd.device, "lcd", RT_DEVICE_FLAG_RDWR); + #ifdef RT_USING_POSIX + lcd.device.fops = &lcd_fops; + #endif + return ret; +} + +INIT_DEVICE_EXPORT(rt_hw_lcd_init); + +#endif /* BSP_USING_LCD */ diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_lcd.h b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_lcd.h new file mode 100644 index 000000000..86dc988b4 --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/drv_lcd.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-04-05 Liuguang the first version. + */ + +#ifndef __DRV_LCD_H__ +#define __DRV_LCD_H__ + +#include +#include + +#define WHITE 0xFFFF +#define BLACK 0x0000 +#define BLUE 0x001F +#define BRED 0XF81F +#define GRED 0XFFE0 +#define GBLUE 0X07FF +#define RED 0xF800 +#define MAGENTA 0xF81F +#define GREEN 0x07E0 +#define CYAN 0x7FFF +#define YELLOW 0xFFE0 +#define BROWN 0XBC40 +#define BRRED 0XFC07 +#define GRAY 0X8430 +#define GRAY175 0XAD75 +#define GRAY151 0X94B2 +#define GRAY187 0XBDD7 +#define GRAY240 0XF79E +#define ORANGE 0XFD20 + + +typedef struct +{ + rt_uint16_t x_pos; + rt_uint16_t y_pos; + rt_uint16_t width; + rt_uint16_t height; + rt_uint8_t font_size; + rt_uint8_t *addr; + rt_uint16_t font_color; + rt_uint16_t back_color; +}lcdstringparam; + +typedef struct +{ + rt_uint16_t x_startpos; + rt_uint16_t x_endpos; + rt_uint16_t y_startpos; + rt_uint16_t y_endpos; + void* pixel_color; +}lcdpixelparam; + +typedef struct +{ + char type; // 0:write string;1:write dot + lcdpixelparam pixel_info; + lcdstringparam string_info; +}lcdwriteparam; + +int rt_hw_lcd_init(void); + +#endif diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/ok1052lcd.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/ok1052lcd.c new file mode 100644 index 000000000..040abc50a --- /dev/null +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/board/ports/ok1052lcd.c @@ -0,0 +1,54 @@ +#include +#ifdef BSP_USING_LCD_XIDATONG +#include +static rt_device_t dev = 0; +static struct rt_device_graphic_info info; +static int lcd_init(void) +{ + int result; + + if (dev) + return 0; + + dev = rt_device_find("lcd"); + if (!dev) + return -1; + + if (rt_device_open(dev, 0) != 0) + { + dev = 0; + return -1; + } + + result = rt_device_control(dev, RTGRAPHIC_CTRL_GET_INFO, &info); + if (result != 0) + { + rt_device_close(dev); + dev = 0; + return result; + } + return 0; +} +INIT_ENV_EXPORT(lcd_init); + +static void lcd_clear(rt_uint16_t color) +{ + for(int i = 0;i < info.height*info.width;i++) + { + *((rt_uint16_t*)info.framebuffer+i) = color; + } +} + +void lcd_test() +{ + lcd_clear(BLUE); + rt_thread_mdelay(1000); + lcd_clear(GREEN); + rt_thread_mdelay(1000); + lcd_clear(GRAY); + rt_thread_mdelay(1000); + lcd_clear(RED); +} +MSH_CMD_EXPORT(lcd_test,lcd test); + +#endif \ No newline at end of file