From 9e47ceebf965d82655fe338cf6843a4e5bd4c87f Mon Sep 17 00:00:00 2001 From: xrip Date: Thu, 11 Jan 2024 10:11:49 +0300 Subject: [PATCH] TFT display pins updated: TFT_CS_PIN (6) TFT_RST_PIN (8) TFT_DC_PIN (10) TFT_DATA_PIN (12) TFT_CLK_PIN (13) TFT_LED_PIN (9) --- CMakeLists.txt | 6 ++++++ drivers/st7789/st7789.c | 30 +++++++++++++++--------------- drivers/st7789/st7789.h | 24 ++++++++++++------------ 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d4f305..c40fe57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,12 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE #BUILD_IN_GAMES #TFT + TFT_CS_PIN=6 + TFT_RST_PIN=8 + TFT_DC_PIN=10 + TFT_DATA_PIN=12 + TFT_CLK_PIN=13 + TFT_LED_PIN=9 ) pico_add_extra_outputs(${PROJECT_NAME}) diff --git a/drivers/st7789/st7789.c b/drivers/st7789/st7789.c index 8bc7b2b..57c5fac 100644 --- a/drivers/st7789/st7789.c +++ b/drivers/st7789/st7789.c @@ -66,7 +66,7 @@ static const uint8_t init_seq[] = { static inline void lcd_set_dc_cs(const bool dc, const bool cs) { sleep_us(5); - gpio_put_masked((1u << PIN_DC) | (1u << PIN_CS), !!dc << PIN_DC | !!cs << PIN_CS); + gpio_put_masked((1u << TFT_DC_PIN) | (1u << TFT_CS_PIN), !!dc << TFT_DC_PIN | !!cs << TFT_CS_PIN); sleep_us(5); } @@ -117,21 +117,21 @@ static inline void start_pixels() { void graphics_init() { const uint offset = pio_add_program(pio, &st7789_lcd_program); sm = pio_claim_unused_sm(pio, true); - st7789_lcd_program_init(pio, sm, offset, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV); - - gpio_init(PIN_CS); - gpio_init(PIN_DC); - gpio_init(PIN_RESET); - gpio_init(PIN_BL); - gpio_set_dir(PIN_CS, GPIO_OUT); - gpio_set_dir(PIN_DC, GPIO_OUT); - gpio_set_dir(PIN_RESET, GPIO_OUT); - gpio_set_dir(PIN_BL, GPIO_OUT); - - gpio_put(PIN_CS, 1); - gpio_put(PIN_RESET, 1); + st7789_lcd_program_init(pio, sm, offset, TFT_DATA_PIN, TFT_CLK_PIN, SERIAL_CLK_DIV); + + gpio_init(TFT_CS_PIN); + gpio_init(TFT_DC_PIN); + gpio_init(TFT_RST_PIN); + gpio_init(TFT_LED_PIN); + gpio_set_dir(TFT_CS_PIN, GPIO_OUT); + gpio_set_dir(TFT_DC_PIN, GPIO_OUT); + gpio_set_dir(TFT_RST_PIN, GPIO_OUT); + gpio_set_dir(TFT_LED_PIN, GPIO_OUT); + + gpio_put(TFT_CS_PIN, 1); + gpio_put(TFT_RST_PIN, 1); lcd_init(init_seq); - gpio_put(PIN_BL, 1); + gpio_put(TFT_LED_PIN, 1); for (int i = 0; i < sizeof palette; i++ ) { graphics_set_palette(i, 0x0000); } diff --git a/drivers/st7789/st7789.h b/drivers/st7789/st7789.h index 04b6f85..0746f62 100644 --- a/drivers/st7789/st7789.h +++ b/drivers/st7789/st7789.h @@ -1,31 +1,31 @@ #ifndef _ST7789_LCD_H_ #define _ST7789_LCD_H_ -#ifndef PIN_RESET -#define PIN_RESET 6 +#ifndef TFT_RST_PIN +#define TFT_RST_PIN 8 #endif -#ifndef PIN_CS -#define PIN_CS 7 +#ifndef TFT_CS_PIN +#define TFT_CS_PIN 6 #endif -#ifndef PIN_BL -#define PIN_BL 8 +#ifndef TFT_LED_PIN +#define TFT_LED_PIN 9 #endif -#ifndef PIN_CLK -#define PIN_CLK 10 +#ifndef TFT_CLK_PIN +#define TFT_CLK_PIN 13 #endif -#ifndef PIN_DIN -#define PIN_DIN 11 +#ifndef TFT_DATA_PIN +#define TFT_DATA_PIN 12 #endif -#ifndef PIN_DC -#define PIN_DC 13 +#ifndef TFT_DC_PIN +#define TFT_DC_PIN 10 #endif #define TEXTMODE_COLS 53