zephyr/scripts/dts/extract/compatible.py
Kumar Gala 35ecc78cdf scripts/dts/extract: Generate unique defines based on compat & instance
Add support to generate defines of the form
DT_<COMPAT>_<INSTANCE>_<PROP>.  The idea is that we can utilize this in
drivers to remove the need for dts_fixup.h.  The <INSTANCE> value is
determined by the script and starts at 0 and counts up for each instance
of a given <COMPAT>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-14 06:33:29 -06:00

82 lines
2.5 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_address Address of 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_address, prop, def_label):
# compatible definition
binding = get_binding(node_address)
compatible = reduced[node_address]['props'][prop]
if not isinstance(compatible, list):
compatible = [compatible, ]
for i, comp in enumerate(compatible):
# Generate #define's
compat_label = convert_string_to_label(str(comp))
compat_defs = 'DT_COMPAT_' + compat_label
load_defs = {
compat_defs: "1",
}
insert_defs(node_address, load_defs, {})
# Generate #define for BUS a "sensor" might be on
# for example:
# #define DT_ST_LPS22HB_PRESS_BUS_SPI 1
if 'parent' in binding:
bus = binding['parent']['bus']
compat_defs = 'DT_' + compat_label + '_BUS_' + bus.upper()
load_defs = {
compat_defs: "1",
}
insert_defs(node_address, load_defs, {})
# Generate defines of the form:
# #define DT_<COMPAT>_<INSTANCE ID> 1
instance = reduced[node_address]['instance_id']
for k in instance:
i = instance[k]
compat_instance = 'DT_' + convert_string_to_label(k) + '_' + str(i)
load_defs = {
compat_instance: "1",
}
insert_defs(node_address, load_defs, {})
# Generate defines of the form:
# #define DT_<COMPAT>_<INSTANCE ID>_BUS_<BUS> 1
if 'parent' in binding:
bus = binding['parent']['bus']
compat_instance += '_BUS_' + bus.upper()
load_defs = {
compat_instance: "1",
}
insert_defs(node_address, load_defs, {})
##
# @brief Management information for compatible.
compatible = DTCompatible()