Fix variable names, minor updates (#1071)

This commit is contained in:
tekka
2018-02-19 13:26:14 +01:00
committed by GitHub
parent a0af38a0d8
commit 345d6d7d11
7 changed files with 83 additions and 128 deletions
+20 -17
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -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