support lt768 lcd
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NSH_DISABLE_LOSMART is not set
|
||||
# CONFIG_STANDARD_SERIAL is not set
|
||||
CONFIG_ADD_NUTTX_FETURES=y
|
||||
CONFIG_ARCH="risc-v"
|
||||
CONFIG_ARCH_BOARD="xidatong-riscv64"
|
||||
CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y
|
||||
CONFIG_ARCH_CHIP="k210"
|
||||
CONFIG_ARCH_CHIP_K210=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BINFMT_DISABLE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=46000
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=2048
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_PERROR_STDOUT=y
|
||||
CONFIG_LIBC_STRERROR=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_DISABLE_IFUPDOWN=y
|
||||
CONFIG_NSH_DISABLE_MKDIR=y
|
||||
CONFIG_NSH_DISABLE_RM=y
|
||||
CONFIG_NSH_DISABLE_RMDIR=y
|
||||
CONFIG_NSH_DISABLE_UMOUNT=y
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NSH_STRERROR=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=2097152
|
||||
CONFIG_RAM_START=0x80400000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_READLINE_CMD_HISTORY=y
|
||||
CONFIG_READLINE_CMD_HISTORY_LEN=100
|
||||
CONFIG_READLINE_CMD_HISTORY_LINELEN=120
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_STACK_COLORATION=y
|
||||
CONFIG_START_DAY=28
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2019
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=20
|
||||
CONFIG_TESTING_GETPRIME=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_READLINE_TABCOMPLETION=y
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_DEV_GPIO=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_K210_HAVE_LCD=y
|
||||
CONFIG_K210_LCD=y
|
||||
CONFIG_K210_LCD_BACKLIGHT=y
|
||||
CONFIG_LCD=y
|
||||
CONFIG_LCD_LT768=y
|
||||
@@ -34,6 +34,10 @@ ifeq ($(CONFIG_ARCH_LEDS),y)
|
||||
CSRCS += k210_leds.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_K210_LCD),y)
|
||||
CSRCS += k210_lcd.c lcd_demo.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEV_GPIO),y)
|
||||
CSRCS += k210_gpio.c
|
||||
endif
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "k210.h"
|
||||
#include "k210_clockconfig.h"
|
||||
#include "xidatong-riscv64.h"
|
||||
|
||||
#ifdef CONFIG_BSP_USING_CH438
|
||||
@@ -75,5 +76,14 @@ int k210_bringup(void)
|
||||
board_ch438_initialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_K210_LCD
|
||||
k210_sysctl_init();
|
||||
ret = board_lcd_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_NOTICE, "board lcd initialize %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file k210_lcd.c
|
||||
* @brief LCD relative driver
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.7.21
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "k210_fpioa.h"
|
||||
#include "k210_gpiohs.h"
|
||||
#include "nuttx/arch.h"
|
||||
#include "nuttx/lcd/lt768.h"
|
||||
#include "nuttx/lcd/lt768_lib.h"
|
||||
#include "nuttx/lcd/k210_lcd.h"
|
||||
#ifdef CONFIG_LCD_LCDDRV_SPIIF
|
||||
#include "nuttx/lcd/lcddrv_spiif.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void test_delay(void)
|
||||
{
|
||||
volatile uint32_t i = 0;
|
||||
for (i = 0; i < 200; ++i)
|
||||
{
|
||||
__asm("NOP"); /* delay */
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_pin_init(void)
|
||||
{
|
||||
k210_fpioa_config(BSP_LCD_NRST, HS_GPIO(FPIOA_LCD_NRST) | K210_IOFLAG_GPIOHS);
|
||||
k210_fpioa_config(BSP_LCD_SCLK, HS_GPIO(FPIOA_LCD_SCLK) | K210_IOFLAG_GPIOHS);
|
||||
k210_fpioa_config(BSP_LCD_MOSI, HS_GPIO(FPIOA_LCD_MOSI) | K210_IOFLAG_GPIOHS);
|
||||
k210_fpioa_config(BSP_LCD_MISO, HS_GPIO(FPIOA_LCD_MISO) | K210_IOFLAG_GPIOHS);
|
||||
k210_fpioa_config(BSP_LCD_NCS, HS_GPIO(FPIOA_LCD_NCS) | K210_IOFLAG_GPIOHS);
|
||||
|
||||
k210_gpiohs_set_direction(FPIOA_LCD_MISO, GPIO_DM_INPUT);
|
||||
k210_gpiohs_set_direction(FPIOA_LCD_NRST, GPIO_DM_OUTPUT);
|
||||
k210_gpiohs_set_direction(FPIOA_LCD_SCLK, GPIO_DM_OUTPUT);
|
||||
k210_gpiohs_set_direction(FPIOA_LCD_MOSI, GPIO_DM_OUTPUT);
|
||||
k210_gpiohs_set_direction(FPIOA_LCD_NCS, GPIO_DM_OUTPUT);
|
||||
|
||||
lcd_set_pin(FPIOA_LCD_SCLK, GPIO_PV_HIGH);
|
||||
lcd_set_pin(FPIOA_LCD_NCS, GPIO_PV_HIGH);
|
||||
lcd_set_pin(FPIOA_LCD_NRST, GPIO_PV_HIGH);
|
||||
}
|
||||
|
||||
void lcd_backlight_init(bool enable)
|
||||
{
|
||||
k210_fpioa_config(BSP_LCD_BL_PIN, HS_GPIO(FPIOA_LCD_BL) | K210_IOFLAG_GPIOHS);
|
||||
k210_gpiohs_set_direction(FPIOA_LCD_BL, GPIO_DM_OUTPUT);
|
||||
k210_gpiohs_set_value(FPIOA_LCD_BL, enable);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LCD_LCDDRV_SPIIF
|
||||
int spiif_backlight(FAR struct lcddrv_lcd_s *lcd, int level)
|
||||
{
|
||||
lcd_backlight_init(true);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t lcd_transfer_byte(uint8_t dat)
|
||||
{
|
||||
uint8_t i, rx_data = 0;
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
CLK_H;
|
||||
|
||||
// MOSI during falling edge
|
||||
if((dat << i) & 0x80)
|
||||
{
|
||||
MOSI_H;
|
||||
}
|
||||
else
|
||||
{
|
||||
MOSI_L;
|
||||
}
|
||||
|
||||
CLK_L;
|
||||
|
||||
// MISO during rising edge
|
||||
rx_data <<= 1;
|
||||
if(lcd_get_pin(FPIOA_LCD_MISO))
|
||||
rx_data ++;
|
||||
}
|
||||
CLK_H;
|
||||
return rx_data;
|
||||
}
|
||||
|
||||
void LCD_CmdWrite(uint8_t cmd)
|
||||
{
|
||||
NCS_L;
|
||||
lcd_transfer_byte(0x00);
|
||||
lcd_transfer_byte(cmd);
|
||||
NCS_H;
|
||||
}
|
||||
|
||||
void LCD_DataWrite(uint8_t data)
|
||||
{
|
||||
NCS_L;
|
||||
lcd_transfer_byte(0x80);
|
||||
lcd_transfer_byte(data);
|
||||
NCS_H;
|
||||
}
|
||||
|
||||
void LCD_DataWrite_Pixel(uint8_t data)
|
||||
{
|
||||
NCS_L;
|
||||
lcd_transfer_byte(0x80);
|
||||
lcd_transfer_byte(data);
|
||||
NCS_H;
|
||||
NCS_L;
|
||||
lcd_transfer_byte(0x80);
|
||||
lcd_transfer_byte(data >> 8);
|
||||
NCS_H;
|
||||
}
|
||||
|
||||
uint8_t LCD_StatusRead(void)
|
||||
{
|
||||
uint8_t temp = 0;
|
||||
NCS_L;
|
||||
lcd_transfer_byte(0x40);
|
||||
temp = lcd_transfer_byte(0xff);
|
||||
NCS_H;
|
||||
return temp;
|
||||
}
|
||||
|
||||
uint8_t LCD_DataRead(void)
|
||||
{
|
||||
uint8_t temp = 0;
|
||||
NCS_L;
|
||||
lcd_transfer_byte(0xc0);
|
||||
temp = lcd_transfer_byte(0xff);
|
||||
NCS_H;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void lcd_drv_init(void)
|
||||
{
|
||||
uint8_t PwmControl = 100;
|
||||
|
||||
lcd_pin_init();
|
||||
lt768_init();
|
||||
Select_SFI_Dual_Mode0();
|
||||
|
||||
// PWM1 enable backlight
|
||||
LT768_PWM1_Init(1, 0, 200, 100, PwmControl);
|
||||
|
||||
// enable RGB output
|
||||
Display_ON();
|
||||
|
||||
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);
|
||||
|
||||
//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)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void board_lcd_initialize(void)
|
||||
{
|
||||
/* Configure the LCD backlight (and turn the backlight off) */
|
||||
lcd_backlight_init(true);
|
||||
lcd_drv_init();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: k210_backlight
|
||||
*
|
||||
* Description:
|
||||
* If CONFIG_K210_LCD_BACKLIGHT is defined, then the board-specific
|
||||
* logic must provide this interface to turn the backlight on and off.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_K210_LCD_BACKLIGHT
|
||||
void k210_backlight(bool blon)
|
||||
{
|
||||
lcd_backlight_init(blon);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
* lcd_demo.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file lcd_demo.c
|
||||
* @brief
|
||||
* @version 1.0.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-07-21
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "nuttx/arch.h"
|
||||
#include "nuttx/lcd/lt768.h"
|
||||
#include "nuttx/lcd/lt768_lib.h"
|
||||
#include "nuttx/lcd/k210_lcd.h"
|
||||
|
||||
void LcdDemo(void)
|
||||
{
|
||||
// int x1 = 0, y1 = 0, x2 = LCD_XSIZE_TFT, y2 = LCD_YSIZE_TFT;
|
||||
int x1 = 100, y1 = 100, x2 = 200, y2 = 200;
|
||||
|
||||
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++)
|
||||
{
|
||||
syslog(LOG_NOTICE, "Disp_demo %d\n", i);
|
||||
LT768_DrawSquare_Fill(x1, y1, x2, y2, Red);
|
||||
up_mdelay(2000);
|
||||
LT768_DrawSquare_Fill(x1, y1, x2, y2, Green);
|
||||
up_mdelay(2000);
|
||||
LT768_DrawSquare_Fill(x1, y1, x2, y2, Blue);
|
||||
up_mdelay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user