zephyr/scripts/dts/extract/compatible.py
Ulf Magnusson f5b17d4138 scripts/dts: Call /foo/bar a "path" instead of an "address"
It's confusing that "address" is often used within the same function to
refer to both node paths and e.g. address cells.

Make things easier to understand by calling /foo/bar a path instead.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-22 12:44:16 -06:00

70 lines
2.1 KiB
Python

#
# Copyright (c) 2018 Bobby Noelte
#
# SPDX-License-Identifier: Apache-2.0
#
from extract.globals import *
from extract.directive import DTDirective
##
# @brief Manage compatible directives.
#
# Handles:
# - compatible
#
class DTCompatible(DTDirective):
def __init__(self):
pass
##
# @brief Extract compatible
#
# @param node_path Path to node owning the
# compatible definition.
# @param prop compatible property name
# @param def_label Define label string of node owning the
# compatible definition.
#
def extract(self, node_path, prop, def_label):
# compatible definition
binding = get_binding(node_path)
compatible = reduced[node_path]['props'][prop]
if not isinstance(compatible, list):
compatible = [compatible, ]
for i, comp in enumerate(compatible):
# Generate #define
insert_defs(node_path,
{'DT_COMPAT_' + str_to_label(comp): '1'},
{})
# Generate #define for BUS a "sensor" might be on, for example
# #define DT_ST_LPS22HB_PRESS_BUS_SPI 1
if 'parent' in binding:
compat_def = 'DT_' + str_to_label(comp) + '_BUS_' + \
binding['parent']['bus'].upper()
insert_defs(node_path, {compat_def: '1'}, {})
# Generate defines of the form:
# #define DT_<COMPAT>_<INSTANCE ID> 1
for compat, instance_id in reduced[node_path]['instance_id'].items():
compat_instance = 'DT_' + str_to_label(compat) + '_' + str(instance_id)
insert_defs(node_path, {compat_instance: '1'}, {})
# Generate defines of the form:
# #define DT_<COMPAT>_<INSTANCE ID>_BUS_<BUS> 1
if 'parent' in binding:
bus = binding['parent']['bus']
insert_defs(node_path,
{compat_instance + '_BUS_' + bus.upper(): '1'},
{})
##
# @brief Management information for compatible.
compatible = DTCompatible()