Skip to content

Commit

Permalink
firmware: drivers: sx127x: Implementation of the SPI and GPIO interfa…
Browse files Browse the repository at this point in the history
…ces #60
  • Loading branch information
mgm8 committed Dec 17, 2021
1 parent 3dd8dfb commit 77058cb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
6 changes: 3 additions & 3 deletions firmware/drivers/sx127x/sx127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,13 @@ static int sx127x_spi_read(uint8_t *data, uint16_t len);
static int sx127x_gpio_init(void);

/**
* \brief Write the state of the SDN pin.
* \brief Write the state of the RESET pin.
*
* \param[in] state is new state of the SDN pin.
* \param[in] state is new state of the RESET pin.
*
* \return The status/error code.
*/
static int sx127X_gpio_write_sdn(bool state);
static int sx127X_gpio_write_reset(bool state);

/**
* \brief Reads the state of the nIRQ pin.
Expand Down
32 changes: 28 additions & 4 deletions firmware/drivers/sx127x/sx127x_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,43 @@

#include "sx127x.h"

/* GPIO configuration */
#define SX127X_GPIO_RESET_PIN GPIO_PIN_16
#define SX127X_GPIO_NIRQ_PIN GPIO_PIN_17

int sx127x_gpio_init(void)
{
return -1;
int err = 0;

gpio_config_t conf = {0};

conf.mode = GPIO_MODE_OUTPUT;

/* RESET pin */
if (gpio_init(SX127X_GPIO_RESET_PIN, conf) != 0)
{
err = -1;
}

conf.mode = GPIO_MODE_INPUT;

/* nIRQ pin */
if (gpio_init(SX127X_GPIO_NIRQ_PIN, conf) != 0)
{
err = -1;
}

return err;
}

int sx127X_gpio_write_sdn(bool state)
int sx127X_gpio_write_reset(bool state)
{
return -1;
return gpio_set_state(SX127X_GPIO_RESET_PIN, state);
}

int sx127x_gpio_read_nirq(void)
{
return -1;
return gpio_get_state(SX127X_GPIO_NIRQ_PIN);
}

/** \} End of sx127x group */
21 changes: 16 additions & 5 deletions firmware/drivers/sx127x/sx127x_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,40 @@

#include "sx127x.h"

/* SPI configuration */
#define SX127X_SPI_PORT SPI_PORT_3
#define SX127X_SPI_CS_PIN SPI_CS_0
#define SX127X_SPI_MODE SPI_MODE_1
#define SX127X_SPI_SPEED CONFIG_SPI_PORT_0_SPEED_BPS

int sx127x_spi_init(void)
{
return -1;
spi_config_t conf = {0};

conf.speed_hz = SX127X_SPI_SPEED;
conf.mode = SX127X_SPI_MODE;

return spi_init(SX127X_SPI_PORT, conf);
}

int sx127x_spi_transfer(uint8_t *wd, uint8_t *rd, uint16_t len)
{
return -1;
return spi_transfer(SX127X_SPI_PORT, SX127X_SPI_CS_PIN, wd, rd, len);
}

int sx127x_spi_write_byte(uint8_t byte)
{
return -1;
return spi_write(SX127X_SPI_PORT, SX127X_SPI_CS_PIN, &byte, 1);
}

int sx127x_spi_write(uint8_t *data, uint16_t len)
{
return -1;
return spi_write(SX127X_SPI_PORT, SX127X_SPI_CS_PIN, data, len);
}

int sx127x_spi_read(uint8_t *data, uint16_t len)
{
return -1;
return spi_read(SX127X_SPI_PORT, SX127X_SPI_CS_PIN, data, len);
}

/** \} End of sx127x group */

0 comments on commit 77058cb

Please sign in to comment.