Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/sx127x: optimize power consumption on nss pin #11384

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions drivers/sx127x/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ static int _init_spi(sx127x_t *dev)
return -1;
}

/* Minimize power consumption of NSS pin */
gpio_init(dev->params.nss_pin, SX127X_DIO_PULL_MODE);

DEBUG("[sx127x] SPI_%i initialized with success\n", dev->params.spi);
return 0;
}
12 changes: 12 additions & 0 deletions drivers/sx127x/sx127x_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,37 @@ uint8_t sx127x_reg_read(const sx127x_t *dev, uint8_t addr)
void sx127x_reg_write_burst(const sx127x_t *dev, uint8_t addr, uint8_t *buffer,
uint8_t size)
{
/* Restore NSS pin working state */
gpio_init(dev->params.nss_pin, GPIO_OUT);

spi_acquire(dev->params.spi, SPI_CS_UNDEF, SX127X_SPI_MODE, SX127X_SPI_SPEED);

gpio_clear(dev->params.nss_pin);
spi_transfer_regs(dev->params.spi, SPI_CS_UNDEF, addr | 0x80, (char *) buffer, NULL, size);
gpio_set(dev->params.nss_pin);

spi_release(dev->params.spi);

/* Minimize power consumption of NSS pin */
gpio_init(dev->params.nss_pin, SX127X_DIO_PULL_MODE);
}

void sx127x_reg_read_burst(const sx127x_t *dev, uint8_t addr, uint8_t *buffer,
uint8_t size)
{
/* Restore NSS pin working state */
gpio_init(dev->params.nss_pin, GPIO_OUT);

spi_acquire(dev->params.spi, SPI_CS_UNDEF, SX127X_SPI_MODE, SX127X_SPI_SPEED);

gpio_clear(dev->params.nss_pin);
spi_transfer_regs(dev->params.spi, SPI_CS_UNDEF, addr & 0x7F, NULL, (char *) buffer, size);
gpio_set(dev->params.nss_pin);

spi_release(dev->params.spi);

/* Minimize power consumption of NSS pin */
gpio_init(dev->params.nss_pin, SX127X_DIO_PULL_MODE);
}

void sx127x_write_fifo(const sx127x_t *dev, uint8_t *buffer, uint8_t size)
Expand Down