zephyr/samples/basic/custom_dts_binding/src/main.c
Keith Packard 0b90fd5adf samples, tests, boards: Switch main return type from void to int
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>
2023-04-14 07:49:41 +09:00

49 lines
1018 B
C

/*
* Copyright (c) 2023 Libre Solar Technologies GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#if !DT_NODE_EXISTS(DT_NODELABEL(load_switch))
#error "Overlay for power output node not properly defined."
#endif
static const struct gpio_dt_spec load_switch =
GPIO_DT_SPEC_GET_OR(DT_NODELABEL(load_switch), gpios, {0});
int main(void)
{
int err;
if (!gpio_is_ready_dt(&load_switch)) {
printf("The load switch pin GPIO port is not ready.\n");
return 0;
}
printf("Initializing pin with inactive level.\n");
err = gpio_pin_configure_dt(&load_switch, GPIO_OUTPUT_INACTIVE);
if (err != 0) {
printf("Configuring GPIO pin failed: %d\n", err);
return 0;
}
printf("Waiting one second.\n");
k_sleep(K_MSEC(1000));
printf("Setting pin to active level.\n");
err = gpio_pin_set_dt(&load_switch, 1);
if (err != 0) {
printf("Setting GPIO pin level failed: %d\n", err);
}
return 0;
}