Skip to content

Commit

Permalink
[stm32] Get timer signalToChannel() information from device data
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed May 10, 2023
1 parent 44a6653 commit 121f4ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 39 deletions.
5 changes: 4 additions & 1 deletion src/modm/platform/gpio/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
# Copyright (c) 2020, Christopher Durand
# Copyright (c) 2020-2023, Christopher Durand
#
# This file is part of the modm project.
#
Expand Down Expand Up @@ -164,6 +164,9 @@ def prepare(module, options):
":cmsis:device",
":math:utils",
":platform:rcc")

module.add_query(EnvironmentQuery(name="all_signals", factory=lambda env: bprops["all_signals"]))

return True

def validate(env):
Expand Down
31 changes: 9 additions & 22 deletions src/modm/platform/timer/stm32/general_purpose_base.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2013, Kevin Läufer
* Copyright (c) 2014, Fabian Greif
* Copyright (c) 2014-2017, Niklas Hauser
* Copyright (c) 2022, Christopher Durand
* Copyright (c) 2022-2023, Christopher Durand
*
* This file is part of the modm project.
*
Expand Down Expand Up @@ -275,28 +275,15 @@ protected:
signalToChannel()
{
modm::platform::detail::SignalConnection<Signal, p>{};
if constexpr (Signal::Signal == Gpio::Signal::Ch1) {
return 1;
} else if constexpr (Signal::Signal == Gpio::Signal::Ch2) {
return 2;
} else if constexpr (Signal::Signal == Gpio::Signal::Ch3) {
return 3;
} else if constexpr (Signal::Signal == Gpio::Signal::Ch4) {
return 4;
%% if target.family not in ["l0","l1"]
} else if constexpr (Signal::Signal == Gpio::Signal::Ch1n) {
return 1;
%% if target.family not in ["f3"]
} else if constexpr (Signal::Signal == Gpio::Signal::Ch2n) {
return 2;
} else if constexpr (Signal::Signal == Gpio::Signal::Ch3n) {
return 3;
%% if target.family in ["g4","u5","h5"]
} else if constexpr (Signal::Signal == Gpio::Signal::Ch4n) {
return 4;
%% endif
%% endif
%% for signal, number in signals
%% if loop.first
if constexpr (Signal::Signal == Gpio::Signal::{{ signal }}) {
return {{ number }};
%% else
} else if constexpr (Signal::Signal == Gpio::Signal::{{ signal }}) {
return {{ number }};
%% endif
%% endfor
} else {
// assert is always false, static_assert(false) would not compile
static_assert(!sizeof(Signal), "Invalid timer channel");
Expand Down
23 changes: 7 additions & 16 deletions src/modm/platform/timer/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2023, Christopher Durand
#
# This file is part of the modm project.
#
Expand All @@ -11,22 +12,9 @@
# -----------------------------------------------------------------------------

from collections import defaultdict
props = {}
import re

def get_connectors(instance):
if instance in [1, 8]:
return ["Channel1", "Channel1N", "Channel2", "Channel2N",
"Channel3", "Channel3N", "Channel4", "Channel4N",
"ExternalTrigger", "BreakIn"]
elif instance in [2, 3, 4, 5, 19]:
return ["Channel1", "Channel2", "Channel3", "Channel4", "ExternalTrigger"]
elif instance in [9, 12]:
return ["Channel1", "Channel2"]
elif instance in [10, 11, 13, 14]:
return ["Channel1"]
elif instance in [15, 16, 17]:
return ["Channel1", "Channel1N", "Channel2", "BreakIn"]
return []
props = {}

class Instance(Module):
def __init__(self, driver, instance):
Expand Down Expand Up @@ -73,7 +61,6 @@ class Instance(Module):
def build(self, env):
global props
props["id"] = self.instance
props["connectors"] = get_connectors(self.instance)
props["vectors"] = self.vectors
props["types"].add(self.type)

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

pattern = re.compile("^(Ch([1-6])n{0,1})$")
all_signals = env.query(":platform:gpio:all_signals")
props["signals"] = [pattern.match(s).groups() for s in all_signals if pattern.match(s)]

# Only generate the base types for timers that were generated
types = props["types"]
if "advanced" in types:
Expand Down

0 comments on commit 121f4ad

Please sign in to comment.