summaryrefslogtreecommitdiff
path: root/src/DisplayApp/DisplayApp.cpp
blob: 36302a20bfb764d2537f9174c7e5868baaa52e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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() {
  return 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
};

static 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!");
  app->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);

}