├── .gitignore ├── components ├── sdcard │ ├── component.mk │ ├── CMakeLists.txt │ ├── sdcard.h │ ├── Kconfig.projbuild │ └── sdcard.c ├── http_client │ ├── component.mk │ ├── CMakeLists.txt │ ├── http_client.h │ └── http_client.c ├── qrcodegen │ ├── component.mk │ ├── CMakeLists.txt │ └── qrcodegen.h ├── tft_library │ ├── component.mk │ ├── CMakeLists.txt │ ├── r61509.h │ ├── st7781.h │ ├── ili9225.h │ ├── ili9320.h │ ├── ili9325.h │ ├── ili9327.h │ ├── ili9341.h │ ├── ili9481.h │ ├── ili9486.h │ ├── ili9488.h │ ├── s6d1121.h │ ├── ili9342.h │ ├── lgdp4532.h │ ├── hx8347.h │ ├── fontx.h │ ├── ili9327.c │ ├── ili9342.c │ ├── ili9481.c │ ├── ili9488.c │ ├── ili9486.c │ ├── st7781.c │ ├── ili9320.c │ ├── lcd_com.h │ ├── lgdp4532.c │ ├── i2s_lcd_driver.h │ ├── lcd_lib.h │ ├── r61509.c │ ├── ili9341.c │ ├── ili9225.c │ ├── ili9325.c │ ├── hx8347.c │ ├── s6d1121.c │ ├── Kconfig.projbuild │ ├── i2s_lcd_esp32s2_driver.c │ └── lcd_com.c └── wifi_station │ ├── component.mk │ ├── CMakeLists.txt │ ├── Kconfig.projbuild │ ├── wifi_station.h │ └── wifi_station.c ├── font ├── ILGH16XB.FNT ├── ILGH24XB.FNT ├── ILGH32XB.FNT ├── ILMH16XB.FNT ├── ILMH24XB.FNT └── ILMH32XB.FNT ├── main ├── CMakeLists.txt ├── component.mk ├── Kconfig.projbuild └── main.c ├── partitions.csv ├── sdkconfig.defaults ├── CMakeLists.txt ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .vscode/ 3 | *.old 4 | sdkconfig 5 | -------------------------------------------------------------------------------- /components/sdcard/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. 2 | -------------------------------------------------------------------------------- /components/http_client/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. 2 | -------------------------------------------------------------------------------- /components/qrcodegen/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. 2 | -------------------------------------------------------------------------------- /components/tft_library/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. 2 | -------------------------------------------------------------------------------- /components/wifi_station/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. 2 | -------------------------------------------------------------------------------- /font/ILGH16XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanfrj/esp32-pix/HEAD/font/ILGH16XB.FNT -------------------------------------------------------------------------------- /font/ILGH24XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanfrj/esp32-pix/HEAD/font/ILGH24XB.FNT -------------------------------------------------------------------------------- /font/ILGH32XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanfrj/esp32-pix/HEAD/font/ILGH32XB.FNT -------------------------------------------------------------------------------- /font/ILMH16XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanfrj/esp32-pix/HEAD/font/ILMH16XB.FNT -------------------------------------------------------------------------------- /font/ILMH24XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanfrj/esp32-pix/HEAD/font/ILMH24XB.FNT -------------------------------------------------------------------------------- /font/ILMH32XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanfrj/esp32-pix/HEAD/font/ILMH32XB.FNT -------------------------------------------------------------------------------- /components/qrcodegen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(component_srcs "qrcodegen.c") 2 | 3 | idf_component_register(SRCS "${component_srcs}" INCLUDE_DIRS ".") -------------------------------------------------------------------------------- /components/sdcard/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(component_srcs "sdcard.c") 2 | 3 | idf_component_register(SRCS "${component_srcs}" 4 | PRIV_REQUIRES fatfs 5 | INCLUDE_DIRS ".") 6 | -------------------------------------------------------------------------------- /main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs "main.c") 2 | 3 | idf_component_register(SRCS ${srcs} INCLUDE_DIRS ".") 4 | # idf_component_register(SRCS ${srcs} INCLUDE_DIRS "." EMBED_TXTFILES luan_eng_br.pem) -------------------------------------------------------------------------------- /components/wifi_station/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(component_srcs "wifi_station.c") 2 | 3 | idf_component_register(SRCS "${component_srcs}" 4 | INCLUDE_DIRS "." 5 | PRIV_REQUIRES nvs_flash 6 | ) 7 | -------------------------------------------------------------------------------- /components/http_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(component_srcs "http_client.c") 2 | 3 | idf_component_register(SRCS "${component_srcs}" 4 | INCLUDE_DIRS "." 5 | PRIV_REQUIRES esp-tls 6 | PRIV_REQUIRES esp_http_client 7 | ) 8 | -------------------------------------------------------------------------------- /partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 1M, 6 | storage, data, spiffs, , 0xF0000, 7 | -------------------------------------------------------------------------------- /main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | COMPONENT_EMBED_TXTFILES := luan_eng_br.pem 10 | -------------------------------------------------------------------------------- /main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "PIX Configuration" 2 | 3 | config PIX_GATEWAY_HOST 4 | string "Hostname do Gateway" 5 | default "pix.host.com" 6 | help 7 | Define o hostname do gateway 8 | 9 | config HOST_USE_HTTPS 10 | bool "Usar HTTPS" 11 | default y 12 | help 13 | Se este item estiver setado as chamadas ao Gateway serão feitas com HTTPS 14 | 15 | endmenu 16 | 17 | -------------------------------------------------------------------------------- /sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Serial flasher config 4 | # 5 | #CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 6 | 7 | # 8 | # Partition Table 9 | # 10 | CONFIG_PARTITION_TABLE_CUSTOM=y 11 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" 12 | CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" 13 | 14 | # 15 | # ESP32-specific 16 | # 17 | CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y 18 | CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 19 | 20 | 21 | CONFIG_ESP_MAIN_TASK_STACK_SIZE=18000 22 | 23 | CONFIG_ESP_TASK_WDT=n 24 | 25 | CONFIG_ESP_TLS_INSECURE=y 26 | CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y 27 | 28 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following five lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | project(esp32-pix) 7 | 8 | # Create a SPIFFS image from the contents of the 'font' directory 9 | # that fits the partition named 'storage'. FLASH_IN_PROJECT indicates that 10 | # the generated image should be flashed when the entire project is flashed to 11 | # the target with 'idf.py -p PORT flash 12 | spiffs_create_partition_image(storage font FLASH_IN_PROJECT) 13 | -------------------------------------------------------------------------------- /components/tft_library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(component_srcs "fontx.c" 2 | "ili9225.c" 3 | "ili9320.c" 4 | "ili9325.c" 5 | "ili9327.c" 6 | "ili9341.c" 7 | "ili9342.c" 8 | "ili9481.c" 9 | "ili9486.c" 10 | "ili9488.c" 11 | "lcd_com.c" 12 | "lcd_lib.c" 13 | "lgdp4532.c" 14 | "r61509.c" 15 | "st7781.c" 16 | "s6d1121.c" 17 | "hx8347.c" 18 | "i2s_lcd_esp32_driver.c" 19 | "i2s_lcd_esp32s2_driver.c" 20 | ) 21 | 22 | idf_component_register(SRCS "${component_srcs}" 23 | PRIV_REQUIRES driver 24 | PRIV_REQUIRES esp_adc_cal 25 | INCLUDE_DIRS ".") 26 | -------------------------------------------------------------------------------- /components/sdcard/sdcard.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "esp_vfs_fat.h" 5 | #include "sdmmc_cmd.h" 6 | 7 | #define MOUNT_POINT "/sdcard" 8 | 9 | #define PIN_NUM_MISO CONFIG_PIN_MISO 10 | #define PIN_NUM_MOSI CONFIG_PIN_MOSI 11 | #define PIN_NUM_CLK CONFIG_PIN_CLK 12 | #define PIN_NUM_CS CONFIG_PIN_CS 13 | 14 | #if CONFIG_IDF_TARGET_ESP32S2 15 | #define SPI_DMA_CHAN host.slot 16 | #elif CONFIG_IDF_TARGET_ESP32C3 17 | #define SPI_DMA_CHAN SPI_DMA_CH_AUTO 18 | #else 19 | #define SPI_DMA_CHAN 1 20 | #endif 21 | 22 | void sdcard_init(sdmmc_card_t *card); 23 | 24 | void sdcard_load_config(char* wifi_ssid, char* wifi_password); 25 | -------------------------------------------------------------------------------- /components/tft_library/r61509.h: -------------------------------------------------------------------------------- 1 | #ifndef __R61509_H__ 2 | #define __R61509_H__ 3 | 4 | void r61509_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void r61509_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void r61509_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void r61509_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void r61509_lcdDisplayOff(TFT_t * dev); 9 | void r61509_lcdDisplayOn(TFT_t * dev); 10 | void r61509_lcdInversionOff(TFT_t * dev); 11 | void r61509_lcdInversionOn(TFT_t * dev); 12 | void r61509_lcdBGRFilter(TFT_t * dev); 13 | bool r61509_lcdEnableScroll(TFT_t * dev); 14 | void r61509_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void r61509_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void r61509_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/st7781.h: -------------------------------------------------------------------------------- 1 | #ifndef __ST7781_H__ 2 | #define __ST7781_H__ 3 | 4 | void st7781_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9325_lcdDisplayOff(TFT_t * dev); 9 | void ili9325_lcdDisplayOn(TFT_t * dev); 10 | void ili9325_lcdInversionOff(TFT_t * dev); 11 | void ili9325_lcdInversionOn(TFT_t * dev); 12 | void ili9325_lcdBGRFilter(TFT_t * dev); 13 | bool ili9325_lcdEnableScroll(TFT_t * dev); 14 | void ili9325_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9325_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9325_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9225.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9225_H__ 2 | #define __ILI9225_H__ 3 | 4 | void ili9225_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9225_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9225_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9225_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9225_lcdDisplayOff(TFT_t * dev); 9 | void ili9225_lcdDisplayOn(TFT_t * dev); 10 | void ili9225_lcdInversionOff(TFT_t * dev); 11 | void ili9225_lcdInversionOn(TFT_t * dev); 12 | void ili9225_lcdBGRFilter(TFT_t * dev); 13 | bool ili9225_lcdEnableScroll(TFT_t * dev); 14 | void ili9225_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9225_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9225_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9320.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9320_H__ 2 | #define __ILI9320_H__ 3 | 4 | void ili9320_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9325_lcdDisplayOff(TFT_t * dev); 9 | void ili9325_lcdDisplayOn(TFT_t * dev); 10 | void ili9325_lcdInversionOff(TFT_t * dev); 11 | void ili9325_lcdInversionOn(TFT_t * dev); 12 | void ili9325_lcdBGRFilter(TFT_t * dev); 13 | bool ili9325_lcdEnableScroll(TFT_t * dev); 14 | void ili9325_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9325_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9325_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9325.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9325_H__ 2 | #define __ILI9325_H__ 3 | 4 | void ili9325_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9325_lcdDisplayOff(TFT_t * dev); 9 | void ili9325_lcdDisplayOn(TFT_t * dev); 10 | void ili9325_lcdInversionOff(TFT_t * dev); 11 | void ili9325_lcdInversionOn(TFT_t * dev); 12 | void ili9325_lcdBGRFilter(TFT_t * dev); 13 | bool ili9325_lcdEnableScroll(TFT_t * dev); 14 | void ili9325_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9325_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9325_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9327.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9327_H__ 2 | #define __ILI9327_H__ 3 | 4 | void ili9327_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9341_lcdDisplayOff(TFT_t * dev); 9 | void ili9341_lcdDisplayOn(TFT_t * dev); 10 | void ili9341_lcdInversionOff(TFT_t * dev); 11 | void ili9341_lcdInversionOn(TFT_t * dev); 12 | void ili9341_lcdBGRFilter(TFT_t * dev); 13 | bool ili9341_lcdEnableScroll(TFT_t * dev); 14 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9341.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9341_H__ 2 | #define __ILI9341_H__ 3 | 4 | void ili9341_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9341_lcdDisplayOff(TFT_t * dev); 9 | void ili9341_lcdDisplayOn(TFT_t * dev); 10 | void ili9341_lcdInversionOff(TFT_t * dev); 11 | void ili9341_lcdInversionOn(TFT_t * dev); 12 | void ili9341_lcdBGRFilter(TFT_t * dev); 13 | bool ili9341_lcdEnableScroll(TFT_t * dev); 14 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9481.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9481_H__ 2 | #define __ILI9481_H__ 3 | 4 | void ili9481_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9341_lcdDisplayOff(TFT_t * dev); 9 | void ili9341_lcdDisplayOn(TFT_t * dev); 10 | void ili9341_lcdInversionOff(TFT_t * dev); 11 | void ili9341_lcdInversionOn(TFT_t * dev); 12 | void ili9341_lcdBGRFilter(TFT_t * dev); 13 | bool ili9341_lcdEnableScroll(TFT_t * dev); 14 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9486.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9486_H__ 2 | #define __ILI9486_H__ 3 | 4 | void ili9486_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9341_lcdDisplayOff(TFT_t * dev); 9 | void ili9341_lcdDisplayOn(TFT_t * dev); 10 | void ili9341_lcdInversionOff(TFT_t * dev); 11 | void ili9341_lcdInversionOn(TFT_t * dev); 12 | void ili9341_lcdBGRFilter(TFT_t * dev); 13 | bool ili9341_lcdEnableScroll(TFT_t * dev); 14 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9488.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9488_H__ 2 | #define __ILI9488_H__ 3 | 4 | void ili9488_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9341_lcdDisplayOff(TFT_t * dev); 9 | void ili9341_lcdDisplayOn(TFT_t * dev); 10 | void ili9341_lcdInversionOff(TFT_t * dev); 11 | void ili9341_lcdInversionOn(TFT_t * dev); 12 | void ili9341_lcdBGRFilter(TFT_t * dev); 13 | bool ili9341_lcdEnableScroll(TFT_t * dev); 14 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/s6d1121.h: -------------------------------------------------------------------------------- 1 | #ifndef __S6D1121_H__ 2 | #define __S6D1121_H__ 3 | 4 | void s6d1121_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void s6d1121_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void s6d1121_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void s6d1121_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void s6d1121_lcdDisplayOff(TFT_t * dev); 9 | void s6d1121_lcdDisplayOn(TFT_t * dev); 10 | void s6d1121_lcdInversionOff(TFT_t * dev); 11 | void s6d1121_lcdInversionOn(TFT_t * dev); 12 | void s6d1121_lcdBGRFilter(TFT_t * dev); 13 | bool s6d1121_lcdEnableScroll(TFT_t * dev); 14 | void s6d1121_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void s6d1121_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void s6d1121_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/tft_library/ili9342.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9342_H__ 2 | #define __ILI9342_H__ 3 | 4 | 5 | void ili9342_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 6 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 7 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 8 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 9 | void ili9341_lcdDisplayOff(TFT_t * dev); 10 | void ili9341_lcdDisplayOn(TFT_t * dev); 11 | void ili9341_lcdInversionOff(TFT_t * dev); 12 | void ili9341_lcdInversionOn(TFT_t * dev); 13 | void ili9341_lcdBGRFilter(TFT_t * dev); 14 | bool ili9341_lcdEnableScroll(TFT_t * dev); 15 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 16 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 17 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp); 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /components/tft_library/lgdp4532.h: -------------------------------------------------------------------------------- 1 | #ifndef __LGDP4532_H__ 2 | #define __LGDP4532_H__ 3 | 4 | void lgdp4532_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 7 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 8 | void ili9325_lcdDisplayOff(TFT_t * dev); 9 | void ili9325_lcdDisplayOn(TFT_t * dev); 10 | void ili9325_lcdInversionOff(TFT_t * dev); 11 | void ili9325_lcdInversionOn(TFT_t * dev); 12 | void ili9325_lcdBGRFilter(TFT_t * dev); 13 | bool ili9325_lcdEnableScroll(TFT_t * dev); 14 | void ili9325_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 15 | void ili9325_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 16 | void ili9325_lcdStartScroll(TFT_t * dev, uint16_t vsp); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /components/wifi_station/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "WIFI Configuration" 2 | 3 | config LOAD_FROM_SD_CARD 4 | bool "Load WiFi SSID and Password from SD Card" 5 | default n 6 | help 7 | If this config item is set, WiFi SSID and Password will be loaded from SD Card. 8 | 9 | config ESP_WIFI_SSID 10 | depends on !LOAD_FROM_SD_CARD 11 | string "WiFi SSID" 12 | default "myssid" 13 | help 14 | SSID (network name) for the example to connect to. 15 | 16 | config ESP_WIFI_PASSWORD 17 | depends on !LOAD_FROM_SD_CARD 18 | string "WiFi Password" 19 | default "mypassword" 20 | help 21 | WiFi password (WPA or WPA2) for the example to use. 22 | 23 | config ESP_MAXIMUM_RETRY 24 | int "Maximum retry" 25 | default 5 26 | help 27 | Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. 28 | endmenu 29 | 30 | -------------------------------------------------------------------------------- /components/tft_library/hx8347.h: -------------------------------------------------------------------------------- 1 | #ifndef __HX8347_H__ 2 | #define __HX8347_H__ 3 | 4 | void hx8347_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void hx8347_lcd_write_register(TFT_t * dev, uint8_t addr, uint16_t data); 6 | void hx8347_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 7 | void hx8347_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 8 | void hx8347_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 9 | void hx8347_lcdDisplayOff(TFT_t * dev); 10 | void hx8347_lcdDisplayOn(TFT_t * dev); 11 | void hx8347_lcdInversionOff(TFT_t * dev); 12 | void hx8347_lcdInversionOn(TFT_t * dev); 13 | void hx8347_lcdBGRFilter(TFT_t * dev); 14 | bool hx8347_lcdEnableScroll(TFT_t * dev); 15 | void hx8347_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 16 | void hx8347_lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 17 | void hx8347_lcdStartScroll(TFT_t * dev, uint16_t vsp); 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /components/wifi_station/wifi_station.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "freertos/event_groups.h" 5 | #include "esp_system.h" 6 | #include "esp_wifi.h" 7 | #include "esp_event.h" 8 | #include "esp_log.h" 9 | #include "nvs_flash.h" 10 | 11 | #include "lwip/err.h" 12 | #include "lwip/sys.h" 13 | 14 | /* The examples use WiFi configuration that you can set via project configuration menu 15 | 16 | If you'd rather not, just change the below entries to strings with 17 | the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid" 18 | */ 19 | #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY 20 | 21 | 22 | /* The event group allows multiple bits for each event, but we only care about two events: 23 | * - we are connected to the AP with an IP 24 | * - we failed to connect after the maximum amount of retries */ 25 | #define WIFI_CONNECTED_BIT BIT0 26 | #define WIFI_FAIL_BIT BIT1 27 | 28 | /* FreeRTOS event group to signal when we are connected*/ 29 | EventGroupHandle_t s_wifi_event_group; 30 | 31 | void wifi_init_sta(char* wifi_ssid, char* wifi_password); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 - present Luan Ferreira Reis de Jesus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/http_client/http_client.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertos/FreeRTOS.h" 4 | #include "freertos/task.h" 5 | #include "esp_log.h" 6 | #include "esp_system.h" 7 | // #include "nvs_flash.h" 8 | #include "esp_event.h" 9 | #include "esp_netif.h" 10 | #include "esp_tls.h" 11 | #include "esp_http_client.h" 12 | 13 | #define MAX_HTTP_RECV_BUFFER 512 14 | #define MAX_HTTP_OUTPUT_BUFFER 2048 15 | 16 | /* Root cert for howsmyssl.com, taken from howsmyssl_com_root_cert.pem 17 | 18 | The PEM file was extracted from the output of this command: 19 | openssl s_client -showcerts -connect www.howsmyssl.com:443 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #if CONFIG_ILI9327 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9327.h" 11 | 12 | #define TAG "ILI9327" 13 | 14 | 15 | void ili9327_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 16 | { 17 | lcdInitDevice(dev, width, height, offsetx, offsety); 18 | 19 | ESP_LOGI(TAG,"Your TFT is ILI9327"); 20 | ESP_LOGI(TAG,"Screen width:%d",width); 21 | ESP_LOGI(TAG,"Screen height:%d",height); 22 | 23 | // Initailize TFT 24 | static const uint8_t reset_off[] = { 25 | 0x01, 0, //Soft Reset 26 | TFTLCD_DELAY8, 150, 27 | 0x28, 0, //Display Off 28 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 29 | }; 30 | 31 | static const uint8_t wake_on[] = { 32 | 0x11, 0, //Sleep Out 33 | TFTLCD_DELAY8, 150, 34 | 0x29, 0, //Display On 35 | }; 36 | 37 | static const uint8_t regValues[] = { 38 | //0x36, 1, 0x08, 39 | 0x36, 1, 0x88, 40 | 0x3A, 1, 0x05, 41 | 0xC0, 6, 0x00, 0x35, 0x00, 0x00, 0x01, 0x02, 42 | 0xC1, 4, 0x10, 0x10, 0x02, 0x02, 43 | 0xC5, 1, 0x04, 44 | 0xC8,15, 0x04, 0x67, 0x35, 0x04, 0x08, 0x06, 0x24, 0x01, 0x37, 0x40, 0x03, 0x10, 0x08, 0x80, 0x00, 45 | 0xD0, 3, 0x07, 0x04, 0x00, 46 | 0xD1, 3, 0x00, 0x0C, 0x0F, 47 | 0xD2, 2, 0x01, 0x44, 48 | }; 49 | lcd_write_table(dev, reset_off, sizeof(reset_off)); 50 | lcd_write_table(dev, regValues, sizeof(regValues)); 51 | lcd_write_table(dev, wake_on, sizeof(wake_on)); 52 | 53 | // ili9327 custom function 54 | DrawPixel = ili9341_lcdDrawPixel; 55 | DrawMultiPixels = ili9341_lcdDrawMultiPixels; 56 | DrawFillRect = ili9341_lcdDrawFillRect; 57 | DisplayOff = ili9341_lcdDisplayOff; 58 | DisplayOn = ili9341_lcdDisplayOn; 59 | InversionOff = ili9341_lcdInversionOff; 60 | InversionOn = ili9341_lcdInversionOn; 61 | EnableScroll = ili9341_lcdEnableScroll; 62 | SetScrollArea = ili9341_lcdSetScrollArea; 63 | ResetScrollArea = ili9341_lcdResetScrollArea; 64 | StartScroll = ili9341_lcdStartScroll; 65 | 66 | } 67 | #endif 68 | -------------------------------------------------------------------------------- /components/tft_library/ili9342.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #if CONFIG_ILI9342 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9342.h" 11 | 12 | #define TAG "ILI9342" 13 | 14 | 15 | void ili9342_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 16 | { 17 | lcdInitDevice(dev, width, height, offsetx, offsety); 18 | 19 | ESP_LOGI(TAG,"Your TFT is ILI9341"); 20 | ESP_LOGI(TAG,"Screen width:%d",width); 21 | ESP_LOGI(TAG,"Screen height:%d",height); 22 | 23 | // Initailize TFT 24 | static const uint8_t reset_off[] = { 25 | 0x01, 0, //Soft Reset 26 | TFTLCD_DELAY8, 150, 27 | 0x28, 0, //Display Off 28 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 29 | }; 30 | 31 | static const uint8_t wake_on[] = { 32 | 0x11, 0, //Sleep Out 33 | TFTLCD_DELAY8, 150, 34 | 0x29, 0, //Display On 35 | }; 36 | 37 | static const uint8_t regValues[] = { 38 | 0xC0, 2, 0x26, 0x09, 39 | 0xC1, 1, 0x10, 40 | 0xC5, 2, 0x3E, 0x28, 41 | 0xC7, 1, 0x86, 42 | 0x36, 1, 0x68, 43 | 0xB1, 2, 0x00, 0x18, 44 | 0xB6, 4, 0x0A, 0xA2, 0x27, 0x04, 45 | 0x21, 0, // Display Inversion ON 46 | 0x26, 1, 0x01, 47 | 0xE0,15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, 48 | 0xE1,15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, 49 | }; 50 | lcd_write_table(dev, reset_off, sizeof(reset_off)); 51 | lcd_write_table(dev, regValues, sizeof(regValues)); 52 | lcd_write_table(dev, wake_on, sizeof(wake_on)); 53 | 54 | // ili9342 custom function 55 | DrawPixel = ili9341_lcdDrawPixel; 56 | DrawMultiPixels = ili9341_lcdDrawMultiPixels; 57 | DrawFillRect = ili9341_lcdDrawFillRect; 58 | DisplayOff = ili9341_lcdDisplayOff; 59 | DisplayOn = ili9341_lcdDisplayOn; 60 | InversionOff = ili9341_lcdInversionOff; 61 | InversionOn = ili9341_lcdInversionOn; 62 | EnableScroll = ili9341_lcdEnableScroll; 63 | SetScrollArea = ili9341_lcdSetScrollArea; 64 | ResetScrollArea = ili9341_lcdResetScrollArea; 65 | StartScroll = ili9341_lcdStartScroll; 66 | 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Esp32-pix 2 | Integração entre esp32 e api pix. 3 | 4 | Este projeto foi desenvolvido usando o framework [ESP-IDF](https://github.com/espressif/esp-idf). 5 | 6 | ## Configuração 7 | 8 | Antes de compilar é preciso ajustar configurações ambientais do sistema. Para isso é preciso executar os seguintes comandos: 9 | ``` 10 | idf.py set-target esp32 11 | 12 | idf.py menuconfig 13 | ``` 14 | No menu **PIX Configuration** ajuste a configuração de conexão com o pix: 15 | 16 | 1. PIX_GATEWAY_HOST: _hostname_ do _gateway_; 17 | 2. HOST_USE_HTTPS: Define se as chamadas ao _gateway_ usarão ou não HTTPS; 18 | 19 | No menu **WIFI Configuration** ajuste a configuração de conexão WiFi: 20 | 21 | 1. LOAD_FROM_SD_CARD: Define se a configuração do WiFi será feita via arquivo ou via menuconfig; 22 | 2. ESP_WIFI_SSID: nome da conexão wifi; 23 | 3. ESP_WIFI_PASSWORD: senha da conexão wifi; 24 | 25 | Caso a configuração seja feita via arquivo é preciso colocar o arquivo config.txt na raiz do cartão SD contendo duas linhas, a primeira com o SSID e a segunda com a Senha. 26 | ``` 27 | SSID 28 | senha 29 | ``` 30 | 31 | No menu **SD CARD SPI Configuration** ajuste a pinagem de conexão com o SD Card. 32 | 33 | No menu **TFT Configuration** escolha o driver e a pinagem do display LCD. 34 | 35 | ## Compilação 36 | 37 | Para compilar o código basta executar os comandos a seguir na raiz do projeto: 38 | 39 | ``` 40 | idf.py build 41 | ``` 42 | 43 | ## Módulos principais 44 | 45 | 1. main: código principal do _firmware_; 46 | 2. tft_library: Biblioteca para comunição o display LCD. Desenvolvida por nopnop2002, https://github.com/nopnop2002/esp-idf-parallel-tft; 47 | 3. qrcodegen: biblioteca usada para gerar o QR Code. Desenvolvida por nayuki, https://github.com/nayuki/QR-Code-generator/tree/master/c; 48 | 4. http_client: biblioteca para encapsular as chamadas HTTP ao _gateway_; 49 | 5. wifi_station: biblioteca que encapsula as configurações do adaptador wifi; 50 | 6. sdcard: biblioteca para comunicar com o cartão sd e ler o arquivo de configuração; 51 | 52 | ## Funcionamento 53 | 54 | Um vídeo do sistema em funcionamento pode ser visto em [https://youtu.be/LkkqwxMjYC8](https://youtu.be/LkkqwxMjYC8) 55 | -------------------------------------------------------------------------------- /components/tft_library/ili9481.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #if CONFIG_ILI9481 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9481.h" 11 | 12 | #define TAG "ILI9481" 13 | 14 | 15 | void ili9481_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 16 | { 17 | lcdInitDevice(dev, width, height, offsetx, offsety); 18 | 19 | ESP_LOGI(TAG,"Your TFT is ILI9481"); 20 | ESP_LOGI(TAG,"Screen width:%d",width); 21 | ESP_LOGI(TAG,"Screen height:%d",height); 22 | 23 | // Initailize TFT 24 | static const uint8_t reset_off[] = { 25 | 0x01, 0, //Soft Reset 26 | TFTLCD_DELAY8, 150, 27 | 0x28, 0, //Display Off 28 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 29 | }; 30 | 31 | static const uint8_t wake_on[] = { 32 | 0x11, 0, //Sleep Out 33 | TFTLCD_DELAY8, 150, 34 | 0x29, 0, //Display On 35 | }; 36 | 37 | static const uint8_t regValues[] = { 38 | 0xB0, 1, 0x00, // unlocks E0, F0 39 | 0xB3, 4, 0x02, 0x00, 0x00, 0x00, //Frame Memory, interface [02 00 00 00] 40 | 0xB4, 1, 0x00, // Frame mode [00] 41 | 0xD0, 3, 0x07, 0x42, 0x18, 42 | 0xD1, 3, 0x00, 0x07, 0x18, 43 | 0xD2, 2, 0x01, 0x02, 44 | 0xD3, 2, 0x01, 0x02, // Set Power for Partial Mode [01 22] 45 | 0xD4, 2, 0x01, 0x02, // Set Power for Idle Mode [01 22] 46 | //0xC0, 5, 0x10, 0x3B, 0x00, 0x02, 0x11, 47 | 0xC0, 5, 0x14, 0x3B, 0x00, 0x02, 0x11, 48 | 0xC1, 3, 0x10, 0x10, 0x88, // Display Timing Normal [10 10 88] 49 | 0xC5, 1, 0x03, //Frame Rate [03] 50 | 0xC6, 1, 0x02, //Interface Control [02] 51 | 0xC8, 12, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16, 0x37, 0x75, 0x77, 0x54, 0x0C, 0x00, 52 | 0xCC, 1, 0x00, //Panel Control [00] 53 | 0x36, 1, 0x18, //0x08, 54 | }; 55 | lcd_write_table(dev, reset_off, sizeof(reset_off)); 56 | lcd_write_table(dev, regValues, sizeof(regValues)); 57 | lcd_write_table(dev, wake_on, sizeof(wake_on)); 58 | 59 | // ili9481 custom function 60 | DrawPixel = ili9341_lcdDrawPixel; 61 | DrawMultiPixels = ili9341_lcdDrawMultiPixels; 62 | DrawFillRect = ili9341_lcdDrawFillRect; 63 | DisplayOff = ili9341_lcdDisplayOff; 64 | DisplayOn = ili9341_lcdDisplayOn; 65 | InversionOff = ili9341_lcdInversionOff; 66 | InversionOn = ili9341_lcdInversionOn; 67 | EnableScroll = ili9341_lcdEnableScroll; 68 | SetScrollArea = ili9341_lcdSetScrollArea; 69 | ResetScrollArea = ili9341_lcdResetScrollArea; 70 | StartScroll = ili9341_lcdStartScroll; 71 | 72 | } 73 | #endif 74 | -------------------------------------------------------------------------------- /components/tft_library/ili9488.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #if CONFIG_ILI9488 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9488.h" 11 | 12 | #define TAG "ILI9488" 13 | 14 | 15 | void ili9488_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 16 | { 17 | lcdInitDevice(dev, width, height, offsetx, offsety); 18 | 19 | ESP_LOGI(TAG,"Your TFT is ILI9488"); 20 | ESP_LOGI(TAG,"Screen width:%d",width); 21 | ESP_LOGI(TAG,"Screen height:%d",height); 22 | 23 | // Initailize TFT 24 | static const uint8_t reset_off[] = { 25 | 0x01, 0, //Soft Reset 26 | TFTLCD_DELAY8, 150, 27 | 0x28, 0, //Display Off 28 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 29 | }; 30 | 31 | static const uint8_t wake_on[] = { 32 | 0x11, 0, //Sleep Out 33 | TFTLCD_DELAY8, 150, 34 | 0x29, 0, //Display On 35 | }; 36 | 37 | static const uint8_t regValues[] = { 38 | 0xC0, 2, 0x10, 0x10, //Power Control 1 [0E 0E] 39 | 0xC1, 1, 0x41, //Power Control 2 [43] 40 | 0xC5, 4, 0x00, 0x22, 0x80, 0x40, //VCOM Control 1 [00 40 00 40] 41 | //0x36, 1, 0x68, //Memory Access [00] 42 | 0x36, 1, 0x98, //Memory Access [00] 43 | 0xB0, 1, 0x00, //Interface [00] 44 | 0xB1, 2, 0xB0, 0x11, //Frame Rate Control [B0 11] 45 | 0xB4, 1, 0x02, //Inversion Control [02] 46 | 0xB6, 3, 0x02, 0x02, 0x3B, // Display Function Control [02 02 3B] .kbv NL=480 47 | 0xB7, 1, 0xC6, //Entry Mode [06] 48 | 0x3A, 1, 0x55, //Interlace Pixel Format [XX] 49 | 0xF7, 4, 0xA9, 0x51, 0x2C, 0x82, //Adjustment Control 3 [A9 51 2C 82] 50 | //0xE0,15, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F, //Positive Gamma Control 51 | //0xE1,15, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F, //Negative Gamma Control 52 | }; 53 | lcd_write_table(dev, reset_off, sizeof(reset_off)); 54 | lcd_write_table(dev, regValues, sizeof(regValues)); 55 | lcd_write_table(dev, wake_on, sizeof(wake_on)); 56 | 57 | // ili9488 custom function 58 | DrawPixel = ili9341_lcdDrawPixel; 59 | DrawMultiPixels = ili9341_lcdDrawMultiPixels; 60 | DrawFillRect = ili9341_lcdDrawFillRect; 61 | DisplayOff = ili9341_lcdDisplayOff; 62 | DisplayOn = ili9341_lcdDisplayOn; 63 | InversionOff = ili9341_lcdInversionOff; 64 | InversionOn = ili9341_lcdInversionOn; 65 | EnableScroll = ili9341_lcdEnableScroll; 66 | SetScrollArea = ili9341_lcdSetScrollArea; 67 | ResetScrollArea = ili9341_lcdResetScrollArea; 68 | StartScroll = ili9341_lcdStartScroll; 69 | 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /components/tft_library/ili9486.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #if CONFIG_ILI9486 || CONFIG_ST7796 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9486.h" 11 | 12 | #define TAG "ILI9486" 13 | 14 | 15 | void ili9486_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 16 | { 17 | lcdInitDevice(dev, width, height, offsetx, offsety); 18 | 19 | #if CONFIG_ILI9486 20 | ESP_LOGI(TAG,"Your TFT is ILI9486.Same as ST7796"); 21 | #elif CONFIG_ST7796 22 | ESP_LOGI(TAG,"Your TFT is ST7796.Same as ILI9486"); 23 | #endif 24 | ESP_LOGI(TAG,"Screen width:%d",width); 25 | ESP_LOGI(TAG,"Screen height:%d",height); 26 | 27 | // Initailize TFT 28 | static const uint8_t reset_off[] = { 29 | 0x01, 0, //Soft Reset 30 | TFTLCD_DELAY8, 150, 31 | 0x28, 0, //Display Off 32 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 33 | }; 34 | 35 | static const uint8_t wake_on[] = { 36 | 0x11, 0, //Sleep Out 37 | TFTLCD_DELAY8, 150, 38 | 0x29, 0, //Display On 39 | }; 40 | 41 | static const uint8_t regValues[] = { 42 | 0xB0, 1, 0x00, // unlocks E0, F0 43 | 0xB3, 4, 0x02, 0x00, 0x00, 0x00, //Frame Memory, interface [02 00 00 00] 44 | 0xB4, 1, 0x00, // Frame mode [00] 45 | //0xB6, 3, 0x02, 0x02, 0x3B, // Display Function Control [02 02 3B] 46 | 0xB6, 3, 0x02, 0x42, 0x3B, // Display Function Control [02 02 3B] 47 | 0xD0, 3, 0x07, 0x42, 0x18, 48 | 0xD1, 3, 0x00, 0x07, 0x18, 49 | 0xD2, 2, 0x01, 0x02, 50 | 0xD3, 2, 0x01, 0x02, // Set Power for Partial Mode [01 22] 51 | 0xD4, 2, 0x01, 0x02, // Set Power for Idle Mode [01 22] 52 | //0xC0, 5, 0x10, 0x3B, 0x00, 0x02, 0x11, 53 | 0xC0, 5, 0x14, 0x3B, 0x00, 0x02, 0x11, 54 | 0xC1, 3, 0x10, 0x10, 0x88, // Display Timing Normal [10 10 88] 55 | 0xC5, 1, 0x03, //Frame Rate [03] 56 | 0xC6, 1, 0x02, //Interface Control [02] 57 | 0xC8, 12, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16, 0x37, 0x75, 0x77, 0x54, 0x0C, 0x00, 58 | 0xCC, 1, 0x00, //Panel Control [00] 59 | 0x36, 1, 0x18, //0x08, 60 | }; 61 | lcd_write_table(dev, reset_off, sizeof(reset_off)); 62 | lcd_write_table(dev, regValues, sizeof(regValues)); 63 | lcd_write_table(dev, wake_on, sizeof(wake_on)); 64 | 65 | // ili9486 custom function 66 | DrawPixel = ili9341_lcdDrawPixel; 67 | DrawMultiPixels = ili9341_lcdDrawMultiPixels; 68 | DrawFillRect = ili9341_lcdDrawFillRect; 69 | DisplayOff = ili9341_lcdDisplayOff; 70 | DisplayOn = ili9341_lcdDisplayOn; 71 | InversionOff = ili9341_lcdInversionOff; 72 | InversionOn = ili9341_lcdInversionOn; 73 | EnableScroll = ili9341_lcdEnableScroll; 74 | SetScrollArea = ili9341_lcdSetScrollArea; 75 | ResetScrollArea = ili9341_lcdResetScrollArea; 76 | StartScroll = ili9341_lcdStartScroll; 77 | 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /components/tft_library/st7781.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #if CONFIG_ST7781 || CONFIG_ST7783 9 | 10 | #include "lcd_com.h" 11 | #include "lcd_lib.h" 12 | #include "st7781.h" 13 | 14 | #define TAG "ST7781" 15 | 16 | void st7781_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | #if CONFIG_ST7781 21 | ESP_LOGI(TAG,"Your TFT is ST7781"); 22 | #elif CONFIG_ST7783 23 | ESP_LOGI(TAG,"Your TFT is ST7783"); 24 | #endif 25 | ESP_LOGI(TAG,"Screen width:%d",width); 26 | ESP_LOGI(TAG,"Screen height:%d",height); 27 | 28 | static const uint16_t ST7781_regValues[] = { 29 | 0x00FF, 0x0001, //can we do 0xFF 30 | 0x00F3, 0x0008, 31 | 0x0000, 0x0001, 32 | 0x0001, 0x0000, // Driver Output Control Register (R01h) 33 | 0x0002, 0x0700, // LCD Driving Waveform Control (R02h) 34 | 0x0003, 0x1030, // Entry Mode (R03h) 35 | //0x0003, 0x1000, // Entry Mode (R03h) 36 | 0x0008, 0x0302, 37 | 0x0009, 0x0000, 38 | 0x0010, 0x0000, // Power Control 1 (R10h) 39 | 0x0011, 0x0007, // Power Control 2 (R11h) 40 | 0x0012, 0x0000, // Power Control 3 (R12h) 41 | 0x0013, 0x0000, // Power Control 4 (R13h) 42 | TFTLCD_DELAY16,50, 43 | 0x0010, 0x14B0, // Power Control 1 SAP=1, BT=4, APE=1, AP=3 44 | TFTLCD_DELAY16,10, 45 | 0x0011, 0x0007, // Power Control 2 VC=7 46 | TFTLCD_DELAY16,10, 47 | 0x0012, 0x008E, // Power Control 3 VCIRE=1, VRH=14 48 | 0x0013, 0x0C00, // Power Control 4 VDV=12 49 | 0x0029, 0x0015, // NVM read data 2 VCM=21 50 | TFTLCD_DELAY16,10, 51 | 0x0030, 0x0000, // Gamma Control 1 52 | 0x0031, 0x0107, // Gamma Control 2 53 | 0x0032, 0x0000, // Gamma Control 3 54 | 0x0035, 0x0203, // Gamma Control 6 55 | 0x0036, 0x0402, // Gamma Control 7 56 | 0x0037, 0x0000, // Gamma Control 8 57 | 0x0038, 0x0207, // Gamma Control 9 58 | 0x0039, 0x0000, // Gamma Control 10 59 | 0x003C, 0x0203, // Gamma Control 13 60 | 0x003D, 0x0403, // Gamma Control 14 61 | //0x0060, 0xA700, // Driver Output Control (R60h) .kbv was 0xa700 62 | 0x0060, 0x2700, // Driver Output Control (R60h) .kbv was 0xa700 63 | 0x0061, 0x0001, // Driver Output Control (R61h) 64 | 0x0090, 0X0029, // Panel Interface Control 1 (R90h) 65 | 0x0007, 0x0133, // Display Control (R07h) 66 | }; 67 | lcd_write_table16(dev, ST7781_regValues, sizeof(ST7781_regValues)); 68 | 69 | // st7781 custom function 70 | DrawPixel = ili9325_lcdDrawPixel; 71 | DrawMultiPixels = ili9325_lcdDrawMultiPixels; 72 | DrawFillRect = ili9325_lcdDrawFillRect; 73 | DisplayOff = ili9325_lcdDisplayOff; 74 | DisplayOn = ili9325_lcdDisplayOn; 75 | InversionOff = ili9325_lcdInversionOff; 76 | InversionOn = ili9325_lcdInversionOn; 77 | EnableScroll = ili9325_lcdEnableScroll; 78 | SetScrollArea = ili9325_lcdSetScrollArea; 79 | ResetScrollArea = ili9325_lcdResetScrollArea; 80 | StartScroll = ili9325_lcdStartScroll; 81 | 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /components/tft_library/ili9320.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9320.h" 11 | 12 | #define TAG "ILI9320" 13 | 14 | #if CONFIG_ILI9320 || CONFIG_SPFD5408 || CONFIG_R61505 15 | 16 | void ili9320_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | #if CONFIG_ILI9320 21 | ESP_LOGI(TAG,"Your TFT is ILI9320"); 22 | #elif CONFIG_SPFD5408 23 | ESP_LOGI(TAG,"Your TFT is SPFD5408"); 24 | #endif 25 | ESP_LOGI(TAG,"Screen width:%d",width); 26 | ESP_LOGI(TAG,"Screen height:%d",height); 27 | 28 | static const uint16_t ILI9320_regValues[] = { 29 | 0x00e5, 0x8000, 30 | 0x0000, 0x0001, 31 | 0x0001, 0x100, 32 | 0x0002, 0x0700, 33 | 0x0003, 0x1030, 34 | 0x0004, 0x0000, 35 | 0x0008, 0x0202, 36 | 0x0009, 0x0000, 37 | 0x000A, 0x0000, 38 | 0x000C, 0x0000, 39 | 0x000D, 0x0000, 40 | 0x000F, 0x0000, 41 | //-----Power On sequence----------------------- 42 | 0x0010, 0x0000, 43 | 0x0011, 0x0007, 44 | 0x0012, 0x0000, 45 | 0x0013, 0x0000, 46 | TFTLCD_DELAY, 50, 47 | 0x0010, 0x17B0, //SAP=1, BT=7, APE=1, AP=3 48 | 0x0011, 0x0007, //DC1=0, DC0=0, VC=7 49 | TFTLCD_DELAY, 10, 50 | 0x0012, 0x013A, //VCMR=1, PON=3, VRH=10 51 | TFTLCD_DELAY, 10, 52 | 0x0013, 0x1A00, //VDV=26 53 | 0x0029, 0x000c, //VCM=12 54 | TFTLCD_DELAY, 10, 55 | //-----Gamma control----------------------- 56 | 0x0030, 0x0000, 57 | 0x0031, 0x0505, 58 | 0x0032, 0x0004, 59 | 0x0035, 0x0006, 60 | 0x0036, 0x0707, 61 | 0x0037, 0x0105, 62 | 0x0038, 0x0002, 63 | 0x0039, 0x0707, 64 | 0x003C, 0x0704, 65 | 0x003D, 0x0807, 66 | //-----Set RAM area----------------------- 67 | //0x0060, 0xA700, //GS=1 68 | 0x0060, 0x2700, //GS=1 69 | 0x0061, 0x0001, 70 | 0x006A, 0x0000, 71 | 0x0021, 0x0000, 72 | 0x0020, 0x0000, 73 | //-----Partial Display Control------------ 74 | 0x0080, 0x0000, 75 | 0x0081, 0x0000, 76 | 0x0082, 0x0000, 77 | 0x0083, 0x0000, 78 | 0x0084, 0x0000, 79 | 0x0085, 0x0000, 80 | //-----Panel Control---------------------- 81 | 0x0090, 0x0010, 82 | 0x0092, 0x0000, 83 | 0x0093, 0x0003, 84 | 0x0095, 0x0110, 85 | 0x0097, 0x0000, 86 | 0x0098, 0x0000, 87 | //-----Display on----------------------- 88 | 0x0007, 0x0173, 89 | TFTLCD_DELAY, 50, 90 | }; 91 | lcd_write_table16(dev, ILI9320_regValues, sizeof(ILI9320_regValues)); 92 | 93 | // ili9320 custom function 94 | DrawPixel = ili9325_lcdDrawPixel; 95 | DrawMultiPixels = ili9325_lcdDrawMultiPixels; 96 | DrawFillRect = ili9325_lcdDrawFillRect; 97 | DisplayOff = ili9325_lcdDisplayOff; 98 | DisplayOn = ili9325_lcdDisplayOn; 99 | InversionOff = ili9325_lcdInversionOff; 100 | InversionOn = ili9325_lcdInversionOn; 101 | EnableScroll = ili9325_lcdEnableScroll; 102 | SetScrollArea = ili9325_lcdSetScrollArea; 103 | ResetScrollArea = ili9325_lcdResetScrollArea; 104 | StartScroll = ili9325_lcdStartScroll; 105 | 106 | } 107 | #endif 108 | -------------------------------------------------------------------------------- /components/wifi_station/wifi_station.c: -------------------------------------------------------------------------------- 1 | #include "wifi_station.h" 2 | 3 | static const char *TAG = "wifi station"; 4 | 5 | static int s_retry_num = 0; 6 | 7 | static void event_handler(void* arg, esp_event_base_t event_base, 8 | int32_t event_id, void* event_data) 9 | { 10 | if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { 11 | esp_wifi_connect(); 12 | } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { 13 | if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { 14 | esp_wifi_connect(); 15 | s_retry_num++; 16 | ESP_LOGI(TAG, "retry to connect to the AP"); 17 | } else { 18 | xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); 19 | } 20 | ESP_LOGI(TAG,"connect to the AP fail"); 21 | } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { 22 | ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; 23 | ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); 24 | s_retry_num = 0; 25 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); 26 | } 27 | } 28 | 29 | void wifi_init_sta(char* wifi_ssid, char* wifi_password) 30 | { 31 | ESP_ERROR_CHECK(esp_netif_init()); 32 | 33 | ESP_ERROR_CHECK(esp_event_loop_create_default()); 34 | esp_netif_create_default_wifi_sta(); 35 | 36 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 37 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 38 | 39 | esp_event_handler_instance_t instance_any_id; 40 | esp_event_handler_instance_t instance_got_ip; 41 | ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, 42 | ESP_EVENT_ANY_ID, 43 | &event_handler, 44 | NULL, 45 | &instance_any_id)); 46 | ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, 47 | IP_EVENT_STA_GOT_IP, 48 | &event_handler, 49 | NULL, 50 | &instance_got_ip)); 51 | 52 | wifi_config_t wifi_config = { 53 | .sta = { 54 | /* Setting a password implies station will connect to all security modes including WEP/WPA. 55 | * However these modes are deprecated and not advisable to be used. Incase your Access point 56 | * doesn't support WPA2, these mode can be enabled by commenting below line */ 57 | .threshold.authmode = WIFI_AUTH_WPA2_PSK, 58 | 59 | .pmf_cfg = { 60 | .capable = true, 61 | .required = false 62 | }, 63 | }, 64 | }; 65 | 66 | strcpy((char*) wifi_config.sta.ssid, (char *) wifi_ssid); 67 | strcpy((char*) wifi_config.sta.password, (char *) wifi_password); 68 | 69 | ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); 70 | ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); 71 | ESP_ERROR_CHECK(esp_wifi_start() ); 72 | 73 | ESP_LOGI(TAG, "wifi_init_sta finished."); 74 | } -------------------------------------------------------------------------------- /components/tft_library/lcd_com.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_COM_H__ 2 | #define __LCD_COM_H__ 3 | 4 | #include "driver/adc.h" 5 | #include "esp_adc_cal.h" 6 | #include "i2s_lcd_driver.h" 7 | 8 | #define TFTLCD_DELAY 0xFFFF 9 | #define TFTLCD_DELAY16 0xFFFF 10 | #define TFTLCD_DELAY8 0x7F 11 | 12 | #define INTERFACE_I2S 1 13 | #define INTERFACE_GPIO 2 14 | #define INTERFACE_REG 3 15 | 16 | #define GPIO_PORT_NUM 0 17 | 18 | #define MODE_RESET 0 19 | #define MODE_OUTPUT 1 20 | #define MODE_INPUT 2 21 | 22 | #define NUMSAMPLES 2 // Number of samples 23 | #define COMP 2 // Coordinate tolerance 24 | #define AVERAGETIME 4 // Number of samples when averaging 25 | #define RXPLATE 300 26 | 27 | typedef struct { 28 | uint16_t _width; 29 | uint16_t _height; 30 | uint16_t _offsetx; 31 | uint16_t _offsety; 32 | uint16_t _font_direction; 33 | uint16_t _font_fill; 34 | uint16_t _font_fill_color; 35 | uint16_t _font_underline; 36 | uint16_t _font_underline_color; 37 | int16_t _rd; 38 | int16_t _wr; 39 | int16_t _rs; 40 | int16_t _cs; 41 | int16_t _d0; 42 | int16_t _d1; 43 | int16_t _d2; 44 | int16_t _d3; 45 | int16_t _d4; 46 | int16_t _d5; 47 | int16_t _d6; 48 | int16_t _d7; 49 | int16_t _delay; 50 | int16_t _interface; 51 | bool _debug; 52 | i2s_lcd_handle_t i2s_lcd_handle; 53 | adc1_channel_t _adc_yp; 54 | adc1_channel_t _adc_xm; 55 | int16_t _gpio_xp; 56 | int16_t _gpio_xm; 57 | int16_t _gpio_yp; 58 | int16_t _gpio_ym; 59 | int16_t _rawxp; 60 | int16_t _rawyp; 61 | bool _calibration; 62 | int16_t _min_xp; // Minimum xp calibration 63 | int16_t _min_yp; // Minimum yp calibration 64 | int16_t _max_xp; // Maximum xp calibration 65 | int16_t _max_yp; // Maximum yp calibration 66 | int16_t _min_xc; // Minimum x coordinate 67 | int16_t _min_yc; // Minimum y coordinate 68 | int16_t _max_xc; // Maximum x coordinate 69 | int16_t _max_yc; // Maximum y coordinate 70 | } TFT_t; 71 | 72 | void gpio_digital_write(int GPIO_PIN, uint8_t data); 73 | void gpio_lcd_write_data(int dummy1, unsigned char *data, size_t size); 74 | void reg_lcd_write_data(int dummy1, unsigned char *data, size_t size); 75 | 76 | void lcd_write_table(TFT_t * dev, const void *table, int16_t size); 77 | void lcd_write_table16(TFT_t * dev, const void *table, int16_t size); 78 | void lcd_write_comm_byte(TFT_t * dev, uint8_t cmd); 79 | void lcd_write_comm_word(TFT_t * dev, uint16_t cmd); 80 | void lcd_write_data_byte(TFT_t * dev, uint8_t data); 81 | void lcd_write_data_word(TFT_t * dev, uint16_t data); 82 | void lcd_write_addr(TFT_t * dev, uint16_t addr1, uint16_t addr2); 83 | void lcd_write_color(TFT_t * dev, uint16_t color, uint16_t size); 84 | void lcd_write_colors(TFT_t * dev, uint16_t * colors, uint16_t size); 85 | void lcd_delay_ms(int delay_time); 86 | void lcd_write_register_word(TFT_t * dev, uint16_t addr, uint16_t data); 87 | void lcd_write_register_byte(TFT_t * dev, uint8_t addr, uint16_t data); 88 | esp_err_t lcd_interface_cfg(TFT_t * dev, int interface); 89 | 90 | void touch_interface_cfg(TFT_t * dev, int adc_yp, int adc_xm, int gpio_xp, int gpio_xm, int gpio_yp, int gpio_ym); 91 | int touch_avr_analog(adc1_channel_t channel, int averagetime); 92 | void touch_gpio(int gpio, int mode, int level); 93 | int touch_getx(TFT_t * dev); 94 | int touch_gety(TFT_t * dev); 95 | int touch_getz(TFT_t * dev); 96 | void touch_getxyz(TFT_t * dev, int *xp, int *yp, int *zp); 97 | bool touch_getxy(TFT_t *dev, int *xp, int *yp); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /components/tft_library/lgdp4532.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #if CONFIG_LGDP4532 9 | 10 | #include "lcd_com.h" 11 | #include "lcd_lib.h" 12 | #include "lgdp4532.h" 13 | 14 | #define TAG "LGDP4532" 15 | 16 | void lgdp4532_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | ESP_LOGI(TAG,"Your TFT is LGDP4532"); 21 | ESP_LOGI(TAG,"Screen width:%d",width); 22 | ESP_LOGI(TAG,"Screen height:%d",height); 23 | 24 | static const uint16_t LGDP4532_regValues[] = { 25 | 0x0000,0x0001, //Device code read 26 | 0x0010,0x0628, //Power control 1 SAP[2:0] BT[3:0] AP[2:0] DK DSTB SLP 27 | 0x0012,0x0006, //Power control 3 PON VRH[3:0] 28 | //0x0013,0x0A32, //Power control 4 VCOMG VDV[4:0] VCM[6:0] 29 | 0x0011,0x0040, //Power control 2; DC1[2:0] DC0[2:0] VC[2:0] 30 | //0x0015,0x0050, //Regulator control RSET RI[2:0] RV[2:0] RCONT[2:0] 31 | 0x0012,0x0016, //Power control 3 PON VRH[3:0] 32 | TFTLCD_DELAY16,50, 33 | 0x0010,0x5660, //Power control 1 SAP[2:0] BT[3:0] AP[2:0] DK DSTB SLP 34 | TFTLCD_DELAY16,50, 35 | //0x0013,0x2A4E, //Power control 4 VCOMG VDV[4:0] VCM[6:0] 36 | //0x0001,0x0100, //Driver output control SM SS 37 | //0x0002,0x0300, //LCD Driving Wave Control 38 | 0x0003,0x1030, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 39 | //0x0003,0x1020, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 40 | //0x0003,0x1010, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 41 | //0x0003,0x1000, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 42 | //0x0007,0x0202, //Display Control 1 PTDE[1:0] BASEE GON DTE COL D[1:0] 43 | TFTLCD_DELAY16,50, 44 | //0x0008,0x0202, //Display Control 2 FP[3:0] BP[3:0] front and back porch (blank period at begin and end..) 45 | //0x000A,0x0000, //Test Register 1 (RA0h) 46 | //Gamma adjustment 47 | 0x0030,0x0000, 48 | 0x0031,0x0402, 49 | 0x0032,0x0106, 50 | 0x0033,0x0700, 51 | 0x0034,0x0104, 52 | 0x0035,0x0301, 53 | 0x0036,0x0707, 54 | 0x0037,0x0305, 55 | 0x0038,0x0208, 56 | 0x0039,0x0F0B, 57 | TFTLCD_DELAY16,50, 58 | //some of this stuff in range 41-93 really throws things off.... 59 | //0x0041,0x0002, 60 | //0x0060,0x2700, //Driver Output Control (R60h) 61 | 0x0060,0xA700, //Driver Output Control (R60h) 62 | 0x0061,0x0001, //Base Image Display Control (R61h) 63 | //0x0090,0x0119, //Panel Interface Control 1 (R90h) DIVI[1:0] RTNI[4:0] 64 | //0x0092,0x010A, //Panel Interface Control 2 (R92h) NOWI[2:0] EQI2[1:0] EQI1[1:0] 65 | //0x0093,0x0004, //Panel Interface Control 3 (R93h) MCPI[2:0] 66 | //0x00A0,0x0100, //Test Register 1 (RA0h) 67 | TFTLCD_DELAY16,50, 68 | 0x0007,0x0133, //Display Control 1 PTDE[1:0] BASEE GON DTE COL D[1:0] 69 | TFTLCD_DELAY16,50, 70 | //0x00A0,0x0000, //Test Register 1 (RA0h) 71 | }; 72 | lcd_write_table16(dev, LGDP4532_regValues, sizeof(LGDP4532_regValues)); 73 | 74 | // lgdp4532 custom function 75 | DrawPixel = ili9325_lcdDrawPixel; 76 | DrawMultiPixels = ili9325_lcdDrawMultiPixels; 77 | DrawFillRect = ili9325_lcdDrawFillRect; 78 | DisplayOff = ili9325_lcdDisplayOff; 79 | DisplayOn = ili9325_lcdDisplayOn; 80 | InversionOff = ili9325_lcdInversionOff; 81 | InversionOn = ili9325_lcdInversionOn; 82 | EnableScroll = ili9325_lcdEnableScroll; 83 | SetScrollArea = ili9325_lcdSetScrollArea; 84 | ResetScrollArea = ili9325_lcdResetScrollArea; 85 | StartScroll = ili9325_lcdStartScroll; 86 | 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /components/sdcard/sdcard.c: -------------------------------------------------------------------------------- 1 | #include "sdcard.h" 2 | 3 | static const char *TAG = "sdcard"; 4 | 5 | void sdcard_init(sdmmc_card_t *card) 6 | { 7 | esp_err_t ret; 8 | 9 | // Options for mounting the filesystem. 10 | // If format_if_mount_failed is set to true, SD card will be partitioned and 11 | // formatted in case when mounting fails. 12 | esp_vfs_fat_sdmmc_mount_config_t mount_config = { 13 | #ifdef CONFIG_FORMAT_IF_MOUNT_FAILED 14 | .format_if_mount_failed = true, 15 | #else 16 | .format_if_mount_failed = false, 17 | #endif // EXAMPLE_FORMAT_IF_MOUNT_FAILED 18 | .max_files = 5, 19 | .allocation_unit_size = 16 * 1024 20 | }; 21 | //sdmmc_card_t *card; 22 | const char mount_point[] = MOUNT_POINT; 23 | ESP_LOGI(TAG, "Initializing SD card"); 24 | 25 | // Use settings defined above to initialize SD card and mount FAT filesystem. 26 | // Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions. 27 | // Please check its source code and implement error recovery when developing 28 | // production applications. 29 | ESP_LOGI(TAG, "Using SPI peripheral"); 30 | 31 | sdmmc_host_t host = SDSPI_HOST_DEFAULT(); 32 | spi_bus_config_t bus_cfg = { 33 | .mosi_io_num = PIN_NUM_MOSI, 34 | .miso_io_num = PIN_NUM_MISO, 35 | .sclk_io_num = PIN_NUM_CLK, 36 | .quadwp_io_num = -1, 37 | .quadhd_io_num = -1, 38 | .max_transfer_sz = 4000, 39 | }; 40 | ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CHAN); 41 | if (ret != ESP_OK) { 42 | ESP_LOGE(TAG, "Failed to initialize bus."); 43 | return; 44 | } 45 | 46 | // This initializes the slot without card detect (CD) and write protect (WP) signals. 47 | // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. 48 | sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT(); 49 | slot_config.gpio_cs = PIN_NUM_CS; 50 | slot_config.host_id = host.slot; 51 | 52 | ESP_LOGI(TAG, "Mounting filesystem"); 53 | ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card); 54 | 55 | if (ret != ESP_OK) { 56 | if (ret == ESP_FAIL) { 57 | ESP_LOGE(TAG, "Failed to mount filesystem. " 58 | "If you want the card to be formatted, set the FORMAT_IF_MOUNT_FAILED menuconfig option."); 59 | } else { 60 | ESP_LOGE(TAG, "Failed to initialize the card (%s). " 61 | "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret)); 62 | } 63 | return; 64 | } 65 | ESP_LOGI(TAG, "Filesystem mounted"); 66 | 67 | // Card has been initialized, print its properties 68 | sdmmc_card_print_info(stdout, card); 69 | 70 | } 71 | 72 | void sdcard_load_config(char* wifi_ssid, char* wifi_password) 73 | { 74 | // First create a file. 75 | const char *file_config = MOUNT_POINT"/config.txt"; 76 | 77 | // Open renamed file for reading 78 | ESP_LOGI(TAG, "Reading file %s", file_config); 79 | FILE *f = fopen(file_config, "r"); 80 | if (f == NULL) { 81 | ESP_LOGE(TAG, "Failed to open file for reading"); 82 | return; 83 | } 84 | fscanf(f, "%[^\n]", wifi_ssid); 85 | fgetc(f); 86 | fscanf(f, "%[^\n]", wifi_password); 87 | 88 | if (wifi_ssid[strlen(wifi_ssid) - 1] == '\r') { 89 | wifi_ssid[strlen(wifi_ssid) - 1] = '\0'; 90 | } 91 | 92 | if (wifi_password[strlen(wifi_password) - 1] == '\r') { 93 | wifi_password[strlen(wifi_password) - 1] = '\0'; 94 | } 95 | 96 | fclose(f); 97 | ESP_LOGI(TAG, "File config read"); 98 | } 99 | 100 | void sdcard_close(sdmmc_card_t *card) 101 | { 102 | 103 | } -------------------------------------------------------------------------------- /components/tft_library/i2s_lcd_driver.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef __I2S_LCD_DRIVER_H__ 15 | #define __I2S_LCD_DRIVER_H__ 16 | 17 | #include "driver/i2s.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" 21 | { 22 | #endif 23 | 24 | #define LCD_CMD_LEV (0) 25 | #define LCD_DATA_LEV (1) 26 | 27 | typedef void * i2s_lcd_handle_t; /** Handle of i2s lcd driver */ 28 | 29 | /** 30 | * @brief Configuration of i2s lcd mode 31 | * 32 | */ 33 | typedef struct { 34 | int8_t data_width; /*!< Parallel data width, 16bit or 8bit available */ 35 | int8_t pin_data_num[16]; /*!< Parallel data output IO*/ 36 | int8_t pin_num_cs; /*!< CS io num */ 37 | int8_t pin_num_wr; /*!< Write clk io*/ 38 | int8_t pin_num_rs; /*!< RS io num */ 39 | int clk_freq; /*!< I2s clock frequency */ 40 | i2s_port_t i2s_port; /*!< I2S port number */ 41 | bool swap_data; /*!< Swap the 2 bytes of RGB565 color */ 42 | uint32_t buffer_size; /*!< DMA buffer size */ 43 | } i2s_lcd_config_t; 44 | 45 | /** 46 | * @brief Initilize i2s lcd driver. 47 | * 48 | * @param config configuration of i2s 49 | * 50 | * @return A handle to the created i2s lcd driver, or NULL in case of error. 51 | */ 52 | i2s_lcd_handle_t i2s_lcd_driver_init(const i2s_lcd_config_t *config); 53 | 54 | /** 55 | * @brief Deinit i2s lcd driver. 56 | * 57 | * @param handle i2s lcd driver handle to deinitilize 58 | * 59 | * @return 60 | * - ESP_OK on success 61 | * - ESP_ERR_INVALID_ARG handle is invalid 62 | */ 63 | esp_err_t i2s_lcd_driver_deinit(i2s_lcd_handle_t handle); 64 | 65 | /** 66 | * @brief Write a data to LCD 67 | * 68 | * @param handle i2s lcd driver handle 69 | * @param data Data to write 70 | * 71 | * @return 72 | * - ESP_OK on success 73 | * - ESP_ERR_INVALID_ARG handle is invalid 74 | */ 75 | esp_err_t i2s_lcd_write_data(i2s_lcd_handle_t handle, uint16_t data); 76 | 77 | /** 78 | * @brief Write a command to LCD 79 | * 80 | * @param handle Handle of i2s lcd driver 81 | * @param cmd command to write 82 | * 83 | * @return 84 | * - ESP_OK on success 85 | * - ESP_ERR_INVALID_ARG handle is invalid 86 | */ 87 | esp_err_t i2s_lcd_write_cmd(i2s_lcd_handle_t handle, uint16_t cmd); 88 | 89 | /** 90 | * @brief Write a command to LCD 91 | * 92 | * @param handle Handle of i2s lcd driver 93 | * @param cmd command to write 94 | * @param length length of command 95 | * 96 | * @return 97 | * - ESP_OK on success 98 | * - ESP_ERR_INVALID_ARG handle is invalid 99 | */ 100 | esp_err_t i2s_lcd_write_command(i2s_lcd_handle_t handle, const uint8_t *cmd, uint32_t length); 101 | 102 | /** 103 | * @brief Write block data to LCD 104 | * 105 | * @param handle Handle of i2s lcd driver 106 | * @param data Pointer of data 107 | * @param length length of data 108 | * 109 | * @return 110 | * - ESP_OK on success 111 | * - ESP_ERR_INVALID_ARG handle is invalid 112 | */ 113 | esp_err_t i2s_lcd_write(i2s_lcd_handle_t handle, const uint8_t *data, uint32_t length); 114 | 115 | /** 116 | * @brief acquire a lock 117 | * 118 | * @param handle Handle of i2s lcd driver 119 | * 120 | * @return Always return ESP_OK 121 | */ 122 | esp_err_t i2s_lcd_acquire(i2s_lcd_handle_t handle); 123 | 124 | /** 125 | * @brief release a lock 126 | * 127 | * @param handle Handle of i2s lcd driver 128 | * 129 | * @return Always return ESP_OK 130 | */ 131 | esp_err_t i2s_lcd_release(i2s_lcd_handle_t handle); 132 | 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /components/tft_library/lcd_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_LIB_H__ 2 | #define __LCD_LIB_H__ 3 | 4 | #include "fontx.h" 5 | 6 | #define RED 0xf800 7 | #define GREEN 0x07e0 8 | #define BLUE 0x001f 9 | #define BLACK 0x0000 10 | #define WHITE 0xffff 11 | #define GRAY 0x8c51 12 | #define YELLOW 0xFFE0 13 | #define CYAN 0x07FF 14 | #define PURPLE 0xF81F 15 | 16 | 17 | #define DIRECTION0 0 18 | #define DIRECTION90 1 19 | #define DIRECTION180 2 20 | #define DIRECTION270 3 21 | 22 | /* 23 | The version of GCC has changed. 24 | In GCC 10.2.1, I get a "multiple definitions" error, but not in GCC 8.3.0. 25 | There was a change in behaviour about global variables between GCC 8.3.0 and GCC 10.2.1. 26 | In C you are supposed to only define a global variable in one translation unit, 27 | other translation unit that want to access the variable should declare it as "extern". 28 | GCC 8.3.0 has a collaborative definition, so no error occurs. 29 | But GCC 10.2.1 don't have cooperative definition, so error occurs. 30 | */ 31 | 32 | #ifndef __TFT_LIB_C__ 33 | #define DECLARE extern 34 | #else 35 | #define DECLARE 36 | #endif 37 | 38 | // Controller-dependent function 39 | DECLARE void (*DrawPixel)(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 40 | DECLARE void (*DrawMultiPixels)(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 41 | DECLARE void (*DrawFillRect)(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 42 | DECLARE void (*DisplayOff)(TFT_t * dev); 43 | DECLARE void (*DisplayOn)(TFT_t * dev); 44 | DECLARE void (*InversionOff)(TFT_t * dev); 45 | DECLARE void (*InversionOn)(TFT_t * dev); 46 | DECLARE bool (*EnableScroll)(TFT_t * dev); 47 | DECLARE void (*SetScrollArea)(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 48 | DECLARE void (*ResetScrollArea)(TFT_t * dev, uint16_t vsa); 49 | DECLARE void (*StartScroll)(TFT_t * dev, uint16_t vsp); 50 | 51 | // Global function 52 | void lcdInitDevice(TFT_t * dev, int width, int height, int offsetx, int offsety); 53 | void lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 54 | void lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 55 | void lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 56 | void lcdDisplayOff(TFT_t * dev); 57 | void lcdDisplayOn(TFT_t * dev); 58 | void lcdInversionOff(TFT_t * dev); 59 | void lcdInversionOn(TFT_t * dev); 60 | bool lcdEnableScroll(TFT_t * dev); 61 | void lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa); 62 | void lcdResetScrollArea(TFT_t * dev, uint16_t vsa); 63 | void lcdStartScroll(TFT_t * dev, uint16_t vsp); 64 | 65 | void lcdFillScreen(TFT_t * dev, uint16_t color); 66 | void lcdDrawLine(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 67 | void lcdDrawRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 68 | void lcdDrawRectAngle(TFT_t * dev, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color); 69 | void lcdDrawTriangle(TFT_t * dev, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color); 70 | void lcdDrawCircle(TFT_t * dev, uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); 71 | void lcdDrawFillCircle(TFT_t * dev, uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); 72 | void lcdDrawRoundRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color); 73 | void lcdDrawArrow(TFT_t * dev, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t w, uint16_t color); 74 | void lcdDrawFillArrow(TFT_t * dev, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t w, uint16_t color); 75 | uint16_t rgb565_conv(uint16_t r, uint16_t g, uint16_t b); 76 | int lcdDrawChar(TFT_t * dev, FontxFile *fx, uint16_t x, uint16_t y, uint8_t ascii, uint16_t color); 77 | int lcdDrawString(TFT_t * dev, FontxFile *fx, uint16_t x, uint16_t y, uint8_t * ascii, uint16_t color); 78 | //int lcdDrawSJISChar(TFT_t * dev, FontxFile *fx, uint16_t x, uint16_t y, uint16_t sjis, uint16_t color); 79 | //int lcdDrawUTF8Char(TFT_t * dev, FontxFile *fx, uint16_t x, uint16_t y, uint8_t *utf8, uint16_t color); 80 | //int lcdDrawUTF8String(TFT_t * dev, FontxFile *fx, uint16_t x, uint16_t y, unsigned char *utfs, uint16_t color); 81 | void lcdSetFontDirection(TFT_t * dev, uint16_t); 82 | void lcdSetFontFill(TFT_t * dev, uint16_t color); 83 | void lcdUnsetFontFill(TFT_t * dev); 84 | void lcdSetFontUnderLine(TFT_t * dev, uint16_t color); 85 | void lcdUnsetFontUnderLine(TFT_t * dev); 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /components/tft_library/r61509.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "r61509.h" 11 | 12 | #define TAG "R61509" 13 | 14 | #if CONFIG_R61509 || CONFIG_ST7793 15 | 16 | void r61509_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | #if CONFIG_R61509 21 | ESP_LOGI(TAG,"Your TFT is R61509"); 22 | #elif CONFIG_ST7793 23 | ESP_LOGI(TAG,"Your TFT is ST7793"); 24 | #endif 25 | ESP_LOGI(TAG,"Screen width:%d",width); 26 | ESP_LOGI(TAG,"Screen height:%d",height); 27 | 28 | static const uint16_t R61509_regValues[] = { 29 | //0x0400, 0x6200, 30 | 0x0008, 0x0808, 31 | 0x0010, 0x0016, //69.5Hz 0016 32 | 0x0011, 0x0101, 33 | 0x0012, 0x0000, 34 | 0x0013, 0x0001, 35 | 0x0100, 0x0330, //BT,AP 36 | 0x0101, 0x0237, //DC0,DC1,VC 37 | 0x0103, 0x0D00, //VDV 38 | 0x0280, 0x6100, //VCM 39 | 0x0102, 0xC1B0, //VRH,VCMR,PSON,PON 40 | TFTLCD_DELAY16,50, 41 | // 0x0001, 0x0100, 42 | 0x0001, 0x0000, 43 | 0x0002, 0x0100, 44 | 0x0003, 0x1030, //1030 45 | 0x0009, 0x0001, 46 | 0x000C, 0x0000, 47 | 0x0090, 0x8000, 48 | 0x000F, 0x0000, 49 | 0x0210, 0x0000, 50 | 0x0211, 0x00EF, 51 | 0x0212, 0x0000, 52 | 0x0213, 0x018F, //432=01AF,400=018F 53 | 0x0500, 0x0000, 54 | 0x0501, 0x0000, 55 | 0x0502, 0x005F, 56 | //0x0400, 0x6200, 57 | 0x0400, 0xE200, 58 | 0x0401, 0x0001, 59 | 0x0404, 0x0000, 60 | TFTLCD_DELAY16,50, 61 | 0x0007, 0x0100, //BASEE 62 | TFTLCD_DELAY16,50, 63 | 0x0200, 0x0000, 64 | 0x0201, 0x0000, 65 | }; 66 | lcd_write_table16(dev, R61509_regValues, sizeof(R61509_regValues)); 67 | 68 | 69 | // r61509 custom function 70 | DrawPixel = r61509_lcdDrawPixel; 71 | DrawMultiPixels = r61509_lcdDrawMultiPixels; 72 | DrawFillRect = r61509_lcdDrawFillRect; 73 | DisplayOff = r61509_lcdDisplayOff; 74 | DisplayOn = r61509_lcdDisplayOn; 75 | InversionOff = r61509_lcdInversionOff; 76 | InversionOn = r61509_lcdInversionOn; 77 | EnableScroll = r61509_lcdEnableScroll; 78 | SetScrollArea = r61509_lcdSetScrollArea; 79 | ResetScrollArea = r61509_lcdResetScrollArea; 80 | StartScroll = r61509_lcdStartScroll; 81 | 82 | } 83 | 84 | 85 | // Draw pixel 86 | // x:X coordinate 87 | // y:Y coordinate 88 | // color:color 89 | void r61509_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color){ 90 | if (x >= dev->_width) return; 91 | if (y >= dev->_height) return; 92 | 93 | uint16_t _x = x + dev->_offsetx; 94 | uint16_t _y = y + dev->_offsety; 95 | 96 | lcd_write_register_word(dev, 0x0200, _x); // RAM Address Set 1 97 | lcd_write_register_word(dev, 0x0201, _y); // RAM Address Set 2 98 | lcd_write_register_word(dev, 0x0202, color); // Write Data to GRAM 99 | } 100 | 101 | // Draw multi pixel 102 | // x:X coordinate 103 | // y:Y coordinate 104 | // size:Number of colors 105 | // colors:colors 106 | void r61509_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors) { 107 | if (x+size > dev->_width) return; 108 | if (y >= dev->_height) return; 109 | 110 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 111 | uint16_t _x1 = x + dev->_offsetx; 112 | //uint16_t _x2 = _x1 + size; 113 | uint16_t _y1 = y + dev->_offsety; 114 | //uint16_t _y2 = _y1; 115 | 116 | lcd_write_register_word(dev, 0x0200, _x1); // RAM Address Set 1 117 | lcd_write_register_word(dev, 0x0201, _y1); // RAM Address Set 2 118 | lcd_write_comm_word(dev, 0x0202); // Write Data to GRAM 119 | lcd_write_colors(dev, colors, size); 120 | } 121 | 122 | 123 | 124 | 125 | // Draw rectangle of filling 126 | // x1:Start X coordinate 127 | // y1:Start Y coordinate 128 | // x2:End X coordinate 129 | // y2:End Y coordinate 130 | // color:color 131 | void r61509_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { 132 | if (x1 >= dev->_width) return; 133 | if (x2 >= dev->_width) x2=dev->_width-1; 134 | if (y1 >= dev->_height) return; 135 | if (y2 >= dev->_height) y2=dev->_height-1; 136 | 137 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 138 | uint16_t _x1 = x1 + dev->_offsetx; 139 | //uint16_t _x2 = x2 + dev->_offsetx; 140 | uint16_t _y1 = y1 + dev->_offsety; 141 | uint16_t _y2 = y2 + dev->_offsety; 142 | uint16_t _size = x2 - x1 + 1; 143 | 144 | for(uint16_t _y=_y1;_y<=_y2;_y++){ 145 | lcd_write_register_word(dev, 0x0200, _x1); // RAM Address Set 1 146 | lcd_write_register_word(dev, 0x0201, _y); // RAM Address Set 2 147 | lcd_write_comm_word(dev, 0x0202); // Write Data to GRAM 148 | lcd_write_color(dev, color, _size); 149 | } 150 | } 151 | 152 | // Display OFF 153 | void r61509_lcdDisplayOff(TFT_t * dev) { 154 | lcd_write_register_word(dev, 0x0007, 0x0000); // Display Control 1 155 | //lcd_write_register_word(dev, 0x0007, 0x0000); // Set GON=0 DTE=0 D1=0, D0=0 156 | } 157 | 158 | // Display ON 159 | void r61509_lcdDisplayOn(TFT_t * dev) { 160 | lcd_write_register_word(dev, 0x0007, 0x0100); // Display Control 1 161 | //lcd_write_register_word(dev, 0x0007, 0x0173); // Set GON=1 DTE=1 D1=1, D0=1 162 | } 163 | 164 | // Display Inversion OFF 165 | void r61509_lcdInversionOff(TFT_t * dev) { 166 | } 167 | 168 | // Display Inversion ON 169 | void r61509_lcdInversionOn(TFT_t * dev) { 170 | } 171 | 172 | // Enable Vertical Scrolling 173 | bool r61509_lcdEnableScroll(TFT_t * dev){ 174 | return false; 175 | } 176 | 177 | 178 | // Vertical Scrolling Definition 179 | // tfa:Top Fixed Area 180 | // vsa:Vertical Scrolling Area 181 | // bfa:Bottom Fixed Area 182 | void r61509_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa){ 183 | } 184 | 185 | void r61509_lcdResetScrollArea(TFT_t * dev, uint16_t vsa){ 186 | } 187 | 188 | // Vertical Scrolling Start Address 189 | // vsp:Vertical Scrolling Start Address 190 | void r61509_lcdStartScroll(TFT_t * dev, uint16_t vsp){ 191 | } 192 | 193 | #endif 194 | -------------------------------------------------------------------------------- /components/tft_library/ili9341.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #include "lcd_com.h" 7 | #include "lcd_lib.h" 8 | #include "ili9341.h" 9 | 10 | #define TAG "ILI9341" 11 | 12 | #if CONFIG_ILI9340 || CONFIG_ILI9341 13 | 14 | void ili9341_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 15 | { 16 | lcdInitDevice(dev, width, height, offsetx, offsety); 17 | 18 | #if CONFIG_ILI9340 19 | ESP_LOGI(TAG,"Your TFT is ILI9340"); 20 | #elif CONFIG_ILI9341 21 | ESP_LOGI(TAG,"Your TFT is ILI9341"); 22 | #endif 23 | ESP_LOGI(TAG,"Screen width:%d",width); 24 | ESP_LOGI(TAG,"Screen height:%d",height); 25 | 26 | // Initailize TFT 27 | static const uint8_t reset_off[] = { 28 | 0x01, 0, //Soft Reset 29 | TFTLCD_DELAY8, 150, 30 | 0x28, 0, //Display Off 31 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 32 | }; 33 | 34 | static const uint8_t wake_on[] = { 35 | 0x11, 0, //Sleep Out 36 | TFTLCD_DELAY8, 150, 37 | 0x29, 0, //Display On 38 | }; 39 | 40 | static const uint8_t regValues[] = { 41 | 0xC0, 1, 0x23, 42 | 0xC1, 1, 0x10, 43 | 0xC5, 2, 0x3E, 0x28, 44 | 0xC7, 1, 0x86, 45 | 0x36, 1, 0xC8, 46 | 0xB1, 2, 0x00, 0x18, 47 | 0xB6, 4, 0x0A, 0xA2, 0x27, 0x04, 48 | 0x26, 1, 0x01, 49 | 0xE0,15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, 50 | 0xE1,15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, 51 | }; 52 | lcd_write_table(dev, reset_off, sizeof(reset_off)); 53 | lcd_write_table(dev, regValues, sizeof(regValues)); 54 | lcd_write_table(dev, wake_on, sizeof(wake_on)); 55 | 56 | // ili9341 custom function 57 | DrawPixel = ili9341_lcdDrawPixel; 58 | DrawMultiPixels = ili9341_lcdDrawMultiPixels; 59 | DrawFillRect = ili9341_lcdDrawFillRect; 60 | DisplayOff = ili9341_lcdDisplayOff; 61 | DisplayOn = ili9341_lcdDisplayOn; 62 | InversionOff = ili9341_lcdInversionOff; 63 | InversionOn = ili9341_lcdInversionOn; 64 | EnableScroll = ili9341_lcdEnableScroll; 65 | SetScrollArea = ili9341_lcdSetScrollArea; 66 | ResetScrollArea = ili9341_lcdResetScrollArea; 67 | StartScroll = ili9341_lcdStartScroll; 68 | 69 | } 70 | #endif 71 | 72 | #if CONFIG_ILI9327 || CONFIG_ILI9340 || CONFIG_ILI9341 || CONFIG_ILI9342 || CONFIG_ILI9481 || CONFIG_ILI9486 || CONFIG_ST7796 || CONFIG_ILI9488 73 | 74 | // Draw pixel 75 | // x:X coordinate 76 | // y:Y coordinate 77 | // color:color 78 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color){ 79 | if (x >= dev->_width) return; 80 | if (y >= dev->_height) return; 81 | 82 | uint16_t _x = x + dev->_offsetx; 83 | uint16_t _y = y + dev->_offsety; 84 | 85 | lcd_write_comm_byte(dev, 0x2A); // set column(x) address 86 | lcd_write_addr(dev, _x, _x); 87 | lcd_write_comm_byte(dev, 0x2B); // set Page(y) address 88 | lcd_write_addr(dev, _y, _y); 89 | lcd_write_comm_byte(dev, 0x2C); // Memory Write 90 | lcd_write_data_word(dev, color); 91 | } 92 | 93 | // Draw multi pixel 94 | // x:X coordinate 95 | // y:Y coordinate 96 | // size:Number of colors 97 | // colors:colors 98 | void ili9341_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors) { 99 | if (x+size > dev->_width) return; 100 | if (y >= dev->_height) return; 101 | 102 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 103 | uint16_t _x1 = x + dev->_offsetx; 104 | uint16_t _x2 = _x1 + size; 105 | uint16_t _y1 = y + dev->_offsety; 106 | uint16_t _y2 = _y1; 107 | ESP_LOGD(TAG,"_x1=%d _x2=%d _y1=%d _y2=%d",_x1, _x2, _y1, _y2); 108 | 109 | lcd_write_comm_byte(dev, 0x2A); // set column(x) address 110 | lcd_write_addr(dev, _x1, _x2); 111 | lcd_write_comm_byte(dev, 0x2B); // set Page(y) address 112 | lcd_write_addr(dev, _y1, _y2); 113 | lcd_write_comm_byte(dev, 0x2C); // Memory Write 114 | lcd_write_colors(dev, colors, size); 115 | } 116 | 117 | 118 | 119 | 120 | // Draw rectangle of filling 121 | // x1:Start X coordinate 122 | // y1:Start Y coordinate 123 | // x2:End X coordinate 124 | // y2:End Y coordinate 125 | // color:color 126 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { 127 | if (x1 >= dev->_width) return; 128 | if (x2 >= dev->_width) x2=dev->_width-1; 129 | if (y1 >= dev->_height) return; 130 | if (y2 >= dev->_height) y2=dev->_height-1; 131 | 132 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 133 | uint16_t _x1 = x1 + dev->_offsetx; 134 | uint16_t _x2 = x2 + dev->_offsetx; 135 | uint16_t _y1 = y1 + dev->_offsety; 136 | uint16_t _y2 = y2 + dev->_offsety; 137 | 138 | lcd_write_comm_byte(dev, 0x2A); // set column(x) address 139 | lcd_write_addr(dev, _x1, _x2); 140 | lcd_write_comm_byte(dev, 0x2B); // set Page(y) address 141 | lcd_write_addr(dev, _y1, _y2); 142 | lcd_write_comm_byte(dev, 0x2C); // Memory Write 143 | for(int i=_x1;i<=_x2;i++) { 144 | uint16_t size = _y2-_y1+1; 145 | lcd_write_color(dev, color, size); 146 | } 147 | } 148 | 149 | // Display OFF 150 | void ili9341_lcdDisplayOff(TFT_t * dev) { 151 | lcd_write_comm_byte(dev, 0x28); 152 | } 153 | 154 | // Display ON 155 | void ili9341_lcdDisplayOn(TFT_t * dev) { 156 | lcd_write_comm_byte(dev, 0x29); 157 | } 158 | 159 | // Display Inversion OFF 160 | void ili9341_lcdInversionOff(TFT_t * dev) { 161 | lcd_write_comm_byte(dev, 0x20); 162 | } 163 | 164 | // Display Inversion ON 165 | void ili9341_lcdInversionOn(TFT_t * dev) { 166 | lcd_write_comm_byte(dev, 0x21); 167 | } 168 | 169 | // Enable Vertical Scrolling 170 | bool ili9341_lcdEnableScroll(TFT_t * dev){ 171 | return true; 172 | } 173 | 174 | 175 | // Vertical Scrolling Definition 176 | // tfa:Top Fixed Area 177 | // vsa:Vertical Scrolling Area 178 | // bfa:Bottom Fixed Area 179 | void ili9341_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa){ 180 | lcd_write_comm_byte(dev, 0x33); // Vertical Scrolling Definition 181 | lcd_write_data_word(dev, tfa); 182 | lcd_write_data_word(dev, vsa); 183 | lcd_write_data_word(dev, bfa); 184 | //lcd_write_comm_byte(dev, 0x12); // Partial Mode ON 185 | } 186 | 187 | void ili9341_lcdResetScrollArea(TFT_t * dev, uint16_t vsa){ 188 | lcd_write_comm_byte(dev, 0x33); // Vertical Scrolling Definition 189 | lcd_write_data_word(dev, 0); 190 | //lcd_write_data_word(dev, 0x140); 191 | lcd_write_data_word(dev, vsa); 192 | lcd_write_data_word(dev, 0); 193 | } 194 | 195 | // Vertical Scrolling Start Address 196 | // vsp:Vertical Scrolling Start Address 197 | void ili9341_lcdStartScroll(TFT_t * dev, uint16_t vsp){ 198 | lcd_write_comm_byte(dev, 0x37); // Vertical Scrolling Start Address 199 | lcd_write_data_word(dev, vsp); 200 | } 201 | #endif 202 | -------------------------------------------------------------------------------- /components/tft_library/ili9225.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9225.h" 11 | 12 | #define TAG "ILI9225" 13 | 14 | #if CONFIG_ILI9225 || CONFIG_ILI9226 || CONFIG_ST7775 15 | 16 | void ili9225_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | #if CONFIG_ILI9225 21 | ESP_LOGI(TAG,"Your TFT is ILI9225"); 22 | #elif CONFIG_ILI9226 23 | ESP_LOGI(TAG,"Your TFT is ILI9226"); 24 | #elif CONFIG_ST7775 25 | ESP_LOGI(TAG,"Your TFT is ST7775"); 26 | #endif 27 | ESP_LOGI(TAG,"Screen width:%d",width); 28 | ESP_LOGI(TAG,"Screen height:%d",height); 29 | 30 | static const uint16_t ILI9225_regValues[] = { 31 | /* Set SS bit and direction output from S528 to S1 */ 32 | 0x10, 0x0000, // Set SAP,DSTB,STB 33 | 0x11, 0x0000, // Set APON,PON,AON,VCI1EN,VC 34 | 0x12, 0x0000, // Set BT,DC1,DC2,DC3 35 | 0x13, 0x0000, // Set GVDD 36 | 0x14, 0x0000, // Set VCOMH/VCOML voltage 37 | TFTLCD_DELAY16, 40, 38 | 39 | // Power-on sequence 40 | 0x11, 0x0018, // Set APON,PON,AON,VCI1EN,VC 41 | 0x12, 0x6121, // Set BT,DC1,DC2,DC3 42 | 0x13, 0x006F, // Set GVDD /*007F 0088 */ 43 | 0x14, 0x495F, // Set VCOMH/VCOML voltage 44 | 0x10, 0x0800, // Set SAP,DSTB,STB 45 | TFTLCD_DELAY16, 10, 46 | 0x11, 0x103B, // Set APON,PON,AON,VCI1EN,VC 47 | TFTLCD_DELAY16, 50, 48 | 49 | //0x01, 0x011C, // set the display line number and display direction 50 | 0x01, 0x021C, // set the display line number and display direction 51 | 0x02, 0x0100, // set 1 line inversion 52 | 0x03, 0x1030, // set GRAM write direction and BGR=1. 53 | 0x07, 0x0000, // Display off 54 | 0x08, 0x0808, // set the back porch and front porch 55 | 0x0B, 0x1100, // set the clocks number per line 56 | 0x0C, 0x0000, // CPU interface 57 | 0x0F, 0x0D01, // Set Osc /*0e01*/ 58 | 0x15, 0x0020, // Set VCI recycling 59 | 0x20, 0x0000, // Horizontal GRAM Address Set 60 | 0x21, 0x0000, // Vertical GRAM Address Set 61 | 62 | /* Set GRAM area */ 63 | 0x30, 0x0000, 64 | 0x31, 0x00DB, 65 | 0x32, 0x0000, 66 | 0x33, 0x0000, 67 | 0x34, 0x00DB, 68 | 0x35, 0x0000, 69 | 0x36, 0x00AF, 70 | 0x37, 0x0000, 71 | 0x38, 0x00DB, 72 | 0x39, 0x0000, 73 | 74 | /* Set GAMMA curve */ 75 | 0x50, 0x0000, 76 | 0x51, 0x0808, 77 | 0x52, 0x080A, 78 | 0x53, 0x000A, 79 | 0x54, 0x0A08, 80 | 0x55, 0x0808, 81 | 0x56, 0x0000, 82 | 0x57, 0x0A00, 83 | 0x58, 0x0710, 84 | 0x59, 0x0710, 85 | 86 | 0x07, 0x0012, 87 | TFTLCD_DELAY16, 50, 88 | 0x07, 0x1017, 89 | }; 90 | lcd_write_table16(dev, ILI9225_regValues, sizeof(ILI9225_regValues)); 91 | 92 | // ili9225 custom function 93 | DrawPixel = ili9225_lcdDrawPixel; 94 | DrawMultiPixels = ili9225_lcdDrawMultiPixels; 95 | DrawFillRect = ili9225_lcdDrawFillRect; 96 | DisplayOff = ili9225_lcdDisplayOff; 97 | DisplayOn = ili9225_lcdDisplayOn; 98 | InversionOff = ili9225_lcdInversionOff; 99 | InversionOn = ili9225_lcdInversionOn; 100 | EnableScroll = ili9225_lcdEnableScroll; 101 | SetScrollArea = ili9225_lcdSetScrollArea; 102 | ResetScrollArea = ili9225_lcdResetScrollArea; 103 | StartScroll = ili9225_lcdStartScroll; 104 | 105 | } 106 | 107 | // Draw pixel 108 | // x:X coordinate 109 | // y:Y coordinate 110 | // color:color 111 | void ili9225_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color){ 112 | if (x >= dev->_width) return; 113 | if (y >= dev->_height) return; 114 | 115 | uint16_t _x = x + dev->_offsetx; 116 | uint16_t _y = y + dev->_offsety; 117 | 118 | lcd_write_register_word(dev, 0x0020, _x); // RAM Address Set 1 119 | lcd_write_register_word(dev, 0x0021, _y); // RAM Address Set 2 120 | lcd_write_register_word(dev, 0x0022, color); // Write Data to GRAM 121 | } 122 | 123 | // Draw multi pixel 124 | // x:X coordinate 125 | // y:Y coordinate 126 | // size:Number of colors 127 | // colors:colors 128 | void ili9225_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors) { 129 | if (x+size > dev->_width) return; 130 | if (y >= dev->_height) return; 131 | 132 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 133 | uint16_t _x1 = x + dev->_offsetx; 134 | //uint16_t _x2 = _x1 + size; 135 | uint16_t _y1 = y + dev->_offsety; 136 | //uint16_t _y2 = _y1; 137 | 138 | lcd_write_register_word(dev, 0x0020, _x1); // RAM Address Set 1 139 | lcd_write_register_word(dev, 0x0021, _y1); // RAM Address Set 2 140 | lcd_write_comm_word(dev, 0x0022); // Write Data to GRAM 141 | lcd_write_colors(dev, colors, size); 142 | } 143 | 144 | 145 | 146 | 147 | // Draw rectangle of filling 148 | // x1:Start X coordinate 149 | // y1:Start Y coordinate 150 | // x2:End X coordinate 151 | // y2:End Y coordinate 152 | // color:color 153 | void ili9225_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { 154 | if (x1 >= dev->_width) return; 155 | if (x2 >= dev->_width) x2=dev->_width-1; 156 | if (y1 >= dev->_height) return; 157 | if (y2 >= dev->_height) y2=dev->_height-1; 158 | 159 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 160 | uint16_t _x1 = x1 + dev->_offsetx; 161 | //uint16_t _x2 = x2 + dev->_offsetx; 162 | uint16_t _y1 = y1 + dev->_offsety; 163 | uint16_t _y2 = y2 + dev->_offsety; 164 | uint16_t _size = x2 - x1 + 1; 165 | 166 | for(uint16_t _y=_y1;_y<=_y2;_y++){ 167 | lcd_write_register_word(dev, 0x0020, _x1); // RAM Address Set 1 168 | lcd_write_register_word(dev, 0x0021, _y); // RAM Address Set 2 169 | lcd_write_comm_word(dev, 0x0022); // Write Data to GRAM 170 | lcd_write_color(dev, color, _size); 171 | } 172 | } 173 | 174 | // Display OFF 175 | void ili9225_lcdDisplayOff(TFT_t * dev) { 176 | lcd_write_register_word(dev, 0x0007, 0x0000); // Set GON=0 DTE=0 D1=0, D0=0 177 | } 178 | 179 | // Display ON 180 | void ili9225_lcdDisplayOn(TFT_t * dev) { 181 | lcd_write_register_word(dev, 0x0007, 0x1017); // Set GON=1 DTE=1 D1=1, D0=1 182 | } 183 | 184 | // Display Inversion OFF 185 | void ili9225_lcdInversionOff(TFT_t * dev) { 186 | lcd_write_register_word(dev, 0x0007, 0x0013); 187 | } 188 | 189 | // Display Inversion ON 190 | void ili9225_lcdInversionOn(TFT_t * dev) { 191 | lcd_write_register_word(dev, 0x0007, 0x0017); 192 | } 193 | 194 | // Enable Vertical Scrolling 195 | bool ili9225_lcdEnableScroll(TFT_t * dev){ 196 | return false; 197 | } 198 | 199 | 200 | // Vertical Scrolling Definition 201 | // tfa:Top Fixed Area 202 | // vsa:Vertical Scrolling Area 203 | // bfa:Bottom Fixed Area 204 | void ili9225_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa){ 205 | } 206 | 207 | void ili9225_lcdResetScrollArea(TFT_t * dev, uint16_t vsa){ 208 | } 209 | 210 | // Vertical Scrolling Start Address 211 | // vsp:Vertical Scrolling Start Address 212 | void ili9225_lcdStartScroll(TFT_t * dev, uint16_t vsp){ 213 | } 214 | 215 | #endif 216 | -------------------------------------------------------------------------------- /components/tft_library/ili9325.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #include "lcd_com.h" 9 | #include "lcd_lib.h" 10 | #include "ili9325.h" 11 | 12 | #define TAG "ILI9325" 13 | 14 | #if CONFIG_ILI9325 15 | 16 | void ili9325_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | ESP_LOGI(TAG,"Your TFT is ILI9325"); 21 | ESP_LOGI(TAG,"Screen width:%d",width); 22 | ESP_LOGI(TAG,"Screen height:%d",height); 23 | 24 | static const uint16_t ILI9325_regValues[] = { 25 | 0x00E5, 0x78F0, // set SRAM internal timing 26 | 0x0001, 0x0100, // set Driver Output Control 27 | 0x0002, 0x0200, // set 1 line inversion 28 | 0x0003, 0x1030, // set GRAM write direction and BGR=1. 29 | 0x0004, 0x0000, // Resize register 30 | 0x0005, 0x0000, // .kbv 16bits Data Format Selection 31 | 0x0008, 0x0207, // set the back porch and front porch 32 | 0x0009, 0x0000, // set non-display area refresh cycle ISC[3:0] 33 | 0x000A, 0x0000, // FMARK function 34 | 0x000C, 0x0000, // RGB interface setting 35 | 0x000D, 0x0000, // Frame marker Position 36 | 0x000F, 0x0000, // RGB interface polarity 37 | // ----------- Power On sequence ----------- // 38 | 0x0010, 0x0000, // SAP, BT[3:0], AP, DSTB, SLP, STB 39 | 0x0011, 0x0007, // DC1[2:0], DC0[2:0], VC[2:0] 40 | 0x0012, 0x0000, // VREG1OUT voltage 41 | 0x0013, 0x0000, // VDV[4:0] for VCOM amplitude 42 | 0x0007, 0x0001, 43 | TFTLCD_DELAY, 200, // Dis-charge capacitor power voltage 44 | 0x0010, 0x1690, // SAP=1, BT=6, APE=1, AP=1, DSTB=0, SLP=0, STB=0 45 | 0x0011, 0x0227, // DC1=2, DC0=2, VC=7 46 | TFTLCD_DELAY, 50, // wait_ms 50ms 47 | 0x0012, 0x000D, // VCIRE=1, PON=0, VRH=5 48 | TFTLCD_DELAY, 50, // wait_ms 50ms 49 | 0x0013, 0x1200, // VDV=28 for VCOM amplitude 50 | 0x0029, 0x000A, // VCM=10 for VCOMH 51 | 0x002B, 0x000D, // Set Frame Rate 52 | TFTLCD_DELAY, 50, // wait_ms 50ms 53 | 0x0020, 0x0000, // GRAM horizontal Address 54 | 0x0021, 0x0000, // GRAM Vertical Address 55 | // ----------- Adjust the Gamma Curve ----------// 56 | 57 | 0x0030, 0x0000, 58 | 0x0031, 0x0404, 59 | 0x0032, 0x0003, 60 | 0x0035, 0x0405, 61 | 0x0036, 0x0808, 62 | 0x0037, 0x0407, 63 | 0x0038, 0x0303, 64 | 0x0039, 0x0707, 65 | 0x003C, 0x0504, 66 | 0x003D, 0x0808, 67 | 68 | //------------------ Set GRAM area ---------------// 69 | //0x0060, 0x2700, // Gate Scan Line GS=0 [0xA700] 70 | 0x0060, 0xA700, // Gate Scan Line GS=0 [0xA700] 71 | 0x0061, 0x0001, // NDL,VLE, REV .kbv 72 | 0x006A, 0x0000, // set scrolling line 73 | //-------------- Partial Display Control ---------// 74 | 0x0080, 0x0000, 75 | 0x0081, 0x0000, 76 | 0x0082, 0x0000, 77 | 0x0083, 0x0000, 78 | 0x0084, 0x0000, 79 | 0x0085, 0x0000, 80 | //-------------- Panel Control -------------------// 81 | 0x0090, 0x0010, 82 | 0x0092, 0x0000, 83 | 0x0007, 0x0133, // 262K color and display ON 84 | }; 85 | lcd_write_table16(dev, ILI9325_regValues, sizeof(ILI9325_regValues)); 86 | 87 | // ili9325 custom function 88 | DrawPixel = ili9325_lcdDrawPixel; 89 | DrawMultiPixels = ili9325_lcdDrawMultiPixels; 90 | DrawFillRect = ili9325_lcdDrawFillRect; 91 | DisplayOff = ili9325_lcdDisplayOff; 92 | DisplayOn = ili9325_lcdDisplayOn; 93 | InversionOff = ili9325_lcdInversionOff; 94 | InversionOn = ili9325_lcdInversionOn; 95 | EnableScroll = ili9325_lcdEnableScroll; 96 | SetScrollArea = ili9325_lcdSetScrollArea; 97 | ResetScrollArea = ili9325_lcdResetScrollArea; 98 | StartScroll = ili9325_lcdStartScroll; 99 | 100 | } 101 | #endif 102 | 103 | #if CONFIG_ILI9320 || CONFIG_ILI9325 || CONFIG_SPFD5408 || CONFIG_R61505 || CONFIG_LGDP4532 || CONFIG_ST7781 || CONFIG_ST7783 104 | 105 | // Draw pixel 106 | // x:X coordinate 107 | // y:Y coordinate 108 | // color:color 109 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color){ 110 | if (x >= dev->_width) return; 111 | if (y >= dev->_height) return; 112 | 113 | uint16_t _x = x + dev->_offsetx; 114 | uint16_t _y = y + dev->_offsety; 115 | 116 | lcd_write_register_word(dev, 0x0020, _x); // RAM Address Set 1 117 | lcd_write_register_word(dev, 0x0021, _y); // RAM Address Set 2 118 | lcd_write_register_word(dev, 0x0022, color); // Write Data to GRAM 119 | } 120 | 121 | // Draw multi pixel 122 | // x:X coordinate 123 | // y:Y coordinate 124 | // size:Number of colors 125 | // colors:colors 126 | void ili9325_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors) { 127 | if (x+size > dev->_width) return; 128 | if (y >= dev->_height) return; 129 | 130 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 131 | uint16_t _x1 = x + dev->_offsetx; 132 | //uint16_t _x2 = _x1 + size; 133 | uint16_t _y1 = y + dev->_offsety; 134 | //uint16_t _y2 = _y1; 135 | 136 | lcd_write_register_word(dev, 0x0020, _x1); // RAM Address Set 1 137 | lcd_write_register_word(dev, 0x0021, _y1); // RAM Address Set 2 138 | lcd_write_comm_word(dev, 0x0022); // Write Data to GRAM 139 | lcd_write_colors(dev, colors, size); 140 | } 141 | 142 | 143 | 144 | 145 | // Draw rectangle of filling 146 | // x1:Start X coordinate 147 | // y1:Start Y coordinate 148 | // x2:End X coordinate 149 | // y2:End Y coordinate 150 | // color:color 151 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { 152 | if (x1 >= dev->_width) return; 153 | if (x2 >= dev->_width) x2=dev->_width-1; 154 | if (y1 >= dev->_height) return; 155 | if (y2 >= dev->_height) y2=dev->_height-1; 156 | 157 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 158 | uint16_t _x1 = x1 + dev->_offsetx; 159 | //uint16_t _x2 = x2 + dev->_offsetx; 160 | uint16_t _y1 = y1 + dev->_offsety; 161 | uint16_t _y2 = y2 + dev->_offsety; 162 | uint16_t _size = x2 - x1 + 1; 163 | 164 | for(uint16_t _y=_y1;_y<=_y2;_y++){ 165 | lcd_write_register_word(dev, 0x0020, _x1); // RAM Address Set 1 166 | lcd_write_register_word(dev, 0x0021, _y); // RAM Address Set 2 167 | lcd_write_comm_word(dev, 0x0022); // Write Data to GRAM 168 | lcd_write_color(dev, color, _size); 169 | } 170 | } 171 | 172 | // Display OFF 173 | void ili9325_lcdDisplayOff(TFT_t * dev) { 174 | lcd_write_register_word(dev, 0x0007, 0x0000); // Set GON=0 DTE=0 D1=0, D0=0 175 | } 176 | 177 | // Display ON 178 | void ili9325_lcdDisplayOn(TFT_t * dev) { 179 | lcd_write_register_word(dev, 0x0007, 0x0173); // Set GON=1 DTE=1 D1=1, D0=1 180 | } 181 | 182 | // Display Inversion OFF 183 | void ili9325_lcdInversionOff(TFT_t * dev) { 184 | lcd_write_register_word(dev, 0x0061, 0x0001); 185 | } 186 | 187 | // Display Inversion ON 188 | void ili9325_lcdInversionOn(TFT_t * dev) { 189 | lcd_write_register_word(dev, 0x0061, 0x0000); 190 | } 191 | 192 | // Enable Vertical Scrolling 193 | bool ili9325_lcdEnableScroll(TFT_t * dev){ 194 | return false; 195 | } 196 | 197 | 198 | // Vertical Scrolling Definition 199 | // tfa:Top Fixed Area 200 | // vsa:Vertical Scrolling Area 201 | // bfa:Bottom Fixed Area 202 | void ili9325_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa){ 203 | } 204 | 205 | void ili9325_lcdResetScrollArea(TFT_t * dev, uint16_t vsa){ 206 | } 207 | 208 | // Vertical Scrolling Start Address 209 | // vsp:Vertical Scrolling Start Address 210 | void ili9325_lcdStartScroll(TFT_t * dev, uint16_t vsp){ 211 | } 212 | 213 | #endif 214 | -------------------------------------------------------------------------------- /components/http_client/http_client.c: -------------------------------------------------------------------------------- 1 | #include "http_client.h" 2 | 3 | static const char *TAG = "Http client"; 4 | 5 | esp_err_t _http_event_handler(esp_http_client_event_t *evt) 6 | { 7 | static char *output_buffer; // Buffer to store response of http request from event handler 8 | static int output_len; // Stores number of bytes read 9 | switch(evt->event_id) { 10 | case HTTP_EVENT_ERROR: 11 | ESP_LOGD(TAG, "HTTP_EVENT_ERROR"); 12 | break; 13 | case HTTP_EVENT_ON_CONNECTED: 14 | ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED"); 15 | break; 16 | case HTTP_EVENT_HEADER_SENT: 17 | ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT"); 18 | break; 19 | case HTTP_EVENT_ON_HEADER: 20 | ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value); 21 | break; 22 | case HTTP_EVENT_ON_DATA: 23 | ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len); 24 | /* 25 | * Check for chunked encoding is added as the URL for chunked encoding used in this example returns binary data. 26 | * However, event handler can also be used in case chunked encoding is used. 27 | */ 28 | if (!esp_http_client_is_chunked_response(evt->client)) { 29 | // If user_data buffer is configured, copy the response into the buffer 30 | if (evt->user_data) { 31 | memcpy(evt->user_data + output_len, evt->data, evt->data_len); 32 | } else { 33 | if (output_buffer == NULL) { 34 | output_buffer = (char *) malloc(esp_http_client_get_content_length(evt->client)); 35 | output_len = 0; 36 | if (output_buffer == NULL) { 37 | ESP_LOGE(TAG, "Failed to allocate memory for output buffer"); 38 | return ESP_FAIL; 39 | } 40 | } 41 | memcpy(output_buffer + output_len, evt->data, evt->data_len); 42 | } 43 | output_len += evt->data_len; 44 | } 45 | 46 | break; 47 | case HTTP_EVENT_ON_FINISH: 48 | ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH"); 49 | if (output_buffer != NULL) { 50 | free(output_buffer); 51 | output_buffer = NULL; 52 | } 53 | output_len = 0; 54 | break; 55 | case HTTP_EVENT_DISCONNECTED: 56 | ESP_LOGI(TAG, "HTTP_EVENT_DISCONNECTED"); 57 | int mbedtls_err = 0; 58 | esp_err_t err = esp_tls_get_and_clear_last_error(evt->data, &mbedtls_err, NULL); 59 | if (err != 0) { 60 | ESP_LOGI(TAG, "Last esp error code: 0x%x", err); 61 | ESP_LOGI(TAG, "Last mbedtls failure: 0x%x", mbedtls_err); 62 | } 63 | if (output_buffer != NULL) { 64 | free(output_buffer); 65 | output_buffer = NULL; 66 | } 67 | output_len = 0; 68 | break; 69 | } 70 | return ESP_OK; 71 | } 72 | 73 | void http_get_qrcode(char *buffer, uint32_t order_id) 74 | { 75 | char query[30]; 76 | sprintf(query, "id=%d", order_id); 77 | 78 | esp_http_client_config_t config = { 79 | .host = CONFIG_PIX_GATEWAY_HOST, 80 | #if CONFIG_HOST_USE_HTTPS 81 | .transport_type = HTTP_TRANSPORT_OVER_SSL, 82 | #endif 83 | .path = "/pix-gateway/v1/qrcode/", 84 | .query = query, 85 | .event_handler = _http_event_handler, 86 | .timeout_ms = 9000 87 | }; 88 | 89 | esp_http_client_handle_t client = esp_http_client_init(&config); 90 | 91 | esp_http_client_set_method(client, HTTP_METHOD_GET); 92 | esp_err_t err = esp_http_client_open(client, 0); 93 | 94 | if (err == ESP_OK) { 95 | int content_len = esp_http_client_fetch_headers(client); 96 | ESP_LOGI(TAG, "content_length = %d", content_len); 97 | int data_len = esp_http_client_read_response(client, buffer, content_len); 98 | ESP_LOGI(TAG, "Read length = %d", data_len); 99 | buffer[content_len] = 0; 100 | ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d", 101 | esp_http_client_get_status_code(client), 102 | esp_http_client_get_content_length(client)); 103 | } else { 104 | ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err)); 105 | } 106 | 107 | esp_http_client_cleanup(client); 108 | } 109 | 110 | void http_get_qrcode_test(char *buffer) 111 | { 112 | esp_http_client_config_t config = { 113 | .host = CONFIG_PIX_GATEWAY_HOST, 114 | #if CONFIG_HOST_USE_HTTPS 115 | .transport_type = HTTP_TRANSPORT_OVER_SSL, 116 | #endif 117 | .path = "/pix-gateway/v1/teste", 118 | .event_handler = _http_event_handler, 119 | .timeout_ms = 5000 120 | }; 121 | 122 | esp_http_client_handle_t client = esp_http_client_init(&config); 123 | 124 | esp_http_client_set_method(client, HTTP_METHOD_GET); 125 | esp_err_t err = esp_http_client_open(client, 0); 126 | 127 | if (err == ESP_OK) { 128 | int content_len = esp_http_client_fetch_headers(client); 129 | ESP_LOGI(TAG, "content_length = %d", content_len); 130 | int data_len = esp_http_client_read_response(client, buffer, content_len); 131 | ESP_LOGI(TAG, "Read length = %d", data_len); 132 | buffer[content_len] = 0; 133 | ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d", 134 | esp_http_client_get_status_code(client), 135 | esp_http_client_get_content_length(client)); 136 | } else { 137 | ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err)); 138 | } 139 | 140 | esp_http_client_cleanup(client); 141 | } 142 | 143 | uint8_t http_get_order_status(uint32_t order_id) 144 | { 145 | char path[85]; 146 | sprintf(path, "/pix-gateway/v1/orders/%d/status", order_id); 147 | 148 | esp_http_client_config_t config = { 149 | .host = CONFIG_PIX_GATEWAY_HOST, 150 | #if CONFIG_HOST_USE_HTTPS 151 | .transport_type = HTTP_TRANSPORT_OVER_SSL, 152 | #endif 153 | .path = path, 154 | .event_handler = _http_event_handler, 155 | .timeout_ms = 9000 156 | }; 157 | 158 | esp_http_client_handle_t client = esp_http_client_init(&config); 159 | 160 | esp_http_client_set_method(client, HTTP_METHOD_GET); 161 | esp_err_t err = esp_http_client_open(client, 0); 162 | 163 | char buffer[2]; 164 | 165 | if (err == ESP_OK) { 166 | int content_len = esp_http_client_fetch_headers(client); 167 | ESP_LOGI(TAG, "content_length = %d", content_len); 168 | if (content_len <= 2) { 169 | int data_len = esp_http_client_read_response(client, buffer, content_len); 170 | ESP_LOGI(TAG, "Read length = %d", data_len); 171 | buffer[content_len] = 0; 172 | } else { 173 | ESP_LOGE(TAG, "Content Length bigger than expected"); 174 | } 175 | ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d", 176 | esp_http_client_get_status_code(client), 177 | esp_http_client_get_content_length(client)); 178 | } else { 179 | ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err)); 180 | } 181 | 182 | if (esp_http_client_get_status_code(client) != 200) { 183 | esp_http_client_cleanup(client); 184 | ESP_LOGE(TAG, "STATUS 0"); 185 | return 0; 186 | } else { 187 | esp_http_client_cleanup(client); 188 | return (uint8_t) atoi(buffer); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /components/tft_library/hx8347.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_log.h" 5 | 6 | #include "lcd_com.h" 7 | #include "lcd_lib.h" 8 | #include "hx8347.h" 9 | 10 | #define TAG "HX8347" 11 | 12 | #if CONFIG_HX8347A || CONFIG_HX8347D || CONFIG_HX8347G || CONFIG_HX8347I 13 | 14 | void hx8347_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 15 | { 16 | lcdInitDevice(dev, width, height, offsetx, offsety); 17 | 18 | ESP_LOGI(TAG,"Your TFT is HX8347"); 19 | ESP_LOGI(TAG,"Screen width:%d",width); 20 | ESP_LOGI(TAG,"Screen height:%d",height); 21 | 22 | // Initailize TFT 23 | static const uint8_t regValues[] = { 24 | 0xEA, 2, 0x00, 0x20, //PTBA[15:0] 25 | 0xEC, 2, 0x0C, 0xC4, //STBA[15:0] 26 | 0xE8, 1, 0x38, //OPON[7:0] 27 | 0xE9, 1, 0x10, //OPON1[7:0] 28 | 0xF1, 1, 0x01, //OTPS1B 29 | 0xF2, 1, 0x10, //GEN 30 | //Gamma 2.2 Setting 31 | 0x40, 13, 0x01, 0x00, 0x00, 0x10, 0x0E, 0x24, 0x04, 0x50, 0x02, 0x13, 0x19, 0x19, 0x16, 32 | 0x50, 14, 0x1B, 0x31, 0x2F, 0x3F, 0x3F, 0x3E, 0x2F, 0x7B, 0x09, 0x06, 0x06, 0x0C, 0x1D, 0xCC, 33 | //Power Voltage Setting 34 | 0x1B, 1, 0x1B, //VRH=4.65V 35 | 0x1A, 1, 0x01, //BT (VGH~15V,VGL~-10V,DDVDH~5V) 36 | 0x24, 1, 0x2F, //VMH(VCOM High voltage ~3.2V) 37 | 0x25, 1, 0x57, //VML(VCOM Low voltage -1.2V) 38 | //****VCOM offset**/// 39 | 0x23, 1, 0x88, //for Flicker adjust //can reload from OTP 40 | //Power on Setting 41 | 0x18, 1, 0x34, //I/P_RADJ,N/P_RADJ, Normal mode 60Hz 42 | 0x19, 1, 0x01, //OSC_EN='1', start Osc 43 | 0x01, 1, 0x00, //DP_STB='0', out deep sleep 44 | 0x1F, 1, 0x88, // GAS=1, VOMG=00, PON=0, DK=1, XDK=0, DVDH_TRI=0, STB=0 45 | TFTLCD_DELAY8, 5, 46 | 0x1F, 1, 0x80, // GAS=1, VOMG=00, PON=0, DK=0, XDK=0, DVDH_TRI=0, STB=0 47 | TFTLCD_DELAY8, 3, 48 | 0x1F, 1, 0x90, // GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=0 49 | TFTLCD_DELAY8, 5, 50 | 0x1F, 1, 0xD0, // GAS=1, VOMG=10, PON=1, DK=0, XDK=0, DDVDH_TRI=0, STB=0 51 | TFTLCD_DELAY8, 5, 52 | //262k/65k color selection 53 | 0x17, 1, 0x05, //default 0x06 262k color // 0x05 65k color 54 | //SET PANEL 55 | 0x36, 1, 0x00, //SS_P, GS_P,REV_P,BGR_P 56 | //Display ON Setting 57 | 0x28, 1, 0x38, //GON=1, DTE=1, D=1000 58 | TFTLCD_DELAY8, 40, 59 | //0x28, 1, 0x3F, //GON=1, DTE=1, D=1100 60 | 0x28, 1, 0x3C, //GON=1, DTE=1, D=1100 61 | 62 | 0x16, 1, 0x98, //MY=1, MX=0, MV=0, ML=1, BGR=1 63 | //0x16, 1, 0x48, //MY=0, MX=1, MV=0, ML=0, BGR=1 64 | }; 65 | lcd_write_table(dev, regValues, sizeof(regValues)); 66 | // hx8347 custom function 67 | DrawPixel = hx8347_lcdDrawPixel; 68 | DrawMultiPixels = hx8347_lcdDrawMultiPixels; 69 | DrawFillRect = hx8347_lcdDrawFillRect; 70 | DisplayOff = hx8347_lcdDisplayOff; 71 | DisplayOn = hx8347_lcdDisplayOn; 72 | InversionOff = hx8347_lcdInversionOff; 73 | InversionOn = hx8347_lcdInversionOn; 74 | EnableScroll = hx8347_lcdEnableScroll; 75 | SetScrollArea = hx8347_lcdSetScrollArea; 76 | ResetScrollArea = hx8347_lcdResetScrollArea; 77 | StartScroll = hx8347_lcdStartScroll; 78 | 79 | } 80 | 81 | void hx8347_lcd_write_register(TFT_t * dev, uint8_t addr, uint16_t data) 82 | { 83 | char d[2]; 84 | d[0] = (data >> 8) & 0xFF; 85 | d[1] = data & 0xFF; 86 | lcd_write_comm_byte(dev, addr); 87 | lcd_write_data_byte(dev, d[0]); 88 | lcd_write_comm_byte(dev, addr+1); 89 | lcd_write_data_byte(dev, d[1]); 90 | } 91 | 92 | // Draw pixel 93 | // x:X coordinate 94 | // y:Y coordinate 95 | // color:color 96 | void hx8347_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color){ 97 | if (x >= dev->_width) return; 98 | if (y >= dev->_height) return; 99 | 100 | uint16_t _x = x + dev->_offsetx; 101 | uint16_t _y = y + dev->_offsety; 102 | 103 | hx8347_lcd_write_register(dev, 0x02, _x); // Column address start register 104 | hx8347_lcd_write_register(dev, 0x04, _x); // Column address end register 105 | hx8347_lcd_write_register(dev, 0x06, _y); // Row address start register 106 | hx8347_lcd_write_register(dev, 0x08, _y); // Row address end register 107 | lcd_write_comm_byte(dev, 0x22); // Memory Write 108 | lcd_write_data_word(dev, color); 109 | } 110 | 111 | // Draw multi pixel 112 | // x:X coordinate 113 | // y:Y coordinate 114 | // size:Number of colors 115 | // colors:colors 116 | void hx8347_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors) { 117 | if (x+size > dev->_width) return; 118 | if (y >= dev->_height) return; 119 | 120 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 121 | uint16_t _x1 = x + dev->_offsetx; 122 | uint16_t _x2 = _x1 + size; 123 | uint16_t _y1 = y + dev->_offsety; 124 | uint16_t _y2 = _y1; 125 | ESP_LOGD(TAG,"_x1=%d _x2=%d _y1=%d _y2=%d",_x1, _x2, _y1, _y2); 126 | 127 | hx8347_lcd_write_register(dev, 0x02, _x1); // Column address start register 128 | hx8347_lcd_write_register(dev, 0x04, _x2); // Column address end register 129 | hx8347_lcd_write_register(dev, 0x06, _y1); // Row address start register 130 | hx8347_lcd_write_register(dev, 0x08, _y2); // Row address end register 131 | lcd_write_comm_byte(dev, 0x22); // Memory Write 132 | lcd_write_colors(dev, colors, size); 133 | } 134 | 135 | 136 | 137 | 138 | // Draw rectangle of filling 139 | // x1:Start X coordinate 140 | // y1:Start Y coordinate 141 | // x2:End X coordinate 142 | // y2:End Y coordinate 143 | // color:color 144 | void hx8347_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { 145 | if (x1 >= dev->_width) return; 146 | if (x2 >= dev->_width) x2=dev->_width-1; 147 | if (y1 >= dev->_height) return; 148 | if (y2 >= dev->_height) y2=dev->_height-1; 149 | 150 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 151 | uint16_t _x1 = x1 + dev->_offsetx; 152 | uint16_t _x2 = x2 + dev->_offsetx; 153 | uint16_t _y1 = y1 + dev->_offsety; 154 | uint16_t _y2 = y2 + dev->_offsety; 155 | 156 | #if 0 157 | hx8347_lcd_write_register(dev, 0x02, _x1); // Column address start register 158 | hx8347_lcd_write_register(dev, 0x04, _x2); // Column address end register 159 | hx8347_lcd_write_register(dev, 0x06, _y1); // Row address start register 160 | hx8347_lcd_write_register(dev, 0x08, _y2); // Row address end register 161 | lcd_write_comm_byte(dev, 0x22); // Memory Write 162 | #endif 163 | for(int _x=_x1;_x<=_x2;_x++) { 164 | hx8347_lcd_write_register(dev, 0x02, _x); // Column address start register 165 | hx8347_lcd_write_register(dev, 0x04, _x); // Column address end register 166 | hx8347_lcd_write_register(dev, 0x06, _y1); // Row address start register 167 | hx8347_lcd_write_register(dev, 0x08, _y2); // Row address end register 168 | lcd_write_comm_byte(dev, 0x22); // Memory Write 169 | uint16_t size = _y2-_y1+1; 170 | lcd_write_color(dev, color, size); 171 | } 172 | } 173 | 174 | // Display OFF 175 | void hx8347_lcdDisplayOff(TFT_t * dev) { 176 | lcd_write_comm_byte(dev, 0x28); 177 | lcd_write_data_byte(dev, 0x30); 178 | } 179 | 180 | // Display ON 181 | void hx8347_lcdDisplayOn(TFT_t * dev) { 182 | lcd_write_comm_byte(dev, 0x28); 183 | lcd_write_data_byte(dev, 0x3C); 184 | } 185 | 186 | // Display Inversion OFF 187 | void hx8347_lcdInversionOff(TFT_t * dev) { 188 | lcd_write_comm_byte(dev, 0x01); 189 | #if CONFIG_HX8347A 190 | lcd_write_data_byte(dev, 0x02); 191 | #else 192 | lcd_write_data_byte(dev, 0x0A); 193 | #endif 194 | } 195 | 196 | // Display Inversion ON 197 | void hx8347_lcdInversionOn(TFT_t * dev) { 198 | lcd_write_comm_byte(dev, 0x01); 199 | #if CONFIG_HX8347A 200 | lcd_write_data_byte(dev, 0x06); 201 | #else 202 | lcd_write_data_byte(dev, 0x08); 203 | #endif 204 | } 205 | 206 | // Enable Vertical Scrolling 207 | bool hx8347_lcdEnableScroll(TFT_t * dev){ 208 | return false; 209 | } 210 | 211 | 212 | // Vertical Scrolling Definition 213 | // tfa:Top Fixed Area 214 | // vsa:Vertical Scrolling Area 215 | // bfa:Bottom Fixed Area 216 | void hx8347_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa){ 217 | } 218 | 219 | void hx8347_lcdResetScrollArea(TFT_t * dev, uint16_t vsa){ 220 | } 221 | 222 | // Vertical Scrolling Start Address 223 | // vsp:Vertical Scrolling Start Address 224 | void hx8347_lcdStartScroll(TFT_t * dev, uint16_t vsp){ 225 | } 226 | #endif 227 | -------------------------------------------------------------------------------- /components/tft_library/s6d1121.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "esp_log.h" 7 | 8 | #if CONFIG_S6D1121 9 | 10 | #include "lcd_com.h" 11 | #include "lcd_lib.h" 12 | #include "s6d1121.h" 13 | 14 | #define TAG "S6D1121" 15 | 16 | void s6d1121_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety) 17 | { 18 | lcdInitDevice(dev, width, height, offsetx, offsety); 19 | 20 | ESP_LOGI(TAG,"Your TFT is S6D1121"); 21 | ESP_LOGI(TAG,"Screen width:%d",width); 22 | ESP_LOGI(TAG,"Screen height:%d",height); 23 | 24 | #if 1 25 | lcd_write_register_word(dev, 0x0011, 0x2004); 26 | lcd_write_register_word(dev, 0x0013, 0xCC00); 27 | lcd_write_register_word(dev, 0x0015, 0x2600); 28 | lcd_write_register_word(dev, 0x0014, 0x252A); 29 | lcd_write_register_word(dev, 0x0012, 0x0033); 30 | lcd_write_register_word(dev, 0x0013, 0xCC04); 31 | lcd_write_register_word(dev, 0x0013, 0xCC06); 32 | lcd_write_register_word(dev, 0x0013, 0xCC4F); 33 | lcd_write_register_word(dev, 0x0013, 0x674F); 34 | lcd_write_register_word(dev, 0x0011, 0x2003); 35 | lcd_write_register_word(dev, 0x0030, 0x2609); 36 | lcd_write_register_word(dev, 0x0031, 0x242C); 37 | lcd_write_register_word(dev, 0x0032, 0x1F23); 38 | lcd_write_register_word(dev, 0x0033, 0x2425); 39 | lcd_write_register_word(dev, 0x0034, 0x2226); 40 | lcd_write_register_word(dev, 0x0035, 0x2523); 41 | lcd_write_register_word(dev, 0x0036, 0x1C1A); 42 | lcd_write_register_word(dev, 0x0037, 0x131D); 43 | lcd_write_register_word(dev, 0x0038, 0x0B11); 44 | lcd_write_register_word(dev, 0x0039, 0x1210); 45 | lcd_write_register_word(dev, 0x003A, 0x1315); 46 | lcd_write_register_word(dev, 0x003B, 0x3619); 47 | lcd_write_register_word(dev, 0x003C, 0x0D00); 48 | lcd_write_register_word(dev, 0x003D, 0x000D); 49 | lcd_write_register_word(dev, 0x0016, 0x0007); 50 | lcd_write_register_word(dev, 0x0002, 0x0013); 51 | lcd_write_register_word(dev, 0x0001, 0x0127); 52 | //lcd_write_register_word(dev, 0x0001, 0x0027); 53 | lcd_write_register_word(dev, 0x0003, 0x0003); 54 | //lcd_write_register_word(dev, 0x0003, 0x0000); 55 | lcd_write_register_word(dev, 0x0008, 0x0303); 56 | lcd_write_register_word(dev, 0x000A, 0x000B); 57 | lcd_write_register_word(dev, 0x000B, 0x0003); 58 | lcd_write_register_word(dev, 0x000C, 0x0000); 59 | lcd_write_register_word(dev, 0x0041, 0x0000); 60 | lcd_write_register_word(dev, 0x0050, 0x0000); 61 | lcd_write_register_word(dev, 0x0060, 0x0005); 62 | lcd_write_register_word(dev, 0x0070, 0x000B); 63 | lcd_write_register_word(dev, 0x0071, 0x0000); 64 | lcd_write_register_word(dev, 0x0078, 0x0000); 65 | lcd_write_register_word(dev, 0x007A, 0x0000); 66 | lcd_write_register_word(dev, 0x0079, 0x0007); 67 | lcd_write_register_word(dev, 0x0007, 0x0051); 68 | lcd_write_register_word(dev, 0x0007, 0x0053); 69 | lcd_write_register_word(dev, 0x0079, 0x0000); 70 | //lcd_write_comm_word(dev, 0x0022); 71 | #endif 72 | 73 | #if 0 74 | static const uint16_t S6D1121_regValues[] = { 75 | 0x0011, 0x2004, 76 | 0x0013, 0xCC00, 77 | 0x0015, 0x2600, 78 | 0x0014, 0x252A, 79 | 0x0012, 0x0033, 80 | 0x0013, 0xCC04, 81 | 0x0013, 0xCC06, 82 | 0x0013, 0xCC4F, 83 | 0x0013, 0x674F, 84 | 0x0011, 0x2003, 85 | 0x0030, 0x2609, 86 | 0x0031, 0x242C, 87 | 0x0032, 0x1F23, 88 | 0x0033, 0x2425, 89 | 0x0034, 0x2226, 90 | 0x0035, 0x2523, 91 | 0x0036, 0x1C1A, 92 | 0x0037, 0x131D, 93 | 0x0038, 0x0B11, 94 | 0x0039, 0x1210, 95 | 0x003A, 0x1315, 96 | 0x003B, 0x3619, 97 | 0x003C, 0x0D00, 98 | 0x003D, 0x000D, 99 | 0x0016, 0x0007, 100 | 0x0002, 0x0013, 101 | 0x0003, 0x0003, 102 | //0x0003, 0x000B, 103 | 0x0001, 0x0127, 104 | 0x0008, 0x0303, 105 | 0x000A, 0x000B, 106 | 0x000B, 0x0003, 107 | 0x000C, 0x0000, 108 | 0x0041, 0x0000, 109 | 0x0050, 0x0000, 110 | 0x0060, 0x0005, 111 | 0x0070, 0x000B, 112 | 0x0071, 0x0000, 113 | 0x0078, 0x0000, 114 | 0x007A, 0x0000, 115 | 0x0079, 0x0007, 116 | 0x0007, 0x0051, 117 | 0x0007, 0x0053, 118 | }; 119 | lcd_write_table16(dev, S6D1121_regValues, sizeof(S6D1121_regValues)); 120 | #endif 121 | 122 | // s6d1121 custom function 123 | DrawPixel = s6d1121_lcdDrawPixel; 124 | DrawMultiPixels = s6d1121_lcdDrawMultiPixels; 125 | DrawFillRect = s6d1121_lcdDrawFillRect; 126 | DisplayOff = s6d1121_lcdDisplayOff; 127 | DisplayOn = s6d1121_lcdDisplayOn; 128 | InversionOff = s6d1121_lcdInversionOff; 129 | InversionOn = s6d1121_lcdInversionOn; 130 | EnableScroll = s6d1121_lcdEnableScroll; 131 | SetScrollArea = s6d1121_lcdSetScrollArea; 132 | ResetScrollArea = s6d1121_lcdResetScrollArea; 133 | StartScroll = s6d1121_lcdStartScroll; 134 | 135 | } 136 | 137 | // Draw pixel 138 | // x:X coordinate 139 | // y:Y coordinate 140 | // color:color 141 | void s6d1121_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color){ 142 | if (x >= dev->_width) return; 143 | if (y >= dev->_height) return; 144 | 145 | uint16_t _x = x + dev->_offsetx; 146 | uint16_t _y = y + dev->_offsety; 147 | 148 | lcd_write_register_word(dev, 0x0046, (_x << 8) | _x); 149 | lcd_write_register_word(dev, 0x0047, _y); 150 | lcd_write_register_word(dev, 0x0048, _y); 151 | lcd_write_register_word(dev, 0x0020, _x); // RAM Address Set 1 152 | lcd_write_register_word(dev, 0x0021, _y); // RAM Address Set 2 153 | lcd_write_register_word(dev, 0x0022, color); // Write Data to GRAM 154 | } 155 | 156 | // Draw multi pixel 157 | // x:X coordinate 158 | // y:Y coordinate 159 | // size:Number of colors 160 | // colors:colors 161 | void s6d1121_lcdDrawMultiPixels(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors) { 162 | if (x+size > dev->_width) return; 163 | if (y >= dev->_height) return; 164 | 165 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 166 | uint16_t _x1 = x + dev->_offsetx; 167 | uint16_t _x2 = _x1 + size; 168 | uint16_t _y1 = y + dev->_offsety; 169 | //uint16_t _y2 = _y1; 170 | 171 | lcd_write_register_word(dev, 0x0046, (_x2 << 8) | _x1); 172 | lcd_write_register_word(dev, 0x0047, _y1); 173 | lcd_write_register_word(dev, 0x0048, _y1); 174 | lcd_write_register_word(dev, 0x0020, _x1); // RAM Address Set 1 175 | lcd_write_register_word(dev, 0x0021, _y1); // RAM Address Set 2 176 | lcd_write_comm_word(dev, 0x0022); // Write Data to GRAM 177 | lcd_write_colors(dev, colors, size); 178 | } 179 | 180 | 181 | 182 | 183 | // Draw rectangle of filling 184 | // x1:Start X coordinate 185 | // y1:Start Y coordinate 186 | // x2:End X coordinate 187 | // y2:End Y coordinate 188 | // color:color 189 | void s6d1121_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { 190 | if (x1 >= dev->_width) return; 191 | if (x2 >= dev->_width) x2=dev->_width-1; 192 | if (y1 >= dev->_height) return; 193 | if (y2 >= dev->_height) y2=dev->_height-1; 194 | 195 | ESP_LOGD(TAG,"offset(x)=%d offset(y)=%d",dev->_offsetx,dev->_offsety); 196 | uint16_t _x1 = x1 + dev->_offsetx; 197 | uint16_t _x2 = x2 + dev->_offsetx; 198 | uint16_t _y1 = y1 + dev->_offsety; 199 | uint16_t _y2 = y2 + dev->_offsety; 200 | uint16_t _size = x2 - x1 + 1; 201 | 202 | for(uint16_t _y=_y1;_y<=_y2;_y++){ 203 | lcd_write_register_word(dev, 0x0046, (_x2 << 8) | _x1); 204 | lcd_write_register_word(dev, 0x0047, _y); 205 | lcd_write_register_word(dev, 0x0048, _y); 206 | lcd_write_register_word(dev, 0x0020, _x1); // RAM Address Set 1 207 | lcd_write_register_word(dev, 0x0021, _y); // RAM Address Set 2 208 | lcd_write_comm_word(dev, 0x0022); // Write Data to GRAM 209 | lcd_write_color(dev, color, _size); 210 | } 211 | } 212 | 213 | // Display OFF 214 | void s6d1121_lcdDisplayOff(TFT_t * dev) { 215 | lcd_write_register_word(dev, 0x0007, 0x0000); // Set GON=0 DTE=0 D1=0, D0=0 216 | } 217 | 218 | // Display ON 219 | void s6d1121_lcdDisplayOn(TFT_t * dev) { 220 | lcd_write_register_word(dev, 0x0007, 0x0173); // Set GON=1 DTE=1 D1=1, D0=1 221 | } 222 | 223 | // Display Inversion OFF 224 | void s6d1121_lcdInversionOff(TFT_t * dev) { 225 | } 226 | 227 | // Display Inversion ON 228 | void s6d1121_lcdInversionOn(TFT_t * dev) { 229 | } 230 | 231 | // Enable Vertical Scrolling 232 | bool s6d1121_lcdEnableScroll(TFT_t * dev){ 233 | return false; 234 | } 235 | 236 | 237 | // Vertical Scrolling Definition 238 | // tfa:Top Fixed Area 239 | // vsa:Vertical Scrolling Area 240 | // bfa:Bottom Fixed Area 241 | void s6d1121_lcdSetScrollArea(TFT_t * dev, uint16_t tfa, uint16_t vsa, uint16_t bfa){ 242 | } 243 | 244 | void s6d1121_lcdResetScrollArea(TFT_t * dev, uint16_t vsa){ 245 | } 246 | 247 | // Vertical Scrolling Start Address 248 | // vsp:Vertical Scrolling Start Address 249 | void s6d1121_lcdStartScroll(TFT_t * dev, uint16_t vsp){ 250 | } 251 | 252 | #endif 253 | -------------------------------------------------------------------------------- /components/tft_library/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "TFT Configuration" 2 | 3 | choice DRIVER 4 | prompt "Display Driver" 5 | default ILI9488 6 | help 7 | Select Display Driver. 8 | config ILI9225 9 | bool "ILI9225" 10 | help 11 | Display Driver is ILI9225. 12 | config ILI9226 13 | bool "ILI9226" 14 | help 15 | Display Driver is ILI9226. 16 | Same as ILI9225. 17 | config ILI9320 18 | bool "ILI9320" 19 | help 20 | Display Driver is ILI9320. 21 | config ILI9325 22 | bool "ILI9325" 23 | help 24 | Display Driver is ILI9325. 25 | config ILI9327 26 | bool "ILI9327" 27 | help 28 | Display Driver is ILI9327. 29 | config ILI9340 30 | bool "ILI9340" 31 | help 32 | Display Driver is ILI9340. 33 | Same as ILI9340. 34 | config ILI9341 35 | bool "ILI9341" 36 | help 37 | Display Driver is ILI9341. 38 | config ILI9342 39 | bool "ILI9342" 40 | help 41 | Display Driver is ILI9342. 42 | config ILI9481 43 | bool "ILI9481" 44 | help 45 | Display Driver is ILI9481. 46 | config ILI9486 47 | bool "ILI9486" 48 | help 49 | Display Driver is ILI9486. 50 | Same as ST7796. 51 | config ILI9488 52 | bool "ILI9488" 53 | help 54 | Display Driver is ILI9488. 55 | config SPFD5408 56 | bool "SPFD5408" 57 | help 58 | Display Driver is SPFD5408. 59 | Same as ILI9320. 60 | config R61505 61 | bool "R61505" 62 | help 63 | Display Driver is R61505. 64 | Same as ILI9320. 65 | config R61509 66 | bool "R61509" 67 | help 68 | Display Driver is R61509. 69 | config LGDP4532 70 | bool "LGDP4532" 71 | help 72 | Display Driver is LGDP4532. 73 | config ST7775 74 | bool "ST7775" 75 | help 76 | Display Driver is ST7775. 77 | Same as ILI9225. 78 | config ST7781 79 | bool "ST7781" 80 | help 81 | Display Driver is ST7781. 82 | Same as ST7783. 83 | config ST7783 84 | bool "ST7783" 85 | help 86 | Display Driver is ST7783. 87 | Same as ST7781. 88 | config ST7793 89 | bool "ST7793" 90 | help 91 | Display Driver is ST7793. 92 | Same as R61509. 93 | config ST7796 94 | bool "ST7796" 95 | help 96 | Display Driver is ST7796. 97 | Same as ILI9486. 98 | config S6D1121 99 | bool "S6D1121" 100 | help 101 | Display Driver is S6D1121. 102 | config HX8347A 103 | bool "HX8347A" 104 | help 105 | Display Driver is HX8347A. 106 | config HX8347D 107 | bool "HX8347D" 108 | help 109 | Display Driver is HX8347D. 110 | config HX8347G 111 | bool "HX8347G" 112 | help 113 | Display Driver is HX8347G. 114 | config HX8347I 115 | bool "HX8347I" 116 | help 117 | Display Driver is HX8347I. 118 | endchoice 119 | 120 | choice INTERFACE 121 | prompt "Parallel Interface" 122 | default INTERFACE_REG 123 | help 124 | Select Parallel Interface. 125 | config INTERFACE_I2S 126 | bool "I2S Parallel Interface" 127 | help 128 | Parallel Interface is I2S. 129 | config INTERFACE_REG 130 | bool "REGISTER Parallel Interface" 131 | help 132 | Parallel Interface is REGISTER I/O. 133 | config INTERFACE_GPIO 134 | bool "GPIO Parallel Interface" 135 | help 136 | Parallel Interface is GPIO. 137 | endchoice 138 | 139 | config WIDTH 140 | int "SCREEN WIDTH" 141 | range 0 999 142 | default 320 143 | help 144 | The width resolution of the screen. 145 | 146 | config HEIGHT 147 | int "SCREEN HEIGHT" 148 | range 0 999 149 | default 480 150 | help 151 | The height resolution of the screen. 152 | 153 | config OFFSETX 154 | int "GRAM X OFFSET" 155 | range 0 99 156 | default 0 157 | help 158 | When your TFT have offset(X), set it. 159 | 160 | config OFFSETY 161 | int "GRAM Y OFFSET" 162 | range 0 99 163 | default 0 164 | help 165 | When your TFT have offset(Y), set it. 166 | 167 | config INVERSION 168 | bool "Enable Display Inversion" 169 | default false 170 | help 171 | Enable Display Inversion. 172 | 173 | config CUSTOM_GPIO_CONFIG 174 | bool "Enable Custom GPIO" 175 | help 176 | Enable Custom GPIO. 177 | 178 | config D0_GPIO 179 | depends on CUSTOM_GPIO_CONFIG 180 | int "D0 GPIO number" 181 | range 0 46 182 | default 2 if IDF_TARGET_ESP32 183 | default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 184 | help 185 | GPIO number (IOxx) to LCD D0. 186 | 187 | config D1_GPIO 188 | depends on CUSTOM_GPIO_CONFIG 189 | int "D1 GPIO number" 190 | range 0 46 191 | default 4 if IDF_TARGET_ESP32 192 | default 2 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 193 | help 194 | GPIO number (IOxx) to LCD D1. 195 | 196 | config D2_GPIO 197 | depends on CUSTOM_GPIO_CONFIG 198 | int "D2 GPIO number" 199 | range 0 46 200 | default 16 if IDF_TARGET_ESP32 201 | default 3 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 202 | help 203 | GPIO number (IOxx) to LCD D2. 204 | 205 | config D3_GPIO 206 | depends on CUSTOM_GPIO_CONFIG 207 | int "D3 GPIO number" 208 | range 0 46 209 | default 17 if IDF_TARGET_ESP32 210 | default 4 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 211 | help 212 | GPIO number (IOxx) to LCD D3. 213 | 214 | config D4_GPIO 215 | depends on CUSTOM_GPIO_CONFIG 216 | int "D4 GPIO number" 217 | range 0 46 218 | default 5 if IDF_TARGET_ESP32 219 | default 5 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 220 | help 221 | GPIO number (IOxx) to LCD D4. 222 | 223 | config D5_GPIO 224 | depends on CUSTOM_GPIO_CONFIG 225 | int "D5 GPIO number" 226 | range 0 46 227 | default 18 if IDF_TARGET_ESP32 228 | default 6 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 229 | help 230 | GPIO number (IOxx) to LCD D5. 231 | 232 | config D6_GPIO 233 | depends on CUSTOM_GPIO_CONFIG 234 | int "D6 GPIO number" 235 | range 0 46 236 | default 19 if IDF_TARGET_ESP32 237 | default 11 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 238 | help 239 | GPIO number (IOxx) to LCD D6. 240 | 241 | config D7_GPIO 242 | depends on CUSTOM_GPIO_CONFIG 243 | int "D7 GPIO number" 244 | range 0 46 245 | default 21 if IDF_TARGET_ESP32 246 | default 12 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 247 | help 248 | GPIO number (IOxx) to LCD D7. 249 | 250 | config RD_GPIO 251 | depends on CUSTOM_GPIO_CONFIG 252 | int "RD GPIO number" 253 | range 0 46 254 | default 26 if IDF_TARGET_ESP32 255 | default 39 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 256 | help 257 | GPIO number (IOxx) to LCD RD. 258 | 259 | config WR_GPIO 260 | depends on CUSTOM_GPIO_CONFIG 261 | int "WR GPIO number" 262 | range 0 46 263 | default 27 if IDF_TARGET_ESP32 264 | default 40 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 265 | help 266 | GPIO number (IOxx) to LCD WR. 267 | 268 | config RS_GPIO 269 | depends on CUSTOM_GPIO_CONFIG 270 | int "RS GPIO number" 271 | range 0 46 272 | default 14 if IDF_TARGET_ESP32 273 | default 41 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 274 | help 275 | GPIO number (IOxx) to LCD RS. 276 | 277 | config CS_GPIO 278 | depends on CUSTOM_GPIO_CONFIG 279 | int "CS GPIO number" 280 | range 0 46 281 | default 13 if IDF_TARGET_ESP32 282 | default 42 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 283 | help 284 | GPIO number (IOxx) to LCD CS. 285 | 286 | config RESET_GPIO 287 | depends on CUSTOM_GPIO_CONFIG 288 | int "RESET GPIO number" 289 | range 0 46 290 | default 12 if IDF_TARGET_ESP32 291 | default 45 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 292 | help 293 | GPIO number (IOxx) to LCD RESET. 294 | 295 | config ENABLE_TOUCH 296 | depends on INTERFACE_REG || INTERFACE_GPIO 297 | bool "Enable 4-line resistance touch screen" 298 | default false 299 | help 300 | Enable 4-line resistance touch screen. 301 | 302 | config ADC_CHANNEL_YP 303 | depends on ENABLE_TOUCH 304 | int "ADC Channel Y+" 305 | default 6 306 | range 3 9 if IDF_TARGET_ESP32 307 | range 0 7 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 308 | help 309 | ADC Channel Y+. 310 | 311 | config ADC_CHANNEL_XM 312 | depends on ENABLE_TOUCH 313 | int "ADC Channel X-" 314 | default 7 315 | range 3 9 if IDF_TARGET_ESP32 316 | range 0 7 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 317 | help 318 | ADC Channel X-. 319 | 320 | config XPT_ACCURACY 321 | depends on ENABLE_TOUCH 322 | int "Touch position accuracy" 323 | range 2 10 324 | default 5 325 | help 326 | Tolerance of touch position. 327 | If the difference from the previous position is within this range, it is considered valid. 328 | The higher the value, the less accurate the position, but the less responsive it is. 329 | 330 | choice XP_GPIO 331 | depends on ENABLE_TOUCH 332 | prompt "GPIO number (IOxx) to Touch X(+)" 333 | default XP_GPIO_D6 334 | help 335 | GPIO number (IOxx) to Touch X(+). 336 | config XP_GPIO_D6 337 | bool "GPIO_D6" 338 | help 339 | "GPIO_D6" 340 | config XP_GPIO_D0 341 | bool "GPIO_D0" 342 | help 343 | "GPIO_D0" 344 | config XP_GPIO_D1 345 | bool "GPIO_D1" 346 | help 347 | "GPIO_D1" 348 | endchoice 349 | 350 | choice XM_GPIO 351 | depends on ENABLE_TOUCH 352 | prompt "GPIO number (IOxx) to Touch X(-)" 353 | default XM_GPIO_RS 354 | help 355 | GPIO number (IOxx) to Touch X(-). 356 | config XM_GPIO_RS 357 | bool "GPIO_RS" 358 | help 359 | "GPIO_D6" 360 | config XM_GPIO_CS 361 | bool "GPIO_CS" 362 | help 363 | "GPIO_CS" 364 | endchoice 365 | 366 | choice YP_GPIO 367 | depends on ENABLE_TOUCH 368 | prompt "GPIO number (IOxx) to Touch Y(+)" 369 | default YP_GPIO_WR 370 | help 371 | GPIO number (IOxx) to Touch Y(+). 372 | config YP_GPIO_WR 373 | bool "GPIO_WR" 374 | help 375 | "GPIO_WR" 376 | config YP_GPIO_CS 377 | bool "GPIO_CS" 378 | help 379 | "GPIO_CS" 380 | config YP_GPIO_RS 381 | bool "GPIO_RS" 382 | help 383 | "GPIO_RS" 384 | endchoice 385 | 386 | choice YM_GPIO 387 | depends on ENABLE_TOUCH 388 | prompt "GPIO number (IOxx) to Touch Y(-)" 389 | default YM_GPIO_D7 390 | help 391 | GPIO number (IOxx) to Touch Y(-). 392 | config YM_GPIO_D0 393 | bool "GPIO_D0" 394 | help 395 | "GPIO_D0" 396 | config YM_GPIO_D1 397 | bool "GPIO_D1" 398 | help 399 | "GPIO_D1" 400 | config YM_GPIO_D7 401 | bool "GPIO_D7" 402 | help 403 | "GPIO_D7" 404 | endchoice 405 | 406 | config SWAP_XY 407 | bool "Swap X and Y coordinates" 408 | default false 409 | help 410 | Swap X and Y coordinates. 411 | endmenu 412 | 413 | -------------------------------------------------------------------------------- /components/qrcodegen/qrcodegen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QR Code generator library (C) 3 | * 4 | * Copyright (c) Project Nayuki. (MIT License) 5 | * https://www.nayuki.io/page/qr-code-generator-library 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * - The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * - The Software is provided "as is", without warranty of any kind, express or 16 | * implied, including but not limited to the warranties of merchantability, 17 | * fitness for a particular purpose and noninfringement. In no event shall the 18 | * authors or copyright holders be liable for any claim, damages or other 19 | * liability, whether in an action of contract, tort or otherwise, arising from, 20 | * out of or in connection with the Software or the use or other dealings in the 21 | * Software. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /* 37 | * This library creates QR Code symbols, which is a type of two-dimension barcode. 38 | * Invented by Denso Wave and described in the ISO/IEC 18004 standard. 39 | * A QR Code structure is an immutable square grid of dark and light cells. 40 | * The library provides functions to create a QR Code from text or binary data. 41 | * The library covers the QR Code Model 2 specification, supporting all versions (sizes) 42 | * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. 43 | * 44 | * Ways to create a QR Code object: 45 | * - High level: Take the payload data and call qrcodegen_encodeText() or qrcodegen_encodeBinary(). 46 | * - Low level: Custom-make the list of segments and call 47 | * qrcodegen_encodeSegments() or qrcodegen_encodeSegmentsAdvanced(). 48 | * (Note that all ways require supplying the desired error correction level and various byte buffers.) 49 | */ 50 | 51 | 52 | /*---- Enum and struct types----*/ 53 | 54 | /* 55 | * The error correction level in a QR Code symbol. 56 | */ 57 | enum qrcodegen_Ecc { 58 | // Must be declared in ascending order of error protection 59 | // so that an internal qrcodegen function works properly 60 | qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords 61 | qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords 62 | qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords 63 | qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords 64 | }; 65 | 66 | 67 | /* 68 | * The mask pattern used in a QR Code symbol. 69 | */ 70 | enum qrcodegen_Mask { 71 | // A special value to tell the QR Code encoder to 72 | // automatically select an appropriate mask pattern 73 | qrcodegen_Mask_AUTO = -1, 74 | // The eight actual mask patterns 75 | qrcodegen_Mask_0 = 0, 76 | qrcodegen_Mask_1, 77 | qrcodegen_Mask_2, 78 | qrcodegen_Mask_3, 79 | qrcodegen_Mask_4, 80 | qrcodegen_Mask_5, 81 | qrcodegen_Mask_6, 82 | qrcodegen_Mask_7, 83 | }; 84 | 85 | 86 | /* 87 | * Describes how a segment's data bits are interpreted. 88 | */ 89 | enum qrcodegen_Mode { 90 | qrcodegen_Mode_NUMERIC = 0x1, 91 | qrcodegen_Mode_ALPHANUMERIC = 0x2, 92 | qrcodegen_Mode_BYTE = 0x4, 93 | qrcodegen_Mode_KANJI = 0x8, 94 | qrcodegen_Mode_ECI = 0x7, 95 | }; 96 | 97 | 98 | /* 99 | * A segment of character/binary/control data in a QR Code symbol. 100 | * The mid-level way to create a segment is to take the payload data 101 | * and call a factory function such as qrcodegen_makeNumeric(). 102 | * The low-level way to create a segment is to custom-make the bit buffer 103 | * and initialize a qrcodegen_Segment struct with appropriate values. 104 | * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. 105 | * Any segment longer than this is meaningless for the purpose of generating QR Codes. 106 | * Moreover, the maximum allowed bit length is 32767 because 107 | * the largest QR Code (version 40) has 31329 modules. 108 | */ 109 | struct qrcodegen_Segment { 110 | // The mode indicator of this segment. 111 | enum qrcodegen_Mode mode; 112 | 113 | // The length of this segment's unencoded data. Measured in characters for 114 | // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. 115 | // Always zero or positive. Not the same as the data's bit length. 116 | int numChars; 117 | 118 | // The data bits of this segment, packed in bitwise big endian. 119 | // Can be null if the bit length is zero. 120 | uint8_t *data; 121 | 122 | // The number of valid data bits used in the buffer. Requires 123 | // 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8. 124 | // The character count (numChars) must agree with the mode and the bit buffer length. 125 | int bitLength; 126 | }; 127 | 128 | 129 | 130 | /*---- Macro constants and functions ----*/ 131 | 132 | #define qrcodegen_VERSION_MIN 1 // The minimum version number supported in the QR Code Model 2 standard 133 | #define qrcodegen_VERSION_MAX 40 // The maximum version number supported in the QR Code Model 2 standard 134 | 135 | // Calculates the number of bytes needed to store any QR Code up to and including the given version number, 136 | // as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];' 137 | // can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16). 138 | // Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX. 139 | #define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1) 140 | 141 | // The worst-case number of bytes needed to store one QR Code, up to and including 142 | // version 40. This value equals 3918, which is just under 4 kilobytes. 143 | // Use this more convenient value to avoid calculating tighter memory bounds for buffers. 144 | #define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX) 145 | 146 | 147 | 148 | /*---- Functions (high level) to generate QR Codes ----*/ 149 | 150 | /* 151 | * Encodes the given text string to a QR Code, returning true if encoding succeeded. 152 | * If the data is too long to fit in any version in the given range 153 | * at the given ECC level, then false is returned. 154 | * - The input text must be encoded in UTF-8 and contain no NULs. 155 | * - The variables ecl and mask must correspond to enum constant values. 156 | * - Requires 1 <= minVersion <= maxVersion <= 40. 157 | * - The arrays tempBuffer and qrcode must each have a length of at least 158 | * qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion), and cannot overlap. 159 | * - After the function returns, tempBuffer contains no useful data. 160 | * - If successful, the resulting QR Code may use numeric, 161 | * alphanumeric, or byte mode to encode the text. 162 | * - In the most optimistic case, a QR Code at version 40 with low ECC 163 | * can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string 164 | * up to 4296 characters, or any digit string up to 7089 characters. 165 | * These numbers represent the hard upper limit of the QR Code standard. 166 | * - Please consult the QR Code specification for information on 167 | * data capacities per version, ECC level, and text encoding mode. 168 | */ 169 | bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], 170 | enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); 171 | 172 | 173 | /* 174 | * Encodes the given binary data to a QR Code, returning true if encoding succeeded. 175 | * If the data is too long to fit in any version in the given range 176 | * at the given ECC level, then false is returned. 177 | * - The input array range dataAndTemp[0 : dataLen] should normally be 178 | * valid UTF-8 text, but is not required by the QR Code standard. 179 | * - The variables ecl and mask must correspond to enum constant values. 180 | * - Requires 1 <= minVersion <= maxVersion <= 40. 181 | * - The arrays dataAndTemp and qrcode must each have a length of at least 182 | * qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion), and cannot overlap. 183 | * - After the function returns, the contents of dataAndTemp may have changed, 184 | * and does not represent useful data anymore. 185 | * - If successful, the resulting QR Code will use byte mode to encode the data. 186 | * - In the most optimistic case, a QR Code at version 40 with low ECC can hold any byte 187 | * sequence up to length 2953. This is the hard upper limit of the QR Code standard. 188 | * - Please consult the QR Code specification for information on 189 | * data capacities per version, ECC level, and text encoding mode. 190 | */ 191 | bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], 192 | enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); 193 | 194 | 195 | /*---- Functions (low level) to generate QR Codes ----*/ 196 | 197 | /* 198 | * Renders a QR Code representing the given segments at the given error correction level. 199 | * The smallest possible QR Code version is automatically chosen for the output. Returns true if 200 | * QR Code creation succeeded, or false if the data is too long to fit in any version. The ECC level 201 | * of the result may be higher than the ecl argument if it can be done without increasing the version. 202 | * This function allows the user to create a custom sequence of segments that switches 203 | * between modes (such as alphanumeric and byte) to encode text in less space. 204 | * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). 205 | * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will 206 | * result in them being clobbered, but the QR Code output will still be correct. 207 | * But the qrcode array must not overlap tempBuffer or any segment's data buffer. 208 | */ 209 | bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len, 210 | enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]); 211 | 212 | 213 | /* 214 | * Renders a QR Code representing the given segments with the given encoding parameters. 215 | * Returns true if QR Code creation succeeded, or false if the data is too long to fit in the range of versions. 216 | * The smallest possible QR Code version within the given range is automatically 217 | * chosen for the output. Iff boostEcl is true, then the ECC level of the result 218 | * may be higher than the ecl argument if it can be done without increasing the 219 | * version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or 220 | * qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow). 221 | * This function allows the user to create a custom sequence of segments that switches 222 | * between modes (such as alphanumeric and byte) to encode text in less space. 223 | * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). 224 | * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will 225 | * result in them being clobbered, but the QR Code output will still be correct. 226 | * But the qrcode array must not overlap tempBuffer or any segment's data buffer. 227 | */ 228 | bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl, 229 | int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]); 230 | 231 | 232 | /* 233 | * Tests whether the given string can be encoded as a segment in numeric mode. 234 | * A string is encodable iff each character is in the range 0 to 9. 235 | */ 236 | bool qrcodegen_isNumeric(const char *text); 237 | 238 | 239 | /* 240 | * Tests whether the given string can be encoded as a segment in alphanumeric mode. 241 | * A string is encodable iff each character is in the following set: 0 to 9, A to Z 242 | * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. 243 | */ 244 | bool qrcodegen_isAlphanumeric(const char *text); 245 | 246 | 247 | /* 248 | * Returns the number of bytes (uint8_t) needed for the data buffer of a segment 249 | * containing the given number of characters using the given mode. Notes: 250 | * - Returns SIZE_MAX on failure, i.e. numChars > INT16_MAX or the internal 251 | * calculation of the number of needed bits exceeds INT16_MAX (i.e. 32767). 252 | * - Otherwise, all valid results are in the range [0, ceil(INT16_MAX / 8)], i.e. at most 4096. 253 | * - It is okay for the user to allocate more bytes for the buffer than needed. 254 | * - For byte mode, numChars measures the number of bytes, not Unicode code points. 255 | * - For ECI mode, numChars must be 0, and the worst-case number of bytes is returned. 256 | * An actual ECI segment can have shorter data. For non-ECI modes, the result is exact. 257 | */ 258 | size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars); 259 | 260 | 261 | /* 262 | * Returns a segment representing the given binary data encoded in 263 | * byte mode. All input byte arrays are acceptable. Any text string 264 | * can be converted to UTF-8 bytes and encoded as a byte mode segment. 265 | */ 266 | struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]); 267 | 268 | 269 | /* 270 | * Returns a segment representing the given string of decimal digits encoded in numeric mode. 271 | */ 272 | struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]); 273 | 274 | 275 | /* 276 | * Returns a segment representing the given text string encoded in alphanumeric mode. 277 | * The characters allowed are: 0 to 9, A to Z (uppercase only), space, 278 | * dollar, percent, asterisk, plus, hyphen, period, slash, colon. 279 | */ 280 | struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]); 281 | 282 | 283 | /* 284 | * Returns a segment representing an Extended Channel Interpretation 285 | * (ECI) designator with the given assignment value. 286 | */ 287 | struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]); 288 | 289 | 290 | /*---- Functions to extract raw data from QR Codes ----*/ 291 | 292 | /* 293 | * Returns the side length of the given QR Code, assuming that encoding succeeded. 294 | * The result is in the range [21, 177]. Note that the length of the array buffer 295 | * is related to the side length - every 'uint8_t qrcode[]' must have length at least 296 | * qrcodegen_BUFFER_LEN_FOR_VERSION(version), which equals ceil(size^2 / 8 + 1). 297 | */ 298 | int qrcodegen_getSize(const uint8_t qrcode[]); 299 | 300 | 301 | /* 302 | * Returns the color of the module (pixel) at the given coordinates, which is false 303 | * for light or true for dark. The top left corner has the coordinates (x=0, y=0). 304 | * If the given coordinates are out of bounds, then false (light) is returned. 305 | */ 306 | bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y); 307 | 308 | 309 | #ifdef __cplusplus 310 | } 311 | #endif 312 | -------------------------------------------------------------------------------- /main/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "freertos/FreeRTOS.h" 8 | #include "freertos/task.h" 9 | #include "driver/gpio.h" 10 | #include "driver/timer.h" 11 | #include "sdkconfig.h" 12 | //#include "ili9488.h" 13 | #include "qrcodegen.h" 14 | #include "wifi_station.h" 15 | #include "http_client.h" 16 | #include "esp_task_wdt.h" 17 | #include "esp_err.h" 18 | #include "esp_log.h" 19 | #include "esp_system.h" 20 | #include "esp_vfs.h" 21 | #include "esp_spiffs.h" 22 | 23 | #include "lcd_com.h" 24 | #include "lcd_lib.h" 25 | #include "fontx.h" 26 | 27 | #include "sdcard.h" 28 | 29 | #if CONFIG_INTERFACE_I2S 30 | #define INTERFACE INTERFACE_I2S 31 | #elif CONFIG_INTERFACE_GPIO 32 | #define INTERFACE INTERFACE_GPIO 33 | #elif CONFIG_INTERFACE_REG 34 | #define INTERFACE INTERFACE_REG 35 | #endif 36 | 37 | #if CONFIG_ILI9225 38 | #include "ili9225.h" 39 | #define DRIVER "ILI9225" 40 | #define INIT_FUNCTION(a, b, c, d, e) ili9225_lcdInit(a, b, c, d, e) 41 | 42 | #elif CONFIG_ILI9226 43 | #include "ili9225.h" 44 | #define DRIVER "ILI9226" 45 | #define INIT_FUNCTION(a, b, c, d, e) ili9225_lcdInit(a, b, c, d, e) 46 | 47 | #elif CONFIG_ILI9320 48 | #include "ili9320.h" 49 | #define DRIVER "ILI9320" 50 | #define INIT_FUNCTION(a, b, c, d, e) ili9320_lcdInit(a, b, c, d, e) 51 | 52 | #elif CONFIG_ILI9325 53 | #include "ili9325.h" 54 | #define DRIVER "ILI9325" 55 | #define INIT_FUNCTION(a, b, c, d, e) ili9325_lcdInit(a, b, c, d, e) 56 | 57 | #elif CONFIG_ILI9327 58 | #include "ili9327.h" 59 | #define DRIVER "ILI9327" 60 | #define INIT_FUNCTION(a, b, c, d, e) ili9327_lcdInit(a, b, c, d, e) 61 | 62 | #elif CONFIG_ILI9340 63 | #include "ili9341.h" 64 | #define DRIVER "ILI9340" 65 | #define INIT_FUNCTION(a, b, c, d, e) ili9341_lcdInit(a, b, c, d, e) 66 | 67 | #elif CONFIG_ILI9341 68 | #include "ili9341.h" 69 | #define DRIVER "ILI9341" 70 | #define INIT_FUNCTION(a, b, c, d, e) ili9341_lcdInit(a, b, c, d, e) 71 | 72 | #elif CONFIG_ILI9342 73 | #include "ili9342.h" 74 | #define DRIVER "ILI9342" 75 | #define INIT_FUNCTION(a, b, c, d, e) ili9342_lcdInit(a, b, c, d, e) 76 | 77 | #elif CONFIG_ILI9481 78 | #include "ili9481.h" 79 | #define DRIVER "ILI9481" 80 | #define INIT_FUNCTION(a, b, c, d, e) ili9481_lcdInit(a, b, c, d, e) 81 | 82 | #elif CONFIG_ILI9486 83 | #include "ili9486.h" 84 | #define DRIVER "ILI9486" 85 | #define INIT_FUNCTION(a, b, c, d, e) ili9486_lcdInit(a, b, c, d, e) 86 | 87 | #elif CONFIG_ILI9488 88 | #include "ili9488.h" 89 | #define DRIVER "ILI9488" 90 | #define INIT_FUNCTION(a, b, c, d, e) ili9488_lcdInit(a, b, c, d, e) 91 | 92 | #elif CONFIG_SPFD5408 93 | #include "ili9320.h" 94 | #define DRIVER "SPFD5408" 95 | #define INIT_FUNCTION(a, b, c, d, e) ili9320_lcdInit(a, b, c, d, e) 96 | 97 | #elif CONFIG_R61505 98 | #include "ili9320.h" 99 | #define DRIVER "R61505" 100 | #define INIT_FUNCTION(a, b, c, d, e) ili9320_lcdInit(a, b, c, d, e) 101 | 102 | #elif CONFIG_R61509 103 | #include "r61509.h" 104 | #define DRIVER "R61509" 105 | #define INIT_FUNCTION(a, b, c, d, e) r61509_lcdInit(a, b, c, d, e) 106 | 107 | #elif CONFIG_LGDP4532 108 | #include "lgdp4532.h" 109 | #define DRIVER "LGDP4532" 110 | #define INIT_FUNCTION(a, b, c, d, e) lgdp4532_lcdInit(a, b, c, d, e) 111 | 112 | #elif CONFIG_ST7775 113 | #include "ili9225.h" 114 | #define DRIVER "ST7775" 115 | #define INIT_FUNCTION(a, b, c, d, e) ili9225_lcdInit(a, b, c, d, e) 116 | 117 | #elif CONFIG_ST7781 118 | #include "st7781.h" 119 | #define DRIVER "ST7781" 120 | #define INIT_FUNCTION(a, b, c, d, e) st7781_lcdInit(a, b, c, d, e) 121 | 122 | #elif CONFIG_ST7783 123 | #include "st7781.h" 124 | #define DRIVER "ST7783" 125 | #define INIT_FUNCTION(a, b, c, d, e) st7781_lcdInit(a, b, c, d, e) 126 | 127 | #elif CONFIG_ST7793 128 | #include "r61509.h" 129 | #define DRIVER "ST7793" 130 | #define INIT_FUNCTION(a, b, c, d, e) r61509_lcdInit(a, b, c, d, e) 131 | 132 | #elif CONFIG_ST7796 133 | #include "ili9486.h" 134 | #define DRIVER "ST7796" 135 | #define INIT_FUNCTION(a, b, c, d, e) ili9486_lcdInit(a, b, c, d, e) 136 | 137 | #elif CONFIG_S6D1121 138 | #include "s6d1121.h" 139 | #define DRIVER "S6D1121" 140 | #define INIT_FUNCTION(a, b, c, d, e) s6d1121_lcdInit(a, b, c, d, e) 141 | 142 | #elif CONFIG_HX8347A 143 | #include "hx8347.h" 144 | #define DRIVER "HX8347A" 145 | #define INIT_FUNCTION(a, b, c, d, e) hx8347_lcdInit(a, b, c, d, e) 146 | 147 | #elif CONFIG_HX8347D 148 | #include "hx8347.h" 149 | #define DRIVER "HX8347D" 150 | #define INIT_FUNCTION(a, b, c, d, e) hx8347_lcdInit(a, b, c, d, e) 151 | 152 | #elif CONFIG_HX8347G 153 | #include "hx8347.h" 154 | #define DRIVER "HX8347G" 155 | #define INIT_FUNCTION(a, b, c, d, e) hx8347_lcdInit(a, b, c, d, e) 156 | 157 | #elif CONFIG_HX8347I 158 | #include "hx8347.h" 159 | #define DRIVER "HX8347I" 160 | #define INIT_FUNCTION(a, b, c, d, e) hx8347_lcdInit(a, b, c, d, e) 161 | 162 | #endif 163 | 164 | #define INTERVAL 400 165 | #define WAIT vTaskDelay(INTERVAL) 166 | 167 | #define STATUS_WAIT_USER_INPUT 0 168 | #define STATUS_REQUEST_QRCODE 1 169 | #define STATUS_CHECK_PAYMENT 2 170 | #define STATUS_ACTUATE_ON_GPIO 3 171 | 172 | #define BUTTON_INPUT 35 173 | #define ATUADOR 15 174 | 175 | #define LAST_ID_KEY "last_id" 176 | 177 | uint8_t current_status; 178 | uint32_t tickNumber = 0; 179 | uint8_t segundos = 0; 180 | uint8_t minutos = 0; 181 | uint8_t horas = 0; 182 | 183 | uint8_t order_status; 184 | 185 | bool generate_qrcode; 186 | bool get_order_status; 187 | bool primeira_vez = true; 188 | 189 | char info[30]; 190 | 191 | uint32_t last_id; 192 | 193 | static const char *TAG = "Main"; 194 | 195 | FontxFile fx16G[2]; 196 | FontxFile fx24G[2]; 197 | FontxFile fx32G[2]; 198 | 199 | FontxFile fx16M[2]; 200 | FontxFile fx24M[2]; 201 | FontxFile fx32M[2]; 202 | 203 | void IRAM_ATTR timer_tick_func(void *para); 204 | 205 | static void print_qrcode(TFT_t* dev, const uint8_t qrcode[]); 206 | 207 | static void timer_configure(void); 208 | 209 | uint32_t read_nvs_data(nvs_handle_t *nvs_handle); 210 | 211 | void save_nvs_data(nvs_handle_t *nvs_handle, uint32_t data); 212 | 213 | void print_last_order(TFT_t* dev, char * info, uint32_t last_order) 214 | { 215 | sprintf(info, "Ultima Compra: %d", last_order); 216 | lcdDrawString(dev, fx24G, 10, 460, (uint8_t *) info, BLUE); 217 | } 218 | 219 | static void SPIFFS_Directory(char * path) { 220 | DIR* dir = opendir(path); 221 | assert(dir != NULL); 222 | while (true) { 223 | struct dirent*pe = readdir(dir); 224 | if (!pe) break; 225 | ESP_LOGI(__FUNCTION__,"d_name=%s d_ino=%d d_type=%x", pe->d_name,pe->d_ino, pe->d_type); 226 | } 227 | closedir(dir); 228 | } 229 | 230 | void app_main() 231 | { 232 | ESP_LOGI(TAG, "Initializing SPIFFS"); 233 | esp_vfs_spiffs_conf_t conf = { 234 | .base_path = "/spiffs", 235 | .partition_label = NULL, 236 | .max_files = 10, 237 | .format_if_mount_failed =true 238 | }; 239 | 240 | // Use settings defined above toinitialize and mount SPIFFS filesystem. 241 | // Note: esp_vfs_spiffs_register is anall-in-one convenience function. 242 | esp_err_t ret = esp_vfs_spiffs_register(&conf); 243 | 244 | if (ret != ESP_OK) { 245 | if (ret == ESP_FAIL) { 246 | ESP_LOGE(TAG, "Failed to mount or format filesystem"); 247 | } else if (ret == ESP_ERR_NOT_FOUND) { 248 | ESP_LOGE(TAG, "Failed to find SPIFFS partition"); 249 | } else { 250 | ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)",esp_err_to_name(ret)); 251 | } 252 | return; 253 | } 254 | 255 | size_t total = 0, used = 0; 256 | ret = esp_spiffs_info(NULL, &total,&used); 257 | if (ret != ESP_OK) { 258 | ESP_LOGE(TAG,"Failed to get SPIFFS partition information (%s)",esp_err_to_name(ret)); 259 | } else { 260 | ESP_LOGI(TAG,"Partition size: total: %d, used: %d", total, used); 261 | } 262 | 263 | SPIFFS_Directory("/spiffs/"); 264 | 265 | #ifdef CONFIG_LOAD_FROM_SD_CARD 266 | ESP_LOGI(TAG, "Carregando configurações do Cartão Micro SD"); 267 | 268 | sdmmc_card_t card; 269 | sdcard_init(&card); 270 | 271 | char wifi_ssid[32]; 272 | char wifi_password[64]; 273 | 274 | sdcard_load_config(wifi_ssid, wifi_password); 275 | 276 | #else 277 | char wifi_ssid[] = CONFIG_ESP_WIFI_SSID; 278 | char wifi_password[] = CONFIG_ESP_WIFI_PASSWORD; 279 | #endif 280 | 281 | // Define o botão de entrada 282 | gpio_set_direction(BUTTON_INPUT, GPIO_MODE_INPUT); 283 | 284 | // Define o pino do atuador como saída 285 | gpio_set_direction(ATUADOR, GPIO_MODE_OUTPUT); 286 | 287 | // Define a saída do atuador para 0; 288 | gpio_set_level(ATUADOR, 0); 289 | 290 | // setup_lcd_pins(); 291 | // delay_ms(100); 292 | 293 | ESP_LOGI(TAG,"Iniciando LCD"); 294 | 295 | // init_lcd(); 296 | 297 | // set font file 298 | 299 | InitFontx(fx16G,"/spiffs/ILGH16XB.FNT",""); // 8x16Dot Gothic 300 | InitFontx(fx24G,"/spiffs/ILGH24XB.FNT",""); // 12x24Dot Gothic 301 | InitFontx(fx32G,"/spiffs/ILGH32XB.FNT",""); // 16x32Dot Gothic 302 | 303 | InitFontx(fx16M,"/spiffs/ILMH16XB.FNT",""); // 8x16Dot Mincyo 304 | InitFontx(fx24M,"/spiffs/ILMH24XB.FNT",""); // 12x24Dot Mincyo 305 | InitFontx(fx32M,"/spiffs/ILMH32XB.FNT",""); // 16x32Dot Mincyo 306 | 307 | TFT_t dev; 308 | lcd_interface_cfg(&dev, INTERFACE); 309 | 310 | INIT_FUNCTION(&dev, CONFIG_WIDTH, CONFIG_HEIGHT, CONFIG_OFFSETX, CONFIG_OFFSETY); 311 | 312 | // Preenche o LCD com o Fundo Preto 313 | lcdFillScreen(&dev, BLACK); 314 | 315 | // Define a direção da dos textos 316 | lcdSetFontDirection(&dev, 0); 317 | 318 | lcdSetFontFill(&dev, BLACK); 319 | 320 | ret = nvs_flash_init(); 321 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { 322 | ESP_ERROR_CHECK(nvs_flash_erase()); 323 | ret = nvs_flash_init(); 324 | } 325 | ESP_ERROR_CHECK(ret); 326 | 327 | 328 | ESP_LOGI(TAG, "Opening Non-Volatile Storage (NVS) handle... "); 329 | nvs_handle_t nvs_handle; 330 | esp_err_t err = nvs_open("storage", NVS_READWRITE, &nvs_handle); 331 | if (err == ESP_OK) { 332 | ESP_LOGI(TAG, "Pronto"); 333 | } else { 334 | ESP_LOGE(TAG, "Falha ao abrir NVS"); 335 | } 336 | 337 | last_id = read_nvs_data(&nvs_handle); 338 | 339 | print_last_order(&dev, info, last_id); 340 | 341 | s_wifi_event_group = xEventGroupCreate(); 342 | 343 | ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); 344 | wifi_init_sta(wifi_ssid, wifi_password); 345 | 346 | char *buffer; 347 | buffer = (char *) malloc(300); 348 | uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX]; 349 | uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX]; 350 | 351 | current_status = STATUS_WAIT_USER_INPUT; 352 | 353 | timer_configure(); 354 | 355 | generate_qrcode = false; 356 | 357 | tickNumber = 0; 358 | 359 | while(1) 360 | { 361 | vTaskDelay(10 / portTICK_PERIOD_MS); 362 | 363 | /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum 364 | * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ 365 | EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, 366 | WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, 367 | pdFALSE, 368 | pdFALSE, 369 | portMAX_DELAY); 370 | 371 | /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually 372 | * happened. */ 373 | if (bits & WIFI_CONNECTED_BIT) { 374 | switch (current_status) 375 | { 376 | case STATUS_WAIT_USER_INPUT: 377 | if (primeira_vez == true) { 378 | sprintf(info, "PRESSIONE O BOTAO"); 379 | lcdDrawString(&dev, fx24G, 6, 46, (uint8_t *) info, YELLOW); 380 | sprintf(info, "PARA PAGAR"); 381 | lcdDrawString(&dev, fx24G, 6, 76, (uint8_t *) info, YELLOW); 382 | primeira_vez = false; 383 | } 384 | if (gpio_get_level(BUTTON_INPUT) == 0) 385 | { 386 | if (tickNumber == 50) { 387 | current_status = STATUS_REQUEST_QRCODE; 388 | last_id++; 389 | save_nvs_data(&nvs_handle, last_id); 390 | print_last_order(&dev, info, last_id); 391 | } 392 | } else { 393 | tickNumber = 0; 394 | } 395 | break; 396 | case STATUS_REQUEST_QRCODE: 397 | http_get_qrcode(buffer, last_id); 398 | // http_get_qrcode_test(buffer); 399 | ESP_LOGI(TAG, "QR CODE: %s", buffer); 400 | ESP_LOGI(TAG, "Gerando QR Code..."); 401 | bool ok = qrcodegen_encodeText(buffer, tempBuffer, qrcode, 402 | qrcodegen_Ecc_HIGH, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true); 403 | if (ok) { 404 | print_qrcode(&dev, qrcode); 405 | } 406 | ESP_LOGI(TAG, "QR Code gerado e Impresso"); 407 | current_status = STATUS_CHECK_PAYMENT; 408 | tickNumber = 0; 409 | break; 410 | case STATUS_CHECK_PAYMENT: 411 | if (tickNumber > 1000) { 412 | tickNumber = 0; 413 | segundos++; 414 | if (segundos == 60) { 415 | segundos = 0; 416 | minutos++; 417 | } 418 | 419 | sprintf(info, "%02d:%02d:%02d", horas, minutos, segundos); 420 | lcdDrawString(&dev, fx16G, 30, 420, (uint8_t *) info, GREEN); 421 | 422 | if (minutos == 2) { 423 | current_status = STATUS_WAIT_USER_INPUT; 424 | primeira_vez = true; 425 | segundos = minutos = horas = 0; 426 | tickNumber = 0; 427 | // Preenche o LCD com o Fundo Preto 428 | lcdFillScreen(&dev, BLACK); 429 | print_last_order(&dev, info, last_id); 430 | sprintf(info, "TEMPO ESGOTADO!!!"); 431 | lcdDrawString(&dev, fx32G, 30, 136, (uint8_t *) info, RED); 432 | } else { 433 | if (segundos % 10 == 0) { 434 | ESP_LOGI(TAG, "Verficando Pagamento"); 435 | order_status = http_get_order_status(last_id); 436 | if (order_status == 1) { 437 | ESP_LOGI(TAG, "Pagamento efetuado"); 438 | // Preenche o LCD com o Fundo Preto 439 | lcdFillScreen(&dev, BLACK); 440 | print_last_order(&dev, info, last_id); 441 | sprintf(info, "PAGAMENTO EFETUADO!!!"); 442 | lcdDrawString(&dev, fx32G, 30, 136, (uint8_t *) info, GREEN); 443 | gpio_set_level(ATUADOR, 1); 444 | current_status = STATUS_ACTUATE_ON_GPIO; 445 | segundos = minutos = horas = 0; 446 | tickNumber = 0; 447 | } else { 448 | ESP_LOGI(TAG, "Pagamento não efetuado"); 449 | } 450 | } 451 | } 452 | } 453 | break; 454 | case STATUS_ACTUATE_ON_GPIO: 455 | if (tickNumber > 1000) { 456 | tickNumber = 0; 457 | segundos++; 458 | if (segundos == 60) { 459 | segundos = 0; 460 | minutos++; 461 | } 462 | sprintf(info, "%02d:%02d:%02d", horas, minutos, segundos); 463 | lcdDrawString(&dev, fx16G, 30, 420, (uint8_t *) info, GREEN); 464 | if (segundos == 10) { 465 | current_status = STATUS_WAIT_USER_INPUT; 466 | primeira_vez = true; 467 | segundos = minutos = horas = 0; 468 | tickNumber = 0; 469 | // Preenche o LCD com o Fundo Preto 470 | lcdFillScreen(&dev, BLACK); 471 | print_last_order(&dev, info, last_id); 472 | gpio_set_level(ATUADOR, 0); 473 | } 474 | } 475 | break; 476 | default: 477 | break; 478 | } 479 | } else if (bits & WIFI_FAIL_BIT) { 480 | if (primeira_vez == true) { 481 | sprintf(info, "Falha ao conectar ao WiFi!!!"); 482 | lcdDrawString(&dev, fx32G, 30, 136, (uint8_t *) info, RED); 483 | primeira_vez = false; 484 | } 485 | } else { 486 | // ESP_LOGE(TAG, "UNEXPECTED EVENT"); 487 | } 488 | 489 | 490 | } 491 | 492 | free(buffer); 493 | } 494 | 495 | static void timer_configure(void) 496 | { 497 | //int timer_group = TIMER_GROUP_0; 498 | int timer_idx = TIMER_0; 499 | 500 | timer_config_t config; 501 | config.alarm_en = 1; 502 | config.auto_reload = 1; 503 | config.counter_dir = TIMER_COUNT_UP; 504 | config.divider = 80; 505 | config.intr_type = TIMER_INTR_LEVEL; 506 | config.counter_en = TIMER_PAUSE; 507 | 508 | /*Configure timer*/ 509 | timer_init(TIMER_GROUP_0, TIMER_0, &config); 510 | /*Stop timer counter*/ 511 | timer_pause(TIMER_GROUP_0, TIMER_0); 512 | /*Load counter value */ 513 | timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL); 514 | /*Set alarm value*/ 515 | timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 1000); 516 | /*Enable timer interrupt*/ 517 | timer_enable_intr(TIMER_GROUP_0, TIMER_0); 518 | /*Set ISR handler*/ 519 | timer_isr_register(TIMER_GROUP_0, TIMER_0, &timer_tick_func, (void*) &timer_idx, ESP_INTR_FLAG_IRAM, NULL); 520 | /*Start timer counter*/ 521 | timer_start(TIMER_GROUP_0, TIMER_0); 522 | } 523 | 524 | void IRAM_ATTR timer_tick_func(void *para) 525 | { 526 | TIMERG0.hw_timer[TIMER_0].update = 1; 527 | TIMERG0.int_clr_timers.t0 = 1; 528 | 529 | tickNumber++; 530 | TIMERG0.hw_timer[TIMER_0].config.alarm_en = 1; 531 | } 532 | 533 | uint32_t read_nvs_data(nvs_handle_t *nvs_handle) { 534 | ESP_LOGI(TAG, "Reading restart counter from NVS ... "); 535 | uint32_t last_id = 0; 536 | esp_err_t err = nvs_get_u32(*nvs_handle, LAST_ID_KEY, &last_id); 537 | switch (err) { 538 | case ESP_OK: 539 | ESP_LOGI(TAG, "Done"); 540 | ESP_LOGI(TAG, "Last Id = %d", last_id); 541 | break; 542 | case ESP_ERR_NVS_NOT_FOUND: 543 | ESP_LOGE(TAG, "The value is not initialized yet!"); 544 | break; 545 | default : 546 | ESP_LOGE(TAG, "Error (%s) reading!", esp_err_to_name(err)); 547 | } 548 | return last_id; 549 | } 550 | 551 | void save_nvs_data(nvs_handle_t *nvs_handle, uint32_t data) { 552 | ESP_LOGI(TAG, "Updating last_id in NVS ... "); 553 | esp_err_t err = nvs_set_u32(*nvs_handle, LAST_ID_KEY, data); 554 | if (err == ESP_OK) { 555 | ESP_LOGI(TAG, "Pronto"); 556 | } else { 557 | ESP_LOGE(TAG, "Falha ao escrever no NVS"); 558 | } 559 | 560 | ESP_LOGI(TAG, "Committing updates in NVS ... "); 561 | err = nvs_commit(*nvs_handle); 562 | if (err == ESP_OK) { 563 | ESP_LOGI(TAG, "Pronto"); 564 | } else { 565 | ESP_LOGE(TAG, "Falha ao escrever no NVS"); 566 | } 567 | } 568 | 569 | static void print_qrcode(TFT_t* dev, const uint8_t qrcode[]) 570 | { 571 | int size = qrcodegen_getSize(qrcode); 572 | char border = 4; 573 | char module_size = 4; 574 | uint16_t color; 575 | // unsigned char r, g, b; 576 | for (int y = -border; y < size + border; y++) 577 | { 578 | for (int x = -border; x < size + border; x++) 579 | { 580 | if (qrcodegen_getModule(qrcode, x, y)) { 581 | color = 0x0000; 582 | } else { 583 | color = 0xFFFF; 584 | } 585 | for (int i = 0; i < module_size; i++) { 586 | for (int j = 0; j < module_size; j++) { 587 | lcdDrawPixel(dev, (x+4)*module_size + j + 6, (y+4)*module_size + i + 86, color); 588 | } 589 | } 590 | } 591 | } 592 | } 593 | -------------------------------------------------------------------------------- /components/tft_library/i2s_lcd_esp32s2_driver.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sdkconfig.h" 16 | #if CONFIG_IDF_TARGET_ESP32S2 17 | 18 | #include 19 | #include 20 | #include "freertos/FreeRTOS.h" 21 | #include "freertos/task.h" 22 | #include "freertos/semphr.h" 23 | #include "esp_log.h" 24 | #include "driver/gpio.h" 25 | #include "esp32s2/rom/gpio.h" 26 | #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) 27 | #include "esp_private/periph_ctrl.h" 28 | #endif 29 | #include "soc/gpio_periph.h" 30 | #include "driver/i2s.h" 31 | #include "soc/i2s_struct.h" 32 | #include "esp_heap_caps.h" 33 | #include "esp32s2/rom/lldesc.h" 34 | #include "soc/system_reg.h" 35 | #include "i2s_lcd_driver.h" 36 | 37 | 38 | static const char *TAG = "ESP32S2_I2S_LCD"; 39 | 40 | #define I2S_CHECK(a, str, ret) if (!(a)) { \ 41 | ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \ 42 | return (ret); \ 43 | } 44 | 45 | #define LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE (4000) // 4-byte aligned 46 | #define LCD_DATA_MAX_WIDTH (24) /*!< Maximum width of LCD data bus */ 47 | 48 | #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) 49 | #define ets_delay_us esp_rom_delay_us 50 | #define portTICK_RATE_MS portTICK_PERIOD_MS 51 | #endif 52 | 53 | typedef struct { 54 | uint32_t dma_buffer_size; 55 | uint32_t dma_half_buffer_size; 56 | uint32_t dma_node_buffer_size; 57 | uint32_t dma_node_cnt; 58 | uint32_t dma_half_node_cnt; 59 | lldesc_t *dma; 60 | uint8_t *dma_buffer; 61 | QueueHandle_t event_queue; 62 | uint8_t width; 63 | bool swap_data; 64 | intr_handle_t lcd_cam_intr_handle; 65 | i2s_dev_t *i2s_dev; 66 | } i2s_lcd_obj_t; 67 | 68 | typedef struct { 69 | int rs_io_num; 70 | i2s_lcd_obj_t *i2s_lcd_obj; 71 | SemaphoreHandle_t mutex; 72 | } i2s_lcd_driver_t; 73 | 74 | static void IRAM_ATTR i2s_isr(void *arg) 75 | { 76 | BaseType_t HPTaskAwoken = pdFALSE; 77 | i2s_lcd_obj_t *i2s_lcd_obj = (i2s_lcd_obj_t*)arg; 78 | i2s_dev_t *i2s_dev = i2s_lcd_obj->i2s_dev; 79 | 80 | typeof(i2s_dev->int_st) status = i2s_dev->int_st; 81 | i2s_dev->int_clr.val = status.val; 82 | if (status.val == 0) { 83 | return; 84 | } 85 | 86 | if (status.out_eof) { 87 | xQueueSendFromISR(i2s_lcd_obj->event_queue, (void*)&status.val, &HPTaskAwoken); 88 | } 89 | 90 | if (HPTaskAwoken == pdTRUE) { 91 | portYIELD_FROM_ISR(); 92 | } 93 | } 94 | 95 | static void lcd_dma_set_int(i2s_lcd_obj_t *i2s_lcd_obj) 96 | { 97 | // Generate a data DMA linked list 98 | for (int x = 0; x < i2s_lcd_obj->dma_node_cnt; x++) { 99 | i2s_lcd_obj->dma[x].size = i2s_lcd_obj->dma_node_buffer_size; 100 | i2s_lcd_obj->dma[x].length = i2s_lcd_obj->dma_node_buffer_size; 101 | i2s_lcd_obj->dma[x].buf = (i2s_lcd_obj->dma_buffer + i2s_lcd_obj->dma_node_buffer_size * x); 102 | i2s_lcd_obj->dma[x].eof = !((x + 1) % i2s_lcd_obj->dma_half_node_cnt); 103 | i2s_lcd_obj->dma[x].empty = (uint32_t)&i2s_lcd_obj->dma[(x + 1) % i2s_lcd_obj->dma_node_cnt]; 104 | } 105 | i2s_lcd_obj->dma[i2s_lcd_obj->dma_half_node_cnt - 1].empty = (uint32_t)NULL; 106 | i2s_lcd_obj->dma[i2s_lcd_obj->dma_node_cnt - 1].empty = (uint32_t)NULL; 107 | } 108 | 109 | static void lcd_dma_set_left(i2s_lcd_obj_t *i2s_lcd_obj, int pos, size_t len) 110 | { 111 | int end_pos = 0, size = 0; 112 | // Processing data length is an integer multiple of i2s_lcd_obj->dma_node_buffer_size 113 | if (len % i2s_lcd_obj->dma_node_buffer_size) { 114 | end_pos = (pos % 2) * i2s_lcd_obj->dma_half_node_cnt + len / i2s_lcd_obj->dma_node_buffer_size; 115 | size = len % i2s_lcd_obj->dma_node_buffer_size; 116 | } else { 117 | end_pos = (pos % 2) * i2s_lcd_obj->dma_half_node_cnt + len / i2s_lcd_obj->dma_node_buffer_size - 1; 118 | size = i2s_lcd_obj->dma_node_buffer_size; 119 | } 120 | // Process the tail node to make it a DMA tail 121 | i2s_lcd_obj->dma[end_pos].size = size; 122 | i2s_lcd_obj->dma[end_pos].length = size; 123 | i2s_lcd_obj->dma[end_pos].eof = 1; 124 | i2s_lcd_obj->dma[end_pos].empty = (uint32_t)NULL; 125 | } 126 | 127 | static void lcd_i2s_start(i2s_dev_t *i2s_dev, uint32_t addr, size_t len) 128 | { 129 | while (!i2s_dev->state.tx_idle); 130 | i2s_dev->conf.tx_start = 0; 131 | i2s_dev->conf.tx_reset = 1; 132 | i2s_dev->conf.tx_reset = 0; 133 | i2s_dev->conf.tx_fifo_reset = 1; 134 | i2s_dev->conf.tx_fifo_reset = 0; 135 | i2s_dev->out_link.addr = addr; 136 | i2s_dev->out_link.start = 1; 137 | ets_delay_us(1); 138 | i2s_dev->conf.tx_start = 1; 139 | } 140 | 141 | static void i2s_write_data(i2s_lcd_obj_t *i2s_lcd_obj, uint8_t *data, size_t len) 142 | { 143 | int event = 0; 144 | int x = 0, y = 0, left = 0, cnt = 0; 145 | if (len <= 0) { 146 | ESP_LOGE(TAG, "wrong len!"); 147 | return; 148 | } 149 | lcd_dma_set_int(i2s_lcd_obj); 150 | uint32_t half_buffer_size = i2s_lcd_obj->dma_half_buffer_size; 151 | cnt = len / half_buffer_size; 152 | // Start signal 153 | xQueueSend(i2s_lcd_obj->event_queue, &event, 0); 154 | // Process a complete piece of data, ping-pong operation 155 | for (x = 0; x < cnt; x++) { 156 | uint8_t *out = (uint8_t*)i2s_lcd_obj->dma[(x % 2) * i2s_lcd_obj->dma_half_node_cnt].buf; 157 | uint8_t *in = data; 158 | if (i2s_lcd_obj->swap_data) { 159 | uint8_t *out1 = out + 1; 160 | uint8_t *in1 = in + 1; 161 | for (y = 0; y < half_buffer_size;) { 162 | out1[y] = in[y]; 163 | out[y] = in1[y]; 164 | y += 2; 165 | out1[y] = in[y]; 166 | out[y] = in1[y]; 167 | y += 2; 168 | } 169 | } else { 170 | memcpy(out, in, half_buffer_size); 171 | } 172 | data += half_buffer_size; 173 | xQueueReceive(i2s_lcd_obj->event_queue, (void *)&event, portMAX_DELAY); 174 | lcd_i2s_start(i2s_lcd_obj->i2s_dev, ((uint32_t)&i2s_lcd_obj->dma[(x % 2) * i2s_lcd_obj->dma_half_node_cnt]) & 0xfffff, half_buffer_size); 175 | } 176 | left = len % half_buffer_size; 177 | // Process remaining incomplete segment data 178 | if (left) { 179 | uint8_t *out = (uint8_t*)i2s_lcd_obj->dma[(x % 2) * i2s_lcd_obj->dma_half_node_cnt].buf; 180 | uint8_t *in = data; 181 | cnt = left - left % 2; 182 | if (cnt) { 183 | if (i2s_lcd_obj->swap_data) { 184 | for (y = 0; y < cnt; y+=2) { 185 | out[y+1] = in[y+0]; 186 | out[y+0] = in[y+1]; 187 | } 188 | } else { 189 | memcpy(out, in, cnt); 190 | } 191 | } 192 | 193 | if (left % 2) { 194 | out[cnt] = in[cnt]; 195 | } 196 | lcd_dma_set_left(i2s_lcd_obj, x, left); 197 | xQueueReceive(i2s_lcd_obj->event_queue, (void *)&event, portMAX_DELAY); 198 | lcd_i2s_start(i2s_lcd_obj->i2s_dev, ((uint32_t)&i2s_lcd_obj->dma[(x % 2) * i2s_lcd_obj->dma_half_node_cnt]) & 0xfffff, left); 199 | } 200 | xQueueReceive(i2s_lcd_obj->event_queue, (void *)&event, portMAX_DELAY); 201 | } 202 | 203 | static esp_err_t i2s_lcd_reg_config(i2s_dev_t *i2s_dev, uint16_t data_width, uint32_t clk_freq) 204 | { 205 | // Configure the clock 206 | i2s_dev->clkm_conf.val = 0; 207 | i2s_dev->clkm_conf.clkm_div_num = 2; // 160MHz / 2 = 80MHz 208 | i2s_dev->clkm_conf.clkm_div_b = 0; 209 | i2s_dev->clkm_conf.clkm_div_a = 63; 210 | i2s_dev->clkm_conf.clk_sel = 2; 211 | i2s_dev->clkm_conf.clk_en = 1; 212 | 213 | // Configure sampling rate 214 | i2s_dev->sample_rate_conf.tx_bck_div_num = 40000000 / clk_freq; // Fws = Fbck / 2 215 | i2s_dev->sample_rate_conf.tx_bits_mod = data_width; 216 | 217 | i2s_dev->timing.val = 0; 218 | 219 | i2s_dev->int_ena.val = 0; 220 | i2s_dev->int_clr.val = ~0; 221 | 222 | i2s_dev->conf2.val = 0; 223 | i2s_dev->conf2.lcd_en = 1; 224 | 225 | // Configuration data format 226 | i2s_dev->conf.val = 0; 227 | i2s_dev->conf.tx_right_first = 1; 228 | i2s_dev->conf.tx_msb_right = 1; 229 | i2s_dev->conf.tx_dma_equal = 1; 230 | 231 | i2s_dev->conf1.tx_pcm_bypass = 1; 232 | i2s_dev->conf1.tx_stop_en = 1; 233 | 234 | i2s_dev->fifo_conf.val = 0; 235 | i2s_dev->fifo_conf.dscr_en = 1; 236 | i2s_dev->fifo_conf.tx_fifo_mod_force_en = 1; 237 | i2s_dev->fifo_conf.tx_data_num = 32; 238 | i2s_dev->fifo_conf.tx_fifo_mod = 2; 239 | i2s_dev->fifo_conf.tx_24msb_en = 0; 240 | 241 | i2s_dev->conf_chan.tx_chan_mod = 0;//remove 242 | i2s_dev->int_ena.out_eof = 1; 243 | return ESP_OK; 244 | } 245 | 246 | static esp_err_t lcd_set_pin(const i2s_lcd_config_t *config) 247 | { 248 | PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_num_wr], PIN_FUNC_GPIO); 249 | gpio_set_direction(config->pin_num_wr, GPIO_MODE_OUTPUT); 250 | gpio_set_pull_mode(config->pin_num_wr, GPIO_FLOATING); 251 | gpio_matrix_out(config->pin_num_wr, I2S0O_WS_OUT_IDX, true, false); 252 | 253 | for (int i = 0; i < config->data_width; i++) { 254 | PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_data_num[i]], PIN_FUNC_GPIO); 255 | gpio_set_direction(config->pin_data_num[i], GPIO_MODE_OUTPUT); 256 | gpio_set_pull_mode(config->pin_data_num[i], GPIO_FLOATING); 257 | // High bit aligned, OUT23 is always the highest bit 258 | gpio_matrix_out(config->pin_data_num[i], I2S0O_DATA_OUT0_IDX + (LCD_DATA_MAX_WIDTH - config->data_width) + i, false, false); 259 | } 260 | 261 | return ESP_OK; 262 | } 263 | 264 | static esp_err_t lcd_dma_config(i2s_lcd_obj_t *i2s_lcd_obj, uint32_t max_dma_buffer_size) 265 | { 266 | int cnt = 0; 267 | if (LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE % 2 != 0) { 268 | ESP_LOGE(TAG, "ESP32 only supports 2-byte aligned data length"); 269 | return ESP_FAIL; 270 | } 271 | if (max_dma_buffer_size >= LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE * 2) { 272 | i2s_lcd_obj->dma_node_buffer_size = LCD_CAM_DMA_NODE_BUFFER_MAX_SIZE; 273 | for (cnt = 0; cnt < max_dma_buffer_size - 8; cnt++) { // Find a buffer size that can divide dma_size 274 | if ((max_dma_buffer_size - cnt) % (i2s_lcd_obj->dma_node_buffer_size * 2) == 0) { 275 | break; 276 | } 277 | } 278 | i2s_lcd_obj->dma_buffer_size = max_dma_buffer_size - cnt; 279 | } else { 280 | i2s_lcd_obj->dma_node_buffer_size = max_dma_buffer_size / 2; 281 | i2s_lcd_obj->dma_buffer_size = i2s_lcd_obj->dma_node_buffer_size * 2; 282 | } 283 | 284 | i2s_lcd_obj->dma_half_buffer_size = i2s_lcd_obj->dma_buffer_size / 2; 285 | i2s_lcd_obj->dma_node_cnt = (i2s_lcd_obj->dma_buffer_size) / i2s_lcd_obj->dma_node_buffer_size; // Number of DMA nodes 286 | i2s_lcd_obj->dma_half_node_cnt = i2s_lcd_obj->dma_node_cnt / 2; 287 | 288 | ESP_LOGI(TAG, "lcd_buffer_size: %d, lcd_dma_size: %d, lcd_dma_node_cnt: %d", i2s_lcd_obj->dma_buffer_size, i2s_lcd_obj->dma_node_buffer_size, i2s_lcd_obj->dma_node_cnt); 289 | 290 | i2s_lcd_obj->dma = (lldesc_t *)heap_caps_malloc(i2s_lcd_obj->dma_node_cnt * sizeof(lldesc_t), MALLOC_CAP_DMA | MALLOC_CAP_8BIT); 291 | i2s_lcd_obj->dma_buffer = (uint8_t *)heap_caps_malloc(i2s_lcd_obj->dma_buffer_size * sizeof(uint8_t), MALLOC_CAP_DMA | MALLOC_CAP_8BIT); 292 | return ESP_OK; 293 | } 294 | 295 | static esp_err_t lcd_cam_deinit(i2s_lcd_driver_t *drv) 296 | { 297 | if (!drv->i2s_lcd_obj) { 298 | return ESP_FAIL; 299 | } 300 | 301 | if (drv->i2s_lcd_obj->event_queue) { 302 | vQueueDelete(drv->i2s_lcd_obj->event_queue); 303 | } 304 | if (drv->i2s_lcd_obj->dma) { 305 | heap_caps_free(drv->i2s_lcd_obj->dma); 306 | } 307 | if (drv->i2s_lcd_obj->dma_buffer) { 308 | heap_caps_free(drv->i2s_lcd_obj->dma_buffer); 309 | } 310 | 311 | if (drv->i2s_lcd_obj->lcd_cam_intr_handle) { 312 | esp_intr_free(drv->i2s_lcd_obj->lcd_cam_intr_handle); 313 | } 314 | 315 | heap_caps_free(drv->i2s_lcd_obj); 316 | drv->i2s_lcd_obj = NULL; 317 | return ESP_OK; 318 | } 319 | 320 | static esp_err_t lcd_cam_init(i2s_lcd_driver_t *drv, const i2s_lcd_config_t *config) 321 | { 322 | esp_err_t ret = ESP_OK; 323 | 324 | i2s_lcd_obj_t *i2s_lcd_obj = (i2s_lcd_obj_t *)heap_caps_calloc(1, sizeof(i2s_lcd_obj_t), MALLOC_CAP_DMA); 325 | if (i2s_lcd_obj == NULL) { 326 | ESP_LOGE(TAG, "lcd_cam object malloc error"); 327 | return ESP_ERR_NO_MEM; 328 | } 329 | drv->i2s_lcd_obj = i2s_lcd_obj; 330 | 331 | if (I2S_NUM_0 == config->i2s_port) { 332 | i2s_lcd_obj->i2s_dev = &I2S0; 333 | periph_module_enable(PERIPH_I2S0_MODULE); 334 | } else { 335 | ESP_LOGE(TAG, "Designated I2S peripheral not found"); 336 | } 337 | 338 | ret |= i2s_lcd_reg_config(i2s_lcd_obj->i2s_dev, config->data_width, config->clk_freq); 339 | 340 | if (ret != ESP_OK) { 341 | ESP_LOGE(TAG, "lcd_cam config fail!"); 342 | lcd_cam_deinit(drv); 343 | return ESP_FAIL; 344 | } 345 | 346 | ret |= lcd_set_pin(config); 347 | ret |= lcd_dma_config(i2s_lcd_obj, config->buffer_size); 348 | 349 | if (ret != ESP_OK) { 350 | ESP_LOGE(TAG, "lcd config fail!"); 351 | lcd_cam_deinit(drv); 352 | return ESP_FAIL; 353 | } 354 | 355 | i2s_lcd_obj->event_queue = xQueueCreate(1, sizeof(int)); 356 | i2s_lcd_obj->width = config->data_width; 357 | i2s_lcd_obj->swap_data = config->swap_data; 358 | 359 | if (i2s_lcd_obj->event_queue == NULL) { 360 | ESP_LOGE(TAG, "lcd config fail!"); 361 | lcd_cam_deinit(drv); 362 | return ESP_FAIL; 363 | } 364 | 365 | ret |= esp_intr_alloc(ETS_I2S0_INTR_SOURCE, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM, i2s_isr, i2s_lcd_obj, &i2s_lcd_obj->lcd_cam_intr_handle); 366 | 367 | if (ret != ESP_OK) { 368 | ESP_LOGE(TAG, "lcd_cam intr alloc fail!"); 369 | lcd_cam_deinit(drv); 370 | return ESP_FAIL; 371 | } 372 | 373 | ESP_LOGI(TAG, "lcd init ok"); 374 | 375 | return ESP_OK; 376 | } 377 | 378 | /**< Public functions */ 379 | 380 | i2s_lcd_handle_t i2s_lcd_driver_init(const i2s_lcd_config_t *config) 381 | { 382 | I2S_CHECK(NULL != config, "config pointer invalid", NULL); 383 | I2S_CHECK(GPIO_IS_VALID_GPIO(config->pin_num_wr), "GPIO WR invalid", NULL); 384 | I2S_CHECK(GPIO_IS_VALID_GPIO(config->pin_num_rs), "GPIO RS invalid", NULL); 385 | I2S_CHECK(config->data_width > 0 && config->data_width <= 16, "Bit width out of range", NULL); 386 | I2S_CHECK(0 == (config->data_width % 8), "Bit width must be a multiple of 8", NULL); 387 | uint64_t pin_mask = 0; 388 | for (size_t i = 0; i < config->data_width; i++) { 389 | uint64_t mask = 1ULL << config->pin_data_num[i]; 390 | I2S_CHECK(!(pin_mask & mask), "Data bus GPIO has a duplicate", NULL); 391 | I2S_CHECK(GPIO_IS_VALID_GPIO(config->pin_data_num[i]), "Data bus gpio invalid", NULL); 392 | pin_mask |= mask; 393 | } 394 | 395 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)heap_caps_malloc(sizeof(i2s_lcd_driver_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); 396 | I2S_CHECK(NULL != i2s_lcd_drv, "Error malloc handle of i2s lcd driver", NULL); 397 | 398 | esp_err_t ret = lcd_cam_init(i2s_lcd_drv, config); 399 | if(ESP_OK != ret) { 400 | ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, "i2s lcd driver initialize failed"); 401 | heap_caps_free(i2s_lcd_drv); 402 | return NULL; 403 | } 404 | 405 | i2s_lcd_drv->mutex = xSemaphoreCreateMutex(); 406 | if (i2s_lcd_drv->mutex == NULL) { 407 | ESP_LOGE(TAG, "%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, "lcd create mutex failed"); 408 | lcd_cam_deinit(i2s_lcd_drv); 409 | heap_caps_free(i2s_lcd_drv); 410 | return NULL; 411 | } 412 | 413 | if (config->pin_num_cs >= 0) { 414 | gpio_pad_select_gpio(config->pin_num_cs); 415 | gpio_set_direction(config->pin_num_cs, GPIO_MODE_OUTPUT); 416 | gpio_set_level(config->pin_num_cs, 0); 417 | } 418 | 419 | gpio_pad_select_gpio(config->pin_num_rs); 420 | gpio_set_direction(config->pin_num_rs, GPIO_MODE_OUTPUT); 421 | i2s_lcd_drv->rs_io_num = config->pin_num_rs; 422 | return (i2s_lcd_handle_t)i2s_lcd_drv; 423 | } 424 | 425 | esp_err_t i2s_lcd_driver_deinit(i2s_lcd_handle_t handle) 426 | { 427 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 428 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 429 | lcd_cam_deinit(i2s_lcd_drv); 430 | vSemaphoreDelete(i2s_lcd_drv->mutex); 431 | heap_caps_free(handle); 432 | return ESP_OK; 433 | } 434 | 435 | esp_err_t i2s_lcd_write_data(i2s_lcd_handle_t handle, uint16_t data) 436 | { 437 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 438 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 439 | i2s_write_data(i2s_lcd_drv->i2s_lcd_obj, (uint8_t *)&data, i2s_lcd_drv->i2s_lcd_obj->width == 16 ? 2 : 1); 440 | return ESP_OK; 441 | } 442 | 443 | esp_err_t i2s_lcd_write_cmd(i2s_lcd_handle_t handle, uint16_t cmd) 444 | { 445 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 446 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 447 | gpio_set_level(i2s_lcd_drv->rs_io_num, LCD_CMD_LEV); 448 | i2s_write_data(i2s_lcd_drv->i2s_lcd_obj, (uint8_t *)&cmd, i2s_lcd_drv->i2s_lcd_obj->width == 16 ? 2 : 1); 449 | gpio_set_level(i2s_lcd_drv->rs_io_num, LCD_DATA_LEV); 450 | return ESP_OK; 451 | } 452 | 453 | esp_err_t i2s_lcd_write_command(i2s_lcd_handle_t handle, const uint8_t *cmd, uint32_t length) 454 | { 455 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 456 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 457 | gpio_set_level(i2s_lcd_drv->rs_io_num, LCD_CMD_LEV); 458 | i2s_write_data(i2s_lcd_drv->i2s_lcd_obj, (uint8_t *)cmd, length); 459 | gpio_set_level(i2s_lcd_drv->rs_io_num, LCD_DATA_LEV); 460 | return ESP_OK; 461 | } 462 | 463 | esp_err_t i2s_lcd_write(i2s_lcd_handle_t handle, const uint8_t *data, uint32_t length) 464 | { 465 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 466 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 467 | i2s_write_data(i2s_lcd_drv->i2s_lcd_obj, (uint8_t*)data, length); 468 | 469 | return ESP_OK; 470 | } 471 | 472 | esp_err_t i2s_lcd_acquire(i2s_lcd_handle_t handle) 473 | { 474 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 475 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 476 | BaseType_t ret = xSemaphoreTake(i2s_lcd_drv->mutex, portMAX_DELAY); 477 | I2S_CHECK(pdTRUE == ret, "Take semaphore failed", ESP_FAIL); 478 | return ESP_OK; 479 | } 480 | 481 | esp_err_t i2s_lcd_release(i2s_lcd_handle_t handle) 482 | { 483 | i2s_lcd_driver_t *i2s_lcd_drv = (i2s_lcd_driver_t *)handle; 484 | I2S_CHECK(NULL != i2s_lcd_drv, "handle pointer invalid", ESP_ERR_INVALID_ARG); 485 | BaseType_t ret = xSemaphoreGive(i2s_lcd_drv->mutex); 486 | I2S_CHECK(pdTRUE == ret, "Give semaphore failed", ESP_FAIL); 487 | return ESP_OK; 488 | } 489 | 490 | #endif // CONFIG_IDF_TARGET_ESP32S2 491 | -------------------------------------------------------------------------------- /components/tft_library/lcd_com.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "freertos/FreeRTOS.h" 4 | #include "freertos/task.h" 5 | #include "esp_system.h" 6 | #include "esp_log.h" 7 | #include "soc/soc.h" 8 | #include "soc/dport_reg.h" 9 | #include "lcd_com.h" 10 | #include "i2s_lcd_driver.h" 11 | #include "hal/gpio_ll.h" // idf-py ver5 12 | #include "driver/gpio.h" 13 | #include "driver/adc_common.h" 14 | 15 | #define TAG "LCD_COM" 16 | 17 | #if CONFIG_CUSTOM_GPIO_CONFIG 18 | #define LCD_D0_PIN CONFIG_D0_GPIO 19 | #define LCD_D1_PIN CONFIG_D1_GPIO 20 | #define LCD_D2_PIN CONFIG_D2_GPIO 21 | #define LCD_D3_PIN CONFIG_D3_GPIO 22 | #define LCD_D4_PIN CONFIG_D4_GPIO 23 | #define LCD_D5_PIN CONFIG_D5_GPIO 24 | #define LCD_D6_PIN CONFIG_D6_GPIO 25 | #define LCD_D7_PIN CONFIG_D7_GPIO 26 | #define LCD_RD_PIN CONFIG_RD_GPIO 27 | #define LCD_WR_PIN CONFIG_WR_GPIO 28 | #define LCD_RS_PIN CONFIG_RS_GPIO 29 | #define LCD_CS_PIN CONFIG_CS_GPIO 30 | #define LCD_RESET_PIN CONFIG_RESET_GPIO 31 | #else 32 | #ifdef CONFIG_IDF_TARGET_ESP32 33 | #define LCD_D0_PIN (12) 34 | #define LCD_D1_PIN (13) 35 | #define LCD_D2_PIN (26) 36 | #define LCD_D3_PIN (25) 37 | #define LCD_D4_PIN (17) 38 | #define LCD_D5_PIN (16) 39 | #define LCD_D6_PIN (27) 40 | #define LCD_D7_PIN (14) 41 | #define LCD_RD_PIN (2) 42 | #define LCD_WR_PIN (4) 43 | #define LCD_RS_PIN (15) 44 | #define LCD_CS_PIN (33) 45 | #define LCD_RESET_PIN (32) 46 | #elif defined CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 47 | #define LCD_D0_PIN (1) 48 | #define LCD_D1_PIN (2) 49 | #define LCD_D2_PIN (3) 50 | #define LCD_D3_PIN (4) 51 | #define LCD_D4_PIN (5) 52 | #define LCD_D5_PIN (6) 53 | #define LCD_D6_PIN (11) 54 | #define LCD_D7_PIN (12) 55 | #define LCD_RD_PIN (39) 56 | #define LCD_WR_PIN (40) 57 | #define LCD_RS_PIN (41) 58 | #define LCD_CS_PIN (42) 59 | #define LCD_RESET_PIN (45) 60 | #endif 61 | #endif 62 | 63 | #define gpio_digital_write(GPIO_PIN, data) \ 64 | do { \ 65 | if (data) { \ 66 | gpio_set_level( GPIO_PIN, 1 ); \ 67 | } else { \ 68 | gpio_set_level( GPIO_PIN, 0 ); \ 69 | } \ 70 | } while (0) 71 | 72 | 73 | #define reg_digital_write(GPIO_PIN, data) \ 74 | do { \ 75 | if (data) { \ 76 | GPIO.out_w1ts = (1 << GPIO_PIN); \ 77 | } else { \ 78 | GPIO.out_w1tc = (1 << GPIO_PIN); \ 79 | } \ 80 | } while (0) 81 | 82 | void gpio_lcd_write_data(int dummy1, unsigned char *data, size_t size) { 83 | for (int i=0;i 0) { 118 | uint8_t cmd = *p++; 119 | uint8_t len = *p++; 120 | if (cmd == TFTLCD_DELAY8) { 121 | lcd_delay_ms(len); 122 | len = 0; 123 | } else { 124 | lcd_write_comm_byte(dev, cmd ); 125 | for (i = 0; i < len; i++) { 126 | uint8_t data = *p++; 127 | lcd_write_data_byte(dev, data ); 128 | } 129 | } 130 | size -= len + 2; 131 | } 132 | } 133 | 134 | void lcd_write_table16(TFT_t * dev, const void *table, int16_t size) 135 | { 136 | uint16_t *p = (uint16_t *) table; 137 | while (size > 0) { 138 | uint16_t cmd = *p++; 139 | uint16_t dat = *p++; 140 | if (cmd == TFTLCD_DELAY16) 141 | lcd_delay_ms(dat); 142 | else { 143 | lcd_write_register_word(dev, cmd, dat); 144 | } 145 | size -= 2 * sizeof(int16_t); 146 | } 147 | } 148 | 149 | 150 | void lcd_write_comm_byte(TFT_t * dev, uint8_t cmd) 151 | { 152 | unsigned char c[1]; 153 | c[0] = cmd; 154 | 155 | gpio_set_level(dev->_cs, 0); 156 | gpio_set_level(dev->_rs, 0); 157 | //gpio_set_level(dev->_rd, 1); 158 | if (dev->_interface == INTERFACE_I2S) { 159 | i2s_lcd_write(dev->i2s_lcd_handle, c, 1); 160 | } else if (dev->_interface == INTERFACE_GPIO) { 161 | gpio_lcd_write_data(GPIO_PORT_NUM, c, 1); 162 | } else if (dev->_interface == INTERFACE_REG) { 163 | reg_lcd_write_data(GPIO_PORT_NUM, c, 1); 164 | } 165 | gpio_set_level(dev->_cs, 1); 166 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 167 | } 168 | 169 | void lcd_write_comm_word(TFT_t * dev, uint16_t cmd) 170 | { 171 | unsigned char c[2]; 172 | c[0] = (cmd >> 8) & 0xFF; 173 | c[1] = cmd & 0xFF; 174 | 175 | gpio_set_level(dev->_cs, 0); 176 | gpio_set_level(dev->_rs, 0); 177 | //gpio_set_level(dev->_rd, 1); 178 | if (dev->_interface == INTERFACE_I2S) { 179 | i2s_lcd_write(dev->i2s_lcd_handle, c, 2); 180 | } else if (dev->_interface == INTERFACE_GPIO) { 181 | gpio_lcd_write_data(GPIO_PORT_NUM, c, 2); 182 | } else if (dev->_interface == INTERFACE_REG) { 183 | reg_lcd_write_data(GPIO_PORT_NUM, c, 2); 184 | } 185 | gpio_set_level(dev->_cs, 1); 186 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 187 | } 188 | 189 | void lcd_write_data_byte(TFT_t * dev, uint8_t data) 190 | { 191 | unsigned char d[1]; 192 | d[0] = data; 193 | 194 | gpio_set_level(dev->_cs, 0); 195 | gpio_set_level(dev->_rs, 1); 196 | //gpio_set_level(dev->_rd, 1); 197 | if (dev->_interface == INTERFACE_I2S) { 198 | i2s_lcd_write(dev->i2s_lcd_handle, d, 1); 199 | } else if (dev->_interface == INTERFACE_GPIO) { 200 | gpio_lcd_write_data(GPIO_PORT_NUM, d, 1); 201 | } else if (dev->_interface == INTERFACE_REG) { 202 | reg_lcd_write_data(GPIO_PORT_NUM, d, 1); 203 | } 204 | gpio_set_level(dev->_cs, 1); 205 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 206 | } 207 | 208 | 209 | void lcd_write_data_word(TFT_t * dev, uint16_t data) 210 | { 211 | unsigned char d[2]; 212 | d[0] = (data >> 8) & 0xFF; 213 | d[1] = data & 0xFF; 214 | 215 | gpio_set_level(dev->_cs, 0); 216 | gpio_set_level(dev->_rs, 1); 217 | //gpio_set_level(dev->_rd, 1); 218 | if (dev->_interface == INTERFACE_I2S) { 219 | i2s_lcd_write(dev->i2s_lcd_handle, d, 2); 220 | } else if (dev->_interface == INTERFACE_GPIO) { 221 | gpio_lcd_write_data(GPIO_PORT_NUM, d, 2); 222 | } else if (dev->_interface == INTERFACE_REG) { 223 | reg_lcd_write_data(GPIO_PORT_NUM, d, 2); 224 | } 225 | gpio_set_level(dev->_cs, 1); 226 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 227 | } 228 | 229 | void lcd_write_addr(TFT_t * dev, uint16_t addr1, uint16_t addr2) 230 | { 231 | unsigned char c[4]; 232 | c[0] = (addr1 >> 8) & 0xFF; 233 | c[1] = addr1 & 0xFF; 234 | c[2] = (addr2 >> 8) & 0xFF; 235 | c[3] = addr2 & 0xFF; 236 | //ESP_LOGI(__FUNCTION__, "c=%02x-%02x-%02x-%02x",c[0],c[1],c[2],c[3]); 237 | 238 | gpio_set_level(dev->_cs, 0); 239 | gpio_set_level(dev->_rs, 1); 240 | //gpio_set_level(dev->_rd, 1); 241 | if (dev->_interface == INTERFACE_I2S) { 242 | i2s_lcd_write(dev->i2s_lcd_handle, c, 4); 243 | } else if (dev->_interface == INTERFACE_GPIO) { 244 | gpio_lcd_write_data(GPIO_PORT_NUM, c, 4); 245 | } else if (dev->_interface == INTERFACE_REG) { 246 | reg_lcd_write_data(GPIO_PORT_NUM, c, 4); 247 | } 248 | gpio_set_level(dev->_cs, 1); 249 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 250 | } 251 | 252 | void lcd_write_color(TFT_t * dev, uint16_t color, uint16_t size) 253 | { 254 | unsigned char *data; 255 | if ((data = malloc(size * 2)) == NULL) return; 256 | int index = 0; 257 | for(int i=0;i> 8) & 0xFF; 259 | data[index++] = color & 0xFF; 260 | } 261 | 262 | gpio_set_level(dev->_cs, 0); 263 | gpio_set_level(dev->_rs, 1); 264 | //gpio_set_level(dev->_rd, 1); 265 | if (dev->_interface == INTERFACE_I2S) { 266 | i2s_lcd_write(dev->i2s_lcd_handle, data, size*2); 267 | } else if (dev->_interface == INTERFACE_GPIO) { 268 | gpio_lcd_write_data(GPIO_PORT_NUM, data, size*2); 269 | } else if (dev->_interface == INTERFACE_REG) { 270 | reg_lcd_write_data(GPIO_PORT_NUM, data, size*2); 271 | } 272 | gpio_set_level(dev->_cs, 1); 273 | free(data); 274 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 275 | } 276 | 277 | void lcd_write_colors(TFT_t * dev, uint16_t * colors, uint16_t size) 278 | { 279 | unsigned char *data; 280 | if ((data = malloc(size * 2)) == NULL) return; 281 | int index = 0; 282 | for(int i=0;i> 8) & 0xFF; 284 | data[index++] = colors[i] & 0xFF; 285 | } 286 | 287 | gpio_set_level(dev->_cs, 0); 288 | gpio_set_level(dev->_rs, 1); 289 | //gpio_set_level(dev->_rd, 1); 290 | if (dev->_interface == INTERFACE_I2S) { 291 | i2s_lcd_write(dev->i2s_lcd_handle, data, size*2); 292 | } else if (dev->_interface == INTERFACE_GPIO) { 293 | gpio_lcd_write_data(GPIO_PORT_NUM, data, size*2); 294 | } else if (dev->_interface == INTERFACE_REG) { 295 | reg_lcd_write_data(GPIO_PORT_NUM, data, size*2); 296 | } 297 | gpio_set_level(dev->_cs, 1); 298 | free(data); 299 | if (dev->_delay != 0) esp_rom_delay_us(dev->_delay); 300 | } 301 | 302 | void lcd_delay_ms(int delay_time) 303 | { 304 | vTaskDelay(delay_time/portTICK_PERIOD_MS); 305 | } 306 | 307 | void lcd_write_register_word(TFT_t * dev, uint16_t addr, uint16_t data) 308 | { 309 | lcd_write_comm_word(dev, addr); 310 | lcd_write_data_word(dev, data); 311 | } 312 | 313 | void lcd_write_register_byte(TFT_t * dev, uint8_t addr, uint16_t data) 314 | { 315 | lcd_write_comm_byte(dev, addr); 316 | lcd_write_data_word(dev, data); 317 | } 318 | 319 | #define BOARD_LCD_I2S_BITWIDTH 8 320 | 321 | esp_err_t lcd_interface_cfg(TFT_t * dev, int interface) 322 | { 323 | #if 0 324 | if (interface == INTERFACE_I2S) { 325 | ESP_LOGI(TAG, "interface=I2S"); 326 | } else if (interface == INTERFACE_GPIO) { 327 | ESP_LOGI(TAG, "interface=GPIO"); 328 | } 329 | #endif 330 | ESP_LOGI(TAG, "LCD_CS_PIN=%d",LCD_CS_PIN); 331 | gpio_reset_pin( LCD_CS_PIN ); 332 | gpio_set_direction( LCD_CS_PIN, GPIO_MODE_OUTPUT ); 333 | gpio_set_level( LCD_CS_PIN, 1 ); 334 | 335 | ESP_LOGI(TAG, "LCD_RS_PIN=%d",LCD_RS_PIN); 336 | gpio_reset_pin( LCD_RS_PIN ); 337 | gpio_set_direction(LCD_RS_PIN, GPIO_MODE_OUTPUT); 338 | gpio_set_level( LCD_RS_PIN, 1 ); 339 | 340 | #if 0 341 | ESP_LOGI(TAG, "LCD_WR_PIN=%d",LCD_WR_PIN); 342 | gpio_reset_pin( LCD_WR_PIN ); 343 | gpio_set_direction( LCD_WR_PIN, GPIO_MODE_OUTPUT ); 344 | gpio_set_level( LCD_WR_PIN, 1 ); 345 | #endif 346 | 347 | ESP_LOGI(TAG, "LCD_RD_PIN=%d",LCD_RD_PIN); 348 | gpio_reset_pin( LCD_RD_PIN ); 349 | gpio_set_direction( LCD_RD_PIN, GPIO_MODE_OUTPUT ); 350 | gpio_set_level( LCD_RD_PIN, 1 ); 351 | 352 | ESP_LOGI(TAG, "LCD_D0_PIN=%d",LCD_D0_PIN); 353 | ESP_LOGI(TAG, "LCD_D1_PIN=%d",LCD_D1_PIN); 354 | ESP_LOGI(TAG, "LCD_D2_PIN=%d",LCD_D2_PIN); 355 | ESP_LOGI(TAG, "LCD_D3_PIN=%d",LCD_D3_PIN); 356 | ESP_LOGI(TAG, "LCD_D4_PIN=%d",LCD_D4_PIN); 357 | ESP_LOGI(TAG, "LCD_D5_PIN=%d",LCD_D5_PIN); 358 | ESP_LOGI(TAG, "LCD_D6_PIN=%d",LCD_D6_PIN); 359 | ESP_LOGI(TAG, "LCD_D7_PIN=%d",LCD_D7_PIN); 360 | 361 | if (interface == INTERFACE_I2S) { 362 | ESP_LOGI(TAG, "INTERFACE is I2S"); 363 | i2s_lcd_config_t i2s_lcd_cfg = { 364 | .data_width = BOARD_LCD_I2S_BITWIDTH, 365 | .pin_data_num = { 366 | LCD_D0_PIN, 367 | LCD_D1_PIN, 368 | LCD_D2_PIN, 369 | LCD_D3_PIN, 370 | LCD_D4_PIN, 371 | LCD_D5_PIN, 372 | LCD_D6_PIN, 373 | LCD_D7_PIN, 374 | //BOARD_LCD_I2S_D8_PIN, 375 | //BOARD_LCD_I2S_D9_PIN, 376 | //BOARD_LCD_I2S_D10_PIN, 377 | //BOARD_LCD_I2S_D11_PIN, 378 | //BOARD_LCD_I2S_D12_PIN, 379 | //BOARD_LCD_I2S_D13_PIN, 380 | //BOARD_LCD_I2S_D14_PIN, 381 | //BOARD_LCD_I2S_D15_PIN, 382 | }, 383 | .pin_num_cs = LCD_CS_PIN, 384 | .pin_num_wr = LCD_WR_PIN, 385 | .pin_num_rs = LCD_RS_PIN, 386 | 387 | .clk_freq = 20000000, 388 | .i2s_port = I2S_NUM_0, 389 | .buffer_size = 32000, 390 | .swap_data = false, 391 | }; 392 | 393 | 394 | //i2s_lcd_handle_t i2s_lcd_handle; 395 | dev->i2s_lcd_handle = i2s_lcd_driver_init(&i2s_lcd_cfg); 396 | if (NULL == dev->i2s_lcd_handle) { 397 | ESP_LOGE(TAG, "%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, "screen 8080 interface create failed"); 398 | return ESP_FAIL; 399 | } 400 | 401 | } else if (interface == INTERFACE_GPIO || interface == INTERFACE_REG) { 402 | if (interface == INTERFACE_GPIO) { 403 | ESP_LOGI(TAG, "INTERFACE is GPIO"); 404 | } else { 405 | ESP_LOGI(TAG, "INTERFACE is REGISTER I/O"); 406 | } 407 | gpio_reset_pin( LCD_D0_PIN ); 408 | gpio_reset_pin( LCD_D1_PIN ); 409 | gpio_reset_pin( LCD_D2_PIN ); 410 | gpio_reset_pin( LCD_D3_PIN ); 411 | gpio_reset_pin( LCD_D4_PIN ); 412 | gpio_reset_pin( LCD_D5_PIN ); 413 | gpio_reset_pin( LCD_D6_PIN ); 414 | gpio_reset_pin( LCD_D7_PIN ); 415 | gpio_reset_pin( LCD_WR_PIN ); 416 | gpio_set_direction( LCD_D0_PIN, GPIO_MODE_OUTPUT ); 417 | gpio_set_direction( LCD_D1_PIN, GPIO_MODE_OUTPUT ); 418 | gpio_set_direction( LCD_D2_PIN, GPIO_MODE_OUTPUT ); 419 | gpio_set_direction( LCD_D3_PIN, GPIO_MODE_OUTPUT ); 420 | gpio_set_direction( LCD_D4_PIN, GPIO_MODE_OUTPUT ); 421 | gpio_set_direction( LCD_D5_PIN, GPIO_MODE_OUTPUT ); 422 | gpio_set_direction( LCD_D6_PIN, GPIO_MODE_OUTPUT ); 423 | gpio_set_direction( LCD_D7_PIN, GPIO_MODE_OUTPUT ); 424 | gpio_set_direction( LCD_WR_PIN, GPIO_MODE_OUTPUT ); 425 | gpio_set_level( LCD_WR_PIN, 1 ); 426 | dev->_d0 = LCD_D0_PIN; 427 | dev->_d1 = LCD_D1_PIN; 428 | dev->_d2 = LCD_D2_PIN; 429 | dev->_d3 = LCD_D3_PIN; 430 | dev->_d4 = LCD_D4_PIN; 431 | dev->_d5 = LCD_D5_PIN; 432 | dev->_d6 = LCD_D6_PIN; 433 | dev->_d7 = LCD_D7_PIN; 434 | } 435 | 436 | 437 | ESP_LOGI(TAG, "LCD_RESET_PIN=%d",LCD_RESET_PIN); 438 | gpio_reset_pin( LCD_RESET_PIN ); 439 | gpio_set_direction( LCD_RESET_PIN, GPIO_MODE_OUTPUT ); 440 | gpio_set_level( LCD_RESET_PIN, 1 ); 441 | vTaskDelay( pdMS_TO_TICKS( 100 ) ); 442 | gpio_set_level( LCD_RESET_PIN, 0 ); 443 | vTaskDelay( pdMS_TO_TICKS( 100 ) ); 444 | gpio_set_level( LCD_RESET_PIN, 1 ); 445 | 446 | dev->_rd = LCD_RD_PIN; 447 | dev->_wr = LCD_WR_PIN; 448 | dev->_rs = LCD_RS_PIN; 449 | dev->_cs = LCD_CS_PIN; 450 | dev->_interface = interface; 451 | 452 | return ESP_OK; 453 | } 454 | 455 | void touch_interface_cfg(TFT_t * dev, int adc_yp, int adc_xm, int gpio_xp, int gpio_xm, int gpio_yp, int gpio_ym) 456 | { 457 | ESP_LOGI(TAG, "_adc_yp=%d _adc_xm=%d", dev->_adc_yp, dev->_adc_xm); 458 | ESP_LOGI(TAG, "_gpio_xp=%d _gpio_xm=%d", gpio_xp, gpio_xm); 459 | dev->_calibration = true; 460 | dev->_adc_yp = adc_yp; 461 | dev->_adc_xm = adc_xm; 462 | //dev->_gpio_xp = dev->_d6; 463 | //dev->_gpio_xm = dev->_rs; 464 | //dev->_gpio_yp = dev->_wr; 465 | //dev->_gpio_ym = dev->_d7; 466 | dev->_gpio_xp = gpio_xp; 467 | dev->_gpio_xm = gpio_xm; 468 | dev->_gpio_yp = gpio_yp; 469 | dev->_gpio_ym = gpio_ym; 470 | } 471 | 472 | int touch_avr_analog(adc1_channel_t channel, int averagetime) 473 | { 474 | if (averagetime > 2) { 475 | int sum = 0; 476 | int max = 0; 477 | int min = 1024; 478 | for(int i = 0; i 10 bits. 483 | } 484 | if (ADC_WIDTH_BIT_DEFAULT == 3) { 485 | tmp = tmp / 4; // 12 bits -> 10 bits. 486 | } 487 | if (ADC_WIDTH_BIT_DEFAULT == 4) { 488 | tmp = tmp / 8; // 13 bits -> 10 bits. 489 | } 490 | if(tmp > max)max = tmp; 491 | if(tmp < min)min = tmp; 492 | sum += tmp; 493 | // sum+=analogRead(adpin); 494 | } 495 | return (sum-min-max)/(averagetime-2); 496 | } else { 497 | return 0; 498 | } 499 | } 500 | 501 | void touch_gpio(int gpio, int mode, int level) 502 | { 503 | esp_log_level_set("gpio", ESP_LOG_WARN); 504 | gpio_reset_pin(gpio); 505 | gpio_config_t io_conf = {}; 506 | io_conf.pin_bit_mask = (1ULL<_gpio_yp, MODE_INPUT, 0); 523 | touch_gpio(dev->_gpio_ym, MODE_INPUT, 0); 524 | touch_gpio(dev->_gpio_xp, MODE_OUTPUT, 1); 525 | touch_gpio(dev->_gpio_xm, MODE_OUTPUT, 0); 526 | 527 | //ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_10Bit)); 528 | ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT)); 529 | ESP_ERROR_CHECK(adc1_config_channel_atten(dev->_adc_yp, ADC_ATTEN_DB_11)); 530 | int samples[NUMSAMPLES]; 531 | for (int i=0; i_adc_yp, AVERAGETIME); 533 | } 534 | int icomp = samples[0] > samples[1]? samples[0] - samples[1]: samples[1] - samples[0]; 535 | ESP_LOGD(TAG, "touch_getx adc=%d samples[0]=%d samples[1]=%d icomp=%d COMP=%d", dev->_adc_yp, samples[0], samples[1], icomp, COMP); 536 | if(icomp <= COMP) xp = samples[0] + samples[1]; 537 | return xp; 538 | } 539 | 540 | int touch_gety(TFT_t * dev) 541 | { 542 | int yp = 0; 543 | touch_gpio(dev->_gpio_yp, MODE_OUTPUT, 1); 544 | touch_gpio(dev->_gpio_ym, MODE_OUTPUT, 0); 545 | touch_gpio(dev->_gpio_xp, MODE_INPUT, 0); 546 | touch_gpio(dev->_gpio_xm, MODE_INPUT, 0); 547 | 548 | //ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_10Bit)); 549 | ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT)); 550 | ESP_ERROR_CHECK(adc1_config_channel_atten(dev->_adc_xm, ADC_ATTEN_DB_11)); 551 | int samples[NUMSAMPLES]; 552 | for (int i=0; i_adc_xm, AVERAGETIME); 554 | } 555 | int icomp = samples[0] > samples[1]? samples[0] - samples[1]: samples[1] - samples[0]; 556 | ESP_LOGD(TAG, "adc=%d samples[0]=%d samples[1]=%d icomp=%d COMP=%d", dev->_adc_xm, samples[0], samples[1], icomp, COMP); 557 | if(icomp <= COMP) yp = samples[0] + samples[1]; 558 | return yp; 559 | 560 | } 561 | 562 | int touch_getz(TFT_t * dev) 563 | { 564 | touch_gpio(dev->_gpio_yp, MODE_INPUT, 0); 565 | touch_gpio(dev->_gpio_ym, MODE_OUTPUT, 1); 566 | touch_gpio(dev->_gpio_xp, MODE_OUTPUT, 0); 567 | touch_gpio(dev->_gpio_xm, MODE_INPUT, 0); 568 | 569 | //ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_10Bit)); 570 | ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT)); 571 | ESP_ERROR_CHECK(adc1_config_channel_atten(dev->_adc_yp, ADC_ATTEN_DB_11)); 572 | ESP_ERROR_CHECK(adc1_config_channel_atten(dev->_adc_xm, ADC_ATTEN_DB_11)); 573 | int z1 = adc1_get_raw(dev->_adc_yp); 574 | int z2 = adc1_get_raw(dev->_adc_xm); 575 | 576 | if (ADC_WIDTH_BIT_DEFAULT == 2) { 577 | z1 = z1 / 2; // 11 bits -> 10 bits. 578 | z2 = z2 / 2; // 11 bits -> 10 bits. 579 | } 580 | if (ADC_WIDTH_BIT_DEFAULT == 3) { 581 | z1 = z1 / 4; // 12 bits -> 10 bits. 582 | z2 = z2 / 4; // 12 bits -> 10 bits. 583 | } 584 | if (ADC_WIDTH_BIT_DEFAULT == 4) { 585 | z1 = z1 / 8; // 13 bits -> 10 bits. 586 | z2 = z2 / 8; // 13 bits -> 10 bits. 587 | } 588 | 589 | int icomp = z1 > z2? z1 - z2: z2 - z1; 590 | ESP_LOGD(TAG, "z1=%d z2=%d icomp=%d", z1, z2, icomp); 591 | return icomp; 592 | 593 | #if 0 594 | float rtouch = 0; 595 | rtouch = z2; 596 | rtouch /= z1; 597 | rtouch -= 1; 598 | rtouch *= (2046-dev->_rawxp)/2; 599 | rtouch *= RXPLATE; 600 | rtouch /= 1024; 601 | ESP_LOGI(pcTaskGetTaskName(0), "rtouch=%f", rtouch); 602 | return rtouch; 603 | #endif 604 | } 605 | 606 | void touch_getxyz(TFT_t * dev, int *xp, int *yp, int *zp) 607 | { 608 | #if CONFIG_SWAP_XY 609 | *yp = touch_getx(dev); 610 | *xp = touch_gety(dev); 611 | #else 612 | *xp = touch_getx(dev); 613 | *yp = touch_gety(dev); 614 | #endif 615 | *zp = touch_getz(dev); 616 | touch_gpio(dev->_gpio_yp, MODE_OUTPUT, 0); 617 | touch_gpio(dev->_gpio_ym, MODE_OUTPUT, 0); 618 | touch_gpio(dev->_gpio_xp, MODE_OUTPUT, 0); 619 | touch_gpio(dev->_gpio_xm, MODE_OUTPUT, 0); 620 | } 621 | 622 | bool touch_getxy(TFT_t *dev, int *xp, int *yp) 623 | { 624 | int _xp; 625 | int _yp; 626 | int _zp; 627 | touch_getxyz(dev, &_xp, &_yp, &_zp); 628 | if (_xp == 0) return false; 629 | if (_yp == 0) return false; 630 | if (_zp == 1023) return false; 631 | *xp = _xp; 632 | *yp = _yp; 633 | return true; 634 | } 635 | --------------------------------------------------------------------------------