From 0eead42aec954565a4d338b3da0edd94493a9493 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 5 Jan 2024 16:59:16 +0700 Subject: [PATCH] add display for sense tft --- Makefile | 3 ++ src/boards/boards.c | 42 +++++++++---------- src/boards/feather_nrf52840_sense_tft/board.h | 28 ++++++++++++- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 866d4a63..17fa1050 100644 --- a/Makefile +++ b/Makefile @@ -139,6 +139,8 @@ C_SRC += \ src/dfu_init.c \ src/flash_nrf5x.c \ src/main.c \ + src/screen.c \ + src/images.c \ # all files in boards C_SRC += src/boards/boards.c @@ -314,6 +316,7 @@ ifneq ($(USE_NFCT),yes) endif CFLAGS += -DSOFTDEVICE_PRESENT +CFLAGS += -DUF2_VERSION_BASE='"$(GIT_VERSION)"' CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS)"' CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"' diff --git a/src/boards/boards.c b/src/boards/boards.c index 4ab04be5..563ed6f1 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -181,6 +181,14 @@ void board_teardown(void) { //--------------------------------------------------------------------+ #ifdef DISPLAY_PIN_SCK +#define TFT_MADCTL_MY 0x80 ///< Page addr order: Bottom to top +#define TFT_MADCTL_MX 0x40 ///< Column addr order: Right to left +#define TFT_MADCTL_MV 0x20 ///< Page/Column order: Reverse Mode ( X <-> Y ) +#define TFT_MADCTL_ML 0x10 ///< LCD refresh Bottom to top +#define TFT_MADCTL_MH 0x04 ///< LCD refresh right to left +#define TFT_MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order +#define TFT_MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order + // Note don't use SPIM3 since it has lots of errata NRF_SPIM_Type* _spim = NRF_SPIM0; @@ -199,19 +207,11 @@ static void spi_write(NRF_SPIM_Type *p_spim, uint8_t const *tx_buf, size_t tx_le static void tft_controller_init(void); static inline void tft_cs(bool state) { - if (state) { - nrf_gpio_pin_set(DISPLAY_PIN_CS); - } else { - nrf_gpio_pin_clear(DISPLAY_PIN_CS); - } + nrf_gpio_pin_write(DISPLAY_PIN_CS, state); } static inline void tft_dc(bool state) { - if (state) { - nrf_gpio_pin_set(DISPLAY_PIN_DC); - } else { - nrf_gpio_pin_clear(DISPLAY_PIN_DC); - } + nrf_gpio_pin_write(DISPLAY_PIN_DC, state); } static void tft_cmd(uint8_t cmd, uint8_t const* data, size_t narg) { @@ -250,17 +250,17 @@ void board_display_init(void) { //------------- Display Init -------------// nrf_gpio_cfg_output(DISPLAY_PIN_DC); - #if defined(DISPLAY_PIN_RST) && DISPLAY_PIN_RST >= 0 +#if defined(DISPLAY_PIN_RST) && DISPLAY_PIN_RST >= 0 nrf_gpio_cfg_output(DISPLAY_PIN_RST); - nrf_gpio_pin_write(DISPLAY_PIN_RST, 0); + nrf_gpio_pin_clear(DISPLAY_PIN_RST); NRFX_DELAY_MS(10); - nrf_gpio_pin_write(DISPLAY_PIN_RST, 1); - #endif + nrf_gpio_pin_set(DISPLAY_PIN_RST); +#endif - #if defined(DISPLAY_PIN_BL) && DISPLAY_PIN_BL >= 0 +#if defined(DISPLAY_PIN_BL) && DISPLAY_PIN_BL >= 0 nrf_gpio_cfg_output(DISPLAY_PIN_BL); nrf_gpio_pin_write(DISPLAY_PIN_BL, DISPLAY_BL_ON); - #endif +#endif tft_controller_init(); } @@ -667,13 +667,9 @@ void neopixel_write (uint8_t *pixels) { } #endif -#define TFT_MADCTL_MY 0x80 ///< Page addr order: Bottom to top -#define TFT_MADCTL_MX 0x40 ///< Column addr order: Right to left -#define TFT_MADCTL_MV 0x20 ///< Page/Column order: Reverse Mode ( X <-> Y ) -#define TFT_MADCTL_ML 0x10 ///< LCD refresh Bottom to top -#define TFT_MADCTL_MH 0x04 ///< LCD refresh right to left -#define TFT_MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order -#define TFT_MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order +//--------------------------------------------------------------------+ +// Display controller +//--------------------------------------------------------------------+ #ifdef DISPLAY_CONTROLLER_ST7789 diff --git a/src/boards/feather_nrf52840_sense_tft/board.h b/src/boards/feather_nrf52840_sense_tft/board.h index 3dcea991..902e75ce 100644 --- a/src/boards/feather_nrf52840_sense_tft/board.h +++ b/src/boards/feather_nrf52840_sense_tft/board.h @@ -47,6 +47,32 @@ #define BUTTON_2 _PINNUM(1, 10) // DFU pin #define BUTTON_PULL NRF_GPIO_PIN_PULLUP +//--------------------------------------------------------------------+ +// Display +//--------------------------------------------------------------------+ +#define DISPLAY_CONTROLLER_ST7789 + +#define DISPLAY_PIN_MOSI _PINNUM(0, 5) +#define DISPLAY_PIN_SCK _PINNUM(0, 26) + +#define DISPLAY_PIN_CS _PINNUM(1, 5) +#define DISPLAY_PIN_DC _PINNUM(1, 1) +#define DISPLAY_PIN_RST _PINNUM(1, 3) +#define DISPLAY_PIN_BL _PINNUM(0, 27) +#define DISPLAY_BL_ON 1 // GPIO state to enable back light + +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 135 + +#define DISPLAY_COL_OFFSET 53 +#define DISPLAY_ROW_OFFSET 40 + +// Memory Data Access Control & // Vertical Scroll Start Address +#define DISPLAY_MADCTL (TFT_MADCTL_MX) +#define DISPLAY_VSCSAD 0 + +#define DISPLAY_TITLE "Sense TFT" + //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ @@ -62,7 +88,7 @@ //------------- UF2 -------------// #define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense TFT" -#define UF2_VOLUME_LABEL "FTHRSNSBOOT" +#define UF2_VOLUME_LABEL "SENSTFTBOOT" #define UF2_BOARD_ID "nRF52840-FeatherSenseTFT-revA" #define UF2_INDEX_URL "https://www.adafruit.com/product/"