1 /*
2  * Copyright (c) 2023 Libre Solar Technologies GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 
9 #include <zephyr/devicetree.h>
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/kernel.h>
12 
13 #if !DT_NODE_EXISTS(DT_NODELABEL(load_switch))
14 #error "Overlay for power output node not properly defined."
15 #endif
16 
17 static const struct gpio_dt_spec load_switch =
18 	GPIO_DT_SPEC_GET_OR(DT_NODELABEL(load_switch), gpios, {0});
19 
main(void)20 int main(void)
21 {
22 	int err;
23 
24 	if (!gpio_is_ready_dt(&load_switch)) {
25 		printf("The load switch pin GPIO port is not ready.\n");
26 		return 0;
27 	}
28 
29 	printf("Initializing pin with inactive level.\n");
30 
31 	err = gpio_pin_configure_dt(&load_switch, GPIO_OUTPUT_INACTIVE);
32 	if (err != 0) {
33 		printf("Configuring GPIO pin failed: %d\n", err);
34 		return 0;
35 	}
36 
37 	printf("Waiting one second.\n");
38 
39 	k_sleep(K_MSEC(1000));
40 
41 	printf("Setting pin to active level.\n");
42 
43 	err = gpio_pin_set_dt(&load_switch, 1);
44 	if (err != 0) {
45 		printf("Setting GPIO pin level failed: %d\n", err);
46 	}
47 	return 0;
48 }
49