一、说明
AI-Talk开发板配备了一块2.4寸的液晶屏,带触屏,LCD驱动IC:ST7789V2,通信接口:SPI,触摸驱动IC:FT5336。
1、LCD接口
使用四线SPI接口。
与处理器的信号连接:
2、触摸接口
使用I2C接口。
与处理器的信号连接:
二、工程
1、创建项目
进入snap/examples/目录,执行创建项目的命令:
lisa zep create
选择display_kscan,然后确定。此时examples目录下有一个display_kscan的工程,这个工程包含液晶和触屏的功能,并且驱动IC也和所用的液晶屏一样。
目录结构如下:
boardscsk6011a_nano.overlaycsk6012_nano.overlay
CMakeLists.txt
prj.conf
README.rst
sample.yaml
srcmain.c
boards目录下包含了两个不同开发板的设备树覆盖文件,设备树覆盖文件用于配置LCD和触屏的硬件信息。
2、配置文件
因为用到的CH32的GPIO和PWM,所以还需要加入:
CONFIG_GPIO_CSK6_CH32V003=yCONFIG_PWM=y
CONFIG_PWM_CSK6_CH32V003=y
3、设备树
修改设备树覆盖csk6011a_nano.overlay,将液晶屏接口由spi0改为spi1,触摸屏接口由i2c0改为i2c1,并且加入CH32V003的配置信息。
修改之后内容如下:
/** Copyright (c) 2023 Anhui(Shenzhen) Listenai Co., Ltd.** SPDX-License-Identifier: Apache-2.0*/#include <zephyr/dt-bindings/adc/adc.h>/ {chosen {zephyr,display=&st7789v;zephyr,keyboard-scan=&ft5336;}; aliases {csk6-exmcu = &csk6_ch32v003;lcd-pwm-ctl = &lcd_pwm_ctl;};pwms {lcd_pwm: lcd_pwm {compatible = "vnd,phandle-holder";status = "okay";pwms = <&expwm 0 12 0x0 100>;};}; leds {lcd_pwm_ctl: lcd_pwm_ctl {gpios = <&exgpiod 2 GPIO_ACTIVE_LOW>;};};
};&pinctrl {pinctrl_i2c1_scl_default: i2c1_scl_default{pinctrls = <I2C1_SCL_GPIOB_09>;};pinctrl_i2c1_sda_default: i2c1_sda_default{pinctrls = <I2C1_SDA_GPIOB_08>;};pinctrl_spi1_sclk_default: spi1_sclk_default {pinctrls = <SPI1_CLK_GPIOA_16>;};pinctrl_spi1_mosi_default: spi1_mosi_default {pinctrls = <SPI1_MOSI_GPIOA_15>;};pinctrl_spi1_cs_default: spi1_cs_default {pinctrls = <SPI1_CS_N_GPIOA_17>;};};&spi1 {status = "okay";pinctrl-0 = <&pinctrl_spi1_sclk_default &pinctrl_spi1_mosi_default &pinctrl_spi1_cs_default>;pinctrl-names = "default";st7789v:st7789v@0 {compatible = "sitronix,st7789v";status = "okay";spi-max-frequency = <20000000>;reg = <0>;cmd-data-gpios = <&gpioa 18 1>;reset-gpios = <&exgpiod 4 0>;width = <320>;height = <240>;x-offset = <0>;y-offset = <0>;// reg: 0xBBvcom = <0x1e>;// reg: 0xB7gctrl = <0x35>;// reg: 0xC3vrhs = <0x0b>;// reg: 0xC4vdvs = <0x20>;// reg: 0x36mdac = <0xA3>;// reg: 0x26gamma = <0x01>;// reg: 0x3acolmod = <0x05>;// reg: 0xc0lcm = <0x3c>;// reg: 0xb2porch-param = [ 0c 0c 00 33 33 ];// reg: 0xDFcmd2en-param = [ 5a 69 02 01 ];// reg: 0xD0pwctrl1-param = [ a4 a1 ];// reg: 0xE0pvgam-param = [ d0 06 0b 07 07 24 2e 32 46 37 13 13 2d 33 ];// reg: 0xE1nvgam-param = [ d0 02 06 09 08 05 29 44 42 38 14 14 2a 30 ];// reg: b0ram-param = [ 00 F0 ];// reg: b1rgb-param = [ CD 08 14 ];};
};&i2c1 {status = "okay";pinctrl-0 = <&pinctrl_i2c1_scl_default &pinctrl_i2c1_sda_default>;pinctrl-names = "default";csk6_ch32v003: csk6_ch32v003@6c {/*** Please make sure that the external MCU firmware has been loaded* SCL --> external MCU PC5* SDA --> external MCU PC6*/compatible = "listenai,csk-i2c-ch32v003";reg = <0x6c>;status = "okay";#address-cells = <1>;#size-cells = <0>;/* CH32V003-GPIOA */exgpioa: gpio@0 {compatible = "listenai,csk-gpio-ch32003-port";reg = <0x00>;status = "okay";ngpios = <8>;#gpio-cells = <2>;gpio-controller;pin_mask = <0x00>;};/* CH32V003-GPIOB */exgpiob: gpio@1 {compatible = "listenai,csk-gpio-ch32003-port";reg = <0x01>;status = "okay";ngpios = <8>;#gpio-cells = <2>;gpio-controller;pin_mask = <0x00>;};/* CH32V003-GPIOC */exgpioc: gpio@2 {compatible = "listenai,csk-gpio-ch32003-port";reg = <0x02>;status = "okay";ngpios = <8>;#gpio-cells = <2>;gpio-controller;pin_mask = <0x00>;};/* CH32V003-GPIOD */exgpiod: gpio@3 {compatible = "listenai,csk-gpio-ch32003-port";reg = <0x03>;status = "okay";ngpios = <8>;#gpio-cells = <2>;gpio-controller;pin_mask = <0x00>;};exadc: adc@4 {/*** external adc channel map** CH0 --> PA2* CH1 --> PA1* CH2 --> PC4* CH3 --> PD2* CH4 --> PD3* CH5 --> PD5* CH6 --> PD6* CH7 --> PD4**/compatible = "listenai,csk-adc-ch32v003";reg = <0x4>;status = "okay";#io-channel-cells = <1>;#address-cells = <1>;#size-cells = <0>;channel@2 {reg = <2>;zephyr,gain = "ADC_GAIN_1";zephyr,reference = "ADC_REF_INTERNAL";zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;zephyr,resolution = <10>;};};expwm: pwm-controller@5 {compatible = "listenai,csk-ch32v003-pwm";reg = <0x5>;status = "okay";clock-prescaler = <480>;clock-frequency = <48000000>;#pwm-cells = <4>;};};ft5336:ft5336@0 {compatible = "focaltech,ft5336";reg = <56>;status = "okay";int-gpios = <&gpiob 7 0>;reset-gpios = <&exgpiod 3 0>;};
};
由于snap/lisa/x1/.listenai/csk-sdk-v2/csk/boards/arm/csk6011a_nano/csk6011a_nano_pinctrl.dtsi文件中将GPIOA_17、GPIOA_18、GPIOA_19定义了spi0的管脚,与LCD所用的管脚冲突了,需要屏蔽csk6011a_nano_pinctrl.dtsi中关于pinctrl_spi0的定义:
/* SPIC alternate function */
// pinctrl_spi0_cs_default: spi0_cs_default{
// pinctrls = <SPI0_CS_N_GPIOA_20>;
// };// pinctrl_spi0_miso_default: spi0_miso_default{
// pinctrls = <SPI0_MISO_GPIOA_17>;
// };// pinctrl_spi0_mosi_default: spi0_mosi_default{
// pinctrls = <SPI0_MOSI_GPIOA_18>;
// };// pinctrl_spi0_sclk_default: spi0_sclk_default{
// pinctrls = <SPI0_CLK_GPIOA_19>;
// };
4、 代码
不做修改。
三、编译
在display_kscan目录下执行编译命令:
lisa zep build -b csk6011a_nano
编译生成的固件:examples/display_kscan/build/zephyr/zephyr.bin
四、烧录
固件的烧录及查看运行日志参照:AI-Talk开发板CSK6固件烧录-CSDN博客