Now that device_api attribute is unmodified at runtime, as well as all the other attributes, it is possible to switch all device driver instance to be constant. A coccinelle rule is used for this: @r_const_dev_1 disable optional_qualifier @ @@ -struct device * +const struct device * @r_const_dev_2 disable optional_qualifier @ @@ -struct device * const +const struct device * Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
31 lines
544 B
C
31 lines
544 B
C
/*
|
|
* Copyright (c) 2017, NXP
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr.h>
|
|
#include <drivers/sensor.h>
|
|
#include <stdio.h>
|
|
|
|
void main(void)
|
|
{
|
|
struct sensor_value green;
|
|
const struct device *dev = device_get_binding(DT_LABEL(DT_INST(0, max_max30101)));
|
|
|
|
if (dev == NULL) {
|
|
printf("Could not get max30101 device\n");
|
|
return;
|
|
}
|
|
|
|
while (1) {
|
|
sensor_sample_fetch(dev);
|
|
sensor_channel_get(dev, SENSOR_CHAN_GREEN, &green);
|
|
|
|
/* Print green LED data*/
|
|
printf("GREEN=%d\n", green.val1);
|
|
|
|
k_sleep(K_MSEC(20));
|
|
}
|
|
}
|