add ili9341 lcd device and simple gui demo
This commit is contained in:
parent
e4999e60b0
commit
269a7683b5
|
@ -32,12 +32,18 @@
|
|||
#include <lwip/sys.h>
|
||||
#include <lwip/api.h>
|
||||
#include <netif/ethernetif.h>
|
||||
#include "stm32f4xx_eth.h"
|
||||
#include "drv_eth.h"
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_GDB
|
||||
#include <gdb_stub.h>
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_GUIENGINE
|
||||
#include "rtgui_demo.h"
|
||||
#include <rtgui/driver.h>
|
||||
#endif
|
||||
|
||||
//rt_module_t module_ptr;
|
||||
#define DATA_PATH "/Data"
|
||||
void rt_init_thread_entry(void* parameter)
|
||||
|
@ -89,19 +95,16 @@ void rt_init_thread_entry(void* parameter)
|
|||
#endif /* RT_USING_DFS_ELMFAT */
|
||||
|
||||
#endif /* DFS */
|
||||
/* LwIP Initialization */
|
||||
#ifdef RT_USING_LWIP
|
||||
|
||||
#ifdef RT_USING_GUIENGINE
|
||||
{
|
||||
extern void lwip_sys_init(void);
|
||||
rt_device_t device;
|
||||
|
||||
/* register ethernetif device */
|
||||
eth_system_device_init();
|
||||
device = rt_device_find("lcd");
|
||||
/* re-set graphic device */
|
||||
rtgui_graphic_set_device(device);
|
||||
|
||||
rt_hw_stm32_eth_init();
|
||||
|
||||
/* init lwip system */
|
||||
lwip_sys_init();
|
||||
rt_kprintf("TCP/IP initialized!\n");
|
||||
rt_gui_demo_init();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* File : application.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/dc_hw.h>
|
||||
|
||||
#include "finsh.h"
|
||||
#include "rtgui_demo.h"
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_PRINTF(...)
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_GUIENGINE
|
||||
|
||||
struct rtgui_win *main_win;
|
||||
rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event);
|
||||
|
||||
static void rt_gui_demo_entry(void *parameter)
|
||||
{
|
||||
struct rtgui_app *app;
|
||||
//struct rtgui_dc *dc;
|
||||
|
||||
DEBUG_PRINTF("gui demo entry\n");
|
||||
|
||||
/* create gui app */
|
||||
app = rtgui_app_create("gui_demo");
|
||||
if (app == RT_NULL)
|
||||
{
|
||||
DEBUG_PRINTF("rtgui_app_create faild\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* create main window */
|
||||
main_win = rtgui_mainwin_create(RT_NULL,
|
||||
"UiWindow", RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
|
||||
if (main_win == RT_NULL)
|
||||
{
|
||||
DEBUG_PRINTF("main_win is null\n");
|
||||
rtgui_app_destroy(app);
|
||||
return;
|
||||
}
|
||||
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(main_win), dc_event_handler);
|
||||
|
||||
DEBUG_PRINTF("rtgui_win_show\n");
|
||||
rtgui_win_show(main_win, RT_FALSE);
|
||||
|
||||
DEBUG_PRINTF("rtgui_app_run\n");
|
||||
rtgui_app_run(app);
|
||||
|
||||
DEBUG_PRINTF("rtgui_win_destroy\n");
|
||||
rtgui_win_destroy(main_win);
|
||||
|
||||
DEBUG_PRINTF("rtgui_app_destroy\n");
|
||||
rtgui_app_destroy(app);
|
||||
}
|
||||
|
||||
rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc *dc;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
rt_kprintf("\r\n RTGUI_EVENT_PAINT \r\n");
|
||||
rtgui_win_event_handler(RTGUI_OBJECT(widget), event);
|
||||
|
||||
rtgui_widget_get_rect(widget, &rect);
|
||||
DEBUG_PRINTF("widget react x1: %d, y1: %d, x2: %d, y2: %d\r\n",
|
||||
rect.x1, rect.y1, rect.x2, rect.y2);
|
||||
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if(dc == RT_NULL)
|
||||
{
|
||||
DEBUG_PRINTF("\r\n dc is null \r\n");
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_dc_draw_line(dc,0,0,240,320);
|
||||
rtgui_dc_draw_line(dc,0,320,240,0);
|
||||
//rtgui_dc_draw_text(dc, __DATE__, &rect);
|
||||
rtgui_dc_draw_text_stroke(dc, __DATE__, &rect, HIGH_LIGHT, BLUE);
|
||||
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
rtgui_dc_draw_text_stroke(dc, __TIME__, &rect, HIGH_LIGHT, BLACK);
|
||||
|
||||
|
||||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
int rt_gui_demo_init(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
tid = rt_thread_create("mygui",
|
||||
rt_gui_demo_entry, RT_NULL,
|
||||
2048, 25, 10);
|
||||
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* RT_USING_GUIENGINE */
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* File : dc.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-06-02 tanek first version
|
||||
*/
|
||||
#ifndef __APP_GUI_DEMO_H__
|
||||
#define __APP_GUI_DEMO_H__
|
||||
|
||||
extern int rt_gui_demo_init(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -18,7 +18,7 @@ drv_mpu.c
|
|||
|
||||
# add Ethernet drivers.
|
||||
if GetDepend('RT_USING_LWIP'):
|
||||
src += ['stm32f4xx_eth.c']
|
||||
src += ['drv_eth.c']
|
||||
|
||||
# add gpio drivers.
|
||||
if GetDepend('RT_USING_PIN'):
|
||||
|
@ -32,6 +32,10 @@ if GetDepend('RT_USING_SPI'):
|
|||
if GetDepend('RT_USING_SFUD'):
|
||||
src += ['drv_spi_flash.c']
|
||||
|
||||
# add lcd drivers.
|
||||
if GetDepend('RT_USING_GUIENGINE'):
|
||||
src += ['drv_lcd.c']
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
|
|
@ -0,0 +1,603 @@
|
|||
/*
|
||||
* File : drv_lcd.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2009 RT-Thread Develop Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-06-08 tanek first implementation
|
||||
*/
|
||||
|
||||
#include "drv_lcd.h"
|
||||
#include <finsh.h>
|
||||
|
||||
//#define DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_PRINTF(...)
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rt_uint16_t width; //LCD 宽度
|
||||
rt_uint16_t height; //LCD 高度
|
||||
rt_uint16_t id; //LCD ID
|
||||
rt_uint8_t dir; //横屏还是竖屏控制:0,竖屏;1,横屏。
|
||||
rt_uint16_t wramcmd; //开始写gram指令
|
||||
rt_uint16_t setxcmd; //设置x坐标指令
|
||||
rt_uint16_t setycmd; //设置y坐标指令
|
||||
} lcd_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
volatile rt_uint16_t reg;
|
||||
volatile rt_uint16_t ram;
|
||||
} lcd_ili9341_t;
|
||||
|
||||
//使用NOR/SRAM的 Bank1.sector1,地址位HADDR[27,26]=00 A18作为数据命令区分线
|
||||
//注意设置时STM32内部会右移一位对其!
|
||||
#define LCD_ILI9341_BASE ((rt_uint32_t)(0x60000000 | 0x0007FFFE))
|
||||
#define ili9341 ((lcd_ili9341_t *) LCD_ILI9341_BASE)
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//扫描方向定义
|
||||
#define L2R_U2D 0 //从左到右,从上到下
|
||||
#define L2R_D2U 1 //从左到右,从下到上
|
||||
#define R2L_U2D 2 //从右到左,从上到下
|
||||
#define R2L_D2U 3 //从右到左,从下到上
|
||||
#define U2D_L2R 4 //从上到下,从左到右
|
||||
#define U2D_R2L 5 //从上到下,从右到左
|
||||
#define D2U_L2R 6 //从下到上,从左到右
|
||||
#define D2U_R2L 7 //从下到上,从右到左
|
||||
#define DFT_SCAN_DIR L2R_U2D //默认的扫描方向
|
||||
|
||||
static lcd_info_t lcddev;
|
||||
|
||||
void delay_us(rt_uint32_t nus)
|
||||
{
|
||||
//rt_thread_delay(1);
|
||||
while (nus--) {
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
|
||||
void delay_ms(rt_uint32_t nms)
|
||||
{
|
||||
//rt_thread_delay((RT_TICK_PER_SECOND * nms + 999) / 1000);
|
||||
while (nms--)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ili9341_write_reg(rt_uint16_t regval)
|
||||
{
|
||||
ili9341->reg = regval;
|
||||
}
|
||||
|
||||
static void ili9341_write_data(rt_uint16_t data)
|
||||
{
|
||||
ili9341->ram = data;
|
||||
}
|
||||
|
||||
rt_uint16_t ili9341_read_ram(void)
|
||||
{
|
||||
return ili9341->ram;
|
||||
}
|
||||
|
||||
static void ili9341_write_reg_with_value(rt_uint16_t reg, rt_uint16_t regValue)
|
||||
{
|
||||
ili9341->reg = reg;
|
||||
ili9341->ram = regValue;
|
||||
}
|
||||
|
||||
static void ili9341_write_ram_prepare(void)
|
||||
{
|
||||
ili9341->reg = lcddev.wramcmd;
|
||||
}
|
||||
|
||||
rt_uint16_t ili9341_bgr2rgb(rt_uint16_t value)
|
||||
{
|
||||
rt_uint16_t red, green, blue;
|
||||
|
||||
blue = (value >> 0) & 0x1f;
|
||||
green = (value >> 5) & 0x3f;
|
||||
red = (value >> 11) & 0x1f;
|
||||
|
||||
return (blue << 11) + (green << 5) + (red << 0);
|
||||
}
|
||||
|
||||
static void ili9341_set_cursor(rt_uint16_t Xpos, rt_uint16_t Ypos)
|
||||
{
|
||||
ili9341_write_reg(lcddev.setxcmd);
|
||||
ili9341_write_data(Xpos >> 8);
|
||||
ili9341_write_data(Xpos & 0XFF);
|
||||
|
||||
ili9341_write_reg(lcddev.setycmd);
|
||||
ili9341_write_data(Ypos >> 8);
|
||||
ili9341_write_data(Ypos & 0XFF);
|
||||
}
|
||||
|
||||
static void ili9341_set_scan_direction(rt_uint8_t dir)
|
||||
{
|
||||
rt_uint16_t regval = 0;
|
||||
rt_uint16_t dirreg = 0;
|
||||
rt_uint16_t temp;
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
case L2R_U2D://从左到右,从上到下
|
||||
regval |= (0 << 7) | (0 << 6) | (0 << 5);
|
||||
break;
|
||||
case L2R_D2U://从左到右,从下到上
|
||||
regval |= (1 << 7) | (0 << 6) | (0 << 5);
|
||||
break;
|
||||
case R2L_U2D://从右到左,从上到下
|
||||
regval |= (0 << 7) | (1 << 6) | (0 << 5);
|
||||
break;
|
||||
case R2L_D2U://从右到左,从下到上
|
||||
regval |= (1 << 7) | (1 << 6) | (0 << 5);
|
||||
break;
|
||||
case U2D_L2R://从上到下,从左到右
|
||||
regval |= (0 << 7) | (0 << 6) | (1 << 5);
|
||||
break;
|
||||
case U2D_R2L://从上到下,从右到左
|
||||
regval |= (0 << 7) | (1 << 6) | (1 << 5);
|
||||
break;
|
||||
case D2U_L2R://从下到上,从左到右
|
||||
regval |= (1 << 7) | (0 << 6) | (1 << 5);
|
||||
break;
|
||||
case D2U_R2L://从下到上,从右到左
|
||||
regval |= (1 << 7) | (1 << 6) | (1 << 5);
|
||||
break;
|
||||
}
|
||||
|
||||
dirreg = 0X36;
|
||||
ili9341_write_reg_with_value(dirreg, regval);
|
||||
|
||||
if (regval & 0X20)
|
||||
{
|
||||
if (lcddev.width < lcddev.height)//交换X,Y
|
||||
{
|
||||
temp = lcddev.width;
|
||||
lcddev.width = lcddev.height;
|
||||
lcddev.height = temp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lcddev.width > lcddev.height)//交换X,Y
|
||||
{
|
||||
temp = lcddev.width;
|
||||
lcddev.width = lcddev.height;
|
||||
lcddev.height = temp;
|
||||
}
|
||||
}
|
||||
|
||||
ili9341_write_reg(lcddev.setxcmd);
|
||||
ili9341_write_data(0);
|
||||
ili9341_write_data(0);
|
||||
ili9341_write_data((lcddev.width - 1) >> 8);
|
||||
ili9341_write_data((lcddev.width - 1) & 0XFF);
|
||||
|
||||
ili9341_write_reg(lcddev.setycmd);
|
||||
ili9341_write_data(0);
|
||||
ili9341_write_data(0);
|
||||
ili9341_write_data((lcddev.height - 1) >> 8);
|
||||
ili9341_write_data((lcddev.height - 1) & 0XFF);
|
||||
}
|
||||
|
||||
void ili9341_set_backlight(rt_uint8_t pwm)
|
||||
{
|
||||
ili9341_write_reg(0xBE);
|
||||
ili9341_write_data(0x05);
|
||||
ili9341_write_data(pwm*2.55);
|
||||
ili9341_write_data(0x01);
|
||||
ili9341_write_data(0xFF);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
}
|
||||
|
||||
void ili9341_set_display_direction(rt_uint8_t dir)
|
||||
{
|
||||
lcddev.dir = dir;
|
||||
if (dir == 0)
|
||||
{
|
||||
lcddev.width = 240;
|
||||
lcddev.height = 320;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcddev.width = 320;
|
||||
lcddev.height = 240;
|
||||
}
|
||||
|
||||
lcddev.wramcmd = 0X2C;
|
||||
lcddev.setxcmd = 0X2A;
|
||||
lcddev.setycmd = 0X2B;
|
||||
|
||||
ili9341_set_scan_direction(DFT_SCAN_DIR);
|
||||
}
|
||||
|
||||
void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_Initure;
|
||||
|
||||
__HAL_RCC_FMC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
|
||||
//init PD0,1,4,5,7,8,9,10,13,14,15
|
||||
GPIO_Initure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7 | GPIO_PIN_8 | \
|
||||
GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_Initure.Pull = GPIO_PULLUP;
|
||||
GPIO_Initure.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_Initure.Alternate = GPIO_AF12_FMC;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_Initure);
|
||||
|
||||
//init PE7,8,9,10,11,12,13,14,15
|
||||
GPIO_Initure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \
|
||||
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_Initure);
|
||||
}
|
||||
|
||||
SRAM_HandleTypeDef SRAM_Handler;
|
||||
|
||||
void _lcd_low_level_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_Initure;
|
||||
|
||||
FMC_NORSRAM_TimingTypeDef FMC_ReadWriteTim;
|
||||
FMC_NORSRAM_TimingTypeDef FMC_WriteTim;
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_Initure.Pin = GPIO_PIN_5;
|
||||
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_Initure.Pull = GPIO_PULLUP;
|
||||
GPIO_Initure.Speed = GPIO_SPEED_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_Initure);
|
||||
|
||||
SRAM_Handler.Instance = FMC_NORSRAM_DEVICE;
|
||||
SRAM_Handler.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
|
||||
|
||||
SRAM_Handler.Init.NSBank = FMC_NORSRAM_BANK1;
|
||||
SRAM_Handler.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
|
||||
SRAM_Handler.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
|
||||
SRAM_Handler.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
|
||||
SRAM_Handler.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
|
||||
SRAM_Handler.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
|
||||
SRAM_Handler.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
|
||||
SRAM_Handler.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
|
||||
SRAM_Handler.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
|
||||
SRAM_Handler.Init.ExtendedMode = FMC_EXTENDED_MODE_ENABLE;
|
||||
SRAM_Handler.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
|
||||
SRAM_Handler.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
|
||||
SRAM_Handler.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC;
|
||||
|
||||
FMC_ReadWriteTim.AddressSetupTime = 0x0F;
|
||||
FMC_ReadWriteTim.AddressHoldTime = 0x00;
|
||||
FMC_ReadWriteTim.DataSetupTime = 0x46;
|
||||
FMC_ReadWriteTim.AccessMode = FMC_ACCESS_MODE_A;
|
||||
|
||||
FMC_WriteTim.AddressSetupTime = 0x0F;
|
||||
FMC_WriteTim.AddressHoldTime = 0x00;
|
||||
FMC_WriteTim.DataSetupTime = 0x0F;
|
||||
FMC_WriteTim.AccessMode = FMC_ACCESS_MODE_A;
|
||||
HAL_SRAM_Init(&SRAM_Handler, &FMC_ReadWriteTim, &FMC_WriteTim);
|
||||
delay_ms(50);
|
||||
|
||||
ili9341_write_reg(0XD3);
|
||||
lcddev.id = ili9341_read_ram();
|
||||
lcddev.id = ili9341_read_ram();
|
||||
lcddev.id = ili9341_read_ram();
|
||||
lcddev.id <<= 8;
|
||||
lcddev.id |= ili9341_read_ram();
|
||||
|
||||
DEBUG_PRINTF(" LCD ID:%x\r\n", lcddev.id); //打印LCD ID
|
||||
|
||||
ili9341_write_reg(0xCF);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0xC1);
|
||||
ili9341_write_data(0X30);
|
||||
ili9341_write_reg(0xED);
|
||||
ili9341_write_data(0x64);
|
||||
ili9341_write_data(0x03);
|
||||
ili9341_write_data(0X12);
|
||||
ili9341_write_data(0X81);
|
||||
ili9341_write_reg(0xE8);
|
||||
ili9341_write_data(0x85);
|
||||
ili9341_write_data(0x10);
|
||||
ili9341_write_data(0x7A);
|
||||
ili9341_write_reg(0xCB);
|
||||
ili9341_write_data(0x39);
|
||||
ili9341_write_data(0x2C);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x34);
|
||||
ili9341_write_data(0x02);
|
||||
ili9341_write_reg(0xF7);
|
||||
ili9341_write_data(0x20);
|
||||
ili9341_write_reg(0xEA);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_reg(0xC0); //Power control
|
||||
ili9341_write_data(0x1B); //VRH[5:0]
|
||||
ili9341_write_reg(0xC1); //Power control
|
||||
ili9341_write_data(0x01); //SAP[2:0];BT[3:0]
|
||||
ili9341_write_reg(0xC5); //VCM control
|
||||
ili9341_write_data(0x30); //3F
|
||||
ili9341_write_data(0x30); //3C
|
||||
ili9341_write_reg(0xC7); //VCM control2
|
||||
ili9341_write_data(0XB7);
|
||||
ili9341_write_reg(0x36); // memory access control
|
||||
ili9341_write_data(0x08); // change here
|
||||
ili9341_write_reg(0x3A);
|
||||
ili9341_write_data(0x55);
|
||||
ili9341_write_reg(0xB1);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x1A);
|
||||
ili9341_write_reg(0xB6); //display function control
|
||||
ili9341_write_data(0x0A);
|
||||
ili9341_write_data(0xA2);
|
||||
ili9341_write_reg(0xF2); //3gamma function disable
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_reg(0x26); //gamma curve selected
|
||||
ili9341_write_data(0x01);
|
||||
ili9341_write_reg(0xE0); //set gamma
|
||||
ili9341_write_data(0x0F);
|
||||
ili9341_write_data(0x2A);
|
||||
ili9341_write_data(0x28);
|
||||
ili9341_write_data(0x08);
|
||||
ili9341_write_data(0x0E);
|
||||
ili9341_write_data(0x08);
|
||||
ili9341_write_data(0x54);
|
||||
ili9341_write_data(0XA9);
|
||||
ili9341_write_data(0x43);
|
||||
ili9341_write_data(0x0A);
|
||||
ili9341_write_data(0x0F);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_reg(0XE1); //set gamma
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x15);
|
||||
ili9341_write_data(0x17);
|
||||
ili9341_write_data(0x07);
|
||||
ili9341_write_data(0x11);
|
||||
ili9341_write_data(0x06);
|
||||
ili9341_write_data(0x2B);
|
||||
ili9341_write_data(0x56);
|
||||
ili9341_write_data(0x3C);
|
||||
ili9341_write_data(0x05);
|
||||
ili9341_write_data(0x10);
|
||||
ili9341_write_data(0x0F);
|
||||
ili9341_write_data(0x3F);
|
||||
ili9341_write_data(0x3F);
|
||||
ili9341_write_data(0x0F);
|
||||
ili9341_write_reg(0x2B);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x01);
|
||||
ili9341_write_data(0x3f);
|
||||
ili9341_write_reg(0x2A);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0x00);
|
||||
ili9341_write_data(0xef);
|
||||
ili9341_write_reg(0x11); //exit sleep
|
||||
delay_ms(120);
|
||||
ili9341_write_reg(0x29); //display on
|
||||
|
||||
FMC_Bank1E->BWTR[0] &= ~(0XF << 0);
|
||||
FMC_Bank1E->BWTR[0] &= ~(0XF << 8);
|
||||
FMC_Bank1E->BWTR[0] |= 4 << 0;
|
||||
FMC_Bank1E->BWTR[0] |= 4 << 8;
|
||||
|
||||
ili9341_set_display_direction(0);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
|
||||
static rt_err_t lcd_init(rt_device_t dev)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t lcd_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t lcd_close(rt_device_t dev)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t lcd_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case RTGRAPHIC_CTRL_GET_INFO:
|
||||
{
|
||||
struct rt_device_graphic_info *info;
|
||||
|
||||
info = (struct rt_device_graphic_info*) args;
|
||||
RT_ASSERT(info != RT_NULL);
|
||||
|
||||
info->bits_per_pixel = 16;
|
||||
info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
|
||||
info->framebuffer = RT_NULL;
|
||||
info->width = 240;
|
||||
info->height = 320;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||
/* nothong to be done */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void ili9341_lcd_set_pixel(const char* pixel, int x, int y)
|
||||
{
|
||||
ili9341_set_cursor(x, y);
|
||||
ili9341_write_ram_prepare();
|
||||
ili9341->ram = *(uint16_t *)pixel;
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
static void lcd_set_pixel(uint16_t color, int x, int y)
|
||||
{
|
||||
rt_kprintf("lcd set pixel, color: %X, x: %d, y: %d", color, x, y);
|
||||
ili9341_lcd_set_pixel((const char *)&color, x, y);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(lcd_set_pixel, set pixel in lcd display);
|
||||
#endif
|
||||
|
||||
static void ili9341_lcd_get_pixel(char* pixel, int x, int y)
|
||||
{
|
||||
rt_uint16_t red = 0;
|
||||
rt_uint16_t green = 0;
|
||||
rt_uint16_t blue = 0;
|
||||
|
||||
if (x >= lcddev.width || y >= lcddev.height)
|
||||
{
|
||||
*(rt_uint16_t*)pixel = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
ili9341_set_cursor(x, y);
|
||||
|
||||
ili9341_write_reg(0X2E);
|
||||
ili9341_read_ram();
|
||||
red = ili9341_read_ram();
|
||||
delay_us(2);
|
||||
|
||||
blue = ili9341_read_ram();
|
||||
green = red & 0XFF;
|
||||
|
||||
*(rt_uint16_t*)pixel = (((red >> 11) << 11) | ((green >> 10) << 5) | (blue >> 11));
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
static void lcd_get_pixel(int x, int y)
|
||||
{
|
||||
uint16_t pixel;
|
||||
ili9341_lcd_get_pixel((char *)&pixel, x, y);
|
||||
rt_kprintf("lcd get pixel, pixel: 0x%X, x: %d, y: %d", pixel, x, y);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(lcd_get_pixel, get pixel in lcd display);
|
||||
#endif
|
||||
|
||||
static void ili9341_lcd_draw_hline(const char* pixel, int x1, int x2, int y)
|
||||
{
|
||||
ili9341_set_cursor(x1, y);
|
||||
ili9341_write_ram_prepare();
|
||||
|
||||
for (; x1 < x2; x1++)
|
||||
{
|
||||
ili9341->ram = *(uint16_t *)pixel;
|
||||
}
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
static void lcd_draw_hline(uint16_t pixel, int x1, int x2, int y)
|
||||
{
|
||||
ili9341_lcd_draw_hline((const char *)&pixel, x1, x2, y);
|
||||
rt_kprintf("lcd draw hline, pixel: 0x%X, x1: %d, x2: %d, y: %d", pixel, x1, x2, y);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(lcd_draw_hline, draw hline in lcd display);
|
||||
#endif
|
||||
|
||||
static void ili9341_lcd_draw_vline(const char* pixel, int x, int y1, int y2)
|
||||
{
|
||||
for (; y1 < y2; y1++)
|
||||
{
|
||||
ili9341_lcd_set_pixel(pixel, x, y1); //write red data
|
||||
}
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
static void lcd_draw_vline(uint16_t pixel, int x, int y1, int y2)
|
||||
{
|
||||
ili9341_lcd_draw_vline((const char *)&pixel, x, y1, y2);
|
||||
rt_kprintf("lcd draw hline, pixel: 0x%X, x: %d, y: %d", pixel, y1, y2);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(lcd_draw_vline, draw vline in lcd display);
|
||||
#endif
|
||||
|
||||
static void ili9341_lcd_blit_line(const char* pixels, int x, int y, rt_size_t size)
|
||||
{
|
||||
rt_uint16_t *ptr = (rt_uint16_t*)pixels;
|
||||
|
||||
ili9341_set_cursor(x, y);
|
||||
ili9341_write_ram_prepare();
|
||||
|
||||
while (size--)
|
||||
{
|
||||
ili9341->ram = *ptr++;
|
||||
}
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
#define LINE_LEN 30
|
||||
static void lcd_blit_line(int x, int y)
|
||||
{
|
||||
uint16_t pixels[LINE_LEN];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LINE_LEN; i++)
|
||||
{
|
||||
pixels[i] = i * 40 + 50;
|
||||
}
|
||||
|
||||
ili9341_lcd_blit_line((const char *)pixels, x, y, LINE_LEN);
|
||||
rt_kprintf("lcd blit line, x: %d, y: %d", x, y);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(lcd_blit_line, draw blit line in lcd display);
|
||||
#endif
|
||||
|
||||
static int rt_hw_lcd_init(void)
|
||||
{
|
||||
_lcd_low_level_init();
|
||||
|
||||
static struct rt_device lcd_device;
|
||||
|
||||
static struct rt_device_graphic_ops ili9341_ops =
|
||||
{
|
||||
ili9341_lcd_set_pixel,
|
||||
ili9341_lcd_get_pixel,
|
||||
ili9341_lcd_draw_hline,
|
||||
ili9341_lcd_draw_vline,
|
||||
ili9341_lcd_blit_line
|
||||
};
|
||||
|
||||
/* register lcd device */
|
||||
lcd_device.type = RT_Device_Class_Graphic;
|
||||
lcd_device.init = lcd_init;
|
||||
lcd_device.open = lcd_open;
|
||||
lcd_device.close = lcd_close;
|
||||
lcd_device.control = lcd_control;
|
||||
lcd_device.read = RT_NULL;
|
||||
lcd_device.write = RT_NULL;
|
||||
|
||||
lcd_device.user_data = &ili9341_ops;
|
||||
|
||||
/* register graphic device driver */
|
||||
rt_device_register(&lcd_device, "lcd",
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef __DRV_LCD_H__
|
||||
#define __DRV_LCD_H__
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
int rt_lcd_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -58,11 +58,11 @@
|
|||
/* #define HAL_DAC_MODULE_ENABLED */
|
||||
/* #define HAL_DCMI_MODULE_ENABLED */
|
||||
/* #define HAL_DMA2D_MODULE_ENABLED */
|
||||
/* #define HAL_ETH_MODULE_ENABLED */
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#define HAL_NAND_MODULE_ENABLED
|
||||
/* #define HAL_NOR_MODULE_ENABLED */
|
||||
/* #define HAL_PCCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SRAM_MODULE_ENABLED */
|
||||
#define HAL_SRAM_MODULE_ENABLED
|
||||
#define HAL_SDRAM_MODULE_ENABLED
|
||||
/* #define HAL_HASH_MODULE_ENABLED */
|
||||
/* #define HAL_I2C_MODULE_ENABLED */
|
||||
|
|
|
@ -66,6 +66,29 @@
|
|||
#define RT_USING_DEVICE
|
||||
#define RT_USING_DEVICE_IPC
|
||||
|
||||
/* SECTION: RTGUI support */
|
||||
/* using RTGUI support */
|
||||
#define RT_USING_GUIENGINE
|
||||
|
||||
/* name length of RTGUI object */
|
||||
#define RTGUI_NAME_MAX 16
|
||||
/* support 16 weight font */
|
||||
#define RTGUI_USING_FONT16
|
||||
/* support 16 weight font */
|
||||
#define RTGUI_USING_FONT12
|
||||
/* support Chinese font */
|
||||
#define RTGUI_USING_FONTHZ
|
||||
/* use DFS as file interface */
|
||||
#define RTGUI_USING_DFS_FILERW
|
||||
/* use font file as Chinese font */
|
||||
/* #define RTGUI_USING_HZ_FILE */
|
||||
/* use Chinese bitmap font */
|
||||
#define RTGUI_USING_HZ_BMP
|
||||
/* use small size in RTGUI */
|
||||
/* #define RTGUI_USING_SMALL_SIZE */
|
||||
/* use mouse cursor */
|
||||
/* #define RTGUI_USING_MOUSE_CURSOR */
|
||||
|
||||
|
||||
/* Using serial framework */
|
||||
#define RT_USING_SERIAL
|
||||
|
@ -151,7 +174,7 @@
|
|||
// #define RT_USING_DFS_ROMFS
|
||||
|
||||
/* SECTION: lwip, a lighwight TCP/IP protocol stack */
|
||||
/* #define RT_USING_LWIP */
|
||||
#define RT_USING_LWIP
|
||||
/* LwIP uses RT-Thread Memory Management */
|
||||
#define RT_LWIP_USING_RT_MEM
|
||||
/* Enable ICMP protocol*/
|
||||
|
@ -162,6 +185,8 @@
|
|||
#define RT_LWIP_TCP
|
||||
/* Enable DNS */
|
||||
#define RT_LWIP_DNS
|
||||
/* Enable DHCP */
|
||||
//#define RT_LWIP_DHCP
|
||||
|
||||
/* the number of simulatenously active TCP connections*/
|
||||
#define RT_LWIP_TCP_PCB_NUM 5
|
||||
|
|
Loading…
Reference in New Issue