For missing optional properties, it can be handy to generate a default value instead of no value, to cut down on #ifdefs. Allow a default value to be specified in the binding, via a new 'default: <default value>' setting for properties in bindings. Defaults are supported for both scalar and array types. YAML arrays are used to specify the value for array types. 'default:' also appears in json-schema, with the same meaning. Include misc. sanity checks, like the 'default' value matching 'type'. The documentation changes in binding-template.yaml explain the syntax. Suggested by Peter A. Bigot in https://github.com/zephyrproject-rtos/zephyr/issues/17829. Fixes: #17829 Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
38 lines
688 B
YAML
38 lines
688 B
YAML
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
title: Property default value test
|
|
description: Property default value test
|
|
|
|
compatible: "defaults"
|
|
|
|
properties:
|
|
int:
|
|
type: int
|
|
required: false
|
|
default: 123
|
|
|
|
array:
|
|
type: array
|
|
required: false
|
|
default: [1, 2, 3]
|
|
|
|
uint8-array:
|
|
type: uint8-array
|
|
required: false
|
|
default: [0x89, 0xAB, 0xCD]
|
|
|
|
string:
|
|
type: string
|
|
required: false
|
|
default: "hello"
|
|
|
|
string-array:
|
|
type: string-array
|
|
required: false
|
|
default: ["hello", "there"]
|
|
|
|
default-not-used:
|
|
type: int
|
|
required: false
|
|
default: 123
|