Skip to content

Commit

Permalink
drivers/sx126x: read error flags
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Mar 5, 2025
1 parent 526acc3 commit 26b0c55
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
23 changes: 18 additions & 5 deletions drivers/sx126x/sx126x.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <errno.h>
#include <stdbool.h>

#include "log.h"
#include "macros/math.h"
#include "macros/utils.h"
#include "net/lora.h"
Expand Down Expand Up @@ -227,11 +228,13 @@ int sx126x_init(sx126x_t *dev)
/* Reset the device */
sx126x_reset(dev);

/* Configure the power regulator mode */
sx126x_set_reg_mode(dev, dev->params->regulator);

/* Initialize radio with the default parameters */
sx126x_init_default_config(dev);
/* check for errors */
sx126x_errors_mask_t error = 0;
sx126x_get_device_errors(dev, &error);
if (error) {
SX126X_LOG_INFO(dev, "startup: device errors 0x%04x\n", error);
}
sx126x_clear_device_errors(dev);

/* Configure available IRQs */
uint16_t irq_mask_dio1 = dev->params->dio1_irq_mask;
Expand Down Expand Up @@ -301,6 +304,16 @@ int sx126x_init(sx126x_t *dev)
sx126x_cal(dev, SX126X_CAL_ALL);
}
#endif
error = 0;
sx126x_get_device_errors(dev, &error);
if (error) {
SX126X_LOG_ERROR(dev, "error: device error 0x%04x\n", error);
}
else {
SX126X_LOG_INFO(dev, "startup successful\n");
}
sx126x_clear_device_errors(dev);

/* The user can specify the use of DC-DC by using the command SetRegulatorMode(...).
This operation must be carried out in STDBY_RC mode only.*/
sx126x_set_reg_mode(dev, dev->params->regulator);
Expand Down
21 changes: 19 additions & 2 deletions drivers/sx126x/sx126x_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)

static int _set_state(sx126x_t *dev, netopt_state_t state)
{
/* check for errors */
sx126x_errors_mask_t error = 0;
sx126x_get_device_errors(dev, &error);
if (error) {
SX126X_DEBUG(dev, "netdev set state: device error 0x%04x before setting state\n", error);
}
sx126x_clear_device_errors(dev);
int ret = sizeof(netopt_state_t);

switch (state) {
case NETOPT_STATE_STANDBY:
DEBUG("[sx126x] netdev: set NETOPT_STATE_STANDBY state\n");
Expand Down Expand Up @@ -347,9 +356,17 @@ static int _set_state(sx126x_t *dev, netopt_state_t state)
break;

default:
return -ENOTSUP;
ret = -ENOTSUP;
}
return sizeof(netopt_state_t);

error = 0;
sx126x_get_device_errors(dev, &error);
if (error) {
SX126X_DEBUG(dev, "netdev set state: device error 0x%04x\n", error);
}
sx126x_clear_device_errors(dev);

return ret;
}

static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
Expand Down

0 comments on commit 26b0c55

Please sign in to comment.