Skip to content

Commit 4f0a4ee

Browse files
tekka007fallberg
authored andcommitted
Use dedicated namespace for radio SPI (#985)
1 parent a23ab14 commit 4f0a4ee

File tree

6 files changed

+48
-46
lines changed

6 files changed

+48
-46
lines changed

drivers/RF24/RF24.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
5757
uint8_t status;
5858
uint8_t* current = buf;
5959
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
60-
_SPI.beginTransaction(SPISettings(MY_RF24_SPI_SPEED, RF24_SPI_DATA_ORDER,
61-
RF24_SPI_DATA_MODE));
60+
RF24_SPI.beginTransaction(SPISettings(MY_RF24_SPI_SPEED, RF24_SPI_DATA_ORDER,
61+
RF24_SPI_DATA_MODE));
6262
#endif
6363
RF24_csn(LOW);
6464
// timing
@@ -76,7 +76,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
7676
*ptx++ = *current++;
7777
}
7878
}
79-
_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
79+
RF24_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
8080
if (readMode) {
8181
if (size == 2) {
8282
status = *++prx; // result is 2nd byte of receive buffer
@@ -91,21 +91,21 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
9191
status = *prx; // status is 1st byte of receive buffer
9292
}
9393
#else
94-
status = _SPI.transfer(cmd);
94+
status = RF24_SPI.transfer(cmd);
9595
while ( len-- ) {
9696
if (readMode) {
97-
status = _SPI.transfer(RF24_CMD_NOP);
97+
status = RF24_SPI.transfer(RF24_CMD_NOP);
9898
if (buf != NULL) {
9999
*current++ = status;
100100
}
101101
} else {
102-
status = _SPI.transfer(*current++);
102+
status = RF24_SPI.transfer(*current++);
103103
}
104104
}
105105
#endif
106106
RF24_csn(HIGH);
107107
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
108-
_SPI.endTransaction();
108+
RF24_SPI.endTransaction();
109109
#endif
110110
// timing
111111
delayMicroseconds(10);
@@ -462,12 +462,12 @@ LOCAL bool RF24_initialize(void)
462462
RF24_csn(HIGH);
463463

464464
// Initialize SPI
465-
_SPI.begin();
465+
RF24_SPI.begin();
466466
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
467467
// assure SPI can be used from interrupt context
468468
// Note: ESP8266 & SoftSPI currently do not support interrupt usage for SPI,
469469
// therefore it is unsafe to use MY_RF24_IRQ_PIN with ESP8266/SoftSPI!
470-
_SPI.usingInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN));
470+
RF24_SPI.usingInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN));
471471
// attach interrupt
472472
attachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING);
473473
#endif

drivers/RF24/RF24.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@
9292

9393
#define RF24_BROADCAST_ADDRESS (255u) //!< RF24_BROADCAST_ADDRESS
9494

95-
#if defined(ARDUINO) && !defined(__arm__) && !defined(_SPI)
95+
#if defined(ARDUINO) && !defined(__arm__) && !defined(RF24_SPI)
9696
#include <SPI.h>
9797
#if defined(MY_SOFTSPI)
9898
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RF24_SPI_DATA_MODE>
99-
_SPI;
99+
RF24_SPI;
100100
#else
101-
#define _SPI SPI //!< SPI
101+
#define RF24_SPI SPI //!< SPI
102102
#endif
103103
#else
104104
#include <stdint.h>
@@ -111,8 +111,8 @@ _SPI;
111111
extern HardwareSPI SPI; //!< SPI
112112
#endif
113113

114-
#if !defined(_SPI)
115-
#define _SPI SPI //!< SPI
114+
#if !defined(RF24_SPI)
115+
#define RF24_SPI SPI //!< SPI
116116
#endif
117117
#endif
118118

drivers/RFM69/new/RFM69_new.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ LOCAL void RFM69_csn(const bool level)
6666
LOCAL void RFM69_prepareSPITransaction(void)
6767
{
6868
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
69-
_SPI.beginTransaction(SPISettings(MY_RFM69_SPI_SPEED, RFM69_SPI_DATA_ORDER, RFM69_SPI_DATA_MODE));
69+
RFM69_SPI.beginTransaction(SPISettings(MY_RFM69_SPI_SPEED, RFM69_SPI_DATA_ORDER,
70+
RFM69_SPI_DATA_MODE));
7071
#else
7172
#if defined(SREG)
7273
_SREG = SREG;
@@ -80,9 +81,9 @@ LOCAL void RFM69_prepareSPITransaction(void)
8081

8182
// set RFM69 SPI settings
8283
#if !defined(MY_SOFTSPI)
83-
_SPI.setDataMode(RFM69_SPI_DATA_MODE);
84-
_SPI.setBitOrder(RFM69_SPI_DATA_ORDER);
85-
_SPI.setClockDivider(RFM69_CLOCK_DIV);
84+
RFM69_SPI.setDataMode(RFM69_SPI_DATA_MODE);
85+
RFM69_SPI.setBitOrder(RFM69_SPI_DATA_ORDER);
86+
RFM69_SPI.setClockDivider(RFM69_CLOCK_DIV);
8687
#endif
8788

8889
#endif
@@ -91,7 +92,7 @@ LOCAL void RFM69_prepareSPITransaction(void)
9192
LOCAL void RFM69_concludeSPITransaction(void)
9293
{
9394
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
94-
_SPI.endTransaction();
95+
RFM69_SPI.endTransaction();
9596
#else
9697
// restore SPI settings to what they were before talking to RFM69
9798
#if defined(SPCR) && defined(SPSR)
@@ -128,7 +129,7 @@ LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
128129
*ptx++ = *current++;
129130
}
130131
}
131-
_SPI.transfernb((char *)spi_txbuff, (char *)spi_rxbuff, size);
132+
RFM69_SPI.transfernb((char *)spi_txbuff, (char *)spi_rxbuff, size);
132133
if (aReadMode) {
133134
if (size == 2) {
134135
status = *++prx; // result is 2nd byte of receive buffer
@@ -143,15 +144,15 @@ LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
143144
status = *prx; // status is 1st byte of receive buffer
144145
}
145146
#else
146-
status = _SPI.transfer(cmd);
147+
status = RFM69_SPI.transfer(cmd);
147148
while (len--) {
148149
if (aReadMode) {
149-
status = _SPI.transfer((uint8_t)RFM69_NOP);
150+
status = RFM69_SPI.transfer((uint8_t)RFM69_NOP);
150151
if (buf != NULL) {
151152
*current++ = status;
152153
}
153154
} else {
154-
status = _SPI.transfer(*current++);
155+
status = RFM69_SPI.transfer(*current++);
155156
}
156157
}
157158
#endif
@@ -223,7 +224,7 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
223224
// SPI init
224225
hwDigitalWrite(MY_RFM69_CS_PIN, HIGH);
225226
hwPinMode(MY_RFM69_CS_PIN, OUTPUT);
226-
_SPI.begin();
227+
RFM69_SPI.begin();
227228

228229
RFM69_setConfiguration();
229230
RFM69_setFrequency(frequencyHz);
@@ -236,7 +237,7 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
236237
// IRQ
237238
hwPinMode(MY_RFM69_IRQ_PIN, INPUT);
238239
#if defined (SPI_HAS_TRANSACTION) && !defined (ESP8266) && !defined (MY_SOFTSPI)
239-
_SPI.usingInterrupt(digitalPinToInterrupt(MY_RFM69_IRQ_PIN));
240+
RFM69_SPI.usingInterrupt(digitalPinToInterrupt(MY_RFM69_IRQ_PIN));
240241
#endif
241242

242243
#ifdef MY_DEBUG_VERBOSE_RFM69_REGISTERS
@@ -302,14 +303,14 @@ LOCAL void RFM69_interruptHandler(void)
302303
RFM69.dataReceived = !RFM69.ackReceived;
303304
}
304305
#else
305-
_SPI.transfer(RFM69_REG_FIFO & RFM69_READ_REGISTER);
306+
RFM69_SPI.transfer(RFM69_REG_FIFO & RFM69_READ_REGISTER);
306307
// set reading pointer
307308
uint8_t* current = (uint8_t*)&RFM69.currentPacket;
308309
bool headerRead = false;
309310
// first read header
310311
uint8_t readingLength = RFM69_HEADER_LEN;
311312
while (readingLength--) {
312-
*current++ = _SPI.transfer((uint8_t)0x00);
313+
*current++ = RFM69_SPI.transfer((uint8_t)0x00);
313314
if (!readingLength && !headerRead) {
314315
// header read
315316
headerRead = true;

drivers/RFM69/new/RFM69_new.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@
120120
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV256 //!< SPI clock divider 256
121121
#endif
122122

123-
#if defined (ARDUINO) && !defined (__arm__) && !defined (_SPI)
123+
#if defined (ARDUINO) && !defined (__arm__) && !defined (RFM69_SPI)
124124
#include <SPI.h>
125125
#if defined(MY_SOFTSPI)
126-
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM69_SPI_DATA_MODE> _SPI;
126+
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM69_SPI_DATA_MODE>
127+
RFM69_SPI;
127128
#else
128-
#define _SPI SPI
129+
#define RFM69_SPI SPI
129130
#endif
130131
#else
131132
#if defined(__arm__) || defined(__linux__)
@@ -134,8 +135,8 @@ SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM69_S
134135
extern HardwareSPI SPI; //!< SPI
135136
#endif
136137

137-
#if !defined(_SPI)
138-
#define _SPI SPI //!< SPI
138+
#if !defined(RFM69_SPI)
139+
#define RFM69_SPI SPI //!< SPI
139140
#endif
140141
#endif
141142

drivers/RFM95/RFM95.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ LOCAL uint8_t RFM95_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
5959
uint8_t status;
6060
uint8_t* current = buf;
6161
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
62-
_SPI.beginTransaction(SPISettings(MY_RFM95_SPI_SPEED, MY_RFM95_SPI_DATA_ORDER,
63-
MY_RFM95_SPI_DATA_MODE));
62+
RFM95_SPI.beginTransaction(SPISettings(MY_RFM95_SPI_SPEED, MY_RFM95_SPI_DATA_ORDER,
63+
MY_RFM95_SPI_DATA_MODE));
6464
#endif
6565
RFM95_csn(LOW);
6666
#if defined(LINUX_SPI_BCM)
@@ -76,7 +76,7 @@ LOCAL uint8_t RFM95_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
7676
*ptx++ = *current++;
7777
}
7878
}
79-
_SPI.transfernb((char *)spi_txbuff, (char *)spi_rxbuff, size);
79+
RFM95_SPI.transfernb((char *)spi_txbuff, (char *)spi_rxbuff, size);
8080
if (aReadMode) {
8181
if (size == 2) {
8282
status = *++prx; // result is 2nd byte of receive buffer
@@ -91,21 +91,21 @@ LOCAL uint8_t RFM95_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
9191
status = *prx; // status is 1st byte of receive buffer
9292
}
9393
#else
94-
status = _SPI.transfer(cmd);
94+
status = RFM95_SPI.transfer(cmd);
9595
while (len--) {
9696
if (aReadMode) {
97-
status = _SPI.transfer((uint8_t)RFM95_NOP);
97+
status = RFM95_SPI.transfer((uint8_t)RFM95_NOP);
9898
if (buf != NULL) {
9999
*current++ = status;
100100
}
101101
} else {
102-
status = _SPI.transfer(*current++);
102+
status = RFM95_SPI.transfer(*current++);
103103
}
104104
}
105105
#endif
106106
RFM95_csn(HIGH);
107107
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
108-
_SPI.endTransaction();
108+
RFM95_SPI.endTransaction();
109109
#endif
110110
return status;
111111
}
@@ -165,7 +165,7 @@ LOCAL bool RFM95_initialise(const uint32_t frequencyHz)
165165
// SPI init
166166
hwDigitalWrite(MY_RFM95_CS_PIN, HIGH);
167167
hwPinMode(MY_RFM95_CS_PIN, OUTPUT);
168-
_SPI.begin();
168+
RFM95_SPI.begin();
169169

170170
// Set LoRa mode (during sleep mode)
171171
RFM95_writeReg(RFM95_REG_01_OP_MODE, RFM95_MODE_SLEEP | RFM95_LONG_RANGE_MODE);
@@ -188,7 +188,7 @@ LOCAL bool RFM95_initialise(const uint32_t frequencyHz)
188188
// IRQ
189189
hwPinMode(MY_RFM95_IRQ_PIN, INPUT);
190190
#if defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) && !defined(MY_SOFTSPI)
191-
_SPI.usingInterrupt(MY_RFM95_IRQ_NUM);
191+
RFM95_SPI.usingInterrupt(MY_RFM95_IRQ_NUM);
192192
#endif
193193

194194
if (!RFM95_sanityCheck()) {

drivers/RFM95/RFM95.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@
114114
#define MY_RFM95_SPI_DATA_ORDER MSBFIRST //!< SPI data order
115115
#define MY_RFM95_SPI_DATA_MODE SPI_MODE0 //!< SPI mode
116116

117-
#if defined (ARDUINO) && !defined (__arm__) && !defined (_SPI)
117+
#if defined (ARDUINO) && !defined (__arm__) && !defined (RFM95_SPI)
118118
#include <SPI.h>
119119
#if defined(MY_SOFTSPI)
120120
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, MY_RF24_SPI_DATA_MODE>
121-
_SPI;
121+
RFM95_SPI;
122122
#else
123-
#define _SPI SPI //!< SPI
123+
#define RFM95_SPI SPI //!< SPI
124124
#endif
125125
#else
126126
#if defined(__arm__) || defined(__linux__)
@@ -129,8 +129,8 @@ _SPI;
129129
extern HardwareSPI SPI; //!< SPI
130130
#endif
131131

132-
#if !defined(_SPI)
133-
#define _SPI SPI //!< SPI
132+
#if !defined(RFM95_SPI)
133+
#define RFM95_SPI SPI //!< SPI
134134
#endif
135135
#endif
136136

0 commit comments

Comments
 (0)