17#define GPIO_LED_STATUS 45
19#define GPIO_LED_ERROR 44
26static struct gpiod_chip *gpio_chip0 =
nullptr;
29static struct gpiod_chip *gpio_led_error_chip =
nullptr;
32static struct gpiod_chip *gpio_led_status_chip =
nullptr;
35static struct gpiod_line *gpio_power =
nullptr;
38static struct gpiod_line *gpio_led_error =
nullptr;
41static struct gpiod_line *gpio_led_status =
nullptr;
46 gpio_chip0 = gpiod_chip_open_by_number(0);
47 if (gpio_chip0 ==
nullptr) {
48 fprintf(stderr,
"Failed opening GPIO controller 0. %d message: %s\n",
49 errno, strerror(errno));
53 gpio_led_error_chip = gpiod_chip_open_by_number(1);
54 if (gpio_led_error_chip ==
nullptr) {
55 fprintf(stderr,
"Failed opening GPIO controller 1. %d message: %s\n",
56 errno, strerror(errno));
60 if (gpio_led_status_chip ==
nullptr) {
61 fprintf(stderr,
"Failed opening GPIO controller 1. %d message: %s\n",
62 errno, strerror(errno));
66 gpio_power = gpiod_chip_get_line(gpio_chip0,
GPIO_POWER);
67 if (gpio_power ==
nullptr) {
68 fprintf(stderr,
"Failed opening power GPIO line. %d message: %s\n",
69 errno, strerror(errno));
75 if (gpio_led_error ==
nullptr) {
76 fprintf(stderr,
"Failed opening error LED GPIO line. %d message: %s\n",
77 errno, strerror(errno));
83 if (gpio_led_status ==
nullptr) {
84 fprintf(stderr,
"Failed opening status LED GPIO line. %d message: %s\n",
85 errno, strerror(errno));
90 const char *gpio_power_name = gpiod_line_name(gpio_power);
91 bool gpio_power_used = gpiod_line_is_used(gpio_power);
92 printf(
"Power GPIO name: %s\t in use: %d\n", gpio_power_name,
95 const char *gpio_led_error_name = gpiod_line_name(gpio_led_error);
96 bool gpio_led_error_used = gpiod_line_is_used(gpio_led_error);
97 printf(
"Error LED GPIO name: %s\t in use: %d\n", gpio_led_error_name,
100 const char *gpio_led_status_name = gpiod_line_name(gpio_led_status);
101 bool gpio_led_status_used = gpiod_line_is_used(gpio_led_status);
102 printf(
"Error LED GPIO name: %s\t in use: %d\n", gpio_led_status_name,
103 gpio_led_status_used);
106 ret = gpiod_line_request_output(gpio_power,
"gpio_pwr", 0);
108 fprintf(stderr,
"Failed configuring power GPIO line. %d message: %s\n",
109 errno, strerror(errno));
112 ret = gpiod_line_request_output(gpio_led_error,
"gpio_led_error", 0);
115 "Failed configuring error LED GPIO line. %d message: %s\n",
116 errno, strerror(errno));
119 ret = gpiod_line_request_output(gpio_led_status,
"gpio_led_status", 0);
122 "Failed configuring status LED GPIO line. %d message: %s\n",
123 errno, strerror(errno));
128 const char *gpio_power_name1 = gpiod_line_name(gpio_power);
129 bool gpio_power_used1 = gpiod_line_is_used(gpio_power);
130 printf(
"Power GPIO name: %s\t in use: %d\n", gpio_power_name1,
133 const char *gpio_led_error_name1 = gpiod_line_name(gpio_led_error);
134 bool gpio_led_error_used1 = gpiod_line_is_used(gpio_led_error);
135 printf(
"Error LED GPIO name: %s\t in use: %d\n", gpio_led_error_name1,
136 gpio_led_error_used1);
138 const char *gpio_led_status_name1 = gpiod_line_name(gpio_led_status);
139 bool gpio_led_status_used1 = gpiod_line_is_used(gpio_led_status);
140 printf(
"Error LED GPIO name: %s\t in use: %d\n", gpio_led_status_name1,
141 gpio_led_status_used1);
144 printf(
"power up RocketLogger Cape\n");
145 ret = gpiod_line_set_value(gpio_power, 1);
147 fprintf(stderr,
"Failed setting power GPIO line. %d message: %s\n",
148 errno, strerror(errno));
151 ret = gpiod_line_set_value(gpio_led_error, 1);
153 fprintf(stderr,
"Failed setting LED error GPIO line. %d message: %s\n",
154 errno, strerror(errno));
157 ret = gpiod_line_set_value(gpio_led_status, 1);
159 fprintf(stderr,
"Failed setting LED status GPIO line. %d message: %s\n",
160 errno, strerror(errno));
166 printf(
"power down RocketLogger Cape\n");
167 ret = gpiod_line_set_value(gpio_power, 0);
169 fprintf(stderr,
"Failed setting power GPIO line. %d message: %s\n",
170 errno, strerror(errno));
173 ret = gpiod_line_set_value(gpio_led_error, 0);
175 fprintf(stderr,
"Failed setting LED error GPIO line. %d message: %s\n",
176 errno, strerror(errno));
179 ret = gpiod_line_set_value(gpio_led_status, 0);
181 fprintf(stderr,
"Failed setting LED status GPIO line. %d message: %s\n",
182 errno, strerror(errno));
187 gpiod_line_release(gpio_led_status);
188 gpiod_line_release(gpio_led_error);
189 gpiod_line_release(gpio_power);
191 gpiod_line_update(gpio_led_status);
192 gpiod_line_update(gpio_led_error);
193 gpiod_line_update(gpio_power);
196 const char *gpio_power_name2 = gpiod_line_name(gpio_power);
197 bool gpio_power_used2 = gpiod_line_is_used(gpio_power);
198 printf(
"Power GPIO name: %s\t in use: %d\n", gpio_power_name2,
201 const char *gpio_led_error_name2 = gpiod_line_name(gpio_led_error);
202 bool gpio_led_error_used2 = gpiod_line_is_used(gpio_led_error);
203 printf(
"Error LED GPIO name: %s\t in use: %d\n", gpio_led_error_name2,
204 gpio_led_error_used2);
206 const char *gpio_led_status_name2 = gpiod_line_name(gpio_led_status);
207 bool gpio_led_status_used2 = gpiod_line_is_used(gpio_led_status);
208 printf(
"Error LED GPIO name: %s\t in use: %d\n", gpio_led_status_name2,
209 gpio_led_status_used2);
211 gpiod_line_close_chip(gpio_led_status);
212 gpiod_line_close_chip(gpio_led_error);
213 gpiod_line_close_chip(gpio_power);
217 printf(
"Wait and test GPIO API\n");
223 fprintf(stderr,
"Failed setting power GPIO line. %d message: %s\n",
224 errno, strerror(errno));
230 if (gpio_power ==
nullptr) {
231 fprintf(stderr,
"Failed configuring power GPIO line. %d message: %s\n",
232 errno, strerror(errno));
237 if (gpio_led_error ==
nullptr) {
239 "Failed configuring error LED GPIO line. %d message: %s\n",
240 errno, strerror(errno));
245 if (gpio_led_status ==
nullptr) {
247 "Failed configuring status LED GPIO line. %d message: %s\n",
248 errno, strerror(errno));
253 printf(
"power up RocketLogger Cape\n");
256 fprintf(stderr,
"Failed setting power GPIO line. %d message: %s\n",
257 errno, strerror(errno));
262 fprintf(stderr,
"Failed setting LED error GPIO line. %d message: %s\n",
263 errno, strerror(errno));
268 fprintf(stderr,
"Failed setting LED status GPIO line. %d message: %s\n",
269 errno, strerror(errno));
277 "Failed setting up interrupt for button GPIO line. %d message: "
279 errno, strerror(errno));
283 struct timespec timeout = {
288 printf(
"wait for button press with timeout of %ld.%09ld sec\n",
289 timeout.tv_sec, timeout.tv_nsec);
296 "Failed waiting for button GPIO interrupt. %d message: %s\n",
297 errno, strerror(errno));
300 printf(
"button interrupt triggered with level %d\n", ret);
303 printf(
"power down RocketLogger Cape\n");
306 fprintf(stderr,
"Failed setting power GPIO line. %d message: %s\n",
307 errno, strerror(errno));
312 fprintf(stderr,
"Failed setting LED error GPIO line. %d message: %s\n",
313 errno, strerror(errno));
318 fprintf(stderr,
"Failed setting LED status GPIO line. %d message: %s\n",
319 errno, strerror(errno));
int gpio_set_value(gpio_t *gpio, int value)
void gpio_release(gpio_t *gpio)
int gpio_wait_interrupt(gpio_t *gpio, const struct timespec *timeout)
gpio_t * gpio_setup_interrupt(int gpio_number, gpio_interrupt_t edge, const char *name)
gpio_t * gpio_setup(int gpio_number, gpio_mode_t mode, const char *name)
@ GPIO_INTERRUPT_BOTH
Interrupt on both edges.
@ GPIO_MODE_OUT
GPIO write mode.
#define GPIO_POWER
Linux sysfs GPIO number of RocketLogger cape power enable.
#define GPIO_LED_STATUS
Linux sysfs GPIO number of status LED.
#define GPIO_LED_ERROR
Linux sysfs GPIO number of error LED.
#define GPIO_BUTTON
Linux sysfs GPIO number of start/stop button.
gpio_t * gpio_button
GPIO handle for user button.