register_driver lcd device on riscv64 on nuttx

This commit is contained in:
wgzAIIT 2022-11-02 09:18:04 +08:00
parent 15ae618a3b
commit 0bb057c642
6 changed files with 164 additions and 35 deletions

View File

@ -48,19 +48,19 @@ void LcdDemo(void)
x2 = LCD_XSIZE_TFT - 50;
y2 = LCD_YSIZE_TFT - 50;
syslog(LOG_NOTICE, "Disp_demo %d (%d,%d - %d,%d)\n", i, x1, y1, x2, y2);
LT768_DrawSquare_Fill(x1, y1, x2, y2, Red);
LT768_DrawSquare_Fill(x1, y1, x2, y2, RED);
up_mdelay(2000);
x1 += 20;
y1 += 20;
x2 -= 20;
y2 -= 20;
LT768_DrawSquare_Fill(x1, y1, x2, y2, Green);
LT768_DrawSquare_Fill(x1, y1, x2, y2, GREEN);
up_mdelay(2000);
x1 += 20;
y1 += 20;
x2 -= 20;
y2 -= 20;
LT768_DrawSquare_Fill(x1, y1, x2, y2, Blue);
LT768_DrawSquare_Fill(x1, y1, x2, y2, BLUE);
up_mdelay(2000);
}
}

View File

@ -22,7 +22,7 @@
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "k210_fpioa.h"
#include "k210_gpiohs.h"
#include "nuttx/arch.h"
@ -31,10 +31,15 @@
#include "nuttx/lcd/if_port.h"
#include <nuttx/board.h>
#include <arch/board/board.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#ifdef CONFIG_LCD_LCDDRV_SPIIF
#include "nuttx/lcd/lcddrv_spiif.h"
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#define NCS_H() k210_gpiohs_set_value(FPIOA_LCD_NCS, GPIO_PV_HIGH); up_udelay(20)
#define NCS_L() k210_gpiohs_set_value(FPIOA_LCD_NCS, GPIO_PV_LOW); up_udelay(20)
#define CLK_H() k210_gpiohs_set_value(FPIOA_LCD_SCLK, GPIO_PV_HIGH); up_udelay(20)
@ -42,6 +47,25 @@
#define MOSI_H() k210_gpiohs_set_value(FPIOA_LCD_MOSI, GPIO_PV_HIGH)
#define MOSI_L() k210_gpiohs_set_value(FPIOA_LCD_MOSI, GPIO_PV_LOW)
static int lcd_open(FAR struct file *filep);
static int lcd_close(FAR struct file *filep);
static ssize_t lcd_read(FAR struct file *filep, FAR char *buffer, size_t buflen);
static ssize_t lcd_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
/****************************************************************************
* Private Data
****************************************************************************/
/* Ch438 POSIX interface */
static const struct file_operations g_lcdfops =
{
lcd_open,
lcd_close,
lcd_read,
lcd_write,
NULL,
NULL,
NULL
};
/****************************************************************************
* Public Functions
****************************************************************************/
@ -184,23 +208,7 @@ void lcd_drv_init(void)
Canvas_Image_Start_address(LCD_START_ADDR);
//fill blue background
LT768_DrawSquare_Fill(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, Blue);
}
/****************************************************************************
* Name: k210_lcd_initialize
*
* Description:
* Initialize the LCD. Setup backlight (initially off)
*
****************************************************************************/
int board_lcd_initialize(void)
{
/* Configure the LCD backlight (and turn the backlight off) */
lcd_backlight_init(true);
lcd_drv_init();
return 0;
LT768_DrawSquare_Fill(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, BLUE);
}
/****************************************************************************
@ -218,3 +226,83 @@ void k210_backlight(bool blon)
lcd_backlight_init(blon);
}
#endif
/****************************************************************************
* Name: lcd_open
****************************************************************************/
static int lcd_open(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: lcd_close
****************************************************************************/
static int lcd_close(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: lcd_read
****************************************************************************/
static ssize_t lcd_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
{
return OK;
}
/****************************************************************************
* Name: ch438_write
****************************************************************************/
static ssize_t lcd_write(FAR struct file *filep, FAR const char *buffer, size_t buflen)
{
if (buffer == NULL) {
return -ERROR;
}
LcdWriteParam * show = (LcdWriteParam *)buffer;
/* output string */
if(0 == show->type)
{
LT768_Select_Internal_Font_Init(show->string_info.height, 1, 1, 1, 1);
LT768_Print_Internal_Font_String(show->string_info.x_pos, show->string_info.y_pos, show->string_info.font_color,show->string_info.back_color,show->string_info.addr);
return buflen;
}
/* output dot */
else if(1 == show->type)
{
LT768_DrawSquare_Fill(show->pixel_info.x_startpos,show->pixel_info.y_startpos, show->pixel_info.x_endpos, show->pixel_info.y_endpos, *(uint32_t *)(show->pixel_info.pixel_color));
return buflen;
}
else
{
return -ERROR;
}
}
/****************************************************************************
* Name: k210_lcd_initialize
*
* Description:
* Initialize the LCD. Setup backlight (initially off)
*
****************************************************************************/
int board_lcd_initialize(void)
{
/* Configure the LCD backlight (and turn the backlight off) */
lcd_backlight_init(true);
lcd_drv_init();
up_mdelay(10);
Main_Image_Start_Address(LCD_START_ADDR);
Main_Image_Width(LCD_XSIZE_TFT);
Main_Window_Start_XY(0, 0);
Canvas_Image_Start_address(LCD_START_ADDR);
Canvas_image_width(LCD_XSIZE_TFT);
Active_Window_XY(0, 0);
Active_Window_WH(LCD_XSIZE_TFT, LCD_YSIZE_TFT);
up_mdelay(10);
Canvas_Image_Start_address(LCD_START_ADDR);
/* register device */
register_driver("/dev/lcd_dev", &g_lcdfops, 0666, NULL);
return OK;
}

View File

@ -6282,7 +6282,7 @@ uint8_t Read_Key_Strobe_Data_2(void)
return temp;
}
void Show_String(char *str)
void Show_String(uint8_t *str)
{
Text_Mode(); //text mode
LCD_CmdWrite(0x04);

View File

@ -1388,7 +1388,7 @@ void LT768_Print_Internal_Font_String
, uint16_t y // font start y
, uint32_t FontColor // font color
, uint32_t BackGroundColor // font background color(when font background is transparent, it is invalid)
, char *c // data start address
, uint8_t *c // data start address
)
{
Text_Mode();

View File

@ -21,6 +21,34 @@
#ifndef __LT768_H_
#define __LT768_H_
typedef struct
{
uint16_t x_pos;
uint16_t y_pos;
uint16_t width;
uint16_t height;
uint8_t font_size;
uint8_t *addr;
uint16_t font_color;
uint16_t back_color;
}LcdStringParam;
typedef struct
{
uint16_t x_startpos;
uint16_t x_endpos;
uint16_t y_startpos;
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;
#define cSetb0 0x01
#define cSetb1 0x02
#define cSetb2 0x04
@ -691,7 +719,7 @@ uint8_t Read_Key_Strobe_Data_0(void);
uint8_t Read_Key_Strobe_Data_1(void);
uint8_t Read_Key_Strobe_Data_2(void);
void Show_String(char *str);
void Show_String(uint8_t *str);
void Show_picture(uint32_t numbers, const uint16_t *data);
void PWM0_ON(void); //PWM0

View File

@ -99,16 +99,29 @@
#define color16M_purple color16M_red|color16M_blue
/* LCD color */
#define White 0xFFFF
#define Black 0x0000
#define Grey 0xF7DE
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F
#define Green 0x07E0
#define Cyan 0x7FFF
#define Yellow 0xFFE0
#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 DARKBLUE 0x01CF
#define LIGHTBLUE 0x7D7C
#define GRAYBLUE 0x5458
#define LIGHTGREEN 0x841F
#define LGRAY 0xC618
#define LGRAYBLUE 0xA651
#define LBBLUE 0x2B12
#define Line0 0
#define Line1 24
@ -474,7 +487,7 @@ void LT768_Print_Internal_Font_String(uint16_t x,
uint16_t y,
uint32_t FontColor,
uint32_t BackGroundColor,
char *c);
uint8_t *c);
/* nor flash use outside font */
/* 16*16 24*24 32*32 */