Skip to content

Commit a3d21e3

Browse files
committed
[stm32] Get timer signalToChannel() information from device data
1 parent 38338fe commit a3d21e3

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Copyright (c) 2016-2018, Niklas Hauser
55
# Copyright (c) 2017, Fabian Greif
6-
# Copyright (c) 2020, Christopher Durand
6+
# Copyright (c) 2020-2023, Christopher Durand
77
#
88
# This file is part of the modm project.
99
#
@@ -164,6 +164,9 @@ def prepare(module, options):
164164
":cmsis:device",
165165
":math:utils",
166166
":platform:rcc")
167+
168+
module.add_query(EnvironmentQuery(name="all_signals", factory=lambda env: bprops["all_signals"]))
169+
167170
return True
168171

169172
def validate(env):

src/modm/platform/timer/stm32/general_purpose_base.hpp.in

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2013, Kevin Läufer
33
* Copyright (c) 2014, Fabian Greif
44
* Copyright (c) 2014-2017, Niklas Hauser
5-
* Copyright (c) 2022, Christopher Durand
5+
* Copyright (c) 2022-2023, Christopher Durand
66
*
77
* This file is part of the modm project.
88
*
@@ -275,28 +275,15 @@ protected:
275275
signalToChannel()
276276
{
277277
modm::platform::detail::SignalConnection<Signal, p>{};
278-
if constexpr (Signal::Signal == Gpio::Signal::Ch1) {
279-
return 1;
280-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch2) {
281-
return 2;
282-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch3) {
283-
return 3;
284-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch4) {
285-
return 4;
286-
%% if target.family not in ["l0","l1"]
287-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch1n) {
288-
return 1;
289-
%% if target.family not in ["f3"]
290-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch2n) {
291-
return 2;
292-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch3n) {
293-
return 3;
294-
%% if target.family in ["g4","u5","h5"]
295-
} else if constexpr (Signal::Signal == Gpio::Signal::Ch4n) {
296-
return 4;
297-
%% endif
298-
%% endif
278+
%% for signal, number in signals
279+
%% if loop.first
280+
if constexpr (Signal::Signal == Gpio::Signal::{{ signal }}) {
281+
return {{ number }};
282+
%% else
283+
} else if constexpr (Signal::Signal == Gpio::Signal::{{ signal }}) {
284+
return {{ number }};
299285
%% endif
286+
%% endfor
300287
} else {
301288
// assert is always false, static_assert(false) would not compile
302289
static_assert(!sizeof(Signal), "Invalid timer channel");

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
#
44
# Copyright (c) 2016-2018, Niklas Hauser
5+
# Copyright (c) 2023, Christopher Durand
56
#
67
# This file is part of the modm project.
78
#
@@ -11,22 +12,9 @@
1112
# -----------------------------------------------------------------------------
1213

1314
from collections import defaultdict
14-
props = {}
15+
import re
1516

16-
def get_connectors(instance):
17-
if instance in [1, 8]:
18-
return ["Channel1", "Channel1N", "Channel2", "Channel2N",
19-
"Channel3", "Channel3N", "Channel4", "Channel4N",
20-
"ExternalTrigger", "BreakIn"]
21-
elif instance in [2, 3, 4, 5, 19]:
22-
return ["Channel1", "Channel2", "Channel3", "Channel4", "ExternalTrigger"]
23-
elif instance in [9, 12]:
24-
return ["Channel1", "Channel2"]
25-
elif instance in [10, 11, 13, 14]:
26-
return ["Channel1"]
27-
elif instance in [15, 16, 17]:
28-
return ["Channel1", "Channel1N", "Channel2", "BreakIn"]
29-
return []
17+
props = {}
3018

3119
class Instance(Module):
3220
def __init__(self, driver, instance):
@@ -73,7 +61,6 @@ class Instance(Module):
7361
def build(self, env):
7462
global props
7563
props["id"] = self.instance
76-
props["connectors"] = get_connectors(self.instance)
7764
props["vectors"] = self.vectors
7865
props["types"].add(self.type)
7966

@@ -129,6 +116,10 @@ def build(env):
129116
env.substitutions = props
130117
env.outbasepath = "modm/src/modm/platform/timer"
131118

119+
pattern = re.compile("^(Ch([1-6])n{0,1})$")
120+
all_signals = env.query(":platform:gpio:all_signals")
121+
props["signals"] = [pattern.match(s).groups() for s in all_signals if pattern.match(s)]
122+
132123
# Only generate the base types for timers that were generated
133124
types = props["types"]
134125
if "advanced" in types:

0 commit comments

Comments
 (0)