Skip to content

Introduce option parameter for shields #82889

@soburi

Description

@soburi

Introduction

Zephyr's shield system, inspired by the Arduino ecosystem, can integrate expansion boards easily. However, the current framework struggles with boards featuring multiple connectors, such as Grove. This proposal addresses these gaps by extending the shield system to support flexible configurations for boards with multiple connectors.

https://builds.zephyrproject.io/zephyr/pr/82825/docs/hardware/porting/shields.html
https://builds.zephyrproject.io/zephyr/pr/82825/docs/doxygen/html/group__dts__shield__option__apis.html#details

Problem description

Zephyr's existing shield system is designed for single-connector configurations, so it is not flexible. So, supporting multi-connector boards like those used in the Grove ecosystem is challenging. We can't even connect it to a different port. This limitation restricts the use of shields across varying hardware configurations.

Proposed change

This proposal enhances the shield framework to enable flexible configurations at build time. By extending the --shield option in the west build command, users can specify parameters such as I2C addresses or GPIO pins directly. Also, users can use multiple instances of the same shield.

A typical example is when you specify

--shield seeed_grove_lis3dhtr@1:addr=0x18

it provides a mechanism to switch the connection to grove_i2c1.
Options can be freely defined, and determining them in the overlay file provides the flexibility to change the shield definition (slightly) from the outside.

I am creating an implementation at #82825. (Work in progress)

Proposed change (Detailed)

Command-Line Parameterization:

We will enhance the --shield option to accept detailed parameters for individual shield configurations. This lets users specify attributes like connector names, I2C addresses, and GPIO pins directly from the command line. The format enables defining multiple configurations for the same shield, ensuring flexibility and efficiency.

The format will allow multiple options to be passed for a single shield, in the format:

<shield_name>[@<index>][:<option>{=<value>}[:<option>{=<value>}]]

Parameterizable overlay definition

Defines a macro so that options specified on the command line can be reflected in the overlay.

Details are provided in the following document.

https://builds.zephyrproject.io/zephyr/pr/82825/docs/doxygen/html/group__dts__shield__option__apis.html#autotoc_md6

Derived overlay:

Shields need to be configured differently for each option specified. To achieve this, a new "derived overlay" concept will be introduced. The build process creates "derived overlays" internally for each option given on the command line.

The details are described in the document.
https://builds.zephyrproject.io/zephyr/pr/82825/docs/hardware/porting/shields.html#derived-overlay

The actual process is described in the documentation.
https://builds.zephyrproject.io/zephyr/pr/82825/docs/doxygen/html/group__dts__shield__option__apis.html#autotoc_md7

Conclusion

This extension to the Zephyr shield framework provides greater flexibility for users working with multi-connector systems like Grove. By allowing configuration parameters to be specified at build time, it becomes much easier to integrate and customize multiple instances of shields on the same device. The use of SHIELD_BASE_NAME and SHIELD_DERIVED_NAME macros ensures unique configuration names, while default values and the direct referencing of SHIELD_OPTION allow for smooth and efficient configurations even without user input.

The example with GPIO interrupts illustrates how this framework can be adapted to various peripherals, enabling more complex hardware configurations in a simple and flexible manner.

Metadata

Metadata

Assignees

Labels

RFCRequest For Comments: want input from the communityarea: ShieldsShields (add-on boards)

Type

Projects

Status

No status

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions