Skip to content

Commit 80eb9dc

Browse files
committed
[examples] Add random access gpio port example for Nucleo F446ZE
1 parent bc5470f commit 80eb9dc

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2021, Christopher Durand
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
#include <modm/board.hpp>
13+
#include <ranges>
14+
15+
using namespace Board;
16+
using namespace std::literals;
17+
18+
int
19+
main()
20+
{
21+
Board::initialize();
22+
23+
using LedPort = RandomAccessPort<LedRed, LedBlue, LedGreen>;
24+
LedPort::setOutput();
25+
26+
// Enable output with index 2 => LedRed
27+
LedPort::set(2);
28+
modm::delay(1000ms);
29+
30+
// Type-erased pin wrapper
31+
const auto port = LedPort{};
32+
port[1].set();
33+
34+
GpioAccessor pin = port[0];
35+
pin.set();
36+
37+
modm::delay(500ms);
38+
39+
// Demonstrate iterator/range interface
40+
static_assert(std::ranges::random_access_range<LedPort>);
41+
42+
auto reversedPins = port | std::views::reverse;
43+
while (true)
44+
{
45+
for(auto pin : reversedPins) {
46+
pin.toggle();
47+
modm::delay(250ms);
48+
}
49+
}
50+
51+
return 0;
52+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<library>
2+
<extends>modm:nucleo-f446ze</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_f446ze/blink</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
</modules>
9+
</library>

0 commit comments

Comments
 (0)