-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ext] Add modm:cmsis:device module for SAM devices
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2019 Niklas Hauser | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_DEVICE_HPP | ||
#define MODM_DEVICE_HPP | ||
|
||
#define DONT_USE_CMSIS_INIT 1 | ||
%% for define in defines | ||
#define {{ define }} 1 | ||
%% endfor | ||
|
||
#include <stdint.h> | ||
// Defines for example the modm_always_inline macro | ||
#include <modm/architecture/utils.hpp> | ||
|
||
// Include external device headers: | ||
%% for header in headers | ||
#include <{{ header }}> | ||
%% endfor | ||
|
||
#endif // MODM_DEVICE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2019, Niklas Hauser | ||
# | ||
# This file is part of the modm project. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import re | ||
from pathlib import Path | ||
|
||
# ----------------------------------------------------------------------------- | ||
def init(module): | ||
module.parent = "cmsis" | ||
module.name = "device" | ||
|
||
def prepare(module, options): | ||
device = options[":target"] | ||
if device.identifier["platform"] != "sam": | ||
return False | ||
|
||
module.depends(":cmsis:core") | ||
return True | ||
|
||
pp = {} | ||
def validate(env): | ||
device = env[":target"] | ||
|
||
define = "__{}__".format(device.identifier.string.upper()) | ||
family_file = None | ||
for famfile in Path(localpath("sam")).glob("**/sam.h"): | ||
content = famfile.read_text(encoding="utf-8", errors="replace") | ||
match = re.findall(r"defined\((?P<define>__SAM.*?__)\)", content) | ||
if match is not None and define in match: | ||
family_file = famfile.relative_to(localpath(".")) | ||
|
||
if family_file is None: | ||
raise ValidateException("No device define found for '{}'!".format(device.partname)) | ||
|
||
family_folder = family_file.parent | ||
device_header = "{}.h".format(device.identifier.string) | ||
|
||
global pp | ||
pp = { | ||
"define": define, | ||
"folder": family_folder, | ||
"device_header": device_header, | ||
} | ||
|
||
def build(env): | ||
global pp | ||
env.collect(":build:path.include", "modm/ext/cmsis/device") | ||
|
||
env.outbasepath = "modm/ext/cmsis/device" | ||
files = ["sam.h", "component-version.h", "pio", "instance", "component", pp["device_header"]] | ||
for file in files: | ||
env.copy(localpath(pp["folder"], file), file) | ||
|
||
env.substitutions = { | ||
"headers": [pp["device_header"]], | ||
"defines": [pp["define"]], | ||
} | ||
env.outbasepath = "modm/src/modm/platform" | ||
env.template("device.hpp.in") |