Skip to content

Instantly share code, notes, and snippets.

@mbolivar
Created February 12, 2020 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbolivar/b1e46f743fed9331d3a554a0857f46bc to your computer and use it in GitHub Desktop.
Save mbolivar/b1e46f743fed9331d3a554a0857f46bc to your computer and use it in GitHub Desktop.
# prop: a Property with type "phandle-array"
#
# Results depend on:
#
# - how many edtlib.ControllerAndData items there are in prop.val
# - whether or not the property 'foos' has a parallel 'foo-names'
# property in the same node
#
# If there's just one ControllerAndData item, like this example:
#
# gpios = <&gpioc 0xd 0>;
#
# Then the macros look like this:
#
# #define DT_<IDENT>_GPIOS_CONTROLLER "GPIOC"
# #define DT_<IDENT>_GPIOS_PIN 13
# #define DT_<IDENT>_GPIOS_FLAGS 0
# #define DT_<IDENT>_GPIOS {"GPIOC", 13, 0}
#
# Where:
#
# - The "GPIOS" part of the macros comes from the property name.
# - The "CONTROLLER" name is hard-coded, and its value comes from
# the "label" property of the node pointed to by the &gpioc phandle.
# If it has no label, the "CONTROLLER" macro is not generated.
# - The "PIN" and "FLAGS" names come from the devicetree YAML binding,
# which in this case contains this:
#
# gpio-cells:
# - pin
# - flags
#
# If there are multiple ControllerAndData items, like this:
#
# cs-gpios = < &gpiod 0xd 0x10 >, < &gpioe 0x0 0x0 >;
#
# Then the macros have trailing indexes (_0 and _1 below),
# and there's a _COUNT macro:
#
# #define DT_<IDENT>_CS_GPIOS_CONTROLLER_0 "GPIOD"
# #define DT_<IDENT>_CS_GPIOS_PIN_0 13
# #define DT_<IDENT>_CS_GPIOS_FLAGS_0 16
# #define DT_<IDENT>_CS_GPIOS_0 {"GPIOD", 13, 16}
# #define DT_<IDENT>_CS_GPIOS_CONTROLLER_1 "GPIOE"
# #define DT_<IDENT>_CS_GPIOS_PIN_1 0
# #define DT_<IDENT>_CS_GPIOS_FLAGS_1 0
# #define DT_<IDENT>_CS_GPIOS_1 {"GPIOE", 0, 0}
# #define DT_<IDENT>_CS_GPIOS_COUNT 2
# #define DT_<IDENT>_CS_GPIOS {DT_<IDENT>_CS_GPIOS_0, DT_<IDENT>_CS_GPIOS_1}
#
# Additionally, if the node also has a property that names the
# individual controllers, like this:
#
# foo {
# io-channels = < &adc1 0x1a >, < &adc1 0x1b >;
# io-channel-names = "SENSOR", "BANDGAP";
# }
#
# Then the -names property will be used to generate additional
# CONTROLLER macros, like this:
#
# #define DT_<IDENT>_IO_CHANNELS_CONTROLLER_0 "ADC_1"
# #define DT_<IDENT>_SENSOR_IO_CHANNELS_CONTROLLER DT_<IDENT>_IO_CHANNELS_CONTROLLER_0
# #define DT_<IDENT>_IO_CHANNELS_CONTROLLER_1 "ADC_1"
# #define DT_<IDENT>_BANDGAP_IO_CHANNELS_CONTROLLER DT_<IDENT>_IO_CHANNELS_CONTROLLER_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment