Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: modules: shields: Introducing shield options #82825

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

soburi
Copy link
Member

@soburi soburi commented Dec 10, 2024

With this change, the shield specified by --shield can receive
a connector name and various options.
This allows you to adapt the shield to your board at compile time.

Command line options:

which connects this device by appending @ after its name.
It can also append options separated with ":" to specify shield-specific
options. Multiple options can be assigned.

The format is as follows:

<shield_identifier>[@<connector>][:<option>{:<option>}]

Derived overlay:

When you specify the connector to connect to, an overlay file is
generated that includes the @connector_name part of the connector name.
Here, we will call this a "derived overlay".

The derived overlay defines the SHIELD_DERIVED_NAME and
SHIELD_DERIVED_NAME_DEFINED macros and including the original overlay
file. The overlay author can use helper macros to reflect options per
the derived definition.

Options and helper macros:

Options are defined in the format [key]=[value]. The value will be
treated as 1 if only the key is specified.
Helper macros are also defined to handle these options in overlays.

  • SHIELD_OPTION_DEFINED(opt) returns 0 or 1 to indicate whether
    opt is defined.
  • SHIELD_OPTION(opt) returns the macro value corresponding to opt if it
    is defined. Otherwise, it returns the value of SHIELD_DEFAULT_[opt].
  • SHIELD_DEFAUILT_[opt] is automatically It is not generated,
    so you must explicitly define it in the overlay file.

Example:

For example, if you specify something like:

--shield seeed_grove_lis3dhtr:addr=1f
--shield seeed_grove_lis3dhtr@grove_i2c1

the automatically generated header will have a definition like

#define SHIELD_SEEED_GROVE_LIS3DHTR_ADDR 1f
#define SHIELD_SEEED_GROVE_LIS3DHTR_ADDR_DEFINED 1
#define SHIELD_SEEED_GROVE_LIS3DHTR_GROVE_I2C1_CONNECTOR_NAME grove_i2c1
#define SHIELD_SEEED_GROVE_LIS3DHTR_GROVE_I2C1_CONNECTOR_NAME_DEFINED 1

A derived overlay is also created with the file name
seeed_grove_lis3dhtr@grove_i2c1.overlay.
In this case, the derived overlay will include
SHIELD_OPTION(CONNECTOR_NAME), You can reference these with
SHIELD_OPTION(ADDR).
To ensure that the helper macros work correctly in the original
overlay and not in a derived overlay,
you must define SHIELD_DEFAULT_CONNECTOR_NAME and
SHIELD_DEFAULT_ADDR.

You also need to take care not to duplicate labels, etc.

Finally, It will look like this:

#define SHIELD_DEFAULT_CONNECTOR_NAME grove_i2c
#define SHIELD_DEFAULT_ADDR 19

&SHIELD_CONNECTOR_NAME {
  SHIELD_CONCAT(lis3dh_, SHIELD_OPTION(ADDR)):
    lis3dh@SHIELD_OPTION(ADDR) {
      compatible = "st,lis3dh", "st,lis2dh";
      reg = <SHIELD_PREFIX_0X(SHIELD_OPTION(ADDR))>;
      ...
  };
};

#undef SHIELD_DEFAULT_ADDR
#undef SHIELD_DEFAULT_CONNECTOR_NAME

By defining it like this,
you can connect this seeed_grove_lis3dhtr to any
grove connector.

As a result, you got processed dts such as follows.

i2c0: grove_i2c: i2c@40044000 {
  lis3dh_1f: lis3dh@1f {
    compatible = "st,lis3dh", "st,lis2dh";
    reg = < 0x1f >;
  };
};
i2c1: grove_i2c1: i2c@40048000 {
  lis3dh_19: lis3dh@19 {
    compatible = "st,lis3dh", "st,lis2dh";
    reg = < 0x19 >;
  };
};

@soburi soburi force-pushed the shield_options branch 2 times, most recently from f382e92 to 9441086 Compare December 14, 2024 17:18
@soburi soburi changed the title cmake: modules: shields: Make possible to give options to shield. cmake: modules: shields: Make it possible to give options to shield Dec 14, 2024
@soburi soburi force-pushed the shield_options branch 6 times, most recently from a02fbd7 to 1be40c0 Compare December 17, 2024 10:25
GTLin08 pushed a commit to GTLin08/zephyr that referenced this pull request Dec 30, 2024
The it8801 template is helpful but in the current state it does not
allow changing the device address as that is in the template itself. Fix
that by moving the template content down a level in the hierarchy, so
that it extends the mfd device itself rather than than instantiate it,
then the base instance can have any address, now the only limitation is
that only one instance is possible, but that is probably alright for
now.

Alternatives would be to use a define for the address, or even a
template per address, but this feels like a better compromise for now.
This may also use
zephyrproject-rtos#82825 in the future if
that ever becomes a thing.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
fabiobaltieri added a commit to fabiobaltieri/zephyr that referenced this pull request Dec 30, 2024
The it8801 template is helpful but in the current state it does not
allow changing the device address as that is in the template itself. Fix
that by moving the template content down a level in the hierarchy, so
that it extends the mfd device itself rather than than instantiate it,
then the base instance can have any address, now the only limitation is
that only one instance is possible, but that is probably alright for
now.

Alternatives would be to use a define for the address, or even a
template per address, but this feels like a better compromise for now.
This may also use
zephyrproject-rtos#82825 in the future if
that ever becomes a thing.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
kartben pushed a commit that referenced this pull request Dec 31, 2024
The it8801 template is helpful but in the current state it does not
allow changing the device address as that is in the template itself. Fix
that by moving the template content down a level in the hierarchy, so
that it extends the mfd device itself rather than than instantiate it,
then the base instance can have any address, now the only limitation is
that only one instance is possible, but that is probably alright for
now.

Alternatives would be to use a define for the address, or even a
template per address, but this feels like a better compromise for now.
This may also use
#82825 in the future if
that ever becomes a thing.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
coreboot-org-bot pushed a commit to coreboot/zephyr-cros that referenced this pull request Jan 1, 2025
The it8801 template is helpful but in the current state it does not
allow changing the device address as that is in the template itself. Fix
that by moving the template content down a level in the hierarchy, so
that it extends the mfd device itself rather than than instantiate it,
then the base instance can have any address, now the only limitation is
that only one instance is possible, but that is probably alright for
now.

Alternatives would be to use a define for the address, or even a
template per address, but this feels like a better compromise for now.
This may also use
zephyrproject-rtos/zephyr#82825 in the future if
that ever becomes a thing.

(cherry picked from commit b716b06)

Original-Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
GitOrigin-RevId: b716b06
Cr-Build-Id: 8726996916743985489
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8726996916743985489
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I9c5ef18d33e2854405fae39b0c519408195c19b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6135133
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Bot-Commit: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Devansh0210 pushed a commit to Devansh0210/zephyr that referenced this pull request Jan 7, 2025
The it8801 template is helpful but in the current state it does not
allow changing the device address as that is in the template itself. Fix
that by moving the template content down a level in the hierarchy, so
that it extends the mfd device itself rather than than instantiate it,
then the base instance can have any address, now the only limitation is
that only one instance is possible, but that is probably alright for
now.

Alternatives would be to use a define for the address, or even a
template per address, but this feels like a better compromise for now.
This may also use
zephyrproject-rtos#82825 in the future if
that ever becomes a thing.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@soburi soburi force-pushed the shield_options branch 9 times, most recently from a054f60 to ec9099d Compare January 9, 2025 04:56
@soburi soburi force-pushed the shield_options branch 7 times, most recently from d3e816a to aa056ca Compare January 10, 2025 01:35
Add dts/common directory to doxygen sources list.
And updated `dts/common/freq.h` and `dts/common/mem.h`
to generate readable API reference.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
To create and tune multiple instances of shields, we are introducing
shield options.
We can now tweak the behavior of a shield by specifying options as a
string after the shield name when building.

To achieve this, we are changing how build and shield overlays work.
See the documentation in this commit for more details.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add shield definition for Seeed's LIS3DHTR accelerometer.

This shield can take option to select connecting bus, so such like
following example.

```
west build -p -b m5stack_atoms3/esp32s3/procpu
--shield=seeed_grove_accel_lis3dhtr@1:addr=0x18 samples/sensor/lis2dh/
```

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi changed the title cmake: modules: shields: Make it possible to give options to shield cmake: modules: shields: Introducing shield options Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant