ESP32S3+HX8347+3线SPI运行LVGL例程

一、clone lv_port_esp32到本地

git clone https://github.com/lvgl/lv_port_esp32.git

 二、增加hx8347.c、hx8347.h

        components\lvgl_esp32_drivers\lvgl_tft下新增2个文件:hx8347.c、hx8347.h。因为lv_port_esp32中没有hx8347的驱动,需要自己写。这两个hx8347.c、hx8347.h修改HX8357的配置文件改的,有很多冗余信息,不影响使用。

hx8347.h

/*** @file HX8347.h** Roughly based on the Adafruit_HX8347_Library** This library should work with:* Adafruit 3.5" TFT 320x480 + Touchscreen Breakout*    http://www.adafruit.com/products/2050** Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers*    https://www.adafruit.com/product/3651**/#ifndef HX8347_H
#define HX8347_H#ifdef __cplusplus
extern "C" {
#endif/**********************      INCLUDES*********************/
#include <stdbool.h>
#include <stdint.h>#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#include "../lvgl_helpers.h"/**********************      DEFINES*********************/
#define HX8347_DC   CONFIG_LV_DISP_PIN_DC
#define HX8347_RST  CONFIG_LV_DISP_PIN_RST
#define HX8347_BCKL CONFIG_LV_DISP_PIN_BCKL
#define HX8347_CS   6//CONFIG_LV_DISP_SPI_CS#define HX8347_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
#define HX8347_INVERT_COLORS            CONFIG_LV_INVERT_COLORS#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL#define HX8347_BCKL_ACTIVE_LVL 1
#else#define HX8347_BCKL_ACTIVE_LVL 0
#endif/******************** HX8347B/D REGS
*********************/
#define HX8347D                    0xD  ///< Our internal const for D type
#define HX8347B                    0xB  ///< Our internal const for B type#define HX8347_TFTWIDTH            320  ///< 320 pixels wide
#define HX8347_TFTHEIGHT           240  ///< 480 pixels tall#define HX8347_NOP                0x00  ///< No op
#define HX8347_SWRESET            0x01  ///< software reset
#define HX8347_RDDID              0x04  ///< Read ID
#define HX8347_RDDST              0x09  ///< (unknown)#define HX8347_RDPOWMODE          0x0A  ///< Read power mode Read power mode
#define HX8347_RDMADCTL           0x0B  ///< Read MADCTL
#define HX8347_RDCOLMOD           0x0C  ///< Column entry mode
#define HX8347_RDDIM              0x0D  ///< Read display image mode
#define HX8347_RDDSDR             0x0F  ///< Read dosplay signal mode#define HX8347_SLPIN              0x10  ///< Enter sleep mode
#define HX8347_SLPOUT             0x11  ///< Exit sleep mode
#define HX8347B_PTLON             0x12  ///< Partial mode on
#define HX8347B_NORON             0x13  ///< Normal mode#define HX8347_INVOFF             0x20  ///< Turn off invert
#define HX8347_INVON              0x21  ///< Turn on invert
#define HX8347_DISPOFF            0x28  ///< Display on
#define HX8347_DISPON             0x29  ///< Display off#define HX8347_CASET              0x2A  ///< Column addr set
#define HX8347_PASET              0x2B  ///< Page addr set
#define HX8347_RAMWR              0x2C  ///< Write VRAM
#define HX8347_RAMRD              0x2E  ///< Read VRAm#define HX8347B_PTLAR             0x30  ///< (unknown)
#define HX8347_TEON               0x35  ///< Tear enable on
#define HX8347_TEARLINE           0x44  ///< (unknown)
#define HX8347_MADCTL             0x16  ///< Memory access control
#define HX8347_COLMOD             0x3A  ///< Color mode#define HX8347_SETOSC             0xB0  ///< Set oscillator
#define HX8347_SETPWR1            0xB1  ///< Set power control
#define HX8347B_SETDISPLAY        0xB2  ///< Set display mode
#define HX8347_SETRGB             0xB3  ///< Set RGB interface
#define HX8347D_SETCOM            0xB6  ///< Set VCOM voltage#define HX8347B_SETDISPMODE       0xB4  ///< Set display mode
#define HX8347D_SETCYC            0xB4  ///< Set display cycle reg
#define HX8347B_SETOTP            0xB7  ///< Set OTP memory
#define HX8347D_SETC              0xB9  ///< Enable extension command#define HX8347B_SET_PANEL_DRIVING 0xC0  ///< Set panel drive mode
#define HX8347D_SETSTBA           0xC0  ///< Set source option
#define HX8347B_SETDGC            0xC1  ///< Set DGC settings
#define HX8347B_SETID             0xC3  ///< Set ID
#define HX8347B_SETDDB            0xC4  ///< Set DDB
#define HX8347B_SETDISPLAYFRAME   0xC5  ///< Set display frame
#define HX8347B_GAMMASET          0xC8  ///< Set Gamma correction
#define HX8347B_SETCABC           0xC9  ///< Set CABC
#define HX8347_SETPANEL           0xCC  ///< Set Panel#define HX8347B_SETPOWER          0xD0  ///< Set power control
#define HX8347B_SETVCOM           0xD1  ///< Set VCOM
#define HX8347B_SETPWRNORMAL      0xD2  ///< Set power normal#define HX8347B_RDID1             0xDA  ///< Read ID #1
#define HX8347B_RDID2             0xDB  ///< Read ID #2
#define HX8347B_RDID3             0xDC  ///< Read ID #3
#define HX8347B_RDID4             0xDD  ///< Read ID #4#define HX8347D_SETGAMMA          0xE0  ///< Set Gamma#define HX8347B_SETGAMMA          0xC8 ///< Set Gamma
#define HX8347B_SETPANELRELATED   0xE9 ///< Set panel related/***********************      TYPEDEFS**********************//*********************** GLOBAL PROTOTYPES**********************/void hx8347_init(void);
void hx8347_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
void hx8347_enable_backlight(bool backlight);
void hx8347_set_rotation(uint8_t r);/***********************      MACROS**********************/#ifdef __cplusplus
} /* extern "C" */
#endif#endif /*HX8347_H*/

hx8347.c

/*** @file HX8347.c** Roughly based on the Adafruit_HX8347_Library** This library should work with:* Adafruit 3.5" TFT 320x480 + Touchscreen Breakout*    http://www.adafruit.com/products/2050** Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers*    https://www.adafruit.com/product/3651**//**********************      INCLUDES*********************/
#include "hx8347.h"
#include "disp_spi.h"
#include "driver/gpio.h"
#include "rom/gpio.h"
#include <esp_log.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"/**********************      DEFINES*********************/
#define TAG        "HX8347"#define MADCTL_MY  0x80 ///< Bottom to top
#define MADCTL_MX  0x40 ///< Right to left
#define MADCTL_MV  0x20 ///< Reverse Mode
#define MADCTL_ML  0x10 ///< LCD refresh Bottom to top
#define MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order
#define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order
//#define MADCTL_MH  0x04 ///< LCD refresh right to left/***********************      TYPEDEFS**********************//*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */
typedef struct {uint8_t cmd;uint8_t data[16];uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
} lcd_init_cmd_t;/***********************  STATIC PROTOTYPES**********************/
static void hx8347_send_cmd(uint8_t cmd);
static void hx8347_send_data(void * data, uint16_t length);
static void hx8347_send_color(void * data, uint16_t length);
static void hx8347_send_16bit(uint8_t d1,uint8_t d2);/***********************  INITIALIZATION ARRAYS**********************/
// Taken from the Adafruit driver
static const uint8_tinitb[] = {//Driving ability Setting0xEA,1,0x00, //PTBA[15:8]0xEB,1,0x20, //PTBA[7:0]0xEC,1,0x0C, //STBA[15:8]0xED,1,0xC4, //STBA[7:0]0xE8,1,0x40, //OPON[7:0]0xE9,1,0x38, //OPON1[7:0]0xF1,1,0x01, //OTPS1B0xF2,1,0x10, //GEN0x27,1,0xA3,//Gamma 2.2 Setting0x40,1,0x01, //0x41,1,0x00, //0x42,1,0x00, //0x43,1,0x10, //0x44,1,0x0E, //0x45,1,0x24, //0x46,1,0x04, //0x47,1,0x50, //0x48,1,0x02, //0x49,1,0x13, //0x4A,1,0x19, //0x4B,1,0x19, //0x4C,1,0x16, //0x50,1,0x1B, //0x51,1,0x31, //0x52,1,0x2F, //0x53,1,0x3F, //0x54,1,0x3F, //0x55,1,0x3E, //0x56,1,0x2F, //0x57,1,0x7B, //0x58,1,0x09, //0x59,1,0x06, //0x5A,1,0x06, //0x5B,1,0x0C, //0x5C,1,0x1D, //0x5D,1,0xCC, //// Window setting//#if (DISP_ORIENTATION == 0)//    0x04,1,0x00,//    0x05,1,0xEF,//    0x08,1,0x01,//    0x09,1,0x3F,//#else//    0x04,1,0x01,//    0x05,1,0x3F,//    0x08,1,0x00,//    0x09,1,0xEF,//#endif//Power Voltage Setting0x1B,1,0x1B, //VRH=4.65V0x1A,1,0x01, //BT (VGH~15V,VGL~-10V,DDVDH~5V)0x24,1,0x15, //VMH(VCOM High voltage ~3.2V)0x25,1,0x50, //VML(VCOM Low voltage -1.2V)0x23,1,0x88, //for Flicker adjust //can reload from OTP//Power on Setting0x18,1,0x36, // I/P_RADJ,N/P_RADJ, Normal mode 60Hz0x19,1,0x01, //OSC_EN='1', start Osc0x01,1,0x00, //DP_STB='0', out deep sleep0x1F,1,0x88,// GAS=1, VOMG=00, PON=0, DK=1, XDK=0, DVDH_TRI=0, STB=00xFF, 0x80 + 50/5,0x1F,1,0x80,// GAS=1, VOMG=00, PON=0, DK=0, XDK=0, DVDH_TRI=0, STB=00xFF, 0x80 + 50/5,0x1F,1,0x90,// GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=00xFF, 0x80 + 50/5,0x1F,1,0xD0,// GAS=1, VOMG=10, PON=1, DK=0, XDK=0, DDVDH_TRI=0, STB=00xFF, 0x80 + 50/5,//262k/65k color selection0x17,1,0x05, //default 0x06 262k color // 0x05 65k color//SET PANEL0x36,1,0x00, //SS_P, GS_P,REV_P,BGR_P//Display ON Setting0x28,1,0x38, //GON=1, DTE=1, D=10000xFF, 0x80 + 50/5,0x28,1,0x3C, //GON=1, DTE=1, D=11000x16,1,0x38, // MY=0, MX=1, MV=1, BGR=1// 0x16,1,0x80, // MY=1, MX=0, MV=0,竖屏时去掉注释//Set GRAM Area0x02,1,0x00,0x03,1,0x00, //Column Start0x04,1,0x00,0x05,1,0xEF, //Column End0x06,1,0x00,0x07,1,0x00, //Row Start0x08,1,0x01,0x09,1,0x3F, //Row End// 0x0a,1,0x00,// 0x0b,1,0xef,// 0x0c,1,0x00,// 0x0d,1,0x00,//  //************* Start Initial Sequence **********//// 	 0x2e,1,0x79,//  0xee,1,0x0c,//  //Driving ability Setting//  0xea,1,0x00,//  0xeb,1,0x20,//  0xec,1,0x08,//  0xed,1,0xc4,//  0xe8,1,0x40,//  0xe9,1,0x38,//  0xf1,1,0x01,//  0xf2,1,0x10,//  0x27,1,0xa3,//  //Gamma 2.2 Setting//  0x40,1,0x01,//  0x41,1,0x07,//  0x42,1,0x07,//  0x43,1,0x13,//  0x44,1,0x11,//  0x45,1,0x24,//  0x46,1,0x10,//  0x47,1,0x57,//  0x48,1,0x09,//  0x49,1,0x14,//  0x4a,1,0x19,//  0x4b,1,0x19,//  0x4c,1,0x16,//  0x50,1,0x1b,//  0x51,1,0x2e,//  0x52,1,0x2c,//  0x53,1,0x38,//  0x54,1,0x38,//  0x55,1,0x3e,//  0x56,1,0x2a,//  0x57,1,0x6f,//  0x58,1,0x09,//  0x59,1,0x06,//  0x5a,1,0x06,//  0x5b,1,0x0b,//  0x5c,1,0x16,//  0x5d,1,0xcc,//  //Power Voltage Setting//  0x1b,1,0x1b,//  0x1a,1,0x01,//  0x24,1,0x29,//  0x25,1,0x57,//  //****VCOM offset**/////  0x23,1,0x8a,//  //Power on Setting//  0x18,1,0x36,//  0x19,1,0x01,//  0x01,1,0x00,//  0x1f,1,0x88,//  0xFF, 0x80 + 50/5,//  0x1f,1,0x80,//  0xFF, 0x80 + 50/5,//  0x1f,1,0x90,//   0xFF, 0x80 + 50/5,//  0x1f,1,0xd0,//   0xFF, 0x80 + 50/5,//  //262k/65k color selection//  0x17,1,0x05,//  //SET PANEL//  0x36,1,0x00,//  //Display ON Setting//  0x28,1,0x38,//  0xFF, 0x80 + 50/5,//  0x28,1,0x3c,//    //设置2.8寸的GAMA参数//   0x46,1,0x94,//   0x47,1,0x41,//   0x48,1,0x00,//   0x49,1,0x33,//   0x4a,1,0x23,//   0x4b,1,0x45,//   0x4c,1,0x44,//   0x4d,1,0x77,//   0x4e,1,0x12,//   0x4f,1,0xcc,//   0x50,1,0x46,//   0x51,1,0x82,//   //320*240 peixl setting//   0x02,1,0x00,//   0x03,1,0x00,//   0x04,1,0x00,//   0x05,1,0xef,//   0x06,1,0x00,//   0x07,1,0x00,//   0x08,1,0x01,//   0x09,1,0x3f,//   //Display setting//   0x01,1,0x06,//   0x16,1,0xc8,//   0x23,1,0x95,//   0x24,1,0x95,//   0x25,1,0xFF,//   0x27,1,0x02,//   0x28,1,0x02,//   0x29,1,0x02,//   0x2a,1,0x02,//   0x2C,1,0x02,//   0x2d,1,0x02,//   0x3a,1,0x01,//   0x3b,1,0x01,//   0x3c,1,0xf0,//   0x3d,1,0x00,//   0xFF, 0x80 + 50/5,//   0x35,1,0x38,//   0x36,1,0x78,//   0x3E,1,0x3,//   0x40,1,0x0F,//   0x41,1,0xF0,//   //power supply setting//   0x19,1,0x49,//   0x93,1,0x0F,//   0xFF, 0x80 + 50/5,//   0x20,1,0x40,//   0x1D,1,0x07,//   0x1E,1,0x00,//   0x1F,1,0x03,//   //VCOM SETTING FOR 2.4' PANNNEL'//   0x44,1,0x42,//   0x45,1,0x11,//   0xFF, 0x80 + 50/5,//   0x1C,1,0x04,//   0xFF, 0x80 + 50/5,//   0x43,1,0x80,//   0xFF, 0x80 + 50/5,//   0x1B,1,0x08,//  0xFF, 0x80 + 50/5,//   // Display ON Setting//   0x90,1,0x7F,//   0x26,1,0x04,//   0xFF, 0x80 + 50/5,//   0x26,1,0x24,//   0x26,1,0x2C,//   0xFF, 0x80 + 50/5,//   0x26,1,0x3C,//   // Fixed the read data issue//   0x57,1,0x02,//   0x56,1,0x02,//   0x57,1,0x00,// //Driving ability Setting// 0xEa,1,0x00,// 0xeb,1,0x20,// 0xec,1,0x0c,// 0xed,1,0xc4,// 0xe8,1,0x38,// 0xe9,1,0x10,// 0xf1,1,0x01,// 0xf2,1,0x10,// //Gamma 2.2 Setting// 0x40,1,0x01,// 0x41,1,0x00,// 0x42,1,0x00,// 0x43,1,0x10,// 0x44,1,0x0e,// 0x45,1,0x24,// 0x46,1,0x04,// 0x47,1,0x50,// 0x48,1,0x02,// 0x49,1,0x13,// 0x4a,1,0x19,// 0x4b,1,0x19,// 0x4c,1,0x16,// 0x50,1,0x1b,// 0x51,1,0x31,// 0x52,1,0x2f,// 0x53,1,0x3f,// 0x54,1,0x3f,// 0x55,1,0x3e,// 0x56,1,0x2f,// 0x57,1,0x7b,// 0x58,1,0x09,// 0x59,1,0x06,// 0x5a,1,0x06,// 0x5b,1,0x0c,// 0x5c,1,0x1d,// 0x5d,1,0xcc,// //Power Voltage Setting// 0x1b,1,0x1b,	//4.65v// 0x1a,1,0x01,// 0x24,1,0x2f,// 0x25,1,0x57,// //vcom offset// 0x23,1,0x88,// //Power on Setting// 0x19,1,0x01,// 0x01,1,0x00,// 0x1f,1,0x88,// 0xFF, 0x80 + 50/5,// 0x1f,1,0x80,// 0xFF, 0x80 + 50/5,// 0x1f,1,0x90,// 0xFF, 0x80 + 50/5,// 0x1f,1,0xd0,// 0xFF, 0x80 + 50/5,// 0x17,1,0x60,// 0x28,1,0x38,// 0xFF, 0x80 + 50/5,// 0x28,1,0x3f,// 0x02,1,0x00,// 0x03,1,0x00,// 0x04,1,0x00,// 0x05,1,0xef,// 0x06,1,0x00,// 0x07,1,0x00,// 0x08,1,0x01,// 0x09,1,0x3f,// 0x28,1,0x38,// 0xFF, 0x80 + 50/5,// 0x1f,1,0x89,// 0xFF, 0x80 + 50/5,// 0x28,1,0x04,// 0xFF, 0x80 + 50/5,// 0x19,1,0x00,// 0xFF, 0x80 + 50/5,0                            // END OF COMMAND LIST}, initd[] = {0x18,1,0x88,  //UADJ 75Hz0x19,1,0x01,  //OSC_EN='1', start Osc//Power Voltage Setting0x1B,1,0x1E, //VRH=4.60V0x1C,1,0x07, //AP Crosstalk    040x1A,1,0x01, //BT (VGH~15V,1,VGL~-10V,1,DDVDH~5V)0x24,1,0x38, //VMH 270x25,1,0x5F, //VML//VCOM offset0x23,1,0x8C, //for Flicker adjust0x1F,1,0x88,// GAS=1,1, VOMG=00,1, PON=0,1, DK=1,1, XDK=0,1, DVDH_TRI=0,1, STB=00xFF, 0x80 + 50/5,0x1F,1,0x80,// GAS=1,1, VOMG=00,1, PON=0,1, DK=0,1, XDK=0,1, DVDH_TRI=0,1, STB=00xFF, 0x80 + 50/5,0x1F,1,0x90,// GAS=1,1, VOMG=00,1, PON=1,1, DK=0,1, XDK=0,1, DVDH_TRI=0,1, STB=00xFF, 0x80 + 50/5,0x1F,1,0xD0,// GAS=1,1, VOMG=10,1, PON=1,1, DK=0,1, XDK=0,1, DDVDH_TRI=0,1, STB=00xFF, 0x80 + 50/5,//Display ON Setting0x28,1,0x38,   //GON=1,1, DTE=1,1, D=10000xFF, 0x80 + 400/5,0x28,1,0x3C,   //GON=1,1, DTE=1,1, D=11000x36,1,0x00,   //REV,1, BGR0x17,1,0x05,  //16BIT/PIXEL//Gamma 2.2 Setting0x40,1,0x00, //0x41,1,0x00, //0x42,1,0x00, //0x43,1,0x11, //0x44,1,0x0e, //0x45,1,0x23, //0x46,1,0x08, //0x47,1,0x53, //0x48,1,0x03, //0x49,1,0x11, //0x4A,1,0x18, //0x4B,1,0x1a, //0x4C,1,0x16, //0x50,1,0x1c, //0x51,1,0x31, //0x52,1,0x2e, //0x53,1,0x3f, //0x54,1,0x3f, //0x55,1,0x3f, //0x56,1,0x2c, //0x57,1,0x77, //0x58,1,0x09, //0x59,1,0x05, //0x5A,1,0x07, //0x5B,1,0x0e, //0x5C,1,0x1c, //0x5D,1,0x88, //0xFF, 0x80 + 100/5,0,                           // END OF COMMAND LIST};/***********************  STATIC VARIABLES**********************//***********************      MACROS**********************//***********************   GLOBAL FUNCTIONS**********************/
static uint8_t displayType = HX8347B;   //HX8347B:RGBvoid lcd_cs_port(uint8_t status)
{if (status) {gpio_set_level(HX8347_CS, 1);} else {gpio_set_level(HX8347_CS, 0);}
}void hx8347_init(void)
{//Initialize non-SPI GPIOs//3线spi没有DC引脚//       gpio_pad_select_gpio(HX8347_DC);// gpio_set_direction(HX8347_DC, GPIO_MODE_OUTPUT);gpio_pad_select_gpio(HX8347_CS);gpio_set_direction(HX8347_CS, GPIO_MODE_OUTPUT);gpio_pad_select_gpio(HX8347_RST);gpio_set_direction(HX8347_RST, GPIO_MODE_OUTPUT);#if HX8347_ENABLE_BACKLIGHT_CONTROLgpio_pad_select_gpio(HX8347_BCKL);gpio_set_direction(HX8347_BCKL, GPIO_MODE_OUTPUT);
#endif//Reset the displaygpio_set_level(HX8347_RST, 0);vTaskDelay(10 / portTICK_PERIOD_MS);gpio_set_level(HX8347_RST, 1);vTaskDelay(120 / portTICK_PERIOD_MS);ESP_LOGI(TAG, "Initialization.");//Send all the commandsconst uint8_t *addr = (displayType == HX8347B) ? initb : initd;uint8_t        cmd, x, numArgs;while((cmd = *addr++) > 0) { // '0' command ends listx = *addr++;numArgs = x & 0x7F;if (cmd != 0xFF) { // '255' is ignoredif (x & 0x80) {  // If high bit set, numArgs is a delay timehx8347_send_cmd(cmd);} else {hx8347_send_cmd(cmd);hx8347_send_data((void *) addr, numArgs);addr += numArgs;}}if (x & 0x80) {       // If high bit set...vTaskDelay(numArgs * 5 / portTICK_PERIOD_MS); // numArgs is actually a delay time (5ms units)}}//hx8347_set_rotation(2); //Portrait竖屏 选0或2;Landscape横屏 选1或3。// #if HX8347_INVERT_COLORS
// 	hx8347_send_cmd(HX8347_INVON);
// #else
//     hx8347_send_cmd(HX8347_INVOFF);
// #endif//hx8347_enable_backlight(true);
}void hx8347_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
{uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);uint8_t data[34]={0};/* Column addresses  */uint8_t xb[] = {(uint8_t) (area->x1 >> 8) & 0xFF,(uint8_t) (area->x1) & 0xFF,(uint8_t) (area->x2 >> 8) & 0xFF,(uint8_t) (area->x2) & 0xFF,};/* Page addresses  */uint8_t yb[] = {(uint8_t) (area->y1 >> 8) & 0xFF,(uint8_t) (area->y1) & 0xFF,(uint8_t) (area->y2 >> 8) & 0xFF,(uint8_t) (area->y2) & 0xFF,};//ESP_LOGI(TAG, "hx8347_flush X:%d,%d,%d,%d",xb[0],xb[1],xb[2],xb[3]);//ESP_LOGI(TAG, "hx8347_flush Y:%d,%d,%d,%d",yb[0],yb[1],yb[2],yb[3]);// /*Column addresses*/// hx8347_send_cmd(0x02);// hx8347_send_data(&xb[0], 1);// hx8347_send_cmd(0x03);// hx8347_send_data(&xb[1], 1);// hx8347_send_cmd(0x04);// hx8347_send_data(&xb[2], 1);// hx8347_send_cmd(0x05);// hx8347_send_data(&xb[3], 1);// /*Page addresses*/// hx8347_send_cmd(0x06);// hx8347_send_data(&yb[0], 1);// hx8347_send_cmd(0x07);// hx8347_send_data(&yb[1], 1);// hx8347_send_cmd(0x08);// hx8347_send_data(&yb[2], 1);// hx8347_send_cmd(0x09);// hx8347_send_data(&yb[3], 1);// /*Memory write*/// hx8347_send_cmd(0x22);data[0]=0x70; data[1]=0x02; data[2]=0x72; data[3]=xb[0];data[4]=0x70; data[5]=0x03; data[6]=0x72; data[7]=xb[1];data[8]=0x70; data[9]=0x04; data[10]=0x72;data[11]=xb[2];data[12]=0x70;data[13]=0x05;data[14]=0x72;data[15]=xb[3];data[16]=0x70; data[17]=0x06; data[18]=0x72; data[19]=yb[0];data[20]=0x70; data[21]=0x07; data[22]=0x72; data[23]=yb[1];data[24]=0x70; data[25]=0x08; data[26]=0x72; data[27]=yb[2];data[28]=0x70; data[29]=0x09; data[30]=0x72; data[31]=yb[3];data[32]=0x70; data[33]=0x22;for(uint8_t i=0;i<17;i++){lcd_cs_port(0);//disp_spi_send_data(&data[2*i],2);hx8347_send_16bit(data[2*i],data[2*i+1]);lcd_cs_port(1);}hx8347_send_color(color_map, size * 2);
}void hx8347_enable_backlight(bool backlight)
{
#if HX8347_ENABLE_BACKLIGHT_CONTROLESP_LOGD(TAG, "%s backlight.\n", backlight ? "Enabling" : "Disabling");uint32_t tmp = 0;#if (HX8347_BCKL_ACTIVE_LVL==1)tmp = backlight ? 1 : 0;
#elsetmp = backlight ? 0 : 1;
#endifgpio_set_level(HX8347_BCKL, tmp);
#endif
}void hx8347_set_rotation(uint8_t r)
{r = r & 3; // can't be higher than 3switch(r) {case 0:r = MADCTL_MX | MADCTL_MY | MADCTL_RGB;break;case 1:r = MADCTL_MV | MADCTL_MY | MADCTL_RGB;break;case 2:r = MADCTL_RGB;break;case 3:r = MADCTL_MX | MADCTL_MV | MADCTL_RGB;break;}hx8347_send_cmd(HX8347_MADCTL);hx8347_send_data(&r, 1);
}/***********************   STATIC FUNCTIONS**********************/static void hx8347_send_16bit(uint8_t d1,uint8_t d2)
{uint8_t c[2];c[0]=d1;c[1]=d2;lcd_cs_port(0);disp_spi_send_data(&c, 2);      //发送2字节lcd_cs_port(1);
}static void hx8347_send_cmd(uint8_t cmd)
{uint8_t c;c=0x70;hx8347_send_16bit(c,cmd);// lcd_cs_port(0);// disp_spi_send_data(&c, 1);      //Command mode// disp_spi_send_data(&cmd, 1);// lcd_cs_port(1);
}static void hx8347_send_data(void * data, uint16_t length)
{uint8_t c;c=0x72;lcd_cs_port(0);disp_spi_send_data(&c, 1);      //Data modedisp_spi_send_data(data, length);lcd_cs_port(1);
}static void hx8347_send_color(void * data, uint16_t length)
{uint8_t c;c=0x72;lcd_cs_port(0);disp_spi_send_data(&c, 1);      //Data modedisp_spi_send_colors(data, length);lcd_cs_port(1);
}

三、修改components\lvgl_esp32_drivers\lvgl_tft\Kconfig文件内容

        在相关位置增加hx8347相关信息,位置可参考其他显示IC配置,方便idf.py menuconfig进行配置:

    config LV_TFT_DISPLAY_USER_CONTROLLER_HX8347

        bool "HX8347"

            select LV_TFT_DISPLAY_CONTROLLER_HX8347

            select LV_TFT_DISPLAY_PROTOCOL_SPI

    config LV_TFT_DISPLAY_CONTROLLER_HX8347

        bool

        help

            HX8347 display controller.

  

配好后,idf.py menuconfig 中就会有hx8347的选项:

 

四、其他的文件修改:

disp_spi.h

//增加了DISP_SPI_SEND_POLLING
static inline void disp_spi_send_colors(uint8_t *data, size_t length) {disp_spi_transaction(data, length,DISP_SPI_SEND_QUEUED | DISP_SPI_SIGNAL_FLUSH|DISP_SPI_SEND_POLLING,NULL, 0, 0);
}

disp_spi.c

void disp_spi_transaction(const uint8_t *data, size_t length,disp_spi_send_flag_t flags, uint8_t *out,uint64_t addr, uint8_t dummy_bits)
{.......if (length <= 4 && data != NULL) {t.base.flags = SPI_TRANS_USE_TXDATA;memcpy(t.base.tx_data, data, length);} else {t.base.flags =SPI_DEVICE_CLK_AS_CS|SPI_DEVICE_NO_DUMMY;//增加了这句t.base.tx_buffer = data;}
.......

disp_driver.h增加了:

#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8347
#include "hx8347.h"

disp_dirver.c增加了:

#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8347hx8347_init();#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8347hx8347_flush(drv, area, color_map);

应该还有其他的地方修改,总之是使lv_port_esp32支持HX8347。

五、最后

LVGL

六、总结

1、ESP32S3运行LVGL,需要LVGL+lv_port_esp32。

2、运行LVGL通常需要4线spi,很不巧,笔者手头的HX8347只支持3线SPI。所以什么都要自己写。3线SPI性能比4线差不少。CS还需要手动控制。

3、0x16寄存器要设置下面这样,否则左右可能颠倒

0x16,1,0x38, // MY=0, MX=1, MV=1, BGR=1

如果用竖屏,要加上:

 0x16,1,0x80, // MY=1, MX=0, MV=0,竖屏时去掉注释

4、idf.py menuconfig的一些设置:

flash size

 运行的例子:

LVGL configuration

LVGL TFT Display configration 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/586132.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1.2.0 IGP高级特性之FRR

理论部分参考文档&#xff1a;Segment Routing TI-LFA FRR保护技术 - 华为 一、快速重路由技术 FRR(Fast Reroute)快速重路由 实现备份链路的快速切换&#xff0c;也可以与BFD联动实现对故障的快速感知。 随着网络的不断发展&#xff0c;VoIP和在线视频等业务对实时性的要求越…

web:[BJDCTF2020]The mystery of ip(ssti模板注入、Smarty 模板引擎)

题目 进入页面显示如下 点击flag页面得到ip 点击hint页面 在hint.php的源代码页面中发现 由题目可以知道要从ip入手 这里尝试抓包加上X-Forwarded-For请求头修改为127.0.0.1 因为直接将127.0.0.1输出到页面&#xff0c;可以猜测是ssti模板注入 可以继续验证 这里发现输入什么…

【数据结构】八、查找

一、基本概念 静态查找&#xff1a;只查找&#xff0c;不改变集合内数据元素 动态查找&#xff1a;有则输出元素&#xff0c;无则添加元素 二、静态查找表 2.1顺序查找 在线性表、链表、树中依次查找 2.2折半查找&#xff08;二分查找&#xff09; 在有序的线性表中&…

HTML5 `<audio>` 面试题

HTML5 <audio> 面试题 什么是HTML5 <audio>元素&#xff1f; 元素是HTML5的音频播放器。它允许在网页中嵌入音频文件&#xff0c;并提供了控制音频播放的功能。 如何在HTML中嵌入音频文件&#xff1f; 使用 <audio> 元素&#xff0c;通过设置 src 属性指定…

获取PG库 database与 user 创建时间以及cluster初始化时间

代码实现 echo "获取数据库创建时间" data_dir$(psql -U postgres -d postgres -X -qAt -c "show data_directory" ) db_dirs$(ls $data_dir/base |grep -v pgsql_tmp) for db_oid in $db_dirs dodb_exists$(psql -U postgres -d postgres -X -qAt -c &qu…

macos下转换.dmg文件为 .iso .cdr文件的简单方法

为了让镜像文件在mac 和windows平台通用, 所以需要将.dmg格式的镜像文件转换为.iso文件, 转换方法也非常简单, 一行命令即可 hdiutil convert /path/to/example.dmg -format UDTO -o /path/to/example.iso 转换完成后的文件名称默认是 example.iso.cdr 这里直接将.cdr后缀删…

C#高级 08Json操作

1.概念 Json是存储和交换文本信息的语法。类似于XML。Json比XML更小、更快、更易解析。Json与XML一样是一种数据格式。Json是一种轻量级的数据交换格式。它基于ECMAScript的一个子集。Json采取完全独立于语言的文本格式&#xff0c; 但是也使用了类似于C语言的习惯。这些特性使…

Kotlin基础语法

Kotlin基础语法 Kotlin内置数据类型变量可读可写变量可读变量 自动类型推导机制when表达式range表达式字符串模版函数函数定义函数简写默认参数具名函数参数Unit函数反引号函数匿名函数隐式返回函数作为形参函数引用函数作为返回值 可空性高级函数 let非空断言空合并操作符 高级…

Mac系统通过homebrew安装postgresql和postgis

花费了大概一天的时间安装postgresql和postgis&#xff0c;期间遇到了大量的坑&#xff0c;记录下来分享给大家&#xff0c;方便自己以后再次安装&#xff0c;也帮助别人踩坑 tip:我的系统是MAC ,通过homebrew安装的 最开始是通过homebrew安装了 postgresql13 &#xff0c;但…

2047过滤空格(C语言)

目录 一&#xff1a;题目 二&#xff1a;思路分析 三&#xff1a;代码 一&#xff1a;题目 二&#xff1a;思路分析 1.首先&#xff0c;这道题是一个字符串的问题&#xff0c;我们要先知道字符串存放在char类型的数组中的&#xff0c;并不是一个变量就可直接存放的下一个完整…

1.Linux快速入门

Linux快速入门 Linux操作系统简介Linux操作系统优点Linux操作系统发行版1. Red Hat Linux2. CentOS3. Ubuntu4. SUSE Linux5. Fedora Linux 32位与64位操作系统的区别Linux内核命名规则 Linux操作系统简介 Linux操作系统是基于UNIX以网络为核心的设计思想&#xff0c;是一个性…

云计算:OpenStack 配置云主机实例的存储挂载并实现外网互通

目录 一、实验 1. 环境 2.配置存储挂载 3.云主机实例连接外部网络&#xff08;SNAT&#xff09; 4.外部网络连接云主机实例&#xff08;DNAT&#xff09; 二、问题 1.云主机 ping 不通外部网络 2.nova list 查看云主机列表报错 3.nova list 与 virsh list --all有何区…

Go语言中的包管理工具之Go Modules的使用

GoLang 中常用的包管理的方式 常用的有三种 Go PathGo VendorGo Modules 关于 Go Modules 1 ) 概述 Go的包管理&#xff0c;经过社区和官方的共同努力下&#xff0c;最终在百家争鸣后Go官方在 2018.8 推出了go 1.11版本中的Go Modules&#xff0c;并且很快成为一统江湖的包…

python学习 21 excel分列

简单做了个模板&#xff0c;能干这个&#xff1a; 指定sheet中某列数据进行按需拆分&#xff0c;拆分后新建一个test的sheet&#xff0c;将数据分别存入test的不同列中。 import os import xlwings as xw import re #excel路径 pathrC:\Users\xxx\Desktop\123.xlsx#设置需要…

【代码随想录】刷题笔记Day42

前言 这两天机器狗终于搞定了&#xff0c;一个控制ROS大佬&#xff0c;一个计院编程大佬&#xff0c;竟然真把创新点这个弄出来了&#xff0c;牛牛牛牛&#xff08;菜鸡我只能负责在旁边喊加油&#xff09;。下午翘了自辩课来刷题&#xff0c;这次应该是元旦前最后一刷了&…

行车记录仪变清晰,变高清的办法一定要收藏

有时候我们会发现行车记录仪拍摄的视频不够清晰&#xff0c;特别是出现事故需要视频为证的时候&#xff0c;如果视频太模糊&#xff0c;很难获得交警的支持&#xff0c;那么如何让行车记录仪拍摄的视频变得更加清晰呢&#xff1f; 小编给大家分享几个办法&#xff0c;建议收藏…

Android实验:contentprovider 实验+SQLite 数据库的实现

目录 SQLite实验目的实验内容实验要求项目结构代码实现结果展示 SQLite SQLite 是一个开源的嵌入式关系数据库&#xff0c;实现了自给自足的、无服务器的、配置无需的、事务性的 SQL 数据库引擎。它是一个零配置的数据库&#xff0c;这意味着与其他数据库系统不同&#xff0c;…

全面好用的setting.xml配置

<?xml version"1.0" encoding"UTF-8"?> <!-- 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…

轻松实现iphone截图传电脑

目录 摘要 引言 用户登录工具和连接设备 生成截图 摘要 本篇博文介绍了克魔助手这款工具&#xff0c;解决了iPhone与Windows系统下图片传输的烦恼。通过连接同一Wi-Fi&#xff0c;使用克魔助手轻松实现了iPhone截图传输到电脑上的便捷操作。用户只需简单地下载并安装克魔助…

前端优化 - 防抖和节流

&#x1f4e2; 鸿蒙专栏&#xff1a;想学鸿蒙的&#xff0c;冲 &#x1f4e2; C语言专栏&#xff1a;想学C语言的&#xff0c;冲 &#x1f4e2; VUE专栏&#xff1a;想学VUE的&#xff0c;冲这里 &#x1f4e2; CSS专栏&#xff1a;想学CSS的&#xff0c;冲这里 &#x1f4…