Skip to content

Commit

Permalink
firmware: drivers: sx127x: Initial structure of the SX127x driver #60
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm8 committed Dec 15, 2021
1 parent 494758e commit 3dd8dfb
Show file tree
Hide file tree
Showing 5 changed files with 456 additions and 0 deletions.
70 changes: 70 additions & 0 deletions firmware/drivers/sx127x/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,74 @@ int sx127x_read_rssi(uint8_t mode)
return -1;
}

int sx127x_power_on_reset(void)
{
return -1;
}

int sx127x_config(void)
{
return -1;
}

int sx127x_set_ant_switch(uint8_t mode)
{
return -1;
}

int sx127x_set_fifo_addr_ptr(uint8_t adr)
{
return -1;
}

int sx127x_enter_rx_mode(void)
{
return -1;
}

int sx127x_enter_tx_mode(void)
{
return -1;
}

int sx127x_write_fifo(uint8_t *data, uint8_t len)
{
return -1;
}

int sx127x_read_fifo(uint8_t *data, uint8_t *len)
{
return -1;
}

int sx127x_set_tx_interrupt(void)
{
return -1;
}

int sx127x_set_rx_interrupt(void)
{
return -1;
}

int sx127x_read_reg(uint8_t adr, uint8_t *val)
{
return -1;
}

int sx127x_write_reg(uint8_t adr, uint8_t val)
{
return -1;
}

int sx127x_burst_read(uint8_t adr, uint8_t *ptr, uint8_t len)
{
return -1;
}

int sx127x_burst_write(uint8_t adr, uint8_t *ptr, uint8_t len)
{
return -1;
}

/** \} End of sx127x group */
218 changes: 218 additions & 0 deletions firmware/drivers/sx127x/sx127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,224 @@ int sx127x_set_rx_timeout(uint16_t symb_timeout);
*/
int sx127x_read_rssi(uint8_t mode);

/**
* \brief Power on the module.
*
* \return The status/error code.
*/
static int sx127x_power_on_reset(void);

/**
* \brief Sets the initial parameters.
*
* \return The status/error code.
*/
static int sx127x_config(void);

/**
* \brief Sets the antenna switch.
*
* \param[in] mode .
*
* \return The status/error code.
*/
static int sx127x_set_ant_switch(uint8_t mode);

/**
* \brief .
*
* \param[in] adr .
*
* \return The status/error code.
*/
static int sx127x_set_fifo_addr_ptr(uint8_t adr);

/**
* \brief Enters in RX mode.
*
* \return The status/error code.
*/
static int sx127x_enter_rx_mode(void);

/**
* \brief Enters in TX mode.
*
* \return The status/error code.
*/
static int sx127x_enter_tx_mode(void);

/**
* \brief Writes data to the FIFO.
*
* \param[in] data is an array with the bytes to be written in the FIFO.
*
* \param[in] len is the number of bytes to be written.
*
* \return The status/error code.
*/
static int sx127x_write_fifo(uint8_t *data, uint8_t len);

/**
* \brief Reads data from the FIFO.
*
* \param[in,out] data is a pointer to store the read data.
*
* \param[in,out] len is the number of read bytes.
*
* \return The status/error code.
*/
static int sx127x_read_fifo(uint8_t *data, uint8_t *len);

/**
* \brief Enables TX done interrupt.
*
* \return The status/error code.
*/
static int sx127x_set_tx_interrupt(void);

/**
* \brief Enables RX done interrupt.
*
* \return The status/error code.
*/
static int sx127x_set_rx_interrupt(void);

/**
* \brief Reads the value of a given register.
*
* \param[in] adr is the address of the register.
*
* \param[in,out] val is a pointer to store the read value.
*
* \return The status/error code.
*/
static int sx127x_read_reg(uint8_t adr, uint8_t *val);

/**
* \brief Writes a value to a register.
*
* \param[in] adr is the address of the register to write.
*
* \param[in] val is the value to write.
*
* \return The status/error code.
*/
static int sx127x_write_reg(uint8_t adr, uint8_t val);

/**
* \brief Reads the buffer trough SPI.
*
* \param[in] adr is the address to start reading.
*
* \param[in] ptr is a pointer to store the read data.
*
* \param[in] len is the number of bytes to read.
*
* \return The status/error code.
*/
static int sx127x_burst_read(uint8_t adr, uint8_t *ptr, uint8_t len);

/**
* \brief Writes buffer trough SPI.
*
* \param[in] adr is the address to start writing.
*
* \param[in] ptr is a pointer with the data to write.
*
* \param[in] len is the number of bytes to write.
*
* \return The status/error code.
*/
static int sx127x_burst_write(uint8_t adr, uint8_t *ptr, uint8_t len);

/**
* \brief SPI interface initialization.
*
* \return The status/error code.
*/
static int sx127x_spi_init(void);

/**
* \brief SPI transfer routine (write and read at the same time).
*
* \param[in] wd is an array ot bytes to write during the transfer.
*
* \param[in,out] rd is an array to store the read bytes during the transfer.
*
* \param[in] len is the number of bytes to transfer.
*
* \return The status/error code.
*/
static int sx127x_spi_transfer(uint8_t *wd, uint8_t *rd, uint16_t len);

/**
* \brief Writes a byte over the SPI interface.
*
* \param[in] byte is the byte to be written to the SPI interface.
*
* \return The status/error code.
*/
static int sx127x_spi_write_byte(uint8_t byte);

/**
* \brief Write an array of bytes over the SPI interface.
*
* \param[in] data is the array of bytes to write to the SPI interface.
*
* \param[in] len is the number of bytes to be written.
*
* \return The status/error code.
*/
static int sx127x_spi_write(uint8_t *data, uint16_t len);

/**
* \brief Reads N bytes from the SPI interface.
*
* \param[in] data is an array to store the read bytes.
*
* \param[in] len is the number of bytes to read.
*
* \return The status/error code.
*/
static int sx127x_spi_read(uint8_t *data, uint16_t len);

/**
* \brief GPIO pins initialization.
*
* \return The status/error code.
*/
static int sx127x_gpio_init(void);

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

/**
* \brief Reads the state of the nIRQ pin.
*
* \return The state of the nIRQ pin. It can be:
* \parblock
* -\b GPIO_STATE_HIGH
* -\b GPIO_STATE_LOW
* .
* \endparblock
*/
static int sx127x_gpio_read_nirq(void);

/**
* \brief Milliseconds delay.
*
* \param[in] ms is the time to delay in milliseconds.
*
* \return None.
*/
void sx127x_delay_ms(uint32_t ms);

#endif /* SX127X_H_ */

/** \} End of sx127x group */
46 changes: 46 additions & 0 deletions firmware/drivers/sx127x/sx127x_delay.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* sx127x_delay.c
*
* Copyright The TTC 2.0 Contributors.
*
* This file is part of TTC 2.0.
*
* TTC 2.0 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TTC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TTC 2.0. If not, see <http:/\/www.gnu.org/licenses/>.
*
*/

/**
* \brief SX127x delay implementation.
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.1.3
*
* \date 2021/12/15
*
* \addtogroup sx127x
* \{
*/

#include <config/config.h>
#include <system/sys_log/sys_log.h>

#include "sx127x.h"

void sx127x_delay_ms(uint32_t ms)
{
return;
}

/** \} End of sx127x group */
Loading

0 comments on commit 3dd8dfb

Please sign in to comment.