From 3d920bf62b57b2c82b24ac2545dc1a94225e8285 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 5 Jan 2024 19:06:01 +0700 Subject: [PATCH] - add slash screen for CLUE - optimize ST77XX_SWRESET, skip if reset pin is available. --- CMakeLists.txt | 13 +++++++++- src/boards/boards.c | 24 ++++++++++------- .../circuitplayground_nrf52840/board.cmake | 1 + src/boards/clue_nrf52840/board.cmake | 1 + src/boards/clue_nrf52840/board.h | 26 +++++++++++++++++++ src/boards/feather_nrf52840_sense_tft/board.h | 2 +- 6 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 src/boards/circuitplayground_nrf52840/board.cmake create mode 100644 src/boards/clue_nrf52840/board.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a124031d..08ff5c2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.17) +find_package(Python COMPONENTS Interpreter) if (NOT DEFINED BOARD) message(FATAL_ERROR "BOARD is not defined") @@ -30,6 +31,9 @@ set(SDK ${CMAKE_CURRENT_LIST_DIR}/lib/sdk/components) set(SOFTDEVICE ${CMAKE_CURRENT_LIST_DIR}/lib/softdevice) set(TUSB ${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb/src) +set(UF2CONV_PY ${CMAKE_CURRENT_LIST_DIR}/lib/uf2/utils/uf2conv.py) +set(UF2_FAMILY_ID_BOOTLOADER 0xd663823c) + #------------------- # Bootloader #------------------- @@ -301,6 +305,8 @@ add_custom_command(TARGET bootloader POST_BUILD add_custom_command(TARGET bootloader POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $ $/bootloader.bin COMMAND ${CMAKE_OBJCOPY} -Oihex $ $/bootloader.hex + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/tools/hexmerge.py --overlap=replace -o $/bootloader_mbr.hex $/bootloader.hex ${MBR_HEX} + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_BOOTLOADER} -c -o $/bootloader_mbr.uf2 $/bootloader_mbr.hex VERBATIM) #---------------------------------- @@ -311,11 +317,16 @@ if (NOT DEFINED NRFJPROG) set(NRFJPROG nrfjprog) endif() -add_custom_target(flash +add_custom_target(flash-jlink DEPENDS bootloader COMMAND ${NRFJPROG} --program $ --verify --sectoranduicrerase -f nrf52 --reset ) +add_custom_target(flash-uf2 + DEPENDS bootloader + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_BOOTLOADER} --deploy $/bootloader_mbr.uf2 + ) + add_custom_target(flash-sd COMMAND ${NRFJPROG} --program ${SD_HEX} --verify --sectorerase -f nrf52 --reset ) diff --git a/src/boards/boards.c b/src/boards/boards.c index b9ed2c0a..74840bf0 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -255,6 +255,7 @@ void board_display_init(void) { nrf_gpio_pin_clear(DISPLAY_PIN_RST); NRFX_DELAY_MS(10); nrf_gpio_pin_set(DISPLAY_PIN_RST); + NRFX_DELAY_MS(20); #endif #if defined(DISPLAY_PIN_BL) && DISPLAY_PIN_BL >= 0 @@ -698,6 +699,7 @@ void neopixel_write (uint8_t *pixels) { #define ST77XX_TEOFF 0x34 #define ST77XX_TEON 0x35 #define ST77XX_MADCTL 0x36 +#define ST77XX_VSCSAD 0x37 #define ST77XX_COLMOD 0x3A #define ST77XX_MADCTL_MY 0x80 @@ -725,23 +727,27 @@ void neopixel_write (uint8_t *pixels) { static void tft_controller_init(void) { // Init commands for 7789 screens uint8_t cmdinit_st7789[] = { - // 1: Software reset, no args, w/delay ~150 ms delay + #if !defined(DISPLAY_PIN_RST) || (DISPLAY_PIN_RST < 0) + // Software reset if rst pin not available, no args, w/delay ~150 ms delay ST77XX_SWRESET, ST_CMD_DELAY, 150, - // 2: Out of sleep mode, no args, w/delay 10 ms delay + #endif + // Out of sleep mode, no args, w/delay 10 ms delay ST77XX_SLPOUT, ST_CMD_DELAY, 10, - // 3: Set color mode, 1 arg + delay: 16-bit color, 10 ms delay + // Set color mode, 1 arg + delay: 16-bit color, 10 ms delay ST77XX_COLMOD, 1 + ST_CMD_DELAY, 0x55, 10, - // 4: Mem access ctrl (directions), 1 arg: Row/col addr, bottom-top refresh + // Mem access ctrl (directions), 1 arg: Row/col addr, bottom-top refresh ST77XX_MADCTL, 1, DISPLAY_MADCTL, - // 5: Column addr set, 4 args, no delay: XSTART = 0, XEND = 240 + // Vertical Scroll Start Address of RAM + // ST77XX_VSCSAD, 2, DISPLAY_VSCSAD >> 8, DISPLAY_VSCSAD & 0xFF, + // Column addr set, 4 args, no delay: XSTART = 0, XEND = 240 ST77XX_CASET, 4, 0x00, 0, 0, 240, - // 6: Row addr set, 4 args, no delay: YSTART = 0 YEND = 320 + // Row addr set, 4 args, no delay: YSTART = 0 YEND = 320 ST77XX_RASET, 4, 0x00, 0, 320 >> 8, 320 & 0xFF, - // 7: hack + // Inversion on ST77XX_INVON, ST_CMD_DELAY, 10, - // 8: Normal display on, no args, w/delay 10 ms delay + // Normal display on, no args, w/delay 10 ms delay ST77XX_NORON, ST_CMD_DELAY, 10, - // 9: Main screen turn on, no args, delay 10 ms delay + // Main screen turn on, no args, delay 10 ms delay ST77XX_DISPON, ST_CMD_DELAY, 10 }; diff --git a/src/boards/circuitplayground_nrf52840/board.cmake b/src/boards/circuitplayground_nrf52840/board.cmake new file mode 100644 index 00000000..25daf71d --- /dev/null +++ b/src/boards/circuitplayground_nrf52840/board.cmake @@ -0,0 +1 @@ +set(MCU_VARIANT nrf52840) diff --git a/src/boards/clue_nrf52840/board.cmake b/src/boards/clue_nrf52840/board.cmake new file mode 100644 index 00000000..25daf71d --- /dev/null +++ b/src/boards/clue_nrf52840/board.cmake @@ -0,0 +1 @@ +set(MCU_VARIANT nrf52840) diff --git a/src/boards/clue_nrf52840/board.h b/src/boards/clue_nrf52840/board.h index efba060a..818f2f4d 100644 --- a/src/boards/clue_nrf52840/board.h +++ b/src/boards/clue_nrf52840/board.h @@ -46,6 +46,32 @@ #define BUTTON_2 _PINNUM(1, 10) // right button #define BUTTON_PULL NRF_GPIO_PIN_PULLUP +//--------------------------------------------------------------------+ +// Display +//--------------------------------------------------------------------+ +#define DISPLAY_CONTROLLER_ST7789 + +#define DISPLAY_PIN_SCK _PINNUM(0, 14) +#define DISPLAY_PIN_MOSI _PINNUM(0, 15) + +#define DISPLAY_PIN_CS _PINNUM(0, 12) +#define DISPLAY_PIN_DC _PINNUM(0, 13) +#define DISPLAY_PIN_RST _PINNUM(1, 3) +#define DISPLAY_PIN_BL _PINNUM(1, 5) +#define DISPLAY_BL_ON 1 // GPIO state to enable back light + +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 240 + +#define DISPLAY_COL_OFFSET 0 +#define DISPLAY_ROW_OFFSET 80 + +// Memory Data Access Control & // Vertical Scroll Start Address +#define DISPLAY_MADCTL (TFT_MADCTL_MY) +#define DISPLAY_VSCSAD 0 + +#define DISPLAY_TITLE "CLUE" + //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ diff --git a/src/boards/feather_nrf52840_sense_tft/board.h b/src/boards/feather_nrf52840_sense_tft/board.h index 902e75ce..b78e2512 100644 --- a/src/boards/feather_nrf52840_sense_tft/board.h +++ b/src/boards/feather_nrf52840_sense_tft/board.h @@ -52,8 +52,8 @@ //--------------------------------------------------------------------+ #define DISPLAY_CONTROLLER_ST7789 -#define DISPLAY_PIN_MOSI _PINNUM(0, 5) #define DISPLAY_PIN_SCK _PINNUM(0, 26) +#define DISPLAY_PIN_MOSI _PINNUM(0, 5) #define DISPLAY_PIN_CS _PINNUM(1, 5) #define DISPLAY_PIN_DC _PINNUM(1, 1)