diff --git a/CMakeLists.txt b/CMakeLists.txt index 1461c66..498ecf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,21 @@ cmake_minimum_required(VERSION 3.16) +project(rnode) + set(CMAKE_C_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELEASE "-O3") - set(CMAKE_C_FLAGS_DEBUG "-O3") set(CMAKE_CXX_FLAGS_DEBUG "-O3") -project(rnode) - add_executable(${PROJECT_NAME}) -target_link_libraries(${PROJECT_NAME} PRIVATE gpiod m cyaml) - add_subdirectory(src) add_subdirectory(sx126x) include_directories(src) include_directories(sx126x) +target_link_libraries(${PROJECT_NAME} PRIVATE m cyaml) + install(FILES rnode.yaml DESTINATION /mnt/rns) install(TARGETS ${PROJECT_NAME} DESTINATION sbin) diff --git a/rnode.yaml b/rnode.yaml index cda0c6b..556cd43 100644 --- a/rnode.yaml +++ b/rnode.yaml @@ -2,8 +2,8 @@ # Board RNS-Gate spi: /dev/spidev1.0 -cs: { port: 0, pin: 13 } -rst: { port: 0, pin: 6 } +cs: { port: 0, pin: 13 } +rst: { port: 0, pin: 6 } busy: { port: 0, pin: 11 } dio1: { port: 0, pin: 12 } rx_en: { port: 0, pin: 2 } diff --git a/sx126x/CMakeLists.txt b/sx126x/CMakeLists.txt index 81608de..64ce194 100644 --- a/sx126x/CMakeLists.txt +++ b/sx126x/CMakeLists.txt @@ -1,3 +1,15 @@ +find_package(PkgConfig REQUIRED) +pkg_check_modules(GPIOD libgpiod>=2.0) + +if(GPIOD_FOUND) + target_sources(${PROJECT_NAME} PRIVATE gpio_hal_v2.c) +else() + pkg_check_modules(GPIOD REQUIRED libgpiod) + target_sources(${PROJECT_NAME} PRIVATE gpio_hal_v1.c) +endif() + +target_link_libraries(${PROJECT_NAME} PRIVATE ${GPIOD_LIBRARIES}) + target_sources(${PROJECT_NAME} PUBLIC sx126x.c ) diff --git a/sx126x/gpio_hal.h b/sx126x/gpio_hal.h new file mode 100644 index 0000000..1f8125d --- /dev/null +++ b/sx126x/gpio_hal.h @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * GPIO HAL + */ + +#pragma once + +typedef struct gpio_line gpio_line_t; + +typedef enum { + GPIO_DIR_OUTPUT, + GPIO_DIR_INPUT, + GPIO_DIR_INPUT_EDGE_RISING +} gpio_dir_t; + +typedef enum { + GPIO_VALUE_INACTIVE = 0, + GPIO_VALUE_ACTIVE = 1 +} gpio_value_t; + +/* Allocate and configure a GPIO line. Returns NULL on failure. */ +gpio_line_t *gpio_request(unsigned int chip, + unsigned int pin, + gpio_dir_t dir, + gpio_value_t initial, + const char *consumer); + +/* Release a line obtained with gpio_request(). */ +void gpio_release(gpio_line_t *line); + +/* Read the current level of an input line. */ +gpio_value_t gpio_get(gpio_line_t *line); + +/* Drive an output line to the given level. */ +void gpio_set(gpio_line_t *line, gpio_value_t val); + +/* + * Block until one edge event is available on an edge-detection line. + * Returns: 1 - event received; 0 - no event (timeout); <0 - error + */ +int gpio_read_edge_rising(gpio_line_t *line); \ No newline at end of file diff --git a/sx126x/gpio_hal_v1.c b/sx126x/gpio_hal_v1.c new file mode 100644 index 0000000..4db8d79 --- /dev/null +++ b/sx126x/gpio_hal_v1.c @@ -0,0 +1,97 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * GPIO HAL (libgpiod v1 backend) + */ + +#include +#include +#include + +#include "gpio_hal.h" + +struct gpio_line { + struct gpiod_line *line; +}; + +gpio_line_t *gpio_request(unsigned int chip, + unsigned int pin, + gpio_dir_t dir, + gpio_value_t initial, + const char *consumer) +{ + struct gpiod_chip *chip_h = gpiod_chip_open_by_number(chip); + if (!chip) return NULL; + + struct gpiod_line *line = gpiod_chip_get_line(chip_h, pin); + if (!line) { + gpiod_chip_close(chip_h); + return NULL; + } + + int result; + + switch (dir) { + case GPIO_DIR_OUTPUT: + result = gpiod_line_request_output(line, consumer, + initial == GPIO_VALUE_ACTIVE ? 1 : 0); + break; + case GPIO_DIR_INPUT: + result = gpiod_line_request_input(line, consumer); + break; + case GPIO_DIR_INPUT_EDGE_RISING: { + struct gpiod_line_request_config cfg = { + .consumer = consumer, + .request_type = GPIOD_LINE_REQUEST_EVENT_RISING_EDGE, + .flags = 0, + }; + result = gpiod_line_request(line, &cfg, 0); + break; + } + default: + result = -1; + break; + } + + gpiod_chip_close(chip_h); + + if (result < 0) return NULL; + + gpio_line_t *gpio = malloc(sizeof(*gpio)); + if (!gpio) { + gpiod_line_release(line); + return NULL; + } + + gpio->line = line; + return gpio; +} + +void gpio_release(gpio_line_t *line) { + if (!line) return; + gpiod_line_release(line->line); + free(line); +} + +gpio_value_t gpio_get(gpio_line_t *line) { + return gpiod_line_get_value(line->line) == 1 + ? GPIO_VALUE_ACTIVE + : GPIO_VALUE_INACTIVE; +} + +void gpio_set(gpio_line_t *line, gpio_value_t val) { + gpiod_line_set_value(line->line, val == GPIO_VALUE_ACTIVE ? 1 : 0); +} + +int gpio_read_edge_rising(gpio_line_t *line) { + struct timespec timeout = { .tv_sec = 60, .tv_nsec = 0 }; + int res = gpiod_line_event_wait(line->line, &timeout); + + if (res < 0) return -1; + if (res == 0) return 0; // timeout, no event + + struct gpiod_line_event event; + if (gpiod_line_event_read(line->line, &event) < 0) return -1; + + return (event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) ? 1 : 0; +} diff --git a/sx126x/gpio_hal_v2.c b/sx126x/gpio_hal_v2.c new file mode 100644 index 0000000..db56e67 --- /dev/null +++ b/sx126x/gpio_hal_v2.c @@ -0,0 +1,133 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * GPIO HAL (libgpiod v2 backend) + */ + +#include +#include +#include +#include + +#include "gpio_hal.h" + +struct gpio_line { + struct gpiod_line_request *req; + unsigned int pin; + struct gpiod_edge_event_buffer *event_buf; +}; + +gpio_line_t *gpio_request(unsigned int chip, + unsigned int pin, + gpio_dir_t dir, + gpio_value_t initial, + const char *consumer) +{ + char chip_path[32]; + snprintf(chip_path, sizeof(chip_path), "/dev/gpiochip%u", chip); + + struct gpiod_chip *chip_h = gpiod_chip_open(chip_path); + if (!chip_h) return NULL; + + struct gpiod_line_settings *settings = gpiod_line_settings_new(); + if (!settings) { + gpiod_chip_close(chip_h); + return NULL; + } + + struct gpiod_line_config *line_cfg = gpiod_line_config_new(); + if (!line_cfg) { + gpiod_line_settings_free(settings); + gpiod_chip_close(chip_h); + return NULL; + } + + struct gpiod_request_config *req_cfg = gpiod_request_config_new(); + if (!req_cfg) { + gpiod_line_config_free(line_cfg); + gpiod_line_settings_free(settings); + gpiod_chip_close(chip_h); + return NULL; + } + + switch (dir) { + case GPIO_DIR_OUTPUT: + gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_OUTPUT); + gpiod_line_settings_set_output_value(settings, + initial == GPIO_VALUE_ACTIVE + ? GPIOD_LINE_VALUE_ACTIVE + : GPIOD_LINE_VALUE_INACTIVE); + break; + case GPIO_DIR_INPUT: + gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_INPUT); + break; + case GPIO_DIR_INPUT_EDGE_RISING: + gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_INPUT); + gpiod_line_settings_set_edge_detection(settings, GPIOD_LINE_EDGE_RISING); + break; + } + + unsigned int offsets[] = { pin }; + gpiod_line_config_add_line_settings(line_cfg, offsets, 1, settings); + gpiod_request_config_set_consumer(req_cfg, consumer); + + gpio_line_t *gpio = malloc(sizeof(*gpio)); + if (gpio) { + gpio->req = gpiod_chip_request_lines(chip_h, req_cfg, line_cfg); + gpio->pin = pin; + gpio->event_buf = NULL; + + if (!gpio->req) { + free(gpio); + gpio = NULL; + } else if (dir == GPIO_DIR_INPUT_EDGE_RISING) { + gpio->event_buf = gpiod_edge_event_buffer_new(1); + if (!gpio->event_buf) { + gpiod_line_request_release(gpio->req); + free(gpio); + gpio = NULL; + } + } + } + + gpiod_line_settings_free(settings); + gpiod_line_config_free(line_cfg); + gpiod_request_config_free(req_cfg); + gpiod_chip_close(chip_h); + + return gpio; +} + +void gpio_release(gpio_line_t *line) { + if (!line) return; + + if (line->event_buf) { + gpiod_edge_event_buffer_free(line->event_buf); + } + gpiod_line_request_release(line->req); + free(line); +} + +gpio_value_t gpio_get(gpio_line_t *line) { + return gpiod_line_request_get_value(line->req, line->pin) + == GPIOD_LINE_VALUE_ACTIVE + ? GPIO_VALUE_ACTIVE + : GPIO_VALUE_INACTIVE; +} + +void gpio_set(gpio_line_t *line, gpio_value_t val) { + gpiod_line_request_set_value(line->req, line->pin, + val == GPIO_VALUE_ACTIVE + ? GPIOD_LINE_VALUE_ACTIVE + : GPIOD_LINE_VALUE_INACTIVE); +} + +int gpio_read_edge_rising(gpio_line_t *line) { + int res = gpiod_line_request_read_edge_events(line->req, line->event_buf, 1); + + if (res < 0) return -1; + if (res == 0) return 0; + + struct gpiod_edge_event *event = gpiod_edge_event_buffer_get_event(line->event_buf, 0); + return (gpiod_edge_event_get_event_type(event) == GPIOD_EDGE_EVENT_RISING_EDGE) ? 1 : 0; +} diff --git a/sx126x/sx126x.c b/sx126x/sx126x.c index c166ede..371114d 100644 --- a/sx126x/sx126x.c +++ b/sx126x/sx126x.c @@ -10,13 +10,14 @@ #include #include #include +#include #include #include #include #include #include #include -#include +#include "gpio_hal.h" #include #include "sx126x.h" @@ -91,12 +92,12 @@ typedef enum { IRQ_NONE = 0x0000 } irq_t; -static struct gpiod_line *cs_line = NULL; -static struct gpiod_line *rst_line = NULL; -static struct gpiod_line *busy_line = NULL; -static struct gpiod_line *dio1_line = NULL; -static struct gpiod_line *tx_en_line = NULL; -static struct gpiod_line *rx_en_line = NULL; +static gpio_line_t *cs = NULL; +static gpio_line_t *rst = NULL; +static gpio_line_t *busy = NULL; +static gpio_line_t *dio1 = NULL; +static gpio_line_t *tx_en = NULL; +static gpio_line_t *rx_en = NULL; static int spi_fd; static uint8_t fifo_tx_addr_ptr = 0; @@ -130,7 +131,7 @@ static sx126x_timeout_callback_t timeout_callback = NULL; static void wait_on_busy() { uint16_t count = 0; - while (gpiod_line_get_value(busy_line) == 1) { + while (gpio_get(busy) == GPIO_VALUE_ACTIVE) { usleep(1000); count++; @@ -149,37 +150,21 @@ static void wait_on_busy() { static void switch_ant() { switch (state) { case SX126X_IDLE: - if (rx_en_line) { - gpiod_line_set_value(rx_en_line, 0); - } - if (tx_en_line) { - gpiod_line_set_value(tx_en_line, 0); - } + if (rx_en) gpio_set(rx_en, GPIO_VALUE_INACTIVE); + if (tx_en) gpio_set(tx_en, GPIO_VALUE_INACTIVE); break; case SX126X_RX_SINGLE: case SX126X_RX_CONTINUOUS: - if (tx_en_line) { - gpiod_line_set_value(tx_en_line, 0); - } - + if (tx_en) gpio_set(tx_en, GPIO_VALUE_INACTIVE); usleep(100); - - if (rx_en_line) { - gpiod_line_set_value(rx_en_line, 1); - } + if (rx_en) gpio_set(rx_en, GPIO_VALUE_ACTIVE); break; case SX126X_TX: - if (rx_en_line) { - gpiod_line_set_value(rx_en_line, 0); - } - + if (rx_en) gpio_set(rx_en, GPIO_VALUE_INACTIVE); usleep(100); - - if (tx_en_line) { - gpiod_line_set_value(tx_en_line, 1); - } + if (tx_en) gpio_set(tx_en, GPIO_VALUE_ACTIVE); break; } } @@ -196,9 +181,9 @@ static bool write_bytes(const uint8_t *buf, size_t len) { .cs_change = 0, }; - gpiod_line_set_value(cs_line, 0); + gpio_set(cs, GPIO_VALUE_INACTIVE); int l = ioctl(spi_fd, SPI_IOC_MESSAGE(1), &k); - gpiod_line_set_value(cs_line, 1); + gpio_set(cs, GPIO_VALUE_ACTIVE); return (l == k.len); } @@ -222,9 +207,9 @@ static bool write_read_bytes(const uint8_t *buf, size_t buf_len, uint8_t *res, s } }; - gpiod_line_set_value(cs_line, 0); + gpio_set(cs, GPIO_VALUE_INACTIVE); int l = ioctl(spi_fd, SPI_IOC_MESSAGE(2), &k); - gpiod_line_set_value(cs_line, 1); + gpio_set(cs, GPIO_VALUE_ACTIVE); return (l == (buf_len + res_len)); } @@ -240,9 +225,9 @@ static bool read_bytes(const uint8_t *buf, uint8_t *res, size_t len) { .cs_change = 0, }; - gpiod_line_set_value(cs_line, 0); + gpio_set(cs, GPIO_VALUE_INACTIVE); int l = ioctl(spi_fd, SPI_IOC_MESSAGE(1), &k); - gpiod_line_set_value(cs_line, 1); + gpio_set(cs, GPIO_VALUE_ACTIVE); return (l == k.len); } @@ -429,8 +414,7 @@ static void set_irq_mask() { /* * */ static void * irq_worker(void *p) { - struct gpiod_line_event event; - bool crc_ok = true; + bool crc_ok = true; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); @@ -440,12 +424,12 @@ static void * irq_worker(void *p) { } while (true) { - struct timespec timeout; + int res = gpio_read_edge_rising(dio1); - timeout.tv_sec = 60; - timeout.tv_nsec = 0; - - int res = gpiod_line_event_wait(dio1_line, &timeout); + if (res < 0) { + syslog(LOG_ERR, "IRQ: edge event wait error: %s", strerror(errno)); + break; + } if (res == 0) { syslog(LOG_INFO, "IRQ: Timeout"); @@ -453,72 +437,64 @@ static void * irq_worker(void *p) { if (timeout_callback) { timeout_callback(); } - } else if (res == 1) { - if (gpiod_line_event_read(dio1_line, &event) != 0) { - continue; - } + } else { + uint16_t status = get_irq_status(); - if (event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) { - uint16_t status = get_irq_status(); + if (status & IRQ_CRC_ERR) { + syslog(LOG_INFO, "IRQ: CRC ERR"); + crc_ok = false; + } - if (status & IRQ_CRC_ERR) { - syslog(LOG_INFO, "IRQ: CRC ERR"); + if (status & IRQ_PREAMBLE_DETECTED) { + syslog(LOG_INFO, "IRQ: PREAMBLE DETECTED"); + crc_ok = true; - crc_ok = false; + if (medium_callback) { + medium_callback(CAUSE_PREAMBLE_DETECTED); } + } - if (status & IRQ_PREAMBLE_DETECTED) { - syslog(LOG_INFO, "IRQ: PREAMBLE DETECTED"); - crc_ok = true; + if (status & IRQ_HEADER_VALID) { + syslog(LOG_INFO, "IRQ: HEADER VALID"); - if (medium_callback) { - medium_callback(CAUSE_PREAMBLE_DETECTED); - } + if (medium_callback) { + medium_callback(CAUSE_HEADER_VALID); } + } - if (status & IRQ_HEADER_VALID) { - syslog(LOG_INFO, "IRQ: HEADER VALID"); + if (status & IRQ_HEADER_ERR) { + syslog(LOG_INFO, "IRQ: HEADER ERR"); - if (medium_callback) { - medium_callback(CAUSE_HEADER_VALID); - } + if (medium_callback) { + medium_callback(CAUSE_HEADER_ERR); } + } - if (status & IRQ_HEADER_ERR) { - syslog(LOG_INFO, "IRQ: HEADER ERR"); + if (status & IRQ_RX_DONE) { + syslog(LOG_INFO, "IRQ: RX DONE"); - if (medium_callback) { - medium_callback(CAUSE_HEADER_ERR); - } + if (medium_callback) { + medium_callback(CAUSE_RX_DONE); } - if (status & IRQ_RX_DONE) { - syslog(LOG_INFO, "IRQ: RX DONE"); - - if (medium_callback) { - medium_callback(CAUSE_RX_DONE); - } - - if (crc_ok) { - payload_tx_rx = get_rx_buffer_status(); - - if (rx_done_callback) { - rx_done_callback(payload_tx_rx); - } + if (crc_ok) { + payload_tx_rx = get_rx_buffer_status(); + if (rx_done_callback) { + rx_done_callback(payload_tx_rx); } } + } - if (status & IRQ_TX_DONE) { - syslog(LOG_INFO, "IRQ: TX DONE"); + if (status & IRQ_TX_DONE) { + syslog(LOG_INFO, "IRQ: TX DONE"); - if (medium_callback) { - medium_callback(CAUSE_TX_DONE); - } + if (medium_callback) { + medium_callback(CAUSE_TX_DONE); + } - if (tx_done_callback) { - tx_done_callback(); - } + if (tx_done_callback) { + tx_done_callback(); } clear_irq_status(0x7F); @@ -526,139 +502,54 @@ static void * irq_worker(void *p) { } } } + + return NULL; } /* * */ bool sx126x_init_spi(const char *spidev, uint8_t cs_port, uint8_t cs_pin) { spi_fd = open(spidev, O_RDWR); + if (spi_fd < 0) return false; - if (spi_fd < 0) { - return false; - } - - syslog(LOG_INFO, "SPI %s, CS GPIO %i:%i", spidev, (int) cs_port, (int) cs_pin); - - struct gpiod_chip *chip = gpiod_chip_open_by_number(cs_port); - - if (!chip) { - return false; - } - - cs_line = gpiod_chip_get_line(chip, cs_pin); - - if (!cs_line) { - return false; - } - - gpiod_line_request_output(cs_line, "sx126x_cs", 1); - - return true; + syslog(LOG_INFO, "SPI %s, CS GPIO chip%u:%u", spidev, (unsigned) cs_port, (unsigned) cs_pin); + cs = gpio_request(cs_port, cs_pin, GPIO_DIR_OUTPUT, GPIO_VALUE_ACTIVE, "sx126x_cs"); + return cs != NULL; } bool sx126x_init_rst(uint8_t port, uint8_t pin) { - struct gpiod_chip *chip = gpiod_chip_open_by_number(port); - - syslog(LOG_INFO, "RST GPIO %i:%i", (int) port, (int) pin); - - if (!chip) { - return false; - } - - rst_line = gpiod_chip_get_line(chip, pin); - - if (!rst_line) { - return false; - } - - gpiod_line_request_output(rst_line, "sx126x_rst", 0); - - return true; + syslog(LOG_INFO, "RST GPIO chip%u:%u", (unsigned) port, (unsigned) pin); + rst = gpio_request(port, pin, GPIO_DIR_OUTPUT, GPIO_VALUE_INACTIVE, "sx126x_rst"); + return rst != NULL; } bool sx126x_init_busy(uint8_t port, uint8_t pin) { - struct gpiod_chip *chip = gpiod_chip_open_by_number(port); - - syslog(LOG_INFO, "Busy GPIO %i:%i", (int) port, (int) pin); - - if (!chip) { - return false; - } - - busy_line = gpiod_chip_get_line(chip, pin); - - if (!busy_line) { - return false; - } - - gpiod_line_request_input(busy_line, "sx126x_busy"); - - return true; + syslog(LOG_INFO, "Busy GPIO chip%u:%u", (unsigned) port, (unsigned) pin); + busy = gpio_request(port, pin, GPIO_DIR_INPUT, GPIO_VALUE_INACTIVE, "sx126x_busy"); + return busy != NULL; } bool sx126x_init_dio1(uint8_t port, uint8_t pin) { - struct gpiod_chip *chip = gpiod_chip_open_by_number(port); - - syslog(LOG_INFO, "DIO1 GPIO %i:%i", (int) port, (int) pin); - - if (!chip) { - return false; - } - - dio1_line = gpiod_chip_get_line(chip, pin); - - if (!dio1_line) { - return false; - } - - gpiod_line_request_both_edges_events(dio1_line, "sx126x_dio1"); + syslog(LOG_INFO, "DIO1 GPIO chip%u:%u", (unsigned) port, (unsigned) pin); + dio1 = gpio_request(port, pin, GPIO_DIR_INPUT_EDGE_RISING, GPIO_VALUE_INACTIVE, "sx126x_dio1"); + if (!dio1) return false; pthread_t thread; - pthread_create(&thread, NULL, irq_worker, NULL); pthread_detach(thread); - return true; } bool sx126x_init_tx_en(uint8_t port, uint8_t pin) { - struct gpiod_chip *chip = gpiod_chip_open_by_number(port); - - syslog(LOG_INFO, "TX EN GPIO %i:%i", (int) port, (int) pin); - - if (!chip) { - return false; - } - - tx_en_line = gpiod_chip_get_line(chip, pin); - - if (!tx_en_line) { - return false; - } - - gpiod_line_request_output(tx_en_line, "sx126x_tx_en", 0); - - return true; + syslog(LOG_INFO, "TX EN GPIO chip%u:%u", (unsigned) port, (unsigned) pin); + tx_en = gpio_request(port, pin, GPIO_DIR_OUTPUT, GPIO_VALUE_INACTIVE, "sx126x_tx_en"); + return tx_en != NULL; } bool sx126x_init_rx_en(uint8_t port, uint8_t pin) { - struct gpiod_chip *chip = gpiod_chip_open_by_number(port); - - syslog(LOG_INFO, "RX EN GPIO %i:%i", (int) port, (int) pin); - - if (!chip) { - return false; - } - - rx_en_line = gpiod_chip_get_line(chip, pin); - - if (!rx_en_line) { - return false; - } - - gpiod_line_request_output(rx_en_line, "sx126x_rx_en", 0); - - return true; + syslog(LOG_INFO, "RX EN GPIO chip%u:%u", (unsigned) port, (unsigned) pin); + rx_en = gpio_request(port, pin, GPIO_DIR_OUTPUT, GPIO_VALUE_INACTIVE, "sx126x_rx_en"); + return rx_en != NULL; } void sx126x_set_rx_done_callback(sx126x_rx_done_callback_t callback) { @@ -678,9 +569,9 @@ void sx126x_set_timeout_callback(sx126x_timeout_callback_t callback) { } bool sx126x_begin() { - gpiod_line_set_value(rst_line, 0); + gpio_set(rst, GPIO_VALUE_INACTIVE); usleep(10000); - gpiod_line_set_value(rst_line, 1); + gpio_set(rst, GPIO_VALUE_ACTIVE); usleep(10000); state = SX126X_IDLE; @@ -912,11 +803,9 @@ void sx126x_packet_signal_raw(uint8_t *rssi, int8_t *snr, uint8_t *signal_rssi) } int8_t sx126x_current_rssi() { - int8_t rssi; - wait_on_busy(); - return -get_current_rssi(&rssi) / 2; + return -get_current_rssi() / 2; } uint32_t sx126x_air_time(uint16_t len, uint32_t *preamble_ms, uint32_t *data_ms) {