From 66182d15bca7e88aaceee9bb4cc03218a4f24569 Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 2 Dec 2019 19:42:10 +0100 Subject: [PATCH] First code tested on the actual pinetime hardware --- README.md | 2 +- cmake-nRF5x/CMake_nRF5x.cmake | 17 +++++ src/BlinkApp/BlinkApp.cpp | 4 +- src/drivers/st7789.cpp | 5 ++ src/drivers/st7789.h | 14 ++++ src/main.cpp | 26 +++++++ src/sdk_config.h | 126 +++++++++++++++++++++++++++++++--- 7 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 src/drivers/st7789.cpp create mode 100644 src/drivers/st7789.h diff --git a/README.md b/README.md index 4644eea5..d683cdb6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# nrf52-baseproject +# PineTime This is a CMake project that configure everything needed to build applications for the NRF52 MCU. It configures the toolchain (arm-none-eabi) and the NRF52 SDK. The CMake files are taken from https://github.com/Polidea/cmake-nRF5x diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake index 9f81b9b0..505f7368 100755 --- a/cmake-nRF5x/CMake_nRF5x.cmake +++ b/cmake-nRF5x/CMake_nRF5x.cmake @@ -208,6 +208,8 @@ macro(nRF5x_setup) "${NRF5_SDK_PATH}/components/libraries/usbd/class/hid/mouse" "${NRF5_SDK_PATH}/components/libraries/usbd/class/msc" "${NRF5_SDK_PATH}/components/libraries/util" + + ) # librarires sources @@ -255,6 +257,21 @@ macro(nRF5x_setup) "${NRF5_SDK_PATH}/external/fprintf/nrf_fprintf_format.c" ) + # LCD/GFX + include_directories( + "${NRF5_SDK_PATH}/external/thedotfactory_fonts" + ) + + list(APPEND SDK_SOURCE_FILES + "${NRF5_SDK_PATH}/components/libraries/gfx/nrf_gfx.c" + "${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_spi.c" +# "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_spi.c" + "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_spim.c" + "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/prs/nrfx_prs.c" + + "${NRF5_SDK_PATH}/components/drivers_ext/st7735/st7735.c" + ) + #BLE S132 include_directories( "${NRF5_SDK_PATH}/components/ble/common" diff --git a/src/BlinkApp/BlinkApp.cpp b/src/BlinkApp/BlinkApp.cpp index 544cd347..2eac9d8f 100644 --- a/src/BlinkApp/BlinkApp.cpp +++ b/src/BlinkApp/BlinkApp.cpp @@ -17,7 +17,9 @@ void BlinkApp::Process(void *instance) { NRF_LOG_INFO("BlinkApp task started!"); while (1) { NRF_LOG_INFO("BlinkApp task running!"); - bsp_board_led_invert(0); +// nrf_gpio_pin_toggle(22); +// nrf_gpio_pin_toggle(23); +// nrf_gpio_pin_toggle(14); vTaskDelay(1000); } } diff --git a/src/drivers/st7789.cpp b/src/drivers/st7789.cpp new file mode 100644 index 00000000..6e2fb68b --- /dev/null +++ b/src/drivers/st7789.cpp @@ -0,0 +1,5 @@ +// +// Created by jf on 12/2/19. +// + +#include "st7789.h" diff --git a/src/drivers/st7789.h b/src/drivers/st7789.h new file mode 100644 index 00000000..dc3f0833 --- /dev/null +++ b/src/drivers/st7789.h @@ -0,0 +1,14 @@ +// +// Created by jf on 12/2/19. +// + +#ifndef PINETIME_ST7789_H +#define PINETIME_ST7789_H + + +class st7789 { + +}; + + +#endif //PINETIME_ST7789_H diff --git a/src/main.cpp b/src/main.cpp index 9ce22d36..c04cc843 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include "nrf_gfx.h" #if NRF_LOG_ENABLED @@ -43,6 +45,25 @@ static void bsp_event_handler(bsp_event_t event) } } +extern const nrf_lcd_t nrf_lcd_st7735; +static nrf_lcd_t const * p_lcd = &nrf_lcd_st7735; +static void gfx_initialization(void) +{ + nrf_gpio_cfg_output(14); + nrf_gpio_cfg_output(22); + nrf_gpio_cfg_output(23); + nrf_gpio_pin_clear(14); + nrf_gpio_pin_set(22); + nrf_gpio_pin_set(23); + + APP_ERROR_CHECK(nrf_gfx_init(p_lcd)); + nrf_gfx_rect_t rect; + rect.height = 10; + rect.width = 10; + rect.x = 10; + rect.y = 10; + nrf_gfx_rect_draw(p_lcd, &rect, 2, 0xffffffff, true); +} void SystemTask(void *) { APP_GPIOTE_INIT(2); @@ -51,6 +72,9 @@ void SystemTask(void *) { bsp_board_init(BSP_INIT_LEDS|BSP_INIT_BUTTONS); bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler); + gfx_initialization(); + + blinkApp.Start(); while (1) { @@ -58,6 +82,8 @@ void SystemTask(void *) { } } + + int main(void) { logger.Init(); nrf_drv_clock_init(); diff --git a/src/sdk_config.h b/src/sdk_config.h index 90c3744b..46a40940 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -4384,13 +4384,13 @@ // NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver //========================================================== #ifndef NRFX_SPIM_ENABLED -#define NRFX_SPIM_ENABLED 0 +#define NRFX_SPIM_ENABLED 1 #endif // NRFX_SPIM0_ENABLED - Enable SPIM0 instance - + #ifndef NRFX_SPIM0_ENABLED -#define NRFX_SPIM0_ENABLED 0 +#define NRFX_SPIM0_ENABLED 1 #endif // NRFX_SPIM1_ENABLED - Enable SPIM1 instance @@ -4435,7 +4435,7 @@ // NRFX_SPIM_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef NRFX_SPIM_CONFIG_LOG_ENABLED -#define NRFX_SPIM_CONFIG_LOG_ENABLED 0 +#define NRFX_SPIM_CONFIG_LOG_ENABLED 1 #endif // NRFX_SPIM_CONFIG_LOG_LEVEL - Default Severity level @@ -4575,7 +4575,7 @@ // <0=> Default // <1=> Black -// <2=> Red +// <2=> Red < // <3=> Green // <4=> Yellow // <5=> Blue @@ -6456,7 +6456,7 @@ // SPI_ENABLED - nrf_drv_spi - SPI/SPIM peripheral driver - legacy layer //========================================================== #ifndef SPI_ENABLED -#define SPI_ENABLED 0 +#define SPI_ENABLED 1 #endif // SPI_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority @@ -6488,7 +6488,7 @@ // SPI0_ENABLED - Enable SPI0 instance //========================================================== #ifndef SPI0_ENABLED -#define SPI0_ENABLED 0 +#define SPI0_ENABLED 1 #endif // SPI0_USE_EASY_DMA - Use EasyDMA @@ -8142,7 +8142,11 @@ #ifndef NRF_GFX_ENABLED -#define NRF_GFX_ENABLED 0 +#define NRF_GFX_ENABLED 1 +#endif + +#ifndef ST7735_ENABLED +#define ST7735_ENABLED 1 #endif // NRF_MEMOBJ_ENABLED - nrf_memobj - Linked memory allocator module @@ -9617,7 +9621,7 @@ // SPI_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef SPI_CONFIG_LOG_ENABLED -#define SPI_CONFIG_LOG_ENABLED 0 +#define SPI_CONFIG_LOG_ENABLED 1 #endif // SPI_CONFIG_LOG_LEVEL - Default Severity level @@ -12933,6 +12937,106 @@ #endif -// <<< end of configuration section >>> -#endif //SDK_CONFIG_H + +// ST7735_SCK_PIN - Pin number <0-47> + + +#ifndef ST7735_SCK_PIN +#define ST7735_SCK_PIN 2 +#endif + +// ST7735_MISO_PIN - Pin number <0-47> + + +#ifndef ST7735_MISO_PIN +#define ST7735_MISO_PIN 4 +#endif + +// ST7735_MOSI_PIN - Pin number <0-47> + + +#ifndef ST7735_MOSI_PIN +#define ST7735_MOSI_PIN 3 +#endif + +// ST7735_SS_PIN - Pin number <0-47> + + +#ifndef ST7735_SS_PIN +#define ST7735_SS_PIN 25 +#endif + +// ST7735_IRQ_PRIORITY - Interrupt priority + + +// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 +// <4=> 4 +// <5=> 5 +// <6=> 6 +// <7=> 7 + +#ifndef ST7735_IRQ_PRIORITY +#define ST7735_IRQ_PRIORITY 3 +#endif + +// +//========================================================== + + +// ST7735_SPI_INSTANCE + +// <0=> 0 +// <1=> 1 +// <2=> 2 + +#ifndef ST7735_SPI_INSTANCE +#define ST7735_SPI_INSTANCE 0 +#endif + +#ifndef ST7735_SPI_MODE +#define ST7735_SPI_MODE 3 +#endif + +#ifndef ST7735_SPI_FREQUENCY +#define ST7735_SPI_FREQUENCY 8000000 +#endif + +// ST7735_TAB_COLOR - Color of the tab attached to the screen. + +// <0=> INITR_GREENTAB +// <1=> INITR_REDTAB +// <2=> INITR_BLACKTAB +// <3=> INITR_144GREENTAB + +#ifndef ST7735_TAB_COLOR +#define ST7735_TAB_COLOR 2 +#endif + +// ST7735_DC_PIN - Pin number <0-47> + + +#ifndef ST7735_DC_PIN +#define ST7735_DC_PIN 18 +#endif + +// ST7735_HEIGHT - ST7735 height <0-162> + + +#ifndef ST7735_HEIGHT +#define ST7735_HEIGHT 160 +#endif + +// ST7735_WIDTH - ST7735 width <0-132> + + +#ifndef ST7735_WIDTH +#define ST7735_WIDTH 128 +#endif + +// <<< end of configuration section >>> +#endif //SDK_CONFIG_H \ No newline at end of file