2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# Copyright (c) 2016, Fabian Greif
5
- # Copyright (c) 2017, Niklas Hauser
5
+ # Copyright (c) 2017, 2024, Niklas Hauser
6
6
#
7
7
# This file is part of the modm project.
8
8
#
@@ -101,6 +101,7 @@ def common_rcc_map(env):
101
101
bprops ["peripherals" ] = peripherals
102
102
return rcc_map
103
103
104
+
104
105
def common_header_file (env ):
105
106
"""
106
107
Gives information about the STM32 header files. For example the STM32F469:
@@ -145,6 +146,45 @@ def common_header_file(env):
145
146
bprops ["folder" ] = folder
146
147
return headers
147
148
149
+
150
+ def common_peripherals (env ):
151
+ """
152
+ All peripherals translated to the modm naming convention.
153
+
154
+ :returns: a sorted list of all peripheral names.
155
+ """
156
+ def get_driver (s ):
157
+ name = None
158
+ if "driver" in s : name = translate (s ["driver" ])
159
+ if "instance" in s : name += translate (s ["instance" ])
160
+ return name
161
+
162
+ def translate (s ):
163
+ return s .replace ("_" , "" ).capitalize ()
164
+
165
+ device = env [":target" ]
166
+ gpio_driver = device .get_driver ("gpio" )
167
+ # Get all the peripherals from the GPIO remap-able signals
168
+ all_peripherals = {get_driver (remap ) for remap in gpio_driver .get ("remap" , [])}
169
+ # Get all the peripherals from the normal GPIO signals
170
+ all_peripherals .update (get_driver (s ) for gpio in gpio_driver ["gpio" ] for s in gpio .get ("signal" , []))
171
+ # Get all peripherals from the driver instances
172
+ all_drivers = (d for d in device ._properties ["driver" ] if d ["name" ] not in ["gpio" , "core" ])
173
+ for d in all_drivers :
174
+ dname = translate (d ["name" ])
175
+ if "instance" in d :
176
+ all_peripherals .update (dname + translate (i ) for i in d ["instance" ])
177
+ else :
178
+ all_peripherals .add (dname )
179
+ if dname == "Dma" and d ["type" ] == "stm32-mux" :
180
+ all_peripherals .add ("Dmamux1" )
181
+
182
+ all_peripherals .discard (None )
183
+ all_peripherals = sorted (list (all_peripherals ))
184
+ bprops ["all_peripherals" ] = all_peripherals
185
+ return all_peripherals
186
+
187
+
148
188
# -----------------------------------------------------------------------------
149
189
def init (module ):
150
190
module .name = ":cmsis:device"
@@ -157,6 +197,8 @@ def prepare(module, options):
157
197
158
198
module .add_query (
159
199
EnvironmentQuery (name = "rcc-map" , factory = common_rcc_map ))
200
+ module .add_query (
201
+ EnvironmentQuery (name = "peripherals" , factory = common_peripherals ))
160
202
module .add_query (
161
203
EnvironmentQuery (name = "headers" , factory = common_header_file ))
162
204
@@ -165,6 +207,7 @@ def prepare(module, options):
165
207
166
208
def validate (env ):
167
209
env .query ("rcc-map" )
210
+ env .query ("peripherals" )
168
211
169
212
def build (env ):
170
213
env .collect (":build:path.include" , "modm/ext" )
@@ -184,3 +227,6 @@ def build(env):
184
227
})
185
228
env .outbasepath = "modm/src/modm/platform"
186
229
env .template ("device.hpp.in" )
230
+
231
+ env .outbasepath = "modm/src/modm/platform/core"
232
+ env .template ("peripherals.hpp.in" )
0 commit comments