Skip to content

Commit

Permalink
[ext] Add modm:cmsis:device module for SAM devices
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Apr 24, 2019
1 parent 53f7f15 commit db4b187
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ext/microchip/device.hpp.in
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
68 changes: 68 additions & 0 deletions ext/microchip/module.lb
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")

0 comments on commit db4b187

Please sign in to comment.