register lcd device on riscv64 on nuttx

This commit is contained in:
wgzAIIT 2022-11-02 14:43:58 +08:00
parent a39bc41597
commit 9965ce4c43
9 changed files with 248 additions and 123 deletions

View File

@ -10,6 +10,10 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
CSRCS += test_lcd.c
endif
ifeq ($(CONFIG_BSP_USING_TOUCH),y)
CSRCS += test_touch.c
endif
include $(APPDIR)/Application.mk
endif

View File

@ -1,26 +1,22 @@
/****************************************************************************
* apps/examples/fb/fb_main.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/****************************************************************************
* Included Files
****************************************************************************/
/**
* @file: test_lcd.c
* @brief: a application of dac function
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/1/11
*/
#include <transform.h>
@ -29,40 +25,35 @@
#ifdef CONFIG_K210_LCD
void LcdDemo(void)
{
int x1 = 50, y1 = 50, x2 = LCD_XSIZE_TFT - 50, y2 = LCD_YSIZE_TFT - 50;
int lcd_fd = PrivOpen("/dev/lcd_dev",O_RDWR);
LcdWriteParam disp_info;
disp_info.type = 1;
lv_color_t redcolor = {
.ch = {
.red = 0b11111,
.green = 0,
.blue = 0
}
};
disp_info.pixel_info.x_startpos = 0;
disp_info.pixel_info.x_endpos = 50;
disp_info.pixel_info.y_startpos = 0;
disp_info.pixel_info.y_endpos = 50;
disp_info.pixel_info.pixel_color = &redcolor;
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);
for(int i = 0; i < 3; i++)
{
x1 = 50;
y1 = 50;
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);
up_mdelay(2000);
x1 += 20;
y1 += 20;
x2 -= 20;
y2 -= 20;
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);
up_mdelay(2000);
}
PrivWrite(lcd_fd, &disp_info, sizeof(LcdWriteParam));
disp_info.type = 0;
disp_info.string_info.x_pos = 80;
disp_info.string_info.y_pos = 80;
disp_info.string_info.width = 250;
disp_info.string_info.height = 24;
disp_info.string_info.font_size = 24;
disp_info.string_info.addr = "wecome test lcd";
disp_info.string_info.font_color = GREEN;
disp_info.string_info.back_color = BLUE;
PrivWrite(lcd_fd, &disp_info, sizeof(LcdWriteParam));
}
#else

View File

@ -0,0 +1,43 @@
/****************************************************************************
* apps/examples/fb/fb_main.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <transform.h>
#ifdef ADD_NUTTX_FETURES
#ifdef CONFIG_BSP_USING_TOUCH
void TestTouch(void)
{
int fd;
TouchDataParam point = {0, 0, 0};
fd = PrivOpen("/dev/touch_dev", O_RDWR);
while(1)
{
PrivRead(fd,&point,1);
printf("Now touch point:(%d,%d)\n",point.x,point.y);
}
}
#endif
#endif

View File

@ -53,6 +53,14 @@
#endif
#endif
#define PRIV_LCD_DEV "/dev/lcd_dev"
#define MY_DISP_HOR_RES 480
#define MY_DISP_VER_RES 272
#define PRIV_TOUCH_DEV "/dev/touch_dev"
#define MY_INDEV_X 480
#define MY_INDEV_Y 272
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
@ -127,6 +135,23 @@ extern "C" {
#define EOK 0
#define x_err_t int
typedef union {
struct {
uint16_t blue : 5;
uint16_t green : 6;
uint16_t red : 5;
} ch;
uint16_t full;
} lv_color16_t;
typedef lv_color16_t lv_color_t;
typedef struct
{
uint16_t x;
uint16_t y;
uint16_t press;
}TouchDataParam;
struct PinDevIrq
{
int irq_mode;//< RISING/FALLING/HIGH/LOW

View File

@ -47,6 +47,10 @@
# include "k210_ch438.h"
#endif
#ifdef CONFIG_BSP_USING_TOUCH
# include "k210_touch.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -87,6 +91,10 @@ int k210_bringup(void)
board_lcd_initialize();
#endif
#ifdef CONFIG_BSP_USING_TOUCH
board_touch_initialize();
#endif
#ifdef CONFIG_K210_16550_UART1
sysctl_clock_enable(SYSCTL_CLOCK_UART1);
sysctl_reset(SYSCTL_RESET_UART1);

View File

@ -55,7 +55,7 @@ static ssize_t lcd_write(FAR struct file *filep, FAR const char *buffer, size_t
/****************************************************************************
* Private Data
****************************************************************************/
/* Ch438 POSIX interface */
/* LCD POSIX interface */
static const struct file_operations g_lcdfops =
{
lcd_open,
@ -208,7 +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);
LT768_DrawSquare_Fill(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, WHITE);
}
/****************************************************************************
@ -257,7 +257,8 @@ 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)
{
if (buffer == NULL) {
if (buffer == NULL)
{
return -ERROR;
}
LcdWriteParam * show = (LcdWriteParam *)buffer;

View File

@ -24,6 +24,44 @@
****************************************************************************/
#include "k210_touch.h"
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void IIC_Init(void);
static void SDA_IN(void);
static void SDA_OUT(void);
static uint8_t READ_SDA(void);
static void IIC_SCL(uint8_t val);
static void IIC_SDA(uint8_t val);
static void IIC_Start(void);
static void IIC_Stop(void);
static uint8_t IIC_Wait_Ack(void);
static void IIC_Ack(void);
static void IIC_NAck(void);
static void IIC_Send_Byte(uint8_t txd);
static uint8_t IIC_Read_Byte(uint8_t ack);
static bool GT911_Scan(POINT* point);
static int touch_open(FAR struct file *filep);
static int touch_close(FAR struct file *filep);
static ssize_t touch_read(FAR struct file *filep, FAR char *buffer, size_t buflen);
static ssize_t touch_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
/****************************************************************************
* Private Data
****************************************************************************/
/* touch POSIX interface */
static const struct file_operations g_touchfops =
{
touch_open,
touch_close,
touch_read,
touch_write,
NULL,
NULL,
NULL
};
/****************************************************************************
* Name: IIC_Init
* Description: i2c pin mode configure
@ -31,7 +69,7 @@
* output: None
* return:none
****************************************************************************/
void IIC_Init(void)
static void IIC_Init(void)
{
/* config simluate IIC bus */
k210_fpioa_config(BSP_IIC_SDA, GT911_FUNC_GPIO(FPIOA_IIC_SDA));
@ -48,7 +86,7 @@ void IIC_Init(void)
* output: None
* return:none
****************************************************************************/
void SDA_IN(void)
static void SDA_IN(void)
{
k210_gpiohs_set_direction(FPIOA_IIC_SDA, GPIO_DM_INPUT_PULL_UP);
}
@ -60,7 +98,7 @@ void SDA_IN(void)
* output: None
* return:none
****************************************************************************/
void SDA_OUT(void)
static void SDA_OUT(void)
{
k210_gpiohs_set_direction(FPIOA_IIC_SDA, GPIO_DM_OUTPUT);
}
@ -72,7 +110,7 @@ void SDA_OUT(void)
* output: None
* return: sda pin value
****************************************************************************/
uint8_t READ_SDA(void)
static uint8_t READ_SDA(void)
{
return k210_gpiohs_get_value(FPIOA_IIC_SDA);
}
@ -84,7 +122,7 @@ uint8_t READ_SDA(void)
* output: None
* return: None
****************************************************************************/
void IIC_SCL(uint8_t val)
static void IIC_SCL(uint8_t val)
{
if (val)
k210_gpiohs_set_value(FPIOA_IIC_SCL,GPIO_PV_HIGH);
@ -101,7 +139,7 @@ void IIC_SCL(uint8_t val)
* output: None
* return: None
****************************************************************************/
void IIC_SDA(uint8_t val)
static void IIC_SDA(uint8_t val)
{
if (val)
k210_gpiohs_set_value(FPIOA_IIC_SDA,GPIO_PV_HIGH);
@ -118,7 +156,7 @@ void IIC_SDA(uint8_t val)
* output: None
* return: None
****************************************************************************/
void IIC_Start(void)
static void IIC_Start(void)
{
SDA_OUT();
IIC_SDA(1);
@ -136,7 +174,7 @@ void IIC_Start(void)
* output: None
* return: None
****************************************************************************/
void IIC_Stop(void)
static void IIC_Stop(void)
{
SDA_OUT();
IIC_SCL(1);
@ -153,7 +191,7 @@ void IIC_Stop(void)
* output: None
* return: Return value: 1:failed to receive response,0:the received response is successful.
********************************************************************************************/
uint8_t IIC_Wait_Ack(void)
static uint8_t IIC_Wait_Ack(void)
{
uint16_t ucErrTime=0;
SDA_IN();
@ -181,7 +219,7 @@ uint8_t IIC_Wait_Ack(void)
* output: None
* return: None
****************************************************************************/
void IIC_Ack(void)
static void IIC_Ack(void)
{
IIC_SCL(0);
SDA_OUT();
@ -200,7 +238,7 @@ void IIC_Ack(void)
* output: None
* return: None
****************************************************************************/
void IIC_NAck(void)
static void IIC_NAck(void)
{
IIC_SCL(0);
SDA_OUT();
@ -219,7 +257,7 @@ void IIC_NAck(void)
* output: None
* return: 1:there is a response,0:no response
****************************************************************************/
void IIC_Send_Byte(uint8_t txd)
static void IIC_Send_Byte(uint8_t txd)
{
uint8_t t;
SDA_OUT();
@ -243,7 +281,7 @@ void IIC_Send_Byte(uint8_t txd)
* output: None
* return: Returns one byte of data read
****************************************************************************/
uint8_t IIC_Read_Byte(uint8_t ack)
static uint8_t IIC_Read_Byte(uint8_t ack)
{
uint8_t i,receive=0;
SDA_IN();
@ -322,20 +360,6 @@ static void GT911_RD_Reg(uint16_t reg,uint8_t *buf,uint8_t len)
IIC_Stop();
}
/***********************************************************************************
* Name: GT911_ReadFirmwareVersion
* Description: Get firmware version number
* input: None
* output: None
* return: version number
***********************************************************************************/
static uint16_t GT911_ReadFirmwareVersion(void)
{
uint8_t buf[2];
GT911_RD_Reg(GT911_FIRMWARE_VERSION_REG, buf, 2);
return ((uint16_t)buf[1] << 8) + buf[0];
}
/***********************************************************************************
* Name: GT911_Scan
* Description: point:structure to store coordinates
@ -343,7 +367,7 @@ static uint16_t GT911_ReadFirmwareVersion(void)
* output: None
* return: Returns true for touch, false for no touch
***********************************************************************************/
bool GT911_Scan(POINT* point)
static bool GT911_Scan(POINT* point)
{
GT911_Dev Dev_Now;
uint8_t Clearbuf = 0;
@ -378,32 +402,74 @@ bool GT911_Scan(POINT* point)
if(Dev_Now.Y[i] > GT911_MAX_HEIGHT -20) Dev_Now.Y[i]=GT911_MAX_HEIGHT - 20;
if(Dev_Now.X[i] < 20) Dev_Now.X[i] = 20;
if(Dev_Now.X[i] > GT911_MAX_WIDTH-20) Dev_Now.X[i] = GT911_MAX_WIDTH - 20;
point->X = Dev_Now.X[i];
point->Y = Dev_Now.Y[i];
point->x = Dev_Now.X[i];
point->y = Dev_Now.Y[i];
}
}
return true;
}
/****************************************************************************
* Name: touch_open
****************************************************************************/
static int touch_open(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: touch_close
****************************************************************************/
static int touch_close(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: lcd_read
****************************************************************************/
static ssize_t touch_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
{
int ret = -ERROR;
POINT touch_point = {0, 0, 0};
if (buffer == NULL)
{
return -ERROR;
}
POINT* data = (POINT*)buffer;
while(1)
{
if(GT911_Scan(&touch_point))
{
data->x = touch_point.x;
data->y = touch_point.y;
ret = buflen;
break;
}
}
return ret;
}
/****************************************************************************
* Name: lcd_read
****************************************************************************/
static ssize_t touch_write(FAR struct file *filep, FAR const char *buffer, size_t buflen)
{
return OK;
}
/***********************************************************************************
* Name: GT911_test
* Description: gt911 test code
* Name: board_touch_initialize
* Description: touch initialize
* input: None
* output: None
* return: Returns true for touch, false for no touch
* return: None
***********************************************************************************/
void GT911_test(void)
void board_touch_initialize(void)
{
uint16_t res;
POINT point = {0, 0};
IIC_Init();
res = GT911_ReadFirmwareVersion();
printf("FirmwareVersion:%2x\n",res);
while(1)
{
if(GT911_Scan(&point))
{
printf("Now touch point:(%d,%d)\n",point.X,point.Y);
}
}
/* register device */
register_driver("/dev/touch_dev", &g_touchfops, 0666, NULL);
}

View File

@ -63,26 +63,13 @@ typedef struct
uint16_t S[CT_MAX_TOUCH];
}GT911_Dev;
typedef struct
typedef struct
{
uint16_t X;
uint16_t Y;
uint16_t x;
uint16_t y;
uint16_t press;
}POINT;
void IIC_Init(void);
void SDA_IN(void);
void SDA_OUT(void);
uint8_t READ_SDA(void);
void IIC_SCL(uint8_t val);
void IIC_SDA(uint8_t val);
void IIC_Start(void);
void IIC_Stop(void);
uint8_t IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
void IIC_Send_Byte(uint8_t txd);
uint8_t IIC_Read_Byte(uint8_t ack);
bool GT911_Scan(POINT* point);
void GT911_test(void);
void board_touch_initialize(void);
#endif

View File

@ -68,11 +68,11 @@ int cmd_w5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* Name: cmd_Touch
****************************************************************************/
#if defined(CONFIG_BSP_USING_TOUCH) && !defined(CONFIG_NSH_DISABLE_TOUCH)
extern void GT911_test(void);
extern void TestTouch(void);
int cmd_Touch(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, "Hello, world!\n");
GT911_test();
TestTouch();
return OK;
}
#endif