forked from xuos/xiuos
Optimize lcd driver for xidatong-riscv64 on nuttx
This commit is contained in:
parent
a04a4288a7
commit
c541128122
|
@ -22,17 +22,11 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
|
||||
#ifdef CONFIG_K210_LCD
|
||||
|
||||
#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 = 50, y1 = 50, x2 = LCD_XSIZE_TFT - 50, y2 = LCD_YSIZE_TFT - 50;
|
||||
|
@ -72,18 +66,6 @@ void LcdDemo(void)
|
|||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
#include <nuttx/video/rgbcolors.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Preprocessor Definitions
|
||||
****************************************************************************/
|
||||
|
|
|
@ -25,11 +25,33 @@
|
|||
#include <nuttx/pthread.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <nuttx/wireless/lpwan/sx127x.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/ioexpander/gpio.h>
|
||||
#include <termios.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#ifdef CONFIG_ADAPTER_SX1278
|
||||
#include <nuttx/wireless/lpwan/sx127x.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USER_TEST_LCD
|
||||
#ifdef CONFIG_K210_LCD
|
||||
# include "nuttx/lcd/lt768.h"
|
||||
# include "nuttx/lcd/lt768_lib.h"
|
||||
# include "nuttx/lcd/if_port.h"
|
||||
#else
|
||||
# include <sys/mman.h>
|
||||
# include <nuttx/video/fb.h>
|
||||
# include <nuttx/video/rgbcolors.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
|
|
|
@ -111,6 +111,14 @@ extern "C"
|
|||
#define BSP_ENET_NRST 13
|
||||
#define BSP_ENET_NINT 14
|
||||
|
||||
/* LCD IO */
|
||||
#define BSP_LCD_NRST 37
|
||||
#define BSP_LCD_SCLK 38
|
||||
#define BSP_LCD_MOSI 39
|
||||
#define BSP_LCD_MISO 40
|
||||
#define BSP_LCD_NCS 41
|
||||
#define BSP_LCD_BL_PIN 47
|
||||
|
||||
/* I2C */
|
||||
#define BSP_IIC_SDA 15
|
||||
#define BSP_IIC_SCL 17
|
||||
|
@ -157,6 +165,14 @@ extern "C"
|
|||
#define FPIOA_ENET_MOSI 23
|
||||
#define FPIOA_ENET_NCS 31
|
||||
|
||||
/* LCD FPIOA */
|
||||
#define FPIOA_LCD_NRST 0
|
||||
#define FPIOA_LCD_BL 9
|
||||
#define FPIOA_LCD_SCLK 28
|
||||
#define FPIOA_LCD_MOSI 29
|
||||
#define FPIOA_LCD_MISO 23
|
||||
#define FPIOA_LCD_NCS 31
|
||||
|
||||
/* I2C */
|
||||
#define FPIOA_IIC_SDA 7
|
||||
#define FPIOA_IIC_SCL 8
|
||||
|
|
|
@ -35,7 +35,7 @@ CSRCS += k210_leds.c
|
|||
endif
|
||||
|
||||
ifeq ($(CONFIG_K210_LCD),y)
|
||||
CSRCS += k210_lcd.c lcd_demo.c
|
||||
CSRCS += k210_lcd.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEV_GPIO),y)
|
||||
|
|
|
@ -80,11 +80,7 @@ int k210_bringup(void)
|
|||
|
||||
#ifdef CONFIG_K210_LCD
|
||||
k210_sysctl_init();
|
||||
ret = board_lcd_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_NOTICE, "board lcd initialize %d\n", ret);
|
||||
}
|
||||
board_lcd_initialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_K210_16550_UART1
|
||||
|
|
|
@ -28,24 +28,24 @@
|
|||
#include "nuttx/arch.h"
|
||||
#include "nuttx/lcd/lt768.h"
|
||||
#include "nuttx/lcd/lt768_lib.h"
|
||||
#include "nuttx/lcd/k210_lcd.h"
|
||||
#include "nuttx/lcd/if_port.h"
|
||||
#include <nuttx/board.h>
|
||||
#include <arch/board/board.h>
|
||||
#ifdef CONFIG_LCD_LCDDRV_SPIIF
|
||||
#include "nuttx/lcd/lcddrv_spiif.h"
|
||||
#endif
|
||||
|
||||
#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)
|
||||
#define CLK_L() k210_gpiohs_set_value(FPIOA_LCD_SCLK, GPIO_PV_LOW); up_udelay(20)
|
||||
#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)
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
|
@ -60,9 +60,9 @@ void lcd_pin_init(void)
|
|||
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);
|
||||
k210_gpiohs_set_value(FPIOA_LCD_SCLK, GPIO_PV_HIGH);
|
||||
k210_gpiohs_set_value(FPIOA_LCD_NCS, GPIO_PV_HIGH);
|
||||
k210_gpiohs_set_value(FPIOA_LCD_NRST, GPIO_PV_HIGH);
|
||||
}
|
||||
|
||||
void lcd_backlight_init(bool enable)
|
||||
|
@ -86,74 +86,74 @@ uint8_t lcd_transfer_byte(uint8_t dat)
|
|||
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
CLK_H;
|
||||
CLK_H();
|
||||
|
||||
// MOSI during falling edge
|
||||
if((dat << i) & 0x80)
|
||||
{
|
||||
MOSI_H;
|
||||
MOSI_H();
|
||||
}
|
||||
else
|
||||
{
|
||||
MOSI_L;
|
||||
MOSI_L();
|
||||
}
|
||||
|
||||
CLK_L;
|
||||
CLK_L();
|
||||
|
||||
// MISO during rising edge
|
||||
rx_data <<= 1;
|
||||
if(lcd_get_pin(FPIOA_LCD_MISO))
|
||||
if(k210_gpiohs_get_value(FPIOA_LCD_MISO))
|
||||
rx_data ++;
|
||||
}
|
||||
CLK_H;
|
||||
CLK_H();
|
||||
return rx_data;
|
||||
}
|
||||
|
||||
void LCD_CmdWrite(uint8_t cmd)
|
||||
{
|
||||
NCS_L;
|
||||
NCS_L();
|
||||
lcd_transfer_byte(0x00);
|
||||
lcd_transfer_byte(cmd);
|
||||
NCS_H;
|
||||
NCS_H();
|
||||
}
|
||||
|
||||
void LCD_DataWrite(uint8_t data)
|
||||
{
|
||||
NCS_L;
|
||||
NCS_L();
|
||||
lcd_transfer_byte(0x80);
|
||||
lcd_transfer_byte(data);
|
||||
NCS_H;
|
||||
NCS_H();
|
||||
}
|
||||
|
||||
void LCD_DataWrite_Pixel(uint8_t data)
|
||||
{
|
||||
NCS_L;
|
||||
NCS_L();
|
||||
lcd_transfer_byte(0x80);
|
||||
lcd_transfer_byte(data);
|
||||
NCS_H;
|
||||
NCS_L;
|
||||
NCS_H();
|
||||
NCS_L();
|
||||
lcd_transfer_byte(0x80);
|
||||
lcd_transfer_byte(data >> 8);
|
||||
NCS_H;
|
||||
NCS_H();
|
||||
}
|
||||
|
||||
uint8_t LCD_StatusRead(void)
|
||||
{
|
||||
uint8_t temp = 0;
|
||||
NCS_L;
|
||||
NCS_L();
|
||||
lcd_transfer_byte(0x40);
|
||||
temp = lcd_transfer_byte(0xff);
|
||||
NCS_H;
|
||||
NCS_H();
|
||||
return temp;
|
||||
}
|
||||
|
||||
uint8_t LCD_DataRead(void)
|
||||
{
|
||||
uint8_t temp = 0;
|
||||
NCS_L;
|
||||
NCS_L();
|
||||
lcd_transfer_byte(0xc0);
|
||||
temp = lcd_transfer_byte(0xff);
|
||||
NCS_H;
|
||||
NCS_H();
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -195,11 +195,12 @@ void lcd_drv_init(void)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void board_lcd_initialize(void)
|
||||
int board_lcd_initialize(void)
|
||||
{
|
||||
/* Configure the LCD backlight (and turn the backlight off) */
|
||||
lcd_backlight_init(true);
|
||||
lcd_drv_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/****************************************************************************
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1839,11 +1839,9 @@ void Display_ON(void)
|
|||
uint8_t temp;
|
||||
LCD_CmdWrite(0x12);
|
||||
temp = LCD_DataRead();
|
||||
syslog(LOG_NOTICE, "Display_ON.pre_read=%02x\n", temp);
|
||||
temp |= cSetb6;
|
||||
LCD_DataWrite(temp);
|
||||
temp = LCD_DataRead();
|
||||
syslog(LOG_NOTICE, "Display_ON.write_read=%02x\n", temp);
|
||||
}
|
||||
|
||||
void Display_OFF(void)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* k210_lcd.h
|
||||
* if_port.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
@ -19,73 +19,31 @@
|
|||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file k210_lcd.h
|
||||
* @file if_port.h
|
||||
* @brief
|
||||
* @version 1.0.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-07-21
|
||||
*/
|
||||
|
||||
#ifndef __K210_LCD_H_
|
||||
#define __K210_LCD_H_
|
||||
#ifndef _IF_PORT_H
|
||||
#define _IF_PORT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "nuttx/lcd/lt768.h"
|
||||
#include "nuttx/lcd/lt768_lib.h"
|
||||
|
||||
//PIN.define
|
||||
#define BSP_LCD_NRST 37
|
||||
#define BSP_LCD_SCLK 38
|
||||
#define BSP_LCD_MOSI 39
|
||||
#define BSP_LCD_MISO 40
|
||||
#define BSP_LCD_NCS 41
|
||||
#define BSP_LCD_BL_PIN 47
|
||||
|
||||
//FPIOA.define
|
||||
#define FPIOA_LCD_NRST 0
|
||||
#define FPIOA_LCD_BL 9
|
||||
#define FPIOA_LCD_SCLK 28
|
||||
#define FPIOA_LCD_MOSI 29
|
||||
#define FPIOA_LCD_MISO 23 //can't use GPIOHS30
|
||||
#define FPIOA_LCD_NCS 31
|
||||
|
||||
#define GPIO_PV_HIGH 1 // true
|
||||
#define GPIO_PV_LOW 0 // false
|
||||
|
||||
#define LCD_START_ADDR 0
|
||||
#define STM32_FSMC_8 0
|
||||
|
||||
#define lcd_set_pin k210_gpiohs_set_value
|
||||
#define lcd_get_pin k210_gpiohs_get_value
|
||||
|
||||
void test_delay(void);
|
||||
|
||||
#define lcd_delay() up_udelay(20)
|
||||
|
||||
#define NCS_H lcd_set_pin(FPIOA_LCD_NCS, GPIO_PV_HIGH); lcd_delay()
|
||||
#define NCS_L lcd_set_pin(FPIOA_LCD_NCS, GPIO_PV_LOW); lcd_delay()
|
||||
|
||||
#define CLK_H lcd_set_pin(FPIOA_LCD_SCLK, GPIO_PV_HIGH); lcd_delay()
|
||||
#define CLK_L lcd_set_pin(FPIOA_LCD_SCLK, GPIO_PV_LOW); lcd_delay()
|
||||
|
||||
#define MOSI_H lcd_set_pin(FPIOA_LCD_MOSI, GPIO_PV_HIGH)
|
||||
#define MOSI_L lcd_set_pin(FPIOA_LCD_MOSI, GPIO_PV_LOW)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void lcd_backlight_init(bool enable);
|
||||
void lcd_drv_init(void);
|
||||
|
||||
void LCD_CmdWrite(uint8_t cmd);
|
||||
void LCD_DataWrite(uint8_t data);
|
||||
uint8_t LCD_DataRead(void);
|
||||
uint8_t LCD_StatusRead(void);
|
||||
void LCD_DataWrite_Pixel(uint8_t data);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue