Skip to content

Commit a5f0511

Browse files
committed
[modm-devices] Refactor data access
1 parent 00301ca commit a5f0511

File tree

42 files changed

+394
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+394
-825
lines changed

README.md

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

7373
modm can generate code for <!--avrcount-->506<!--/avrcount-->
74-
AVR, <!--samcount-->163<!--/samcount--> SAM and <!--stmcount-->2010<!--/stmcount-->
74+
AVR, <!--samcount-->163<!--/samcount--> SAM and <!--stmcount-->2110<!--/stmcount-->
7575
STM32 devices, however, there are different levels of support and testing.
7676

7777
<center>

examples/nucleo_f767zi/ethernet/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ main()
188188
Leds::setOutput();
189189
MODM_LOG_INFO << "\n\nReboot: Ethernet Example" << modm::endl;
190190

191-
Ethernet::Port::connect<Ethernet::RMII_Ref_Clk::Refclk,
191+
Ethernet::Port::connect<
192+
Ethernet::RMII_Ref_Clk::RefClk,
192193
Ethernet::RMII_Mdc::Mdc,
193194
Ethernet::RMII_Mdio::Mdio,
194-
Ethernet::RMII_Crs_Dv::Rcccrsdv,
195-
Ethernet::RMII_Tx_En::Txen,
195+
Ethernet::RMII_Crs_Dv::RccCrsDv,
196+
Ethernet::RMII_Tx_En::TxEn,
196197
Ethernet::RMII_Tx_D0::Txd0,
197198
Ethernet::RMII_Tx_D1::Txd1,
198199
Ethernet::RMII_Rx_D0::Rxd0,

ext/modm-devices

Submodule modm-devices updated 148 files

repo.lb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ def init(repo):
240240
repo.add_filter("modm.ord", lambda letter: ord(letter[0].lower()) - ord("a"))
241241
repo.add_filter("modm.chr", lambda num: chr(num + ord("A")))
242242

243+
# Global filters for naming things
244+
def fmt_str(s):
245+
return "".join(p.capitalize() for p in str(s).split("_"))
246+
def fmt_driver(d):
247+
return fmt_str(d.get("driver", "")) + fmt_str(d.get("instance", ""))
248+
repo.add_filter("modm.fmt", fmt_str)
249+
repo.add_filter("modm.fmt.driver", fmt_driver)
250+
243251
# Compute the available data from modm-devices
244252
devices = DevicesCache()
245253
try:

src/modm/board/disco_f746ng/board.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ initializeUsbHs()
219219
{
220220
usb_hs::Device::initialize<SystemClock>();
221221
usb_hs::Device::connect<
222-
usb_hs::Ck::Ulpick, usb_hs::Stp::Ulpistp,
223-
usb_hs::Dir::Ulpidir, usb_hs::Nxt::Ulpinxt,
224-
usb_hs::D0::Ulpid0, usb_hs::D1::Ulpid1,
225-
usb_hs::D2::Ulpid2, usb_hs::D3::Ulpid3,
226-
usb_hs::D4::Ulpid4, usb_hs::D5::Ulpid5,
227-
usb_hs::D6::Ulpid6, usb_hs::D7::Ulpid7>();
222+
usb_hs::Ck::UlpiCk, usb_hs::Stp::UlpiStp,
223+
usb_hs::Dir::UlpiDir, usb_hs::Nxt::UlpiNxt,
224+
usb_hs::D0::UlpiD0, usb_hs::D1::UlpiD1,
225+
usb_hs::D2::UlpiD2, usb_hs::D3::UlpiD3,
226+
usb_hs::D4::UlpiD4, usb_hs::D5::UlpiD5,
227+
usb_hs::D6::UlpiD6, usb_hs::D7::UlpiD7>();
228228
usb_hs::Overcurrent::setInput();
229229

230230
// Deactivate VBUS Sensing B

src/modm/driver/gpio/gpio_sampler.lb

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,22 @@ def prepare(module, options):
1919
if options[":target"].identifier["platform"] != "stm32":
2020
return False
2121

22-
core = options[":target"].get_driver("core:cortex-m*")
22+
core = options[":target"].driver("core").type
2323
# Cortex-M0 doesn't have the DWT->CYCCNT and Cortex-M7 support is broken
24-
if not core or "m0" in core["type"] or "m7" in core["type"]:
24+
if "m0" in core or "m7" in core:
2525
return False
2626

2727
module.depends(
2828
":platform:gpio",
2929
":platform:core",
3030
":architecture:interrupt")
31+
3132
return True
3233

3334

3435
def build(env):
35-
exti_vectors = [v["name"] for v in env[":target"].get_driver("core")["vector"] if "EXTI" in v["name"]]
36-
# These are all exti possible vectors: 0, 0_1, 1, 15_10, 2, 2_3, 2_TSC, 3, 4, 4_15, 9_5
37-
extimap = {
38-
"0": [0], "1": [1], "2": [2], "3": [3], "4": [4],
39-
"0_1": [0,1],
40-
"2_TSC": [2],
41-
"2_3": [2,3],
42-
"4_15": [4,5,6,7,8,9,10,11,12,13,14,15],
43-
"9_5": [5,6,7,8,9],
44-
"15_10": [10,11,12,13,14,15],
45-
}
46-
extis = OrderedDict()
47-
for v in sorted(exti_vectors):
48-
extis[v] = extimap[v[4:]]
49-
5036
env.substitutions = {
51-
"extis": extis,
37+
"extis": env[":target"].core.shared_irqs("EXTI"),
5238
"vectors_location": env.get(":platform:core:vector_table_location", "rom")
5339
}
5440
env.outbasepath = "modm/src/modm/driver"

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,17 @@ def prepare(module, options):
7070
return False
7171
global props
7272
props = {}
73-
driver = device.get_driver("adc")
7473
props["target"] = target = device.identifier
75-
props["driver"] = driver
7674
props["instances"] = []
7775

78-
if target["family"] in ["f2", "f4", "f7"]:
79-
props["shared_irqs"] = {"ADC": listify(device.get_driver("adc")["instance"])}
80-
props["shared_irq_ids"] = props["shared_irqs"]["ADC"]
76+
if target["family"] in ["f2", "f4", "f7", "l1", "f1"]:
77+
irq_name = next(device.core.vectors(lambda v: v.startswith("ADC")), "ADC")
78+
instances = [i.number for i in device.driver("adc").instances()]
79+
props["shared_irqs"] = {irq_name: instances}
80+
props["shared_irq_ids"] = instances
8181
else:
82-
shared_irqs = [v["name"] for v in device.get_driver("core")["vector"]]
83-
shared_irqs = [v for v in shared_irqs if v.startswith("ADC") and "_" in v]
84-
props["shared_irqs"] = {}
85-
props["shared_irq_ids"] = []
86-
for irq in shared_irqs:
87-
parts = irq[3:].split("_")
88-
shared_irqs_ids = (int(parts[0]), int(parts[1]) )
89-
props["shared_irqs"][irq] = shared_irqs_ids
90-
props["shared_irq_ids"].extend(shared_irqs_ids)
91-
82+
props["shared_irqs"] = device.core.shared_irqs("ADC")
83+
props["shared_irq_ids"] = list(props["shared_irqs"].values())[0]
9284

9385
module.depends(
9486
":architecture:adc",
@@ -99,21 +91,18 @@ def prepare(module, options):
9991
":math:algorithm",
10092
":utils")
10193

102-
for instance in listify(device.get_driver("adc").get("instance", [])):
103-
module.add_submodule(Instance(int(instance)))
94+
for instance in device.driver("adc").instances():
95+
module.add_submodule(Instance(instance.number))
10496

10597
return True
10698

10799
def build(env):
108100
device = env[":target"]
109-
driver = device.get_driver("adc")
110-
111101
global props
112-
113102
env.substitutions = props
114103
env.outbasepath = "modm/src/modm/platform/adc"
115104

116-
if device.get_driver("adc").get("instance", None) is None:
105+
if not device.driver("adc").instances():
117106
Instance(None).build(env)
118107

119108
if any(i in props["shared_irq_ids"] for i in props["instances"]):

src/modm/platform/adc/stm32f0/module.lb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def init(module):
1818

1919
def prepare(module, options):
2020
device = options[":target"]
21-
if not (device.has_driver("adc:stm32-f0") or
22-
device.has_driver("adc:stm32-g0")):
21+
if not device.has_driver("adc:stm32-[fg]0"):
2322
return False
2423
module.depends(
2524
":architecture:delay",
@@ -33,11 +32,10 @@ def prepare(module, options):
3332

3433
def build(env):
3534
device = env[":target"]
36-
driver = device.get_driver("adc")
3735

3836
properties = {}
3937
properties["target"] = target = device.identifier
40-
properties["id"] = driver.get("instance", [""])[0]
38+
properties["id"] = device.driver("adc").instances([""])[0]
4139

4240
channels = {i:"In{}".format(i) for i in reversed(range(0,19))}
4341
if target.family in ["g0"]:
@@ -52,10 +50,7 @@ def build(env):
5250
else:
5351
channels[18] = "Battery"
5452
properties["channels"] = channels
55-
56-
irq = next(v["name"] for v in device.get_driver("core")["vector"]
57-
if v["name"].startswith("ADC1"))
58-
properties["irq"] = irq
53+
properties["irq"] = next(device.core.vectors(lambda v: v.startswith("ADC1")))
5954

6055
env.substitutions = properties
6156
env.outbasepath = "modm/src/modm/platform/adc"

src/modm/platform/adc/stm32f3/module.lb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ def prepare(module, options):
145145
":platform:gpio",
146146
":platform:rcc")
147147

148-
for instance in listify(device.get_driver("adc")["instance"]):
149-
module.add_submodule(Instance(int(instance)))
148+
for instance in device.driver("adc").instances():
149+
module.add_submodule(Instance(instance.number))
150150

151151
return True
152152

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ can_map = {
7777
}
7878

7979
def get_substitutions(env, instance):
80-
target = env["target"].identifier
81-
driver = env["target"].get_driver("can")
82-
instances = map(lambda i: int(i), driver["instance"]) if "instance" in driver else (0,)
80+
device = env[":target"]
81+
target = device.identifier
82+
83+
driver = device.get_driver("can")
84+
instances = (i.number for i in device.driver("can").instances())
85+
instances = instances if instances else [0]
8386

8487
cm = can_map[target.family]
8588
is_single = (cm[instance].type == CanType.Single) or (cm[instance].associated_instance not in instances)
@@ -140,12 +143,12 @@ def prepare(module, options):
140143
":platform:rcc",
141144
":utils")
142145

143-
driver = device.get_driver("can")
146+
instances = device.driver("can").instances()
144147
# If there is only one instance of the peripheral it is not numbered and
145148
# merged into the generic can module.
146-
if "instance" in driver:
147-
for instance in listify(driver["instance"]):
148-
module.add_submodule(Instance(int(instance)))
149+
if instances:
150+
for instance in instances:
151+
module.add_submodule(Instance(instance.number))
149152
else:
150153
load_options(module)
151154

@@ -158,7 +161,7 @@ def build(env):
158161
env.template("can_filter.hpp.in")
159162
env.template("can_filter.cpp.in")
160163

161-
if "instance" not in driver:
164+
if not env[":target"].driver("can").instances():
162165
env.substitutions = get_substitutions(env, 0)
163166
env.template("can.hpp.in")
164167
env.template("can.cpp.in")

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def prepare(module, options):
2121
if not options[":target"].has_driver("rcc:stm32*"):
2222
return False
2323

24-
module.depends(":cmsis:device", ":utils", ":platform:clock")
25-
# FIXME: Move Peripherals enum somewhere better
26-
module.depends(":platform:gpio")
24+
module.depends(":cmsis:device", ":utils", ":platform:clock", ":platform:core")
2725
return True
2826

2927
def build(env):
@@ -67,31 +65,18 @@ def build(env):
6765
properties["pllsai_p_usb"] = (target["family"] == "f7") or \
6866
((target["family"] == "f4") and target["name"] in ["46", "69", "79"])
6967

70-
flash_latencies = {}
71-
for vcore in device.get_driver("flash")["latency"]:
72-
flash_latencies[int(vcore["vcore-min"])] = sorted([int(f["hclk-max"]) for f in vcore["wait-state"]])
73-
74-
properties["table"] = flash_latencies
68+
properties["table"] = device.flash.wait_states
7569
env.substitutions = properties
7670
env.outbasepath = "modm/src/modm/platform/clock"
7771

7872
env.template("rcc.cpp.in")
7973
env.template("rcc.hpp.in")
8074

81-
all_peripherals = set()
82-
all_drivers = [d for d in device._properties["driver"] if d["name"] not in ["gpio", "core"]]
83-
translate = lambda s: s.replace("_", "").capitalize()
84-
for d in all_drivers:
85-
dname = translate(d["name"])
86-
if "instance" in d:
87-
all_peripherals.update(dname + translate(i) for i in d["instance"])
88-
else:
89-
all_peripherals.add(dname)
90-
all_peripherals = sorted(list(all_peripherals))
91-
9275
rcc_map = env.query(":cmsis:device:rcc-map")
9376
rcc_enable = {}
9477
rcc_reset = {}
78+
all_peripherals = uniquify(map(env.filter("modm.fmt.driver"), env[":target"].peripherals))
79+
all_peripherals_lut = {p.lower():p for p in all_peripherals}
9580

9681
for per, mode in rcc_map.items():
9782
nper = per
@@ -110,14 +95,14 @@ def build(env):
11095
if "Eth" in all_peripherals and per == "ETHMAC":
11196
per = "Eth"
11297
# Fix USBOTG OTG
113-
if "Usbotgfs" in all_peripherals and per.startswith("OTG"):
98+
if "UsbOtgFs" in all_peripherals and per.startswith("OTG"):
11499
if per == "OTGH": per = "OTGHS";
115100
per = "USB"+per
116101
# print(per, mode)
117-
if per.capitalize() not in all_peripherals:
102+
if per.lower() not in all_peripherals_lut:
118103
continue
119104
if "EN" in mode:
120-
rcc_enable[per.capitalize()] = (nper, mode["EN"])
105+
rcc_enable[all_peripherals_lut[per.lower()]] = (nper, mode["EN"])
121106
if "RST" in mode:
122107
rcc_reset[nper] = mode["RST"]
123108

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ namespace modm::platform
1919
/// @ingroup modm_platform_comp
2020
class CompBase
2121
{
22-
{% if driver.type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
22+
{% if type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
2323
public:
2424
enum class
2525
Mode
2626
{
27-
{% if driver.type in ["stm32-v1.3"] -%}
27+
{% if type in ["stm32-v1.3"] -%}
2828
UltraLowPower = 0b00 << 2,
2929
LowPower = 0b01 << 2,
3030
MediumSpeed = 0b10 << 2,
3131
HighSpeed = 0b11 << 2,
32-
{% elif driver.type in ["stm32-tsmc90_cube"] -%}
32+
{% elif type in ["stm32-tsmc90_cube"] -%}
3333
HighSpeed = 0b00 << 2,
3434
MediumSpeed = 0b01 << 2,
3535
//MediumSpeed2 = 0b10 << 2,
@@ -50,7 +50,7 @@ namespace modm::platform
5050
protected:
5151
static constexpr uint32_t PolarityMask = 0b1 << 15;
5252

53-
{% if driver.type in ["stm32-v1.3", "stm32-tsmc90_cube"] -%}
53+
{% if type in ["stm32-v1.3", "stm32-tsmc90_cube"] -%}
5454
public:
5555
enum class
5656
Hysteresis
@@ -62,7 +62,7 @@ namespace modm::platform
6262
};
6363
protected:
6464
static constexpr uint32_t HysteresisMask = 0b11 << 16;
65-
{% elif "g4" in driver.type -%}
65+
{% elif "g4" in type -%}
6666
public:
6767
enum class
6868
Hysteresis

src/modm/platform/comp/stm32/comp.hpp.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ namespace modm::platform
234234
Output out = Output::NoSelection,
235235
{% endif -%}
236236
Hysteresis hyst = Hysteresis::NoHysteresis,
237-
{% if driver.type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
237+
{% if type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
238238
Mode mode = Mode::HighSpeed,
239239
{% endif -%}
240240
Polarity pol = Polarity::NonInverted,
@@ -248,7 +248,7 @@ namespace modm::platform
248248
setOutputSelection(out);
249249
{% endif -%}
250250
setHysteresis(hyst);
251-
{% if driver.type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
251+
{% if type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
252252
setMode(mode);
253253
{% endif -%}
254254
setPolarity(pol);
@@ -308,7 +308,7 @@ namespace modm::platform
308308
}
309309
{% endif -%}
310310

311-
{% if driver.type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
311+
{% if type not in ["stm32-tsmc90_g4_rockfish_cube"] -%}
312312
/**
313313
* \brief Sets the mode that determins speed/power consumption.
314314
*

0 commit comments

Comments
 (0)