-
Notifications
You must be signed in to change notification settings - Fork 7.7k
kernel/device: Update to multi API device model #49374
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
Closed
bjarki-andreasen
wants to merge
3
commits into
zephyrproject-rtos:main
from
bjarki-andreasen:device_update_to_multi_api_dev_model
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(multi_api_shell) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2022 Trackunit A/S | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&i2c2 { | ||
lis2dh@0b { | ||
compatible = "st,lis2dh"; | ||
reg = <0x0b>; | ||
label = "sensor2"; | ||
}; | ||
|
||
lis2dh@0c { | ||
compatible = "bosch,bme280"; | ||
reg = <0x0c>; | ||
label = "sensor3"; | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# nothing here | ||
# Board b_u585i_iot02a | ||
|
||
CONFIG_SENSOR=y | ||
CONFIG_HTS221=y | ||
CONFIG_LIS2DH=y | ||
CONFIG_BME280=y | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is? where else is it defined? |
||
CONFIG_LEGACY_DEVICE_MODEL=n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sample: | ||
description: Simple dummy shell | ||
name: Multi API sensor shell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2022 Trackunit A/S | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/sensor.h> | ||
|
||
struct sensor_info { | ||
const struct device *dev; | ||
const char *vendor; | ||
const char *model; | ||
const char *friendly_name; | ||
}; | ||
|
||
|
||
|
||
/* | ||
* Note that DEVICE_DT_PROPERTY and DT_PROP use the same node so they | ||
* can be mixed | ||
*/ | ||
#ifdef CONFIG_LEGACY_DEVICE_MODEL | ||
|
||
#define SENSOR_INFO_INITIALIZER(node_id) \ | ||
{ \ | ||
.dev = DEVICE_DT_GET(node_id), \ | ||
.vendor = DEVICE_DT_PROPERTY(node_id, vendor), \ | ||
.model = DEVICE_DT_PROPERTY(node_id, model), \ | ||
.friendly_name = DT_PROP_OR(node_id, label, "") \ | ||
}, | ||
|
||
#else | ||
|
||
#define SENSOR_INFO_INITIALIZER(node_id) \ | ||
{ \ | ||
.dev = DEVICE_DT_API_GET(node_id, sensor), \ | ||
.vendor = DEVICE_DT_PROPERTY(node_id, vendor), \ | ||
.model = DEVICE_DT_PROPERTY(node_id, model), \ | ||
.friendly_name = DT_PROP_OR(node_id, label, "") \ | ||
}, | ||
|
||
#endif /* CONFIG_LEGACY_DEVICE_MODEL */ | ||
|
||
/* | ||
* It is known at compile time if any sensor exists in the system, save | ||
* memory by warning user to exclude the shell using KConfig. | ||
*/ | ||
#if (DEVICE_DT_API_SUPPORTED_ANY(sensor) == 0) | ||
#warning "Sensor shell is enabled without any sensor in system" | ||
#endif | ||
|
||
/* | ||
* Every sensor with status OK in devicetree will be filled into this | ||
* list automatically during compile time | ||
*/ | ||
static struct sensor_info sensors[] = | ||
{ | ||
DEVICE_DT_API_FOREACH(SENSOR_INFO_INITIALIZER, sensor) | ||
}; | ||
|
||
/* | ||
* Yes, this is not actually a shell, it is an example showing how to | ||
* identify and include all sensors in the system. | ||
*/ | ||
void main(void) | ||
{ | ||
/* Print sensor info header */ | ||
printk("Sensor info:\n"); | ||
printk("Sensor count: %u\n\n", ARRAY_SIZE(sensors)); | ||
|
||
/* Print sensor info for each sensor */ | ||
for (int i = 0; i < ARRAY_SIZE(sensors); i++) { | ||
printk("device: %u, vendor: %s, model: %s, friendly_name: %s\n", | ||
(size_t)sensors[i].dev, sensors[i].vendor, sensors[i].model, | ||
sensors[i].friendly_name); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.