本帖最后由 xiaoch669 于 2024-2-1 16:33 编辑
大家好,
最近我尝试使用 SDK中aithinker_Ai-M6X_SDK\bsp\common\lcd文件夹下的代码驱动1.3寸LCD,我想在这里分享一下我的经验和一些解决方案。希望这对那些遇到类似问题的人有所帮助。
驱动位置:
屏幕参数:
接口:SPI
微控制器:Ai-M61-32S-Kit
配置屏幕参数首先要新建自己的配置文件lcd_conf_user.h
根据自己屏幕的驱动在lcd_conf.h选择合适的参数写入lcd_conf_user.h中
lcd_conf_user.h如下:
包含引脚信息
- #ifndef _LCD_CONF_USER_H_
- #define _LCD_CONF_USER_H_
- #define LCD_SPI_ST7789V
- #define LCD_SPI_INTERFACE_TYPE 1
- /* Selecting pixel format
- 1: rgb565
- */
- #define ST7789V_SPI_PIXEL_FORMAT 1
- /* enable the lcd reset function
- 0: Does not care about lcd hard reset
- 1: use gpio to reset the lcd
- */
- #define LCD_RESET_EN 1
- /* LCD width and height */
- #define ST7789V_SPI_W 240 //宽度
- #define ST7789V_SPI_H 240 //高度
- /* The offset of the area can be displayed */
- #define ST7789V_SPI_OFFSET_X 0
- #define ST7789V_SPI_OFFSET_Y 0
- /********** SPI hard 4-wire configuration ***********/
- #if (defined(LCD_SPI_INTERFACE_TYPE) && (LCD_SPI_INTERFACE_TYPE == 1))
- /* spi idx */
- #define LCD_SPI_HARD_4_NAME "spi0"
- /* dma used by spi */
- #define LCD_SPI_HARD_4_DMA_NAME "dma0_ch3"
- /* The maximum pixel cnt to be transferred affects the number of LLI memory pools */
- #define LCD_SPI_HARD_4_PIXEL_CNT_MAX (800 * 640)
- /* spi pin, hardware controlled */
- #define LCD_SPI_HARD_4_PIN_CLK GPIO_PIN_13 //SCL引脚
- #define LCD_SPI_HARD_4_PIN_DAT GPIO_PIN_15 //SDA引脚
- /* cs/dc pin, software controlled */
- #define LCD_SPI_HARD_4_PIN_CS GPIO_PIN_14 //CS引脚
- #define LCD_SPI_HARD_4_PIN_DC GPIO_PIN_16 // DC引脚
- #endif
- /********** lcd reset configuration ***********/
- #if (defined(LCD_RESET_EN) && LCD_RESET_EN)
- /* lcd reset signal pin, please leave blank if not needed */
- #define LCD_RESET_PIN GPIO_PIN_12 //RES引脚
- /* lcd reset signal active level
- 0: lcd reset at low level
- 1: lcd reset at high level
- */
- #define LCD_RESET_ACTIVE_LEVEL 0
- /* lcd reset active hold time (ms) */
- #define LCD_RESET_HOLD_MS 10
- /* lcd recovery time after reset end (ms) */
- #define LCD_RESET_DELAY 100
- /********** lcd blk configuration ***********/
- /*BLK背光引脚不用可以悬空不接*/
- #define LCD_BLK_PIN GPIO_PIN_17 //BLK引脚
- #endif
- #endif
复制代码 如果需要配置BLK引脚,需要在lcd.c中增加以下代码
- #if LCD_BLK_PIN
- bflb_gpio_init(gpio, LCD_BLK_PIN, GPIO_OUTPUT | GPIO_PULLUP);
- bflb_gpio_set(gpio, LCD_BLK_PIN);
- #endif
复制代码
位置如下:
main.c如下
- #include "bflb_mtimer.h"
- #include "bflb_spi.h"
- #include "board.h"
- #include "bflb_gpio.h"
- #include "lcd.h"
- #include "spi\st7796_spi.h"
- #include "spi\bl_spi_hard_4.h"
- int main()
- {
- lcd_color_t red = LCD_COLOR_RGB(255, 0, 0);
- lcd_color_t white=LCD_COLOR_RGB(255,255,255);
- board_init();
- st7789v_spi_init();
- lcd_init();
- lcd_set_dir(0,0);
- lcd_clear(white);
- while (1)
- {
- //lcd_draw_line(0,0,20,20,my_color);
- lcd_draw_str_ascii16(0,0,red,white,"hello world",11);
- lcd_draw_area(80,80,200,200,red);
- }
-
- }
复制代码
CMakeLists.txt如下
- cmake_minimum_required(VERSION 3.15)
- include(proj.conf)
- find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
- sdk_set_main_file(main.c)
- target_sources(app PRIVATE
- lcd_conf.h
- lcd.c
- lcd_conf_user.h
- lcd.h
- font.h
- font.c
- spi/bl_spi_hard_4.h
- spi/bl_spi_hard_4.c
- spi/st7789v_spi.h
- spi/st7789v_spi.c
- )
- sdk_add_include_directories(.)
- project(helloworld)
复制代码 实验现象
驱动代码:
lcd.rar
(77.91 KB, 下载次数: 15)
|
|