-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsx1278-Hal.c
More file actions
180 lines (154 loc) · 4.54 KB
/
sx1278-Hal.c
File metadata and controls
180 lines (154 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND
* (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER.
* CONSEQUENTLY, SEMTECH SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR
* CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* Copyright (C) SEMTECH S.A.
*/
/*!
* \file sx1278-Hal.c
* \brief SX1278 Hardware Abstraction Layer
*
* \version 2.0.B2
* \date Nov 21 2012
* \author Miguel Luis
*
* Last modified by Marc0 Xu on Jan 07 2018
*/
//#include <stdint.h>
//#include <stdbool.h>
#include "platform.h"
#include "RadioConfig.h"
#if defined( USE_SX1278_RADIO )
#include "sx1278-Hal.h"
/*!
* SX1278 RESET I/O definitions
*/
/*!
* SX1278 SPI NSS I/O definitions
*/
#define SPI_NSS_LOW() HAL_GPIO_WritePin(NSS_IOPORT , NSS_PIN, GPIO_PIN_RESET)
#define SPI_NSS_HIGH() HAL_GPIO_WritePin(NSS_IOPORT , NSS_PIN, GPIO_PIN_SET)
#define DUMMY_BYTE 0
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Configure system clock to run at 16MHz
* @param None
* @retval None
*/
void BoardInit( void )
{
HAL_GPIO_WritePin(RST_IOPORT,RST_PIN,GPIO_PIN_RESET);
osDelay(10);
HAL_GPIO_WritePin(RST_IOPORT,RST_PIN,GPIO_PIN_SET);
osDelay(10);
}
void SX1278InitIo( void )
{
//EXTI_SetPinSensitivity(EXTI_Pin_5, EXTI_Trigger_Rising);
}
/**********************************************************
* @brief Sends a byte through the SPI interface and
return the byte received from the SPI bus.
* @param byte: byte to send.
* @retval The value of the received byte.
**********************************************************/
static uint8_t SPI1_SendByte(uint8_t byte)
{
uint8_t Readbyte;
HAL_SPI_TransmitReceive(&SX1278SPI,&byte,&Readbyte,1,100);
return Readbyte;
}
/**********************************************************
**Name: SPIWrite
**Function: SPI Write CMD
**Input: uint8_t address & uint8_t data
**Output: None
**********************************************************/
void SPIWrite(uint8_t adr, uint8_t WrPara)
{
SPI_NSS_LOW();
SPI1_SendByte(adr|0x80);
SPI1_SendByte(WrPara);
SPI_NSS_HIGH();
}
/**********************************************************
**Name: SPIRead
**Function: SPI Read CMD
**Input: adr -> address for read
**Output: None
**********************************************************/
uint8_t SPIRead(uint8_t adr)
{
uint8_t tmp;
SPI_NSS_LOW();
SPI1_SendByte(adr);
tmp = SPI1_SendByte(DUMMY_BYTE);
SPI_NSS_HIGH();
return(tmp);
}
/**********************************************************
**Name: SX1278ReadBuffer
**Function: SPI burst read mode
**Input: adr-----address for read
** ptr-----data buffer point for read
** length--how many bytes for read
**Output: None
**********************************************************/
void SX1278ReadBuffer(uint8_t adr, uint8_t *ptr, uint8_t length)
{
uint8_t i;
SPI_NSS_LOW();
SPI1_SendByte(adr);
for(i=0;i<length;i++)
ptr[i] = SPI1_SendByte(DUMMY_BYTE);
SPI_NSS_HIGH();
}
/**********************************************************
**Name: SX1278WriteBuffer
**Function: SPI burst write mode
**Input: adr-----address for write
** ptr-----data buffer point for write
** length--how many bytes for write
**Output: none
**********************************************************/
void SX1278WriteBuffer(uint8_t adr, uint8_t *ptr, uint8_t length)
{
uint8_t i;
SPI_NSS_LOW();
SPI1_SendByte(adr|0x80);
for(i=0;i<length;i++)
SPI1_SendByte(ptr[i]);
SPI_NSS_HIGH();
}
void SX1278Write( uint8_t addr, uint8_t data )
{
SX1278WriteBuffer( addr, &data, 1 );
#if (SX1278_DEBUG==1)
printf("WRITE REG 0x%02X = 0x%02X\r\n",addr,data);
#endif
}
void SX1278Read( uint8_t addr, uint8_t *data )
{
SX1278ReadBuffer( addr, data, 1 );
#if (SX1278_DEBUG==1)
printf("READ REG 0x%02X : 0x%02X\r\n",addr,*data);
#endif
}
void SX1278WriteFifo( uint8_t *buffer, uint8_t size )
{
SX1278WriteBuffer( 0, buffer, size );
}
void SX1278ReadFifo( uint8_t *buffer, uint8_t size )
{
SX1278ReadBuffer( 0, buffer, size );
}
inline uint8_t SX1278ReadDio0( void )
{
return HAL_GPIO_ReadPin( DIO0_IOPORT, DIO0_PIN );
}
#endif // USE_SX1278_RADIO