Add DisplayApp, and lcdfont. Update the display every second

This commit is contained in:
JF 2019-12-05 21:19:47 +01:00
parent 29efb9aef6
commit 5225706cc8
6 changed files with 7481 additions and 80 deletions

View file

@ -30,6 +30,8 @@ include_directories(.)
list(APPEND SOURCE_FILES list(APPEND SOURCE_FILES
Logging/NrfLogger.cpp Logging/NrfLogger.cpp
BlinkApp/BlinkApp.cpp BlinkApp/BlinkApp.cpp
DisplayApp/DisplayApp.cpp
DisplayApp/lcdfont.c
main.cpp main.cpp
drivers/st7789.cpp drivers/st7789.cpp
drivers/spi_master_fast.cpp drivers/spi_master_fast.cpp
@ -39,6 +41,8 @@ set(INCLUDE_FILES
Logging/Logger.h Logging/Logger.h
Logging/NrfLogger.h Logging/NrfLogger.h
BlinkApp/BlinkApp.h BlinkApp/BlinkApp.h
DisplayApp/DisplayApp.h
DisplayApp/lcdfont.h
drivers/st7789.h drivers/st7789.h
drivers/spi_master_fast.h drivers/spi_master_fast.h
) )

View file

@ -0,0 +1,184 @@
#include "DisplayApp.h"
#include <FreeRTOS.h>
#include <task.h>
#include <libraries/log/nrf_log.h>
#include <boards.h>
#include <libraries/gfx/nrf_gfx.h>
using namespace Pinetime::Applications;
Pinetime::Drivers::st7789 lcd;
ret_code_t lcd_init() {
lcd.Init();
}
void lcd_dummy() {
};
void lcd_pixel_draw(uint16_t x, uint16_t y, uint32_t color) {
lcd.DrawPixel(x, y, color);
}
void lcd_rectangle_draw(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color) {
lcd.FillRectangle(x, y, width, height, color);
}
void lcd_rotation_set(nrf_lcd_rotation_t rotation) {
}
void lcd_display_invert(bool invert) {
}
static lcd_cb_t st7789_cb = {
.height = 240,
.width = 240
};
const nrf_lcd_t nrf_lcd_st7789 = {
.lcd_init = lcd_init,
.lcd_uninit = lcd_dummy,
.lcd_pixel_draw = lcd_pixel_draw,
.lcd_rect_draw = lcd_rectangle_draw,
.lcd_display = lcd_dummy,
.lcd_rotation_set = lcd_rotation_set,
.lcd_display_invert = lcd_display_invert,
.p_lcd_cb = &st7789_cb
};
//extern const FONT_INFO orkney_24ptFontInfo;
//extern const uint_8 lCD_30ptBitmaps[];
extern const FONT_INFO lCD_70ptFontInfo;
//extern const FONT_CHAR_INFO lCD_30ptDescriptors[];
void DisplayApp::Start() {
if (pdPASS != xTaskCreate(DisplayApp::Process, "DisplayApp", 256, this, 0, &taskHandle))
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
void DisplayApp::Process(void *instance) {
auto* app = static_cast<DisplayApp*>(instance);
NRF_LOG_INFO("DisplayApp task started!");
gfx_initialization();
uint8_t hour = 0;
uint8_t minute = 1;
while (1) {
NRF_LOG_INFO("BlinkApp task running!");
nrf_gfx_rect_t rect;
rect.height = 74;
rect.width = 52;
rect.x = 7;
rect.y = 78;
nrf_gfx_rect_draw(&nrf_lcd_st7789, &rect, 2, 0x00000000, true);
nrf_gfx_font_desc_t font;
font.charInfo = lCD_70ptFontInfo.charInfo;
font.data = lCD_70ptFontInfo.data;
font.endChar = lCD_70ptFontInfo.endChar;
font.height = lCD_70ptFontInfo.height;
font.spacePixels = lCD_70ptFontInfo.spacePixels;
font.startChar = lCD_70ptFontInfo.startChar;
char t[2];
sprintf(t, "%1d", hour);
nrf_gfx_point_t point;
point.x = 7;
point.y = 78;
nrf_gfx_print(&nrf_lcd_st7789,
&point,
0xffff,
t,
&font,
true);
// point.x = 61;
// point.y = 78;
// nrf_gfx_print(&nrf_lcd_st7789,
// &point,
// 0xffff,
// "2",
// &font,
// true);
//
// point.x = 115;
// point.y = 78;
// nrf_gfx_print(&nrf_lcd_st7789,
// &point,
// 0xffff,
// ":",
// &font,
// true);
//
// point.x = 127;
// point.y = 78;
// nrf_gfx_print(&nrf_lcd_st7789,
// &point,
// 0xffff,
// "3",
// &font,
// true);
//
// point.x = 181;
// point.y = 78;
// nrf_gfx_print(&nrf_lcd_st7789,
// &point,
// 0xffff,
// "4",
// &font,
// true);
if(hour < 9)
hour++;
else hour = 0;
vTaskDelay(1000);
}
}
void DisplayApp::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(&nrf_lcd_st7789));
nrf_gfx_rect_t rect;
rect.height = 240;
rect.width = 240;
rect.x = 0;
rect.y = 0;
nrf_gfx_rect_draw(&nrf_lcd_st7789, &rect, 2, 0x00000000, true);
nrf_gfx_point_t point;
point.x = 7;
point.y = 78;
nrf_gfx_font_desc_t font;
font.charInfo = lCD_70ptFontInfo.charInfo;
font.data = lCD_70ptFontInfo.data;
font.endChar = lCD_70ptFontInfo.endChar;
font.height = lCD_70ptFontInfo.height;
font.spacePixels = lCD_70ptFontInfo.spacePixels;
font.startChar = lCD_70ptFontInfo.startChar;
nrf_gfx_print(&nrf_lcd_st7789,
&point,
0xffff,
"20:45",
&font,
true);
}

View file

@ -0,0 +1,20 @@
#pragma once
#include <FreeRTOS.h>
#include <task.h>
#include <drivers/st7789.h>
namespace Pinetime {
namespace Applications {
class DisplayApp {
public:
void Start();
private:
TaskHandle_t taskHandle;
static void Process(void* instance);
static void gfx_initialization();
};
}
}

7264
src/DisplayApp/lcdfont.c Normal file

File diff suppressed because it is too large Load diff

5
src/DisplayApp/lcdfont.h Normal file
View file

@ -0,0 +1,5 @@
// Font data for LCD 70pt
extern const uint_8 lCD_70ptBitmaps[];
extern const FONT_INFO lCD_70ptFontInfo;
extern const FONT_CHAR_INFO lCD_70ptDescriptors[];

View file

@ -9,6 +9,7 @@
#include <libraries/gpiote/app_gpiote.h> #include <libraries/gpiote/app_gpiote.h>
#include <libraries/gfx/nrf_lcd.h> #include <libraries/gfx/nrf_lcd.h>
#include <drivers/st7789.h> #include <drivers/st7789.h>
#include <DisplayApp/DisplayApp.h>
#include "nrf_gfx.h" #include "nrf_gfx.h"
@ -21,8 +22,9 @@ Pinetime::Logging::DummyLogger logger;
#endif #endif
Pinetime::Applications::BlinkApp blinkApp; Pinetime::Applications::BlinkApp blinkApp;
Pinetime::Applications::DisplayApp displayApp;
TaskHandle_t systemThread; TaskHandle_t systemThread;
Pinetime::Drivers::st7789 lcd; //Pinetime::Drivers::st7789 lcd;
extern "C" { extern "C" {
void vApplicationIdleHook() { void vApplicationIdleHook() {
@ -46,86 +48,9 @@ static void bsp_event_handler(bsp_event_t event)
} }
} }
ret_code_t lcd_init() {
lcd.Init();
}
void lcd_dummy() {
};
void lcd_pixel_draw(uint16_t x, uint16_t y, uint32_t color) {
lcd.DrawPixel(x, y, color);
}
void lcd_rectangle_draw(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color) {
lcd.FillRectangle(x, y, width, height, color);
}
void lcd_rotation_set(nrf_lcd_rotation_t rotation) {
}
void lcd_display_invert(bool invert) {
}
static lcd_cb_t st7789_cb = {
.height = 240,
.width = 240
};
const nrf_lcd_t nrf_lcd_st7789 = {
.lcd_init = lcd_init,
.lcd_uninit = lcd_dummy,
.lcd_pixel_draw = lcd_pixel_draw,
.lcd_rect_draw = lcd_rectangle_draw,
.lcd_display = lcd_dummy,
.lcd_rotation_set = lcd_rotation_set,
.lcd_display_invert = lcd_display_invert,
.p_lcd_cb = &st7789_cb
};
extern const FONT_INFO orkney_24ptFontInfo;
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(&nrf_lcd_st7789));
nrf_gfx_rect_t rect;
rect.height = 240;
rect.width = 240;
rect.x = 0;
rect.y = 0;
nrf_gfx_rect_draw(&nrf_lcd_st7789, &rect, 2, 0xaaaaaaaa, true);
nrf_gfx_point_t point;
point.x = 10;
point.y = 10;
nrf_gfx_font_desc_t font;
font.charInfo = orkney_24ptFontInfo.charInfo;
font.data = orkney_24ptFontInfo.data;
font.endChar = orkney_24ptFontInfo.endChar;
font.height = orkney_24ptFontInfo.height;
font.spacePixels = orkney_24ptFontInfo.spacePixels;
font.startChar = orkney_24ptFontInfo.startChar;
nrf_gfx_print(&nrf_lcd_st7789,
&point,
0xffff,
"#Pinetime\nRocks!",
&font,
true);
}
void SystemTask(void *) { void SystemTask(void *) {
APP_GPIOTE_INIT(2); APP_GPIOTE_INIT(2);
@ -137,8 +62,6 @@ void SystemTask(void *) {
nrf_gpio_pin_clear(14); nrf_gpio_pin_clear(14);
nrf_gpio_pin_clear(22); nrf_gpio_pin_clear(22);
nrf_gpio_pin_clear(23); nrf_gpio_pin_clear(23);
gfx_initialization();
// lcd.Init(); // lcd.Init();
// lcd.FillRectangle(0,0,240,240,0xffaa); // lcd.FillRectangle(0,0,240,240,0xffaa);
// lcd.FillRectangle(10,10,50,50,0x011bb); // lcd.FillRectangle(10,10,50,50,0x011bb);
@ -146,6 +69,7 @@ void SystemTask(void *) {
// lcd.FillRectangle(120,120,120,120,0x1212); // lcd.FillRectangle(120,120,120,120,0x1212);
blinkApp.Start(); blinkApp.Start();
displayApp.Start();
while (1) { while (1) {
vTaskSuspend(nullptr); vTaskSuspend(nullptr);