|
9 | 9 | */
|
10 | 10 | // ----------------------------------------------------------------------------
|
11 | 11 |
|
12 |
| -#ifndef MODM_AVR_GPIO_PORT_HPP |
13 |
| -#define MODM_AVR_GPIO_PORT_HPP |
| 12 | +#pragma once |
14 | 13 |
|
15 |
| -#include "base.hpp" |
| 14 | +#include "port_shim.hpp" |
16 | 15 | #include "set.hpp"
|
17 | 16 | #include <modm/math/utils/bit_operation.hpp>
|
18 | 17 |
|
19 |
| -namespace modm |
| 18 | +namespace modm::platform |
20 | 19 | {
|
21 | 20 |
|
22 |
| -namespace platform |
23 |
| -{ |
24 |
| - |
25 |
| -/// @cond |
26 |
| -template< Gpio::Port port > |
27 |
| -struct GpioPortInfo; |
28 |
| -template< class StartGpio, int8_t Width > |
29 |
| -struct GpioSetShim |
30 |
| -{ |
31 |
| - static typename GpioPortInfo<StartGpio::port>::template check<StartGpio::pin, Width> check; |
32 |
| -}; |
33 |
| -/// @endcond |
34 |
| - |
35 | 21 | /// @ingroup modm_platform_gpio
|
36 | 22 | template< class StartGpio, int8_t Width >
|
37 |
| -class GpioPort : public ::modm::GpioPort/** @cond */, public GpioSetShim<StartGpio, Width>/** @endcond */ |
| 23 | +class GpioPort : public ::modm::GpioPort/** @cond */, public detail::GpioSetShim<StartGpio, Width>/** @endcond */ |
38 | 24 | {
|
39 |
| - using PinSet = GpioSetShim<StartGpio, Width>; |
| 25 | + using PinSet = detail::GpioSetShim<StartGpio, Width>; |
40 | 26 | public:
|
41 | 27 | using PinSet::width;
|
42 | 28 | static_assert(width <= 8, "Only a maximum of 8 pins are supported by GpioPort!");
|
@@ -83,61 +69,4 @@ public:
|
83 | 69 | }
|
84 | 70 | };
|
85 | 71 |
|
86 |
| -/// @cond |
87 |
| -// ------ Port Width Information ------ |
88 |
| -%% for port in ranges |
89 |
| -template<> |
90 |
| -struct GpioPortInfo<Gpio::Port::{{port["name"]}}> |
91 |
| -{ |
92 |
| - static constexpr int8_t Width = {{port["width"]}}; |
93 |
| - static constexpr int8_t StartPin = {{port["start"]}}; |
94 |
| - static constexpr int8_t EndPin = StartPin + Width; |
95 |
| - |
96 |
| - template< uint8_t QueryStartPin, int8_t QueryWidth > |
97 |
| - struct check |
98 |
| - { |
99 |
| - static constexpr bool isNormal = QueryWidth > 0; |
100 |
| - static constexpr bool isReversed = QueryWidth < 0; |
101 |
| - static constexpr int8_t width = isNormal ? QueryWidth : -QueryWidth; |
102 |
| - static_assert(isReversed or width <= Width, |
103 |
| - "GpioPort Width out of bounds! Maximum is {{port["width"]}}."); |
104 |
| - |
105 |
| - static_assert(isReversed or (QueryStartPin + QueryWidth <= EndPin), |
106 |
| - "GpioPort StartPin + Width out of bounds! Maximum is {{port["start"] + port["width"] - 1}}."); |
107 |
| - static_assert(isNormal or (StartPin <= QueryStartPin + QueryWidth + 1), |
108 |
| - "GpioPort StartPin - Width out of bounds! Minimum is {{port["start"]}}."); |
109 |
| - }; |
110 |
| -}; |
111 |
| -%% endfor |
112 |
| - |
113 |
| -// ------ Translator classes from Gpio + Width -> GpioSet ------ |
114 |
| -template< class StartGpio, int8_t offset > |
115 |
| -struct GpioShim |
116 |
| -{ |
117 |
| - static constexpr typename StartGpio::Port port = StartGpio::port; |
118 |
| - static constexpr uint8_t mask = (1ul << (StartGpio::pin + offset)); |
119 |
| - static constexpr bool isInverted = StartGpio::isInverted; |
120 |
| -}; |
121 |
| -%% for width in range(-8, 0) |
122 |
| -template< class StartGpio > |
123 |
| -struct GpioSetShim<StartGpio, {{width}}> : public GpioSet< |
124 |
| - %% for offset in (range(width + 1, 1) | reverse) |
125 |
| - GpioShim<StartGpio, {{offset}}>{% if not loop.last %},{% endif %} |
126 |
| - %% endfor |
127 |
| - > { static typename GpioPortInfo<StartGpio::port>::template check<StartGpio::pin, {{width}}> check; }; |
128 |
| -%% endfor |
129 |
| -%% for width in range(0, 9) |
130 |
| -template< class StartGpio > |
131 |
| -struct GpioSetShim<StartGpio, {{width}}> : public GpioSet< |
132 |
| - %% for offset in (range(width) | reverse) |
133 |
| - GpioShim<StartGpio, {{offset}}>{% if not loop.last %},{% endif %} |
134 |
| - %% endfor |
135 |
| - > { static typename GpioPortInfo<StartGpio::port>::template check<StartGpio::pin, {{width}}> check; }; |
136 |
| -%% endfor |
137 |
| -/// @endcond |
138 |
| - |
139 |
| -} // namespace platform |
140 |
| - |
141 |
| -} // namespace modm |
142 |
| - |
143 |
| -#endif // MODM_AVR_GPIO_PORT_HPP |
| 72 | +} // namespace modm::platform |
0 commit comments