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>
49 lines
940 B
C
49 lines
940 B
C
/*
|
|
* Copyright (c) 2016 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr.h>
|
|
#include <sys/printk.h>
|
|
#include <drivers/sensor.h>
|
|
|
|
/**
|
|
* @file Sample app using the MAX44009 light sensor through ARC I2C.
|
|
*
|
|
* This app will read the sensor reading via I2C interface and show
|
|
* the result every 4 seconds.
|
|
*/
|
|
|
|
void main(void)
|
|
{
|
|
const struct device *dev;
|
|
struct sensor_value val;
|
|
uint32_t lum = 0U;
|
|
|
|
printk("MAX44009 light sensor application\n");
|
|
|
|
dev = device_get_binding("MAX44009");
|
|
if (!dev) {
|
|
printk("sensor: device not found.\n");
|
|
return;
|
|
}
|
|
|
|
while (1) {
|
|
if (sensor_sample_fetch_chan(dev, SENSOR_CHAN_LIGHT) != 0) {
|
|
printk("sensor: sample fetch fail.\n");
|
|
return;
|
|
}
|
|
|
|
if (sensor_channel_get(dev, SENSOR_CHAN_LIGHT, &val) != 0) {
|
|
printk("sensor: channel get fail.\n");
|
|
return;
|
|
}
|
|
|
|
lum = val.val1;
|
|
printk("sensor: lum reading: %d\n", lum);
|
|
|
|
k_sleep(K_MSEC(4000));
|
|
}
|
|
}
|