-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathmain.cpp
199 lines (155 loc) · 4.37 KB
/
main.cpp
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* Copyright (c) 2010-2011, 2013, Fabian Greif
* Copyright (c) 2012-2018, Niklas Hauser
* Copyright (c) 2014, Sascha Schade
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------
#include <modm/platform.hpp>
#include <modm/architecture/interface/interrupt.hpp>
#include <modm/driver/display/ea_dog.hpp>
#include <modm/processing/timer.hpp>
#include "images/rca_logo_128x64.hpp"
using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;
using namespace modm::color::html;
namespace led
{
typedef GpioOutputD7 R;
typedef GpioOutputD6 G;
typedef GpioOutputD5 B;
}
// define the pins used by the LCD
namespace lcd
{
typedef GpioOutputB7 Sck;
typedef GpioOutputB5 Mosi;
typedef GpioOutputD2 Cs;
typedef GpioOutputD3 A0;
typedef GpioOutputD4 Reset;
typedef BitBangSpiMaster< Sck, Mosi > SPI;
}
modm::DogM128< lcd::SPI, lcd::Cs, lcd::A0, lcd::Reset, true > display;
using namespace modm::glcd;
void
setup()
{
SystemClock::enable();
led::R::set();
led::G::set();
led::B::reset();
led::R::setOutput();
led::G::setOutput();
led::B::setOutput();
lcd::SPI::connect<lcd::Sck::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<SystemClock, 2_MHz>();
// enable interrupts
enableInterrupts();
display.initialize();
}
void
introScreen()
{
display.drawImage(
Point(0, 0),
modm::accessor::asFlash(bitmap::rca_logo_128x64));
display.update();
modm::delay(2s);
display.clear();
display.setFont(modm::font::ScriptoNarrow);
display.setCursor(Point(0, 0));
display << "ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"§$%&" << modm::endl;
display << "abcdefghijklmnopqrstuvwxyz012345";
display.setFont(modm::font::AllCaps3x5);
display.setCursor(Point(0, 20));
display << "ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"§$%&/()" << modm::endl;
display << "abcdefghijklmnopqrstuvwxyz01234567";
display.setFont(modm::font::FixedWidth5x8);
display.setCursor(Point(0, 35));
display << "ABCDEFGHIJKLMNOPQRSTU" << modm::endl;
display << "abcdefghijklmnopqrstu";
display.update();
modm::delay(1s);
display.setCursor(Point(40, 55));
display << "5 ";
display.update();
modm::delay(1s);
display << "4 ";
display.update();
modm::delay(1s);
display << "3 ";
display.update();
modm::delay(1s);
display << "2 ";
display.update();
modm::delay(1s);
display << "1";
display.update();
modm::delay(1s);
display.clear();
}
// this draws an object that appears to spin
void
drawSpinner(Point center, uint8_t pos)
{
const uint8_t x = center.x();
const uint8_t y = center.y();
switch(pos % 8)
{
case 0: display.drawLine(x, y-8, x, y+8); break;
case 1: display.drawLine(x+3, y-7, x-3, y+7); break;
case 2: display.drawLine(x+6, y-6, x-6, y+6); break;
case 3: display.drawLine(x+7, y-3, x-7, y+3); break;
case 4: display.drawLine(x+8, y, x-8, y); break;
case 5: display.drawLine(x+7, y+3, x-7, y-3); break;
case 6: display.drawLine(x+6, y+6, x-6, y-6); break;
case 7: display.drawLine(x+3, y+7, x-3, y-7); break;
}
}
int
main()
{
setup();
introScreen();
display.setFont(modm::font::FixedWidth5x8);
modm::ShortPeriodicTimer timer(1s);
while (true)
{
uint8_t iter = 0;
while (!timer.execute())
{
// rectangle in left side of screen
// display.setColor(Black);
display.drawRectangle(Point(0, 0), 62, 62);
// rounded rectangle around text area
display.drawRoundedRectangle(Point(66, 0), 127-66, 62, 5);
// draw lines from upper left down right side of rectangle
for(uint8_t i = 0; i < 62; i += 4) {
display.drawLine(Point(1, 1), Point(63, i));
}
// draw circle centered in the left side of screen
display.drawCircle(Point(31, 31), 31);
// clear previous spinner position
// TODO display.setColor(White);
display.fillRectangle(Point(87, 40), 16, 16);
static uint8_t loops = 0;
// TODO display.setColor(Black);
drawSpinner(Point(95, 48), loops++);
// TODO display.setColor(White);
display.setCursor(Point(25, 40));
display << ++iter;
display.update();
}
// print number of iterations in one second
display.clear();
display.setCursor(Point(80, 10));
// display.setColor(White);
display << "FPS=" << iter;
}
}