File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
examples/nucleo_f446ze/random_access_gpio_port Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ <library >
2
+ <extends >modm:nucleo-f446ze</extends >
3
+ <options >
4
+ <option name =" modm:build:build.path" >../../../build/nucleo_f446ze/random_access_gpio_port</option >
5
+ </options >
6
+ <modules >
7
+ <module >modm:build:scons</module >
8
+ </modules >
9
+ </library >
You can’t perform that action at this time.
0 commit comments