69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
/**
|
|
* Author Wojciech Domski <Wojciech.Domski@gmail.com>
|
|
* www: www.Domski.pl
|
|
*
|
|
* Hardware layer for SX1278 LoRa module
|
|
*/
|
|
|
|
#include "SX1278_hw.h"
|
|
#include <string.h>
|
|
|
|
#include "systick.h"
|
|
#include "softspi.h"
|
|
|
|
#define SetSS SoftSPI_SetSS(sx1278_spix)
|
|
#define ClrSS SoftSPI_ClrSS(sx1278_spix)
|
|
#define SPI_WriteRead(__byte__) SoftSPI_WriteRead(sx1278_spix, __byte__)
|
|
|
|
extern SoftSPI_TypeDef *sx1278_spix;
|
|
|
|
void SX1278_hw_init(SX1278_hw_t *hw)
|
|
{
|
|
SX1278_hw_SetNSS(hw, 1);
|
|
HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
void SX1278_hw_SetNSS(SX1278_hw_t *hw, int value)
|
|
{
|
|
(value == 1) ? SetSS : ClrSS;
|
|
}
|
|
|
|
void SX1278_hw_Reset(SX1278_hw_t *hw)
|
|
{
|
|
SX1278_hw_SetNSS(hw, 1);
|
|
HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_RESET);
|
|
|
|
SX1278_hw_DelayMs(1);
|
|
|
|
HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
|
|
|
|
SX1278_hw_DelayMs(100);
|
|
}
|
|
|
|
void SX1278_hw_SPICommand(SX1278_hw_t *hw, uint8_t cmd)
|
|
{
|
|
SX1278_hw_SetNSS(hw, 0);
|
|
SPI_WriteRead(cmd);
|
|
}
|
|
|
|
uint8_t SX1278_hw_SPIReadByte(SX1278_hw_t *hw)
|
|
{
|
|
uint8_t txByte = 0x00;
|
|
uint8_t rxByte = 0x00;
|
|
|
|
SX1278_hw_SetNSS(hw, 0);
|
|
rxByte = SPI_WriteRead(txByte);
|
|
|
|
return rxByte;
|
|
}
|
|
|
|
void SX1278_hw_DelayMs(uint32_t msec)
|
|
{
|
|
Delay_ms(msec);
|
|
}
|
|
|
|
// int SX1278_hw_GetDIO0(SX1278_hw_t *hw)
|
|
// {
|
|
// return (HAL_GPIO_ReadPin(hw->dio0.port, hw->dio0.pin) == GPIO_PIN_SET);
|
|
// }
|