As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.
Most of these changes were automated using coccinelle with the following
script:
@@
@@
- void
+ int
main(...) {
...
- return;
+ return 0;
...
}
Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.
Signed-off-by: Keith Packard <keithp@keithp.com>
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
/*
|
|
* Copyright (c) 2012-2014 Wind River Systems, Inc.
|
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr/kernel.h>
|
|
#include <zephyr/device.h>
|
|
#include <zephyr/devicetree.h>
|
|
#include <zephyr/drivers/sensor.h>
|
|
|
|
/*
|
|
* Get a device structure from a devicetree node with compatible
|
|
* "bosch,bme280". (If there are multiple, just pick one.)
|
|
*/
|
|
static const struct device *get_bme280_device(void)
|
|
{
|
|
const struct device *const dev = DEVICE_DT_GET_ANY(bosch_bme280);
|
|
|
|
if (dev == NULL) {
|
|
/* No such node, or the node does not have status "okay". */
|
|
printk("\nError: no device found.\n");
|
|
return NULL;
|
|
}
|
|
|
|
if (!device_is_ready(dev)) {
|
|
printk("\nError: Device \"%s\" is not ready; "
|
|
"check the driver initialization logs for errors.\n",
|
|
dev->name);
|
|
return NULL;
|
|
}
|
|
|
|
printk("Found device \"%s\", getting sensor data\n", dev->name);
|
|
return dev;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
const struct device *dev = get_bme280_device();
|
|
|
|
if (dev == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
while (1) {
|
|
struct sensor_value temp, press, humidity;
|
|
|
|
sensor_sample_fetch(dev);
|
|
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
|
|
sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
|
|
sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
|
|
|
|
printk("temp: %d.%06d; press: %d.%06d; humidity: %d.%06d\n",
|
|
temp.val1, temp.val2, press.val1, press.val2,
|
|
humidity.val1, humidity.val2);
|
|
|
|
k_sleep(K_MSEC(1000));
|
|
}
|
|
return 0;
|
|
}
|