Skip to content

Commit bf44fe8

Browse files
committed
[wip] More complete Gpio class
1 parent ae6002e commit bf44fe8

File tree

6 files changed

+315
-160
lines changed

6 files changed

+315
-160
lines changed

examples/nucleo_f446ze/random_access_gpio_port/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ main()
3131
const auto port = LedPort{};
3232
port[1].set();
3333

34-
GpioAccessor pin = port[0];
34+
RtGpio pin = port[0];
3535
pin.set();
3636

3737
modm::delay(500ms);

examples/stm32f3_discovery/blink/main.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,39 @@
1515

1616
using namespace Board;
1717

18+
RtGpio north = Board::LedNorth();
19+
RtGpio northEast = Board::LedNorthEast();
20+
RtGpio east = Board::LedEast();
21+
RtGpio southEast = Board::LedSouthEast();
22+
RtGpio south = Board::LedSouth();
23+
RtGpio southWest = Board::LedSouthWest();
24+
RtGpio west = Board::LedWest();
25+
RtGpio northWest = Board::LedNorthWest();
26+
1827
int
1928
main()
2029
{
2130
Board::initialize();
2231

23-
Board::LedNorth::set();
32+
north.set();
2433

2534
while (true)
2635
{
27-
Board::LedNorth::toggle();
36+
north.toggle();
2837
modm::delay(100ms);
29-
Board::LedNorthEast::toggle();
38+
northEast.toggle();
3039
modm::delay(100ms);
31-
Board::LedEast::toggle();
40+
east.toggle();
3241
modm::delay(100ms);
33-
Board::LedSouthEast::toggle();
42+
southEast.toggle();
3443
modm::delay(100ms);
35-
Board::LedSouth::toggle();
44+
south.toggle();
3645
modm::delay(100ms);
37-
Board::LedSouthWest::toggle();
46+
southWest.toggle();
3847
modm::delay(100ms);
39-
Board::LedWest::toggle();
48+
west.toggle();
4049
modm::delay(100ms);
41-
Board::LedNorthWest::toggle();
50+
northWest.toggle();
4251
modm::delay(100ms);
4352
}
4453

src/modm/platform/gpio/stm32/gpio_accessor.hpp.in

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/modm/platform/gpio/stm32/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def build(env):
303303
env.template("unused.hpp.in")
304304
if len(env["enable_ports"]):
305305
env.template("enable.cpp.in")
306-
env.template("gpio_accessor.hpp.in")
306+
env.template("runtime_gpio.hpp.in")
307307

308308
env.copy("random_access_port.hpp")
309309
env.copy("../common/inverted.hpp", "inverted.hpp")

src/modm/platform/gpio/stm32/random_access_port.hpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <algorithm>
1818

1919
#include "software_port.hpp"
20-
#include "gpio_accessor.hpp"
20+
#include "runtime_gpio.hpp"
2121

2222
namespace modm::platform
2323
{
@@ -37,7 +37,7 @@ namespace modm::platform
3737
*
3838
* Port port;
3939
* // set pin C8
40-
* GpioAccessor pin = port[0];
40+
* RtGpio pin = port[0];
4141
* pin.set();
4242
*
4343
* auto reversedPins = port | std::views::reverse;
@@ -56,10 +56,10 @@ class RandomAccessPort : public SoftwareGpioPort<Gpios...>
5656
{
5757
public:
5858
using Index = int_fast8_t;
59-
static constexpr inline size_t Size{sizeof...(Gpios)};
59+
static constexpr size_t Size{sizeof...(Gpios)};
6060

6161
private:
62-
static constexpr inline std::array<GpioAccessor, Size> GpioPins = [](){
62+
static constexpr std::array<RtGpio, Size> gpioPins = [](){
6363
auto gpios = makeGpioArray<Gpios...>();
6464
// Reverse pin order to match SoftwareGpioPort indexing
6565
std::reverse(gpios.begin(), gpios.end());
@@ -77,53 +77,53 @@ class RandomAccessPort : public SoftwareGpioPort<Gpios...>
7777
public:
7878
using iterator_category = std::random_access_iterator_tag;
7979
using difference_type = Index;
80-
using value_type = GpioAccessor;
81-
using reference = const GpioAccessor&;
80+
using value_type = RtGpio;
81+
using reference = RtGpio&;
8282

8383
constexpr GpioIterator() = default;
8484
constexpr explicit GpioIterator(Index index) : index_{index}
8585
{}
8686

87-
constexpr inline GpioIterator&
87+
constexpr GpioIterator&
8888
operator+=(difference_type diff) { index_ += diff; return *this; }
8989

90-
constexpr inline GpioIterator&
90+
constexpr GpioIterator&
9191
operator-=(difference_type diff) { index_ -= diff; return *this; }
9292

93-
constexpr inline reference
94-
operator*() const { return RandomAccessPort::GpioPins[index_]; }
93+
constexpr reference
94+
operator*() const { return RandomAccessPort::gpioPins[index_]; }
9595

96-
constexpr inline reference
97-
operator[](difference_type diff) const { return RandomAccessPort::GpioPins[index_ + diff]; }
96+
constexpr reference
97+
operator[](difference_type diff) const { return RandomAccessPort::gpioPins[index_ + diff]; }
9898

99-
constexpr inline GpioIterator&
99+
constexpr GpioIterator&
100100
operator++() { ++index_; return *this; }
101101

102-
constexpr inline GpioIterator&
102+
constexpr GpioIterator&
103103
operator--() { --index_; return *this; }
104104

105-
constexpr inline GpioIterator
105+
constexpr GpioIterator
106106
operator++(int) { GpioIterator tmp{*this}; ++index_; return tmp; }
107107

108-
constexpr inline GpioIterator
108+
constexpr GpioIterator
109109
operator--(int) { GpioIterator tmp{*this}; --index_; return tmp; }
110110

111-
constexpr inline difference_type
111+
constexpr difference_type
112112
operator-(const GpioIterator& rhs) const { return index_ - rhs.index_; }
113113

114-
constexpr inline GpioIterator
114+
constexpr GpioIterator
115115
operator+(difference_type diff) const { return GpioIterator{index_ + diff}; }
116116

117-
constexpr inline GpioIterator
117+
constexpr GpioIterator
118118
operator-(difference_type diff) const { return GpioIterator{index_ - diff}; }
119119

120-
friend constexpr inline GpioIterator
120+
friend constexpr GpioIterator
121121
operator+(difference_type lhs, const GpioIterator& rhs) { return GpioIterator{lhs + rhs.index_}; }
122122

123-
friend constexpr inline GpioIterator
123+
friend constexpr GpioIterator
124124
operator-(difference_type lhs, const GpioIterator& rhs) { return GpioIterator{lhs - rhs.index_}; }
125125

126-
constexpr inline auto
126+
constexpr auto
127127
operator<=>(const GpioIterator& rhs) const = default;
128128
};
129129
static_assert(std::random_access_iterator<GpioIterator>);
@@ -134,40 +134,40 @@ class RandomAccessPort : public SoftwareGpioPort<Gpios...>
134134
constexpr GpioIterator
135135
end() const { return GpioIterator{Size}; }
136136

137-
constexpr const GpioAccessor&
137+
constexpr const RtGpio&
138138
operator[](Index index) const
139139
{
140-
return GpioPins[index];
140+
return gpioPins[index];
141141
}
142142

143143
static void set(Index index, bool enable)
144144
{
145-
GpioPins[index].set(enable);
145+
gpioPins[index].set(enable);
146146
}
147147

148148
static void set(Index index)
149149
{
150-
GpioPins[index].set();
150+
gpioPins[index].set();
151151
}
152152

153153
static void reset(Index index)
154154
{
155-
GpioPins[index].reset();
155+
gpioPins[index].reset();
156156
}
157157

158158
static void toggle(Index index)
159159
{
160-
GpioPins[index].toggle();
160+
gpioPins[index].toggle();
161161
}
162162

163163
static bool read(Index index)
164164
{
165-
return GpioPins[index].read();
165+
return gpioPins[index].read();
166166
}
167167

168168
static bool isSet(Index index)
169169
{
170-
return GpioPins[index].isSet();
170+
return gpioPins[index].isSet();
171171
}
172172
};
173173

0 commit comments

Comments
 (0)