mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sx127x: avoid explicit cast to netdev
This commit is contained in:
parent
c9ee5fb76a
commit
bfbbec3de3
@ -75,7 +75,7 @@ static void sx127x_on_dio3_isr(void *arg);
|
||||
|
||||
void sx127x_setup(sx127x_t *dev, const sx127x_params_t *params, uint8_t index)
|
||||
{
|
||||
netdev_t *netdev = (netdev_t *)dev;
|
||||
netdev_t *netdev = &dev->netdev;
|
||||
|
||||
netdev->driver = &sx127x_driver;
|
||||
dev->params = *params;
|
||||
@ -234,27 +234,27 @@ void sx127x_isr(netdev_t *dev)
|
||||
static void sx127x_on_dio_isr(sx127x_t *dev, sx127x_flags_t flag)
|
||||
{
|
||||
dev->irq |= flag;
|
||||
sx127x_isr((netdev_t *)dev);
|
||||
sx127x_isr(&dev->netdev);
|
||||
}
|
||||
|
||||
static void sx127x_on_dio0_isr(void *arg)
|
||||
{
|
||||
sx127x_on_dio_isr((sx127x_t *)arg, SX127X_IRQ_DIO0);
|
||||
sx127x_on_dio_isr(arg, SX127X_IRQ_DIO0);
|
||||
}
|
||||
|
||||
static void sx127x_on_dio1_isr(void *arg)
|
||||
{
|
||||
sx127x_on_dio_isr((sx127x_t *)arg, SX127X_IRQ_DIO1);
|
||||
sx127x_on_dio_isr(arg, SX127X_IRQ_DIO1);
|
||||
}
|
||||
|
||||
static void sx127x_on_dio2_isr(void *arg)
|
||||
{
|
||||
sx127x_on_dio_isr((sx127x_t *)arg, SX127X_IRQ_DIO2);
|
||||
sx127x_on_dio_isr(arg, SX127X_IRQ_DIO2);
|
||||
}
|
||||
|
||||
static void sx127x_on_dio3_isr(void *arg)
|
||||
{
|
||||
sx127x_on_dio_isr((sx127x_t *)arg, SX127X_IRQ_DIO3);
|
||||
sx127x_on_dio_isr(arg, SX127X_IRQ_DIO3);
|
||||
}
|
||||
|
||||
/* Internal event handlers */
|
||||
@ -316,14 +316,14 @@ static int _init_gpios(sx127x_t *dev)
|
||||
|
||||
static void _on_tx_timeout(void *arg)
|
||||
{
|
||||
netdev_t *dev = (netdev_t *)arg;
|
||||
netdev_t *dev = arg;
|
||||
|
||||
dev->event_callback(dev, NETDEV_EVENT_TX_TIMEOUT);
|
||||
}
|
||||
|
||||
static void _on_rx_timeout(void *arg)
|
||||
{
|
||||
netdev_t *dev = (netdev_t *)arg;
|
||||
netdev_t *dev = arg;
|
||||
|
||||
dev->event_callback(dev, NETDEV_EVENT_RX_TIMEOUT);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ void _on_dio3_irq(void *arg);
|
||||
static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||
{
|
||||
DEBUG("[sx127x] Sending packet now.\n");
|
||||
sx127x_t *dev = (sx127x_t *)netdev;
|
||||
sx127x_t *dev = container_of(netdev, sx127x_t, netdev);
|
||||
|
||||
if (sx127x_get_state(dev) == SX127X_RF_TX_RUNNING) {
|
||||
DEBUG("[sx127x] Cannot send packet: radio already in transmitting "
|
||||
@ -107,7 +107,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||
|
||||
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||
{
|
||||
sx127x_t *dev = (sx127x_t *)netdev;
|
||||
sx127x_t *dev = container_of(netdev, sx127x_t, netdev);
|
||||
volatile uint8_t irq_flags = 0;
|
||||
uint8_t size = 0;
|
||||
|
||||
@ -205,7 +205,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||
|
||||
static int _init(netdev_t *netdev)
|
||||
{
|
||||
sx127x_t *sx127x = (sx127x_t *)netdev;
|
||||
sx127x_t *sx127x = container_of(netdev, sx127x_t, netdev);
|
||||
|
||||
sx127x->irq = 0;
|
||||
sx127x_radio_settings_t settings;
|
||||
@ -234,7 +234,7 @@ static int _init(netdev_t *netdev)
|
||||
|
||||
static void _isr(netdev_t *netdev)
|
||||
{
|
||||
sx127x_t *dev = (sx127x_t *)netdev;
|
||||
sx127x_t *dev = container_of(netdev, sx127x_t, netdev);
|
||||
|
||||
uint8_t interruptReg = sx127x_reg_read(dev, SX127X_REG_LR_IRQFLAGS);
|
||||
|
||||
@ -261,7 +261,7 @@ static void _isr(netdev_t *netdev)
|
||||
static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
|
||||
{
|
||||
(void)max_len; /* unused when compiled without debug, assert empty */
|
||||
sx127x_t *dev = (sx127x_t *)netdev;
|
||||
sx127x_t *dev = container_of(netdev, sx127x_t, netdev);
|
||||
|
||||
if (dev == NULL) {
|
||||
return -ENODEV;
|
||||
@ -360,7 +360,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
{
|
||||
(void)len; /* unused when compiled without debug, assert empty */
|
||||
|
||||
sx127x_t *dev = (sx127x_t *)netdev;
|
||||
sx127x_t *dev = container_of(netdev, sx127x_t, netdev);
|
||||
int res = -ENOTSUP;
|
||||
|
||||
if (dev == NULL) {
|
||||
@ -577,8 +577,8 @@ static int _get_state(sx127x_t *dev, void *val)
|
||||
|
||||
void _on_dio0_irq(void *arg)
|
||||
{
|
||||
sx127x_t *dev = (sx127x_t *)arg;
|
||||
netdev_t *netdev = (netdev_t *)&dev->netdev;
|
||||
sx127x_t *dev = arg;
|
||||
netdev_t *netdev = &dev->netdev;
|
||||
|
||||
switch (dev->settings.state) {
|
||||
case SX127X_RF_RX_RUNNING:
|
||||
@ -612,8 +612,8 @@ void _on_dio0_irq(void *arg)
|
||||
void _on_dio1_irq(void *arg)
|
||||
{
|
||||
/* Get interrupt context */
|
||||
sx127x_t *dev = (sx127x_t *)arg;
|
||||
netdev_t *netdev = (netdev_t *)&dev->netdev;
|
||||
sx127x_t *dev = arg;
|
||||
netdev_t *netdev = &dev->netdev;
|
||||
|
||||
switch (dev->settings.state) {
|
||||
case SX127X_RF_RX_RUNNING:
|
||||
@ -652,8 +652,8 @@ void _on_dio1_irq(void *arg)
|
||||
void _on_dio2_irq(void *arg)
|
||||
{
|
||||
/* Get interrupt context */
|
||||
sx127x_t *dev = (sx127x_t *)arg;
|
||||
netdev_t *netdev = (netdev_t *)dev;
|
||||
sx127x_t *dev = arg;
|
||||
netdev_t *netdev = &dev->netdev;
|
||||
|
||||
switch (dev->settings.state) {
|
||||
case SX127X_RF_RX_RUNNING:
|
||||
@ -705,8 +705,8 @@ void _on_dio2_irq(void *arg)
|
||||
void _on_dio3_irq(void *arg)
|
||||
{
|
||||
/* Get interrupt context */
|
||||
sx127x_t *dev = (sx127x_t *)arg;
|
||||
netdev_t *netdev = (netdev_t *)dev;
|
||||
sx127x_t *dev = arg;
|
||||
netdev_t *netdev = &dev->netdev;
|
||||
|
||||
switch (dev->settings.state) {
|
||||
case SX127X_RF_CAD:
|
||||
|
@ -108,7 +108,7 @@ int lora_setup_cmd(int argc, char **argv)
|
||||
uint8_t lora_cr = (uint8_t)(cr - 4);
|
||||
|
||||
/* Configure radio device */
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
netdev->driver->set(netdev, NETOPT_BANDWIDTH,
|
||||
&lora_bw, sizeof(lora_bw));
|
||||
@ -127,7 +127,7 @@ int random_cmd(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
uint32_t rand;
|
||||
|
||||
netdev->driver->get(netdev, NETOPT_RANDOM, &rand, sizeof(rand));
|
||||
@ -135,7 +135,7 @@ int random_cmd(int argc, char **argv)
|
||||
(unsigned int)rand);
|
||||
|
||||
/* reinit the transceiver to default values */
|
||||
sx127x_init_radio_settings((sx127x_t *)netdev);
|
||||
sx127x_init_radio_settings(&sx127x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -249,7 +249,7 @@ int send_cmd(int argc, char **argv)
|
||||
.iol_len = (strlen(argv[1]) + 1)
|
||||
};
|
||||
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
if (netdev->driver->send(netdev, &iolist) == -ENOTSUP) {
|
||||
puts("Cannot send: radio is still transmitting");
|
||||
@ -263,7 +263,7 @@ int listen_cmd(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
/* Switch to continuous listen mode */
|
||||
const netopt_enable_t single = false;
|
||||
|
||||
@ -289,7 +289,7 @@ int syncword_cmd(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
uint8_t syncword;
|
||||
|
||||
if (strstr(argv[1], "get") != NULL) {
|
||||
@ -323,7 +323,7 @@ int channel_cmd(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
uint32_t chan;
|
||||
|
||||
if (strstr(argv[1], "get") != NULL) {
|
||||
@ -358,7 +358,7 @@ int rx_timeout_cmd(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
uint8_t rx_timeout;
|
||||
|
||||
if (strstr(argv[1], "set") != NULL) {
|
||||
@ -383,7 +383,7 @@ int reset_cmd(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
puts("resetting sx127x...");
|
||||
netopt_state_t state = NETOPT_STATE_RESET;
|
||||
@ -409,7 +409,7 @@ static void _set_opt(netdev_t *netdev, netopt_t opt, bool val, char *str_help)
|
||||
|
||||
int crc_cmd(int argc, char **argv)
|
||||
{
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||
printf("usage: %s set <1|0>\n", argv[0]);
|
||||
@ -424,7 +424,7 @@ int crc_cmd(int argc, char **argv)
|
||||
|
||||
int implicit_cmd(int argc, char **argv)
|
||||
{
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||
printf("usage: %s set <1|0>\n", argv[0]);
|
||||
@ -439,7 +439,7 @@ int implicit_cmd(int argc, char **argv)
|
||||
|
||||
int payload_cmd(int argc, char **argv)
|
||||
{
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||
printf("usage: %s set <payload length>\n", argv[0]);
|
||||
@ -542,7 +542,7 @@ void *_recv_thread(void *arg)
|
||||
int main(void)
|
||||
{
|
||||
sx127x.params = sx127x_params[0];
|
||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||
netdev_t *netdev = &sx127x.netdev;
|
||||
|
||||
netdev->driver = &sx127x_driver;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user