Fix variable names, minor updates (#1071)
This commit is contained in:
+20
-17
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Copyright (C) 2013-2018 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
@@ -36,9 +36,10 @@ LOCAL uint8_t RF24_NODE_ADDRESS = RF24_BROADCAST_ADDRESS;
|
||||
LOCAL RF24_receiveCallbackType RF24_receiveCallback = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef LINUX_SPI_BCM
|
||||
uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
|
||||
uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
|
||||
#if defined(LINUX_SPI_BCM)
|
||||
uint8_t RF24_spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
|
||||
uint8_t RF24_spi_txbuff[32+1]
|
||||
; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
|
||||
#endif
|
||||
|
||||
LOCAL void RF24_csn(const bool level)
|
||||
@@ -51,21 +52,22 @@ LOCAL void RF24_ce(const bool level)
|
||||
hwDigitalWrite(MY_RF24_CE_PIN, level);
|
||||
}
|
||||
|
||||
LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t len,
|
||||
LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_t len,
|
||||
const bool readMode)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t* current = buf;
|
||||
uint8_t *current = buf;
|
||||
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
|
||||
RF24_SPI.beginTransaction(SPISettings(MY_RF24_SPI_SPEED, RF24_SPI_DATA_ORDER,
|
||||
RF24_SPI_DATA_MODE));
|
||||
#endif
|
||||
|
||||
RF24_csn(LOW);
|
||||
// timing
|
||||
delayMicroseconds(10);
|
||||
#ifdef LINUX_SPI_BCM
|
||||
uint8_t * prx = spi_rxbuff;
|
||||
uint8_t * ptx = spi_txbuff;
|
||||
uint8_t *prx = RF24_spi_rxbuff;
|
||||
uint8_t *ptx = RF24_spi_txbuff;
|
||||
uint8_t size = len + 1; // Add register value to transmit buffer
|
||||
|
||||
*ptx++ = cmd;
|
||||
@@ -76,7 +78,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
|
||||
*ptx++ = *current++;
|
||||
}
|
||||
}
|
||||
RF24_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
|
||||
RF24_SPI.transfernb( (char *) RF24_spi_txbuff, (char *) RF24_spi_rxbuff, size);
|
||||
if (readMode) {
|
||||
if (size == 2) {
|
||||
status = *++prx; // result is 2nd byte of receive buffer
|
||||
@@ -103,6 +105,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
RF24_csn(HIGH);
|
||||
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
|
||||
RF24_SPI.endTransaction();
|
||||
@@ -198,7 +201,7 @@ LOCAL void RF24_setRFConfiguration(const uint8_t configuration)
|
||||
RF24_writeByteRegister(RF24_REG_NRF_CONFIG, configuration);
|
||||
}
|
||||
|
||||
LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t* address, const uint8_t addressWidth)
|
||||
LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t *address, const uint8_t addressWidth)
|
||||
{
|
||||
RF24_writeMultiByteRegister(pipe, address, addressWidth);
|
||||
}
|
||||
@@ -283,7 +286,7 @@ LOCAL void RF24_standBy(void)
|
||||
}
|
||||
|
||||
|
||||
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint8_t len,
|
||||
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void *buf, const uint8_t len,
|
||||
const bool noACK)
|
||||
{
|
||||
uint8_t RF24_status;
|
||||
@@ -296,7 +299,7 @@ LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint
|
||||
// AutoACK is disabled on the broadcasting pipe - NO_ACK prevents resending
|
||||
RF24_spiMultiByteTransfer((recipient == RF24_BROADCAST_ADDRESS ||
|
||||
noACK) ? RF24_CMD_WRITE_TX_PAYLOAD_NO_ACK :
|
||||
RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t*)buf, len, false );
|
||||
RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t *)buf, len, false );
|
||||
// go, TX starts after ~10us, CE high also enables PA+LNA on supported HW
|
||||
RF24_ce(HIGH);
|
||||
// timeout counter to detect HW issues
|
||||
@@ -337,11 +340,11 @@ LOCAL bool RF24_isDataAvailable(void)
|
||||
}
|
||||
|
||||
|
||||
LOCAL uint8_t RF24_readMessage(void* buf)
|
||||
LOCAL uint8_t RF24_readMessage(void *buf)
|
||||
{
|
||||
const uint8_t len = RF24_getDynamicPayloadSize();
|
||||
RF24_DEBUG(PSTR("RF24:RXM:LEN=%" PRIu8 "\n"), len); // read message
|
||||
RF24_spiMultiByteTransfer(RF24_CMD_READ_RX_PAYLOAD,(uint8_t*)buf,len,true);
|
||||
RF24_spiMultiByteTransfer(RF24_CMD_READ_RX_PAYLOAD,(uint8_t *)buf,len,true);
|
||||
// clear RX interrupt
|
||||
RF24_setStatus(_BV(RF24_RX_DR));
|
||||
return len;
|
||||
@@ -500,11 +503,11 @@ LOCAL bool RF24_initialize(void)
|
||||
RF24_setDynamicPayload(_BV(RF24_DPL_P0 + RF24_BROADCAST_PIPE) | _BV(RF24_DPL_P0));
|
||||
// listen to broadcast pipe
|
||||
RF24_BASE_ID[0] = RF24_BROADCAST_ADDRESS;
|
||||
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0 + RF24_BROADCAST_PIPE, (uint8_t*)&RF24_BASE_ID,
|
||||
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0 + RF24_BROADCAST_PIPE, (uint8_t *)&RF24_BASE_ID,
|
||||
RF24_BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH);
|
||||
// pipe 0, set full address, later only LSB is updated
|
||||
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0, (uint8_t*)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
|
||||
RF24_setPipeAddress(RF24_REG_TX_ADDR, (uint8_t*)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
|
||||
RF24_setPipeAddress(RF24_REG_RX_ADDR_P0, (uint8_t *)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
|
||||
RF24_setPipeAddress(RF24_REG_TX_ADDR, (uint8_t *)&RF24_BASE_ID, MY_RF24_ADDR_WIDTH);
|
||||
// reset FIFO
|
||||
RF24_flushRX();
|
||||
RF24_flushTX();
|
||||
|
||||
+26
-26
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Copyright (C) 2013-2018 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
@@ -34,26 +34,26 @@
|
||||
* RF24 driver-related log messages, format: [!]SYSTEM:[SUB SYSTEM:]MESSAGE
|
||||
* - [!] Exclamation mark is prepended in case of error
|
||||
*
|
||||
* |E| SYS | SUB | Message | Comment
|
||||
* |-|------|------|--------------------|---------------------------------------------------------------------
|
||||
* | | RF24 | INIT | | Initialise RF24 radio
|
||||
* | | RF24 | INIT | PIN,CE=%d,CS=%d | Pin configuration: chip enable (CE), chip select (CS)
|
||||
* |!| RF24 | INIT | SANCHK FAIL | Sanity check failed, check wiring or replace module
|
||||
* | | RF24 | SPP | PCT=%d,TX LEVEL=%d | Set TX level, input TX percent (PCT)
|
||||
* | | RF24 | RBR | REG=%d,VAL=%d | Read register (REG), value=(VAL)
|
||||
* | | RF24 | WBR | REG=%d,VAL=%d | Write register (REG), value=(VAL)
|
||||
* | | RF24 | FRX | | Flush RX buffer
|
||||
* | | RF24 | FTX | | Flush TX buffer
|
||||
* | | RF24 | OWP | RCPT=%d | Open writing pipe, recipient=(RCPT)
|
||||
* | | RF24 | STL | | Start listening
|
||||
* | | RF24 | SPL | | Stop listening
|
||||
* | | RF24 | SLP | | Set radio to sleep
|
||||
* | | RF24 | SBY | | Set radio to standby
|
||||
* | | RF24 | TXM | TO=%d,LEN=%d | Transmit message to=(TO), length=(LEN)
|
||||
* |!| RF24 | TXM | MAX_RT | Max TX retries, no ACK received
|
||||
* |!| RF24 | GDP | PYL INV | Invalid payload size
|
||||
* | | RF24 | RXM | LEN=%d | Read message, length=(LEN)
|
||||
* | | RF24 | STX | LEVEL=%d | Set TX level, level=(LEVEL)
|
||||
* |E| SYS | SUB | Message | Comment
|
||||
* |-|------|------|----------------------|---------------------------------------------------------------------
|
||||
* | | RF24 | INIT | | Initialise RF24 radio
|
||||
* | | RF24 | INIT | PIN,CE=%%d,CS=%%d | Pin configuration: chip enable (CE), chip select (CS)
|
||||
* |!| RF24 | INIT | SANCHK FAIL | Sanity check failed, check wiring or replace module
|
||||
* | | RF24 | SPP | PCT=%%d,TX LEVEL=%%d | Set TX level, input TX percent (PCT)
|
||||
* | | RF24 | RBR | REG=%%d,VAL=%%d | Read register (REG), value=(VAL)
|
||||
* | | RF24 | WBR | REG=%%d,VAL=%%d | Write register (REG), value=(VAL)
|
||||
* | | RF24 | FRX | | Flush RX buffer
|
||||
* | | RF24 | FTX | | Flush TX buffer
|
||||
* | | RF24 | OWP | RCPT=%%d | Open writing pipe, recipient=(RCPT)
|
||||
* | | RF24 | STL | | Start listening
|
||||
* | | RF24 | SPL | | Stop listening
|
||||
* | | RF24 | SLP | | Set radio to sleep
|
||||
* | | RF24 | SBY | | Set radio to standby
|
||||
* | | RF24 | TXM | TO=%%d,LEN=%%d | Transmit message to=(TO), length=(LEN)
|
||||
* |!| RF24 | TXM | MAX_RT | Max TX retries, no ACK received
|
||||
* |!| RF24 | GDP | PYL INV | Invalid payload size
|
||||
* | | RF24 | RXM | LEN=%%d | Read message, length=(LEN)
|
||||
* | | RF24 | STX | LEVEL=%%d | Set TX level, level=(LEVEL)
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -174,7 +174,7 @@ LOCAL void RF24_ce(const bool level);
|
||||
* @param readMode
|
||||
* @return
|
||||
*/
|
||||
LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, const uint8_t len,
|
||||
LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, const uint8_t len,
|
||||
const bool readMode);
|
||||
/**
|
||||
* @brief RF24_spiByteTransfer
|
||||
@@ -199,7 +199,7 @@ LOCAL uint8_t RF24_RAW_writeByteRegister(const uint8_t cmd, const uint8_t value)
|
||||
// helper macros
|
||||
#define RF24_readByteRegister(__reg) RF24_RAW_readByteRegister(RF24_CMD_READ_REGISTER | (RF24_REGISTER_MASK & (__reg))) //!< RF24_readByteRegister
|
||||
#define RF24_writeByteRegister(__reg,__value) RF24_RAW_writeByteRegister(RF24_CMD_WRITE_REGISTER | (RF24_REGISTER_MASK & (__reg)), __value) //!< RF24_writeByteRegister
|
||||
#define RF24_writeMultiByteRegister(__reg,__buf,__len) RF24_spiMultiByteTransfer(RF24_CMD_WRITE_REGISTER | (RF24_REGISTER_MASK & (__reg)),(uint8_t*)__buf, __len,false) //!< RF24_writeMultiByteRegister
|
||||
#define RF24_writeMultiByteRegister(__reg,__buf,__len) RF24_spiMultiByteTransfer(RF24_CMD_WRITE_REGISTER | (RF24_REGISTER_MASK & (__reg)),(uint8_t *)__buf, __len,false) //!< RF24_writeMultiByteRegister
|
||||
|
||||
/**
|
||||
* @brief RF24_flushRX
|
||||
@@ -256,7 +256,7 @@ LOCAL void RF24_powerUp(void);
|
||||
* @param noACK set True if no ACK is required
|
||||
* @return
|
||||
*/
|
||||
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint8_t len,
|
||||
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void *buf, const uint8_t len,
|
||||
const bool noACK = false);
|
||||
/**
|
||||
* @brief RF24_getDynamicPayloadSize
|
||||
@@ -272,7 +272,7 @@ LOCAL bool RF24_isDataAvailable(void);
|
||||
* @brief RF24_readMessage
|
||||
* @return
|
||||
*/
|
||||
LOCAL uint8_t RF24_readMessage(void* buf);
|
||||
LOCAL uint8_t RF24_readMessage(void *buf);
|
||||
/**
|
||||
* @brief RF24_setNodeAddress
|
||||
* @param address
|
||||
@@ -345,7 +345,7 @@ LOCAL void RF24_setRFConfiguration(const uint8_t configuration);
|
||||
* @param address
|
||||
* @param addressWidth
|
||||
*/
|
||||
LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t* address, const uint8_t addressWidth);
|
||||
LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t *address, const uint8_t addressWidth);
|
||||
/**
|
||||
* @brief RF24_setPipeLSB
|
||||
* @param pipe
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Copyright (C) 2013-2018 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
|
||||
@@ -42,12 +42,12 @@
|
||||
#endif
|
||||
|
||||
rfm69_internal_t RFM69; //!< internal variables
|
||||
volatile uint8_t rfm69_irq; //!< rfm69 irq flag
|
||||
volatile uint8_t RFM69_irq; //!< rfm69 irq flag
|
||||
|
||||
#if defined(LINUX_SPI_BCM)
|
||||
// SPI RX and TX buffers (max packet len + 1 byte for the command)
|
||||
uint8_t spi_rxbuff[RFM69_MAX_PACKET_LEN + 1];
|
||||
uint8_t spi_txbuff[RFM69_MAX_PACKET_LEN + 1];
|
||||
uint8_t RFM69_spi_rxbuff[RFM69_MAX_PACKET_LEN + 1];
|
||||
uint8_t RFM69_spi_txbuff[RFM69_MAX_PACKET_LEN + 1];
|
||||
#endif
|
||||
|
||||
LOCAL void RFM69_csn(const bool level)
|
||||
@@ -60,24 +60,6 @@ LOCAL void RFM69_prepareSPITransaction(void)
|
||||
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
|
||||
RFM69_SPI.beginTransaction(SPISettings(MY_RFM69_SPI_SPEED, RFM69_SPI_DATA_ORDER,
|
||||
RFM69_SPI_DATA_MODE));
|
||||
#else
|
||||
#if defined(SREG)
|
||||
_SREG = SREG;
|
||||
#endif
|
||||
noInterrupts();
|
||||
#if defined(SPCR) && defined(SPSR)
|
||||
// save current SPI settings
|
||||
_SPCR = SPCR;
|
||||
_SPSR = SPSR;
|
||||
#endif
|
||||
|
||||
// set RFM69 SPI settings
|
||||
#if !defined(MY_SOFTSPI)
|
||||
RFM69_SPI.setDataMode(RFM69_SPI_DATA_MODE);
|
||||
RFM69_SPI.setBitOrder(RFM69_SPI_DATA_ORDER);
|
||||
RFM69_SPI.setClockDivider(RFM69_CLOCK_DIV);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -85,17 +67,6 @@ LOCAL void RFM69_concludeSPITransaction(void)
|
||||
{
|
||||
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
|
||||
RFM69_SPI.endTransaction();
|
||||
#else
|
||||
// restore SPI settings to what they were before talking to RFM69
|
||||
#if defined(SPCR) && defined(SPSR)
|
||||
SPCR = _SPCR;
|
||||
SPSR = _SPSR;
|
||||
#endif
|
||||
// restore the prior interrupt state
|
||||
#if defined(SREG)
|
||||
SREG = _SREG;
|
||||
#endif
|
||||
interrupts();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -109,8 +80,8 @@ LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
|
||||
RFM69_csn(LOW);
|
||||
|
||||
#if defined(LINUX_SPI_BCM)
|
||||
uint8_t *prx = spi_rxbuff;
|
||||
uint8_t *ptx = spi_txbuff;
|
||||
uint8_t *prx = RFM69_spi_rxbuff;
|
||||
uint8_t *ptx = RFM69_spi_txbuff;
|
||||
uint8_t size = len + 1; // Add register value to transmit buffer
|
||||
|
||||
*ptx++ = cmd;
|
||||
@@ -121,7 +92,7 @@ LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_
|
||||
*ptx++ = *current++;
|
||||
}
|
||||
}
|
||||
RFM69_SPI.transfernb((char *)spi_txbuff, (char *)spi_rxbuff, size);
|
||||
RFM69_SPI.transfernb((char *)RFM69_spi_txbuff, (char *)RFM69_spi_rxbuff, size);
|
||||
if (aReadMode) {
|
||||
if (size == 2) {
|
||||
status = *++prx; // result is 2nd byte of receive buffer
|
||||
@@ -257,7 +228,7 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
|
||||
// clear FIFO and flags
|
||||
RFM69_clearFIFO();
|
||||
// IRQ
|
||||
rfm69_irq = false;
|
||||
RFM69_irq = false;
|
||||
hwPinMode(MY_RFM69_IRQ_PIN, INPUT);
|
||||
attachInterrupt(MY_RFM69_IRQ_NUM, RFM69_interruptHandler, RISING);
|
||||
return true;
|
||||
@@ -271,7 +242,7 @@ LOCAL void RFM69_clearFIFO(void)
|
||||
LOCAL void RFM69_interruptHandler(void)
|
||||
{
|
||||
// set flag
|
||||
rfm69_irq = true;
|
||||
RFM69_irq = true;
|
||||
}
|
||||
|
||||
LOCAL void RFM69_interruptHandling(void)
|
||||
@@ -346,10 +317,10 @@ LOCAL void RFM69_interruptHandling(void)
|
||||
|
||||
LOCAL void RFM69_handler(void)
|
||||
{
|
||||
if (rfm69_irq) {
|
||||
if (RFM69_irq) {
|
||||
// radio is in STDBY
|
||||
// clear flag, 8bit - no need for critical section
|
||||
rfm69_irq = false;
|
||||
RFM69_irq = false;
|
||||
RFM69_interruptHandling();
|
||||
}
|
||||
}
|
||||
@@ -429,10 +400,10 @@ LOCAL bool RFM69_sendFrame(rfm69_packet_t *packet, const bool increaseSequenceCo
|
||||
// send message
|
||||
(void)RFM69_setRadioMode(RFM69_RADIO_MODE_TX); // irq upon txsent
|
||||
const uint32_t txStartMS = hwMillis();
|
||||
while (!rfm69_irq && (hwMillis() - txStartMS < MY_RFM69_TX_TIMEOUT_MS)) {
|
||||
while (!RFM69_irq && (hwMillis() - txStartMS < MY_RFM69_TX_TIMEOUT_MS)) {
|
||||
doYield();
|
||||
};
|
||||
return rfm69_irq;
|
||||
return RFM69_irq;
|
||||
}
|
||||
|
||||
LOCAL bool RFM69_send(const uint8_t recipient, uint8_t *data, const uint8_t len,
|
||||
|
||||
@@ -99,30 +99,10 @@
|
||||
#define RFM69_SPI_DATA_ORDER MSBFIRST //!< SPI data order
|
||||
#define RFM69_SPI_DATA_MODE SPI_MODE0 //!< SPI mode
|
||||
|
||||
// SPI clock divier for non-transaction implementations
|
||||
#if (MY_RFM69_SPI_SPEED >= F_CPU / 2)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV2 //!< SPI clock divider 2
|
||||
#elif (MY_RFM69_SPI_SPEED >= F_CPU / 4)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV4 //!< SPI clock divider 4
|
||||
#elif (MY_RFM69_SPI_SPEED >= F_CPU / 8)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV8 //!< SPI clock divider 8
|
||||
#elif (MY_RFM69_SPI_SPEED >= F_CPU / 16)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV16 //!< SPI clock divider 16
|
||||
#elif (MY_RFM69_SPI_SPEED >= F_CPU / 32)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV32 //!< SPI clock divider 32
|
||||
#elif (MY_RFM69_SPI_SPEED >= F_CPU / 64)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV64 //!< SPI clock divider 64
|
||||
#elif (MY_RFM69_SPI_SPEED >= F_CPU / 128)
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV128 //!< SPI clock divider 128
|
||||
#else
|
||||
#define RFM69_CLOCK_DIV SPI_CLOCK_DIV256 //!< SPI clock divider 256
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO) && !defined(__arm__) && !defined(RFM69_SPI)
|
||||
#include <SPI.h>
|
||||
#if defined(MY_SOFTSPI)
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM69_SPI_DATA_MODE>
|
||||
RFM69_SPI;
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM69_SPI_DATA_MODE>RFM69_SPI;
|
||||
#else
|
||||
#define RFM69_SPI SPI
|
||||
#endif
|
||||
|
||||
+20
-18
@@ -35,15 +35,15 @@
|
||||
#define RFM95_DEBUG(x,...) //!< DEBUG null
|
||||
#endif
|
||||
|
||||
rfm95_internal_t RFM95; //!< internal variables
|
||||
volatile uint8_t RFM95_irq; //<! rfm95 irq flag
|
||||
|
||||
#if defined(LINUX_SPI_BCM)
|
||||
// SPI RX and TX buffers (max packet len + 1 byte for the command)
|
||||
uint8_t spi_rxbuff[RFM95_MAX_PACKET_LEN + 1];
|
||||
uint8_t spi_txbuff[RFM95_MAX_PACKET_LEN + 1];
|
||||
uint8_t RFM95_spi_rxbuff[RFM95_MAX_PACKET_LEN + 1];
|
||||
uint8_t RFM95_spi_txbuff[RFM95_MAX_PACKET_LEN + 1];
|
||||
#endif
|
||||
|
||||
rfm95_internal_t RFM95; //!< internal variables
|
||||
volatile uint8_t rfm95_irq; //<! rfm95 irq flag
|
||||
|
||||
LOCAL void RFM95_csn(const bool level)
|
||||
{
|
||||
hwDigitalWrite(MY_RFM95_CS_PIN, level);
|
||||
@@ -55,13 +55,14 @@ LOCAL uint8_t RFM95_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_
|
||||
uint8_t status;
|
||||
uint8_t *current = buf;
|
||||
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
|
||||
RFM95_SPI.beginTransaction(SPISettings(MY_RFM95_SPI_SPEED, MY_RFM95_SPI_DATA_ORDER,
|
||||
MY_RFM95_SPI_DATA_MODE));
|
||||
RFM95_SPI.beginTransaction(SPISettings(MY_RFM95_SPI_SPEED, RFM95_SPI_DATA_ORDER,
|
||||
RFM95_SPI_DATA_MODE));
|
||||
#endif
|
||||
|
||||
RFM95_csn(LOW);
|
||||
#if defined(LINUX_SPI_BCM)
|
||||
uint8_t *prx = spi_rxbuff;
|
||||
uint8_t *ptx = spi_txbuff;
|
||||
uint8_t *prx = RFM95_spi_rxbuff;
|
||||
uint8_t *ptx = RFM95_spi_txbuff;
|
||||
uint8_t size = len + 1; // Add register value to transmit buffer
|
||||
|
||||
*ptx++ = cmd;
|
||||
@@ -72,7 +73,7 @@ LOCAL uint8_t RFM95_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_
|
||||
*ptx++ = *current++;
|
||||
}
|
||||
}
|
||||
RFM95_SPI.transfernb((char *)spi_txbuff, (char *)spi_rxbuff, size);
|
||||
RFM95_SPI.transfernb((char *)RFM95_spi_txbuff, (char *)RFM95_spi_rxbuff, size);
|
||||
if (aReadMode) {
|
||||
if (size == 2) {
|
||||
status = *++prx; // result is 2nd byte of receive buffer
|
||||
@@ -100,6 +101,7 @@ LOCAL uint8_t RFM95_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_
|
||||
}
|
||||
#endif
|
||||
RFM95_csn(HIGH);
|
||||
|
||||
#if !defined(MY_SOFTSPI) && defined(SPI_HAS_TRANSACTION)
|
||||
RFM95_SPI.endTransaction();
|
||||
#endif
|
||||
@@ -220,7 +222,7 @@ LOCAL bool RFM95_initialise(const uint32_t frequencyHz)
|
||||
}
|
||||
|
||||
// IRQ
|
||||
rfm95_irq = false;
|
||||
RFM95_irq = false;
|
||||
hwPinMode(MY_RFM95_IRQ_PIN, INPUT);
|
||||
attachInterrupt(MY_RFM95_IRQ_NUM, RFM95_interruptHandler, RISING);
|
||||
return true;
|
||||
@@ -229,7 +231,7 @@ LOCAL bool RFM95_initialise(const uint32_t frequencyHz)
|
||||
LOCAL void RFM95_interruptHandler(void)
|
||||
{
|
||||
// set flag
|
||||
rfm95_irq = true;
|
||||
RFM95_irq = true;
|
||||
}
|
||||
|
||||
// RxDone, TxDone, CADDone is mapped to DI0
|
||||
@@ -278,8 +280,8 @@ LOCAL void RFM95_interruptHandling(void)
|
||||
|
||||
LOCAL void RFM95_handler(void)
|
||||
{
|
||||
if (rfm95_irq) {
|
||||
rfm95_irq = false;
|
||||
if (RFM95_irq) {
|
||||
RFM95_irq = false;
|
||||
RFM95_interruptHandling();
|
||||
}
|
||||
}
|
||||
@@ -345,12 +347,12 @@ LOCAL bool RFM95_sendFrame(rfm95_packet_t *packet, const bool increaseSequenceCo
|
||||
(void)RFM95_setRadioMode(RFM95_RADIO_MODE_TX);
|
||||
// wait until IRQ fires or timeout
|
||||
const uint32_t startTX_MS = hwMillis();
|
||||
while (!rfm95_irq &&
|
||||
while (!RFM95_irq &&
|
||||
(hwMillis() - startTX_MS <
|
||||
MY_RFM95_TX_TIMEOUT_MS) ) { // make this payload length + bit rate dependend
|
||||
doYield();
|
||||
}
|
||||
return rfm95_irq;
|
||||
return RFM95_irq;
|
||||
}
|
||||
|
||||
LOCAL bool RFM95_send(const uint8_t recipient, uint8_t *data, const uint8_t len,
|
||||
@@ -468,7 +470,7 @@ LOCAL bool RFM95_setRadioMode(const rfm95_radioMode_t newRadioMode)
|
||||
LOCAL void RFM95_powerUp(void)
|
||||
{
|
||||
#if defined(MY_RFM95_POWER_PIN)
|
||||
RFM69_DEBUG(PSTR("RFM95:PWU\n")); // power up radio
|
||||
RFM95_DEBUG(PSTR("RFM95:PWU\n")); // power up radio
|
||||
hwDigitalWrite(MY_RFM95_POWER_PIN, HIGH);
|
||||
delay(RFM95_POWERUP_DELAY_MS);
|
||||
#endif
|
||||
@@ -476,7 +478,7 @@ LOCAL void RFM95_powerUp(void)
|
||||
LOCAL void RFM95_powerDown(void)
|
||||
{
|
||||
#if defined(MY_RFM95_POWER_PIN)
|
||||
RFM69_DEBUG(PSTR("RFM95:PWD\n")); // power down radio
|
||||
RFM95_DEBUG(PSTR("RFM95:PWD\n")); // power down radio
|
||||
hwDigitalWrite(MY_RFM95_POWER_PIN, LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -107,14 +107,13 @@
|
||||
#define DEFAULT_RFM95_CS_PIN (SS) //!< DEFAULT_RFM95_CS_PIN
|
||||
|
||||
// SPI settings
|
||||
#define MY_RFM95_SPI_DATA_ORDER MSBFIRST //!< SPI data order
|
||||
#define MY_RFM95_SPI_DATA_MODE SPI_MODE0 //!< SPI mode
|
||||
#define RFM95_SPI_DATA_ORDER MSBFIRST //!< SPI data order
|
||||
#define RFM95_SPI_DATA_MODE SPI_MODE0 //!< SPI mode
|
||||
|
||||
#if defined (ARDUINO) && !defined (__arm__) && !defined (RFM95_SPI)
|
||||
#include <SPI.h>
|
||||
#if defined(MY_SOFTSPI)
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, MY_RF24_SPI_DATA_MODE>
|
||||
RFM95_SPI;
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM95_SPI_DATA_MODE>RFM95_SPI;
|
||||
#else
|
||||
#define RFM95_SPI SPI //!< SPI
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user