Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix initialization location
  • Loading branch information
leventelist committed Aug 30, 2025
commit 752c000c3674f40bf75c6b7f846580911a5fb951
11 changes: 7 additions & 4 deletions src/gpio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "gpio_common.h"

#define GPIO_MAX_LINES 32
#define GPIO_CONSUMER "FLDIGI"
#define GPIO_CONSUMER "DIREWOLF"

//Types
typedef struct gpio_common {
Expand All @@ -21,6 +21,9 @@ typedef struct gpio_common {

static gpio_common_t gpio[GPIO_MAX_LINES];


// Function implementations

void gpio_common_init(void) {
fprintf(stderr, "Initializing GPIO common structure\n");
for (gpio_num_t i = 0; i < GPIO_MAX_LINES; i++) {
Expand Down Expand Up @@ -132,7 +135,7 @@ gpio_num_t gpio_common_open_line(const char *chip_name, unsigned int line, bool

int gpio_common_release_line(gpio_num_t gpio_num) {
if (gpio_num >= GPIO_MAX_LINES) {
return -1;
return GPIO_COMMON_ERR;
}

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

int gpio_common_set(gpio_num_t gpio_num, bool val) {
if (gpio_num >= GPIO_MAX_LINES || gpio[gpio_num].request == NULL) {
return -1;
return GPIO_COMMON_ERR;
}
uint16_t gpiod_val;

Expand All @@ -160,7 +163,7 @@ int gpio_common_set(gpio_num_t gpio_num, bool val) {
int ret = gpiod_line_request_set_value(gpio[gpio_num].request, gpio[gpio_num].offset, gpiod_val);
if (ret < 0) {
fprintf(stderr, "Error setting line\n");
return -1;
return GPIO_COMMON_ERR;
}
return 0;
}
Expand Down
13 changes: 10 additions & 3 deletions src/gpio_common.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#ifndef GPIO_COMMON_H
#define GPIO_COMMON_H


#ifdef __cplusplus
extern "C" {
#endif

#include <gpiod.h>
#include <stdint.h>



// Types
typedef uint16_t gpio_num_t;

// Return values
#define GPIO_COMMON_UNKNOWN UINT16_MAX
#define GPIO_COMMON_OK 0
#define GPIO_COMMON_ERR -1
Expand All @@ -22,4 +27,6 @@ int gpio_common_set(gpio_num_t gpio_num, bool val);

#ifdef __cplusplus
}
#endif
#endif

#endif // GPIO_COMMON_H
5 changes: 4 additions & 1 deletion src/ptt.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,10 @@ void ptt_init (struct audio_s *audio_config_p)
int using_gpio;
#endif

#if USE_GPIOD
gpio_common_init();
#endif

#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("ptt_init ( ... )\n");
Expand Down Expand Up @@ -760,7 +764,6 @@ void ptt_init (struct audio_s *audio_config_p)
audio_config_p->achan[ch].octrl[ot].ptt_invert);
}
}
gpio_common_init();
}

/*
Expand Down