@@ -89,7 +89,7 @@ struct OneOfSignals
89
89
static constexpr bool value = ((std::is_same_v<typename Signal::signal, Signals>) | ...);
90
90
};
91
91
92
- %% if target["family"] in ["g"]
92
+ %% if target["family"] in ["g", "v" ]
93
93
94
94
template<class... PinConfigs>
95
95
struct PinMuxMixin
@@ -105,15 +105,13 @@ struct PinMuxMixin<PinConfig, PinConfigs...>
105
105
{
106
106
uint8_t bit0 = cfg & 1;
107
107
uint8_t bit1 = (cfg & 2) >> 1;
108
- if constexpr (PinConfig::port == PortName::A)
108
+ %% for port in ports
109
+ if constexpr (PinConfig::port == PortName::{{ port }})
109
110
{
110
- PIOA->PIO_ABCDSR[0] = (PIOA->PIO_ABCDSR[0] & ~(1<<PinConfig::pin)) | (bit0 << PinConfig::pin);
111
- PIOA->PIO_ABCDSR[1] = (PIOA->PIO_ABCDSR[1] & ~(1<<PinConfig::pin)) | (bit1 << PinConfig::pin);
112
- } else if constexpr (PinConfig::port == PortName::B)
113
- {
114
- PIOB->PIO_ABCDSR[0] = (PIOB->PIO_ABCDSR[0] & ~(1<<PinConfig::pin)) | (bit0 << PinConfig::pin);
115
- PIOB->PIO_ABCDSR[1] = (PIOB->PIO_ABCDSR[1] & ~(1<<PinConfig::pin)) | (bit1 << PinConfig::pin);
111
+ PIO{{ port }}->PIO_ABCDSR[0] = (PIO{{ port }}->PIO_ABCDSR[0] & ~(1<<PinConfig::pin)) | (bit0 << PinConfig::pin);
112
+ PIO{{ port }}->PIO_ABCDSR[1] = (PIO{{ port }}->PIO_ABCDSR[1] & ~(1<<PinConfig::pin)) | (bit1 << PinConfig::pin);
116
113
}
114
+ %% endfor
117
115
PinMuxMixin<PinConfigs...>::set(cfg);
118
116
}
119
117
};
@@ -134,36 +132,33 @@ protected:
134
132
inline static constexpr volatile uint32_t*
135
133
getPortReg(size_t offset)
136
134
{
137
- if constexpr (port == PortName::A) {
138
- return (uint32_t*)((uint8_t*)PIOA + offset);
139
- }
140
- if constexpr (port == PortName::B) {
141
- return (uint32_t*)((uint8_t*)PIOB + offset);
135
+ %% for port in ports
136
+ if constexpr (port == PortName::{{ port }}) {
137
+ return (uint32_t*)((uint8_t*)PIO{{ port }} + offset);
142
138
}
139
+ %% endfor
143
140
}
144
141
145
142
inline static constexpr void
146
143
setPortReg(size_t offset)
147
144
{
148
- if constexpr (mask(PortName::A) != 0) { *getPortReg<PortName::A>(offset) = mask(PortName::A); }
149
- if constexpr (mask(PortName::B) != 0) { *getPortReg<PortName::B>(offset) = mask(PortName::B); }
145
+ %% for port in ports
146
+ if constexpr (mask(PortName::{{ port }}) != 0) { *getPortReg<PortName::{{ port }}>(offset) = mask(PortName::{{ port }}); }
147
+ %% endfor
150
148
}
151
149
152
150
template<PortName port>
153
151
inline static constexpr uint32_t
154
152
readPortReg(size_t offset)
155
153
{
156
- if constexpr (port == PortName::A)
154
+ %% for port in ports
155
+ if constexpr (port == PortName::{{ port }})
157
156
{
158
- static_assert(mask(PortName::A) != 0,
159
- "Trying to read port which is not in the GpioSet!");
160
- return *getPortReg<PortName::A>(offset) & mask(PortName::A);
161
- } else if constexpr (port == PortName::B)
162
- {
163
- static_assert(mask(PortName::B) != 0,
164
- "Trying to read port which is not in the GpioSet!");
165
- return *getPortReg<PortName::B>(offset) & mask(PortName::B);
157
+ static_assert(mask(PortName::{{ port }}) != 0,
158
+ "Trying to read port which is not in the GpioSet!");
159
+ return *getPortReg<PortName::{{ port }}>(offset) & mask(PortName::{{ port }});
166
160
}
161
+ %% endfor
167
162
}
168
163
169
164
public:
@@ -236,18 +231,14 @@ public:
236
231
static void
237
232
toggle()
238
233
{
239
- if constexpr (mask(PortName::A) != 0) {
240
- volatile uint32_t *reg = getPortReg<PortName::A>(PIO_ODSR_OFFSET);
234
+ %% for port in ports
235
+ if constexpr (mask(PortName::{{ port }}) != 0) {
236
+ volatile uint32_t *reg = getPortReg<PortName::{{ port }}>(PIO_ODSR_OFFSET);
241
237
uint32_t tmp = *reg;
242
- tmp ^= mask(PortName::A);
243
- *reg = tmp;
244
- }
245
- if constexpr (mask(PortName::B) != 0) {
246
- volatile uint32_t *reg = getPortReg<PortName::B>(PIO_ODSR_OFFSET);
247
- uint32_t tmp = *reg;
248
- tmp ^= mask(PortName::B);
238
+ tmp ^= mask(PortName::{{ port }});
249
239
*reg = tmp;
250
240
}
241
+ %% endfor
251
242
}
252
243
253
244
static void
@@ -271,13 +262,10 @@ struct PinCfgMixin<PinConfig, PinConfigs...>
271
262
inline static void
272
263
set(uint8_t cfg)
273
264
{
274
- if constexpr (PinConfig::port == PortName::A)
275
- {
276
- PORT->Group[0].PINCFG[PinConfig::pin].reg = cfg;
277
- } else if constexpr (PinConfig::port == PortName::B)
278
- {
279
- PORT->Group[1].PINCFG[PinConfig::pin].reg = cfg;
280
- }
265
+ %% for port in ports
266
+ if constexpr (PinConfig::port == PortName::{{ port }})
267
+ PORT->Group[{{loop.index0}}].PINCFG[PinConfig::pin].reg = cfg;
268
+ %% endfor
281
269
PinCfgMixin<PinConfigs...>::set(cfg);
282
270
}
283
271
};
@@ -298,36 +286,31 @@ protected:
298
286
inline static constexpr volatile uint32_t*
299
287
getPortReg(size_t offset)
300
288
{
301
- if constexpr (port == PortName::A) {
302
- return (uint32_t*)(&PORT->Group[0]) + offset / sizeof(uint32_t);
303
- }
304
- if constexpr (port == PortName::B) {
305
- return (uint32_t*)(&PORT->Group[1]) + offset / sizeof(uint32_t);
306
- }
289
+ %% for port in ports
290
+ if constexpr (port == PortName::{{port}})
291
+ return (uint32_t*)(&PORT->Group[{{loop.index0}}]) + offset / sizeof(uint32_t);
292
+ %% endfor
307
293
}
308
294
309
295
inline static constexpr void
310
296
setPortReg(size_t offset)
311
297
{
312
- if constexpr (mask(PortName::A) != 0) { *getPortReg<PortName::A>(offset) = mask(PortName::A); }
313
- if constexpr (mask(PortName::B) != 0) { *getPortReg<PortName::B>(offset) = mask(PortName::B); }
298
+ %% for port in ports
299
+ if constexpr (mask(PortName::{{port}})) { *getPortReg<PortName::{{port}}>(offset) = mask(PortName::{{port}}); }
300
+ %% endfor
314
301
}
315
302
316
303
template<PortName port>
317
304
inline static constexpr uint32_t
318
305
readPortReg(size_t offset)
319
306
{
320
- if constexpr (port == PortName::A)
321
- {
322
- static_assert(mask(PortName::A) != 0,
323
- "Trying to read port which is not in the GpioSet!");
324
- return *getPortReg<PortName::A>(offset) & mask(PortName::A);
325
- } else if constexpr (port == PortName::B)
307
+ %% for port in ports
308
+ if constexpr (port == PortName::{{port}})
326
309
{
327
- static_assert(mask(PortName::B) != 0,
328
- "Trying to read port which is not in the GpioSet!");
329
- return *getPortReg<PortName::B>(offset) & mask(PortName::B);
310
+ static_assert(mask(PortName::{{port}}), "Trying to read port which is not in the GpioSet!");
311
+ return *getPortReg<PortName::{{port}}>(offset) & mask(PortName::{{port}});
330
312
}
313
+ %% endfor
331
314
}
332
315
333
316
public:
@@ -428,7 +411,7 @@ public:
428
411
inline static bool
429
412
read()
430
413
{
431
- %% if target["family"] in ["g"]
414
+ %% if target["family"] in ["g", "v" ]
432
415
return Base::readPortReg<PinConfig::port>(PIO_PDSR_OFFSET);
433
416
%% else
434
417
return Base::readPortReg<PinConfig::port>(PORT_IN_OFFSET);
@@ -491,13 +474,12 @@ struct Gpio<PinConfig>::As : public Gpio<PinConfig>
491
474
inline static void
492
475
connect()
493
476
{
494
- %% if target["family"] in ["g"]
477
+ %% if target["family"] in ["g", "v" ]
495
478
Pio* PIOBase;
496
- if constexpr (PinConfig::port == PortName::A) {
497
- PIOBase = PIOA;
498
- } else {
499
- PIOBase = PIOB;
500
- }
479
+ %% for port in ports
480
+ if constexpr (PinConfig::port == PortName::{{ port }})
481
+ PIOBase = PIO{{ port }};
482
+ %% endfor
501
483
PIOBase->PIO_PDR = (1<<PinConfig::pin);
502
484
Base::PinMux::set((uint32_t)PinSignal::function);
503
485
%% else
0 commit comments