Skip to content

Commit 752c000

Browse files
committed
Fix initialization location
1 parent 54c29c1 commit 752c000

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/gpio_common.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "gpio_common.h"
99

1010
#define GPIO_MAX_LINES 32
11-
#define GPIO_CONSUMER "FLDIGI"
11+
#define GPIO_CONSUMER "DIREWOLF"
1212

1313
//Types
1414
typedef struct gpio_common {
@@ -21,6 +21,9 @@ typedef struct gpio_common {
2121

2222
static gpio_common_t gpio[GPIO_MAX_LINES];
2323

24+
25+
// Function implementations
26+
2427
void gpio_common_init(void) {
2528
fprintf(stderr, "Initializing GPIO common structure\n");
2629
for (gpio_num_t i = 0; i < GPIO_MAX_LINES; i++) {
@@ -132,7 +135,7 @@ gpio_num_t gpio_common_open_line(const char *chip_name, unsigned int line, bool
132135

133136
int gpio_common_release_line(gpio_num_t gpio_num) {
134137
if (gpio_num >= GPIO_MAX_LINES) {
135-
return -1;
138+
return GPIO_COMMON_ERR;
136139
}
137140

138141
if (gpio[gpio_num].request != NULL) {
@@ -146,7 +149,7 @@ int gpio_common_release_line(gpio_num_t gpio_num) {
146149

147150
int gpio_common_set(gpio_num_t gpio_num, bool val) {
148151
if (gpio_num >= GPIO_MAX_LINES || gpio[gpio_num].request == NULL) {
149-
return -1;
152+
return GPIO_COMMON_ERR;
150153
}
151154
uint16_t gpiod_val;
152155

@@ -160,7 +163,7 @@ int gpio_common_set(gpio_num_t gpio_num, bool val) {
160163
int ret = gpiod_line_request_set_value(gpio[gpio_num].request, gpio[gpio_num].offset, gpiod_val);
161164
if (ret < 0) {
162165
fprintf(stderr, "Error setting line\n");
163-
return -1;
166+
return GPIO_COMMON_ERR;
164167
}
165168
return 0;
166169
}

src/gpio_common.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
#ifndef GPIO_COMMON_H
2+
#define GPIO_COMMON_H
3+
4+
15
#ifdef __cplusplus
26
extern "C" {
37
#endif
48

59
#include <gpiod.h>
610
#include <stdint.h>
711

8-
9-
12+
// Types
1013
typedef uint16_t gpio_num_t;
14+
15+
// Return values
1116
#define GPIO_COMMON_UNKNOWN UINT16_MAX
1217
#define GPIO_COMMON_OK 0
1318
#define GPIO_COMMON_ERR -1
@@ -22,4 +27,6 @@ int gpio_common_set(gpio_num_t gpio_num, bool val);
2227

2328
#ifdef __cplusplus
2429
}
25-
#endif
30+
#endif
31+
32+
#endif // GPIO_COMMON_H

src/ptt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,10 @@ void ptt_init (struct audio_s *audio_config_p)
724724
int using_gpio;
725725
#endif
726726

727+
#if USE_GPIOD
728+
gpio_common_init();
729+
#endif
730+
727731
#if DEBUG
728732
text_color_set(DW_COLOR_DEBUG);
729733
dw_printf ("ptt_init ( ... )\n");
@@ -760,7 +764,6 @@ void ptt_init (struct audio_s *audio_config_p)
760764
audio_config_p->achan[ch].octrl[ot].ptt_invert);
761765
}
762766
}
763-
gpio_common_init();
764767
}
765768

766769
/*

0 commit comments

Comments
 (0)