Skip to content

Commit ebf252a

Browse files
committed
[modm-devices] Refactor data access
1 parent 17f313a commit ebf252a

File tree

18 files changed

+250
-573
lines changed

18 files changed

+250
-573
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ git clone --recurse-submodules https://github.com/modm-io/modm.git
7070

7171
## Targets
7272

73-
modm can generate code for <!--avrcount-->530<!--/avrcount--> AVR and <!--stmcount-->1959<!--/stmcount-->
73+
modm can generate code for <!--avrcount-->506<!--/avrcount--> AVR and <!--stmcount-->1959<!--/stmcount-->
7474
STM32 devices, however, there are different levels of support and testing.
7575

7676
<center>

ext/arm/core.lb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def build(env):
2929
env.copy("cmsis/CMSIS/Core/Include/cmsis_gcc.h", "cmsis_gcc.h")
3030
if core != "0": # 0+ has MPU support though!
3131
env.copy("cmsis/CMSIS/Core/Include/mpu_armv7.h", "mpu_armv7.h")
32-
print(core)
3332
if core == "7":
3433
env.copy("cmsis/CMSIS/Core/Include/cachel1_armv7.h", "cachel1_armv7.h")
3534

ext/modm-devices

Submodule modm-devices updated 91 files

repo.lb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from os.path import normpath
2424

2525
# Check for miminum required lbuild version
2626
import lbuild
27-
min_lbuild_version = "1.13.2"
27+
min_lbuild_version = "1.13.4"
2828
if StrictVersion(getattr(lbuild, "__version__", "0.1.0")) < StrictVersion(min_lbuild_version):
2929
print("modm requires at least lbuild v{}, please upgrade!\n"
3030
" pip3 install -U lbuild".format(min_lbuild_version))
@@ -234,6 +234,14 @@ def init(repo):
234234
repo.add_filter("modm.ord", lambda letter: ord(letter[0].lower()) - ord("a"))
235235
repo.add_filter("modm.chr", lambda num: chr(num + ord("A")))
236236

237+
# Global filters for naming things
238+
def fmt_str(s):
239+
return "".join(p.capitalize() for p in str(s).split("_"))
240+
def fmt_driver(d):
241+
return fmt_str(d.get("driver", "")) + fmt_str(d.get("instance", ""))
242+
repo.add_filter("modm.fmt", fmt_str)
243+
repo.add_filter("modm.fmt.driver", fmt_driver)
244+
237245
# Compute the available data from modm-devices
238246
devices = DevicesCache()
239247
try:

src/modm/platform/core/cortex/module.lb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
1212
# -----------------------------------------------------------------------------
1313

14+
import copy
15+
1416
def common_vector_table_location(env):
1517
return env.get(":platform:cortex-m:vector_table_location", "rom")
1618

@@ -72,7 +74,7 @@ def common_memories(env):
7274
:returns: dictionary of memory properties
7375
"""
7476
device = env[":target"]
75-
memories = listify(device.get_driver("core")["memory"])
77+
memories = copy.deepcopy(listify(device.get_driver("core")["memory"]))
7678

7779
# Convert from string to int and add offsets
7880
flash_offset = env.get(":platform:cortex-m:linkerscript.flash_offset", 0)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def build(env):
3535

3636
def post_build(env):
3737
properties = env.query("::cortex-m:linkerscript")
38-
target = env[":target"].identifier
38+
device = env[":target"]
3939
properties["with_crashcatcher"] = env.has_module(":crashcatcher")
4040

41-
if target.family in ["l4"]: # FIXME!
41+
if device.identifier.family in ["l4"]: # FIXME!
4242
properties["regions"].remove("sram2")
4343
if "backup" in properties["regions"]:
4444
properties["regions"].remove("backup")
@@ -69,3 +69,9 @@ def post_build(env):
6969
env.substitutions = properties
7070
env.outbasepath = "modm/link"
7171
env.template("linkerscript/stm32_{}.ld.in".format(linkerscript), "linkerscript.ld")
72+
73+
# Generate a list of all on-device peripherals
74+
peripherals = uniquify(map(env.filter("modm.fmt.driver"), device.peripherals))
75+
env.substitutions = {"peripherals": peripherals}
76+
env.outbasepath = "modm/src/modm/platform/core"
77+
env.template("peripherals.hpp.in")
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Niklas Hauser
2+
* Copyright (c) 2019-2020, Niklas Hauser
33
*
44
* This file is part of the modm project.
55
*
@@ -9,22 +9,20 @@
99
*/
1010
// ----------------------------------------------------------------------------
1111

12-
#ifndef MODM_STM32_PERIPHERALS_HPP
13-
#define MODM_STM32_PERIPHERALS_HPP
12+
#pragma once
1413

1514
namespace modm::platform
1615
{
1716

17+
/// @ingroup modm_platform_core
1818
enum class
1919
Peripheral
2020
{
2121
BitBang,
22-
%% for per in all_peripherals
22+
%% for per in peripherals
2323
{{ per }},
2424
%% endfor
2525
Syscfg = Sys,
2626
};
2727

2828
}
29-
30-
#endif // MODM_STM32_PERIPHERALS_HPP

src/modm/platform/gpio/at90_tiny_mega/base.hpp.in

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
#include "define.h"
1616
#include <modm/architecture/interface/gpio.hpp>
1717

18-
namespace modm
19-
{
20-
21-
namespace platform
18+
namespace modm::platform
2219
{
2320

2421
/// @ingroup modm_platform_gpio
@@ -95,7 +92,7 @@ protected:
9592
template< class Pin >
9693
class GpioOpenDrain : public Pin
9794
{
98-
static Gpio::InputType inputType;
95+
static inline Gpio::InputType inputType{Gpio::InputType::Floating};
9996
static_assert(Pin::direction == modm::Gpio::Direction::InOut, "Pin must inherit from modm::GpioIO");
10097
public:
10198
using Output = GpioOpenDrain<typename Pin::IO>;
@@ -143,12 +140,6 @@ public:
143140
}
144141
};
145142

146-
} // namespace platform
147-
148143
} // namespace modm
149144

150-
template< class Pin >
151-
modm::platform::Gpio::InputType
152-
modm::platform::GpioOpenDrain<Pin>::inputType(modm::platform::Gpio::InputType::Floating);
153-
154145
#endif // MODM_AVR_GPIO_BASE_HPP

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct Gpio
2626
enum class
2727
InputType
2828
{
29-
%% if target["family"] in ["f1"]
29+
%% if target.family in ["f1"]
3030
Floating = 0x4, ///< floating on input
3131
PullUp = 0x9, ///< pull-up on input
3232
PullDown = 0x8, ///< pull-down on input
@@ -41,7 +41,7 @@ struct Gpio
4141
OutputType
4242
{
4343
PushPull = 0x0, ///< push-pull on output
44-
%% if target["family"] in ["f1"]
44+
%% if target.family in ["f1"]
4545
OpenDrain = 0x4, ///< open-drain on output
4646
%% else
4747
OpenDrain = 0x1, ///< open-drain on output
@@ -51,14 +51,14 @@ struct Gpio
5151
enum class
5252
OutputSpeed
5353
{
54-
%% if target["family"] in ["f1"]
54+
%% if target.family in ["f1"]
5555
Low = 0x2,
5656
Medium = 0x1,
5757
High = 0x3,
5858
MHz2 = Low,
5959
MHz10 = Medium,
6060
MHz50 = High,
61-
%% elif target["family"] in ["f0", "f3"]
61+
%% elif target.family in ["f0", "f3"]
6262
Low = 0,
6363
Medium = 0x1,
6464
High = 0x3,
@@ -99,15 +99,15 @@ struct Gpio
9999
Signal
100100
{
101101
BitBang,
102-
%% for signal in all_signals
103-
{{ signal }},
102+
%% for signal in signal_names
103+
{{ signal | modm.fmt }},
104104
%% endfor
105105
};
106106
/// @endcond
107107

108108
protected:
109109
/// @cond
110-
%% if target["family"] not in ["f1"]
110+
%% if target.family not in ["f1"]
111111
/// I/O Direction Mode values for this specific pin.
112112
enum class
113113
Mode

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static constexpr uint8_t lmb(uint32_t value)
3434
} // namespace detail
3535

3636
// specializations
37-
%% for remap in driver.remap
37+
%% for remap in signal_remap
3838
%% set reg = "MAPR" if (remap["position"] | int) < 32 else "MAPR2"
39-
%% set per = remap | formatPeripheral
39+
%% set per = remap | modm.fmt.driver
4040
template< template<Peripheral _> class... Signals >
4141
struct GpioConnector<Peripheral::{{ per }}, Signals...>
4242
{
@@ -51,14 +51,14 @@ struct GpioConnector<Peripheral::{{ per }}, Signals...>
5151
{
5252
using namespace detail_gpio_connector;
5353
static constexpr uint32_t id = detail::GpioSignalConnect<Peripheral::{{ per }}, Signals...>::id;
54-
static_assert((id == uint32_t(-1)) || {% for group in remap.group %}(lmb(id) == {{group.id}}UL){% if not loop.last %} || {% else %},{% endif %}{% endfor %}
54+
static_assert((id == uint32_t(-1)) || {% for group in remap.group %}(lmb(id) == {{group.id}}ul){% if not loop.last %} || {% else %},{% endif %}{% endfor %}
5555
"This pin set contains conflicting remap groups!\nAvailable groups for {{per}} are:\n"
5656
%% for line in group_map | printSignalMap(per)
5757
"{{line}}\n"
5858
%% endfor
5959
);
6060
if (id != uint32_t(-1)) {
61-
AFIO->{{reg}} = (AFIO->{{reg}} & ~({{ remap["mask"] }}UL << {{ (remap["position"] | int) % 32 }})) | (lmb(id) << {{ (remap["position"] | int) % 32 }});
61+
AFIO->{{reg}} = (AFIO->{{reg}} & ~({{ remap.mask }}ul << {{ (remap.position | int) % 32 }})) | (lmb(id) << {{ (remap.position | int) % 32 }});
6262
}
6363
detail::GpioSignalConnect<Peripheral::{{ per }}, Signals...>::connect();
6464
}

0 commit comments

Comments
 (0)